PageRenderTime 79ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llbox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 125 lines | 52 code | 12 blank | 61 comment | 0 complexity | fec38995bd5a96a787c3eb6abe7458c4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llbox.cpp
  3. * @brief Draws a box using display lists for speed.
  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 "llbox.h"
  28. #include "llgl.h"
  29. #include "llrender.h"
  30. #include "llglheaders.h"
  31. LLBox gBox;
  32. // These routines support multiple textures on a box
  33. void LLBox::prerender()
  34. {
  35. F32 size = 1.f;
  36. mTriangleCount = 6 * 2;
  37. mVertex[0][0] = mVertex[1][0] = mVertex[2][0] = mVertex[3][0] = -size / 2;
  38. mVertex[4][0] = mVertex[5][0] = mVertex[6][0] = mVertex[7][0] = size / 2;
  39. mVertex[0][1] = mVertex[1][1] = mVertex[4][1] = mVertex[5][1] = -size / 2;
  40. mVertex[2][1] = mVertex[3][1] = mVertex[6][1] = mVertex[7][1] = size / 2;
  41. mVertex[0][2] = mVertex[3][2] = mVertex[4][2] = mVertex[7][2] = -size / 2;
  42. mVertex[1][2] = mVertex[2][2] = mVertex[5][2] = mVertex[6][2] = size / 2;
  43. }
  44. // These routines support multiple textures on a box
  45. void LLBox::cleanupGL()
  46. {
  47. // No GL state, a noop.
  48. }
  49. void LLBox::renderface(S32 which_face)
  50. {
  51. /*static F32 normals[6][3] =
  52. {
  53. {-1.0f, 0.0f, 0.0f},
  54. { 0.0f, 1.0f, 0.0f},
  55. { 1.0f, 0.0f, 0.0f},
  56. { 0.0f, -1.0f, 0.0f},
  57. { 0.0f, 0.0f, 1.0f},
  58. { 0.0f, 0.0f, -1.0f}
  59. };*/
  60. static S32 faces[6][4] =
  61. {
  62. {0, 1, 2, 3},
  63. {3, 2, 6, 7},
  64. {7, 6, 5, 4},
  65. {4, 5, 1, 0},
  66. {5, 6, 2, 1},
  67. {7, 4, 0, 3}
  68. };
  69. gGL.begin(LLRender::QUADS);
  70. //gGL.normal3fv(&normals[which_face][0]);
  71. gGL.texCoord2f(1,0);
  72. gGL.vertex3fv(&mVertex[ faces[which_face][0] ][0]);
  73. gGL.texCoord2f(1,1);
  74. gGL.vertex3fv(&mVertex[ faces[which_face][1] ][0]);
  75. gGL.texCoord2f(0,1);
  76. gGL.vertex3fv(&mVertex[ faces[which_face][2] ][0]);
  77. gGL.texCoord2f(0,0);
  78. gGL.vertex3fv(&mVertex[ faces[which_face][3] ][0]);
  79. gGL.end();
  80. }
  81. void LLBox::render()
  82. {
  83. // This is a flattend representation of the box as render here
  84. // .
  85. // (-++) (+++) /|\t
  86. // +------------+ | (texture coordinates)
  87. // |2 1| |
  88. // | 4 | (*) --->s
  89. // | TOP |
  90. // | |
  91. // (-++) (--+)|3 0|(+-+) (+++) (-++)
  92. // +------------+------------+------------+------------+
  93. // |2 1|2 1|2 1|2 1|
  94. // | 0 | 1 | 2 | 3 |
  95. // | BACK | RIGHT | FRONT | LEFT |
  96. // | | | | |
  97. // |3 0|3 0|3 0|3 0|
  98. // +------------+------------+------------+------------+
  99. // (-+-) (---)|2 1|(+--) (++-) (-+-)
  100. // | 5 |
  101. // | BOTTOM |
  102. // | |
  103. // |3 0|
  104. // +------------+
  105. // (-+-) (++-)
  106. renderface(5);
  107. renderface(4);
  108. renderface(3);
  109. renderface(2);
  110. renderface(1);
  111. renderface(0);
  112. gGL.flush();
  113. }