Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Code to create the buffers and etc; Buffers can only hold 3 Quads of data before being "full" */
- //Map flag at start
- mappingFlag = D3D11_MAP_WRITE_NO_OVERWRITE;
- void SystemBatcher::endBatch()
- {
- //Lock the buffers for mapping
- batchContext->Map(vertexBuffer, 0, mappingFlag, 0, &mapVertexResource);
- batchContext->Map(indexBuffer, 0, mappingFlag, 0, &mapIndexResource);
- //For all the quads that need to be drawn place them in the buffer
- for(std::vector<Quad>::iterator i = drawData.begin(); i != drawData.end(); i++)
- {
- //If the buffer is full
- if(vertexBufferSize - drawDataAmount == 0)
- {
- //State the buffer is full
- std::cout<<"Vertex Buffer is full"<<std::endl;
- //Unlock the buffer
- batchContext->Unmap(indexBuffer, 0);
- batchContext->Unmap(vertexBuffer, 0);
- //Draw the quad data
- //indexDrawCount: number of indices to draw
- //indexOffset: The start location to use in the index buffer
- //drawnVertexCount: The start location to use in the Vertex Buffer
- batchContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- batchContext->DrawIndexed(indexDrawCount, indexOffset, drawnVertexCount);
- //Change the flag to discard since we are fill; Reset the buffer positions
- //Reset the other counts
- mappingFlag = D3D11_MAP_WRITE_DISCARD;
- vertexBufferPosition = 0;
- indexBufferPosition = 0;
- indexDrawCount = 0;
- drawDataAmount = 0;
- //Reset the start location
- drawnVertexCount = 0;
- indexOffset = 0;
- //Re lock the buffers with the DISCARD Flag; Change th flag back to NO OVERWRITE
- batchContext->Map(vertexBuffer, 0, mappingFlag, 0, &mapVertexResource);
- batchContext->Map(indexBuffer, 0, mappingFlag, 0, &mapIndexResource);
- mappingFlag = D3D11_MAP_WRITE_NO_OVERWRITE;
- }
- //Copy the vertex buffer data in from the Quad
- memcpy((Vertex*)mapVertexResource.pData + vertexBufferPosition, (*i).vertices, sizeof((*i).vertices));
- //Calculate the index positions based on the vertex buffer
- ((SHORT*)mapIndexResource.pData)[indexBufferPosition] = vertexBufferPosition;
- ((SHORT*)mapIndexResource.pData)[indexBufferPosition + 1] = vertexBufferPosition + 1;
- ((SHORT*)mapIndexResource.pData)[indexBufferPosition + 2] = vertexBufferPosition + 2;
- ((SHORT*)mapIndexResource.pData)[indexBufferPosition + 3] = vertexBufferPosition + 3;
- ((SHORT*)mapIndexResource.pData)[indexBufferPosition + 4] = vertexBufferPosition;
- ((SHORT*)mapIndexResource.pData)[indexBufferPosition + 5] = vertexBufferPosition + 2;
- //Add on to the buffer positions
- vertexBufferPosition += 4;
- indexBufferPosition += 6;
- //Add onto the drawDataAmount we have (Used when calculating if the buffer is full);
- //Add onto the index count used when drawning
- drawDataAmount += 4 * vertexSize;
- indexDrawCount += 6;
- }
- //Unlock the buffers
- batchContext->Unmap(indexBuffer, 0);
- batchContext->Unmap(vertexBuffer, 0);
- //Draw the quad data
- //indexDrawCount: number of indices to draw
- //indexOffset: The start location to use in the index buffer
- //drawnVertexCount: The start location to use in the Vertex Buffer
- batchContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- batchContext->DrawIndexed(indexDrawCount, indexOffset, drawnVertexCount);
- //Add onto the offsets used in the DrawIndexed calls
- drawnVertexCount += vertexBufferPosition;
- indexOffset += indexDrawCount;
- indexDrawCount = 0;
- //Clear out all of the drawData that was in the drawData vector
- drawData.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement