Jump to content
  • Advertisement
Sign in to follow this  
ChaosIII

Of Batching Vertices and Drawing Primitves ... [solved]

This topic is 3964 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

Hi There. I am currently working on a 2D game and using textured quads to draw all my stuff. To be able to batch quads with the same texture together i am using a VertexBuffer in combination with an IndexBuffer. In theory I want to be able to do something like that in the end:
batchQuad(quadA);
batchQuad(quadB);
processBatch(Texture1);

batchQuad(quadC);
batchQuad(quadD);
processBatch(Texture2);
batchQuad() simply locks the VertexBuffer and IndexBuffer accordingly (taking into account the offset occupied by previously batched quads) and increases the batchCount. processBatch then simply sets the texture, calls DrawIndexedPrimitive() and finally sets the batchCount to 0 (Zero) thereby resetting the offset in the Buffers. However, apparently only the last call to processBatch seems to draw anything at all. In the above example that would mean that quads C & D will be drawn but A & B won't (since they have apparently been replaced by C & D in the buffer). If I do somthing like:
batchQuad(quadA);
batchQuad(quadB);
batchQuad(quadC);
batchQuad(quadD);
processBatch(Texture1);
All quads are drawn correctly, but they have, of course, all the same texture which is not the desired effect here. Could anyone explain this behaviour? Does anyone know what happens internally when I call DrawIndexedPrimitve()? Thanks! == EDIT == Amazing what a cup of coffee can do... It turned out i didn't unlock the IndexBuffer after filling it and unlocked the VertexBuffer (a second time) instead. Afterwards it suprised me that the application ran at all without any errors. Even more surprising that the the attempt to unlock a VertexBuffer that hasn't been locked before obviously doesn't return an error since I always checked the HRESULT return values of all calls... [Edited by - ChaosIII on February 3, 2008 4:36:46 PM]

Share this post


Link to post
Share on other sites
Advertisement
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!