| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1 | /* $Id: context.c,v 1.27 1999/12/10 19:09:21 brianp Exp $ */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 5 | * Version: 3.3 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 1999 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 | |
| 27 | |
| 28 | /* |
| 29 | * If multi-threading is enabled (-DTHREADS) then each thread has it's |
| 30 | * own rendering context. A thread obtains the pointer to its GLcontext |
| 31 | * with the gl_get_thread_context() function. Otherwise, the global |
| 32 | * pointer, CC, points to the current context used by all threads in |
| 33 | * the address space. |
| 34 | */ |
| 35 | |
| 36 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 37 | #ifdef PC_HEADER |
| 38 | #include "all.h" |
| 39 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 40 | #include "glheader.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 41 | #include "accum.h" |
| 42 | #include "alphabuf.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 43 | #include "clip.h" |
| 44 | #include "context.h" |
| 45 | #include "cva.h" |
| 46 | #include "depth.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 47 | #include "dispatch.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 48 | #include "dlist.h" |
| 49 | #include "eval.h" |
| 50 | #include "enums.h" |
| Brian Paul | 585a68c | 1999-09-11 11:31:34 +0000 | [diff] [blame] | 51 | #include "extensions.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 52 | #include "fog.h" |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 53 | #include "get.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 54 | #include "glapi.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 55 | #include "hash.h" |
| 56 | #include "light.h" |
| 57 | #include "lines.h" |
| 58 | #include "dlist.h" |
| 59 | #include "macros.h" |
| 60 | #include "matrix.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 61 | #include "mem.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 62 | #include "mmath.h" |
| 63 | #include "pb.h" |
| 64 | #include "pipeline.h" |
| 65 | #include "points.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 66 | #include "quads.h" |
| 67 | #include "shade.h" |
| 68 | #include "simple_list.h" |
| 69 | #include "stencil.h" |
| 70 | #include "stages.h" |
| 71 | #include "triangle.h" |
| 72 | #include "translate.h" |
| 73 | #include "teximage.h" |
| 74 | #include "texobj.h" |
| 75 | #include "texstate.h" |
| 76 | #include "texture.h" |
| 77 | #include "types.h" |
| 78 | #include "varray.h" |
| 79 | #include "vb.h" |
| 80 | #include "vbcull.h" |
| 81 | #include "vbfill.h" |
| 82 | #include "vbrender.h" |
| 83 | #include "vbxform.h" |
| Keith Whitwell | 3875679 | 1999-08-29 10:26:31 +0000 | [diff] [blame] | 84 | #include "vertices.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 85 | #include "xform.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
| 88 | |
| 89 | |
| 90 | /**********************************************************************/ |
| 91 | /***** Context and Thread management *****/ |
| 92 | /**********************************************************************/ |
| 93 | |
| 94 | |
| 95 | #ifdef THREADS |
| 96 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 97 | #include "mthreads.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 98 | static MesaTSD mesa_ctx_tsd; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 99 | static void mesa_ctx_thread_init() { |
| 100 | MesaInitTSD(&mesa_ctx_tsd); |
| 101 | } |
| 102 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 103 | #else |
| 104 | |
| 105 | /* One Current Context pointer for all threads in the address space */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 106 | GLcontext *_mesa_current_context = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 107 | struct immediate *CURRENT_INPUT = NULL; |
| 108 | |
| 109 | #endif /*THREADS*/ |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | /**********************************************************************/ |
| 115 | /***** Profiling functions *****/ |
| 116 | /**********************************************************************/ |
| 117 | |
| 118 | #ifdef PROFILE |
| 119 | |
| 120 | #include <sys/times.h> |
| 121 | #include <sys/param.h> |
| 122 | |
| 123 | |
| 124 | /* |
| 125 | * Return system time in seconds. |
| 126 | * NOTE: this implementation may not be very portable! |
| 127 | */ |
| 128 | GLdouble gl_time( void ) |
| 129 | { |
| 130 | static GLdouble prev_time = 0.0; |
| 131 | static GLdouble time; |
| 132 | struct tms tm; |
| 133 | clock_t clk; |
| 134 | |
| 135 | clk = times(&tm); |
| 136 | |
| 137 | #ifdef CLK_TCK |
| 138 | time = (double)clk / (double)CLK_TCK; |
| 139 | #else |
| 140 | time = (double)clk / (double)HZ; |
| 141 | #endif |
| 142 | |
| 143 | if (time>prev_time) { |
| 144 | prev_time = time; |
| 145 | return time; |
| 146 | } |
| 147 | else { |
| 148 | return prev_time; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * Reset the timing/profiling counters |
| 154 | */ |
| 155 | static void init_timings( GLcontext *ctx ) |
| 156 | { |
| 157 | ctx->BeginEndCount = 0; |
| 158 | ctx->BeginEndTime = 0.0; |
| 159 | ctx->VertexCount = 0; |
| 160 | ctx->VertexTime = 0.0; |
| 161 | ctx->PointCount = 0; |
| 162 | ctx->PointTime = 0.0; |
| 163 | ctx->LineCount = 0; |
| 164 | ctx->LineTime = 0.0; |
| 165 | ctx->PolygonCount = 0; |
| 166 | ctx->PolygonTime = 0.0; |
| 167 | ctx->ClearCount = 0; |
| 168 | ctx->ClearTime = 0.0; |
| 169 | ctx->SwapCount = 0; |
| 170 | ctx->SwapTime = 0.0; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | /* |
| 175 | * Print the accumulated timing/profiling data. |
| 176 | */ |
| 177 | static void print_timings( GLcontext *ctx ) |
| 178 | { |
| 179 | GLdouble beginendrate; |
| 180 | GLdouble vertexrate; |
| 181 | GLdouble pointrate; |
| 182 | GLdouble linerate; |
| 183 | GLdouble polygonrate; |
| 184 | GLdouble overhead; |
| 185 | GLdouble clearrate; |
| 186 | GLdouble swaprate; |
| 187 | GLdouble avgvertices; |
| 188 | |
| 189 | if (ctx->BeginEndTime>0.0) { |
| 190 | beginendrate = ctx->BeginEndCount / ctx->BeginEndTime; |
| 191 | } |
| 192 | else { |
| 193 | beginendrate = 0.0; |
| 194 | } |
| 195 | if (ctx->VertexTime>0.0) { |
| 196 | vertexrate = ctx->VertexCount / ctx->VertexTime; |
| 197 | } |
| 198 | else { |
| 199 | vertexrate = 0.0; |
| 200 | } |
| 201 | if (ctx->PointTime>0.0) { |
| 202 | pointrate = ctx->PointCount / ctx->PointTime; |
| 203 | } |
| 204 | else { |
| 205 | pointrate = 0.0; |
| 206 | } |
| 207 | if (ctx->LineTime>0.0) { |
| 208 | linerate = ctx->LineCount / ctx->LineTime; |
| 209 | } |
| 210 | else { |
| 211 | linerate = 0.0; |
| 212 | } |
| 213 | if (ctx->PolygonTime>0.0) { |
| 214 | polygonrate = ctx->PolygonCount / ctx->PolygonTime; |
| 215 | } |
| 216 | else { |
| 217 | polygonrate = 0.0; |
| 218 | } |
| 219 | if (ctx->ClearTime>0.0) { |
| 220 | clearrate = ctx->ClearCount / ctx->ClearTime; |
| 221 | } |
| 222 | else { |
| 223 | clearrate = 0.0; |
| 224 | } |
| 225 | if (ctx->SwapTime>0.0) { |
| 226 | swaprate = ctx->SwapCount / ctx->SwapTime; |
| 227 | } |
| 228 | else { |
| 229 | swaprate = 0.0; |
| 230 | } |
| 231 | |
| 232 | if (ctx->BeginEndCount>0) { |
| 233 | avgvertices = (GLdouble) ctx->VertexCount / (GLdouble) ctx->BeginEndCount; |
| 234 | } |
| 235 | else { |
| 236 | avgvertices = 0.0; |
| 237 | } |
| 238 | |
| 239 | overhead = ctx->BeginEndTime - ctx->VertexTime - ctx->PointTime |
| 240 | - ctx->LineTime - ctx->PolygonTime; |
| 241 | |
| 242 | |
| 243 | printf(" Count Time (s) Rate (/s) \n"); |
| 244 | printf("--------------------------------------------------------\n"); |
| 245 | printf("glBegin/glEnd %7d %8.3f %10.3f\n", |
| 246 | ctx->BeginEndCount, ctx->BeginEndTime, beginendrate); |
| 247 | printf(" vertexes transformed %7d %8.3f %10.3f\n", |
| 248 | ctx->VertexCount, ctx->VertexTime, vertexrate ); |
| 249 | printf(" points rasterized %7d %8.3f %10.3f\n", |
| 250 | ctx->PointCount, ctx->PointTime, pointrate ); |
| 251 | printf(" lines rasterized %7d %8.3f %10.3f\n", |
| 252 | ctx->LineCount, ctx->LineTime, linerate ); |
| 253 | printf(" polygons rasterized %7d %8.3f %10.3f\n", |
| 254 | ctx->PolygonCount, ctx->PolygonTime, polygonrate ); |
| 255 | printf(" overhead %8.3f\n", overhead ); |
| 256 | printf("glClear %7d %8.3f %10.3f\n", |
| 257 | ctx->ClearCount, ctx->ClearTime, clearrate ); |
| 258 | printf("SwapBuffers %7d %8.3f %10.3f\n", |
| 259 | ctx->SwapCount, ctx->SwapTime, swaprate ); |
| 260 | printf("\n"); |
| 261 | |
| 262 | printf("Average number of vertices per begin/end: %8.3f\n", avgvertices ); |
| 263 | } |
| 264 | #endif |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | /**********************************************************************/ |
| 271 | /***** Context allocation, initialization, destroying *****/ |
| 272 | /**********************************************************************/ |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | * This function just calls all the various one-time-init functions in Mesa. |
| 277 | */ |
| 278 | static void one_time_init( void ) |
| 279 | { |
| 280 | static GLboolean alreadyCalled = GL_FALSE; |
| 281 | if (!alreadyCalled) { |
| 282 | gl_init_clip(); |
| 283 | gl_init_eval(); |
| 284 | gl_init_fog(); |
| 285 | gl_init_math(); |
| 286 | gl_init_lists(); |
| 287 | gl_init_shade(); |
| 288 | gl_init_texture(); |
| 289 | gl_init_transformation(); |
| 290 | gl_init_translate(); |
| 291 | gl_init_vbrender(); |
| 292 | gl_init_vbxform(); |
| Keith Whitwell | 3875679 | 1999-08-29 10:26:31 +0000 | [diff] [blame] | 293 | gl_init_vertices(); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 294 | alreadyCalled = GL_TRUE; |
| 295 | } |
| 296 | #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__) |
| 297 | fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__); |
| 298 | #endif |
| 299 | } |
| 300 | |
| 301 | |
| 302 | /* |
| 303 | * Allocate and initialize a shared context state structure. |
| 304 | */ |
| 305 | static struct gl_shared_state *alloc_shared_state( void ) |
| 306 | { |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 307 | GLuint d; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 308 | struct gl_shared_state *ss; |
| 309 | GLboolean outOfMemory; |
| 310 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 311 | ss = CALLOC_STRUCT(gl_shared_state); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 312 | if (!ss) |
| 313 | return NULL; |
| 314 | |
| 315 | ss->DisplayList = NewHashTable(); |
| 316 | |
| 317 | ss->TexObjects = NewHashTable(); |
| 318 | |
| 319 | /* Default Texture objects */ |
| 320 | outOfMemory = GL_FALSE; |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 321 | for (d = 1 ; d <= 3 ; d++) { |
| 322 | ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d); |
| 323 | if (!ss->DefaultD[d]) { |
| 324 | outOfMemory = GL_TRUE; |
| 325 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 326 | } |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 327 | ss->DefaultD[d]->RefCount++; /* don't free if not in use */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | if (!ss->DisplayList || !ss->TexObjects || outOfMemory) { |
| 331 | /* Ran out of memory at some point. Free everything and return NULL */ |
| 332 | if (ss->DisplayList) |
| 333 | DeleteHashTable(ss->DisplayList); |
| 334 | if (ss->TexObjects) |
| 335 | DeleteHashTable(ss->TexObjects); |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 336 | if (ss->DefaultD[1]) |
| 337 | gl_free_texture_object(ss, ss->DefaultD[1]); |
| 338 | if (ss->DefaultD[2]) |
| 339 | gl_free_texture_object(ss, ss->DefaultD[2]); |
| 340 | if (ss->DefaultD[3]) |
| 341 | gl_free_texture_object(ss, ss->DefaultD[3]); |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 342 | FREE(ss); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 343 | return NULL; |
| 344 | } |
| 345 | else { |
| 346 | return ss; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | |
| 351 | /* |
| 352 | * Deallocate a shared state context and all children structures. |
| 353 | */ |
| 354 | static void free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) |
| 355 | { |
| 356 | /* Free display lists */ |
| 357 | while (1) { |
| 358 | GLuint list = HashFirstEntry(ss->DisplayList); |
| 359 | if (list) { |
| 360 | gl_destroy_list(ctx, list); |
| 361 | } |
| 362 | else { |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | DeleteHashTable(ss->DisplayList); |
| 367 | |
| 368 | /* Free texture objects */ |
| 369 | while (ss->TexObjectList) |
| 370 | { |
| 371 | if (ctx->Driver.DeleteTexture) |
| 372 | (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList ); |
| 373 | /* this function removes from linked list too! */ |
| 374 | gl_free_texture_object(ss, ss->TexObjectList); |
| 375 | } |
| 376 | DeleteHashTable(ss->TexObjects); |
| 377 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 378 | FREE(ss); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | /* |
| 387 | * Initialize the nth light. Note that the defaults for light 0 are |
| 388 | * different than the other lights. |
| 389 | */ |
| 390 | static void init_light( struct gl_light *l, GLuint n ) |
| 391 | { |
| 392 | make_empty_list( l ); |
| 393 | |
| 394 | ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 ); |
| 395 | if (n==0) { |
| 396 | ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 ); |
| 397 | ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 ); |
| 398 | } |
| 399 | else { |
| 400 | ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 ); |
| 401 | ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 ); |
| 402 | } |
| 403 | ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 ); |
| 404 | ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 ); |
| 405 | l->SpotExponent = 0.0; |
| 406 | gl_compute_spot_exp_table( l ); |
| 407 | l->SpotCutoff = 180.0; |
| 408 | l->CosCutoff = 0.0; /* KW: -ve values not admitted */ |
| 409 | l->ConstantAttenuation = 1.0; |
| 410 | l->LinearAttenuation = 0.0; |
| 411 | l->QuadraticAttenuation = 0.0; |
| 412 | l->Enabled = GL_FALSE; |
| 413 | } |
| 414 | |
| 415 | |
| 416 | |
| 417 | static void init_lightmodel( struct gl_lightmodel *lm ) |
| 418 | { |
| 419 | ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 ); |
| 420 | lm->LocalViewer = GL_FALSE; |
| 421 | lm->TwoSide = GL_FALSE; |
| 422 | lm->ColorControl = GL_SINGLE_COLOR; |
| 423 | } |
| 424 | |
| 425 | |
| 426 | static void init_material( struct gl_material *m ) |
| 427 | { |
| 428 | ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 ); |
| 429 | ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 ); |
| 430 | ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 ); |
| 431 | ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 ); |
| 432 | m->Shininess = 0.0; |
| 433 | m->AmbientIndex = 0; |
| 434 | m->DiffuseIndex = 1; |
| 435 | m->SpecularIndex = 1; |
| 436 | } |
| 437 | |
| 438 | |
| 439 | |
| 440 | static void init_texture_unit( GLcontext *ctx, GLuint unit ) |
| 441 | { |
| 442 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; |
| 443 | |
| 444 | texUnit->EnvMode = GL_MODULATE; |
| 445 | ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 ); |
| 446 | texUnit->TexGenEnabled = 0; |
| 447 | texUnit->GenModeS = GL_EYE_LINEAR; |
| 448 | texUnit->GenModeT = GL_EYE_LINEAR; |
| 449 | texUnit->GenModeR = GL_EYE_LINEAR; |
| 450 | texUnit->GenModeQ = GL_EYE_LINEAR; |
| 451 | /* Yes, these plane coefficients are correct! */ |
| 452 | ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 ); |
| 453 | ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 ); |
| 454 | ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 ); |
| 455 | ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 ); |
| 456 | ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 ); |
| 457 | ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 ); |
| 458 | ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 ); |
| 459 | ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 ); |
| 460 | |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 461 | texUnit->CurrentD[1] = ctx->Shared->DefaultD[1]; |
| 462 | texUnit->CurrentD[2] = ctx->Shared->DefaultD[2]; |
| 463 | texUnit->CurrentD[3] = ctx->Shared->DefaultD[3]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | |
| 467 | static void init_fallback_arrays( GLcontext *ctx ) |
| 468 | { |
| 469 | struct gl_client_array *cl; |
| 470 | GLuint i; |
| 471 | |
| 472 | cl = &ctx->Fallback.Normal; |
| 473 | cl->Size = 3; |
| 474 | cl->Type = GL_FLOAT; |
| 475 | cl->Stride = 0; |
| 476 | cl->StrideB = 0; |
| 477 | cl->Ptr = (void *) ctx->Current.Normal; |
| 478 | cl->Enabled = 1; |
| 479 | |
| 480 | cl = &ctx->Fallback.Color; |
| 481 | cl->Size = 4; |
| 482 | cl->Type = GL_UNSIGNED_BYTE; |
| 483 | cl->Stride = 0; |
| 484 | cl->StrideB = 0; |
| 485 | cl->Ptr = (void *) ctx->Current.ByteColor; |
| 486 | cl->Enabled = 1; |
| 487 | |
| 488 | cl = &ctx->Fallback.Index; |
| 489 | cl->Size = 1; |
| 490 | cl->Type = GL_UNSIGNED_INT; |
| 491 | cl->Stride = 0; |
| 492 | cl->StrideB = 0; |
| 493 | cl->Ptr = (void *) &ctx->Current.Index; |
| 494 | cl->Enabled = 1; |
| 495 | |
| 496 | for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) { |
| 497 | cl = &ctx->Fallback.TexCoord[i]; |
| 498 | cl->Size = 4; |
| 499 | cl->Type = GL_FLOAT; |
| 500 | cl->Stride = 0; |
| 501 | cl->StrideB = 0; |
| 502 | cl->Ptr = (void *) ctx->Current.Texcoord[i]; |
| 503 | cl->Enabled = 1; |
| 504 | } |
| 505 | |
| 506 | cl = &ctx->Fallback.EdgeFlag; |
| 507 | cl->Size = 1; |
| 508 | cl->Type = GL_UNSIGNED_BYTE; |
| 509 | cl->Stride = 0; |
| 510 | cl->StrideB = 0; |
| 511 | cl->Ptr = (void *) &ctx->Current.EdgeFlag; |
| 512 | cl->Enabled = 1; |
| 513 | } |
| 514 | |
| 515 | /* Initialize a 1-D evaluator map */ |
| 516 | static void init_1d_map( struct gl_1d_map *map, int n, const float *initial ) |
| 517 | { |
| 518 | map->Order = 1; |
| 519 | map->u1 = 0.0; |
| 520 | map->u2 = 1.0; |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 521 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat)); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 522 | if (map->Points) { |
| 523 | GLint i; |
| 524 | for (i=0;i<n;i++) |
| 525 | map->Points[i] = initial[i]; |
| 526 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | |
| 530 | /* Initialize a 2-D evaluator map */ |
| 531 | static void init_2d_map( struct gl_2d_map *map, int n, const float *initial ) |
| 532 | { |
| 533 | map->Uorder = 1; |
| 534 | map->Vorder = 1; |
| 535 | map->u1 = 0.0; |
| 536 | map->u2 = 1.0; |
| 537 | map->v1 = 0.0; |
| 538 | map->v2 = 1.0; |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 539 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat)); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 540 | if (map->Points) { |
| 541 | GLint i; |
| 542 | for (i=0;i<n;i++) |
| 543 | map->Points[i] = initial[i]; |
| 544 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | |
| Brian Paul | f0dee65 | 1999-11-19 22:51:29 +0000 | [diff] [blame] | 548 | static void init_color_table( struct gl_color_table *p ) |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 549 | { |
| 550 | p->Table[0] = 255; |
| 551 | p->Table[1] = 255; |
| 552 | p->Table[2] = 255; |
| 553 | p->Table[3] = 255; |
| 554 | p->Size = 1; |
| 555 | p->IntFormat = GL_RGBA; |
| 556 | p->Format = GL_RGBA; |
| 557 | } |
| 558 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 559 | |
| 560 | /* |
| 561 | * Initialize a gl_context structure to default values. |
| 562 | */ |
| 563 | static void initialize_context( GLcontext *ctx ) |
| 564 | { |
| 565 | GLuint i, j; |
| 566 | |
| 567 | if (ctx) { |
| 568 | /* Constants, may be overriden by device driver */ |
| 569 | ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS; |
| 570 | ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1); |
| 571 | ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS; |
| 572 | ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE; |
| 573 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 574 | /* Modelview matrix */ |
| 575 | gl_matrix_ctr( &ctx->ModelView ); |
| 576 | gl_matrix_alloc_inv( &ctx->ModelView ); |
| 577 | |
| 578 | ctx->ModelViewStackDepth = 0; |
| 579 | for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) { |
| 580 | gl_matrix_ctr( &ctx->ModelViewStack[i] ); |
| 581 | gl_matrix_alloc_inv( &ctx->ModelViewStack[i] ); |
| 582 | } |
| 583 | |
| 584 | /* Projection matrix - need inv for user clipping in clip space*/ |
| 585 | gl_matrix_ctr( &ctx->ProjectionMatrix ); |
| 586 | gl_matrix_alloc_inv( &ctx->ProjectionMatrix ); |
| 587 | |
| 588 | gl_matrix_ctr( &ctx->ModelProjectMatrix ); |
| 589 | gl_matrix_ctr( &ctx->ModelProjectWinMatrix ); |
| 590 | ctx->ModelProjectWinMatrixUptodate = GL_FALSE; |
| 591 | |
| 592 | ctx->ProjectionStackDepth = 0; |
| 593 | ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */ |
| 594 | ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */ |
| 595 | |
| 596 | for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) { |
| 597 | gl_matrix_ctr( &ctx->ProjectionStack[i] ); |
| 598 | gl_matrix_alloc_inv( &ctx->ProjectionStack[i] ); |
| 599 | } |
| 600 | |
| 601 | /* Texture matrix */ |
| 602 | for (i=0; i<MAX_TEXTURE_UNITS; i++) { |
| 603 | gl_matrix_ctr( &ctx->TextureMatrix[i] ); |
| 604 | ctx->TextureStackDepth[i] = 0; |
| 605 | for (j = 0 ; j < MAX_TEXTURE_STACK_DEPTH ; j++) { |
| 606 | ctx->TextureStack[i][j].inv = 0; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | /* Accumulate buffer group */ |
| 611 | ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 ); |
| 612 | |
| 613 | /* Color buffer group */ |
| 614 | ctx->Color.IndexMask = 0xffffffff; |
| 615 | ctx->Color.ColorMask[0] = 0xff; |
| 616 | ctx->Color.ColorMask[1] = 0xff; |
| 617 | ctx->Color.ColorMask[2] = 0xff; |
| 618 | ctx->Color.ColorMask[3] = 0xff; |
| 619 | ctx->Color.SWmasking = GL_FALSE; |
| 620 | ctx->Color.ClearIndex = 0; |
| 621 | ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 ); |
| 622 | ctx->Color.DrawBuffer = GL_FRONT; |
| 623 | ctx->Color.AlphaEnabled = GL_FALSE; |
| 624 | ctx->Color.AlphaFunc = GL_ALWAYS; |
| 625 | ctx->Color.AlphaRef = 0; |
| 626 | ctx->Color.BlendEnabled = GL_FALSE; |
| 627 | ctx->Color.BlendSrcRGB = GL_ONE; |
| 628 | ctx->Color.BlendDstRGB = GL_ZERO; |
| 629 | ctx->Color.BlendSrcA = GL_ONE; |
| 630 | ctx->Color.BlendDstA = GL_ZERO; |
| 631 | ctx->Color.BlendEquation = GL_FUNC_ADD_EXT; |
| 632 | ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */ |
| 633 | ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 ); |
| 634 | ctx->Color.IndexLogicOpEnabled = GL_FALSE; |
| 635 | ctx->Color.ColorLogicOpEnabled = GL_FALSE; |
| 636 | ctx->Color.SWLogicOpEnabled = GL_FALSE; |
| 637 | ctx->Color.LogicOp = GL_COPY; |
| 638 | ctx->Color.DitherFlag = GL_TRUE; |
| 639 | ctx->Color.MultiDrawBuffer = GL_FALSE; |
| 640 | |
| 641 | /* Current group */ |
| 642 | ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255); |
| 643 | ctx->Current.Index = 1; |
| 644 | for (i=0; i<MAX_TEXTURE_UNITS; i++) |
| 645 | ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 ); |
| 646 | ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 ); |
| 647 | ctx->Current.RasterDistance = 0.0; |
| 648 | ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 ); |
| 649 | ctx->Current.RasterIndex = 1; |
| 650 | for (i=0; i<MAX_TEXTURE_UNITS; i++) |
| 651 | ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 ); |
| 652 | ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0]; |
| 653 | ctx->Current.RasterPosValid = GL_TRUE; |
| 654 | ctx->Current.EdgeFlag = GL_TRUE; |
| 655 | ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 ); |
| 656 | ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1); |
| 657 | |
| 658 | ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE| |
| 659 | VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL); |
| 660 | |
| 661 | init_fallback_arrays( ctx ); |
| 662 | |
| 663 | /* Depth buffer group */ |
| 664 | ctx->Depth.Test = GL_FALSE; |
| 665 | ctx->Depth.Clear = 1.0; |
| 666 | ctx->Depth.Func = GL_LESS; |
| 667 | ctx->Depth.Mask = GL_TRUE; |
| 668 | |
| 669 | /* Evaluators group */ |
| 670 | ctx->Eval.Map1Color4 = GL_FALSE; |
| 671 | ctx->Eval.Map1Index = GL_FALSE; |
| 672 | ctx->Eval.Map1Normal = GL_FALSE; |
| 673 | ctx->Eval.Map1TextureCoord1 = GL_FALSE; |
| 674 | ctx->Eval.Map1TextureCoord2 = GL_FALSE; |
| 675 | ctx->Eval.Map1TextureCoord3 = GL_FALSE; |
| 676 | ctx->Eval.Map1TextureCoord4 = GL_FALSE; |
| 677 | ctx->Eval.Map1Vertex3 = GL_FALSE; |
| 678 | ctx->Eval.Map1Vertex4 = GL_FALSE; |
| 679 | ctx->Eval.Map2Color4 = GL_FALSE; |
| 680 | ctx->Eval.Map2Index = GL_FALSE; |
| 681 | ctx->Eval.Map2Normal = GL_FALSE; |
| 682 | ctx->Eval.Map2TextureCoord1 = GL_FALSE; |
| 683 | ctx->Eval.Map2TextureCoord2 = GL_FALSE; |
| 684 | ctx->Eval.Map2TextureCoord3 = GL_FALSE; |
| 685 | ctx->Eval.Map2TextureCoord4 = GL_FALSE; |
| 686 | ctx->Eval.Map2Vertex3 = GL_FALSE; |
| 687 | ctx->Eval.Map2Vertex4 = GL_FALSE; |
| 688 | ctx->Eval.AutoNormal = GL_FALSE; |
| 689 | ctx->Eval.MapGrid1un = 1; |
| 690 | ctx->Eval.MapGrid1u1 = 0.0; |
| 691 | ctx->Eval.MapGrid1u2 = 1.0; |
| 692 | ctx->Eval.MapGrid2un = 1; |
| 693 | ctx->Eval.MapGrid2vn = 1; |
| 694 | ctx->Eval.MapGrid2u1 = 0.0; |
| 695 | ctx->Eval.MapGrid2u2 = 1.0; |
| 696 | ctx->Eval.MapGrid2v1 = 0.0; |
| 697 | ctx->Eval.MapGrid2v2 = 1.0; |
| 698 | |
| 699 | /* Evaluator data */ |
| 700 | { |
| 701 | static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 }; |
| 702 | static GLfloat normal[3] = { 0.0, 0.0, 1.0 }; |
| 703 | static GLfloat index[1] = { 1.0 }; |
| 704 | static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 705 | static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 }; |
| 706 | |
| 707 | init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex ); |
| 708 | init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex ); |
| 709 | init_1d_map( &ctx->EvalMap.Map1Index, 1, index ); |
| 710 | init_1d_map( &ctx->EvalMap.Map1Color4, 4, color ); |
| 711 | init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal ); |
| 712 | init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord ); |
| 713 | init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord ); |
| 714 | init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord ); |
| 715 | init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord ); |
| 716 | |
| 717 | init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex ); |
| 718 | init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex ); |
| 719 | init_2d_map( &ctx->EvalMap.Map2Index, 1, index ); |
| 720 | init_2d_map( &ctx->EvalMap.Map2Color4, 4, color ); |
| 721 | init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal ); |
| 722 | init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord ); |
| 723 | init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord ); |
| 724 | init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord ); |
| 725 | init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord ); |
| 726 | } |
| 727 | |
| 728 | /* Fog group */ |
| 729 | ctx->Fog.Enabled = GL_FALSE; |
| 730 | ctx->Fog.Mode = GL_EXP; |
| 731 | ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 ); |
| 732 | ctx->Fog.Index = 0.0; |
| 733 | ctx->Fog.Density = 1.0; |
| 734 | ctx->Fog.Start = 0.0; |
| 735 | ctx->Fog.End = 1.0; |
| 736 | |
| 737 | /* Hint group */ |
| 738 | ctx->Hint.PerspectiveCorrection = GL_DONT_CARE; |
| 739 | ctx->Hint.PointSmooth = GL_DONT_CARE; |
| 740 | ctx->Hint.LineSmooth = GL_DONT_CARE; |
| 741 | ctx->Hint.PolygonSmooth = GL_DONT_CARE; |
| 742 | ctx->Hint.Fog = GL_DONT_CARE; |
| 743 | |
| 744 | ctx->Hint.AllowDrawWin = GL_TRUE; |
| 745 | ctx->Hint.AllowDrawSpn = GL_TRUE; |
| 746 | ctx->Hint.AllowDrawMem = GL_TRUE; |
| 747 | ctx->Hint.StrictLighting = GL_TRUE; |
| 748 | |
| 749 | /* Pipeline */ |
| 750 | gl_pipeline_init( ctx ); |
| 751 | gl_cva_init( ctx ); |
| 752 | |
| 753 | /* Extensions */ |
| 754 | gl_extensions_ctr( ctx ); |
| 755 | |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 756 | ctx->AllowVertexCull = CLIP_CULLED_BIT; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 757 | |
| 758 | /* Lighting group */ |
| 759 | for (i=0;i<MAX_LIGHTS;i++) { |
| 760 | init_light( &ctx->Light.Light[i], i ); |
| 761 | } |
| 762 | make_empty_list( &ctx->Light.EnabledList ); |
| 763 | |
| 764 | init_lightmodel( &ctx->Light.Model ); |
| 765 | init_material( &ctx->Light.Material[0] ); |
| 766 | init_material( &ctx->Light.Material[1] ); |
| 767 | ctx->Light.ShadeModel = GL_SMOOTH; |
| 768 | ctx->Light.Enabled = GL_FALSE; |
| 769 | ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK; |
| 770 | ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE; |
| 771 | ctx->Light.ColorMaterialBitmask |
| 772 | = gl_material_bitmask( ctx, |
| 773 | GL_FRONT_AND_BACK, |
| 774 | GL_AMBIENT_AND_DIFFUSE, ~0, 0 ); |
| 775 | |
| 776 | ctx->Light.ColorMaterialEnabled = GL_FALSE; |
| 777 | |
| 778 | /* Line group */ |
| 779 | ctx->Line.SmoothFlag = GL_FALSE; |
| 780 | ctx->Line.StippleFlag = GL_FALSE; |
| 781 | ctx->Line.Width = 1.0; |
| 782 | ctx->Line.StipplePattern = 0xffff; |
| 783 | ctx->Line.StippleFactor = 1; |
| 784 | |
| 785 | /* Display List group */ |
| 786 | ctx->List.ListBase = 0; |
| 787 | |
| 788 | /* Pixel group */ |
| 789 | ctx->Pixel.RedBias = 0.0; |
| 790 | ctx->Pixel.RedScale = 1.0; |
| 791 | ctx->Pixel.GreenBias = 0.0; |
| 792 | ctx->Pixel.GreenScale = 1.0; |
| 793 | ctx->Pixel.BlueBias = 0.0; |
| 794 | ctx->Pixel.BlueScale = 1.0; |
| 795 | ctx->Pixel.AlphaBias = 0.0; |
| 796 | ctx->Pixel.AlphaScale = 1.0; |
| 797 | ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE; |
| 798 | ctx->Pixel.DepthBias = 0.0; |
| 799 | ctx->Pixel.DepthScale = 1.0; |
| 800 | ctx->Pixel.IndexOffset = 0; |
| 801 | ctx->Pixel.IndexShift = 0; |
| 802 | ctx->Pixel.ZoomX = 1.0; |
| 803 | ctx->Pixel.ZoomY = 1.0; |
| 804 | ctx->Pixel.MapColorFlag = GL_FALSE; |
| 805 | ctx->Pixel.MapStencilFlag = GL_FALSE; |
| 806 | ctx->Pixel.MapStoSsize = 1; |
| 807 | ctx->Pixel.MapItoIsize = 1; |
| 808 | ctx->Pixel.MapItoRsize = 1; |
| 809 | ctx->Pixel.MapItoGsize = 1; |
| 810 | ctx->Pixel.MapItoBsize = 1; |
| 811 | ctx->Pixel.MapItoAsize = 1; |
| 812 | ctx->Pixel.MapRtoRsize = 1; |
| 813 | ctx->Pixel.MapGtoGsize = 1; |
| 814 | ctx->Pixel.MapBtoBsize = 1; |
| 815 | ctx->Pixel.MapAtoAsize = 1; |
| 816 | ctx->Pixel.MapStoS[0] = 0; |
| 817 | ctx->Pixel.MapItoI[0] = 0; |
| 818 | ctx->Pixel.MapItoR[0] = 0.0; |
| 819 | ctx->Pixel.MapItoG[0] = 0.0; |
| 820 | ctx->Pixel.MapItoB[0] = 0.0; |
| 821 | ctx->Pixel.MapItoA[0] = 0.0; |
| 822 | ctx->Pixel.MapItoR8[0] = 0; |
| 823 | ctx->Pixel.MapItoG8[0] = 0; |
| 824 | ctx->Pixel.MapItoB8[0] = 0; |
| 825 | ctx->Pixel.MapItoA8[0] = 0; |
| 826 | ctx->Pixel.MapRtoR[0] = 0.0; |
| 827 | ctx->Pixel.MapGtoG[0] = 0.0; |
| 828 | ctx->Pixel.MapBtoB[0] = 0.0; |
| 829 | ctx->Pixel.MapAtoA[0] = 0.0; |
| 830 | |
| 831 | /* Point group */ |
| 832 | ctx->Point.SmoothFlag = GL_FALSE; |
| 833 | ctx->Point.Size = 1.0; |
| 834 | ctx->Point.Params[0] = 1.0; |
| 835 | ctx->Point.Params[1] = 0.0; |
| 836 | ctx->Point.Params[2] = 0.0; |
| 837 | ctx->Point.Attenuated = GL_FALSE; |
| 838 | ctx->Point.MinSize = 0.0; |
| 839 | ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE; |
| 840 | ctx->Point.Threshold = 1.0; |
| 841 | |
| 842 | /* Polygon group */ |
| 843 | ctx->Polygon.CullFlag = GL_FALSE; |
| 844 | ctx->Polygon.CullFaceMode = GL_BACK; |
| 845 | ctx->Polygon.FrontFace = GL_CCW; |
| 846 | ctx->Polygon.FrontBit = 0; |
| 847 | ctx->Polygon.FrontMode = GL_FILL; |
| 848 | ctx->Polygon.BackMode = GL_FILL; |
| 849 | ctx->Polygon.Unfilled = GL_FALSE; |
| 850 | ctx->Polygon.SmoothFlag = GL_FALSE; |
| 851 | ctx->Polygon.StippleFlag = GL_FALSE; |
| 852 | ctx->Polygon.OffsetFactor = 0.0F; |
| 853 | ctx->Polygon.OffsetUnits = 0.0F; |
| 854 | ctx->Polygon.OffsetPoint = GL_FALSE; |
| 855 | ctx->Polygon.OffsetLine = GL_FALSE; |
| 856 | ctx->Polygon.OffsetFill = GL_FALSE; |
| 857 | |
| 858 | /* Polygon Stipple group */ |
| 859 | MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) ); |
| 860 | |
| 861 | /* Scissor group */ |
| 862 | ctx->Scissor.Enabled = GL_FALSE; |
| 863 | ctx->Scissor.X = 0; |
| 864 | ctx->Scissor.Y = 0; |
| 865 | ctx->Scissor.Width = 0; |
| 866 | ctx->Scissor.Height = 0; |
| 867 | |
| 868 | /* Stencil group */ |
| 869 | ctx->Stencil.Enabled = GL_FALSE; |
| 870 | ctx->Stencil.Function = GL_ALWAYS; |
| 871 | ctx->Stencil.FailFunc = GL_KEEP; |
| 872 | ctx->Stencil.ZPassFunc = GL_KEEP; |
| 873 | ctx->Stencil.ZFailFunc = GL_KEEP; |
| 874 | ctx->Stencil.Ref = 0; |
| Brian Paul | c63a869 | 1999-12-04 21:23:17 +0000 | [diff] [blame] | 875 | ctx->Stencil.ValueMask = STENCIL_MAX; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 876 | ctx->Stencil.Clear = 0; |
| Brian Paul | c63a869 | 1999-12-04 21:23:17 +0000 | [diff] [blame] | 877 | ctx->Stencil.WriteMask = STENCIL_MAX; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 878 | |
| 879 | /* Texture group */ |
| 880 | ctx->Texture.CurrentUnit = 0; /* multitexture */ |
| 881 | ctx->Texture.CurrentTransformUnit = 0; /* multitexture */ |
| 882 | ctx->Texture.Enabled = 0; |
| 883 | |
| 884 | for (i=0; i<MAX_TEXTURE_UNITS; i++) |
| 885 | init_texture_unit( ctx, i ); |
| 886 | |
| Brian Paul | f0dee65 | 1999-11-19 22:51:29 +0000 | [diff] [blame] | 887 | init_color_table(&ctx->Texture.Palette); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 888 | |
| 889 | /* Transformation group */ |
| 890 | ctx->Transform.MatrixMode = GL_MODELVIEW; |
| 891 | ctx->Transform.Normalize = GL_FALSE; |
| 892 | ctx->Transform.RescaleNormals = GL_FALSE; |
| 893 | for (i=0;i<MAX_CLIP_PLANES;i++) { |
| 894 | ctx->Transform.ClipEnabled[i] = GL_FALSE; |
| 895 | ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 ); |
| 896 | } |
| 897 | ctx->Transform.AnyClip = GL_FALSE; |
| 898 | |
| 899 | /* Viewport group */ |
| 900 | ctx->Viewport.X = 0; |
| 901 | ctx->Viewport.Y = 0; |
| 902 | ctx->Viewport.Width = 0; |
| 903 | ctx->Viewport.Height = 0; |
| 904 | ctx->Viewport.Near = 0.0; |
| 905 | ctx->Viewport.Far = 1.0; |
| 906 | gl_matrix_ctr(&ctx->Viewport.WindowMap); |
| 907 | |
| 908 | #define Sz 10 |
| 909 | #define Tz 14 |
| 910 | ctx->Viewport.WindowMap.m[Sz] = 0.5 * DEPTH_SCALE; |
| 911 | ctx->Viewport.WindowMap.m[Tz] = 0.5 * DEPTH_SCALE; |
| 912 | #undef Sz |
| 913 | #undef Tz |
| 914 | |
| 915 | ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION; |
| 916 | ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT; |
| 917 | |
| 918 | /* Vertex arrays */ |
| 919 | ctx->Array.Vertex.Size = 4; |
| 920 | ctx->Array.Vertex.Type = GL_FLOAT; |
| 921 | ctx->Array.Vertex.Stride = 0; |
| 922 | ctx->Array.Vertex.StrideB = 0; |
| 923 | ctx->Array.Vertex.Ptr = NULL; |
| 924 | ctx->Array.Vertex.Enabled = GL_FALSE; |
| 925 | ctx->Array.Normal.Type = GL_FLOAT; |
| 926 | ctx->Array.Normal.Stride = 0; |
| 927 | ctx->Array.Normal.StrideB = 0; |
| 928 | ctx->Array.Normal.Ptr = NULL; |
| 929 | ctx->Array.Normal.Enabled = GL_FALSE; |
| 930 | ctx->Array.Color.Size = 4; |
| 931 | ctx->Array.Color.Type = GL_FLOAT; |
| 932 | ctx->Array.Color.Stride = 0; |
| 933 | ctx->Array.Color.StrideB = 0; |
| 934 | ctx->Array.Color.Ptr = NULL; |
| 935 | ctx->Array.Color.Enabled = GL_FALSE; |
| 936 | ctx->Array.Index.Type = GL_FLOAT; |
| 937 | ctx->Array.Index.Stride = 0; |
| 938 | ctx->Array.Index.StrideB = 0; |
| 939 | ctx->Array.Index.Ptr = NULL; |
| 940 | ctx->Array.Index.Enabled = GL_FALSE; |
| 941 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) { |
| 942 | ctx->Array.TexCoord[i].Size = 4; |
| 943 | ctx->Array.TexCoord[i].Type = GL_FLOAT; |
| 944 | ctx->Array.TexCoord[i].Stride = 0; |
| 945 | ctx->Array.TexCoord[i].StrideB = 0; |
| 946 | ctx->Array.TexCoord[i].Ptr = NULL; |
| 947 | ctx->Array.TexCoord[i].Enabled = GL_FALSE; |
| 948 | } |
| 949 | ctx->Array.TexCoordInterleaveFactor = 1; |
| 950 | ctx->Array.EdgeFlag.Stride = 0; |
| 951 | ctx->Array.EdgeFlag.StrideB = 0; |
| 952 | ctx->Array.EdgeFlag.Ptr = NULL; |
| 953 | ctx->Array.EdgeFlag.Enabled = GL_FALSE; |
| 954 | ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ |
| 955 | |
| 956 | /* Pixel transfer */ |
| 957 | ctx->Pack.Alignment = 4; |
| 958 | ctx->Pack.RowLength = 0; |
| Brian Paul | 12cc2bf | 1999-10-30 08:22:45 +0000 | [diff] [blame] | 959 | ctx->Pack.ImageHeight = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 960 | ctx->Pack.SkipPixels = 0; |
| 961 | ctx->Pack.SkipRows = 0; |
| Brian Paul | 12cc2bf | 1999-10-30 08:22:45 +0000 | [diff] [blame] | 962 | ctx->Pack.SkipImages = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 963 | ctx->Pack.SwapBytes = GL_FALSE; |
| 964 | ctx->Pack.LsbFirst = GL_FALSE; |
| 965 | ctx->Unpack.Alignment = 4; |
| 966 | ctx->Unpack.RowLength = 0; |
| Brian Paul | 12cc2bf | 1999-10-30 08:22:45 +0000 | [diff] [blame] | 967 | ctx->Unpack.ImageHeight = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 968 | ctx->Unpack.SkipPixels = 0; |
| 969 | ctx->Unpack.SkipRows = 0; |
| Brian Paul | 12cc2bf | 1999-10-30 08:22:45 +0000 | [diff] [blame] | 970 | ctx->Unpack.SkipImages = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 971 | ctx->Unpack.SwapBytes = GL_FALSE; |
| 972 | ctx->Unpack.LsbFirst = GL_FALSE; |
| 973 | |
| 974 | /* Feedback */ |
| 975 | ctx->Feedback.Type = GL_2D; /* TODO: verify */ |
| 976 | ctx->Feedback.Buffer = NULL; |
| 977 | ctx->Feedback.BufferSize = 0; |
| 978 | ctx->Feedback.Count = 0; |
| 979 | |
| 980 | /* Selection/picking */ |
| 981 | ctx->Select.Buffer = NULL; |
| 982 | ctx->Select.BufferSize = 0; |
| 983 | ctx->Select.BufferCount = 0; |
| 984 | ctx->Select.Hits = 0; |
| 985 | ctx->Select.NameStackDepth = 0; |
| 986 | |
| 987 | /* Optimized Accum buffer */ |
| 988 | ctx->IntegerAccumMode = GL_TRUE; |
| 989 | ctx->IntegerAccumScaler = 0.0; |
| 990 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 991 | /* Renderer and client attribute stacks */ |
| 992 | ctx->AttribStackDepth = 0; |
| 993 | ctx->ClientAttribStackDepth = 0; |
| 994 | |
| 995 | /*** Miscellaneous ***/ |
| 996 | ctx->NewState = NEW_ALL; |
| 997 | ctx->RenderMode = GL_RENDER; |
| 998 | ctx->StippleCounter = 0; |
| 999 | ctx->NeedNormals = GL_FALSE; |
| 1000 | ctx->DoViewportMapping = GL_TRUE; |
| 1001 | |
| 1002 | ctx->NeedEyeCoords = GL_FALSE; |
| 1003 | ctx->NeedEyeNormals = GL_FALSE; |
| 1004 | ctx->vb_proj_matrix = &ctx->ModelProjectMatrix; |
| 1005 | |
| 1006 | /* Display list */ |
| 1007 | ctx->CallDepth = 0; |
| 1008 | ctx->ExecuteFlag = GL_TRUE; |
| 1009 | ctx->CompileFlag = GL_FALSE; |
| 1010 | ctx->CurrentListPtr = NULL; |
| 1011 | ctx->CurrentBlock = NULL; |
| 1012 | ctx->CurrentListNum = 0; |
| 1013 | ctx->CurrentPos = 0; |
| 1014 | |
| 1015 | ctx->ErrorValue = (GLenum) GL_NO_ERROR; |
| 1016 | |
| 1017 | ctx->CatchSignals = GL_TRUE; |
| 1018 | |
| 1019 | /* For debug/development only */ |
| 1020 | ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE; |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 1021 | ctx->FirstTimeCurrent = GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1022 | |
| 1023 | /* Dither disable */ |
| 1024 | ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE; |
| 1025 | if (ctx->NoDither) { |
| 1026 | if (getenv("MESA_DEBUG")) { |
| 1027 | fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n"); |
| 1028 | } |
| 1029 | ctx->Color.DitherFlag = GL_FALSE; |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | /* |
| 1037 | * Allocate a new GLvisual object. |
| 1038 | * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode |
| 1039 | * alphaFlag - alloc software alpha buffers? |
| 1040 | * dbFlag - double buffering? |
| 1041 | * stereoFlag - stereo buffer? |
| 1042 | * depthFits - requested minimum bits per depth buffer value |
| 1043 | * stencilFits - requested minimum bits per stencil buffer value |
| 1044 | * accumFits - requested minimum bits per accum buffer component |
| 1045 | * indexFits - number of bits per pixel if rgbFlag==GL_FALSE |
| 1046 | * red/green/blue/alphaFits - number of bits per color component |
| 1047 | * in frame buffer for RGB(A) mode. |
| 1048 | * Return: pointer to new GLvisual or NULL if requested parameters can't |
| 1049 | * be met. |
| 1050 | */ |
| 1051 | GLvisual *gl_create_visual( GLboolean rgbFlag, |
| 1052 | GLboolean alphaFlag, |
| 1053 | GLboolean dbFlag, |
| 1054 | GLboolean stereoFlag, |
| 1055 | GLint depthBits, |
| 1056 | GLint stencilBits, |
| 1057 | GLint accumBits, |
| 1058 | GLint indexBits, |
| 1059 | GLint redBits, |
| 1060 | GLint greenBits, |
| 1061 | GLint blueBits, |
| 1062 | GLint alphaBits ) |
| 1063 | { |
| 1064 | GLvisual *vis; |
| 1065 | |
| 1066 | if (depthBits > (GLint) (8*sizeof(GLdepth))) { |
| 1067 | /* can't meet depth buffer requirements */ |
| 1068 | return NULL; |
| 1069 | } |
| 1070 | if (stencilBits > (GLint) (8*sizeof(GLstencil))) { |
| 1071 | /* can't meet stencil buffer requirements */ |
| 1072 | return NULL; |
| 1073 | } |
| 1074 | if (accumBits > (GLint) (8*sizeof(GLaccum))) { |
| 1075 | /* can't meet accum buffer requirements */ |
| 1076 | return NULL; |
| 1077 | } |
| 1078 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1079 | vis = (GLvisual *) CALLOC( sizeof(GLvisual) ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1080 | if (!vis) { |
| 1081 | return NULL; |
| 1082 | } |
| 1083 | |
| 1084 | vis->RGBAflag = rgbFlag; |
| 1085 | vis->DBflag = dbFlag; |
| 1086 | vis->StereoFlag = stereoFlag; |
| 1087 | vis->RedBits = redBits; |
| 1088 | vis->GreenBits = greenBits; |
| 1089 | vis->BlueBits = blueBits; |
| 1090 | vis->AlphaBits = alphaFlag ? 8*sizeof(GLubyte) : alphaBits; |
| 1091 | |
| 1092 | vis->IndexBits = indexBits; |
| 1093 | vis->DepthBits = (depthBits>0) ? 8*sizeof(GLdepth) : 0; |
| 1094 | vis->AccumBits = (accumBits>0) ? 8*sizeof(GLaccum) : 0; |
| 1095 | vis->StencilBits = (stencilBits>0) ? 8*sizeof(GLstencil) : 0; |
| 1096 | |
| 1097 | vis->SoftwareAlpha = alphaFlag; |
| 1098 | |
| 1099 | return vis; |
| 1100 | } |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | void gl_destroy_visual( GLvisual *vis ) |
| 1105 | { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1106 | FREE( vis ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | /* |
| 1112 | * Allocate the proxy textures. If we run out of memory part way through |
| 1113 | * the allocations clean up and return GL_FALSE. |
| 1114 | * Return: GL_TRUE=success, GL_FALSE=failure |
| 1115 | */ |
| 1116 | static GLboolean alloc_proxy_textures( GLcontext *ctx ) |
| 1117 | { |
| 1118 | GLboolean out_of_memory; |
| 1119 | GLint i; |
| 1120 | |
| 1121 | ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1); |
| 1122 | if (!ctx->Texture.Proxy1D) { |
| 1123 | return GL_FALSE; |
| 1124 | } |
| 1125 | |
| 1126 | ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2); |
| 1127 | if (!ctx->Texture.Proxy2D) { |
| 1128 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D); |
| 1129 | return GL_FALSE; |
| 1130 | } |
| 1131 | |
| 1132 | ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3); |
| 1133 | if (!ctx->Texture.Proxy3D) { |
| 1134 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D); |
| 1135 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D); |
| 1136 | return GL_FALSE; |
| 1137 | } |
| 1138 | |
| 1139 | out_of_memory = GL_FALSE; |
| 1140 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) { |
| 1141 | ctx->Texture.Proxy1D->Image[i] = gl_alloc_texture_image(); |
| 1142 | ctx->Texture.Proxy2D->Image[i] = gl_alloc_texture_image(); |
| 1143 | ctx->Texture.Proxy3D->Image[i] = gl_alloc_texture_image(); |
| 1144 | if (!ctx->Texture.Proxy1D->Image[i] |
| 1145 | || !ctx->Texture.Proxy2D->Image[i] |
| 1146 | || !ctx->Texture.Proxy3D->Image[i]) { |
| 1147 | out_of_memory = GL_TRUE; |
| 1148 | } |
| 1149 | } |
| 1150 | if (out_of_memory) { |
| 1151 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) { |
| 1152 | if (ctx->Texture.Proxy1D->Image[i]) { |
| 1153 | gl_free_texture_image(ctx->Texture.Proxy1D->Image[i]); |
| 1154 | } |
| 1155 | if (ctx->Texture.Proxy2D->Image[i]) { |
| 1156 | gl_free_texture_image(ctx->Texture.Proxy2D->Image[i]); |
| 1157 | } |
| 1158 | if (ctx->Texture.Proxy3D->Image[i]) { |
| 1159 | gl_free_texture_image(ctx->Texture.Proxy3D->Image[i]); |
| 1160 | } |
| 1161 | } |
| 1162 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D); |
| 1163 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D); |
| 1164 | gl_free_texture_object(NULL, ctx->Texture.Proxy3D); |
| 1165 | return GL_FALSE; |
| 1166 | } |
| 1167 | else { |
| 1168 | return GL_TRUE; |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | |
| 1173 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1174 | /* |
| 1175 | * Allocate and initialize a GLcontext structure. |
| 1176 | * Input: visual - a GLvisual pointer |
| 1177 | * sharelist - another context to share display lists with or NULL |
| 1178 | * driver_ctx - pointer to device driver's context state struct |
| 1179 | * Return: pointer to a new gl_context struct or NULL if error. |
| 1180 | */ |
| 1181 | GLcontext *gl_create_context( GLvisual *visual, |
| 1182 | GLcontext *share_list, |
| 1183 | void *driver_ctx, |
| 1184 | GLboolean direct ) |
| 1185 | { |
| 1186 | GLcontext *ctx; |
| 1187 | GLuint i; |
| 1188 | |
| 1189 | (void) direct; /* not used */ |
| 1190 | |
| 1191 | /* do some implementation tests */ |
| 1192 | assert( sizeof(GLbyte) == 1 ); |
| 1193 | assert( sizeof(GLshort) >= 2 ); |
| 1194 | assert( sizeof(GLint) >= 4 ); |
| 1195 | assert( sizeof(GLubyte) == 1 ); |
| 1196 | assert( sizeof(GLushort) >= 2 ); |
| 1197 | assert( sizeof(GLuint) >= 4 ); |
| 1198 | |
| 1199 | /* misc one-time initializations */ |
| 1200 | one_time_init(); |
| 1201 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1202 | ctx = (GLcontext *) CALLOC( sizeof(GLcontext) ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1203 | if (!ctx) { |
| 1204 | return NULL; |
| 1205 | } |
| 1206 | |
| 1207 | ctx->DriverCtx = driver_ctx; |
| 1208 | ctx->Visual = visual; |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1209 | ctx->DrawBuffer = NULL; |
| 1210 | ctx->ReadBuffer = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1211 | |
| 1212 | ctx->VB = gl_vb_create_for_immediate( ctx ); |
| 1213 | if (!ctx->VB) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1214 | FREE( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1215 | return NULL; |
| 1216 | } |
| 1217 | ctx->input = ctx->VB->IM; |
| 1218 | |
| 1219 | ctx->PB = gl_alloc_pb(); |
| 1220 | if (!ctx->PB) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1221 | FREE( ctx->VB ); |
| 1222 | FREE( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1223 | return NULL; |
| 1224 | } |
| 1225 | |
| 1226 | if (share_list) { |
| 1227 | /* share the group of display lists of another context */ |
| 1228 | ctx->Shared = share_list->Shared; |
| 1229 | } |
| 1230 | else { |
| 1231 | /* allocate new group of display lists */ |
| 1232 | ctx->Shared = alloc_shared_state(); |
| 1233 | if (!ctx->Shared) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1234 | FREE(ctx->VB); |
| 1235 | FREE(ctx->PB); |
| 1236 | FREE(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1237 | return NULL; |
| 1238 | } |
| 1239 | } |
| 1240 | ctx->Shared->RefCount++; |
| 1241 | |
| 1242 | initialize_context( ctx ); |
| 1243 | gl_reset_vb( ctx->VB ); |
| 1244 | gl_reset_input( ctx ); |
| 1245 | |
| 1246 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1247 | ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1248 | make_empty_list( ctx->ShineTabList ); |
| 1249 | |
| 1250 | for (i = 0 ; i < 10 ; i++) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1251 | struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1252 | s->shininess = -1; |
| 1253 | s->refcount = 0; |
| 1254 | insert_at_tail( ctx->ShineTabList, s ); |
| 1255 | } |
| 1256 | |
| 1257 | for (i = 0 ; i < 4 ; i++) { |
| 1258 | ctx->ShineTable[i] = ctx->ShineTabList->prev; |
| 1259 | ctx->ShineTable[i]->refcount++; |
| 1260 | } |
| 1261 | |
| 1262 | if (visual->DBflag) { |
| 1263 | ctx->Color.DrawBuffer = GL_BACK; |
| 1264 | ctx->Color.DriverDrawBuffer = GL_BACK_LEFT; |
| 1265 | ctx->Color.DrawDestMask = BACK_LEFT_BIT; |
| 1266 | ctx->Pixel.ReadBuffer = GL_BACK; |
| 1267 | ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT; |
| 1268 | } |
| 1269 | else { |
| 1270 | ctx->Color.DrawBuffer = GL_FRONT; |
| 1271 | ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT; |
| 1272 | ctx->Color.DrawDestMask = FRONT_LEFT_BIT; |
| 1273 | ctx->Pixel.ReadBuffer = GL_FRONT; |
| 1274 | ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT; |
| 1275 | } |
| 1276 | |
| Keith Whitwell | 324beb9 | 1999-09-04 14:40:49 +0000 | [diff] [blame] | 1277 | |
| 1278 | /* Fill in some driver defaults now. |
| 1279 | */ |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1280 | #if 0 |
| Keith Whitwell | 324beb9 | 1999-09-04 14:40:49 +0000 | [diff] [blame] | 1281 | ctx->Driver.AllocDepthBuffer = gl_alloc_depth_buffer; |
| 1282 | ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float; |
| 1283 | ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int; |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1284 | #endif |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 1285 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1286 | #ifdef PROFILE |
| 1287 | init_timings( ctx ); |
| 1288 | #endif |
| 1289 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1290 | if (!alloc_proxy_textures(ctx)) { |
| 1291 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1292 | FREE(ctx->VB); |
| 1293 | FREE(ctx->PB); |
| 1294 | FREE(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1295 | return NULL; |
| 1296 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1297 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1298 | /* setup API dispatch tables */ |
| 1299 | _mesa_init_exec_table( &ctx->Exec ); |
| 1300 | _mesa_init_dlist_table( &ctx->Save ); |
| 1301 | ctx->CurrentDispatch = &ctx->Exec; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1302 | |
| 1303 | return ctx; |
| 1304 | } |
| 1305 | |
| 1306 | /* Just reads the config files... |
| 1307 | */ |
| 1308 | void gl_context_initialize( GLcontext *ctx ) |
| 1309 | { |
| 1310 | gl_read_config_file( ctx ); |
| 1311 | } |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | /* |
| 1317 | * Destroy a gl_context structure. |
| 1318 | */ |
| 1319 | void gl_destroy_context( GLcontext *ctx ) |
| 1320 | { |
| 1321 | if (ctx) { |
| 1322 | |
| 1323 | GLuint i; |
| 1324 | struct gl_shine_tab *s, *tmps; |
| 1325 | |
| 1326 | #ifdef PROFILE |
| 1327 | if (getenv("MESA_PROFILE")) { |
| 1328 | print_timings( ctx ); |
| 1329 | } |
| 1330 | #endif |
| 1331 | |
| 1332 | gl_matrix_dtr( &ctx->ModelView ); |
| 1333 | for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) { |
| 1334 | gl_matrix_dtr( &ctx->ModelViewStack[i] ); |
| 1335 | } |
| Keith Whitwell | 5a437d5 | 1999-09-19 23:43:02 +0000 | [diff] [blame] | 1336 | gl_matrix_dtr( &ctx->ProjectionMatrix ); |
| 1337 | for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) { |
| 1338 | gl_matrix_dtr( &ctx->ProjectionStack[i] ); |
| 1339 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1340 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1341 | FREE( ctx->PB ); |
| Keith Whitwell | 5a437d5 | 1999-09-19 23:43:02 +0000 | [diff] [blame] | 1342 | |
| 1343 | if(ctx->input != ctx->VB->IM) |
| 1344 | gl_immediate_free( ctx->input ); |
| 1345 | |
| 1346 | gl_vb_free( ctx->VB ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1347 | |
| 1348 | ctx->Shared->RefCount--; |
| 1349 | assert(ctx->Shared->RefCount>=0); |
| 1350 | if (ctx->Shared->RefCount==0) { |
| 1351 | /* free shared state */ |
| 1352 | free_shared_state( ctx, ctx->Shared ); |
| 1353 | } |
| 1354 | |
| 1355 | foreach_s( s, tmps, ctx->ShineTabList ) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1356 | FREE( s ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1357 | } |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1358 | FREE( ctx->ShineTabList ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1359 | |
| 1360 | /* Free proxy texture objects */ |
| 1361 | gl_free_texture_object( NULL, ctx->Texture.Proxy1D ); |
| 1362 | gl_free_texture_object( NULL, ctx->Texture.Proxy2D ); |
| 1363 | gl_free_texture_object( NULL, ctx->Texture.Proxy3D ); |
| 1364 | |
| 1365 | /* Free evaluator data */ |
| 1366 | if (ctx->EvalMap.Map1Vertex3.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1367 | FREE( ctx->EvalMap.Map1Vertex3.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1368 | if (ctx->EvalMap.Map1Vertex4.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1369 | FREE( ctx->EvalMap.Map1Vertex4.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1370 | if (ctx->EvalMap.Map1Index.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1371 | FREE( ctx->EvalMap.Map1Index.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1372 | if (ctx->EvalMap.Map1Color4.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1373 | FREE( ctx->EvalMap.Map1Color4.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1374 | if (ctx->EvalMap.Map1Normal.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1375 | FREE( ctx->EvalMap.Map1Normal.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1376 | if (ctx->EvalMap.Map1Texture1.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1377 | FREE( ctx->EvalMap.Map1Texture1.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1378 | if (ctx->EvalMap.Map1Texture2.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1379 | FREE( ctx->EvalMap.Map1Texture2.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1380 | if (ctx->EvalMap.Map1Texture3.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1381 | FREE( ctx->EvalMap.Map1Texture3.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1382 | if (ctx->EvalMap.Map1Texture4.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1383 | FREE( ctx->EvalMap.Map1Texture4.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1384 | |
| 1385 | if (ctx->EvalMap.Map2Vertex3.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1386 | FREE( ctx->EvalMap.Map2Vertex3.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1387 | if (ctx->EvalMap.Map2Vertex4.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1388 | FREE( ctx->EvalMap.Map2Vertex4.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1389 | if (ctx->EvalMap.Map2Index.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1390 | FREE( ctx->EvalMap.Map2Index.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1391 | if (ctx->EvalMap.Map2Color4.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1392 | FREE( ctx->EvalMap.Map2Color4.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1393 | if (ctx->EvalMap.Map2Normal.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1394 | FREE( ctx->EvalMap.Map2Normal.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1395 | if (ctx->EvalMap.Map2Texture1.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1396 | FREE( ctx->EvalMap.Map2Texture1.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1397 | if (ctx->EvalMap.Map2Texture2.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1398 | FREE( ctx->EvalMap.Map2Texture2.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1399 | if (ctx->EvalMap.Map2Texture3.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1400 | FREE( ctx->EvalMap.Map2Texture3.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1401 | if (ctx->EvalMap.Map2Texture4.Points) |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1402 | FREE( ctx->EvalMap.Map2Texture4.Points ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1403 | |
| Keith Whitwell | 5a437d5 | 1999-09-19 23:43:02 +0000 | [diff] [blame] | 1404 | /* Free cache of immediate buffers. */ |
| 1405 | while (ctx->nr_im_queued-- > 0) { |
| 1406 | struct immediate * next = ctx->freed_im_queue->next; |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1407 | FREE( ctx->freed_im_queue ); |
| Keith Whitwell | 5a437d5 | 1999-09-19 23:43:02 +0000 | [diff] [blame] | 1408 | ctx->freed_im_queue = next; |
| 1409 | } |
| 1410 | gl_extensions_dtr(ctx); |
| 1411 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1412 | FREE( (void *) ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1413 | |
| 1414 | #ifndef THREADS |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1415 | if (ctx == _mesa_current_context) { |
| 1416 | _mesa_current_context = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1417 | CURRENT_INPUT = NULL; |
| 1418 | } |
| 1419 | #endif |
| 1420 | |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | /* |
| 1427 | * Create a new framebuffer. A GLframebuffer is a struct which |
| 1428 | * encapsulates the depth, stencil and accum buffers and related |
| 1429 | * parameters. |
| 1430 | * Input: visual - a GLvisual pointer |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1431 | * softwareDepth - create/use a software depth buffer? |
| 1432 | * softwareStencil - create/use a software stencil buffer? |
| 1433 | * softwareAccum - create/use a software accum buffer? |
| 1434 | * softwareAlpha - create/use a software alpha buffer? |
| 1435 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1436 | * Return: pointer to new GLframebuffer struct or NULL if error. |
| 1437 | */ |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1438 | GLframebuffer *gl_create_framebuffer( GLvisual *visual, |
| 1439 | GLboolean softwareDepth, |
| 1440 | GLboolean softwareStencil, |
| 1441 | GLboolean softwareAccum, |
| 1442 | GLboolean softwareAlpha ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1443 | { |
| 1444 | GLframebuffer *buffer; |
| 1445 | |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1446 | buffer = CALLOC_STRUCT(gl_frame_buffer); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1447 | if (!buffer) { |
| 1448 | return NULL; |
| 1449 | } |
| 1450 | |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1451 | /* sanity checks */ |
| 1452 | if (softwareDepth ) { |
| 1453 | assert(visual->DepthBits > 0); |
| 1454 | } |
| 1455 | if (softwareStencil) { |
| 1456 | assert(visual->StencilBits > 0); |
| 1457 | } |
| 1458 | if (softwareAccum) { |
| 1459 | assert(visual->RGBAflag); |
| 1460 | assert(visual->AccumBits > 0); |
| 1461 | } |
| 1462 | if (softwareAlpha) { |
| 1463 | assert(visual->RGBAflag); |
| 1464 | assert(visual->AlphaBits > 0); |
| 1465 | } |
| 1466 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1467 | buffer->Visual = visual; |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1468 | buffer->UseSoftwareDepthBuffer = softwareDepth; |
| 1469 | buffer->UseSoftwareStencilBuffer = softwareStencil; |
| 1470 | buffer->UseSoftwareAccumBuffer = softwareAccum; |
| 1471 | buffer->UseSoftwareAlphaBuffers = softwareAlpha; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1472 | |
| 1473 | return buffer; |
| 1474 | } |
| 1475 | |
| 1476 | |
| 1477 | |
| 1478 | /* |
| 1479 | * Free a framebuffer struct and its buffers. |
| 1480 | */ |
| 1481 | void gl_destroy_framebuffer( GLframebuffer *buffer ) |
| 1482 | { |
| 1483 | if (buffer) { |
| 1484 | if (buffer->Depth) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1485 | FREE( buffer->Depth ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1486 | } |
| 1487 | if (buffer->Accum) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1488 | FREE( buffer->Accum ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1489 | } |
| 1490 | if (buffer->Stencil) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1491 | FREE( buffer->Stencil ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1492 | } |
| 1493 | if (buffer->FrontLeftAlpha) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1494 | FREE( buffer->FrontLeftAlpha ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1495 | } |
| 1496 | if (buffer->BackLeftAlpha) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1497 | FREE( buffer->BackLeftAlpha ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1498 | } |
| 1499 | if (buffer->FrontRightAlpha) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1500 | FREE( buffer->FrontRightAlpha ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1501 | } |
| 1502 | if (buffer->BackRightAlpha) { |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1503 | FREE( buffer->BackRightAlpha ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1504 | } |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1505 | FREE(buffer); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | /* |
| 1512 | * Set the current context, binding the given frame buffer to the context. |
| 1513 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1514 | void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1515 | { |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1516 | gl_make_current2( newCtx, buffer, buffer ); |
| 1517 | } |
| 1518 | |
| 1519 | |
| 1520 | /* |
| 1521 | * Bind the given context to the given draw-buffer and read-buffer |
| 1522 | * and make it the current context for this thread. |
| 1523 | */ |
| 1524 | void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer, |
| 1525 | GLframebuffer *readBuffer ) |
| 1526 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1527 | GET_CURRENT_CONTEXT(oldCtx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1528 | |
| 1529 | /* Flush the old context |
| 1530 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1531 | if (oldCtx) { |
| 1532 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1535 | /* unbind frame buffers from context */ |
| 1536 | if (oldCtx && oldCtx->DrawBuffer) { |
| 1537 | oldCtx->DrawBuffer = NULL; |
| 1538 | } |
| 1539 | if (oldCtx && oldCtx->ReadBuffer) { |
| 1540 | oldCtx->ReadBuffer = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1541 | } |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 1542 | |
| 1543 | #ifdef THREADS |
| 1544 | /* TODO: unbind old buffer from context? */ |
| 1545 | MesaSetTSD(&mesa_ctx_tsd, (void *) newCtx, mesa_ctx_thread_init); |
| 1546 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1547 | _mesa_current_context = newCtx; |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 1548 | #endif |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1549 | if (newCtx) { |
| 1550 | SET_IMMEDIATE(newCtx, newCtx->input); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1551 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1552 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1553 | if (newCtx) |
| 1554 | _glapi_set_dispatch(newCtx->CurrentDispatch); |
| 1555 | else |
| 1556 | _glapi_set_dispatch(NULL); /* none current */ |
| 1557 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1558 | if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n"); |
| 1559 | |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1560 | if (newCtx && drawBuffer && readBuffer) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1561 | /* TODO: check if newCtx and buffer's visual match??? */ |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1562 | newCtx->DrawBuffer = drawBuffer; |
| 1563 | newCtx->ReadBuffer = readBuffer; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1564 | newCtx->NewState = NEW_ALL; /* just to be safe */ |
| 1565 | gl_update_state( newCtx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1566 | } |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 1567 | |
| 1568 | /* We can use this to help debug user's problems. Tell the to set |
| 1569 | * the MESA_INFO env variable before running their app. Then the |
| 1570 | * first time each context is made current we'll print some useful |
| 1571 | * information. |
| 1572 | */ |
| Brian Paul | 32c3255 | 1999-12-02 20:33:06 +0000 | [diff] [blame] | 1573 | if (newCtx && newCtx->FirstTimeCurrent) { |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 1574 | if (getenv("MESA_INFO")) { |
| 1575 | fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION)); |
| 1576 | fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER)); |
| 1577 | fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR)); |
| 1578 | fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS)); |
| 1579 | } |
| 1580 | newCtx->FirstTimeCurrent = GL_FALSE; |
| 1581 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1585 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1586 | /* |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 1587 | * Return current context handle for the calling thread. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1588 | */ |
| 1589 | GLcontext *gl_get_current_context( void ) |
| 1590 | { |
| 1591 | #ifdef THREADS |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 1592 | return (GLcontext *) MesaGetTSD(&mesa_ctx_tsd); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1593 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1594 | return _mesa_current_context; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1595 | #endif |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | /* |
| 1601 | * Copy attribute groups from one context to another. |
| 1602 | * Input: src - source context |
| 1603 | * dst - destination context |
| 1604 | * mask - bitwise OR of GL_*_BIT flags |
| 1605 | */ |
| 1606 | void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask ) |
| 1607 | { |
| 1608 | if (mask & GL_ACCUM_BUFFER_BIT) { |
| 1609 | MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) ); |
| 1610 | } |
| 1611 | if (mask & GL_COLOR_BUFFER_BIT) { |
| 1612 | MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) ); |
| 1613 | } |
| 1614 | if (mask & GL_CURRENT_BIT) { |
| 1615 | MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) ); |
| 1616 | } |
| 1617 | if (mask & GL_DEPTH_BUFFER_BIT) { |
| 1618 | MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) ); |
| 1619 | } |
| 1620 | if (mask & GL_ENABLE_BIT) { |
| 1621 | /* no op */ |
| 1622 | } |
| 1623 | if (mask & GL_EVAL_BIT) { |
| 1624 | MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) ); |
| 1625 | } |
| 1626 | if (mask & GL_FOG_BIT) { |
| 1627 | MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) ); |
| 1628 | } |
| 1629 | if (mask & GL_HINT_BIT) { |
| 1630 | MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) ); |
| 1631 | } |
| 1632 | if (mask & GL_LIGHTING_BIT) { |
| 1633 | MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) ); |
| 1634 | /* gl_reinit_light_attrib( &dst->Light ); */ |
| 1635 | } |
| 1636 | if (mask & GL_LINE_BIT) { |
| 1637 | MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) ); |
| 1638 | } |
| 1639 | if (mask & GL_LIST_BIT) { |
| 1640 | MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) ); |
| 1641 | } |
| 1642 | if (mask & GL_PIXEL_MODE_BIT) { |
| 1643 | MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) ); |
| 1644 | } |
| 1645 | if (mask & GL_POINT_BIT) { |
| 1646 | MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) ); |
| 1647 | } |
| 1648 | if (mask & GL_POLYGON_BIT) { |
| 1649 | MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) ); |
| 1650 | } |
| 1651 | if (mask & GL_POLYGON_STIPPLE_BIT) { |
| 1652 | /* Use loop instead of MEMCPY due to problem with Portland Group's |
| 1653 | * C compiler. Reported by John Stone. |
| 1654 | */ |
| 1655 | int i; |
| 1656 | for (i=0;i<32;i++) { |
| 1657 | dst->PolygonStipple[i] = src->PolygonStipple[i]; |
| 1658 | } |
| 1659 | } |
| 1660 | if (mask & GL_SCISSOR_BIT) { |
| 1661 | MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) ); |
| 1662 | } |
| 1663 | if (mask & GL_STENCIL_BUFFER_BIT) { |
| 1664 | MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) ); |
| 1665 | } |
| 1666 | if (mask & GL_TEXTURE_BIT) { |
| 1667 | MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) ); |
| 1668 | } |
| 1669 | if (mask & GL_TRANSFORM_BIT) { |
| 1670 | MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) ); |
| 1671 | } |
| 1672 | if (mask & GL_VIEWPORT_BIT) { |
| 1673 | MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) ); |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1678 | /* |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1679 | * This should be called by device drivers just before they do a |
| 1680 | * swapbuffers. Any pending rendering commands will be executed. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1681 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1682 | void |
| 1683 | _mesa_swapbuffers(GLcontext *ctx) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1684 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1685 | FLUSH_VB( ctx, "swap buffers" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1689 | /* |
| 1690 | * Return pointer to this context's current API dispatch table. |
| 1691 | * It'll either be the immediate-mode execute dispatcher or the |
| 1692 | * display list compile dispatcher. |
| 1693 | */ |
| 1694 | struct _glapi_table * |
| 1695 | _mesa_get_dispatch(GLcontext *ctx) |
| 1696 | { |
| 1697 | return ctx->CurrentDispatch; |
| 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | void |
| 1703 | _mesa_ResizeBuffersMESA( void ) |
| 1704 | { |
| 1705 | GET_CURRENT_CONTEXT(ctx); |
| 1706 | |
| 1707 | GLuint buf_width, buf_height; |
| 1708 | |
| 1709 | if (MESA_VERBOSE & VERBOSE_API) |
| 1710 | fprintf(stderr, "glResizeBuffersMESA\n"); |
| 1711 | |
| 1712 | /* ask device driver for size of output buffer */ |
| 1713 | (*ctx->Driver.GetBufferSize)( ctx, &buf_width, &buf_height ); |
| 1714 | |
| 1715 | /* see if size of device driver's color buffer (window) has changed */ |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1716 | if (ctx->DrawBuffer->Width == (GLint) buf_width && |
| 1717 | ctx->DrawBuffer->Height == (GLint) buf_height) |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1718 | return; |
| 1719 | |
| 1720 | ctx->NewState |= NEW_RASTER_OPS; /* to update scissor / window bounds */ |
| 1721 | |
| 1722 | /* save buffer size */ |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1723 | ctx->DrawBuffer->Width = buf_width; |
| 1724 | ctx->DrawBuffer->Height = buf_height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1725 | |
| 1726 | /* Reallocate other buffers if needed. */ |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1727 | if (ctx->DrawBuffer->UseSoftwareDepthBuffer) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1728 | /* reallocate depth buffer */ |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1729 | gl_alloc_depth_buffer( ctx ); |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1730 | } |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1731 | if (ctx->DrawBuffer->UseSoftwareStencilBuffer) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1732 | /* reallocate stencil buffer */ |
| 1733 | gl_alloc_stencil_buffer( ctx ); |
| 1734 | } |
| Brian Paul | 5c3bee5 | 1999-12-10 19:09:21 +0000 | [diff] [blame^] | 1735 | if (ctx->DrawBuffer->UseSoftwareAccumBuffer) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1736 | /* reallocate accum buffer */ |
| 1737 | gl_alloc_accum_buffer( ctx ); |
| 1738 | } |
| 1739 | if (ctx->Visual->SoftwareAlpha) { |
| 1740 | gl_alloc_alpha_buffers( ctx ); |
| 1741 | } |
| 1742 | } |
| 1743 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1744 | |
| 1745 | |
| 1746 | /**********************************************************************/ |
| 1747 | /***** Miscellaneous functions *****/ |
| 1748 | /**********************************************************************/ |
| 1749 | |
| 1750 | |
| 1751 | /* |
| 1752 | * This function is called when the Mesa user has stumbled into a code |
| 1753 | * path which may not be implemented fully or correctly. |
| 1754 | */ |
| 1755 | void gl_problem( const GLcontext *ctx, const char *s ) |
| 1756 | { |
| 1757 | fprintf( stderr, "Mesa implementation error: %s\n", s ); |
| 1758 | fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" ); |
| 1759 | (void) ctx; |
| 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | /* |
| 1765 | * This is called to inform the user that he or she has tried to do |
| 1766 | * something illogical or if there's likely a bug in their program |
| 1767 | * (like enabled depth testing without a depth buffer). |
| 1768 | */ |
| 1769 | void gl_warning( const GLcontext *ctx, const char *s ) |
| 1770 | { |
| 1771 | GLboolean debug; |
| 1772 | #ifdef DEBUG |
| 1773 | debug = GL_TRUE; |
| 1774 | #else |
| 1775 | if (getenv("MESA_DEBUG")) { |
| 1776 | debug = GL_TRUE; |
| 1777 | } |
| 1778 | else { |
| 1779 | debug = GL_FALSE; |
| 1780 | } |
| 1781 | #endif |
| 1782 | if (debug) { |
| 1783 | fprintf( stderr, "Mesa warning: %s\n", s ); |
| 1784 | } |
| 1785 | (void) ctx; |
| 1786 | } |
| 1787 | |
| 1788 | |
| 1789 | |
| 1790 | void gl_compile_error( GLcontext *ctx, GLenum error, const char *s ) |
| 1791 | { |
| 1792 | if (ctx->CompileFlag) |
| 1793 | gl_save_error( ctx, error, s ); |
| 1794 | |
| 1795 | if (ctx->ExecuteFlag) |
| 1796 | gl_error( ctx, error, s ); |
| 1797 | } |
| 1798 | |
| 1799 | |
| 1800 | /* |
| 1801 | * This is Mesa's error handler. Normally, all that's done is the updating |
| 1802 | * of the current error value. If Mesa is compiled with -DDEBUG or if the |
| 1803 | * environment variable "MESA_DEBUG" is defined then a real error message |
| 1804 | * is printed to stderr. |
| 1805 | * Input: error - the error value |
| 1806 | * s - a diagnostic string |
| 1807 | */ |
| 1808 | void gl_error( GLcontext *ctx, GLenum error, const char *s ) |
| 1809 | { |
| 1810 | GLboolean debug; |
| 1811 | |
| 1812 | #ifdef DEBUG |
| 1813 | debug = GL_TRUE; |
| 1814 | #else |
| 1815 | if (getenv("MESA_DEBUG")) { |
| 1816 | debug = GL_TRUE; |
| 1817 | } |
| 1818 | else { |
| 1819 | debug = GL_FALSE; |
| 1820 | } |
| 1821 | #endif |
| 1822 | |
| 1823 | if (debug) { |
| 1824 | char errstr[1000]; |
| 1825 | |
| 1826 | switch (error) { |
| 1827 | case GL_NO_ERROR: |
| 1828 | strcpy( errstr, "GL_NO_ERROR" ); |
| 1829 | break; |
| 1830 | case GL_INVALID_VALUE: |
| 1831 | strcpy( errstr, "GL_INVALID_VALUE" ); |
| 1832 | break; |
| 1833 | case GL_INVALID_ENUM: |
| 1834 | strcpy( errstr, "GL_INVALID_ENUM" ); |
| 1835 | break; |
| 1836 | case GL_INVALID_OPERATION: |
| 1837 | strcpy( errstr, "GL_INVALID_OPERATION" ); |
| 1838 | break; |
| 1839 | case GL_STACK_OVERFLOW: |
| 1840 | strcpy( errstr, "GL_STACK_OVERFLOW" ); |
| 1841 | break; |
| 1842 | case GL_STACK_UNDERFLOW: |
| 1843 | strcpy( errstr, "GL_STACK_UNDERFLOW" ); |
| 1844 | break; |
| 1845 | case GL_OUT_OF_MEMORY: |
| 1846 | strcpy( errstr, "GL_OUT_OF_MEMORY" ); |
| 1847 | break; |
| 1848 | default: |
| 1849 | strcpy( errstr, "unknown" ); |
| 1850 | break; |
| 1851 | } |
| 1852 | fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s ); |
| 1853 | } |
| 1854 | |
| 1855 | if (ctx->ErrorValue==GL_NO_ERROR) { |
| 1856 | ctx->ErrorValue = error; |
| 1857 | } |
| 1858 | |
| 1859 | /* Call device driver's error handler, if any. This is used on the Mac. */ |
| 1860 | if (ctx->Driver.Error) { |
| 1861 | (*ctx->Driver.Error)( ctx ); |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | |
| 1866 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1867 | /**********************************************************************/ |
| 1868 | /***** State update logic *****/ |
| 1869 | /**********************************************************************/ |
| 1870 | |
| 1871 | |
| 1872 | /* |
| 1873 | * Since the device driver may or may not support pixel logic ops we |
| 1874 | * have to make some extensive tests to determine whether or not |
| 1875 | * software-implemented logic operations have to be used. |
| 1876 | */ |
| 1877 | static void update_pixel_logic( GLcontext *ctx ) |
| 1878 | { |
| 1879 | if (ctx->Visual->RGBAflag) { |
| 1880 | /* RGBA mode blending w/ Logic Op */ |
| 1881 | if (ctx->Color.ColorLogicOpEnabled) { |
| 1882 | if (ctx->Driver.LogicOp |
| 1883 | && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) { |
| 1884 | /* Device driver can do logic, don't have to do it in software */ |
| 1885 | ctx->Color.SWLogicOpEnabled = GL_FALSE; |
| 1886 | } |
| 1887 | else { |
| 1888 | /* Device driver can't do logic op so we do it in software */ |
| 1889 | ctx->Color.SWLogicOpEnabled = GL_TRUE; |
| 1890 | } |
| 1891 | } |
| 1892 | else { |
| 1893 | /* no logic op */ |
| 1894 | if (ctx->Driver.LogicOp) { |
| 1895 | (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY ); |
| 1896 | } |
| 1897 | ctx->Color.SWLogicOpEnabled = GL_FALSE; |
| 1898 | } |
| 1899 | } |
| 1900 | else { |
| 1901 | /* CI mode Logic Op */ |
| 1902 | if (ctx->Color.IndexLogicOpEnabled) { |
| 1903 | if (ctx->Driver.LogicOp |
| 1904 | && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) { |
| 1905 | /* Device driver can do logic, don't have to do it in software */ |
| 1906 | ctx->Color.SWLogicOpEnabled = GL_FALSE; |
| 1907 | } |
| 1908 | else { |
| 1909 | /* Device driver can't do logic op so we do it in software */ |
| 1910 | ctx->Color.SWLogicOpEnabled = GL_TRUE; |
| 1911 | } |
| 1912 | } |
| 1913 | else { |
| 1914 | /* no logic op */ |
| 1915 | if (ctx->Driver.LogicOp) { |
| 1916 | (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY ); |
| 1917 | } |
| 1918 | ctx->Color.SWLogicOpEnabled = GL_FALSE; |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | /* |
| 1926 | * Check if software implemented RGBA or Color Index masking is needed. |
| 1927 | */ |
| 1928 | static void update_pixel_masking( GLcontext *ctx ) |
| 1929 | { |
| 1930 | if (ctx->Visual->RGBAflag) { |
| 1931 | GLuint *colorMask = (GLuint *) ctx->Color.ColorMask; |
| 1932 | if (*colorMask == 0xffffffff) { |
| 1933 | /* disable masking */ |
| 1934 | if (ctx->Driver.ColorMask) { |
| 1935 | (void) (*ctx->Driver.ColorMask)( ctx, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); |
| 1936 | } |
| 1937 | ctx->Color.SWmasking = GL_FALSE; |
| 1938 | } |
| 1939 | else { |
| 1940 | /* Ask driver to do color masking, if it can't then |
| 1941 | * do it in software |
| 1942 | */ |
| 1943 | GLboolean red = ctx->Color.ColorMask[RCOMP] ? GL_TRUE : GL_FALSE; |
| 1944 | GLboolean green = ctx->Color.ColorMask[GCOMP] ? GL_TRUE : GL_FALSE; |
| 1945 | GLboolean blue = ctx->Color.ColorMask[BCOMP] ? GL_TRUE : GL_FALSE; |
| 1946 | GLboolean alpha = ctx->Color.ColorMask[ACOMP] ? GL_TRUE : GL_FALSE; |
| 1947 | if (ctx->Driver.ColorMask |
| 1948 | && (*ctx->Driver.ColorMask)( ctx, red, green, blue, alpha )) { |
| 1949 | ctx->Color.SWmasking = GL_FALSE; |
| 1950 | } |
| 1951 | else { |
| 1952 | ctx->Color.SWmasking = GL_TRUE; |
| 1953 | } |
| 1954 | } |
| 1955 | } |
| 1956 | else { |
| 1957 | if (ctx->Color.IndexMask==0xffffffff) { |
| 1958 | /* disable masking */ |
| 1959 | if (ctx->Driver.IndexMask) { |
| 1960 | (void) (*ctx->Driver.IndexMask)( ctx, 0xffffffff ); |
| 1961 | } |
| 1962 | ctx->Color.SWmasking = GL_FALSE; |
| 1963 | } |
| 1964 | else { |
| 1965 | /* Ask driver to do index masking, if it can't then |
| 1966 | * do it in software |
| 1967 | */ |
| 1968 | if (ctx->Driver.IndexMask |
| 1969 | && (*ctx->Driver.IndexMask)( ctx, ctx->Color.IndexMask )) { |
| 1970 | ctx->Color.SWmasking = GL_FALSE; |
| 1971 | } |
| 1972 | else { |
| 1973 | ctx->Color.SWmasking = GL_TRUE; |
| 1974 | } |
| 1975 | } |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | |
| 1980 | static void update_fog_mode( GLcontext *ctx ) |
| 1981 | { |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 1982 | int old_mode = ctx->FogMode; |
| 1983 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1984 | if (ctx->Fog.Enabled) { |
| 1985 | if (ctx->Texture.Enabled) |
| 1986 | ctx->FogMode = FOG_FRAGMENT; |
| 1987 | else if (ctx->Hint.Fog == GL_NICEST) |
| 1988 | ctx->FogMode = FOG_FRAGMENT; |
| 1989 | else |
| 1990 | ctx->FogMode = FOG_VERTEX; |
| 1991 | |
| 1992 | if (ctx->Driver.GetParameteri) |
| 1993 | if ((ctx->Driver.GetParameteri)( ctx, DD_HAVE_HARDWARE_FOG )) |
| 1994 | ctx->FogMode = FOG_FRAGMENT; |
| 1995 | } |
| 1996 | else { |
| 1997 | ctx->FogMode = FOG_NONE; |
| 1998 | } |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 1999 | |
| 2000 | if (old_mode != ctx->FogMode) |
| 2001 | ctx->NewState |= NEW_FOG; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | |
| 2005 | /* |
| 2006 | * Recompute the value of ctx->RasterMask, etc. according to |
| 2007 | * the current context. |
| 2008 | */ |
| 2009 | static void update_rasterflags( GLcontext *ctx ) |
| 2010 | { |
| 2011 | ctx->RasterMask = 0; |
| 2012 | |
| 2013 | if (ctx->Color.AlphaEnabled) ctx->RasterMask |= ALPHATEST_BIT; |
| 2014 | if (ctx->Color.BlendEnabled) ctx->RasterMask |= BLEND_BIT; |
| 2015 | if (ctx->Depth.Test) ctx->RasterMask |= DEPTH_BIT; |
| 2016 | if (ctx->FogMode==FOG_FRAGMENT) ctx->RasterMask |= FOG_BIT; |
| 2017 | if (ctx->Color.SWLogicOpEnabled) ctx->RasterMask |= LOGIC_OP_BIT; |
| 2018 | if (ctx->Scissor.Enabled) ctx->RasterMask |= SCISSOR_BIT; |
| 2019 | if (ctx->Stencil.Enabled) ctx->RasterMask |= STENCIL_BIT; |
| 2020 | if (ctx->Color.SWmasking) ctx->RasterMask |= MASKING_BIT; |
| 2021 | |
| 2022 | if (ctx->Visual->SoftwareAlpha && ctx->Color.ColorMask[ACOMP] |
| 2023 | && ctx->Color.DrawBuffer != GL_NONE) |
| 2024 | ctx->RasterMask |= ALPHABUF_BIT; |
| 2025 | |
| 2026 | if ( ctx->Viewport.X<0 |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2027 | || ctx->Viewport.X + ctx->Viewport.Width > ctx->DrawBuffer->Width |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2028 | || ctx->Viewport.Y<0 |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2029 | || ctx->Viewport.Y + ctx->Viewport.Height > ctx->DrawBuffer->Height) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2030 | ctx->RasterMask |= WINCLIP_BIT; |
| 2031 | } |
| 2032 | |
| 2033 | /* If we're not drawing to exactly one color buffer set the |
| 2034 | * MULTI_DRAW_BIT flag. Also set it if we're drawing to no |
| 2035 | * buffers or the RGBA or CI mask disables all writes. |
| 2036 | */ |
| 2037 | |
| 2038 | ctx->TriangleCaps &= ~DD_MULTIDRAW; |
| 2039 | |
| 2040 | if (ctx->Color.MultiDrawBuffer) { |
| 2041 | ctx->RasterMask |= MULTI_DRAW_BIT; |
| 2042 | ctx->TriangleCaps |= DD_MULTIDRAW; |
| 2043 | } |
| 2044 | else if (ctx->Color.DrawBuffer==GL_NONE) { |
| 2045 | ctx->RasterMask |= MULTI_DRAW_BIT; |
| 2046 | ctx->TriangleCaps |= DD_MULTIDRAW; |
| 2047 | } |
| 2048 | else if (ctx->Visual->RGBAflag && ctx->Color.ColorMask==0) { |
| 2049 | /* all RGBA channels disabled */ |
| 2050 | ctx->RasterMask |= MULTI_DRAW_BIT; |
| 2051 | ctx->TriangleCaps |= DD_MULTIDRAW; |
| 2052 | ctx->Color.DrawDestMask = 0; |
| 2053 | } |
| 2054 | else if (!ctx->Visual->RGBAflag && ctx->Color.IndexMask==0) { |
| 2055 | /* all color index bits disabled */ |
| 2056 | ctx->RasterMask |= MULTI_DRAW_BIT; |
| 2057 | ctx->TriangleCaps |= DD_MULTIDRAW; |
| 2058 | ctx->Color.DrawDestMask = 0; |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | |
| 2063 | void gl_print_state( const char *msg, GLuint state ) |
| 2064 | { |
| 2065 | fprintf(stderr, |
| 2066 | "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
| 2067 | msg, |
| 2068 | state, |
| 2069 | (state & NEW_LIGHTING) ? "lighting, " : "", |
| 2070 | (state & NEW_RASTER_OPS) ? "raster-ops, " : "", |
| 2071 | (state & NEW_TEXTURING) ? "texturing, " : "", |
| 2072 | (state & NEW_POLYGON) ? "polygon, " : "", |
| 2073 | (state & NEW_DRVSTATE0) ? "driver-0, " : "", |
| 2074 | (state & NEW_DRVSTATE1) ? "driver-1, " : "", |
| 2075 | (state & NEW_DRVSTATE2) ? "driver-2, " : "", |
| 2076 | (state & NEW_DRVSTATE3) ? "driver-3, " : "", |
| 2077 | (state & NEW_MODELVIEW) ? "modelview, " : "", |
| 2078 | (state & NEW_PROJECTION) ? "projection, " : "", |
| 2079 | (state & NEW_TEXTURE_MATRIX) ? "texture-matrix, " : "", |
| 2080 | (state & NEW_USER_CLIP) ? "user-clip, " : "", |
| 2081 | (state & NEW_TEXTURE_ENV) ? "texture-env, " : "", |
| 2082 | (state & NEW_CLIENT_STATE) ? "client-state, " : "", |
| 2083 | (state & NEW_FOG) ? "fog, " : "", |
| 2084 | (state & NEW_NORMAL_TRANSFORM) ? "normal-transform, " : "", |
| 2085 | (state & NEW_VIEWPORT) ? "viewport, " : "", |
| 2086 | (state & NEW_TEXTURE_ENABLE) ? "texture-enable, " : ""); |
| 2087 | } |
| 2088 | |
| 2089 | void gl_print_enable_flags( const char *msg, GLuint flags ) |
| 2090 | { |
| 2091 | fprintf(stderr, |
| 2092 | "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s\n", |
| 2093 | msg, |
| 2094 | flags, |
| 2095 | (flags & ENABLE_TEX0) ? "tex-0, " : "", |
| 2096 | (flags & ENABLE_TEX1) ? "tex-1, " : "", |
| 2097 | (flags & ENABLE_LIGHT) ? "light, " : "", |
| 2098 | (flags & ENABLE_FOG) ? "fog, " : "", |
| 2099 | (flags & ENABLE_USERCLIP) ? "userclip, " : "", |
| 2100 | (flags & ENABLE_TEXGEN0) ? "tex-gen-0, " : "", |
| 2101 | (flags & ENABLE_TEXGEN1) ? "tex-gen-1, " : "", |
| 2102 | (flags & ENABLE_TEXMAT0) ? "tex-mat-0, " : "", |
| 2103 | (flags & ENABLE_TEXMAT1) ? "tex-mat-1, " : "", |
| 2104 | (flags & ENABLE_NORMALIZE) ? "normalize, " : "", |
| 2105 | (flags & ENABLE_RESCALE) ? "rescale, " : ""); |
| 2106 | } |
| 2107 | |
| 2108 | |
| 2109 | /* |
| 2110 | * If ctx->NewState is non-zero then this function MUST be called before |
| 2111 | * rendering any primitive. Basically, function pointers and miscellaneous |
| 2112 | * flags are updated to reflect the current state of the state machine. |
| 2113 | */ |
| 2114 | void gl_update_state( GLcontext *ctx ) |
| 2115 | { |
| 2116 | GLuint i; |
| 2117 | |
| 2118 | if (MESA_VERBOSE & VERBOSE_STATE) |
| 2119 | gl_print_state("", ctx->NewState); |
| 2120 | |
| 2121 | if (ctx->NewState & NEW_CLIENT_STATE) |
| 2122 | gl_update_client_state( ctx ); |
| 2123 | |
| 2124 | if ((ctx->NewState & NEW_TEXTURE_ENABLE) && |
| 2125 | (ctx->Enabled & ENABLE_TEX_ANY) != ctx->Texture.Enabled) |
| 2126 | ctx->NewState |= NEW_TEXTURING | NEW_RASTER_OPS; |
| 2127 | |
| 2128 | if (ctx->NewState & NEW_TEXTURE_ENV) { |
| 2129 | if (ctx->Texture.Unit[0].EnvMode == ctx->Texture.Unit[0].LastEnvMode && |
| 2130 | ctx->Texture.Unit[1].EnvMode == ctx->Texture.Unit[1].LastEnvMode) |
| 2131 | ctx->NewState &= ~NEW_TEXTURE_ENV; |
| 2132 | ctx->Texture.Unit[0].LastEnvMode = ctx->Texture.Unit[0].EnvMode; |
| 2133 | ctx->Texture.Unit[1].LastEnvMode = ctx->Texture.Unit[1].EnvMode; |
| 2134 | } |
| 2135 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2136 | if (ctx->NewState & NEW_TEXTURE_MATRIX) { |
| 2137 | ctx->Enabled &= ~(ENABLE_TEXMAT0|ENABLE_TEXMAT1); |
| 2138 | |
| 2139 | for (i=0; i < MAX_TEXTURE_UNITS; i++) { |
| 2140 | if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) |
| 2141 | { |
| 2142 | gl_matrix_analyze( &ctx->TextureMatrix[i] ); |
| 2143 | ctx->TextureMatrix[i].flags &= ~MAT_DIRTY_DEPENDENTS; |
| 2144 | |
| 2145 | if (ctx->Texture.Unit[i].Enabled && |
| 2146 | ctx->TextureMatrix[i].type != MATRIX_IDENTITY) |
| 2147 | ctx->Enabled |= ENABLE_TEXMAT0 << i; |
| 2148 | } |
| 2149 | } |
| 2150 | } |
| 2151 | |
| Brian Paul | ece75ac | 1999-11-15 22:21:47 +0000 | [diff] [blame] | 2152 | if (ctx->NewState & (NEW_TEXTURING | NEW_TEXTURE_ENABLE)) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2153 | ctx->Texture.NeedNormals = GL_FALSE; |
| 2154 | gl_update_dirty_texobjs(ctx); |
| 2155 | ctx->Enabled &= ~(ENABLE_TEXGEN0|ENABLE_TEXGEN1); |
| 2156 | ctx->Texture.ReallyEnabled = 0; |
| 2157 | |
| 2158 | for (i=0; i < MAX_TEXTURE_UNITS; i++) { |
| 2159 | if (ctx->Texture.Unit[i].Enabled) { |
| 2160 | gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] ); |
| 2161 | |
| 2162 | ctx->Texture.ReallyEnabled |= |
| 2163 | ctx->Texture.Unit[i].ReallyEnabled<<(i*4); |
| 2164 | |
| 2165 | if (ctx->Texture.Unit[i].GenFlags != 0) { |
| 2166 | ctx->Enabled |= ENABLE_TEXGEN0 << i; |
| 2167 | |
| 2168 | if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS) |
| 2169 | { |
| 2170 | ctx->Texture.NeedNormals = GL_TRUE; |
| 2171 | ctx->Texture.NeedEyeCoords = GL_TRUE; |
| 2172 | } |
| 2173 | |
| 2174 | if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD) |
| 2175 | { |
| 2176 | ctx->Texture.NeedEyeCoords = GL_TRUE; |
| 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | |
| 2182 | ctx->Texture.Enabled = ctx->Enabled & ENABLE_TEX_ANY; |
| 2183 | ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals); |
| 2184 | } |
| 2185 | |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2186 | if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING | NEW_FOG)) { |
| 2187 | |
| 2188 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2189 | if (ctx->NewState & NEW_RASTER_OPS) { |
| 2190 | update_pixel_logic(ctx); |
| 2191 | update_pixel_masking(ctx); |
| 2192 | update_fog_mode(ctx); |
| 2193 | update_rasterflags(ctx); |
| 2194 | if (ctx->Driver.Dither) { |
| 2195 | (*ctx->Driver.Dither)( ctx, ctx->Color.DitherFlag ); |
| 2196 | } |
| 2197 | |
| 2198 | /* Check if incoming colors can be modified during rasterization */ |
| 2199 | if (ctx->Fog.Enabled || |
| 2200 | ctx->Texture.Enabled || |
| 2201 | ctx->Color.BlendEnabled || |
| 2202 | ctx->Color.SWmasking || |
| 2203 | ctx->Color.SWLogicOpEnabled) { |
| 2204 | ctx->MutablePixels = GL_TRUE; |
| 2205 | } |
| 2206 | else { |
| 2207 | ctx->MutablePixels = GL_FALSE; |
| 2208 | } |
| 2209 | |
| 2210 | /* update scissor region */ |
| 2211 | |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2212 | ctx->DrawBuffer->Xmin = 0; |
| 2213 | ctx->DrawBuffer->Ymin = 0; |
| 2214 | ctx->DrawBuffer->Xmax = ctx->DrawBuffer->Width-1; |
| 2215 | ctx->DrawBuffer->Ymax = ctx->DrawBuffer->Height-1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2216 | if (ctx->Scissor.Enabled) { |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2217 | if (ctx->Scissor.X > ctx->DrawBuffer->Xmin) { |
| 2218 | ctx->DrawBuffer->Xmin = ctx->Scissor.X; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2219 | } |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2220 | if (ctx->Scissor.Y > ctx->DrawBuffer->Ymin) { |
| 2221 | ctx->DrawBuffer->Ymin = ctx->Scissor.Y; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2222 | } |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2223 | if (ctx->Scissor.X + ctx->Scissor.Width - 1 < ctx->DrawBuffer->Xmax) { |
| 2224 | ctx->DrawBuffer->Xmax = ctx->Scissor.X + ctx->Scissor.Width - 1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2225 | } |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2226 | if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < ctx->DrawBuffer->Ymax) { |
| 2227 | ctx->DrawBuffer->Ymax = ctx->Scissor.Y + ctx->Scissor.Height - 1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2228 | } |
| 2229 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | if (ctx->NewState & NEW_LIGHTING) { |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2233 | ctx->TriangleCaps &= ~(DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2234 | if (ctx->Light.Enabled) { |
| 2235 | if (ctx->Light.Model.TwoSide) |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2236 | ctx->TriangleCaps |= (DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2237 | gl_update_lighting(ctx); |
| 2238 | } |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | if (ctx->NewState & (NEW_POLYGON | NEW_LIGHTING)) { |
| 2243 | |
| Keith Whitwell | b6e6937 | 1999-09-02 13:16:17 +0000 | [diff] [blame] | 2244 | ctx->TriangleCaps &= ~DD_TRI_CULL_FRONT_BACK; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2245 | |
| 2246 | if (ctx->NewState & NEW_POLYGON) { |
| 2247 | /* Setup CullBits bitmask */ |
| 2248 | if (ctx->Polygon.CullFlag) { |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2249 | ctx->backface_sign = 1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2250 | switch(ctx->Polygon.CullFaceMode) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2251 | case GL_BACK: |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2252 | if(ctx->Polygon.FrontFace==GL_CCW) |
| 2253 | ctx->backface_sign = -1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2254 | ctx->Polygon.CullBits = 1; |
| 2255 | break; |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2256 | case GL_FRONT: |
| 2257 | if(ctx->Polygon.FrontFace!=GL_CCW) |
| 2258 | ctx->backface_sign = -1; |
| 2259 | ctx->Polygon.CullBits = 2; |
| 2260 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2261 | default: |
| 2262 | case GL_FRONT_AND_BACK: |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2263 | ctx->backface_sign = 0; |
| Keith Whitwell | b6e6937 | 1999-09-02 13:16:17 +0000 | [diff] [blame] | 2264 | ctx->Polygon.CullBits = 0; |
| 2265 | ctx->TriangleCaps |= DD_TRI_CULL_FRONT_BACK; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2266 | break; |
| 2267 | } |
| 2268 | } |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2269 | else { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2270 | ctx->Polygon.CullBits = 3; |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2271 | ctx->backface_sign = 0; |
| 2272 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2273 | |
| 2274 | /* Any Polygon offsets enabled? */ |
| 2275 | ctx->TriangleCaps &= ~DD_TRI_OFFSET; |
| 2276 | |
| 2277 | if (ctx->Polygon.OffsetPoint || |
| 2278 | ctx->Polygon.OffsetLine || |
| 2279 | ctx->Polygon.OffsetFill) |
| 2280 | ctx->TriangleCaps |= DD_TRI_OFFSET; |
| 2281 | |
| 2282 | /* reset Z offsets now */ |
| 2283 | ctx->PointZoffset = 0.0; |
| 2284 | ctx->LineZoffset = 0.0; |
| 2285 | ctx->PolygonZoffset = 0.0; |
| 2286 | } |
| 2287 | } |
| 2288 | |
| Brian Paul | ece75ac | 1999-11-15 22:21:47 +0000 | [diff] [blame] | 2289 | if (ctx->NewState & ~(NEW_CLIENT_STATE| |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2290 | NEW_DRIVER_STATE|NEW_USER_CLIP| |
| 2291 | NEW_POLYGON)) |
| 2292 | gl_update_clipmask(ctx); |
| 2293 | |
| 2294 | if (ctx->NewState & (NEW_LIGHTING| |
| 2295 | NEW_RASTER_OPS| |
| 2296 | NEW_TEXTURING| |
| Brian Paul | ece75ac | 1999-11-15 22:21:47 +0000 | [diff] [blame] | 2297 | NEW_TEXTURE_ENABLE| |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2298 | NEW_TEXTURE_ENV| |
| 2299 | NEW_POLYGON| |
| 2300 | NEW_DRVSTATE0| |
| 2301 | NEW_DRVSTATE1| |
| 2302 | NEW_DRVSTATE2| |
| 2303 | NEW_DRVSTATE3| |
| 2304 | NEW_USER_CLIP)) |
| 2305 | { |
| 2306 | ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps; |
| 2307 | ctx->IndirectTriangles |= DD_SW_RASTERIZE; |
| 2308 | |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2309 | if (MESA_VERBOSE&VERBOSE_CULL) |
| 2310 | gl_print_tri_caps("initial indirect tris", ctx->IndirectTriangles); |
| 2311 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2312 | ctx->Driver.PointsFunc = NULL; |
| 2313 | ctx->Driver.LineFunc = NULL; |
| 2314 | ctx->Driver.TriangleFunc = NULL; |
| 2315 | ctx->Driver.QuadFunc = NULL; |
| 2316 | ctx->Driver.RectFunc = NULL; |
| 2317 | ctx->Driver.RenderVBClippedTab = NULL; |
| 2318 | ctx->Driver.RenderVBCulledTab = NULL; |
| 2319 | ctx->Driver.RenderVBRawTab = NULL; |
| 2320 | |
| 2321 | /* |
| 2322 | * Here the driver sets up all the ctx->Driver function pointers to |
| 2323 | * it's specific, private functions. |
| 2324 | */ |
| 2325 | ctx->Driver.UpdateState(ctx); |
| 2326 | |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2327 | if (MESA_VERBOSE&VERBOSE_CULL) |
| 2328 | gl_print_tri_caps("indirect tris", ctx->IndirectTriangles); |
| 2329 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2330 | /* |
| 2331 | * In case the driver didn't hook in an optimized point, line or |
| 2332 | * triangle function we'll now select "core/fallback" point, line |
| 2333 | * and triangle functions. |
| 2334 | */ |
| 2335 | if (ctx->IndirectTriangles & DD_SW_RASTERIZE) { |
| 2336 | gl_set_point_function(ctx); |
| 2337 | gl_set_line_function(ctx); |
| 2338 | gl_set_triangle_function(ctx); |
| 2339 | gl_set_quad_function(ctx); |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2340 | |
| 2341 | if ((ctx->IndirectTriangles & |
| 2342 | (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL)) == |
| 2343 | (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL)) |
| 2344 | ctx->IndirectTriangles &= ~DD_TRI_CULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2347 | if (MESA_VERBOSE&VERBOSE_CULL) |
| 2348 | gl_print_tri_caps("indirect tris 2", ctx->IndirectTriangles); |
| 2349 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2350 | gl_set_render_vb_function(ctx); |
| 2351 | } |
| 2352 | |
| 2353 | /* Should only be calc'd when !need_eye_coords and not culling. |
| 2354 | */ |
| 2355 | if (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) { |
| 2356 | if (ctx->NewState & NEW_MODELVIEW) { |
| 2357 | gl_matrix_analyze( &ctx->ModelView ); |
| 2358 | ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS; |
| 2359 | } |
| 2360 | |
| 2361 | if (ctx->NewState & NEW_PROJECTION) { |
| 2362 | gl_matrix_analyze( &ctx->ProjectionMatrix ); |
| 2363 | ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS; |
| 2364 | |
| 2365 | if (ctx->Transform.AnyClip) { |
| 2366 | gl_update_userclip( ctx ); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | gl_calculate_model_project_matrix( ctx ); |
| 2371 | ctx->ModelProjectWinMatrixUptodate = 0; |
| 2372 | } |
| 2373 | |
| 2374 | /* Figure out whether we can light in object space or not. If we |
| 2375 | * can, find the current positions of the lights in object space |
| 2376 | */ |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2377 | if ((ctx->Enabled & (ENABLE_POINT_ATTEN | ENABLE_LIGHT | ENABLE_FOG | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2378 | ENABLE_TEXGEN0 | ENABLE_TEXGEN1)) && |
| 2379 | (ctx->NewState & (NEW_LIGHTING | |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 2380 | NEW_FOG | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2381 | NEW_MODELVIEW | |
| 2382 | NEW_PROJECTION | |
| 2383 | NEW_TEXTURING | |
| 2384 | NEW_RASTER_OPS | |
| 2385 | NEW_USER_CLIP))) |
| 2386 | { |
| 2387 | GLboolean oldcoord, oldnorm; |
| 2388 | |
| 2389 | oldcoord = ctx->NeedEyeCoords; |
| 2390 | oldnorm = ctx->NeedEyeNormals; |
| 2391 | |
| 2392 | ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals); |
| 2393 | ctx->NeedEyeCoords = ((ctx->Fog.Enabled && ctx->Hint.Fog != GL_NICEST) || |
| 2394 | ctx->Point.Attenuated); |
| 2395 | ctx->NeedEyeNormals = GL_FALSE; |
| 2396 | |
| 2397 | if (ctx->Light.Enabled) { |
| 2398 | if (ctx->Light.Flags & LIGHT_POSITIONAL) { |
| 2399 | /* Need length for attenuation */ |
| 2400 | if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING)) |
| 2401 | ctx->NeedEyeCoords = GL_TRUE; |
| 2402 | } else if (ctx->Light.NeedVertices) { |
| 2403 | /* Need angle for spot calculations */ |
| 2404 | if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_ANGLE_PRESERVING)) |
| 2405 | ctx->NeedEyeCoords = GL_TRUE; |
| 2406 | } |
| 2407 | ctx->NeedEyeNormals = ctx->NeedEyeCoords; |
| 2408 | } |
| 2409 | if (ctx->Texture.Enabled || ctx->RenderMode==GL_FEEDBACK) { |
| 2410 | if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE; |
| 2411 | if (ctx->Texture.NeedNormals) |
| 2412 | ctx->NeedNormals = ctx->NeedEyeNormals = GL_TRUE; |
| 2413 | } |
| 2414 | |
| 2415 | ctx->vb_proj_matrix = &ctx->ModelProjectMatrix; |
| 2416 | |
| 2417 | if (ctx->NeedEyeCoords) |
| 2418 | ctx->vb_proj_matrix = &ctx->ProjectionMatrix; |
| 2419 | |
| 2420 | if (ctx->Light.Enabled) { |
| 2421 | gl_update_lighting_function(ctx); |
| 2422 | |
| 2423 | if ( (ctx->NewState & NEW_LIGHTING) || |
| 2424 | ((ctx->NewState & (NEW_MODELVIEW| NEW_PROJECTION)) && |
| 2425 | !ctx->NeedEyeCoords) || |
| 2426 | oldcoord != ctx->NeedEyeCoords || |
| 2427 | oldnorm != ctx->NeedEyeNormals) { |
| 2428 | gl_compute_light_positions(ctx); |
| 2429 | } |
| 2430 | |
| 2431 | ctx->rescale_factor = 1.0F; |
| 2432 | |
| 2433 | if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE | |
| 2434 | MAT_FLAG_GENERAL_SCALE | |
| 2435 | MAT_FLAG_GENERAL_3D | |
| 2436 | MAT_FLAG_GENERAL) ) |
| 2437 | |
| 2438 | { |
| 2439 | GLfloat *m = ctx->ModelView.inv; |
| 2440 | GLfloat f = m[2]*m[2] + m[6]*m[6] + m[10]*m[10]; |
| 2441 | if (f > 1e-12 && (f-1)*(f-1) > 1e-12) |
| 2442 | ctx->rescale_factor = 1.0/GL_SQRT(f); |
| 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | gl_update_normal_transform( ctx ); |
| 2447 | } |
| 2448 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2449 | gl_update_pipelines(ctx); |
| 2450 | ctx->NewState = 0; |
| 2451 | } |