infrastructure for GL_ARB_multisample
[mesa.git] / src / mesa / main / context.c
1 /* $Id: context.c,v 1.139 2001/05/29 15:23:48 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "buffers.h"
33 #include "clip.h"
34 #include "colortab.h"
35 #include "context.h"
36 #include "dlist.h"
37 #include "eval.h"
38 #include "enums.h"
39 #include "extensions.h"
40 #include "fog.h"
41 #include "get.h"
42 #include "glthread.h"
43 #include "hash.h"
44 #include "imports.h"
45 #include "light.h"
46 #include "macros.h"
47 #include "mem.h"
48 #include "mmath.h"
49 #include "simple_list.h"
50 #include "state.h"
51 #include "teximage.h"
52 #include "texobj.h"
53 #include "mtypes.h"
54 #include "varray.h"
55 #include "vtxfmt.h"
56
57 #include "math/m_translate.h"
58 #include "math/m_vertices.h"
59 #include "math/m_matrix.h"
60 #include "math/m_xform.h"
61 #include "math/mathmod.h"
62 #endif
63
64 #if defined(MESA_TRACE)
65 #include "Trace/tr_context.h"
66 #include "Trace/tr_wrapper.h"
67 #endif
68
69
70 #ifndef MESA_VERBOSE
71 int MESA_VERBOSE = 0
72 /* | VERBOSE_PIPELINE */
73 /* | VERBOSE_IMMEDIATE */
74 /* | VERBOSE_VARRAY */
75 /* | VERBOSE_TEXTURE */
76 /* | VERBOSE_API */
77 /* | VERBOSE_DRIVER */
78 /* | VERBOSE_STATE */
79 /* | VERBOSE_DISPLAY_LIST */
80 ;
81 #endif
82
83 #ifndef MESA_DEBUG_FLAGS
84 int MESA_DEBUG_FLAGS = 0
85 /* | DEBUG_ALWAYS_FLUSH */
86 ;
87 #endif
88
89 /**********************************************************************/
90 /***** OpenGL SI-style interface (new in Mesa 3.5) *****/
91 /**********************************************************************/
92
93 static GLboolean
94 _mesa_DestroyContext(__GLcontext *gc)
95 {
96 if (gc) {
97 _mesa_free_context_data(gc);
98 (*gc->imports.free)(gc, gc);
99 }
100 return GL_TRUE;
101 }
102
103
104 /* exported OpenGL SI interface */
105 __GLcontext *
106 __glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
107 {
108 GLcontext *ctx;
109
110 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
111 if (ctx == NULL) {
112 return NULL;
113 }
114 ctx->imports = *imports;
115
116 _mesa_initialize_visual(&ctx->Visual,
117 modes->rgbMode,
118 modes->doubleBufferMode,
119 modes->stereoMode,
120 modes->redBits,
121 modes->greenBits,
122 modes->blueBits,
123 modes->alphaBits,
124 modes->indexBits,
125 modes->depthBits,
126 modes->stencilBits,
127 modes->accumRedBits,
128 modes->accumGreenBits,
129 modes->accumBlueBits,
130 modes->accumAlphaBits,
131 0);
132
133 /* KW: was imports->wscx */
134 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
135
136 ctx->exports.destroyContext = _mesa_DestroyContext;
137
138 return ctx;
139 }
140
141
142 /* exported OpenGL SI interface */
143 void
144 __glCoreNopDispatch(void)
145 {
146 #if 0
147 /* SI */
148 __gl_dispatch = __glNopDispatchState;
149 #else
150 /* Mesa */
151 _glapi_set_dispatch(NULL);
152 #endif
153 }
154
155
156 /**********************************************************************/
157 /***** Context and Thread management *****/
158 /**********************************************************************/
159
160
161
162 /**********************************************************************/
163 /***** GL Visual allocation/destruction *****/
164 /**********************************************************************/
165
166
167 /*
168 * Allocate a new GLvisual object.
169 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
170 * dbFlag - double buffering?
171 * stereoFlag - stereo buffer?
172 * depthBits - requested bits per depth buffer value
173 * Any value in [0, 32] is acceptable but the actual
174 * depth type will be GLushort or GLuint as needed.
175 * stencilBits - requested minimum bits per stencil buffer value
176 * accumBits - requested minimum bits per accum buffer component
177 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
178 * red/green/blue/alphaBits - number of bits per color component
179 * in frame buffer for RGB(A) mode.
180 * We always use 8 in core Mesa though.
181 * Return: pointer to new GLvisual or NULL if requested parameters can't
182 * be met.
183 */
184 GLvisual *
185 _mesa_create_visual( GLboolean rgbFlag,
186 GLboolean dbFlag,
187 GLboolean stereoFlag,
188 GLint redBits,
189 GLint greenBits,
190 GLint blueBits,
191 GLint alphaBits,
192 GLint indexBits,
193 GLint depthBits,
194 GLint stencilBits,
195 GLint accumRedBits,
196 GLint accumGreenBits,
197 GLint accumBlueBits,
198 GLint accumAlphaBits,
199 GLint numSamples )
200 {
201 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
202 if (vis) {
203 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
204 redBits, greenBits, blueBits, alphaBits,
205 indexBits, depthBits, stencilBits,
206 accumRedBits, accumGreenBits,
207 accumBlueBits, accumAlphaBits,
208 numSamples)) {
209 FREE(vis);
210 return NULL;
211 }
212 }
213 return vis;
214 }
215
216
217 /*
218 * Initialize the fields of the given GLvisual.
219 * Input: see _mesa_create_visual() above.
220 * Return: GL_TRUE = success
221 * GL_FALSE = failure.
222 */
223 GLboolean
224 _mesa_initialize_visual( GLvisual *vis,
225 GLboolean rgbFlag,
226 GLboolean dbFlag,
227 GLboolean stereoFlag,
228 GLint redBits,
229 GLint greenBits,
230 GLint blueBits,
231 GLint alphaBits,
232 GLint indexBits,
233 GLint depthBits,
234 GLint stencilBits,
235 GLint accumRedBits,
236 GLint accumGreenBits,
237 GLint accumBlueBits,
238 GLint accumAlphaBits,
239 GLint numSamples )
240 {
241 (void) numSamples;
242
243 assert(vis);
244
245 /* This is to catch bad values from device drivers not updated for
246 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
247 * bad value now (a 1-bit depth buffer!?!).
248 */
249 assert(depthBits == 0 || depthBits > 1);
250
251 if (depthBits < 0 || depthBits > 32) {
252 return GL_FALSE;
253 }
254 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
255 return GL_FALSE;
256 }
257 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
258 return GL_FALSE;
259 }
260 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
261 return GL_FALSE;
262 }
263 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
264 return GL_FALSE;
265 }
266 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
267 return GL_FALSE;
268 }
269
270 vis->rgbMode = rgbFlag;
271 vis->doubleBufferMode = dbFlag;
272 vis->stereoMode = stereoFlag;
273 vis->redBits = redBits;
274 vis->greenBits = greenBits;
275 vis->blueBits = blueBits;
276 vis->alphaBits = alphaBits;
277
278 vis->indexBits = indexBits;
279 vis->depthBits = depthBits;
280 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
281 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
282 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
283 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
284 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
285
286 return GL_TRUE;
287 }
288
289
290 void
291 _mesa_destroy_visual( GLvisual *vis )
292 {
293 FREE(vis);
294 }
295
296
297 /**********************************************************************/
298 /***** GL Framebuffer allocation/destruction *****/
299 /**********************************************************************/
300
301
302 /*
303 * Create a new framebuffer. A GLframebuffer is a struct which
304 * encapsulates the depth, stencil and accum buffers and related
305 * parameters.
306 * Input: visual - a GLvisual pointer (we copy the struct contents)
307 * softwareDepth - create/use a software depth buffer?
308 * softwareStencil - create/use a software stencil buffer?
309 * softwareAccum - create/use a software accum buffer?
310 * softwareAlpha - create/use a software alpha buffer?
311 * Return: pointer to new GLframebuffer struct or NULL if error.
312 */
313 GLframebuffer *
314 _mesa_create_framebuffer( const GLvisual *visual,
315 GLboolean softwareDepth,
316 GLboolean softwareStencil,
317 GLboolean softwareAccum,
318 GLboolean softwareAlpha )
319 {
320 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
321 assert(visual);
322 if (buffer) {
323 _mesa_initialize_framebuffer(buffer, visual,
324 softwareDepth, softwareStencil,
325 softwareAccum, softwareAlpha );
326 }
327 return buffer;
328 }
329
330
331 /*
332 * Initialize a GLframebuffer object.
333 * Input: See _mesa_create_framebuffer() above.
334 */
335 void
336 _mesa_initialize_framebuffer( GLframebuffer *buffer,
337 const GLvisual *visual,
338 GLboolean softwareDepth,
339 GLboolean softwareStencil,
340 GLboolean softwareAccum,
341 GLboolean softwareAlpha )
342 {
343 assert(buffer);
344 assert(visual);
345
346 /* sanity checks */
347 if (softwareDepth ) {
348 assert(visual->depthBits > 0);
349 }
350 if (softwareStencil) {
351 assert(visual->stencilBits > 0);
352 }
353 if (softwareAccum) {
354 assert(visual->rgbMode);
355 assert(visual->accumRedBits > 0);
356 assert(visual->accumGreenBits > 0);
357 assert(visual->accumBlueBits > 0);
358 }
359 if (softwareAlpha) {
360 assert(visual->rgbMode);
361 assert(visual->alphaBits > 0);
362 }
363
364 buffer->Visual = *visual;
365 buffer->UseSoftwareDepthBuffer = softwareDepth;
366 buffer->UseSoftwareStencilBuffer = softwareStencil;
367 buffer->UseSoftwareAccumBuffer = softwareAccum;
368 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
369 }
370
371
372 /*
373 * Free a framebuffer struct and its buffers.
374 */
375 void
376 _mesa_destroy_framebuffer( GLframebuffer *buffer )
377 {
378 if (buffer) {
379 _mesa_free_framebuffer_data(buffer);
380 FREE(buffer);
381 }
382 }
383
384
385 /*
386 * Free the data hanging off of <buffer>, but not <buffer> itself.
387 */
388 void
389 _mesa_free_framebuffer_data( GLframebuffer *buffer )
390 {
391 if (!buffer)
392 return;
393
394 if (buffer->DepthBuffer) {
395 FREE( buffer->DepthBuffer );
396 buffer->DepthBuffer = NULL;
397 }
398 if (buffer->Accum) {
399 FREE( buffer->Accum );
400 buffer->Accum = NULL;
401 }
402 if (buffer->Stencil) {
403 FREE( buffer->Stencil );
404 buffer->Stencil = NULL;
405 }
406 if (buffer->FrontLeftAlpha) {
407 FREE( buffer->FrontLeftAlpha );
408 buffer->FrontLeftAlpha = NULL;
409 }
410 if (buffer->BackLeftAlpha) {
411 FREE( buffer->BackLeftAlpha );
412 buffer->BackLeftAlpha = NULL;
413 }
414 if (buffer->FrontRightAlpha) {
415 FREE( buffer->FrontRightAlpha );
416 buffer->FrontRightAlpha = NULL;
417 }
418 if (buffer->BackRightAlpha) {
419 FREE( buffer->BackRightAlpha );
420 buffer->BackRightAlpha = NULL;
421 }
422 }
423
424
425
426 /**********************************************************************/
427 /***** Context allocation, initialization, destroying *****/
428 /**********************************************************************/
429
430
431 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
432
433
434 /*
435 * This function just calls all the various one-time-init functions in Mesa.
436 */
437 static void
438 one_time_init( void )
439 {
440 static GLboolean alreadyCalled = GL_FALSE;
441 _glthread_LOCK_MUTEX(OneTimeLock);
442 if (!alreadyCalled) {
443 /* do some implementation tests */
444 assert( sizeof(GLbyte) == 1 );
445 assert( sizeof(GLshort) >= 2 );
446 assert( sizeof(GLint) >= 4 );
447 assert( sizeof(GLubyte) == 1 );
448 assert( sizeof(GLushort) >= 2 );
449 assert( sizeof(GLuint) >= 4 );
450
451 _mesa_init_lists();
452
453 _math_init();
454 _mesa_init_math();
455
456 if (getenv("MESA_DEBUG")) {
457 _glapi_noop_enable_warnings(GL_TRUE);
458 }
459 else {
460 _glapi_noop_enable_warnings(GL_FALSE);
461 }
462
463 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
464 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
465 #endif
466
467 alreadyCalled = GL_TRUE;
468 }
469 _glthread_UNLOCK_MUTEX(OneTimeLock);
470 }
471
472
473
474 /*
475 * Allocate and initialize a shared context state structure.
476 */
477 static struct gl_shared_state *
478 alloc_shared_state( void )
479 {
480 struct gl_shared_state *ss;
481 GLboolean outOfMemory;
482
483 ss = CALLOC_STRUCT(gl_shared_state);
484 if (!ss)
485 return NULL;
486
487 _glthread_INIT_MUTEX(ss->Mutex);
488
489 ss->DisplayList = _mesa_NewHashTable();
490 ss->TexObjects = _mesa_NewHashTable();
491
492 /* Default Texture objects */
493 outOfMemory = GL_FALSE;
494
495 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
496 if (!ss->Default1D) {
497 outOfMemory = GL_TRUE;
498 }
499
500 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
501 if (!ss->Default2D) {
502 outOfMemory = GL_TRUE;
503 }
504
505 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
506 if (!ss->Default3D) {
507 outOfMemory = GL_TRUE;
508 }
509
510 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
511 if (!ss->DefaultCubeMap) {
512 outOfMemory = GL_TRUE;
513 }
514
515 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
516 /* Ran out of memory at some point. Free everything and return NULL */
517 if (ss->DisplayList)
518 _mesa_DeleteHashTable(ss->DisplayList);
519 if (ss->TexObjects)
520 _mesa_DeleteHashTable(ss->TexObjects);
521 if (ss->Default1D)
522 _mesa_free_texture_object(ss, ss->Default1D);
523 if (ss->Default2D)
524 _mesa_free_texture_object(ss, ss->Default2D);
525 if (ss->Default3D)
526 _mesa_free_texture_object(ss, ss->Default3D);
527 if (ss->DefaultCubeMap)
528 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
529 FREE(ss);
530 return NULL;
531 }
532 else {
533 return ss;
534 }
535 }
536
537
538 /*
539 * Deallocate a shared state context and all children structures.
540 */
541 static void
542 free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
543 {
544 /* Free display lists */
545 while (1) {
546 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
547 if (list) {
548 _mesa_destroy_list(ctx, list);
549 }
550 else {
551 break;
552 }
553 }
554 _mesa_DeleteHashTable(ss->DisplayList);
555
556 /* Free texture objects */
557 while (ss->TexObjectList) {
558 if (ctx->Driver.DeleteTexture)
559 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
560 /* this function removes from linked list too! */
561 _mesa_free_texture_object(ss, ss->TexObjectList);
562 }
563 _mesa_DeleteHashTable(ss->TexObjects);
564
565 FREE(ss);
566 }
567
568
569
570 /*
571 * Initialize the nth light. Note that the defaults for light 0 are
572 * different than the other lights.
573 */
574 static void
575 init_light( struct gl_light *l, GLuint n )
576 {
577 make_empty_list( l );
578
579 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
580 if (n==0) {
581 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
582 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
583 }
584 else {
585 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
586 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
587 }
588 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
589 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
590 l->SpotExponent = 0.0;
591 _mesa_invalidate_spot_exp_table( l );
592 l->SpotCutoff = 180.0;
593 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
594 l->ConstantAttenuation = 1.0;
595 l->LinearAttenuation = 0.0;
596 l->QuadraticAttenuation = 0.0;
597 l->Enabled = GL_FALSE;
598 }
599
600
601
602 static void
603 init_lightmodel( struct gl_lightmodel *lm )
604 {
605 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
606 lm->LocalViewer = GL_FALSE;
607 lm->TwoSide = GL_FALSE;
608 lm->ColorControl = GL_SINGLE_COLOR;
609 }
610
611
612 static void
613 init_material( struct gl_material *m )
614 {
615 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
616 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
617 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
618 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
619 m->Shininess = 0.0;
620 m->AmbientIndex = 0;
621 m->DiffuseIndex = 1;
622 m->SpecularIndex = 1;
623 }
624
625
626
627 static void
628 init_texture_unit( GLcontext *ctx, GLuint unit )
629 {
630 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
631
632 texUnit->EnvMode = GL_MODULATE;
633 texUnit->CombineModeRGB = GL_MODULATE;
634 texUnit->CombineModeA = GL_MODULATE;
635 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
636 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
637 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
638 texUnit->CombineSourceA[0] = GL_TEXTURE;
639 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
640 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
641 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
642 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
643 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
644 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
645 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
646 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
647 texUnit->CombineScaleShiftRGB = 0;
648 texUnit->CombineScaleShiftA = 0;
649
650 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
651 texUnit->TexGenEnabled = 0;
652 texUnit->GenModeS = GL_EYE_LINEAR;
653 texUnit->GenModeT = GL_EYE_LINEAR;
654 texUnit->GenModeR = GL_EYE_LINEAR;
655 texUnit->GenModeQ = GL_EYE_LINEAR;
656 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
657 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
658 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
659 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
660
661 /* Yes, these plane coefficients are correct! */
662 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
664 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
665 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
666 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
667 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
668 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
669 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
670
671 texUnit->Current1D = ctx->Shared->Default1D;
672 texUnit->Current2D = ctx->Shared->Default2D;
673 texUnit->Current3D = ctx->Shared->Default3D;
674 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
675 }
676
677
678
679
680 /* Initialize a 1-D evaluator map */
681 static void
682 init_1d_map( struct gl_1d_map *map, int n, const float *initial )
683 {
684 map->Order = 1;
685 map->u1 = 0.0;
686 map->u2 = 1.0;
687 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
688 if (map->Points) {
689 GLint i;
690 for (i=0;i<n;i++)
691 map->Points[i] = initial[i];
692 }
693 }
694
695
696 /* Initialize a 2-D evaluator map */
697 static void
698 init_2d_map( struct gl_2d_map *map, int n, const float *initial )
699 {
700 map->Uorder = 1;
701 map->Vorder = 1;
702 map->u1 = 0.0;
703 map->u2 = 1.0;
704 map->v1 = 0.0;
705 map->v2 = 1.0;
706 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
707 if (map->Points) {
708 GLint i;
709 for (i=0;i<n;i++)
710 map->Points[i] = initial[i];
711 }
712 }
713
714
715 /*
716 * Initialize the attribute groups in a GLcontext.
717 */
718 static void
719 init_attrib_groups( GLcontext *ctx )
720 {
721 GLuint i, j;
722
723 assert(ctx);
724
725 /* Constants, may be overriden by device drivers */
726 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
727 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
728 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
729 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
730 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
731 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
732 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
733 ctx->Const.MinPointSize = MIN_POINT_SIZE;
734 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
735 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
736 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
737 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
738 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
739 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
740 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
741 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
742 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
743 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
744 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
745 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
746 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
747 ctx->Const.NumCompressedTextureFormats = 0;
748 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
749 ctx->Const.MaxLights = MAX_LIGHTS;
750
751 /* Modelview matrix */
752 _math_matrix_ctr( &ctx->ModelView );
753 _math_matrix_alloc_inv( &ctx->ModelView );
754
755 ctx->ModelViewStackDepth = 0;
756 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
757 _math_matrix_ctr( &ctx->ModelViewStack[i] );
758 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
759 }
760
761 /* Projection matrix - need inv for user clipping in clip space*/
762 _math_matrix_ctr( &ctx->ProjectionMatrix );
763 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
764
765 ctx->ProjectionStackDepth = 0;
766 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
767 _math_matrix_ctr( &ctx->ProjectionStack[i] );
768 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
769 }
770
771 /* Derived ModelProject matrix */
772 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
773
774 /* Texture matrix */
775 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
776 _math_matrix_ctr( &ctx->TextureMatrix[i] );
777 ctx->TextureStackDepth[i] = 0;
778 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
779 _math_matrix_ctr( &ctx->TextureStack[i][j] );
780 ctx->TextureStack[i][j].inv = 0;
781 }
782 }
783
784 /* Color matrix */
785 _math_matrix_ctr(&ctx->ColorMatrix);
786 ctx->ColorStackDepth = 0;
787 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
788 _math_matrix_ctr(&ctx->ColorStack[j]);
789 }
790
791 /* Accumulate buffer group */
792 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
793
794 /* Color buffer group */
795 ctx->Color.IndexMask = 0xffffffff;
796 ctx->Color.ColorMask[0] = 0xff;
797 ctx->Color.ColorMask[1] = 0xff;
798 ctx->Color.ColorMask[2] = 0xff;
799 ctx->Color.ColorMask[3] = 0xff;
800 ctx->Color.ClearIndex = 0;
801 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
802 ctx->Color.DrawBuffer = GL_FRONT;
803 ctx->Color.AlphaEnabled = GL_FALSE;
804 ctx->Color.AlphaFunc = GL_ALWAYS;
805 ctx->Color.AlphaRef = 0;
806 ctx->Color.BlendEnabled = GL_FALSE;
807 ctx->Color.BlendSrcRGB = GL_ONE;
808 ctx->Color.BlendDstRGB = GL_ZERO;
809 ctx->Color.BlendSrcA = GL_ONE;
810 ctx->Color.BlendDstA = GL_ZERO;
811 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
812 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
813 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
814 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
815 ctx->Color.LogicOp = GL_COPY;
816 ctx->Color.DitherFlag = GL_TRUE;
817 ctx->Color.MultiDrawBuffer = GL_FALSE;
818
819 /* Current group */
820 ASSIGN_4V( ctx->Current.Color, 1.0, 1.0, 1.0, 1.0 );
821 ctx->Current.Index = 1;
822 for (i=0; i<MAX_TEXTURE_UNITS; i++)
823 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
824 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
825 ctx->Current.RasterDistance = 0.0;
826 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
827 ctx->Current.RasterIndex = 1;
828 for (i=0; i<MAX_TEXTURE_UNITS; i++)
829 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
830 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
831 ctx->Current.RasterPosValid = GL_TRUE;
832 ctx->Current.EdgeFlag = GL_TRUE;
833 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
834
835
836 /* Depth buffer group */
837 ctx->Depth.Test = GL_FALSE;
838 ctx->Depth.Clear = 1.0;
839 ctx->Depth.Func = GL_LESS;
840 ctx->Depth.Mask = GL_TRUE;
841 ctx->Depth.OcclusionTest = GL_FALSE;
842
843 /* Evaluators group */
844 ctx->Eval.Map1Color4 = GL_FALSE;
845 ctx->Eval.Map1Index = GL_FALSE;
846 ctx->Eval.Map1Normal = GL_FALSE;
847 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
848 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
849 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
850 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
851 ctx->Eval.Map1Vertex3 = GL_FALSE;
852 ctx->Eval.Map1Vertex4 = GL_FALSE;
853 ctx->Eval.Map2Color4 = GL_FALSE;
854 ctx->Eval.Map2Index = GL_FALSE;
855 ctx->Eval.Map2Normal = GL_FALSE;
856 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
857 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
858 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
859 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
860 ctx->Eval.Map2Vertex3 = GL_FALSE;
861 ctx->Eval.Map2Vertex4 = GL_FALSE;
862 ctx->Eval.AutoNormal = GL_FALSE;
863 ctx->Eval.MapGrid1un = 1;
864 ctx->Eval.MapGrid1u1 = 0.0;
865 ctx->Eval.MapGrid1u2 = 1.0;
866 ctx->Eval.MapGrid2un = 1;
867 ctx->Eval.MapGrid2vn = 1;
868 ctx->Eval.MapGrid2u1 = 0.0;
869 ctx->Eval.MapGrid2u2 = 1.0;
870 ctx->Eval.MapGrid2v1 = 0.0;
871 ctx->Eval.MapGrid2v2 = 1.0;
872
873 /* Evaluator data */
874 {
875 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
876 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
877 static GLfloat index[1] = { 1.0 };
878 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
879 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
880
881 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
882 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
883 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
884 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
885 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
886 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
887 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
888 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
889 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
890
891 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
892 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
893 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
894 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
895 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
896 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
897 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
898 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
899 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
900 }
901
902 /* Fog group */
903 ctx->Fog.Enabled = GL_FALSE;
904 ctx->Fog.Mode = GL_EXP;
905 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
906 ctx->Fog.Index = 0.0;
907 ctx->Fog.Density = 1.0;
908 ctx->Fog.Start = 0.0;
909 ctx->Fog.End = 1.0;
910 ctx->Fog.ColorSumEnabled = GL_FALSE;
911 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
912
913 /* Hint group */
914 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
915 ctx->Hint.PointSmooth = GL_DONT_CARE;
916 ctx->Hint.LineSmooth = GL_DONT_CARE;
917 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
918 ctx->Hint.Fog = GL_DONT_CARE;
919 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
920 ctx->Hint.TextureCompression = GL_DONT_CARE;
921 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
922
923 /* Histogram group */
924 ctx->Histogram.Width = 0;
925 ctx->Histogram.Format = GL_RGBA;
926 ctx->Histogram.Sink = GL_FALSE;
927 ctx->Histogram.RedSize = 0;
928 ctx->Histogram.GreenSize = 0;
929 ctx->Histogram.BlueSize = 0;
930 ctx->Histogram.AlphaSize = 0;
931 ctx->Histogram.LuminanceSize = 0;
932 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
933 ctx->Histogram.Count[i][0] = 0;
934 ctx->Histogram.Count[i][1] = 0;
935 ctx->Histogram.Count[i][2] = 0;
936 ctx->Histogram.Count[i][3] = 0;
937 }
938
939 /* Min/Max group */
940 ctx->MinMax.Format = GL_RGBA;
941 ctx->MinMax.Sink = GL_FALSE;
942 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
943 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
944 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
945 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
946
947 /* Extensions */
948 _mesa_extensions_ctr( ctx );
949
950 /* Lighting group */
951 for (i=0;i<MAX_LIGHTS;i++) {
952 init_light( &ctx->Light.Light[i], i );
953 }
954 make_empty_list( &ctx->Light.EnabledList );
955
956 init_lightmodel( &ctx->Light.Model );
957 init_material( &ctx->Light.Material[0] );
958 init_material( &ctx->Light.Material[1] );
959 ctx->Light.ShadeModel = GL_SMOOTH;
960 ctx->Light.Enabled = GL_FALSE;
961 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
962 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
963 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
964 GL_FRONT_AND_BACK,
965 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
966
967 ctx->Light.ColorMaterialEnabled = GL_FALSE;
968
969 /* Lighting miscellaneous */
970 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
971 make_empty_list( ctx->_ShineTabList );
972 for (i = 0 ; i < 10 ; i++) {
973 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
974 s->shininess = -1;
975 s->refcount = 0;
976 insert_at_tail( ctx->_ShineTabList, s );
977 }
978
979
980 /* Line group */
981 ctx->Line.SmoothFlag = GL_FALSE;
982 ctx->Line.StippleFlag = GL_FALSE;
983 ctx->Line.Width = 1.0;
984 ctx->Line._Width = 1.0;
985 ctx->Line.StipplePattern = 0xffff;
986 ctx->Line.StippleFactor = 1;
987
988 /* Display List group */
989 ctx->List.ListBase = 0;
990
991 /* Multisample */
992 ctx->Multisample.Enabled = GL_FALSE;
993 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
994 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
995 ctx->Multisample.SampleCoverage = GL_FALSE;
996 ctx->Multisample.SampleCoverageValue = 1.0;
997 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
998
999 /* Pixel group */
1000 ctx->Pixel.RedBias = 0.0;
1001 ctx->Pixel.RedScale = 1.0;
1002 ctx->Pixel.GreenBias = 0.0;
1003 ctx->Pixel.GreenScale = 1.0;
1004 ctx->Pixel.BlueBias = 0.0;
1005 ctx->Pixel.BlueScale = 1.0;
1006 ctx->Pixel.AlphaBias = 0.0;
1007 ctx->Pixel.AlphaScale = 1.0;
1008 ctx->Pixel.DepthBias = 0.0;
1009 ctx->Pixel.DepthScale = 1.0;
1010 ctx->Pixel.IndexOffset = 0;
1011 ctx->Pixel.IndexShift = 0;
1012 ctx->Pixel.ZoomX = 1.0;
1013 ctx->Pixel.ZoomY = 1.0;
1014 ctx->Pixel.MapColorFlag = GL_FALSE;
1015 ctx->Pixel.MapStencilFlag = GL_FALSE;
1016 ctx->Pixel.MapStoSsize = 1;
1017 ctx->Pixel.MapItoIsize = 1;
1018 ctx->Pixel.MapItoRsize = 1;
1019 ctx->Pixel.MapItoGsize = 1;
1020 ctx->Pixel.MapItoBsize = 1;
1021 ctx->Pixel.MapItoAsize = 1;
1022 ctx->Pixel.MapRtoRsize = 1;
1023 ctx->Pixel.MapGtoGsize = 1;
1024 ctx->Pixel.MapBtoBsize = 1;
1025 ctx->Pixel.MapAtoAsize = 1;
1026 ctx->Pixel.MapStoS[0] = 0;
1027 ctx->Pixel.MapItoI[0] = 0;
1028 ctx->Pixel.MapItoR[0] = 0.0;
1029 ctx->Pixel.MapItoG[0] = 0.0;
1030 ctx->Pixel.MapItoB[0] = 0.0;
1031 ctx->Pixel.MapItoA[0] = 0.0;
1032 ctx->Pixel.MapItoR8[0] = 0;
1033 ctx->Pixel.MapItoG8[0] = 0;
1034 ctx->Pixel.MapItoB8[0] = 0;
1035 ctx->Pixel.MapItoA8[0] = 0;
1036 ctx->Pixel.MapRtoR[0] = 0.0;
1037 ctx->Pixel.MapGtoG[0] = 0.0;
1038 ctx->Pixel.MapBtoB[0] = 0.0;
1039 ctx->Pixel.MapAtoA[0] = 0.0;
1040 ctx->Pixel.HistogramEnabled = GL_FALSE;
1041 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1042 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1043 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1044 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
1045 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1046 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1047 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1048 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
1049 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1050 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1051 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1052 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
1053 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1054 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1055 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
1056 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1057 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1058 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1059 for (i = 0; i < 3; i++) {
1060 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1061 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1062 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1063 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1064 }
1065 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1066 ctx->Convolution1D.Filter[i] = 0.0;
1067 ctx->Convolution2D.Filter[i] = 0.0;
1068 ctx->Separable2D.Filter[i] = 0.0;
1069 }
1070 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1071 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
1072
1073 /* Point group */
1074 ctx->Point.SmoothFlag = GL_FALSE;
1075 ctx->Point.Size = 1.0;
1076 ctx->Point._Size = 1.0;
1077 ctx->Point.Params[0] = 1.0;
1078 ctx->Point.Params[1] = 0.0;
1079 ctx->Point.Params[2] = 0.0;
1080 ctx->Point._Attenuated = GL_FALSE;
1081 ctx->Point.MinSize = 0.0;
1082 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
1083 ctx->Point.Threshold = 1.0;
1084 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
1085
1086 /* Polygon group */
1087 ctx->Polygon.CullFlag = GL_FALSE;
1088 ctx->Polygon.CullFaceMode = GL_BACK;
1089 ctx->Polygon.FrontFace = GL_CCW;
1090 ctx->Polygon._FrontBit = 0;
1091 ctx->Polygon.FrontMode = GL_FILL;
1092 ctx->Polygon.BackMode = GL_FILL;
1093 ctx->Polygon.SmoothFlag = GL_FALSE;
1094 ctx->Polygon.StippleFlag = GL_FALSE;
1095 ctx->Polygon.OffsetFactor = 0.0F;
1096 ctx->Polygon.OffsetUnits = 0.0F;
1097 ctx->Polygon.OffsetMRD = 0.0F;
1098 ctx->Polygon.OffsetPoint = GL_FALSE;
1099 ctx->Polygon.OffsetLine = GL_FALSE;
1100 ctx->Polygon.OffsetFill = GL_FALSE;
1101
1102 /* Polygon Stipple group */
1103 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
1104
1105 /* Scissor group */
1106 ctx->Scissor.Enabled = GL_FALSE;
1107 ctx->Scissor.X = 0;
1108 ctx->Scissor.Y = 0;
1109 ctx->Scissor.Width = 0;
1110 ctx->Scissor.Height = 0;
1111
1112 /* Stencil group */
1113 ctx->Stencil.Enabled = GL_FALSE;
1114 ctx->Stencil.Function = GL_ALWAYS;
1115 ctx->Stencil.FailFunc = GL_KEEP;
1116 ctx->Stencil.ZPassFunc = GL_KEEP;
1117 ctx->Stencil.ZFailFunc = GL_KEEP;
1118 ctx->Stencil.Ref = 0;
1119 ctx->Stencil.ValueMask = STENCIL_MAX;
1120 ctx->Stencil.Clear = 0;
1121 ctx->Stencil.WriteMask = STENCIL_MAX;
1122
1123 /* Texture group */
1124 ctx->Texture.CurrentUnit = 0; /* multitexture */
1125 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
1126 ctx->Texture._ReallyEnabled = 0;
1127 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1128 init_texture_unit( ctx, i );
1129 ctx->Texture.SharedPalette = GL_FALSE;
1130 _mesa_init_colortable(&ctx->Texture.Palette);
1131
1132 /* Transformation group */
1133 ctx->Transform.MatrixMode = GL_MODELVIEW;
1134 ctx->Transform.Normalize = GL_FALSE;
1135 ctx->Transform.RescaleNormals = GL_FALSE;
1136 for (i=0;i<MAX_CLIP_PLANES;i++) {
1137 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1138 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1139 }
1140 ctx->Transform._AnyClip = GL_FALSE;
1141
1142 /* Viewport group */
1143 ctx->Viewport.X = 0;
1144 ctx->Viewport.Y = 0;
1145 ctx->Viewport.Width = 0;
1146 ctx->Viewport.Height = 0;
1147 ctx->Viewport.Near = 0.0;
1148 ctx->Viewport.Far = 1.0;
1149 _math_matrix_ctr(&ctx->Viewport._WindowMap);
1150
1151 #define Sz 10
1152 #define Tz 14
1153 ctx->Viewport._WindowMap.m[Sz] = 0.5 * ctx->DepthMaxF;
1154 ctx->Viewport._WindowMap.m[Tz] = 0.5 * ctx->DepthMaxF;
1155 #undef Sz
1156 #undef Tz
1157
1158 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1159 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
1160
1161 /* Vertex arrays */
1162 ctx->Array.Vertex.Size = 4;
1163 ctx->Array.Vertex.Type = GL_FLOAT;
1164 ctx->Array.Vertex.Stride = 0;
1165 ctx->Array.Vertex.StrideB = 0;
1166 ctx->Array.Vertex.Ptr = NULL;
1167 ctx->Array.Vertex.Enabled = GL_FALSE;
1168 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
1169 ctx->Array.Normal.Type = GL_FLOAT;
1170 ctx->Array.Normal.Stride = 0;
1171 ctx->Array.Normal.StrideB = 0;
1172 ctx->Array.Normal.Ptr = NULL;
1173 ctx->Array.Normal.Enabled = GL_FALSE;
1174 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
1175 ctx->Array.Color.Size = 4;
1176 ctx->Array.Color.Type = GL_FLOAT;
1177 ctx->Array.Color.Stride = 0;
1178 ctx->Array.Color.StrideB = 0;
1179 ctx->Array.Color.Ptr = NULL;
1180 ctx->Array.Color.Enabled = GL_FALSE;
1181 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1182 ctx->Array.SecondaryColor.Size = 4;
1183 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1184 ctx->Array.SecondaryColor.Stride = 0;
1185 ctx->Array.SecondaryColor.StrideB = 0;
1186 ctx->Array.SecondaryColor.Ptr = NULL;
1187 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1188 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1189 ctx->Array.FogCoord.Size = 1;
1190 ctx->Array.FogCoord.Type = GL_FLOAT;
1191 ctx->Array.FogCoord.Stride = 0;
1192 ctx->Array.FogCoord.StrideB = 0;
1193 ctx->Array.FogCoord.Ptr = NULL;
1194 ctx->Array.FogCoord.Enabled = GL_FALSE;
1195 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
1196 ctx->Array.Index.Type = GL_FLOAT;
1197 ctx->Array.Index.Stride = 0;
1198 ctx->Array.Index.StrideB = 0;
1199 ctx->Array.Index.Ptr = NULL;
1200 ctx->Array.Index.Enabled = GL_FALSE;
1201 ctx->Array.Index.Flags = CA_CLIENT_DATA;
1202 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1203 ctx->Array.TexCoord[i].Size = 4;
1204 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1205 ctx->Array.TexCoord[i].Stride = 0;
1206 ctx->Array.TexCoord[i].StrideB = 0;
1207 ctx->Array.TexCoord[i].Ptr = NULL;
1208 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1209 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
1210 }
1211 ctx->Array.TexCoordInterleaveFactor = 1;
1212 ctx->Array.EdgeFlag.Stride = 0;
1213 ctx->Array.EdgeFlag.StrideB = 0;
1214 ctx->Array.EdgeFlag.Ptr = NULL;
1215 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1216 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
1217 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1218
1219 /* Pixel transfer */
1220 ctx->Pack.Alignment = 4;
1221 ctx->Pack.RowLength = 0;
1222 ctx->Pack.ImageHeight = 0;
1223 ctx->Pack.SkipPixels = 0;
1224 ctx->Pack.SkipRows = 0;
1225 ctx->Pack.SkipImages = 0;
1226 ctx->Pack.SwapBytes = GL_FALSE;
1227 ctx->Pack.LsbFirst = GL_FALSE;
1228 ctx->Unpack.Alignment = 4;
1229 ctx->Unpack.RowLength = 0;
1230 ctx->Unpack.ImageHeight = 0;
1231 ctx->Unpack.SkipPixels = 0;
1232 ctx->Unpack.SkipRows = 0;
1233 ctx->Unpack.SkipImages = 0;
1234 ctx->Unpack.SwapBytes = GL_FALSE;
1235 ctx->Unpack.LsbFirst = GL_FALSE;
1236
1237 /* Feedback */
1238 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1239 ctx->Feedback.Buffer = NULL;
1240 ctx->Feedback.BufferSize = 0;
1241 ctx->Feedback.Count = 0;
1242
1243 /* Selection/picking */
1244 ctx->Select.Buffer = NULL;
1245 ctx->Select.BufferSize = 0;
1246 ctx->Select.BufferCount = 0;
1247 ctx->Select.Hits = 0;
1248 ctx->Select.NameStackDepth = 0;
1249
1250 /* Renderer and client attribute stacks */
1251 ctx->AttribStackDepth = 0;
1252 ctx->ClientAttribStackDepth = 0;
1253
1254 /* Display list */
1255 ctx->CallDepth = 0;
1256 ctx->ExecuteFlag = GL_TRUE;
1257 ctx->CompileFlag = GL_FALSE;
1258 ctx->CurrentListPtr = NULL;
1259 ctx->CurrentBlock = NULL;
1260 ctx->CurrentListNum = 0;
1261 ctx->CurrentPos = 0;
1262
1263 /* Color tables */
1264 _mesa_init_colortable(&ctx->ColorTable);
1265 _mesa_init_colortable(&ctx->ProxyColorTable);
1266 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1267 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1268 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1269 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
1270
1271 /* Miscellaneous */
1272 ctx->NewState = _NEW_ALL;
1273 ctx->RenderMode = GL_RENDER;
1274 ctx->_ImageTransferState = 0;
1275
1276 ctx->_NeedNormals = 0;
1277 ctx->_NeedEyeCoords = 0;
1278 ctx->_ModelViewInvScale = 1.0;
1279
1280 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1281
1282 ctx->CatchSignals = GL_TRUE;
1283 ctx->OcclusionResult = GL_FALSE;
1284 ctx->OcclusionResultSaved = GL_FALSE;
1285
1286 /* For debug/development only */
1287 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1288 ctx->FirstTimeCurrent = GL_TRUE;
1289
1290 /* Dither disable */
1291 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1292 if (ctx->NoDither) {
1293 if (getenv("MESA_DEBUG")) {
1294 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
1295 }
1296 ctx->Color.DitherFlag = GL_FALSE;
1297 }
1298 }
1299
1300
1301
1302
1303 /*
1304 * Allocate the proxy textures. If we run out of memory part way through
1305 * the allocations clean up and return GL_FALSE.
1306 * Return: GL_TRUE=success, GL_FALSE=failure
1307 */
1308 static GLboolean
1309 alloc_proxy_textures( GLcontext *ctx )
1310 {
1311 GLboolean out_of_memory;
1312 GLint i;
1313
1314 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
1315 if (!ctx->Texture.Proxy1D) {
1316 return GL_FALSE;
1317 }
1318
1319 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
1320 if (!ctx->Texture.Proxy2D) {
1321 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1322 return GL_FALSE;
1323 }
1324
1325 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
1326 if (!ctx->Texture.Proxy3D) {
1327 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1328 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1329 return GL_FALSE;
1330 }
1331
1332 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1333 if (!ctx->Texture.ProxyCubeMap) {
1334 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1335 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1336 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
1337 return GL_FALSE;
1338 }
1339
1340 out_of_memory = GL_FALSE;
1341 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1342 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1343 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1344 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
1345 if (!ctx->Texture.Proxy1D->Image[i]
1346 || !ctx->Texture.Proxy2D->Image[i]
1347 || !ctx->Texture.Proxy3D->Image[i]) {
1348 out_of_memory = GL_TRUE;
1349 }
1350 }
1351 if (out_of_memory) {
1352 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1353 if (ctx->Texture.Proxy1D->Image[i]) {
1354 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
1355 }
1356 if (ctx->Texture.Proxy2D->Image[i]) {
1357 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
1358 }
1359 if (ctx->Texture.Proxy3D->Image[i]) {
1360 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
1361 }
1362 }
1363 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1364 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1365 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
1366 return GL_FALSE;
1367 }
1368 else {
1369 return GL_TRUE;
1370 }
1371 }
1372
1373
1374 /*
1375 * Initialize a GLcontext struct. This includes allocating all the
1376 * other structs and arrays which hang off of the context by pointers.
1377 */
1378 GLboolean
1379 _mesa_initialize_context( GLcontext *ctx,
1380 const GLvisual *visual,
1381 GLcontext *share_list,
1382 void *driver_ctx,
1383 GLboolean direct )
1384 {
1385 GLuint dispatchSize;
1386
1387 (void) direct; /* not used */
1388
1389 /* misc one-time initializations */
1390 one_time_init();
1391
1392 /**
1393 ** OpenGL SI stuff
1394 **/
1395 if (!ctx->imports.malloc) {
1396 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1397 }
1398 /* exports are setup by the device driver */
1399
1400 ctx->DriverCtx = driver_ctx;
1401 ctx->Visual = *visual;
1402 ctx->DrawBuffer = NULL;
1403 ctx->ReadBuffer = NULL;
1404
1405 if (share_list) {
1406 /* share state with another context */
1407 ctx->Shared = share_list->Shared;
1408 }
1409 else {
1410 /* allocate new, unshared state */
1411 ctx->Shared = alloc_shared_state();
1412 if (!ctx->Shared) {
1413 return GL_FALSE;
1414 }
1415 }
1416 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1417 ctx->Shared->RefCount++;
1418 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1419
1420 /* Effectively bind the default textures to all texture units */
1421 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1422 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1423 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1424 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1425
1426 init_attrib_groups( ctx );
1427
1428 if (visual->doubleBufferMode) {
1429 ctx->Color.DrawBuffer = GL_BACK;
1430 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1431 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1432 ctx->Pixel.ReadBuffer = GL_BACK;
1433 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1434 }
1435 else {
1436 ctx->Color.DrawBuffer = GL_FRONT;
1437 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1438 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1439 ctx->Pixel.ReadBuffer = GL_FRONT;
1440 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1441 }
1442
1443 if (!alloc_proxy_textures(ctx)) {
1444 free_shared_state(ctx, ctx->Shared);
1445 return GL_FALSE;
1446 }
1447
1448 /* register the most recent extension functions with libGL */
1449 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1450 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1451 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1452 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1453 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1454 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1455 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1456 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1457
1458 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1459 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1460 * Mesa we do this to accomodate different versions of libGL and various
1461 * DRI drivers.
1462 */
1463 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1464 sizeof(struct _glapi_table) / sizeof(void *));
1465
1466 /* setup API dispatch tables */
1467 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1468 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1469 if (!ctx->Exec || !ctx->Save) {
1470 free_shared_state(ctx, ctx->Shared);
1471 if (ctx->Exec)
1472 FREE( ctx->Exec );
1473 }
1474 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1475 _mesa_init_dlist_table(ctx->Save, dispatchSize);
1476 ctx->CurrentDispatch = ctx->Exec;
1477
1478 ctx->ExecPrefersFloat = GL_FALSE;
1479 ctx->SavePrefersFloat = GL_FALSE;
1480
1481 /* Neutral tnl module stuff */
1482 _mesa_init_exec_vtxfmt( ctx );
1483 ctx->TnlModule.Current = NULL;
1484 ctx->TnlModule.SwapCount = 0;
1485
1486 /* Z buffer stuff */
1487 if (ctx->Visual.depthBits == 0) {
1488 /* Special case. Even if we don't have a depth buffer we need
1489 * good values for DepthMax for Z vertex transformation purposes
1490 * and for per-fragment fog computation.
1491 */
1492 ctx->DepthMax = 1 << 16;
1493 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1494 }
1495 else if (ctx->Visual.depthBits < 32) {
1496 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1497 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1498 }
1499 else {
1500 /* Special case since shift values greater than or equal to the
1501 * number of bits in the left hand expression's type are undefined.
1502 */
1503 ctx->DepthMax = 0xffffffff;
1504 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1505 }
1506 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
1507
1508
1509 #if defined(MESA_TRACE)
1510 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
1511 #if 0
1512 /* Brian: do you want to have CreateContext fail here,
1513 or should we just trap in NewTrace (currently done)? */
1514 if (!(ctx->TraceCtx)) {
1515 free_shared_state(ctx, ctx->Shared);
1516 FREE( ctx->Exec );
1517 FREE( ctx->Save );
1518 return GL_FALSE;
1519 }
1520 #endif
1521 trInitContext(ctx->TraceCtx);
1522
1523 ctx->TraceDispatch = (struct _glapi_table *)
1524 CALLOC(dispatchSize * sizeof(void*));
1525 #if 0
1526 if (!(ctx->TraceCtx)) {
1527 free_shared_state(ctx, ctx->Shared);
1528 FREE( ctx->Exec );
1529 FREE( ctx->Save );
1530 FREE( ctx->TraceCtx );
1531 return GL_FALSE;
1532 }
1533 #endif
1534 trInitDispatch(ctx->TraceDispatch);
1535 #endif
1536
1537 return GL_TRUE;
1538 }
1539
1540
1541
1542 /*
1543 * Allocate and initialize a GLcontext structure.
1544 * Input: visual - a GLvisual pointer (we copy the struct contents)
1545 * sharelist - another context to share display lists with or NULL
1546 * driver_ctx - pointer to device driver's context state struct
1547 * Return: pointer to a new __GLcontextRec or NULL if error.
1548 */
1549 GLcontext *
1550 _mesa_create_context( const GLvisual *visual,
1551 GLcontext *share_list,
1552 void *driver_ctx,
1553 GLboolean direct )
1554 {
1555 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1556 if (!ctx) {
1557 return NULL;
1558 }
1559
1560 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
1561 return ctx;
1562 }
1563 else {
1564 FREE(ctx);
1565 return NULL;
1566 }
1567 }
1568
1569
1570
1571 /*
1572 * Free the data associated with the given context.
1573 * But don't free() the GLcontext struct itself!
1574 */
1575 void
1576 _mesa_free_context_data( GLcontext *ctx )
1577 {
1578 struct gl_shine_tab *s, *tmps;
1579 GLuint i, j;
1580
1581 /* if we're destroying the current context, unbind it first */
1582 if (ctx == _mesa_get_current_context()) {
1583 _mesa_make_current(NULL, NULL);
1584 }
1585
1586 _math_matrix_dtr( &ctx->ModelView );
1587 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
1588 _math_matrix_dtr( &ctx->ModelViewStack[i] );
1589 }
1590 _math_matrix_dtr( &ctx->ProjectionMatrix );
1591 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
1592 _math_matrix_dtr( &ctx->ProjectionStack[i] );
1593 }
1594 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1595 _math_matrix_dtr( &ctx->TextureMatrix[i] );
1596 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1597 _math_matrix_dtr( &ctx->TextureStack[i][j] );
1598 }
1599 }
1600
1601 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1602 ctx->Shared->RefCount--;
1603 assert(ctx->Shared->RefCount >= 0);
1604 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1605 if (ctx->Shared->RefCount == 0) {
1606 /* free shared state */
1607 free_shared_state( ctx, ctx->Shared );
1608 }
1609
1610 foreach_s( s, tmps, ctx->_ShineTabList ) {
1611 FREE( s );
1612 }
1613 FREE( ctx->_ShineTabList );
1614
1615 /* Free proxy texture objects */
1616 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1617 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1618 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
1619
1620 /* Free evaluator data */
1621 if (ctx->EvalMap.Map1Vertex3.Points)
1622 FREE( ctx->EvalMap.Map1Vertex3.Points );
1623 if (ctx->EvalMap.Map1Vertex4.Points)
1624 FREE( ctx->EvalMap.Map1Vertex4.Points );
1625 if (ctx->EvalMap.Map1Index.Points)
1626 FREE( ctx->EvalMap.Map1Index.Points );
1627 if (ctx->EvalMap.Map1Color4.Points)
1628 FREE( ctx->EvalMap.Map1Color4.Points );
1629 if (ctx->EvalMap.Map1Normal.Points)
1630 FREE( ctx->EvalMap.Map1Normal.Points );
1631 if (ctx->EvalMap.Map1Texture1.Points)
1632 FREE( ctx->EvalMap.Map1Texture1.Points );
1633 if (ctx->EvalMap.Map1Texture2.Points)
1634 FREE( ctx->EvalMap.Map1Texture2.Points );
1635 if (ctx->EvalMap.Map1Texture3.Points)
1636 FREE( ctx->EvalMap.Map1Texture3.Points );
1637 if (ctx->EvalMap.Map1Texture4.Points)
1638 FREE( ctx->EvalMap.Map1Texture4.Points );
1639
1640 if (ctx->EvalMap.Map2Vertex3.Points)
1641 FREE( ctx->EvalMap.Map2Vertex3.Points );
1642 if (ctx->EvalMap.Map2Vertex4.Points)
1643 FREE( ctx->EvalMap.Map2Vertex4.Points );
1644 if (ctx->EvalMap.Map2Index.Points)
1645 FREE( ctx->EvalMap.Map2Index.Points );
1646 if (ctx->EvalMap.Map2Color4.Points)
1647 FREE( ctx->EvalMap.Map2Color4.Points );
1648 if (ctx->EvalMap.Map2Normal.Points)
1649 FREE( ctx->EvalMap.Map2Normal.Points );
1650 if (ctx->EvalMap.Map2Texture1.Points)
1651 FREE( ctx->EvalMap.Map2Texture1.Points );
1652 if (ctx->EvalMap.Map2Texture2.Points)
1653 FREE( ctx->EvalMap.Map2Texture2.Points );
1654 if (ctx->EvalMap.Map2Texture3.Points)
1655 FREE( ctx->EvalMap.Map2Texture3.Points );
1656 if (ctx->EvalMap.Map2Texture4.Points)
1657 FREE( ctx->EvalMap.Map2Texture4.Points );
1658
1659 _mesa_free_colortable_data( &ctx->ColorTable );
1660 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1661 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1662 _mesa_free_colortable_data( &ctx->Texture.Palette );
1663
1664 _mesa_extensions_dtr(ctx);
1665
1666 FREE(ctx->Exec);
1667 FREE(ctx->Save);
1668 }
1669
1670
1671
1672 /*
1673 * Destroy a GLcontext structure.
1674 */
1675 void
1676 _mesa_destroy_context( GLcontext *ctx )
1677 {
1678 if (ctx) {
1679 _mesa_free_context_data(ctx);
1680 FREE( (void *) ctx );
1681 }
1682 }
1683
1684
1685
1686 /*
1687 * Copy attribute groups from one context to another.
1688 * Input: src - source context
1689 * dst - destination context
1690 * mask - bitwise OR of GL_*_BIT flags
1691 */
1692 void
1693 _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
1694 {
1695 if (mask & GL_ACCUM_BUFFER_BIT) {
1696 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1697 }
1698 if (mask & GL_COLOR_BUFFER_BIT) {
1699 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1700 }
1701 if (mask & GL_CURRENT_BIT) {
1702 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1703 }
1704 if (mask & GL_DEPTH_BUFFER_BIT) {
1705 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1706 }
1707 if (mask & GL_ENABLE_BIT) {
1708 /* no op */
1709 }
1710 if (mask & GL_EVAL_BIT) {
1711 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1712 }
1713 if (mask & GL_FOG_BIT) {
1714 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1715 }
1716 if (mask & GL_HINT_BIT) {
1717 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1718 }
1719 if (mask & GL_LIGHTING_BIT) {
1720 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
1721 /* gl_reinit_light_attrib( &dst->Light ); */
1722 }
1723 if (mask & GL_LINE_BIT) {
1724 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1725 }
1726 if (mask & GL_LIST_BIT) {
1727 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1728 }
1729 if (mask & GL_PIXEL_MODE_BIT) {
1730 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1731 }
1732 if (mask & GL_POINT_BIT) {
1733 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1734 }
1735 if (mask & GL_POLYGON_BIT) {
1736 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1737 }
1738 if (mask & GL_POLYGON_STIPPLE_BIT) {
1739 /* Use loop instead of MEMCPY due to problem with Portland Group's
1740 * C compiler. Reported by John Stone.
1741 */
1742 int i;
1743 for (i=0;i<32;i++) {
1744 dst->PolygonStipple[i] = src->PolygonStipple[i];
1745 }
1746 }
1747 if (mask & GL_SCISSOR_BIT) {
1748 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1749 }
1750 if (mask & GL_STENCIL_BUFFER_BIT) {
1751 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1752 }
1753 if (mask & GL_TEXTURE_BIT) {
1754 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1755 }
1756 if (mask & GL_TRANSFORM_BIT) {
1757 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1758 }
1759 if (mask & GL_VIEWPORT_BIT) {
1760 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1761 }
1762 /* XXX FIXME: Call callbacks?
1763 */
1764 dst->NewState = _NEW_ALL;
1765 }
1766
1767
1768 /*
1769 * Set the current context, binding the given frame buffer to the context.
1770 */
1771 void
1772 _mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1773 {
1774 _mesa_make_current2( newCtx, buffer, buffer );
1775 }
1776
1777
1778 static void print_info( void )
1779 {
1780 fprintf(stderr, "Mesa GL_VERSION = %s\n",
1781 (char *) _mesa_GetString(GL_VERSION));
1782 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
1783 (char *) _mesa_GetString(GL_RENDERER));
1784 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
1785 (char *) _mesa_GetString(GL_VENDOR));
1786 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
1787 (char *) _mesa_GetString(GL_EXTENSIONS));
1788 #if defined(THREADS)
1789 fprintf(stderr, "Mesa thread-safe: YES\n");
1790 #else
1791 fprintf(stderr, "Mesa thread-safe: NO\n");
1792 #endif
1793 #if defined(USE_X86_ASM)
1794 fprintf(stderr, "Mesa x86-optimized: YES\n");
1795 #else
1796 fprintf(stderr, "Mesa x86-optimized: NO\n");
1797 #endif
1798 }
1799
1800
1801 /*
1802 * Bind the given context to the given draw-buffer and read-buffer
1803 * and make it the current context for this thread.
1804 */
1805 void
1806 _mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1807 GLframebuffer *readBuffer )
1808 {
1809 if (MESA_VERBOSE)
1810 fprintf(stderr, "_mesa_make_current2()\n");
1811
1812 /* Check that the context's and framebuffer's visuals are compatible.
1813 * We could do a lot more checking here but this'll catch obvious
1814 * problems.
1815 */
1816 if (newCtx && drawBuffer && readBuffer) {
1817 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1818 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1819 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1820 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1821 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1822 return; /* incompatible */
1823 }
1824 }
1825
1826 /* We call this function periodically (just here for now) in
1827 * order to detect when multithreading has begun.
1828 */
1829 _glapi_check_multithread();
1830
1831 _glapi_set_context((void *) newCtx);
1832 ASSERT(_mesa_get_current_context() == newCtx);
1833
1834
1835 if (!newCtx) {
1836 _glapi_set_dispatch(NULL); /* none current */
1837 }
1838 else {
1839 _glapi_set_dispatch(newCtx->CurrentDispatch);
1840
1841 if (drawBuffer && readBuffer) {
1842 /* TODO: check if newCtx and buffer's visual match??? */
1843 newCtx->DrawBuffer = drawBuffer;
1844 newCtx->ReadBuffer = readBuffer;
1845 newCtx->NewState |= _NEW_BUFFERS;
1846 /* _mesa_update_state( newCtx ); */
1847 }
1848
1849 if (newCtx->Driver.MakeCurrent)
1850 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1851
1852 /* We can use this to help debug user's problems. Tell them to set
1853 * the MESA_INFO env variable before running their app. Then the
1854 * first time each context is made current we'll print some useful
1855 * information.
1856 */
1857 if (newCtx->FirstTimeCurrent) {
1858 if (getenv("MESA_INFO")) {
1859 print_info();
1860 }
1861 newCtx->FirstTimeCurrent = GL_FALSE;
1862 }
1863 }
1864 }
1865
1866
1867
1868 /*
1869 * Return current context handle for the calling thread.
1870 * This isn't the fastest way to get the current context.
1871 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1872 */
1873 GLcontext *
1874 _mesa_get_current_context( void )
1875 {
1876 return (GLcontext *) _glapi_get_context();
1877 }
1878
1879
1880
1881 /*
1882 * This should be called by device drivers just before they do a
1883 * swapbuffers. Any pending rendering commands will be executed.
1884 */
1885 void
1886 _mesa_swapbuffers(GLcontext *ctx)
1887 {
1888 FLUSH_VERTICES( ctx, 0 );
1889 }
1890
1891
1892
1893 /*
1894 * Return pointer to this context's current API dispatch table.
1895 * It'll either be the immediate-mode execute dispatcher or the
1896 * display list compile dispatcher.
1897 */
1898 struct _glapi_table *
1899 _mesa_get_dispatch(GLcontext *ctx)
1900 {
1901 return ctx->CurrentDispatch;
1902 }
1903
1904
1905
1906 /**********************************************************************/
1907 /***** Miscellaneous functions *****/
1908 /**********************************************************************/
1909
1910
1911 /*
1912 * This function is called when the Mesa user has stumbled into a code
1913 * path which may not be implemented fully or correctly.
1914 */
1915 void _mesa_problem( const GLcontext *ctx, const char *s )
1916 {
1917 fprintf( stderr, "Mesa implementation error: %s\n", s );
1918 #ifdef XF86DRI
1919 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
1920 #else
1921 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
1922 #endif
1923 (void) ctx;
1924 }
1925
1926
1927
1928 /*
1929 * This is called to inform the user that he or she has tried to do
1930 * something illogical or if there's likely a bug in their program
1931 * (like enabled depth testing without a depth buffer).
1932 */
1933 void
1934 _mesa_warning( const GLcontext *ctx, const char *s )
1935 {
1936 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
1937 }
1938
1939
1940
1941 /*
1942 * Compile an error into current display list.
1943 */
1944 void
1945 _mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
1946 {
1947 if (ctx->CompileFlag)
1948 _mesa_save_error( ctx, error, s );
1949
1950 if (ctx->ExecuteFlag)
1951 _mesa_error( ctx, error, s );
1952 }
1953
1954
1955
1956 /*
1957 * This is Mesa's error handler. Normally, all that's done is the updating
1958 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1959 * environment variable "MESA_DEBUG" is defined then a real error message
1960 * is printed to stderr.
1961 * Input: ctx - the GL context
1962 * error - the error value
1963 * where - usually the name of function where error was detected
1964 */
1965 void
1966 _mesa_error( GLcontext *ctx, GLenum error, const char *where )
1967 {
1968 const char *debugEnv = getenv("MESA_DEBUG");
1969 GLboolean debug;
1970
1971 #ifdef DEBUG
1972 if (debugEnv && strstr(debugEnv, "silent"))
1973 debug = GL_FALSE;
1974 else
1975 debug = GL_TRUE;
1976 #else
1977 if (debugEnv)
1978 debug = GL_TRUE;
1979 else
1980 debug = GL_FALSE;
1981 #endif
1982
1983 if (debug) {
1984 const char *errstr;
1985 switch (error) {
1986 case GL_NO_ERROR:
1987 errstr = "GL_NO_ERROR";
1988 break;
1989 case GL_INVALID_VALUE:
1990 errstr = "GL_INVALID_VALUE";
1991 break;
1992 case GL_INVALID_ENUM:
1993 errstr = "GL_INVALID_ENUM";
1994 break;
1995 case GL_INVALID_OPERATION:
1996 errstr = "GL_INVALID_OPERATION";
1997 break;
1998 case GL_STACK_OVERFLOW:
1999 errstr = "GL_STACK_OVERFLOW";
2000 break;
2001 case GL_STACK_UNDERFLOW:
2002 errstr = "GL_STACK_UNDERFLOW";
2003 break;
2004 case GL_OUT_OF_MEMORY:
2005 errstr = "GL_OUT_OF_MEMORY";
2006 break;
2007 case GL_TABLE_TOO_LARGE:
2008 errstr = "GL_TABLE_TOO_LARGE";
2009 break;
2010 default:
2011 errstr = "unknown";
2012 break;
2013 }
2014 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
2015 }
2016
2017 if (ctx->ErrorValue == GL_NO_ERROR) {
2018 ctx->ErrorValue = error;
2019 }
2020
2021 /* Call device driver's error handler, if any. This is used on the Mac. */
2022 if (ctx->Driver.Error) {
2023 (*ctx->Driver.Error)( ctx );
2024 }
2025 }
2026
2027
2028
2029 void
2030 _mesa_Finish( void )
2031 {
2032 GET_CURRENT_CONTEXT(ctx);
2033 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2034 if (ctx->Driver.Finish) {
2035 (*ctx->Driver.Finish)( ctx );
2036 }
2037 }
2038
2039
2040
2041 void
2042 _mesa_Flush( void )
2043 {
2044 GET_CURRENT_CONTEXT(ctx);
2045 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2046 if (ctx->Driver.Flush) {
2047 (*ctx->Driver.Flush)( ctx );
2048 }
2049 }
2050
2051
2052
2053 const char *_mesa_prim_name[GL_POLYGON+4] = {
2054 "GL_POINTS",
2055 "GL_LINES",
2056 "GL_LINE_LOOP",
2057 "GL_LINE_STRIP",
2058 "GL_TRIANGLES",
2059 "GL_TRIANGLE_STRIP",
2060 "GL_TRIANGLE_FAN",
2061 "GL_QUADS",
2062 "GL_QUAD_STRIP",
2063 "GL_POLYGON",
2064 "outside begin/end",
2065 "inside unkown primitive",
2066 "unknown state"
2067 };