Jump to content
  • Advertisement
Sign in to follow this  
devdept

Other 2 stupid questions

This topic is 4055 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 All again, 1) Why if I draw two separated lines this way: device.DrawPrimitives(PrimitiveType.LineList, 0, 1); device.DrawPrimitives(PrimitiveType.LineList, 1, 1); the result is 2 connected lines? 2) Is it possible to use mixed VertexFormats in the same scene? Or has it to be defined at the beginning and never changed? device.VertexFormat = CustomVertex.TransformedColored.Format; Thanks a lot, Alberto

Share this post


Link to post
Share on other sites
Advertisement
Hi,

1) The way you try to render the line forces them to be connected. The second parameter in DrawPrimitives is the index to the first vertex in the vertex list. You once hand over 0 and then 1. Handing over 0 means that vertex 0 and 1 are used to draw the line. Handing over 1 means that vertex 1 and 2 are used.

If you want to draw 2 line you either have to put them into one vertex buffer and draw 2 primitives (device.DrawPrimitives(PrimitiveType.LineList, 0, 2);) or you have to put all vertices into the list and adjust your indices (device.DrawPrimitives(PrimitiveType.LineList, 0, 1); device.DrawPrimitives(PrimitiveType.LineList, 2, 1);).


2) This depends how your scene is stored. If your scene is contained in one huge vertex buffer, then you may not switch the vertex format in the middle of that buffer.

If your scene is seperated into different buffers then you can use different vertex formats. There should be no problem.

Have fun,
Metron

Share this post


Link to post
Share on other sites
Just one little more question:

1) Is it soo silly to have a vertex buffer for each entity?!?

Like:

class Line {

VertexBuffer vertexBuffer;

public Line (...)
{
vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 2, dev, 0, CustomVertex.TransformedColored.Format, Pool.Default);
}

}

class Triangle {

VertexBuffer vertexBuffer;

public Triangle (...)
{
vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 3, dev, 0, CustomVertex.TransformedColored.Format, Pool.Default);
}

}


I found it so logical.

Thanks again,

Alberto

Share this post


Link to post
Share on other sites
It might be logical, but it's also incredibly inneficient. D3D is designed to send as many vertices to the card in one go, you're sending 2 or 3 at a time.

Using this method, you're likely to only get 10FPS drawing 500 triangles or so.

Share this post


Link to post
Share on other sites
I could split my engine in 4 different entity arrays (points, lines, triangle, and meshes), but what about selection and getting the right entity ID?

With a single master entity array is very simple.


Thanks, Alberto

Share this post


Link to post
Share on other sites
Hi again :)

Well... it might not be as easy as it sounds. Actually, while it is a bad idea to have "a lot of" vertex buffers that are uploaded to the GFX card, it's also a bad idea to not have enough.

Perhaps you should take a different view to what can be done:

- You might have data that can/will change almost every frame (ie. your FPS display, some animated particle system, etc). Those data should be held in dynamic vertex buffers. Those are buffers which are more or less optimized for regular changement and should only contain few data because they'll be uploaded to the card everytime the buffer has been changed.

- You'll certainly have data that never changes. I'm thinking of boxes, walls, stairways, etc. These object are most subject for what is called "batching". When you batch objects, you try to stick as many objects of the same kind (ie. all using the same textures and render settings) into one large buffer and you only touch this buffer when really needed (ie. when new objects come into the view (the player turns around)). Optimum would be to pre-transform them to avoid multiple drawprimitive calls with altered transformation matrices for each object in the buffer.

- The third category would be semi dynamic objects. I call semi dynamic objects for example skinned objects (like animals or humans). They're skinned which means that the vertex buffer is static and the vertices are transformed by indexed matrices (or quaternions when using vertex shaders). These ideally have one vertex buffer per mesh. The meshes are reusable for multiple rendering the same figure (using different transformation matrices and thus different positions in space).

The second and the third category of objects are subject for instancing.

If you have different primitives (such as lines, triangles, list, fans, etc) then you should set up a different buffer. At least for lines and triangle. Within the same primitive type it is possible to use the same buffer as long as the vertex information (the content of one vertex) is the same. I, for my part, would not do it (mix same primitive but differnet storage type (fan/list/span)) because it would be too error prone to memorize the index into the buffer, the number of vertices and the primitive type.

Think a little bit about what you actually need for your meshes and then select what you actually need ;)

Have fun,
Metron

Share this post


Link to post
Share on other sites
Metron,


You are so kind, now I really see the whole picture!

What is the best book to learn DirectX, released recently?


Thanks again!

Alberto

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!