PageRenderTime 72ms CodeModel.GetById 40ms app.highlight 11ms RepoModel.GetById 19ms app.codeStats 0ms

/indra/newview/lldrawpoolsky.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 157 lines | 95 code | 32 blank | 30 comment | 10 complexity | 270dfcf49c24e30cd19aacb55611096d MD5 | raw file
  1/** 
  2 * @file lldrawpoolsky.cpp
  3 * @brief LLDrawPoolSky 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 "lldrawpoolsky.h"
 30
 31#include "imageids.h"
 32
 33#include "llagent.h"
 34#include "lldrawable.h"
 35#include "llface.h"
 36#include "llsky.h"
 37#include "llviewercamera.h"
 38#include "llviewertexturelist.h"
 39#include "llviewerregion.h"
 40#include "llvosky.h"
 41#include "llworld.h" // To get water height
 42#include "pipeline.h"
 43#include "llviewershadermgr.h"
 44
 45LLDrawPoolSky::LLDrawPoolSky()
 46:	LLFacePool(POOL_SKY),
 47	
 48	mSkyTex(NULL),
 49	mShader(NULL)
 50{
 51}
 52
 53LLDrawPool *LLDrawPoolSky::instancePool()
 54{
 55	return new LLDrawPoolSky();
 56}
 57
 58void LLDrawPoolSky::prerender()
 59{
 60	mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_ENVIRONMENT); 
 61	gSky.mVOSkyp->updateGeometry(gSky.mVOSkyp->mDrawable);
 62}
 63
 64void LLDrawPoolSky::render(S32 pass)
 65{
 66	gGL.flush();
 67
 68	if (mDrawFace.empty())
 69	{
 70		return;
 71	}
 72
 73	// Don't draw the sky box if we can and are rendering the WL sky dome.
 74	if (gPipeline.canUseWindLightShaders())
 75	{
 76		return;
 77	}
 78	
 79	// don't render sky under water (background just gets cleared to fog color)
 80	if(mVertexShaderLevel > 0 && LLPipeline::sUnderWaterRender)
 81	{
 82		return;
 83	}
 84
 85
 86	if (LLGLSLShader::sNoFixedFunction)
 87	{ //just use the UI shader (generic single texture no lighting)
 88		gOneTextureNoColorProgram.bind();
 89	}
 90	else
 91	{
 92		// don't use shaders!
 93		if (gGLManager.mHasShaderObjects)
 94		{
 95			// Ironically, we must support shader objects to be
 96			// able to use this call.
 97			LLGLSLShader::bindNoShader();
 98		}
 99		mShader = NULL;
100	}
101	
102
103	LLGLSPipelineSkyBox gls_skybox;
104
105	LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
106
107	LLGLSquashToFarClip far_clip(glh_get_current_projection());
108
109	LLGLEnable fog_enable( (mVertexShaderLevel < 1 && LLViewerCamera::getInstance()->cameraUnderWater()) ? GL_FOG : 0);
110
111	gPipeline.disableLights();
112	
113	LLGLDisable clip(GL_CLIP_PLANE0);
114
115	gGL.pushMatrix();
116	LLVector3 origin = LLViewerCamera::getInstance()->getOrigin();
117	gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]);
118
119	S32 face_count = (S32)mDrawFace.size();
120
121	LLVertexBuffer::unbind();
122	gGL.diffuseColor4f(1,1,1,1);
123
124	for (S32 i = 0; i < llmin(6, face_count); ++i)
125	{
126		renderSkyCubeFace(i);
127	}
128
129	gGL.popMatrix();
130}
131
132void LLDrawPoolSky::renderSkyCubeFace(U8 side)
133{
134	LLFace &face = *mDrawFace[LLVOSky::FACE_SIDE0 + side];
135	if (!face.getGeomCount())
136	{
137		return;
138	}
139
140	llassert(mSkyTex);
141	mSkyTex[side].bindTexture(TRUE);
142	
143	face.renderIndexed();
144
145	if (LLSkyTex::doInterpolate())
146	{
147		
148		LLGLEnable blend(GL_BLEND);
149		mSkyTex[side].bindTexture(FALSE);
150		gGL.diffuseColor4f(1, 1, 1, LLSkyTex::getInterpVal()); // lighting is disabled
151		face.renderIndexed();
152	}
153}
154
155void LLDrawPoolSky::endRenderPass( S32 pass )
156{
157}