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