lldrawpoolsky.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "lldrawpoolsky.h"
00035 
00036 #include "imageids.h"
00037 
00038 #include "llagent.h"
00039 #include "lldrawable.h"
00040 #include "llface.h"
00041 #include "llsky.h"
00042 #include "llviewercamera.h"
00043 #include "llviewerimagelist.h"
00044 #include "llviewerregion.h"
00045 #include "llviewerwindow.h"
00046 #include "llvosky.h"
00047 #include "llworld.h" // To get water height
00048 #include "pipeline.h"
00049 #include "llglslshader.h"
00050 
00051 LLDrawPoolSky::LLDrawPoolSky() :
00052         LLFacePool(POOL_SKY)
00053 {
00054 }
00055 
00056 LLDrawPool *LLDrawPoolSky::instancePool()
00057 {
00058         return new LLDrawPoolSky();
00059 }
00060 
00061 void LLDrawPoolSky::prerender()
00062 {
00063         mVertexShaderLevel = LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_ENVIRONMENT);
00064 }
00065 
00066 void LLDrawPoolSky::render(S32 pass)
00067 {
00068         if (mDrawFace.empty())
00069         {
00070                 return;
00071         }
00072 
00073         LLVOSky *voskyp = gSky.mVOSkyp;
00074         LLGLSPipelineSkyBox gls_skybox;
00075         LLGLDepthTest gls_depth(GL_FALSE, GL_FALSE);
00076 
00077         if (gCamera->getOrigin().mV[VZ] < gAgent.getRegion()->getWaterHeight())
00078                 //gWorldPointer->getWaterHeight())
00079         {
00080                 //gGLSFog.set();
00081         }
00082 
00083         gPipeline.disableLights();
00084         
00085         glMatrixMode( GL_PROJECTION );
00086 
00087         glPushMatrix();
00088         //gViewerWindow->setup3DRender();
00089 
00090         glMatrixMode(GL_MODELVIEW);
00091         glPushMatrix();
00092         LLVector3 origin = gCamera->getOrigin();
00093         glTranslatef(origin.mV[0], origin.mV[1], origin.mV[2]);
00094 
00095         glEnableClientState(GL_VERTEX_ARRAY);
00096         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
00097         glDisableClientState(GL_NORMAL_ARRAY);
00098 
00099         S32 face_count = (S32)mDrawFace.size();
00100 
00101         for (S32 i = 0; i < llmin(6, face_count); ++i)
00102         {
00103                 renderSkyCubeFace(i);
00104         }
00105         
00106         LLFace *hbfaces[3];
00107         hbfaces[0] = NULL;
00108         hbfaces[1] = NULL;
00109         hbfaces[2] = NULL;
00110         for (S32 curr_face = 0; curr_face < face_count; curr_face++)
00111         {
00112                 LLFace* facep = mDrawFace[curr_face];
00113                 if (voskyp->isSameFace(LLVOSky::FACE_SUN, facep))
00114                 {
00115                         hbfaces[0] = facep;
00116                 }
00117                 if (voskyp->isSameFace(LLVOSky::FACE_MOON, facep))
00118                 {
00119                         hbfaces[1] = facep;
00120                 }
00121                 if (voskyp->isSameFace(LLVOSky::FACE_BLOOM, facep))
00122                 {
00123                         hbfaces[2] = facep;
00124                 }
00125         }
00126 
00127         LLGLEnable blend(GL_BLEND);
00128 
00129         if (hbfaces[2])
00130         {
00131                 renderSunHalo(hbfaces[2]);
00132         }
00133         if (hbfaces[0])
00134         {
00135                 renderHeavenlyBody(0, hbfaces[0]);
00136         }
00137         if (hbfaces[1])
00138         {
00139                 renderHeavenlyBody(1, hbfaces[1]);
00140         }
00141 
00142 
00143         glMatrixMode( GL_PROJECTION );
00144         glPopMatrix();
00145         glMatrixMode( GL_MODELVIEW );
00146         glPopMatrix();
00147 }
00148 
00149 void LLDrawPoolSky::renderSkyCubeFace(U8 side)
00150 {
00151         LLFace &face = *mDrawFace[LLVOSky::FACE_SIDE0 + side];
00152         if (!face.getGeomCount())
00153         {
00154                 return;
00155         }
00156 
00157         mSkyTex[side].bindTexture(TRUE);
00158         
00159         face.renderIndexed();
00160 
00161         if (LLSkyTex::doInterpolate())
00162         {
00163                 LLGLEnable blend(GL_BLEND);
00164                 mSkyTex[side].bindTexture(FALSE);
00165                 glColor4f(1, 1, 1, LLSkyTex::getInterpVal()); // lighting is disabled
00166                 face.renderIndexed();
00167         }
00168 
00169         mIndicesDrawn += face.getIndicesCount();
00170 }
00171 
00172 void LLDrawPoolSky::renderHeavenlyBody(U8 hb, LLFace* face)
00173 {
00174         if ( !mHB[hb]->getDraw() ) return;
00175         if (! face->getGeomCount()) return;
00176 
00177         LLImageGL* tex = face->getTexture();
00178         tex->bind();
00179         LLColor4 color(mHB[hb]->getInterpColor());
00180         LLOverrideFaceColor override(this, color);
00181         face->renderIndexed();
00182         mIndicesDrawn += face->getIndicesCount();
00183 }
00184 
00185 
00186 
00187 void LLDrawPoolSky::renderSunHalo(LLFace* face)
00188 {
00189         if (! mHB[0]->getDraw()) return;
00190         if (! face->getGeomCount()) return;
00191 
00192         LLImageGL* tex = face->getTexture();
00193         tex->bind();
00194         LLColor4 color(mHB[0]->getInterpColor());
00195         color.mV[3] = llclamp(mHB[0]->getHaloBrighness(), 0.f, 1.f);
00196 
00197         LLOverrideFaceColor override(this, color);
00198         face->renderIndexed();
00199         mIndicesDrawn += face->getIndicesCount();
00200 }
00201 
00202 
00203 void LLDrawPoolSky::renderForSelect()
00204 {
00205 }
00206 

Generated on Thu Jul 1 06:08:26 2010 for Second Life Viewer by  doxygen 1.4.7