PageRenderTime 100ms CodeModel.GetById 22ms app.highlight 71ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/pipeline.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 857 lines | 659 code | 130 blank | 68 comment | 11 complexity | a2ab19e7eb332a43d620799085c96869 MD5 | raw file
  1/** 
  2 * @file pipeline.h
  3 * @brief Rendering pipeline definitions
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_PIPELINE_H
 28#define LL_PIPELINE_H
 29
 30#include "llcamera.h"
 31#include "llerror.h"
 32#include "lldarrayptr.h"
 33#include "lldqueueptr.h"
 34#include "lldrawpool.h"
 35#include "llspatialpartition.h"
 36#include "m4math.h"
 37#include "llpointer.h"
 38#include "lldrawpool.h"
 39#include "llgl.h"
 40#include "lldrawable.h"
 41#include "llrendertarget.h"
 42
 43#include <stack>
 44
 45#include <stack>
 46
 47#include <stack>
 48
 49class LLViewerTexture;
 50class LLEdge;
 51class LLFace;
 52class LLViewerObject;
 53class LLAgent;
 54class LLDisplayPrimitive;
 55class LLTextureEntry;
 56class LLRenderFunc;
 57class LLCubeMap;
 58class LLCullResult;
 59class LLVOAvatar;
 60class LLGLSLShader;
 61class LLCurlRequest;
 62
 63class LLMeshResponder;
 64
 65typedef enum e_avatar_skinning_method
 66{
 67	SKIN_METHOD_SOFTWARE,
 68	SKIN_METHOD_VERTEX_PROGRAM
 69} EAvatarSkinningMethod;
 70
 71BOOL compute_min_max(LLMatrix4& box, LLVector2& min, LLVector2& max); // Shouldn't be defined here!
 72bool LLRayAABB(const LLVector3 &center, const LLVector3 &size, const LLVector3& origin, const LLVector3& dir, LLVector3 &coord, F32 epsilon = 0);
 73BOOL setup_hud_matrices(); // use whole screen to render hud
 74BOOL setup_hud_matrices(const LLRect& screen_region); // specify portion of screen (in pixels) to render hud attachments from (for picking)
 75glh::matrix4f glh_copy_matrix(F32* src);
 76glh::matrix4f glh_get_current_modelview();
 77void glh_set_current_modelview(const glh::matrix4f& mat);
 78glh::matrix4f glh_get_current_projection();
 79void glh_set_current_projection(glh::matrix4f& mat);
 80glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar);
 81glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
 82glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up);
 83
 84extern LLFastTimer::DeclareTimer FTM_RENDER_GEOMETRY;
 85extern LLFastTimer::DeclareTimer FTM_RENDER_GRASS;
 86extern LLFastTimer::DeclareTimer FTM_RENDER_INVISIBLE;
 87extern LLFastTimer::DeclareTimer FTM_RENDER_OCCLUSION;
 88extern LLFastTimer::DeclareTimer FTM_RENDER_SHINY;
 89extern LLFastTimer::DeclareTimer FTM_RENDER_SIMPLE;
 90extern LLFastTimer::DeclareTimer FTM_RENDER_TERRAIN;
 91extern LLFastTimer::DeclareTimer FTM_RENDER_TREES;
 92extern LLFastTimer::DeclareTimer FTM_RENDER_UI;
 93extern LLFastTimer::DeclareTimer FTM_RENDER_WATER;
 94extern LLFastTimer::DeclareTimer FTM_RENDER_WL_SKY;
 95extern LLFastTimer::DeclareTimer FTM_RENDER_ALPHA;
 96extern LLFastTimer::DeclareTimer FTM_RENDER_CHARACTERS;
 97extern LLFastTimer::DeclareTimer FTM_RENDER_BUMP;
 98extern LLFastTimer::DeclareTimer FTM_RENDER_FULLBRIGHT;
 99extern LLFastTimer::DeclareTimer FTM_RENDER_GLOW;
100extern LLFastTimer::DeclareTimer FTM_STATESORT;
101extern LLFastTimer::DeclareTimer FTM_PIPELINE;
102extern LLFastTimer::DeclareTimer FTM_CLIENT_COPY;
103
104
105class LLPipeline
106{
107public:
108	LLPipeline();
109	~LLPipeline();
110
111	void destroyGL();
112	void restoreGL();
113	void resetVertexBuffers();
114	void resizeScreenTexture();
115	void releaseGLBuffers();
116	void releaseScreenBuffers();
117	void createGLBuffers();
118
119	void allocateScreenBuffer(U32 resX, U32 resY);
120	bool allocateScreenBuffer(U32 resX, U32 resY, U32 samples);
121	void allocatePhysicsBuffer();
122	
123	void resetVertexBuffers(LLDrawable* drawable);
124	void generateImpostor(LLVOAvatar* avatar);
125	void bindScreenToTexture();
126	void renderBloom(BOOL for_snapshot, F32 zoom_factor = 1.f, int subfield = 0);
127
128	void init();
129	void cleanup();
130	BOOL isInit() { return mInitialized; };
131
132	/// @brief Get a draw pool from pool type (POOL_SIMPLE, POOL_MEDIA) and texture.
133	/// @return Draw pool, or NULL if not found.
134	LLDrawPool *findPool(const U32 pool_type, LLViewerTexture *tex0 = NULL);
135
136	/// @brief Get a draw pool for faces of the appropriate type and texture.  Create if necessary.
137	/// @return Always returns a draw pool.
138	LLDrawPool *getPool(const U32 pool_type, LLViewerTexture *tex0 = NULL);
139
140	/// @brief Figures out draw pool type from texture entry. Creates pool if necessary.
141	static LLDrawPool* getPoolFromTE(const LLTextureEntry* te, LLViewerTexture* te_image);
142	static U32 getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* imagep);
143
144	void		 addPool(LLDrawPool *poolp);	// Only to be used by LLDrawPool classes for splitting pools!
145	void		 removePool( LLDrawPool* poolp );
146
147	void		 allocDrawable(LLViewerObject *obj);
148
149	void		 unlinkDrawable(LLDrawable*);
150
151	// Object related methods
152	void        markVisible(LLDrawable *drawablep, LLCamera& camera);
153	void		markOccluder(LLSpatialGroup* group);
154	void		doOcclusion(LLCamera& camera);
155	void		markNotCulled(LLSpatialGroup* group, LLCamera &camera);
156	void        markMoved(LLDrawable *drawablep, BOOL damped_motion = FALSE);
157	void        markShift(LLDrawable *drawablep);
158	void        markTextured(LLDrawable *drawablep);
159	void		markGLRebuild(LLGLUpdate* glu);
160	void		markRebuild(LLSpatialGroup* group, BOOL priority = FALSE);
161	void        markRebuild(LLDrawable *drawablep, LLDrawable::EDrawableFlags flag = LLDrawable::REBUILD_ALL, BOOL priority = FALSE);
162	void		markPartitionMove(LLDrawable* drawablep);
163
164	//get the object between start and end that's closest to start.
165	LLViewerObject* lineSegmentIntersectInWorld(const LLVector3& start, const LLVector3& end,
166												BOOL pick_transparent,
167												S32* face_hit,                          // return the face hit
168												LLVector3* intersection = NULL,         // return the intersection point
169												LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
170												LLVector3* normal = NULL,               // return the surface normal at the intersection point
171												LLVector3* bi_normal = NULL             // return the surface bi-normal at the intersection point  
172		);
173	LLViewerObject* lineSegmentIntersectInHUD(const LLVector3& start, const LLVector3& end,
174											  BOOL pick_transparent,
175											  S32* face_hit,                          // return the face hit
176											  LLVector3* intersection = NULL,         // return the intersection point
177											  LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
178											  LLVector3* normal = NULL,               // return the surface normal at the intersection point
179											  LLVector3* bi_normal = NULL             // return the surface bi-normal at the intersection point
180		);
181
182	// Something about these textures has changed.  Dirty them.
183	void        dirtyPoolObjectTextures(const std::set<LLViewerFetchedTexture*>& textures);
184
185	void        resetDrawOrders();
186
187	U32         addObject(LLViewerObject *obj);
188
189	void		enableShadows(const BOOL enable_shadows);
190
191// 	void		setLocalLighting(const BOOL local_lighting);
192// 	BOOL		isLocalLightingEnabled() const;
193	S32			setLightingDetail(S32 level);
194	S32			getLightingDetail() const { return mLightingDetail; }
195	S32			getMaxLightingDetail() const;
196		
197	void		setUseVertexShaders(BOOL use_shaders);
198	BOOL		getUseVertexShaders() const { return mVertexShadersEnabled; }
199	BOOL		canUseVertexShaders();
200	BOOL		canUseWindLightShaders() const;
201	BOOL		canUseWindLightShadersOnObjects() const;
202	BOOL		canUseAntiAliasing() const;
203
204	// phases
205	void resetFrameStats();
206
207	void updateMoveDampedAsync(LLDrawable* drawablep);
208	void updateMoveNormalAsync(LLDrawable* drawablep);
209	void updateMovedList(LLDrawable::drawable_vector_t& move_list);
210	void updateMove();
211	BOOL visibleObjectsInFrustum(LLCamera& camera);
212	BOOL getVisibleExtents(LLCamera& camera, LLVector3 &min, LLVector3& max);
213	BOOL getVisiblePointCloud(LLCamera& camera, LLVector3 &min, LLVector3& max, std::vector<LLVector3>& fp, LLVector3 light_dir = LLVector3(0,0,0));
214	void updateCull(LLCamera& camera, LLCullResult& result, S32 water_clip = 0, LLPlane* plane = NULL);  //if water_clip is 0, ignore water plane, 1, cull to above plane, -1, cull to below plane
215	void createObjects(F32 max_dtime);
216	void createObject(LLViewerObject* vobj);
217	void processPartitionQ();
218	void updateGeom(F32 max_dtime);
219	void updateGL();
220	void rebuildPriorityGroups();
221	void rebuildGroups();
222
223	//calculate pixel area of given box from vantage point of given camera
224	static F32 calcPixelArea(LLVector3 center, LLVector3 size, LLCamera& camera);
225	static F32 calcPixelArea(const LLVector4a& center, const LLVector4a& size, LLCamera &camera);
226
227	void stateSort(LLCamera& camera, LLCullResult& result);
228	void stateSort(LLSpatialGroup* group, LLCamera& camera);
229	void stateSort(LLSpatialBridge* bridge, LLCamera& camera);
230	void stateSort(LLDrawable* drawablep, LLCamera& camera);
231	void postSort(LLCamera& camera);
232	void forAllVisibleDrawables(void (*func)(LLDrawable*));
233
234	void renderObjects(U32 type, U32 mask, BOOL texture = TRUE, BOOL batch_texture = FALSE);
235	void renderGroups(LLRenderPass* pass, U32 type, U32 mask, BOOL texture);
236
237	void grabReferences(LLCullResult& result);
238	void clearReferences();
239
240	//check references will assert that there are no references in sCullResult to the provided data
241	void checkReferences(LLFace* face);
242	void checkReferences(LLDrawable* drawable);
243	void checkReferences(LLDrawInfo* draw_info);
244	void checkReferences(LLSpatialGroup* group);
245
246
247	void renderGeom(LLCamera& camera, BOOL forceVBOUpdate = FALSE);
248	void renderGeomDeferred(LLCamera& camera);
249	void renderGeomPostDeferred(LLCamera& camera);
250	void renderGeomShadow(LLCamera& camera);
251	void bindDeferredShader(LLGLSLShader& shader, U32 light_index = 0, U32 noise_map = 0xFFFFFFFF);
252	void setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep);
253
254	void unbindDeferredShader(LLGLSLShader& shader);
255	void renderDeferredLighting();
256	
257	void generateWaterReflection(LLCamera& camera);
258	void generateSunShadow(LLCamera& camera);
259	void generateHighlight(LLCamera& camera);
260	void renderHighlight(const LLViewerObject* obj, F32 fade);
261	void setHighlightObject(LLDrawable* obj) { mHighlightObject = obj; }
262
263
264	void renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& camera, LLCullResult& result, BOOL use_shader = TRUE, BOOL use_occlusion = TRUE);
265	void renderHighlights();
266	void renderDebug();
267	void renderPhysicsDisplay();
268
269	void rebuildPools(); // Rebuild pools
270
271	void findReferences(LLDrawable *drawablep);	// Find the lists which have references to this object
272	BOOL verify();						// Verify that all data in the pipeline is "correct"
273
274	S32  getLightCount() const { return mLights.size(); }
275
276	void calcNearbyLights(LLCamera& camera);
277	void setupHWLights(LLDrawPool* pool);
278	void setupAvatarLights(BOOL for_edit = FALSE);
279	void enableLights(U32 mask);
280	void enableLightsStatic();
281	void enableLightsDynamic();
282	void enableLightsAvatar();
283	void enableLightsPreview();
284	void enableLightsAvatarEdit(const LLColor4& color);
285	void enableLightsFullbright(const LLColor4& color);
286	void disableLights();
287
288	void shiftObjects(const LLVector3 &offset);
289
290	void setLight(LLDrawable *drawablep, BOOL is_light);
291	
292	BOOL hasRenderBatches(const U32 type) const;
293	LLCullResult::drawinfo_list_t::iterator beginRenderMap(U32 type);
294	LLCullResult::drawinfo_list_t::iterator endRenderMap(U32 type);
295	LLCullResult::sg_list_t::iterator beginAlphaGroups();
296	LLCullResult::sg_list_t::iterator endAlphaGroups();
297	
298
299	void addTrianglesDrawn(S32 index_count, U32 render_type = LLRender::TRIANGLES);
300
301	BOOL hasRenderDebugFeatureMask(const U32 mask) const	{ return (mRenderDebugFeatureMask & mask) ? TRUE : FALSE; }
302	BOOL hasRenderDebugMask(const U32 mask) const			{ return (mRenderDebugMask & mask) ? TRUE : FALSE; }
303	
304
305
306	BOOL hasRenderType(const U32 type) const;
307	BOOL hasAnyRenderType(const U32 type, ...) const;
308
309	void setRenderTypeMask(U32 type, ...);
310	void orRenderTypeMask(U32 type, ...);
311	void andRenderTypeMask(U32 type, ...);
312	void clearRenderTypeMask(U32 type, ...);
313	
314	void pushRenderTypeMask();
315	void popRenderTypeMask();
316
317	static void toggleRenderType(U32 type);
318
319	// For UI control of render features
320	static BOOL hasRenderTypeControl(void* data);
321	static void toggleRenderDebug(void* data);
322	static void toggleRenderDebugFeature(void* data);
323	static void toggleRenderTypeControl(void* data);
324	static BOOL toggleRenderTypeControlNegated(void* data);
325	static BOOL toggleRenderDebugControl(void* data);
326	static BOOL toggleRenderDebugFeatureControl(void* data);
327	static void setRenderDebugFeatureControl(U32 bit, bool value);
328
329	static void setRenderParticleBeacons(BOOL val);
330	static void toggleRenderParticleBeacons(void* data);
331	static BOOL getRenderParticleBeacons(void* data);
332
333	static void setRenderSoundBeacons(BOOL val);
334	static void toggleRenderSoundBeacons(void* data);
335	static BOOL getRenderSoundBeacons(void* data);
336
337	static void setRenderMOAPBeacons(BOOL val);
338	static void toggleRenderMOAPBeacons(void * data);
339	static BOOL getRenderMOAPBeacons(void * data);
340
341	static void setRenderPhysicalBeacons(BOOL val);
342	static void toggleRenderPhysicalBeacons(void* data);
343	static BOOL getRenderPhysicalBeacons(void* data);
344
345	static void setRenderScriptedBeacons(BOOL val);
346	static void toggleRenderScriptedBeacons(void* data);
347	static BOOL getRenderScriptedBeacons(void* data);
348
349	static void setRenderScriptedTouchBeacons(BOOL val);
350	static void toggleRenderScriptedTouchBeacons(void* data);
351	static BOOL getRenderScriptedTouchBeacons(void* data);
352
353	static void setRenderBeacons(BOOL val);
354	static void toggleRenderBeacons(void* data);
355	static BOOL getRenderBeacons(void* data);
356
357	static void setRenderHighlights(BOOL val);
358	static void toggleRenderHighlights(void* data);
359	static BOOL getRenderHighlights(void* data);
360
361	static void updateRenderDeferred();
362	static void refreshCachedSettings();
363
364	static void throttleNewMemoryAllocation(BOOL disable);
365
366	void addDebugBlip(const LLVector3& position, const LLColor4& color);
367
368private:
369	void unloadShaders();
370	void addToQuickLookup( LLDrawPool* new_poolp );
371	void removeFromQuickLookup( LLDrawPool* poolp );
372	BOOL updateDrawableGeom(LLDrawable* drawable, BOOL priority);
373	void assertInitializedDoError();
374	bool assertInitialized() { const bool is_init = isInit(); if (!is_init) assertInitializedDoError(); return is_init; };
375	
376public:
377	enum {GPU_CLASS_MAX = 3 };
378
379	enum LLRenderTypeMask
380	{
381		// Following are pool types (some are also object types)
382		RENDER_TYPE_SKY							= LLDrawPool::POOL_SKY,
383		RENDER_TYPE_WL_SKY						= LLDrawPool::POOL_WL_SKY,
384		RENDER_TYPE_GROUND						= LLDrawPool::POOL_GROUND,	
385		RENDER_TYPE_TERRAIN						= LLDrawPool::POOL_TERRAIN,
386		RENDER_TYPE_SIMPLE						= LLDrawPool::POOL_SIMPLE,
387		RENDER_TYPE_GRASS						= LLDrawPool::POOL_GRASS,
388		RENDER_TYPE_FULLBRIGHT					= LLDrawPool::POOL_FULLBRIGHT,
389		RENDER_TYPE_BUMP						= LLDrawPool::POOL_BUMP,
390		RENDER_TYPE_AVATAR						= LLDrawPool::POOL_AVATAR,
391		RENDER_TYPE_TREE						= LLDrawPool::POOL_TREE,
392		RENDER_TYPE_INVISIBLE					= LLDrawPool::POOL_INVISIBLE,
393		RENDER_TYPE_VOIDWATER					= LLDrawPool::POOL_VOIDWATER,
394		RENDER_TYPE_WATER						= LLDrawPool::POOL_WATER,
395 		RENDER_TYPE_ALPHA						= LLDrawPool::POOL_ALPHA,
396		RENDER_TYPE_GLOW						= LLDrawPool::POOL_GLOW,
397		RENDER_TYPE_PASS_SIMPLE 				= LLRenderPass::PASS_SIMPLE,
398		RENDER_TYPE_PASS_GRASS					= LLRenderPass::PASS_GRASS,
399		RENDER_TYPE_PASS_FULLBRIGHT				= LLRenderPass::PASS_FULLBRIGHT,
400		RENDER_TYPE_PASS_INVISIBLE				= LLRenderPass::PASS_INVISIBLE,
401		RENDER_TYPE_PASS_INVISI_SHINY			= LLRenderPass::PASS_INVISI_SHINY,
402		RENDER_TYPE_PASS_FULLBRIGHT_SHINY		= LLRenderPass::PASS_FULLBRIGHT_SHINY,
403		RENDER_TYPE_PASS_SHINY					= LLRenderPass::PASS_SHINY,
404		RENDER_TYPE_PASS_BUMP					= LLRenderPass::PASS_BUMP,
405		RENDER_TYPE_PASS_POST_BUMP				= LLRenderPass::PASS_POST_BUMP,
406		RENDER_TYPE_PASS_GLOW					= LLRenderPass::PASS_GLOW,
407		RENDER_TYPE_PASS_ALPHA					= LLRenderPass::PASS_ALPHA,
408		RENDER_TYPE_PASS_ALPHA_MASK				= LLRenderPass::PASS_ALPHA_MASK,
409		RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK	= LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK,
410		// Following are object types (only used in drawable mRenderType)
411		RENDER_TYPE_HUD = LLRenderPass::NUM_RENDER_TYPES,
412		RENDER_TYPE_VOLUME,
413		RENDER_TYPE_PARTICLES,
414		RENDER_TYPE_CLOUDS,
415		RENDER_TYPE_HUD_PARTICLES,
416		NUM_RENDER_TYPES,
417		END_RENDER_TYPES = NUM_RENDER_TYPES
418	};
419
420	enum LLRenderDebugFeatureMask
421	{
422		RENDER_DEBUG_FEATURE_UI					= 0x0001,
423		RENDER_DEBUG_FEATURE_SELECTED			= 0x0002,
424		RENDER_DEBUG_FEATURE_HIGHLIGHTED		= 0x0004,
425		RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES	= 0x0008,
426// 		RENDER_DEBUG_FEATURE_HW_LIGHTING		= 0x0010,
427		RENDER_DEBUG_FEATURE_FLEXIBLE			= 0x0010,
428		RENDER_DEBUG_FEATURE_FOG				= 0x0020,
429		RENDER_DEBUG_FEATURE_FR_INFO			= 0x0080,
430		RENDER_DEBUG_FEATURE_FOOT_SHADOWS		= 0x0100,
431	};
432
433	enum LLRenderDebugMask
434	{
435		RENDER_DEBUG_COMPOSITION		= 0x0000001,
436		RENDER_DEBUG_VERIFY				= 0x0000002,
437		RENDER_DEBUG_BBOXES				= 0x0000004,
438		RENDER_DEBUG_OCTREE				= 0x0000008,
439		RENDER_DEBUG_WIND_VECTORS		= 0x0000010,
440		RENDER_DEBUG_OCCLUSION			= 0x0000020,
441		RENDER_DEBUG_POINTS				= 0x0000040,
442		RENDER_DEBUG_TEXTURE_PRIORITY	= 0x0000080,
443		RENDER_DEBUG_TEXTURE_AREA		= 0x0000100,
444		RENDER_DEBUG_FACE_AREA			= 0x0000200,
445		RENDER_DEBUG_PARTICLES			= 0x0000400,
446		RENDER_DEBUG_GLOW				= 0x0000800,
447		RENDER_DEBUG_TEXTURE_ANIM		= 0x0001000,
448		RENDER_DEBUG_LIGHTS				= 0x0002000,
449		RENDER_DEBUG_BATCH_SIZE			= 0x0004000,
450		RENDER_DEBUG_ALPHA_BINS			= 0x0008000,
451		RENDER_DEBUG_RAYCAST            = 0x0010000,
452		RENDER_DEBUG_SHAME				= 0x0020000,
453		RENDER_DEBUG_SHADOW_FRUSTA		= 0x0040000,
454		RENDER_DEBUG_SCULPTED           = 0x0080000,
455		RENDER_DEBUG_AVATAR_VOLUME      = 0x0100000,
456		RENDER_DEBUG_BUILD_QUEUE		= 0x0200000,
457		RENDER_DEBUG_AGENT_TARGET       = 0x0400000,
458		RENDER_DEBUG_UPDATE_TYPE		= 0x0800000,
459		RENDER_DEBUG_PHYSICS_SHAPES     = 0x1000000,
460		RENDER_DEBUG_NORMALS	        = 0x2000000,
461		RENDER_DEBUG_LOD_INFO	        = 0x4000000,
462		RENDER_DEBUG_RENDER_COMPLEXITY  = 0x8000000
463	};
464
465public:
466	
467	LLSpatialPartition* getSpatialPartition(LLViewerObject* vobj);
468
469	void updateCamera(BOOL reset = FALSE);
470	
471	LLVector3				mFlyCamPosition;
472	LLQuaternion			mFlyCamRotation;
473
474	BOOL					 mBackfaceCull;
475	S32						 mBatchCount;
476	S32						 mMatrixOpCount;
477	S32						 mTextureMatrixOps;
478	S32						 mMaxBatchSize;
479	S32						 mMinBatchSize;
480	S32						 mMeanBatchSize;
481	S32						 mTrianglesDrawn;
482	S32						 mNumVisibleNodes;
483	S32						 mVerticesRelit;
484
485	S32						 mDebugTextureUploadCost;
486	S32						 mDebugSculptUploadCost;
487	S32						 mDebugMeshUploadCost;
488
489	S32						 mLightingChanges;
490	S32						 mGeometryChanges;
491
492	S32						 mNumVisibleFaces;
493
494	static S32				sCompiles;
495
496	static BOOL				sShowHUDAttachments;
497	static BOOL				sForceOldBakedUpload; // If true will not use capabilities to upload baked textures.
498	static S32				sUseOcclusion;  // 0 = no occlusion, 1 = read only, 2 = read/write
499	static BOOL				sDelayVBUpdate;
500	static BOOL				sAutoMaskAlphaDeferred;
501	static BOOL				sAutoMaskAlphaNonDeferred;
502	static BOOL				sDisableShaders; // if TRUE, rendering will be done without shaders
503	static BOOL				sRenderBump;
504	static BOOL				sBakeSunlight;
505	static BOOL				sNoAlpha;
506	static BOOL				sUseTriStrips;
507	static BOOL				sUseFarClip;
508	static BOOL				sShadowRender;
509	static BOOL				sWaterReflections;
510	static BOOL				sDynamicLOD;
511	static BOOL				sPickAvatar;
512	static BOOL				sReflectionRender;
513	static BOOL				sImpostorRender;
514	static BOOL				sUnderWaterRender;
515	static BOOL				sRenderGlow;
516	static BOOL				sTextureBindTest;
517	static BOOL				sRenderFrameTest;
518	static BOOL				sRenderAttachedLights;
519	static BOOL				sRenderAttachedParticles;
520	static BOOL				sRenderDeferred;
521	static BOOL             sMemAllocationThrottled;
522	static S32				sVisibleLightCount;
523	static F32				sMinRenderSize;	
524
525	//screen texture
526	U32 					mScreenWidth;
527	U32 					mScreenHeight;
528	
529	LLRenderTarget			mScreen;
530	LLRenderTarget			mUIScreen;
531	LLRenderTarget			mDeferredScreen;
532	LLRenderTarget			mFXAABuffer;
533	LLRenderTarget			mEdgeMap;
534	LLRenderTarget			mDeferredDepth;
535	LLRenderTarget			mDeferredLight;
536	LLRenderTarget			mHighlight;
537	LLRenderTarget			mPhysicsDisplay;
538
539	//utility buffer for rendering post effects, gets abused by renderDeferredLighting
540	LLPointer<LLVertexBuffer> mDeferredVB;
541
542	//sun shadow map
543	LLRenderTarget			mShadow[6];
544	std::vector<LLVector3>	mShadowFrustPoints[4];
545	LLVector4				mShadowError;
546	LLVector4				mShadowFOV;
547	LLVector3				mShadowFrustOrigin[4];
548	LLCamera				mShadowCamera[8];
549	LLVector3				mShadowExtents[4][2];
550	glh::matrix4f			mSunShadowMatrix[6];
551	glh::matrix4f			mShadowModelview[6];
552	glh::matrix4f			mShadowProjection[6];
553	glh::matrix4f			mGIMatrix;
554	glh::matrix4f			mGIMatrixProj;
555	glh::matrix4f			mGIModelview;
556	glh::matrix4f			mGIProjection;
557	glh::matrix4f			mGINormalMatrix;
558	glh::matrix4f			mGIInvProj;
559	LLVector2				mGIRange;
560	F32						mGILightRadius;
561	
562	LLPointer<LLDrawable>				mShadowSpotLight[2];
563	F32									mSpotLightFade[2];
564	LLPointer<LLDrawable>				mTargetShadowSpotLight[2];
565
566	LLVector4				mSunClipPlanes;
567	LLVector4				mSunOrthoClipPlanes;
568
569	LLVector2				mScreenScale;
570
571	//water reflection texture
572	LLRenderTarget				mWaterRef;
573
574	//water distortion texture (refraction)
575	LLRenderTarget				mWaterDis;
576
577	//texture for making the glow
578	LLRenderTarget				mGlow[3];
579
580	//noise map
581	U32					mNoiseMap;
582	U32					mTrueNoiseMap;
583	U32					mLightFunc;
584
585	LLColor4				mSunDiffuse;
586	LLVector3				mSunDir;
587	LLVector3				mTransformedSunDir;
588
589	BOOL					mInitialized;
590	BOOL					mVertexShadersEnabled;
591	S32						mVertexShadersLoaded; // 0 = no, 1 = yes, -1 = failed
592
593protected:
594	BOOL					mRenderTypeEnabled[NUM_RENDER_TYPES];
595	std::stack<std::string> mRenderTypeEnableStack;
596
597	U32						mRenderDebugFeatureMask;
598	U32						mRenderDebugMask;
599
600	U32						mOldRenderDebugMask;
601	
602	/////////////////////////////////////////////
603	//
604	//
605	LLDrawable::drawable_vector_t	mMovedList;
606	LLDrawable::drawable_vector_t mMovedBridge;
607	LLDrawable::drawable_vector_t	mShiftList;
608
609	/////////////////////////////////////////////
610	//
611	//
612	struct Light
613	{
614		Light(LLDrawable* ptr, F32 d, F32 f = 0.0f)
615			: drawable(ptr),
616			  dist(d),
617			  fade(f)
618		{}
619		LLPointer<LLDrawable> drawable;
620		F32 dist;
621		F32 fade;
622		struct compare
623		{
624			bool operator()(const Light& a, const Light& b) const
625			{
626				if ( a.dist < b.dist )
627					return true;
628				else if ( a.dist > b.dist )
629					return false;
630				else
631					return a.drawable < b.drawable;
632			}
633		};
634	};
635	typedef std::set< Light, Light::compare > light_set_t;
636	
637	LLDrawable::drawable_set_t		mLights;
638	light_set_t						mNearbyLights; // lights near camera
639	LLColor4						mHWLightColors[8];
640	
641	/////////////////////////////////////////////
642	//
643	// Different queues of drawables being processed.
644	//
645	LLDrawable::drawable_list_t 	mBuildQ1; // priority
646	LLDrawable::drawable_list_t 	mBuildQ2; // non-priority
647	LLSpatialGroup::sg_vector_t		mGroupQ1; //priority
648	LLSpatialGroup::sg_vector_t		mGroupQ2; // non-priority
649
650	LLDrawable::drawable_list_t		mPartitionQ; //drawables that need to update their spatial partition radius 
651
652	bool mGroupQ2Locked;
653	bool mGroupQ1Locked;
654
655	LLViewerObject::vobj_list_t		mCreateQ;
656		
657	LLDrawable::drawable_set_t		mRetexturedList;
658
659	class HighlightItem
660	{
661	public:
662		const LLPointer<LLDrawable> mItem;
663		mutable F32 mFade;
664
665		HighlightItem(LLDrawable* item)
666		: mItem(item), mFade(0)
667		{
668		}
669
670		bool operator<(const HighlightItem& rhs) const
671		{
672			return mItem < rhs.mItem;
673		}
674
675		bool operator==(const HighlightItem& rhs) const
676		{
677			return mItem == rhs.mItem;
678		}
679
680		void incrFade(F32 val) const
681		{
682			mFade = llclamp(mFade+val, 0.f, 1.f);
683		}
684	};
685
686	std::set<HighlightItem> mHighlightSet;
687	LLPointer<LLDrawable> mHighlightObject;
688
689	//////////////////////////////////////////////////
690	//
691	// Draw pools are responsible for storing all rendered data,
692	// and performing the actual rendering of objects.
693	//
694	struct compare_pools
695	{
696		bool operator()(const LLDrawPool* a, const LLDrawPool* b) const
697		{
698			if (!a)
699				return true;
700			else if (!b)
701				return false;
702			else
703			{
704				S32 atype = a->getType();
705				S32 btype = b->getType();
706				if (atype < btype)
707					return true;
708				else if (atype > btype)
709					return false;
710				else
711					return a->getId() < b->getId();
712			}
713		}
714	};
715 	typedef std::set<LLDrawPool*, compare_pools > pool_set_t;
716	pool_set_t mPools;
717	LLDrawPool*	mLastRebuildPool;
718	
719	// For quick-lookups into mPools (mapped by texture pointer)
720	std::map<uintptr_t, LLDrawPool*>	mTerrainPools;
721	std::map<uintptr_t, LLDrawPool*>	mTreePools;
722	LLDrawPool*					mAlphaPool;
723	LLDrawPool*					mSkyPool;
724	LLDrawPool*					mTerrainPool;
725	LLDrawPool*					mWaterPool;
726	LLDrawPool*					mGroundPool;
727	LLRenderPass*				mSimplePool;
728	LLRenderPass*				mGrassPool;
729	LLRenderPass*				mFullbrightPool;
730	LLDrawPool*					mInvisiblePool;
731	LLDrawPool*					mGlowPool;
732	LLDrawPool*					mBumpPool;
733	LLDrawPool*					mWLSkyPool;
734	// Note: no need to keep an quick-lookup to avatar pools, since there's only one per avatar
735	
736public:
737	std::vector<LLFace*>		mHighlightFaces;	// highlight faces on physical objects
738protected:
739	std::vector<LLFace*>		mSelectedFaces;
740
741	class DebugBlip
742	{
743	public:
744		LLColor4 mColor;
745		LLVector3 mPosition;
746		F32 mAge;
747
748		DebugBlip(const LLVector3& position, const LLColor4& color)
749			: mColor(color), mPosition(position), mAge(0.f)
750		{ }
751	};
752
753	std::list<DebugBlip> mDebugBlips;
754
755	LLPointer<LLViewerFetchedTexture>	mFaceSelectImagep;
756	
757	U32						mLightMask;
758	U32						mLightMovingMask;
759	S32						mLightingDetail;
760		
761	static BOOL				sRenderPhysicalBeacons;
762	static BOOL				sRenderMOAPBeacons;
763	static BOOL				sRenderScriptedTouchBeacons;
764	static BOOL				sRenderScriptedBeacons;
765	static BOOL				sRenderParticleBeacons;
766	static BOOL				sRenderSoundBeacons;
767public:
768	static BOOL				sRenderBeacons;
769	static BOOL				sRenderHighlight;
770
771	//debug use
772	static U32              sCurRenderPoolType ;
773
774	//cached settings
775	static BOOL WindLightUseAtmosShaders;
776	static BOOL VertexShaderEnable;
777	static BOOL RenderAvatarVP;
778	static BOOL RenderDeferred;
779	static F32 RenderDeferredSunWash;
780	static U32 RenderFSAASamples;
781	static U32 RenderResolutionDivisor;
782	static BOOL RenderUIBuffer;
783	static S32 RenderShadowDetail;
784	static BOOL RenderDeferredSSAO;
785	static F32 RenderShadowResolutionScale;
786	static BOOL RenderLocalLights;
787	static BOOL RenderDelayCreation;
788	static BOOL RenderAnimateRes;
789	static BOOL FreezeTime;
790	static S32 DebugBeaconLineWidth;
791	static F32 RenderHighlightBrightness;
792	static LLColor4 RenderHighlightColor;
793	static F32 RenderHighlightThickness;
794	static BOOL RenderSpotLightsInNondeferred;
795	static LLColor4 PreviewAmbientColor;
796	static LLColor4 PreviewDiffuse0;
797	static LLColor4 PreviewSpecular0;
798	static LLColor4 PreviewDiffuse1;
799	static LLColor4 PreviewSpecular1;
800	static LLColor4 PreviewDiffuse2;
801	static LLColor4 PreviewSpecular2;
802	static LLVector3 PreviewDirection0;
803	static LLVector3 PreviewDirection1;
804	static LLVector3 PreviewDirection2;
805	static F32 RenderGlowMinLuminance;
806	static F32 RenderGlowMaxExtractAlpha;
807	static F32 RenderGlowWarmthAmount;
808	static LLVector3 RenderGlowLumWeights;
809	static LLVector3 RenderGlowWarmthWeights;
810	static S32 RenderGlowResolutionPow;
811	static S32 RenderGlowIterations;
812	static F32 RenderGlowWidth;
813	static F32 RenderGlowStrength;
814	static BOOL RenderDepthOfField;
815	static F32 CameraFocusTransitionTime;
816	static F32 CameraFNumber;
817	static F32 CameraFocalLength;
818	static F32 CameraFieldOfView;
819	static F32 RenderShadowNoise;
820	static F32 RenderShadowBlurSize;
821	static F32 RenderSSAOScale;
822	static U32 RenderSSAOMaxScale;
823	static F32 RenderSSAOFactor;
824	static LLVector3 RenderSSAOEffect;
825	static F32 RenderShadowOffsetError;
826	static F32 RenderShadowBiasError;
827	static F32 RenderShadowOffset;
828	static F32 RenderShadowBias;
829	static F32 RenderSpotShadowOffset;
830	static F32 RenderSpotShadowBias;
831	static F32 RenderEdgeDepthCutoff;
832	static F32 RenderEdgeNormCutoff;
833	static LLVector3 RenderShadowGaussian;
834	static F32 RenderShadowBlurDistFactor;
835	static BOOL RenderDeferredAtmospheric;
836	static S32 RenderReflectionDetail;
837	static F32 RenderHighlightFadeTime;
838	static LLVector3 RenderShadowClipPlanes;
839	static LLVector3 RenderShadowOrthoClipPlanes;
840	static LLVector3 RenderShadowNearDist;
841	static F32 RenderFarClip;
842	static LLVector3 RenderShadowSplitExponent;
843	static F32 RenderShadowErrorCutoff;
844	static F32 RenderShadowFOVCutoff;
845	static BOOL CameraOffset;
846	static F32 CameraMaxCoF;
847	static F32 CameraDoFResScale;
848};
849
850void render_bbox(const LLVector3 &min, const LLVector3 &max);
851void render_hud_elements();
852
853extern LLPipeline gPipeline;
854extern BOOL gDebugPipeline;
855extern const LLMatrix4* gGLLastMatrix;
856
857#endif