• Advertisement
Sign in to follow this  

[.net] Vertex Buffer Creation in MDX 2.0

This topic is 4426 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 have spent a good portion of the day trying to render a vertex buffer in the new MDX 2.0. I recently upgraded my code and apon render I could not see anything. Something was going on because the FPS took a dive but no visual result. I eventually, after much reading found another way to create my vertex buffer and everything works fine now but I would like to know what was wrong with my initial vertex buffer creation that would cause no visual rendering. Here is the original code I used: vertexBuffer = new VertexBuffer(device, PositionColoredTextured.StrideSize * numVerts, Usage.WriteOnly, PositionColoredTextured.Format, Pool.Managed, null); Here is the new code I am currently using: vertexBuffer = VertexBuffer.CreateGeneric<PositionNormalTextured>(device, numVerts, Usage.WriteOnly, PositionNormalTextured.Format, Pool.Managed, null); I am just curious as to the difference since the first one seemed more natural with the recent changes in the DirectX.

Share this post


Link to post
Share on other sites
Advertisement
It would help if you post some more Code or the direct error you get, if any. Because there seems nothing wrong with that code. I use the same way to init my vb and it works just fine. How are you writing to the VB? There has been a big change with the formerly GraphicsStream now GraphicsBuffer, which you should give a lock on the vb and write to the GB if you want it on the VB. SetData has been deprecated.

So, please post some code and lets see if we cannot get it to work. And please post exactly which directx and vs you are using. There have been problems too.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It may not be anything to do with using the CreateGeneric method vs. newing a VB yourself. You're using two different vertex formats. In the first snippet you use PositionColoredTextured, and in the second you're using PositionNormalTextured. So the second snipped isn't even trying to do the same thing as the first.

Share this post


Link to post
Share on other sites
Ok in response to the anonymous poster, I am sorry for the confusion, when I recreated the line of code that wasn't working I did it incorrectly here in the forum. It should read:

Here is the original code I used:
vertexBuffer = new VertexBuffer(device, PositionNormalTextured.StrideSize * numVerts, Usage.WriteOnly, PositionNormalTextured.Format, Pool.Managed, null);

Here is the new code I am currently using:
vertexBuffer = VertexBuffer.CreateGeneric<PositionNormalTextured>(device, numVerts, Usage.WriteOnly, PositionNormalTextured.Format, Pool.Managed, null);

For further information I am using Visual Studio 2005 RTM with Managed DirectX December, using the new beta 2.0.0.0 reference.

As for the rest of my code, it is as follows (assume "data" is a filled array of vertex infromation)

GraphicsBuffer<PositionNormalTextured> vertBuffData = VertexBuffer.Lock<PositionNormalTextured>(0, 0, 0);
vertBuffData.Write(data);
vertexBuffer.Unlock();

As I said before, if I replace my first stated vertex buffer creation line with the second one it works perfectly. Also I am not alone in this problem, I know of one other person who experienced the same, after advising to use the CreateGeneric() method his problem was also solved. Also as indicated before I recieve no error or exception, the program runs as expected except there is no visual output.

PS. I realised when converting my code to MDX 2.0 that SetData() has been deprecated, does anyone know the reasoning behind its removal? it seemed somewhat convienient.

Share this post


Link to post
Share on other sites
There is just a discussion about SetData started in the newsgroup. Tom said he wanted to build a general approach because sometimes SetData was used sometimes lock/unlock was used. Internal SetData was just a wrapper for lock/unlock so it went away. I think it was the right decision, even if it looks somehow more complicated if known how its easy and straight forward in my opinion.

I have the same problem with Generic working and Constructor won't. I do not know why but I think it has something to do with a wrong implementation of the StrideSize. PositionColoredTextured.StrideSize * numVerts is the probable error. I do not know why, I do not see how to fix. Until the next release I will use CreateGeneric but I will post that error in the newsgroup to see if anyone knows why.

[Edited by - INsanityDesign on January 6, 2006 5:11:08 AM]

Share this post


Link to post
Share on other sites
I have the answer to my own problem, so I will post what I learned here for others to read:

The reason the create generic call worked and the normal constructor didn't is due to the fact that when you use create generic you have a strongly typed vertex buffer. When you call SetStreamSource when you are going to render, in the case of the strongly typed vertex buffer, it already knows the stride size. If you use the normal constructor method, it does *not* know the stride size so you must provide it as a fourth parameter (otherwsie it defaults to 0)

I tried this on my code and it fixed it, I will probably use the create generic method in the future though since my vertex buffer is strongly typed. Thanks goes to Tom Miller for providing me with these answers.

Share this post


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

  • Advertisement