-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIndexBuffer.h
90 lines (72 loc) · 3.13 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include "stdafx.h"
#include "typeDefs3D.h"
#ifdef ENABLE_SDL
class IndexBuffer
{
public:
enum Format {
FMT_INDEX16 = 16,
FMT_INDEX32 = 32
};
void lock(const unsigned int offsetToLock, const unsigned int sizeToLock, void **dataBuffer, const DWORD flags);
void unlock(void);
void release(void);
void bind();
static void bindNull() { m_curIndexBuffer = nullptr; }
static void CreateIndexBuffer(const unsigned int numIndices, const DWORD usage, const IndexBuffer::Format format, IndexBuffer **idxBuffer);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const unsigned int * indices);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const WORD * indices);
static IndexBuffer* CreateAndFillIndexBuffer(const std::vector<unsigned int>& indices);
static IndexBuffer* CreateAndFillIndexBuffer(const std::vector<WORD>& indices);
GLuint getOffset() const { return offset; }
Format getIndexFormat() const { return indexFormat; }
static void UploadBuffers();
private:
GLuint count;
GLuint size;
GLuint offset;
DWORD usage;
bool isUploaded;
bool sharedBuffer;
// CPU memory management
unsigned int offsetToLock;
unsigned int sizeToLock;
void *dataBuffer;
//GPU memory management
GLuint Buffer;
Format indexFormat;
static IndexBuffer* m_curIndexBuffer; // for caching
static std::vector<IndexBuffer*> notUploadedBuffers;
void UploadData(bool freeData);
void addToNotUploadedBuffers(const void* indices = nullptr);
};
#else
class IndexBuffer : public IDirect3DIndexBuffer9
{
public:
enum Format {
FMT_INDEX16 = D3DFMT_INDEX16,
FMT_INDEX32 = D3DFMT_INDEX32
};
enum LockFlags
{
WRITEONLY = 0, // in DX9, this is specified during VB creation
NOOVERWRITE = D3DLOCK_NOOVERWRITE, // meaning: no recently drawn vertices are overwritten. only works with dynamic VBs.
// it's only needed for VBs which are locked several times per frame
DISCARD = D3DLOCK_DISCARD // discard previous contents; only works with dynamic VBs
};
void lock(const unsigned int offsetToLock, const unsigned int sizeToLock, void **dataBuffer, const DWORD flags);
void unlock(void);
void release(void);
static void CreateIndexBuffer(const unsigned int numIndices, const DWORD usage, const IndexBuffer::Format format, IndexBuffer **idxBuffer);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const unsigned int * indices);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const WORD * indices);
static IndexBuffer* CreateAndFillIndexBuffer(const std::vector<unsigned int>& indices);
static IndexBuffer* CreateAndFillIndexBuffer(const std::vector<WORD>& indices);
static void setD3DDevice(IDirect3DDevice9* pD3DDevice);
private:
IndexBuffer(); // disable default constructor
static IDirect3DDevice9* m_pD3DDevice;
};
#endif