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