Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 1 | /* $Id: api_arrayelt.c,v 1.3 2001/06/01 22:22:10 keithw Exp $ */ |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 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" |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 28 | #include "api_arrayelt.h" |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 29 | #include "context.h" |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 30 | #include "mem.h" |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 31 | #include "macros.h" |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 32 | #include "mtypes.h" |
| 33 | |
| 34 | |
| 35 | typedef struct { |
| 36 | GLint unit; |
| 37 | struct gl_client_array *array; |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 38 | void (*func)( GLenum, const void * ); |
| 39 | } AEtexarray; |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 40 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 41 | |
| 42 | typedef struct { |
| 43 | struct gl_client_array *array; |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 44 | void (*func)( const void * ); |
| 45 | } AEarray; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 46 | |
| 47 | typedef struct { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 48 | AEtexarray texarrays[MAX_TEXTURE_UNITS+1]; |
| 49 | AEarray arrays[32]; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 50 | GLuint NewState; |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 51 | } AEcontext; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 52 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 53 | #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context) |
| 54 | #define TYPE_IDX(t) ((t) & 0xf) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 55 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 56 | static void (*colorfuncs[2][8])( const void * ) = { |
| 57 | { (void (*)( const void * ))glColor3bv, |
| 58 | (void (*)( const void * ))glColor3ub, |
| 59 | (void (*)( const void * ))glColor3sv, |
| 60 | (void (*)( const void * ))glColor3usv, |
| 61 | (void (*)( const void * ))glColor3iv, |
| 62 | (void (*)( const void * ))glColor3uiv, |
| 63 | (void (*)( const void * ))glColor3fv, |
| 64 | (void (*)( const void * ))glColor3dv }, |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 65 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 66 | { (void (*)( const void * ))glColor4bv, |
| 67 | (void (*)( const void * ))glColor4ub, |
| 68 | (void (*)( const void * ))glColor4sv, |
| 69 | (void (*)( const void * ))glColor4usv, |
| 70 | (void (*)( const void * ))glColor4iv, |
| 71 | (void (*)( const void * ))glColor4uiv, |
| 72 | (void (*)( const void * ))glColor4fv, |
| 73 | (void (*)( const void * ))glColor4dv } |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 76 | static void (*vertexfuncs[3][8])( const void * ) = { |
| 77 | { 0, |
| 78 | 0, |
| 79 | (void (*)( const void * ))glVertex2sv, |
| 80 | 0, |
| 81 | (void (*)( const void * ))glVertex2iv, |
| 82 | 0, |
| 83 | (void (*)( const void * ))glVertex2fv, |
| 84 | (void (*)( const void * ))glVertex2dv }, |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 85 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 86 | { 0, |
| 87 | 0, |
| 88 | (void (*)( const void * ))glVertex3sv, |
| 89 | 0, |
| 90 | (void (*)( const void * ))glVertex3iv, |
| 91 | 0, |
| 92 | (void (*)( const void * ))glVertex3fv, |
| 93 | (void (*)( const void * ))glVertex3dv }, |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 94 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 95 | { 0, |
| 96 | 0, |
| 97 | (void (*)( const void * ))glVertex4sv, |
| 98 | 0, |
| 99 | (void (*)( const void * ))glVertex4iv, |
| 100 | 0, |
| 101 | (void (*)( const void * ))glVertex4fv, |
| 102 | (void (*)( const void * ))glVertex4dv } |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 106 | static void (*multitexfuncs[4][8])( GLenum, const void * ) = { |
| 107 | { 0, |
| 108 | 0, |
| 109 | (void (*)( GLenum, const void * ))glMultiTexCoord1svARB, |
| 110 | 0, |
| 111 | (void (*)( GLenum, const void * ))glMultiTexCoord1ivARB, |
| 112 | 0, |
| 113 | (void (*)( GLenum, const void * ))glMultiTexCoord1fvARB, |
| 114 | (void (*)( GLenum, const void * ))glMultiTexCoord1dvARB }, |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 115 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 116 | { 0, |
| 117 | 0, |
| 118 | (void (*)( GLenum, const void * ))glMultiTexCoord2svARB, |
| 119 | 0, |
| 120 | (void (*)( GLenum, const void * ))glMultiTexCoord2ivARB, |
| 121 | 0, |
| 122 | (void (*)( GLenum, const void * ))glMultiTexCoord2fvARB, |
| 123 | (void (*)( GLenum, const void * ))glMultiTexCoord2dvARB }, |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 124 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 125 | { 0, |
| 126 | 0, |
| 127 | (void (*)( GLenum, const void * ))glMultiTexCoord3svARB, |
| 128 | 0, |
| 129 | (void (*)( GLenum, const void * ))glMultiTexCoord3ivARB, |
| 130 | 0, |
| 131 | (void (*)( GLenum, const void * ))glMultiTexCoord3fvARB, |
| 132 | (void (*)( GLenum, const void * ))glMultiTexCoord3dvARB }, |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 133 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 134 | { 0, |
| 135 | 0, |
| 136 | (void (*)( GLenum, const void * ))glMultiTexCoord4svARB, |
| 137 | 0, |
| 138 | (void (*)( GLenum, const void * ))glMultiTexCoord4ivARB, |
| 139 | 0, |
| 140 | (void (*)( GLenum, const void * ))glMultiTexCoord4fvARB, |
| 141 | (void (*)( GLenum, const void * ))glMultiTexCoord4dvARB } |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 144 | static void (*indexfuncs[8])( const void * ) = { |
| 145 | 0, |
| 146 | (void (*)( const void * ))glIndexubv, |
| 147 | (void (*)( const void * ))glIndexsv, |
| 148 | 0, |
| 149 | (void (*)( const void * ))glIndexiv, |
| 150 | 0, |
| 151 | (void (*)( const void * ))glIndexfv, |
| 152 | (void (*)( const void * ))glIndexdv |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 156 | static void (*normalfuncs[8])( const void * ) = { |
| 157 | (void (*)( const void * ))glNormal3bv, |
| 158 | 0, |
| 159 | (void (*)( const void * ))glNormal3sv, |
| 160 | 0, |
| 161 | (void (*)( const void * ))glNormal3iv, |
| 162 | 0, |
| 163 | (void (*)( const void * ))glNormal3fv, |
| 164 | (void (*)( const void * ))glNormal3dv, |
| 165 | }; |
| 166 | |
| 167 | static void (*fogcoordfuncs[8])( const void * ) = { |
| 168 | 0, |
| 169 | 0, |
| 170 | 0, |
| 171 | 0, |
| 172 | 0, |
| 173 | 0, |
| 174 | (void (*)( const void * ))glFogCoordfvEXT, |
| 175 | (void (*)( const void * ))glFogCoorddvEXT, |
| 176 | }; |
| 177 | |
| 178 | static void (*secondarycolorfuncs[8])( const void * ) = { |
| 179 | (void (*)( const void * ))glSecondaryColor3bvEXT, |
| 180 | (void (*)( const void * ))glSecondaryColor3ubvEXT, |
| 181 | (void (*)( const void * ))glSecondaryColor3svEXT, |
| 182 | (void (*)( const void * ))glSecondaryColor3usvEXT, |
| 183 | (void (*)( const void * ))glSecondaryColor3ivEXT, |
| 184 | (void (*)( const void * ))glSecondaryColor3uivEXT, |
| 185 | (void (*)( const void * ))glSecondaryColor3fvEXT, |
| 186 | (void (*)( const void * ))glSecondaryColor3dvEXT, |
| 187 | }; |
| 188 | |
| 189 | |
| 190 | GLboolean _ae_create_context( GLcontext *ctx ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 191 | { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 192 | ctx->aelt_context = MALLOC( sizeof(AEcontext) ); |
| 193 | if (!ctx->aelt_context) |
| 194 | return GL_FALSE; |
| 195 | |
| 196 | AE_CONTEXT(ctx)->NewState = ~0; |
| 197 | return GL_TRUE; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 200 | |
| 201 | void _ae_destroy_context( GLcontext *ctx ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 202 | { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 203 | if ( AE_CONTEXT( ctx ) ) { |
| 204 | FREE( ctx->aelt_context ); |
| 205 | ctx->aelt_context = 0; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | |
| 210 | static void _ae_update_state( GLcontext *ctx ) |
| 211 | { |
| 212 | AEcontext *actx = AE_CONTEXT(ctx); |
| 213 | AEtexarray *ta = actx->texarrays; |
| 214 | AEarray *aa = actx->arrays; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 215 | int i; |
| 216 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 217 | for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 218 | if (ctx->Array.TexCoord[i].Enabled) { |
| 219 | ta->unit = i; |
| 220 | ta->array = &ctx->Array.TexCoord[i]; |
| 221 | ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)]; |
| 222 | ta++; |
| 223 | } |
| 224 | |
| 225 | ta->func = 0; |
| 226 | |
| 227 | if (ctx->Array.Color.Enabled) { |
| 228 | aa->array = &ctx->Array.Color; |
| 229 | aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)]; |
| 230 | aa++; |
| 231 | } |
| 232 | |
| 233 | if (ctx->Array.Normal.Enabled) { |
| 234 | aa->array = &ctx->Array.Normal; |
| 235 | aa->func = normalfuncs[TYPE_IDX(aa->array->Type)]; |
| 236 | aa++; |
| 237 | } |
| 238 | |
| 239 | if (ctx->Array.Index.Enabled) { |
| 240 | aa->array = &ctx->Array.Index; |
| 241 | aa->func = indexfuncs[TYPE_IDX(aa->array->Type)]; |
| 242 | aa++; |
| 243 | } |
| 244 | |
| 245 | if (ctx->Array.EdgeFlag.Enabled) { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 246 | aa->array = &ctx->Array.EdgeFlag; |
| 247 | aa->func = (void (*)( const void * ))glEdgeFlagv; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 248 | aa++; |
| 249 | } |
| 250 | |
| 251 | if (ctx->Array.FogCoord.Enabled) { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 252 | aa->array = &ctx->Array.FogCoord; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 253 | aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)]; |
| 254 | aa++; |
| 255 | } |
| 256 | |
| 257 | if (ctx->Array.SecondaryColor.Enabled) { |
| 258 | aa->array = &ctx->Array.SecondaryColor; |
| 259 | aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)]; |
| 260 | aa++; |
| 261 | } |
| 262 | |
| 263 | /* Must be last |
| 264 | */ |
| 265 | if (ctx->Array.Vertex.Enabled) { |
| 266 | aa->array = &ctx->Array.Vertex; |
| 267 | aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)]; |
| 268 | aa++; |
| 269 | } |
| 270 | |
| 271 | aa->func = 0; |
| 272 | actx->NewState = 0; |
| 273 | } |
| 274 | |
| 275 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 276 | void _ae_loopback_array_elt( GLint elt ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 277 | { |
| 278 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 279 | AEcontext *actx = AE_CONTEXT(ctx); |
| 280 | AEtexarray *ta; |
| 281 | AEarray *aa; |
| 282 | |
| 283 | if (actx->NewState) |
| 284 | _ae_update_state( ctx ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 285 | |
| 286 | for (ta = actx->texarrays ; ta->func ; ta++) { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 287 | ta->func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->StrideB ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 290 | /* Must be last |
| 291 | */ |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 292 | for (aa = actx->arrays ; aa->func ; aa++) { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 293 | aa->func( (char *)aa->array->Ptr + elt * aa->array->StrideB ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 298 | |
| 299 | void _ae_invalidate_state( GLcontext *ctx, GLuint new_state ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 300 | { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame^] | 301 | AE_CONTEXT(ctx)->NewState |= new_state; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 302 | } |