Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygent_vb_normals.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 struct normal_stage_data { 00043 normal_func NormalTransform; 00044 GLvector4f normal; 00045 }; 00046 00047 #define NORMAL_STAGE_DATA(stage) ((struct normal_stage_data *)stage->privatePtr) 00048 00049 00050 static GLboolean 00051 run_normal_stage(GLcontext *ctx, struct tnl_pipeline_stage *stage) 00052 { 00053 struct normal_stage_data *store = NORMAL_STAGE_DATA(stage); 00054 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; 00055 const GLfloat *lengths; 00056 00057 if (!store->NormalTransform) 00058 return GL_TRUE; 00059 00060 /* We can only use the display list's saved normal lengths if we've 00061 * got a transformation matrix with uniform scaling. 00062 */ 00063 if (_math_matrix_is_general_scale(ctx->ModelviewMatrixStack.Top)) 00064 lengths = NULL; 00065 else 00066 lengths = VB->NormalLengthPtr; 00067 00068 store->NormalTransform( ctx->ModelviewMatrixStack.Top, 00069 ctx->_ModelViewInvScale, 00070 VB->AttribPtr[_TNL_ATTRIB_NORMAL], /* input normals */ 00071 lengths, 00072 &store->normal ); /* resulting normals */ 00073 00074 if (VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count > 1) { 00075 store->normal.stride = 4 * sizeof(GLfloat); 00076 } 00077 else { 00078 store->normal.stride = 0; 00079 } 00080 00081 VB->AttribPtr[_TNL_ATTRIB_NORMAL] = &store->normal; 00082 VB->NormalPtr = &store->normal; 00083 00084 VB->NormalLengthPtr = NULL; /* no longer valid */ 00085 return GL_TRUE; 00086 } 00087 00088 00093 static void 00094 validate_normal_stage(GLcontext *ctx, struct tnl_pipeline_stage *stage) 00095 { 00096 struct normal_stage_data *store = NORMAL_STAGE_DATA(stage); 00097 00098 if (ctx->VertexProgram._Current || 00099 (!ctx->Light.Enabled && 00100 !(ctx->Texture._GenFlags & TEXGEN_NEED_NORMALS))) { 00101 store->NormalTransform = NULL; 00102 return; 00103 } 00104 00105 if (ctx->_NeedEyeCoords) { 00106 /* Eye coordinates are needed, for whatever reasons. 00107 * Do lighting in eye coordinates, as the GL spec says. 00108 */ 00109 GLuint transform = NORM_TRANSFORM_NO_ROT; 00110 00111 if (_math_matrix_has_rotation(ctx->ModelviewMatrixStack.Top)) { 00112 /* need to do full (3x3) matrix transform */ 00113 transform = NORM_TRANSFORM; 00114 } 00115 00116 if (ctx->Transform.Normalize) { 00117 store->NormalTransform = _mesa_normal_tab[transform | NORM_NORMALIZE]; 00118 } 00119 else if (ctx->Transform.RescaleNormals && 00120 ctx->_ModelViewInvScale != 1.0) { 00121 store->NormalTransform = _mesa_normal_tab[transform | NORM_RESCALE]; 00122 } 00123 else { 00124 store->NormalTransform = _mesa_normal_tab[transform]; 00125 } 00126 } 00127 else { 00128 /* We don't need eye coordinates. 00129 * Do lighting in object coordinates. Thus, we don't need to fully 00130 * transform normal vectors (just leave them in object coordinates) 00131 * but we still need to do normalization/rescaling if enabled. 00132 */ 00133 if (ctx->Transform.Normalize) { 00134 store->NormalTransform = _mesa_normal_tab[NORM_NORMALIZE]; 00135 } 00136 else if (!ctx->Transform.RescaleNormals && 00137 ctx->_ModelViewInvScale != 1.0) { 00138 store->NormalTransform = _mesa_normal_tab[NORM_RESCALE]; 00139 } 00140 else { 00141 store->NormalTransform = NULL; 00142 } 00143 } 00144 } 00145 00146 00150 static GLboolean 00151 alloc_normal_data(GLcontext *ctx, struct tnl_pipeline_stage *stage) 00152 { 00153 TNLcontext *tnl = TNL_CONTEXT(ctx); 00154 struct normal_stage_data *store; 00155 00156 stage->privatePtr = _mesa_malloc(sizeof(*store)); 00157 store = NORMAL_STAGE_DATA(stage); 00158 if (!store) 00159 return GL_FALSE; 00160 00161 _mesa_vector4f_alloc( &store->normal, 0, tnl->vb.Size, 32 ); 00162 return GL_TRUE; 00163 } 00164 00165 00169 static void 00170 free_normal_data(struct tnl_pipeline_stage *stage) 00171 { 00172 struct normal_stage_data *store = NORMAL_STAGE_DATA(stage); 00173 if (store) { 00174 _mesa_vector4f_free( &store->normal ); 00175 _mesa_free( store ); 00176 stage->privatePtr = NULL; 00177 } 00178 } 00179 00180 00181 const struct tnl_pipeline_stage _tnl_normal_transform_stage = 00182 { 00183 "normal transform", /* name */ 00184 NULL, /* privatePtr */ 00185 alloc_normal_data, /* create */ 00186 free_normal_data, /* destroy */ 00187 validate_normal_stage, /* validate */ 00188 run_normal_stage /* run */ 00189 }; Generated on Thu May 24 2012 04:20:58 for ReactOS by
1.7.6.1
|