DirectX11 Creating a vertex cache

Source: Internet
Author: User
Create a vertex cache

What is the role of vertex caching.

Vertex caching is used to store all vertex data for a mesh model. When we create a vertex cache in Direct3D, we are the object that creates an optimal location for memory, such as the graphics hardware's memory, which is chosen by the device driver of the hardware. When Direct3D renders our object, it transforms the cache information through the graphics bus and performs the necessary actions through the rendering pipeline to ultimately determine whether the geometry is rendered on the screen. The "No" here is due to the fact that the geometry is eventually Direct3D to be invisible. Attempts to render large amounts of invisible geometry can cause performance degradation, and most advanced 3D commercial video games use a technique that determines whether the geometry is pre-visible and submits only those visible or potentially visible graphics to the graphics hardware. This is a high-level topic that belongs to the scene Management Section and handles multiple sub-themes such as cropping and partitioning algorithms.

How to create a vertex cache.

First we'll use an array to hold the vertex information. As an example:

Vertexpos vertices[] = 
{ 
XMFLOAT3 (0.5f, 0.5f, 0.5f), 
XMFLOAT3 (0.5f, -0.5f, 0.5f), 
XMFLOAT3 ( -0.5f,-0). 5f, 0.5f) 

Use the Createbuffer function of the device to create a vertex cache.
The first parameter is a device description object that describes the vertex cache.
The second parameter is the child resource data, the PSYSMEM member of the struct is a pointer to the memory that has been initialized, and in this case we are sending the memory populated by the cache, which is the vertex array above.
The third parameter holds the cached object pointer that was created.

How the vertex cache is described.

The cache description mainly uses the following members: usage, cache usage. Here we use D3d11_usage_default. Bindflags, bind identifier, here we use vertex cache binding identity: D3d11_bind_vertex_buffer bytewidth, Cache byte width, here can be used sizeof (vertices).

How child resource data is created.

Here, we can simply pass the psysmem of the D3d11_subresource_data structure object into the vertices vertex array.

Here is an example of creating a triangular vertex cache:

 Vertexpos vertices[] = {XMFLOAT3 (0.5f, 0.5f, 0.5f), XMFLOAT3 (0.5f,-0.5 

    F, 0.5f), XMFLOAT3 ( -0.5f, -0.5f, 0.5f)}; 

    D3d11_buffer_desc Vertexdesc; 

    ZeroMemory (&vertexdesc, sizeof (VERTEXDESC)); 

    Vertexdesc.usage = D3d11_usage_default; 

    Vertexdesc.bindflags = D3d11_bind_vertex_buffer; 

    Vertexdesc.bytewidth = sizeof (vertexpos) * 3; 

    D3d11_subresource_data Resourcedata; 

    ZeroMemory (&resourcedata, sizeof (Resourcedata)); 

    Resourcedata.psysmem = vertices; 

    id3d11buffer* VertexBuffer; 
HRESULT result = D3ddevice_->createbuffer (&vertexdesc, &resourcedata,&vertexbuffer); 

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.