1

I want to draw many cubes and many lines.

I am dealing with many cubes, that is ok. But to do if I also want to draw another shapes(not triangles)?

Do I need to create 2 vertex and index buffers? One for cubes and one for lines? If yes then line vertex buffer is just like below?

Vertex vList[] =
{

{ 0.0f, 0.0f, 0.0f},
{ 1.0f, 0.0f, 0.0f}

}

And also, if yes, then in UpdatePipeline() I should check whether I want to draw a triangle or a line, and reset Input Assembler’s vertex buffer, index buffer and primitive topology?


What I generally want is to draw particles, connected by a line(but not all connected which each other). So I gonna to draw draw cubes(I don’t know how to draw sphere), I then draw lines.

Artur
  • 325
  • 2
  • 16
  • Seems, I really have to switch primitive topology https://stackoverflow.com/questions/21649766/simplest-way-to-draw-line-in-directx-11-c – Artur Apr 01 '20 at 08:43

1 Answers1

0

There are numerous ways to draw geometry in DirectX because the right solution depends on what you are trying to do. The main limitation is that everything you draw in a single call to Draw must use the same state/shaders--commonly called 'material'. For performance reasons, you want to be drawing thousands or tens of thousands of vertices in each Draw call.

You can use some tricks to combine different materials into a single Draw, but it's easier to think of each call as a single 'material'.

Given that there are three basic ways to draw geometry in DirectX:

  • Static submission In this case you copy your vertex/index data into a vertex/index buffer and reuse it many times. This is the most efficient way to render because the data can be placed in GPU only memory. You can use transformations, merged buffers, and other tricks to reuse the same vertex/index data. This is typically how objects are drawn in most scenes.

For an example, see the GeometricPrimitive and Modelclasses in DirectX Tool Kit.

Because of the data upload model of DirectX 12, you have to explicitly convert these from D3D12_HEAP_TYPE_UPLOAD to D3D12_HEAP_TYPE_DEFAULT via a LoadStaticBuffers method, but it achieves the same thing as DirectX 11's D3D11_USAGE_DEFAULT copying from a D3D11_USAGE_STAGING resource.

  • Dynamic submission builds up the vertex/index buffer every time it is used. This is not as efficient because the buffer itself has to reside in memory shared between the CPU & GPU, but it is a very useful way to handle cases where you are creating the geometry on the CPU every render frame. For DirectX 12 this is a D3D12_HEAP_UPLOAD resource. See DX11: How to: Use dynamic resources for using D3D11_USAGE_DYNAMIC in DirectX 11.

For an examples of this, see the SpriteBatch and PrimitiveBatch classes in DirectX Tool Kit

  • Generally the most efficient way to draw a bunch of the same shape (assuming you are using the same state/shader) is to use instancing. See the SimpleInstancing sample for DX11 and DX12.

If you are new to DirectX, you should strongly consider using DirectX 11 first instead of DirectX 12. In any case, see the DirectX Tool Kit for DX11 / DX12.

Community
  • 1
  • 1
Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • I wrote **different geometries**, **different shapes**. Instancing needs, if I understand correctly, when one want to draw many instance(even with transformation) of the same geometry. But I want to draw even different type of topology – Artur Mar 31 '20 at 08:44
  • Can You answer respectively to what did I ask for. Because I even wrote what I want to do in general. I don’t think my question is unclear or something like that. I just trying to understand things – Artur Mar 31 '20 at 08:47
  • What if to make vertex buffer empty at all, and send the entire data using constant buffer? – Artur Apr 01 '20 at 09:41
  • What matters is how much data you are sending to the video card. Constant Buffers are not special in any particular way... they are just designed to be fully updated every frame. – Chuck Walbourn Apr 01 '20 at 18:36
  • I have new related question https://stackoverflow.com/questions/60977148/using-vertex-buffer-instancing-how-to-dynamically-change-separate-instance-posi I will appreciate if You know how to help – Artur Apr 01 '20 at 18:50