Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 3 | * Version: 6.1 |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 4 | * |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 5 | * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
Keith Whitwell | fc00cbe | 2001-12-20 15:30:45 +0000 | [diff] [blame] | 25 | /* Author: |
Brian Paul | 05a4b37 | 2002-10-29 20:28:36 +0000 | [diff] [blame] | 26 | * Keith Whitwell <keith@tungstengraphics.com> |
Keith Whitwell | fc00cbe | 2001-12-20 15:30:45 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 29 | #include "glheader.h" |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 30 | #include "api_arrayelt.h" |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 31 | #include "context.h" |
Keith Whitwell | fc00cbe | 2001-12-20 15:30:45 +0000 | [diff] [blame] | 32 | #include "glapi.h" |
Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 33 | #include "imports.h" |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 34 | #include "macros.h" |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 35 | #include "mtypes.h" |
| 36 | |
Karl Schultz | b72902e | 2004-01-28 22:24:12 +0000 | [diff] [blame] | 37 | typedef void (GLAPIENTRY *array_func)( const void * ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 38 | |
| 39 | typedef struct { |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 40 | const struct gl_client_array *array; |
Gareth Hughes | 1fb0a43 | 2001-12-28 06:28:10 +0000 | [diff] [blame] | 41 | array_func func; |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 42 | } AEarray; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 43 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 44 | typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data, GLboolean normalized, GLuint size ); |
| 45 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 46 | typedef struct { |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 47 | const struct gl_client_array *array; |
| 48 | attrib_func func; |
| 49 | GLuint index; |
| 50 | } AEattrib; |
| 51 | |
| 52 | typedef struct { |
| 53 | AEarray arrays[3]; /* color index, edge flag, null terminator */ |
| 54 | AEattrib attribs[VERT_ATTRIB_MAX + 1]; |
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) |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 59 | |
| 60 | /* |
| 61 | * Convert GL_BYTE, GL_UNSIGNED_BYTE, .. GL_DOUBLE into an integer |
| 62 | * in the range [0, 7]. Luckily these type tokens are sequentially |
| 63 | * numbered in gl.h |
| 64 | */ |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 65 | #define TYPE_IDX(t) ((t) & 0xf) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 66 | |
Karl Schultz | b72902e | 2004-01-28 22:24:12 +0000 | [diff] [blame] | 67 | static void (GLAPIENTRY *indexfuncs[8])( const void * ) = { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 68 | 0, |
Gareth Hughes | 1fb0a43 | 2001-12-28 06:28:10 +0000 | [diff] [blame] | 69 | (array_func)glIndexubv, |
| 70 | (array_func)glIndexsv, |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 71 | 0, |
Gareth Hughes | 1fb0a43 | 2001-12-28 06:28:10 +0000 | [diff] [blame] | 72 | (array_func)glIndexiv, |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 73 | 0, |
Gareth Hughes | 1fb0a43 | 2001-12-28 06:28:10 +0000 | [diff] [blame] | 74 | (array_func)glIndexfv, |
| 75 | (array_func)glIndexdv |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 79 | /**********************************************************************/ |
| 80 | |
| 81 | /* 1, 2, 3 or 4 GL_BYTE attribute */ |
| 82 | static void VertexAttribbv(GLuint index, const GLbyte *v, |
| 83 | GLboolean normalized, GLuint size) |
| 84 | { |
| 85 | switch (size) { |
| 86 | case 1: |
| 87 | if (normalized) |
| 88 | _glapi_Dispatch->VertexAttrib4fNV(index, BYTE_TO_FLOAT(v[0]), |
| 89 | 0, 0, 1); |
| 90 | else |
| 91 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], 0, 0, 1); |
| 92 | return; |
| 93 | case 2: |
| 94 | if (normalized) |
| 95 | _glapi_Dispatch->VertexAttrib4fNV(index, BYTE_TO_FLOAT(v[0]), |
| 96 | BYTE_TO_FLOAT(v[1]), 0, 1); |
| 97 | else |
| 98 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], 0, 1); |
| 99 | return; |
| 100 | case 3: |
| 101 | if (normalized) |
| 102 | _glapi_Dispatch->VertexAttrib4fNV(index, BYTE_TO_FLOAT(v[0]), |
| 103 | BYTE_TO_FLOAT(v[1]), |
| 104 | BYTE_TO_FLOAT(v[2]), 1); |
| 105 | else |
| 106 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], 1); |
| 107 | return; |
| 108 | case 4: |
| 109 | if (normalized) |
| 110 | _glapi_Dispatch->VertexAttrib4fNV(index, BYTE_TO_FLOAT(v[0]), |
| 111 | BYTE_TO_FLOAT(v[1]), |
| 112 | BYTE_TO_FLOAT(v[2]), |
| 113 | BYTE_TO_FLOAT(v[3])); |
| 114 | else |
| 115 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], v[3]); |
| 116 | return; |
| 117 | default: |
| 118 | _mesa_problem(NULL, "Bad size in VertexAttribbv"); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /* 1, 2, 3 or 4 GL_UNSIGNED_BYTE attribute */ |
| 123 | static void VertexAttribubv(GLuint index, const GLubyte *v, |
| 124 | GLboolean normalized, GLuint size) |
| 125 | { |
| 126 | switch (size) { |
| 127 | case 1: |
| 128 | if (normalized) |
| 129 | _glapi_Dispatch->VertexAttrib4fNV(index, UBYTE_TO_FLOAT(v[0]), |
| 130 | 0, 0, 1); |
| 131 | else |
| 132 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], 0, 0, 1); |
| 133 | return; |
| 134 | case 2: |
| 135 | if (normalized) |
| 136 | _glapi_Dispatch->VertexAttrib4fNV(index, UBYTE_TO_FLOAT(v[0]), |
| 137 | UBYTE_TO_FLOAT(v[1]), 0, 1); |
| 138 | else |
| 139 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], 0, 1); |
| 140 | return; |
| 141 | case 3: |
| 142 | if (normalized) |
| 143 | _glapi_Dispatch->VertexAttrib4fNV(index, UBYTE_TO_FLOAT(v[0]), |
| 144 | UBYTE_TO_FLOAT(v[1]), |
| 145 | UBYTE_TO_FLOAT(v[2]), 1); |
| 146 | else |
| 147 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], 1); |
| 148 | return; |
| 149 | case 4: |
| 150 | if (normalized) |
| 151 | _glapi_Dispatch->VertexAttrib4fNV(index, UBYTE_TO_FLOAT(v[0]), |
| 152 | UBYTE_TO_FLOAT(v[1]), |
| 153 | UBYTE_TO_FLOAT(v[2]), |
| 154 | UBYTE_TO_FLOAT(v[3])); |
| 155 | else |
| 156 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], v[3]); |
| 157 | return; |
| 158 | default: |
| 159 | _mesa_problem(NULL, "Bad size in VertexAttribubv"); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /* 1, 2, 3 or 4 GL_SHORT attribute */ |
| 164 | static void VertexAttribsv(GLuint index, const GLshort *v, |
| 165 | GLboolean normalized, GLuint size) |
| 166 | { |
| 167 | switch (size) { |
| 168 | case 1: |
| 169 | if (normalized) |
| 170 | _glapi_Dispatch->VertexAttrib4fNV(index, SHORT_TO_FLOAT(v[0]), |
| 171 | 0, 0, 1); |
| 172 | else |
| 173 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], 0, 0, 1); |
| 174 | return; |
| 175 | case 2: |
| 176 | if (normalized) |
| 177 | _glapi_Dispatch->VertexAttrib4fNV(index, SHORT_TO_FLOAT(v[0]), |
| 178 | SHORT_TO_FLOAT(v[1]), 0, 1); |
| 179 | else |
| 180 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], 0, 1); |
| 181 | return; |
| 182 | case 3: |
| 183 | if (normalized) |
| 184 | _glapi_Dispatch->VertexAttrib4fNV(index, SHORT_TO_FLOAT(v[0]), |
| 185 | SHORT_TO_FLOAT(v[1]), |
| 186 | SHORT_TO_FLOAT(v[2]), 1); |
| 187 | else |
| 188 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], 1); |
| 189 | return; |
| 190 | case 4: |
| 191 | if (normalized) |
| 192 | _glapi_Dispatch->VertexAttrib4fNV(index, SHORT_TO_FLOAT(v[0]), |
| 193 | SHORT_TO_FLOAT(v[1]), |
| 194 | SHORT_TO_FLOAT(v[2]), |
| 195 | SHORT_TO_FLOAT(v[3])); |
| 196 | else |
| 197 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], v[3]); |
| 198 | return; |
| 199 | default: |
| 200 | _mesa_problem(NULL, "Bad size in VertexAttribsv"); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | |
| 205 | /* 1, 2, 3 or 4 GL_UNSIGNED_SHORT attribute */ |
| 206 | static void VertexAttribusv(GLuint index, const GLushort *v, |
| 207 | GLboolean normalized, GLuint size) |
| 208 | { |
| 209 | switch (size) { |
| 210 | case 1: |
| 211 | if (normalized) |
| 212 | _glapi_Dispatch->VertexAttrib4fNV(index, USHORT_TO_FLOAT(v[0]), |
| 213 | 0, 0, 1); |
| 214 | else |
| 215 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], 0, 0, 1); |
| 216 | return; |
| 217 | case 2: |
| 218 | if (normalized) |
| 219 | _glapi_Dispatch->VertexAttrib4fNV(index, USHORT_TO_FLOAT(v[0]), |
| 220 | USHORT_TO_FLOAT(v[1]), 0, 1); |
| 221 | else |
| 222 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], 0, 1); |
| 223 | return; |
| 224 | case 3: |
| 225 | if (normalized) |
| 226 | _glapi_Dispatch->VertexAttrib4fNV(index, USHORT_TO_FLOAT(v[0]), |
| 227 | USHORT_TO_FLOAT(v[1]), |
| 228 | USHORT_TO_FLOAT(v[2]), 1); |
| 229 | else |
| 230 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], 1); |
| 231 | return; |
| 232 | case 4: |
| 233 | if (normalized) |
| 234 | _glapi_Dispatch->VertexAttrib4fNV(index, USHORT_TO_FLOAT(v[0]), |
| 235 | USHORT_TO_FLOAT(v[1]), |
| 236 | USHORT_TO_FLOAT(v[2]), |
| 237 | USHORT_TO_FLOAT(v[3])); |
| 238 | else |
| 239 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], v[3]); |
| 240 | return; |
| 241 | default: |
| 242 | _mesa_problem(NULL, "Bad size in VertexAttribusv"); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /* 1, 2, 3 or 4 GL_INT attribute */ |
| 247 | static void VertexAttribiv(GLuint index, const GLint *v, |
| 248 | GLboolean normalized, GLuint size) |
| 249 | { |
| 250 | switch (size) { |
| 251 | case 1: |
| 252 | if (normalized) |
| 253 | _glapi_Dispatch->VertexAttrib4fNV(index, INT_TO_FLOAT(v[0]), |
| 254 | 0, 0, 1); |
| 255 | else |
| 256 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], 0, 0, 1); |
| 257 | return; |
| 258 | case 2: |
| 259 | if (normalized) |
| 260 | _glapi_Dispatch->VertexAttrib4fNV(index, INT_TO_FLOAT(v[0]), |
| 261 | INT_TO_FLOAT(v[1]), 0, 1); |
| 262 | else |
| 263 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], 0, 1); |
| 264 | return; |
| 265 | case 3: |
| 266 | if (normalized) |
| 267 | _glapi_Dispatch->VertexAttrib4fNV(index, INT_TO_FLOAT(v[0]), |
| 268 | INT_TO_FLOAT(v[1]), |
| 269 | INT_TO_FLOAT(v[2]), 1); |
| 270 | else |
| 271 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], 1); |
| 272 | return; |
| 273 | case 4: |
| 274 | if (normalized) |
| 275 | _glapi_Dispatch->VertexAttrib4fNV(index, INT_TO_FLOAT(v[0]), |
| 276 | INT_TO_FLOAT(v[1]), |
| 277 | INT_TO_FLOAT(v[2]), |
| 278 | INT_TO_FLOAT(v[3])); |
| 279 | else |
| 280 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], v[3]); |
| 281 | return; |
| 282 | default: |
| 283 | _mesa_problem(NULL, "Bad size in VertexAttribiv"); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /* 1, 2, 3 or 4 GL_UNSIGNED_INT attribute */ |
| 288 | static void VertexAttribuiv(GLuint index, const GLuint *v, |
| 289 | GLboolean normalized, GLuint size) |
| 290 | { |
| 291 | switch (size) { |
| 292 | case 1: |
| 293 | if (normalized) |
| 294 | _glapi_Dispatch->VertexAttrib4fNV(index, UINT_TO_FLOAT(v[0]), |
| 295 | 0, 0, 1); |
| 296 | else |
| 297 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], 0, 0, 1); |
| 298 | return; |
| 299 | case 2: |
| 300 | if (normalized) |
| 301 | _glapi_Dispatch->VertexAttrib4fNV(index, UINT_TO_FLOAT(v[0]), |
| 302 | UINT_TO_FLOAT(v[1]), 0, 1); |
| 303 | else |
| 304 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], 0, 1); |
| 305 | return; |
| 306 | case 3: |
| 307 | if (normalized) |
| 308 | _glapi_Dispatch->VertexAttrib4fNV(index, UINT_TO_FLOAT(v[0]), |
| 309 | UINT_TO_FLOAT(v[1]), |
| 310 | UINT_TO_FLOAT(v[2]), 1); |
| 311 | else |
| 312 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], 1); |
| 313 | return; |
| 314 | case 4: |
| 315 | if (normalized) |
| 316 | _glapi_Dispatch->VertexAttrib4fNV(index, UINT_TO_FLOAT(v[0]), |
| 317 | UINT_TO_FLOAT(v[1]), |
| 318 | UINT_TO_FLOAT(v[2]), |
| 319 | UINT_TO_FLOAT(v[3])); |
| 320 | else |
| 321 | _glapi_Dispatch->VertexAttrib4fNV(index, v[0], v[1], v[2], v[3]); |
| 322 | return; |
| 323 | default: |
| 324 | _mesa_problem(NULL, "Bad size in VertexAttribuiv"); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /* 1, 2, 3 or 4 GL_FLOAT attribute */ |
| 329 | static void VertexAttribfv(GLuint index, const GLfloat *v, |
| 330 | GLboolean normalized, GLuint size) |
| 331 | { |
| 332 | (void) normalized; |
| 333 | switch (size) { |
| 334 | case 1: |
| 335 | _glapi_Dispatch->VertexAttrib1fvNV(index, v); |
| 336 | return; |
| 337 | case 2: |
| 338 | _glapi_Dispatch->VertexAttrib2fvNV(index, v); |
| 339 | return; |
| 340 | case 3: |
| 341 | _glapi_Dispatch->VertexAttrib3fvNV(index, v); |
| 342 | return; |
| 343 | case 4: |
| 344 | _glapi_Dispatch->VertexAttrib4fvNV(index, v); |
| 345 | return; |
| 346 | default: |
| 347 | _mesa_problem(NULL, "Bad size in VertexAttribfv"); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /* 1, 2, 3 or 4 GL_DOUBLE attribute */ |
| 352 | static void VertexAttribdv(GLuint index, const GLdouble *v, |
| 353 | GLboolean normalized, GLuint size) |
| 354 | { |
| 355 | (void) normalized; |
| 356 | switch (size) { |
| 357 | case 1: |
| 358 | _glapi_Dispatch->VertexAttrib1dvNV(index, v); |
| 359 | return; |
| 360 | case 2: |
| 361 | _glapi_Dispatch->VertexAttrib2dvNV(index, v); |
| 362 | return; |
| 363 | case 3: |
| 364 | _glapi_Dispatch->VertexAttrib3dvNV(index, v); |
| 365 | return; |
| 366 | case 4: |
| 367 | _glapi_Dispatch->VertexAttrib4dvNV(index, v); |
| 368 | return; |
| 369 | default: |
| 370 | _mesa_problem(NULL, "Bad size in VertexAttribdv"); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Array [size][type] of VertexAttrib functions |
| 376 | */ |
| 377 | static void (GLAPIENTRY *attribfuncs[8])( GLuint, const void *, GLboolean, GLuint ) = { |
| 378 | (attrib_func) VertexAttribbv, |
| 379 | (attrib_func) VertexAttribubv, |
| 380 | (attrib_func) VertexAttribsv, |
| 381 | (attrib_func) VertexAttribusv, |
| 382 | (attrib_func) VertexAttribiv, |
| 383 | (attrib_func) VertexAttribuiv, |
| 384 | (attrib_func) VertexAttribfv, |
| 385 | (attrib_func) VertexAttribdv |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 386 | }; |
| 387 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 388 | /**********************************************************************/ |
Brian Paul | 03c0c2e | 2002-01-14 16:06:35 +0000 | [diff] [blame] | 389 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 390 | |
| 391 | GLboolean _ae_create_context( GLcontext *ctx ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 392 | { |
Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 393 | if (ctx->aelt_context) |
| 394 | return GL_TRUE; |
| 395 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 396 | ctx->aelt_context = MALLOC( sizeof(AEcontext) ); |
Gareth Hughes | 1fb0a43 | 2001-12-28 06:28:10 +0000 | [diff] [blame] | 397 | if (!ctx->aelt_context) |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 398 | return GL_FALSE; |
| 399 | |
| 400 | AE_CONTEXT(ctx)->NewState = ~0; |
| 401 | return GL_TRUE; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 404 | |
| 405 | void _ae_destroy_context( GLcontext *ctx ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 406 | { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 407 | if ( AE_CONTEXT( ctx ) ) { |
| 408 | FREE( ctx->aelt_context ); |
| 409 | ctx->aelt_context = 0; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 414 | /* |
| 415 | * Return pointer to the conventional vertex array which corresponds |
| 416 | * to the given vertex attribute index. |
| 417 | */ |
| 418 | static struct gl_client_array * |
| 419 | conventional_array(GLcontext *ctx, GLuint index) |
| 420 | { |
| 421 | ASSERT(index < VERT_ATTRIB_MAX); |
| 422 | switch (index) { |
| 423 | case VERT_ATTRIB_POS: |
| 424 | return &ctx->Array.Vertex; |
| 425 | case VERT_ATTRIB_NORMAL: |
| 426 | return &ctx->Array.Normal; |
| 427 | case VERT_ATTRIB_COLOR0: |
| 428 | return &ctx->Array.Color; |
| 429 | case VERT_ATTRIB_COLOR1: |
| 430 | return &ctx->Array.SecondaryColor; |
| 431 | case VERT_ATTRIB_FOG: |
| 432 | return &ctx->Array.FogCoord; |
| 433 | case VERT_ATTRIB_TEX0: |
| 434 | case VERT_ATTRIB_TEX1: |
| 435 | case VERT_ATTRIB_TEX2: |
| 436 | case VERT_ATTRIB_TEX3: |
| 437 | case VERT_ATTRIB_TEX4: |
| 438 | case VERT_ATTRIB_TEX5: |
| 439 | case VERT_ATTRIB_TEX6: |
| 440 | case VERT_ATTRIB_TEX7: |
| 441 | return &ctx->Array.TexCoord[index - VERT_ATTRIB_TEX0]; |
| 442 | default: |
| 443 | return NULL; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | |
| 448 | /** |
| 449 | * Make a list of functions to call per glArrayElement call which will |
| 450 | * access the vertex array data. |
| 451 | * Most vertex attributes are handled via glVertexAttrib4fvNV. |
| 452 | */ |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 453 | static void _ae_update_state( GLcontext *ctx ) |
| 454 | { |
| 455 | AEcontext *actx = AE_CONTEXT(ctx); |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 456 | AEarray *aa = actx->arrays; |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 457 | AEattrib *at = actx->attribs; |
Brian Paul | db07de0 | 2002-04-19 00:23:08 +0000 | [diff] [blame] | 458 | GLuint i; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 459 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 460 | /* yuck, no generic array to correspond to color index or edge flag */ |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 461 | if (ctx->Array.Index.Enabled) { |
| 462 | aa->array = &ctx->Array.Index; |
| 463 | aa->func = indexfuncs[TYPE_IDX(aa->array->Type)]; |
| 464 | aa++; |
| 465 | } |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 466 | if (ctx->Array.EdgeFlag.Enabled) { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 467 | aa->array = &ctx->Array.EdgeFlag; |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 468 | aa->func = (array_func) glEdgeFlagv; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 469 | aa++; |
| 470 | } |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 471 | aa->func = NULL; /* terminate the list */ |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 472 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 473 | /* all other arrays handled here */ |
| 474 | for (i = 0; i < VERT_ATTRIB_MAX; i++) { |
| 475 | /* Note: we count down to zero so glVertex (attrib 0) is last!!! */ |
| 476 | const GLuint index = VERT_ATTRIB_MAX - i - 1; |
| 477 | struct gl_client_array *array = conventional_array(ctx, index); |
| 478 | |
| 479 | /* check for overriding generic vertex attribute */ |
| 480 | if (ctx->VertexProgram.Enabled |
| 481 | && ctx->Array.VertexAttrib[index].Enabled) { |
| 482 | array = &ctx->Array.VertexAttrib[index]; |
| 483 | } |
| 484 | |
| 485 | /* if array's enabled, add it to the list */ |
| 486 | if (array && array->Enabled) { |
| 487 | at->array = array; |
| 488 | at->func = attribfuncs[TYPE_IDX(array->Type)]; |
| 489 | at->index = index; |
| 490 | at++; |
| 491 | } |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 492 | } |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 493 | ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX); |
| 494 | at->func = NULL; /* terminate the list */ |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 495 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 496 | actx->NewState = 0; |
| 497 | } |
| 498 | |
| 499 | |
Karl Schultz | d674569 | 2003-12-04 20:23:44 +0000 | [diff] [blame] | 500 | void GLAPIENTRY _ae_loopback_array_elt( GLint elt ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 501 | { |
| 502 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 503 | const AEcontext *actx = AE_CONTEXT(ctx); |
| 504 | const AEarray *aa; |
| 505 | const AEattrib *at; |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 506 | |
| 507 | if (actx->NewState) |
| 508 | _ae_update_state( ctx ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 509 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 510 | /* color index and edge flags */ |
| 511 | for (aa = actx->arrays; aa->func ; aa++) { |
| 512 | const GLubyte *src = aa->array->BufferObj->Data |
| 513 | + (GLuint) aa->array->Ptr |
| 514 | + elt * aa->array->StrideB; |
| 515 | aa->func( src ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Brian Paul | 0aa8a10 | 2004-02-08 02:03:41 +0000 | [diff] [blame^] | 518 | /* all other attributes */ |
| 519 | for (at = actx->attribs; at->func; at++) { |
| 520 | const GLubyte *src = at->array->BufferObj->Data |
| 521 | + (GLuint) at->array->Ptr |
| 522 | + elt * at->array->StrideB; |
| 523 | at->func( at->index, src, at->array->Normalized, at->array->Size ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
| 527 | |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 528 | |
| 529 | void _ae_invalidate_state( GLcontext *ctx, GLuint new_state ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 530 | { |
Keith Whitwell | 4b7d6f2 | 2001-06-01 22:22:10 +0000 | [diff] [blame] | 531 | AE_CONTEXT(ctx)->NewState |= new_state; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 532 | } |