[MDX] Vertices SDK Tutorial-Related Question

Started by
8 comments, last by John H 18 years ago
Hey guys, I've just started going through the DirectX 9.0c (SDK Summer 2004) tutorials, and I've got them working without a hitch. Only problem is, there's a couple of things I don't fully understand and I was wondering if someone could give me a quick description. I'm on the second tutorial which deals primarily with vertex buffers. Here's the relevant code.

public void OnCreateVertexBuffer(object sender, EventArgs e)
{
	VertexBuffer vb = (VertexBuffer) sender;
	GraphicsStream stm = vb.Lock(0, 0, 0);
	CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
			
	verts[0].X = 150; verts[0].Y = 50; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Aqua.ToArgb();
	verts[1].X = 250; verts[1].Y = 250; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Brown.ToArgb();
	verts[2].X = 50; verts[2].Y = 250; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.LightPink.ToArgb();

	stm.Write(verts);

	vb.Unlock();
}

I understand what is happening in regards to the verts[] array being setup, but I'm not really understanding the use of vb.Lock() and vb.Unlock(). Is there a reason that vb.Lock() is called to initialise the GraphicsStream? The reason I ask is because after taking a look at the VertexBuffer class, it looks as though I could just call:

vb.SetData(verts, 0, LockFlags.None);

Would this accomplish the same thing? Thanks in advance.
Advertisement
What you said is typically how I see it done, it's how I do it, and it's the way Tom Miller says to do it in "Managed DirectX 9 Graphics and Game Programming Kickstart". I guess the Lock/Unlock method is just faster than SetData, because Mr. Miller does say that GraphicsStreams are faster. Hope any of that helped.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
think of it more like this

the vertex buffer must be locked to changed the data (unles you are funky with shaders) because it's gotta go back to the card after.

-programmer_tom
Cheers guys,

Thought I'd ask because the docs say that SetData locks first, then writes the vertices and then unlocks again. Speaking of which, u235, is that book you mentioned any good? Looks good from the reviews I've seen, but in your opinion? I might pick it up.

Thanks again! [smile]
I found it to be a very good start to the world of Managed DirectX. I wish it would have been a little more elaborate on things like HLSL and the more advanced topics, but for a beginner's book it's a great book. Everything is explained very clearly and it's very readable. Also, Mr. Miller goes into every namespace in the Managed DirectX SDK except for Security and Diagnostics, so that's a plus. I found it to be a good enough book that I'm going to keep it around and I definitely recommend it to anyone getting started with MDX. Not sure how much my opinion counts for, but there it is. Hope it helps.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Thanks a lot mate, and your opinion means a lot because you've had personal experiences with the book. Not only that, but you actually answered the questions I was going to ask, so thank you very much. The book should get here in the next 24 hours. [smile]
Well it's good to know my opinion helped you make your decision. I hope the book helps you as much as it did me, and make sure to report back on how you found the book to be. I'm curious to know what others think about it. Again, it's was my pleasure to give my opinion and thanks for letting me know it helped you reach your decision.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Hey, no problem, thanks for helping me decide in the first place! [wink] I'll definitely let you know how I get on. Can't wait to get started!
Oh and thanks for the rating++...at least, I think that was you.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Yeah, that was me, and likewise thanks for the same. [wink]

This topic is closed to new replies.

Advertisement