\\ Home : Articoli
Di RobyDx (del 22/04/2007 @ 15:30:19, in English, linkato 1929 volte)

Now let's talk about buffers. A buffer used for vertices it's called vertex buffer
At first we must define a structure for vertex that will contain position, color, texture coord and other. We will use the same structure of previous tutorial

struct VertexType
D3DXVECTOR3 position;
D3DXVECTOR4 color;

D3DXVECTOR are types defined in DirectX10: D3DXVECTOR3 contains 3 floats (xyz), while VECTOR4 has got 4 floats (xyzw). If you remember in the shader we defined the position as a float4 but now we have got only 3 floats. If you remember in first tutorial i explained you that vertices are used as omogeneus (then last value = 1). If we use a vector3 passing a float4 in the shader, directx automatically will set last value to 1.
A vertex requires a description using a struct called VertexLayout that will let us to specify what semantics will have each value.
ID3D10InputLayout* vertexLayout;


The description is contained in the ID3D10InputLayout interface. At first we describe vertex data. In this case we have got 2 informations: position and color. These information will be inserted with an array of D3D10_INPUT_ELEMENT_DESCThe Element_Desc struct has got this fields:

  • SemanticName: name to associe in the shader. That data in the shader will have got that name
  • SemanticIndex: An index for element. In this mode we can have POSITION1, POSITION2...
  • Format: format of element
  • InputSlot: It's possibile to use more slot in same time. Here we have to specify what.
  • AlignedByteOffset: The memory point from which directx will start read data (in bytes)
  • InputSlotClass: data type
  • InstanceDataStepRate: Information for instancing type. This will be explained later, VERY later!

In first case we set first 12 bytes of structure at POSITION variable, saying that it's first data of struct (the the offset is 0, and 12 becouse 3 * sizeof(float) = 12). The second case there will be COLOR, with R32G32B32A32_FLOAT format becouse it's formed by float4 and will have offset = 12 becouse we must read after the position. From shader now we will take its description to associe vertex to the shader.
D3D10_PASS_DESC PassDesc;
effect->GetTechniqueByIndex(0)->GetPassByIndex( 0 )->GetDesc( &PassDesc );

Now we can finally create InputLayout
HRESULT hr= device->CreateInputLayout( layout, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &vertexLayout );

Now vertexLayout has got all information for association. Now we can create VertexBuffer that will contain our vertices. We must remeber that our shader does not multiplicate position and matrices. It just give us position. Then we must use DirectX coordinates (then in the range -1,1)

ID3D10Buffer* vertexBuffer;

VertexType vertices[3];

bd.Usage = D3D10_USAGE_DEFAULT;
bd.ByteWidth = stride * vertexCount;
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
InitData.pSysMem = data;
HRESULT hr=device->CreateBuffer( &bd, &vertices, &vertexBuffer );

With these istructions we create a vertex buffer. Very important is ByteWidth in which we must set the size of our buffer (in our case the struct it's a vector3+vector4 (= 7 floats) * sizeof(float) = 28 bytes. 28 (sizeof 1 structure) * 3 (becouse we have created 3 vertices) = 84 bytes) that it's value to assing. Other parameter it's pSysMem that it's a pointer that contains buffer data (that in our case it's vertices array)
Now we are ready to use buffer.

device->IASetVertexBuffers( 0, 1, &vertexBuffer, &stride, &offset );

With there 4 istruction we set buffer into device. First istruction sets layout, second one what kind of polygon are we going to render (a triangle, for now), third one the buffer (slot position,how much buffers contains the buffer, on our case 1, and buffer with stride values into device)
Apply also the shader now it's all ready.

This will send to video the result to the screen. The Draw function takes in input number of vertices and from what vertex it must start to render.

Here is the demo. In next tutorial we will continue our lessons with shaders.


A special thanks goes to Vincent who translate this lesson.

Articolo Articolo  Storico Storico Stampa Stampa
I commenti sono disabilitati.
"La logica ti porterà dal punto A al punto B. L'immaginazione ti porterà ovunque"

Albert Einstein

Cerca per parola chiave

Articoli (4)
C++ (4)
Direct3D10 (30)
Direct3D11 (20)
DirectX9 (82)
DotNet (10)
English (9)
FanGames (22)
ManagedDX11 (2)
Materiale Utile (4)
News (39)
Shader Library (12)
SharpDX (1)
Software (25)
Tecnologia (19)
Varie (9)

Gli interventi più cliccati

Ultimi commenti:
If you wish to retai...
23/05/2013 @ 13:07:45
Di chanel outlet
You deficit of self-...
23/05/2013 @ 13:07:13
Di cartier watches uk
Reinforce your own l...
23/05/2013 @ 13:06:37
Di replica watches
Whenever you"re shiv...
23/05/2013 @ 13:06:11
Di swiss replica watches
It's likely you have...
23/05/2013 @ 13:05:02
Di chanel handbags
Cheap automobile ins...
23/05/2013 @ 13:04:28
Di replica watches

Con quale tecnologia state realizzando o avete intenzione di realizzare i vostri progetti?

 DirectX8 o Precedenti
 Motori grafici già pronti

Umorismo (17)

Le fotografie più cliccate

Ci sono 155 persone collegate
Sono state visualizzate  pagine

03/12/2021 @ 21:24:18
script eseguito in 40 ms