PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lldrawpoolsimple.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 423 lines | 307 code | 77 blank | 39 comment | 18 complexity | a3f04329d50ce9b22c3f1e02d5687f1b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lldrawpoolsimple.cpp
  3. * @brief LLDrawPoolSimple class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #include "llviewerprecompiledheaders.h"
  27. #include "lldrawpoolsimple.h"
  28. #include "llviewercamera.h"
  29. #include "lldrawable.h"
  30. #include "llface.h"
  31. #include "llsky.h"
  32. #include "pipeline.h"
  33. #include "llspatialpartition.h"
  34. #include "llviewershadermgr.h"
  35. #include "llrender.h"
  36. static LLGLSLShader* simple_shader = NULL;
  37. static LLGLSLShader* fullbright_shader = NULL;
  38. static LLFastTimer::DeclareTimer FTM_RENDER_SIMPLE_DEFERRED("Deferred Simple");
  39. static LLFastTimer::DeclareTimer FTM_RENDER_GRASS_DEFERRED("Deferred Grass");
  40. void LLDrawPoolGlow::beginPostDeferredPass(S32 pass)
  41. {
  42. gDeferredEmissiveProgram.bind();
  43. }
  44. static LLFastTimer::DeclareTimer FTM_RENDER_GLOW_PUSH("Glow Push");
  45. void LLDrawPoolGlow::renderPostDeferred(S32 pass)
  46. {
  47. LLFastTimer t(FTM_RENDER_GLOW);
  48. LLGLEnable blend(GL_BLEND);
  49. LLGLDisable test(GL_ALPHA_TEST);
  50. gGL.flush();
  51. /// Get rid of z-fighting with non-glow pass.
  52. LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
  53. glPolygonOffset(-1.0f, -1.0f);
  54. gGL.setSceneBlendType(LLRender::BT_ADD);
  55. LLGLDepthTest depth(GL_TRUE, GL_FALSE);
  56. gGL.setColorMask(false, true);
  57. {
  58. LLFastTimer t(FTM_RENDER_GLOW_PUSH);
  59. pushBatches(LLRenderPass::PASS_GLOW, getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX, TRUE, TRUE);
  60. }
  61. gGL.setColorMask(true, false);
  62. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  63. }
  64. void LLDrawPoolGlow::endPostDeferredPass(S32 pass)
  65. {
  66. gDeferredEmissiveProgram.unbind();
  67. LLRenderPass::endRenderPass(pass);
  68. }
  69. S32 LLDrawPoolGlow::getNumPasses()
  70. {
  71. if (LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 0)
  72. {
  73. return 1;
  74. }
  75. else
  76. {
  77. return 0;
  78. }
  79. }
  80. void LLDrawPoolGlow::render(S32 pass)
  81. {
  82. LLFastTimer t(FTM_RENDER_GLOW);
  83. LLGLEnable blend(GL_BLEND);
  84. LLGLDisable test(GL_ALPHA_TEST);
  85. gGL.flush();
  86. /// Get rid of z-fighting with non-glow pass.
  87. LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
  88. glPolygonOffset(-1.0f, -1.0f);
  89. gGL.setSceneBlendType(LLRender::BT_ADD);
  90. U32 shader_level = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  91. //should never get here without basic shaders enabled
  92. llassert(shader_level > 0);
  93. LLGLSLShader* shader = LLPipeline::sUnderWaterRender ? &gObjectEmissiveWaterProgram : &gObjectEmissiveProgram;
  94. shader->bind();
  95. LLGLDepthTest depth(GL_TRUE, GL_FALSE);
  96. gGL.setColorMask(false, true);
  97. pushBatches(LLRenderPass::PASS_GLOW, getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX, TRUE, TRUE);
  98. gGL.setColorMask(true, false);
  99. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  100. if (shader_level > 0 && fullbright_shader)
  101. {
  102. shader->unbind();
  103. }
  104. }
  105. void LLDrawPoolGlow::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture, BOOL batch_textures)
  106. {
  107. //gGL.diffuseColor4ubv(params.mGlowColor.mV);
  108. LLRenderPass::pushBatch(params, mask, texture, batch_textures);
  109. }
  110. LLDrawPoolSimple::LLDrawPoolSimple() :
  111. LLRenderPass(POOL_SIMPLE)
  112. {
  113. }
  114. void LLDrawPoolSimple::prerender()
  115. {
  116. mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  117. }
  118. void LLDrawPoolSimple::beginRenderPass(S32 pass)
  119. {
  120. LLFastTimer t(FTM_RENDER_SIMPLE);
  121. if (LLPipeline::sUnderWaterRender)
  122. {
  123. simple_shader = &gObjectSimpleWaterProgram;
  124. }
  125. else
  126. {
  127. simple_shader = &gObjectSimpleProgram;
  128. }
  129. if (mVertexShaderLevel > 0)
  130. {
  131. simple_shader->bind();
  132. }
  133. else
  134. {
  135. // don't use shaders!
  136. if (gGLManager.mHasShaderObjects)
  137. {
  138. LLGLSLShader::bindNoShader();
  139. }
  140. }
  141. }
  142. void LLDrawPoolSimple::endRenderPass(S32 pass)
  143. {
  144. LLFastTimer t(FTM_RENDER_SIMPLE);
  145. stop_glerror();
  146. LLRenderPass::endRenderPass(pass);
  147. stop_glerror();
  148. if (mVertexShaderLevel > 0)
  149. {
  150. simple_shader->unbind();
  151. }
  152. }
  153. void LLDrawPoolSimple::render(S32 pass)
  154. {
  155. LLGLDisable blend(GL_BLEND);
  156. { //render simple
  157. LLFastTimer t(FTM_RENDER_SIMPLE);
  158. gPipeline.enableLightsDynamic();
  159. if (mVertexShaderLevel > 0)
  160. {
  161. U32 mask = getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX;
  162. pushBatches(LLRenderPass::PASS_SIMPLE, mask, TRUE, TRUE);
  163. if (LLPipeline::sRenderDeferred)
  164. { //if deferred rendering is enabled, bump faces aren't registered as simple
  165. //render bump faces here as simple so bump faces will appear under water
  166. pushBatches(LLRenderPass::PASS_BUMP, mask, TRUE, TRUE);
  167. }
  168. }
  169. else
  170. {
  171. LLGLDisable alpha_test(GL_ALPHA_TEST);
  172. renderTexture(LLRenderPass::PASS_SIMPLE, getVertexDataMask());
  173. }
  174. }
  175. }
  176. //===============================
  177. //DEFERRED IMPLEMENTATION
  178. //===============================
  179. void LLDrawPoolSimple::beginDeferredPass(S32 pass)
  180. {
  181. LLFastTimer t(FTM_RENDER_SIMPLE_DEFERRED);
  182. gDeferredDiffuseProgram.bind();
  183. }
  184. void LLDrawPoolSimple::endDeferredPass(S32 pass)
  185. {
  186. LLFastTimer t(FTM_RENDER_SIMPLE_DEFERRED);
  187. LLRenderPass::endRenderPass(pass);
  188. gDeferredDiffuseProgram.unbind();
  189. }
  190. void LLDrawPoolSimple::renderDeferred(S32 pass)
  191. {
  192. LLGLDisable blend(GL_BLEND);
  193. LLGLDisable alpha_test(GL_ALPHA_TEST);
  194. { //render simple
  195. LLFastTimer t(FTM_RENDER_SIMPLE_DEFERRED);
  196. pushBatches(LLRenderPass::PASS_SIMPLE, getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX, TRUE, TRUE);
  197. }
  198. }
  199. // grass drawpool
  200. LLDrawPoolGrass::LLDrawPoolGrass() :
  201. LLRenderPass(POOL_GRASS)
  202. {
  203. }
  204. void LLDrawPoolGrass::prerender()
  205. {
  206. mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  207. }
  208. void LLDrawPoolGrass::beginRenderPass(S32 pass)
  209. {
  210. LLFastTimer t(FTM_RENDER_GRASS);
  211. stop_glerror();
  212. if (LLPipeline::sUnderWaterRender)
  213. {
  214. simple_shader = &gObjectAlphaMaskNonIndexedWaterProgram;
  215. }
  216. else
  217. {
  218. simple_shader = &gObjectAlphaMaskNonIndexedProgram;
  219. }
  220. if (mVertexShaderLevel > 0)
  221. {
  222. simple_shader->bind();
  223. simple_shader->setMinimumAlpha(0.5f);
  224. }
  225. else
  226. {
  227. gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f);
  228. // don't use shaders!
  229. if (gGLManager.mHasShaderObjects)
  230. {
  231. LLGLSLShader::bindNoShader();
  232. }
  233. }
  234. }
  235. void LLDrawPoolGrass::endRenderPass(S32 pass)
  236. {
  237. LLFastTimer t(FTM_RENDER_GRASS);
  238. LLRenderPass::endRenderPass(pass);
  239. if (mVertexShaderLevel > 0)
  240. {
  241. simple_shader->unbind();
  242. }
  243. else
  244. {
  245. gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
  246. }
  247. }
  248. void LLDrawPoolGrass::render(S32 pass)
  249. {
  250. LLGLDisable blend(GL_BLEND);
  251. {
  252. LLFastTimer t(FTM_RENDER_GRASS);
  253. LLGLEnable test(GL_ALPHA_TEST);
  254. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  255. //render grass
  256. LLRenderPass::renderTexture(LLRenderPass::PASS_GRASS, getVertexDataMask());
  257. }
  258. }
  259. void LLDrawPoolGrass::beginDeferredPass(S32 pass)
  260. {
  261. }
  262. void LLDrawPoolGrass::endDeferredPass(S32 pass)
  263. {
  264. }
  265. void LLDrawPoolGrass::renderDeferred(S32 pass)
  266. {
  267. {
  268. LLFastTimer t(FTM_RENDER_GRASS_DEFERRED);
  269. gDeferredNonIndexedDiffuseAlphaMaskProgram.bind();
  270. gDeferredNonIndexedDiffuseAlphaMaskProgram.setMinimumAlpha(0.5f);
  271. //render grass
  272. LLRenderPass::renderTexture(LLRenderPass::PASS_GRASS, getVertexDataMask());
  273. }
  274. }
  275. // Fullbright drawpool
  276. LLDrawPoolFullbright::LLDrawPoolFullbright() :
  277. LLRenderPass(POOL_FULLBRIGHT)
  278. {
  279. }
  280. void LLDrawPoolFullbright::prerender()
  281. {
  282. mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  283. }
  284. void LLDrawPoolFullbright::beginPostDeferredPass(S32 pass)
  285. {
  286. gDeferredFullbrightProgram.bind();
  287. }
  288. void LLDrawPoolFullbright::renderPostDeferred(S32 pass)
  289. {
  290. LLFastTimer t(FTM_RENDER_FULLBRIGHT);
  291. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  292. U32 fullbright_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXTURE_INDEX;
  293. pushBatches(LLRenderPass::PASS_FULLBRIGHT, fullbright_mask, TRUE, TRUE);
  294. }
  295. void LLDrawPoolFullbright::endPostDeferredPass(S32 pass)
  296. {
  297. gDeferredFullbrightProgram.unbind();
  298. LLRenderPass::endRenderPass(pass);
  299. }
  300. void LLDrawPoolFullbright::beginRenderPass(S32 pass)
  301. {
  302. LLFastTimer t(FTM_RENDER_FULLBRIGHT);
  303. if (LLPipeline::sUnderWaterRender)
  304. {
  305. fullbright_shader = &gObjectFullbrightWaterProgram;
  306. }
  307. else
  308. {
  309. fullbright_shader = &gObjectFullbrightProgram;
  310. }
  311. }
  312. void LLDrawPoolFullbright::endRenderPass(S32 pass)
  313. {
  314. LLFastTimer t(FTM_RENDER_FULLBRIGHT);
  315. LLRenderPass::endRenderPass(pass);
  316. stop_glerror();
  317. if (mVertexShaderLevel > 0)
  318. {
  319. fullbright_shader->unbind();
  320. }
  321. stop_glerror();
  322. }
  323. void LLDrawPoolFullbright::render(S32 pass)
  324. { //render fullbright
  325. LLFastTimer t(FTM_RENDER_FULLBRIGHT);
  326. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  327. stop_glerror();
  328. if (mVertexShaderLevel > 0)
  329. {
  330. fullbright_shader->bind();
  331. fullbright_shader->uniform1f(LLViewerShaderMgr::FULLBRIGHT, 1.f);
  332. U32 fullbright_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXTURE_INDEX;
  333. pushBatches(LLRenderPass::PASS_FULLBRIGHT, fullbright_mask, TRUE, TRUE);
  334. }
  335. else
  336. {
  337. gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
  338. U32 fullbright_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR;
  339. renderTexture(LLRenderPass::PASS_FULLBRIGHT, fullbright_mask);
  340. }
  341. stop_glerror();
  342. }
  343. S32 LLDrawPoolFullbright::getNumPasses()
  344. {
  345. return 1;
  346. }