PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewershadermgr.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 349 lines | 254 code | 54 blank | 41 comment | 6 complexity | 88b0037c686fa488422d533a734906e4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewershadermgr.h
  3. * @brief Viewer Shader Manager
  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. #ifndef LL_VIEWER_SHADER_MGR_H
  27. #define LL_VIEWER_SHADER_MGR_H
  28. #include "llshadermgr.h"
  29. class LLViewerShaderMgr: public LLShaderMgr
  30. {
  31. public:
  32. static BOOL sInitialized;
  33. static bool sSkipReload;
  34. LLViewerShaderMgr();
  35. /* virtual */ ~LLViewerShaderMgr();
  36. // singleton pattern implementation
  37. static LLViewerShaderMgr * instance();
  38. void initAttribsAndUniforms(void);
  39. void setShaders();
  40. void unloadShaders();
  41. S32 getVertexShaderLevel(S32 type);
  42. BOOL loadBasicShaders();
  43. BOOL loadShadersEffects();
  44. BOOL loadShadersDeferred();
  45. BOOL loadShadersObject();
  46. BOOL loadShadersAvatar();
  47. BOOL loadShadersEnvironment();
  48. BOOL loadShadersWater();
  49. BOOL loadShadersInterface();
  50. BOOL loadShadersWindLight();
  51. std::vector<S32> mVertexShaderLevel;
  52. S32 mMaxAvatarShaderLevel;
  53. enum EShaderClass
  54. {
  55. SHADER_LIGHTING,
  56. SHADER_OBJECT,
  57. SHADER_AVATAR,
  58. SHADER_ENVIRONMENT,
  59. SHADER_INTERFACE,
  60. SHADER_EFFECT,
  61. SHADER_WINDLIGHT,
  62. SHADER_WATER,
  63. SHADER_DEFERRED,
  64. SHADER_COUNT
  65. };
  66. typedef enum
  67. {
  68. SHINY_ORIGIN = END_RESERVED_UNIFORMS
  69. } eShinyUniforms;
  70. typedef enum
  71. {
  72. WATER_SCREENTEX = END_RESERVED_UNIFORMS,
  73. WATER_SCREENDEPTH,
  74. WATER_REFTEX,
  75. WATER_EYEVEC,
  76. WATER_TIME,
  77. WATER_WAVE_DIR1,
  78. WATER_WAVE_DIR2,
  79. WATER_LIGHT_DIR,
  80. WATER_SPECULAR,
  81. WATER_SPECULAR_EXP,
  82. WATER_FOGCOLOR,
  83. WATER_FOGDENSITY,
  84. WATER_REFSCALE,
  85. WATER_WATERHEIGHT,
  86. } eWaterUniforms;
  87. typedef enum
  88. {
  89. WL_CAMPOSLOCAL = END_RESERVED_UNIFORMS,
  90. WL_WATERHEIGHT
  91. } eWLUniforms;
  92. typedef enum
  93. {
  94. TERRAIN_DETAIL0 = END_RESERVED_UNIFORMS,
  95. TERRAIN_DETAIL1,
  96. TERRAIN_DETAIL2,
  97. TERRAIN_DETAIL3,
  98. TERRAIN_ALPHARAMP
  99. } eTerrainUniforms;
  100. typedef enum
  101. {
  102. GLOW_DELTA = END_RESERVED_UNIFORMS
  103. } eGlowUniforms;
  104. typedef enum
  105. {
  106. AVATAR_MATRIX = END_RESERVED_UNIFORMS,
  107. AVATAR_WIND,
  108. AVATAR_SINWAVE,
  109. AVATAR_GRAVITY,
  110. } eAvatarUniforms;
  111. // simple model of forward iterator
  112. // http://www.sgi.com/tech/stl/ForwardIterator.html
  113. class shader_iter
  114. {
  115. private:
  116. friend bool operator == (shader_iter const & a, shader_iter const & b);
  117. friend bool operator != (shader_iter const & a, shader_iter const & b);
  118. typedef std::vector<LLGLSLShader *>::const_iterator base_iter_t;
  119. public:
  120. shader_iter()
  121. {
  122. }
  123. shader_iter(base_iter_t iter) : mIter(iter)
  124. {
  125. }
  126. LLGLSLShader & operator * () const
  127. {
  128. return **mIter;
  129. }
  130. LLGLSLShader * operator -> () const
  131. {
  132. return *mIter;
  133. }
  134. shader_iter & operator++ ()
  135. {
  136. ++mIter;
  137. return *this;
  138. }
  139. shader_iter operator++ (int)
  140. {
  141. return mIter++;
  142. }
  143. private:
  144. base_iter_t mIter;
  145. };
  146. shader_iter beginShaders() const;
  147. shader_iter endShaders() const;
  148. /* virtual */ std::string getShaderDirPrefix(void);
  149. /* virtual */ void updateShaderUniforms(LLGLSLShader * shader);
  150. private:
  151. std::vector<std::string> mShinyUniforms;
  152. //water parameters
  153. std::vector<std::string> mWaterUniforms;
  154. std::vector<std::string> mWLUniforms;
  155. //terrain parameters
  156. std::vector<std::string> mTerrainUniforms;
  157. //glow parameters
  158. std::vector<std::string> mGlowUniforms;
  159. std::vector<std::string> mGlowExtractUniforms;
  160. std::vector<std::string> mAvatarUniforms;
  161. // the list of shaders we need to propagate parameters to.
  162. std::vector<LLGLSLShader *> mShaderList;
  163. }; //LLViewerShaderMgr
  164. inline bool operator == (LLViewerShaderMgr::shader_iter const & a, LLViewerShaderMgr::shader_iter const & b)
  165. {
  166. return a.mIter == b.mIter;
  167. }
  168. inline bool operator != (LLViewerShaderMgr::shader_iter const & a, LLViewerShaderMgr::shader_iter const & b)
  169. {
  170. return a.mIter != b.mIter;
  171. }
  172. extern LLVector4 gShinyOrigin;
  173. //utility shaders
  174. extern LLGLSLShader gOcclusionProgram;
  175. extern LLGLSLShader gCustomAlphaProgram;
  176. extern LLGLSLShader gGlowCombineProgram;
  177. extern LLGLSLShader gSplatTextureRectProgram;
  178. extern LLGLSLShader gGlowCombineFXAAProgram;
  179. extern LLGLSLShader gDebugProgram;
  180. extern LLGLSLShader gAlphaMaskProgram;
  181. //output tex0[tc0] + tex1[tc1]
  182. extern LLGLSLShader gTwoTextureAddProgram;
  183. extern LLGLSLShader gOneTextureNoColorProgram;
  184. //object shaders
  185. extern LLGLSLShader gObjectSimpleProgram;
  186. extern LLGLSLShader gObjectPreviewProgram;
  187. extern LLGLSLShader gObjectSimpleAlphaMaskProgram;
  188. extern LLGLSLShader gObjectSimpleWaterProgram;
  189. extern LLGLSLShader gObjectSimpleWaterAlphaMaskProgram;
  190. extern LLGLSLShader gObjectSimpleNonIndexedProgram;
  191. extern LLGLSLShader gObjectSimpleNonIndexedTexGenProgram;
  192. extern LLGLSLShader gObjectSimpleNonIndexedTexGenWaterProgram;
  193. extern LLGLSLShader gObjectSimpleNonIndexedWaterProgram;
  194. extern LLGLSLShader gObjectAlphaMaskNonIndexedProgram;
  195. extern LLGLSLShader gObjectAlphaMaskNonIndexedWaterProgram;
  196. extern LLGLSLShader gObjectAlphaMaskNoColorProgram;
  197. extern LLGLSLShader gObjectAlphaMaskNoColorWaterProgram;
  198. extern LLGLSLShader gObjectFullbrightProgram;
  199. extern LLGLSLShader gObjectFullbrightWaterProgram;
  200. extern LLGLSLShader gObjectFullbrightNoColorProgram;
  201. extern LLGLSLShader gObjectFullbrightNoColorWaterProgram;
  202. extern LLGLSLShader gObjectEmissiveProgram;
  203. extern LLGLSLShader gObjectEmissiveWaterProgram;
  204. extern LLGLSLShader gObjectFullbrightAlphaMaskProgram;
  205. extern LLGLSLShader gObjectFullbrightWaterAlphaMaskProgram;
  206. extern LLGLSLShader gObjectFullbrightNonIndexedProgram;
  207. extern LLGLSLShader gObjectFullbrightNonIndexedWaterProgram;
  208. extern LLGLSLShader gObjectEmissiveNonIndexedProgram;
  209. extern LLGLSLShader gObjectEmissiveNonIndexedWaterProgram;
  210. extern LLGLSLShader gObjectBumpProgram;
  211. extern LLGLSLShader gTreeProgram;
  212. extern LLGLSLShader gTreeWaterProgram;
  213. extern LLGLSLShader gObjectSimpleLODProgram;
  214. extern LLGLSLShader gObjectFullbrightLODProgram;
  215. extern LLGLSLShader gObjectFullbrightShinyProgram;
  216. extern LLGLSLShader gObjectFullbrightShinyWaterProgram;
  217. extern LLGLSLShader gObjectFullbrightShinyNonIndexedProgram;
  218. extern LLGLSLShader gObjectFullbrightShinyNonIndexedWaterProgram;
  219. extern LLGLSLShader gObjectShinyProgram;
  220. extern LLGLSLShader gObjectShinyWaterProgram;
  221. extern LLGLSLShader gObjectShinyNonIndexedProgram;
  222. extern LLGLSLShader gObjectShinyNonIndexedWaterProgram;
  223. extern LLGLSLShader gSkinnedObjectSimpleProgram;
  224. extern LLGLSLShader gSkinnedObjectFullbrightProgram;
  225. extern LLGLSLShader gSkinnedObjectEmissiveProgram;
  226. extern LLGLSLShader gSkinnedObjectFullbrightShinyProgram;
  227. extern LLGLSLShader gSkinnedObjectShinySimpleProgram;
  228. extern LLGLSLShader gSkinnedObjectSimpleWaterProgram;
  229. extern LLGLSLShader gSkinnedObjectFullbrightWaterProgram;
  230. extern LLGLSLShader gSkinnedObjectEmissiveWaterProgram;
  231. extern LLGLSLShader gSkinnedObjectFullbrightShinyWaterProgram;
  232. extern LLGLSLShader gSkinnedObjectShinySimpleWaterProgram;
  233. //environment shaders
  234. extern LLGLSLShader gTerrainProgram;
  235. extern LLGLSLShader gTerrainWaterProgram;
  236. extern LLGLSLShader gWaterProgram;
  237. extern LLGLSLShader gUnderWaterProgram;
  238. extern LLGLSLShader gGlowProgram;
  239. extern LLGLSLShader gGlowExtractProgram;
  240. //interface shaders
  241. extern LLGLSLShader gHighlightProgram;
  242. // avatar shader handles
  243. extern LLGLSLShader gAvatarProgram;
  244. extern LLGLSLShader gAvatarWaterProgram;
  245. extern LLGLSLShader gAvatarEyeballProgram;
  246. extern LLGLSLShader gAvatarPickProgram;
  247. extern LLGLSLShader gImpostorProgram;
  248. // WindLight shader handles
  249. extern LLGLSLShader gWLSkyProgram;
  250. extern LLGLSLShader gWLCloudProgram;
  251. // Post Process Shaders
  252. extern LLGLSLShader gPostColorFilterProgram;
  253. extern LLGLSLShader gPostNightVisionProgram;
  254. // Deferred rendering shaders
  255. extern LLGLSLShader gDeferredImpostorProgram;
  256. extern LLGLSLShader gDeferredWaterProgram;
  257. extern LLGLSLShader gDeferredDiffuseProgram;
  258. extern LLGLSLShader gDeferredDiffuseAlphaMaskProgram;
  259. extern LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskProgram;
  260. extern LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
  261. extern LLGLSLShader gDeferredNonIndexedDiffuseProgram;
  262. extern LLGLSLShader gDeferredSkinnedDiffuseProgram;
  263. extern LLGLSLShader gDeferredSkinnedBumpProgram;
  264. extern LLGLSLShader gDeferredSkinnedAlphaProgram;
  265. extern LLGLSLShader gDeferredBumpProgram;
  266. extern LLGLSLShader gDeferredTerrainProgram;
  267. extern LLGLSLShader gDeferredTreeProgram;
  268. extern LLGLSLShader gDeferredTreeShadowProgram;
  269. extern LLGLSLShader gDeferredLightProgram;
  270. extern LLGLSLShader gDeferredMultiLightProgram;
  271. extern LLGLSLShader gDeferredSpotLightProgram;
  272. extern LLGLSLShader gDeferredMultiSpotLightProgram;
  273. extern LLGLSLShader gDeferredSunProgram;
  274. extern LLGLSLShader gDeferredBlurLightProgram;
  275. extern LLGLSLShader gDeferredAvatarProgram;
  276. extern LLGLSLShader gDeferredSoftenProgram;
  277. extern LLGLSLShader gDeferredShadowProgram;
  278. extern LLGLSLShader gDeferredShadowAlphaMaskProgram;
  279. extern LLGLSLShader gDeferredPostProgram;
  280. extern LLGLSLShader gDeferredCoFProgram;
  281. extern LLGLSLShader gDeferredDoFCombineProgram;
  282. extern LLGLSLShader gFXAAProgram;
  283. extern LLGLSLShader gDeferredPostNoDoFProgram;
  284. extern LLGLSLShader gDeferredAvatarShadowProgram;
  285. extern LLGLSLShader gDeferredAttachmentShadowProgram;
  286. extern LLGLSLShader gDeferredAlphaProgram;
  287. extern LLGLSLShader gDeferredFullbrightProgram;
  288. extern LLGLSLShader gDeferredEmissiveProgram;
  289. extern LLGLSLShader gDeferredAvatarEyesProgram;
  290. extern LLGLSLShader gDeferredAvatarAlphaProgram;
  291. extern LLGLSLShader gDeferredWLSkyProgram;
  292. extern LLGLSLShader gDeferredWLCloudProgram;
  293. extern LLGLSLShader gDeferredStarProgram;
  294. extern LLGLSLShader gNormalMapGenProgram;
  295. #endif