Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygent_vb_vertex.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 6.5 00004 * 00005 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 * 00024 * Authors: 00025 * Keith Whitwell <keith@tungstengraphics.com> 00026 */ 00027 00028 00029 #include "main/glheader.h" 00030 #include "main/colormac.h" 00031 #include "main/context.h" 00032 #include "main/macros.h" 00033 #include "main/imports.h" 00034 #include "main/mtypes.h" 00035 00036 #include "math/m_xform.h" 00037 00038 #include "t_context.h" 00039 #include "t_pipeline.h" 00040 00041 00042 00043 struct vertex_stage_data { 00044 GLvector4f eye; 00045 GLvector4f clip; 00046 GLvector4f proj; 00047 GLubyte *clipmask; 00048 GLubyte ormask; 00049 GLubyte andmask; 00050 }; 00051 00052 #define VERTEX_STAGE_DATA(stage) ((struct vertex_stage_data *)stage->privatePtr) 00053 00054 00055 00056 00057 /* This function implements cliptesting for user-defined clip planes. 00058 * The clipping of primitives to these planes is implemented in 00059 * t_render_clip.h. 00060 */ 00061 #define USER_CLIPTEST(NAME, SZ) \ 00062 static void NAME( GLcontext *ctx, \ 00063 GLvector4f *clip, \ 00064 GLubyte *clipmask, \ 00065 GLubyte *clipormask, \ 00066 GLubyte *clipandmask ) \ 00067 { \ 00068 GLuint p; \ 00069 \ 00070 for (p = 0; p < ctx->Const.MaxClipPlanes; p++) \ 00071 if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { \ 00072 GLuint nr, i; \ 00073 const GLfloat a = ctx->Transform._ClipUserPlane[p][0]; \ 00074 const GLfloat b = ctx->Transform._ClipUserPlane[p][1]; \ 00075 const GLfloat c = ctx->Transform._ClipUserPlane[p][2]; \ 00076 const GLfloat d = ctx->Transform._ClipUserPlane[p][3]; \ 00077 GLfloat *coord = (GLfloat *)clip->data; \ 00078 GLuint stride = clip->stride; \ 00079 GLuint count = clip->count; \ 00080 \ 00081 for (nr = 0, i = 0 ; i < count ; i++) { \ 00082 GLfloat dp = coord[0] * a + coord[1] * b; \ 00083 if (SZ > 2) dp += coord[2] * c; \ 00084 if (SZ > 3) dp += coord[3] * d; else dp += d; \ 00085 \ 00086 if (dp < 0) { \ 00087 nr++; \ 00088 clipmask[i] |= CLIP_USER_BIT; \ 00089 } \ 00090 \ 00091 STRIDE_F(coord, stride); \ 00092 } \ 00093 \ 00094 if (nr > 0) { \ 00095 *clipormask |= CLIP_USER_BIT; \ 00096 if (nr == count) { \ 00097 *clipandmask |= CLIP_USER_BIT; \ 00098 return; \ 00099 } \ 00100 } \ 00101 } \ 00102 } 00103 00104 00105 USER_CLIPTEST(userclip2, 2) 00106 USER_CLIPTEST(userclip3, 3) 00107 USER_CLIPTEST(userclip4, 4) 00108 00109 static void (*(usercliptab[5]))( GLcontext *, 00110 GLvector4f *, GLubyte *, 00111 GLubyte *, GLubyte * ) = 00112 { 00113 NULL, 00114 NULL, 00115 userclip2, 00116 userclip3, 00117 userclip4 00118 }; 00119 00120 00121 00122 static GLboolean run_vertex_stage( GLcontext *ctx, 00123 struct tnl_pipeline_stage *stage ) 00124 { 00125 struct vertex_stage_data *store = (struct vertex_stage_data *)stage->privatePtr; 00126 TNLcontext *tnl = TNL_CONTEXT(ctx); 00127 struct vertex_buffer *VB = &tnl->vb; 00128 00129 if (ctx->VertexProgram._Current) 00130 return GL_TRUE; 00131 00132 if (ctx->_NeedEyeCoords) { 00133 /* Separate modelview transformation: 00134 * Use combined ModelProject to avoid some depth artifacts 00135 */ 00136 if (ctx->ModelviewMatrixStack.Top->type == MATRIX_IDENTITY) 00137 VB->EyePtr = VB->ObjPtr; 00138 else 00139 VB->EyePtr = TransformRaw( &store->eye, 00140 ctx->ModelviewMatrixStack.Top, 00141 VB->ObjPtr); 00142 } 00143 00144 VB->ClipPtr = TransformRaw( &store->clip, 00145 &ctx->_ModelProjectMatrix, 00146 VB->ObjPtr ); 00147 00148 /* Drivers expect this to be clean to element 4... 00149 */ 00150 switch (VB->ClipPtr->size) { 00151 case 1: 00152 /* impossible */ 00153 case 2: 00154 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 2 ); 00155 /* fall-through */ 00156 case 3: 00157 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 3 ); 00158 /* fall-through */ 00159 case 4: 00160 break; 00161 } 00162 00163 00164 /* Cliptest and perspective divide. Clip functions must clear 00165 * the clipmask. 00166 */ 00167 store->ormask = 0; 00168 store->andmask = CLIP_FRUSTUM_BITS; 00169 00170 if (tnl->NeedNdcCoords) { 00171 VB->NdcPtr = 00172 _mesa_clip_tab[VB->ClipPtr->size]( VB->ClipPtr, 00173 &store->proj, 00174 store->clipmask, 00175 &store->ormask, 00176 &store->andmask ); 00177 } 00178 else { 00179 VB->NdcPtr = NULL; 00180 _mesa_clip_np_tab[VB->ClipPtr->size]( VB->ClipPtr, 00181 NULL, 00182 store->clipmask, 00183 &store->ormask, 00184 &store->andmask ); 00185 } 00186 00187 if (store->andmask) 00188 return GL_FALSE; 00189 00190 00191 /* Test userclip planes. This contributes to VB->ClipMask, so 00192 * is essentially required to be in this stage. 00193 */ 00194 if (ctx->Transform.ClipPlanesEnabled) { 00195 usercliptab[VB->ClipPtr->size]( ctx, 00196 VB->ClipPtr, 00197 store->clipmask, 00198 &store->ormask, 00199 &store->andmask ); 00200 00201 if (store->andmask) 00202 return GL_FALSE; 00203 } 00204 00205 VB->ClipAndMask = store->andmask; 00206 VB->ClipOrMask = store->ormask; 00207 VB->ClipMask = store->clipmask; 00208 00209 return GL_TRUE; 00210 } 00211 00212 00213 static GLboolean init_vertex_stage( GLcontext *ctx, 00214 struct tnl_pipeline_stage *stage ) 00215 { 00216 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; 00217 struct vertex_stage_data *store; 00218 GLuint size = VB->Size; 00219 00220 stage->privatePtr = CALLOC(sizeof(*store)); 00221 store = VERTEX_STAGE_DATA(stage); 00222 if (!store) 00223 return GL_FALSE; 00224 00225 _mesa_vector4f_alloc( &store->eye, 0, size, 32 ); 00226 _mesa_vector4f_alloc( &store->clip, 0, size, 32 ); 00227 _mesa_vector4f_alloc( &store->proj, 0, size, 32 ); 00228 00229 store->clipmask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte)*size, 32 ); 00230 00231 if (!store->clipmask || 00232 !store->eye.data || 00233 !store->clip.data || 00234 !store->proj.data) 00235 return GL_FALSE; 00236 00237 return GL_TRUE; 00238 } 00239 00240 static void dtr( struct tnl_pipeline_stage *stage ) 00241 { 00242 struct vertex_stage_data *store = VERTEX_STAGE_DATA(stage); 00243 00244 if (store) { 00245 _mesa_vector4f_free( &store->eye ); 00246 _mesa_vector4f_free( &store->clip ); 00247 _mesa_vector4f_free( &store->proj ); 00248 ALIGN_FREE( store->clipmask ); 00249 FREE(store); 00250 stage->privatePtr = NULL; 00251 stage->run = init_vertex_stage; 00252 } 00253 } 00254 00255 00256 const struct tnl_pipeline_stage _tnl_vertex_transform_stage = 00257 { 00258 "modelview/project/cliptest/divide", 00259 NULL, /* private data */ 00260 init_vertex_stage, 00261 dtr, /* destructor */ 00262 NULL, 00263 run_vertex_stage /* run -- initially set to init */ 00264 }; Generated on Sun May 27 2012 04:20:46 for ReactOS by
1.7.6.1
|