1 /* $Id: context.c,v 1.181 2002/10/09 19:36:24 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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"
48 #include "simple_list.h"
57 #include "math/m_translate.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"
76 #ifndef MESA_DEBUG_FLAGS
77 int MESA_DEBUG_FLAGS
= 0;
86 extern void *calloc(size_t, size_t);
90 extern void free(void *);
95 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
);
98 /**********************************************************************/
99 /***** OpenGL SI-style interface (new in Mesa 3.5) *****/
100 /**********************************************************************/
102 /* Called by window system/device driver (via gc->exports.destroyCurrent())
103 * when the rendering context is to be destroyed.
106 _mesa_destroyContext(__GLcontext
*gc
)
109 _mesa_free_context_data(gc
);
110 (*gc
->imports
.free
)(gc
, gc
);
115 /* Called by window system/device driver (via gc->exports.loseCurrent())
116 * when the rendering context is made non-current.
119 _mesa_loseCurrent(__GLcontext
*gc
)
121 /* XXX unbind context from thread */
125 /* Called by window system/device driver (via gc->exports.makeCurrent())
126 * when the rendering context is made current.
129 _mesa_makeCurrent(__GLcontext
*gc
)
131 /* XXX bind context to thread */
135 /* Called by window system/device driver - yadda, yadda, yadda.
136 * See above comments.
139 _mesa_shareContext(__GLcontext
*gc
, __GLcontext
*gcShare
)
141 if (gc
&& gcShare
&& gc
->Shared
&& gcShare
->Shared
) {
142 gc
->Shared
->RefCount
--;
143 if (gc
->Shared
->RefCount
== 0) {
144 free_shared_state(gc
, gc
->Shared
);
146 gc
->Shared
= gcShare
->Shared
;
147 gc
->Shared
->RefCount
++;
156 _mesa_copyContext(__GLcontext
*dst
, const __GLcontext
*src
, GLuint mask
)
159 _mesa_copy_context( src
, dst
, mask
);
168 _mesa_forceCurrent(__GLcontext
*gc
)
174 _mesa_notifyResize(__GLcontext
*gc
)
177 GLuint width
, height
;
178 __GLdrawablePrivate
*d
= gc
->imports
.getDrawablePrivate(gc
);
179 if (!d
|| !d
->getDrawableSize
)
181 d
->getDrawableSize( d
, &x
, &y
, &width
, &height
);
182 /* update viewport, resize software buffers, etc. */
187 _mesa_notifyDestroy(__GLcontext
*gc
)
191 /* Called by window system just before swapping buffers.
192 * We have to finish any pending rendering.
195 _mesa_notifySwapBuffers(__GLcontext
*gc
)
197 FLUSH_VERTICES( gc
, 0 );
200 struct __GLdispatchStateRec
*
201 _mesa_dispatchExec(__GLcontext
*gc
)
207 _mesa_beginDispatchOverride(__GLcontext
*gc
)
212 _mesa_endDispatchOverride(__GLcontext
*gc
)
216 /* Setup the exports. The window system will call these functions
217 * when it needs Mesa to do something.
218 * NOTE: Device drivers should override these functions! For example,
219 * the Xlib driver should plug in the XMesa*-style functions into this
220 * structure. The XMesa-style functions should then call the _mesa_*
221 * version of these functions. This is an approximation to OO design
222 * (inheritance and virtual functions).
225 _mesa_init_default_exports(__GLexports
*exports
)
227 exports
->destroyContext
= _mesa_destroyContext
;
228 exports
->loseCurrent
= _mesa_loseCurrent
;
229 exports
->makeCurrent
= _mesa_makeCurrent
;
230 exports
->shareContext
= _mesa_shareContext
;
231 exports
->copyContext
= _mesa_copyContext
;
232 exports
->forceCurrent
= _mesa_forceCurrent
;
233 exports
->notifyResize
= _mesa_notifyResize
;
234 exports
->notifyDestroy
= _mesa_notifyDestroy
;
235 exports
->notifySwapBuffers
= _mesa_notifySwapBuffers
;
236 exports
->dispatchExec
= _mesa_dispatchExec
;
237 exports
->beginDispatchOverride
= _mesa_beginDispatchOverride
;
238 exports
->endDispatchOverride
= _mesa_endDispatchOverride
;
243 /* exported OpenGL SI interface */
245 __glCoreCreateContext(__GLimports
*imports
, __GLcontextModes
*modes
)
249 ctx
= (GLcontext
*) (*imports
->calloc
)(NULL
, 1, sizeof(GLcontext
));
253 ctx
->Driver
.CurrentExecPrimitive
=0; /* XXX why is this here??? */
254 ctx
->imports
= *imports
;
255 _mesa_init_default_exports(&(ctx
->exports
));
257 _mesa_initialize_visual(&ctx
->Visual
,
259 modes
->doubleBufferMode
,
269 modes
->accumGreenBits
,
270 modes
->accumBlueBits
,
271 modes
->accumAlphaBits
,
274 _mesa_initialize_context(ctx
, &ctx
->Visual
, NULL
, imports
);
280 /* exported OpenGL SI interface */
282 __glCoreNopDispatch(void)
286 __gl_dispatch
= __glNopDispatchState
;
289 _glapi_set_dispatch(NULL
);
294 /**********************************************************************/
295 /***** GL Visual allocation/destruction *****/
296 /**********************************************************************/
300 * Allocate a new GLvisual object.
301 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
302 * dbFlag - double buffering?
303 * stereoFlag - stereo buffer?
304 * depthBits - requested bits per depth buffer value
305 * Any value in [0, 32] is acceptable but the actual
306 * depth type will be GLushort or GLuint as needed.
307 * stencilBits - requested minimum bits per stencil buffer value
308 * accumBits - requested minimum bits per accum buffer component
309 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
310 * red/green/blue/alphaBits - number of bits per color component
311 * in frame buffer for RGB(A) mode.
312 * We always use 8 in core Mesa though.
313 * Return: pointer to new GLvisual or NULL if requested parameters can't
317 _mesa_create_visual( GLboolean rgbFlag
,
319 GLboolean stereoFlag
,
328 GLint accumGreenBits
,
330 GLint accumAlphaBits
,
333 GLvisual
*vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
335 if (!_mesa_initialize_visual(vis
, rgbFlag
, dbFlag
, stereoFlag
,
336 redBits
, greenBits
, blueBits
, alphaBits
,
337 indexBits
, depthBits
, stencilBits
,
338 accumRedBits
, accumGreenBits
,
339 accumBlueBits
, accumAlphaBits
,
350 * Initialize the fields of the given GLvisual.
351 * Input: see _mesa_create_visual() above.
352 * Return: GL_TRUE = success
353 * GL_FALSE = failure.
356 _mesa_initialize_visual( GLvisual
*vis
,
359 GLboolean stereoFlag
,
368 GLint accumGreenBits
,
370 GLint accumAlphaBits
,
377 /* This is to catch bad values from device drivers not updated for
378 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
379 * bad value now (a 1-bit depth buffer!?!).
381 assert(depthBits
== 0 || depthBits
> 1);
383 if (depthBits
< 0 || depthBits
> 32) {
386 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
389 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
392 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
395 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
398 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
402 vis
->rgbMode
= rgbFlag
;
403 vis
->doubleBufferMode
= dbFlag
;
404 vis
->stereoMode
= stereoFlag
;
405 vis
->redBits
= redBits
;
406 vis
->greenBits
= greenBits
;
407 vis
->blueBits
= blueBits
;
408 vis
->alphaBits
= alphaBits
;
410 vis
->indexBits
= indexBits
;
411 vis
->depthBits
= depthBits
;
412 vis
->accumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
413 vis
->accumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
414 vis
->accumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
415 vis
->accumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
416 vis
->stencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
423 _mesa_destroy_visual( GLvisual
*vis
)
429 /**********************************************************************/
430 /***** GL Framebuffer allocation/destruction *****/
431 /**********************************************************************/
435 * Create a new framebuffer. A GLframebuffer is a struct which
436 * encapsulates the depth, stencil and accum buffers and related
438 * Input: visual - a GLvisual pointer (we copy the struct contents)
439 * softwareDepth - create/use a software depth buffer?
440 * softwareStencil - create/use a software stencil buffer?
441 * softwareAccum - create/use a software accum buffer?
442 * softwareAlpha - create/use a software alpha buffer?
443 * Return: pointer to new GLframebuffer struct or NULL if error.
446 _mesa_create_framebuffer( const GLvisual
*visual
,
447 GLboolean softwareDepth
,
448 GLboolean softwareStencil
,
449 GLboolean softwareAccum
,
450 GLboolean softwareAlpha
)
452 GLframebuffer
*buffer
= CALLOC_STRUCT(gl_frame_buffer
);
455 _mesa_initialize_framebuffer(buffer
, visual
,
456 softwareDepth
, softwareStencil
,
457 softwareAccum
, softwareAlpha
);
464 * Initialize a GLframebuffer object.
465 * Input: See _mesa_create_framebuffer() above.
468 _mesa_initialize_framebuffer( GLframebuffer
*buffer
,
469 const GLvisual
*visual
,
470 GLboolean softwareDepth
,
471 GLboolean softwareStencil
,
472 GLboolean softwareAccum
,
473 GLboolean softwareAlpha
)
478 BZERO(buffer
, sizeof(GLframebuffer
));
481 if (softwareDepth
) {
482 assert(visual
->depthBits
> 0);
484 if (softwareStencil
) {
485 assert(visual
->stencilBits
> 0);
488 assert(visual
->rgbMode
);
489 assert(visual
->accumRedBits
> 0);
490 assert(visual
->accumGreenBits
> 0);
491 assert(visual
->accumBlueBits
> 0);
494 assert(visual
->rgbMode
);
495 assert(visual
->alphaBits
> 0);
498 buffer
->Visual
= *visual
;
499 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
500 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
501 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
502 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
507 * Free a framebuffer struct and its buffers.
510 _mesa_destroy_framebuffer( GLframebuffer
*buffer
)
513 _mesa_free_framebuffer_data(buffer
);
520 * Free the data hanging off of <buffer>, but not <buffer> itself.
523 _mesa_free_framebuffer_data( GLframebuffer
*buffer
)
528 if (buffer
->DepthBuffer
) {
529 MESA_PBUFFER_FREE( buffer
->DepthBuffer
);
530 buffer
->DepthBuffer
= NULL
;
533 MESA_PBUFFER_FREE( buffer
->Accum
);
534 buffer
->Accum
= NULL
;
536 if (buffer
->Stencil
) {
537 MESA_PBUFFER_FREE( buffer
->Stencil
);
538 buffer
->Stencil
= NULL
;
540 if (buffer
->FrontLeftAlpha
) {
541 MESA_PBUFFER_FREE( buffer
->FrontLeftAlpha
);
542 buffer
->FrontLeftAlpha
= NULL
;
544 if (buffer
->BackLeftAlpha
) {
545 MESA_PBUFFER_FREE( buffer
->BackLeftAlpha
);
546 buffer
->BackLeftAlpha
= NULL
;
548 if (buffer
->FrontRightAlpha
) {
549 MESA_PBUFFER_FREE( buffer
->FrontRightAlpha
);
550 buffer
->FrontRightAlpha
= NULL
;
552 if (buffer
->BackRightAlpha
) {
553 MESA_PBUFFER_FREE( buffer
->BackRightAlpha
);
554 buffer
->BackRightAlpha
= NULL
;
560 /**********************************************************************/
561 /***** Context allocation, initialization, destroying *****/
562 /**********************************************************************/
565 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
569 * This function just calls all the various one-time-init functions in Mesa.
572 one_time_init( GLcontext
*ctx
)
574 static GLboolean alreadyCalled
= GL_FALSE
;
575 _glthread_LOCK_MUTEX(OneTimeLock
);
576 if (!alreadyCalled
) {
577 /* do some implementation tests */
578 assert( sizeof(GLbyte
) == 1 );
579 assert( sizeof(GLshort
) >= 2 );
580 assert( sizeof(GLint
) >= 4 );
581 assert( sizeof(GLubyte
) == 1 );
582 assert( sizeof(GLushort
) >= 2 );
583 assert( sizeof(GLuint
) >= 4 );
591 _mesa_init_sparc_glapi_relocs();
593 if (ctx
->imports
.getenv(ctx
, "MESA_DEBUG")) {
594 _glapi_noop_enable_warnings(GL_TRUE
);
595 _glapi_set_warning_func( (_glapi_warning_func
) _mesa_warning
);
598 _glapi_noop_enable_warnings(GL_FALSE
);
601 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
602 _mesa_debug(ctx
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
605 alreadyCalled
= GL_TRUE
;
607 _glthread_UNLOCK_MUTEX(OneTimeLock
);
612 init_matrix_stack( struct matrix_stack
*stack
,
613 GLuint maxDepth
, GLuint dirtyFlag
)
618 stack
->MaxDepth
= maxDepth
;
619 stack
->DirtyFlag
= dirtyFlag
;
621 stack
->Stack
= (GLmatrix
*) CALLOC(maxDepth
* sizeof(GLmatrix
));
622 for (i
= 0; i
< maxDepth
; i
++) {
623 _math_matrix_ctr(&stack
->Stack
[i
]);
624 _math_matrix_alloc_inv(&stack
->Stack
[i
]);
626 stack
->Top
= stack
->Stack
;
631 free_matrix_stack( struct matrix_stack
*stack
)
634 for (i
= 0; i
< stack
->MaxDepth
; i
++) {
635 _math_matrix_dtr(&stack
->Stack
[i
]);
638 stack
->Stack
= stack
->Top
= NULL
;
643 * Allocate and initialize a shared context state structure.
645 static struct gl_shared_state
*
646 alloc_shared_state( void )
648 struct gl_shared_state
*ss
;
649 GLboolean outOfMemory
;
651 ss
= CALLOC_STRUCT(gl_shared_state
);
655 _glthread_INIT_MUTEX(ss
->Mutex
);
657 ss
->DisplayList
= _mesa_NewHashTable();
658 ss
->TexObjects
= _mesa_NewHashTable();
659 ss
->VertexPrograms
= _mesa_NewHashTable();
661 /* Default Texture objects */
662 outOfMemory
= GL_FALSE
;
664 ss
->Default1D
= _mesa_alloc_texture_object(ss
, 0, GL_TEXTURE_1D
);
665 if (!ss
->Default1D
) {
666 outOfMemory
= GL_TRUE
;
669 ss
->Default2D
= _mesa_alloc_texture_object(ss
, 0, GL_TEXTURE_2D
);
670 if (!ss
->Default2D
) {
671 outOfMemory
= GL_TRUE
;
674 ss
->Default3D
= _mesa_alloc_texture_object(ss
, 0, GL_TEXTURE_3D
);
675 if (!ss
->Default3D
) {
676 outOfMemory
= GL_TRUE
;
679 ss
->DefaultCubeMap
= _mesa_alloc_texture_object(ss
, 0,
680 GL_TEXTURE_CUBE_MAP_ARB
);
681 if (!ss
->DefaultCubeMap
) {
682 outOfMemory
= GL_TRUE
;
685 ss
->DefaultRect
= _mesa_alloc_texture_object(ss
, 0,
686 GL_TEXTURE_RECTANGLE_NV
);
687 if (!ss
->DefaultRect
) {
688 outOfMemory
= GL_TRUE
;
691 if (!ss
->DisplayList
|| !ss
->TexObjects
|| !ss
->VertexPrograms
693 /* Ran out of memory at some point. Free everything and return NULL */
695 _mesa_DeleteHashTable(ss
->DisplayList
);
697 _mesa_DeleteHashTable(ss
->TexObjects
);
698 if (ss
->VertexPrograms
)
699 _mesa_DeleteHashTable(ss
->VertexPrograms
);
701 _mesa_free_texture_object(ss
, ss
->Default1D
);
703 _mesa_free_texture_object(ss
, ss
->Default2D
);
705 _mesa_free_texture_object(ss
, ss
->Default3D
);
706 if (ss
->DefaultCubeMap
)
707 _mesa_free_texture_object(ss
, ss
->DefaultCubeMap
);
709 _mesa_free_texture_object(ss
, ss
->DefaultRect
);
720 * Deallocate a shared state context and all children structures.
723 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
725 /* Free display lists */
727 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
729 _mesa_destroy_list(ctx
, list
);
735 _mesa_DeleteHashTable(ss
->DisplayList
);
737 /* Free texture objects */
738 while (ss
->TexObjectList
) {
739 if (ctx
->Driver
.DeleteTexture
)
740 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
741 /* this function removes from linked list too! */
742 _mesa_free_texture_object(ss
, ss
->TexObjectList
);
744 _mesa_DeleteHashTable(ss
->TexObjects
);
746 /* Free vertex programs */
748 GLuint prog
= _mesa_HashFirstEntry(ss
->VertexPrograms
);
750 _mesa_delete_program(ctx
, prog
);
756 _mesa_DeleteHashTable(ss
->VertexPrograms
);
764 * Initialize the nth light. Note that the defaults for light 0 are
765 * different than the other lights.
768 init_light( struct gl_light
*l
, GLuint n
)
770 make_empty_list( l
);
772 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
774 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
775 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
778 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
779 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
781 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
782 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
783 l
->SpotExponent
= 0.0;
784 _mesa_invalidate_spot_exp_table( l
);
785 l
->SpotCutoff
= 180.0;
786 l
->_CosCutoff
= 0.0; /* KW: -ve values not admitted */
787 l
->ConstantAttenuation
= 1.0;
788 l
->LinearAttenuation
= 0.0;
789 l
->QuadraticAttenuation
= 0.0;
790 l
->Enabled
= GL_FALSE
;
796 init_lightmodel( struct gl_lightmodel
*lm
)
798 ASSIGN_4V( lm
->Ambient
, 0.2F
, 0.2F
, 0.2F
, 1.0F
);
799 lm
->LocalViewer
= GL_FALSE
;
800 lm
->TwoSide
= GL_FALSE
;
801 lm
->ColorControl
= GL_SINGLE_COLOR
;
806 init_material( struct gl_material
*m
)
808 ASSIGN_4V( m
->Ambient
, 0.2F
, 0.2F
, 0.2F
, 1.0F
);
809 ASSIGN_4V( m
->Diffuse
, 0.8F
, 0.8F
, 0.8F
, 1.0F
);
810 ASSIGN_4V( m
->Specular
, 0.0F
, 0.0F
, 0.0F
, 1.0F
);
811 ASSIGN_4V( m
->Emission
, 0.0F
, 0.0F
, 0.0F
, 1.0F
);
815 m
->SpecularIndex
= 1;
821 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
823 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
825 texUnit
->EnvMode
= GL_MODULATE
;
826 texUnit
->CombineModeRGB
= GL_MODULATE
;
827 texUnit
->CombineModeA
= GL_MODULATE
;
828 texUnit
->CombineSourceRGB
[0] = GL_TEXTURE
;
829 texUnit
->CombineSourceRGB
[1] = GL_PREVIOUS_EXT
;
830 texUnit
->CombineSourceRGB
[2] = GL_CONSTANT_EXT
;
831 texUnit
->CombineSourceA
[0] = GL_TEXTURE
;
832 texUnit
->CombineSourceA
[1] = GL_PREVIOUS_EXT
;
833 texUnit
->CombineSourceA
[2] = GL_CONSTANT_EXT
;
834 texUnit
->CombineOperandRGB
[0] = GL_SRC_COLOR
;
835 texUnit
->CombineOperandRGB
[1] = GL_SRC_COLOR
;
836 texUnit
->CombineOperandRGB
[2] = GL_SRC_ALPHA
;
837 texUnit
->CombineOperandA
[0] = GL_SRC_ALPHA
;
838 texUnit
->CombineOperandA
[1] = GL_SRC_ALPHA
;
839 texUnit
->CombineOperandA
[2] = GL_SRC_ALPHA
;
840 texUnit
->CombineScaleShiftRGB
= 0;
841 texUnit
->CombineScaleShiftA
= 0;
843 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
844 texUnit
->TexGenEnabled
= 0;
845 texUnit
->GenModeS
= GL_EYE_LINEAR
;
846 texUnit
->GenModeT
= GL_EYE_LINEAR
;
847 texUnit
->GenModeR
= GL_EYE_LINEAR
;
848 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
849 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
850 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
851 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
852 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
854 /* Yes, these plane coefficients are correct! */
855 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
856 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
857 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
858 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
859 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
860 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
861 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
862 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
864 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
865 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
866 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
867 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
868 texUnit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
874 /* Initialize a 1-D evaluator map */
876 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
881 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
885 map
->Points
[i
] = initial
[i
];
890 /* Initialize a 2-D evaluator map */
892 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
900 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
904 map
->Points
[i
] = initial
[i
];
910 * Initialize the attribute groups in a GLcontext.
913 init_attrib_groups( GLcontext
*ctx
)
919 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
920 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
922 /* Constants, may be overriden by device drivers */
923 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
924 ctx
->Const
.Max3DTextureLevels
= MAX_3D_TEXTURE_LEVELS
;
925 ctx
->Const
.MaxCubeTextureLevels
= MAX_CUBE_TEXTURE_LEVELS
;
926 ctx
->Const
.MaxTextureRectSize
= MAX_TEXTURE_RECT_SIZE
;
927 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
928 ctx
->Const
.MaxTextureMaxAnisotropy
= MAX_TEXTURE_MAX_ANISOTROPY
;
929 ctx
->Const
.MaxTextureLodBias
= MAX_TEXTURE_LOD_BIAS
;
930 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
931 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
932 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
933 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
934 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
935 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
936 ctx
->Const
.PointSizeGranularity
= (GLfloat
) POINT_SIZE_GRANULARITY
;
937 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
938 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
939 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
940 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
941 ctx
->Const
.LineWidthGranularity
= (GLfloat
) LINE_WIDTH_GRANULARITY
;
942 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
943 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
944 ctx
->Const
.MaxConvolutionWidth
= MAX_CONVOLUTION_WIDTH
;
945 ctx
->Const
.MaxConvolutionHeight
= MAX_CONVOLUTION_HEIGHT
;
946 ctx
->Const
.MaxClipPlanes
= MAX_CLIP_PLANES
;
947 ctx
->Const
.MaxLights
= MAX_LIGHTS
;
949 /* Initialize matrix stacks */
950 init_matrix_stack(&ctx
->ModelviewMatrixStack
, MAX_MODELVIEW_STACK_DEPTH
,
952 init_matrix_stack(&ctx
->ProjectionMatrixStack
, MAX_PROJECTION_STACK_DEPTH
,
954 init_matrix_stack(&ctx
->ColorMatrixStack
, MAX_COLOR_STACK_DEPTH
,
956 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
957 init_matrix_stack(&ctx
->TextureMatrixStack
[i
], MAX_TEXTURE_STACK_DEPTH
,
958 _NEW_TEXTURE_MATRIX
);
959 for (i
= 0; i
< MAX_PROGRAM_MATRICES
; i
++)
960 init_matrix_stack(&ctx
->ProgramMatrixStack
[i
], MAX_PROGRAM_STACK_DEPTH
,
962 ctx
->CurrentStack
= &ctx
->ModelviewMatrixStack
;
964 /* Init combined Modelview*Projection matrix */
965 _math_matrix_ctr( &ctx
->_ModelProjectMatrix
);
967 /* Accumulate buffer group */
968 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
970 /* Color buffer group */
971 ctx
->Color
.IndexMask
= 0xffffffff;
972 ctx
->Color
.ColorMask
[0] = 0xff;
973 ctx
->Color
.ColorMask
[1] = 0xff;
974 ctx
->Color
.ColorMask
[2] = 0xff;
975 ctx
->Color
.ColorMask
[3] = 0xff;
976 ctx
->Color
.ClearIndex
= 0;
977 ASSIGN_4V( ctx
->Color
.ClearColor
, 0, 0, 0, 0 );
978 ctx
->Color
.DrawBuffer
= GL_FRONT
;
979 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
980 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
981 ctx
->Color
.AlphaRef
= 0;
982 ctx
->Color
.BlendEnabled
= GL_FALSE
;
983 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
984 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
985 ctx
->Color
.BlendSrcA
= GL_ONE
;
986 ctx
->Color
.BlendDstA
= GL_ZERO
;
987 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
988 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
989 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
990 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
991 ctx
->Color
.LogicOp
= GL_COPY
;
992 ctx
->Color
.DitherFlag
= GL_TRUE
;
995 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_WEIGHT
], 0.0, 0.0, 0.0, 0.0 );
996 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
], 0.0, 0.0, 1.0, 0.0 );
997 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], 1.0, 1.0, 1.0, 1.0 );
998 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
], 0.0, 0.0, 0.0, 0.0 );
999 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
], 0.0, 0.0, 0.0, 0.0 );
1000 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
1001 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
], 0.0, 0.0, 0.0, 1.0 );
1002 ctx
->Current
.Index
= 1;
1003 ctx
->Current
.EdgeFlag
= GL_TRUE
;
1005 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
1006 ctx
->Current
.RasterDistance
= 0.0;
1007 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
1008 ctx
->Current
.RasterIndex
= 1;
1009 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1010 ASSIGN_4V( ctx
->Current
.RasterTexCoords
[i
], 0.0, 0.0, 0.0, 1.0 );
1011 ctx
->Current
.RasterPosValid
= GL_TRUE
;
1014 /* Depth buffer group */
1015 ctx
->Depth
.Test
= GL_FALSE
;
1016 ctx
->Depth
.Clear
= 1.0;
1017 ctx
->Depth
.Func
= GL_LESS
;
1018 ctx
->Depth
.Mask
= GL_TRUE
;
1019 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
1021 /* Evaluators group */
1022 ctx
->Eval
.Map1Color4
= GL_FALSE
;
1023 ctx
->Eval
.Map1Index
= GL_FALSE
;
1024 ctx
->Eval
.Map1Normal
= GL_FALSE
;
1025 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
1026 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
1027 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
1028 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
1029 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
1030 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
1031 MEMSET(ctx
->Eval
.Map1Attrib
, 0, sizeof(ctx
->Eval
.Map1Attrib
));
1032 ctx
->Eval
.Map2Color4
= GL_FALSE
;
1033 ctx
->Eval
.Map2Index
= GL_FALSE
;
1034 ctx
->Eval
.Map2Normal
= GL_FALSE
;
1035 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
1036 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
1037 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
1038 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
1039 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
1040 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
1041 MEMSET(ctx
->Eval
.Map2Attrib
, 0, sizeof(ctx
->Eval
.Map2Attrib
));
1042 ctx
->Eval
.AutoNormal
= GL_FALSE
;
1043 ctx
->Eval
.MapGrid1un
= 1;
1044 ctx
->Eval
.MapGrid1u1
= 0.0;
1045 ctx
->Eval
.MapGrid1u2
= 1.0;
1046 ctx
->Eval
.MapGrid2un
= 1;
1047 ctx
->Eval
.MapGrid2vn
= 1;
1048 ctx
->Eval
.MapGrid2u1
= 0.0;
1049 ctx
->Eval
.MapGrid2u2
= 1.0;
1050 ctx
->Eval
.MapGrid2v1
= 0.0;
1051 ctx
->Eval
.MapGrid2v2
= 1.0;
1053 /* Evaluator data */
1055 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
1056 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
1057 static GLfloat index
[1] = { 1.0 };
1058 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
1059 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
1060 static GLfloat attrib
[4] = { 0.0, 0.0, 0.0, 1.0 };
1062 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
1063 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
1064 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
1065 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
1066 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
1067 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
1068 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
1069 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
1070 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
1071 for (i
= 0; i
< 16; i
++)
1072 init_1d_map( ctx
->EvalMap
.Map1Attrib
+ i
, 4, attrib
);
1074 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
1075 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
1076 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
1077 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
1078 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
1079 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
1080 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
1081 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
1082 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
1083 for (i
= 0; i
< 16; i
++)
1084 init_2d_map( ctx
->EvalMap
.Map2Attrib
+ i
, 4, attrib
);
1088 ctx
->Fog
.Enabled
= GL_FALSE
;
1089 ctx
->Fog
.Mode
= GL_EXP
;
1090 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
1091 ctx
->Fog
.Index
= 0.0;
1092 ctx
->Fog
.Density
= 1.0;
1093 ctx
->Fog
.Start
= 0.0;
1095 ctx
->Fog
.ColorSumEnabled
= GL_FALSE
;
1096 ctx
->Fog
.FogCoordinateSource
= GL_FRAGMENT_DEPTH_EXT
;
1099 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
1100 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
1101 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
1102 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
1103 ctx
->Hint
.Fog
= GL_DONT_CARE
;
1104 ctx
->Hint
.ClipVolumeClipping
= GL_DONT_CARE
;
1105 ctx
->Hint
.TextureCompression
= GL_DONT_CARE
;
1106 ctx
->Hint
.GenerateMipmap
= GL_DONT_CARE
;
1108 /* Histogram group */
1109 ctx
->Histogram
.Width
= 0;
1110 ctx
->Histogram
.Format
= GL_RGBA
;
1111 ctx
->Histogram
.Sink
= GL_FALSE
;
1112 ctx
->Histogram
.RedSize
= 0;
1113 ctx
->Histogram
.GreenSize
= 0;
1114 ctx
->Histogram
.BlueSize
= 0;
1115 ctx
->Histogram
.AlphaSize
= 0;
1116 ctx
->Histogram
.LuminanceSize
= 0;
1117 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
1118 ctx
->Histogram
.Count
[i
][0] = 0;
1119 ctx
->Histogram
.Count
[i
][1] = 0;
1120 ctx
->Histogram
.Count
[i
][2] = 0;
1121 ctx
->Histogram
.Count
[i
][3] = 0;
1125 ctx
->MinMax
.Format
= GL_RGBA
;
1126 ctx
->MinMax
.Sink
= GL_FALSE
;
1127 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
1128 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
1129 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
1130 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
1133 _mesa_extensions_ctr( ctx
);
1135 /* Lighting group */
1136 for (i
=0;i
<MAX_LIGHTS
;i
++) {
1137 init_light( &ctx
->Light
.Light
[i
], i
);
1139 make_empty_list( &ctx
->Light
.EnabledList
);
1141 init_lightmodel( &ctx
->Light
.Model
);
1142 init_material( &ctx
->Light
.Material
[0] );
1143 init_material( &ctx
->Light
.Material
[1] );
1144 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
1145 ctx
->Light
.Enabled
= GL_FALSE
;
1146 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
1147 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
1148 ctx
->Light
.ColorMaterialBitmask
= _mesa_material_bitmask( ctx
,
1150 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
1152 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1154 /* Lighting miscellaneous */
1155 ctx
->_ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1156 make_empty_list( ctx
->_ShineTabList
);
1157 for (i
= 0 ; i
< 10 ; i
++) {
1158 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1161 insert_at_tail( ctx
->_ShineTabList
, s
);
1166 ctx
->Line
.SmoothFlag
= GL_FALSE
;
1167 ctx
->Line
.StippleFlag
= GL_FALSE
;
1168 ctx
->Line
.Width
= 1.0;
1169 ctx
->Line
._Width
= 1.0;
1170 ctx
->Line
.StipplePattern
= 0xffff;
1171 ctx
->Line
.StippleFactor
= 1;
1173 /* Display List group */
1174 ctx
->List
.ListBase
= 0;
1177 ctx
->Multisample
.Enabled
= GL_FALSE
;
1178 ctx
->Multisample
.SampleAlphaToCoverage
= GL_FALSE
;
1179 ctx
->Multisample
.SampleAlphaToOne
= GL_FALSE
;
1180 ctx
->Multisample
.SampleCoverage
= GL_FALSE
;
1181 ctx
->Multisample
.SampleCoverageValue
= 1.0;
1182 ctx
->Multisample
.SampleCoverageInvert
= GL_FALSE
;
1185 ctx
->Pixel
.RedBias
= 0.0;
1186 ctx
->Pixel
.RedScale
= 1.0;
1187 ctx
->Pixel
.GreenBias
= 0.0;
1188 ctx
->Pixel
.GreenScale
= 1.0;
1189 ctx
->Pixel
.BlueBias
= 0.0;
1190 ctx
->Pixel
.BlueScale
= 1.0;
1191 ctx
->Pixel
.AlphaBias
= 0.0;
1192 ctx
->Pixel
.AlphaScale
= 1.0;
1193 ctx
->Pixel
.DepthBias
= 0.0;
1194 ctx
->Pixel
.DepthScale
= 1.0;
1195 ctx
->Pixel
.IndexOffset
= 0;
1196 ctx
->Pixel
.IndexShift
= 0;
1197 ctx
->Pixel
.ZoomX
= 1.0;
1198 ctx
->Pixel
.ZoomY
= 1.0;
1199 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
1200 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
1201 ctx
->Pixel
.MapStoSsize
= 1;
1202 ctx
->Pixel
.MapItoIsize
= 1;
1203 ctx
->Pixel
.MapItoRsize
= 1;
1204 ctx
->Pixel
.MapItoGsize
= 1;
1205 ctx
->Pixel
.MapItoBsize
= 1;
1206 ctx
->Pixel
.MapItoAsize
= 1;
1207 ctx
->Pixel
.MapRtoRsize
= 1;
1208 ctx
->Pixel
.MapGtoGsize
= 1;
1209 ctx
->Pixel
.MapBtoBsize
= 1;
1210 ctx
->Pixel
.MapAtoAsize
= 1;
1211 ctx
->Pixel
.MapStoS
[0] = 0;
1212 ctx
->Pixel
.MapItoI
[0] = 0;
1213 ctx
->Pixel
.MapItoR
[0] = 0.0;
1214 ctx
->Pixel
.MapItoG
[0] = 0.0;
1215 ctx
->Pixel
.MapItoB
[0] = 0.0;
1216 ctx
->Pixel
.MapItoA
[0] = 0.0;
1217 ctx
->Pixel
.MapItoR8
[0] = 0;
1218 ctx
->Pixel
.MapItoG8
[0] = 0;
1219 ctx
->Pixel
.MapItoB8
[0] = 0;
1220 ctx
->Pixel
.MapItoA8
[0] = 0;
1221 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1222 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1223 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1224 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1225 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
1226 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
1227 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
1228 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1229 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1230 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixScale
, 1.0, 1.0, 1.0, 1.0);
1231 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixBias
, 0.0, 0.0, 0.0, 0.0);
1232 ASSIGN_4V(ctx
->Pixel
.ColorTableScale
, 1.0, 1.0, 1.0, 1.0);
1233 ASSIGN_4V(ctx
->Pixel
.ColorTableBias
, 0.0, 0.0, 0.0, 0.0);
1234 ASSIGN_4V(ctx
->Pixel
.PCCTscale
, 1.0, 1.0, 1.0, 1.0);
1235 ASSIGN_4V(ctx
->Pixel
.PCCTbias
, 0.0, 0.0, 0.0, 0.0);
1236 ASSIGN_4V(ctx
->Pixel
.PCMCTscale
, 1.0, 1.0, 1.0, 1.0);
1237 ASSIGN_4V(ctx
->Pixel
.PCMCTbias
, 0.0, 0.0, 0.0, 0.0);
1238 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1239 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1240 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1241 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
1242 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
1243 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
1244 for (i
= 0; i
< 3; i
++) {
1245 ASSIGN_4V(ctx
->Pixel
.ConvolutionBorderColor
[i
], 0.0, 0.0, 0.0, 0.0);
1246 ctx
->Pixel
.ConvolutionBorderMode
[i
] = GL_REDUCE
;
1247 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterScale
[i
], 1.0, 1.0, 1.0, 1.0);
1248 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterBias
[i
], 0.0, 0.0, 0.0, 0.0);
1250 for (i
= 0; i
< MAX_CONVOLUTION_WIDTH
* MAX_CONVOLUTION_WIDTH
* 4; i
++) {
1251 ctx
->Convolution1D
.Filter
[i
] = 0.0;
1252 ctx
->Convolution2D
.Filter
[i
] = 0.0;
1253 ctx
->Separable2D
.Filter
[i
] = 0.0;
1255 ASSIGN_4V(ctx
->Pixel
.PostConvolutionScale
, 1.0, 1.0, 1.0, 1.0);
1256 ASSIGN_4V(ctx
->Pixel
.PostConvolutionBias
, 0.0, 0.0, 0.0, 0.0);
1259 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1260 ctx
->Point
.Size
= 1.0;
1261 ctx
->Point
._Size
= 1.0;
1262 ctx
->Point
.Params
[0] = 1.0;
1263 ctx
->Point
.Params
[1] = 0.0;
1264 ctx
->Point
.Params
[2] = 0.0;
1265 ctx
->Point
._Attenuated
= GL_FALSE
;
1266 ctx
->Point
.MinSize
= 0.0;
1267 ctx
->Point
.MaxSize
= ctx
->Const
.MaxPointSize
;
1268 ctx
->Point
.Threshold
= 1.0;
1269 ctx
->Point
.PointSprite
= GL_FALSE
; /* GL_NV_point_sprite */
1270 ctx
->Point
.SpriteRMode
= GL_ZERO
; /* GL_NV_point_sprite */
1271 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1272 ctx
->Point
.CoordReplace
[i
] = GL_FALSE
; /* GL_NV_point_sprite */
1276 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1277 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1278 ctx
->Polygon
.FrontFace
= GL_CCW
;
1279 ctx
->Polygon
._FrontBit
= 0;
1280 ctx
->Polygon
.FrontMode
= GL_FILL
;
1281 ctx
->Polygon
.BackMode
= GL_FILL
;
1282 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1283 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1284 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1285 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1286 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1287 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1288 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1290 /* Polygon Stipple group */
1291 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1294 ctx
->Scissor
.Enabled
= GL_FALSE
;
1297 ctx
->Scissor
.Width
= 0;
1298 ctx
->Scissor
.Height
= 0;
1301 ctx
->Stencil
.Enabled
= GL_FALSE
;
1302 ctx
->Stencil
.TestTwoSide
= GL_FALSE
;
1303 ctx
->Stencil
.ActiveFace
= 0; /* 0 = GL_FRONT, 1 = GL_BACK */
1304 ctx
->Stencil
.Function
[0] = GL_ALWAYS
;
1305 ctx
->Stencil
.Function
[1] = GL_ALWAYS
;
1306 ctx
->Stencil
.FailFunc
[0] = GL_KEEP
;
1307 ctx
->Stencil
.FailFunc
[1] = GL_KEEP
;
1308 ctx
->Stencil
.ZPassFunc
[0] = GL_KEEP
;
1309 ctx
->Stencil
.ZPassFunc
[1] = GL_KEEP
;
1310 ctx
->Stencil
.ZFailFunc
[0] = GL_KEEP
;
1311 ctx
->Stencil
.ZFailFunc
[1] = GL_KEEP
;
1312 ctx
->Stencil
.Ref
[0] = 0;
1313 ctx
->Stencil
.Ref
[1] = 0;
1314 ctx
->Stencil
.ValueMask
[0] = STENCIL_MAX
;
1315 ctx
->Stencil
.ValueMask
[1] = STENCIL_MAX
;
1316 ctx
->Stencil
.WriteMask
[0] = STENCIL_MAX
;
1317 ctx
->Stencil
.WriteMask
[1] = STENCIL_MAX
;
1318 ctx
->Stencil
.Clear
= 0;
1321 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1322 ctx
->Texture
._EnabledUnits
= 0;
1323 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1324 init_texture_unit( ctx
, i
);
1325 ctx
->Texture
.SharedPalette
= GL_FALSE
;
1326 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1328 /* Transformation group */
1329 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1330 ctx
->Transform
.Normalize
= GL_FALSE
;
1331 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1332 ctx
->Transform
.RasterPositionUnclipped
= GL_FALSE
;
1333 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1334 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1336 ctx
->Transform
.ClipPlanesEnabled
= 0;
1338 /* Viewport group */
1339 ctx
->Viewport
.X
= 0;
1340 ctx
->Viewport
.Y
= 0;
1341 ctx
->Viewport
.Width
= 0;
1342 ctx
->Viewport
.Height
= 0;
1343 ctx
->Viewport
.Near
= 0.0;
1344 ctx
->Viewport
.Far
= 1.0;
1345 _math_matrix_ctr(&ctx
->Viewport
._WindowMap
);
1349 ctx
->Viewport
._WindowMap
.m
[Sz
] = 0.5F
* ctx
->DepthMaxF
;
1350 ctx
->Viewport
._WindowMap
.m
[Tz
] = 0.5F
* ctx
->DepthMaxF
;
1354 ctx
->Viewport
._WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1355 ctx
->Viewport
._WindowMap
.type
= MATRIX_3D_NO_ROT
;
1358 ctx
->Array
.Vertex
.Size
= 4;
1359 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1360 ctx
->Array
.Vertex
.Stride
= 0;
1361 ctx
->Array
.Vertex
.StrideB
= 0;
1362 ctx
->Array
.Vertex
.Ptr
= NULL
;
1363 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1364 ctx
->Array
.Vertex
.Flags
= CA_CLIENT_DATA
;
1365 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1366 ctx
->Array
.Normal
.Stride
= 0;
1367 ctx
->Array
.Normal
.StrideB
= 0;
1368 ctx
->Array
.Normal
.Ptr
= NULL
;
1369 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1370 ctx
->Array
.Normal
.Flags
= CA_CLIENT_DATA
;
1371 ctx
->Array
.Color
.Size
= 4;
1372 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1373 ctx
->Array
.Color
.Stride
= 0;
1374 ctx
->Array
.Color
.StrideB
= 0;
1375 ctx
->Array
.Color
.Ptr
= NULL
;
1376 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1377 ctx
->Array
.Color
.Flags
= CA_CLIENT_DATA
;
1378 ctx
->Array
.SecondaryColor
.Size
= 4;
1379 ctx
->Array
.SecondaryColor
.Type
= GL_FLOAT
;
1380 ctx
->Array
.SecondaryColor
.Stride
= 0;
1381 ctx
->Array
.SecondaryColor
.StrideB
= 0;
1382 ctx
->Array
.SecondaryColor
.Ptr
= NULL
;
1383 ctx
->Array
.SecondaryColor
.Enabled
= GL_FALSE
;
1384 ctx
->Array
.SecondaryColor
.Flags
= CA_CLIENT_DATA
;
1385 ctx
->Array
.FogCoord
.Size
= 1;
1386 ctx
->Array
.FogCoord
.Type
= GL_FLOAT
;
1387 ctx
->Array
.FogCoord
.Stride
= 0;
1388 ctx
->Array
.FogCoord
.StrideB
= 0;
1389 ctx
->Array
.FogCoord
.Ptr
= NULL
;
1390 ctx
->Array
.FogCoord
.Enabled
= GL_FALSE
;
1391 ctx
->Array
.FogCoord
.Flags
= CA_CLIENT_DATA
;
1392 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1393 ctx
->Array
.Index
.Stride
= 0;
1394 ctx
->Array
.Index
.StrideB
= 0;
1395 ctx
->Array
.Index
.Ptr
= NULL
;
1396 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1397 ctx
->Array
.Index
.Flags
= CA_CLIENT_DATA
;
1398 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1399 ctx
->Array
.TexCoord
[i
].Size
= 4;
1400 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1401 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1402 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1403 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1404 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1405 ctx
->Array
.TexCoord
[i
].Flags
= CA_CLIENT_DATA
;
1407 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1408 ctx
->Array
.EdgeFlag
.Stride
= 0;
1409 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1410 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1411 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1412 ctx
->Array
.EdgeFlag
.Flags
= CA_CLIENT_DATA
;
1413 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1415 /* Pixel transfer */
1416 ctx
->Pack
.Alignment
= 4;
1417 ctx
->Pack
.RowLength
= 0;
1418 ctx
->Pack
.ImageHeight
= 0;
1419 ctx
->Pack
.SkipPixels
= 0;
1420 ctx
->Pack
.SkipRows
= 0;
1421 ctx
->Pack
.SkipImages
= 0;
1422 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1423 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1424 ctx
->Unpack
.Alignment
= 4;
1425 ctx
->Unpack
.RowLength
= 0;
1426 ctx
->Unpack
.ImageHeight
= 0;
1427 ctx
->Unpack
.SkipPixels
= 0;
1428 ctx
->Unpack
.SkipRows
= 0;
1429 ctx
->Unpack
.SkipImages
= 0;
1430 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1431 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1434 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1435 ctx
->Feedback
.Buffer
= NULL
;
1436 ctx
->Feedback
.BufferSize
= 0;
1437 ctx
->Feedback
.Count
= 0;
1439 /* Selection/picking */
1440 ctx
->Select
.Buffer
= NULL
;
1441 ctx
->Select
.BufferSize
= 0;
1442 ctx
->Select
.BufferCount
= 0;
1443 ctx
->Select
.Hits
= 0;
1444 ctx
->Select
.NameStackDepth
= 0;
1446 /* Renderer and client attribute stacks */
1447 ctx
->AttribStackDepth
= 0;
1448 ctx
->ClientAttribStackDepth
= 0;
1452 ctx
->ExecuteFlag
= GL_TRUE
;
1453 ctx
->CompileFlag
= GL_FALSE
;
1454 ctx
->CurrentListPtr
= NULL
;
1455 ctx
->CurrentBlock
= NULL
;
1456 ctx
->CurrentListNum
= 0;
1457 ctx
->CurrentPos
= 0;
1460 _mesa_init_colortable(&ctx
->ColorTable
);
1461 _mesa_init_colortable(&ctx
->ProxyColorTable
);
1462 _mesa_init_colortable(&ctx
->PostConvolutionColorTable
);
1463 _mesa_init_colortable(&ctx
->ProxyPostConvolutionColorTable
);
1464 _mesa_init_colortable(&ctx
->PostColorMatrixColorTable
);
1465 _mesa_init_colortable(&ctx
->ProxyPostColorMatrixColorTable
);
1467 /* GL_NV_vertex_program */
1468 ctx
->VertexProgram
.Enabled
= GL_FALSE
;
1469 ctx
->VertexProgram
.PointSizeEnabled
= GL_FALSE
;
1470 ctx
->VertexProgram
.TwoSideEnabled
= GL_FALSE
;
1471 ctx
->VertexProgram
.CurrentID
= 0;
1472 ctx
->VertexProgram
.ErrorPos
= -1;
1473 ctx
->VertexProgram
.Current
= NULL
;
1474 for (i
= 0; i
< VP_NUM_PROG_REGS
/ 4; i
++) {
1475 ctx
->VertexProgram
.TrackMatrix
[i
] = GL_NONE
;
1476 ctx
->VertexProgram
.TrackMatrixTransform
[i
] = GL_IDENTITY_NV
;
1480 ctx
->NewState
= _NEW_ALL
;
1481 ctx
->RenderMode
= GL_RENDER
;
1482 ctx
->_ImageTransferState
= 0;
1484 ctx
->_NeedNormals
= 0;
1485 ctx
->_NeedEyeCoords
= 0;
1486 ctx
->_ModelViewInvScale
= 1.0;
1488 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1490 ctx
->CatchSignals
= GL_TRUE
;
1491 ctx
->OcclusionResult
= GL_FALSE
;
1492 ctx
->OcclusionResultSaved
= GL_FALSE
;
1495 /* For debug/development only */
1496 ctx
->NoRaster
= ctx
->imports
.getenv(ctx
, "MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1497 ctx
->FirstTimeCurrent
= GL_TRUE
;
1499 /* Dither disable */
1500 ctx
->NoDither
= ctx
->imports
.getenv(ctx
, "MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1501 if (ctx
->NoDither
) {
1502 if (ctx
->imports
.getenv(ctx
, "MESA_DEBUG")) {
1503 _mesa_debug(ctx
, "MESA_NO_DITHER set - dithering disabled\n");
1505 ctx
->Color
.DitherFlag
= GL_FALSE
;
1513 * Allocate the proxy textures. If we run out of memory part way through
1514 * the allocations clean up and return GL_FALSE.
1515 * Return: GL_TRUE=success, GL_FALSE=failure
1518 alloc_proxy_textures( GLcontext
*ctx
)
1520 GLboolean out_of_memory
;
1523 ctx
->Texture
.Proxy1D
= _mesa_alloc_texture_object(NULL
, 0, GL_TEXTURE_1D
);
1524 if (!ctx
->Texture
.Proxy1D
) {
1528 ctx
->Texture
.Proxy2D
= _mesa_alloc_texture_object(NULL
, 0, GL_TEXTURE_2D
);
1529 if (!ctx
->Texture
.Proxy2D
) {
1530 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1534 ctx
->Texture
.Proxy3D
= _mesa_alloc_texture_object(NULL
, 0, GL_TEXTURE_3D
);
1535 if (!ctx
->Texture
.Proxy3D
) {
1536 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1537 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1541 ctx
->Texture
.ProxyCubeMap
= _mesa_alloc_texture_object(NULL
, 0,
1542 GL_TEXTURE_CUBE_MAP_ARB
);
1543 if (!ctx
->Texture
.ProxyCubeMap
) {
1544 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1545 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1546 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1550 ctx
->Texture
.ProxyRect
= _mesa_alloc_texture_object(NULL
, 0,
1551 GL_TEXTURE_RECTANGLE_NV
);
1552 if (!ctx
->Texture
.ProxyRect
) {
1553 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1554 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1555 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1556 _mesa_free_texture_object(NULL
, ctx
->Texture
.ProxyCubeMap
);
1560 out_of_memory
= GL_FALSE
;
1561 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1562 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1563 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1564 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1565 ctx
->Texture
.ProxyCubeMap
->Image
[i
] = _mesa_alloc_texture_image();
1566 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1567 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1568 || !ctx
->Texture
.Proxy3D
->Image
[i
]
1569 || !ctx
->Texture
.ProxyCubeMap
->Image
[i
]) {
1570 out_of_memory
= GL_TRUE
;
1573 ctx
->Texture
.ProxyRect
->Image
[0] = _mesa_alloc_texture_image();
1574 if (!ctx
->Texture
.ProxyRect
->Image
[0])
1575 out_of_memory
= GL_TRUE
;
1577 if (out_of_memory
) {
1578 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1579 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1580 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1582 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1583 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1585 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1586 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1588 if (ctx
->Texture
.ProxyCubeMap
->Image
[i
]) {
1589 _mesa_free_texture_image(ctx
->Texture
.ProxyCubeMap
->Image
[i
]);
1592 if (ctx
->Texture
.ProxyRect
->Image
[0]) {
1593 _mesa_free_texture_image(ctx
->Texture
.ProxyRect
->Image
[0]);
1595 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1596 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1597 _mesa_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1598 _mesa_free_texture_object(NULL
, ctx
->Texture
.ProxyCubeMap
);
1599 _mesa_free_texture_object(NULL
, ctx
->Texture
.ProxyRect
);
1608 static void add_debug_flags( const char *debug
)
1611 if (strstr(debug
, "varray"))
1612 MESA_VERBOSE
|= VERBOSE_VARRAY
;
1614 if (strstr(debug
, "tex"))
1615 MESA_VERBOSE
|= VERBOSE_TEXTURE
;
1617 if (strstr(debug
, "imm"))
1618 MESA_VERBOSE
|= VERBOSE_IMMEDIATE
;
1620 if (strstr(debug
, "pipe"))
1621 MESA_VERBOSE
|= VERBOSE_PIPELINE
;
1623 if (strstr(debug
, "driver"))
1624 MESA_VERBOSE
|= VERBOSE_DRIVER
;
1626 if (strstr(debug
, "state"))
1627 MESA_VERBOSE
|= VERBOSE_STATE
;
1629 if (strstr(debug
, "api"))
1630 MESA_VERBOSE
|= VERBOSE_API
;
1632 if (strstr(debug
, "list"))
1633 MESA_VERBOSE
|= VERBOSE_DISPLAY_LIST
;
1635 if (strstr(debug
, "lighting"))
1636 MESA_VERBOSE
|= VERBOSE_LIGHTING
;
1640 if (strstr(debug
, "flush"))
1641 MESA_DEBUG_FLAGS
|= DEBUG_ALWAYS_FLUSH
;
1647 * Initialize a GLcontext struct. This includes allocating all the
1648 * other structs and arrays which hang off of the context by pointers.
1651 _mesa_initialize_context( GLcontext
*ctx
,
1652 const GLvisual
*visual
,
1653 GLcontext
*share_list
,
1654 const __GLimports
*imports
)
1656 GLuint dispatchSize
;
1659 ASSERT(imports
->other
); /* other points to the device driver's context */
1661 /* assing imports */
1662 ctx
->imports
= *imports
;
1664 /* initialize the exports (Mesa functions called by the window system) */
1665 _mesa_init_default_exports( &(ctx
->exports
) );
1667 /* misc one-time initializations */
1674 if (!ctx
->imports
.malloc
) {
1675 _mesa_init_default_imports(&ctx
->imports
, driver_ctx
);
1677 /* exports are setup by the device driver */
1680 ctx
->DriverCtx
= imports
->other
;
1681 ctx
->Visual
= *visual
;
1682 ctx
->DrawBuffer
= NULL
;
1683 ctx
->ReadBuffer
= NULL
;
1686 /* share state with another context */
1687 ctx
->Shared
= share_list
->Shared
;
1690 /* allocate new, unshared state */
1691 ctx
->Shared
= alloc_shared_state();
1696 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1697 ctx
->Shared
->RefCount
++;
1698 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1700 /* Effectively bind the default textures to all texture units */
1701 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
1702 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
1703 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
1704 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
1705 ctx
->Shared
->DefaultRect
->RefCount
+= MAX_TEXTURE_UNITS
;
1707 init_attrib_groups( ctx
);
1709 if (visual
->doubleBufferMode
) {
1710 ctx
->Color
.DrawBuffer
= GL_BACK
;
1711 ctx
->Color
._DriverDrawBuffer
= GL_BACK_LEFT
;
1712 ctx
->Color
._DrawDestMask
= BACK_LEFT_BIT
;
1713 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1714 ctx
->Pixel
._DriverReadBuffer
= GL_BACK_LEFT
;
1717 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1718 ctx
->Color
._DriverDrawBuffer
= GL_FRONT_LEFT
;
1719 ctx
->Color
._DrawDestMask
= FRONT_LEFT_BIT
;
1720 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1721 ctx
->Pixel
._DriverReadBuffer
= GL_FRONT_LEFT
;
1724 if (!alloc_proxy_textures(ctx
)) {
1725 free_shared_state(ctx
, ctx
->Shared
);
1729 /* register the most recent extension functions with libGL */
1730 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1731 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1732 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1733 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1734 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1735 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1736 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1737 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1738 /* XXX we should add a bunch of new functions here */
1741 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1742 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1743 * Mesa we do this to accomodate different versions of libGL and various
1746 dispatchSize
= MAX2(_glapi_get_dispatch_table_size(),
1747 sizeof(struct _glapi_table
) / sizeof(void *));
1749 /* setup API dispatch tables */
1750 ctx
->Exec
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1751 ctx
->Save
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1752 if (!ctx
->Exec
|| !ctx
->Save
) {
1753 free_shared_state(ctx
, ctx
->Shared
);
1757 _mesa_init_exec_table(ctx
->Exec
, dispatchSize
);
1758 _mesa_init_dlist_table(ctx
->Save
, dispatchSize
);
1759 ctx
->CurrentDispatch
= ctx
->Exec
;
1761 ctx
->ExecPrefersFloat
= GL_FALSE
;
1762 ctx
->SavePrefersFloat
= GL_FALSE
;
1764 /* Neutral tnl module stuff */
1765 _mesa_init_exec_vtxfmt( ctx
);
1766 ctx
->TnlModule
.Current
= NULL
;
1767 ctx
->TnlModule
.SwapCount
= 0;
1769 /* Z buffer stuff */
1770 if (ctx
->Visual
.depthBits
== 0) {
1771 /* Special case. Even if we don't have a depth buffer we need
1772 * good values for DepthMax for Z vertex transformation purposes
1773 * and for per-fragment fog computation.
1775 ctx
->DepthMax
= 1 << 16;
1776 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1778 else if (ctx
->Visual
.depthBits
< 32) {
1779 ctx
->DepthMax
= (1 << ctx
->Visual
.depthBits
) - 1;
1780 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1783 /* Special case since shift values greater than or equal to the
1784 * number of bits in the left hand expression's type are undefined.
1786 ctx
->DepthMax
= 0xffffffff;
1787 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
1789 ctx
->MRD
= 1.0; /* Minimum resolvable depth value, for polygon offset */
1792 #if defined(MESA_TRACE)
1793 ctx
->TraceCtx
= (trace_context_t
*) CALLOC( sizeof(trace_context_t
) );
1795 /* Brian: do you want to have CreateContext fail here,
1796 or should we just trap in NewTrace (currently done)? */
1797 if (!(ctx
->TraceCtx
)) {
1798 free_shared_state(ctx
, ctx
->Shared
);
1804 trInitContext(ctx
->TraceCtx
);
1806 ctx
->TraceDispatch
= (struct _glapi_table
*)
1807 CALLOC(dispatchSize
* sizeof(void*));
1809 if (!(ctx
->TraceCtx
)) {
1810 free_shared_state(ctx
, ctx
->Shared
);
1813 FREE( ctx
->TraceCtx
);
1817 trInitDispatch(ctx
->TraceDispatch
);
1821 if (ctx
->imports
.getenv(ctx
, "MESA_DEBUG"))
1822 add_debug_flags(ctx
->imports
.getenv(ctx
, "MESA_DEBUG"));
1824 if (ctx
->imports
.getenv(ctx
, "MESA_VERBOSE"))
1825 add_debug_flags(ctx
->imports
.getenv(ctx
, "MESA_VERBOSE"));
1833 * Allocate and initialize a GLcontext structure.
1834 * Input: visual - a GLvisual pointer (we copy the struct contents)
1835 * sharelist - another context to share display lists with or NULL
1836 * imports - points to a fully-initialized __GLimports object.
1837 * Return: pointer to a new __GLcontextRec or NULL if error.
1840 _mesa_create_context( const GLvisual
*visual
,
1841 GLcontext
*share_list
,
1842 const __GLimports
*imports
)
1848 ASSERT(imports
->calloc
);
1850 ctx
= (GLcontext
*) imports
->calloc(NULL
, 1, sizeof(GLcontext
));
1854 ctx
->Driver
.CurrentExecPrimitive
= 0; /* XXX why is this here??? */
1856 if (_mesa_initialize_context(ctx
, visual
, share_list
, imports
)) {
1860 imports
->free(NULL
, ctx
);
1868 * Free the data associated with the given context.
1869 * But don't free() the GLcontext struct itself!
1872 _mesa_free_context_data( GLcontext
*ctx
)
1874 struct gl_shine_tab
*s
, *tmps
;
1877 /* if we're destroying the current context, unbind it first */
1878 if (ctx
== _mesa_get_current_context()) {
1879 _mesa_make_current(NULL
, NULL
);
1883 * Free transformation matrix stacks
1885 free_matrix_stack(&ctx
->ModelviewMatrixStack
);
1886 free_matrix_stack(&ctx
->ProjectionMatrixStack
);
1887 free_matrix_stack(&ctx
->ColorMatrixStack
);
1888 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
1889 free_matrix_stack(&ctx
->TextureMatrixStack
[i
]);
1890 for (i
= 0; i
< MAX_PROGRAM_MATRICES
; i
++)
1891 free_matrix_stack(&ctx
->ProgramMatrixStack
[i
]);
1892 /* combined Modelview*Projection matrix */
1893 _math_matrix_dtr( &ctx
->_ModelProjectMatrix
);
1896 if (ctx
->VertexProgram
.Current
) {
1897 ctx
->VertexProgram
.Current
->RefCount
--;
1898 if (ctx
->VertexProgram
.Current
->RefCount
<= 0)
1899 _mesa_delete_program(ctx
, ctx
->VertexProgram
.CurrentID
);
1902 /* Shared context state (display lists, textures, etc) */
1903 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1904 ctx
->Shared
->RefCount
--;
1905 assert(ctx
->Shared
->RefCount
>= 0);
1906 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1907 if (ctx
->Shared
->RefCount
== 0) {
1908 /* free shared state */
1909 free_shared_state( ctx
, ctx
->Shared
);
1912 /* Free lighting shininess exponentiation table */
1913 foreach_s( s
, tmps
, ctx
->_ShineTabList
) {
1916 FREE( ctx
->_ShineTabList
);
1918 /* Free proxy texture objects */
1919 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1920 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1921 _mesa_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1922 _mesa_free_texture_object( NULL
, ctx
->Texture
.ProxyCubeMap
);
1923 _mesa_free_texture_object( NULL
, ctx
->Texture
.ProxyRect
);
1925 /* Free evaluator data */
1926 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1927 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1928 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1929 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1930 if (ctx
->EvalMap
.Map1Index
.Points
)
1931 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1932 if (ctx
->EvalMap
.Map1Color4
.Points
)
1933 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1934 if (ctx
->EvalMap
.Map1Normal
.Points
)
1935 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1936 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1937 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1938 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1939 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1940 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1941 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1942 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1943 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1944 for (i
= 0; i
< 16; i
++)
1945 FREE((ctx
->EvalMap
.Map1Attrib
[i
].Points
));
1947 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1948 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1949 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1950 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1951 if (ctx
->EvalMap
.Map2Index
.Points
)
1952 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1953 if (ctx
->EvalMap
.Map2Color4
.Points
)
1954 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1955 if (ctx
->EvalMap
.Map2Normal
.Points
)
1956 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1957 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1958 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1959 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1960 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1961 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1962 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1963 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1964 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1965 for (i
= 0; i
< 16; i
++)
1966 FREE((ctx
->EvalMap
.Map2Attrib
[i
].Points
));
1968 _mesa_free_colortable_data( &ctx
->ColorTable
);
1969 _mesa_free_colortable_data( &ctx
->PostConvolutionColorTable
);
1970 _mesa_free_colortable_data( &ctx
->PostColorMatrixColorTable
);
1971 _mesa_free_colortable_data( &ctx
->Texture
.Palette
);
1973 _math_matrix_dtr(&ctx
->Viewport
._WindowMap
);
1975 _mesa_extensions_dtr(ctx
);
1984 * Destroy a GLcontext structure.
1987 _mesa_destroy_context( GLcontext
*ctx
)
1990 _mesa_free_context_data(ctx
);
1991 FREE( (void *) ctx
);
1998 * Copy attribute groups from one context to another.
1999 * Input: src - source context
2000 * dst - destination context
2001 * mask - bitwise OR of GL_*_BIT flags
2004 _mesa_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
2006 if (mask
& GL_ACCUM_BUFFER_BIT
) {
2008 dst
->Accum
= src
->Accum
;
2010 if (mask
& GL_COLOR_BUFFER_BIT
) {
2012 dst
->Color
= src
->Color
;
2014 if (mask
& GL_CURRENT_BIT
) {
2016 dst
->Current
= src
->Current
;
2018 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2020 dst
->Depth
= src
->Depth
;
2022 if (mask
& GL_ENABLE_BIT
) {
2025 if (mask
& GL_EVAL_BIT
) {
2027 dst
->Eval
= src
->Eval
;
2029 if (mask
& GL_FOG_BIT
) {
2031 dst
->Fog
= src
->Fog
;
2033 if (mask
& GL_HINT_BIT
) {
2035 dst
->Hint
= src
->Hint
;
2037 if (mask
& GL_LIGHTING_BIT
) {
2039 /* begin with memcpy */
2040 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light
) );
2041 /* fixup linked lists to prevent pointer insanity */
2042 make_empty_list( &(dst
->Light
.EnabledList
) );
2043 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
2044 if (dst
->Light
.Light
[i
].Enabled
) {
2045 insert_at_tail(&(dst
->Light
.EnabledList
), &(dst
->Light
.Light
[i
]));
2049 if (mask
& GL_LINE_BIT
) {
2051 dst
->Line
= src
->Line
;
2053 if (mask
& GL_LIST_BIT
) {
2055 dst
->List
= src
->List
;
2057 if (mask
& GL_PIXEL_MODE_BIT
) {
2059 dst
->Pixel
= src
->Pixel
;
2061 if (mask
& GL_POINT_BIT
) {
2063 dst
->Point
= src
->Point
;
2065 if (mask
& GL_POLYGON_BIT
) {
2067 dst
->Polygon
= src
->Polygon
;
2069 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
2070 /* Use loop instead of MEMCPY due to problem with Portland Group's
2071 * C compiler. Reported by John Stone.
2074 for (i
= 0; i
< 32; i
++) {
2075 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
2078 if (mask
& GL_SCISSOR_BIT
) {
2080 dst
->Scissor
= src
->Scissor
;
2082 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2084 dst
->Stencil
= src
->Stencil
;
2086 if (mask
& GL_TEXTURE_BIT
) {
2087 /* Cannot memcpy because of pointers */
2088 _mesa_copy_texture_state(src
, dst
);
2090 if (mask
& GL_TRANSFORM_BIT
) {
2092 dst
->Transform
= src
->Transform
;
2094 if (mask
& GL_VIEWPORT_BIT
) {
2095 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
2096 dst
->Viewport
.X
= src
->Viewport
.X
;
2097 dst
->Viewport
.Y
= src
->Viewport
.Y
;
2098 dst
->Viewport
.Width
= src
->Viewport
.Width
;
2099 dst
->Viewport
.Height
= src
->Viewport
.Height
;
2100 dst
->Viewport
.Near
= src
->Viewport
.Near
;
2101 dst
->Viewport
.Far
= src
->Viewport
.Far
;
2102 _math_matrix_copy(&dst
->Viewport
._WindowMap
, &src
->Viewport
._WindowMap
);
2105 /* XXX FIXME: Call callbacks?
2107 dst
->NewState
= _NEW_ALL
;
2112 static void print_info( void )
2114 _mesa_debug(NULL
, "Mesa GL_VERSION = %s\n",
2115 (char *) _mesa_GetString(GL_VERSION
));
2116 _mesa_debug(NULL
, "Mesa GL_RENDERER = %s\n",
2117 (char *) _mesa_GetString(GL_RENDERER
));
2118 _mesa_debug(NULL
, "Mesa GL_VENDOR = %s\n",
2119 (char *) _mesa_GetString(GL_VENDOR
));
2120 _mesa_debug(NULL
, "Mesa GL_EXTENSIONS = %s\n",
2121 (char *) _mesa_GetString(GL_EXTENSIONS
));
2122 #if defined(THREADS)
2123 _mesa_debug(NULL
, "Mesa thread-safe: YES\n");
2125 _mesa_debug(NULL
, "Mesa thread-safe: NO\n");
2127 #if defined(USE_X86_ASM)
2128 _mesa_debug(NULL
, "Mesa x86-optimized: YES\n");
2130 _mesa_debug(NULL
, "Mesa x86-optimized: NO\n");
2132 #if defined(USE_SPARC_ASM)
2133 _mesa_debug(NULL
, "Mesa sparc-optimized: YES\n");
2135 _mesa_debug(NULL
, "Mesa sparc-optimized: NO\n");
2141 * Set the current context, binding the given frame buffer to the context.
2144 _mesa_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
2146 _mesa_make_current2( newCtx
, buffer
, buffer
);
2151 * Bind the given context to the given draw-buffer and read-buffer
2152 * and make it the current context for this thread.
2155 _mesa_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
2156 GLframebuffer
*readBuffer
)
2159 _mesa_debug(newCtx
, "_mesa_make_current2()\n");
2161 /* Check that the context's and framebuffer's visuals are compatible.
2162 * We could do a lot more checking here but this'll catch obvious
2165 if (newCtx
&& drawBuffer
&& readBuffer
) {
2166 if (newCtx
->Visual
.rgbMode
!= drawBuffer
->Visual
.rgbMode
||
2167 newCtx
->Visual
.redBits
!= drawBuffer
->Visual
.redBits
||
2168 newCtx
->Visual
.depthBits
!= drawBuffer
->Visual
.depthBits
||
2169 newCtx
->Visual
.stencilBits
!= drawBuffer
->Visual
.stencilBits
||
2170 newCtx
->Visual
.accumRedBits
!= drawBuffer
->Visual
.accumRedBits
) {
2171 return; /* incompatible */
2175 /* We call this function periodically (just here for now) in
2176 * order to detect when multithreading has begun.
2178 _glapi_check_multithread();
2180 _glapi_set_context((void *) newCtx
);
2181 ASSERT(_mesa_get_current_context() == newCtx
);
2185 _glapi_set_dispatch(NULL
); /* none current */
2188 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
2190 if (drawBuffer
&& readBuffer
) {
2191 /* TODO: check if newCtx and buffer's visual match??? */
2192 newCtx
->DrawBuffer
= drawBuffer
;
2193 newCtx
->ReadBuffer
= readBuffer
;
2194 newCtx
->NewState
|= _NEW_BUFFERS
;
2196 if (drawBuffer
->Width
== 0 && drawBuffer
->Height
== 0) {
2197 /* get initial window size */
2198 GLuint bufWidth
, bufHeight
;
2200 /* ask device driver for size of output buffer */
2201 (*newCtx
->Driver
.GetBufferSize
)( drawBuffer
, &bufWidth
, &bufHeight
);
2203 if (drawBuffer
->Width
== bufWidth
&& drawBuffer
->Height
== bufHeight
)
2204 return; /* size is as expected */
2206 drawBuffer
->Width
= bufWidth
;
2207 drawBuffer
->Height
= bufHeight
;
2209 newCtx
->Driver
.ResizeBuffers( drawBuffer
);
2212 if (readBuffer
!= drawBuffer
&&
2213 readBuffer
->Width
== 0 && readBuffer
->Height
== 0) {
2214 /* get initial window size */
2215 GLuint bufWidth
, bufHeight
;
2217 /* ask device driver for size of output buffer */
2218 (*newCtx
->Driver
.GetBufferSize
)( readBuffer
, &bufWidth
, &bufHeight
);
2220 if (readBuffer
->Width
== bufWidth
&& readBuffer
->Height
== bufHeight
)
2221 return; /* size is as expected */
2223 readBuffer
->Width
= bufWidth
;
2224 readBuffer
->Height
= bufHeight
;
2226 newCtx
->Driver
.ResizeBuffers( readBuffer
);
2230 /* This is only for T&L - a bit out of place, or misnamed (BP) */
2231 if (newCtx
->Driver
.MakeCurrent
)
2232 newCtx
->Driver
.MakeCurrent( newCtx
, drawBuffer
, readBuffer
);
2234 /* We can use this to help debug user's problems. Tell them to set
2235 * the MESA_INFO env variable before running their app. Then the
2236 * first time each context is made current we'll print some useful
2239 if (newCtx
->FirstTimeCurrent
) {
2240 if (newCtx
->imports
.getenv(newCtx
, "MESA_INFO")) {
2243 newCtx
->FirstTimeCurrent
= GL_FALSE
;
2251 * Return current context handle for the calling thread.
2252 * This isn't the fastest way to get the current context.
2253 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
2256 _mesa_get_current_context( void )
2258 return (GLcontext
*) _glapi_get_context();
2264 * This should be called by device drivers just before they do a
2265 * swapbuffers. Any pending rendering commands will be executed.
2266 * XXX we should really rename this function to _mesa_flush() or something.
2269 _mesa_swapbuffers(GLcontext
*ctx
)
2271 FLUSH_VERTICES( ctx
, 0 );
2277 * Return pointer to this context's current API dispatch table.
2278 * It'll either be the immediate-mode execute dispatcher or the
2279 * display list compile dispatcher.
2281 struct _glapi_table
*
2282 _mesa_get_dispatch(GLcontext
*ctx
)
2284 return ctx
->CurrentDispatch
;
2289 /**********************************************************************/
2290 /***** Miscellaneous functions *****/
2291 /**********************************************************************/
2295 * Record the given error code and call the driver's Error function if defined.
2296 * This is called via _mesa_error().
2299 _mesa_record_error( GLcontext
*ctx
, GLenum error
)
2304 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
2305 ctx
->ErrorValue
= error
;
2308 /* Call device driver's error handler, if any. This is used on the Mac. */
2309 if (ctx
->Driver
.Error
) {
2310 (*ctx
->Driver
.Error
)( ctx
);
2316 _mesa_Finish( void )
2318 GET_CURRENT_CONTEXT(ctx
);
2319 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2320 if (ctx
->Driver
.Finish
) {
2321 (*ctx
->Driver
.Finish
)( ctx
);
2330 GET_CURRENT_CONTEXT(ctx
);
2331 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2332 if (ctx
->Driver
.Flush
) {
2333 (*ctx
->Driver
.Flush
)( ctx
);
2339 const char *_mesa_prim_name
[GL_POLYGON
+4] = {
2345 "GL_TRIANGLE_STRIP",
2350 "outside begin/end",
2351 "inside unkown primitive",