lldrawpoolsky.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @file lldrawpoolsky.cpp
  3. * @brief LLDrawPoolSky class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lldrawpoolsky.h"
  34. #include "lldrawable.h"
  35. #include "llface.h"
  36. #include "llpipeline.h"
  37. #include "llsky.h"
  38. #include "llviewercamera.h"
  39. #include "llviewershadermgr.h"
  40. #include "llviewertexture.h"
  41. #include "llvosky.h"
  42. LLDrawPoolSky::LLDrawPoolSky()
  43. : LLFacePool(POOL_SKY),
  44. mSkyTex(NULL)
  45. {
  46. }
  47. //virtual
  48. void LLDrawPoolSky::prerender()
  49. {
  50. mShaderLevel =
  51. gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_ENVIRONMENT);
  52. if (!gUsePBRShaders)
  53. {
  54. LLDrawable* drawablep = gSky.mVOSkyp->mDrawable;
  55. if (drawablep)
  56. {
  57. gSky.mVOSkyp->updateGeometry(drawablep);
  58. }
  59. }
  60. }
  61. //virtual
  62. void LLDrawPoolSky::render(S32)
  63. {
  64. if (mDrawFace.empty() ||
  65. // Do not draw the sky box if we can and are rendering the WL sky dome.
  66. gPipeline.canUseWindLightShaders() ||
  67. // Do not render sky under water (background just gets cleared to fog
  68. // color).
  69. (mShaderLevel > 0 && LLPipeline::sUnderWaterRender))
  70. {
  71. return;
  72. }
  73. gGL.flush();
  74. // Just use the UI shader (generic single texture no lighting)
  75. gOneTextureNoColorProgram.bind();
  76. LLVector3 origin = gViewerCamera.getOrigin();
  77. U32 face_count = mDrawFace.size();
  78. LLGLSPipelineDepthTestSkyBox gls_skybox(GL_TRUE, GL_FALSE);
  79. gGL.pushMatrix();
  80. gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]);
  81. LLVertexBuffer::unbind();
  82. gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f);
  83. for (U32 i = 0; i < face_count; ++i)
  84. {
  85. renderSkyFace(i);
  86. }
  87. gGL.popMatrix();
  88. }
  89. void LLDrawPoolSky::renderSkyFace(U8 index)
  90. {
  91. LLFace* facep = mDrawFace[index];
  92. if (!facep || !facep->getGeomCount())
  93. {
  94. return;
  95. }
  96. if (index < LLVOSky::FACE_SUN) // Sky texture, interpolate
  97. {
  98. mSkyTex[index].bindTexture(true); // Bind the current texture
  99. facep->renderIndexed();
  100. }
  101. else if (index == LLVOSky::FACE_MOON) // Moon
  102. {
  103. // SL-14113: write depth for Moon so stars can test if behind it
  104. LLGLSPipelineDepthTestSkyBox gls_skybox(GL_TRUE, GL_TRUE);
  105. LLGLEnable blend(GL_BLEND);
  106. LLViewerTexture* texp = facep->getTexture(LLRender::DIFFUSE_MAP);
  107. if (texp)
  108. {
  109. gMoonProgram.bind(); // SL-14113 was gOneTextureNoColorProgram
  110. gGL.getTexUnit(0)->bind(texp);
  111. facep->renderIndexed();
  112. }
  113. }
  114. else // Heavenly body faces, no interp.
  115. {
  116. // Reset to previous
  117. LLGLSPipelineDepthTestSkyBox gls_skybox(GL_TRUE, GL_FALSE);
  118. LLGLEnable blend(GL_BLEND);
  119. LLViewerTexture* texp = facep->getTexture(LLRender::DIFFUSE_MAP);
  120. if (texp)
  121. {
  122. gOneTextureNoColorProgram.bind();
  123. gGL.getTexUnit(0)->bind(texp);
  124. facep->renderIndexed();
  125. }
  126. }
  127. }