-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstantBuffer.cpp
More file actions
30 lines (23 loc) · 869 Bytes
/
ConstantBuffer.cpp
File metadata and controls
30 lines (23 loc) · 869 Bytes
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
#include "ConstantBuffer.h"
ConstantBuffer::ConstantBuffer(void* buffer, UINT size_buffer, RenderSystem* system)
{
mRenderSystem = 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(mRenderSystem->mD3DDevice->CreateBuffer(&buff_desc, &init_data, &mBuffer)))
throw std::exception("ConstantBuffer was not created.");
}
ConstantBuffer::~ConstantBuffer()
{
if (mBuffer) mBuffer->Release();
}
void ConstantBuffer::update(const DeviceContextPtr& context, void* buffer)
{
context->mDeviceContext->UpdateSubresource(this->mBuffer, NULL, nullptr, buffer, NULL, NULL);
}