diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llrender/llvertexbuffer.h | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llrender/llvertexbuffer.h | 67 |
1 files changed, 56 insertions, 11 deletions
diff --git a/linden/indra/llrender/llvertexbuffer.h b/linden/indra/llrender/llvertexbuffer.h index 43a32c9..3031b2d 100644 --- a/linden/indra/llrender/llvertexbuffer.h +++ b/linden/indra/llrender/llvertexbuffer.h | |||
@@ -50,12 +50,38 @@ | |||
50 | // be called as soon as getVertexPointer(), etc is called (which MUST ONLY be | 50 | // be called as soon as getVertexPointer(), etc is called (which MUST ONLY be |
51 | // called from the main (i.e OpenGL) thread) | 51 | // called from the main (i.e OpenGL) thread) |
52 | 52 | ||
53 | |||
54 | //============================================================================ | ||
55 | // gl name pools for dynamic and streaming buffers | ||
56 | |||
57 | class LLVBOPool : public LLGLNamePool | ||
58 | { | ||
59 | protected: | ||
60 | virtual GLuint allocateName() | ||
61 | { | ||
62 | GLuint name; | ||
63 | glGenBuffersARB(1, &name); | ||
64 | return name; | ||
65 | } | ||
66 | |||
67 | virtual void releaseName(GLuint name) | ||
68 | { | ||
69 | glDeleteBuffersARB(1, &name); | ||
70 | } | ||
71 | }; | ||
72 | |||
73 | |||
53 | //============================================================================ | 74 | //============================================================================ |
54 | // base class | 75 | // base class |
55 | 76 | ||
56 | class LLVertexBuffer : public LLRefCount | 77 | class LLVertexBuffer : public LLRefCount |
57 | { | 78 | { |
58 | public: | 79 | public: |
80 | static LLVBOPool sStreamVBOPool; | ||
81 | static LLVBOPool sDynamicVBOPool; | ||
82 | static LLVBOPool sStreamIBOPool; | ||
83 | static LLVBOPool sDynamicIBOPool; | ||
84 | |||
59 | static void initClass(bool use_vbo); | 85 | static void initClass(bool use_vbo); |
60 | static void cleanupClass(); | 86 | static void cleanupClass(); |
61 | static void startRender(); //between start and stop render, no client copies will occur | 87 | static void startRender(); //between start and stop render, no client copies will occur |
@@ -63,6 +89,12 @@ public: | |||
63 | static void clientCopy(F64 max_time = 0.005); //copy data from client to GL | 89 | static void clientCopy(F64 max_time = 0.005); //copy data from client to GL |
64 | static void unbind(); //unbind any bound vertex buffer | 90 | static void unbind(); //unbind any bound vertex buffer |
65 | 91 | ||
92 | //get the size of a vertex with the given typemask | ||
93 | //if offsets is not NULL, its contents will be filled | ||
94 | //with the offset of each vertex component in the buffer, | ||
95 | // indexed by the following enum | ||
96 | static S32 calcStride(const U32& typemask, S32* offsets = NULL); | ||
97 | |||
66 | enum { | 98 | enum { |
67 | TYPE_VERTEX, | 99 | TYPE_VERTEX, |
68 | TYPE_NORMAL, | 100 | TYPE_NORMAL, |
@@ -92,10 +124,16 @@ public: | |||
92 | }; | 124 | }; |
93 | 125 | ||
94 | protected: | 126 | protected: |
127 | friend class LLGLImmediate; | ||
128 | |||
95 | virtual ~LLVertexBuffer(); // use unref() | 129 | virtual ~LLVertexBuffer(); // use unref() |
96 | 130 | ||
97 | virtual void setupVertexBuffer(U32 data_mask) const; // pure virtual, called from mapBuffer() | 131 | virtual void setupVertexBuffer(U32 data_mask) const; // pure virtual, called from mapBuffer() |
98 | 132 | ||
133 | void genBuffer(); | ||
134 | void genIndices(); | ||
135 | void releaseBuffer(); | ||
136 | void releaseIndices(); | ||
99 | void createGLBuffer(); | 137 | void createGLBuffer(); |
100 | void createGLIndices(); | 138 | void createGLIndices(); |
101 | void destroyGLBuffer(); | 139 | void destroyGLBuffer(); |
@@ -104,7 +142,7 @@ protected: | |||
104 | void updateNumIndices(S32 nindices); | 142 | void updateNumIndices(S32 nindices); |
105 | virtual BOOL useVBOs() const; | 143 | virtual BOOL useVBOs() const; |
106 | void unmapBuffer(); | 144 | void unmapBuffer(); |
107 | 145 | ||
108 | public: | 146 | public: |
109 | LLVertexBuffer(U32 typemask, S32 usage); | 147 | LLVertexBuffer(U32 typemask, S32 usage); |
110 | 148 | ||
@@ -115,8 +153,7 @@ public: | |||
115 | // allocate buffer | 153 | // allocate buffer |
116 | void allocateBuffer(S32 nverts, S32 nindices, bool create); | 154 | void allocateBuffer(S32 nverts, S32 nindices, bool create); |
117 | virtual void resizeBuffer(S32 newnverts, S32 newnindices); | 155 | virtual void resizeBuffer(S32 newnverts, S32 newnindices); |
118 | void makeStatic(); | 156 | |
119 | |||
120 | // Only call each getVertexPointer, etc, once before calling unmapBuffer() | 157 | // Only call each getVertexPointer, etc, once before calling unmapBuffer() |
121 | // call unmapBuffer() after calls to getXXXStrider() before any cals to setBuffer() | 158 | // call unmapBuffer() after calls to getXXXStrider() before any cals to setBuffer() |
122 | // example: | 159 | // example: |
@@ -125,7 +162,7 @@ public: | |||
125 | // setVertsNorms(verts, norms); | 162 | // setVertsNorms(verts, norms); |
126 | // vb->unmapBuffer(); | 163 | // vb->unmapBuffer(); |
127 | bool getVertexStrider(LLStrider<LLVector3>& strider, S32 index=0); | 164 | bool getVertexStrider(LLStrider<LLVector3>& strider, S32 index=0); |
128 | bool getIndexStrider(LLStrider<U32>& strider, S32 index=0); | 165 | bool getIndexStrider(LLStrider<U16>& strider, S32 index=0); |
129 | bool getTexCoordStrider(LLStrider<LLVector2>& strider, S32 index=0); | 166 | bool getTexCoordStrider(LLStrider<LLVector2>& strider, S32 index=0); |
130 | bool getTexCoord2Strider(LLStrider<LLVector2>& strider, S32 index=0); | 167 | bool getTexCoord2Strider(LLStrider<LLVector2>& strider, S32 index=0); |
131 | bool getNormalStrider(LLStrider<LLVector3>& strider, S32 index=0); | 168 | bool getNormalStrider(LLStrider<LLVector3>& strider, S32 index=0); |
@@ -138,13 +175,16 @@ public: | |||
138 | BOOL isLocked() const { return mLocked; } | 175 | BOOL isLocked() const { return mLocked; } |
139 | S32 getNumVerts() const { return mNumVerts; } | 176 | S32 getNumVerts() const { return mNumVerts; } |
140 | S32 getNumIndices() const { return mNumIndices; } | 177 | S32 getNumIndices() const { return mNumIndices; } |
178 | S32 getRequestedVerts() const { return mRequestedNumVerts; } | ||
179 | S32 getRequestedIndices() const { return mRequestedNumIndices; } | ||
180 | |||
141 | U8* getIndicesPointer() const { return useVBOs() ? NULL : mMappedIndexData; } | 181 | U8* getIndicesPointer() const { return useVBOs() ? NULL : mMappedIndexData; } |
142 | U8* getVerticesPointer() const { return useVBOs() ? NULL : mMappedData; } | 182 | U8* getVerticesPointer() const { return useVBOs() ? NULL : mMappedData; } |
143 | S32 getStride() const { return mStride; } | 183 | S32 getStride() const { return mStride; } |
144 | S32 getTypeMask() const { return mTypeMask; } | 184 | S32 getTypeMask() const { return mTypeMask; } |
145 | BOOL hasDataType(S32 type) const { return ((1 << type) & getTypeMask()) ? TRUE : FALSE; } | 185 | BOOL hasDataType(S32 type) const { return ((1 << type) & getTypeMask()) ? TRUE : FALSE; } |
146 | S32 getSize() const { return mNumVerts*mStride; } | 186 | S32 getSize() const { return mNumVerts*mStride; } |
147 | S32 getIndicesSize() const { return mNumIndices * sizeof(U32); } | 187 | S32 getIndicesSize() const { return mNumIndices * sizeof(U16); } |
148 | U8* getMappedData() const { return mMappedData; } | 188 | U8* getMappedData() const { return mMappedData; } |
149 | U8* getMappedIndices() const { return mMappedIndexData; } | 189 | U8* getMappedIndices() const { return mMappedIndexData; } |
150 | S32 getOffset(S32 type) const { return mOffsets[type]; } | 190 | S32 getOffset(S32 type) const { return mOffsets[type]; } |
@@ -153,11 +193,13 @@ public: | |||
153 | void setStride(S32 type, S32 new_stride); | 193 | void setStride(S32 type, S32 new_stride); |
154 | 194 | ||
155 | void markDirty(U32 vert_index, U32 vert_count, U32 indices_index, U32 indices_count); | 195 | void markDirty(U32 vert_index, U32 vert_count, U32 indices_index, U32 indices_count); |
156 | void markClean(); | ||
157 | 196 | ||
158 | protected: | 197 | protected: |
159 | S32 mNumVerts; // Number of vertices | 198 | S32 mNumVerts; // Number of vertices allocated |
160 | S32 mNumIndices; // Number of indices | 199 | S32 mNumIndices; // Number of indices allocated |
200 | S32 mRequestedNumVerts; // Number of vertices requested | ||
201 | S32 mRequestedNumIndices; // Number of indices requested | ||
202 | |||
161 | S32 mStride; | 203 | S32 mStride; |
162 | U32 mTypeMask; | 204 | U32 mTypeMask; |
163 | S32 mUsage; // GL usage | 205 | S32 mUsage; // GL usage |
@@ -192,10 +234,11 @@ public: | |||
192 | static BOOL sRenderActive; | 234 | static BOOL sRenderActive; |
193 | static S32 sCount; | 235 | static S32 sCount; |
194 | static S32 sGLCount; | 236 | static S32 sGLCount; |
237 | static S32 sMappedCount; | ||
238 | static BOOL sMapped; | ||
195 | static std::vector<U32> sDeleteList; | 239 | static std::vector<U32> sDeleteList; |
196 | typedef std::list<LLVertexBuffer*> buffer_list_t; | 240 | typedef std::list<LLVertexBuffer*> buffer_list_t; |
197 | static buffer_list_t sLockedList; | 241 | |
198 | |||
199 | static BOOL sEnableVBOs; | 242 | static BOOL sEnableVBOs; |
200 | static S32 sTypeOffsets[TYPE_MAX]; | 243 | static S32 sTypeOffsets[TYPE_MAX]; |
201 | static U32 sGLRenderBuffer; | 244 | static U32 sGLRenderBuffer; |
@@ -204,6 +247,8 @@ public: | |||
204 | static BOOL sIBOActive; | 247 | static BOOL sIBOActive; |
205 | static U32 sLastMask; | 248 | static U32 sLastMask; |
206 | static U32 sAllocatedBytes; | 249 | static U32 sAllocatedBytes; |
250 | static U32 sBindCount; | ||
251 | static U32 sSetCount; | ||
207 | }; | 252 | }; |
208 | 253 | ||
209 | 254 | ||