Jump to content

  • Log In with Google      Sign In   
  • Create Account


GLSL vertex attributes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Laval B   Crossbones+   -  Reputation: 4390

Like
0Likes
Like

Posted 16 June 2013 - 05:12 PM

Hello everyone.

 

My question is about vertex attributes. I'm targeting OpenGL 3.2 and above core profile with the corresponding version of GLSL. Is it ok to assign vertex attribute location using glBindAttribLocation before linking the program or is it preferable to just query them after linking. If i assign locations, some may not be contiguous e.g. position might be 0, normal 1 and texture coordiante 5, is that a problem ?


Edited by Laval B, 16 June 2013 - 05:20 PM.

We think in generalities, but we live in details.
 
Alfred North Whitehead

Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7467

Like
2Likes
Like

Posted 16 June 2013 - 05:48 PM

If you have GL_ARB_explicit_attrib_location available I'd advise using that.

 

If you can't, then it really doesn't matter which method you use, so pick the one that suits how you're going to structure your program the best.  Personally I'd run with your first option (a set of glBindAttribLocation calls) as it means you could make assumptions such as "position is always going into attrib 0, so I don't need to make a new glVertexAttribPointer call if nothing but the shader needs to change".  That may not suit your own code, and depending on how you have things structured elsewhere you may find it more convenient to query the locations.

 

Either way, it shouldn't matter if locations are not consecutive.  Attrib locations are really just a software/driver level abstraction, and some commercially released major titles use non-consecutive locations (e.g Doom 3 BFG Edition used 0/2/3/4/8/9).  I could imagine some lower quality GL implementations choking on non-consecutive locations though, so be sure to test it on those too.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 martyj2009   Members   -  Reputation: 114

Like
0Likes
Like

Posted 16 June 2013 - 08:36 PM

As far as your question of can you use them before you linking the shader, I believe the answer is no.

 

I don't think OpenGL doesn't know about attribute locations until you link them.



#4 MarekKnows.com   Members   -  Reputation: 438

Like
0Likes
Like

Posted 20 June 2013 - 08:28 AM

The details of when you can can can't call glBindAttribLocation are described in the OpenGL spec: http://www.opengl.org/registry/


---
Free C++, OpenGL, and Game Development Video Tutorials @
www.MarekKnows.com
Play my free games: Ghost Toast, Zing, Jewel Thief


#5 mhagain   Crossbones+   -  Reputation: 7467

Like
1Likes
Like

Posted 20 June 2013 - 03:58 PM

This can be slightly confusing, so I'm going to clarify some more.

 

If you're using glBindAttribLocation then you must make your glBindAttribLocation calls before linking.  In the old days (i.e. before GL_ARB_explicit_attrib_location) I liked to specify a struct describing the attribs, pass an array of those structs to my shader creation function, and loop through that array binding my locations before making my glLinkProgram call.  I expect that's probably the way most people do it.

 

In this case if you've already linked the program, you don't need to worry too much - you can just make your glBindAttribLocation calls and then call glLinkProgram again.  This is obviously not ideal - you really should just link once (for no reason other than it makes program startup faster) so view it as a "get out of jail" card that you can use pending a redesign rather than as a permanent working solution.

 

If you're using glGetAttribLocation you must make your glGetAttribLocation calls after linking.  The same struct trick I mention previously could be used here, but in general I never liked using this call as I always wanted the same attribs in the same locations across different program objects (so that I could change programs without having to issue a new set of glVertexAttribPointer calls, for example).

 

If you're using explicit attrib locations then in theory you don't need to do anything.  You specify an attrib location in your shader, you use that same location in your C/C++ code.  You may if you wish query the attrib locations using glGetAttribLocation (after linking) if you want to generalise things a little more, but this never really bothered me as I see a danger in trying to generalise too much.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS