Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

m_clip_tmp.h 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Mesa 3-D graphics library
  3. * Version: 6.2
  4. *
  5. * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /*
  25. * New (3.1) transformation code written by Keith Whitwell.
  26. */
  27. /* KW: a clever asm implementation would nestle integer versions
  28. * of the outcode calculation underneath the division. Gcc won't
  29. * do this, strangely enough, so I only do the divide in
  30. * the case where the cliptest passes. This isn't essential,
  31. * and an asm implementation needn't replicate that behaviour.
  32. *
  33. * \param clip_vec vector of incoming clip-space coords
  34. * \param proj_vec vector of resultant NDC-space projected coords
  35. * \param clipMask resulting array of clip flags
  36. * \param orMask bitwise-OR of clipMask values
  37. * \param andMask bitwise-AND of clipMask values
  38. * \return proj_vec pointer
  39. */
  40. static GLvector4f * _XFORMAPI TAG(cliptest_points4)( GLvector4f *clip_vec,
  41. GLvector4f *proj_vec,
  42. GLubyte clipMask[],
  43. GLubyte *orMask,
  44. GLubyte *andMask )
  45. {
  46. const GLuint stride = clip_vec->stride;
  47. const GLfloat *from = (GLfloat *)clip_vec->start;
  48. const GLuint count = clip_vec->count;
  49. GLuint c = 0;
  50. GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
  51. GLubyte tmpAndMask = *andMask;
  52. GLubyte tmpOrMask = *orMask;
  53. GLuint i;
  54. STRIDE_LOOP {
  55. const GLfloat cx = from[0];
  56. const GLfloat cy = from[1];
  57. const GLfloat cz = from[2];
  58. const GLfloat cw = from[3];
  59. #if defined(macintosh) || defined(__powerpc__)
  60. /* on powerpc cliptest is 17% faster in this way. */
  61. GLuint mask;
  62. mask = (((cw < cx) << CLIP_RIGHT_SHIFT));
  63. mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
  64. mask |= (((cw < cy) << CLIP_TOP_SHIFT));
  65. mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
  66. mask |= (((cw < cz) << CLIP_FAR_SHIFT));
  67. mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
  68. #else /* !defined(macintosh)) */
  69. GLubyte mask = 0;
  70. if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
  71. if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
  72. if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
  73. if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
  74. if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
  75. if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
  76. #endif /* defined(macintosh) */
  77. clipMask[i] = mask;
  78. if (mask) {
  79. c++;
  80. tmpAndMask &= mask;
  81. tmpOrMask |= mask;
  82. vProj[i][0] = 0;
  83. vProj[i][1] = 0;
  84. vProj[i][2] = 0;
  85. vProj[i][3] = 1;
  86. } else {
  87. GLfloat oow = 1.0F / cw;
  88. vProj[i][0] = cx * oow;
  89. vProj[i][1] = cy * oow;
  90. vProj[i][2] = cz * oow;
  91. vProj[i][3] = oow;
  92. }
  93. }
  94. *orMask = tmpOrMask;
  95. *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
  96. proj_vec->flags |= VEC_SIZE_4;
  97. proj_vec->size = 4;
  98. proj_vec->count = clip_vec->count;
  99. return proj_vec;
  100. }
  101. /*
  102. * \param clip_vec vector of incoming clip-space coords
  103. * \param proj_vec vector of resultant NDC-space projected coords
  104. * \param clipMask resulting array of clip flags
  105. * \param orMask bitwise-OR of clipMask values
  106. * \param andMask bitwise-AND of clipMask values
  107. * \return clip_vec pointer
  108. */
  109. static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec,
  110. GLvector4f *proj_vec,
  111. GLubyte clipMask[],
  112. GLubyte *orMask,
  113. GLubyte *andMask )
  114. {
  115. const GLuint stride = clip_vec->stride;
  116. const GLuint count = clip_vec->count;
  117. const GLfloat *from = (GLfloat *)clip_vec->start;
  118. GLuint c = 0;
  119. GLubyte tmpAndMask = *andMask;
  120. GLubyte tmpOrMask = *orMask;
  121. GLuint i;
  122. (void) proj_vec;
  123. STRIDE_LOOP {
  124. const GLfloat cx = from[0];
  125. const GLfloat cy = from[1];
  126. const GLfloat cz = from[2];
  127. const GLfloat cw = from[3];
  128. #if defined(macintosh) || defined(__powerpc__)
  129. /* on powerpc cliptest is 17% faster in this way. */
  130. GLuint mask;
  131. mask = (((cw < cx) << CLIP_RIGHT_SHIFT));
  132. mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
  133. mask |= (((cw < cy) << CLIP_TOP_SHIFT));
  134. mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
  135. mask |= (((cw < cz) << CLIP_FAR_SHIFT));
  136. mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
  137. #else /* !defined(macintosh)) */
  138. GLubyte mask = 0;
  139. if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
  140. if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
  141. if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
  142. if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
  143. if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
  144. if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
  145. #endif /* defined(macintosh) */
  146. clipMask[i] = mask;
  147. if (mask) {
  148. c++;
  149. tmpAndMask &= mask;
  150. tmpOrMask |= mask;
  151. }
  152. }
  153. *orMask = tmpOrMask;
  154. *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
  155. return clip_vec;
  156. }
  157. static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec,
  158. GLvector4f *proj_vec,
  159. GLubyte clipMask[],
  160. GLubyte *orMask,
  161. GLubyte *andMask )
  162. {
  163. const GLuint stride = clip_vec->stride;
  164. const GLuint count = clip_vec->count;
  165. const GLfloat *from = (GLfloat *)clip_vec->start;
  166. GLubyte tmpOrMask = *orMask;
  167. GLubyte tmpAndMask = *andMask;
  168. GLuint i;
  169. (void) proj_vec;
  170. STRIDE_LOOP {
  171. const GLfloat cx = from[0], cy = from[1], cz = from[2];
  172. GLubyte mask = 0;
  173. if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
  174. else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
  175. if (cy > 1.0) mask |= CLIP_TOP_BIT;
  176. else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
  177. if (cz > 1.0) mask |= CLIP_FAR_BIT;
  178. else if (cz < -1.0) mask |= CLIP_NEAR_BIT;
  179. clipMask[i] = mask;
  180. tmpOrMask |= mask;
  181. tmpAndMask &= mask;
  182. }
  183. *orMask = tmpOrMask;
  184. *andMask = tmpAndMask;
  185. return clip_vec;
  186. }
  187. static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec,
  188. GLvector4f *proj_vec,
  189. GLubyte clipMask[],
  190. GLubyte *orMask,
  191. GLubyte *andMask )
  192. {
  193. const GLuint stride = clip_vec->stride;
  194. const GLuint count = clip_vec->count;
  195. const GLfloat *from = (GLfloat *)clip_vec->start;
  196. GLubyte tmpOrMask = *orMask;
  197. GLubyte tmpAndMask = *andMask;
  198. GLuint i;
  199. (void) proj_vec;
  200. STRIDE_LOOP {
  201. const GLfloat cx = from[0], cy = from[1];
  202. GLubyte mask = 0;
  203. if (cx > 1.0) mask |= CLIP_RIGHT_BIT;
  204. else if (cx < -1.0) mask |= CLIP_LEFT_BIT;
  205. if (cy > 1.0) mask |= CLIP_TOP_BIT;
  206. else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT;
  207. clipMask[i] = mask;
  208. tmpOrMask |= mask;
  209. tmpAndMask &= mask;
  210. }
  211. *orMask = tmpOrMask;
  212. *andMask = tmpAndMask;
  213. return clip_vec;
  214. }
  215. static void TAG(init_c_cliptest)( void )
  216. {
  217. _mesa_clip_tab[4] = TAG(cliptest_points4);
  218. _mesa_clip_tab[3] = TAG(cliptest_points3);
  219. _mesa_clip_tab[2] = TAG(cliptest_points2);
  220. _mesa_clip_np_tab[4] = TAG(cliptest_np_points4);
  221. _mesa_clip_np_tab[3] = TAG(cliptest_points3);
  222. _mesa_clip_np_tab[2] = TAG(cliptest_points2);
  223. }