I'm working on using a vertex and index buffer to draw some quads to the screen, but I'm running into some issues with some flickering. It seems that I'm not drawing all of the quads I need every frame.
For testing, my vertex and index buffer can only hold a max of 3 quads. Once 3 quads of data are in the buffer I call DISCARD to get a new buffer to use. Currently, I'm attempting to draw 4 quads, but for some reason I only draw 3 of the 4 quads for two frames. Meaning I draw all 4 quads, then only draw 3, draw 3 again, then draw all 4.
What is weird to me is that my first quad is the one that is at fault. It gets placed into the buffer, but it seems like it gets skipped when I do the draw call.
The only thing I can think of is that I am not using the StartIndexLocation and BaseVertexLocation parameters properly for the DrawIndexed call.
My Index Buffer is 16-bit and uses USHORTs. My draw call looks like:
//indexDrawCount (UINT): Number of indices used in the draw call
//indexOffset (UINT): Where to start in the index buffer
//drawnVertexCount (int): Where to start in the vertex buffer
batchContext->DrawIndexed(indexDrawCount, indexOffset, drawnVertexCount);
Here is my whole method: http://pastebin.com/XeMzX0WF
Could someone please shed some light on what is going on?
Present call 1 [ All quads draw; Buffer is fresh ]
[attachment=19097:frame1.png]
Present Call 2 [Only draws the last 3; Buffer had 1 Quad of data in it at start]
[attachment=19098:frame2.PNG]
Present Call 3 is the same as Call 2 [Only draws the last 3; Buffer had 2 Quads of data in it at start]
Present Call 4 is the same as Call 1 [Draws all 4 quads; Buffer had no data in it at start]
Render method in Main.cpp
void render()
{
systemX11.deviceContext->ClearRenderTargetView(systemX11.backBufferRenderTarget, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));
batcher->draw(0.0f, 0.0f, 32.0f, 32.0f);
batcher->draw(50.0f, 0.0f, 32.0f, 32.0f);
batcher->draw(100.0f, 0.0f, 32.0f, 32.0f);
batcher->draw(150.0f, 0.0f, 32.0f, 32.0f);
batcher->Batch();
systemX11.swapChain->Present(0,0);
}