Direct3d10: Input Layout

Source: Internet
Author: User

A vertex has a position. more often than not, it also has other attributes as well, such as a normal, one or more colors, texture coordinates (used for texture mapping), and so on. vertex layout defines how these attributes lie in memory: what data type each attribute uses, what size each attribute has, and the order of the attributes in memory. because the attributes usually have different types, similar to the fields in a C structure, a vertex is usually represented by a structure. the size of the vertex is conveniently obtained from the size of the structure.

In this tutorial, we are only working with the position of the vertices. therefore, we define our vertex structure with a single field of the type d3dxvector3. this type is a vector of 3 Floating-points components, which is typically the Data Type Used for position in 3D.

    struct SimpleVertex    {        D3DXVECTOR3 Pos;  // Position    };

We now have a structure that represents our vertex. that takes care of storing vertex information in system memory in our application. however, when we feed the GPU the vertex buffer containing our vertices, we are just feeding it a chunk of memory. the GPU must also know about the vertex layout in order to extract correct attributes out from the buffer. to accomplish this requires the use of input layout.

In direct3d 10, an input layout is a direct3d object that describes the structure of vertices in a way that can be understood by the GPU. each vertex attribute can be described with the d3d10_input_element_desc structure. an application defines one or more d3d10_input_element_desc, then uses that array to create the input layout object which describes the vertex as a whole. we will now look at the fields of d3d10_input_element_desc in details.

Semanticname Semantic name is a string containing a word that describes the nature or purpose (or semantics) of this element. the word can be in any form that a C identifier can, and can be anything that we choose. for instance, a good semantic name for the vertex's position is position. semantic names are not case-sensitive.
Semanticindex Semantic index supplements semantic name. A vertex may have multiple attributes of the same nature. for example, it may have 2 sets of texture coordinates or 2 sets of colors. instead of using semantic names that have numbers appended, such as "color0" and "color1", the two elements can share a single semantic name, "color ", with different semantic indices 0 and 1.
Format Format defines the data type to be used for this element. for instance, a format of dxgi_format_r32g32b32_float has three 32-bit floating point numbers, making the element 12-byte long. A format of dxgi_format_r16g16b16a16_uint has four 16-bit unsigned integers, making the element 8-byte long.
Inputslot As mentioned previusly, A direct3d 10 application passes vertex data to GPU via the use of vertex buffer. in direct3d 10, multiple vertex buffers can be fed to the GPU simultaneously, 16 to be exact. each vertex buffer is bound to an input slot number ranging from 0 to 15. the inputslot field tells the GPU which vertex buffer it shocould fetch for this element.
Alignedbyteoffset A vertex in vertex buffer is simply a chunk of memory. The alignedbyteoffset field tells the GPU where in that chunk of memory it shold start fetching for this element.
Inputslotclass This field usually has the value d3d10_input_per_vertex_data. when an application uses instancing, it can set an input layout's inputslotclass to d3d10_input_per_instance_data to work with vertex buffer containing instance data. instancing is an advanced direct3d topic and will not be discussed here. for our tutorial, we will use d3d10_input_per_vertex_data exclusively.
Instancedatasteprate This field is used for instancing. Since we are not using instancing, this field is not used and must be set to 0.

Now we can define our d3d10_input_element_desc array and create the input layout:

    // Define the input layout    D3D10_INPUT_ELEMENT_DESC layout[] =    {        { L"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },      };   UINT numElements = sizeof(layout)/sizeof(layout[0]);

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.