r/opengl•
Stysner

EBO binding using DSA

EDIT:

Coming from non-DSA I still had an "unbind buffers" function at the end of each render iteration. It unbound the vertex buffer, element buffer and then the vertex array. Meaning it unbound the VBO/EBO from the VAO. Changing that function to only unbind the VAO instead fixed everything.

Original post below for posterity:

I'm using DSA to create VAO/VBO/EBO, and when drawing you don't have to bind the VBO because it's now tied to the VAO using glVertexArrayVertexBuffer, which works great.

I thought that when binding an EBO using glVertexArrayElementBuffer the same would go for the EBO. But if I try that I get a GL_INVALID_OPERATION error with the message "Some kind of element buffer must be bound."

Trying to bind an EBO (before drawing) with just one 0 in it (to try and see if "some kind" really means "some kind") fails as well. If I bind the actual EBO for the object it works fine.

Am I mistaken in thinking you can use DSA to forego binding the EBO at draw time like you can the VBO? I can't find anything on it...

Posted Jul 21, 2022, 11:54 AM UTC · edited

37

Does this help? Victor Gordan shows how to use DSA, helped me a ton! https://m.youtube.com/watch?v=cadzqhqPqVA

4
StysnerOP•

I've seen that video. At 2:24 there's a snippet of the drawing code; it only binds the VAO there. Which is what I'm doing, yet I'm getting the error.

To note I'm using glMultiDrawElementsIndirect instead of glDrawElements, but that shouldn't matter no?

1
null_8_15•

I can assure you that DSA is working for what you want, because at work we are using DSA wherever possible and also for VAOs and multidraw indirect combined.

I’m not exactly sure whats going on your side, but are u binding the EBO once? Maybe you have your VAO already bound and u need to unbind it first to be able to change the EBO?

1
StysnerOP•

Well, I've narrowed it down to 1 vertex format I have. I'm using generic functions that take in vertex formats to create the meshes/render objects and update the VBO/EBO for that format. So the order of creation etc is exactly the same for each different vertex format.

It was all working as intended before (non-DSA), and now it does work with DSA except for 1 format. When I query OpenGL for the bound vertex array it returns the correct handle for all except that one; it does indeed return 0, meaning it wasn't bound with the VAO like I expected.

When I in that case bind the EBO like you would in the non-DSA case, it works flawlessly.

So I guess I have some hours of stepping through my code to find some dank implementation detail ahead of me...

Thank you for your comment though. I wasn't wrong about the way DSA is supposed to work, that helps!

1
StysnerOP•

Maybe you have your VAO already bound and u need to unbind it first to be able to change the EBO?

And I'm trying that first. The offending vertex format is indeed the last one I make, and it probably is still bound when uploading the mesh data for the first time, I thought the currently bound buffer doesn't matter for DSA, but you're saying you can't have the VAO bound when updating the buffers attached to it?

1
StysnerOP•

I got it. Because my rendering code was still non-DSA, I had a "unbind buffers" function at the end of each render iteration that did the following:

Unbind the VBO,Unbind the EBO,Unbind the VAO.

With DSA that probably means I was actually unbinding the state from the VAO that was bound at that time. Weird that doesn't give a "no VBO bound" warning before a "no EBO bound" warning, but yeah... Another day, another self-inflicted bug! :D

1
null_8_15•

great you figured it out!

2