-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConstantBuffer.cpp
41 lines (27 loc) · 979 Bytes
/
ConstantBuffer.cpp
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
#include "ConstantBuffer.h"
#include "RenderSystem.h"
#include "DeviceContext.h"
#include <exception>
ConstantBuffer::ConstantBuffer(void* buffer, UINT size_buffer,RenderSystem* render_system) : m_render_system(render_system)
{
D3D11_BUFFER_DESC buff_desc = {};
buff_desc.Usage = D3D11_USAGE_DEFAULT;
buff_desc.ByteWidth = size_buffer;
buff_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
buff_desc.CPUAccessFlags = 0;
buff_desc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA init_data = {};
init_data.pSysMem = buffer;
if (FAILED(m_render_system->m_d3d_device->CreateBuffer(&buff_desc, &init_data, &m_buffer)))
{
throw std::exception("ConstantBuffer was not created successfully");
}
}
void ConstantBuffer::update(DeviceContextPtr context, void* buffer)
{
context->m_device_context->UpdateSubresource(this->m_buffer,NULL,NULL,buffer,NULL,NULL);
}
ConstantBuffer::~ConstantBuffer()
{
if (m_buffer)m_buffer->Release();
}