-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexturedVertexBuffer.cpp
More file actions
62 lines (52 loc) · 1.95 KB
/
TexturedVertexBuffer.cpp
File metadata and controls
62 lines (52 loc) · 1.95 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
56
57
58
59
60
61
62
#include "TexturedVertexBuffer.h"
#include "GraphicsEngine.h"
#include <iostream>
TexturedVertexBuffer::TexturedVertexBuffer() : VertexBuffer()
{
}
TexturedVertexBuffer::~TexturedVertexBuffer()
{
VertexBuffer::~VertexBuffer();
}
void TexturedVertexBuffer::load(void* vertexList, UINT vertexSize, UINT listSize, void* shaderByteCode, UINT byteShaderSize)
{
//release if previous buffer and input layout are used from previous frame update.
if (this->m_buffer!= NULL) {
this->m_buffer->Release();
}
if (this->m_input_layout != NULL) {
this->m_input_layout->Release();
}
D3D11_BUFFER_DESC bufferDesc = {};
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = vertexSize * listSize;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA initData = {};
initData.pSysMem = vertexList;
this->m_size_vertex = vertexSize;
this->m_size_list = listSize;
ID3D11Device* directXDevice = GraphicsEngine::get()->getDirect3DDevice();
HRESULT bufferResult = directXDevice->CreateBuffer(&bufferDesc, &initData, &this->m_buffer);
if (SUCCEEDED(bufferResult)) {
std::cout << "Creation of textured buffer succeeded. \n";
}
else {
std::cout << "An error occurred in creating a textured buffer. \n";
}
D3D11_INPUT_ELEMENT_DESC layout[] = {
//semantic name - index, format, input slot, aligned byte offset, input slot class, instance data step rate
//2 bytes each entry
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
UINT layoutSize = ARRAYSIZE(layout);
HRESULT layoutResult = directXDevice->CreateInputLayout(layout, layoutSize, shaderByteCode, byteShaderSize, &this->m_input_layout);
if (SUCCEEDED(layoutResult)) {
std::cout << "Creation of input layout succeeded. \n";
}
else {
std::cout << "An error occurred in creating an input layout. \n";
}
}