vtxfmt.c revision d2237d48eccbd47a4e69078c25de09453730d298
1/* $Id: vtxfmt.c,v 1.10 2001/12/15 02:14:43 brianp Exp $ */ 2 3/* 4 * Mesa 3-D graphics library 5 * Version: 4.1 6 * 7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 * Authors: 27 * Keith Whitwell <keithw@valinux.com> 28 * Gareth Hughes <gareth@valinux.com> 29 */ 30 31#include "glheader.h" 32#include "api_loopback.h" 33#include "context.h" 34#include "mtypes.h" 35#include "state.h" 36#include "vtxfmt.h" 37 38 39/* The neutral vertex format. This wraps all tnl module functions, 40 * verifying that the currently-installed module is valid and then 41 * installing the function pointers in a lazy fashion. It records the 42 * function pointers that have been swapped out, which allows a fast 43 * restoration of the neutral module in almost all cases -- a typical 44 * app might only require 4-6 functions to be modified from the neutral 45 * baseline, and only restoring these is certainly preferable to doing 46 * the entire module's 60 or so function pointers. 47 */ 48 49#define PRE_LOOPBACK( FUNC ) \ 50{ \ 51 GET_CURRENT_CONTEXT(ctx); \ 52 struct gl_tnl_module *tnl = &(ctx->TnlModule); \ 53 const GLuint new_state = ctx->NewState; \ 54 \ 55 if ( new_state ) \ 56 _mesa_update_state( ctx ); \ 57 \ 58 /* Validate the current tnl module. */ \ 59 if ( new_state & ctx->Driver.NeedValidate ) \ 60 ctx->Driver.ValidateTnlModule( ctx, new_state ); \ 61 \ 62 ASSERT( tnl->Current ); \ 63 ASSERT( tnl->SwapCount < NUM_VERTEX_FORMAT_ENTRIES ); \ 64 \ 65 /* Save the swapped function's dispatch entry so it can be */ \ 66 /* restored later. */ \ 67 tnl->Swapped[tnl->SwapCount][0] = (void *)&(ctx->Exec->FUNC); \ 68 tnl->Swapped[tnl->SwapCount][1] = (void *)TAG(FUNC); \ 69 tnl->SwapCount++; \ 70 \ 71 if ( 0 ) \ 72 fprintf( stderr, " swapping gl" #FUNC"...\n" ); \ 73 \ 74 /* Install the tnl function pointer. */ \ 75 ctx->Exec->FUNC = tnl->Current->FUNC; \ 76} 77 78#define TAG(x) neutral_##x 79#include "vtxfmt_tmp.h" 80 81 82 83static void install_vtxfmt( struct _glapi_table *tab, GLvertexformat *vfmt ) 84{ 85 tab->ArrayElement = vfmt->ArrayElement; 86 tab->Color3f = vfmt->Color3f; 87 tab->Color3fv = vfmt->Color3fv; 88 tab->Color3ub = vfmt->Color3ub; 89 tab->Color3ubv = vfmt->Color3ubv; 90 tab->Color4f = vfmt->Color4f; 91 tab->Color4fv = vfmt->Color4fv; 92 tab->Color4ub = vfmt->Color4ub; 93 tab->Color4ubv = vfmt->Color4ubv; 94 tab->EdgeFlag = vfmt->EdgeFlag; 95 tab->EdgeFlagv = vfmt->EdgeFlagv; 96 tab->EvalCoord1f = vfmt->EvalCoord1f; 97 tab->EvalCoord1fv = vfmt->EvalCoord1fv; 98 tab->EvalCoord2f = vfmt->EvalCoord2f; 99 tab->EvalCoord2fv = vfmt->EvalCoord2fv; 100 tab->EvalPoint1 = vfmt->EvalPoint1; 101 tab->EvalPoint2 = vfmt->EvalPoint2; 102 tab->FogCoordfEXT = vfmt->FogCoordfEXT; 103 tab->FogCoordfvEXT = vfmt->FogCoordfvEXT; 104 tab->Indexi = vfmt->Indexi; 105 tab->Indexiv = vfmt->Indexiv; 106 tab->Materialfv = vfmt->Materialfv; 107 tab->MultiTexCoord1fARB = vfmt->MultiTexCoord1fARB; 108 tab->MultiTexCoord1fvARB = vfmt->MultiTexCoord1fvARB; 109 tab->MultiTexCoord2fARB = vfmt->MultiTexCoord2fARB; 110 tab->MultiTexCoord2fvARB = vfmt->MultiTexCoord2fvARB; 111 tab->MultiTexCoord3fARB = vfmt->MultiTexCoord3fARB; 112 tab->MultiTexCoord3fvARB = vfmt->MultiTexCoord3fvARB; 113 tab->MultiTexCoord4fARB = vfmt->MultiTexCoord4fARB; 114 tab->MultiTexCoord4fvARB = vfmt->MultiTexCoord4fvARB; 115 tab->Normal3f = vfmt->Normal3f; 116 tab->Normal3fv = vfmt->Normal3fv; 117 tab->SecondaryColor3fEXT = vfmt->SecondaryColor3fEXT; 118 tab->SecondaryColor3fvEXT = vfmt->SecondaryColor3fvEXT; 119 tab->SecondaryColor3ubEXT = vfmt->SecondaryColor3ubEXT; 120 tab->SecondaryColor3ubvEXT = vfmt->SecondaryColor3ubvEXT; 121 tab->TexCoord1f = vfmt->TexCoord1f; 122 tab->TexCoord1fv = vfmt->TexCoord1fv; 123 tab->TexCoord2f = vfmt->TexCoord2f; 124 tab->TexCoord2fv = vfmt->TexCoord2fv; 125 tab->TexCoord3f = vfmt->TexCoord3f; 126 tab->TexCoord3fv = vfmt->TexCoord3fv; 127 tab->TexCoord4f = vfmt->TexCoord4f; 128 tab->TexCoord4fv = vfmt->TexCoord4fv; 129 tab->Vertex2f = vfmt->Vertex2f; 130 tab->Vertex2fv = vfmt->Vertex2fv; 131 tab->Vertex3f = vfmt->Vertex3f; 132 tab->Vertex3fv = vfmt->Vertex3fv; 133 tab->Vertex4f = vfmt->Vertex4f; 134 tab->Vertex4fv = vfmt->Vertex4fv; 135 tab->CallList = vfmt->CallList; 136 tab->Begin = vfmt->Begin; 137 tab->End = vfmt->End; 138 tab->VertexAttrib4fNV = vfmt->VertexAttrib4fNV; 139 tab->Rectf = vfmt->Rectf; 140 tab->DrawArrays = vfmt->DrawArrays; 141 tab->DrawElements = vfmt->DrawElements; 142 tab->DrawRangeElements = vfmt->DrawRangeElements; 143 tab->EvalMesh1 = vfmt->EvalMesh1; 144 tab->EvalMesh2 = vfmt->EvalMesh2; 145 assert(tab->EvalMesh2); 146} 147 148 149void _mesa_init_exec_vtxfmt( GLcontext *ctx ) 150{ 151 install_vtxfmt( ctx->Exec, &neutral_vtxfmt ); 152} 153 154 155void _mesa_install_exec_vtxfmt( GLcontext *ctx, GLvertexformat *vfmt ) 156{ 157 ctx->TnlModule.Current = vfmt; 158 _mesa_restore_exec_vtxfmt( ctx ); 159 if ( ctx->ExecPrefersFloat != vfmt->prefer_float_colors ) 160 _mesa_loopback_prefer_float( ctx->Exec, vfmt->prefer_float_colors ); 161} 162 163void _mesa_install_save_vtxfmt( GLcontext *ctx, GLvertexformat *vfmt ) 164{ 165 install_vtxfmt( ctx->Save, vfmt ); 166 if ( ctx->SavePrefersFloat != vfmt->prefer_float_colors ) 167 _mesa_loopback_prefer_float( ctx->Save, vfmt->prefer_float_colors ); 168} 169 170 171void _mesa_restore_exec_vtxfmt( GLcontext *ctx ) 172{ 173 struct gl_tnl_module *tnl = &(ctx->TnlModule); 174 GLuint i; 175 176 /* Restore the neutral tnl module wrapper. 177 */ 178 for ( i = 0 ; i < tnl->SwapCount ; i++ ) { 179 *(void **)tnl->Swapped[i][0] = tnl->Swapped[i][1]; 180 } 181 182 tnl->SwapCount = 0; 183} 184