PageRenderTime 33ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llvoground.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 168 lines | 101 code | 31 blank | 36 comment | 7 complexity | d5c127a96e67c31ba681a3d08f6f3093 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvoground.cpp
  3. * @brief LLVOGround class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&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 "llvoground.h"
  28. #include "lldrawpoolground.h"
  29. #include "llviewercontrol.h"
  30. #include "lldrawable.h"
  31. #include "llface.h"
  32. #include "llsky.h"
  33. #include "llviewercamera.h"
  34. #include "llviewerregion.h"
  35. #include "pipeline.h"
  36. LLVOGround::LLVOGround(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
  37. : LLStaticViewerObject(id, pcode, regionp, TRUE)
  38. {
  39. mbCanSelect = FALSE;
  40. }
  41. LLVOGround::~LLVOGround()
  42. {
  43. }
  44. BOOL LLVOGround::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
  45. {
  46. if (mDead || !(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_GROUND)))
  47. {
  48. return TRUE;
  49. }
  50. /*if (mDrawable)
  51. {
  52. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
  53. }*/
  54. return TRUE;
  55. }
  56. void LLVOGround::updateTextures()
  57. {
  58. }
  59. LLDrawable *LLVOGround::createDrawable(LLPipeline *pipeline)
  60. {
  61. pipeline->allocDrawable(this);
  62. mDrawable->setLit(FALSE);
  63. mDrawable->setRenderType(LLPipeline::RENDER_TYPE_GROUND);
  64. LLDrawPoolGround *poolp = (LLDrawPoolGround*) gPipeline.getPool(LLDrawPool::POOL_GROUND);
  65. mDrawable->addFace(poolp, NULL);
  66. return mDrawable;
  67. }
  68. BOOL LLVOGround::updateGeometry(LLDrawable *drawable)
  69. {
  70. LLStrider<LLVector3> verticesp;
  71. LLStrider<LLVector3> normalsp;
  72. LLStrider<LLVector2> texCoordsp;
  73. LLStrider<U16> indicesp;
  74. S32 index_offset;
  75. LLFace *face;
  76. LLDrawPoolGround *poolp = (LLDrawPoolGround*) gPipeline.getPool(LLDrawPool::POOL_GROUND);
  77. if (drawable->getNumFaces() < 1)
  78. drawable->addFace(poolp, NULL);
  79. face = drawable->getFace(0);
  80. if (!face->getVertexBuffer())
  81. {
  82. face->setSize(5, 12);
  83. LLVertexBuffer* buff = new LLVertexBuffer(LLDrawPoolGround::VERTEX_DATA_MASK, GL_STREAM_DRAW_ARB);
  84. buff->allocateBuffer(face->getGeomCount(), face->getIndicesCount(), TRUE);
  85. face->setGeomIndex(0);
  86. face->setIndicesIndex(0);
  87. face->setVertexBuffer(buff);
  88. }
  89. index_offset = face->getGeometry(verticesp,normalsp,texCoordsp, indicesp);
  90. if (-1 == index_offset)
  91. {
  92. return TRUE;
  93. }
  94. ///////////////////////////////////////
  95. //
  96. //
  97. //
  98. LLVector3 at_dir = LLViewerCamera::getInstance()->getAtAxis();
  99. at_dir.mV[VZ] = 0.f;
  100. if (at_dir.normVec() < 0.01)
  101. {
  102. // We really don't care, as we're not looking anywhere near the horizon.
  103. }
  104. LLVector3 left_dir = LLViewerCamera::getInstance()->getLeftAxis();
  105. left_dir.mV[VZ] = 0.f;
  106. left_dir.normVec();
  107. // Our center top point
  108. LLColor4 ground_color = gSky.getFogColor();
  109. ground_color.mV[3] = 1.f;
  110. face->setFaceColor(ground_color);
  111. *(verticesp++) = LLVector3(64, 64, 0);
  112. *(verticesp++) = LLVector3(-64, 64, 0);
  113. *(verticesp++) = LLVector3(-64, -64, 0);
  114. *(verticesp++) = LLVector3(64, -64, 0);
  115. *(verticesp++) = LLVector3(0, 0, -1024);
  116. // Triangles for each side
  117. *indicesp++ = index_offset + 0;
  118. *indicesp++ = index_offset + 1;
  119. *indicesp++ = index_offset + 4;
  120. *indicesp++ = index_offset + 1;
  121. *indicesp++ = index_offset + 2;
  122. *indicesp++ = index_offset + 4;
  123. *indicesp++ = index_offset + 2;
  124. *indicesp++ = index_offset + 3;
  125. *indicesp++ = index_offset + 4;
  126. *indicesp++ = index_offset + 3;
  127. *indicesp++ = index_offset + 0;
  128. *indicesp++ = index_offset + 4;
  129. *(texCoordsp++) = LLVector2(0.f, 0.f);
  130. *(texCoordsp++) = LLVector2(1.f, 0.f);
  131. *(texCoordsp++) = LLVector2(1.f, 1.f);
  132. *(texCoordsp++) = LLVector2(0.f, 1.f);
  133. *(texCoordsp++) = LLVector2(0.5f, 0.5f);
  134. face->getVertexBuffer()->flush();
  135. LLPipeline::sCompiles++;
  136. return TRUE;
  137. }