Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 1 | /* $Id: api_arrayelt.c,v 1.2 2001/03/12 00:48:37 gareth Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| 5 | * Version: 3.5 |
| 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 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 27 | #include "glheader.h" |
| 28 | #include "api_noop.h" |
| 29 | #include "context.h" |
| 30 | #include "colormac.h" |
| 31 | #include "light.h" |
| 32 | #include "macros.h" |
| 33 | #include "mmath.h" |
| 34 | #include "mtypes.h" |
| 35 | |
| 36 | |
| 37 | typedef struct { |
| 38 | GLint unit; |
| 39 | struct gl_client_array *array; |
| 40 | void *func; |
| 41 | } AAtexarray; |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 42 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 43 | |
| 44 | typedef struct { |
| 45 | struct gl_client_array *array; |
| 46 | void *func; |
| 47 | } AAarray; |
| 48 | |
| 49 | typedef struct { |
| 50 | AAtexarray texarrays[MAX_TEXTURE_UNITS+1]; |
| 51 | AAarray arrays[10]; |
| 52 | GLuint NewState; |
| 53 | } AAcontext; |
| 54 | |
| 55 | |
| 56 | static void *colorfuncs[2][7] = { |
| 57 | { glColor3bv, |
| 58 | glColor3ub, |
| 59 | glColor3sv, |
| 60 | glColor3usv, |
| 61 | glColor3iv, |
| 62 | glColor3fv, |
| 63 | glColor3dv }, |
| 64 | |
| 65 | { glColor4bv, |
| 66 | glColor4ub, |
| 67 | glColor4sv, |
| 68 | glColor4usv, |
| 69 | glColor4iv, |
| 70 | glColor4fv, |
| 71 | glColor4dv } |
| 72 | }; |
| 73 | |
| 74 | static void *vertexfuncs[3][7] = { |
| 75 | { glVertex3bv, |
| 76 | glVertex3ub, |
| 77 | glVertex3sv, |
| 78 | glVertex3usv, |
| 79 | glVertex3iv, |
| 80 | glVertex3fv, |
| 81 | glVertex3dv }, |
| 82 | |
| 83 | { glVertex3bv, |
| 84 | glVertex3ub, |
| 85 | glVertex3sv, |
| 86 | glVertex3usv, |
| 87 | glVertex3iv, |
| 88 | glVertex3fv, |
| 89 | glVertex3dv }, |
| 90 | |
| 91 | { glVertex4bv, |
| 92 | glVertex4ub, |
| 93 | glVertex4sv, |
| 94 | glVertex4usv, |
| 95 | glVertex4iv, |
| 96 | glVertex4fv, |
| 97 | glVertex4dv } |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | static void *multitexfuncs[4][7] = { |
| 102 | { glMultiTexCoord1bv, |
| 103 | glMultiTexCoord1ub, |
| 104 | glMultiTexCoord1sv, |
| 105 | glMultiTexCoord1usv, |
| 106 | glMultiTexCoord1iv, |
| 107 | glMultiTexCoord1fv, |
| 108 | glMultiTexCoord1dv }, |
| 109 | |
| 110 | { glMultiTexCoord2bv, |
| 111 | glMultiTexCoord2ub, |
| 112 | glMultiTexCoord2sv, |
| 113 | glMultiTexCoord2usv, |
| 114 | glMultiTexCoord2iv, |
| 115 | glMultiTexCoord2fv, |
| 116 | glMultiTexCoord2dv }, |
| 117 | |
| 118 | { glMultiTexCoord3bv, |
| 119 | glMultiTexCoord3ub, |
| 120 | glMultiTexCoord3sv, |
| 121 | glMultiTexCoord3usv, |
| 122 | glMultiTexCoord3iv, |
| 123 | glMultiTexCoord3fv, |
| 124 | glMultiTexCoord3dv }, |
| 125 | |
| 126 | { glMultiTexCoord4bv, |
| 127 | glMultiTexCoord4ub, |
| 128 | glMultiTexCoord4sv, |
| 129 | glMultiTexCoord4usv, |
| 130 | glMultiTexCoord4iv, |
| 131 | glMultiTexCoord4fv, |
| 132 | glMultiTexCoord4dv } |
| 133 | }; |
| 134 | |
| 135 | static void *indexfuncs[7] = { |
| 136 | { glIndexbv, |
| 137 | glIndexub, |
| 138 | glIndexsv, |
| 139 | glIndexusv, |
| 140 | glIndexiv, |
| 141 | glIndexfv, |
| 142 | glIndexdv }, |
| 143 | }; |
| 144 | |
| 145 | static void *edgeflagfuncs[7] = { |
| 146 | { glEdgeFlagbv, |
| 147 | glEdgeFlagub, |
| 148 | glEdgeFlagsv, |
| 149 | glEdgeFlagusv, |
| 150 | glEdgeFlagiv, |
| 151 | glEdgeFlagfv, |
| 152 | glEdgeFlagdv }, |
| 153 | }; |
| 154 | |
| 155 | static void *normalfuncs[7] = { |
| 156 | { glNormal3bv, |
| 157 | glNormal3ub, |
| 158 | glNormal3sv, |
| 159 | glNormal3usv, |
| 160 | glNormal3iv, |
| 161 | glNormal3fv, |
| 162 | glNormal3dv }, |
| 163 | }; |
| 164 | |
| 165 | static void *fogcoordfuncs[7] = { |
| 166 | { glFogCoordbv, |
| 167 | glFogCoordub, |
| 168 | glFogCoordsv, |
| 169 | glFogCoordusv, |
| 170 | glFogCoordiv, |
| 171 | glFogCoordfv, |
| 172 | glFogCoorddv }, |
| 173 | }; |
| 174 | |
| 175 | static void *secondarycolorfuncs[7] = { |
| 176 | { glSecondaryColor3bv, |
| 177 | glSecondaryColor3ub, |
| 178 | glSecondaryColor3sv, |
| 179 | glSecondaryColor3usv, |
| 180 | glSecondaryColor3iv, |
| 181 | glSecondaryColor3fv, |
| 182 | glSecondaryColor3dv }, |
| 183 | }; |
| 184 | |
| 185 | |
| 186 | void _aa_create_context( GLcontext *ctx ) |
| 187 | { |
| 188 | ctx->aa_context = MALLOC( sizeof(AAcontext) ); |
| 189 | AA_CONTEXT(ctx)->NewState = ~0; |
| 190 | } |
| 191 | |
| 192 | static void _aa_update_state( GLcontext *ctx ) |
| 193 | { |
| 194 | AAcontext *actx = AA_CONTEXT(ctx); |
| 195 | AAtexarray *ta = actx->texarrays; |
| 196 | AAarray *aa = actx->arrays; |
| 197 | int i; |
| 198 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 199 | for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 200 | if (ctx->Array.TexCoord[i].Enabled) { |
| 201 | ta->unit = i; |
| 202 | ta->array = &ctx->Array.TexCoord[i]; |
| 203 | ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)]; |
| 204 | ta++; |
| 205 | } |
| 206 | |
| 207 | ta->func = 0; |
| 208 | |
| 209 | if (ctx->Array.Color.Enabled) { |
| 210 | aa->array = &ctx->Array.Color; |
| 211 | aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)]; |
| 212 | aa++; |
| 213 | } |
| 214 | |
| 215 | if (ctx->Array.Normal.Enabled) { |
| 216 | aa->array = &ctx->Array.Normal; |
| 217 | aa->func = normalfuncs[TYPE_IDX(aa->array->Type)]; |
| 218 | aa++; |
| 219 | } |
| 220 | |
| 221 | if (ctx->Array.Index.Enabled) { |
| 222 | aa->array = &ctx->Array.Index; |
| 223 | aa->func = indexfuncs[TYPE_IDX(aa->array->Type)]; |
| 224 | aa++; |
| 225 | } |
| 226 | |
| 227 | if (ctx->Array.EdgeFlag.Enabled) { |
| 228 | aa->array = &ctx->Array.Edgeflag; |
| 229 | aa->func = edgeflagfuncs[TYPE_IDX(aa->array->Type)]; |
| 230 | aa++; |
| 231 | } |
| 232 | |
| 233 | if (ctx->Array.FogCoord.Enabled) { |
| 234 | aa->array = &ctx->Array.Fogcoord; |
| 235 | aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)]; |
| 236 | aa++; |
| 237 | } |
| 238 | |
| 239 | if (ctx->Array.SecondaryColor.Enabled) { |
| 240 | aa->array = &ctx->Array.SecondaryColor; |
| 241 | aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)]; |
| 242 | aa++; |
| 243 | } |
| 244 | |
| 245 | /* Must be last |
| 246 | */ |
| 247 | if (ctx->Array.Vertex.Enabled) { |
| 248 | aa->array = &ctx->Array.Vertex; |
| 249 | aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)]; |
| 250 | aa++; |
| 251 | } |
| 252 | |
| 253 | aa->func = 0; |
| 254 | actx->NewState = 0; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | static void _aa_loopback_array_elt( GLint elt ) |
| 259 | { |
| 260 | GET_CURRENT_CONTEXT(ctx); |
| 261 | AAcontext *actx = AA_CONTEXT(ctx); |
| 262 | AAtexarray *ta; |
| 263 | AAarray *aa; |
| 264 | |
| 265 | for (ta = actx->texarrays ; ta->func ; ta++) { |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 266 | void (*func)( GLint, const void * ) = |
| 267 | (void (*)( GLint, const void * )) ta->func; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 268 | func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->SizeB ); |
| 269 | } |
| 270 | |
| 271 | for (aa = actx->arrays ; aa->func ; aa++) { |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 272 | void (*func)( GLint, const void * ) = |
| 273 | (void (*)( GLint, const void * )) aa->func; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 274 | func( (char *)aa->array->Ptr + elt * aa->array->SizeB ); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | |
| 279 | void _aa_exec_array_elt( GLint elt ) |
| 280 | { |
| 281 | GET_CURRENT_CONTEXT(ctx); |
| 282 | AAcontext *actx = AA_CONTEXT(ctx); |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 283 | |
| 284 | if (actx->NewState) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 285 | _aa_update_state( ctx ); |
| 286 | |
| 287 | ctx->Exec->ArrayElement = _aa_loopback_array_elt; |
| 288 | _aa_loopback_array_elt( elt ); |
| 289 | } |
| 290 | |
| 291 | /* This works for save as well: |
| 292 | */ |
| 293 | void _aa_save_array_elt( GLint elt ) |
| 294 | { |
| 295 | GET_CURRENT_CONTEXT(ctx); |
| 296 | AAcontext *actx = AA_CONTEXT(ctx); |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 297 | |
| 298 | if (actx->NewState) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 299 | _aa_update_state( ctx ); |
| 300 | |
| 301 | ctx->Save->ArrayElement = _aa_loopback_array_elt; |
| 302 | _aa_loopback_array_elt( elt ); |
| 303 | } |
| 304 | |
| 305 | |
| 306 | void aa_invalidate_state( GLcontext *ctx, GLuint new_state ) |
| 307 | { |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame^] | 308 | if (AA_CONTEXT(ctx)) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 309 | AA_CONTEXT(ctx)->NewState |= new_state; |
| 310 | } |