changed _gl prefix to _mesa_ on fog functions
[mesa.git] / src / mesa / main / context.c
1 /* $Id: context.c,v 1.40 2000/02/02 22:21:39 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 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 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "accum.h"
33 #include "alphabuf.h"
34 #include "clip.h"
35 #include "context.h"
36 #include "cva.h"
37 #include "depth.h"
38 #include "dlist.h"
39 #include "eval.h"
40 #include "enums.h"
41 #include "extensions.h"
42 #include "fog.h"
43 #include "get.h"
44 #include "glapi.h"
45 #include "glapinoop.h"
46 #include "glthread.h"
47 #include "hash.h"
48 #include "light.h"
49 #include "macros.h"
50 #include "matrix.h"
51 #include "mem.h"
52 #include "mmath.h"
53 #include "pb.h"
54 #include "pipeline.h"
55 #include "shade.h"
56 #include "simple_list.h"
57 #include "stencil.h"
58 #include "stages.h"
59 #include "state.h"
60 #include "translate.h"
61 #include "teximage.h"
62 #include "texobj.h"
63 #include "texstate.h"
64 #include "texture.h"
65 #include "types.h"
66 #include "varray.h"
67 #include "vb.h"
68 #include "vbcull.h"
69 #include "vbrender.h"
70 #include "vbxform.h"
71 #include "vertices.h"
72 #include "xform.h"
73 #endif
74
75
76
77 /**********************************************************************/
78 /***** Context and Thread management *****/
79 /**********************************************************************/
80
81
82 #if !defined(THREADS)
83
84 struct immediate *_mesa_CurrentInput = NULL;
85
86 #endif
87
88
89
90
91 /**********************************************************************/
92 /***** Profiling functions *****/
93 /**********************************************************************/
94
95 #ifdef PROFILE
96
97 #include <sys/times.h>
98 #include <sys/param.h>
99
100
101 /*
102 * Return system time in seconds.
103 * NOTE: this implementation may not be very portable!
104 */
105 GLdouble gl_time( void )
106 {
107 static GLdouble prev_time = 0.0;
108 static GLdouble time;
109 struct tms tm;
110 clock_t clk;
111
112 clk = times(&tm);
113
114 #ifdef CLK_TCK
115 time = (double)clk / (double)CLK_TCK;
116 #else
117 time = (double)clk / (double)HZ;
118 #endif
119
120 if (time>prev_time) {
121 prev_time = time;
122 return time;
123 }
124 else {
125 return prev_time;
126 }
127 }
128
129 /*
130 * Reset the timing/profiling counters
131 */
132 static void init_timings( GLcontext *ctx )
133 {
134 ctx->BeginEndCount = 0;
135 ctx->BeginEndTime = 0.0;
136 ctx->VertexCount = 0;
137 ctx->VertexTime = 0.0;
138 ctx->PointCount = 0;
139 ctx->PointTime = 0.0;
140 ctx->LineCount = 0;
141 ctx->LineTime = 0.0;
142 ctx->PolygonCount = 0;
143 ctx->PolygonTime = 0.0;
144 ctx->ClearCount = 0;
145 ctx->ClearTime = 0.0;
146 ctx->SwapCount = 0;
147 ctx->SwapTime = 0.0;
148 }
149
150
151 /*
152 * Print the accumulated timing/profiling data.
153 */
154 static void print_timings( GLcontext *ctx )
155 {
156 GLdouble beginendrate;
157 GLdouble vertexrate;
158 GLdouble pointrate;
159 GLdouble linerate;
160 GLdouble polygonrate;
161 GLdouble overhead;
162 GLdouble clearrate;
163 GLdouble swaprate;
164 GLdouble avgvertices;
165
166 if (ctx->BeginEndTime>0.0) {
167 beginendrate = ctx->BeginEndCount / ctx->BeginEndTime;
168 }
169 else {
170 beginendrate = 0.0;
171 }
172 if (ctx->VertexTime>0.0) {
173 vertexrate = ctx->VertexCount / ctx->VertexTime;
174 }
175 else {
176 vertexrate = 0.0;
177 }
178 if (ctx->PointTime>0.0) {
179 pointrate = ctx->PointCount / ctx->PointTime;
180 }
181 else {
182 pointrate = 0.0;
183 }
184 if (ctx->LineTime>0.0) {
185 linerate = ctx->LineCount / ctx->LineTime;
186 }
187 else {
188 linerate = 0.0;
189 }
190 if (ctx->PolygonTime>0.0) {
191 polygonrate = ctx->PolygonCount / ctx->PolygonTime;
192 }
193 else {
194 polygonrate = 0.0;
195 }
196 if (ctx->ClearTime>0.0) {
197 clearrate = ctx->ClearCount / ctx->ClearTime;
198 }
199 else {
200 clearrate = 0.0;
201 }
202 if (ctx->SwapTime>0.0) {
203 swaprate = ctx->SwapCount / ctx->SwapTime;
204 }
205 else {
206 swaprate = 0.0;
207 }
208
209 if (ctx->BeginEndCount>0) {
210 avgvertices = (GLdouble) ctx->VertexCount / (GLdouble) ctx->BeginEndCount;
211 }
212 else {
213 avgvertices = 0.0;
214 }
215
216 overhead = ctx->BeginEndTime - ctx->VertexTime - ctx->PointTime
217 - ctx->LineTime - ctx->PolygonTime;
218
219
220 printf(" Count Time (s) Rate (/s) \n");
221 printf("--------------------------------------------------------\n");
222 printf("glBegin/glEnd %7d %8.3f %10.3f\n",
223 ctx->BeginEndCount, ctx->BeginEndTime, beginendrate);
224 printf(" vertexes transformed %7d %8.3f %10.3f\n",
225 ctx->VertexCount, ctx->VertexTime, vertexrate );
226 printf(" points rasterized %7d %8.3f %10.3f\n",
227 ctx->PointCount, ctx->PointTime, pointrate );
228 printf(" lines rasterized %7d %8.3f %10.3f\n",
229 ctx->LineCount, ctx->LineTime, linerate );
230 printf(" polygons rasterized %7d %8.3f %10.3f\n",
231 ctx->PolygonCount, ctx->PolygonTime, polygonrate );
232 printf(" overhead %8.3f\n", overhead );
233 printf("glClear %7d %8.3f %10.3f\n",
234 ctx->ClearCount, ctx->ClearTime, clearrate );
235 printf("SwapBuffers %7d %8.3f %10.3f\n",
236 ctx->SwapCount, ctx->SwapTime, swaprate );
237 printf("\n");
238
239 printf("Average number of vertices per begin/end: %8.3f\n", avgvertices );
240 }
241 #endif
242
243
244
245
246
247 /**********************************************************************/
248 /***** GL Visual allocation/destruction *****/
249 /**********************************************************************/
250
251
252 /*
253 * Allocate a new GLvisual object.
254 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
255 * alphaFlag - alloc software alpha buffers?
256 * dbFlag - double buffering?
257 * stereoFlag - stereo buffer?
258 * depthFits - requested minimum bits per depth buffer value
259 * stencilFits - requested minimum bits per stencil buffer value
260 * accumFits - requested minimum bits per accum buffer component
261 * indexFits - number of bits per pixel if rgbFlag==GL_FALSE
262 * red/green/blue/alphaFits - number of bits per color component
263 * in frame buffer for RGB(A) mode.
264 * Return: pointer to new GLvisual or NULL if requested parameters can't
265 * be met.
266 */
267 GLvisual *gl_create_visual( GLboolean rgbFlag,
268 GLboolean alphaFlag,
269 GLboolean dbFlag,
270 GLboolean stereoFlag,
271 GLint depthBits,
272 GLint stencilBits,
273 GLint accumBits,
274 GLint indexBits,
275 GLint redBits,
276 GLint greenBits,
277 GLint blueBits,
278 GLint alphaBits )
279 {
280 GLvisual *vis;
281
282 if (depthBits > (GLint) (8*sizeof(GLdepth))) {
283 /* can't meet depth buffer requirements */
284 return NULL;
285 }
286 if (stencilBits > (GLint) (8*sizeof(GLstencil))) {
287 /* can't meet stencil buffer requirements */
288 return NULL;
289 }
290 if (accumBits > (GLint) (8*sizeof(GLaccum))) {
291 /* can't meet accum buffer requirements */
292 return NULL;
293 }
294
295 vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
296 if (!vis) {
297 return NULL;
298 }
299
300 vis->RGBAflag = rgbFlag;
301 vis->DBflag = dbFlag;
302 vis->StereoFlag = stereoFlag;
303 vis->RedBits = redBits;
304 vis->GreenBits = greenBits;
305 vis->BlueBits = blueBits;
306 vis->AlphaBits = alphaFlag ? 8*sizeof(GLubyte) : alphaBits;
307
308 vis->IndexBits = indexBits;
309 vis->DepthBits = (depthBits>0) ? 8*sizeof(GLdepth) : 0;
310 vis->AccumBits = (accumBits>0) ? 8*sizeof(GLaccum) : 0;
311 vis->StencilBits = (stencilBits>0) ? 8*sizeof(GLstencil) : 0;
312
313 vis->SoftwareAlpha = alphaFlag;
314
315 return vis;
316 }
317
318
319
320 void gl_destroy_visual( GLvisual *vis )
321 {
322 FREE( vis );
323 }
324
325
326
327 /**********************************************************************/
328 /***** GL Framebuffer allocation/destruction *****/
329 /**********************************************************************/
330
331
332 /*
333 * Create a new framebuffer. A GLframebuffer is a struct which
334 * encapsulates the depth, stencil and accum buffers and related
335 * parameters.
336 * Input: visual - a GLvisual pointer
337 * softwareDepth - create/use a software depth buffer?
338 * softwareStencil - create/use a software stencil buffer?
339 * softwareAccum - create/use a software accum buffer?
340 * softwareAlpha - create/use a software alpha buffer?
341
342 * Return: pointer to new GLframebuffer struct or NULL if error.
343 */
344 GLframebuffer *gl_create_framebuffer( GLvisual *visual,
345 GLboolean softwareDepth,
346 GLboolean softwareStencil,
347 GLboolean softwareAccum,
348 GLboolean softwareAlpha )
349 {
350 GLframebuffer *buffer;
351
352 buffer = CALLOC_STRUCT(gl_frame_buffer);
353 if (!buffer) {
354 return NULL;
355 }
356
357 /* sanity checks */
358 if (softwareDepth ) {
359 assert(visual->DepthBits > 0);
360 }
361 if (softwareStencil) {
362 assert(visual->StencilBits > 0);
363 }
364 if (softwareAccum) {
365 assert(visual->RGBAflag);
366 assert(visual->AccumBits > 0);
367 }
368 if (softwareAlpha) {
369 assert(visual->RGBAflag);
370 assert(visual->AlphaBits > 0);
371 }
372
373 buffer->Visual = visual;
374 buffer->UseSoftwareDepthBuffer = softwareDepth;
375 buffer->UseSoftwareStencilBuffer = softwareStencil;
376 buffer->UseSoftwareAccumBuffer = softwareAccum;
377 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
378
379 return buffer;
380 }
381
382
383
384 /*
385 * Free a framebuffer struct and its buffers.
386 */
387 void gl_destroy_framebuffer( GLframebuffer *buffer )
388 {
389 if (buffer) {
390 if (buffer->Depth) {
391 FREE( buffer->Depth );
392 }
393 if (buffer->Accum) {
394 FREE( buffer->Accum );
395 }
396 if (buffer->Stencil) {
397 FREE( buffer->Stencil );
398 }
399 if (buffer->FrontLeftAlpha) {
400 FREE( buffer->FrontLeftAlpha );
401 }
402 if (buffer->BackLeftAlpha) {
403 FREE( buffer->BackLeftAlpha );
404 }
405 if (buffer->FrontRightAlpha) {
406 FREE( buffer->FrontRightAlpha );
407 }
408 if (buffer->BackRightAlpha) {
409 FREE( buffer->BackRightAlpha );
410 }
411 FREE(buffer);
412 }
413 }
414
415
416
417 /**********************************************************************/
418 /***** Context allocation, initialization, destroying *****/
419 /**********************************************************************/
420
421
422 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
423
424
425 /*
426 * This function just calls all the various one-time-init functions in Mesa.
427 */
428 static void one_time_init( void )
429 {
430 static GLboolean alreadyCalled = GL_FALSE;
431 _glthread_LOCK_MUTEX(OneTimeLock);
432 if (!alreadyCalled) {
433 /* do some implementation tests */
434 assert( sizeof(GLbyte) == 1 );
435 assert( sizeof(GLshort) >= 2 );
436 assert( sizeof(GLint) >= 4 );
437 assert( sizeof(GLubyte) == 1 );
438 assert( sizeof(GLushort) >= 2 );
439 assert( sizeof(GLuint) >= 4 );
440
441 gl_init_clip();
442 gl_init_eval();
443 _mesa_init_fog();
444 gl_init_math();
445 gl_init_lists();
446 gl_init_shade();
447 gl_init_texture();
448 gl_init_transformation();
449 gl_init_translate();
450 gl_init_vbrender();
451 gl_init_vbxform();
452 gl_init_vertices();
453
454 if (getenv("MESA_DEBUG")) {
455 _glapi_noop_enable_warnings(GL_TRUE);
456 }
457 else {
458 _glapi_noop_enable_warnings(GL_FALSE);
459 }
460
461 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
462 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
463 #endif
464
465 alreadyCalled = GL_TRUE;
466 }
467 _glthread_UNLOCK_MUTEX(OneTimeLock);
468 }
469
470
471
472 /*
473 * Allocate and initialize a shared context state structure.
474 */
475 static struct gl_shared_state *alloc_shared_state( void )
476 {
477 GLuint d;
478 struct gl_shared_state *ss;
479 GLboolean outOfMemory;
480
481 ss = CALLOC_STRUCT(gl_shared_state);
482 if (!ss)
483 return NULL;
484
485 ss->DisplayList = _mesa_NewHashTable();
486
487 ss->TexObjects = _mesa_NewHashTable();
488
489 /* Default Texture objects */
490 outOfMemory = GL_FALSE;
491 for (d = 1 ; d <= 3 ; d++) {
492 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
493 if (!ss->DefaultD[d]) {
494 outOfMemory = GL_TRUE;
495 break;
496 }
497 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
498 }
499
500 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
501 /* Ran out of memory at some point. Free everything and return NULL */
502 if (ss->DisplayList)
503 _mesa_DeleteHashTable(ss->DisplayList);
504 if (ss->TexObjects)
505 _mesa_DeleteHashTable(ss->TexObjects);
506 if (ss->DefaultD[1])
507 gl_free_texture_object(ss, ss->DefaultD[1]);
508 if (ss->DefaultD[2])
509 gl_free_texture_object(ss, ss->DefaultD[2]);
510 if (ss->DefaultD[3])
511 gl_free_texture_object(ss, ss->DefaultD[3]);
512 FREE(ss);
513 return NULL;
514 }
515 else {
516 return ss;
517 }
518 }
519
520
521 /*
522 * Deallocate a shared state context and all children structures.
523 */
524 static void free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
525 {
526 /* Free display lists */
527 while (1) {
528 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
529 if (list) {
530 gl_destroy_list(ctx, list);
531 }
532 else {
533 break;
534 }
535 }
536 _mesa_DeleteHashTable(ss->DisplayList);
537
538 /* Free texture objects */
539 while (ss->TexObjectList)
540 {
541 if (ctx->Driver.DeleteTexture)
542 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
543 /* this function removes from linked list too! */
544 gl_free_texture_object(ss, ss->TexObjectList);
545 }
546 _mesa_DeleteHashTable(ss->TexObjects);
547
548 FREE(ss);
549 }
550
551
552
553 /*
554 * Initialize the nth light. Note that the defaults for light 0 are
555 * different than the other lights.
556 */
557 static void init_light( struct gl_light *l, GLuint n )
558 {
559 make_empty_list( l );
560
561 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
562 if (n==0) {
563 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
564 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
565 }
566 else {
567 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
568 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
569 }
570 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
571 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
572 l->SpotExponent = 0.0;
573 gl_compute_spot_exp_table( l );
574 l->SpotCutoff = 180.0;
575 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
576 l->ConstantAttenuation = 1.0;
577 l->LinearAttenuation = 0.0;
578 l->QuadraticAttenuation = 0.0;
579 l->Enabled = GL_FALSE;
580 }
581
582
583
584 static void init_lightmodel( struct gl_lightmodel *lm )
585 {
586 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
587 lm->LocalViewer = GL_FALSE;
588 lm->TwoSide = GL_FALSE;
589 lm->ColorControl = GL_SINGLE_COLOR;
590 }
591
592
593 static void init_material( struct gl_material *m )
594 {
595 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
596 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
597 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
598 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
599 m->Shininess = 0.0;
600 m->AmbientIndex = 0;
601 m->DiffuseIndex = 1;
602 m->SpecularIndex = 1;
603 }
604
605
606
607 static void init_texture_unit( GLcontext *ctx, GLuint unit )
608 {
609 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
610
611 texUnit->EnvMode = GL_MODULATE;
612 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
613 texUnit->TexGenEnabled = 0;
614 texUnit->GenModeS = GL_EYE_LINEAR;
615 texUnit->GenModeT = GL_EYE_LINEAR;
616 texUnit->GenModeR = GL_EYE_LINEAR;
617 texUnit->GenModeQ = GL_EYE_LINEAR;
618 /* Yes, these plane coefficients are correct! */
619 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
620 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
621 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
622 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
623 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
624 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
625 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
626 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
627
628 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
629 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
630 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
631 }
632
633
634 static void init_fallback_arrays( GLcontext *ctx )
635 {
636 struct gl_client_array *cl;
637 GLuint i;
638
639 cl = &ctx->Fallback.Normal;
640 cl->Size = 3;
641 cl->Type = GL_FLOAT;
642 cl->Stride = 0;
643 cl->StrideB = 0;
644 cl->Ptr = (void *) ctx->Current.Normal;
645 cl->Enabled = 1;
646
647 cl = &ctx->Fallback.Color;
648 cl->Size = 4;
649 cl->Type = GL_UNSIGNED_BYTE;
650 cl->Stride = 0;
651 cl->StrideB = 0;
652 cl->Ptr = (void *) ctx->Current.ByteColor;
653 cl->Enabled = 1;
654
655 cl = &ctx->Fallback.Index;
656 cl->Size = 1;
657 cl->Type = GL_UNSIGNED_INT;
658 cl->Stride = 0;
659 cl->StrideB = 0;
660 cl->Ptr = (void *) &ctx->Current.Index;
661 cl->Enabled = 1;
662
663 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
664 cl = &ctx->Fallback.TexCoord[i];
665 cl->Size = 4;
666 cl->Type = GL_FLOAT;
667 cl->Stride = 0;
668 cl->StrideB = 0;
669 cl->Ptr = (void *) ctx->Current.Texcoord[i];
670 cl->Enabled = 1;
671 }
672
673 cl = &ctx->Fallback.EdgeFlag;
674 cl->Size = 1;
675 cl->Type = GL_UNSIGNED_BYTE;
676 cl->Stride = 0;
677 cl->StrideB = 0;
678 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
679 cl->Enabled = 1;
680 }
681
682
683 /* Initialize a 1-D evaluator map */
684 static void init_1d_map( struct gl_1d_map *map, int n, const float *initial )
685 {
686 map->Order = 1;
687 map->u1 = 0.0;
688 map->u2 = 1.0;
689 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
690 if (map->Points) {
691 GLint i;
692 for (i=0;i<n;i++)
693 map->Points[i] = initial[i];
694 }
695 }
696
697
698 /* Initialize a 2-D evaluator map */
699 static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
700 {
701 map->Uorder = 1;
702 map->Vorder = 1;
703 map->u1 = 0.0;
704 map->u2 = 1.0;
705 map->v1 = 0.0;
706 map->v2 = 1.0;
707 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
708 if (map->Points) {
709 GLint i;
710 for (i=0;i<n;i++)
711 map->Points[i] = initial[i];
712 }
713 }
714
715
716 static void init_color_table( struct gl_color_table *p )
717 {
718 p->Table[0] = 255;
719 p->Table[1] = 255;
720 p->Table[2] = 255;
721 p->Table[3] = 255;
722 p->Size = 1;
723 p->IntFormat = GL_RGBA;
724 p->Format = GL_RGBA;
725 }
726
727
728 /*
729 * Initialize the attribute groups in a GLcontext.
730 */
731 static void init_attrib_groups( GLcontext *ctx )
732 {
733 GLuint i, j;
734
735 assert(ctx);
736
737 /* Constants, may be overriden by device driver */
738 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
739 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
740 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
741 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
742
743 /* Modelview matrix */
744 gl_matrix_ctr( &ctx->ModelView );
745 gl_matrix_alloc_inv( &ctx->ModelView );
746
747 ctx->ModelViewStackDepth = 0;
748 for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
749 gl_matrix_ctr( &ctx->ModelViewStack[i] );
750 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
751 }
752
753 /* Projection matrix - need inv for user clipping in clip space*/
754 gl_matrix_ctr( &ctx->ProjectionMatrix );
755 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
756
757 gl_matrix_ctr( &ctx->ModelProjectMatrix );
758 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
759 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
760
761 ctx->ProjectionStackDepth = 0;
762 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
763 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
764
765 for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
766 gl_matrix_ctr( &ctx->ProjectionStack[i] );
767 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
768 }
769
770 /* Texture matrix */
771 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
772 gl_matrix_ctr( &ctx->TextureMatrix[i] );
773 ctx->TextureStackDepth[i] = 0;
774 for (j = 0 ; j < MAX_TEXTURE_STACK_DEPTH ; j++) {
775 ctx->TextureStack[i][j].inv = 0;
776 }
777 }
778
779 /* Accumulate buffer group */
780 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
781
782 /* Color buffer group */
783 ctx->Color.IndexMask = 0xffffffff;
784 ctx->Color.ColorMask[0] = 0xff;
785 ctx->Color.ColorMask[1] = 0xff;
786 ctx->Color.ColorMask[2] = 0xff;
787 ctx->Color.ColorMask[3] = 0xff;
788 ctx->Color.SWmasking = GL_FALSE;
789 ctx->Color.ClearIndex = 0;
790 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
791 ctx->Color.DrawBuffer = GL_FRONT;
792 ctx->Color.AlphaEnabled = GL_FALSE;
793 ctx->Color.AlphaFunc = GL_ALWAYS;
794 ctx->Color.AlphaRef = 0;
795 ctx->Color.BlendEnabled = GL_FALSE;
796 ctx->Color.BlendSrcRGB = GL_ONE;
797 ctx->Color.BlendDstRGB = GL_ZERO;
798 ctx->Color.BlendSrcA = GL_ONE;
799 ctx->Color.BlendDstA = GL_ZERO;
800 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
801 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
802 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
803 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
804 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
805 ctx->Color.SWLogicOpEnabled = GL_FALSE;
806 ctx->Color.LogicOp = GL_COPY;
807 ctx->Color.DitherFlag = GL_TRUE;
808 ctx->Color.MultiDrawBuffer = GL_FALSE;
809
810 /* Current group */
811 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
812 ctx->Current.Index = 1;
813 for (i=0; i<MAX_TEXTURE_UNITS; i++)
814 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
815 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
816 ctx->Current.RasterDistance = 0.0;
817 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
818 ctx->Current.RasterIndex = 1;
819 for (i=0; i<MAX_TEXTURE_UNITS; i++)
820 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
821 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
822 ctx->Current.RasterPosValid = GL_TRUE;
823 ctx->Current.EdgeFlag = GL_TRUE;
824 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
825 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
826
827 ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
828 VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
829
830 init_fallback_arrays( ctx );
831
832 /* Depth buffer group */
833 ctx->Depth.Test = GL_FALSE;
834 ctx->Depth.Clear = 1.0;
835 ctx->Depth.Func = GL_LESS;
836 ctx->Depth.Mask = GL_TRUE;
837
838 /* Evaluators group */
839 ctx->Eval.Map1Color4 = GL_FALSE;
840 ctx->Eval.Map1Index = GL_FALSE;
841 ctx->Eval.Map1Normal = GL_FALSE;
842 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
843 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
844 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
845 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
846 ctx->Eval.Map1Vertex3 = GL_FALSE;
847 ctx->Eval.Map1Vertex4 = GL_FALSE;
848 ctx->Eval.Map2Color4 = GL_FALSE;
849 ctx->Eval.Map2Index = GL_FALSE;
850 ctx->Eval.Map2Normal = GL_FALSE;
851 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
852 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
853 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
854 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
855 ctx->Eval.Map2Vertex3 = GL_FALSE;
856 ctx->Eval.Map2Vertex4 = GL_FALSE;
857 ctx->Eval.AutoNormal = GL_FALSE;
858 ctx->Eval.MapGrid1un = 1;
859 ctx->Eval.MapGrid1u1 = 0.0;
860 ctx->Eval.MapGrid1u2 = 1.0;
861 ctx->Eval.MapGrid2un = 1;
862 ctx->Eval.MapGrid2vn = 1;
863 ctx->Eval.MapGrid2u1 = 0.0;
864 ctx->Eval.MapGrid2u2 = 1.0;
865 ctx->Eval.MapGrid2v1 = 0.0;
866 ctx->Eval.MapGrid2v2 = 1.0;
867
868 /* Evaluator data */
869 {
870 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
871 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
872 static GLfloat index[1] = { 1.0 };
873 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
874 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
875
876 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
877 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
878 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
879 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
880 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
881 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
882 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
883 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
884 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
885
886 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
887 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
888 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
889 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
890 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
891 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
892 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
893 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
894 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
895 }
896
897 /* Fog group */
898 ctx->Fog.Enabled = GL_FALSE;
899 ctx->Fog.Mode = GL_EXP;
900 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
901 ctx->Fog.Index = 0.0;
902 ctx->Fog.Density = 1.0;
903 ctx->Fog.Start = 0.0;
904 ctx->Fog.End = 1.0;
905
906 /* Hint group */
907 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
908 ctx->Hint.PointSmooth = GL_DONT_CARE;
909 ctx->Hint.LineSmooth = GL_DONT_CARE;
910 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
911 ctx->Hint.Fog = GL_DONT_CARE;
912
913 ctx->Hint.AllowDrawWin = GL_TRUE;
914 ctx->Hint.AllowDrawSpn = GL_TRUE;
915 ctx->Hint.AllowDrawMem = GL_TRUE;
916 ctx->Hint.StrictLighting = GL_TRUE;
917
918 /* Pipeline */
919 gl_pipeline_init( ctx );
920 gl_cva_init( ctx );
921
922 /* Extensions */
923 gl_extensions_ctr( ctx );
924
925 ctx->AllowVertexCull = CLIP_CULLED_BIT;
926
927 /* Lighting group */
928 for (i=0;i<MAX_LIGHTS;i++) {
929 init_light( &ctx->Light.Light[i], i );
930 }
931 make_empty_list( &ctx->Light.EnabledList );
932
933 init_lightmodel( &ctx->Light.Model );
934 init_material( &ctx->Light.Material[0] );
935 init_material( &ctx->Light.Material[1] );
936 ctx->Light.ShadeModel = GL_SMOOTH;
937 ctx->Light.Enabled = GL_FALSE;
938 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
939 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
940 ctx->Light.ColorMaterialBitmask
941 = gl_material_bitmask( ctx,
942 GL_FRONT_AND_BACK,
943 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
944
945 ctx->Light.ColorMaterialEnabled = GL_FALSE;
946
947 /* Lighting miscellaneous */
948 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
949 make_empty_list( ctx->ShineTabList );
950 for (i = 0 ; i < 10 ; i++) {
951 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
952 s->shininess = -1;
953 s->refcount = 0;
954 insert_at_tail( ctx->ShineTabList, s );
955 }
956 for (i = 0 ; i < 4 ; i++) {
957 ctx->ShineTable[i] = ctx->ShineTabList->prev;
958 ctx->ShineTable[i]->refcount++;
959 }
960
961
962 /* Line group */
963 ctx->Line.SmoothFlag = GL_FALSE;
964 ctx->Line.StippleFlag = GL_FALSE;
965 ctx->Line.Width = 1.0;
966 ctx->Line.StipplePattern = 0xffff;
967 ctx->Line.StippleFactor = 1;
968
969 /* Display List group */
970 ctx->List.ListBase = 0;
971
972 /* Pixel group */
973 ctx->Pixel.RedBias = 0.0;
974 ctx->Pixel.RedScale = 1.0;
975 ctx->Pixel.GreenBias = 0.0;
976 ctx->Pixel.GreenScale = 1.0;
977 ctx->Pixel.BlueBias = 0.0;
978 ctx->Pixel.BlueScale = 1.0;
979 ctx->Pixel.AlphaBias = 0.0;
980 ctx->Pixel.AlphaScale = 1.0;
981 ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
982 ctx->Pixel.DepthBias = 0.0;
983 ctx->Pixel.DepthScale = 1.0;
984 ctx->Pixel.IndexOffset = 0;
985 ctx->Pixel.IndexShift = 0;
986 ctx->Pixel.ZoomX = 1.0;
987 ctx->Pixel.ZoomY = 1.0;
988 ctx->Pixel.MapColorFlag = GL_FALSE;
989 ctx->Pixel.MapStencilFlag = GL_FALSE;
990 ctx->Pixel.MapStoSsize = 1;
991 ctx->Pixel.MapItoIsize = 1;
992 ctx->Pixel.MapItoRsize = 1;
993 ctx->Pixel.MapItoGsize = 1;
994 ctx->Pixel.MapItoBsize = 1;
995 ctx->Pixel.MapItoAsize = 1;
996 ctx->Pixel.MapRtoRsize = 1;
997 ctx->Pixel.MapGtoGsize = 1;
998 ctx->Pixel.MapBtoBsize = 1;
999 ctx->Pixel.MapAtoAsize = 1;
1000 ctx->Pixel.MapStoS[0] = 0;
1001 ctx->Pixel.MapItoI[0] = 0;
1002 ctx->Pixel.MapItoR[0] = 0.0;
1003 ctx->Pixel.MapItoG[0] = 0.0;
1004 ctx->Pixel.MapItoB[0] = 0.0;
1005 ctx->Pixel.MapItoA[0] = 0.0;
1006 ctx->Pixel.MapItoR8[0] = 0;
1007 ctx->Pixel.MapItoG8[0] = 0;
1008 ctx->Pixel.MapItoB8[0] = 0;
1009 ctx->Pixel.MapItoA8[0] = 0;
1010 ctx->Pixel.MapRtoR[0] = 0.0;
1011 ctx->Pixel.MapGtoG[0] = 0.0;
1012 ctx->Pixel.MapBtoB[0] = 0.0;
1013 ctx->Pixel.MapAtoA[0] = 0.0;
1014
1015 /* Point group */
1016 ctx->Point.SmoothFlag = GL_FALSE;
1017 ctx->Point.Size = 1.0;
1018 ctx->Point.Params[0] = 1.0;
1019 ctx->Point.Params[1] = 0.0;
1020 ctx->Point.Params[2] = 0.0;
1021 ctx->Point.Attenuated = GL_FALSE;
1022 ctx->Point.MinSize = 0.0;
1023 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1024 ctx->Point.Threshold = 1.0;
1025
1026 /* Polygon group */
1027 ctx->Polygon.CullFlag = GL_FALSE;
1028 ctx->Polygon.CullFaceMode = GL_BACK;
1029 ctx->Polygon.FrontFace = GL_CCW;
1030 ctx->Polygon.FrontBit = 0;
1031 ctx->Polygon.FrontMode = GL_FILL;
1032 ctx->Polygon.BackMode = GL_FILL;
1033 ctx->Polygon.Unfilled = GL_FALSE;
1034 ctx->Polygon.SmoothFlag = GL_FALSE;
1035 ctx->Polygon.StippleFlag = GL_FALSE;
1036 ctx->Polygon.OffsetFactor = 0.0F;
1037 ctx->Polygon.OffsetUnits = 0.0F;
1038 ctx->Polygon.OffsetPoint = GL_FALSE;
1039 ctx->Polygon.OffsetLine = GL_FALSE;
1040 ctx->Polygon.OffsetFill = GL_FALSE;
1041
1042 /* Polygon Stipple group */
1043 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
1044
1045 /* Scissor group */
1046 ctx->Scissor.Enabled = GL_FALSE;
1047 ctx->Scissor.X = 0;
1048 ctx->Scissor.Y = 0;
1049 ctx->Scissor.Width = 0;
1050 ctx->Scissor.Height = 0;
1051
1052 /* Stencil group */
1053 ctx->Stencil.Enabled = GL_FALSE;
1054 ctx->Stencil.Function = GL_ALWAYS;
1055 ctx->Stencil.FailFunc = GL_KEEP;
1056 ctx->Stencil.ZPassFunc = GL_KEEP;
1057 ctx->Stencil.ZFailFunc = GL_KEEP;
1058 ctx->Stencil.Ref = 0;
1059 ctx->Stencil.ValueMask = STENCIL_MAX;
1060 ctx->Stencil.Clear = 0;
1061 ctx->Stencil.WriteMask = STENCIL_MAX;
1062
1063 /* Texture group */
1064 ctx->Texture.CurrentUnit = 0; /* multitexture */
1065 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
1066 ctx->Texture.Enabled = 0;
1067 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1068 init_texture_unit( ctx, i );
1069 init_color_table(&ctx->Texture.Palette);
1070
1071 /* Transformation group */
1072 ctx->Transform.MatrixMode = GL_MODELVIEW;
1073 ctx->Transform.Normalize = GL_FALSE;
1074 ctx->Transform.RescaleNormals = GL_FALSE;
1075 for (i=0;i<MAX_CLIP_PLANES;i++) {
1076 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1077 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1078 }
1079 ctx->Transform.AnyClip = GL_FALSE;
1080
1081 /* Viewport group */
1082 ctx->Viewport.X = 0;
1083 ctx->Viewport.Y = 0;
1084 ctx->Viewport.Width = 0;
1085 ctx->Viewport.Height = 0;
1086 ctx->Viewport.Near = 0.0;
1087 ctx->Viewport.Far = 1.0;
1088 gl_matrix_ctr(&ctx->Viewport.WindowMap);
1089
1090 #define Sz 10
1091 #define Tz 14
1092 ctx->Viewport.WindowMap.m[Sz] = 0.5 * DEPTH_SCALE;
1093 ctx->Viewport.WindowMap.m[Tz] = 0.5 * DEPTH_SCALE;
1094 #undef Sz
1095 #undef Tz
1096
1097 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1098 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
1099
1100 /* Vertex arrays */
1101 ctx->Array.Vertex.Size = 4;
1102 ctx->Array.Vertex.Type = GL_FLOAT;
1103 ctx->Array.Vertex.Stride = 0;
1104 ctx->Array.Vertex.StrideB = 0;
1105 ctx->Array.Vertex.Ptr = NULL;
1106 ctx->Array.Vertex.Enabled = GL_FALSE;
1107 ctx->Array.Normal.Type = GL_FLOAT;
1108 ctx->Array.Normal.Stride = 0;
1109 ctx->Array.Normal.StrideB = 0;
1110 ctx->Array.Normal.Ptr = NULL;
1111 ctx->Array.Normal.Enabled = GL_FALSE;
1112 ctx->Array.Color.Size = 4;
1113 ctx->Array.Color.Type = GL_FLOAT;
1114 ctx->Array.Color.Stride = 0;
1115 ctx->Array.Color.StrideB = 0;
1116 ctx->Array.Color.Ptr = NULL;
1117 ctx->Array.Color.Enabled = GL_FALSE;
1118 ctx->Array.Index.Type = GL_FLOAT;
1119 ctx->Array.Index.Stride = 0;
1120 ctx->Array.Index.StrideB = 0;
1121 ctx->Array.Index.Ptr = NULL;
1122 ctx->Array.Index.Enabled = GL_FALSE;
1123 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1124 ctx->Array.TexCoord[i].Size = 4;
1125 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1126 ctx->Array.TexCoord[i].Stride = 0;
1127 ctx->Array.TexCoord[i].StrideB = 0;
1128 ctx->Array.TexCoord[i].Ptr = NULL;
1129 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1130 }
1131 ctx->Array.TexCoordInterleaveFactor = 1;
1132 ctx->Array.EdgeFlag.Stride = 0;
1133 ctx->Array.EdgeFlag.StrideB = 0;
1134 ctx->Array.EdgeFlag.Ptr = NULL;
1135 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1136 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1137
1138 /* Pixel transfer */
1139 ctx->Pack.Alignment = 4;
1140 ctx->Pack.RowLength = 0;
1141 ctx->Pack.ImageHeight = 0;
1142 ctx->Pack.SkipPixels = 0;
1143 ctx->Pack.SkipRows = 0;
1144 ctx->Pack.SkipImages = 0;
1145 ctx->Pack.SwapBytes = GL_FALSE;
1146 ctx->Pack.LsbFirst = GL_FALSE;
1147 ctx->Unpack.Alignment = 4;
1148 ctx->Unpack.RowLength = 0;
1149 ctx->Unpack.ImageHeight = 0;
1150 ctx->Unpack.SkipPixels = 0;
1151 ctx->Unpack.SkipRows = 0;
1152 ctx->Unpack.SkipImages = 0;
1153 ctx->Unpack.SwapBytes = GL_FALSE;
1154 ctx->Unpack.LsbFirst = GL_FALSE;
1155
1156 /* Feedback */
1157 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1158 ctx->Feedback.Buffer = NULL;
1159 ctx->Feedback.BufferSize = 0;
1160 ctx->Feedback.Count = 0;
1161
1162 /* Selection/picking */
1163 ctx->Select.Buffer = NULL;
1164 ctx->Select.BufferSize = 0;
1165 ctx->Select.BufferCount = 0;
1166 ctx->Select.Hits = 0;
1167 ctx->Select.NameStackDepth = 0;
1168
1169 /* Optimized Accum buffer */
1170 ctx->IntegerAccumMode = GL_TRUE;
1171 ctx->IntegerAccumScaler = 0.0;
1172
1173 /* Renderer and client attribute stacks */
1174 ctx->AttribStackDepth = 0;
1175 ctx->ClientAttribStackDepth = 0;
1176
1177 /* Miscellaneous */
1178 ctx->NewState = NEW_ALL;
1179 ctx->RenderMode = GL_RENDER;
1180 ctx->StippleCounter = 0;
1181 ctx->NeedNormals = GL_FALSE;
1182 ctx->DoViewportMapping = GL_TRUE;
1183
1184 ctx->NeedEyeCoords = GL_FALSE;
1185 ctx->NeedEyeNormals = GL_FALSE;
1186 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1187
1188 /* Display list */
1189 ctx->CallDepth = 0;
1190 ctx->ExecuteFlag = GL_TRUE;
1191 ctx->CompileFlag = GL_FALSE;
1192 ctx->CurrentListPtr = NULL;
1193 ctx->CurrentBlock = NULL;
1194 ctx->CurrentListNum = 0;
1195 ctx->CurrentPos = 0;
1196
1197 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1198
1199 ctx->CatchSignals = GL_TRUE;
1200
1201 /* For debug/development only */
1202 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1203 ctx->FirstTimeCurrent = GL_TRUE;
1204
1205 /* Dither disable */
1206 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1207 if (ctx->NoDither) {
1208 if (getenv("MESA_DEBUG")) {
1209 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
1210 }
1211 ctx->Color.DitherFlag = GL_FALSE;
1212 }
1213 }
1214
1215
1216
1217
1218 /*
1219 * Allocate the proxy textures. If we run out of memory part way through
1220 * the allocations clean up and return GL_FALSE.
1221 * Return: GL_TRUE=success, GL_FALSE=failure
1222 */
1223 static GLboolean alloc_proxy_textures( GLcontext *ctx )
1224 {
1225 GLboolean out_of_memory;
1226 GLint i;
1227
1228 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1229 if (!ctx->Texture.Proxy1D) {
1230 return GL_FALSE;
1231 }
1232
1233 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1234 if (!ctx->Texture.Proxy2D) {
1235 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1236 return GL_FALSE;
1237 }
1238
1239 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1240 if (!ctx->Texture.Proxy3D) {
1241 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1242 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1243 return GL_FALSE;
1244 }
1245
1246 out_of_memory = GL_FALSE;
1247 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1248 ctx->Texture.Proxy1D->Image[i] = gl_alloc_texture_image();
1249 ctx->Texture.Proxy2D->Image[i] = gl_alloc_texture_image();
1250 ctx->Texture.Proxy3D->Image[i] = gl_alloc_texture_image();
1251 if (!ctx->Texture.Proxy1D->Image[i]
1252 || !ctx->Texture.Proxy2D->Image[i]
1253 || !ctx->Texture.Proxy3D->Image[i]) {
1254 out_of_memory = GL_TRUE;
1255 }
1256 }
1257 if (out_of_memory) {
1258 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1259 if (ctx->Texture.Proxy1D->Image[i]) {
1260 gl_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
1261 }
1262 if (ctx->Texture.Proxy2D->Image[i]) {
1263 gl_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
1264 }
1265 if (ctx->Texture.Proxy3D->Image[i]) {
1266 gl_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
1267 }
1268 }
1269 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1270 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1271 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1272 return GL_FALSE;
1273 }
1274 else {
1275 return GL_TRUE;
1276 }
1277 }
1278
1279
1280
1281 /*
1282 * Initialize a GLcontext struct.
1283 */
1284 GLboolean gl_initialize_context_data( GLcontext *ctx,
1285 GLvisual *visual,
1286 GLcontext *share_list,
1287 void *driver_ctx,
1288 GLboolean direct )
1289 {
1290 (void) direct; /* not used */
1291
1292 /* misc one-time initializations */
1293 one_time_init();
1294
1295 ctx->DriverCtx = driver_ctx;
1296 ctx->Visual = visual;
1297 ctx->DrawBuffer = NULL;
1298 ctx->ReadBuffer = NULL;
1299
1300 ctx->VB = gl_vb_create_for_immediate( ctx );
1301 if (!ctx->VB) {
1302 FREE( ctx );
1303 return GL_FALSE;
1304 }
1305 ctx->input = ctx->VB->IM;
1306
1307 ctx->PB = gl_alloc_pb();
1308 if (!ctx->PB) {
1309 FREE( ctx->VB );
1310 FREE( ctx );
1311 return GL_FALSE;
1312 }
1313
1314 if (share_list) {
1315 /* share the group of display lists of another context */
1316 ctx->Shared = share_list->Shared;
1317 }
1318 else {
1319 /* allocate new group of display lists */
1320 ctx->Shared = alloc_shared_state();
1321 if (!ctx->Shared) {
1322 FREE(ctx->VB);
1323 FREE(ctx->PB);
1324 FREE(ctx);
1325 return GL_FALSE;
1326 }
1327 }
1328 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1329 ctx->Shared->RefCount++;
1330 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1331
1332 init_attrib_groups( ctx );
1333
1334 gl_reset_vb( ctx->VB );
1335 gl_reset_input( ctx );
1336
1337 if (visual->DBflag) {
1338 ctx->Color.DrawBuffer = GL_BACK;
1339 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1340 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1341 ctx->Pixel.ReadBuffer = GL_BACK;
1342 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1343 }
1344 else {
1345 ctx->Color.DrawBuffer = GL_FRONT;
1346 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1347 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1348 ctx->Pixel.ReadBuffer = GL_FRONT;
1349 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1350 }
1351
1352 #ifdef PROFILE
1353 init_timings( ctx );
1354 #endif
1355
1356 if (!alloc_proxy_textures(ctx)) {
1357 free_shared_state(ctx, ctx->Shared);
1358 FREE(ctx->VB);
1359 FREE(ctx->PB);
1360 FREE(ctx);
1361 return GL_FALSE;
1362 }
1363
1364 /* setup API dispatch tables */
1365 _mesa_init_exec_table( &ctx->Exec );
1366 _mesa_init_dlist_table( &ctx->Save );
1367 ctx->CurrentDispatch = &ctx->Exec;
1368
1369 return GL_TRUE;
1370 }
1371
1372
1373
1374 /*
1375 * Allocate and initialize a GLcontext structure.
1376 * Input: visual - a GLvisual pointer
1377 * sharelist - another context to share display lists with or NULL
1378 * driver_ctx - pointer to device driver's context state struct
1379 * Return: pointer to a new gl_context struct or NULL if error.
1380 */
1381 GLcontext *gl_create_context( GLvisual *visual,
1382 GLcontext *share_list,
1383 void *driver_ctx,
1384 GLboolean direct )
1385 {
1386 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1387 if (!ctx) {
1388 return NULL;
1389 }
1390
1391 if (gl_initialize_context_data(ctx, visual, share_list,
1392 driver_ctx, direct)) {
1393 return ctx;
1394 }
1395 else {
1396 FREE(ctx);
1397 return NULL;
1398 }
1399 }
1400
1401
1402
1403 /*
1404 * Free the data associated with the given context.
1405 * But don't free() the GLcontext struct itself!
1406 */
1407 void gl_free_context_data( GLcontext *ctx )
1408 {
1409 GLuint i;
1410 struct gl_shine_tab *s, *tmps;
1411
1412 /* if we're destroying the current context, unbind it first */
1413 if (ctx == gl_get_current_context()) {
1414 gl_make_current(NULL, NULL);
1415 }
1416
1417 #ifdef PROFILE
1418 if (getenv("MESA_PROFILE")) {
1419 print_timings( ctx );
1420 }
1421 #endif
1422
1423 gl_matrix_dtr( &ctx->ModelView );
1424 for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
1425 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1426 }
1427 gl_matrix_dtr( &ctx->ProjectionMatrix );
1428 for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
1429 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1430 }
1431
1432 FREE( ctx->PB );
1433
1434 if(ctx->input != ctx->VB->IM)
1435 gl_immediate_free( ctx->input );
1436
1437 gl_vb_free( ctx->VB );
1438
1439 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1440 ctx->Shared->RefCount--;
1441 assert(ctx->Shared->RefCount >= 0);
1442 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1443 if (ctx->Shared->RefCount == 0) {
1444 /* free shared state */
1445 free_shared_state( ctx, ctx->Shared );
1446 }
1447
1448 foreach_s( s, tmps, ctx->ShineTabList ) {
1449 FREE( s );
1450 }
1451 FREE( ctx->ShineTabList );
1452
1453 /* Free proxy texture objects */
1454 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1455 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1456 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1457
1458 /* Free evaluator data */
1459 if (ctx->EvalMap.Map1Vertex3.Points)
1460 FREE( ctx->EvalMap.Map1Vertex3.Points );
1461 if (ctx->EvalMap.Map1Vertex4.Points)
1462 FREE( ctx->EvalMap.Map1Vertex4.Points );
1463 if (ctx->EvalMap.Map1Index.Points)
1464 FREE( ctx->EvalMap.Map1Index.Points );
1465 if (ctx->EvalMap.Map1Color4.Points)
1466 FREE( ctx->EvalMap.Map1Color4.Points );
1467 if (ctx->EvalMap.Map1Normal.Points)
1468 FREE( ctx->EvalMap.Map1Normal.Points );
1469 if (ctx->EvalMap.Map1Texture1.Points)
1470 FREE( ctx->EvalMap.Map1Texture1.Points );
1471 if (ctx->EvalMap.Map1Texture2.Points)
1472 FREE( ctx->EvalMap.Map1Texture2.Points );
1473 if (ctx->EvalMap.Map1Texture3.Points)
1474 FREE( ctx->EvalMap.Map1Texture3.Points );
1475 if (ctx->EvalMap.Map1Texture4.Points)
1476 FREE( ctx->EvalMap.Map1Texture4.Points );
1477
1478 if (ctx->EvalMap.Map2Vertex3.Points)
1479 FREE( ctx->EvalMap.Map2Vertex3.Points );
1480 if (ctx->EvalMap.Map2Vertex4.Points)
1481 FREE( ctx->EvalMap.Map2Vertex4.Points );
1482 if (ctx->EvalMap.Map2Index.Points)
1483 FREE( ctx->EvalMap.Map2Index.Points );
1484 if (ctx->EvalMap.Map2Color4.Points)
1485 FREE( ctx->EvalMap.Map2Color4.Points );
1486 if (ctx->EvalMap.Map2Normal.Points)
1487 FREE( ctx->EvalMap.Map2Normal.Points );
1488 if (ctx->EvalMap.Map2Texture1.Points)
1489 FREE( ctx->EvalMap.Map2Texture1.Points );
1490 if (ctx->EvalMap.Map2Texture2.Points)
1491 FREE( ctx->EvalMap.Map2Texture2.Points );
1492 if (ctx->EvalMap.Map2Texture3.Points)
1493 FREE( ctx->EvalMap.Map2Texture3.Points );
1494 if (ctx->EvalMap.Map2Texture4.Points)
1495 FREE( ctx->EvalMap.Map2Texture4.Points );
1496
1497 /* Free cache of immediate buffers. */
1498 while (ctx->nr_im_queued-- > 0) {
1499 struct immediate * next = ctx->freed_im_queue->next;
1500 FREE( ctx->freed_im_queue );
1501 ctx->freed_im_queue = next;
1502 }
1503 gl_extensions_dtr(ctx);
1504 }
1505
1506
1507
1508 /*
1509 * Destroy a GLcontext structure.
1510 */
1511 void gl_destroy_context( GLcontext *ctx )
1512 {
1513 if (ctx) {
1514 gl_free_context_data(ctx);
1515 FREE( (void *) ctx );
1516 }
1517 }
1518
1519
1520
1521 /*
1522 * Called by the driver after both the context and driver are fully
1523 * initialized. Currently just reads the config file.
1524 */
1525 void gl_context_initialize( GLcontext *ctx )
1526 {
1527 gl_read_config_file( ctx );
1528 }
1529
1530
1531
1532 /*
1533 * Copy attribute groups from one context to another.
1534 * Input: src - source context
1535 * dst - destination context
1536 * mask - bitwise OR of GL_*_BIT flags
1537 */
1538 void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
1539 {
1540 if (mask & GL_ACCUM_BUFFER_BIT) {
1541 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1542 }
1543 if (mask & GL_COLOR_BUFFER_BIT) {
1544 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1545 }
1546 if (mask & GL_CURRENT_BIT) {
1547 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1548 }
1549 if (mask & GL_DEPTH_BUFFER_BIT) {
1550 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1551 }
1552 if (mask & GL_ENABLE_BIT) {
1553 /* no op */
1554 }
1555 if (mask & GL_EVAL_BIT) {
1556 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1557 }
1558 if (mask & GL_FOG_BIT) {
1559 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1560 }
1561 if (mask & GL_HINT_BIT) {
1562 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1563 }
1564 if (mask & GL_LIGHTING_BIT) {
1565 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
1566 /* gl_reinit_light_attrib( &dst->Light ); */
1567 }
1568 if (mask & GL_LINE_BIT) {
1569 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1570 }
1571 if (mask & GL_LIST_BIT) {
1572 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1573 }
1574 if (mask & GL_PIXEL_MODE_BIT) {
1575 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1576 }
1577 if (mask & GL_POINT_BIT) {
1578 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1579 }
1580 if (mask & GL_POLYGON_BIT) {
1581 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1582 }
1583 if (mask & GL_POLYGON_STIPPLE_BIT) {
1584 /* Use loop instead of MEMCPY due to problem with Portland Group's
1585 * C compiler. Reported by John Stone.
1586 */
1587 int i;
1588 for (i=0;i<32;i++) {
1589 dst->PolygonStipple[i] = src->PolygonStipple[i];
1590 }
1591 }
1592 if (mask & GL_SCISSOR_BIT) {
1593 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1594 }
1595 if (mask & GL_STENCIL_BUFFER_BIT) {
1596 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1597 }
1598 if (mask & GL_TEXTURE_BIT) {
1599 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1600 }
1601 if (mask & GL_TRANSFORM_BIT) {
1602 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1603 }
1604 if (mask & GL_VIEWPORT_BIT) {
1605 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1606 }
1607 }
1608
1609
1610 /*
1611 * Set the current context, binding the given frame buffer to the context.
1612 */
1613 void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1614 {
1615 gl_make_current2( newCtx, buffer, buffer );
1616 }
1617
1618
1619 /*
1620 * Bind the given context to the given draw-buffer and read-buffer
1621 * and make it the current context for this thread.
1622 */
1623 void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1624 GLframebuffer *readBuffer )
1625 {
1626 #if 0
1627 GLcontext *oldCtx = gl_get_context();
1628
1629 /* Flush the old context
1630 */
1631 if (oldCtx) {
1632 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
1633
1634 /* unbind frame buffers from context */
1635 if (oldCtx->DrawBuffer) {
1636 oldCtx->DrawBuffer = NULL;
1637 }
1638 if (oldCtx->ReadBuffer) {
1639 oldCtx->ReadBuffer = NULL;
1640 }
1641 }
1642 #endif
1643
1644 /* We call this function periodically (just here for now) in
1645 * order to detect when multithreading has begun.
1646 */
1647 _glapi_check_multithread();
1648
1649 _glapi_set_context((void *) newCtx);
1650 ASSERT(gl_get_current_context() == newCtx);
1651 if (newCtx) {
1652 SET_IMMEDIATE(newCtx, newCtx->input);
1653 _glapi_set_dispatch(newCtx->CurrentDispatch);
1654 }
1655 else {
1656 _glapi_set_dispatch(NULL); /* none current */
1657 }
1658
1659 if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
1660
1661 if (newCtx && drawBuffer && readBuffer) {
1662 /* TODO: check if newCtx and buffer's visual match??? */
1663 newCtx->DrawBuffer = drawBuffer;
1664 newCtx->ReadBuffer = readBuffer;
1665 newCtx->NewState = NEW_ALL; /* just to be safe */
1666 gl_update_state( newCtx );
1667 }
1668
1669 /* We can use this to help debug user's problems. Tell the to set
1670 * the MESA_INFO env variable before running their app. Then the
1671 * first time each context is made current we'll print some useful
1672 * information.
1673 */
1674 if (newCtx && newCtx->FirstTimeCurrent) {
1675 if (getenv("MESA_INFO")) {
1676 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1677 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1678 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1679 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
1680 #if defined(THREADS)
1681 fprintf(stderr, "Mesa thread-safe: YES\n");
1682 #else
1683 fprintf(stderr, "Mesa thread-safe: NO\n");
1684 #endif
1685 #if defined(USE_X86_ASM)
1686 fprintf(stderr, "Mesa x86-optimized: YES\n");
1687 #else
1688 fprintf(stderr, "Mesa x86-optimized: NO\n");
1689 #endif
1690 }
1691 newCtx->FirstTimeCurrent = GL_FALSE;
1692 }
1693 }
1694
1695
1696
1697 /*
1698 * Return current context handle for the calling thread.
1699 * This isn't the fastest way to get the current context.
1700 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1701 */
1702 GLcontext *gl_get_current_context( void )
1703 {
1704 return (GLcontext *) _glapi_get_context();
1705 }
1706
1707
1708
1709 /*
1710 * This should be called by device drivers just before they do a
1711 * swapbuffers. Any pending rendering commands will be executed.
1712 */
1713 void
1714 _mesa_swapbuffers(GLcontext *ctx)
1715 {
1716 FLUSH_VB( ctx, "swap buffers" );
1717 }
1718
1719
1720
1721 /*
1722 * Return pointer to this context's current API dispatch table.
1723 * It'll either be the immediate-mode execute dispatcher or the
1724 * display list compile dispatcher.
1725 */
1726 struct _glapi_table *
1727 _mesa_get_dispatch(GLcontext *ctx)
1728 {
1729 return ctx->CurrentDispatch;
1730 }
1731
1732
1733
1734 /**********************************************************************/
1735 /***** Miscellaneous functions *****/
1736 /**********************************************************************/
1737
1738
1739 /*
1740 * This function is called when the Mesa user has stumbled into a code
1741 * path which may not be implemented fully or correctly.
1742 */
1743 void gl_problem( const GLcontext *ctx, const char *s )
1744 {
1745 fprintf( stderr, "Mesa implementation error: %s\n", s );
1746 fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" );
1747 (void) ctx;
1748 }
1749
1750
1751
1752 /*
1753 * This is called to inform the user that he or she has tried to do
1754 * something illogical or if there's likely a bug in their program
1755 * (like enabled depth testing without a depth buffer).
1756 */
1757 void gl_warning( const GLcontext *ctx, const char *s )
1758 {
1759 GLboolean debug;
1760 #ifdef DEBUG
1761 debug = GL_TRUE;
1762 #else
1763 if (getenv("MESA_DEBUG")) {
1764 debug = GL_TRUE;
1765 }
1766 else {
1767 debug = GL_FALSE;
1768 }
1769 #endif
1770 if (debug) {
1771 fprintf( stderr, "Mesa warning: %s\n", s );
1772 }
1773 (void) ctx;
1774 }
1775
1776
1777
1778 /*
1779 * Compile an error into current display list.
1780 */
1781 void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
1782 {
1783 if (ctx->CompileFlag)
1784 gl_save_error( ctx, error, s );
1785
1786 if (ctx->ExecuteFlag)
1787 gl_error( ctx, error, s );
1788 }
1789
1790
1791
1792 /*
1793 * This is Mesa's error handler. Normally, all that's done is the updating
1794 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1795 * environment variable "MESA_DEBUG" is defined then a real error message
1796 * is printed to stderr.
1797 * Input: error - the error value
1798 * s - a diagnostic string
1799 */
1800 void gl_error( GLcontext *ctx, GLenum error, const char *s )
1801 {
1802 GLboolean debug;
1803
1804 #ifdef DEBUG
1805 debug = GL_TRUE;
1806 #else
1807 if (getenv("MESA_DEBUG")) {
1808 debug = GL_TRUE;
1809 }
1810 else {
1811 debug = GL_FALSE;
1812 }
1813 #endif
1814
1815 if (debug) {
1816 char errstr[1000];
1817
1818 switch (error) {
1819 case GL_NO_ERROR:
1820 strcpy( errstr, "GL_NO_ERROR" );
1821 break;
1822 case GL_INVALID_VALUE:
1823 strcpy( errstr, "GL_INVALID_VALUE" );
1824 break;
1825 case GL_INVALID_ENUM:
1826 strcpy( errstr, "GL_INVALID_ENUM" );
1827 break;
1828 case GL_INVALID_OPERATION:
1829 strcpy( errstr, "GL_INVALID_OPERATION" );
1830 break;
1831 case GL_STACK_OVERFLOW:
1832 strcpy( errstr, "GL_STACK_OVERFLOW" );
1833 break;
1834 case GL_STACK_UNDERFLOW:
1835 strcpy( errstr, "GL_STACK_UNDERFLOW" );
1836 break;
1837 case GL_OUT_OF_MEMORY:
1838 strcpy( errstr, "GL_OUT_OF_MEMORY" );
1839 break;
1840 default:
1841 strcpy( errstr, "unknown" );
1842 break;
1843 }
1844 fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
1845 }
1846
1847 if (ctx->ErrorValue==GL_NO_ERROR) {
1848 ctx->ErrorValue = error;
1849 }
1850
1851 /* Call device driver's error handler, if any. This is used on the Mac. */
1852 if (ctx->Driver.Error) {
1853 (*ctx->Driver.Error)( ctx );
1854 }
1855 }
1856
1857
1858
1859 void
1860 _mesa_Finish( void )
1861 {
1862 GET_CURRENT_CONTEXT(ctx);
1863 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
1864 if (ctx->Driver.Finish) {
1865 (*ctx->Driver.Finish)( ctx );
1866 }
1867 }
1868
1869
1870
1871 void
1872 _mesa_Flush( void )
1873 {
1874 GET_CURRENT_CONTEXT(ctx);
1875 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
1876 if (ctx->Driver.Flush) {
1877 (*ctx->Driver.Flush)( ctx );
1878 }
1879 }