v3d/tex: handle correctly coordinates for cube/cubearrays images
[mesa.git] / src / mesa / math / m_norm_tmp.h
index bab84d24f572fdcf0440b74886c9b570c1df43a2..6f1db8d0bd0aeebe9852a3058476f5f7a77d9642 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: m_norm_tmp.h,v 1.7 2001/03/30 14:44:43 gareth Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /*
  * New (3.1) transformation code written by Keith Whitwell.
  */
 
-#include <math.h>
-#include "m_vertices.h"
+/* Functions to tranform a vector of normals.  This includes applying
+ * the transformation matrix, rescaling and normalization.
+ */
 
-static void _XFORMAPI
+/*
+ * mat - the 4x4 transformation matrix
+ * scale - uniform scale factor of the transformation matrix (not always used)
+ * in - the source vector of normals
+ * lengths - length of each incoming normal (may be NULL) (a display list
+ *           optimization)
+ * dest - the destination vector of normals
+ */
+static void
 TAG(transform_normalize_normals)( const GLmatrix *mat,
                                   GLfloat scale,
-                                  const GLvector3f *in,
+                                  const GLvector4f *in,
                                   const GLfloat *lengths,
-                                  GLvector3f *dest )
+                                  GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
-   GLfloat *m = mat->inv;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
+   const GLfloat *m = mat->inv;
    GLfloat m0 = m[0],  m4 = m[4],  m8 = m[8];
    GLfloat m1 = m[1],  m5 = m[5],  m9 = m[9];
    GLfloat m2 = m[2],  m6 = m[6],  m10 = m[10];
+   GLuint i;
 
    if (!lengths) {
       STRIDE_LOOP {
@@ -60,20 +68,19 @@ TAG(transform_normalize_normals)( const GLmatrix *mat,
         {
            GLdouble len = tx*tx + ty*ty + tz*tz;
            if (len > 1e-20) {
-              GLdouble scale = 1.0 / GL_SQRT(len);
-              out[i][0] = (GLfloat) (tx * scale);
-              out[i][1] = (GLfloat) (ty * scale);
-              out[i][2] = (GLfloat) (tz * scale);
+              GLfloat scale = 1.0f / sqrtf(len);
+              out[i][0] = tx * scale;
+              out[i][1] = ty * scale;
+              out[i][2] = tz * scale;
            }
-           else
-           {
+           else {
               out[i][0] = out[i][1] = out[i][2] = 0;
            }
         }
       }
    }
    else {
-      if (scale != 1.0) {
+      if (scale != 1.0f) {
         m0 *= scale,  m4 *= scale,  m8 *= scale;
         m1 *= scale,  m5 *= scale,  m9 *= scale;
         m2 *= scale,  m6 *= scale,  m10 *= scale;
@@ -99,22 +106,23 @@ TAG(transform_normalize_normals)( const GLmatrix *mat,
 }
 
 
-static void _XFORMAPI
+static void
 TAG(transform_normalize_normals_no_rot)( const GLmatrix *mat,
                                          GLfloat scale,
-                                         const GLvector3f *in,
+                                         const GLvector4f *in,
                                          const GLfloat *lengths,
-                                         GLvector3f *dest )
+                                         GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
-   GLfloat *m = mat->inv;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
+   const GLfloat *m = mat->inv;
    GLfloat m0 = m[0];
    GLfloat m5 = m[5];
    GLfloat m10 = m[10];
+   GLuint i;
+
    if (!lengths) {
       STRIDE_LOOP {
         GLfloat tx, ty, tz;
@@ -127,26 +135,21 @@ TAG(transform_normalize_normals_no_rot)( const GLmatrix *mat,
         {
            GLdouble len = tx*tx + ty*ty + tz*tz;
            if (len > 1e-20) {
-              GLdouble scale = 1.0 / GL_SQRT(len);
-              out[i][0] = (GLfloat) (tx * scale);
-              out[i][1] = (GLfloat) (ty * scale);
-              out[i][2] = (GLfloat) (tz * scale);
+              GLfloat scale = 1.0f / sqrtf(len);
+              out[i][0] = tx * scale;
+              out[i][1] = ty * scale;
+              out[i][2] = tz * scale;
            }
-           else
-           {
+           else {
               out[i][0] = out[i][1] = out[i][2] = 0;
            }
         }
       }
    }
    else {
-      /* scale has been snapped to 1.0 if it is close.
-       */
-      if (scale != 1.0) {
-        m0 *= scale;
-        m5 *= scale;
-        m10 *= scale;
-      }
+      m0 *= scale;
+      m5 *= scale;
+      m10 *= scale;
 
       STRIDE_LOOP {
         GLfloat tx, ty, tz;
@@ -168,23 +171,25 @@ TAG(transform_normalize_normals_no_rot)( const GLmatrix *mat,
 }
 
 
-static void _XFORMAPI
+static void
 TAG(transform_rescale_normals_no_rot)( const GLmatrix *mat,
                                        GLfloat scale,
-                                       const GLvector3f *in,
+                                       const GLvector4f *in,
                                        const GLfloat *lengths,
-                                       GLvector3f *dest )
+                                       GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
    const GLfloat *m = mat->inv;
-   GLfloat m0 = scale*m[0];
-   GLfloat m5 = scale*m[5];
-   GLfloat m10 = scale*m[10];
+   const GLfloat m0 = scale*m[0];
+   const GLfloat m5 = scale*m[5];
+   const GLfloat m10 = scale*m[10];
+   GLuint i;
+
    (void) lengths;
+
    STRIDE_LOOP {
       GLfloat ux = from[0],  uy = from[1],  uz = from[2];
       out[i][0] = ux * m0;
@@ -194,26 +199,29 @@ TAG(transform_rescale_normals_no_rot)( const GLmatrix *mat,
    dest->count = in->count;
 }
 
-static void _XFORMAPI
+
+static void
 TAG(transform_rescale_normals)( const GLmatrix *mat,
                                 GLfloat scale,
-                                const GLvector3f *in,
+                                const GLvector4f *in,
                                 const GLfloat *lengths,
-                                GLvector3f *dest )
+                                GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
    /* Since we are unlikely to have < 3 vertices in the buffer,
     * it makes sense to pre-multiply by scale.
     */
    const GLfloat *m = mat->inv;
-   GLfloat m0 = scale*m[0],  m4 = scale*m[4],  m8 = scale*m[8];
-   GLfloat m1 = scale*m[1],  m5 = scale*m[5],  m9 = scale*m[9];
-   GLfloat m2 = scale*m[2],  m6 = scale*m[6],  m10 = scale*m[10];
+   const GLfloat m0 = scale*m[0],  m4 = scale*m[4],  m8 = scale*m[8];
+   const GLfloat m1 = scale*m[1],  m5 = scale*m[5],  m9 = scale*m[9];
+   const GLfloat m2 = scale*m[2],  m6 = scale*m[6],  m10 = scale*m[10];
+   GLuint i;
+
    (void) lengths;
+
    STRIDE_LOOP {
       GLfloat ux = from[0],  uy = from[1],  uz = from[2];
       out[i][0] = ux * m0 + uy * m1 + uz * m2;
@@ -224,24 +232,26 @@ TAG(transform_rescale_normals)( const GLmatrix *mat,
 }
 
 
-static void _XFORMAPI
+static void
 TAG(transform_normals_no_rot)( const GLmatrix *mat,
                               GLfloat scale,
-                              const GLvector3f *in,
+                              const GLvector4f *in,
                               const GLfloat *lengths,
-                              GLvector3f *dest )
+                              GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
    const GLfloat *m = mat->inv;
-   GLfloat m0 = m[0];
-   GLfloat m5 = m[5];
-   GLfloat m10 = m[10];
+   const GLfloat m0 = m[0];
+   const GLfloat m5 = m[5];
+   const GLfloat m10 = m[10];
+   GLuint i;
+
    (void) scale;
    (void) lengths;
+
    STRIDE_LOOP {
       GLfloat ux = from[0],  uy = from[1],  uz = from[2];
       out[i][0] = ux * m0;
@@ -252,24 +262,26 @@ TAG(transform_normals_no_rot)( const GLmatrix *mat,
 }
 
 
-static void _XFORMAPI
+static void
 TAG(transform_normals)( const GLmatrix *mat,
                         GLfloat scale,
-                        const GLvector3f *in,
+                        const GLvector4f *in,
                         const GLfloat *lengths,
-                        GLvector3f *dest )
+                        GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
    const GLfloat *m = mat->inv;
-   GLfloat m0 = m[0],  m4 = m[4],  m8 = m[8];
-   GLfloat m1 = m[1],  m5 = m[5],  m9 = m[9];
-   GLfloat m2 = m[2],  m6 = m[6],  m10 = m[10];
+   const GLfloat m0 = m[0],  m4 = m[4],  m8 = m[8];
+   const GLfloat m1 = m[1],  m5 = m[5],  m9 = m[9];
+   const GLfloat m2 = m[2],  m6 = m[6],  m10 = m[10];
+   GLuint i;
+
    (void) scale;
    (void) lengths;
+
    STRIDE_LOOP {
       GLfloat ux = from[0],  uy = from[1],  uz = from[2];
       out[i][0] = ux * m0 + uy * m1 + uz * m2;
@@ -280,20 +292,22 @@ TAG(transform_normals)( const GLmatrix *mat,
 }
 
 
-static void _XFORMAPI
+static void
 TAG(normalize_normals)( const GLmatrix *mat,
                         GLfloat scale,
-                        const GLvector3f *in,
+                        const GLvector4f *in,
                         const GLfloat *lengths,
-                        GLvector3f *dest )
+                        GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
+   GLuint i;
+
    (void) mat;
    (void) scale;
+
    if (lengths) {
       STRIDE_LOOP {
         const GLfloat x = from[0], y = from[1], z = from[2];
@@ -308,10 +322,10 @@ TAG(normalize_normals)( const GLmatrix *mat,
         const GLfloat x = from[0], y = from[1], z = from[2];
         GLdouble len = x * x + y * y + z * z;
         if (len > 1e-50) {
-           len = 1.0 / GL_SQRT(len);
-           out[i][0] = (GLfloat) (x * len);
-           out[i][1] = (GLfloat) (y * len);
-           out[i][2] = (GLfloat) (z * len);
+           len = 1.0f / sqrtf(len);
+           out[i][0] = (GLfloat)(x * len);
+           out[i][1] = (GLfloat)(y * len);
+           out[i][2] = (GLfloat)(z * len);
         }
         else {
            out[i][0] = x;
@@ -324,20 +338,22 @@ TAG(normalize_normals)( const GLmatrix *mat,
 }
 
 
-static void _XFORMAPI
+static void
 TAG(rescale_normals)( const GLmatrix *mat,
                       GLfloat scale,
-                      const GLvector3f *in,
+                      const GLvector4f *in,
                       const GLfloat *lengths,
-                      GLvector3f *dest )
+                      GLvector4f *dest )
 {
-   GLuint i;
+   GLfloat (*out)[4] = (GLfloat (*)[4])dest->start;
    const GLfloat *from = in->start;
-   GLuint stride = in->stride;
-   GLuint count = in->count;
-   GLfloat (*out)[3] = (GLfloat (*)[3])dest->start;
+   const GLuint stride = in->stride;
+   const GLuint count = in->count;
+   GLuint i;
+
    (void) mat;
    (void) lengths;
+
    STRIDE_LOOP {
       SCALE_SCALAR_3V( out[i], scale, from );
    }
@@ -345,7 +361,7 @@ TAG(rescale_normals)( const GLmatrix *mat,
 }
 
 
-static void _XFORMAPI
+static void
 TAG(init_c_norm_transform)( void )
 {
    _mesa_normal_tab[NORM_TRANSFORM_NO_ROT] =