glEnableVertexAttribArray - when to call?

Hi,

Using ES 2.0 on Android (java)

I using multiple VBO’s and multiple shaders and using glDrawElements and it works fine…however, I have a question.

This is a piece of code from my draw()->


		GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexCoordsVBO[0]);
		GLES20.glVertexAttribPointer(mShader.mVertexCoordHandler, 3, GLES20.GL_FLOAT, false, 0, 0);
		GLES20.glEnableVertexAttribArray(mShader.mVertexCoordHandler);       


and this is a piece from my initial setup →


	private void copyVertexCoordsToGPU() {
		
		GLES20.glGenBuffers(1, mVertexCoordsVBO, 0);
		GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexCoordsVBO[0]);
		GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mDC.getVertices().capacity()*Float.SIZE/8, mDC.getVertices(), GLES20.GL_STATIC_DRAW);
	}

Now, reading about the “glVertexAttribPointer” in the spec, it says “Also, the buffer object binding (GL_ARRAY_BUFFER_BINDING) is saved as generic vertex attribute array client-side state (GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) for index index.”
spec http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttribPointer.xml

Does this mean that I should be able to do it this way instead?

In the draw() →


		GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexCoordsVBO[0]);
//		[i]GLES20.glVertexAttribPointer(mShader.mVertexCoordHandler, 3, GLES20.GL_FLOAT, false, 0, 0);[/i]
		GLES20.glEnableVertexAttribArray(mShader.mVertexCoordHandler);       


and in the init setup →


	private void copyVertexCoordsToGPU() {
		
		GLES20.glGenBuffers(1, mVertexCoordsVBO, 0);
		GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexCoordsVBO[0]);
		GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mDC.getVertices().capacity()*Float.SIZE/8, mDC.getVertices(), GLES20.GL_STATIC_DRAW);
		GLES20.glVertexAttribPointer(mShader.mVertexCoordHandler, 3, GLES20.GL_FLOAT, false, 0, 0);
	}

It doesn’t work for me though…and the question is if this should be possible or if I have missunderstood something.

Thanks
Peter

No you had it right the first time round.

Ok, thanks. I still don’t understand what the spec says…

Also, the buffer object binding (GL_ARRAY_BUFFER_BINDING) is saved as generic vertex attribute array client-side state (GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) for index index.

I know that the state of a bound buffer object is saved whenever I do any changes/updates to the specific target it is bound to (for example GL_ARRAY_BUFFER). But maybe that qoute has nothing to do with this…

It means that when you call glVertexAttribPointer, as well as storing “size”, “type”, “normalized”, “stride” and “pointer” for attribute “index”, the current value of GL_ARRAY_BUFFER is also grabbed + stored with it.

Ahhhhh…

Thanks, I see it now :slight_smile:

The vertex buffer object binding that is active when glVertexAttribPointer is called, is saved (somewhere in some vertexattrib internal secret memory?) as well as the parameters to it. Then when glDrawElements is called, it checks for enabled vertexattribarrays and uses the “saved” information to incorporate the buffer contents with each index.

Thanks all!
/P