Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: BindAttribLoc work, GetAttribLoc doesn't

  1. #1
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    33

    BindAttribLoc work, GetAttribLoc doesn't

    Hi OpenGl Community!

    I'm working with GLSL shader and decide to get attribute location after the link instead of bind it.

    So I've just translate my code

    Code :
    glAttachShader(_shaderProgram, vertexShader);
     
    // prepare varing for future binding to VBOs
    glBindAttribLocation(_shaderProgram, _pointIndexAttr, "in_Position");
    glBindAttribLocation(_shaderProgram, _sizeIndexAttr, "in_Size");
    glBindAttribLocation(_shaderProgram, _colorIndexAttr, "in_Color");
     
    glLinkProgram(_shaderProgram);

    To this:


    Code :
    glAttachShader(_shaderProgram, vertexShader);
     
    glLinkProgram(_shaderProgram);
     
    _pointIndexAttr = glGetAttribLocation(_shaderProgram, "in_Position");
    _sizeIndexAttr = glGetAttribLocation(_shaderProgram, "in_Size");
    _colorIndexAttr = glGetAttribLocation(_shaderProgram, "in_Color");


    And this doesn't work! o_O

    I mean, the first code show something and the second show nothing...

    I really don't understand why a simple thing that only change value after the link instead of before can create a such problem. I'm sure I've made something stupid.

    I never call hard coded number for shader attribute (I always use "_pointIndexAttr").

    This break my head you can't imagine...

    Thanks in advance for help!

    Regards,

    Dorian
    Working on coral, a node based procedural workflow software.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,726

    Re: BindAttribLoc work, GetAttribLoc doesn't

    You're going to have to post more than that. For example, if you have multiple programs, each program will have its own set of attribute locations.

  3. #3
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    33

    Re: BindAttribLoc work, GetAttribLoc doesn't

    Thanks for respond and sorry,

    The whole code is here:

    http://code.google.com/p/coral-repo/...wPointNode.cpp

    The binding is made at line 188 in initShader().

    I just do the little modification I write I my first post and it didn't work...

    I think it's crazy as, in anyway, _*IndexAttr variable are suppose to be the index value of the their own attribute...

    Thanks in advance!
    Working on coral, a node based procedural workflow software.

  4. #4
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    949

    Re: BindAttribLoc work, GetAttribLoc doesn't

    Just make you program active before querying locations. Linking does not activate program.

  5. #5
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    33

    Re: BindAttribLoc work, GetAttribLoc doesn't

    Thanks a lot for answer!

    So I need to set:

    Code :
    glUseProgram(_shaderProgram);
    // querying locations
    glUseProgram(0);

    ...in initShader(). Ok!

    But my are locations will stay correct once in the draw()? When I call glUseProgram(_shaderProgram) function again?

    I'm supposed to query location at each frame? o_O

    Thanks in advance!

    EDIT: It seems you don't need to activate shaders to do query attributes: http://stackoverflow.com/questions/2...-vbo-in-opengl
    Working on coral, a node based procedural workflow software.

  6. #6
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    949

    Re: BindAttribLoc work, GetAttribLoc doesn't

    Quote Originally Posted by Narann
    But my are locations will stay correct once in the draw()? When I call glUseProgram(_shaderProgram) function again?
    I'm supposed to query location at each frame? o_O
    No! Unless you relink your program.

  7. #7
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    33

    Re: BindAttribLoc work, GetAttribLoc doesn't

    Ok, thanks!

    What I don't understand is that there is no place where it's written that you need to call glUseProgram before glGetAttribLocation. It's only write that this as to be done after glLinkProgram:

    http://www.opengl.org/registry/doc/g...e.20110808.pdf

    Can someone told me where I am suppose to know that?
    Working on coral, a node based procedural workflow software.

  8. #8
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    949

    Re: BindAttribLoc work, GetAttribLoc doesn't

    You are looking at the wrong document.
    GetAttribLocation is described in GL spec.

    Anyway, it seems that link also bind the program. So, it is not really necessary to cal UseProgram, at least on NV drivers (I've just tried successfully). But if you are reading attributes location just after linking, why don't you set them with BindAttribLocation?

  9. #9
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    33

    Re: BindAttribLoc work, GetAttribLoc doesn't

    Thanks!

    So I need to find the good spec file to look in.

    I have a ATI card, that's maybe why there is some differences about this, even on Internet.

    Yes, I could set them with BindAttribLocation but I wont to define indexes...

    I use attribute mat4 value (you know, the attribute that have +1, +2, +3 once you get it) and as I'm not very familiar with it, you can do mistake if you bind them:

    matrixAttr = 0
    anAttr = 1
    anotherAttr = 2

    This is invalid because as matrixAttr is a mat4 attr, you will have 0, 1, 2, 3. and anAttr and anotherAttr are 1 and 2 so they are in conflict with it...

    I won't to lost my time with this I try to do simpler as possible and I was thinking use GetAttribLocation was the simpler way as it's OpenGL that choose which index set to attributes.

    Anyway, if you have good reading about how deal simply with manually binded attributes I would very graceful if you send them to me.
    Working on coral, a node based procedural workflow software.

  10. #10
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    33

    Re: BindAttribLoc work, GetAttribLoc doesn't

    I just test to do:

    Code :
    glAttachShader(_shaderProgram, vertexShader);
     
    glLinkProgram(_shaderProgram);
     
    glUseProgram(_shaderProgram);
     
    _pointIndexAttr = glGetAttribLocation(_shaderProgram, "in_Position");
    _sizeIndexAttr = glGetAttribLocation(_shaderProgram, "in_Size");
    _colorIndexAttr = glGetAttribLocation(_shaderProgram, "in_Color");
    glUseProgram(0);

    And it doesn't work. And:


    Code :
    glUseProgram(_shaderProgram);
     
    _pointIndexAttr = glGetAttribLocation(_shaderProgram, "in_Position");
    _sizeIndexAttr = glGetAttribLocation(_shaderProgram, "in_Size");
    _colorIndexAttr = glGetAttribLocation(_shaderProgram, "in_Color");

    In the draw function doesn't work too... But just bind attribute work............
    Working on coral, a node based procedural workflow software.

Posting Permissions

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