1 /* $Id: context.c,v 1.61 2000/04/22 01:05:00 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 #include "extensions.h"
46 #include "glapinoop.h"
57 #include "simple_list.h"
61 #include "translate.h"
78 /**********************************************************************/
79 /***** Context and Thread management *****/
80 /**********************************************************************/
85 struct immediate
*_mesa_CurrentInput
= NULL
;
90 /**********************************************************************/
91 /***** GL Visual allocation/destruction *****/
92 /**********************************************************************/
96 * Allocate a new GLvisual object.
97 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
98 * alphaFlag - alloc software alpha buffers?
99 * dbFlag - double buffering?
100 * stereoFlag - stereo buffer?
101 * depthBits - requested bits per depth buffer value
102 * Any value in [0, 32] is acceptable but the actual
103 * depth type will be GLushort or GLuint as needed.
104 * stencilBits - requested minimum bits per stencil buffer value
105 * accumBits - requested minimum bits per accum buffer component
106 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
107 * red/green/blue/alphaBits - number of bits per color component
108 * in frame buffer for RGB(A) mode.
109 * We always use 8 in core Mesa though.
110 * Return: pointer to new GLvisual or NULL if requested parameters can't
114 _mesa_create_visual( GLboolean rgbFlag
,
117 GLboolean stereoFlag
,
126 GLint accumGreenBits
,
128 GLint accumAlphaBits
,
131 GLvisual
*vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
133 if (!_mesa_initialize_visual(vis
, rgbFlag
, alphaFlag
, dbFlag
, stereoFlag
,
134 redBits
, greenBits
, blueBits
, alphaBits
,
135 indexBits
, depthBits
, stencilBits
,
136 accumRedBits
, accumGreenBits
,
137 accumBlueBits
, accumAlphaBits
,
148 * Initialize the fields of the given GLvisual.
149 * Input: see _mesa_create_visual() above.
150 * Return: GL_TRUE = success
151 * GL_FALSE = failure.
154 _mesa_initialize_visual( GLvisual
*vis
,
158 GLboolean stereoFlag
,
167 GLint accumGreenBits
,
169 GLint accumAlphaBits
,
174 /* This is to catch bad values from device drivers not updated for
175 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
176 * bad value now (a 1-bit depth buffer!?!).
178 assert(depthBits
== 0 || depthBits
> 1);
180 if (depthBits
< 0 || depthBits
> 32) {
183 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
186 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
189 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
192 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
195 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
199 vis
->RGBAflag
= rgbFlag
;
200 vis
->DBflag
= dbFlag
;
201 vis
->StereoFlag
= stereoFlag
;
202 vis
->RedBits
= redBits
;
203 vis
->GreenBits
= greenBits
;
204 vis
->BlueBits
= blueBits
;
205 vis
->AlphaBits
= alphaFlag
? (8 * sizeof(GLubyte
)) : alphaBits
;
207 vis
->IndexBits
= indexBits
;
208 vis
->DepthBits
= depthBits
;
209 vis
->AccumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
210 vis
->AccumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
211 vis
->AccumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
212 vis
->AccumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
213 vis
->StencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
215 vis
->SoftwareAlpha
= alphaFlag
;
217 if (depthBits
== 0) {
218 /* Special case. Even if we don't have a depth buffer we need
219 * good values for DepthMax for Z vertex transformation purposes.
222 vis
->DepthMaxF
= 1.0F
;
225 vis
->DepthMax
= (1 << depthBits
) - 1;
226 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
233 /* This function should no longer be used. Use _mesa_create_visual() instead */
235 gl_create_visual( GLboolean rgbFlag
,
238 GLboolean stereoFlag
,
248 return _mesa_create_visual(rgbFlag
, alphaFlag
, dbFlag
, stereoFlag
,
249 redBits
, greenBits
, blueBits
, alphaBits
,
250 indexBits
, depthBits
, stencilBits
,
251 accumBits
, accumBits
, accumBits
, accumBits
, 0);
256 _mesa_destroy_visual( GLvisual
*vis
)
264 gl_destroy_visual( GLvisual
*vis
)
266 _mesa_destroy_visual(vis
);
271 /**********************************************************************/
272 /***** GL Framebuffer allocation/destruction *****/
273 /**********************************************************************/
277 * Create a new framebuffer. A GLframebuffer is a struct which
278 * encapsulates the depth, stencil and accum buffers and related
280 * Input: visual - a GLvisual pointer
281 * softwareDepth - create/use a software depth buffer?
282 * softwareStencil - create/use a software stencil buffer?
283 * softwareAccum - create/use a software accum buffer?
284 * softwareAlpha - create/use a software alpha buffer?
286 * Return: pointer to new GLframebuffer struct or NULL if error.
289 gl_create_framebuffer( GLvisual
*visual
,
290 GLboolean softwareDepth
,
291 GLboolean softwareStencil
,
292 GLboolean softwareAccum
,
293 GLboolean softwareAlpha
)
295 GLframebuffer
*buffer
= CALLOC_STRUCT(gl_frame_buffer
);
298 _mesa_initialize_framebuffer(buffer
, visual
,
299 softwareDepth
, softwareStencil
,
300 softwareAccum
, softwareAlpha
);
307 * Initialize a GLframebuffer object.
308 * Input: See gl_create_framebuffer() above.
311 _mesa_initialize_framebuffer( GLframebuffer
*buffer
,
313 GLboolean softwareDepth
,
314 GLboolean softwareStencil
,
315 GLboolean softwareAccum
,
316 GLboolean softwareAlpha
)
322 if (softwareDepth
) {
323 assert(visual
->DepthBits
> 0);
325 if (softwareStencil
) {
326 assert(visual
->StencilBits
> 0);
329 assert(visual
->RGBAflag
);
330 assert(visual
->AccumRedBits
> 0);
331 assert(visual
->AccumGreenBits
> 0);
332 assert(visual
->AccumBlueBits
> 0);
335 assert(visual
->RGBAflag
);
336 assert(visual
->AlphaBits
> 0);
339 buffer
->Visual
= visual
;
340 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
341 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
342 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
343 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
348 * Free a framebuffer struct and its buffers.
351 gl_destroy_framebuffer( GLframebuffer
*buffer
)
354 if (buffer
->DepthBuffer
) {
355 FREE( buffer
->DepthBuffer
);
358 FREE( buffer
->Accum
);
360 if (buffer
->Stencil
) {
361 FREE( buffer
->Stencil
);
363 if (buffer
->FrontLeftAlpha
) {
364 FREE( buffer
->FrontLeftAlpha
);
366 if (buffer
->BackLeftAlpha
) {
367 FREE( buffer
->BackLeftAlpha
);
369 if (buffer
->FrontRightAlpha
) {
370 FREE( buffer
->FrontRightAlpha
);
372 if (buffer
->BackRightAlpha
) {
373 FREE( buffer
->BackRightAlpha
);
381 /**********************************************************************/
382 /***** Context allocation, initialization, destroying *****/
383 /**********************************************************************/
386 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
390 * This function just calls all the various one-time-init functions in Mesa.
393 one_time_init( void )
395 static GLboolean alreadyCalled
= GL_FALSE
;
396 _glthread_LOCK_MUTEX(OneTimeLock
);
397 if (!alreadyCalled
) {
398 /* do some implementation tests */
399 assert( sizeof(GLbyte
) == 1 );
400 assert( sizeof(GLshort
) >= 2 );
401 assert( sizeof(GLint
) >= 4 );
402 assert( sizeof(GLubyte
) == 1 );
403 assert( sizeof(GLushort
) >= 2 );
404 assert( sizeof(GLuint
) >= 4 );
413 gl_init_transformation();
419 if (getenv("MESA_DEBUG")) {
420 _glapi_noop_enable_warnings(GL_TRUE
);
423 _glapi_noop_enable_warnings(GL_FALSE
);
426 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
427 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
430 alreadyCalled
= GL_TRUE
;
432 _glthread_UNLOCK_MUTEX(OneTimeLock
);
438 * Allocate and initialize a shared context state structure.
440 static struct gl_shared_state
*
441 alloc_shared_state( void )
444 struct gl_shared_state
*ss
;
445 GLboolean outOfMemory
;
447 ss
= CALLOC_STRUCT(gl_shared_state
);
451 ss
->DisplayList
= _mesa_NewHashTable();
453 ss
->TexObjects
= _mesa_NewHashTable();
455 /* Default Texture objects */
456 outOfMemory
= GL_FALSE
;
457 for (d
= 1 ; d
<= 3 ; d
++) {
458 ss
->DefaultD
[d
] = gl_alloc_texture_object(ss
, 0, d
);
459 if (!ss
->DefaultD
[d
]) {
460 outOfMemory
= GL_TRUE
;
463 ss
->DefaultD
[d
]->RefCount
++; /* don't free if not in use */
466 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
467 /* Ran out of memory at some point. Free everything and return NULL */
469 _mesa_DeleteHashTable(ss
->DisplayList
);
471 _mesa_DeleteHashTable(ss
->TexObjects
);
473 gl_free_texture_object(ss
, ss
->DefaultD
[1]);
475 gl_free_texture_object(ss
, ss
->DefaultD
[2]);
477 gl_free_texture_object(ss
, ss
->DefaultD
[3]);
488 * Deallocate a shared state context and all children structures.
491 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
493 /* Free display lists */
495 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
497 gl_destroy_list(ctx
, list
);
503 _mesa_DeleteHashTable(ss
->DisplayList
);
505 /* Free texture objects */
506 while (ss
->TexObjectList
)
508 if (ctx
->Driver
.DeleteTexture
)
509 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
510 /* this function removes from linked list too! */
511 gl_free_texture_object(ss
, ss
->TexObjectList
);
513 _mesa_DeleteHashTable(ss
->TexObjects
);
521 * Initialize the nth light. Note that the defaults for light 0 are
522 * different than the other lights.
525 init_light( struct gl_light
*l
, GLuint n
)
527 make_empty_list( l
);
529 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
531 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
532 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
535 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
536 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
538 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
539 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
540 l
->SpotExponent
= 0.0;
541 gl_compute_spot_exp_table( l
);
542 l
->SpotCutoff
= 180.0;
543 l
->CosCutoff
= 0.0; /* KW: -ve values not admitted */
544 l
->ConstantAttenuation
= 1.0;
545 l
->LinearAttenuation
= 0.0;
546 l
->QuadraticAttenuation
= 0.0;
547 l
->Enabled
= GL_FALSE
;
553 init_lightmodel( struct gl_lightmodel
*lm
)
555 ASSIGN_4V( lm
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
556 lm
->LocalViewer
= GL_FALSE
;
557 lm
->TwoSide
= GL_FALSE
;
558 lm
->ColorControl
= GL_SINGLE_COLOR
;
563 init_material( struct gl_material
*m
)
565 ASSIGN_4V( m
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
566 ASSIGN_4V( m
->Diffuse
, 0.8, 0.8, 0.8, 1.0 );
567 ASSIGN_4V( m
->Specular
, 0.0, 0.0, 0.0, 1.0 );
568 ASSIGN_4V( m
->Emission
, 0.0, 0.0, 0.0, 1.0 );
572 m
->SpecularIndex
= 1;
578 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
580 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
582 texUnit
->EnvMode
= GL_MODULATE
;
583 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
584 texUnit
->TexGenEnabled
= 0;
585 texUnit
->GenModeS
= GL_EYE_LINEAR
;
586 texUnit
->GenModeT
= GL_EYE_LINEAR
;
587 texUnit
->GenModeR
= GL_EYE_LINEAR
;
588 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
589 /* Yes, these plane coefficients are correct! */
590 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
591 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
592 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
593 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
594 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
595 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
596 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
597 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
599 texUnit
->CurrentD
[1] = ctx
->Shared
->DefaultD
[1];
600 texUnit
->CurrentD
[2] = ctx
->Shared
->DefaultD
[2];
601 texUnit
->CurrentD
[3] = ctx
->Shared
->DefaultD
[3];
606 init_fallback_arrays( GLcontext
*ctx
)
608 struct gl_client_array
*cl
;
611 cl
= &ctx
->Fallback
.Normal
;
616 cl
->Ptr
= (void *) ctx
->Current
.Normal
;
619 cl
= &ctx
->Fallback
.Color
;
621 cl
->Type
= GL_UNSIGNED_BYTE
;
624 cl
->Ptr
= (void *) ctx
->Current
.ByteColor
;
627 cl
= &ctx
->Fallback
.Index
;
629 cl
->Type
= GL_UNSIGNED_INT
;
632 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
635 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
636 cl
= &ctx
->Fallback
.TexCoord
[i
];
641 cl
->Ptr
= (void *) ctx
->Current
.Texcoord
[i
];
645 cl
= &ctx
->Fallback
.EdgeFlag
;
647 cl
->Type
= GL_UNSIGNED_BYTE
;
650 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
655 /* Initialize a 1-D evaluator map */
657 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
662 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
666 map
->Points
[i
] = initial
[i
];
671 /* Initialize a 2-D evaluator map */
673 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
681 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
685 map
->Points
[i
] = initial
[i
];
691 * Initialize the attribute groups in a GLcontext.
694 init_attrib_groups( GLcontext
*ctx
)
700 /* Constants, may be overriden by device drivers */
701 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
702 ctx
->Const
.MaxTextureSize
= 1 << (MAX_TEXTURE_LEVELS
- 1);
703 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
704 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
705 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
706 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
707 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
708 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
709 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
710 ctx
->Const
.PointSizeGranularity
= POINT_SIZE_GRANULARITY
;
711 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
712 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
713 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
714 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
715 ctx
->Const
.LineWidthGranularity
= LINE_WIDTH_GRANULARITY
;
716 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
717 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
719 /* Modelview matrix */
720 gl_matrix_ctr( &ctx
->ModelView
);
721 gl_matrix_alloc_inv( &ctx
->ModelView
);
723 ctx
->ModelViewStackDepth
= 0;
724 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
725 gl_matrix_ctr( &ctx
->ModelViewStack
[i
] );
726 gl_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
729 /* Projection matrix - need inv for user clipping in clip space*/
730 gl_matrix_ctr( &ctx
->ProjectionMatrix
);
731 gl_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
733 gl_matrix_ctr( &ctx
->ModelProjectMatrix
);
734 gl_matrix_ctr( &ctx
->ModelProjectWinMatrix
);
735 ctx
->ModelProjectWinMatrixUptodate
= GL_FALSE
;
737 ctx
->ProjectionStackDepth
= 0;
738 ctx
->NearFarStack
[0][0] = 1.0; /* These values seem weird by make */
739 ctx
->NearFarStack
[0][1] = 0.0; /* sense mathematically. */
741 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
742 gl_matrix_ctr( &ctx
->ProjectionStack
[i
] );
743 gl_matrix_alloc_inv( &ctx
->ProjectionStack
[i
] );
747 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
748 gl_matrix_ctr( &ctx
->TextureMatrix
[i
] );
749 ctx
->TextureStackDepth
[i
] = 0;
750 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
751 ctx
->TextureStack
[i
][j
].inv
= 0;
756 gl_matrix_ctr(&ctx
->ColorMatrix
);
757 ctx
->ColorStackDepth
= 0;
758 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
759 gl_matrix_ctr(&ctx
->ColorStack
[j
]);
762 /* Accumulate buffer group */
763 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
765 /* Color buffer group */
766 ctx
->Color
.IndexMask
= 0xffffffff;
767 ctx
->Color
.ColorMask
[0] = 0xff;
768 ctx
->Color
.ColorMask
[1] = 0xff;
769 ctx
->Color
.ColorMask
[2] = 0xff;
770 ctx
->Color
.ColorMask
[3] = 0xff;
771 ctx
->Color
.SWmasking
= GL_FALSE
;
772 ctx
->Color
.ClearIndex
= 0;
773 ASSIGN_4V( ctx
->Color
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
774 ctx
->Color
.DrawBuffer
= GL_FRONT
;
775 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
776 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
777 ctx
->Color
.AlphaRef
= 0;
778 ctx
->Color
.BlendEnabled
= GL_FALSE
;
779 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
780 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
781 ctx
->Color
.BlendSrcA
= GL_ONE
;
782 ctx
->Color
.BlendDstA
= GL_ZERO
;
783 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
784 ctx
->Color
.BlendFunc
= NULL
; /* this pointer set only when needed */
785 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
786 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
787 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
788 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
789 ctx
->Color
.LogicOp
= GL_COPY
;
790 ctx
->Color
.DitherFlag
= GL_TRUE
;
791 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
794 ASSIGN_4V( ctx
->Current
.ByteColor
, 255, 255, 255, 255);
795 ctx
->Current
.Index
= 1;
796 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
797 ASSIGN_4V( ctx
->Current
.Texcoord
[i
], 0.0, 0.0, 0.0, 1.0 );
798 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
799 ctx
->Current
.RasterDistance
= 0.0;
800 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
801 ctx
->Current
.RasterIndex
= 1;
802 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
803 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
804 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
805 ctx
->Current
.RasterPosValid
= GL_TRUE
;
806 ctx
->Current
.EdgeFlag
= GL_TRUE
;
807 ASSIGN_3V( ctx
->Current
.Normal
, 0.0, 0.0, 1.0 );
808 ctx
->Current
.Primitive
= (GLenum
) (GL_POLYGON
+ 1);
810 ctx
->Current
.Flag
= (VERT_NORM
|VERT_INDEX
|VERT_RGBA
|VERT_EDGE
|
811 VERT_TEX0_1
|VERT_TEX1_1
|VERT_MATERIAL
);
813 init_fallback_arrays( ctx
);
815 /* Depth buffer group */
816 ctx
->Depth
.Test
= GL_FALSE
;
817 ctx
->Depth
.Clear
= 1.0;
818 ctx
->Depth
.Func
= GL_LESS
;
819 ctx
->Depth
.Mask
= GL_TRUE
;
820 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
822 /* Evaluators group */
823 ctx
->Eval
.Map1Color4
= GL_FALSE
;
824 ctx
->Eval
.Map1Index
= GL_FALSE
;
825 ctx
->Eval
.Map1Normal
= GL_FALSE
;
826 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
827 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
828 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
829 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
830 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
831 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
832 ctx
->Eval
.Map2Color4
= GL_FALSE
;
833 ctx
->Eval
.Map2Index
= GL_FALSE
;
834 ctx
->Eval
.Map2Normal
= GL_FALSE
;
835 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
836 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
837 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
838 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
839 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
840 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
841 ctx
->Eval
.AutoNormal
= GL_FALSE
;
842 ctx
->Eval
.MapGrid1un
= 1;
843 ctx
->Eval
.MapGrid1u1
= 0.0;
844 ctx
->Eval
.MapGrid1u2
= 1.0;
845 ctx
->Eval
.MapGrid2un
= 1;
846 ctx
->Eval
.MapGrid2vn
= 1;
847 ctx
->Eval
.MapGrid2u1
= 0.0;
848 ctx
->Eval
.MapGrid2u2
= 1.0;
849 ctx
->Eval
.MapGrid2v1
= 0.0;
850 ctx
->Eval
.MapGrid2v2
= 1.0;
854 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
855 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
856 static GLfloat index
[1] = { 1.0 };
857 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
858 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
860 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
861 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
862 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
863 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
864 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
865 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
866 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
867 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
868 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
870 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
871 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
872 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
873 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
874 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
875 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
876 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
877 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
878 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
882 ctx
->Fog
.Enabled
= GL_FALSE
;
883 ctx
->Fog
.Mode
= GL_EXP
;
884 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
885 ctx
->Fog
.Index
= 0.0;
886 ctx
->Fog
.Density
= 1.0;
887 ctx
->Fog
.Start
= 0.0;
891 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
892 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
893 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
894 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
895 ctx
->Hint
.Fog
= GL_DONT_CARE
;
897 ctx
->Hint
.AllowDrawWin
= GL_TRUE
;
898 ctx
->Hint
.AllowDrawFrg
= GL_TRUE
;
899 ctx
->Hint
.AllowDrawMem
= GL_TRUE
;
900 ctx
->Hint
.StrictLighting
= GL_TRUE
;
902 /* Histogram group */
903 ctx
->Histogram
.Width
= 0;
904 ctx
->Histogram
.Format
= GL_RGBA
;
905 ctx
->Histogram
.Sink
= GL_FALSE
;
906 ctx
->Histogram
.RedSize
= 0xffffffff;
907 ctx
->Histogram
.GreenSize
= 0xffffffff;
908 ctx
->Histogram
.BlueSize
= 0xffffffff;
909 ctx
->Histogram
.AlphaSize
= 0xffffffff;
910 ctx
->Histogram
.LuminanceSize
= 0xffffffff;
911 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
912 ctx
->Histogram
.Count
[i
][0] = 0;
913 ctx
->Histogram
.Count
[i
][1] = 0;
914 ctx
->Histogram
.Count
[i
][2] = 0;
915 ctx
->Histogram
.Count
[i
][3] = 0;
919 ctx
->MinMax
.Format
= GL_RGBA
;
920 ctx
->MinMax
.Sink
= GL_FALSE
;
921 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
922 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
923 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
924 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
929 gl_pipeline_init( ctx
);
933 gl_extensions_ctr( ctx
);
935 ctx
->AllowVertexCull
= CLIP_CULLED_BIT
;
938 for (i
=0;i
<MAX_LIGHTS
;i
++) {
939 init_light( &ctx
->Light
.Light
[i
], i
);
941 make_empty_list( &ctx
->Light
.EnabledList
);
943 init_lightmodel( &ctx
->Light
.Model
);
944 init_material( &ctx
->Light
.Material
[0] );
945 init_material( &ctx
->Light
.Material
[1] );
946 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
947 ctx
->Light
.Enabled
= GL_FALSE
;
948 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
949 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
950 ctx
->Light
.ColorMaterialBitmask
951 = gl_material_bitmask( ctx
,
953 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
955 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
957 /* Lighting miscellaneous */
958 ctx
->ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
959 make_empty_list( ctx
->ShineTabList
);
960 for (i
= 0 ; i
< 10 ; i
++) {
961 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
964 insert_at_tail( ctx
->ShineTabList
, s
);
966 for (i
= 0 ; i
< 4 ; i
++) {
967 ctx
->ShineTable
[i
] = ctx
->ShineTabList
->prev
;
968 ctx
->ShineTable
[i
]->refcount
++;
973 ctx
->Line
.SmoothFlag
= GL_FALSE
;
974 ctx
->Line
.StippleFlag
= GL_FALSE
;
975 ctx
->Line
.Width
= 1.0;
976 ctx
->Line
.StipplePattern
= 0xffff;
977 ctx
->Line
.StippleFactor
= 1;
979 /* Display List group */
980 ctx
->List
.ListBase
= 0;
983 ctx
->Pixel
.RedBias
= 0.0;
984 ctx
->Pixel
.RedScale
= 1.0;
985 ctx
->Pixel
.GreenBias
= 0.0;
986 ctx
->Pixel
.GreenScale
= 1.0;
987 ctx
->Pixel
.BlueBias
= 0.0;
988 ctx
->Pixel
.BlueScale
= 1.0;
989 ctx
->Pixel
.AlphaBias
= 0.0;
990 ctx
->Pixel
.AlphaScale
= 1.0;
991 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_FALSE
;
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 ctx
->Pixel
.PostColorMatrixRedBias
= 0.0;
1030 ctx
->Pixel
.PostColorMatrixRedScale
= 1.0;
1031 ctx
->Pixel
.PostColorMatrixGreenBias
= 0.0;
1032 ctx
->Pixel
.PostColorMatrixGreenScale
= 1.0;
1033 ctx
->Pixel
.PostColorMatrixBlueBias
= 0.0;
1034 ctx
->Pixel
.PostColorMatrixBlueScale
= 1.0;
1035 ctx
->Pixel
.PostColorMatrixAlphaBias
= 0.0;
1036 ctx
->Pixel
.PostColorMatrixAlphaScale
= 1.0;
1037 ctx
->Pixel
.ColorTableScale
[0] = 1.0F
;
1038 ctx
->Pixel
.ColorTableScale
[1] = 1.0F
;
1039 ctx
->Pixel
.ColorTableScale
[2] = 1.0F
;
1040 ctx
->Pixel
.ColorTableScale
[3] = 1.0F
;
1041 ctx
->Pixel
.ColorTableBias
[0] = 0.0F
;
1042 ctx
->Pixel
.ColorTableBias
[1] = 0.0F
;
1043 ctx
->Pixel
.ColorTableBias
[2] = 0.0F
;
1044 ctx
->Pixel
.ColorTableBias
[3] = 0.0F
;
1045 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1046 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1047 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1050 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1051 ctx
->Point
.Size
= 1.0;
1052 ctx
->Point
.Params
[0] = 1.0;
1053 ctx
->Point
.Params
[1] = 0.0;
1054 ctx
->Point
.Params
[2] = 0.0;
1055 ctx
->Point
.Attenuated
= GL_FALSE
;
1056 ctx
->Point
.MinSize
= 0.0;
1057 ctx
->Point
.MaxSize
= (GLfloat
) MAX_POINT_SIZE
;
1058 ctx
->Point
.Threshold
= 1.0;
1061 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1062 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1063 ctx
->Polygon
.FrontFace
= GL_CCW
;
1064 ctx
->Polygon
.FrontBit
= 0;
1065 ctx
->Polygon
.FrontMode
= GL_FILL
;
1066 ctx
->Polygon
.BackMode
= GL_FILL
;
1067 ctx
->Polygon
.Unfilled
= GL_FALSE
;
1068 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1069 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1070 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1071 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1072 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1073 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1074 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1076 /* Polygon Stipple group */
1077 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1080 ctx
->Scissor
.Enabled
= GL_FALSE
;
1083 ctx
->Scissor
.Width
= 0;
1084 ctx
->Scissor
.Height
= 0;
1087 ctx
->Stencil
.Enabled
= GL_FALSE
;
1088 ctx
->Stencil
.Function
= GL_ALWAYS
;
1089 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1090 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1091 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1092 ctx
->Stencil
.Ref
= 0;
1093 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1094 ctx
->Stencil
.Clear
= 0;
1095 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1098 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1099 ctx
->Texture
.CurrentTransformUnit
= 0; /* multitexture */
1100 ctx
->Texture
.Enabled
= 0;
1101 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1102 init_texture_unit( ctx
, i
);
1103 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1105 /* Transformation group */
1106 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1107 ctx
->Transform
.Normalize
= GL_FALSE
;
1108 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1109 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1110 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1111 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1113 ctx
->Transform
.AnyClip
= GL_FALSE
;
1115 /* Viewport group */
1116 ctx
->Viewport
.X
= 0;
1117 ctx
->Viewport
.Y
= 0;
1118 ctx
->Viewport
.Width
= 0;
1119 ctx
->Viewport
.Height
= 0;
1120 ctx
->Viewport
.Near
= 0.0;
1121 ctx
->Viewport
.Far
= 1.0;
1122 gl_matrix_ctr(&ctx
->Viewport
.WindowMap
);
1126 ctx
->Viewport
.WindowMap
.m
[Sz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1127 ctx
->Viewport
.WindowMap
.m
[Tz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1131 ctx
->Viewport
.WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1132 ctx
->Viewport
.WindowMap
.type
= MATRIX_3D_NO_ROT
;
1135 ctx
->Array
.Vertex
.Size
= 4;
1136 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1137 ctx
->Array
.Vertex
.Stride
= 0;
1138 ctx
->Array
.Vertex
.StrideB
= 0;
1139 ctx
->Array
.Vertex
.Ptr
= NULL
;
1140 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1141 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1142 ctx
->Array
.Normal
.Stride
= 0;
1143 ctx
->Array
.Normal
.StrideB
= 0;
1144 ctx
->Array
.Normal
.Ptr
= NULL
;
1145 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1146 ctx
->Array
.Color
.Size
= 4;
1147 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1148 ctx
->Array
.Color
.Stride
= 0;
1149 ctx
->Array
.Color
.StrideB
= 0;
1150 ctx
->Array
.Color
.Ptr
= NULL
;
1151 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1152 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1153 ctx
->Array
.Index
.Stride
= 0;
1154 ctx
->Array
.Index
.StrideB
= 0;
1155 ctx
->Array
.Index
.Ptr
= NULL
;
1156 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1157 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1158 ctx
->Array
.TexCoord
[i
].Size
= 4;
1159 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1160 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1161 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1162 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1163 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1165 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1166 ctx
->Array
.EdgeFlag
.Stride
= 0;
1167 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1168 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1169 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1170 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1172 /* Pixel transfer */
1173 ctx
->Pack
.Alignment
= 4;
1174 ctx
->Pack
.RowLength
= 0;
1175 ctx
->Pack
.ImageHeight
= 0;
1176 ctx
->Pack
.SkipPixels
= 0;
1177 ctx
->Pack
.SkipRows
= 0;
1178 ctx
->Pack
.SkipImages
= 0;
1179 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1180 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1181 ctx
->Unpack
.Alignment
= 4;
1182 ctx
->Unpack
.RowLength
= 0;
1183 ctx
->Unpack
.ImageHeight
= 0;
1184 ctx
->Unpack
.SkipPixels
= 0;
1185 ctx
->Unpack
.SkipRows
= 0;
1186 ctx
->Unpack
.SkipImages
= 0;
1187 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1188 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1191 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1192 ctx
->Feedback
.Buffer
= NULL
;
1193 ctx
->Feedback
.BufferSize
= 0;
1194 ctx
->Feedback
.Count
= 0;
1196 /* Selection/picking */
1197 ctx
->Select
.Buffer
= NULL
;
1198 ctx
->Select
.BufferSize
= 0;
1199 ctx
->Select
.BufferCount
= 0;
1200 ctx
->Select
.Hits
= 0;
1201 ctx
->Select
.NameStackDepth
= 0;
1203 /* Optimized Accum buffer */
1204 ctx
->IntegerAccumMode
= GL_TRUE
;
1205 ctx
->IntegerAccumScaler
= 0.0;
1207 /* Renderer and client attribute stacks */
1208 ctx
->AttribStackDepth
= 0;
1209 ctx
->ClientAttribStackDepth
= 0;
1213 ctx
->ExecuteFlag
= GL_TRUE
;
1214 ctx
->CompileFlag
= GL_FALSE
;
1215 ctx
->CurrentListPtr
= NULL
;
1216 ctx
->CurrentBlock
= NULL
;
1217 ctx
->CurrentListNum
= 0;
1218 ctx
->CurrentPos
= 0;
1221 _mesa_init_colortable(&ctx
->ColorTable
);
1222 _mesa_init_colortable(&ctx
->ProxyColorTable
);
1223 _mesa_init_colortable(&ctx
->PostConvolutionColorTable
);
1224 _mesa_init_colortable(&ctx
->ProxyPostConvolutionColorTable
);
1225 _mesa_init_colortable(&ctx
->PostColorMatrixColorTable
);
1226 _mesa_init_colortable(&ctx
->ProxyPostColorMatrixColorTable
);
1229 ctx
->NewState
= NEW_ALL
;
1230 ctx
->RenderMode
= GL_RENDER
;
1231 ctx
->StippleCounter
= 0;
1232 ctx
->NeedNormals
= GL_FALSE
;
1233 ctx
->DoViewportMapping
= GL_TRUE
;
1235 ctx
->NeedEyeCoords
= GL_FALSE
;
1236 ctx
->NeedEyeNormals
= GL_FALSE
;
1237 ctx
->vb_proj_matrix
= &ctx
->ModelProjectMatrix
;
1239 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1241 ctx
->CatchSignals
= GL_TRUE
;
1242 ctx
->OcclusionResult
= GL_FALSE
;
1243 ctx
->OcclusionResultSaved
= GL_FALSE
;
1245 /* For debug/development only */
1246 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1247 ctx
->FirstTimeCurrent
= GL_TRUE
;
1249 /* Dither disable */
1250 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1251 if (ctx
->NoDither
) {
1252 if (getenv("MESA_DEBUG")) {
1253 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1255 ctx
->Color
.DitherFlag
= GL_FALSE
;
1263 * Allocate the proxy textures. If we run out of memory part way through
1264 * the allocations clean up and return GL_FALSE.
1265 * Return: GL_TRUE=success, GL_FALSE=failure
1268 alloc_proxy_textures( GLcontext
*ctx
)
1270 GLboolean out_of_memory
;
1273 ctx
->Texture
.Proxy1D
= gl_alloc_texture_object(NULL
, 0, 1);
1274 if (!ctx
->Texture
.Proxy1D
) {
1278 ctx
->Texture
.Proxy2D
= gl_alloc_texture_object(NULL
, 0, 2);
1279 if (!ctx
->Texture
.Proxy2D
) {
1280 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1284 ctx
->Texture
.Proxy3D
= gl_alloc_texture_object(NULL
, 0, 3);
1285 if (!ctx
->Texture
.Proxy3D
) {
1286 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1287 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1291 out_of_memory
= GL_FALSE
;
1292 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1293 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1294 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1295 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1296 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1297 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1298 || !ctx
->Texture
.Proxy3D
->Image
[i
]) {
1299 out_of_memory
= GL_TRUE
;
1302 if (out_of_memory
) {
1303 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1304 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1305 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1307 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1308 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1310 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1311 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1314 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1315 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1316 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1327 * Initialize a GLcontext struct.
1330 _mesa_initialize_context( GLcontext
*ctx
,
1332 GLcontext
*share_list
,
1336 (void) direct
; /* not used */
1338 /* misc one-time initializations */
1341 ctx
->DriverCtx
= driver_ctx
;
1342 ctx
->Visual
= visual
;
1343 ctx
->DrawBuffer
= NULL
;
1344 ctx
->ReadBuffer
= NULL
;
1346 ctx
->VB
= gl_vb_create_for_immediate( ctx
);
1351 ctx
->input
= ctx
->VB
->IM
;
1353 ctx
->PB
= gl_alloc_pb();
1361 /* share the group of display lists of another context */
1362 ctx
->Shared
= share_list
->Shared
;
1365 /* allocate new group of display lists */
1366 ctx
->Shared
= alloc_shared_state();
1374 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1375 ctx
->Shared
->RefCount
++;
1376 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1378 init_attrib_groups( ctx
);
1380 gl_reset_vb( ctx
->VB
);
1381 gl_reset_input( ctx
);
1383 if (visual
->DBflag
) {
1384 ctx
->Color
.DrawBuffer
= GL_BACK
;
1385 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1386 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1387 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1388 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1391 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1392 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1393 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1394 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1395 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1398 if (!alloc_proxy_textures(ctx
)) {
1399 free_shared_state(ctx
, ctx
->Shared
);
1406 /* setup API dispatch tables */
1407 ctx
->Exec
= (struct _glapi_table
*) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1408 ctx
->Save
= (struct _glapi_table
*) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1409 if (!ctx
->Exec
|| !ctx
->Save
) {
1410 free_shared_state(ctx
, ctx
->Shared
);
1417 _mesa_init_exec_table( ctx
->Exec
);
1418 _mesa_init_dlist_table( ctx
->Save
);
1419 ctx
->CurrentDispatch
= ctx
->Exec
;
1427 * Allocate and initialize a GLcontext structure.
1428 * Input: visual - a GLvisual pointer
1429 * sharelist - another context to share display lists with or NULL
1430 * driver_ctx - pointer to device driver's context state struct
1431 * Return: pointer to a new gl_context struct or NULL if error.
1434 gl_create_context( GLvisual
*visual
,
1435 GLcontext
*share_list
,
1439 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1444 if (_mesa_initialize_context(ctx
, visual
, share_list
, driver_ctx
, direct
)) {
1456 * Free the data associated with the given context.
1457 * But don't free() the GLcontext struct itself!
1460 gl_free_context_data( GLcontext
*ctx
)
1462 struct gl_shine_tab
*s
, *tmps
;
1465 /* if we're destroying the current context, unbind it first */
1466 if (ctx
== gl_get_current_context()) {
1467 gl_make_current(NULL
, NULL
);
1470 gl_matrix_dtr( &ctx
->ModelView
);
1471 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
1472 gl_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1474 gl_matrix_dtr( &ctx
->ProjectionMatrix
);
1475 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
1476 gl_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1478 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1479 gl_matrix_dtr( &ctx
->TextureMatrix
[i
] );
1480 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
1481 gl_matrix_dtr( &ctx
->TextureStack
[i
][j
] );
1487 if (ctx
->input
!= ctx
->VB
->IM
)
1488 gl_immediate_free( ctx
->input
);
1490 gl_vb_free( ctx
->VB
);
1492 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1493 ctx
->Shared
->RefCount
--;
1494 assert(ctx
->Shared
->RefCount
>= 0);
1495 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1496 if (ctx
->Shared
->RefCount
== 0) {
1497 /* free shared state */
1498 free_shared_state( ctx
, ctx
->Shared
);
1501 foreach_s( s
, tmps
, ctx
->ShineTabList
) {
1504 FREE( ctx
->ShineTabList
);
1506 /* Free proxy texture objects */
1507 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1508 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1509 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1511 /* Free evaluator data */
1512 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1513 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1514 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1515 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1516 if (ctx
->EvalMap
.Map1Index
.Points
)
1517 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1518 if (ctx
->EvalMap
.Map1Color4
.Points
)
1519 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1520 if (ctx
->EvalMap
.Map1Normal
.Points
)
1521 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1522 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1523 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1524 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1525 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1526 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1527 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1528 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1529 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1531 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1532 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1533 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1534 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1535 if (ctx
->EvalMap
.Map2Index
.Points
)
1536 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1537 if (ctx
->EvalMap
.Map2Color4
.Points
)
1538 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1539 if (ctx
->EvalMap
.Map2Normal
.Points
)
1540 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1541 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1542 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1543 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1544 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1545 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1546 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1547 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1548 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1550 _mesa_free_colortable_data( &ctx
->ColorTable
);
1551 _mesa_free_colortable_data( &ctx
->PostConvolutionColorTable
);
1552 _mesa_free_colortable_data( &ctx
->PostColorMatrixColorTable
);
1553 _mesa_free_colortable_data( &ctx
->Texture
.Palette
);
1555 /* Free cache of immediate buffers. */
1556 while (ctx
->nr_im_queued
-- > 0) {
1557 struct immediate
* next
= ctx
->freed_im_queue
->next
;
1558 FREE( ctx
->freed_im_queue
);
1559 ctx
->freed_im_queue
= next
;
1561 gl_extensions_dtr(ctx
);
1570 * Destroy a GLcontext structure.
1573 gl_destroy_context( GLcontext
*ctx
)
1576 gl_free_context_data(ctx
);
1577 FREE( (void *) ctx
);
1584 * Called by the driver after both the context and driver are fully
1585 * initialized. Currently just reads the config file.
1588 gl_context_initialize( GLcontext
*ctx
)
1590 gl_read_config_file( ctx
);
1596 * Copy attribute groups from one context to another.
1597 * Input: src - source context
1598 * dst - destination context
1599 * mask - bitwise OR of GL_*_BIT flags
1602 gl_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1604 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1605 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1607 if (mask
& GL_COLOR_BUFFER_BIT
) {
1608 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1610 if (mask
& GL_CURRENT_BIT
) {
1611 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1613 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1614 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1616 if (mask
& GL_ENABLE_BIT
) {
1619 if (mask
& GL_EVAL_BIT
) {
1620 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1622 if (mask
& GL_FOG_BIT
) {
1623 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1625 if (mask
& GL_HINT_BIT
) {
1626 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1628 if (mask
& GL_LIGHTING_BIT
) {
1629 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1630 /* gl_reinit_light_attrib( &dst->Light ); */
1632 if (mask
& GL_LINE_BIT
) {
1633 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1635 if (mask
& GL_LIST_BIT
) {
1636 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1638 if (mask
& GL_PIXEL_MODE_BIT
) {
1639 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1641 if (mask
& GL_POINT_BIT
) {
1642 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1644 if (mask
& GL_POLYGON_BIT
) {
1645 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1647 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1648 /* Use loop instead of MEMCPY due to problem with Portland Group's
1649 * C compiler. Reported by John Stone.
1652 for (i
=0;i
<32;i
++) {
1653 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1656 if (mask
& GL_SCISSOR_BIT
) {
1657 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1659 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1660 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1662 if (mask
& GL_TEXTURE_BIT
) {
1663 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1665 if (mask
& GL_TRANSFORM_BIT
) {
1666 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1668 if (mask
& GL_VIEWPORT_BIT
) {
1669 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1675 * Set the current context, binding the given frame buffer to the context.
1677 void gl_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1679 gl_make_current2( newCtx
, buffer
, buffer
);
1684 * Bind the given context to the given draw-buffer and read-buffer
1685 * and make it the current context for this thread.
1687 void gl_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1688 GLframebuffer
*readBuffer
)
1691 GLcontext
*oldCtx
= gl_get_context();
1693 /* Flush the old context
1696 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx
, "gl_make_current");
1698 /* unbind frame buffers from context */
1699 if (oldCtx
->DrawBuffer
) {
1700 oldCtx
->DrawBuffer
= NULL
;
1702 if (oldCtx
->ReadBuffer
) {
1703 oldCtx
->ReadBuffer
= NULL
;
1708 /* We call this function periodically (just here for now) in
1709 * order to detect when multithreading has begun.
1711 _glapi_check_multithread();
1713 _glapi_set_context((void *) newCtx
);
1714 ASSERT(gl_get_current_context() == newCtx
);
1716 SET_IMMEDIATE(newCtx
, newCtx
->input
);
1717 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1720 _glapi_set_dispatch(NULL
); /* none current */
1723 if (MESA_VERBOSE
) fprintf(stderr
, "gl_make_current()\n");
1725 if (newCtx
&& drawBuffer
&& readBuffer
) {
1726 /* TODO: check if newCtx and buffer's visual match??? */
1727 newCtx
->DrawBuffer
= drawBuffer
;
1728 newCtx
->ReadBuffer
= readBuffer
;
1729 newCtx
->NewState
= NEW_ALL
; /* just to be safe */
1730 gl_update_state( newCtx
);
1733 /* We can use this to help debug user's problems. Tell the to set
1734 * the MESA_INFO env variable before running their app. Then the
1735 * first time each context is made current we'll print some useful
1738 if (newCtx
&& newCtx
->FirstTimeCurrent
) {
1739 if (getenv("MESA_INFO")) {
1740 fprintf(stderr
, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION
));
1741 fprintf(stderr
, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER
));
1742 fprintf(stderr
, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR
));
1743 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS
));
1744 #if defined(THREADS)
1745 fprintf(stderr
, "Mesa thread-safe: YES\n");
1747 fprintf(stderr
, "Mesa thread-safe: NO\n");
1749 #if defined(USE_X86_ASM)
1750 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1752 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1755 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1762 * Return current context handle for the calling thread.
1763 * This isn't the fastest way to get the current context.
1764 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1766 GLcontext
*gl_get_current_context( void )
1768 return (GLcontext
*) _glapi_get_context();
1774 * This should be called by device drivers just before they do a
1775 * swapbuffers. Any pending rendering commands will be executed.
1778 _mesa_swapbuffers(GLcontext
*ctx
)
1780 FLUSH_VB( ctx
, "swap buffers" );
1786 * Return pointer to this context's current API dispatch table.
1787 * It'll either be the immediate-mode execute dispatcher or the
1788 * display list compile dispatcher.
1790 struct _glapi_table
*
1791 _mesa_get_dispatch(GLcontext
*ctx
)
1793 return ctx
->CurrentDispatch
;
1798 /**********************************************************************/
1799 /***** Miscellaneous functions *****/
1800 /**********************************************************************/
1804 * This function is called when the Mesa user has stumbled into a code
1805 * path which may not be implemented fully or correctly.
1807 void gl_problem( const GLcontext
*ctx
, const char *s
)
1809 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
1810 fprintf( stderr
, "Report to mesa-bugs@mesa3d.org\n" );
1817 * This is called to inform the user that he or she has tried to do
1818 * something illogical or if there's likely a bug in their program
1819 * (like enabled depth testing without a depth buffer).
1821 void gl_warning( const GLcontext
*ctx
, const char *s
)
1827 if (getenv("MESA_DEBUG")) {
1835 fprintf( stderr
, "Mesa warning: %s\n", s
);
1843 * Compile an error into current display list.
1845 void gl_compile_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1847 if (ctx
->CompileFlag
)
1848 gl_save_error( ctx
, error
, s
);
1850 if (ctx
->ExecuteFlag
)
1851 gl_error( ctx
, error
, s
);
1857 * This is Mesa's error handler. Normally, all that's done is the updating
1858 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1859 * environment variable "MESA_DEBUG" is defined then a real error message
1860 * is printed to stderr.
1861 * Input: error - the error value
1862 * s - a diagnostic string
1864 void gl_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1871 if (getenv("MESA_DEBUG")) {
1884 strcpy( errstr
, "GL_NO_ERROR" );
1886 case GL_INVALID_VALUE
:
1887 strcpy( errstr
, "GL_INVALID_VALUE" );
1889 case GL_INVALID_ENUM
:
1890 strcpy( errstr
, "GL_INVALID_ENUM" );
1892 case GL_INVALID_OPERATION
:
1893 strcpy( errstr
, "GL_INVALID_OPERATION" );
1895 case GL_STACK_OVERFLOW
:
1896 strcpy( errstr
, "GL_STACK_OVERFLOW" );
1898 case GL_STACK_UNDERFLOW
:
1899 strcpy( errstr
, "GL_STACK_UNDERFLOW" );
1901 case GL_OUT_OF_MEMORY
:
1902 strcpy( errstr
, "GL_OUT_OF_MEMORY" );
1905 strcpy( errstr
, "unknown" );
1908 fprintf( stderr
, "Mesa user error: %s in %s\n", errstr
, s
);
1911 if (ctx
->ErrorValue
==GL_NO_ERROR
) {
1912 ctx
->ErrorValue
= error
;
1915 /* Call device driver's error handler, if any. This is used on the Mac. */
1916 if (ctx
->Driver
.Error
) {
1917 (*ctx
->Driver
.Error
)( ctx
);
1924 _mesa_Finish( void )
1926 GET_CURRENT_CONTEXT(ctx
);
1927 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFinish");
1928 if (ctx
->Driver
.Finish
) {
1929 (*ctx
->Driver
.Finish
)( ctx
);
1938 GET_CURRENT_CONTEXT(ctx
);
1939 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFlush");
1940 if (ctx
->Driver
.Flush
) {
1941 (*ctx
->Driver
.Flush
)( ctx
);