-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConstantBuffer.cpp
43 lines (32 loc) · 943 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
42
43
#include "ConstantBuffer.h"
ConstantBuffer::ConstantBuffer(Renderer* renderer) : m_renderer(renderer)
{
}
bool ConstantBuffer::Load(void* buffer, unsigned size)
{
D3D11_BUFFER_DESC desc = {};
memset((&desc), 0, (sizeof(desc)));
desc.Usage = D3D11_USAGE_DEFAULT;
desc.ByteWidth = size;
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA data = {};
data.pSysMem = buffer;
auto hr = m_renderer->GetDevice()->CreateBuffer(&desc, &data, &m_buffer);
return hr >= 0x0L ? true : false;
}
void ConstantBuffer::Update(DeviceContext* deviceContext, void* buffer)
{
deviceContext->GetDeviceContext()->UpdateSubresource(m_buffer.Get(), NULL, NULL, buffer, NULL, NULL);
}
void ConstantBuffer::Release()
{
ConstantBuffer::~ConstantBuffer();
delete this;
}
ConstantBuffer::~ConstantBuffer() = default;
ID3D11Buffer* ConstantBuffer::GetBuffer()
{
return m_buffer.Get();
}