I'm trying to understand the relations between [glGenBuffers
, glBindData
, glBufferData
, glBufferSubData
] and glVertexAttribPointer
.
I saw that you don't really have to use the buffers method (at least not in Android) but rather call glVertexAttribPointer
directly, passing a pointer to the buffer object as the last parameter. (the buffers being a FloatBuffer
in this case)
e.g.
GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 12, vertexBuffer);
GLES20.glVertexAttribPointer(colorHandle, 4, GLES20.GL_FLOAT, false, 16, colorBuffer);
GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT, false, 12, normalsBuffer);
GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
1) Why would I want to use the buffer methods? Only if my data is happened to be stacked together in one array?
2) How do openGL handle these direct (non buffer) functions behind the scenes? I saw that it calls glVertexAttribPointerBounds
- does it actually stack it together to a single array of bytes?
3) If I do bind an array to the GL_ARRAY_BUFFER
- it means I have to use the stacked array version, and I won't be able to pass anymore direct objects, correct? i.e. I cannot do this:
int[] bufferVertices = new int[1];
GLES20.glGenBuffers(1, bufferVertices, 0);
vertexBufferId = bufferVertices[0];
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferId);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeCoords.length * 4 , vertexBuffer, GLES20.GL_STATIC_DRAW);
GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,0);
GLES20.glVertexAttribPointer(colorHandle, 4, GLES20.GL_FLOAT, false, 16, colorBuffer);
GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT, false,12, normalsBuffer);
GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false,8, textureBuffer);