Fluxtah

I please bear with me as I am new to this kind of stuff.

I want to know the best practice for manipulating vertex data between draw calls, is it just a matter of changing my array of vertices and calling SetData() in the Update() method every frame

I am only doing this with a simple quad so I only have 4 vertices to change (or may change) each frame, any one care to help a newb

regards

Fluxtah



Re: XNA Framework Best way to manipulate vertex data between draw calls?

aclysma

I'm not sure what you're trying to do but it might be possible to achieve the results you want without modifying the vertex buffer. If you're wanting to do 2D by rendering to quads, you can use the world matrix transformation to scale/rotate/skew those vertices, and if you want to flip texture coordinates you could have a couple vertex buffers or one vertex buffer which you use different halves (or thirds, fourths, whatever) for what you want to do.

What I'm trying to say I guess is I'd try to figure out if you can do what you want just using matrix transforms and a small set of vertex buffers you have cached. I think the result would be faster and easier to program, especially if your particular problem lends itself well to this approach.

I am by no means a graphics guru. There've been a couple posts I've wanted to respond to and I've typed up a short draft and actually changed my mind because I'm not a graphics guru. So if I'm way off base, don't flame me - just trying to be helpful :)




Re: XNA Framework Best way to manipulate vertex data between draw calls?

Fluxtah

Well thanks for the response, I think I can probably just use transforms instead of changing the vertices each frame, however I was actually hoping the results would be faster than matrices.

I am actually using the quad to render a single character from a bitmap font onto it so the size of it has to change, in some sense I could render a 1x1 quad and scale it to the correct size, however I would still need to manipulate the texture coords since I am using one texture for the character set, or the other alternative is to use a quad for every character in my character set, this actually might be the sensible option.

Now there are already some rudimentary text drawing functionality made available by the community, but im not in it for the copy and paste factor, I want to learn how to do everything myself, I have time to waste :)

regards

Fluxtah





Re: XNA Framework Best way to manipulate vertex data between draw calls?

Fluxtah

aclysma wrote:
...and if you want to flip texture coordinates you could have a couple vertex buffers or one vertex buffer which you use different halves (or thirds, fourths, whatever) for what you want to do.

Just caught this on my second re-read, sorry I have to read things a few times before I get it! to clarify you are suggesting that I could use a single vertex buffer and just render parts of it to use different texture coordinates for each draw





Re: XNA Framework Best way to manipulate vertex data between draw calls?

aclysma

exactly. Lets say you want to draw bitmaps by rendering them as textured quads. And sometimes you want to flip them. You could have one vertex with 12 entries. The first 6 entries of the buffer could have appropriate coordinates for an unchanged blit-like functionality and the last 6 could be different texture coordinates that would render it flipped.

I don't know how appropriate it would be to make 6*number of characters entries sized vertex buffer. I think it'd be fast and I don't think it'd even be that hard on memory. But there's bound to be a less-envolved way to do it. If your text is in a single texture, maybe you could just use an overload from spritebatch.




Re: XNA Framework Best way to manipulate vertex data between draw calls?

Fluxtah

cool cheers, spritebatch was the first method I used successfully, however I am not very keen on spritebatch and also it does not put me through any pain to get something done, I would rather suffer the hard way in order to better my understanding.

I am actually only using 4*character entries as I will use an index buffer to piece the quads together.

Thanks for the help! I am going with your suggestion :)

Fluxtah