| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.1 |
| 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 |
|
| 26 |
#ifndef _M_XFORM_H |
| 27 |
#define _M_XFORM_H |
| 28 |
|
| 29 |
|
| 30 |
#include "glheader.h" |
| 31 |
#include "config.h" |
| 32 |
#include "math/m_vector.h" |
| 33 |
#include "math/m_matrix.h" |
| 34 |
|
| 35 |
#ifdef USE_X86_ASM |
| 36 |
#define _XFORMAPI _ASMAPI |
| 37 |
#define _XFORMAPIP _ASMAPIP |
| 38 |
#else |
| 39 |
#define _XFORMAPI |
| 40 |
#define _XFORMAPIP * |
| 41 |
#endif |
| 42 |
|
| 43 |
|
| 44 |
extern void |
| 45 |
_mesa_transform_vector(GLfloat u[4], CONST GLfloat v[4], CONST GLfloat m[16]); |
| 46 |
|
| 47 |
|
| 48 |
extern void |
| 49 |
_math_init_transformation(void); |
| 50 |
|
| 51 |
|
| 52 |
/* KW: Clip functions now do projective divide as well. The projected |
| 53 |
* coordinates are very useful to us because they let us cull |
| 54 |
* backfaces and eliminate vertices from lighting, fogging, etc |
| 55 |
* calculations. Despite the fact that this divide could be done one |
| 56 |
* day in hardware, we would still have a reason to want to do it here |
| 57 |
* as long as those other calculations remain in software. |
| 58 |
* |
| 59 |
* Clipping is a convenient place to do the divide on x86 as it should be |
| 60 |
* possible to overlap with integer outcode calculations. |
| 61 |
* |
| 62 |
* There are two cases where we wouldn't want to do the divide in cliptest: |
| 63 |
* - When we aren't clipping. We still might want to cull backfaces |
| 64 |
* so the divide should be done elsewhere. This currently never |
| 65 |
* happens. |
| 66 |
* |
| 67 |
* - When culling isn't likely to help us, such as when the GL culling |
| 68 |
* is disabled and we not lighting or are only lighting |
| 69 |
* one-sided. In this situation, backface determination provides |
| 70 |
* us with no useful information. A tricky case to detect is when |
| 71 |
* all input data is already culled, although hopefully the |
| 72 |
* application wouldn't turn on culling in such cases. |
| 73 |
* |
| 74 |
* We supply a buffer to hold the [x/w,y/w,z/w,1/w] values which |
| 75 |
* are the result of the projection. This is only used in the |
| 76 |
* 4-vector case - in other cases, we just use the clip coordinates |
| 77 |
* as the projected coordinates - they are identical. |
| 78 |
* |
| 79 |
* This is doubly convenient because it means the Win[] array is now |
| 80 |
* of the same stride as all the others, so I can now turn map_vertices |
| 81 |
* into a straight-forward matrix transformation, with asm acceleration |
| 82 |
* automatically available. |
| 83 |
*/ |
| 84 |
|
| 85 |
/* Vertex buffer clipping flags |
| 86 |
*/ |
| 87 |
#define CLIP_RIGHT_SHIFT 0 |
| 88 |
#define CLIP_LEFT_SHIFT 1 |
| 89 |
#define CLIP_TOP_SHIFT 2 |
| 90 |
#define CLIP_BOTTOM_SHIFT 3 |
| 91 |
#define CLIP_NEAR_SHIFT 4 |
| 92 |
#define CLIP_FAR_SHIFT 5 |
| 93 |
|
| 94 |
#define CLIP_RIGHT_BIT 0x01 |
| 95 |
#define CLIP_LEFT_BIT 0x02 |
| 96 |
#define CLIP_TOP_BIT 0x04 |
| 97 |
#define CLIP_BOTTOM_BIT 0x08 |
| 98 |
#define CLIP_NEAR_BIT 0x10 |
| 99 |
#define CLIP_FAR_BIT 0x20 |
| 100 |
#define CLIP_USER_BIT 0x40 |
| 101 |
#define CLIP_CULL_BIT 0x80 |
| 102 |
#define CLIP_ALL_BITS 0x3f |
| 103 |
|
| 104 |
|
| 105 |
typedef GLvector4f * (_XFORMAPIP clip_func)( GLvector4f *vClip, |
| 106 |
GLvector4f *vProj, |
| 107 |
GLubyte clipMask[], |
| 108 |
GLubyte *orMask, |
| 109 |
GLubyte *andMask ); |
| 110 |
|
| 111 |
typedef void (*dotprod_func)( GLfloat *out, |
| 112 |
GLuint out_stride, |
| 113 |
CONST GLvector4f *coord_vec, |
| 114 |
CONST GLfloat plane[4] ); |
| 115 |
|
| 116 |
typedef void (*vec_copy_func)( GLvector4f *to, |
| 117 |
CONST GLvector4f *from ); |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
/* |
| 122 |
* Functions for transformation of normals in the VB. |
| 123 |
*/ |
| 124 |
typedef void (_NORMAPIP normal_func)( CONST GLmatrix *mat, |
| 125 |
GLfloat scale, |
| 126 |
CONST GLvector4f *in, |
| 127 |
CONST GLfloat lengths[], |
| 128 |
GLvector4f *dest ); |
| 129 |
|
| 130 |
|
| 131 |
/* Flags for selecting a normal transformation function. |
| 132 |
*/ |
| 133 |
#define NORM_RESCALE 0x1 /* apply the scale factor */ |
| 134 |
#define NORM_NORMALIZE 0x2 /* normalize */ |
| 135 |
#define NORM_TRANSFORM 0x4 /* apply the transformation matrix */ |
| 136 |
#define NORM_TRANSFORM_NO_ROT 0x8 /* apply the transformation matrix */ |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
/* KW: New versions of the transform function allow a mask array |
| 142 |
* specifying that individual vector transform should be skipped |
| 143 |
* when the mask byte is zero. This is always present as a |
| 144 |
* parameter, to allow a unified interface. |
| 145 |
*/ |
| 146 |
typedef void (_XFORMAPIP transform_func)( GLvector4f *to_vec, |
| 147 |
CONST GLfloat m[16], |
| 148 |
CONST GLvector4f *from_vec ); |
| 149 |
|
| 150 |
|
| 151 |
extern GLvector4f *_mesa_project_points( GLvector4f *to, |
| 152 |
CONST GLvector4f *from ); |
| 153 |
|
| 154 |
extern void _mesa_transform_bounds3( GLubyte *orMask, GLubyte *andMask, |
| 155 |
CONST GLfloat m[16], |
| 156 |
CONST GLfloat src[][3] ); |
| 157 |
|
| 158 |
extern void _mesa_transform_bounds2( GLubyte *orMask, GLubyte *andMask, |
| 159 |
CONST GLfloat m[16], |
| 160 |
CONST GLfloat src[][3] ); |
| 161 |
|
| 162 |
|
| 163 |
extern dotprod_func _mesa_dotprod_tab[5]; |
| 164 |
extern vec_copy_func _mesa_copy_tab[0x10]; |
| 165 |
extern vec_copy_func _mesa_copy_clean_tab[5]; |
| 166 |
extern clip_func _mesa_clip_tab[5]; |
| 167 |
extern clip_func _mesa_clip_np_tab[5]; |
| 168 |
extern normal_func _mesa_normal_tab[0xf]; |
| 169 |
|
| 170 |
/* Use of 2 layers of linked 1-dimensional arrays to reduce |
| 171 |
* cost of lookup. |
| 172 |
*/ |
| 173 |
extern transform_func *_mesa_transform_tab[5]; |
| 174 |
|
| 175 |
|
| 176 |
extern void _mesa_transform_point_sz( GLfloat Q[4], CONST GLfloat M[16], |
| 177 |
CONST GLfloat P[4], GLuint sz ); |
| 178 |
|
| 179 |
|
| 180 |
#define TransformRaw( to, mat, from ) \ |
| 181 |
( _mesa_transform_tab[(from)->size][(mat)->type]( to, (mat)->m, from ), \ |
| 182 |
(to) ) |
| 183 |
|
| 184 |
|
| 185 |
#endif |