Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: [solved] textureSize with GL_LINEAR_MIPMAP_LINEAR

  1. #1
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101

    [solved] textureSize with GL_LINEAR_MIPMAP_LINEAR

    This is just for information. I created a non-mipmap texture with
    Code :
    glBindTexture(GL_TEXTURE_2D, c_Textures[RESOLVE]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GLsizei(m_Width), GLsizei(m_Height),GL_FALSE,GL_RGBA,GL_UNSIGNED_INT,0);

    when I tried to get the size in the fragment shader

    Code :
      ivec2 sz = textureSize(u_ResolvedColourTexture,int(0));

    the size returned is 0,0. Replacing GL_LINEAR_MIPMAP_LINEAR with GL_LINEAR returned the correct size

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    661
    That is probably an unfortunate combination of application error (providing an incomplete texture) and a driver bug (not correctly returning the size of an incomplete texture).

  3. #3
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    My general feeling with GL would be that this is actually intended behavior, but as you mentioned it i can find any text that would allow implementation to return garbage (or zero) from textureSize when the texture is incomplete. This seems counter intuitive for me, as it essentially requires the driver to pass an array of uniforms to the shader (i.e. this information probably can't be taken from surface setup that hw needs).

    If this is a bug, then id be willing to bet its a spec bug instead.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    Quote Originally Posted by kyle_ View Post
    My general feeling with GL would be that this is actually intended behavior, but as you mentioned it i can find any text that would allow implementation to return garbage (or zero) from textureSize when the texture is incomplete.
    If a texture is incomplete, you cannot get any information out of it. This applies to both texels, size and other stuff.

    Quote Originally Posted by kyle_ View Post
    This seems counter intuitive for me, as it essentially requires the driver to pass an array of uniforms to the shader (i.e. this information probably can't be taken from surface setup that hw needs).
    Well, that's just your assumption. The hardware is free to get the size information from anywhere. Yes, it might be an internal array of uniforms, but in practice, it's very likely that the hardware actually has this information from the internal data structure that corresponds to a sampler uniform.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101
    The main reason I posted this was because the texture creation logic did not generate any error from either glCheckFramebufferStatus nor glGetError

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    661
    If a texture is incomplete, you cannot get any information out of it. This applies to both texels, size and other stuff.
    Can you cite the corresponding paragraph from the specs?
    There is language talking about sampling from incomplete textures, but querying the size of such a texture has not been deemed undefined.

  7. #7
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Quote Originally Posted by aqnuep View Post
    Yes, it might be an internal array of uniforms, but in practice, it's very likely that the hardware actually has this information from the internal data structure that corresponds to a sampler uniform.
    Yes, this all is based on assumption that textureSize has to work with incomplete textures, and frankly I would be very surprised if anyone implemented it that way.

    Its highly improbable that HW would support specifying misbehaved textures (as allowed by GL). Say, setup a surface that has first level of size 1x1 RGBA8 format, second level is empty an third level is 100x1 DEPTH_COMPONENT8. Now HW could be made to 'support' textureSize on such abomination, but it would probably not be very good idea - i assume that serious HW vendors don't waste silicon to support idiotic cases written (?) in GL spec. Given this assumption pretty much only way to do that would be by using uniform arrays but this is wasteful and again not very bright.

    Quote Originally Posted by aqnuep View Post
    If a texture is incomplete, you cannot get any information out of it. This applies to both texels, size and other stuff.
    By what wording? I see only this in core spec:
    Incomplete textures (see section
    3.9.14) are considered to return a texture source color of (0, 0, 0, 1) for all four source texels.

    Which handles all sampling functions. There are 2 other functions though that have to do with samplers: textureSize and textureQueryLod. textureQueryLod is explicitly allowed to return garbage on incomplete textures (as per GLSL spec), textureSize is not.
    There is nothing more regarding incomplete textures in both specs afaik. Do you see something else relevant to this case?

    Last edited by kyle_; 04-30-2012 at 11:27 AM. Reason: the forum hates me

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    Then I think it's most probably a specification bug. Actually, this is not the only specification bug in the "Texture Size Query" section of chapter 2.11.7. If you look closely, it says in the last sentence that the "layer index" is returned for array textures, but it should say "number of layers" instead.

    I'm just saying, I wouldn't expect any proper behavior from the shader's point of view if you try to do anything with a sampler uniform that references an incomplete texture. It may be a specification bug, but I don't think it's a driver bug.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •