home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / vertices.c < prev    next >
C/C++ Source or Header  |  2000-01-07  |  5KB  |  203 lines

  1. /* $Id: vertices.c,v 1.7 1999/11/08 07:36:45 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  * 
  7.  * Copyright (C) 1999  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. #ifndef XFree86Server
  28. #include <stdio.h>
  29. #else
  30. #include "GL/xf86glx.h"
  31. #endif
  32. #include "types.h"
  33. #include "vertices.h"
  34.  
  35. #if defined(USE_X86_ASM)
  36. #include "X86/common_x86asm.h"
  37. #endif
  38.  
  39. /* The start of a bunch of vertex oriented geometry routines.  These
  40.  * are expected to support the production of driver-specific fast paths
  41.  * for CVA and eventually normal processing.
  42.  *
  43.  * These have been taken from fxfastpath.c, and are now also used in
  44.  * the mga driver.
  45.  *
  46.  * These should grow to include:
  47.  *     - choice of 8/16 dword vertices
  48.  *     - ??
  49.  *     - use of portable assembly layouts.
  50.  *
  51.  * More tentatively:
  52.  *     - more (all?) matrix types
  53.  *     - more (?) vertex sizes
  54.  *
  55.  * -- Keith Whitwell.
  56.  */
  57.  
  58. /* The inline 3dnow code seems to give problems with some peoples
  59.  * compiler/binutils. 
  60.  */
  61. /*  #undef USE_3DNOW_ASM */
  62.  
  63.  
  64. #if defined(USE_X86_ASM) && defined(__GNUC__)
  65.  
  66.  
  67. #endif
  68.  
  69.  
  70. static void transform_v16(GLfloat *f,
  71.               const GLfloat *m,
  72.               const GLfloat *obj,
  73.               GLuint obj_stride,
  74.               GLuint count )
  75. {
  76.    GLuint i;
  77.  
  78.    for (i = 0 ; i < count ; i++, STRIDE_F(obj, obj_stride), f+=16) 
  79.    {
  80.       const GLfloat ox = obj[0], oy = obj[1], oz = obj[2];
  81.       f[0] = m[0] * ox + m[4] * oy + m[8]  * oz + m[12];
  82.       f[1] = m[1] * ox + m[5] * oy + m[9]  * oz + m[13];
  83.       f[2] = m[2] * ox + m[6] * oy + m[10] * oz + m[14];
  84.       f[3] = m[3] * ox + m[7] * oy + m[11] * oz + m[15];
  85.    }
  86. }
  87.  
  88. /* Project all vertices upto but not including last.  Guarenteed to be 
  89.  * at least one such vertex.
  90.  */
  91. static void project_verts(GLfloat *first,
  92.               GLfloat *last,
  93.               const GLfloat *m,
  94.               GLuint stride )
  95. {
  96.    const GLfloat sx = m[0], sy = m[5], sz = m[10];
  97.    const GLfloat tx = m[12], ty = m[13], tz = m[14];
  98.    GLfloat *f;
  99.    
  100.    for ( f = first ; f != last ; STRIDE_F(f,stride))
  101.    {
  102.       const GLfloat oow = 1.0F / f[3];
  103.       f[0] = sx * f[0] * oow + tx;
  104.       f[1] = sy * f[1] * oow + ty;
  105.       f[2] = sz * f[2] * oow + tz;
  106.       f[3] = oow;
  107.    }
  108. }
  109.  
  110. static void project_clipped_verts(GLfloat *first,
  111.                   GLfloat *last,
  112.                   const GLfloat *m,
  113.                   GLuint stride,
  114.                   const GLubyte *clipmask )
  115. {
  116.    const GLfloat sx = m[0], sy = m[5], sz = m[10];
  117.    const GLfloat tx = m[12], ty = m[13], tz = m[14];
  118.    GLfloat *f;
  119.    
  120.    for ( f = first ; f != last ; STRIDE_F(f,stride), clipmask++)
  121.    {
  122.       if (!*clipmask) {
  123.      const GLfloat oow = 1.0F / f[3];
  124.      f[0] = sx * f[0] * oow + tx;
  125.      f[1] = sy * f[1] * oow + ty;
  126.      f[2] = sz * f[2] * oow + tz;
  127.      f[3] = oow;
  128.       }
  129.    }
  130. }
  131.  
  132.  
  133.  
  134.  
  135. static void cliptest_v16( GLfloat *first,
  136.               GLfloat *last,
  137.               GLubyte *p_clipOr,
  138.               GLubyte *p_clipAnd,
  139.               GLubyte *clipmask )
  140. {    
  141.    GLubyte clipAnd = (GLubyte) ~0;
  142.    GLubyte clipOr = 0;
  143.    GLfloat *f = first;
  144.    static int i;
  145.    i = 0;
  146.  
  147.    for ( ; f != last ; f+=16, clipmask++, i++) 
  148.    {
  149.       const GLfloat cx = f[0];
  150.       const GLfloat cy = f[1];
  151.       const GLfloat cz = f[2];
  152.       const GLfloat cw = f[3];      
  153.       GLubyte mask = 0;
  154.  
  155.       if (cx >  cw) mask |= CLIP_RIGHT_BIT;
  156.       if (cx < -cw) mask |= CLIP_LEFT_BIT;
  157.       if (cy >  cw) mask |= CLIP_TOP_BIT;
  158.       if (cy < -cw) mask |= CLIP_BOTTOM_BIT;
  159.       if (cz >  cw) mask |= CLIP_FAR_BIT;
  160.       if (cz < -cw) mask |= CLIP_NEAR_BIT;
  161.  
  162.       *clipmask = mask;
  163.       clipAnd &= mask;
  164.       clipOr |= mask;
  165.    }
  166.  
  167.    (*p_clipOr) |= clipOr;
  168.    (*p_clipAnd) &= clipAnd;
  169. }
  170.  
  171.  
  172.  
  173. GLenum gl_reduce_prim[GL_POLYGON+1] = {
  174.    GL_POINTS,
  175.    GL_LINES,
  176.    GL_LINES,
  177.    GL_LINES,
  178.    GL_TRIANGLES,
  179.    GL_TRIANGLES,
  180.    GL_TRIANGLES,
  181.    GL_TRIANGLES,
  182.    GL_TRIANGLES,
  183.    GL_TRIANGLES,
  184. };  
  185.  
  186. gl_transform_func gl_xform_points3_v16_general = transform_v16;
  187. gl_cliptest_func gl_cliptest_points4_v16 = cliptest_v16;
  188. gl_project_clipped_func gl_project_clipped_v16 = project_clipped_verts;
  189. gl_project_func gl_project_v16 = project_verts;
  190.  
  191. void gl_init_vertices()
  192. {
  193. }
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.