/opengles/src/ContextPoints.cpp

http://ftk.googlecode.com/ · C++ · 242 lines · 146 code · 55 blank · 41 comment · 26 complexity · 2cec7cf0fa7be5fe62734ea1637f44d5 MD5 · raw file

  1. // ==========================================================================
  2. //
  3. // points.cpp Rendering Context Class for 3D Rendering Library
  4. //
  5. // Rendering Operations for Points
  6. //
  7. // --------------------------------------------------------------------------
  8. //
  9. // 08-12-2003 Hans-Martin Will initial version
  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. #include "fixed.h"
  41. #include "Rasterizer.h"
  42. using namespace EGL;
  43. void Context :: PointSizex(GLfixed size) {
  44. if (size <= 0) {
  45. RecordError(GL_INVALID_VALUE);
  46. } else {
  47. m_PointSize = size;
  48. }
  49. }
  50. inline EGL_Fixed Context :: SelectPointSizeArrayElement(int index) {
  51. if (!m_PointSizeArray.effectivePointer) {
  52. // as long as we do not have anti-aliasing, determining the point size here is fine
  53. return m_PointSize;
  54. } else {
  55. EGL_Fixed coords[1];
  56. m_PointSizeArray.FetchValues(index, coords);
  57. return coords[0];
  58. }
  59. }
  60. void Context :: RenderPoints(GLint first, GLsizei count) {
  61. m_Rasterizer->PreparePoint();
  62. while (count >= 1) {
  63. count -= 1;
  64. RasterPos pos0;
  65. EGL_Fixed size = SelectPointSizeArrayElement(first);
  66. SelectArrayElement(first++);
  67. CurrentValuesToRasterPos(&pos0);
  68. RenderPoint(pos0, size);
  69. }
  70. }
  71. void Context :: RenderPoints(GLsizei count, const GLubyte * indices) {
  72. m_Rasterizer->PreparePoint();
  73. while (count >= 1) {
  74. count -= 1;
  75. RasterPos pos0;
  76. EGL_Fixed size = SelectPointSizeArrayElement(*indices);
  77. SelectArrayElement(*indices++);
  78. CurrentValuesToRasterPos(&pos0);
  79. RenderPoint(pos0, size);
  80. }
  81. }
  82. void Context :: RenderPoints(GLsizei count, const GLushort * indices) {
  83. m_Rasterizer->PreparePoint();
  84. while (count >= 1) {
  85. count -= 1;
  86. RasterPos pos0;
  87. EGL_Fixed size = SelectPointSizeArrayElement(*indices);
  88. SelectArrayElement(*indices++);
  89. CurrentValuesToRasterPos(&pos0);
  90. RenderPoint(pos0, size);
  91. }
  92. }
  93. void Context :: RenderPoint(RasterPos& point, EGL_Fixed size) {
  94. // any user defined clip planes?
  95. if (m_ClipPlaneEnabled) {
  96. for (size_t index = 0, mask = 1; index < NUM_CLIP_PLANES; ++index, mask <<= 1) {
  97. if (m_ClipPlaneEnabled & mask) {
  98. if (point.m_EyeCoords * m_ClipPlanes[index] < 0) {
  99. return;
  100. }
  101. }
  102. }
  103. }
  104. // in principle, the scissor test can be included in here
  105. if (point.m_ClipCoords.x() < -point.m_ClipCoords.w() ||
  106. point.m_ClipCoords.x() > point.m_ClipCoords.w() ||
  107. point.m_ClipCoords.y() < -point.m_ClipCoords.w() ||
  108. point.m_ClipCoords.y() > point.m_ClipCoords.w() ||
  109. point.m_ClipCoords.z() < -point.m_ClipCoords.w() ||
  110. point.m_ClipCoords.z() > point.m_ClipCoords.w())
  111. return;
  112. ClipCoordsToWindowCoords(point);
  113. point.m_Color = point.m_FrontColor;
  114. if (m_PointSizeAttenuate) {
  115. EGL_Fixed eyeDistance = EGL_Abs(point.m_EyeCoords.z());
  116. EGL_Fixed factor =
  117. EGL_InvSqrt(m_PointDistanceAttenuation[0] +
  118. EGL_Mul(m_PointDistanceAttenuation[1], eyeDistance) +
  119. EGL_Mul(m_PointDistanceAttenuation[2], EGL_Mul(eyeDistance, eyeDistance)));
  120. size = EGL_Mul(size, factor);
  121. }
  122. // as long as we do not have anti-aliasing, determining the effective point size here is fine
  123. EGL_Fixed pointSize = EGL_Max(size, EGL_ONE);
  124. m_Rasterizer->RasterPoint(point, pointSize);
  125. }
  126. void Context :: PointSizePointer(GLenum type, GLsizei stride, const GLvoid *pointer) {
  127. if (type != GL_FIXED && type != GL_FLOAT) {
  128. RecordError(GL_INVALID_ENUM);
  129. return;
  130. }
  131. const size_t size = 1;
  132. if (stride < 0) {
  133. RecordError(GL_INVALID_VALUE);
  134. return;
  135. }
  136. if (stride == 0) {
  137. switch (type) {
  138. case GL_BYTE:
  139. stride = sizeof (GLbyte) * size;
  140. break;
  141. case GL_SHORT:
  142. stride = sizeof (GLshort) * size;
  143. break;
  144. case GL_FIXED:
  145. stride = sizeof (GLfixed) * size;
  146. break;
  147. case GL_FLOAT:
  148. stride = sizeof (GLfloat) * size;
  149. break;
  150. }
  151. }
  152. m_PointSizeArray.pointer = pointer;
  153. m_PointSizeArray.stride = stride;
  154. m_PointSizeArray.type = type;
  155. m_PointSizeArray.size = size;
  156. m_PointSizeArray.boundBuffer = m_CurrentArrayBuffer;
  157. }
  158. void Context :: PointParameterx(GLenum pname, GLfixed param) {
  159. switch (pname) {
  160. case GL_POINT_SIZE_MIN:
  161. m_PointSizeMin = param;
  162. break;
  163. case GL_POINT_SIZE_MAX:
  164. m_PointSizeMax = param;
  165. break;
  166. case GL_POINT_FADE_THRESHOLD_SIZE:
  167. m_PointFadeThresholdSize = param;
  168. break;
  169. default:
  170. RecordError(GL_INVALID_ENUM);
  171. break;
  172. }
  173. }
  174. void Context :: PointParameterxv(GLenum pname, const GLfixed *params) {
  175. switch (pname) {
  176. case GL_POINT_DISTANCE_ATTENUATION:
  177. m_PointDistanceAttenuation[0] = params[0];
  178. m_PointDistanceAttenuation[1] = params[1];
  179. m_PointDistanceAttenuation[2] = params[2];
  180. m_PointSizeAttenuate =
  181. (params[0] != EGL_ONE || params[1] || params[2]);
  182. break;
  183. default:
  184. PointParameterx(pname, *params);
  185. break;
  186. }
  187. }