00001
00032 #ifndef LL_PIPELINE_H
00033 #define LL_PIPELINE_H
00034
00035 #include "lldarrayptr.h"
00036 #include "lldqueueptr.h"
00037 #include "llstat.h"
00038 #include "lllinkedqueue.h"
00039 #include "llskiplist.h"
00040 #include "lldrawpool.h"
00041 #include "llspatialpartition.h"
00042 #include "m4math.h"
00043 #include "llmemory.h"
00044 #include "lldrawpool.h"
00045 #include "llgl.h"
00046
00047 class LLViewerImage;
00048 class LLDrawable;
00049 class LLEdge;
00050 class LLFace;
00051 class LLViewerObject;
00052 class LLAgent;
00053 class LLDisplayPrimitive;
00054 class LLTextureEntry;
00055 class LLRenderFunc;
00056 class LLCubeMap;
00057
00058 typedef enum e_avatar_skinning_method
00059 {
00060 SKIN_METHOD_SOFTWARE,
00061 SKIN_METHOD_VERTEX_PROGRAM
00062 } EAvatarSkinningMethod;
00063
00064 BOOL compute_min_max(LLMatrix4& box, LLVector2& min, LLVector2& max);
00065 bool LLRayAABB(const LLVector3 ¢er, const LLVector3 &size, const LLVector3& origin, const LLVector3& dir, LLVector3 &coord, F32 epsilon = 0);
00066 BOOL LLLineSegmentAABB(const LLVector3& start, const LLVector3& end, const LLVector3& center, const LLVector3& size);
00067 BOOL setup_hud_matrices(BOOL for_select);
00068
00069 class LLPipeline
00070 {
00071 public:
00072 LLPipeline();
00073 ~LLPipeline();
00074
00075 void destroyGL();
00076 void restoreGL();
00077 void resetVertexBuffers();
00078 void releaseGLBuffers();
00079 void resetVertexBuffers(LLDrawable* drawable);
00080 void setUseVBO(BOOL use_vbo);
00081 void generateReflectionMap(LLCubeMap* cube_map, LLCamera& camera, GLsizei res);
00082 void blurReflectionMap(LLCubeMap* cube_in, LLCubeMap* cube_out, U32 res);
00083 void bindScreenToTexture();
00084 void renderBloom(GLuint source, GLuint dest, GLuint buffer, U32 res, LLVector2 tc1, LLVector2 tc2);
00085
00086 void init();
00087 void cleanup();
00088
00091 LLDrawPool *findPool(const U32 pool_type, LLViewerImage *tex0 = NULL);
00092
00095 LLDrawPool *getPool(const U32 pool_type, LLViewerImage *tex0 = NULL);
00096
00098 static LLDrawPool* getPoolFromTE(const LLTextureEntry* te, LLViewerImage* te_image);
00099 static U32 getPoolTypeFromTE(const LLTextureEntry* te, LLViewerImage* imagep);
00100
00101 void addPool(LLDrawPool *poolp);
00102 void removePool( LLDrawPool* poolp );
00103
00104 void allocDrawable(LLViewerObject *obj);
00105
00106 void unlinkDrawable(LLDrawable*);
00107
00108
00109 void markVisible(LLDrawable *drawablep, LLCamera& camera);
00110 void doOcclusion(LLCamera& camera);
00111 void markNotCulled(LLSpatialGroup* group, LLCamera &camera, BOOL active = FALSE);
00112 void markMoved(LLDrawable *drawablep, BOOL damped_motion = FALSE);
00113 void markShift(LLDrawable *drawablep);
00114 void markTextured(LLDrawable *drawablep);
00115 void markRebuild(LLDrawable *drawablep, LLDrawable::EDrawableFlags flag = LLDrawable::REBUILD_ALL, BOOL priority = FALSE);
00116 void markRelight(LLDrawable *drawablep, const BOOL now = FALSE);
00117
00118
00119 LLViewerObject* pickObject(const LLVector3 &start, const LLVector3 &end, LLVector3 &collision);
00120
00121
00122 void dirtyPoolObjectTextures(const std::set<LLViewerImage*>& textures);
00123
00124 void resetDrawOrders();
00125
00126 U32 addObject(LLViewerObject *obj);
00127
00128 void enableShadows(const BOOL enable_shadows);
00129
00130
00131
00132 S32 setLightingDetail(S32 level);
00133 S32 getLightingDetail() const { return mLightingDetail; }
00134 S32 getMaxLightingDetail() const;
00135
00136 void setUseVertexShaders(BOOL use_shaders);
00137 BOOL getUseVertexShaders() const { return mVertexShadersEnabled; }
00138 BOOL canUseVertexShaders();
00139
00140
00141 void resetFrameStats();
00142
00143 void updateMoveDampedAsync(LLDrawable* drawablep);
00144 void updateMoveNormalAsync(LLDrawable* drawablep);
00145 void updateMovedList(LLDrawable::drawable_vector_t& move_list);
00146 void updateMove();
00147 void updateCull(LLCamera& camera);
00148 void updateGeom(F32 max_dtime);
00149
00150
00151 static F32 calcPixelArea(LLVector3 center, LLVector3 size, LLCamera& camera);
00152
00153 void stateSort(LLCamera& camera);
00154 void stateSort(LLSpatialGroup* group, LLCamera& camera);
00155 void stateSort(LLSpatialBridge* bridge, LLCamera& camera);
00156 void stateSort(LLDrawable* drawablep, LLCamera& camera);
00157 void postSort(LLCamera& camera);
00158 void forAllDrawables(LLSpatialGroup::sg_vector_t& groups, void (*func)(LLDrawable*));
00159 void forAllVisibleDrawables(void (*func)(LLDrawable*));
00160
00161 void renderObjects(U32 type, U32 mask, BOOL texture = TRUE);
00162
00163 void renderGeom(LLCamera& camera);
00164 void renderHighlights();
00165 void renderDebug();
00166 void processOcclusion(LLCamera& camera);
00167
00168 void renderForSelect(std::set<LLViewerObject*>& objects);
00169 void renderFaceForUVSelect(LLFace* facep);
00170 void rebuildPools();
00171
00172 void findReferences(LLDrawable *drawablep);
00173 BOOL verify();
00174
00175 S32 getVisibleCount() const { return mVisibleList.size(); }
00176 S32 getLightCount() const { return mLights.size(); }
00177
00178 void calcNearbyLights(LLCamera& camera);
00179 void setupHWLights(LLDrawPool* pool);
00180 void setupAvatarLights(BOOL for_edit = FALSE);
00181 void enableLights(U32 mask, F32 shadow_factor);
00182 void enableLightsStatic(F32 shadow_factor);
00183 void enableLightsDynamic(F32 shadow_factor);
00184 void enableLightsAvatar(F32 shadow_factor);
00185 void enableLightsAvatarEdit(const LLColor4& color);
00186 void enableLightsFullbright(const LLColor4& color);
00187 void disableLights();
00188 void setAmbient(const LLColor4& ambient);
00189
00190 void shiftObjects(const LLVector3 &offset);
00191
00192 void setLight(LLDrawable *drawablep, BOOL is_light);
00193 void setActive(LLDrawable *drawablep, BOOL active);
00194
00195 BOOL hasRenderType(const U32 type) const { return (type && (mRenderTypeMask & (1<<type))) ? TRUE : FALSE; }
00196 BOOL hasRenderDebugFeatureMask(const U32 mask) const { return (mRenderDebugFeatureMask & mask) ? TRUE : FALSE; }
00197 BOOL hasRenderFeatureMask(const U32 mask) const { return (mRenderFeatureMask & mask) ? TRUE : FALSE; }
00198 BOOL hasRenderDebugMask(const U32 mask) const { return (mRenderDebugMask & mask) ? TRUE : FALSE; }
00199 void setRenderTypeMask(const U32 mask) { mRenderTypeMask = mask; }
00200 U32 getRenderTypeMask() const { return mRenderTypeMask; }
00201 static void toggleRenderType(U32 type);
00202
00203
00204 static BOOL hasRenderTypeControl(void* data);
00205 static void toggleRenderDebug(void* data);
00206 static void toggleRenderDebugFeature(void* data);
00207 static void toggleRenderTypeControl(void* data);
00208 static BOOL toggleRenderTypeControlNegated(void* data);
00209 static BOOL toggleRenderDebugControl(void* data);
00210 static BOOL toggleRenderDebugFeatureControl(void* data);
00211
00212 static void setRenderParticleBeacons(BOOL val);
00213 static void toggleRenderParticleBeacons(void* data);
00214 static BOOL getRenderParticleBeacons(void* data);
00215
00216 static void setRenderSoundBeacons(BOOL val);
00217 static void toggleRenderSoundBeacons(void* data);
00218 static BOOL getRenderSoundBeacons(void* data);
00219
00220 static void setRenderPhysicalBeacons(BOOL val);
00221 static void toggleRenderPhysicalBeacons(void* data);
00222 static BOOL getRenderPhysicalBeacons(void* data);
00223
00224 static void setRenderScriptedBeacons(BOOL val);
00225 static void toggleRenderScriptedBeacons(void* data);
00226 static BOOL getRenderScriptedBeacons(void* data);
00227
00228 static void setRenderScriptedTouchBeacons(BOOL val);
00229 static void toggleRenderScriptedTouchBeacons(void* data);
00230 static BOOL getRenderScriptedTouchBeacons(void* data);
00231
00232 static void setRenderBeacons(BOOL val);
00233 static void toggleRenderBeacons(void* data);
00234 static BOOL getRenderBeacons(void* data);
00235
00236 static void setRenderHighlights(BOOL val);
00237 static void toggleRenderHighlights(void* data);
00238 static BOOL getRenderHighlights(void* data);
00239
00240 static BOOL getProcessBeacons(void* data);
00241
00242 private:
00243 void initShaders(BOOL force);
00244 void unloadShaders();
00245 BOOL loadShaders();
00246 void saveVertexShaderLevel(S32 type, S32 level, S32 max);
00247 void addToQuickLookup( LLDrawPool* new_poolp );
00248 void removeFromQuickLookup( LLDrawPool* poolp );
00249 BOOL updateDrawableGeom(LLDrawable* drawable, BOOL priority);
00250
00251 public:
00252 enum {GPU_CLASS_MAX = 3 };
00253
00254 enum LLRenderTypeMask
00255 {
00256
00257 RENDER_TYPE_SKY = LLDrawPool::POOL_SKY,
00258 RENDER_TYPE_STARS = LLDrawPool::POOL_STARS,
00259 RENDER_TYPE_GROUND = LLDrawPool::POOL_GROUND,
00260 RENDER_TYPE_TERRAIN = LLDrawPool::POOL_TERRAIN,
00261 RENDER_TYPE_SIMPLE = LLDrawPool::POOL_SIMPLE,
00262 RENDER_TYPE_BUMP = LLDrawPool::POOL_BUMP,
00263 RENDER_TYPE_AVATAR = LLDrawPool::POOL_AVATAR,
00264 RENDER_TYPE_TREE = LLDrawPool::POOL_TREE,
00265 RENDER_TYPE_WATER = LLDrawPool::POOL_WATER,
00266 RENDER_TYPE_ALPHA = LLDrawPool::POOL_ALPHA,
00267 RENDER_TYPE_GLOW = LLDrawPool::POOL_GLOW,
00268
00269
00270 RENDER_TYPE_HUD = LLDrawPool::NUM_POOL_TYPES,
00271 RENDER_TYPE_VOLUME,
00272 RENDER_TYPE_GRASS,
00273 RENDER_TYPE_PARTICLES,
00274 RENDER_TYPE_CLOUDS,
00275 };
00276
00277 enum LLRenderDebugFeatureMask
00278 {
00279 RENDER_DEBUG_FEATURE_UI = 0x0001,
00280 RENDER_DEBUG_FEATURE_SELECTED = 0x0002,
00281 RENDER_DEBUG_FEATURE_HIGHLIGHTED = 0x0004,
00282 RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES = 0x0008,
00283
00284 RENDER_DEBUG_FEATURE_FLEXIBLE = 0x0010,
00285 RENDER_DEBUG_FEATURE_FOG = 0x0020,
00286 RENDER_DEBUG_FEATURE_PALETTE = 0x0040,
00287 RENDER_DEBUG_FEATURE_FR_INFO = 0x0080,
00288 RENDER_DEBUG_FEATURE_FOOT_SHADOWS = 0x0100,
00289 };
00290
00291 enum LLRenderFeatureMask
00292 {
00293 RENDER_FEATURE_LOCAL_LIGHTING = 0x02,
00294 RENDER_FEATURE_OBJECT_BUMP = 0x04,
00295 RENDER_FEATURE_AVATAR_BUMP = 0x08,
00296
00297 RENDER_FEATURE_RIPPLE_WATER = 0X20
00298 };
00299
00300 enum LLRenderDebugMask
00301 {
00302 RENDER_DEBUG_LIGHT_TRACE = 0x00001,
00303 RENDER_DEBUG_COMPOSITION = 0x00020,
00304 RENDER_DEBUG_VERIFY = 0x00080,
00305 RENDER_DEBUG_SHADOW_MAP = 0x00100,
00306 RENDER_DEBUG_BBOXES = 0x00200,
00307 RENDER_DEBUG_OCTREE = 0x00400,
00308 RENDER_DEBUG_PICKING = 0x00800,
00309 RENDER_DEBUG_OCCLUSION = 0x01000,
00310 RENDER_DEBUG_POINTS = 0x02000,
00311 RENDER_DEBUG_TEXTURE_PRIORITY = 0x04000,
00312 RENDER_DEBUG_TEXTURE_AREA = 0x08000,
00313 RENDER_DEBUG_FACE_AREA = 0x10000,
00314 RENDER_DEBUG_PARTICLES = 0x20000,
00315 RENDER_DEBUG_GLOW = 0x40000,
00316 RENDER_DEBUG_TEXTURE_ANIM = 0x80000,
00317 };
00318
00319 LLPointer<LLViewerImage> mAlphaSizzleImagep;
00320
00321
00322 typedef enum
00323 {
00324 PARTITION_VOLUME = 0,
00325 PARTITION_BRIDGE,
00326 PARTITION_HUD,
00327 PARTITION_TERRAIN,
00328 PARTITION_WATER,
00329 PARTITION_TREE,
00330 PARTITION_PARTICLE,
00331 PARTITION_CLOUD,
00332 PARTITION_GRASS,
00333 PARTITION_NONE,
00334 NUM_PARTITIONS
00335 } eObjectPartitions;
00336
00337 private:
00338 std::vector<LLSpatialPartition*> mObjectPartition;
00339 public:
00340
00341 LLSpatialPartition* getSpatialPartition(LLViewerObject* vobj);
00342 LLSpatialPartition* getSpatialPartition(U32 index);
00343
00344 void updateCamera(BOOL reset = FALSE);
00345
00346 LLVector3 mFlyCamPosition;
00347 LLQuaternion mFlyCamRotation;
00348
00349 BOOL mBackfaceCull;
00350 S32 mTrianglesDrawn;
00351 LLStat mTrianglesDrawnStat;
00352 S32 mVerticesRelit;
00353
00354 S32 mLightingChanges;
00355 S32 mGeometryChanges;
00356
00357 S32 mNumVisibleFaces;
00358
00359 static S32 sCompiles;
00360
00361 static BOOL sShowHUDAttachments;
00362 static BOOL sUseOcclusion;
00363 static BOOL sSkipUpdate;
00364 static BOOL sDynamicReflections;
00365 static BOOL sRenderGlow;
00366
00367
00368 GLuint mScreenTex;
00369 LLVector2 mScreenScale;
00370
00371
00372 GLuint mGlowMap;
00373 GLuint mGlowBuffer;
00374
00375
00376 GLuint mFramebuffer[2];
00377
00378
00379 LLPointer<LLCubeMap> mCubeBuffer;
00380
00381
00382 GLuint mCubeFrameBuffer;
00383
00384
00385 GLuint mCubeDepth;
00386
00387
00388 LLColor4 mSunDiffuse;
00389 LLVector3 mSunDir;
00390
00391 LLSpatialGroup::sg_vector_t mActiveGroups;
00392 LLSpatialGroup::drawmap_elem_t mRenderMap[LLRenderPass::NUM_RENDER_TYPES];
00393 std::vector<LLSpatialGroup* > mAlphaGroups;
00394 std::vector<LLSpatialGroup* > mAlphaGroupsPostWater;
00395 LLSpatialGroup::sg_vector_t mVisibleGroups;
00396 LLSpatialGroup::sg_vector_t mDrawableGroups;
00397
00398 void clearRenderMap();
00399
00400 BOOL mInitialized;
00401 BOOL mVertexShadersEnabled;
00402 S32 mVertexShadersLoaded;
00403
00404 protected:
00405 U32 mRenderTypeMask;
00406 U32 mRenderFeatureMask;
00407 U32 mRenderDebugFeatureMask;
00408 U32 mRenderDebugMask;
00409
00410 U32 mOldRenderDebugMask;
00411
00413
00414
00415 LLDrawable::drawable_vector_t mVisibleList;
00416 LLSpatialBridge::bridge_vector_t mVisibleBridge;
00417 LLSpatialBridge::bridge_vector_t mOccludedBridge;
00418 LLDrawable::drawable_vector_t mMovedList;
00419 LLDrawable::drawable_vector_t mMovedBridge;
00420 LLDrawable::drawable_vector_t mShiftList;
00421
00423
00424
00425 struct Light
00426 {
00427 Light(LLDrawable* ptr, F32 d, F32 f = 0.0f)
00428 : drawable(ptr),
00429 dist(d),
00430 fade(f)
00431 {}
00432 LLPointer<LLDrawable> drawable;
00433 F32 dist;
00434 F32 fade;
00435 struct compare
00436 {
00437 bool operator()(const Light& a, const Light& b) const
00438 {
00439 if ( a.dist < b.dist )
00440 return true;
00441 else if ( a.dist > b.dist )
00442 return false;
00443 else
00444 return a.drawable < b.drawable;
00445 }
00446 };
00447 };
00448 typedef std::set< Light, Light::compare > light_set_t;
00449
00450 LLDrawable::drawable_set_t mLights;
00451 light_set_t mNearbyLights;
00452 LLColor4 mHWLightColors[8];
00453
00455
00456
00457
00458 LLDrawable::drawable_list_t mBuildQ1;
00459 LLDrawable::drawable_list_t mBuildQ2;
00460
00461 LLDrawable::drawable_set_t mActiveQ;
00462
00463 LLDrawable::drawable_set_t mRetexturedList;
00464
00466
00467
00468
00469
00470 struct compare_pools
00471 {
00472 bool operator()(const LLDrawPool* a, const LLDrawPool* b) const
00473 {
00474 if (!a)
00475 return true;
00476 else if (!b)
00477 return false;
00478 else
00479 {
00480 S32 atype = a->getType();
00481 S32 btype = b->getType();
00482 if (atype < btype)
00483 return true;
00484 else if (atype > btype)
00485 return false;
00486 else
00487 return a->getId() < b->getId();
00488 }
00489 }
00490 };
00491 typedef std::set<LLDrawPool*, compare_pools > pool_set_t;
00492 pool_set_t mPools;
00493 LLDrawPool* mLastRebuildPool;
00494
00495
00496 std::map<uintptr_t, LLDrawPool*> mTerrainPools;
00497 std::map<uintptr_t, LLDrawPool*> mTreePools;
00498 LLDrawPool* mAlphaPool;
00499 LLDrawPool* mAlphaPoolPostWater;
00500 LLDrawPool* mSkyPool;
00501 LLDrawPool* mStarsPool;
00502 LLDrawPool* mTerrainPool;
00503 LLDrawPool* mWaterPool;
00504 LLDrawPool* mGroundPool;
00505 LLRenderPass* mSimplePool;
00506 LLDrawPool* mGlowPool;
00507 LLDrawPool* mBumpPool;
00508
00509
00510 public:
00511 std::vector<LLFace*> mHighlightFaces;
00512 protected:
00513 std::vector<LLFace*> mSelectedFaces;
00514
00515 LLPointer<LLViewerImage> mFaceSelectImagep;
00516 LLPointer<LLViewerImage> mBloomImagep;
00517 LLPointer<LLViewerImage> mBloomImage2p;
00518
00519 U32 mLightMask;
00520 U32 mLightMovingMask;
00521 S32 mLightingDetail;
00522 F32 mSunShadowFactor;
00523
00524 static BOOL sRenderPhysicalBeacons;
00525 static BOOL sRenderScriptedTouchBeacons;
00526 static BOOL sRenderScriptedBeacons;
00527 static BOOL sRenderParticleBeacons;
00528 static BOOL sRenderSoundBeacons;
00529 public:
00530 static BOOL sRenderBeacons;
00531 static BOOL sRenderHighlight;
00532 static BOOL sRenderProcessBeacons;
00533 };
00534
00535 void render_bbox(const LLVector3 &min, const LLVector3 &max);
00536
00537 extern LLPipeline gPipeline;
00538 extern BOOL gRenderForSelect;
00539
00540 #endif