• Create Account

## D3D11 DrawIndexed confusion

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1noodleBowl  Members

Posted 07 December 2013 - 08:28 PM

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 ]

Present Call 2 [Only draws the last 3; Buffer had 1 Quad of data in it at start]

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);
}


Edited by noodleBowl, 08 December 2013 - 09:19 AM.

Just in case I forget to say it, I'm targeting OpenGL ES 2.0

### #2Jason Z  Members

Posted 08 December 2013 - 08:25 PM

What are the parameters to the draw indexed call?  Do they change from frame to frame?

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #3noodleBowl  Members

Posted 08 December 2013 - 09:33 PM

What are the parameters to the draw indexed call?  Do they change from frame to frame?

DrawIndexed(IndexCount, StartIndexLocation, BaseVertexLocation);

IndexCount: The number of indices to draw

StartIndexLocation: The location to start at in the index buffer; The index offset

BaseVertexLocation: I really don't understand this one, I thought this was the offset in relation to the vertex buffer but that causes the problem above

The IndexCount and StartIndexLocation change depending on the frame, because I only DISCARD when the buffer is full otherwise I have the buffers locked with NO OVERWRITE.

The base vertex location I think it should change, but since I do not really understand this one [Since of the above issue] I'm not sure if this should change every frame or etc

I am assuming it should be because at some point the StartIndexLocation does, and if the StartIndexLocation is the offset for the index buffer. Then BaseVertexLocation is the offset in relation to the vertex buffer

Edited by noodleBowl, 08 December 2013 - 10:55 PM.

Just in case I forget to say it, I'm targeting OpenGL ES 2.0

### #4Joyal  Members

Posted 03 January 2014 - 06:32 AM

You don't need to change the vertex buffer, you can use one quad , to draw all your quads , the only thing you need is update the matrix transformation to update their position

i had a issue not related with this but i posted some of my code, how i did the batch