Jump to content
  • Advertisement
Sign in to follow this  
Gumgo

gl_VertexID and gl_InstanceID seem to be broken

This topic is 2220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In any shader, if I use gl_VertexID or gl_InstanceID anywhere, nothing is rendered at all. For example:

[font=courier new,courier,monospace]gl_Position = mvpMatrix * vec4( pos, 0.0f, 1.0f );[/font]

works perfectly. However, if I do something like the following:

[font=courier new,courier,monospace]vec2 verySmall = vec2( 1.0, 1.0 ) * float( gl_VertexID ) * 0.0000001;[/font]
[font=courier new,courier,monospace]gl_Position = mvpMatrix * vec4( pos + verySmall, 0.0f, 1.0f );[/font]
(I do this to ensure it's not optimized out)

then I get nothing drawn. No compiler errors or anything, the shader simply produces nothing. I'm using core profile, and GLSL 1.5 (#version 150). Has anyone experienced anything like this? Are there any things to check to ensure that I'm setting everything up properly to use gl_VertexID? Otherwise I'd have to suspect that it's driver issues. I've got an ATI Mobility Radeon HD 5870 with ATI's drivers (8.638.0.0).

In terms of updating drivers - I'll give it a try if that's all that's left. But in the past I've had serious issues with newer drivers and this card (lots of BSODs and random lockups). Apparently it's due to needing to update the VBIOS (I had some repair done on it and that may have already been done). Anyway, I'd rather look at other solutions before wandering into VBIOS territory.

Let me know if there's any more information I can provide. Edited by Gumgo

Share this post


Link to post
Share on other sites
Advertisement
Have you tried using gl_VertexID and gl_InstanceID to set the primitive's color instead of using it to calculate vertex positions? It would be much easier to debug unexpected colors instead of unexpected positions (which might easily fall outside the frustrum).

Share this post


Link to post
Share on other sites
I have seen threads like this on here before, but I can't remember the issue/solution.

How are you drawing your primitives? The spec does say that those built-in variables are only valid if:

  • the vertex comes from a vertex array command that speci?es a complete primitive (DrawArrays, MultiDrawArrays, DrawElements, MultiDrawElements, or DrawRangeElements)
  • all enabled vertex arrays have non-zero buffer object bindings, and
  • the vertex does not come from a display list, even if the display list was compiled using one of the vertex array commands described above with data sourced from buffer objects.

Share this post


Link to post
Share on other sites
Thanks for the replies.

BitMaster - I can give the color test a try just to be sure, but the test I'm using shouldn't affect the vertex positions enough to cause even a visible change. gl_VertexID is going to be small (no more than 32) and I'm multiplying it by 0.0000001 to ensure that the resulting difference in the vertex positions is tiny (but that gl_VertexID isn't optimized away).

Hodgman - to make the draw call I am using glDrawArrays(). I've bound a valid VBO to GL_ARRAY_BUFFER (is that what you meant by your second point?). And I'm not using display lists at all.

Oh yeah, and glGetError() returns 0 both before and after the call to glDrawArrays().

EDIT: Nothing from glIntercept either. Edited by Gumgo

Share this post


Link to post
Share on other sites
Have you checked the shader and program info log? Even if there are no errors, it might contain warnings or other diagnostic messages that might help pinpoint the issue.

Share this post


Link to post
Share on other sites
I've checked the log and there are no warnings either. Both the vertex and fragment shaders compile and link properly.

Share this post


Link to post
Share on other sites
Updated drivers (hoping to avoid crashes and BSODs) and the issue is gone. So I guess it was just a driver problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!