Question

I happen to have multiple parts in drawing for each frame that could use the same shader/program but need different data passed to vertexShader as attributes. That data is stored in different buffers, though (one having GL_STATIC_DRAW, other GL_STREAM_DRAW). The static buffer is kinda large which is why I dont want to have it all streamed from the same buffer.

My question:

Is OpenGL ES 2.0 / WebGL capable of using different data for the same attribute/shader setup (read from gpu memory) ?

What have I tried ?

I have tried to get the attributeLocation for e.g. a_position_f4 multiple times (bindBuffer() used to change the buffer) and then setting vertexAttribPointer() each - but debugging showed that the attribute indicies are not dependant on the bound buffer and so changing bound buffers and en-/disabling the vertexAttributes won't lead to the desired behaviour.

Was it helpful?

Solution

I have tried to get the attributeLocation for e.g. a_position_f4 multiple times (bindBuffer() used to change the buffer) and then setting vertexAttribPointer() each - but debugging showed that the attribute indicies are not dependant on the bound buffer and so changing bound buffers and en-/disabling the vertexAttributes won't lead to the desired behaviour.

Youre conclusion is wrong. The attribute locations have nothing to do with the buffers you use. They are determined at shader link time and are not tied to buffer objects in any way. The vertex attrib pointer however will always reference the currently bound GL_ARRAY_BUFFER (at the time of the glVertexAttribPointer call). So you should just query the attribute locations once (per program object), and then can use

glBindBuffer(GL_ARRAY_BUFFER, bufID);
glVertexAttribPointer(attrib_loc, ...);

any time to specify the buffer bufID as the source for the attribute data for the attribute with index attrib_loc. (As you can see here, each attribute array may come from a different buffer, or sever or all can come from the same, that is up to you). The GL is a state machine, an this setup will stay until you change it again, so all draw calls following this statement will use that location for fetching that attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top