| 1 |
|
| 2 |
// vbuffer.h [pengine] |
| 3 |
|
| 4 |
// Copyright 2004-2006 Jasmine Langridge, [email protected] |
| 5 |
// License: GPL version 2 (see included gpl.txt) |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#define BUFFER_OFFSET(i) ((char *)nullptr + (i)) |
| 10 |
|
| 11 |
|
| 12 |
class PVBuffer { |
| 13 |
public: |
| 14 |
enum contenttype { |
| 15 |
VertexContent, IndexContent |
| 16 |
}; |
| 17 |
enum usagemode { |
| 18 |
StreamUsage, StaticUsage, DynamicUsage |
| 19 |
}; |
| 20 |
|
| 21 |
protected: |
| 22 |
GLuint buffid; |
| 23 |
GLenum target; |
| 24 |
|
| 25 |
contenttype pr_type; |
| 26 |
|
| 27 |
// emulation: |
| 28 |
|
| 29 |
uint8 *buffer; |
| 30 |
//int buffersize; // not used anyway |
| 31 |
|
| 32 |
// in order to implement vbuffer emulation, need to add |
| 33 |
// DrawRangeElements type call to this class |
| 34 |
|
| 35 |
//static PVBuffer *bound, *boundelem; |
| 36 |
|
| 37 |
public: |
| 38 |
PVBuffer() { buffid = 0; buffer = nullptr; } |
| 39 |
~PVBuffer(); |
| 40 |
|
| 41 |
bool create(int buffsize, contenttype type, usagemode usage, const void *data = nullptr); |
| 42 |
void update(int offset, int buffsize, const void *data); |
| 43 |
void unload(); |
| 44 |
|
| 45 |
uint8 *getPointer(int offset); |
| 46 |
|
| 47 |
void bind(); |
| 48 |
|
| 49 |
static void unbind(); |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
class PRamFile { |
| 54 |
protected: |
| 55 |
std::vector<uint8> buffer; |
| 56 |
int cursor; |
| 57 |
|
| 58 |
public: |
| 59 |
PRamFile() { cursor = 0; } |
| 60 |
|
| 61 |
void write(const void *data, int datasize); |
| 62 |
|
| 63 |
void seek_cur(int pos) { seek_set(pos + cursor); } |
| 64 |
void seek_end(int pos) { seek_set(pos + buffer.size()); } |
| 65 |
void seek_set(int pos) { cursor = (pos >= 0) ? pos : 0; } |
| 66 |
int tell() { return cursor; } |
| 67 |
|
| 68 |
void clear() { buffer.clear(); cursor = 0; } |
| 69 |
|
| 70 |
void *getData() { return &buffer[0]; } |
| 71 |
int getSize() { return buffer.size(); } |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
|