1 /* $Id: context.c,v 1.82 2000/09/05 20:28:06 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
42 #include "extensions.h"
46 #include "glapinoop.h"
57 #include "simple_list.h"
61 #include "translate.h"
78 #include "Trace/tr_context.h"
79 #include "Trace/tr_wrapper.h"
83 /**********************************************************************/
84 /***** Context and Thread management *****/
85 /**********************************************************************/
90 struct immediate
*_mesa_CurrentInput
= NULL
;
95 /**********************************************************************/
96 /***** GL Visual allocation/destruction *****/
97 /**********************************************************************/
101 * Allocate a new GLvisual object.
102 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
103 * dbFlag - double buffering?
104 * stereoFlag - stereo buffer?
105 * depthBits - requested bits per depth buffer value
106 * Any value in [0, 32] is acceptable but the actual
107 * depth type will be GLushort or GLuint as needed.
108 * stencilBits - requested minimum bits per stencil buffer value
109 * accumBits - requested minimum bits per accum buffer component
110 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
111 * red/green/blue/alphaBits - number of bits per color component
112 * in frame buffer for RGB(A) mode.
113 * We always use 8 in core Mesa though.
114 * Return: pointer to new GLvisual or NULL if requested parameters can't
118 _mesa_create_visual( GLboolean rgbFlag
,
120 GLboolean stereoFlag
,
129 GLint accumGreenBits
,
131 GLint accumAlphaBits
,
134 GLvisual
*vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
136 if (!_mesa_initialize_visual(vis
, rgbFlag
, dbFlag
, stereoFlag
,
137 redBits
, greenBits
, blueBits
, alphaBits
,
138 indexBits
, depthBits
, stencilBits
,
139 accumRedBits
, accumGreenBits
,
140 accumBlueBits
, accumAlphaBits
,
151 * Initialize the fields of the given GLvisual.
152 * Input: see _mesa_create_visual() above.
153 * Return: GL_TRUE = success
154 * GL_FALSE = failure.
157 _mesa_initialize_visual( GLvisual
*vis
,
160 GLboolean stereoFlag
,
169 GLint accumGreenBits
,
171 GLint accumAlphaBits
,
176 /* This is to catch bad values from device drivers not updated for
177 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
178 * bad value now (a 1-bit depth buffer!?!).
180 assert(depthBits
== 0 || depthBits
> 1);
182 if (depthBits
< 0 || depthBits
> 32) {
185 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
188 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
191 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
194 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
197 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
201 vis
->RGBAflag
= rgbFlag
;
202 vis
->DBflag
= dbFlag
;
203 vis
->StereoFlag
= stereoFlag
;
204 vis
->RedBits
= redBits
;
205 vis
->GreenBits
= greenBits
;
206 vis
->BlueBits
= blueBits
;
207 vis
->AlphaBits
= alphaBits
;
209 vis
->IndexBits
= indexBits
;
210 vis
->DepthBits
= depthBits
;
211 vis
->AccumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
212 vis
->AccumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
213 vis
->AccumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
214 vis
->AccumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
215 vis
->StencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
217 if (depthBits
== 0) {
218 /* Special case. Even if we don't have a depth buffer we need
219 * good values for DepthMax for Z vertex transformation purposes.
222 vis
->DepthMaxF
= 1.0F
;
224 else if (depthBits
< 32) {
225 vis
->DepthMax
= (1 << depthBits
) - 1;
226 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
229 /* Special case since shift values greater than or equal to the
230 * number of bits in the left hand expression's type are
233 vis
->DepthMax
= 0xffffffff;
234 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
241 /* This function should no longer be used. Use _mesa_create_visual() instead */
243 gl_create_visual( GLboolean rgbFlag
,
246 GLboolean stereoFlag
,
257 return _mesa_create_visual(rgbFlag
, dbFlag
, stereoFlag
,
258 redBits
, greenBits
, blueBits
, alphaBits
,
259 indexBits
, depthBits
, stencilBits
,
260 accumBits
, accumBits
, accumBits
, accumBits
, 0);
265 _mesa_destroy_visual( GLvisual
*vis
)
273 gl_destroy_visual( GLvisual
*vis
)
275 _mesa_destroy_visual(vis
);
280 /**********************************************************************/
281 /***** GL Framebuffer allocation/destruction *****/
282 /**********************************************************************/
286 * Create a new framebuffer. A GLframebuffer is a struct which
287 * encapsulates the depth, stencil and accum buffers and related
289 * Input: visual - a GLvisual pointer
290 * softwareDepth - create/use a software depth buffer?
291 * softwareStencil - create/use a software stencil buffer?
292 * softwareAccum - create/use a software accum buffer?
293 * softwareAlpha - create/use a software alpha buffer?
295 * Return: pointer to new GLframebuffer struct or NULL if error.
298 gl_create_framebuffer( GLvisual
*visual
,
299 GLboolean softwareDepth
,
300 GLboolean softwareStencil
,
301 GLboolean softwareAccum
,
302 GLboolean softwareAlpha
)
304 GLframebuffer
*buffer
= CALLOC_STRUCT(gl_frame_buffer
);
307 _mesa_initialize_framebuffer(buffer
, visual
,
308 softwareDepth
, softwareStencil
,
309 softwareAccum
, softwareAlpha
);
316 * Initialize a GLframebuffer object.
317 * Input: See gl_create_framebuffer() above.
320 _mesa_initialize_framebuffer( GLframebuffer
*buffer
,
322 GLboolean softwareDepth
,
323 GLboolean softwareStencil
,
324 GLboolean softwareAccum
,
325 GLboolean softwareAlpha
)
331 if (softwareDepth
) {
332 assert(visual
->DepthBits
> 0);
334 if (softwareStencil
) {
335 assert(visual
->StencilBits
> 0);
338 assert(visual
->RGBAflag
);
339 assert(visual
->AccumRedBits
> 0);
340 assert(visual
->AccumGreenBits
> 0);
341 assert(visual
->AccumBlueBits
> 0);
344 assert(visual
->RGBAflag
);
345 assert(visual
->AlphaBits
> 0);
348 buffer
->Visual
= visual
;
349 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
350 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
351 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
352 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
357 * Free a framebuffer struct and its buffers.
360 gl_destroy_framebuffer( GLframebuffer
*buffer
)
363 if (buffer
->DepthBuffer
) {
364 FREE( buffer
->DepthBuffer
);
367 FREE( buffer
->Accum
);
369 if (buffer
->Stencil
) {
370 FREE( buffer
->Stencil
);
372 if (buffer
->FrontLeftAlpha
) {
373 FREE( buffer
->FrontLeftAlpha
);
375 if (buffer
->BackLeftAlpha
) {
376 FREE( buffer
->BackLeftAlpha
);
378 if (buffer
->FrontRightAlpha
) {
379 FREE( buffer
->FrontRightAlpha
);
381 if (buffer
->BackRightAlpha
) {
382 FREE( buffer
->BackRightAlpha
);
390 /**********************************************************************/
391 /***** Context allocation, initialization, destroying *****/
392 /**********************************************************************/
395 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
399 * This function just calls all the various one-time-init functions in Mesa.
402 one_time_init( void )
404 static GLboolean alreadyCalled
= GL_FALSE
;
405 _glthread_LOCK_MUTEX(OneTimeLock
);
406 if (!alreadyCalled
) {
407 /* do some implementation tests */
408 assert( sizeof(GLbyte
) == 1 );
409 assert( sizeof(GLshort
) >= 2 );
410 assert( sizeof(GLint
) >= 4 );
411 assert( sizeof(GLubyte
) == 1 );
412 assert( sizeof(GLushort
) >= 2 );
413 assert( sizeof(GLuint
) >= 4 );
422 gl_init_transformation();
428 if (getenv("MESA_DEBUG")) {
429 _glapi_noop_enable_warnings(GL_TRUE
);
432 _glapi_noop_enable_warnings(GL_FALSE
);
435 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
436 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
439 alreadyCalled
= GL_TRUE
;
441 _glthread_UNLOCK_MUTEX(OneTimeLock
);
447 * Allocate and initialize a shared context state structure.
449 static struct gl_shared_state
*
450 alloc_shared_state( void )
453 struct gl_shared_state
*ss
;
454 GLboolean outOfMemory
;
456 ss
= CALLOC_STRUCT(gl_shared_state
);
460 ss
->DisplayList
= _mesa_NewHashTable();
462 ss
->TexObjects
= _mesa_NewHashTable();
464 /* Default Texture objects */
465 outOfMemory
= GL_FALSE
;
466 for (d
= 1 ; d
<= 3 ; d
++) {
467 ss
->DefaultD
[d
] = gl_alloc_texture_object(ss
, 0, d
);
468 if (!ss
->DefaultD
[d
]) {
469 outOfMemory
= GL_TRUE
;
472 ss
->DefaultD
[d
]->RefCount
++; /* don't free if not in use */
475 ss
->DefaultCubeMap
= gl_alloc_texture_object(ss
, 0, 6);
476 if (!ss
->DefaultCubeMap
) {
477 outOfMemory
= GL_TRUE
;
480 ss
->DefaultCubeMap
->RefCount
++;
483 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
484 /* Ran out of memory at some point. Free everything and return NULL */
486 _mesa_DeleteHashTable(ss
->DisplayList
);
488 _mesa_DeleteHashTable(ss
->TexObjects
);
490 gl_free_texture_object(ss
, ss
->DefaultD
[1]);
492 gl_free_texture_object(ss
, ss
->DefaultD
[2]);
494 gl_free_texture_object(ss
, ss
->DefaultD
[3]);
495 if (ss
->DefaultCubeMap
)
496 gl_free_texture_object(ss
, ss
->DefaultCubeMap
);
507 * Deallocate a shared state context and all children structures.
510 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
512 /* Free display lists */
514 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
516 gl_destroy_list(ctx
, list
);
522 _mesa_DeleteHashTable(ss
->DisplayList
);
524 /* Free texture objects */
525 while (ss
->TexObjectList
)
527 if (ctx
->Driver
.DeleteTexture
)
528 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
529 /* this function removes from linked list too! */
530 gl_free_texture_object(ss
, ss
->TexObjectList
);
532 _mesa_DeleteHashTable(ss
->TexObjects
);
540 * Initialize the nth light. Note that the defaults for light 0 are
541 * different than the other lights.
544 init_light( struct gl_light
*l
, GLuint n
)
546 make_empty_list( l
);
548 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
550 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
551 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
554 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
555 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
557 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
558 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
559 l
->SpotExponent
= 0.0;
560 gl_compute_spot_exp_table( l
);
561 l
->SpotCutoff
= 180.0;
562 l
->CosCutoff
= 0.0; /* KW: -ve values not admitted */
563 l
->ConstantAttenuation
= 1.0;
564 l
->LinearAttenuation
= 0.0;
565 l
->QuadraticAttenuation
= 0.0;
566 l
->Enabled
= GL_FALSE
;
572 init_lightmodel( struct gl_lightmodel
*lm
)
574 ASSIGN_4V( lm
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
575 lm
->LocalViewer
= GL_FALSE
;
576 lm
->TwoSide
= GL_FALSE
;
577 lm
->ColorControl
= GL_SINGLE_COLOR
;
582 init_material( struct gl_material
*m
)
584 ASSIGN_4V( m
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
585 ASSIGN_4V( m
->Diffuse
, 0.8, 0.8, 0.8, 1.0 );
586 ASSIGN_4V( m
->Specular
, 0.0, 0.0, 0.0, 1.0 );
587 ASSIGN_4V( m
->Emission
, 0.0, 0.0, 0.0, 1.0 );
591 m
->SpecularIndex
= 1;
597 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
599 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
601 texUnit
->EnvMode
= GL_MODULATE
;
602 texUnit
->CombineModeRGB
= GL_MODULATE
;
603 texUnit
->CombineModeA
= GL_MODULATE
;
604 texUnit
->CombineSourceRGB
[0] = GL_TEXTURE
;
605 texUnit
->CombineSourceRGB
[1] = GL_PREVIOUS_EXT
;
606 texUnit
->CombineSourceRGB
[2] = GL_CONSTANT_EXT
;
607 texUnit
->CombineSourceA
[0] = GL_TEXTURE
;
608 texUnit
->CombineSourceA
[1] = GL_PREVIOUS_EXT
;
609 texUnit
->CombineSourceA
[2] = GL_CONSTANT_EXT
;
610 texUnit
->CombineOperandRGB
[0] = GL_SRC_COLOR
;
611 texUnit
->CombineOperandRGB
[1] = GL_SRC_COLOR
;
612 texUnit
->CombineOperandRGB
[2] = GL_SRC_ALPHA
;
613 texUnit
->CombineOperandA
[0] = GL_SRC_ALPHA
;
614 texUnit
->CombineOperandA
[1] = GL_SRC_ALPHA
;
615 texUnit
->CombineOperandA
[2] = GL_SRC_ALPHA
;
616 texUnit
->CombineScaleShiftRGB
= 0;
617 texUnit
->CombineScaleShiftA
= 0;
619 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
620 texUnit
->TexGenEnabled
= 0;
621 texUnit
->GenModeS
= GL_EYE_LINEAR
;
622 texUnit
->GenModeT
= GL_EYE_LINEAR
;
623 texUnit
->GenModeR
= GL_EYE_LINEAR
;
624 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
625 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
626 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
627 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
628 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
630 /* Yes, these plane coefficients are correct! */
631 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
632 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
633 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
634 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
635 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
636 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
637 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
638 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
640 texUnit
->CurrentD
[1] = ctx
->Shared
->DefaultD
[1];
641 texUnit
->CurrentD
[2] = ctx
->Shared
->DefaultD
[2];
642 texUnit
->CurrentD
[3] = ctx
->Shared
->DefaultD
[3];
643 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
648 init_fallback_arrays( GLcontext
*ctx
)
650 struct gl_client_array
*cl
;
653 cl
= &ctx
->Fallback
.Normal
;
658 cl
->Ptr
= (void *) ctx
->Current
.Normal
;
661 cl
= &ctx
->Fallback
.Color
;
663 cl
->Type
= GL_UNSIGNED_BYTE
;
666 cl
->Ptr
= (void *) ctx
->Current
.ByteColor
;
669 cl
= &ctx
->Fallback
.Index
;
671 cl
->Type
= GL_UNSIGNED_INT
;
674 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
677 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
678 cl
= &ctx
->Fallback
.TexCoord
[i
];
683 cl
->Ptr
= (void *) ctx
->Current
.Texcoord
[i
];
687 cl
= &ctx
->Fallback
.EdgeFlag
;
689 cl
->Type
= GL_UNSIGNED_BYTE
;
692 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
697 /* Initialize a 1-D evaluator map */
699 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
704 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
708 map
->Points
[i
] = initial
[i
];
713 /* Initialize a 2-D evaluator map */
715 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
723 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
727 map
->Points
[i
] = initial
[i
];
733 * Initialize the attribute groups in a GLcontext.
736 init_attrib_groups( GLcontext
*ctx
)
742 /* Constants, may be overriden by device drivers */
743 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
744 ctx
->Const
.MaxTextureSize
= 1 << (MAX_TEXTURE_LEVELS
- 1);
745 ctx
->Const
.MaxCubeTextureSize
= ctx
->Const
.MaxTextureSize
;
746 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
747 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
748 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
749 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
750 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
751 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
752 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
753 ctx
->Const
.PointSizeGranularity
= POINT_SIZE_GRANULARITY
;
754 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
755 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
756 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
757 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
758 ctx
->Const
.LineWidthGranularity
= LINE_WIDTH_GRANULARITY
;
759 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
760 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
761 ctx
->Const
.MaxConvolutionWidth
= MAX_CONVOLUTION_WIDTH
;
762 ctx
->Const
.MaxConvolutionHeight
= MAX_CONVOLUTION_HEIGHT
;
763 ctx
->Const
.NumCompressedTextureFormats
= 0;
765 /* Modelview matrix */
766 gl_matrix_ctr( &ctx
->ModelView
);
767 gl_matrix_alloc_inv( &ctx
->ModelView
);
769 ctx
->ModelViewStackDepth
= 0;
770 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
771 gl_matrix_ctr( &ctx
->ModelViewStack
[i
] );
772 gl_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
775 /* Projection matrix - need inv for user clipping in clip space*/
776 gl_matrix_ctr( &ctx
->ProjectionMatrix
);
777 gl_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
779 gl_matrix_ctr( &ctx
->ModelProjectMatrix
);
780 gl_matrix_ctr( &ctx
->ModelProjectWinMatrix
);
781 ctx
->ModelProjectWinMatrixUptodate
= GL_FALSE
;
783 ctx
->ProjectionStackDepth
= 0;
784 ctx
->NearFarStack
[0][0] = 1.0; /* These values seem weird by make */
785 ctx
->NearFarStack
[0][1] = 0.0; /* sense mathematically. */
787 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
788 gl_matrix_ctr( &ctx
->ProjectionStack
[i
] );
789 gl_matrix_alloc_inv( &ctx
->ProjectionStack
[i
] );
793 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
794 gl_matrix_ctr( &ctx
->TextureMatrix
[i
] );
795 ctx
->TextureStackDepth
[i
] = 0;
796 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
797 gl_matrix_ctr( &ctx
->TextureStack
[i
][j
] );
798 ctx
->TextureStack
[i
][j
].inv
= 0;
803 gl_matrix_ctr(&ctx
->ColorMatrix
);
804 ctx
->ColorStackDepth
= 0;
805 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
806 gl_matrix_ctr(&ctx
->ColorStack
[j
]);
809 /* Accumulate buffer group */
810 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
812 /* Color buffer group */
813 ctx
->Color
.IndexMask
= 0xffffffff;
814 ctx
->Color
.ColorMask
[0] = 0xff;
815 ctx
->Color
.ColorMask
[1] = 0xff;
816 ctx
->Color
.ColorMask
[2] = 0xff;
817 ctx
->Color
.ColorMask
[3] = 0xff;
818 ctx
->Color
.SWmasking
= GL_FALSE
;
819 ctx
->Color
.ClearIndex
= 0;
820 ASSIGN_4V( ctx
->Color
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
821 ctx
->Color
.DrawBuffer
= GL_FRONT
;
822 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
823 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
824 ctx
->Color
.AlphaRef
= 0;
825 ctx
->Color
.BlendEnabled
= GL_FALSE
;
826 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
827 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
828 ctx
->Color
.BlendSrcA
= GL_ONE
;
829 ctx
->Color
.BlendDstA
= GL_ZERO
;
830 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
831 ctx
->Color
.BlendFunc
= NULL
; /* this pointer set only when needed */
832 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
833 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
834 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
835 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
836 ctx
->Color
.LogicOp
= GL_COPY
;
837 ctx
->Color
.DitherFlag
= GL_TRUE
;
838 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
841 ASSIGN_4V( ctx
->Current
.ByteColor
, 255, 255, 255, 255);
842 ctx
->Current
.Index
= 1;
843 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
844 ASSIGN_4V( ctx
->Current
.Texcoord
[i
], 0.0, 0.0, 0.0, 1.0 );
845 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
846 ctx
->Current
.RasterDistance
= 0.0;
847 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
848 ctx
->Current
.RasterIndex
= 1;
849 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
850 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
851 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
852 ctx
->Current
.RasterPosValid
= GL_TRUE
;
853 ctx
->Current
.EdgeFlag
= GL_TRUE
;
854 ASSIGN_3V( ctx
->Current
.Normal
, 0.0, 0.0, 1.0 );
855 ctx
->Current
.Primitive
= (GLenum
) (GL_POLYGON
+ 1);
857 ctx
->Current
.Flag
= (VERT_NORM
|VERT_INDEX
|VERT_RGBA
|VERT_EDGE
|
858 VERT_TEX0_1
|VERT_TEX1_1
|VERT_MATERIAL
);
860 init_fallback_arrays( ctx
);
862 /* Depth buffer group */
863 ctx
->Depth
.Test
= GL_FALSE
;
864 ctx
->Depth
.Clear
= 1.0;
865 ctx
->Depth
.Func
= GL_LESS
;
866 ctx
->Depth
.Mask
= GL_TRUE
;
867 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
869 /* Evaluators group */
870 ctx
->Eval
.Map1Color4
= GL_FALSE
;
871 ctx
->Eval
.Map1Index
= GL_FALSE
;
872 ctx
->Eval
.Map1Normal
= GL_FALSE
;
873 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
874 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
875 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
876 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
877 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
878 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
879 ctx
->Eval
.Map2Color4
= GL_FALSE
;
880 ctx
->Eval
.Map2Index
= GL_FALSE
;
881 ctx
->Eval
.Map2Normal
= GL_FALSE
;
882 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
883 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
884 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
885 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
886 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
887 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
888 ctx
->Eval
.AutoNormal
= GL_FALSE
;
889 ctx
->Eval
.MapGrid1un
= 1;
890 ctx
->Eval
.MapGrid1u1
= 0.0;
891 ctx
->Eval
.MapGrid1u2
= 1.0;
892 ctx
->Eval
.MapGrid2un
= 1;
893 ctx
->Eval
.MapGrid2vn
= 1;
894 ctx
->Eval
.MapGrid2u1
= 0.0;
895 ctx
->Eval
.MapGrid2u2
= 1.0;
896 ctx
->Eval
.MapGrid2v1
= 0.0;
897 ctx
->Eval
.MapGrid2v2
= 1.0;
901 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
902 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
903 static GLfloat index
[1] = { 1.0 };
904 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
905 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
907 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
908 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
909 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
910 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
911 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
912 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
913 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
914 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
915 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
917 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
918 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
919 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
920 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
921 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
922 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
923 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
924 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
925 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
929 ctx
->Fog
.Enabled
= GL_FALSE
;
930 ctx
->Fog
.Mode
= GL_EXP
;
931 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
932 ctx
->Fog
.Index
= 0.0;
933 ctx
->Fog
.Density
= 1.0;
934 ctx
->Fog
.Start
= 0.0;
938 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
939 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
940 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
941 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
942 ctx
->Hint
.Fog
= GL_DONT_CARE
;
943 ctx
->Hint
.AllowDrawWin
= GL_TRUE
;
944 ctx
->Hint
.AllowDrawFrg
= GL_TRUE
;
945 ctx
->Hint
.AllowDrawMem
= GL_TRUE
;
946 ctx
->Hint
.StrictLighting
= GL_TRUE
;
947 ctx
->Hint
.ClipVolumeClipping
= GL_DONT_CARE
;
948 ctx
->Hint
.TextureCompression
= GL_DONT_CARE
;
950 /* Histogram group */
951 ctx
->Histogram
.Width
= 0;
952 ctx
->Histogram
.Format
= GL_RGBA
;
953 ctx
->Histogram
.Sink
= GL_FALSE
;
954 ctx
->Histogram
.RedSize
= 0xffffffff;
955 ctx
->Histogram
.GreenSize
= 0xffffffff;
956 ctx
->Histogram
.BlueSize
= 0xffffffff;
957 ctx
->Histogram
.AlphaSize
= 0xffffffff;
958 ctx
->Histogram
.LuminanceSize
= 0xffffffff;
959 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
960 ctx
->Histogram
.Count
[i
][0] = 0;
961 ctx
->Histogram
.Count
[i
][1] = 0;
962 ctx
->Histogram
.Count
[i
][2] = 0;
963 ctx
->Histogram
.Count
[i
][3] = 0;
967 ctx
->MinMax
.Format
= GL_RGBA
;
968 ctx
->MinMax
.Sink
= GL_FALSE
;
969 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
970 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
971 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
972 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
977 gl_pipeline_init( ctx
);
981 gl_extensions_ctr( ctx
);
983 ctx
->AllowVertexCull
= CLIP_CULLED_BIT
;
986 for (i
=0;i
<MAX_LIGHTS
;i
++) {
987 init_light( &ctx
->Light
.Light
[i
], i
);
989 make_empty_list( &ctx
->Light
.EnabledList
);
991 init_lightmodel( &ctx
->Light
.Model
);
992 init_material( &ctx
->Light
.Material
[0] );
993 init_material( &ctx
->Light
.Material
[1] );
994 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
995 ctx
->Light
.Enabled
= GL_FALSE
;
996 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
997 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
998 ctx
->Light
.ColorMaterialBitmask
999 = gl_material_bitmask( ctx
,
1001 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
1003 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1005 /* Lighting miscellaneous */
1006 ctx
->ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1007 make_empty_list( ctx
->ShineTabList
);
1008 for (i
= 0 ; i
< 10 ; i
++) {
1009 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1012 insert_at_tail( ctx
->ShineTabList
, s
);
1014 for (i
= 0 ; i
< 4 ; i
++) {
1015 ctx
->ShineTable
[i
] = ctx
->ShineTabList
->prev
;
1016 ctx
->ShineTable
[i
]->refcount
++;
1019 gl_compute_shine_table( ctx
, 0, ctx
->Light
.Material
[0].Shininess
);
1020 gl_compute_shine_table( ctx
, 2, ctx
->Light
.Material
[0].Shininess
* .5 );
1021 gl_compute_shine_table( ctx
, 1, ctx
->Light
.Material
[1].Shininess
);
1022 gl_compute_shine_table( ctx
, 3, ctx
->Light
.Material
[1].Shininess
* .5 );
1026 ctx
->Line
.SmoothFlag
= GL_FALSE
;
1027 ctx
->Line
.StippleFlag
= GL_FALSE
;
1028 ctx
->Line
.Width
= 1.0;
1029 ctx
->Line
.StipplePattern
= 0xffff;
1030 ctx
->Line
.StippleFactor
= 1;
1032 /* Display List group */
1033 ctx
->List
.ListBase
= 0;
1036 ctx
->Pixel
.RedBias
= 0.0;
1037 ctx
->Pixel
.RedScale
= 1.0;
1038 ctx
->Pixel
.GreenBias
= 0.0;
1039 ctx
->Pixel
.GreenScale
= 1.0;
1040 ctx
->Pixel
.BlueBias
= 0.0;
1041 ctx
->Pixel
.BlueScale
= 1.0;
1042 ctx
->Pixel
.AlphaBias
= 0.0;
1043 ctx
->Pixel
.AlphaScale
= 1.0;
1044 ctx
->Pixel
.DepthBias
= 0.0;
1045 ctx
->Pixel
.DepthScale
= 1.0;
1046 ctx
->Pixel
.IndexOffset
= 0;
1047 ctx
->Pixel
.IndexShift
= 0;
1048 ctx
->Pixel
.ZoomX
= 1.0;
1049 ctx
->Pixel
.ZoomY
= 1.0;
1050 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
1051 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
1052 ctx
->Pixel
.MapStoSsize
= 1;
1053 ctx
->Pixel
.MapItoIsize
= 1;
1054 ctx
->Pixel
.MapItoRsize
= 1;
1055 ctx
->Pixel
.MapItoGsize
= 1;
1056 ctx
->Pixel
.MapItoBsize
= 1;
1057 ctx
->Pixel
.MapItoAsize
= 1;
1058 ctx
->Pixel
.MapRtoRsize
= 1;
1059 ctx
->Pixel
.MapGtoGsize
= 1;
1060 ctx
->Pixel
.MapBtoBsize
= 1;
1061 ctx
->Pixel
.MapAtoAsize
= 1;
1062 ctx
->Pixel
.MapStoS
[0] = 0;
1063 ctx
->Pixel
.MapItoI
[0] = 0;
1064 ctx
->Pixel
.MapItoR
[0] = 0.0;
1065 ctx
->Pixel
.MapItoG
[0] = 0.0;
1066 ctx
->Pixel
.MapItoB
[0] = 0.0;
1067 ctx
->Pixel
.MapItoA
[0] = 0.0;
1068 ctx
->Pixel
.MapItoR8
[0] = 0;
1069 ctx
->Pixel
.MapItoG8
[0] = 0;
1070 ctx
->Pixel
.MapItoB8
[0] = 0;
1071 ctx
->Pixel
.MapItoA8
[0] = 0;
1072 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1073 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1074 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1075 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1076 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
1077 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
1078 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
1079 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1080 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1081 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixScale
, 1.0, 1.0, 1.0, 1.0);
1082 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixBias
, 0.0, 0.0, 0.0, 0.0);
1083 ASSIGN_4V(ctx
->Pixel
.ColorTableScale
, 1.0, 1.0, 1.0, 1.0);
1084 ASSIGN_4V(ctx
->Pixel
.ColorTableBias
, 0.0, 0.0, 0.0, 0.0);
1085 ASSIGN_4V(ctx
->Pixel
.PCCTscale
, 1.0, 1.0, 1.0, 1.0);
1086 ASSIGN_4V(ctx
->Pixel
.PCCTbias
, 0.0, 0.0, 0.0, 0.0);
1087 ASSIGN_4V(ctx
->Pixel
.PCMCTscale
, 1.0, 1.0, 1.0, 1.0);
1088 ASSIGN_4V(ctx
->Pixel
.PCMCTbias
, 0.0, 0.0, 0.0, 0.0);
1089 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1090 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1091 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1092 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
1093 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
1094 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
1095 for (i
= 0; i
< 3; i
++) {
1096 ASSIGN_4V(ctx
->Pixel
.ConvolutionBorderColor
[i
], 0.0, 0.0, 0.0, 0.0);
1097 ctx
->Pixel
.ConvolutionBorderMode
[i
] = GL_REDUCE
;
1098 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterScale
[i
], 1.0, 1.0, 1.0, 1.0);
1099 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterBias
[i
], 0.0, 0.0, 0.0, 0.0);
1101 ASSIGN_4V(ctx
->Pixel
.PostConvolutionScale
, 1.0, 1.0, 1.0, 1.0);
1102 ASSIGN_4V(ctx
->Pixel
.PostConvolutionBias
, 0.0, 0.0, 0.0, 0.0);
1105 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1106 ctx
->Point
.UserSize
= 1.0;
1107 ctx
->Point
.Size
= 1.0;
1108 ctx
->Point
.Params
[0] = 1.0;
1109 ctx
->Point
.Params
[1] = 0.0;
1110 ctx
->Point
.Params
[2] = 0.0;
1111 ctx
->Point
.Attenuated
= GL_FALSE
;
1112 ctx
->Point
.MinSize
= 0.0;
1113 ctx
->Point
.MaxSize
= (GLfloat
) MAX_POINT_SIZE
;
1114 ctx
->Point
.Threshold
= 1.0;
1117 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1118 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1119 ctx
->Polygon
.FrontFace
= GL_CCW
;
1120 ctx
->Polygon
.FrontBit
= 0;
1121 ctx
->Polygon
.FrontMode
= GL_FILL
;
1122 ctx
->Polygon
.BackMode
= GL_FILL
;
1123 ctx
->Polygon
.Unfilled
= GL_FALSE
;
1124 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1125 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1126 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1127 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1128 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1129 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1130 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1132 /* Polygon Stipple group */
1133 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1136 ctx
->Scissor
.Enabled
= GL_FALSE
;
1139 ctx
->Scissor
.Width
= 0;
1140 ctx
->Scissor
.Height
= 0;
1143 ctx
->Stencil
.Enabled
= GL_FALSE
;
1144 ctx
->Stencil
.Function
= GL_ALWAYS
;
1145 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1146 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1147 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1148 ctx
->Stencil
.Ref
= 0;
1149 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1150 ctx
->Stencil
.Clear
= 0;
1151 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1154 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1155 ctx
->Texture
.CurrentTransformUnit
= 0; /* multitexture */
1156 ctx
->Texture
.Enabled
= 0;
1157 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1158 init_texture_unit( ctx
, i
);
1159 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1161 /* Transformation group */
1162 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1163 ctx
->Transform
.Normalize
= GL_FALSE
;
1164 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1165 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1166 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1167 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1169 ctx
->Transform
.AnyClip
= GL_FALSE
;
1171 /* Viewport group */
1172 ctx
->Viewport
.X
= 0;
1173 ctx
->Viewport
.Y
= 0;
1174 ctx
->Viewport
.Width
= 0;
1175 ctx
->Viewport
.Height
= 0;
1176 ctx
->Viewport
.Near
= 0.0;
1177 ctx
->Viewport
.Far
= 1.0;
1178 gl_matrix_ctr(&ctx
->Viewport
.WindowMap
);
1182 ctx
->Viewport
.WindowMap
.m
[Sz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1183 ctx
->Viewport
.WindowMap
.m
[Tz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1187 ctx
->Viewport
.WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1188 ctx
->Viewport
.WindowMap
.type
= MATRIX_3D_NO_ROT
;
1191 ctx
->Array
.Vertex
.Size
= 4;
1192 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1193 ctx
->Array
.Vertex
.Stride
= 0;
1194 ctx
->Array
.Vertex
.StrideB
= 0;
1195 ctx
->Array
.Vertex
.Ptr
= NULL
;
1196 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1197 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1198 ctx
->Array
.Normal
.Stride
= 0;
1199 ctx
->Array
.Normal
.StrideB
= 0;
1200 ctx
->Array
.Normal
.Ptr
= NULL
;
1201 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1202 ctx
->Array
.Color
.Size
= 4;
1203 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1204 ctx
->Array
.Color
.Stride
= 0;
1205 ctx
->Array
.Color
.StrideB
= 0;
1206 ctx
->Array
.Color
.Ptr
= NULL
;
1207 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1208 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1209 ctx
->Array
.Index
.Stride
= 0;
1210 ctx
->Array
.Index
.StrideB
= 0;
1211 ctx
->Array
.Index
.Ptr
= NULL
;
1212 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1213 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1214 ctx
->Array
.TexCoord
[i
].Size
= 4;
1215 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1216 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1217 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1218 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1219 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1221 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1222 ctx
->Array
.EdgeFlag
.Stride
= 0;
1223 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1224 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1225 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1226 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1228 /* Pixel transfer */
1229 ctx
->Pack
.Alignment
= 4;
1230 ctx
->Pack
.RowLength
= 0;
1231 ctx
->Pack
.ImageHeight
= 0;
1232 ctx
->Pack
.SkipPixels
= 0;
1233 ctx
->Pack
.SkipRows
= 0;
1234 ctx
->Pack
.SkipImages
= 0;
1235 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1236 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1237 ctx
->Unpack
.Alignment
= 4;
1238 ctx
->Unpack
.RowLength
= 0;
1239 ctx
->Unpack
.ImageHeight
= 0;
1240 ctx
->Unpack
.SkipPixels
= 0;
1241 ctx
->Unpack
.SkipRows
= 0;
1242 ctx
->Unpack
.SkipImages
= 0;
1243 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1244 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1247 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1248 ctx
->Feedback
.Buffer
= NULL
;
1249 ctx
->Feedback
.BufferSize
= 0;
1250 ctx
->Feedback
.Count
= 0;
1252 /* Selection/picking */
1253 ctx
->Select
.Buffer
= NULL
;
1254 ctx
->Select
.BufferSize
= 0;
1255 ctx
->Select
.BufferCount
= 0;
1256 ctx
->Select
.Hits
= 0;
1257 ctx
->Select
.NameStackDepth
= 0;
1259 /* Optimized Accum buffer */
1260 ctx
->IntegerAccumMode
= GL_TRUE
;
1261 ctx
->IntegerAccumScaler
= 0.0;
1263 /* Renderer and client attribute stacks */
1264 ctx
->AttribStackDepth
= 0;
1265 ctx
->ClientAttribStackDepth
= 0;
1269 ctx
->ExecuteFlag
= GL_TRUE
;
1270 ctx
->CompileFlag
= GL_FALSE
;
1271 ctx
->CurrentListPtr
= NULL
;
1272 ctx
->CurrentBlock
= NULL
;
1273 ctx
->CurrentListNum
= 0;
1274 ctx
->CurrentPos
= 0;
1277 _mesa_init_colortable(&ctx
->ColorTable
);
1278 _mesa_init_colortable(&ctx
->ProxyColorTable
);
1279 _mesa_init_colortable(&ctx
->PostConvolutionColorTable
);
1280 _mesa_init_colortable(&ctx
->ProxyPostConvolutionColorTable
);
1281 _mesa_init_colortable(&ctx
->PostColorMatrixColorTable
);
1282 _mesa_init_colortable(&ctx
->ProxyPostColorMatrixColorTable
);
1285 ctx
->NewState
= NEW_ALL
;
1286 ctx
->RenderMode
= GL_RENDER
;
1287 ctx
->StippleCounter
= 0;
1288 ctx
->NeedNormals
= GL_FALSE
;
1289 ctx
->DoViewportMapping
= GL_TRUE
;
1290 ctx
->ImageTransferState
= UPDATE_IMAGE_TRANSFER_STATE
;
1292 ctx
->NeedEyeCoords
= GL_FALSE
;
1293 ctx
->NeedEyeNormals
= GL_FALSE
;
1294 ctx
->vb_proj_matrix
= &ctx
->ModelProjectMatrix
;
1296 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1298 ctx
->CatchSignals
= GL_TRUE
;
1299 ctx
->OcclusionResult
= GL_FALSE
;
1300 ctx
->OcclusionResultSaved
= GL_FALSE
;
1302 /* For debug/development only */
1303 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1304 ctx
->FirstTimeCurrent
= GL_TRUE
;
1306 /* Dither disable */
1307 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1308 if (ctx
->NoDither
) {
1309 if (getenv("MESA_DEBUG")) {
1310 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1312 ctx
->Color
.DitherFlag
= GL_FALSE
;
1320 * Allocate the proxy textures. If we run out of memory part way through
1321 * the allocations clean up and return GL_FALSE.
1322 * Return: GL_TRUE=success, GL_FALSE=failure
1325 alloc_proxy_textures( GLcontext
*ctx
)
1327 GLboolean out_of_memory
;
1330 ctx
->Texture
.Proxy1D
= gl_alloc_texture_object(NULL
, 0, 1);
1331 if (!ctx
->Texture
.Proxy1D
) {
1335 ctx
->Texture
.Proxy2D
= gl_alloc_texture_object(NULL
, 0, 2);
1336 if (!ctx
->Texture
.Proxy2D
) {
1337 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1341 ctx
->Texture
.Proxy3D
= gl_alloc_texture_object(NULL
, 0, 3);
1342 if (!ctx
->Texture
.Proxy3D
) {
1343 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1344 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1348 out_of_memory
= GL_FALSE
;
1349 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1350 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1351 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1352 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1353 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1354 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1355 || !ctx
->Texture
.Proxy3D
->Image
[i
]) {
1356 out_of_memory
= GL_TRUE
;
1359 if (out_of_memory
) {
1360 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1361 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1362 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1364 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1365 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1367 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1368 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1371 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1372 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1373 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1384 * Initialize a GLcontext struct. This includes allocating all the
1385 * other structs and arrays which hang off of the context by pointers.
1388 _mesa_initialize_context( GLcontext
*ctx
,
1390 GLcontext
*share_list
,
1394 GLuint dispatchSize
;
1396 (void) direct
; /* not used */
1398 /* misc one-time initializations */
1401 ctx
->DriverCtx
= driver_ctx
;
1402 ctx
->Visual
= visual
;
1403 ctx
->DrawBuffer
= NULL
;
1404 ctx
->ReadBuffer
= NULL
;
1406 ctx
->VB
= gl_vb_create_for_immediate( ctx
);
1410 ctx
->input
= ctx
->VB
->IM
;
1412 ctx
->PB
= gl_alloc_pb();
1414 ALIGN_FREE( ctx
->VB
);
1419 /* share the group of display lists of another context */
1420 ctx
->Shared
= share_list
->Shared
;
1423 /* allocate new group of display lists */
1424 ctx
->Shared
= alloc_shared_state();
1426 ALIGN_FREE( ctx
->VB
);
1431 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1432 ctx
->Shared
->RefCount
++;
1433 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1435 init_attrib_groups( ctx
);
1437 gl_reset_vb( ctx
->VB
);
1438 gl_reset_input( ctx
);
1440 if (visual
->DBflag
) {
1441 ctx
->Color
.DrawBuffer
= GL_BACK
;
1442 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1443 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1444 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1445 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1448 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1449 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1450 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1451 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1452 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1455 if (!alloc_proxy_textures(ctx
)) {
1456 free_shared_state(ctx
, ctx
->Shared
);
1457 ALIGN_FREE( ctx
->VB
);
1462 /* register the most recent extension functions with libGL */
1463 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1464 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1465 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1466 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1467 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1468 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1469 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1470 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1472 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1473 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1474 * Mesa we do this to accomodate different versions of libGL and various
1477 dispatchSize
= MAX2(_glapi_get_dispatch_table_size(),
1478 sizeof(struct _glapi_table
) / sizeof(void *));
1480 /* setup API dispatch tables */
1481 ctx
->Exec
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1482 ctx
->Save
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1483 if (!ctx
->Exec
|| !ctx
->Save
) {
1484 free_shared_state(ctx
, ctx
->Shared
);
1485 ALIGN_FREE( ctx
->VB
);
1490 _mesa_init_exec_table(ctx
->Exec
, dispatchSize
);
1491 _mesa_init_dlist_table(ctx
->Save
, dispatchSize
);
1492 ctx
->CurrentDispatch
= ctx
->Exec
;
1495 ctx
->TraceCtx
= CALLOC( sizeof(trace_context_t
) );
1497 /* Brian: do you want to have CreateContext fail here,
1498 or should we just trap in NewTrace (currently done)? */
1499 if (!(ctx
->TraceCtx
)) {
1500 free_shared_state(ctx
, ctx
->Shared
);
1501 ALIGN_FREE( ctx
->VB
);
1508 trInitContext(ctx
->TraceCtx
);
1510 ctx
->TraceDispatch
= (struct _glapi_table
*)
1511 CALLOC(dispatchSize
* sizeof(void*));
1513 if (!(ctx
->TraceCtx
)) {
1514 free_shared_state(ctx
, ctx
->Shared
);
1515 ALIGN_FREE( ctx
->VB
);
1519 FREE( ctx
->TraceCtx
);
1523 trInitDispatch(ctx
->TraceDispatch
);
1532 * Allocate and initialize a GLcontext structure.
1533 * Input: visual - a GLvisual pointer
1534 * sharelist - another context to share display lists with or NULL
1535 * driver_ctx - pointer to device driver's context state struct
1536 * Return: pointer to a new gl_context struct or NULL if error.
1539 gl_create_context( GLvisual
*visual
,
1540 GLcontext
*share_list
,
1544 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1549 if (_mesa_initialize_context(ctx
, visual
, share_list
, driver_ctx
, direct
)) {
1561 * Free the data associated with the given context.
1562 * But don't free() the GLcontext struct itself!
1565 gl_free_context_data( GLcontext
*ctx
)
1567 struct gl_shine_tab
*s
, *tmps
;
1570 /* if we're destroying the current context, unbind it first */
1571 if (ctx
== gl_get_current_context()) {
1572 gl_make_current(NULL
, NULL
);
1575 gl_matrix_dtr( &ctx
->ModelView
);
1576 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
1577 gl_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1579 gl_matrix_dtr( &ctx
->ProjectionMatrix
);
1580 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
1581 gl_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1583 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1584 gl_matrix_dtr( &ctx
->TextureMatrix
[i
] );
1585 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
1586 gl_matrix_dtr( &ctx
->TextureStack
[i
][j
] );
1592 if (ctx
->input
!= ctx
->VB
->IM
)
1593 gl_immediate_free( ctx
->input
);
1595 gl_vb_free( ctx
->VB
);
1597 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1598 ctx
->Shared
->RefCount
--;
1599 assert(ctx
->Shared
->RefCount
>= 0);
1600 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1601 if (ctx
->Shared
->RefCount
== 0) {
1602 /* free shared state */
1603 free_shared_state( ctx
, ctx
->Shared
);
1606 foreach_s( s
, tmps
, ctx
->ShineTabList
) {
1609 FREE( ctx
->ShineTabList
);
1611 /* Free proxy texture objects */
1612 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1613 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1614 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1616 /* Free evaluator data */
1617 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1618 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1619 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1620 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1621 if (ctx
->EvalMap
.Map1Index
.Points
)
1622 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1623 if (ctx
->EvalMap
.Map1Color4
.Points
)
1624 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1625 if (ctx
->EvalMap
.Map1Normal
.Points
)
1626 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1627 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1628 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1629 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1630 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1631 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1632 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1633 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1634 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1636 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1637 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1638 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1639 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1640 if (ctx
->EvalMap
.Map2Index
.Points
)
1641 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1642 if (ctx
->EvalMap
.Map2Color4
.Points
)
1643 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1644 if (ctx
->EvalMap
.Map2Normal
.Points
)
1645 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1646 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1647 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1648 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1649 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1650 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1651 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1652 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1653 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1655 _mesa_free_colortable_data( &ctx
->ColorTable
);
1656 _mesa_free_colortable_data( &ctx
->PostConvolutionColorTable
);
1657 _mesa_free_colortable_data( &ctx
->PostColorMatrixColorTable
);
1658 _mesa_free_colortable_data( &ctx
->Texture
.Palette
);
1660 /* Free cache of immediate buffers. */
1661 while (ctx
->nr_im_queued
-- > 0) {
1662 struct immediate
* next
= ctx
->freed_im_queue
->next
;
1663 ALIGN_FREE( ctx
->freed_im_queue
);
1664 ctx
->freed_im_queue
= next
;
1666 gl_extensions_dtr(ctx
);
1675 * Destroy a GLcontext structure.
1678 gl_destroy_context( GLcontext
*ctx
)
1681 gl_free_context_data(ctx
);
1682 FREE( (void *) ctx
);
1689 * Called by the driver after both the context and driver are fully
1690 * initialized. Currently just reads the config file.
1693 gl_context_initialize( GLcontext
*ctx
)
1695 gl_read_config_file( ctx
);
1701 * Copy attribute groups from one context to another.
1702 * Input: src - source context
1703 * dst - destination context
1704 * mask - bitwise OR of GL_*_BIT flags
1707 gl_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1709 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1710 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1712 if (mask
& GL_COLOR_BUFFER_BIT
) {
1713 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1715 if (mask
& GL_CURRENT_BIT
) {
1716 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1718 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1719 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1721 if (mask
& GL_ENABLE_BIT
) {
1724 if (mask
& GL_EVAL_BIT
) {
1725 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1727 if (mask
& GL_FOG_BIT
) {
1728 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1730 if (mask
& GL_HINT_BIT
) {
1731 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1733 if (mask
& GL_LIGHTING_BIT
) {
1734 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1735 /* gl_reinit_light_attrib( &dst->Light ); */
1737 if (mask
& GL_LINE_BIT
) {
1738 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1740 if (mask
& GL_LIST_BIT
) {
1741 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1743 if (mask
& GL_PIXEL_MODE_BIT
) {
1744 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1746 if (mask
& GL_POINT_BIT
) {
1747 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1749 if (mask
& GL_POLYGON_BIT
) {
1750 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1752 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1753 /* Use loop instead of MEMCPY due to problem with Portland Group's
1754 * C compiler. Reported by John Stone.
1757 for (i
=0;i
<32;i
++) {
1758 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1761 if (mask
& GL_SCISSOR_BIT
) {
1762 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1764 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1765 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1767 if (mask
& GL_TEXTURE_BIT
) {
1768 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1770 if (mask
& GL_TRANSFORM_BIT
) {
1771 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1773 if (mask
& GL_VIEWPORT_BIT
) {
1774 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1780 * Set the current context, binding the given frame buffer to the context.
1782 void gl_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1784 gl_make_current2( newCtx
, buffer
, buffer
);
1789 * Bind the given context to the given draw-buffer and read-buffer
1790 * and make it the current context for this thread.
1792 void gl_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1793 GLframebuffer
*readBuffer
)
1796 GLcontext
*oldCtx
= gl_get_context();
1798 /* Flush the old context
1801 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx
, "gl_make_current");
1803 /* unbind frame buffers from context */
1804 if (oldCtx
->DrawBuffer
) {
1805 oldCtx
->DrawBuffer
= NULL
;
1807 if (oldCtx
->ReadBuffer
) {
1808 oldCtx
->ReadBuffer
= NULL
;
1813 /* We call this function periodically (just here for now) in
1814 * order to detect when multithreading has begun.
1816 _glapi_check_multithread();
1818 _glapi_set_context((void *) newCtx
);
1819 ASSERT(gl_get_current_context() == newCtx
);
1821 SET_IMMEDIATE(newCtx
, newCtx
->input
);
1822 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1825 _glapi_set_dispatch(NULL
); /* none current */
1828 if (MESA_VERBOSE
) fprintf(stderr
, "gl_make_current()\n");
1830 if (newCtx
&& drawBuffer
&& readBuffer
) {
1831 /* TODO: check if newCtx and buffer's visual match??? */
1832 newCtx
->DrawBuffer
= drawBuffer
;
1833 newCtx
->ReadBuffer
= readBuffer
;
1834 newCtx
->NewState
= NEW_ALL
; /* just to be safe */
1835 gl_update_state( newCtx
);
1838 /* We can use this to help debug user's problems. Tell the to set
1839 * the MESA_INFO env variable before running their app. Then the
1840 * first time each context is made current we'll print some useful
1843 if (newCtx
&& newCtx
->FirstTimeCurrent
) {
1844 if (getenv("MESA_INFO")) {
1845 fprintf(stderr
, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION
));
1846 fprintf(stderr
, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER
));
1847 fprintf(stderr
, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR
));
1848 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS
));
1849 #if defined(THREADS)
1850 fprintf(stderr
, "Mesa thread-safe: YES\n");
1852 fprintf(stderr
, "Mesa thread-safe: NO\n");
1854 #if defined(USE_X86_ASM)
1855 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1857 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1860 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1867 * Return current context handle for the calling thread.
1868 * This isn't the fastest way to get the current context.
1869 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1871 GLcontext
*gl_get_current_context( void )
1873 return (GLcontext
*) _glapi_get_context();
1879 * This should be called by device drivers just before they do a
1880 * swapbuffers. Any pending rendering commands will be executed.
1883 _mesa_swapbuffers(GLcontext
*ctx
)
1885 FLUSH_VB( ctx
, "swap buffers" );
1891 * Return pointer to this context's current API dispatch table.
1892 * It'll either be the immediate-mode execute dispatcher or the
1893 * display list compile dispatcher.
1895 struct _glapi_table
*
1896 _mesa_get_dispatch(GLcontext
*ctx
)
1898 return ctx
->CurrentDispatch
;
1903 /**********************************************************************/
1904 /***** Miscellaneous functions *****/
1905 /**********************************************************************/
1909 * This function is called when the Mesa user has stumbled into a code
1910 * path which may not be implemented fully or correctly.
1912 void gl_problem( const GLcontext
*ctx
, const char *s
)
1914 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
1915 fprintf( stderr
, "Report to Mesa bug database at www.mesa3d.org\n" );
1922 * This is called to inform the user that he or she has tried to do
1923 * something illogical or if there's likely a bug in their program
1924 * (like enabled depth testing without a depth buffer).
1926 void gl_warning( const GLcontext
*ctx
, const char *s
)
1932 if (getenv("MESA_DEBUG")) {
1940 fprintf( stderr
, "Mesa warning: %s\n", s
);
1948 * Compile an error into current display list.
1950 void gl_compile_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1952 if (ctx
->CompileFlag
)
1953 gl_save_error( ctx
, error
, s
);
1955 if (ctx
->ExecuteFlag
)
1956 gl_error( ctx
, error
, s
);
1962 * This is Mesa's error handler. Normally, all that's done is the updating
1963 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1964 * environment variable "MESA_DEBUG" is defined then a real error message
1965 * is printed to stderr.
1966 * Input: ctx - the GL context
1967 * error - the error value
1968 * where - usually the name of function where error was detected
1971 gl_error( GLcontext
*ctx
, GLenum error
, const char *where
)
1973 const char *debugEnv
= getenv("MESA_DEBUG");
1977 if (debugEnv
&& strstr(debugEnv
, "silent"))
1992 errstr
= "GL_NO_ERROR";
1994 case GL_INVALID_VALUE
:
1995 errstr
= "GL_INVALID_VALUE";
1997 case GL_INVALID_ENUM
:
1998 errstr
= "GL_INVALID_ENUM";
2000 case GL_INVALID_OPERATION
:
2001 errstr
= "GL_INVALID_OPERATION";
2003 case GL_STACK_OVERFLOW
:
2004 errstr
= "GL_STACK_OVERFLOW";
2006 case GL_STACK_UNDERFLOW
:
2007 errstr
= "GL_STACK_UNDERFLOW";
2009 case GL_OUT_OF_MEMORY
:
2010 errstr
= "GL_OUT_OF_MEMORY";
2012 case GL_TABLE_TOO_LARGE
:
2013 errstr
= "GL_TABLE_TOO_LARGE";
2019 fprintf(stderr
, "Mesa user error: %s in %s\n", errstr
, where
);
2022 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
2023 ctx
->ErrorValue
= error
;
2026 /* Call device driver's error handler, if any. This is used on the Mac. */
2027 if (ctx
->Driver
.Error
) {
2028 (*ctx
->Driver
.Error
)( ctx
);
2035 _mesa_Finish( void )
2037 GET_CURRENT_CONTEXT(ctx
);
2038 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFinish");
2039 if (ctx
->Driver
.Finish
) {
2040 (*ctx
->Driver
.Finish
)( ctx
);
2049 GET_CURRENT_CONTEXT(ctx
);
2050 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFlush");
2051 if (ctx
->Driver
.Flush
) {
2052 (*ctx
->Driver
.Flush
)( ctx
);