cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

proguruman
Journeyman III

OpenGL ES2 SDK glDrawElements and glGetIntegerv Problems.

First, let me say that I have a working version of a game in opengl ES 1.1 on the iphone and

the android and I'm porting to OpenGL ES2 using the AMD SDK.

First, the simple problem... glGetIntegerv doesn't seem to provide correct query

values for GL_ARRAY_BUFFER_BINDING, GL_ELEMENT_ARRAY_BUFFER_BINDING,

and GL_ACTIVE_TEXTURE, For example, if I create an array buffer, upload appropriate vertex

data, execute the following

     glBindBuffer (GL_ARRAY_BUFFER, verticesHandle);

     GLint retrievedHandle; glGetIntegerv (GL_ARRAY_BUFFER_BINDING, &retrievedHandle);

and continue to draw it, everything works fine... If I log the above handles, then

verticesHandle will be some arbitrary value such as 6 that depends on when I created

it but retrievedHandle will always be 0. The same kind of thing happens for GL_ELEMENT_ARRAY_BUFFER_BINDING

and GL_ACTIVE_TEXTURE... Generally, I'm just not using glGetIntegerv since it's not required

but I was trying to use it for debugging.

The second problem is more fundamental... I've created a vertex buffer with less than 64k vertices

and a very large index buffer (more than 200k)...

I bind the vertex buffer handle, bind the index buffer handle, activate the appropriate vertex attributes

and execute


     glDrawElements (GL_TRIANGLE_STRIP, size, GL_UNSIGNED_SHORT, offset);


and follow it by a test for an OpenGL error. Everything is perfect as long as the offset is small.

A typical scenario which goes wrong (i.e., generates an GL_INVALID_OPERATION error) occurs

when size = 594 and offset = 139658. The driver is apparently concluding that there must be

an error because the offset is larger than one GL_UNSIGNED_SHORT. But this is a mistake

because the indexes that must be in the range of the unsigned short are the indices used

to index into the vertices; i.e. THE ELEMENTS must be unsigned shorts (NOT THE START

OF THE SET OF INDICES).


To repeat, there is nothing wrong in having 100k of GL_UNSIGNED_SHORT indices provided

they index into a vertex array with fewer than 65k vertices.

0 Likes
0 Replies