lldrawpool.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /**
  2. * @file lldrawpool.h
  3. * @brief LLDrawPool class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLDRAWPOOL_H
  33. #define LL_LLDRAWPOOL_H
  34. #include "llcolor4u.h"
  35. #include "llvector2.h"
  36. #include "llvector3.h"
  37. #include "llvertexbuffer.h"
  38. #include "llviewertexturelist.h"
  39. class LLDrawInfo;
  40. class LLFace;
  41. class LLMatrix4;
  42. class LLMeshSkinInfo;
  43. class LLSpatialGroup;
  44. class LLViewerTexture;
  45. class LLViewerFetchedTexture;
  46. class LLVOAvatar;
  47. class LLDrawPool
  48. {
  49. protected:
  50. LOG_CLASS(LLDrawPool);
  51. public:
  52. enum : U32
  53. {
  54. // Correspond to LLPipeline render type (and to gPoolNames).
  55. // Also controls render order, so passes that do not use alpha masking
  56. // or blending should come before other passes to preserve hierarchical
  57. // Z for occlusion queries. Occlusion queries happen just before grass,
  58. // so grass should be the first alpha masked pool. Other ordering
  59. // should be done based on fill rate and likelihood to occlude future
  60. // passes (faster, large occluders first).
  61. POOL_SKY = 1,
  62. POOL_WL_SKY,
  63. POOL_SIMPLE,
  64. POOL_FULLBRIGHT,
  65. POOL_BUMP,
  66. POOL_MATERIALS,
  67. POOL_MAT_PBR, // PBR only
  68. POOL_TERRAIN,
  69. POOL_GRASS,
  70. POOL_MAT_PBR_ALPHA_MASK, // PBR only
  71. POOL_TREE,
  72. POOL_ALPHA_MASK,
  73. POOL_FULLBRIGHT_ALPHA_MASK,
  74. POOL_INVISIBLE, // EE only (*)
  75. POOL_AVATAR,
  76. POOL_PUPPET, // Animesh
  77. POOL_GLOW,
  78. POOL_ALPHA_PRE_WATER, // PBR only
  79. POOL_VOIDWATER,
  80. POOL_WATER,
  81. POOL_ALPHA_POST_WATER, // PBR only
  82. // Note: for PBR, there is no actual "POOL_ALPHA" but pre-water and
  83. // post-water pools consume POOL_ALPHA faces.
  84. POOL_ALPHA,
  85. NUM_POOL_TYPES,
  86. // (*) Invisiprims work by rendering to the depth buffer but not the
  87. // color buffer, occluding anything rendered after them and the
  88. // LLDrawPool types enum controls what order things are rendered
  89. // in so, it has absolute control over what invisprims block,
  90. // invisiprims being rendered in pool_invisible shiny/bump mapped
  91. // objects in rendered in POOL_BUMP.
  92. };
  93. LLDrawPool(U32 type);
  94. virtual ~LLDrawPool() = default;
  95. virtual bool isDead() = 0;
  96. LL_INLINE S32 getId() const { return mId; }
  97. LL_INLINE U32 getType() const { return mType; }
  98. LL_INLINE S32 getShaderLevel() const { return mShaderLevel; }
  99. // No more in use with the PBR renderer
  100. virtual U32 getVertexDataMask() = 0;
  101. virtual void prerender() {}
  102. // Unless overridden, returns 1 in EE rendering mode and 0 in PBR mode
  103. // (no forward rendering available for the latter). HB
  104. virtual S32 getNumPasses();
  105. LL_INLINE virtual void beginRenderPass(S32 pass) {}
  106. virtual void endRenderPass(S32 pass);
  107. virtual void render(S32 pass = 0) {}
  108. LL_INLINE virtual S32 getNumDeferredPasses() { return 0; }
  109. LL_INLINE virtual void beginDeferredPass(S32 pass) {}
  110. LL_INLINE virtual void endDeferredPass(S32 pass) {}
  111. LL_INLINE virtual void renderDeferred(S32 pass = 0) {}
  112. LL_INLINE virtual S32 getNumPostDeferredPasses() { return 0; }
  113. LL_INLINE virtual void beginPostDeferredPass(S32 pass) {}
  114. LL_INLINE virtual void endPostDeferredPass(S32 pass) {}
  115. LL_INLINE virtual void renderPostDeferred(S32 p = 0) {}
  116. LL_INLINE virtual S32 getNumShadowPasses() { return 0; }
  117. LL_INLINE virtual void beginShadowPass(S32 pass) {}
  118. LL_INLINE virtual void endShadowPass(S32 pass) {}
  119. LL_INLINE virtual void renderShadow(S32 pass = 0) {}
  120. // Verifies that all data in the draw pool is correct.
  121. LL_INLINE virtual bool verify() const { return true; }
  122. LL_INLINE virtual bool isFacePool() { return false; }
  123. LL_INLINE virtual bool isTerrainPool() { return false; }
  124. // Overridden in LLDrawPoolTerrain and LLDrawPoolTree.
  125. virtual LLViewerTexture* getTexture() { return NULL; }
  126. // Overridden in LLFacePool only.
  127. virtual void pushFaceGeometry() {}
  128. virtual void resetDrawOrders() {}
  129. static LLDrawPool* createPool(U32 type, LLViewerTexture* tex0p = NULL);
  130. protected:
  131. U32 mType; // Type of draw pool
  132. S32 mId;
  133. S32 mShaderLevel;
  134. private:
  135. static S32 sNumDrawPools;
  136. };
  137. class LLRenderPass : public LLDrawPool
  138. {
  139. public:
  140. // List of possible LLRenderPass types to assign a render batch to.
  141. // IMPORTANT: the "rigged" variant MUST be non-rigged variant + 1 !
  142. enum : U32
  143. {
  144. PASS_SIMPLE = NUM_POOL_TYPES,
  145. PASS_SIMPLE_RIGGED,
  146. PASS_GRASS,
  147. PASS_FULLBRIGHT,
  148. PASS_FULLBRIGHT_RIGGED,
  149. PASS_INVISIBLE,
  150. PASS_INVISIBLE_RIGGED,
  151. PASS_INVISI_SHINY,
  152. PASS_INVISI_SHINY_RIGGED,
  153. PASS_FULLBRIGHT_SHINY,
  154. PASS_FULLBRIGHT_SHINY_RIGGED,
  155. PASS_SHINY,
  156. PASS_SHINY_RIGGED,
  157. PASS_BUMP,
  158. PASS_BUMP_RIGGED,
  159. PASS_POST_BUMP,
  160. PASS_POST_BUMP_RIGGED,
  161. PASS_MATERIAL,
  162. PASS_MATERIAL_RIGGED,
  163. PASS_MATERIAL_ALPHA,
  164. PASS_MATERIAL_ALPHA_RIGGED,
  165. PASS_MATERIAL_ALPHA_MASK,
  166. PASS_MATERIAL_ALPHA_MASK_RIGGED,
  167. PASS_MATERIAL_ALPHA_EMISSIVE,
  168. PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED,
  169. PASS_SPECMAP,
  170. PASS_SPECMAP_RIGGED,
  171. PASS_SPECMAP_BLEND,
  172. PASS_SPECMAP_BLEND_RIGGED,
  173. PASS_SPECMAP_MASK,
  174. PASS_SPECMAP_MASK_RIGGED,
  175. PASS_SPECMAP_EMISSIVE,
  176. PASS_SPECMAP_EMISSIVE_RIGGED,
  177. PASS_NORMMAP,
  178. PASS_NORMMAP_RIGGED,
  179. PASS_NORMMAP_BLEND,
  180. PASS_NORMMAP_BLEND_RIGGED,
  181. PASS_NORMMAP_MASK,
  182. PASS_NORMMAP_MASK_RIGGED,
  183. PASS_NORMMAP_EMISSIVE,
  184. PASS_NORMMAP_EMISSIVE_RIGGED,
  185. PASS_NORMSPEC,
  186. PASS_NORMSPEC_RIGGED,
  187. PASS_NORMSPEC_BLEND,
  188. PASS_NORMSPEC_BLEND_RIGGED,
  189. PASS_NORMSPEC_MASK,
  190. PASS_NORMSPEC_MASK_RIGGED,
  191. PASS_NORMSPEC_EMISSIVE,
  192. PASS_NORMSPEC_EMISSIVE_RIGGED,
  193. PASS_GLOW,
  194. PASS_GLOW_RIGGED,
  195. PASS_PBR_GLOW,
  196. PASS_PBR_GLOW_RIGGED,
  197. PASS_ALPHA,
  198. PASS_ALPHA_RIGGED,
  199. PASS_ALPHA_MASK,
  200. PASS_ALPHA_MASK_RIGGED,
  201. PASS_FULLBRIGHT_ALPHA_MASK,
  202. PASS_FULLBRIGHT_ALPHA_MASK_RIGGED,
  203. PASS_ALPHA_INVISIBLE,
  204. PASS_ALPHA_INVISIBLE_RIGGED,
  205. PASS_MAT_PBR,
  206. PASS_MAT_PBR_RIGGED,
  207. PASS_MAT_PBR_ALPHA_MASK,
  208. PASS_MAT_PBR_ALPHA_MASK_RIGGED,
  209. NUM_RENDER_TYPES,
  210. };
  211. LL_INLINE LLRenderPass(U32 type)
  212. : LLDrawPool(type)
  213. {
  214. }
  215. LL_INLINE bool isDead() override { return false; }
  216. // NOTE: in the following methods, the 'mask' parameter is ignored for the
  217. // PBR renderer. I kept them "as is" to avoid duplicating too much code for
  218. // the dual EE-PBR renderer. HB
  219. void pushBatches(U32 type, U32 mask, bool texture = true,
  220. bool batch_textures = false);
  221. void pushRiggedBatches(U32 type, U32 mask, bool texture = true,
  222. bool batch_textures = false);
  223. void pushMaskBatches(U32 type, U32 mask, bool texture = true,
  224. bool batch_textures = false);
  225. void pushRiggedMaskBatches(U32 type, U32 mask, bool texture = true,
  226. bool batch_textures = false);
  227. // Overridden in LLDrawPoolBump only. HB
  228. virtual void pushBatch(LLDrawInfo& params, U32 mask, bool texture,
  229. bool batch_textures = false);
  230. // For PBR rendering
  231. static void pushUntexturedBatches(U32 type);
  232. static void pushUntexturedRiggedBatches(U32 type);
  233. static void pushUntexturedBatch(LLDrawInfo& params);
  234. static void pushGLTFBatches(U32 type);
  235. static void pushGLTFBatch(LLDrawInfo& params);
  236. // Like pushGLTFBatches, but will not bind textures or set up texture
  237. // transforms.
  238. static void pushUntexturedGLTFBatches(U32 type);
  239. // Rigged variants of above
  240. static void pushRiggedGLTFBatches(U32 type);
  241. static void pushUntexturedGLTFBatch(LLDrawInfo& params);
  242. static void pushUntexturedRiggedGLTFBatches(U32 type);
  243. // Helper methods for dispatching to textured or untextured pass based on
  244. // boolean 'textured' (declared const and methods inlined to try and hint
  245. // the compiler to optimize it out - HB).
  246. LL_INLINE static void pushGLTFBatches(U32 type, const bool textured)
  247. {
  248. if (textured)
  249. {
  250. pushGLTFBatches(type);
  251. }
  252. else
  253. {
  254. pushUntexturedGLTFBatches(type);
  255. }
  256. }
  257. LL_INLINE static void pushRiggedGLTFBatches(U32 type, const bool textured)
  258. {
  259. if (textured)
  260. {
  261. pushRiggedGLTFBatches(type);
  262. }
  263. else
  264. {
  265. pushUntexturedRiggedGLTFBatches(type);
  266. }
  267. }
  268. virtual void renderGroup(LLSpatialGroup* groupp, U32 type, U32 mask,
  269. bool texture = true);
  270. virtual void renderRiggedGroup(LLSpatialGroup* groupp, U32 type, U32 mask,
  271. bool texture = true);
  272. static void applyModelMatrix(LLDrawInfo& params);
  273. // For rendering that does not use LLDrawInfo for some reason.
  274. static void applyModelMatrix(const LLMatrix4* model_matp);
  275. static bool uploadMatrixPalette(const LLDrawInfo& params);
  276. static bool uploadMatrixPalette(LLVOAvatar* avp, LLMeshSkinInfo* skinp);
  277. };
  278. class LLFacePool : public LLDrawPool
  279. {
  280. protected:
  281. LOG_CLASS(LLFacePool);
  282. public:
  283. typedef std::vector<LLFace*> face_vec_t;
  284. enum
  285. {
  286. SHADER_LEVEL_SCATTERING = 2
  287. };
  288. public:
  289. LLFacePool(U32 type);
  290. ~LLFacePool() override;
  291. LL_INLINE bool isDead() override { return mReferences.empty(); }
  292. virtual void enqueue(LLFace* facep);
  293. virtual bool addFace(LLFace* facep);
  294. virtual bool removeFace(LLFace* facep);
  295. // Verifies that all data in the draw pool is correct.
  296. bool verify() const override;
  297. void pushFaceGeometry() override;
  298. void resetDrawOrders() override;
  299. void resetAll();
  300. void destroy();
  301. void buildEdges();
  302. void addFaceReference(LLFace* facep);
  303. void removeFaceReference(LLFace* facep);
  304. void printDebugInfo() const;
  305. LL_INLINE bool isFacePool() override { return true; }
  306. friend class LLFace;
  307. friend class LLPipeline;
  308. public:
  309. face_vec_t mDrawFace;
  310. face_vec_t mMoveFace;
  311. face_vec_t mReferences;
  312. public:
  313. class LLOverrideFaceColor
  314. {
  315. public:
  316. LL_INLINE LLOverrideFaceColor(LLDrawPool* pool)
  317. : mOverride(sOverrideFaceColor),
  318. mPool(pool)
  319. {
  320. sOverrideFaceColor = true;
  321. }
  322. LL_INLINE LLOverrideFaceColor(LLDrawPool* pool, const LLColor4& color)
  323. : mOverride(sOverrideFaceColor),
  324. mPool(pool)
  325. {
  326. sOverrideFaceColor = true;
  327. setColor(color);
  328. }
  329. LL_INLINE LLOverrideFaceColor(LLDrawPool* pool, const LLColor4U& color)
  330. : mOverride(sOverrideFaceColor),
  331. mPool(pool)
  332. {
  333. sOverrideFaceColor = true;
  334. setColor(color);
  335. }
  336. LL_INLINE LLOverrideFaceColor(LLDrawPool* pool,
  337. F32 r, F32 g, F32 b, F32 a)
  338. : mOverride(sOverrideFaceColor),
  339. mPool(pool)
  340. {
  341. sOverrideFaceColor = true;
  342. setColor(r, g, b, a);
  343. }
  344. LL_INLINE ~LLOverrideFaceColor()
  345. {
  346. sOverrideFaceColor = mOverride;
  347. }
  348. void setColor(const LLColor4& color);
  349. void setColor(const LLColor4U& color);
  350. void setColor(F32 r, F32 g, F32 b, F32 a);
  351. public:
  352. LLDrawPool* mPool;
  353. bool mOverride;
  354. static bool sOverrideFaceColor;
  355. };
  356. };
  357. #endif //LL_LLDRAWPOOL_H