123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Mesa 3-D graphics library
3bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul * Version:  7.3
422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
5bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * copy of this software and associated documentation files (the "Software"),
923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to deal in the Software without restriction, including without limitation
1023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
1223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Software is furnished to do so, subject to the following conditions:
1322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
1423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * The above copyright notice and this permission notice shall be included
1523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * in all copies or substantial portions of the Software.
1622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
1723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
2423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
2523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
2623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifndef _M_XFORM_H
2723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define _M_XFORM_H
2823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
2923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
30816ad9bc23e22950a1740de1d70c2c9ebbdda724Vinson Lee#include "main/compiler.h"
31bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/glheader.h"
3223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "math/m_matrix.h"
33816ad9bc23e22950a1740de1d70c2c9ebbdda724Vinson Lee#include "math/m_vector.h"
3423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
3523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifdef USE_X86_ASM
3623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define _XFORMAPI _ASMAPI
3723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define _XFORMAPIP _ASMAPIP
3823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#else
3923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define _XFORMAPI
4023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define _XFORMAPIP *
4123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
4223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
4323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
44f76314a69ad6ece95cc319b18be90e0a045a3cceBrian Paulextern void
45f76314a69ad6ece95cc319b18be90e0a045a3cceBrian Paul_math_init_transformation(void);
46b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholtextern void
47b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholtinit_c_cliptest(void);
4823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
4923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* KW: Clip functions now do projective divide as well.  The projected
5023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * coordinates are very useful to us because they let us cull
5123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * backfaces and eliminate vertices from lighting, fogging, etc
5223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * calculations.  Despite the fact that this divide could be done one
5323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * day in hardware, we would still have a reason to want to do it here
5423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * as long as those other calculations remain in software.
5523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
5623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Clipping is a convenient place to do the divide on x86 as it should be
5723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * possible to overlap with integer outcode calculations.
5823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
5923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * There are two cases where we wouldn't want to do the divide in cliptest:
6023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - When we aren't clipping.  We still might want to cull backfaces
6122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *      so the divide should be done elsewhere.  This currently never
6223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      happens.
6323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
6423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - When culling isn't likely to help us, such as when the GL culling
6523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      is disabled and we not lighting or are only lighting
6623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      one-sided.  In this situation, backface determination provides
6723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      us with no useful information.  A tricky case to detect is when
6823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      all input data is already culled, although hopefully the
6923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      application wouldn't turn on culling in such cases.
7023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
7123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * We supply a buffer to hold the [x/w,y/w,z/w,1/w] values which
7222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * are the result of the projection.  This is only used in the
7323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 4-vector case - in other cases, we just use the clip coordinates
7423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * as the projected coordinates - they are identical.
7522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
7623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * This is doubly convenient because it means the Win[] array is now
7723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * of the same stride as all the others, so I can now turn map_vertices
7823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * into a straight-forward matrix transformation, with asm acceleration
7922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * automatically available.
8023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
8123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
8222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes/* Vertex buffer clipping flags
8323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
8423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_RIGHT_SHIFT 	0
8523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_LEFT_SHIFT 	1
8623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_TOP_SHIFT  	2
8723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_BOTTOM_SHIFT       3
8823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_NEAR_SHIFT  	4
8923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_FAR_SHIFT  	5
9023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
9123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_RIGHT_BIT   0x01
9223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_LEFT_BIT    0x02
9323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_TOP_BIT     0x04
9423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_BOTTOM_BIT  0x08
9523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_NEAR_BIT    0x10
9623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_FAR_BIT     0x20
9723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define CLIP_USER_BIT    0x40
98352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell#define CLIP_CULL_BIT    0x80
9951faca127005c41277df76bc8eafc8fd64ca0673Brian Paul#define CLIP_FRUSTUM_BITS    0x3f
10023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
10123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
10223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwelltypedef GLvector4f * (_XFORMAPIP clip_func)( GLvector4f *vClip,
10322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes					     GLvector4f *vProj,
104cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell					     GLubyte clipMask[],
10522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes					     GLubyte *orMask,
106b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt					     GLubyte *andMask,
107b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt					     GLboolean viewport_z_clip );
10823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
10922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughestypedef void (*dotprod_func)( GLfloat *out,
110cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell			      GLuint out_stride,
11122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes			      CONST GLvector4f *coord_vec,
1125e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes			      CONST GLfloat plane[4] );
11323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
11422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughestypedef void (*vec_copy_func)( GLvector4f *to,
1155e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes			       CONST GLvector4f *from );
11623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
11723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
11823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
11923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
12023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Functions for transformation of normals in the VB.
12123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
122cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwelltypedef void (_NORMAPIP normal_func)( CONST GLmatrix *mat,
123cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell				      GLfloat scale,
124bd1a9dacf6a45e6aa6954eeb490d55ebcc80ace8Brian Paul				      CONST GLvector4f *in,
125cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell				      CONST GLfloat lengths[],
126bd1a9dacf6a45e6aa6954eeb490d55ebcc80ace8Brian Paul				      GLvector4f *dest );
12723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
12922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes/* Flags for selecting a normal transformation function.
13023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
1315e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes#define NORM_RESCALE   0x1		/* apply the scale factor */
1325e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes#define NORM_NORMALIZE 0x2		/* normalize */
1335e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes#define NORM_TRANSFORM 0x4		/* apply the transformation matrix */
13423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define NORM_TRANSFORM_NO_ROT 0x8	/* apply the transformation matrix */
13523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
13623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
13723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
13823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
13923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* KW: New versions of the transform function allow a mask array
14023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *     specifying that individual vector transform should be skipped
14123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *     when the mask byte is zero.  This is always present as a
14222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *     parameter, to allow a unified interface.
14323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
14423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwelltypedef void (_XFORMAPIP transform_func)( GLvector4f *to_vec,
145cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell					  CONST GLfloat m[16],
1465e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes					  CONST GLvector4f *from_vec );
14723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
14823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
1495e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesextern dotprod_func  _mesa_dotprod_tab[5];
1505e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesextern vec_copy_func _mesa_copy_tab[0x10];
1515e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesextern vec_copy_func _mesa_copy_clean_tab[5];
152188f2949eaf181f4aab041a6dad26fa76e746eeeBrian Paulextern clip_func     _mesa_clip_tab[5];
153188f2949eaf181f4aab041a6dad26fa76e746eeeBrian Paulextern clip_func     _mesa_clip_np_tab[5];
1545e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesextern normal_func   _mesa_normal_tab[0xf];
15523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
1565e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes/* Use of 2 layers of linked 1-dimensional arrays to reduce
15723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * cost of lookup.
15823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
1595e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesextern transform_func *_mesa_transform_tab[5];
16023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
16123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
16223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
16323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define TransformRaw( to, mat, from ) \
1645e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes   ( _mesa_transform_tab[(from)->size][(mat)->type]( to, (mat)->m, from ), \
1655e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes     (to) )
16623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
16723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
16823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
169