1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Mesa 3-D graphics library 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included 14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef _M_XFORM_H 27bf215546Sopenharmony_ci#define _M_XFORM_H 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "util/compiler.h" 31bf215546Sopenharmony_ci#include "main/glheader.h" 32bf215546Sopenharmony_ci#include "math/m_matrix.h" 33bf215546Sopenharmony_ci#include "math/m_vector.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ciextern void 37bf215546Sopenharmony_ci_math_init_transformation(void); 38bf215546Sopenharmony_ciextern void 39bf215546Sopenharmony_ciinit_c_cliptest(void); 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci/* KW: Clip functions now do projective divide as well. The projected 42bf215546Sopenharmony_ci * coordinates are very useful to us because they let us cull 43bf215546Sopenharmony_ci * backfaces and eliminate vertices from lighting, fogging, etc 44bf215546Sopenharmony_ci * calculations. Despite the fact that this divide could be done one 45bf215546Sopenharmony_ci * day in hardware, we would still have a reason to want to do it here 46bf215546Sopenharmony_ci * as long as those other calculations remain in software. 47bf215546Sopenharmony_ci * 48bf215546Sopenharmony_ci * Clipping is a convenient place to do the divide on x86 as it should be 49bf215546Sopenharmony_ci * possible to overlap with integer outcode calculations. 50bf215546Sopenharmony_ci * 51bf215546Sopenharmony_ci * There are two cases where we wouldn't want to do the divide in cliptest: 52bf215546Sopenharmony_ci * - When we aren't clipping. We still might want to cull backfaces 53bf215546Sopenharmony_ci * so the divide should be done elsewhere. This currently never 54bf215546Sopenharmony_ci * happens. 55bf215546Sopenharmony_ci * 56bf215546Sopenharmony_ci * - When culling isn't likely to help us, such as when the GL culling 57bf215546Sopenharmony_ci * is disabled and we not lighting or are only lighting 58bf215546Sopenharmony_ci * one-sided. In this situation, backface determination provides 59bf215546Sopenharmony_ci * us with no useful information. A tricky case to detect is when 60bf215546Sopenharmony_ci * all input data is already culled, although hopefully the 61bf215546Sopenharmony_ci * application wouldn't turn on culling in such cases. 62bf215546Sopenharmony_ci * 63bf215546Sopenharmony_ci * We supply a buffer to hold the [x/w,y/w,z/w,1/w] values which 64bf215546Sopenharmony_ci * are the result of the projection. This is only used in the 65bf215546Sopenharmony_ci * 4-vector case - in other cases, we just use the clip coordinates 66bf215546Sopenharmony_ci * as the projected coordinates - they are identical. 67bf215546Sopenharmony_ci * 68bf215546Sopenharmony_ci * This is doubly convenient because it means the Win[] array is now 69bf215546Sopenharmony_ci * of the same stride as all the others, so I can now turn map_vertices 70bf215546Sopenharmony_ci * into a straight-forward matrix transformation, with asm acceleration 71bf215546Sopenharmony_ci * automatically available. 72bf215546Sopenharmony_ci */ 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci/* Vertex buffer clipping flags 75bf215546Sopenharmony_ci */ 76bf215546Sopenharmony_ci#define CLIP_RIGHT_SHIFT 0 77bf215546Sopenharmony_ci#define CLIP_LEFT_SHIFT 1 78bf215546Sopenharmony_ci#define CLIP_TOP_SHIFT 2 79bf215546Sopenharmony_ci#define CLIP_BOTTOM_SHIFT 3 80bf215546Sopenharmony_ci#define CLIP_NEAR_SHIFT 4 81bf215546Sopenharmony_ci#define CLIP_FAR_SHIFT 5 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci#define CLIP_RIGHT_BIT 0x01 84bf215546Sopenharmony_ci#define CLIP_LEFT_BIT 0x02 85bf215546Sopenharmony_ci#define CLIP_TOP_BIT 0x04 86bf215546Sopenharmony_ci#define CLIP_BOTTOM_BIT 0x08 87bf215546Sopenharmony_ci#define CLIP_NEAR_BIT 0x10 88bf215546Sopenharmony_ci#define CLIP_FAR_BIT 0x20 89bf215546Sopenharmony_ci#define CLIP_USER_BIT 0x40 90bf215546Sopenharmony_ci#define CLIP_CULL_BIT 0x80 91bf215546Sopenharmony_ci#define CLIP_FRUSTUM_BITS 0x3f 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_citypedef GLvector4f * (*clip_func)(GLvector4f *vClip, 95bf215546Sopenharmony_ci GLvector4f *vProj, 96bf215546Sopenharmony_ci GLubyte clipMask[], 97bf215546Sopenharmony_ci GLubyte *orMask, 98bf215546Sopenharmony_ci GLubyte *andMask, 99bf215546Sopenharmony_ci GLboolean viewport_z_clip); 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_citypedef void (*dotprod_func)( GLfloat *out, 102bf215546Sopenharmony_ci GLuint out_stride, 103bf215546Sopenharmony_ci const GLvector4f *coord_vec, 104bf215546Sopenharmony_ci const GLfloat plane[4] ); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_citypedef void (*vec_copy_func)( GLvector4f *to, 107bf215546Sopenharmony_ci const GLvector4f *from ); 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci/* 112bf215546Sopenharmony_ci * Functions for transformation of normals in the VB. 113bf215546Sopenharmony_ci */ 114bf215546Sopenharmony_citypedef void (*normal_func)(const GLmatrix *mat, 115bf215546Sopenharmony_ci GLfloat scale, 116bf215546Sopenharmony_ci const GLvector4f *in, 117bf215546Sopenharmony_ci const GLfloat lengths[], 118bf215546Sopenharmony_ci GLvector4f *dest); 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci/* Flags for selecting a normal transformation function. 122bf215546Sopenharmony_ci */ 123bf215546Sopenharmony_ci#define NORM_RESCALE 0x1 /* apply the scale factor */ 124bf215546Sopenharmony_ci#define NORM_NORMALIZE 0x2 /* normalize */ 125bf215546Sopenharmony_ci#define NORM_TRANSFORM 0x4 /* apply the transformation matrix */ 126bf215546Sopenharmony_ci#define NORM_TRANSFORM_NO_ROT 0x8 /* apply the transformation matrix */ 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci/* KW: New versions of the transform function allow a mask array 132bf215546Sopenharmony_ci * specifying that individual vector transform should be skipped 133bf215546Sopenharmony_ci * when the mask byte is zero. This is always present as a 134bf215546Sopenharmony_ci * parameter, to allow a unified interface. 135bf215546Sopenharmony_ci */ 136bf215546Sopenharmony_citypedef void (*transform_func)(GLvector4f *to_vec, 137bf215546Sopenharmony_ci const GLfloat m[16], 138bf215546Sopenharmony_ci const GLvector4f *from_vec); 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ciextern dotprod_func _mesa_dotprod_tab[5]; 142bf215546Sopenharmony_ciextern vec_copy_func _mesa_copy_tab[0x10]; 143bf215546Sopenharmony_ciextern vec_copy_func _mesa_copy_clean_tab[5]; 144bf215546Sopenharmony_ciextern clip_func _mesa_clip_tab[5]; 145bf215546Sopenharmony_ciextern clip_func _mesa_clip_np_tab[5]; 146bf215546Sopenharmony_ciextern normal_func _mesa_normal_tab[0xf]; 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci/* Use of 2 layers of linked 1-dimensional arrays to reduce 149bf215546Sopenharmony_ci * cost of lookup. 150bf215546Sopenharmony_ci */ 151bf215546Sopenharmony_ciextern transform_func *_mesa_transform_tab[5]; 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci#define TransformRaw( to, mat, from ) \ 156bf215546Sopenharmony_ci ( _mesa_transform_tab[(from)->size][(mat)->type]( to, (mat)->m, from ), \ 157bf215546Sopenharmony_ci (to) ) 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci#endif 161