PageRenderTime 367ms CodeModel.GetById 161ms app.highlight 14ms RepoModel.GetById 190ms app.codeStats 0ms

/indra/newview/lldrawpooltree.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 211 lines | 137 code | 36 blank | 38 comment | 8 complexity | 4b9d739f07dd4feb1dc47c66d717fa14 MD5 | raw file
  1/** 
  2 * @file lldrawpooltree.cpp
  3 * @brief LLDrawPoolTree 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 "lldrawpooltree.h"
 30
 31#include "lldrawable.h"
 32#include "llface.h"
 33#include "llsky.h"
 34#include "llvotree.h"
 35#include "pipeline.h"
 36#include "llviewercamera.h"
 37#include "llviewershadermgr.h"
 38#include "llrender.h"
 39#include "llviewercontrol.h"
 40
 41S32 LLDrawPoolTree::sDiffTex = 0;
 42static LLGLSLShader* shader = NULL;
 43static LLFastTimer::DeclareTimer FTM_SHADOW_TREE("Tree Shadow");
 44
 45LLDrawPoolTree::LLDrawPoolTree(LLViewerTexture *texturep) :
 46	LLFacePool(POOL_TREE),
 47	mTexturep(texturep)
 48{
 49	mTexturep->setAddressMode(LLTexUnit::TAM_WRAP);
 50}
 51
 52LLDrawPool *LLDrawPoolTree::instancePool()
 53{
 54	return new LLDrawPoolTree(mTexturep);
 55}
 56
 57void LLDrawPoolTree::prerender()
 58{
 59	mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
 60}
 61
 62void LLDrawPoolTree::beginRenderPass(S32 pass)
 63{
 64	LLFastTimer t(FTM_RENDER_TREES);
 65		
 66	if (LLPipeline::sUnderWaterRender)
 67	{
 68		shader = &gTreeWaterProgram;
 69	}
 70	else
 71	{
 72		shader = &gTreeProgram;
 73	}
 74
 75	if (gPipeline.canUseVertexShaders())
 76	{
 77		shader->bind();
 78		shader->setMinimumAlpha(0.5f);
 79		gGL.diffuseColor4f(1,1,1,1);
 80	}
 81	else
 82	{
 83		gPipeline.enableLightsDynamic();
 84		gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f);
 85	}
 86}
 87
 88void LLDrawPoolTree::render(S32 pass)
 89{
 90	LLFastTimer t(LLPipeline::sShadowRender ? FTM_SHADOW_TREE : FTM_RENDER_TREES);
 91
 92	if (mDrawFace.empty())
 93	{
 94		return;
 95	}
 96
 97	LLGLState test(GL_ALPHA_TEST, LLGLSLShader::sNoFixedFunction ? 0 : 1);
 98	LLOverrideFaceColor color(this, 1.f, 1.f, 1.f, 1.f);
 99
100	gGL.getTexUnit(sDiffTex)->bind(mTexturep);
101				
102	for (std::vector<LLFace*>::iterator iter = mDrawFace.begin();
103		 iter != mDrawFace.end(); iter++)
104	{
105		LLFace *face = *iter;
106		LLVertexBuffer* buff = face->getVertexBuffer();
107		if(buff)
108		{
109			buff->setBuffer(LLDrawPoolTree::VERTEX_DATA_MASK);
110			buff->drawRange(LLRender::TRIANGLES, 0, buff->getNumVerts()-1, buff->getNumIndices(), 0); 
111			gPipeline.addTrianglesDrawn(buff->getNumIndices());
112		}
113	}
114}
115
116void LLDrawPoolTree::endRenderPass(S32 pass)
117{
118	LLFastTimer t(FTM_RENDER_TREES);
119		
120	if (gPipeline.canUseWindLightShadersOnObjects())
121	{
122		shader->unbind();
123	}
124	
125	if (mVertexShaderLevel <= 0)
126	{
127		gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
128	}
129}
130
131//============================================
132// deferred implementation
133//============================================
134void LLDrawPoolTree::beginDeferredPass(S32 pass)
135{
136	LLFastTimer t(FTM_RENDER_TREES);
137		
138	shader = &gDeferredTreeProgram;
139	shader->bind();
140	shader->setMinimumAlpha(0.5f);
141}
142
143void LLDrawPoolTree::renderDeferred(S32 pass)
144{
145	render(pass);
146}
147
148void LLDrawPoolTree::endDeferredPass(S32 pass)
149{
150	LLFastTimer t(FTM_RENDER_TREES);
151		
152	shader->unbind();
153}
154
155//============================================
156// shadow implementation
157//============================================
158void LLDrawPoolTree::beginShadowPass(S32 pass)
159{
160	LLFastTimer t(FTM_SHADOW_TREE);
161	
162	glPolygonOffset(gSavedSettings.getF32("RenderDeferredTreeShadowOffset"),
163					gSavedSettings.getF32("RenderDeferredTreeShadowBias"));
164
165	gDeferredTreeShadowProgram.bind();
166	gDeferredTreeShadowProgram.setMinimumAlpha(0.5f);
167}
168
169void LLDrawPoolTree::renderShadow(S32 pass)
170{
171	render(pass);
172}
173
174void LLDrawPoolTree::endShadowPass(S32 pass)
175{
176	LLFastTimer t(FTM_SHADOW_TREE);
177	
178	glPolygonOffset(gSavedSettings.getF32("RenderDeferredSpotShadowOffset"),
179						gSavedSettings.getF32("RenderDeferredSpotShadowBias"));
180	gDeferredTreeShadowProgram.unbind();
181}
182
183BOOL LLDrawPoolTree::verify() const
184{
185/*	BOOL ok = TRUE;
186
187	if (!ok)
188	{
189		printDebugInfo();
190	}
191	return ok;*/
192
193	return TRUE;
194}
195
196LLViewerTexture *LLDrawPoolTree::getTexture()
197{
198	return mTexturep;
199}
200
201LLViewerTexture *LLDrawPoolTree::getDebugTexture()
202{
203	return mTexturep;
204}
205
206
207LLColor3 LLDrawPoolTree::getDebugColor() const
208{
209	return LLColor3(1.f, 0.f, 1.f);
210}
211