Sign in to follow this  
tfm

mixing drawprimitives & Mesh

Recommended Posts

tfm    100
Hi, I just need a suggestion, I'm creating a Mathematical plotter & for rendering 2D graphs I use: DrawPrimitives(PrimitiveType.LineStrip, 0, this.vertices.Count - 1); but for 3D I use the Mesh structure. Is this approach correct ? Also as I need to switch between 2D & 3D I think I need to clear the device data structures & stuff because I don't see a correct 2D plot once I've made a 3D plot because I set stuff like IndexBuffer & VertexBuffer for 3D and then need to return back to plain DrawPrimitives. I guess you understand what I mean Btw I don't use TransformedVertices for 2D. I use CustomVertex.PositionOnly Thanks

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by tfm
DrawPrimitives(PrimitiveType.LineStrip, 0, this.vertices.Count - 1);

but for 3D I use the Mesh structure.

Is this approach correct ?
It's not the only way, but I don't see anything wrong with it. If it works for you then stick with it [smile]

Quote:
Original post by tfm
Also as I need to switch between 2D & 3D I think I need to clear the
device data structures & stuff because I don't see a correct 2D plot
once I've made a 3D plot because I set stuff like IndexBuffer &
VertexBuffer for 3D and then need to return back to plain
DrawPrimitives. I guess you understand what I mean
You need to be careful about managing pipeline configuration. Have a look at state blocks for some API-level help, but otherwise its down to you writing clean code that doesn't rely on any default behaviour nor make any assumptions about pipeline state.

Quote:
Original post by tfm
Btw I don't use TransformedVertices for 2D. I use CustomVertex.PositionOnly
Transformed and lit vertices are intended for 2D but you aren't forced to use them. In fact, using an orthogonal projection matrix and "pure" 3D geometry opens up a lot of options for doing 2D-in-3D...

hth
Jack

Share this post


Link to post
Share on other sites
jollyjeffers    1570
For 2D rendering I opt for projection-space geometry manipulated via a vertex shader.

Transformed vertices are ideal for static 2D geometry but can be a bit of a pain when you want to change them on a regular basis (as in, regular changes of large amounts of transformed vertices can get slow). Using projection-space coordinates allows for resolution independence (at the cost of making it hard to get pixel-precise accuracy) and access to the full hardware processing capabilities...

hth
Jack

Share this post


Link to post
Share on other sites
tfm    100
I don't think I'm using Transformed vertices's. I'm using CustomVertex.PositionOnly and I guess that is not Transformed vertices.

Share this post


Link to post
Share on other sites
tfm    100
ok another thing, the following is part of my render code so drawing a mesh and then a primitive inside the same render function is correct ? cause things aren't working properly.

for (int i = 0; i < numSubSets; ++i)
{
mesh.DrawSubset(i);
}
d3dManager.device.DrawPrimitives(PrimitiveType.LineList, 0, 3);

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
I'm using CustomVertex.PositionOnly and I guess that is not Transformed vertices
You are correct.

Quote:
for (int i = 0; i < numSubSets; ++i)
{
mesh.DrawSubset(i);
}
d3dManager.device.DrawPrimitives(PrimitiveType.LineList, 0, 3);
You're not setting things like the VB, IB, FVF (or shaders+decl)... In fact you're doing no pipeline (re-)configuration whatsoever. If it did work it would only be down to coincidence and luck [smile]

You need to configure your pipeline before the DrawPrimitives() call and after DrawSubset(). Exactly how you do this is for you to work out - you haven't given enough information in this thread.

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this