aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llvertexbuffer.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:50 -0500
committerJacek Antonelli2008-08-15 23:44:50 -0500
commit89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch)
treebcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/llrender/llvertexbuffer.h
parentSecond Life viewer sources 1.13.3.2 (diff)
downloadmeta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/llrender/llvertexbuffer.h')
-rw-r--r--linden/indra/llrender/llvertexbuffer.h179
1 files changed, 179 insertions, 0 deletions
diff --git a/linden/indra/llrender/llvertexbuffer.h b/linden/indra/llrender/llvertexbuffer.h
new file mode 100644
index 0000000..b221d35
--- /dev/null
+++ b/linden/indra/llrender/llvertexbuffer.h
@@ -0,0 +1,179 @@
1#ifndef LL_LLVERTEXBUFFER_H
2#define LL_LLVERTEXBUFFER_H
3
4#include "llgl.h"
5#include "v2math.h"
6#include "v3math.h"
7#include "v4math.h"
8#include "v4coloru.h"
9#include "llstrider.h"
10#include "llmemory.h"
11#include <set>
12#include <vector>
13
14//============================================================================
15// NOTES
16// Threading:
17// All constructors should take an 'create' paramater which should only be
18// 'true' when called from the main thread. Otherwise createGLBuffer() will
19// be called as soon as getVertexPointer(), etc is called (which MUST ONLY be
20// called from the main (i.e OpenGL) thread)
21
22//============================================================================
23// base class
24
25class LLVertexBuffer : public LLRefCount
26{
27public:
28 static void initClass(bool use_vbo);
29 static void cleanupClass();
30 static void startRender(); //between start and stop render, no client copies will occur
31 static void stopRender(); //any buffer not copied to GL will be rendered from client memory
32 static void clientCopy(F64 max_time = 0.005); //copy data from client to GL
33 static void unbind(); //unbind any bound vertex buffer
34
35 enum {
36 TYPE_VERTEX,
37 TYPE_NORMAL,
38 TYPE_TEXCOORD,
39 TYPE_TEXCOORD2,
40 TYPE_COLOR,
41 // These use VertexAttribPointer and should possibly be made generic
42 TYPE_BINORMAL,
43 TYPE_WEIGHT,
44 TYPE_CLOTHWEIGHT,
45 TYPE_MAX,
46 TYPE_INDEX,
47 };
48 enum {
49 MAP_VERTEX = (1<<TYPE_VERTEX),
50 MAP_NORMAL = (1<<TYPE_NORMAL),
51 MAP_TEXCOORD = (1<<TYPE_TEXCOORD),
52 MAP_TEXCOORD2 = (1<<TYPE_TEXCOORD2),
53 MAP_COLOR = (1<<TYPE_COLOR),
54 // These use VertexAttribPointer and should possibly be made generic
55 MAP_BINORMAL = (1<<TYPE_BINORMAL),
56 MAP_WEIGHT = (1<<TYPE_WEIGHT),
57 MAP_CLOTHWEIGHT = (1<<TYPE_CLOTHWEIGHT),
58 MAP_DRAW = 0x2000, // Buffer is in draw (read-only) mode
59 MAP_MAPPED = 0x4000, // Indicates that buffer has been mapped, but not to any type of data
60 MAP_UNMAPPED = 0x8000 // Indicates that buffer has been logically un-mapped
61 };
62
63protected:
64 virtual ~LLVertexBuffer(); // use unref()
65
66 virtual void setupVertexBuffer(U32 data_mask) const; // pure virtual, called from mapBuffer()
67
68 void createGLBuffer();
69 void createGLIndices();
70 void destroyGLBuffer();
71 void destroyGLIndices();
72 void updateNumVerts(S32 nverts);
73 void updateNumIndices(S32 nindices);
74 virtual BOOL useVBOs() const;
75 void unmapBuffer();
76
77public:
78 LLVertexBuffer(U32 typemask, S32 usage);
79
80 // map for data access
81 U8* mapBuffer(S32 access = -1);
82 // set for rendering
83 virtual void setBuffer(U32 data_mask); // calls setupVertexBuffer() if data_mask is not 0
84 // allocate buffer
85 void allocateBuffer(S32 nverts, S32 nindices, bool create);
86 virtual void resizeBuffer(S32 newnverts, S32 newnindices);
87 void makeStatic();
88
89 // Only call each getVertexPointer, etc, once before calling unmapBuffer()
90 // call unmapBuffer() after calls to getXXXStrider() before any cals to setBuffer()
91 // example:
92 // vb->getVertexBuffer(verts);
93 // vb->getNormalStrider(norms);
94 // setVertsNorms(verts, norms);
95 // vb->unmapBuffer();
96 bool getVertexStrider(LLStrider<LLVector3>& strider, S32 index=0);
97 bool getIndexStrider(LLStrider<U32>& strider, S32 index=0);
98 bool getTexCoordStrider(LLStrider<LLVector2>& strider, S32 index=0);
99 bool getTexCoord2Strider(LLStrider<LLVector2>& strider, S32 index=0);
100 bool getNormalStrider(LLStrider<LLVector3>& strider, S32 index=0);
101 bool getBinormalStrider(LLStrider<LLVector3>& strider, S32 index=0);
102 bool getColorStrider(LLStrider<LLColor4U>& strider, S32 index=0);
103 bool getWeightStrider(LLStrider<F32>& strider, S32 index=0);
104 bool getClothWeightStrider(LLStrider<LLVector4>& strider, S32 index=0);
105
106 BOOL isEmpty() const { return mEmpty; }
107 BOOL isLocked() const { return mLocked; }
108 S32 getNumVerts() const { return mNumVerts; }
109 S32 getNumIndices() const { return mNumIndices; }
110 U8* getIndicesPointer() const { return useVBOs() ? NULL : mMappedIndexData; }
111 U8* getVerticesPointer() const { return useVBOs() ? NULL : mMappedData; }
112 S32 getStride() const { return mStride; }
113 S32 getTypeMask() const { return mTypeMask; }
114 BOOL hasDataType(S32 type) const { return ((1 << type) & getTypeMask()) ? TRUE : FALSE; }
115 S32 getSize() const { return mNumVerts*mStride; }
116 S32 getIndicesSize() const { return mNumIndices * sizeof(U32); }
117 U8* getMappedData() const { return mMappedData; }
118 U8* getMappedIndices() const { return mMappedIndexData; }
119 S32 getOffset(S32 type) const { return mOffsets[type]; }
120 S32 getUsage() const { return mUsage; }
121
122 void setStride(S32 type, S32 new_stride);
123
124 void markDirty(U32 vert_index, U32 vert_count, U32 indices_index, U32 indices_count);
125 void markClean();
126
127protected:
128 S32 mNumVerts; // Number of vertices
129 S32 mNumIndices; // Number of indices
130 S32 mStride;
131 U32 mTypeMask;
132 S32 mUsage; // GL usage
133 U32 mGLBuffer; // GL VBO handle
134 U32 mGLIndices; // GL IBO handle
135 U8* mMappedData; // pointer to currently mapped data (NULL if unmapped)
136 U8* mMappedIndexData; // pointer to currently mapped indices (NULL if unmapped)
137 BOOL mLocked; // if TRUE, buffer is being or has been written to in client memory
138 BOOL mFinal; // if TRUE, buffer can not be mapped again
139 BOOL mFilthy; // if TRUE, entire buffer must be copied (used to prevent redundant dirty flags)
140 BOOL mEmpty; // if TRUE, client buffer is empty (or NULL). Old values have been discarded.
141 S32 mOffsets[TYPE_MAX];
142 BOOL mResized; // if TRUE, client buffer has been resized and GL buffer has not
143 BOOL mDynamicSize; // if TRUE, buffer has been resized at least once (and should be padded)
144
145 class DirtyRegion
146 {
147 public:
148 U32 mIndex;
149 U32 mCount;
150 U32 mIndicesIndex;
151 U32 mIndicesCount;
152
153 DirtyRegion(U32 vi, U32 vc, U32 ii, U32 ic)
154 : mIndex(vi), mCount(vc), mIndicesIndex(ii), mIndicesCount(ic)
155 { }
156 };
157
158 std::vector<DirtyRegion> mDirtyRegions; //vector of dirty regions to rebuild
159
160public:
161 static BOOL sRenderActive;
162 static S32 sCount;
163 static S32 sGLCount;
164 static std::vector<U32> sDeleteList;
165 typedef std::list<LLVertexBuffer*> buffer_list_t;
166 static buffer_list_t sLockedList;
167
168 static BOOL sEnableVBOs;
169 static S32 sTypeOffsets[TYPE_MAX];
170 static U32 sGLRenderBuffer;
171 static U32 sGLRenderIndices;
172 static BOOL sVBOActive;
173 static BOOL sIBOActive;
174 static U32 sLastMask;
175 static U32 sAllocatedBytes;
176};
177
178
179#endif // LL_LLVERTEXBUFFER_H