Results 1 to 9 of 9

Thread: Texture unit problem...

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2016
    Posts
    6

    Texture unit problem...

    Hi i try to use shader to display frame (YUV in 3 plans), i use epoxy and GtkGLArea.
    my GC (intel iris) support max texture unit : 8

    My problem is that on my shader the last created texture seem to be use for all sampler ?
    - if i create only the first one (Y 320x240 8 bits), my shader display it (Y) as expected.
    - if i create 2 textures (add U 160x240 8 bits), my shader display it (U) in place of first one (Y).
    - if i create 3 textures (add V 160x240 8 bits), my shader display it (V) in place of first one (Y).

    For my test, i modify the shader to display only Y (i apply a factor of 0.00001 to U & V to ensure that shader compiler do not remove associated sampler...

    I remove all error check to simply the code.

    Thanks for your help i send all my weekend on this problem...

    WCdr

    I create 3 textures (one 8 bits channel) like this :
    guint id {};
    glGenTextures ( 1, &id);
    glBindTexture ( GL_TEXTURE_2D, id );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
    glTexImage2D ( GL_TEXTURE_2D, 0, GL_RED, sizeWidth, sizeHeight, 0, GL_RED, GL_UNSIGNED_BYTE, pvData );
    => I check image data it's ok (dim & bitmap)
    => I store each id on my texture object.

    I get shader sampler like this :
    Load vertex shader
    Load fragment shader
    Link program
    m_uiSamplerIndexY = glGetUniformLocation ( scpProgram, "Texture0" );
    m_uiSamplerIndexU = glGetUniformLocation ( scpProgram, "Texture1" );
    m_uiSamplerIndexV = glGetUniformLocation ( scpProgram, "Texture2" );
    Detach vertex & fragment.
    => I check all index, there's valid : 1, 2 & 3

    I render like this :
    glClearColor ( 0.0F, 0.0F, 0.0F, 1.0F );
    glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glActiveTexture ( GL_TEXTURE0 );
    m_oTexture.Bind ();
    glUniform1i ( m_uiSamplerIndexY, 0 );

    glActiveTexture ( GL_TEXTURE1 );
    m_oTextureU.Bind ();
    glUniform1i ( m_uiSamplerIndexU, 1 );

    glActiveTexture ( GL_TEXTURE2 );
    m_oTextureV.Bind ();
    glUniform1i ( m_uiSamplerIndexV, 2 );

    glUniformMatrix4fv ( m_uiMatrixIndex, 1, GL_FALSE, m_matrixTransform.data ());
    glBindVertexArray ( m_uiVertexIndex );
    glDrawArrays ( GL_TRIANGLE_STRIP, 0, m_arrayVertexDesc.size ());

    Vertex shader.
    #version 330 core

    in vec2 posVertex;
    in vec2 uvVertex;

    uniform mat4 matrixTransform;

    smooth out vec2 coordTexture;

    void main()
    {
    coordTexture = uvVertex;
    gl_Position = matrixTransform * vec4 ( posVertex, 0.0, 1.0 );
    }

    #version 330 core

    uniform sampler2D Texture0;
    uniform sampler2D Texture1;
    uniform sampler2D Texture2;

    smooth in vec2 coordTexture;

    void main ()
    {
    float fY = texture2D ( Texture0, coordTexture ).r;
    float fU = texture2D ( Texture1, coordTexture ).r;
    float fV = texture2D ( Texture2, coordTexture ).r;

    float fPixel = fY + ( fU + fV ) * 0.00001;

    gl_FragColor = vec4 ( fPixel, fPixel, fPixel, 1.0 );
    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,104
    There's nothing wrong with the code you posted, so the problem is somewhere in the code which wasn't posted.

  3. #3
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    One thing I can see is that you don't seem to have a glUseProgram call, but maybe that's in the code you haven't posted?

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2016
    Posts
    6

    Thanks, I put it just after glClear

    Quote Originally Posted by mhagain View Post
    One thing I can see is that you don't seem to have a glUseProgram call, but maybe that's in the code you haven't posted?
    I put it just after glClear

    Thanks for your help...

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2016
    Posts
    6

    Thanks, but there's not more opengl code

    Quote Originally Posted by GClements View Post
    There's nothing wrong with the code you posted, so the problem is somewhere in the code which wasn't posted.
    Thanks, but there's no more opengl code... maybe be an other bugs on GtkGLArea (gtkmm 3.18.0, gtk 3.18.9), i already solve two :
    1 - Inheritance issue, i solve it using composition.
    2 - Destruction issue, i intercept application close to call opengl release code...
    or an issue in my c++14 encapsulation, i already remove camera code using dumped raw frame (checked with external program viewer)

    I plan to write a separate program using pure xcb & glx without any encapsulation in pure C instead...

    Thanks for your help...

  6. #6
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Code :
    float fY = texture2D ( Texture0, coordTexture ).r;
    texture2D is deprecated in version 330 core. Use texture instead:
    Code :
    float fY = texture ( Texture0, coordTexture ).r;
    Probability is that your shaders failed to compile and (I guess) you're not doing error checking.

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2016
    Posts
    6
    Quote Originally Posted by mhagain View Post
    Code :
    float fY = texture2D ( Texture0, coordTexture ).r;
    texture2D is deprecated in version 330 core. Use texture instead:
    Code :
    float fY = texture ( Texture0, coordTexture ).r;
    Probability is that your shaders failed to compile and (I guess) you're not doing error checking.
    My problem is not that shader do not compile (or link), i check error and every is ok, my problem is that last loaded texture seems to override previous one...

    I replace texture2D by texture, no change...

    Thanks for you answer,

  8. #8
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Quote Originally Posted by wizardcoder View Post
    My problem is not that shader do not compile (or link), i check error and every is ok, my problem is that last loaded texture seems to override previous one...

    I replace texture2D by texture, no change...

    Thanks for you answer,
    OK.

    The reason why I'm saying this is that the behaviour you're reporting is consistent with shaders failing to compile or link; i.e as if glUseProgram (0) were called, or as if glUseProgram with a valid program object name were never called; or consistent with using the old fixed pipeline with GL_REPLACE mode in all of your texture units.

  9. #9
    Junior Member Newbie
    Join Date
    Jun 2016
    Posts
    6
    Quote Originally Posted by mhagain View Post
    OK.

    The reason why I'm saying this is that the behaviour you're reporting is consistent with shaders failing to compile or link; i.e as if glUseProgram (0) were called, or as if glUseProgram with a valid program object name were never called; or consistent with using the old fixed pipeline with GL_REPLACE mode in all of your texture units.
    Good information, i donít notice this information, i am a newbie with OpenGL, normally y use DirectX with is object api, it's more natural for me.... the switch to Linux with all is library is hard ^_^

    Thanks for your answer

Similar Threads

  1. OpenGl Texture unit problem
    By agersoor in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 05-08-2012, 03:56 AM
  2. Depth texture bound to FBO and texture unit?
    By imported_pjcozzi in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 02-01-2011, 05:14 PM
  3. Texture unit 0 blending with Texture unit 1 problem
    By kackurot in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 10-31-2006, 10:16 PM
  4. Multiple 3D Texture on different texture unit question
    By SW in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 06-04-2002, 06:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean