1

I am confused with the internal format related to texture2D() in GLSL and glTexImage2D() in OpenGL, When I use(pay attention to the third and the eighth parameters):

glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA16F_ARB, WINDOW_SIZE, WINDOW_SIZE, 0, GL_RGBA, 
            GL_FLOAT, floatDataPtr);

I got the nonclampedvalue of sampler2D in the glsl without clamped to [0, 1]:

vec4 nonclampedvalue = texture2D(my16floattex2d, texcoord1);

When I use:

glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, WINDOW_SIZE, WINDOW_SIZE, 0, GL_RGBA, 
            GL_UNSIGNED_BYTE, byteDataPtr);

I got the clampedvalue of sampler2D in the glsl clamped to [0, 1]:

vec4 clampedvalue = texuture2D(myunsignedbytetex2d, texcoord2);

So my questions are this:

  1. What value will I get in glsl when invoke the glTexImage2D like this(clamped or not clamped):

    glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, WINDOW_SIZE, WINDOW_SIZE, 0, GL_RGBA, 
           GL_FLOAT, floatDataPtr);
    
  2. What value will I get in glsl when invoke the glTexImage2D like this(clamped or not clamped):

    glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA16F_ARB, WINDOW_SIZE, WINDOW_SIZE, 0, GL_RGBA,
            GL_UNSIGNED_BYTE, byteDataPtr);
    
  3. As I can't find the detailed information in OpenGL official website, What value will be return in the sampler2D texture with different internal format as well as different type(such as GL_FLOAT or GL_UNSIGNED_BYTE mentioned above) of the data passed to the texture when invoke the glTexImage2D()? what's all the rules?

Does anyone can help?

toolchainX
  • 1,998
  • 3
  • 27
  • 43

1 Answers1

3

What value will I get in glsl when invoke the glTexImage2D like this(clamped or not clamped):

This is governed only by the "internal format" parameter. Normalized internal formats are... normalized. They don't store floating point values; they store integer values which are interpreted as floats. The maximum integer value becomes 1.0 and the minimum becomes 0.0 (or -1.0 if it's an SNORM format).

As I can't find the detailed information in OpenGL official website

Look harder next time; it's right there on the Wiki. The "internal format" used for creating textures and renderbuffers. It even explains that the last three parameters govern pixel transfer operations: uploading data to the image.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • it seems that in my program the function invoked: `glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA16F_ARB, WINDOW_SIZE, WINDOW_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, byteDataPtr);` give me an value clamped to [0, 1]. As I understanded in the [internal format](http://www.opengl.org/wiki/Image_Format), isn't it be some value between [0.0f, 255.0f]? – toolchainX Apr 26 '12 at 00:47
  • @tlh1987: That's why I linked you to the page on pixel transfers. *You gave OpenGL values between [0, 1]*. You said that your data was in RGBA order, and that each value was an unsigned byte. Thus, you told OpenGL that your data contained integer values that were stored as normalized unsigned bytes. All OpenGL did was read your data and interpret it as you described, storing it in a texture that could have been able to store larger data. – Nicol Bolas Apr 26 '12 at 01:10