I was wondering about this and I’m hoping you guys can help me out.
I hope I can explain this, so please bare with me.
I come from the world of DirectX 11 where you can use / setup Dynamic Vertex and Index Buffers.
Which have ‘lock flags’, these log flags basically tell the GPU how data is going to be treated. Well when you set up Dynamic Vertex Buffers and Index Buffers you use a DISCARD and NOOVERWRITE flag. The DISCARD flags says trash everything in the buffers, we don’t care about it. Where as the NOOVERWRITE flag says anything that is already in use, you can’t have.
Using these both you can create a circular buffer system. since the DISCARD flag does this special thing that creates a new place in mem for the GPU to use. Something like the below is a way to get a circular buffer:
//Code done when needing to draw, places the draw data directly into the vertex buffer
if(vertexBufferPosition + vertexdPerQuad > maxVertexAllowed)
{
//Says that we are done manipulating draw data
batchContext->Unmap(vertexBuffer, 0);
//Go ahead aand send everything of to the GPU and draw all that needs to be ddrawn
batchContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
batchContext->DrawIndexed(indexCount, 0, 0);
indexCount = 0;
//Reset our stuff and since we were out of space, give us another spot in mem to use (Setting the mapFlag to DISCARD)
vertexBufferPosition = 0;
mappingFlag = D3D11_MAP_WRITE_DISCARD;
//Relock the buffer so we can add more GPU data, also since we are using a fresh buffer, set the lockflag to NOOVERWRITE
batchContext->Map(vertexBuffer, 0, mappingFlag, 0, &mapVertexResouce);
mappingFlag = D3D11_MAP_WRITE_NO_OVERWRITE;
}
//Draw data placed directly into the vertex buffer
addDrawData(x,y,width,height);
SO my question, can this be done in openGL? Is there such things as lockflags and mapping?
I understand how to place data into a vertex buffer based on some tutorials, but that was for static buffers
How should I be placing data into a buffer when it needs to change every frame or so? For things such as a SpriteBatcher or Partical emitter? I should also mention I’m trying to target openGL 3.3 and up