1 /* $Id: context.c,v 1.122 2001/02/26 23:58:12 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"
42 #include "glapinoop.h"
50 #include "simple_list.h"
57 #include "math/m_translate.h"
58 #include "math/m_vertices.h"
59 #include "math/m_matrix.h"
60 #include "math/m_xform.h"
61 #include "math/mathmod.h"
64 #if defined(MESA_TRACE)
65 #include "Trace/tr_context.h"
66 #include "Trace/tr_wrapper.h"
72 /* | VERBOSE_PIPELINE */
73 /* | VERBOSE_IMMEDIATE */
74 /* | VERBOSE_VARRAY */
75 /* | VERBOSE_TEXTURE */
77 /* | VERBOSE_DRIVER */
79 /* | VERBOSE_DISPLAY_LIST */
83 #ifndef MESA_DEBUG_FLAGS
84 int MESA_DEBUG_FLAGS
= 0
85 /* | DEBUG_ALWAYS_FLUSH */
89 /**********************************************************************/
90 /***** OpenGL SI-style interface (new in Mesa 3.5) *****/
91 /**********************************************************************/
94 _mesa_DestroyContext(__GLcontext
*gc
)
97 _mesa_free_context_data(gc
);
98 (*gc
->imports
.free
)(gc
, gc
);
104 /* exported OpenGL SI interface */
106 __glCoreCreateContext(__GLimports
*imports
, __GLcontextModes
*modes
)
110 ctx
= (GLcontext
*) (*imports
->calloc
)(0, 1, sizeof(GLcontext
));
114 ctx
->imports
= *imports
;
116 _mesa_initialize_visual(&ctx
->Visual
,
118 modes
->doubleBufferMode
,
128 modes
->accumGreenBits
,
129 modes
->accumBlueBits
,
130 modes
->accumAlphaBits
,
133 /* KW: was imports->wscx */
134 _mesa_initialize_context(ctx
, &ctx
->Visual
, NULL
, imports
->other
, GL_FALSE
);
136 ctx
->exports
.destroyContext
= _mesa_DestroyContext
;
142 /* exported OpenGL SI interface */
144 __glCoreNopDispatch(void)
148 __gl_dispatch
= __glNopDispatchState
;
151 _glapi_set_dispatch(NULL
);
156 /**********************************************************************/
157 /***** Context and Thread management *****/
158 /**********************************************************************/
162 /**********************************************************************/
163 /***** GL Visual allocation/destruction *****/
164 /**********************************************************************/
168 * Allocate a new GLvisual object.
169 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
170 * dbFlag - double buffering?
171 * stereoFlag - stereo buffer?
172 * depthBits - requested bits per depth buffer value
173 * Any value in [0, 32] is acceptable but the actual
174 * depth type will be GLushort or GLuint as needed.
175 * stencilBits - requested minimum bits per stencil buffer value
176 * accumBits - requested minimum bits per accum buffer component
177 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
178 * red/green/blue/alphaBits - number of bits per color component
179 * in frame buffer for RGB(A) mode.
180 * We always use 8 in core Mesa though.
181 * Return: pointer to new GLvisual or NULL if requested parameters can't
185 _mesa_create_visual( GLboolean rgbFlag
,
187 GLboolean stereoFlag
,
196 GLint accumGreenBits
,
198 GLint accumAlphaBits
,
201 GLvisual
*vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
203 if (!_mesa_initialize_visual(vis
, rgbFlag
, dbFlag
, stereoFlag
,
204 redBits
, greenBits
, blueBits
, alphaBits
,
205 indexBits
, depthBits
, stencilBits
,
206 accumRedBits
, accumGreenBits
,
207 accumBlueBits
, accumAlphaBits
,
218 * Initialize the fields of the given GLvisual.
219 * Input: see _mesa_create_visual() above.
220 * Return: GL_TRUE = success
221 * GL_FALSE = failure.
224 _mesa_initialize_visual( GLvisual
*vis
,
227 GLboolean stereoFlag
,
236 GLint accumGreenBits
,
238 GLint accumAlphaBits
,
245 /* This is to catch bad values from device drivers not updated for
246 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
247 * bad value now (a 1-bit depth buffer!?!).
249 assert(depthBits
== 0 || depthBits
> 1);
251 if (depthBits
< 0 || depthBits
> 32) {
254 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
257 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
260 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
263 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
266 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
270 vis
->rgbMode
= rgbFlag
;
271 vis
->doubleBufferMode
= dbFlag
;
272 vis
->stereoMode
= stereoFlag
;
273 vis
->redBits
= redBits
;
274 vis
->greenBits
= greenBits
;
275 vis
->blueBits
= blueBits
;
276 vis
->alphaBits
= alphaBits
;
278 vis
->indexBits
= indexBits
;
279 vis
->depthBits
= depthBits
;
280 vis
->accumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
281 vis
->accumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
282 vis
->accumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
283 vis
->accumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
284 vis
->stencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
291 _mesa_destroy_visual( GLvisual
*vis
)
297 /**********************************************************************/
298 /***** GL Framebuffer allocation/destruction *****/
299 /**********************************************************************/
303 * Create a new framebuffer. A GLframebuffer is a struct which
304 * encapsulates the depth, stencil and accum buffers and related
306 * Input: visual - a GLvisual pointer
307 * softwareDepth - create/use a software depth buffer?
308 * softwareStencil - create/use a software stencil buffer?
309 * softwareAccum - create/use a software accum buffer?
310 * softwareAlpha - create/use a software alpha buffer?
312 * Return: pointer to new GLframebuffer struct or NULL if error.
315 _mesa_create_framebuffer( GLvisual
*visual
,
316 GLboolean softwareDepth
,
317 GLboolean softwareStencil
,
318 GLboolean softwareAccum
,
319 GLboolean softwareAlpha
)
321 GLframebuffer
*buffer
= CALLOC_STRUCT(gl_frame_buffer
);
324 _mesa_initialize_framebuffer(buffer
, visual
,
325 softwareDepth
, softwareStencil
,
326 softwareAccum
, softwareAlpha
);
333 * Initialize a GLframebuffer object.
334 * Input: See _mesa_create_framebuffer() above.
337 _mesa_initialize_framebuffer( GLframebuffer
*buffer
,
339 GLboolean softwareDepth
,
340 GLboolean softwareStencil
,
341 GLboolean softwareAccum
,
342 GLboolean softwareAlpha
)
348 if (softwareDepth
) {
349 assert(visual
->depthBits
> 0);
351 if (softwareStencil
) {
352 assert(visual
->stencilBits
> 0);
355 assert(visual
->rgbMode
);
356 assert(visual
->accumRedBits
> 0);
357 assert(visual
->accumGreenBits
> 0);
358 assert(visual
->accumBlueBits
> 0);
361 assert(visual
->rgbMode
);
362 assert(visual
->alphaBits
> 0);
365 buffer
->Visual
= visual
; /* XXX copy instead? */
366 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
367 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
368 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
369 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
374 * Free a framebuffer struct and its buffers.
377 _mesa_destroy_framebuffer( GLframebuffer
*buffer
)
380 if (buffer
->DepthBuffer
) {
381 FREE( buffer
->DepthBuffer
);
384 FREE( buffer
->Accum
);
386 if (buffer
->Stencil
) {
387 FREE( buffer
->Stencil
);
389 if (buffer
->FrontLeftAlpha
) {
390 FREE( buffer
->FrontLeftAlpha
);
392 if (buffer
->BackLeftAlpha
) {
393 FREE( buffer
->BackLeftAlpha
);
395 if (buffer
->FrontRightAlpha
) {
396 FREE( buffer
->FrontRightAlpha
);
398 if (buffer
->BackRightAlpha
) {
399 FREE( buffer
->BackRightAlpha
);
407 /**********************************************************************/
408 /***** Context allocation, initialization, destroying *****/
409 /**********************************************************************/
412 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
416 * This function just calls all the various one-time-init functions in Mesa.
419 one_time_init( void )
421 static GLboolean alreadyCalled
= GL_FALSE
;
422 _glthread_LOCK_MUTEX(OneTimeLock
);
423 if (!alreadyCalled
) {
424 /* do some implementation tests */
425 assert( sizeof(GLbyte
) == 1 );
426 assert( sizeof(GLshort
) >= 2 );
427 assert( sizeof(GLint
) >= 4 );
428 assert( sizeof(GLubyte
) == 1 );
429 assert( sizeof(GLushort
) >= 2 );
430 assert( sizeof(GLuint
) >= 4 );
437 if (getenv("MESA_DEBUG")) {
438 _glapi_noop_enable_warnings(GL_TRUE
);
441 _glapi_noop_enable_warnings(GL_FALSE
);
444 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
445 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
448 alreadyCalled
= GL_TRUE
;
450 _glthread_UNLOCK_MUTEX(OneTimeLock
);
456 * Allocate and initialize a shared context state structure.
458 static struct gl_shared_state
*
459 alloc_shared_state( void )
461 struct gl_shared_state
*ss
;
462 GLboolean outOfMemory
;
464 ss
= CALLOC_STRUCT(gl_shared_state
);
468 _glthread_INIT_MUTEX(ss
->Mutex
);
470 ss
->DisplayList
= _mesa_NewHashTable();
471 ss
->TexObjects
= _mesa_NewHashTable();
473 /* Default Texture objects */
474 outOfMemory
= GL_FALSE
;
476 ss
->Default1D
= _mesa_alloc_texture_object(ss
, 0, 1);
477 if (!ss
->Default1D
) {
478 outOfMemory
= GL_TRUE
;
481 ss
->Default1D
->RefCount
++;
484 ss
->Default2D
= _mesa_alloc_texture_object(ss
, 0, 2);
485 if (!ss
->Default2D
) {
486 outOfMemory
= GL_TRUE
;
489 ss
->Default2D
->RefCount
++;
492 ss
->Default3D
= _mesa_alloc_texture_object(ss
, 0, 3);
493 if (!ss
->Default3D
) {
494 outOfMemory
= GL_TRUE
;
497 ss
->Default1D
->RefCount
++;
500 ss
->DefaultCubeMap
= _mesa_alloc_texture_object(ss
, 0, 6);
501 if (!ss
->DefaultCubeMap
) {
502 outOfMemory
= GL_TRUE
;
505 ss
->DefaultCubeMap
->RefCount
++;
508 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
509 /* Ran out of memory at some point. Free everything and return NULL */
511 _mesa_DeleteHashTable(ss
->DisplayList
);
513 _mesa_DeleteHashTable(ss
->TexObjects
);
515 _mesa_free_texture_object(ss
, ss
->Default1D
);
517 _mesa_free_texture_object(ss
, ss
->Default2D
);
519 _mesa_free_texture_object(ss
, ss
->Default3D
);
520 if (ss
->DefaultCubeMap
)
521 _mesa_free_texture_object(ss
, ss
->DefaultCubeMap
);
532 * Deallocate a shared state context and all children structures.
535 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
537 /* Free display lists */
539 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
541 gl_destroy_list(ctx
, list
);
547 _mesa_DeleteHashTable(ss
->DisplayList
);
549 /* Free texture objects */
550 while (ss
->TexObjectList
)
552 if (ctx
->Driver
.DeleteTexture
)
553 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
554 /* this function removes from linked list too! */
555 _mesa_free_texture_object(ss
, ss
->TexObjectList
);
557 _mesa_DeleteHashTable(ss
->TexObjects
);
565 * Initialize the nth light. Note that the defaults for light 0 are
566 * different than the other lights.
569 init_light( struct gl_light
*l
, GLuint n
)
571 make_empty_list( l
);
573 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
575 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
576 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
579 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
580 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
582 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
583 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
584 l
->SpotExponent
= 0.0;
585 gl_invalidate_spot_exp_table( l
);
586 l
->SpotCutoff
= 180.0;
587 l
->_CosCutoff
= 0.0; /* KW: -ve values not admitted */
588 l
->ConstantAttenuation
= 1.0;
589 l
->LinearAttenuation
= 0.0;
590 l
->QuadraticAttenuation
= 0.0;
591 l
->Enabled
= GL_FALSE
;
597 init_lightmodel( struct gl_lightmodel
*lm
)
599 ASSIGN_4V( lm
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
600 lm
->LocalViewer
= GL_FALSE
;
601 lm
->TwoSide
= GL_FALSE
;
602 lm
->ColorControl
= GL_SINGLE_COLOR
;
607 init_material( struct gl_material
*m
)
609 ASSIGN_4V( m
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
610 ASSIGN_4V( m
->Diffuse
, 0.8, 0.8, 0.8, 1.0 );
611 ASSIGN_4V( m
->Specular
, 0.0, 0.0, 0.0, 1.0 );
612 ASSIGN_4V( m
->Emission
, 0.0, 0.0, 0.0, 1.0 );
616 m
->SpecularIndex
= 1;
622 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
624 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
626 texUnit
->EnvMode
= GL_MODULATE
;
627 texUnit
->CombineModeRGB
= GL_MODULATE
;
628 texUnit
->CombineModeA
= GL_MODULATE
;
629 texUnit
->CombineSourceRGB
[0] = GL_TEXTURE
;
630 texUnit
->CombineSourceRGB
[1] = GL_PREVIOUS_EXT
;
631 texUnit
->CombineSourceRGB
[2] = GL_CONSTANT_EXT
;
632 texUnit
->CombineSourceA
[0] = GL_TEXTURE
;
633 texUnit
->CombineSourceA
[1] = GL_PREVIOUS_EXT
;
634 texUnit
->CombineSourceA
[2] = GL_CONSTANT_EXT
;
635 texUnit
->CombineOperandRGB
[0] = GL_SRC_COLOR
;
636 texUnit
->CombineOperandRGB
[1] = GL_SRC_COLOR
;
637 texUnit
->CombineOperandRGB
[2] = GL_SRC_ALPHA
;
638 texUnit
->CombineOperandA
[0] = GL_SRC_ALPHA
;
639 texUnit
->CombineOperandA
[1] = GL_SRC_ALPHA
;
640 texUnit
->CombineOperandA
[2] = GL_SRC_ALPHA
;
641 texUnit
->CombineScaleShiftRGB
= 0;
642 texUnit
->CombineScaleShiftA
= 0;
644 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
645 texUnit
->TexGenEnabled
= 0;
646 texUnit
->GenModeS
= GL_EYE_LINEAR
;
647 texUnit
->GenModeT
= GL_EYE_LINEAR
;
648 texUnit
->GenModeR
= GL_EYE_LINEAR
;
649 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
650 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
651 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
652 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
653 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
655 /* Yes, these plane coefficients are correct! */
656 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
657 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
658 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
659 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
660 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
661 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
662 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
665 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
666 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
667 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
668 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
674 /* Initialize a 1-D evaluator map */
676 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
681 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
685 map
->Points
[i
] = initial
[i
];
690 /* Initialize a 2-D evaluator map */
692 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
700 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
704 map
->Points
[i
] = initial
[i
];
710 * Initialize the attribute groups in a GLcontext.
713 init_attrib_groups( GLcontext
*ctx
)
719 /* Constants, may be overriden by device drivers */
720 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
721 ctx
->Const
.MaxTextureSize
= 1 << (MAX_TEXTURE_LEVELS
- 1);
722 ctx
->Const
.MaxCubeTextureSize
= ctx
->Const
.MaxTextureSize
;
723 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
724 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
725 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
726 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
727 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
728 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
729 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
730 ctx
->Const
.PointSizeGranularity
= POINT_SIZE_GRANULARITY
;
731 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
732 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
733 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
734 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
735 ctx
->Const
.LineWidthGranularity
= LINE_WIDTH_GRANULARITY
;
736 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
737 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
738 ctx
->Const
.MaxConvolutionWidth
= MAX_CONVOLUTION_WIDTH
;
739 ctx
->Const
.MaxConvolutionHeight
= MAX_CONVOLUTION_HEIGHT
;
740 ctx
->Const
.NumCompressedTextureFormats
= 0;
741 ctx
->Const
.MaxClipPlanes
= MAX_CLIP_PLANES
;
742 ctx
->Const
.MaxLights
= MAX_LIGHTS
;
744 /* Modelview matrix */
745 _math_matrix_ctr( &ctx
->ModelView
);
746 _math_matrix_alloc_inv( &ctx
->ModelView
);
748 ctx
->ModelViewStackDepth
= 0;
749 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
750 _math_matrix_ctr( &ctx
->ModelViewStack
[i
] );
751 _math_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
754 /* Projection matrix - need inv for user clipping in clip space*/
755 _math_matrix_ctr( &ctx
->ProjectionMatrix
);
756 _math_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
758 ctx
->ProjectionStackDepth
= 0;
759 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
760 _math_matrix_ctr( &ctx
->ProjectionStack
[i
] );
761 _math_matrix_alloc_inv( &ctx
->ProjectionStack
[i
] );
764 /* Derived ModelProject matrix */
765 _math_matrix_ctr( &ctx
->_ModelProjectMatrix
);
768 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
769 _math_matrix_ctr( &ctx
->TextureMatrix
[i
] );
770 ctx
->TextureStackDepth
[i
] = 0;
771 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
772 _math_matrix_ctr( &ctx
->TextureStack
[i
][j
] );
773 ctx
->TextureStack
[i
][j
].inv
= 0;
778 _math_matrix_ctr(&ctx
->ColorMatrix
);
779 ctx
->ColorStackDepth
= 0;
780 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
781 _math_matrix_ctr(&ctx
->ColorStack
[j
]);
784 /* Accumulate buffer group */
785 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
787 /* Color buffer group */
788 ctx
->Color
.IndexMask
= 0xffffffff;
789 ctx
->Color
.ColorMask
[0] = 0xff;
790 ctx
->Color
.ColorMask
[1] = 0xff;
791 ctx
->Color
.ColorMask
[2] = 0xff;
792 ctx
->Color
.ColorMask
[3] = 0xff;
793 ctx
->Color
.ClearIndex
= 0;
794 ASSIGN_4V( ctx
->Color
.ClearColor
, 0, 0, 0, 0 );
795 ctx
->Color
.DrawBuffer
= GL_FRONT
;
796 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
797 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
798 ctx
->Color
.AlphaRef
= 0;
799 ctx
->Color
.BlendEnabled
= GL_FALSE
;
800 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
801 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
802 ctx
->Color
.BlendSrcA
= GL_ONE
;
803 ctx
->Color
.BlendDstA
= GL_ZERO
;
804 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
805 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
806 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
807 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
808 ctx
->Color
.LogicOp
= GL_COPY
;
809 ctx
->Color
.DitherFlag
= GL_TRUE
;
810 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
813 ASSIGN_4V( ctx
->Current
.Color
, CHAN_MAX
, CHAN_MAX
, CHAN_MAX
, CHAN_MAX
);
814 ctx
->Current
.Index
= 1;
815 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
816 ASSIGN_4V( ctx
->Current
.Texcoord
[i
], 0.0, 0.0, 0.0, 1.0 );
817 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
818 ctx
->Current
.RasterDistance
= 0.0;
819 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
820 ctx
->Current
.RasterIndex
= 1;
821 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
822 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
823 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
824 ctx
->Current
.RasterPosValid
= GL_TRUE
;
825 ctx
->Current
.EdgeFlag
= GL_TRUE
;
826 ASSIGN_3V( ctx
->Current
.Normal
, 0.0, 0.0, 1.0 );
829 /* Depth buffer group */
830 ctx
->Depth
.Test
= GL_FALSE
;
831 ctx
->Depth
.Clear
= 1.0;
832 ctx
->Depth
.Func
= GL_LESS
;
833 ctx
->Depth
.Mask
= GL_TRUE
;
834 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
836 /* Evaluators group */
837 ctx
->Eval
.Map1Color4
= GL_FALSE
;
838 ctx
->Eval
.Map1Index
= GL_FALSE
;
839 ctx
->Eval
.Map1Normal
= GL_FALSE
;
840 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
841 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
842 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
843 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
844 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
845 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
846 ctx
->Eval
.Map2Color4
= GL_FALSE
;
847 ctx
->Eval
.Map2Index
= GL_FALSE
;
848 ctx
->Eval
.Map2Normal
= GL_FALSE
;
849 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
850 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
851 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
852 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
853 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
854 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
855 ctx
->Eval
.AutoNormal
= GL_FALSE
;
856 ctx
->Eval
.MapGrid1un
= 1;
857 ctx
->Eval
.MapGrid1u1
= 0.0;
858 ctx
->Eval
.MapGrid1u2
= 1.0;
859 ctx
->Eval
.MapGrid2un
= 1;
860 ctx
->Eval
.MapGrid2vn
= 1;
861 ctx
->Eval
.MapGrid2u1
= 0.0;
862 ctx
->Eval
.MapGrid2u2
= 1.0;
863 ctx
->Eval
.MapGrid2v1
= 0.0;
864 ctx
->Eval
.MapGrid2v2
= 1.0;
868 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
869 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
870 static GLfloat index
[1] = { 1.0 };
871 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
872 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
874 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
875 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
876 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
877 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
878 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
879 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
880 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
881 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
882 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
884 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
885 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
886 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
887 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
888 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
889 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
890 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
891 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
892 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
896 ctx
->Fog
.Enabled
= GL_FALSE
;
897 ctx
->Fog
.Mode
= GL_EXP
;
898 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
899 ctx
->Fog
.Index
= 0.0;
900 ctx
->Fog
.Density
= 1.0;
901 ctx
->Fog
.Start
= 0.0;
903 ctx
->Fog
.ColorSumEnabled
= GL_FALSE
;
904 ctx
->Fog
.FogCoordinateSource
= GL_FRAGMENT_DEPTH_EXT
;
907 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
908 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
909 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
910 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
911 ctx
->Hint
.Fog
= GL_DONT_CARE
;
912 ctx
->Hint
.ClipVolumeClipping
= GL_DONT_CARE
;
913 ctx
->Hint
.TextureCompression
= GL_DONT_CARE
;
915 /* Histogram group */
916 ctx
->Histogram
.Width
= 0;
917 ctx
->Histogram
.Format
= GL_RGBA
;
918 ctx
->Histogram
.Sink
= GL_FALSE
;
919 ctx
->Histogram
.RedSize
= 0;
920 ctx
->Histogram
.GreenSize
= 0;
921 ctx
->Histogram
.BlueSize
= 0;
922 ctx
->Histogram
.AlphaSize
= 0;
923 ctx
->Histogram
.LuminanceSize
= 0;
924 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
925 ctx
->Histogram
.Count
[i
][0] = 0;
926 ctx
->Histogram
.Count
[i
][1] = 0;
927 ctx
->Histogram
.Count
[i
][2] = 0;
928 ctx
->Histogram
.Count
[i
][3] = 0;
932 ctx
->MinMax
.Format
= GL_RGBA
;
933 ctx
->MinMax
.Sink
= GL_FALSE
;
934 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
935 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
936 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
937 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
940 _mesa_extensions_ctr( ctx
);
943 for (i
=0;i
<MAX_LIGHTS
;i
++) {
944 init_light( &ctx
->Light
.Light
[i
], i
);
946 make_empty_list( &ctx
->Light
.EnabledList
);
948 init_lightmodel( &ctx
->Light
.Model
);
949 init_material( &ctx
->Light
.Material
[0] );
950 init_material( &ctx
->Light
.Material
[1] );
951 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
952 ctx
->Light
.Enabled
= GL_FALSE
;
953 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
954 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
955 ctx
->Light
.ColorMaterialBitmask
956 = gl_material_bitmask( ctx
,
958 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
960 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
962 /* Lighting miscellaneous */
963 ctx
->_ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
964 make_empty_list( ctx
->_ShineTabList
);
965 for (i
= 0 ; i
< 10 ; i
++) {
966 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
969 insert_at_tail( ctx
->_ShineTabList
, s
);
974 ctx
->Line
.SmoothFlag
= GL_FALSE
;
975 ctx
->Line
.StippleFlag
= GL_FALSE
;
976 ctx
->Line
.Width
= 1.0;
977 ctx
->Line
.StipplePattern
= 0xffff;
978 ctx
->Line
.StippleFactor
= 1;
980 /* Display List group */
981 ctx
->List
.ListBase
= 0;
984 ctx
->Pixel
.RedBias
= 0.0;
985 ctx
->Pixel
.RedScale
= 1.0;
986 ctx
->Pixel
.GreenBias
= 0.0;
987 ctx
->Pixel
.GreenScale
= 1.0;
988 ctx
->Pixel
.BlueBias
= 0.0;
989 ctx
->Pixel
.BlueScale
= 1.0;
990 ctx
->Pixel
.AlphaBias
= 0.0;
991 ctx
->Pixel
.AlphaScale
= 1.0;
992 ctx
->Pixel
.DepthBias
= 0.0;
993 ctx
->Pixel
.DepthScale
= 1.0;
994 ctx
->Pixel
.IndexOffset
= 0;
995 ctx
->Pixel
.IndexShift
= 0;
996 ctx
->Pixel
.ZoomX
= 1.0;
997 ctx
->Pixel
.ZoomY
= 1.0;
998 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
999 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
1000 ctx
->Pixel
.MapStoSsize
= 1;
1001 ctx
->Pixel
.MapItoIsize
= 1;
1002 ctx
->Pixel
.MapItoRsize
= 1;
1003 ctx
->Pixel
.MapItoGsize
= 1;
1004 ctx
->Pixel
.MapItoBsize
= 1;
1005 ctx
->Pixel
.MapItoAsize
= 1;
1006 ctx
->Pixel
.MapRtoRsize
= 1;
1007 ctx
->Pixel
.MapGtoGsize
= 1;
1008 ctx
->Pixel
.MapBtoBsize
= 1;
1009 ctx
->Pixel
.MapAtoAsize
= 1;
1010 ctx
->Pixel
.MapStoS
[0] = 0;
1011 ctx
->Pixel
.MapItoI
[0] = 0;
1012 ctx
->Pixel
.MapItoR
[0] = 0.0;
1013 ctx
->Pixel
.MapItoG
[0] = 0.0;
1014 ctx
->Pixel
.MapItoB
[0] = 0.0;
1015 ctx
->Pixel
.MapItoA
[0] = 0.0;
1016 ctx
->Pixel
.MapItoR8
[0] = 0;
1017 ctx
->Pixel
.MapItoG8
[0] = 0;
1018 ctx
->Pixel
.MapItoB8
[0] = 0;
1019 ctx
->Pixel
.MapItoA8
[0] = 0;
1020 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1021 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1022 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1023 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1024 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
1025 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
1026 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
1027 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1028 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1029 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixScale
, 1.0, 1.0, 1.0, 1.0);
1030 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixBias
, 0.0, 0.0, 0.0, 0.0);
1031 ASSIGN_4V(ctx
->Pixel
.ColorTableScale
, 1.0, 1.0, 1.0, 1.0);
1032 ASSIGN_4V(ctx
->Pixel
.ColorTableBias
, 0.0, 0.0, 0.0, 0.0);
1033 ASSIGN_4V(ctx
->Pixel
.PCCTscale
, 1.0, 1.0, 1.0, 1.0);
1034 ASSIGN_4V(ctx
->Pixel
.PCCTbias
, 0.0, 0.0, 0.0, 0.0);
1035 ASSIGN_4V(ctx
->Pixel
.PCMCTscale
, 1.0, 1.0, 1.0, 1.0);
1036 ASSIGN_4V(ctx
->Pixel
.PCMCTbias
, 0.0, 0.0, 0.0, 0.0);
1037 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1038 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1039 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1040 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
1041 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
1042 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
1043 for (i
= 0; i
< 3; i
++) {
1044 ASSIGN_4V(ctx
->Pixel
.ConvolutionBorderColor
[i
], 0.0, 0.0, 0.0, 0.0);
1045 ctx
->Pixel
.ConvolutionBorderMode
[i
] = GL_REDUCE
;
1046 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterScale
[i
], 1.0, 1.0, 1.0, 1.0);
1047 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterBias
[i
], 0.0, 0.0, 0.0, 0.0);
1049 for (i
= 0; i
< MAX_CONVOLUTION_WIDTH
* MAX_CONVOLUTION_WIDTH
* 4; i
++) {
1050 ctx
->Convolution1D
.Filter
[i
] = 0.0;
1051 ctx
->Convolution2D
.Filter
[i
] = 0.0;
1052 ctx
->Separable2D
.Filter
[i
] = 0.0;
1054 ASSIGN_4V(ctx
->Pixel
.PostConvolutionScale
, 1.0, 1.0, 1.0, 1.0);
1055 ASSIGN_4V(ctx
->Pixel
.PostConvolutionBias
, 0.0, 0.0, 0.0, 0.0);
1058 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1059 ctx
->Point
.Size
= 1.0;
1060 ctx
->Point
._Size
= 1.0;
1061 ctx
->Point
.Params
[0] = 1.0;
1062 ctx
->Point
.Params
[1] = 0.0;
1063 ctx
->Point
.Params
[2] = 0.0;
1064 ctx
->Point
._Attenuated
= GL_FALSE
;
1065 ctx
->Point
.MinSize
= 0.0;
1066 ctx
->Point
.MaxSize
= ctx
->Const
.MaxPointSize
;
1067 ctx
->Point
.Threshold
= 1.0;
1068 ctx
->Point
.SpriteMode
= GL_FALSE
; /* GL_MESA_sprite_point */
1071 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1072 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1073 ctx
->Polygon
.FrontFace
= GL_CCW
;
1074 ctx
->Polygon
._FrontBit
= 0;
1075 ctx
->Polygon
.FrontMode
= GL_FILL
;
1076 ctx
->Polygon
.BackMode
= GL_FILL
;
1077 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1078 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1079 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1080 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1081 ctx
->Polygon
.OffsetMRD
= 0.0F
;
1082 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1083 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1084 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1086 /* Polygon Stipple group */
1087 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1090 ctx
->Scissor
.Enabled
= GL_FALSE
;
1093 ctx
->Scissor
.Width
= 0;
1094 ctx
->Scissor
.Height
= 0;
1097 ctx
->Stencil
.Enabled
= GL_FALSE
;
1098 ctx
->Stencil
.Function
= GL_ALWAYS
;
1099 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1100 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1101 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1102 ctx
->Stencil
.Ref
= 0;
1103 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1104 ctx
->Stencil
.Clear
= 0;
1105 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1108 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1109 ctx
->Texture
.CurrentTransformUnit
= 0; /* multitexture */
1110 ctx
->Texture
._ReallyEnabled
= 0;
1111 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1112 init_texture_unit( ctx
, i
);
1113 ctx
->Texture
.SharedPalette
= GL_FALSE
;
1114 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1116 /* Transformation group */
1117 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1118 ctx
->Transform
.Normalize
= GL_FALSE
;
1119 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1120 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1121 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1122 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1124 ctx
->Transform
._AnyClip
= GL_FALSE
;
1126 /* Viewport group */
1127 ctx
->Viewport
.X
= 0;
1128 ctx
->Viewport
.Y
= 0;
1129 ctx
->Viewport
.Width
= 0;
1130 ctx
->Viewport
.Height
= 0;
1131 ctx
->Viewport
.Near
= 0.0;
1132 ctx
->Viewport
.Far
= 1.0;
1133 _math_matrix_ctr(&ctx
->Viewport
._WindowMap
);
1137 ctx
->Viewport
._WindowMap
.m
[Sz
] = 0.5 * ctx
->DepthMaxF
;
1138 ctx
->Viewport
._WindowMap
.m
[Tz
] = 0.5 * ctx
->DepthMaxF
;
1142 ctx
->Viewport
._WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1143 ctx
->Viewport
._WindowMap
.type
= MATRIX_3D_NO_ROT
;
1146 ctx
->Array
.Vertex
.Size
= 4;
1147 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1148 ctx
->Array
.Vertex
.Stride
= 0;
1149 ctx
->Array
.Vertex
.StrideB
= 0;
1150 ctx
->Array
.Vertex
.Ptr
= NULL
;
1151 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1152 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1153 ctx
->Array
.Normal
.Stride
= 0;
1154 ctx
->Array
.Normal
.StrideB
= 0;
1155 ctx
->Array
.Normal
.Ptr
= NULL
;
1156 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1157 ctx
->Array
.Color
.Size
= 4;
1158 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1159 ctx
->Array
.Color
.Stride
= 0;
1160 ctx
->Array
.Color
.StrideB
= 0;
1161 ctx
->Array
.Color
.Ptr
= NULL
;
1162 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1163 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1164 ctx
->Array
.Index
.Stride
= 0;
1165 ctx
->Array
.Index
.StrideB
= 0;
1166 ctx
->Array
.Index
.Ptr
= NULL
;
1167 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1168 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1169 ctx
->Array
.TexCoord
[i
].Size
= 4;
1170 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1171 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1172 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1173 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1174 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1176 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1177 ctx
->Array
.EdgeFlag
.Stride
= 0;
1178 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1179 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1180 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1181 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1183 /* Pixel transfer */
1184 ctx
->Pack
.Alignment
= 4;
1185 ctx
->Pack
.RowLength
= 0;
1186 ctx
->Pack
.ImageHeight
= 0;
1187 ctx
->Pack
.SkipPixels
= 0;
1188 ctx
->Pack
.SkipRows
= 0;
1189 ctx
->Pack
.SkipImages
= 0;
1190 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1191 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1192 ctx
->Unpack
.Alignment
= 4;
1193 ctx
->Unpack
.RowLength
= 0;
1194 ctx
->Unpack
.ImageHeight
= 0;
1195 ctx
->Unpack
.SkipPixels
= 0;
1196 ctx
->Unpack
.SkipRows
= 0;
1197 ctx
->Unpack
.SkipImages
= 0;
1198 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1199 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1202 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1203 ctx
->Feedback
.Buffer
= NULL
;
1204 ctx
->Feedback
.BufferSize
= 0;
1205 ctx
->Feedback
.Count
= 0;
1207 /* Selection/picking */
1208 ctx
->Select
.Buffer
= NULL
;
1209 ctx
->Select
.BufferSize
= 0;
1210 ctx
->Select
.BufferCount
= 0;
1211 ctx
->Select
.Hits
= 0;
1212 ctx
->Select
.NameStackDepth
= 0;
1214 /* Renderer and client attribute stacks */
1215 ctx
->AttribStackDepth
= 0;
1216 ctx
->ClientAttribStackDepth
= 0;
1220 ctx
->ExecuteFlag
= GL_TRUE
;
1221 ctx
->CompileFlag
= GL_FALSE
;
1222 ctx
->CurrentListPtr
= NULL
;
1223 ctx
->CurrentBlock
= NULL
;
1224 ctx
->CurrentListNum
= 0;
1225 ctx
->CurrentPos
= 0;
1228 _mesa_init_colortable(&ctx
->ColorTable
);
1229 _mesa_init_colortable(&ctx
->ProxyColorTable
);
1230 _mesa_init_colortable(&ctx
->PostConvolutionColorTable
);
1231 _mesa_init_colortable(&ctx
->ProxyPostConvolutionColorTable
);
1232 _mesa_init_colortable(&ctx
->PostColorMatrixColorTable
);
1233 _mesa_init_colortable(&ctx
->ProxyPostColorMatrixColorTable
);
1236 ctx
->NewState
= _NEW_ALL
;
1237 ctx
->RenderMode
= GL_RENDER
;
1238 ctx
->_ImageTransferState
= 0;
1240 ctx
->_NeedNormals
= 0;
1241 ctx
->_NeedEyeCoords
= 0;
1242 ctx
->_ModelViewInvScale
= 1.0;
1244 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1246 ctx
->CatchSignals
= GL_TRUE
;
1247 ctx
->OcclusionResult
= GL_FALSE
;
1248 ctx
->OcclusionResultSaved
= GL_FALSE
;
1250 /* For debug/development only */
1251 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1252 ctx
->FirstTimeCurrent
= GL_TRUE
;
1254 /* Dither disable */
1255 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1256 if (ctx
->NoDither
) {
1257 if (getenv("MESA_DEBUG")) {
1258 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1260 ctx
->Color
.DitherFlag
= GL_FALSE
;
1268 * Allocate the proxy textures. If we run out of memory part way through
1269 * the allocations clean up and return GL_FALSE.
1270 * Return: GL_TRUE=success, GL_FALSE=failure
1273 alloc_proxy_textures( GLcontext
*ctx
)
1275 GLboolean out_of_memory
;
1278 ctx
->Texture
.Proxy1D
= _mesa_alloc_texture_object(NULL
, 0, 1);
1279 if (!ctx
->Texture
.Proxy1D
) {
1283 ctx
->Texture
.Proxy2D
= _mesa_alloc_texture_object(NULL
, 0, 2);
1284 if (!ctx
->Texture
.Proxy2D
) {
1285 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1289 ctx
->Texture
.Proxy3D
= _mesa_alloc_texture_object(NULL
, 0, 3);
1290 if (!ctx
->Texture
.Proxy3D
) {
1291 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1292 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1296 ctx
->Texture
.ProxyCubeMap
= _mesa_alloc_texture_object(NULL
, 0, 6);
1297 if (!ctx
->Texture
.ProxyCubeMap
) {
1298 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1299 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1300 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1304 out_of_memory
= GL_FALSE
;
1305 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1306 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1307 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1308 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1309 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1310 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1311 || !ctx
->Texture
.Proxy3D
->Image
[i
]) {
1312 out_of_memory
= GL_TRUE
;
1315 if (out_of_memory
) {
1316 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1317 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1318 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1320 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1321 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1323 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1324 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1327 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1328 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1329 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1339 * Initialize a GLcontext struct. This includes allocating all the
1340 * other structs and arrays which hang off of the context by pointers.
1343 _mesa_initialize_context( GLcontext
*ctx
,
1345 GLcontext
*share_list
,
1349 GLuint dispatchSize
;
1351 (void) direct
; /* not used */
1353 /* misc one-time initializations */
1359 if (!ctx
->imports
.malloc
) {
1360 _mesa_InitDefaultImports(&ctx
->imports
, driver_ctx
, NULL
);
1362 /* exports are setup by the device driver */
1364 ctx
->DriverCtx
= driver_ctx
;
1365 ctx
->Visual
= *visual
;
1366 ctx
->DrawBuffer
= NULL
;
1367 ctx
->ReadBuffer
= NULL
;
1370 /* share the group of display lists of another context */
1371 ctx
->Shared
= share_list
->Shared
;
1374 /* allocate new group of display lists */
1375 ctx
->Shared
= alloc_shared_state();
1380 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1381 ctx
->Shared
->RefCount
++;
1382 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1384 init_attrib_groups( ctx
);
1386 if (visual
->doubleBufferMode
) {
1387 ctx
->Color
.DrawBuffer
= GL_BACK
;
1388 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1389 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1390 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1391 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1394 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1395 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1396 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1397 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1398 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1401 if (!alloc_proxy_textures(ctx
)) {
1402 free_shared_state(ctx
, ctx
->Shared
);
1406 /* register the most recent extension functions with libGL */
1407 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1408 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1409 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1410 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1411 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1412 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1413 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1414 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1416 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1417 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1418 * Mesa we do this to accomodate different versions of libGL and various
1421 dispatchSize
= MAX2(_glapi_get_dispatch_table_size(),
1422 sizeof(struct _glapi_table
) / sizeof(void *));
1424 /* setup API dispatch tables */
1425 ctx
->Exec
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1426 ctx
->Save
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1427 if (!ctx
->Exec
|| !ctx
->Save
) {
1428 free_shared_state(ctx
, ctx
->Shared
);
1432 _mesa_init_exec_table(ctx
->Exec
, dispatchSize
);
1433 _mesa_init_dlist_table(ctx
->Save
, dispatchSize
);
1434 ctx
->CurrentDispatch
= ctx
->Exec
;
1436 ctx
->ExecPrefersFloat
= GL_FALSE
;
1437 ctx
->SavePrefersFloat
= GL_FALSE
;
1439 /* Z buffer stuff */
1440 if (ctx
->Visual
.depthBits
== 0) {
1441 /* Special case. Even if we don't have a depth buffer we need
1442 * good values for DepthMax for Z vertex transformation purposes
1443 * and for per-fragment fog computation.
1445 ctx
->DepthMax
= 1 << 16;
1446 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1448 else if (ctx
->Visual
.depthBits
< 32) {
1449 ctx
->DepthMax
= (1 << ctx
->Visual
.depthBits
) - 1;
1450 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1453 /* Special case since shift values greater than or equal to the
1454 * number of bits in the left hand expression's type are undefined.
1456 ctx
->DepthMax
= 0xffffffff;
1457 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1459 ctx
->MRD
= 2.0; /* XXX temporary value */
1462 #if defined(MESA_TRACE)
1463 ctx
->TraceCtx
= CALLOC( sizeof(trace_context_t
) );
1465 /* Brian: do you want to have CreateContext fail here,
1466 or should we just trap in NewTrace (currently done)? */
1467 if (!(ctx
->TraceCtx
)) {
1468 free_shared_state(ctx
, ctx
->Shared
);
1474 trInitContext(ctx
->TraceCtx
);
1476 ctx
->TraceDispatch
= (struct _glapi_table
*)
1477 CALLOC(dispatchSize
* sizeof(void*));
1479 if (!(ctx
->TraceCtx
)) {
1480 free_shared_state(ctx
, ctx
->Shared
);
1483 FREE( ctx
->TraceCtx
);
1487 trInitDispatch(ctx
->TraceDispatch
);
1496 * Allocate and initialize a GLcontext structure.
1497 * Input: visual - a GLvisual pointer
1498 * sharelist - another context to share display lists with or NULL
1499 * driver_ctx - pointer to device driver's context state struct
1500 * Return: pointer to a new __GLcontextRec or NULL if error.
1503 _mesa_create_context( GLvisual
*visual
,
1504 GLcontext
*share_list
,
1508 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1513 if (_mesa_initialize_context(ctx
, visual
, share_list
, driver_ctx
, direct
)) {
1525 * Free the data associated with the given context.
1526 * But don't free() the GLcontext struct itself!
1529 _mesa_free_context_data( GLcontext
*ctx
)
1531 struct gl_shine_tab
*s
, *tmps
;
1534 /* if we're destroying the current context, unbind it first */
1535 if (ctx
== _mesa_get_current_context()) {
1536 _mesa_make_current(NULL
, NULL
);
1539 _math_matrix_dtr( &ctx
->ModelView
);
1540 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
1541 _math_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1543 _math_matrix_dtr( &ctx
->ProjectionMatrix
);
1544 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
1545 _math_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1547 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1548 _math_matrix_dtr( &ctx
->TextureMatrix
[i
] );
1549 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
1550 _math_matrix_dtr( &ctx
->TextureStack
[i
][j
] );
1554 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1555 ctx
->Shared
->RefCount
--;
1556 assert(ctx
->Shared
->RefCount
>= 0);
1557 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1558 if (ctx
->Shared
->RefCount
== 0) {
1559 /* free shared state */
1560 free_shared_state( ctx
, ctx
->Shared
);
1563 foreach_s( s
, tmps
, ctx
->_ShineTabList
) {
1566 FREE( ctx
->_ShineTabList
);
1568 /* Free proxy texture objects */
1569 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1570 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1571 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1573 /* Free evaluator data */
1574 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1575 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1576 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1577 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1578 if (ctx
->EvalMap
.Map1Index
.Points
)
1579 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1580 if (ctx
->EvalMap
.Map1Color4
.Points
)
1581 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1582 if (ctx
->EvalMap
.Map1Normal
.Points
)
1583 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1584 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1585 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1586 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1587 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1588 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1589 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1590 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1591 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1593 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1594 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1595 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1596 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1597 if (ctx
->EvalMap
.Map2Index
.Points
)
1598 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1599 if (ctx
->EvalMap
.Map2Color4
.Points
)
1600 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1601 if (ctx
->EvalMap
.Map2Normal
.Points
)
1602 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1603 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1604 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1605 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1606 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1607 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1608 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1609 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1610 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1612 _mesa_free_colortable_data( &ctx
->ColorTable
);
1613 _mesa_free_colortable_data( &ctx
->PostConvolutionColorTable
);
1614 _mesa_free_colortable_data( &ctx
->PostColorMatrixColorTable
);
1615 _mesa_free_colortable_data( &ctx
->Texture
.Palette
);
1617 _mesa_extensions_dtr(ctx
);
1626 * Destroy a GLcontext structure.
1629 _mesa_destroy_context( GLcontext
*ctx
)
1632 _mesa_free_context_data(ctx
);
1633 FREE( (void *) ctx
);
1640 * Called by the driver after both the context and driver are fully
1641 * initialized. Currently just reads the config file.
1644 _mesa_context_initialize( GLcontext
*ctx
)
1646 gl_read_config_file( ctx
);
1652 * Copy attribute groups from one context to another.
1653 * Input: src - source context
1654 * dst - destination context
1655 * mask - bitwise OR of GL_*_BIT flags
1658 _mesa_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1660 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1661 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1663 if (mask
& GL_COLOR_BUFFER_BIT
) {
1664 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1666 if (mask
& GL_CURRENT_BIT
) {
1667 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1669 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1670 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1672 if (mask
& GL_ENABLE_BIT
) {
1675 if (mask
& GL_EVAL_BIT
) {
1676 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1678 if (mask
& GL_FOG_BIT
) {
1679 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1681 if (mask
& GL_HINT_BIT
) {
1682 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1684 if (mask
& GL_LIGHTING_BIT
) {
1685 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1686 /* gl_reinit_light_attrib( &dst->Light ); */
1688 if (mask
& GL_LINE_BIT
) {
1689 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1691 if (mask
& GL_LIST_BIT
) {
1692 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1694 if (mask
& GL_PIXEL_MODE_BIT
) {
1695 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1697 if (mask
& GL_POINT_BIT
) {
1698 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1700 if (mask
& GL_POLYGON_BIT
) {
1701 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1703 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1704 /* Use loop instead of MEMCPY due to problem with Portland Group's
1705 * C compiler. Reported by John Stone.
1708 for (i
=0;i
<32;i
++) {
1709 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1712 if (mask
& GL_SCISSOR_BIT
) {
1713 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1715 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1716 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1718 if (mask
& GL_TEXTURE_BIT
) {
1719 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1721 if (mask
& GL_TRANSFORM_BIT
) {
1722 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1724 if (mask
& GL_VIEWPORT_BIT
) {
1725 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1727 /* XXX FIXME: Call callbacks?
1729 dst
->NewState
= _NEW_ALL
;
1734 * Set the current context, binding the given frame buffer to the context.
1737 _mesa_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1739 _mesa_make_current2( newCtx
, buffer
, buffer
);
1743 static void print_info( void )
1745 fprintf(stderr
, "Mesa GL_VERSION = %s\n",
1746 (char *) _mesa_GetString(GL_VERSION
));
1747 fprintf(stderr
, "Mesa GL_RENDERER = %s\n",
1748 (char *) _mesa_GetString(GL_RENDERER
));
1749 fprintf(stderr
, "Mesa GL_VENDOR = %s\n",
1750 (char *) _mesa_GetString(GL_VENDOR
));
1751 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n",
1752 (char *) _mesa_GetString(GL_EXTENSIONS
));
1753 #if defined(THREADS)
1754 fprintf(stderr
, "Mesa thread-safe: YES\n");
1756 fprintf(stderr
, "Mesa thread-safe: NO\n");
1758 #if defined(USE_X86_ASM)
1759 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1761 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1767 * Bind the given context to the given draw-buffer and read-buffer
1768 * and make it the current context for this thread.
1771 _mesa_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1772 GLframebuffer
*readBuffer
)
1775 fprintf(stderr
, "_mesa_make_current2()\n");
1777 /* We call this function periodically (just here for now) in
1778 * order to detect when multithreading has begun.
1780 _glapi_check_multithread();
1782 _glapi_set_context((void *) newCtx
);
1783 ASSERT(_mesa_get_current_context() == newCtx
);
1787 _glapi_set_dispatch(NULL
); /* none current */
1790 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1792 if (drawBuffer
&& readBuffer
) {
1793 /* TODO: check if newCtx and buffer's visual match??? */
1794 newCtx
->DrawBuffer
= drawBuffer
;
1795 newCtx
->ReadBuffer
= readBuffer
;
1796 newCtx
->NewState
|= _NEW_BUFFERS
;
1797 /* gl_update_state( newCtx ); */
1800 if (newCtx
->Driver
.MakeCurrent
)
1801 newCtx
->Driver
.MakeCurrent( newCtx
, drawBuffer
, readBuffer
);
1803 /* We can use this to help debug user's problems. Tell them to set
1804 * the MESA_INFO env variable before running their app. Then the
1805 * first time each context is made current we'll print some useful
1808 if (newCtx
->FirstTimeCurrent
) {
1809 if (getenv("MESA_INFO")) {
1812 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1820 * Return current context handle for the calling thread.
1821 * This isn't the fastest way to get the current context.
1822 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1825 _mesa_get_current_context( void )
1827 return (GLcontext
*) _glapi_get_context();
1833 * This should be called by device drivers just before they do a
1834 * swapbuffers. Any pending rendering commands will be executed.
1837 _mesa_swapbuffers(GLcontext
*ctx
)
1839 FLUSH_VERTICES( ctx
, 0 );
1845 * Return pointer to this context's current API dispatch table.
1846 * It'll either be the immediate-mode execute dispatcher or the
1847 * display list compile dispatcher.
1849 struct _glapi_table
*
1850 _mesa_get_dispatch(GLcontext
*ctx
)
1852 return ctx
->CurrentDispatch
;
1857 /**********************************************************************/
1858 /***** Miscellaneous functions *****/
1859 /**********************************************************************/
1863 * This function is called when the Mesa user has stumbled into a code
1864 * path which may not be implemented fully or correctly.
1866 void gl_problem( const GLcontext
*ctx
, const char *s
)
1868 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
1869 fprintf( stderr
, "Report to Mesa bug database at www.mesa3d.org\n" );
1876 * This is called to inform the user that he or she has tried to do
1877 * something illogical or if there's likely a bug in their program
1878 * (like enabled depth testing without a depth buffer).
1881 _mesa_warning( const GLcontext
*ctx
, const char *s
)
1883 (*ctx
->imports
.warning
)((__GLcontext
*) ctx
, (char *) s
);
1889 * Compile an error into current display list.
1892 _mesa_compile_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1894 if (ctx
->CompileFlag
)
1895 gl_save_error( ctx
, error
, s
);
1897 if (ctx
->ExecuteFlag
)
1898 gl_error( ctx
, error
, s
);
1904 * This is Mesa's error handler. Normally, all that's done is the updating
1905 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1906 * environment variable "MESA_DEBUG" is defined then a real error message
1907 * is printed to stderr.
1908 * Input: ctx - the GL context
1909 * error - the error value
1910 * where - usually the name of function where error was detected
1913 gl_error( GLcontext
*ctx
, GLenum error
, const char *where
)
1915 const char *debugEnv
= getenv("MESA_DEBUG");
1919 if (debugEnv
&& strstr(debugEnv
, "silent"))
1934 errstr
= "GL_NO_ERROR";
1936 case GL_INVALID_VALUE
:
1937 errstr
= "GL_INVALID_VALUE";
1939 case GL_INVALID_ENUM
:
1940 errstr
= "GL_INVALID_ENUM";
1942 case GL_INVALID_OPERATION
:
1943 errstr
= "GL_INVALID_OPERATION";
1945 case GL_STACK_OVERFLOW
:
1946 errstr
= "GL_STACK_OVERFLOW";
1948 case GL_STACK_UNDERFLOW
:
1949 errstr
= "GL_STACK_UNDERFLOW";
1951 case GL_OUT_OF_MEMORY
:
1952 errstr
= "GL_OUT_OF_MEMORY";
1954 case GL_TABLE_TOO_LARGE
:
1955 errstr
= "GL_TABLE_TOO_LARGE";
1961 fprintf(stderr
, "Mesa user error: %s in %s\n", errstr
, where
);
1964 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
1965 ctx
->ErrorValue
= error
;
1968 /* Call device driver's error handler, if any. This is used on the Mac. */
1969 if (ctx
->Driver
.Error
) {
1970 (*ctx
->Driver
.Error
)( ctx
);
1977 _mesa_Finish( void )
1979 GET_CURRENT_CONTEXT(ctx
);
1980 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1981 if (ctx
->Driver
.Finish
) {
1982 (*ctx
->Driver
.Finish
)( ctx
);
1991 GET_CURRENT_CONTEXT(ctx
);
1992 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1993 if (ctx
->Driver
.Flush
) {
1994 (*ctx
->Driver
.Flush
)( ctx
);
2000 const char *_mesa_prim_name
[GL_POLYGON
+4] = {
2006 "GL_TRIANGLE_STRIP",
2011 "outside begin/end",
2012 "inside unkown primitive",
2017 GLenum gl_reduce_prim
[GL_POLYGON
+1] = {