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