/opengles/src/ContextMesh.cpp

http://ftk.googlecode.com/ · C++ · 119 lines · 55 code · 22 blank · 42 comment · 9 complexity · cfa8fbc438486282f008f72e071738d6 MD5 · raw file

  1. // ==========================================================================
  2. //
  3. // ContextMesg Rendering Context Class for 3D Rendering Library
  4. //
  5. // Mesh rendering
  6. //
  7. // --------------------------------------------------------------------------
  8. //
  9. // 03-25-2004 Hans-Martin Will adaptation from prototype
  10. //
  11. // --------------------------------------------------------------------------
  12. //
  13. // Copyright (c) 2004, Hans-Martin Will. All rights reserved.
  14. //
  15. // Redistribution and use in source and binary forms, with or without
  16. // modification, are permitted provided that the following conditions are
  17. // met:
  18. //
  19. // * Redistributions of source code must retain the above copyright
  20. // notice, this list of conditions and the following disclaimer.
  21. // * Redistributions in binary form must reproduce the above copyright
  22. // notice, this list of conditions and the following disclaimer in the
  23. // documentation and/or other materials provided with the distribution.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  30. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. // THE POSSIBILITY OF SUCH DAMAGE.
  36. //
  37. // ==========================================================================
  38. #include "stdafx.h"
  39. #include "Context.h"
  40. using namespace EGL;
  41. /*
  42. Added by Valtteri Rahkonen:
  43. This is propably legacy (not declared on Context.h) and it wont compile
  44. with gcc, so I just if it out.
  45. */
  46. #if !defined(EGL_ON_LINUX)
  47. void Context :: DrawMesh(GLsizei count, GLenum type, GLsizei stride,
  48. GLsizei offsetVertex, GLsizei strideVertex,
  49. GLsizei offsetNormal, GLsizei strideNormal,
  50. GLsizei offsetTexture, GLsizei strideTexture,
  51. GLsizei offsetColor, GLsizei strideColor,
  52. const GLvoid *pointer) {
  53. m_Rasterizer->PrepareTriangle();
  54. RasterPos pos[3];
  55. if (type == GL_UNSIGNED_BYTE) {
  56. while (count-- > 0) {
  57. const U8 * pVertexIndex = reinterpret_cast<const U8 *>(pointer) + offsetVertex;
  58. const U8 * pNormalIndex = reinterpret_cast<const U8 *>(pointer) + offsetNormal;
  59. const U8 * pTextureIndex = reinterpret_cast<const U8 *>(pointer) + offsetTexture;
  60. const U8 * pColorIndex = reinterpret_cast<const U8 *>(pointer) + offsetColor;
  61. for (size_t index = 0; index < 3; ++index) {
  62. SelectArrayElement(*reinterpret_cast<const GLubyte *>(pVertexIndex),
  63. *reinterpret_cast<const GLubyte *>(pNormalIndex),
  64. *reinterpret_cast<const GLubyte *>(pTextureIndex),
  65. *reinterpret_cast<const GLubyte *>(pColorIndex));
  66. CurrentValuesToRasterPos(pos + index);
  67. pVertexIndex += strideVertex;
  68. pNormalIndex += strideNormal;
  69. pTextureIndex += strideTexture;
  70. pColorIndex += strideColor;
  71. }
  72. RenderTriangle(pos[0], pos[1], pos[2]);
  73. pointer = reinterpret_cast<const U8 *>(pointer) + stride;
  74. }
  75. } else if (type == GL_UNSIGNED_SHORT) {
  76. while (count-- > 0) {
  77. const U8 * pVertexIndex = reinterpret_cast<const U8 *>(pointer) + offsetVertex;
  78. const U8 * pNormalIndex = reinterpret_cast<const U8 *>(pointer) + offsetNormal;
  79. const U8 * pTextureIndex = reinterpret_cast<const U8 *>(pointer) + offsetTexture;
  80. const U8 * pColorIndex = reinterpret_cast<const U8 *>(pointer) + offsetColor;
  81. for (size_t index = 0; index < 3; ++index) {
  82. SelectArrayElement(*reinterpret_cast<const GLushort *>(pVertexIndex),
  83. *reinterpret_cast<const GLushort *>(pNormalIndex),
  84. *reinterpret_cast<const GLushort *>(pTextureIndex),
  85. *reinterpret_cast<const GLushort *>(pColorIndex));
  86. CurrentValuesToRasterPos(pos + index);
  87. pVertexIndex += strideVertex;
  88. pNormalIndex += strideNormal;
  89. pTextureIndex += strideTexture;
  90. pColorIndex += strideColor;
  91. }
  92. RenderTriangle(pos[0], pos[1], pos[2]);
  93. pointer = reinterpret_cast<const U8 *>(pointer) + stride;
  94. }
  95. }
  96. }
  97. #endif