diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lldrawpool.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/lldrawpool.h')
-rw-r--r-- | linden/indra/newview/lldrawpool.h | 367 |
1 files changed, 367 insertions, 0 deletions
diff --git a/linden/indra/newview/lldrawpool.h b/linden/indra/newview/lldrawpool.h new file mode 100644 index 0000000..2ce13fb --- /dev/null +++ b/linden/indra/newview/lldrawpool.h | |||
@@ -0,0 +1,367 @@ | |||
1 | /** | ||
2 | * @file lldrawpool.h | ||
3 | * @brief LLDrawPool class definition | ||
4 | * | ||
5 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLDRAWPOOL_H | ||
29 | #define LL_LLDRAWPOOL_H | ||
30 | |||
31 | #include "llagparray.h" | ||
32 | #include "lldarray.h" | ||
33 | #include "lldlinked.h" | ||
34 | #include "llstrider.h" | ||
35 | #include "llviewerimage.h" | ||
36 | #include "v4coloru.h" | ||
37 | #include "v2math.h" | ||
38 | #include "v3math.h" | ||
39 | #include "llstrider.h" | ||
40 | |||
41 | class LLFace; | ||
42 | class LLImageGL; | ||
43 | class LLViewerImage; | ||
44 | |||
45 | #define DEFAULT_MAX_VERTICES 65535 | ||
46 | |||
47 | class LLDrawPool | ||
48 | { | ||
49 | public: | ||
50 | typedef LLDynamicArray<LLFace*, 128> face_array_t; | ||
51 | |||
52 | enum | ||
53 | { | ||
54 | SHADER_LEVEL_SCATTERING = 2 | ||
55 | }; | ||
56 | |||
57 | public: | ||
58 | LLDrawPool(const U32 type, const U32 data_mask_il, const U32 data_mask_nil); | ||
59 | virtual ~LLDrawPool(); | ||
60 | |||
61 | static LLDrawPool* createPool(const U32 type, LLViewerImage *tex0 = NULL); | ||
62 | |||
63 | void flushAGP(); // Flush the AGP buffers so they can be repacked and reallocated. | ||
64 | void syncAGP(); | ||
65 | |||
66 | virtual LLDrawPool *instancePool() = 0; // Create an empty new instance of the pool. | ||
67 | virtual void beginRenderPass( S32 pass ); | ||
68 | virtual void endRenderPass( S32 pass ); | ||
69 | virtual S32 getNumPasses() { return 1; } | ||
70 | virtual void render(S32 pass = 0) = 0; | ||
71 | virtual void renderForSelect() = 0; | ||
72 | virtual BOOL match(LLFace* last_face, LLFace* facep) { return FALSE; } | ||
73 | virtual void renderFaceSelected(LLFace *facep, LLImageGL *image, const LLColor4 &color, | ||
74 | const S32 index_offset = 0, const S32 index_count = 0); | ||
75 | |||
76 | virtual void prerender() = 0; | ||
77 | virtual S32 rebuild(); | ||
78 | |||
79 | virtual S32 getMaterialAttribIndex() = 0; | ||
80 | |||
81 | virtual LLViewerImage *getTexture(); | ||
82 | virtual LLViewerImage *getDebugTexture(); | ||
83 | virtual void dirtyTexture(const LLViewerImage* texturep); | ||
84 | |||
85 | virtual void enqueue(LLFace *face); | ||
86 | virtual BOOL addFace(LLFace *face); | ||
87 | virtual BOOL removeFace(LLFace *face); | ||
88 | |||
89 | virtual BOOL verify() const; // Verify that all data in the draw pool is correct! | ||
90 | virtual LLColor3 getDebugColor() const; // For AGP debug display | ||
91 | |||
92 | virtual void resetDrawOrders(); | ||
93 | virtual void resetVertexData(S32 reserve_count); | ||
94 | virtual void resetIndices(S32 num_indices); | ||
95 | void resetAll(); | ||
96 | |||
97 | BOOL moveFace(LLFace *face, LLDrawPool *poolp, BOOL copy_data = FALSE); | ||
98 | |||
99 | |||
100 | S32 getId() const { return mId; } | ||
101 | U32 getType() const { return mType; } | ||
102 | |||
103 | const U32 getStride() const; | ||
104 | inline const U32 getStride(const U32 data_type) const; | ||
105 | inline const U32 getOffset(const U32 data_type) const; | ||
106 | |||
107 | S32 reserveGeom(U32 count); | ||
108 | S32 reserveInd (U32 count); | ||
109 | S32 unReserveGeom(const S32 index, const U32 count); | ||
110 | S32 unReserveInd(const S32 index, const U32 count); | ||
111 | |||
112 | void bindGLVertexPointer(); | ||
113 | void bindGLTexCoordPointer(const U32 pass=0); | ||
114 | void bindGLNormalPointer(); | ||
115 | void bindGLBinormalPointer(S32 index); | ||
116 | void bindGLColorPointer(); | ||
117 | void bindGLVertexWeightPointer(S32 index); | ||
118 | void bindGLVertexClothingWeightPointer(S32 index); | ||
119 | |||
120 | const U32 getIndexCount() const; | ||
121 | const U32 getTexCoordCount(const U32 pass=0) const; | ||
122 | const U32 getVertexCount() const; | ||
123 | const U32 getNormalCount() const; | ||
124 | const U32 getBinormalCount() const; | ||
125 | const U32 getColorCount() const; | ||
126 | const U32 getVertexWeightCount() const; | ||
127 | |||
128 | void setDirty(); | ||
129 | void setDirtyMemory() { mMemory.setDirty(); } | ||
130 | void setDirtyWeights() { mWeights.setDirty(); } | ||
131 | |||
132 | const U32* getRawIndices() const { return mIndices.getMem(); } | ||
133 | |||
134 | U32 getIndex(const S32 index) { return mIndices[index]; } // Use to get one index | ||
135 | U32 *getIndices(const S32 index); // Used to get an array of indices for reading/writing | ||
136 | void CheckIntegrity(); // DEBUG | ||
137 | |||
138 | const LLVector3& getVertex(const S32 index); | ||
139 | const LLVector2& getTexCoord(const S32 index, const U32 pass); | ||
140 | const LLVector3& getNormal(const S32 index); | ||
141 | const LLVector3& getBinormal(const S32 index); | ||
142 | const LLColor4U& getColor(const S32 index); | ||
143 | const F32& getVertexWeight(const S32 index); | ||
144 | const LLVector4& getClothingWeight(const S32 index); | ||
145 | |||
146 | void setRebuild(const BOOL rebuild); | ||
147 | |||
148 | void destroy(); | ||
149 | |||
150 | void buildEdges(); | ||
151 | |||
152 | static S32 drawLoop(face_array_t& face_list, const U32* index_array); | ||
153 | static S32 drawLoopSetTex(face_array_t& face_list, const U32* index_array, S32 stage); | ||
154 | void drawLoop(); | ||
155 | |||
156 | void renderVisibility(); | ||
157 | |||
158 | void addFaceReference(LLFace *facep); | ||
159 | void removeFaceReference(LLFace *facep); | ||
160 | U32 getTrianglesDrawn() const; | ||
161 | void resetTrianglesDrawn(); | ||
162 | void addIndicesDrawn(const U32 indices); | ||
163 | |||
164 | void printDebugInfo() const; | ||
165 | S32 getMemUsage(const BOOL print = FALSE); | ||
166 | |||
167 | BOOL setUseAGP(BOOL use_agp); | ||
168 | BOOL canUseAGP() const { return mMemory.isAGP(); } // Return TRUE if this pool can use AGP | ||
169 | |||
170 | S32 getMaxVertices() const { return mMaxVertices; } | ||
171 | S32 getVertexShaderLevel() const { return mVertexShaderLevel; } | ||
172 | |||
173 | friend class LLFace; | ||
174 | friend class LLPipeline; | ||
175 | public: | ||
176 | |||
177 | enum | ||
178 | { | ||
179 | // Correspond to LLPipeline render type | ||
180 | POOL_SKY = 1, | ||
181 | POOL_STARS, | ||
182 | POOL_GROUND, | ||
183 | POOL_TERRAIN, | ||
184 | POOL_SIMPLE, | ||
185 | POOL_MEDIA, // unused | ||
186 | POOL_BUMP, | ||
187 | POOL_AVATAR, | ||
188 | POOL_TREE, | ||
189 | POOL_TREE_NEW, | ||
190 | POOL_WATER, | ||
191 | POOL_CLOUDS, | ||
192 | POOL_ALPHA, | ||
193 | POOL_HUD, | ||
194 | }; | ||
195 | |||
196 | |||
197 | // If you change the order or add params to these, you also need to adjust the sizes in the | ||
198 | // mDataSizes array defined in lldrawpool.cpp | ||
199 | typedef enum e_data_type | ||
200 | { | ||
201 | DATA_VERTICES = 0, | ||
202 | DATA_TEX_COORDS0 = 1, | ||
203 | DATA_TEX_COORDS1 = 2, | ||
204 | DATA_TEX_COORDS2 = 3, | ||
205 | DATA_TEX_COORDS3 = 4, | ||
206 | DATA_NORMALS = 5, | ||
207 | DATA_VERTEX_WEIGHTS = 6, | ||
208 | DATA_CLOTHING_WEIGHTS = 7, | ||
209 | DATA_BINORMALS = 8, | ||
210 | DATA_COLORS = 9, | ||
211 | DATA_MAX_TYPES = 10 | ||
212 | } EDataType; | ||
213 | |||
214 | typedef enum e_data_mask | ||
215 | { | ||
216 | DATA_VERTICES_MASK = 1 << DATA_VERTICES, | ||
217 | DATA_TEX_COORDS0_MASK = 1 << DATA_TEX_COORDS0, | ||
218 | DATA_TEX_COORDS1_MASK = 1 << DATA_TEX_COORDS1, | ||
219 | DATA_TEX_COORDS2_MASK = 1 << DATA_TEX_COORDS2, | ||
220 | DATA_TEX_COORDS3_MASK = 1 << DATA_TEX_COORDS3, | ||
221 | DATA_NORMALS_MASK = 1 << DATA_NORMALS, | ||
222 | DATA_VERTEX_WEIGHTS_MASK = 1 << DATA_VERTEX_WEIGHTS, | ||
223 | DATA_CLOTHING_WEIGHTS_MASK = 1 << DATA_CLOTHING_WEIGHTS, | ||
224 | DATA_BINORMALS_MASK = 1 << DATA_BINORMALS, | ||
225 | DATA_COLORS_MASK = 1 << DATA_COLORS, | ||
226 | |||
227 | // Masks for standard types. | ||
228 | // IL for interleaved, NIL for non-interleaved. | ||
229 | DATA_SIMPLE_IL_MASK = DATA_VERTICES_MASK | DATA_TEX_COORDS0_MASK | DATA_NORMALS_MASK, | ||
230 | DATA_SIMPLE_NIL_MASK = 0, | ||
231 | DATA_BUMP_IL_MASK = DATA_SIMPLE_IL_MASK | DATA_BINORMALS_MASK | DATA_TEX_COORDS1_MASK, | ||
232 | } EDataMask; | ||
233 | |||
234 | face_array_t mDrawFace; | ||
235 | face_array_t mMoveFace; | ||
236 | face_array_t mReferences; | ||
237 | |||
238 | U32 mDataMaskIL; // Interleaved data | ||
239 | U32 mDataMaskNIL; // Non-interleaved data | ||
240 | U32 mDataOffsets[DATA_MAX_TYPES]; | ||
241 | S32 mStride; | ||
242 | |||
243 | S32 mRebuildFreq; | ||
244 | S32 mRebuildTime; | ||
245 | S32 mGeneration; | ||
246 | |||
247 | |||
248 | S32 mSkippedVertices; | ||
249 | |||
250 | static U32 sDataSizes[DATA_MAX_TYPES]; | ||
251 | static S32 sNumDrawPools; | ||
252 | |||
253 | protected: | ||
254 | LLAGPArray<U8> mMemory; | ||
255 | LLAGPArray<F32> mWeights; | ||
256 | LLAGPArray<LLVector4> mClothingWeights; | ||
257 | LLAGPArray<U32> mIndices; | ||
258 | |||
259 | public: | ||
260 | |||
261 | BOOL getVertexStrider (LLStrider<LLVector3> &vertices, const U32 index = 0); | ||
262 | BOOL getTexCoordStrider (LLStrider<LLVector2> &tex_coords, const U32 index = 0, const U32 pass=0); | ||
263 | BOOL getNormalStrider (LLStrider<LLVector3> &normals, const U32 index = 0); | ||
264 | BOOL getBinormalStrider (LLStrider<LLVector3> &binormals, const U32 index = 0); | ||
265 | BOOL getColorStrider (LLStrider<LLColor4U> &colors, const U32 index = 0); | ||
266 | BOOL getVertexWeightStrider(LLStrider<F32> &vertex_weights, const U32 index = 0); | ||
267 | BOOL getClothingWeightStrider(LLStrider<LLVector4> &clothing_weights, const U32 index = 0); | ||
268 | |||
269 | public: | ||
270 | enum { NUM_BUCKETS = 8 }; // Need to change freeListBucket() if NUM_BUCKETS changes | ||
271 | struct FreeListNode | ||
272 | { | ||
273 | U32 count; | ||
274 | S32 next; | ||
275 | }; | ||
276 | protected: | ||
277 | int freeListBucket(U32 count); | ||
278 | void freeListAddGeom(S32 index, U32 count); | ||
279 | void freeListAddInd(S32 index, U32 count); | ||
280 | S32 freeListFindGeom(U32 count); | ||
281 | S32 freeListFindInd(U32 count); | ||
282 | |||
283 | protected: | ||
284 | BOOL mUseAGP; | ||
285 | S32 mVertexShaderLevel; | ||
286 | S32 mId; | ||
287 | U32 mType; // Type of draw pool | ||
288 | S32 mMaxVertices; | ||
289 | S32 mIndicesDrawn; | ||
290 | BOOL mCleanupUnused; // Cleanup unused data when too full | ||
291 | |||
292 | S32 mFreeListGeomHead[8]; | ||
293 | S32 mFreeListIndHead[8]; | ||
294 | |||
295 | public: | ||
296 | class LLOverrideFaceColor | ||
297 | { | ||
298 | public: | ||
299 | LLOverrideFaceColor(LLDrawPool* pool) | ||
300 | : mOverride(sOverrideFaceColor), mPool(pool) | ||
301 | { | ||
302 | sOverrideFaceColor = TRUE; | ||
303 | } | ||
304 | LLOverrideFaceColor(LLDrawPool* pool, const LLColor4& color) | ||
305 | : mOverride(sOverrideFaceColor), mPool(pool) | ||
306 | { | ||
307 | sOverrideFaceColor = TRUE; | ||
308 | setColor(color); | ||
309 | } | ||
310 | LLOverrideFaceColor(LLDrawPool* pool, const LLColor4U& color) | ||
311 | : mOverride(sOverrideFaceColor), mPool(pool) | ||
312 | { | ||
313 | sOverrideFaceColor = TRUE; | ||
314 | setColor(color); | ||
315 | } | ||
316 | LLOverrideFaceColor(LLDrawPool* pool, F32 r, F32 g, F32 b, F32 a) | ||
317 | : mOverride(sOverrideFaceColor), mPool(pool) | ||
318 | { | ||
319 | sOverrideFaceColor = TRUE; | ||
320 | setColor(r, g, b, a); | ||
321 | } | ||
322 | ~LLOverrideFaceColor() | ||
323 | { | ||
324 | sOverrideFaceColor = mOverride; | ||
325 | } | ||
326 | void setColor(const LLColor4& color); | ||
327 | void setColor(const LLColor4U& color); | ||
328 | void setColor(F32 r, F32 g, F32 b, F32 a); | ||
329 | BOOL mOverride; | ||
330 | LLDrawPool* mPool; | ||
331 | static BOOL sOverrideFaceColor; | ||
332 | }; | ||
333 | |||
334 | virtual void enableShade(); | ||
335 | virtual void disableShade(); | ||
336 | virtual void setShade(F32 shade); | ||
337 | |||
338 | }; | ||
339 | |||
340 | inline const U32 LLDrawPool::getStride() const | ||
341 | { | ||
342 | return mStride; | ||
343 | } | ||
344 | |||
345 | inline const U32 LLDrawPool::getOffset(const U32 data_type) const | ||
346 | { | ||
347 | return mDataOffsets[data_type]; | ||
348 | } | ||
349 | |||
350 | inline const U32 LLDrawPool::getStride(const U32 data_type) const | ||
351 | { | ||
352 | if (mDataMaskIL & (1 << data_type)) | ||
353 | { | ||
354 | return mStride; | ||
355 | } | ||
356 | else if (mDataMaskNIL & (1 << data_type)) | ||
357 | { | ||
358 | return 0; | ||
359 | } | ||
360 | else | ||
361 | { | ||
362 | llerrs << "Getting stride for unsupported data type " << data_type << llendl; | ||
363 | return 0; | ||
364 | } | ||
365 | } | ||
366 | |||
367 | #endif //LL_LLDRAWPOOL_H | ||