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