Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

m_xform_tmp.h 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*
  2. * Mesa 3-D graphics library
  3. * Version: 3.5
  4. *
  5. * Copyright (C) 1999-2001 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. /*----------------------------------------------------------------------
  28. * Begin Keith's new code
  29. *
  30. *----------------------------------------------------------------------
  31. */
  32. /* KW: Fixed stride, now measured in bytes as is the OpenGL array stride.
  33. */
  34. /* KW: These are now parameterized to produce two versions, one
  35. * which transforms all incoming points, and a second which
  36. * takes notice of a cullmask array, and only transforms
  37. * unculled vertices.
  38. */
  39. /* KW: 1-vectors can sneak into the texture pipeline via the array
  40. * interface. These functions are here because I want consistant
  41. * treatment of the vertex sizes and a lazy strategy for
  42. * cleaning unused parts of the vector, and so as not to exclude
  43. * them from the vertex array interface.
  44. *
  45. * Under our current analysis of matrices, there is no way that
  46. * the product of a matrix and a 1-vector can remain a 1-vector,
  47. * with the exception of the identity transform.
  48. */
  49. /* KW: No longer zero-pad outgoing vectors. Now that external
  50. * vectors can get into the pipeline we cannot ever assume
  51. * that there is more to a vector than indicated by its
  52. * size.
  53. */
  54. /* KW: Now uses clipmask and a flag to allow us to skip both/either
  55. * cliped and/or culled vertices.
  56. */
  57. /* GH: Not any more -- it's easier (and faster) to just process the
  58. * entire vector. Clipping and culling are handled further down
  59. * the pipe, most often during or after the conversion to some
  60. * driver-specific vertex format.
  61. */
  62. static void _XFORMAPI
  63. TAG(transform_points1_general)( GLvector4f *to_vec,
  64. const GLfloat m[16],
  65. const GLvector4f *from_vec )
  66. {
  67. const GLuint stride = from_vec->stride;
  68. GLfloat *from = from_vec->start;
  69. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  70. GLuint count = from_vec->count;
  71. const GLfloat m0 = m[0], m12 = m[12];
  72. const GLfloat m1 = m[1], m13 = m[13];
  73. const GLfloat m2 = m[2], m14 = m[14];
  74. const GLfloat m3 = m[3], m15 = m[15];
  75. GLuint i;
  76. STRIDE_LOOP {
  77. const GLfloat ox = from[0];
  78. to[i][0] = m0 * ox + m12;
  79. to[i][1] = m1 * ox + m13;
  80. to[i][2] = m2 * ox + m14;
  81. to[i][3] = m3 * ox + m15;
  82. }
  83. to_vec->size = 4;
  84. to_vec->flags |= VEC_SIZE_4;
  85. to_vec->count = from_vec->count;
  86. }
  87. static void _XFORMAPI
  88. TAG(transform_points1_identity)( GLvector4f *to_vec,
  89. const GLfloat m[16],
  90. const GLvector4f *from_vec )
  91. {
  92. const GLuint stride = from_vec->stride;
  93. GLfloat *from = from_vec->start;
  94. GLuint count = from_vec->count;
  95. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  96. GLuint i;
  97. (void) m;
  98. if (to_vec == from_vec) return;
  99. STRIDE_LOOP {
  100. to[i][0] = from[0];
  101. }
  102. to_vec->size = 1;
  103. to_vec->flags |= VEC_SIZE_1;
  104. to_vec->count = from_vec->count;
  105. }
  106. static void _XFORMAPI
  107. TAG(transform_points1_2d)( GLvector4f *to_vec,
  108. const GLfloat m[16],
  109. const GLvector4f *from_vec )
  110. {
  111. const GLuint stride = from_vec->stride;
  112. GLfloat *from = from_vec->start;
  113. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  114. GLuint count = from_vec->count;
  115. const GLfloat m0 = m[0], m1 = m[1];
  116. const GLfloat m12 = m[12], m13 = m[13];
  117. GLuint i;
  118. STRIDE_LOOP {
  119. const GLfloat ox = from[0];
  120. to[i][0] = m0 * ox + m12;
  121. to[i][1] = m1 * ox + m13;
  122. }
  123. to_vec->size = 2;
  124. to_vec->flags |= VEC_SIZE_2;
  125. to_vec->count = from_vec->count;
  126. }
  127. static void _XFORMAPI
  128. TAG(transform_points1_2d_no_rot)( GLvector4f *to_vec,
  129. const GLfloat m[16],
  130. const GLvector4f *from_vec )
  131. {
  132. const GLuint stride = from_vec->stride;
  133. GLfloat *from = from_vec->start;
  134. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  135. GLuint count = from_vec->count;
  136. const GLfloat m0 = m[0], m12 = m[12], m13 = m[13];
  137. GLuint i;
  138. STRIDE_LOOP {
  139. const GLfloat ox = from[0];
  140. to[i][0] = m0 * ox + m12;
  141. to[i][1] = m13;
  142. }
  143. to_vec->size = 2;
  144. to_vec->flags |= VEC_SIZE_2;
  145. to_vec->count = from_vec->count;
  146. }
  147. static void _XFORMAPI
  148. TAG(transform_points1_3d)( GLvector4f *to_vec,
  149. const GLfloat m[16],
  150. const GLvector4f *from_vec )
  151. {
  152. const GLuint stride = from_vec->stride;
  153. GLfloat *from = from_vec->start;
  154. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  155. GLuint count = from_vec->count;
  156. const GLfloat m0 = m[0], m1 = m[1], m2 = m[2];
  157. const GLfloat m12 = m[12], m13 = m[13], m14 = m[14];
  158. GLuint i;
  159. STRIDE_LOOP {
  160. const GLfloat ox = from[0];
  161. to[i][0] = m0 * ox + m12;
  162. to[i][1] = m1 * ox + m13;
  163. to[i][2] = m2 * ox + m14;
  164. }
  165. to_vec->size = 3;
  166. to_vec->flags |= VEC_SIZE_3;
  167. to_vec->count = from_vec->count;
  168. }
  169. static void _XFORMAPI
  170. TAG(transform_points1_3d_no_rot)( GLvector4f *to_vec,
  171. const GLfloat m[16],
  172. const GLvector4f *from_vec )
  173. {
  174. const GLuint stride = from_vec->stride;
  175. GLfloat *from = from_vec->start;
  176. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  177. GLuint count = from_vec->count;
  178. const GLfloat m0 = m[0];
  179. const GLfloat m12 = m[12], m13 = m[13], m14 = m[14];
  180. GLuint i;
  181. STRIDE_LOOP {
  182. const GLfloat ox = from[0];
  183. to[i][0] = m0 * ox + m12;
  184. to[i][1] = m13;
  185. to[i][2] = m14;
  186. }
  187. to_vec->size = 3;
  188. to_vec->flags |= VEC_SIZE_3;
  189. to_vec->count = from_vec->count;
  190. }
  191. static void _XFORMAPI
  192. TAG(transform_points1_perspective)( GLvector4f *to_vec,
  193. const GLfloat m[16],
  194. const GLvector4f *from_vec )
  195. {
  196. const GLuint stride = from_vec->stride;
  197. GLfloat *from = from_vec->start;
  198. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  199. GLuint count = from_vec->count;
  200. const GLfloat m0 = m[0], m14 = m[14];
  201. GLuint i;
  202. STRIDE_LOOP {
  203. const GLfloat ox = from[0];
  204. to[i][0] = m0 * ox ;
  205. to[i][1] = 0 ;
  206. to[i][2] = m14;
  207. to[i][3] = 0;
  208. }
  209. to_vec->size = 4;
  210. to_vec->flags |= VEC_SIZE_4;
  211. to_vec->count = from_vec->count;
  212. }
  213. /* 2-vectors, which are a lot more relevant than 1-vectors, are
  214. * present early in the geometry pipeline and throughout the
  215. * texture pipeline.
  216. */
  217. static void _XFORMAPI
  218. TAG(transform_points2_general)( GLvector4f *to_vec,
  219. const GLfloat m[16],
  220. const GLvector4f *from_vec )
  221. {
  222. const GLuint stride = from_vec->stride;
  223. GLfloat *from = from_vec->start;
  224. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  225. GLuint count = from_vec->count;
  226. const GLfloat m0 = m[0], m4 = m[4], m12 = m[12];
  227. const GLfloat m1 = m[1], m5 = m[5], m13 = m[13];
  228. const GLfloat m2 = m[2], m6 = m[6], m14 = m[14];
  229. const GLfloat m3 = m[3], m7 = m[7], m15 = m[15];
  230. GLuint i;
  231. STRIDE_LOOP {
  232. const GLfloat ox = from[0], oy = from[1];
  233. to[i][0] = m0 * ox + m4 * oy + m12;
  234. to[i][1] = m1 * ox + m5 * oy + m13;
  235. to[i][2] = m2 * ox + m6 * oy + m14;
  236. to[i][3] = m3 * ox + m7 * oy + m15;
  237. }
  238. to_vec->size = 4;
  239. to_vec->flags |= VEC_SIZE_4;
  240. to_vec->count = from_vec->count;
  241. }
  242. static void _XFORMAPI
  243. TAG(transform_points2_identity)( GLvector4f *to_vec,
  244. const GLfloat m[16],
  245. const GLvector4f *from_vec )
  246. {
  247. const GLuint stride = from_vec->stride;
  248. GLfloat *from = from_vec->start;
  249. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  250. GLuint count = from_vec->count;
  251. GLuint i;
  252. (void) m;
  253. if (to_vec == from_vec) return;
  254. STRIDE_LOOP {
  255. to[i][0] = from[0];
  256. to[i][1] = from[1];
  257. }
  258. to_vec->size = 2;
  259. to_vec->flags |= VEC_SIZE_2;
  260. to_vec->count = from_vec->count;
  261. }
  262. static void _XFORMAPI
  263. TAG(transform_points2_2d)( GLvector4f *to_vec,
  264. const GLfloat m[16],
  265. const GLvector4f *from_vec )
  266. {
  267. const GLuint stride = from_vec->stride;
  268. GLfloat *from = from_vec->start;
  269. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  270. GLuint count = from_vec->count;
  271. const GLfloat m0 = m[0], m1 = m[1], m4 = m[4], m5 = m[5];
  272. const GLfloat m12 = m[12], m13 = m[13];
  273. GLuint i;
  274. STRIDE_LOOP {
  275. const GLfloat ox = from[0], oy = from[1];
  276. to[i][0] = m0 * ox + m4 * oy + m12;
  277. to[i][1] = m1 * ox + m5 * oy + m13;
  278. }
  279. to_vec->size = 2;
  280. to_vec->flags |= VEC_SIZE_2;
  281. to_vec->count = from_vec->count;
  282. }
  283. static void _XFORMAPI
  284. TAG(transform_points2_2d_no_rot)( GLvector4f *to_vec,
  285. const GLfloat m[16],
  286. const GLvector4f *from_vec )
  287. {
  288. const GLuint stride = from_vec->stride;
  289. GLfloat *from = from_vec->start;
  290. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  291. GLuint count = from_vec->count;
  292. const GLfloat m0 = m[0], m5 = m[5], m12 = m[12], m13 = m[13];
  293. GLuint i;
  294. STRIDE_LOOP {
  295. const GLfloat ox = from[0], oy = from[1];
  296. to[i][0] = m0 * ox + m12;
  297. to[i][1] = m5 * oy + m13;
  298. }
  299. to_vec->size = 2;
  300. to_vec->flags |= VEC_SIZE_2;
  301. to_vec->count = from_vec->count;
  302. }
  303. static void _XFORMAPI
  304. TAG(transform_points2_3d)( GLvector4f *to_vec,
  305. const GLfloat m[16],
  306. const GLvector4f *from_vec )
  307. {
  308. const GLuint stride = from_vec->stride;
  309. GLfloat *from = from_vec->start;
  310. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  311. GLuint count = from_vec->count;
  312. const GLfloat m0 = m[0], m1 = m[1], m2 = m[2], m4 = m[4], m5 = m[5];
  313. const GLfloat m6 = m[6], m12 = m[12], m13 = m[13], m14 = m[14];
  314. GLuint i;
  315. STRIDE_LOOP {
  316. const GLfloat ox = from[0], oy = from[1];
  317. to[i][0] = m0 * ox + m4 * oy + m12;
  318. to[i][1] = m1 * ox + m5 * oy + m13;
  319. to[i][2] = m2 * ox + m6 * oy + m14;
  320. }
  321. to_vec->size = 3;
  322. to_vec->flags |= VEC_SIZE_3;
  323. to_vec->count = from_vec->count;
  324. }
  325. /* I would actually say this was a fairly important function, from
  326. * a texture transformation point of view.
  327. */
  328. static void _XFORMAPI
  329. TAG(transform_points2_3d_no_rot)( GLvector4f *to_vec,
  330. const GLfloat m[16],
  331. const GLvector4f *from_vec )
  332. {
  333. const GLuint stride = from_vec->stride;
  334. GLfloat *from = from_vec->start;
  335. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  336. GLuint count = from_vec->count;
  337. const GLfloat m0 = m[0], m5 = m[5];
  338. const GLfloat m12 = m[12], m13 = m[13], m14 = m[14];
  339. GLuint i;
  340. STRIDE_LOOP {
  341. const GLfloat ox = from[0], oy = from[1];
  342. to[i][0] = m0 * ox + m12;
  343. to[i][1] = m5 * oy + m13;
  344. to[i][2] = m14;
  345. }
  346. if (m14 == 0) {
  347. to_vec->size = 2;
  348. to_vec->flags |= VEC_SIZE_2;
  349. } else {
  350. to_vec->size = 3;
  351. to_vec->flags |= VEC_SIZE_3;
  352. }
  353. to_vec->count = from_vec->count;
  354. }
  355. static void _XFORMAPI
  356. TAG(transform_points2_perspective)( GLvector4f *to_vec,
  357. const GLfloat m[16],
  358. const GLvector4f *from_vec )
  359. {
  360. const GLuint stride = from_vec->stride;
  361. GLfloat *from = from_vec->start;
  362. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  363. GLuint count = from_vec->count;
  364. const GLfloat m0 = m[0], m5 = m[5], m14 = m[14];
  365. GLuint i;
  366. STRIDE_LOOP {
  367. const GLfloat ox = from[0], oy = from[1];
  368. to[i][0] = m0 * ox ;
  369. to[i][1] = m5 * oy ;
  370. to[i][2] = m14;
  371. to[i][3] = 0;
  372. }
  373. to_vec->size = 4;
  374. to_vec->flags |= VEC_SIZE_4;
  375. to_vec->count = from_vec->count;
  376. }
  377. static void _XFORMAPI
  378. TAG(transform_points3_general)( GLvector4f *to_vec,
  379. const GLfloat m[16],
  380. const GLvector4f *from_vec )
  381. {
  382. const GLuint stride = from_vec->stride;
  383. GLfloat *from = from_vec->start;
  384. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  385. GLuint count = from_vec->count;
  386. const GLfloat m0 = m[0], m4 = m[4], m8 = m[8], m12 = m[12];
  387. const GLfloat m1 = m[1], m5 = m[5], m9 = m[9], m13 = m[13];
  388. const GLfloat m2 = m[2], m6 = m[6], m10 = m[10], m14 = m[14];
  389. const GLfloat m3 = m[3], m7 = m[7], m11 = m[11], m15 = m[15];
  390. GLuint i;
  391. STRIDE_LOOP {
  392. const GLfloat ox = from[0], oy = from[1], oz = from[2];
  393. to[i][0] = m0 * ox + m4 * oy + m8 * oz + m12;
  394. to[i][1] = m1 * ox + m5 * oy + m9 * oz + m13;
  395. to[i][2] = m2 * ox + m6 * oy + m10 * oz + m14;
  396. to[i][3] = m3 * ox + m7 * oy + m11 * oz + m15;
  397. }
  398. to_vec->size = 4;
  399. to_vec->flags |= VEC_SIZE_4;
  400. to_vec->count = from_vec->count;
  401. }
  402. static void _XFORMAPI
  403. TAG(transform_points3_identity)( GLvector4f *to_vec,
  404. const GLfloat m[16],
  405. const GLvector4f *from_vec )
  406. {
  407. const GLuint stride = from_vec->stride;
  408. GLfloat *from = from_vec->start;
  409. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  410. GLuint count = from_vec->count;
  411. GLuint i;
  412. (void) m;
  413. if (to_vec == from_vec) return;
  414. STRIDE_LOOP {
  415. to[i][0] = from[0];
  416. to[i][1] = from[1];
  417. to[i][2] = from[2];
  418. }
  419. to_vec->size = 3;
  420. to_vec->flags |= VEC_SIZE_3;
  421. to_vec->count = from_vec->count;
  422. }
  423. static void _XFORMAPI
  424. TAG(transform_points3_2d)( GLvector4f *to_vec,
  425. const GLfloat m[16],
  426. const GLvector4f *from_vec )
  427. {
  428. const GLuint stride = from_vec->stride;
  429. GLfloat *from = from_vec->start;
  430. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  431. GLuint count = from_vec->count;
  432. const GLfloat m0 = m[0], m1 = m[1], m4 = m[4], m5 = m[5];
  433. const GLfloat m12 = m[12], m13 = m[13];
  434. GLuint i;
  435. STRIDE_LOOP {
  436. const GLfloat ox = from[0], oy = from[1], oz = from[2];
  437. to[i][0] = m0 * ox + m4 * oy + m12 ;
  438. to[i][1] = m1 * ox + m5 * oy + m13 ;
  439. to[i][2] = + oz ;
  440. }
  441. to_vec->size = 3;
  442. to_vec->flags |= VEC_SIZE_3;
  443. to_vec->count = from_vec->count;
  444. }
  445. static void _XFORMAPI
  446. TAG(transform_points3_2d_no_rot)( GLvector4f *to_vec,
  447. const GLfloat m[16],
  448. const GLvector4f *from_vec )
  449. {
  450. const GLuint stride = from_vec->stride;
  451. GLfloat *from = from_vec->start;
  452. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  453. GLuint count = from_vec->count;
  454. const GLfloat m0 = m[0], m5 = m[5], m12 = m[12], m13 = m[13];
  455. GLuint i;
  456. STRIDE_LOOP {
  457. const GLfloat ox = from[0], oy = from[1], oz = from[2];
  458. to[i][0] = m0 * ox + m12 ;
  459. to[i][1] = m5 * oy + m13 ;
  460. to[i][2] = + oz ;
  461. }
  462. to_vec->size = 3;
  463. to_vec->flags |= VEC_SIZE_3;
  464. to_vec->count = from_vec->count;
  465. }
  466. static void _XFORMAPI
  467. TAG(transform_points3_3d)( GLvector4f *to_vec,
  468. const GLfloat m[16],
  469. const GLvector4f *from_vec )
  470. {
  471. const GLuint stride = from_vec->stride;
  472. GLfloat *from = from_vec->start;
  473. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  474. GLuint count = from_vec->count;
  475. const GLfloat m0 = m[0], m1 = m[1], m2 = m[2], m4 = m[4], m5 = m[5];
  476. const GLfloat m6 = m[6], m8 = m[8], m9 = m[9], m10 = m[10];
  477. const GLfloat m12 = m[12], m13 = m[13], m14 = m[14];
  478. GLuint i;
  479. STRIDE_LOOP {
  480. const GLfloat ox = from[0], oy = from[1], oz = from[2];
  481. to[i][0] = m0 * ox + m4 * oy + m8 * oz + m12 ;
  482. to[i][1] = m1 * ox + m5 * oy + m9 * oz + m13 ;
  483. to[i][2] = m2 * ox + m6 * oy + m10 * oz + m14 ;
  484. }
  485. to_vec->size = 3;
  486. to_vec->flags |= VEC_SIZE_3;
  487. to_vec->count = from_vec->count;
  488. }
  489. /* previously known as ortho...
  490. */
  491. static void _XFORMAPI
  492. TAG(transform_points3_3d_no_rot)( GLvector4f *to_vec,
  493. const GLfloat m[16],
  494. const GLvector4f *from_vec )
  495. {
  496. const GLuint stride = from_vec->stride;
  497. GLfloat *from = from_vec->start;
  498. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  499. GLuint count = from_vec->count;
  500. const GLfloat m0 = m[0], m5 = m[5];
  501. const GLfloat m10 = m[10], m12 = m[12], m13 = m[13], m14 = m[14];
  502. GLuint i;
  503. STRIDE_LOOP {
  504. const GLfloat ox = from[0], oy = from[1], oz = from[2];
  505. to[i][0] = m0 * ox + m12 ;
  506. to[i][1] = m5 * oy + m13 ;
  507. to[i][2] = m10 * oz + m14 ;
  508. }
  509. to_vec->size = 3;
  510. to_vec->flags |= VEC_SIZE_3;
  511. to_vec->count = from_vec->count;
  512. }
  513. static void _XFORMAPI
  514. TAG(transform_points3_perspective)( GLvector4f *to_vec,
  515. const GLfloat m[16],
  516. const GLvector4f *from_vec )
  517. {
  518. const GLuint stride = from_vec->stride;
  519. GLfloat *from = from_vec->start;
  520. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  521. GLuint count = from_vec->count;
  522. const GLfloat m0 = m[0], m5 = m[5], m8 = m[8], m9 = m[9];
  523. const GLfloat m10 = m[10], m14 = m[14];
  524. GLuint i;
  525. STRIDE_LOOP {
  526. const GLfloat ox = from[0], oy = from[1], oz = from[2];
  527. to[i][0] = m0 * ox + m8 * oz ;
  528. to[i][1] = m5 * oy + m9 * oz ;
  529. to[i][2] = m10 * oz + m14 ;
  530. to[i][3] = -oz ;
  531. }
  532. to_vec->size = 4;
  533. to_vec->flags |= VEC_SIZE_4;
  534. to_vec->count = from_vec->count;
  535. }
  536. static void _XFORMAPI
  537. TAG(transform_points4_general)( GLvector4f *to_vec,
  538. const GLfloat m[16],
  539. const GLvector4f *from_vec )
  540. {
  541. const GLuint stride = from_vec->stride;
  542. GLfloat *from = from_vec->start;
  543. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  544. GLuint count = from_vec->count;
  545. const GLfloat m0 = m[0], m4 = m[4], m8 = m[8], m12 = m[12];
  546. const GLfloat m1 = m[1], m5 = m[5], m9 = m[9], m13 = m[13];
  547. const GLfloat m2 = m[2], m6 = m[6], m10 = m[10], m14 = m[14];
  548. const GLfloat m3 = m[3], m7 = m[7], m11 = m[11], m15 = m[15];
  549. GLuint i;
  550. STRIDE_LOOP {
  551. const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3];
  552. to[i][0] = m0 * ox + m4 * oy + m8 * oz + m12 * ow;
  553. to[i][1] = m1 * ox + m5 * oy + m9 * oz + m13 * ow;
  554. to[i][2] = m2 * ox + m6 * oy + m10 * oz + m14 * ow;
  555. to[i][3] = m3 * ox + m7 * oy + m11 * oz + m15 * ow;
  556. }
  557. to_vec->size = 4;
  558. to_vec->flags |= VEC_SIZE_4;
  559. to_vec->count = from_vec->count;
  560. }
  561. static void _XFORMAPI
  562. TAG(transform_points4_identity)( GLvector4f *to_vec,
  563. const GLfloat m[16],
  564. const GLvector4f *from_vec )
  565. {
  566. const GLuint stride = from_vec->stride;
  567. GLfloat *from = from_vec->start;
  568. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  569. GLuint count = from_vec->count;
  570. GLuint i;
  571. (void) m;
  572. if (to_vec == from_vec) return;
  573. STRIDE_LOOP {
  574. to[i][0] = from[0];
  575. to[i][1] = from[1];
  576. to[i][2] = from[2];
  577. to[i][3] = from[3];
  578. }
  579. to_vec->size = 4;
  580. to_vec->flags |= VEC_SIZE_4;
  581. to_vec->count = from_vec->count;
  582. }
  583. static void _XFORMAPI
  584. TAG(transform_points4_2d)( GLvector4f *to_vec,
  585. const GLfloat m[16],
  586. const GLvector4f *from_vec )
  587. {
  588. const GLuint stride = from_vec->stride;
  589. GLfloat *from = from_vec->start;
  590. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  591. GLuint count = from_vec->count;
  592. const GLfloat m0 = m[0], m1 = m[1], m4 = m[4], m5 = m[5];
  593. const GLfloat m12 = m[12], m13 = m[13];
  594. GLuint i;
  595. STRIDE_LOOP {
  596. const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3];
  597. to[i][0] = m0 * ox + m4 * oy + m12 * ow;
  598. to[i][1] = m1 * ox + m5 * oy + m13 * ow;
  599. to[i][2] = + oz ;
  600. to[i][3] = ow;
  601. }
  602. to_vec->size = 4;
  603. to_vec->flags |= VEC_SIZE_4;
  604. to_vec->count = from_vec->count;
  605. }
  606. static void _XFORMAPI
  607. TAG(transform_points4_2d_no_rot)( GLvector4f *to_vec,
  608. const GLfloat m[16],
  609. const GLvector4f *from_vec )
  610. {
  611. const GLuint stride = from_vec->stride;
  612. GLfloat *from = from_vec->start;
  613. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  614. GLuint count = from_vec->count;
  615. const GLfloat m0 = m[0], m5 = m[5], m12 = m[12], m13 = m[13];
  616. GLuint i;
  617. STRIDE_LOOP {
  618. const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3];
  619. to[i][0] = m0 * ox + m12 * ow;
  620. to[i][1] = m5 * oy + m13 * ow;
  621. to[i][2] = + oz ;
  622. to[i][3] = ow;
  623. }
  624. to_vec->size = 4;
  625. to_vec->flags |= VEC_SIZE_4;
  626. to_vec->count = from_vec->count;
  627. }
  628. static void _XFORMAPI
  629. TAG(transform_points4_3d)( GLvector4f *to_vec,
  630. const GLfloat m[16],
  631. const GLvector4f *from_vec )
  632. {
  633. const GLuint stride = from_vec->stride;
  634. GLfloat *from = from_vec->start;
  635. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  636. GLuint count = from_vec->count;
  637. const GLfloat m0 = m[0], m1 = m[1], m2 = m[2], m4 = m[4], m5 = m[5];
  638. const GLfloat m6 = m[6], m8 = m[8], m9 = m[9], m10 = m[10];
  639. const GLfloat m12 = m[12], m13 = m[13], m14 = m[14];
  640. GLuint i;
  641. STRIDE_LOOP {
  642. const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3];
  643. to[i][0] = m0 * ox + m4 * oy + m8 * oz + m12 * ow;
  644. to[i][1] = m1 * ox + m5 * oy + m9 * oz + m13 * ow;
  645. to[i][2] = m2 * ox + m6 * oy + m10 * oz + m14 * ow;
  646. to[i][3] = ow;
  647. }
  648. to_vec->size = 4;
  649. to_vec->flags |= VEC_SIZE_4;
  650. to_vec->count = from_vec->count;
  651. }
  652. static void _XFORMAPI
  653. TAG(transform_points4_3d_no_rot)( GLvector4f *to_vec,
  654. const GLfloat m[16],
  655. const GLvector4f *from_vec )
  656. {
  657. const GLuint stride = from_vec->stride;
  658. GLfloat *from = from_vec->start;
  659. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  660. GLuint count = from_vec->count;
  661. const GLfloat m0 = m[0], m5 = m[5];
  662. const GLfloat m10 = m[10], m12 = m[12], m13 = m[13], m14 = m[14];
  663. GLuint i;
  664. STRIDE_LOOP {
  665. const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3];
  666. to[i][0] = m0 * ox + m12 * ow;
  667. to[i][1] = m5 * oy + m13 * ow;
  668. to[i][2] = m10 * oz + m14 * ow;
  669. to[i][3] = ow;
  670. }
  671. to_vec->size = 4;
  672. to_vec->flags |= VEC_SIZE_4;
  673. to_vec->count = from_vec->count;
  674. }
  675. static void _XFORMAPI
  676. TAG(transform_points4_perspective)( GLvector4f *to_vec,
  677. const GLfloat m[16],
  678. const GLvector4f *from_vec )
  679. {
  680. const GLuint stride = from_vec->stride;
  681. GLfloat *from = from_vec->start;
  682. GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start;
  683. GLuint count = from_vec->count;
  684. const GLfloat m0 = m[0], m5 = m[5], m8 = m[8], m9 = m[9];
  685. const GLfloat m10 = m[10], m14 = m[14];
  686. GLuint i;
  687. STRIDE_LOOP {
  688. const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3];
  689. to[i][0] = m0 * ox + m8 * oz ;
  690. to[i][1] = m5 * oy + m9 * oz ;
  691. to[i][2] = m10 * oz + m14 * ow ;
  692. to[i][3] = -oz ;
  693. }
  694. to_vec->size = 4;
  695. to_vec->flags |= VEC_SIZE_4;
  696. to_vec->count = from_vec->count;
  697. }
  698. static transform_func TAG(transform_tab_1)[7];
  699. static transform_func TAG(transform_tab_2)[7];
  700. static transform_func TAG(transform_tab_3)[7];
  701. static transform_func TAG(transform_tab_4)[7];
  702. /* Similar functions could be called several times, with more highly
  703. * optimized routines overwriting the arrays. This only occurs during
  704. * startup.
  705. */
  706. static void _XFORMAPI TAG(init_c_transformations)( void )
  707. {
  708. #define TAG_TAB _mesa_transform_tab
  709. #define TAG_TAB_1 TAG(transform_tab_1)
  710. #define TAG_TAB_2 TAG(transform_tab_2)
  711. #define TAG_TAB_3 TAG(transform_tab_3)
  712. #define TAG_TAB_4 TAG(transform_tab_4)
  713. TAG_TAB[1] = TAG_TAB_1;
  714. TAG_TAB[2] = TAG_TAB_2;
  715. TAG_TAB[3] = TAG_TAB_3;
  716. TAG_TAB[4] = TAG_TAB_4;
  717. /* 1-D points (ie texcoords) */
  718. TAG_TAB_1[MATRIX_GENERAL] = TAG(transform_points1_general);
  719. TAG_TAB_1[MATRIX_IDENTITY] = TAG(transform_points1_identity);
  720. TAG_TAB_1[MATRIX_3D_NO_ROT] = TAG(transform_points1_3d_no_rot);
  721. TAG_TAB_1[MATRIX_PERSPECTIVE] = TAG(transform_points1_perspective);
  722. TAG_TAB_1[MATRIX_2D] = TAG(transform_points1_2d);
  723. TAG_TAB_1[MATRIX_2D_NO_ROT] = TAG(transform_points1_2d_no_rot);
  724. TAG_TAB_1[MATRIX_3D] = TAG(transform_points1_3d);
  725. /* 2-D points */
  726. TAG_TAB_2[MATRIX_GENERAL] = TAG(transform_points2_general);
  727. TAG_TAB_2[MATRIX_IDENTITY] = TAG(transform_points2_identity);
  728. TAG_TAB_2[MATRIX_3D_NO_ROT] = TAG(transform_points2_3d_no_rot);
  729. TAG_TAB_2[MATRIX_PERSPECTIVE] = TAG(transform_points2_perspective);
  730. TAG_TAB_2[MATRIX_2D] = TAG(transform_points2_2d);
  731. TAG_TAB_2[MATRIX_2D_NO_ROT] = TAG(transform_points2_2d_no_rot);
  732. TAG_TAB_2[MATRIX_3D] = TAG(transform_points2_3d);
  733. /* 3-D points */
  734. TAG_TAB_3[MATRIX_GENERAL] = TAG(transform_points3_general);
  735. TAG_TAB_3[MATRIX_IDENTITY] = TAG(transform_points3_identity);
  736. TAG_TAB_3[MATRIX_3D_NO_ROT] = TAG(transform_points3_3d_no_rot);
  737. TAG_TAB_3[MATRIX_PERSPECTIVE] = TAG(transform_points3_perspective);
  738. TAG_TAB_3[MATRIX_2D] = TAG(transform_points3_2d);
  739. TAG_TAB_3[MATRIX_2D_NO_ROT] = TAG(transform_points3_2d_no_rot);
  740. TAG_TAB_3[MATRIX_3D] = TAG(transform_points3_3d);
  741. /* 4-D points */
  742. TAG_TAB_4[MATRIX_GENERAL] = TAG(transform_points4_general);
  743. TAG_TAB_4[MATRIX_IDENTITY] = TAG(transform_points4_identity);
  744. TAG_TAB_4[MATRIX_3D_NO_ROT] = TAG(transform_points4_3d_no_rot);
  745. TAG_TAB_4[MATRIX_PERSPECTIVE] = TAG(transform_points4_perspective);
  746. TAG_TAB_4[MATRIX_2D] = TAG(transform_points4_2d);
  747. TAG_TAB_4[MATRIX_2D_NO_ROT] = TAG(transform_points4_2d_no_rot);
  748. TAG_TAB_4[MATRIX_3D] = TAG(transform_points4_3d);
  749. #undef TAG_TAB
  750. #undef TAG_TAB_1
  751. #undef TAG_TAB_2
  752. #undef TAG_TAB_3
  753. #undef TAG_TAB_4
  754. }