Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between glTexParameter and glSamplerParameter

Because I am no expert, please dont consider this question silly. I have read several tutorials where texture parameters were set using glTexParameter. I am talking about GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER , GL_TEXTURE_WRAP_R etc.. Suddenly I come across a tutorial that now used glSamplerParameter to set these parameters.

I see there are some common parameters between glTexParameter and glSamplerParameter like (GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER , GL_TEXTURE_WRAP_R, GL_TEXTURE_MIN_LOD etc), and there are some that are only applicable in glTexParameter (GL_TEXTURE_BASE_LEVEL, GL_TEXTURE_SWIZZLE_R etc). I perfectly understand the uncommon ones because after all, the glTexParameter is acting on the image, and these parameters are specifying attributes image per se.

But I dont quite understand why are there some parameters that are common between these 2 GL calls. Which should be used when? In my opinion sampling parameters like (GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER , GL_TEXTURE_WRAP_R, etc) should only be applicable to sampler (glSamplerParameter) and not to glTexParameter.

Please help me understand the difference between two.

like image 565
viktorzeid Avatar asked Sep 30 '13 03:09

viktorzeid


People also ask

What is Gltexparameteri?

The glTexParameter function assigns the value or values in params to the texture parameter specified as pname. The target parameter defines the target texture, either GL_TEXTURE_1D or GL_TEXTURE_2D. As more texture elements are sampled in the minification process, fewer aliasing artifacts will be apparent.

What is sampler2D?

A sampler2D is used to do lookup in a standard texture image; a samplerCube is used to do lookup in a cubemap texture (Subsection 5.3. 4). The value of a sampler variable is a reference to a texture unit. The value tells which texture unit is invoked when the sampler variable is used to do texture lookup.

What is OpenGL texture?

A texture is an OpenGL Object that contains one or more images that all have the same image format. A texture can be used in two ways: it can be the source of a texture access from a Shader, or it can be used as a render target.


1 Answers

glSamplerParameter is relatively new. The way a texture is sampled is actually a property of the thing doing the sampling, not of the texture itself — not just in semantic terms but on actual, real hardware.

Besides the desire to represent things as they actually function on the hardware, tying two unrelated things together can cost you in performance terms. If you make the way something is sampled a property of the sampler then e.g. you can sample the same texture in two different ways within the same shader. If it's a property of the texture then you're going to have to upload the same texture twice or write a multi-pass shader.

Hence the two things are now being separated.

like image 125
Tommy Avatar answered Oct 14 '22 13:10

Tommy