-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexBuffer.cpp
More file actions
55 lines (46 loc) · 1.9 KB
/
VertexBuffer.cpp
File metadata and controls
55 lines (46 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "VertexBuffer.h"
VertexBuffer::VertexBuffer(
void* list_vertices,
UINT size_vertex,
UINT size_list,
void* shader_byte_code,
size_t size_byte_shader,
RenderSystem* system
)
{
mRenderSystem = system;
D3D11_BUFFER_DESC buff_desc = {};
buff_desc.Usage = D3D11_USAGE_DEFAULT;
buff_desc.ByteWidth = size_vertex * size_list;
buff_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
buff_desc.CPUAccessFlags = 0;
buff_desc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA init_data = {};
init_data.pSysMem = list_vertices;
mSizeVertex = size_vertex;
mSizeList = size_list;
if (FAILED(mRenderSystem->mD3DDevice->CreateBuffer(&buff_desc, &init_data, &mBuffer)))
throw std::exception("VertexBuffer was not created.");
// Properties for each vertex
D3D11_INPUT_ELEMENT_DESC layout[] =
{
// Semantic name - semantic index - format - input slot - aligned byte offset - input slot class - instance data step rate
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
// The aligned byte offset is 12 for TEXCOORD because it's the sum of the previous attribute (32b -> 4B * 3)
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
if (FAILED(mRenderSystem->mD3DDevice->CreateInputLayout(layout, ARRAYSIZE(layout), shader_byte_code, size_byte_shader, &mLayout)))
throw std::exception("Input layout was not created.");
}
VertexBuffer::~VertexBuffer()
{
this->mLayout->Release();
this->mBuffer->Release();
}
UINT VertexBuffer::getSizeVertexList()
{
return this->mSizeList;
}