glDrawElements generates invalid operation

Started by
5 comments, last by george_azure 13 years, 1 month ago
Hi guys,

I'm having some troubles with integrating speedtree 5.2 because every glDrawElements call generates GL_INVALID_OPERATION and does not render anything even though the vertex and index buffers are constructed properly(that's why everybody is using speedtree).
Can you guys give me a practical example when and how glDrawElements might generate this error?I looked into specifications but dind't understand it completely.
Your answer can help me a lot finding the source of this problem.
Why should we play games with poor gameplay, weak AI but good graphics when we have REALITY?
Advertisement
The specification lists all cases that sets an error flag, but I suggest a more specific source like the man pages instead.
I've looked in all specifications but didn't quite understand what "GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to an enabled array" means.(That's why I've posted here)
What exactly is an enabled array?The array that is stored in video memory or in the regular memory?
Why should we play games with poor gameplay, weak AI but good graphics when we have REALITY?
Post some code dude. ;) Check what arrays have you enabled via glEnableClientState( ) and their state match your gl*****Pointer( ) usage before glDrawElement( ). Also, the sate of arrays via glEnableClientState( ) should strictly reflect the data you made avaialble to the VBO upon construction - that is via glBufferData( ).

Also, GL_INVALID_OPERATION could have been tripped by something else, way before before glDrawElement( ). Check that too.
Latest project: Sideways Racing on the iPad
If I could post some code I would have done it, but speedtree is pretty complex and does everything properly.I even checked the buffer creation and rendering a thousand times myself.
I am using glintercept and it detects the invalid operation error exactly at gldrawelements.
The problem can be some conflicts in the main engine but I'm not sure where. That's why I am asking some examples when this function can generate this error.Also I put some questions above(What is an enabled array?).It will be really helpful is someone could answer to them.
Why should we play games with poor gameplay, weak AI but good graphics when we have REALITY?
Also I put some questions above(What is an enabled array?).It will be really helpful is someone could answer to them. [/quote]

"Array" could imply one of the following: Vertex array, normal array, colour array, texture coordinate array(s) and any other arrays typically used with buffer objects.

An "enabled array" implies that a particular aforementioned array was enabled to use for draw calls. For example, to enable an array, you use glEnableClientState( ) with either GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_TEXTURE_COORD_ARRAY, ... and so on.

Therefore, if you invoke glEnableClientState(GL_VERTEX_ARRAY), you are instructing all subsequent glDrawElement( ) calls to look for a vertex array, as specified by glVertexPointer( ).


Anyway, if GL_INVALID_OPERATION is indeed triggered by glDrawElement( ) , a possible scenario is that glMapBuffer( ) is still bound to the particular buffer object you want to render.

"A mapped data store must be unmapped with glUnmapBuffer before its buffer object is used. Otherwise an error will be generated by any GL command that attempts to dereference the buffer object's data store."
Latest project: Sideways Racing on the iPad
Thanks for the explanation!

I've verified, and the buffer's data is not currently mapped nor the call is between glBegin and glEnd.So the problem should be that "a non-zero buffer object name is bound to an enabled array or the element array"(how they say).But should a non zero buffer object be bound first before gldrawelements call?(I hope I've understood this statement).
I usually do:
glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_iVb );//vertex buffer
glVertexPointer( 3, GL_FLOAT, 0, m_pVertices );
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, g_iIb);//index buffer
glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_SHORT,0);
Why should we play games with poor gameplay, weak AI but good graphics when we have REALITY?

This topic is closed to new replies.

Advertisement