This repository has been archived by the owner on Oct 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
IndexBuffer.h
111 lines (84 loc) · 3.74 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once
#include "stdafx.h"
#include "typedefs3D.h"
#ifdef ENABLE_SDL
class IndexBuffer final
{
public:
enum Format {
FMT_INDEX16 = 16,
FMT_INDEX32 = 32
};
enum LockFlags //!! not handled
{
WRITEONLY,
NOOVERWRITE,
DISCARDCONTENTS
};
void lock(const unsigned int offsetToLock, const unsigned int sizeToLock, void **dataBuffer, const DWORD flags);
void unlock();
void release();
void bind();
static void bindNull() { m_curIndexBuffer = nullptr; }
static void CreateIndexBuffer(const unsigned int numIndices, const DWORD usage, const IndexBuffer::Format format, IndexBuffer **idxBuffer, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const unsigned int * indices, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const WORD * indices, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const vector<unsigned int>& indices, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const vector<WORD>& indices, const deviceNumber dN);
static void UploadBuffers();
GLuint getOffset() const { return offset; }
Format getIndexFormat() const { return indexFormat; }
static IndexBuffer* m_curIndexBuffer; // for caching
private:
GLuint count;
GLuint size;
GLuint offset;
DWORD usage;
bool isUploaded;
bool sharedBuffer;
// CPU memory management
unsigned int offsetToLock;
unsigned int sizeToLock;
void *dataBuffer = nullptr;
//GPU memory management
GLuint Buffer = 0;
Format indexFormat;
static vector<IndexBuffer*> notUploadedBuffers;
void UploadData(bool freeData);
void addToNotUploadedBuffers(const void* indices = nullptr);
};
#else
class IndexBuffer final
{
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
DISCARDCONTENTS = 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 release();
void bind();
static void bindNull() { m_curIndexBuffer = nullptr; }
static void setD3DDevice(IDirect3DDevice9* primary, IDirect3DDevice9* secondary) { m_pd3dPrimaryDevice = primary; m_pd3dSecondaryDevice = secondary; }
static void CreateIndexBuffer(const unsigned int numIndices, const DWORD usage, const IndexBuffer::Format format, IndexBuffer** idxBuffer, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const unsigned int* indices, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const unsigned int numIndices, const WORD* indices, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const vector<unsigned int>& indices, const deviceNumber dN);
static IndexBuffer* CreateAndFillIndexBuffer(const vector<WORD>& indices, const deviceNumber dN);
static IndexBuffer* m_curIndexBuffer; // for caching
IDirect3DIndexBuffer9* m_ib = nullptr;
private:
//IndexBuffer(); // disable default constructor
deviceNumber m_dN;
static IDirect3DDevice9* m_pd3dPrimaryDevice;
static IDirect3DDevice9* m_pd3dSecondaryDevice;
};
#endif