lldrawpoolsimple.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:8k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file lldrawpoolsimple.cpp
  3.  * @brief LLDrawPoolSimple class implementation
  4.  *
  5.  * $LicenseInfo:firstyear=2002&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2002-2010, 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. #include "llviewerprecompiledheaders.h"
  33. #include "lldrawpoolsimple.h"
  34. #include "llviewercamera.h"
  35. #include "lldrawable.h"
  36. #include "llface.h"
  37. #include "llsky.h"
  38. #include "pipeline.h"
  39. #include "llspatialpartition.h"
  40. #include "llviewershadermgr.h"
  41. #include "llrender.h"
  42. static LLGLSLShader* simple_shader = NULL;
  43. static LLGLSLShader* fullbright_shader = NULL;
  44. static LLFastTimer::DeclareTimer FTM_RENDER_SIMPLE_DEFERRED("Deferred Simple");
  45. static LLFastTimer::DeclareTimer FTM_RENDER_GRASS_DEFERRED("Deferred Grass");
  46. void LLDrawPoolGlow::render(S32 pass)
  47. {
  48. LLFastTimer t(FTM_RENDER_GLOW);
  49. LLGLEnable blend(GL_BLEND);
  50. LLGLDisable test(GL_ALPHA_TEST);
  51. gGL.setSceneBlendType(LLRender::BT_ADD);
  52. U32 shader_level = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  53. if (shader_level > 0 && fullbright_shader)
  54. {
  55. fullbright_shader->bind();
  56. }
  57. else
  58. {
  59. gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
  60. }
  61. LLGLDepthTest depth(GL_TRUE, GL_FALSE);
  62. gGL.setColorMask(false, true);
  63. renderTexture(LLRenderPass::PASS_GLOW, getVertexDataMask());
  64. gGL.setColorMask(true, false);
  65. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  66. if (shader_level > 0 && fullbright_shader)
  67. {
  68. fullbright_shader->unbind();
  69. }
  70. }
  71. void LLDrawPoolGlow::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture)
  72. {
  73. glColor4ubv(params.mGlowColor.mV);
  74. LLRenderPass::pushBatch(params, mask, texture);
  75. }
  76. LLDrawPoolSimple::LLDrawPoolSimple() :
  77. LLRenderPass(POOL_SIMPLE)
  78. {
  79. }
  80. void LLDrawPoolSimple::prerender()
  81. {
  82. mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  83. }
  84. void LLDrawPoolSimple::beginRenderPass(S32 pass)
  85. {
  86. LLFastTimer t(FTM_RENDER_SIMPLE);
  87. if (LLPipeline::sUnderWaterRender)
  88. {
  89. simple_shader = &gObjectSimpleWaterProgram;
  90. }
  91. else
  92. {
  93. simple_shader = &gObjectSimpleProgram;
  94. }
  95. if (mVertexShaderLevel > 0)
  96. {
  97. simple_shader->bind();
  98. }
  99. else 
  100. {
  101. // don't use shaders!
  102. if (gGLManager.mHasShaderObjects)
  103. {
  104. LLGLSLShader::bindNoShader();
  105. }
  106. }
  107. }
  108. void LLDrawPoolSimple::endRenderPass(S32 pass)
  109. {
  110. LLFastTimer t(FTM_RENDER_SIMPLE);
  111. LLRenderPass::endRenderPass(pass);
  112. if (mVertexShaderLevel > 0){
  113. simple_shader->unbind();
  114. }
  115. }
  116. void LLDrawPoolSimple::render(S32 pass)
  117. {
  118. LLGLDisable blend(GL_BLEND);
  119. LLGLDisable alpha_test(GL_ALPHA_TEST);
  120. { //render simple
  121. LLFastTimer t(FTM_RENDER_SIMPLE);
  122. gPipeline.enableLightsDynamic();
  123. renderTexture(LLRenderPass::PASS_SIMPLE, getVertexDataMask());
  124. if (LLPipeline::sRenderDeferred)
  125. {
  126. renderTexture(LLRenderPass::PASS_BUMP, getVertexDataMask());
  127. }
  128. }
  129. }
  130. //===============================
  131. //DEFERRED IMPLEMENTATION
  132. //===============================
  133. void LLDrawPoolSimple::beginDeferredPass(S32 pass)
  134. {
  135. LLFastTimer t(FTM_RENDER_SIMPLE_DEFERRED);
  136. gDeferredDiffuseProgram.bind();
  137. }
  138. void LLDrawPoolSimple::endDeferredPass(S32 pass)
  139. {
  140. LLFastTimer t(FTM_RENDER_SIMPLE_DEFERRED);
  141. LLRenderPass::endRenderPass(pass);
  142. gDeferredDiffuseProgram.unbind();
  143. }
  144. void LLDrawPoolSimple::renderDeferred(S32 pass)
  145. {
  146. LLGLDisable blend(GL_BLEND);
  147. LLGLDisable alpha_test(GL_ALPHA_TEST);
  148. { //render simple
  149. LLFastTimer t(FTM_RENDER_SIMPLE_DEFERRED);
  150. renderTexture(LLRenderPass::PASS_SIMPLE, getVertexDataMask());
  151. }
  152. }
  153. // grass drawpool
  154. LLDrawPoolGrass::LLDrawPoolGrass() :
  155.  LLRenderPass(POOL_GRASS)
  156. {
  157. }
  158. void LLDrawPoolGrass::prerender()
  159. {
  160. mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  161. }
  162. void LLDrawPoolGrass::beginRenderPass(S32 pass)
  163. {
  164. LLFastTimer t(FTM_RENDER_GRASS);
  165. if (LLPipeline::sUnderWaterRender)
  166. {
  167. simple_shader = &gObjectSimpleWaterProgram;
  168. }
  169. else
  170. {
  171. simple_shader = &gObjectSimpleProgram;
  172. }
  173. if (mVertexShaderLevel > 0)
  174. {
  175. simple_shader->bind();
  176. }
  177. else 
  178. {
  179. // don't use shaders!
  180. if (gGLManager.mHasShaderObjects)
  181. {
  182. LLGLSLShader::bindNoShader();
  183. }
  184. }
  185. }
  186. void LLDrawPoolGrass::endRenderPass(S32 pass)
  187. {
  188. LLFastTimer t(FTM_RENDER_GRASS);
  189. LLRenderPass::endRenderPass(pass);
  190. if (mVertexShaderLevel > 0)
  191. {
  192. simple_shader->unbind();
  193. }
  194. }
  195. void LLDrawPoolGrass::render(S32 pass)
  196. {
  197. LLGLDisable blend(GL_BLEND);
  198. gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f);
  199. {
  200. LLFastTimer t(FTM_RENDER_GRASS);
  201. LLGLEnable test(GL_ALPHA_TEST);
  202. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  203. //render grass
  204. LLRenderPass::renderTexture(LLRenderPass::PASS_GRASS, getVertexDataMask());
  205. }
  206. gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
  207. }
  208. void LLDrawPoolGrass::beginDeferredPass(S32 pass)
  209. {
  210. }
  211. void LLDrawPoolGrass::endDeferredPass(S32 pass)
  212. {
  213. }
  214. void LLDrawPoolGrass::renderDeferred(S32 pass)
  215. {
  216. gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.f);
  217. {
  218. LLFastTimer t(FTM_RENDER_GRASS_DEFERRED);
  219. gDeferredTreeProgram.bind();
  220. LLGLEnable test(GL_ALPHA_TEST);
  221. //render grass
  222. LLRenderPass::renderTexture(LLRenderPass::PASS_GRASS, getVertexDataMask());
  223. }
  224. gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
  225. }
  226. // Fullbright drawpool
  227. LLDrawPoolFullbright::LLDrawPoolFullbright() :
  228. LLRenderPass(POOL_FULLBRIGHT)
  229. {
  230. }
  231. void LLDrawPoolFullbright::prerender()
  232. {
  233. mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
  234. }
  235. void LLDrawPoolFullbright::beginRenderPass(S32 pass)
  236. {
  237. LLFastTimer t(FTM_RENDER_FULLBRIGHT);
  238. if (LLPipeline::sUnderWaterRender)
  239. {
  240. fullbright_shader = &gObjectFullbrightWaterProgram;
  241. }
  242. else
  243. {
  244. fullbright_shader = &gObjectFullbrightProgram;
  245. }
  246. }
  247. void LLDrawPoolFullbright::endRenderPass(S32 pass)
  248. {
  249. LLFastTimer t(FTM_RENDER_FULLBRIGHT);
  250. LLRenderPass::endRenderPass(pass);
  251. if (mVertexShaderLevel > 0)
  252. {
  253. fullbright_shader->unbind();
  254. }
  255. }
  256. void LLDrawPoolFullbright::render(S32 pass)
  257. { //render fullbright
  258. LLFastTimer t(FTM_RENDER_FULLBRIGHT);
  259. if (mVertexShaderLevel > 0)
  260. {
  261. fullbright_shader->bind();
  262. fullbright_shader->uniform1f(LLViewerShaderMgr::FULLBRIGHT, 1.f);
  263. }
  264. else
  265. {
  266. gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
  267. }
  268. //gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.25f);
  269. //LLGLEnable test(GL_ALPHA_TEST);
  270. //LLGLEnable blend(GL_BLEND);
  271. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  272. U32 fullbright_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR;
  273. renderTexture(LLRenderPass::PASS_FULLBRIGHT, fullbright_mask);
  274. //gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
  275. }
  276. S32 LLDrawPoolFullbright::getNumPasses()
  277. return 1;
  278. }