1 /* $Id: context.c,v 1.150 2001/12/14 02:50:01 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
39 #include "extensions.h"
49 #include "simple_list.h"
56 #include "math/m_translate.h"
57 #include "math/m_vertices.h"
58 #include "math/m_matrix.h"
59 #include "math/m_xform.h"
60 #include "math/mathmod.h"
63 #if defined(MESA_TRACE)
64 #include "Trace/tr_context.h"
65 #include "Trace/tr_wrapper.h"
69 #include "SPARC/sparc.h"
74 /* | VERBOSE_PIPELINE */
75 /* | VERBOSE_IMMEDIATE */
76 /* | VERBOSE_VARRAY */
77 /* | VERBOSE_TEXTURE */
79 /* | VERBOSE_DRIVER */
81 /* | VERBOSE_DISPLAY_LIST */
85 #ifndef MESA_DEBUG_FLAGS
86 int MESA_DEBUG_FLAGS
= 0
87 /* | DEBUG_ALWAYS_FLUSH */
93 /**********************************************************************/
94 /***** OpenGL SI-style interface (new in Mesa 3.5) *****/
95 /**********************************************************************/
98 _mesa_DestroyContext(__GLcontext
*gc
)
101 _mesa_free_context_data(gc
);
102 (*gc
->imports
.free
)(gc
, gc
);
108 /* exported OpenGL SI interface */
110 __glCoreCreateContext(__GLimports
*imports
, __GLcontextModes
*modes
)
114 ctx
= (GLcontext
*) (*imports
->calloc
)(0, 1, sizeof(GLcontext
));
118 ctx
->Driver
.CurrentExecPrimitive
=0;
119 ctx
->imports
= *imports
;
121 _mesa_initialize_visual(&ctx
->Visual
,
123 modes
->doubleBufferMode
,
133 modes
->accumGreenBits
,
134 modes
->accumBlueBits
,
135 modes
->accumAlphaBits
,
138 /* KW: was imports->wscx */
139 _mesa_initialize_context(ctx
, &ctx
->Visual
, NULL
, imports
->other
, GL_FALSE
);
141 ctx
->exports
.destroyContext
= _mesa_DestroyContext
;
147 /* exported OpenGL SI interface */
149 __glCoreNopDispatch(void)
153 __gl_dispatch
= __glNopDispatchState
;
156 _glapi_set_dispatch(NULL
);
161 /**********************************************************************/
162 /***** Context and Thread management *****/
163 /**********************************************************************/
167 /**********************************************************************/
168 /***** GL Visual allocation/destruction *****/
169 /**********************************************************************/
173 * Allocate a new GLvisual object.
174 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
175 * dbFlag - double buffering?
176 * stereoFlag - stereo buffer?
177 * depthBits - requested bits per depth buffer value
178 * Any value in [0, 32] is acceptable but the actual
179 * depth type will be GLushort or GLuint as needed.
180 * stencilBits - requested minimum bits per stencil buffer value
181 * accumBits - requested minimum bits per accum buffer component
182 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
183 * red/green/blue/alphaBits - number of bits per color component
184 * in frame buffer for RGB(A) mode.
185 * We always use 8 in core Mesa though.
186 * Return: pointer to new GLvisual or NULL if requested parameters can't
190 _mesa_create_visual( GLboolean rgbFlag
,
192 GLboolean stereoFlag
,
201 GLint accumGreenBits
,
203 GLint accumAlphaBits
,
206 GLvisual
*vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
208 if (!_mesa_initialize_visual(vis
, rgbFlag
, dbFlag
, stereoFlag
,
209 redBits
, greenBits
, blueBits
, alphaBits
,
210 indexBits
, depthBits
, stencilBits
,
211 accumRedBits
, accumGreenBits
,
212 accumBlueBits
, accumAlphaBits
,
223 * Initialize the fields of the given GLvisual.
224 * Input: see _mesa_create_visual() above.
225 * Return: GL_TRUE = success
226 * GL_FALSE = failure.
229 _mesa_initialize_visual( GLvisual
*vis
,
232 GLboolean stereoFlag
,
241 GLint accumGreenBits
,
243 GLint accumAlphaBits
,
250 /* This is to catch bad values from device drivers not updated for
251 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
252 * bad value now (a 1-bit depth buffer!?!).
254 assert(depthBits
== 0 || depthBits
> 1);
256 if (depthBits
< 0 || depthBits
> 32) {
259 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
262 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
265 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
268 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
271 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
275 vis
->rgbMode
= rgbFlag
;
276 vis
->doubleBufferMode
= dbFlag
;
277 vis
->stereoMode
= stereoFlag
;
278 vis
->redBits
= redBits
;
279 vis
->greenBits
= greenBits
;
280 vis
->blueBits
= blueBits
;
281 vis
->alphaBits
= alphaBits
;
283 vis
->indexBits
= indexBits
;
284 vis
->depthBits
= depthBits
;
285 vis
->accumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
286 vis
->accumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
287 vis
->accumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
288 vis
->accumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
289 vis
->stencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
296 _mesa_destroy_visual( GLvisual
*vis
)
302 /**********************************************************************/
303 /***** GL Framebuffer allocation/destruction *****/
304 /**********************************************************************/
308 * Create a new framebuffer. A GLframebuffer is a struct which
309 * encapsulates the depth, stencil and accum buffers and related
311 * Input: visual - a GLvisual pointer (we copy the struct contents)
312 * softwareDepth - create/use a software depth buffer?
313 * softwareStencil - create/use a software stencil buffer?
314 * softwareAccum - create/use a software accum buffer?
315 * softwareAlpha - create/use a software alpha buffer?
316 * Return: pointer to new GLframebuffer struct or NULL if error.
319 _mesa_create_framebuffer( const GLvisual
*visual
,
320 GLboolean softwareDepth
,
321 GLboolean softwareStencil
,
322 GLboolean softwareAccum
,
323 GLboolean softwareAlpha
)
325 GLframebuffer
*buffer
= CALLOC_STRUCT(gl_frame_buffer
);
328 _mesa_initialize_framebuffer(buffer
, visual
,
329 softwareDepth
, softwareStencil
,
330 softwareAccum
, softwareAlpha
);
337 * Initialize a GLframebuffer object.
338 * Input: See _mesa_create_framebuffer() above.
341 _mesa_initialize_framebuffer( GLframebuffer
*buffer
,
342 const GLvisual
*visual
,
343 GLboolean softwareDepth
,
344 GLboolean softwareStencil
,
345 GLboolean softwareAccum
,
346 GLboolean softwareAlpha
)
352 if (softwareDepth
) {
353 assert(visual
->depthBits
> 0);
355 if (softwareStencil
) {
356 assert(visual
->stencilBits
> 0);
359 assert(visual
->rgbMode
);
360 assert(visual
->accumRedBits
> 0);
361 assert(visual
->accumGreenBits
> 0);
362 assert(visual
->accumBlueBits
> 0);
365 assert(visual
->rgbMode
);
366 assert(visual
->alphaBits
> 0);
369 buffer
->Visual
= *visual
;
370 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
371 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
372 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
373 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
378 * Free a framebuffer struct and its buffers.
381 _mesa_destroy_framebuffer( GLframebuffer
*buffer
)
384 _mesa_free_framebuffer_data(buffer
);
391 * Free the data hanging off of <buffer>, but not <buffer> itself.
394 _mesa_free_framebuffer_data( GLframebuffer
*buffer
)
399 if (buffer
->DepthBuffer
) {
400 FREE( buffer
->DepthBuffer
);
401 buffer
->DepthBuffer
= NULL
;
404 FREE( buffer
->Accum
);
405 buffer
->Accum
= NULL
;
407 if (buffer
->Stencil
) {
408 FREE( buffer
->Stencil
);
409 buffer
->Stencil
= NULL
;
411 if (buffer
->FrontLeftAlpha
) {
412 FREE( buffer
->FrontLeftAlpha
);
413 buffer
->FrontLeftAlpha
= NULL
;
415 if (buffer
->BackLeftAlpha
) {
416 FREE( buffer
->BackLeftAlpha
);
417 buffer
->BackLeftAlpha
= NULL
;
419 if (buffer
->FrontRightAlpha
) {
420 FREE( buffer
->FrontRightAlpha
);
421 buffer
->FrontRightAlpha
= NULL
;
423 if (buffer
->BackRightAlpha
) {
424 FREE( buffer
->BackRightAlpha
);
425 buffer
->BackRightAlpha
= NULL
;
431 /**********************************************************************/
432 /***** Context allocation, initialization, destroying *****/
433 /**********************************************************************/
436 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
440 * This function just calls all the various one-time-init functions in Mesa.
443 one_time_init( void )
445 static GLboolean alreadyCalled
= GL_FALSE
;
446 _glthread_LOCK_MUTEX(OneTimeLock
);
447 if (!alreadyCalled
) {
448 /* do some implementation tests */
449 assert( sizeof(GLbyte
) == 1 );
450 assert( sizeof(GLshort
) >= 2 );
451 assert( sizeof(GLint
) >= 4 );
452 assert( sizeof(GLubyte
) == 1 );
453 assert( sizeof(GLushort
) >= 2 );
454 assert( sizeof(GLuint
) >= 4 );
462 _mesa_init_sparc_glapi_relocs();
464 if (getenv("MESA_DEBUG")) {
465 _glapi_noop_enable_warnings(GL_TRUE
);
468 _glapi_noop_enable_warnings(GL_FALSE
);
471 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
472 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
475 alreadyCalled
= GL_TRUE
;
477 _glthread_UNLOCK_MUTEX(OneTimeLock
);
482 init_matrix_stack( struct matrix_stack
*stack
,
483 GLuint maxDepth
, GLuint dirtyFlag
)
488 stack
->MaxDepth
= maxDepth
;
489 stack
->DirtyFlag
= dirtyFlag
;
491 _math_matrix_ctr( &stack
->Top
);
492 _math_matrix_alloc_inv( &stack
->Top
);
494 stack
->Stack
= MALLOC(maxDepth
* sizeof(GLmatrix
));
495 for (i
= 0; i
< maxDepth
; i
++) {
496 _math_matrix_ctr(&stack
->Stack
[i
]);
497 _math_matrix_alloc_inv(&stack
->Stack
[i
]);
503 free_matrix_stack( struct matrix_stack
*stack
)
506 _math_matrix_dtr( &stack
->Top
);
507 for (i
= 0; i
< stack
->MaxDepth
; i
++) {
508 _math_matrix_dtr(&stack
->Stack
[i
]);
514 * Allocate and initialize a shared context state structure.
516 static struct gl_shared_state
*
517 alloc_shared_state( void )
519 struct gl_shared_state
*ss
;
520 GLboolean outOfMemory
;
522 ss
= CALLOC_STRUCT(gl_shared_state
);
526 _glthread_INIT_MUTEX(ss
->Mutex
);
528 ss
->DisplayList
= _mesa_NewHashTable();
529 ss
->TexObjects
= _mesa_NewHashTable();
531 /* Default Texture objects */
532 outOfMemory
= GL_FALSE
;
534 ss
->Default1D
= _mesa_alloc_texture_object(ss
, 0, 1);
535 if (!ss
->Default1D
) {
536 outOfMemory
= GL_TRUE
;
539 ss
->Default2D
= _mesa_alloc_texture_object(ss
, 0, 2);
540 if (!ss
->Default2D
) {
541 outOfMemory
= GL_TRUE
;
544 ss
->Default3D
= _mesa_alloc_texture_object(ss
, 0, 3);
545 if (!ss
->Default3D
) {
546 outOfMemory
= GL_TRUE
;
549 ss
->DefaultCubeMap
= _mesa_alloc_texture_object(ss
, 0, 6);
550 if (!ss
->DefaultCubeMap
) {
551 outOfMemory
= GL_TRUE
;
554 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
555 /* Ran out of memory at some point. Free everything and return NULL */
557 _mesa_DeleteHashTable(ss
->DisplayList
);
559 _mesa_DeleteHashTable(ss
->TexObjects
);
561 _mesa_free_texture_object(ss
, ss
->Default1D
);
563 _mesa_free_texture_object(ss
, ss
->Default2D
);
565 _mesa_free_texture_object(ss
, ss
->Default3D
);
566 if (ss
->DefaultCubeMap
)
567 _mesa_free_texture_object(ss
, ss
->DefaultCubeMap
);
578 * Deallocate a shared state context and all children structures.
581 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
583 /* Free display lists */
585 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
587 _mesa_destroy_list(ctx
, list
);
593 _mesa_DeleteHashTable(ss
->DisplayList
);
595 /* Free texture objects */
596 while (ss
->TexObjectList
) {
597 if (ctx
->Driver
.DeleteTexture
)
598 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
599 /* this function removes from linked list too! */
600 _mesa_free_texture_object(ss
, ss
->TexObjectList
);
602 _mesa_DeleteHashTable(ss
->TexObjects
);
610 * Initialize the nth light. Note that the defaults for light 0 are
611 * different than the other lights.
614 init_light( struct gl_light
*l
, GLuint n
)
616 make_empty_list( l
);
618 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
620 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
621 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
624 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
625 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
627 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
628 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
629 l
->SpotExponent
= 0.0;
630 _mesa_invalidate_spot_exp_table( l
);
631 l
->SpotCutoff
= 180.0;
632 l
->_CosCutoff
= 0.0; /* KW: -ve values not admitted */
633 l
->ConstantAttenuation
= 1.0;
634 l
->LinearAttenuation
= 0.0;
635 l
->QuadraticAttenuation
= 0.0;
636 l
->Enabled
= GL_FALSE
;
642 init_lightmodel( struct gl_lightmodel
*lm
)
644 ASSIGN_4V( lm
->Ambient
, 0.2F
, 0.2F
, 0.2F
, 1.0F
);
645 lm
->LocalViewer
= GL_FALSE
;
646 lm
->TwoSide
= GL_FALSE
;
647 lm
->ColorControl
= GL_SINGLE_COLOR
;
652 init_material( struct gl_material
*m
)
654 ASSIGN_4V( m
->Ambient
, 0.2F
, 0.2F
, 0.2F
, 1.0F
);
655 ASSIGN_4V( m
->Diffuse
, 0.8F
, 0.8F
, 0.8F
, 1.0F
);
656 ASSIGN_4V( m
->Specular
, 0.0F
, 0.0F
, 0.0F
, 1.0F
);
657 ASSIGN_4V( m
->Emission
, 0.0F
, 0.0F
, 0.0F
, 1.0F
);
661 m
->SpecularIndex
= 1;
667 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
669 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
671 texUnit
->EnvMode
= GL_MODULATE
;
672 texUnit
->CombineModeRGB
= GL_MODULATE
;
673 texUnit
->CombineModeA
= GL_MODULATE
;
674 texUnit
->CombineSourceRGB
[0] = GL_TEXTURE
;
675 texUnit
->CombineSourceRGB
[1] = GL_PREVIOUS_EXT
;
676 texUnit
->CombineSourceRGB
[2] = GL_CONSTANT_EXT
;
677 texUnit
->CombineSourceA
[0] = GL_TEXTURE
;
678 texUnit
->CombineSourceA
[1] = GL_PREVIOUS_EXT
;
679 texUnit
->CombineSourceA
[2] = GL_CONSTANT_EXT
;
680 texUnit
->CombineOperandRGB
[0] = GL_SRC_COLOR
;
681 texUnit
->CombineOperandRGB
[1] = GL_SRC_COLOR
;
682 texUnit
->CombineOperandRGB
[2] = GL_SRC_ALPHA
;
683 texUnit
->CombineOperandA
[0] = GL_SRC_ALPHA
;
684 texUnit
->CombineOperandA
[1] = GL_SRC_ALPHA
;
685 texUnit
->CombineOperandA
[2] = GL_SRC_ALPHA
;
686 texUnit
->CombineScaleShiftRGB
= 0;
687 texUnit
->CombineScaleShiftA
= 0;
689 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
690 texUnit
->TexGenEnabled
= 0;
691 texUnit
->GenModeS
= GL_EYE_LINEAR
;
692 texUnit
->GenModeT
= GL_EYE_LINEAR
;
693 texUnit
->GenModeR
= GL_EYE_LINEAR
;
694 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
695 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
696 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
697 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
698 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
700 /* Yes, these plane coefficients are correct! */
701 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
702 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
703 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
704 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
705 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
706 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
707 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
708 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
710 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
711 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
712 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
713 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
719 /* Initialize a 1-D evaluator map */
721 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
726 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
730 map
->Points
[i
] = initial
[i
];
735 /* Initialize a 2-D evaluator map */
737 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
745 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
749 map
->Points
[i
] = initial
[i
];
755 * Initialize the attribute groups in a GLcontext.
758 init_attrib_groups( GLcontext
*ctx
)
764 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
765 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
767 /* Constants, may be overriden by device drivers */
768 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
769 ctx
->Const
.Max3DTextureLevels
= MAX_3D_TEXTURE_LEVELS
;
770 ctx
->Const
.MaxCubeTextureLevels
= MAX_CUBE_TEXTURE_LEVELS
;
771 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
772 ctx
->Const
.MaxTextureMaxAnisotropy
= MAX_TEXTURE_MAX_ANISOTROPY
;
773 ctx
->Const
.MaxTextureLodBias
= MAX_TEXTURE_LOD_BIAS
;
774 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
775 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
776 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
777 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
778 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
779 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
780 ctx
->Const
.PointSizeGranularity
= (GLfloat
) POINT_SIZE_GRANULARITY
;
781 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
782 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
783 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
784 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
785 ctx
->Const
.LineWidthGranularity
= (GLfloat
) LINE_WIDTH_GRANULARITY
;
786 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
787 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
788 ctx
->Const
.MaxConvolutionWidth
= MAX_CONVOLUTION_WIDTH
;
789 ctx
->Const
.MaxConvolutionHeight
= MAX_CONVOLUTION_HEIGHT
;
790 ctx
->Const
.NumCompressedTextureFormats
= 0;
791 ctx
->Const
.MaxClipPlanes
= MAX_CLIP_PLANES
;
792 ctx
->Const
.MaxLights
= MAX_LIGHTS
;
794 /* Modelview matrix */
795 _math_matrix_ctr( &ctx
->ModelView
);
796 _math_matrix_alloc_inv( &ctx
->ModelView
);
798 ctx
->ModelViewStackDepth
= 0;
799 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
800 _math_matrix_ctr( &ctx
->ModelViewStack
[i
] );
801 _math_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
804 init_matrix_stack(&ctx
->ModelviewStack
, 32, _NEW_MODELVIEW
);
807 /* Projection matrix - need inv for user clipping in clip space*/
808 _math_matrix_ctr( &ctx
->ProjectionMatrix
);
809 _math_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
811 ctx
->ProjectionStackDepth
= 0;
812 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
813 _math_matrix_ctr( &ctx
->ProjectionStack
[i
] );
814 _math_matrix_alloc_inv( &ctx
->ProjectionStack
[i
] );
817 /* Derived ModelProject matrix */
818 _math_matrix_ctr( &ctx
->_ModelProjectMatrix
);
821 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
822 _math_matrix_ctr( &ctx
->TextureMatrix
[i
] );
823 ctx
->TextureStackDepth
[i
] = 0;
824 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
825 _math_matrix_ctr( &ctx
->TextureStack
[i
][j
] );
826 ctx
->TextureStack
[i
][j
].inv
= 0;
831 _math_matrix_ctr(&ctx
->ColorMatrix
);
832 ctx
->ColorStackDepth
= 0;
833 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
834 _math_matrix_ctr(&ctx
->ColorStack
[j
]);
837 /* Accumulate buffer group */
838 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
840 /* Color buffer group */
841 ctx
->Color
.IndexMask
= 0xffffffff;
842 ctx
->Color
.ColorMask
[0] = 0xff;
843 ctx
->Color
.ColorMask
[1] = 0xff;
844 ctx
->Color
.ColorMask
[2] = 0xff;
845 ctx
->Color
.ColorMask
[3] = 0xff;
846 ctx
->Color
.ClearIndex
= 0;
847 ASSIGN_4V( ctx
->Color
.ClearColor
, 0, 0, 0, 0 );
848 ctx
->Color
.DrawBuffer
= GL_FRONT
;
849 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
850 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
851 ctx
->Color
.AlphaRef
= 0;
852 ctx
->Color
.BlendEnabled
= GL_FALSE
;
853 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
854 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
855 ctx
->Color
.BlendSrcA
= GL_ONE
;
856 ctx
->Color
.BlendDstA
= GL_ZERO
;
857 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
858 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
859 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
860 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
861 ctx
->Color
.LogicOp
= GL_COPY
;
862 ctx
->Color
.DitherFlag
= GL_TRUE
;
863 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
866 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_WEIGHT
], 0.0, 0.0, 0.0, 0.0 );
867 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
], 0.0, 0.0, 1.0, 0.0 );
868 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], 1.0, 1.0, 1.0, 1.0 );
869 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
], 0.0, 0.0, 0.0, 0.0 );
870 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
], 0.0, 0.0, 0.0, 0.0 );
871 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
872 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
], 0.0, 0.0, 0.0, 1.0 );
873 ctx
->Current
.Index
= 1;
874 ctx
->Current
.EdgeFlag
= GL_TRUE
;
876 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
877 ctx
->Current
.RasterDistance
= 0.0;
878 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
879 ctx
->Current
.RasterIndex
= 1;
880 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
881 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
882 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
883 ctx
->Current
.RasterPosValid
= GL_TRUE
;
886 /* Depth buffer group */
887 ctx
->Depth
.Test
= GL_FALSE
;
888 ctx
->Depth
.Clear
= 1.0;
889 ctx
->Depth
.Func
= GL_LESS
;
890 ctx
->Depth
.Mask
= GL_TRUE
;
891 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
893 /* Evaluators group */
894 ctx
->Eval
.Map1Color4
= GL_FALSE
;
895 ctx
->Eval
.Map1Index
= GL_FALSE
;
896 ctx
->Eval
.Map1Normal
= GL_FALSE
;
897 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
898 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
899 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
900 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
901 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
902 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
903 ctx
->Eval
.Map2Color4
= GL_FALSE
;
904 ctx
->Eval
.Map2Index
= GL_FALSE
;
905 ctx
->Eval
.Map2Normal
= GL_FALSE
;
906 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
907 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
908 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
909 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
910 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
911 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
912 ctx
->Eval
.AutoNormal
= GL_FALSE
;
913 ctx
->Eval
.MapGrid1un
= 1;
914 ctx
->Eval
.MapGrid1u1
= 0.0;
915 ctx
->Eval
.MapGrid1u2
= 1.0;
916 ctx
->Eval
.MapGrid2un
= 1;
917 ctx
->Eval
.MapGrid2vn
= 1;
918 ctx
->Eval
.MapGrid2u1
= 0.0;
919 ctx
->Eval
.MapGrid2u2
= 1.0;
920 ctx
->Eval
.MapGrid2v1
= 0.0;
921 ctx
->Eval
.MapGrid2v2
= 1.0;
925 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
926 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
927 static GLfloat index
[1] = { 1.0 };
928 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
929 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
931 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
932 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
933 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
934 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
935 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
936 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
937 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
938 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
939 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
941 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
942 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
943 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
944 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
945 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
946 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
947 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
948 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
949 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
953 ctx
->Fog
.Enabled
= GL_FALSE
;
954 ctx
->Fog
.Mode
= GL_EXP
;
955 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
956 ctx
->Fog
.Index
= 0.0;
957 ctx
->Fog
.Density
= 1.0;
958 ctx
->Fog
.Start
= 0.0;
960 ctx
->Fog
.ColorSumEnabled
= GL_FALSE
;
961 ctx
->Fog
.FogCoordinateSource
= GL_FRAGMENT_DEPTH_EXT
;
964 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
965 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
966 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
967 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
968 ctx
->Hint
.Fog
= GL_DONT_CARE
;
969 ctx
->Hint
.ClipVolumeClipping
= GL_DONT_CARE
;
970 ctx
->Hint
.TextureCompression
= GL_DONT_CARE
;
971 ctx
->Hint
.GenerateMipmap
= GL_DONT_CARE
;
973 /* Histogram group */
974 ctx
->Histogram
.Width
= 0;
975 ctx
->Histogram
.Format
= GL_RGBA
;
976 ctx
->Histogram
.Sink
= GL_FALSE
;
977 ctx
->Histogram
.RedSize
= 0;
978 ctx
->Histogram
.GreenSize
= 0;
979 ctx
->Histogram
.BlueSize
= 0;
980 ctx
->Histogram
.AlphaSize
= 0;
981 ctx
->Histogram
.LuminanceSize
= 0;
982 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
983 ctx
->Histogram
.Count
[i
][0] = 0;
984 ctx
->Histogram
.Count
[i
][1] = 0;
985 ctx
->Histogram
.Count
[i
][2] = 0;
986 ctx
->Histogram
.Count
[i
][3] = 0;
990 ctx
->MinMax
.Format
= GL_RGBA
;
991 ctx
->MinMax
.Sink
= GL_FALSE
;
992 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
993 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
994 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
995 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
998 _mesa_extensions_ctr( ctx
);
1000 /* Lighting group */
1001 for (i
=0;i
<MAX_LIGHTS
;i
++) {
1002 init_light( &ctx
->Light
.Light
[i
], i
);
1004 make_empty_list( &ctx
->Light
.EnabledList
);
1006 init_lightmodel( &ctx
->Light
.Model
);
1007 init_material( &ctx
->Light
.Material
[0] );
1008 init_material( &ctx
->Light
.Material
[1] );
1009 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
1010 ctx
->Light
.Enabled
= GL_FALSE
;
1011 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
1012 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
1013 ctx
->Light
.ColorMaterialBitmask
= _mesa_material_bitmask( ctx
,
1015 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
1017 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1019 /* Lighting miscellaneous */
1020 ctx
->_ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1021 make_empty_list( ctx
->_ShineTabList
);
1022 for (i
= 0 ; i
< 10 ; i
++) {
1023 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1026 insert_at_tail( ctx
->_ShineTabList
, s
);
1031 ctx
->Line
.SmoothFlag
= GL_FALSE
;
1032 ctx
->Line
.StippleFlag
= GL_FALSE
;
1033 ctx
->Line
.Width
= 1.0;
1034 ctx
->Line
._Width
= 1.0;
1035 ctx
->Line
.StipplePattern
= 0xffff;
1036 ctx
->Line
.StippleFactor
= 1;
1038 /* Display List group */
1039 ctx
->List
.ListBase
= 0;
1042 ctx
->Multisample
.Enabled
= GL_FALSE
;
1043 ctx
->Multisample
.SampleAlphaToCoverage
= GL_FALSE
;
1044 ctx
->Multisample
.SampleAlphaToOne
= GL_FALSE
;
1045 ctx
->Multisample
.SampleCoverage
= GL_FALSE
;
1046 ctx
->Multisample
.SampleCoverageValue
= 1.0;
1047 ctx
->Multisample
.SampleCoverageInvert
= GL_FALSE
;
1050 ctx
->Pixel
.RedBias
= 0.0;
1051 ctx
->Pixel
.RedScale
= 1.0;
1052 ctx
->Pixel
.GreenBias
= 0.0;
1053 ctx
->Pixel
.GreenScale
= 1.0;
1054 ctx
->Pixel
.BlueBias
= 0.0;
1055 ctx
->Pixel
.BlueScale
= 1.0;
1056 ctx
->Pixel
.AlphaBias
= 0.0;
1057 ctx
->Pixel
.AlphaScale
= 1.0;
1058 ctx
->Pixel
.DepthBias
= 0.0;
1059 ctx
->Pixel
.DepthScale
= 1.0;
1060 ctx
->Pixel
.IndexOffset
= 0;
1061 ctx
->Pixel
.IndexShift
= 0;
1062 ctx
->Pixel
.ZoomX
= 1.0;
1063 ctx
->Pixel
.ZoomY
= 1.0;
1064 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
1065 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
1066 ctx
->Pixel
.MapStoSsize
= 1;
1067 ctx
->Pixel
.MapItoIsize
= 1;
1068 ctx
->Pixel
.MapItoRsize
= 1;
1069 ctx
->Pixel
.MapItoGsize
= 1;
1070 ctx
->Pixel
.MapItoBsize
= 1;
1071 ctx
->Pixel
.MapItoAsize
= 1;
1072 ctx
->Pixel
.MapRtoRsize
= 1;
1073 ctx
->Pixel
.MapGtoGsize
= 1;
1074 ctx
->Pixel
.MapBtoBsize
= 1;
1075 ctx
->Pixel
.MapAtoAsize
= 1;
1076 ctx
->Pixel
.MapStoS
[0] = 0;
1077 ctx
->Pixel
.MapItoI
[0] = 0;
1078 ctx
->Pixel
.MapItoR
[0] = 0.0;
1079 ctx
->Pixel
.MapItoG
[0] = 0.0;
1080 ctx
->Pixel
.MapItoB
[0] = 0.0;
1081 ctx
->Pixel
.MapItoA
[0] = 0.0;
1082 ctx
->Pixel
.MapItoR8
[0] = 0;
1083 ctx
->Pixel
.MapItoG8
[0] = 0;
1084 ctx
->Pixel
.MapItoB8
[0] = 0;
1085 ctx
->Pixel
.MapItoA8
[0] = 0;
1086 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1087 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1088 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1089 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1090 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
1091 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
1092 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
1093 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1094 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1095 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixScale
, 1.0, 1.0, 1.0, 1.0);
1096 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixBias
, 0.0, 0.0, 0.0, 0.0);
1097 ASSIGN_4V(ctx
->Pixel
.ColorTableScale
, 1.0, 1.0, 1.0, 1.0);
1098 ASSIGN_4V(ctx
->Pixel
.ColorTableBias
, 0.0, 0.0, 0.0, 0.0);
1099 ASSIGN_4V(ctx
->Pixel
.PCCTscale
, 1.0, 1.0, 1.0, 1.0);
1100 ASSIGN_4V(ctx
->Pixel
.PCCTbias
, 0.0, 0.0, 0.0, 0.0);
1101 ASSIGN_4V(ctx
->Pixel
.PCMCTscale
, 1.0, 1.0, 1.0, 1.0);
1102 ASSIGN_4V(ctx
->Pixel
.PCMCTbias
, 0.0, 0.0, 0.0, 0.0);
1103 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1104 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1105 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1106 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
1107 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
1108 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
1109 for (i
= 0; i
< 3; i
++) {
1110 ASSIGN_4V(ctx
->Pixel
.ConvolutionBorderColor
[i
], 0.0, 0.0, 0.0, 0.0);
1111 ctx
->Pixel
.ConvolutionBorderMode
[i
] = GL_REDUCE
;
1112 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterScale
[i
], 1.0, 1.0, 1.0, 1.0);
1113 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterBias
[i
], 0.0, 0.0, 0.0, 0.0);
1115 for (i
= 0; i
< MAX_CONVOLUTION_WIDTH
* MAX_CONVOLUTION_WIDTH
* 4; i
++) {
1116 ctx
->Convolution1D
.Filter
[i
] = 0.0;
1117 ctx
->Convolution2D
.Filter
[i
] = 0.0;
1118 ctx
->Separable2D
.Filter
[i
] = 0.0;
1120 ASSIGN_4V(ctx
->Pixel
.PostConvolutionScale
, 1.0, 1.0, 1.0, 1.0);
1121 ASSIGN_4V(ctx
->Pixel
.PostConvolutionBias
, 0.0, 0.0, 0.0, 0.0);
1124 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1125 ctx
->Point
.Size
= 1.0;
1126 ctx
->Point
._Size
= 1.0;
1127 ctx
->Point
.Params
[0] = 1.0;
1128 ctx
->Point
.Params
[1] = 0.0;
1129 ctx
->Point
.Params
[2] = 0.0;
1130 ctx
->Point
._Attenuated
= GL_FALSE
;
1131 ctx
->Point
.MinSize
= 0.0;
1132 ctx
->Point
.MaxSize
= ctx
->Const
.MaxPointSize
;
1133 ctx
->Point
.Threshold
= 1.0;
1134 ctx
->Point
.SpriteMode
= GL_FALSE
; /* GL_MESA_sprite_point */
1137 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1138 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1139 ctx
->Polygon
.FrontFace
= GL_CCW
;
1140 ctx
->Polygon
._FrontBit
= 0;
1141 ctx
->Polygon
.FrontMode
= GL_FILL
;
1142 ctx
->Polygon
.BackMode
= GL_FILL
;
1143 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1144 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1145 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1146 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1147 ctx
->Polygon
.OffsetMRD
= 0.0F
;
1148 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1149 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1150 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1152 /* Polygon Stipple group */
1153 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1156 ctx
->Scissor
.Enabled
= GL_FALSE
;
1159 ctx
->Scissor
.Width
= 0;
1160 ctx
->Scissor
.Height
= 0;
1163 ctx
->Stencil
.Enabled
= GL_FALSE
;
1164 ctx
->Stencil
.Function
= GL_ALWAYS
;
1165 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1166 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1167 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1168 ctx
->Stencil
.Ref
= 0;
1169 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1170 ctx
->Stencil
.Clear
= 0;
1171 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1174 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1175 ctx
->Texture
._ReallyEnabled
= 0;
1176 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1177 init_texture_unit( ctx
, i
);
1178 ctx
->Texture
.SharedPalette
= GL_FALSE
;
1179 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1181 /* Transformation group */
1182 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1183 ctx
->Transform
.Normalize
= GL_FALSE
;
1184 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1185 ctx
->Transform
.RasterPositionUnclipped
= GL_FALSE
;
1186 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1187 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1188 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1190 ctx
->Transform
._AnyClip
= GL_FALSE
;
1192 /* Viewport group */
1193 ctx
->Viewport
.X
= 0;
1194 ctx
->Viewport
.Y
= 0;
1195 ctx
->Viewport
.Width
= 0;
1196 ctx
->Viewport
.Height
= 0;
1197 ctx
->Viewport
.Near
= 0.0;
1198 ctx
->Viewport
.Far
= 1.0;
1199 _math_matrix_ctr(&ctx
->Viewport
._WindowMap
);
1203 ctx
->Viewport
._WindowMap
.m
[Sz
] = 0.5F
* ctx
->DepthMaxF
;
1204 ctx
->Viewport
._WindowMap
.m
[Tz
] = 0.5F
* ctx
->DepthMaxF
;
1208 ctx
->Viewport
._WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1209 ctx
->Viewport
._WindowMap
.type
= MATRIX_3D_NO_ROT
;
1212 ctx
->Array
.Vertex
.Size
= 4;
1213 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1214 ctx
->Array
.Vertex
.Stride
= 0;
1215 ctx
->Array
.Vertex
.StrideB
= 0;
1216 ctx
->Array
.Vertex
.Ptr
= NULL
;
1217 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1218 ctx
->Array
.Vertex
.Flags
= CA_CLIENT_DATA
;
1219 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1220 ctx
->Array
.Normal
.Stride
= 0;
1221 ctx
->Array
.Normal
.StrideB
= 0;
1222 ctx
->Array
.Normal
.Ptr
= NULL
;
1223 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1224 ctx
->Array
.Normal
.Flags
= CA_CLIENT_DATA
;
1225 ctx
->Array
.Color
.Size
= 4;
1226 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1227 ctx
->Array
.Color
.Stride
= 0;
1228 ctx
->Array
.Color
.StrideB
= 0;
1229 ctx
->Array
.Color
.Ptr
= NULL
;
1230 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1231 ctx
->Array
.Color
.Flags
= CA_CLIENT_DATA
;
1232 ctx
->Array
.SecondaryColor
.Size
= 4;
1233 ctx
->Array
.SecondaryColor
.Type
= GL_FLOAT
;
1234 ctx
->Array
.SecondaryColor
.Stride
= 0;
1235 ctx
->Array
.SecondaryColor
.StrideB
= 0;
1236 ctx
->Array
.SecondaryColor
.Ptr
= NULL
;
1237 ctx
->Array
.SecondaryColor
.Enabled
= GL_FALSE
;
1238 ctx
->Array
.SecondaryColor
.Flags
= CA_CLIENT_DATA
;
1239 ctx
->Array
.FogCoord
.Size
= 1;
1240 ctx
->Array
.FogCoord
.Type
= GL_FLOAT
;
1241 ctx
->Array
.FogCoord
.Stride
= 0;
1242 ctx
->Array
.FogCoord
.StrideB
= 0;
1243 ctx
->Array
.FogCoord
.Ptr
= NULL
;
1244 ctx
->Array
.FogCoord
.Enabled
= GL_FALSE
;
1245 ctx
->Array
.FogCoord
.Flags
= CA_CLIENT_DATA
;
1246 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1247 ctx
->Array
.Index
.Stride
= 0;
1248 ctx
->Array
.Index
.StrideB
= 0;
1249 ctx
->Array
.Index
.Ptr
= NULL
;
1250 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1251 ctx
->Array
.Index
.Flags
= CA_CLIENT_DATA
;
1252 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1253 ctx
->Array
.TexCoord
[i
].Size
= 4;
1254 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1255 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1256 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1257 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1258 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1259 ctx
->Array
.TexCoord
[i
].Flags
= CA_CLIENT_DATA
;
1261 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1262 ctx
->Array
.EdgeFlag
.Stride
= 0;
1263 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1264 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1265 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1266 ctx
->Array
.EdgeFlag
.Flags
= CA_CLIENT_DATA
;
1267 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1269 /* Pixel transfer */
1270 ctx
->Pack
.Alignment
= 4;
1271 ctx
->Pack
.RowLength
= 0;
1272 ctx
->Pack
.ImageHeight
= 0;
1273 ctx
->Pack
.SkipPixels
= 0;
1274 ctx
->Pack
.SkipRows
= 0;
1275 ctx
->Pack
.SkipImages
= 0;
1276 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1277 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1278 ctx
->Unpack
.Alignment
= 4;
1279 ctx
->Unpack
.RowLength
= 0;
1280 ctx
->Unpack
.ImageHeight
= 0;
1281 ctx
->Unpack
.SkipPixels
= 0;
1282 ctx
->Unpack
.SkipRows
= 0;
1283 ctx
->Unpack
.SkipImages
= 0;
1284 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1285 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1288 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1289 ctx
->Feedback
.Buffer
= NULL
;
1290 ctx
->Feedback
.BufferSize
= 0;
1291 ctx
->Feedback
.Count
= 0;
1293 /* Selection/picking */
1294 ctx
->Select
.Buffer
= NULL
;
1295 ctx
->Select
.BufferSize
= 0;
1296 ctx
->Select
.BufferCount
= 0;
1297 ctx
->Select
.Hits
= 0;
1298 ctx
->Select
.NameStackDepth
= 0;
1300 /* Renderer and client attribute stacks */
1301 ctx
->AttribStackDepth
= 0;
1302 ctx
->ClientAttribStackDepth
= 0;
1306 ctx
->ExecuteFlag
= GL_TRUE
;
1307 ctx
->CompileFlag
= GL_FALSE
;
1308 ctx
->CurrentListPtr
= NULL
;
1309 ctx
->CurrentBlock
= NULL
;
1310 ctx
->CurrentListNum
= 0;
1311 ctx
->CurrentPos
= 0;
1314 _mesa_init_colortable(&ctx
->ColorTable
);
1315 _mesa_init_colortable(&ctx
->ProxyColorTable
);
1316 _mesa_init_colortable(&ctx
->PostConvolutionColorTable
);
1317 _mesa_init_colortable(&ctx
->ProxyPostConvolutionColorTable
);
1318 _mesa_init_colortable(&ctx
->PostColorMatrixColorTable
);
1319 _mesa_init_colortable(&ctx
->ProxyPostColorMatrixColorTable
);
1321 /* GL_NV_vertex_program */
1322 ctx
->VertexProgram
.Binding
= 0;
1323 ctx
->VertexProgram
.HashTable
= _mesa_NewHashTable();
1324 ctx
->VertexProgram
.Enabled
= GL_FALSE
;
1325 ctx
->VertexProgram
.PointSizeEnabled
= GL_FALSE
;
1326 ctx
->VertexProgram
.TwoSideEnabled
= GL_FALSE
;
1327 for (i
= 0; i
< VP_NUM_PROG_REGS
/ 4; i
++) {
1328 ctx
->VertexProgram
.TrackMatrix
[i
] = GL_NONE
;
1329 ctx
->VertexProgram
.TrackMatrixTransform
[i
] = GL_IDENTITY_NV
;
1333 ctx
->NewState
= _NEW_ALL
;
1334 ctx
->RenderMode
= GL_RENDER
;
1335 ctx
->_ImageTransferState
= 0;
1337 ctx
->_NeedNormals
= 0;
1338 ctx
->_NeedEyeCoords
= 0;
1339 ctx
->_ModelViewInvScale
= 1.0;
1341 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1343 ctx
->CatchSignals
= GL_TRUE
;
1344 ctx
->OcclusionResult
= GL_FALSE
;
1345 ctx
->OcclusionResultSaved
= GL_FALSE
;
1347 /* For debug/development only */
1348 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1349 ctx
->FirstTimeCurrent
= GL_TRUE
;
1351 /* Dither disable */
1352 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1353 if (ctx
->NoDither
) {
1354 if (getenv("MESA_DEBUG")) {
1355 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1357 ctx
->Color
.DitherFlag
= GL_FALSE
;
1365 * Allocate the proxy textures. If we run out of memory part way through
1366 * the allocations clean up and return GL_FALSE.
1367 * Return: GL_TRUE=success, GL_FALSE=failure
1370 alloc_proxy_textures( GLcontext
*ctx
)
1372 GLboolean out_of_memory
;
1375 ctx
->Texture
.Proxy1D
= _mesa_alloc_texture_object(NULL
, 0, 1);
1376 if (!ctx
->Texture
.Proxy1D
) {
1380 ctx
->Texture
.Proxy2D
= _mesa_alloc_texture_object(NULL
, 0, 2);
1381 if (!ctx
->Texture
.Proxy2D
) {
1382 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1386 ctx
->Texture
.Proxy3D
= _mesa_alloc_texture_object(NULL
, 0, 3);
1387 if (!ctx
->Texture
.Proxy3D
) {
1388 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1389 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1393 ctx
->Texture
.ProxyCubeMap
= _mesa_alloc_texture_object(NULL
, 0, 6);
1394 if (!ctx
->Texture
.ProxyCubeMap
) {
1395 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1396 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1397 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1401 out_of_memory
= GL_FALSE
;
1402 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1403 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1404 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1405 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1406 ctx
->Texture
.ProxyCubeMap
->Image
[i
] = _mesa_alloc_texture_image();
1407 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1408 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1409 || !ctx
->Texture
.Proxy3D
->Image
[i
]
1410 || !ctx
->Texture
.ProxyCubeMap
->Image
[i
]) {
1411 out_of_memory
= GL_TRUE
;
1414 if (out_of_memory
) {
1415 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1416 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1417 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1419 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1420 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1422 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1423 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1425 if (ctx
->Texture
.ProxyCubeMap
->Image
[i
]) {
1426 _mesa_free_texture_image(ctx
->Texture
.ProxyCubeMap
->Image
[i
]);
1429 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1430 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1431 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1432 _mesa_free_texture_object(NULL
, ctx
->Texture
.ProxyCubeMap
);
1442 * Initialize a GLcontext struct. This includes allocating all the
1443 * other structs and arrays which hang off of the context by pointers.
1446 _mesa_initialize_context( GLcontext
*ctx
,
1447 const GLvisual
*visual
,
1448 GLcontext
*share_list
,
1452 GLuint dispatchSize
;
1454 (void) direct
; /* not used */
1456 /* misc one-time initializations */
1462 if (!ctx
->imports
.malloc
) {
1463 _mesa_InitDefaultImports(&ctx
->imports
, driver_ctx
, NULL
);
1465 /* exports are setup by the device driver */
1467 ctx
->DriverCtx
= driver_ctx
;
1468 ctx
->Visual
= *visual
;
1469 ctx
->DrawBuffer
= NULL
;
1470 ctx
->ReadBuffer
= NULL
;
1473 /* share state with another context */
1474 ctx
->Shared
= share_list
->Shared
;
1477 /* allocate new, unshared state */
1478 ctx
->Shared
= alloc_shared_state();
1483 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1484 ctx
->Shared
->RefCount
++;
1485 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1487 /* Effectively bind the default textures to all texture units */
1488 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
1489 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
1490 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
1491 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
1493 init_attrib_groups( ctx
);
1495 if (visual
->doubleBufferMode
) {
1496 ctx
->Color
.DrawBuffer
= GL_BACK
;
1497 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1498 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1499 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1500 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1503 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1504 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1505 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1506 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1507 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1510 if (!alloc_proxy_textures(ctx
)) {
1511 free_shared_state(ctx
, ctx
->Shared
);
1515 /* register the most recent extension functions with libGL */
1516 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1517 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1518 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1519 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1520 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1521 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1522 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1523 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1525 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1526 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1527 * Mesa we do this to accomodate different versions of libGL and various
1530 dispatchSize
= MAX2(_glapi_get_dispatch_table_size(),
1531 sizeof(struct _glapi_table
) / sizeof(void *));
1533 /* setup API dispatch tables */
1534 ctx
->Exec
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1535 ctx
->Save
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1536 if (!ctx
->Exec
|| !ctx
->Save
) {
1537 free_shared_state(ctx
, ctx
->Shared
);
1541 _mesa_init_exec_table(ctx
->Exec
, dispatchSize
);
1542 _mesa_init_dlist_table(ctx
->Save
, dispatchSize
);
1543 ctx
->CurrentDispatch
= ctx
->Exec
;
1545 ctx
->ExecPrefersFloat
= GL_FALSE
;
1546 ctx
->SavePrefersFloat
= GL_FALSE
;
1548 /* Neutral tnl module stuff */
1549 _mesa_init_exec_vtxfmt( ctx
);
1550 ctx
->TnlModule
.Current
= NULL
;
1551 ctx
->TnlModule
.SwapCount
= 0;
1553 /* Z buffer stuff */
1554 if (ctx
->Visual
.depthBits
== 0) {
1555 /* Special case. Even if we don't have a depth buffer we need
1556 * good values for DepthMax for Z vertex transformation purposes
1557 * and for per-fragment fog computation.
1559 ctx
->DepthMax
= 1 << 16;
1560 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1562 else if (ctx
->Visual
.depthBits
< 32) {
1563 ctx
->DepthMax
= (1 << ctx
->Visual
.depthBits
) - 1;
1564 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1567 /* Special case since shift values greater than or equal to the
1568 * number of bits in the left hand expression's type are undefined.
1570 ctx
->DepthMax
= 0xffffffff;
1571 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1573 ctx
->MRD
= 1.0; /* Minimum resolvable depth value, for polygon offset */
1576 #if defined(MESA_TRACE)
1577 ctx
->TraceCtx
= (trace_context_t
*) CALLOC( sizeof(trace_context_t
) );
1579 /* Brian: do you want to have CreateContext fail here,
1580 or should we just trap in NewTrace (currently done)? */
1581 if (!(ctx
->TraceCtx
)) {
1582 free_shared_state(ctx
, ctx
->Shared
);
1588 trInitContext(ctx
->TraceCtx
);
1590 ctx
->TraceDispatch
= (struct _glapi_table
*)
1591 CALLOC(dispatchSize
* sizeof(void*));
1593 if (!(ctx
->TraceCtx
)) {
1594 free_shared_state(ctx
, ctx
->Shared
);
1597 FREE( ctx
->TraceCtx
);
1601 trInitDispatch(ctx
->TraceDispatch
);
1610 * Allocate and initialize a GLcontext structure.
1611 * Input: visual - a GLvisual pointer (we copy the struct contents)
1612 * sharelist - another context to share display lists with or NULL
1613 * driver_ctx - pointer to device driver's context state struct
1614 * Return: pointer to a new __GLcontextRec or NULL if error.
1617 _mesa_create_context( const GLvisual
*visual
,
1618 GLcontext
*share_list
,
1622 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1626 ctx
->Driver
.CurrentExecPrimitive
= 0;
1627 if (_mesa_initialize_context(ctx
, visual
, share_list
, driver_ctx
, direct
)) {
1639 * Free the data associated with the given context.
1640 * But don't free() the GLcontext struct itself!
1643 _mesa_free_context_data( GLcontext
*ctx
)
1645 struct gl_shine_tab
*s
, *tmps
;
1648 /* if we're destroying the current context, unbind it first */
1649 if (ctx
== _mesa_get_current_context()) {
1650 _mesa_make_current(NULL
, NULL
);
1654 free_matrix_stack(&ctx
->ModelviewStack
);
1657 _math_matrix_dtr( &ctx
->ModelView
);
1658 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
1659 _math_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1661 _math_matrix_dtr( &ctx
->ProjectionMatrix
);
1662 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
1663 _math_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1665 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1666 _math_matrix_dtr( &ctx
->TextureMatrix
[i
] );
1667 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
1668 _math_matrix_dtr( &ctx
->TextureStack
[i
][j
] );
1672 _math_matrix_dtr( &ctx
->_ModelProjectMatrix
);
1674 _math_matrix_dtr(&ctx
->ColorMatrix
);
1675 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
1676 _math_matrix_dtr(&ctx
->ColorStack
[j
]);
1679 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1680 ctx
->Shared
->RefCount
--;
1681 assert(ctx
->Shared
->RefCount
>= 0);
1682 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1683 if (ctx
->Shared
->RefCount
== 0) {
1684 /* free shared state */
1685 free_shared_state( ctx
, ctx
->Shared
);
1688 foreach_s( s
, tmps
, ctx
->_ShineTabList
) {
1691 FREE( ctx
->_ShineTabList
);
1693 /* Free proxy texture objects */
1694 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1695 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1696 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1697 _mesa_free_texture_object( NULL
, ctx
->Texture
.ProxyCubeMap
);
1699 /* Free evaluator data */
1700 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1701 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1702 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1703 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1704 if (ctx
->EvalMap
.Map1Index
.Points
)
1705 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1706 if (ctx
->EvalMap
.Map1Color4
.Points
)
1707 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1708 if (ctx
->EvalMap
.Map1Normal
.Points
)
1709 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1710 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1711 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1712 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1713 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1714 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1715 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1716 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1717 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1719 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1720 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1721 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1722 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1723 if (ctx
->EvalMap
.Map2Index
.Points
)
1724 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1725 if (ctx
->EvalMap
.Map2Color4
.Points
)
1726 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1727 if (ctx
->EvalMap
.Map2Normal
.Points
)
1728 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1729 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1730 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1731 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1732 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1733 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1734 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1735 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1736 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1738 _mesa_free_colortable_data( &ctx
->ColorTable
);
1739 _mesa_free_colortable_data( &ctx
->PostConvolutionColorTable
);
1740 _mesa_free_colortable_data( &ctx
->PostColorMatrixColorTable
);
1741 _mesa_free_colortable_data( &ctx
->Texture
.Palette
);
1743 _math_matrix_dtr(&ctx
->Viewport
._WindowMap
);
1745 _mesa_extensions_dtr(ctx
);
1747 /* GL_NV_vertex_program */
1748 _mesa_DeleteHashTable(ctx
->VertexProgram
.HashTable
);
1757 * Destroy a GLcontext structure.
1760 _mesa_destroy_context( GLcontext
*ctx
)
1763 _mesa_free_context_data(ctx
);
1764 FREE( (void *) ctx
);
1771 * Copy attribute groups from one context to another.
1772 * Input: src - source context
1773 * dst - destination context
1774 * mask - bitwise OR of GL_*_BIT flags
1777 _mesa_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1779 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1780 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1782 if (mask
& GL_COLOR_BUFFER_BIT
) {
1783 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1785 if (mask
& GL_CURRENT_BIT
) {
1786 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1788 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1789 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1791 if (mask
& GL_ENABLE_BIT
) {
1794 if (mask
& GL_EVAL_BIT
) {
1795 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1797 if (mask
& GL_FOG_BIT
) {
1798 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1800 if (mask
& GL_HINT_BIT
) {
1801 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1803 if (mask
& GL_LIGHTING_BIT
) {
1804 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1805 /* gl_reinit_light_attrib( &dst->Light ); */
1807 if (mask
& GL_LINE_BIT
) {
1808 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1810 if (mask
& GL_LIST_BIT
) {
1811 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1813 if (mask
& GL_PIXEL_MODE_BIT
) {
1814 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1816 if (mask
& GL_POINT_BIT
) {
1817 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1819 if (mask
& GL_POLYGON_BIT
) {
1820 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1822 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1823 /* Use loop instead of MEMCPY due to problem with Portland Group's
1824 * C compiler. Reported by John Stone.
1827 for (i
=0;i
<32;i
++) {
1828 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1831 if (mask
& GL_SCISSOR_BIT
) {
1832 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1834 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1835 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1837 if (mask
& GL_TEXTURE_BIT
) {
1838 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1840 if (mask
& GL_TRANSFORM_BIT
) {
1841 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1843 if (mask
& GL_VIEWPORT_BIT
) {
1844 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1846 /* XXX FIXME: Call callbacks?
1848 dst
->NewState
= _NEW_ALL
;
1853 * Set the current context, binding the given frame buffer to the context.
1856 _mesa_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1858 _mesa_make_current2( newCtx
, buffer
, buffer
);
1862 static void print_info( void )
1864 fprintf(stderr
, "Mesa GL_VERSION = %s\n",
1865 (char *) _mesa_GetString(GL_VERSION
));
1866 fprintf(stderr
, "Mesa GL_RENDERER = %s\n",
1867 (char *) _mesa_GetString(GL_RENDERER
));
1868 fprintf(stderr
, "Mesa GL_VENDOR = %s\n",
1869 (char *) _mesa_GetString(GL_VENDOR
));
1870 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n",
1871 (char *) _mesa_GetString(GL_EXTENSIONS
));
1872 #if defined(THREADS)
1873 fprintf(stderr
, "Mesa thread-safe: YES\n");
1875 fprintf(stderr
, "Mesa thread-safe: NO\n");
1877 #if defined(USE_X86_ASM)
1878 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1880 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1882 #if defined(USE_SPARC_ASM)
1883 fprintf(stderr
, "Mesa sparc-optimized: YES\n");
1885 fprintf(stderr
, "Mesa sparc-optimized: NO\n");
1891 * Bind the given context to the given draw-buffer and read-buffer
1892 * and make it the current context for this thread.
1895 _mesa_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1896 GLframebuffer
*readBuffer
)
1899 fprintf(stderr
, "_mesa_make_current2()\n");
1901 /* Check that the context's and framebuffer's visuals are compatible.
1902 * We could do a lot more checking here but this'll catch obvious
1905 if (newCtx
&& drawBuffer
&& readBuffer
) {
1906 if (newCtx
->Visual
.rgbMode
!= drawBuffer
->Visual
.rgbMode
||
1907 newCtx
->Visual
.redBits
!= drawBuffer
->Visual
.redBits
||
1908 newCtx
->Visual
.depthBits
!= drawBuffer
->Visual
.depthBits
||
1909 newCtx
->Visual
.stencilBits
!= drawBuffer
->Visual
.stencilBits
||
1910 newCtx
->Visual
.accumRedBits
!= drawBuffer
->Visual
.accumRedBits
) {
1911 return; /* incompatible */
1915 /* We call this function periodically (just here for now) in
1916 * order to detect when multithreading has begun.
1918 _glapi_check_multithread();
1920 _glapi_set_context((void *) newCtx
);
1921 ASSERT(_mesa_get_current_context() == newCtx
);
1925 _glapi_set_dispatch(NULL
); /* none current */
1928 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1930 if (drawBuffer
&& readBuffer
) {
1931 /* TODO: check if newCtx and buffer's visual match??? */
1932 newCtx
->DrawBuffer
= drawBuffer
;
1933 newCtx
->ReadBuffer
= readBuffer
;
1934 newCtx
->NewState
|= _NEW_BUFFERS
;
1935 /* _mesa_update_state( newCtx ); */
1938 if (newCtx
->Driver
.MakeCurrent
)
1939 newCtx
->Driver
.MakeCurrent( newCtx
, drawBuffer
, readBuffer
);
1941 /* We can use this to help debug user's problems. Tell them to set
1942 * the MESA_INFO env variable before running their app. Then the
1943 * first time each context is made current we'll print some useful
1946 if (newCtx
->FirstTimeCurrent
) {
1947 if (getenv("MESA_INFO")) {
1950 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1958 * Return current context handle for the calling thread.
1959 * This isn't the fastest way to get the current context.
1960 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1963 _mesa_get_current_context( void )
1965 return (GLcontext
*) _glapi_get_context();
1971 * This should be called by device drivers just before they do a
1972 * swapbuffers. Any pending rendering commands will be executed.
1975 _mesa_swapbuffers(GLcontext
*ctx
)
1977 FLUSH_VERTICES( ctx
, 0 );
1983 * Return pointer to this context's current API dispatch table.
1984 * It'll either be the immediate-mode execute dispatcher or the
1985 * display list compile dispatcher.
1987 struct _glapi_table
*
1988 _mesa_get_dispatch(GLcontext
*ctx
)
1990 return ctx
->CurrentDispatch
;
1995 /**********************************************************************/
1996 /***** Miscellaneous functions *****/
1997 /**********************************************************************/
2001 * This function is called when the Mesa user has stumbled into a code
2002 * path which may not be implemented fully or correctly.
2004 void _mesa_problem( const GLcontext
*ctx
, const char *s
)
2006 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
2008 fprintf( stderr
, "Please report to the DRI bug database at dri.sourceforge.net\n");
2010 fprintf( stderr
, "Please report to the Mesa bug database at www.mesa3d.org\n" );
2018 * This is called to inform the user that he or she has tried to do
2019 * something illogical or if there's likely a bug in their program
2020 * (like enabled depth testing without a depth buffer).
2023 _mesa_warning( const GLcontext
*ctx
, const char *s
)
2025 (*ctx
->imports
.warning
)((__GLcontext
*) ctx
, (char *) s
);
2031 * This is Mesa's error handler. Normally, all that's done is the updating
2032 * of the current error value. If Mesa is compiled with -DDEBUG or if the
2033 * environment variable "MESA_DEBUG" is defined then a real error message
2034 * is printed to stderr.
2035 * Input: ctx - the GL context
2036 * error - the error value
2037 * where - usually the name of function where error was detected
2040 _mesa_error( GLcontext
*ctx
, GLenum error
, const char *where
)
2042 const char *debugEnv
= getenv("MESA_DEBUG");
2046 if (debugEnv
&& strstr(debugEnv
, "silent"))
2061 errstr
= "GL_NO_ERROR";
2063 case GL_INVALID_VALUE
:
2064 errstr
= "GL_INVALID_VALUE";
2066 case GL_INVALID_ENUM
:
2067 errstr
= "GL_INVALID_ENUM";
2069 case GL_INVALID_OPERATION
:
2070 errstr
= "GL_INVALID_OPERATION";
2072 case GL_STACK_OVERFLOW
:
2073 errstr
= "GL_STACK_OVERFLOW";
2075 case GL_STACK_UNDERFLOW
:
2076 errstr
= "GL_STACK_UNDERFLOW";
2078 case GL_OUT_OF_MEMORY
:
2079 errstr
= "GL_OUT_OF_MEMORY";
2081 case GL_TABLE_TOO_LARGE
:
2082 errstr
= "GL_TABLE_TOO_LARGE";
2088 fprintf(stderr
, "Mesa user error: %s in %s\n", errstr
, where
);
2091 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
2092 ctx
->ErrorValue
= error
;
2095 /* Call device driver's error handler, if any. This is used on the Mac. */
2096 if (ctx
->Driver
.Error
) {
2097 (*ctx
->Driver
.Error
)( ctx
);
2104 _mesa_Finish( void )
2106 GET_CURRENT_CONTEXT(ctx
);
2107 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2108 if (ctx
->Driver
.Finish
) {
2109 (*ctx
->Driver
.Finish
)( ctx
);
2118 GET_CURRENT_CONTEXT(ctx
);
2119 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2120 if (ctx
->Driver
.Flush
) {
2121 (*ctx
->Driver
.Flush
)( ctx
);
2127 const char *_mesa_prim_name
[GL_POLYGON
+4] = {
2133 "GL_TRIANGLE_STRIP",
2138 "outside begin/end",
2139 "inside unkown primitive",