Jump to content
  • Advertisement
Sign in to follow this  
dpadam450

OpenGL glDrawElementsInstanced not drawing

This topic is 1511 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

I'm pretty sure that I have the code setup properly to do this. My graphics card supports openGL 4.0, but I'm still using a GL 2.0 context.

Can I still use the extension? My code compiles and glew seems to find the extension pointer. I assume because it doesn't crash that everything is good and I just have to debug this but I wanted to make sure.

Share this post


Link to post
Share on other sites
Advertisement

You need to check for the GL_ARB_draw_instanced extension, and if that exists, use glDrawElementsInstancedARB. Even if glDrawElementsInstanced exists and seems to work without problems, GL doesn't guarantee that the extension function pointer and the non-extension function pointer are the same. The only guarantee you have is that if an extension is available, then the functions defined by that extension are available.

Edited by Xycaleth

Share this post


Link to post
Share on other sites

I got it working now. I forgot with this mesh I was using is using non-indexed and needed to use glDrawArraysInstanced instead of glDrawElementsInstanced

 

 

My new problem is this. The second I add in all this per-instance attributes along with glDrawArraysInstanced, nothing show up. My shader works when I draw with glDrawArrays so the shader is perfectly fine. glDrawArraysInstanced is working, but just when I turn on the surrounding attribute code which is to pass an instance color down, nothing show. I don't know if its somehow over-writing other attributes or if I have messed up badly.

 

I can say that a don't use vertex attributes for the rest of the data. I use multi-texture coords for tangents and other per vertex data at the moment. Is this my problem that I'm using gl_Vertex and the built-in attributes along with my own custom ones? attribLoc seems to = 4 and be valid tho.

 

                    int attribLoc = glGetAttribLocation(NormalMap.handle_, "color");
                    glEnableVertexAttribArray(attribLoc);
                    glBindBuffer(GL_ARRAY_BUFFER, VBO_Index);
                    glVertexAttribPointer(attribLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (void*)(0));
                    glVertexAttribDivisor(attribLoc, 2);

                    glMatrixMode(GL_MODELVIEW);
                    glLoadIdentity();

                    glDrawArraysInstanced(GL_TRIANGLES, 0, meshToRender->num_faces*3, 2);
                
                
                    glDisableVertexAttribArray(attribLoc);

Edited by dpadam450

Share this post


Link to post
Share on other sites

You still need to use the ARB versions of the function if you only have a 2.0 context smile.png

 

I think the problem is you have the divisor set to 2? This means the colour attribute will change every 2 instances, so your 2 instances will have the same colour.  If you want it to be per-instance, you need to set the divisor to 1:

glVertexAttribDivisor(attribLoc, 1);

Share this post


Link to post
Share on other sites

That's correct, I tried using per instance and per 2 instances, but at the end of the day that attribute is a color to the shaders, nothing to do with position. So I should at least see something rendered. Like I do without using the per-instance attributes.

 

ARB didnt do anything, I don't use ARB in anything, I think glew strips that by default. Either way it worked just not with the attributes turned on, hopefully this doesn't turn into a long bug.

Edited by dpadam450

Share this post


Link to post
Share on other sites

Sorry, I completely misread your post. As far as I know, you can't mix the generic vertex attributes (glVertexAttribPointer) with the built-in attributes - how would the built-in attributes know which generic attribute to use? You should be using your own custom attributes in this case.

Share this post


Link to post
Share on other sites

I'll give that a try. Well it does return 4 as a valid index, and i have pos,normal,texcoord,tangent   so the next attribute would be 4.

I would think it still knows though because my shader compiles knowing what built-in and custom attributes to use an build an index map for them. I still call glVertexPointer, normal texcoord, which those might map to a default.

I get what you are saying though it probably is the issue, don't know what else it would be.

Share this post


Link to post
Share on other sites

So yes, you can use mixed attributes. My prior glVertex,glNormal,glTexCoord pointers all still work with adding another attribute I have create.

My issue was my new vbo to hold matrices was bad. I forgot to call glBufferData() before calling glBufferSubData(), so it was all garbage.

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!