Jump to content
  • Advertisement
Sign in to follow this  

D3D11 DrawIndexed confusion

This topic is 2113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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


Edited by noodleBowl

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!