-
Notifications
You must be signed in to change notification settings - Fork 1
/
VertexBuffer.h
80 lines (63 loc) · 2.32 KB
/
VertexBuffer.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
#pragma once
#include "stdafx.h"
#include "typeDefs3D.h"
#ifdef ENABLE_SDL
class VertexBuffer
{
public:
enum LockFlags
{
WRITEONLY,
NOOVERWRITE,
DISCARDCONTENTS = D3DLOCK_DISCARD
};
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_curVertexBuffer = nullptr; }
static void CreateVertexBuffer(const unsigned int vertexCount, const DWORD usage, const DWORD fvf, VertexBuffer **vBuffer);
GLuint getOffset() const { return offset; }
static void UploadBuffers();
private:
GLuint count;
GLuint size;
GLuint sizePerVertex;
DWORD fvf;
DWORD usage;
bool isUploaded;
bool sharedBuffer;
// CPU memory management
unsigned int offsetToLock;
unsigned int sizeToLock;
void *dataBuffer;
//GPU memory management
GLuint Buffer;
GLuint Array;
GLuint offset;//unused ATM, but if we want to group multiple IndexBuffers later in one buffer we might need it
static VertexBuffer* m_curVertexBuffer; // for caching
static std::vector<VertexBuffer*> notUploadedBuffers;
void UploadData();
void addToNotUploadedBuffers();
};
#else
class VertexBuffer : public IDirect3DVertexBuffer9
{
public:
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);
void release(void);
static void CreateVertexBuffer(const unsigned int vertexCount, const DWORD usage, const DWORD fvf, VertexBuffer **vBuffer);
static void setD3DDevice(IDirect3DDevice9* pD3DDevice);
private:
VertexBuffer(); // disable default constructor
static IDirect3DDevice9* m_pD3DDevice;
};
#endif