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 3 of 3

Thread: OpenGl Texture unit problem

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    3

    OpenGl Texture unit problem

    I have these two 3D textures that are being sent to the fragment shader and are rendered perfectly OK.
    But there is a problem, As soon as I even create another texture (it’s a 1D texture), a black screen is being rendered instead of the correct former result.

    About this 1D texture, I’m not even sending it to the fragment shader. The minute I call glTexImage1D(…) the black screen shows up. I comment this line and it goes away!!And the two textures are rendered.

    I figured there has to be some kind of problem with texture units. Because when I run the application with gDebugger, the texture unit of one of 3D textures is THE SAME as the one assigned to the 1D texture.

    I did not assign any texture unit to the 1D texture, I just created it. Apparently texture unit GL_TEXTURE0 is being automatically assigned to the 1D texture. The weird part is that although I use GL_TEXTURE2 and GL_TEXTURE3 for the 3D texture, one of them is being bound to GL_TEXTURE0 as a result of calling glTexImage1D!

    Here is an output from the textures list window of gDebugger:

    Texture 1 (unit 2 ,bound3d)-enabled
    Texture 2 (unit 0 ,bound1d)
    Texture 3 (unit 0 ,bound3d)-Enabled (unit 3,bound3D)-enabled

    Can you please explain to me why is this happening?
    thanks,

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    So why don't you use TEXTURE0 and TEXTURE1 instead of 2 and 3?

    PS: texture units can't be enabled or disabled. They are always enabled.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    433
    Are you absolutely sure your program logic is binding the right textures to the right units + the uniforms are correctly assigned to the correct texture units?

    From the OpenGL spec:
    Quote Originally Posted by OpenGL_4.2_Spec_Section_2.11.9 (Samplers)
    It is not allowed to have variables of different sampler types pointing to the same texture image unit within a program object. This situation can only be detected at the next rendering command issued, and an INVALID_OPERATION error will then be generated.
    But I guess it shouldn't apply if you aren't actually trying to access the 1D texture in the shader. Are you getting any error messages reported?

    And as V-man said, whether texture units are enabled/disabled is ignored by shaders.
    Last edited by Dan Bartlett; 05-08-2012 at 03:08 AM. Reason: mis-read question

Tags for this Thread

Posting Permissions

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