home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / math / m_xform_tmp.h < prev    next >
Text File  |  2001-05-18  |  27KB  |  808 lines

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