-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndexBuffer.h
59 lines (46 loc) · 1.09 KB
/
IndexBuffer.h
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
#ifndef IndicesBuffer_h__
#define IndicesBuffer_h__
#include <d3d11.h>
#include <vector>
class IndexBuffer
{
private:
IndexBuffer(const IndexBuffer& rhs);
private:
ID3D11Buffer* _buffer;
UINT _bufferSize = 0;
public:
IndexBuffer() {}
ID3D11Buffer* Get()const
{
return _buffer;
}
ID3D11Buffer* const* GetAddressOf()const
{
return &_buffer;
}
UINT BufferSize()const
{
return _bufferSize;
}
HRESULT Initialize(ID3D11Device* dev, DWORD* data, UINT numIndices)
{
_bufferSize = numIndices;
D3D11_BUFFER_DESC indexBufferDesc;
ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc));
indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(DWORD) * numIndices;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA indexBufferData;
ZeroMemory(&indexBufferData, sizeof(indexBufferData));
indexBufferData.pSysMem = data;
HRESULT hr = dev->CreateBuffer(&indexBufferDesc, &indexBufferData, &_buffer);
return hr;
}
void Release()
{
_buffer->Release();
}
};
#endif // !IndicesBuffer_h__