1 /* $Id: context.c,v 1.102 2000/10/31 18:09:44 keithw 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.
40 #include "extensions.h"
43 #include "glapinoop.h"
54 #include "simple_list.h"
57 #include "translate.h"
68 #include "swrast/swrast.h"
71 #if defined(MESA_TRACE)
72 #include "Trace/tr_context.h"
73 #include "Trace/tr_wrapper.h"
78 /**********************************************************************/
79 /***** OpenGL SI-style interface (new in Mesa 3.5) *****/
80 /**********************************************************************/
83 _mesa_DestroyContext(__GLcontext
*gc
)
86 _mesa_free_context_data(gc
);
87 (*gc
->imports
.free
)(gc
, gc
);
93 /* exported OpenGL SI interface */
95 __glCoreCreateContext(__GLimports
*imports
, __GLcontextModes
*modes
)
99 ctx
= (GLcontext
*) (*imports
->calloc
)(0, 1, sizeof(GLcontext
));
103 ctx
->imports
= *imports
;
105 _mesa_initialize_visual(&ctx
->Visual
,
107 modes
->doubleBufferMode
,
117 modes
->accumGreenBits
,
118 modes
->accumBlueBits
,
119 modes
->accumAlphaBits
,
122 _mesa_initialize_context(ctx
, &ctx
->Visual
, NULL
, imports
->wscx
, GL_FALSE
);
124 ctx
->exports
.destroyContext
= _mesa_DestroyContext
;
130 /* exported OpenGL SI interface */
132 __glCoreNopDispatch(void)
136 __gl_dispatch
= __glNopDispatchState
;
139 _glapi_set_dispatch(NULL
);
144 /**********************************************************************/
145 /***** Context and Thread management *****/
146 /**********************************************************************/
149 #if !defined(THREADS)
151 struct immediate
*_mesa_CurrentInput
= NULL
;
156 /**********************************************************************/
157 /***** GL Visual allocation/destruction *****/
158 /**********************************************************************/
162 * Allocate a new GLvisual object.
163 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
164 * dbFlag - double buffering?
165 * stereoFlag - stereo buffer?
166 * depthBits - requested bits per depth buffer value
167 * Any value in [0, 32] is acceptable but the actual
168 * depth type will be GLushort or GLuint as needed.
169 * stencilBits - requested minimum bits per stencil buffer value
170 * accumBits - requested minimum bits per accum buffer component
171 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
172 * red/green/blue/alphaBits - number of bits per color component
173 * in frame buffer for RGB(A) mode.
174 * We always use 8 in core Mesa though.
175 * Return: pointer to new GLvisual or NULL if requested parameters can't
179 _mesa_create_visual( GLboolean rgbFlag
,
181 GLboolean stereoFlag
,
190 GLint accumGreenBits
,
192 GLint accumAlphaBits
,
195 GLvisual
*vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
197 if (!_mesa_initialize_visual(vis
, rgbFlag
, dbFlag
, stereoFlag
,
198 redBits
, greenBits
, blueBits
, alphaBits
,
199 indexBits
, depthBits
, stencilBits
,
200 accumRedBits
, accumGreenBits
,
201 accumBlueBits
, accumAlphaBits
,
212 * Initialize the fields of the given GLvisual.
213 * Input: see _mesa_create_visual() above.
214 * Return: GL_TRUE = success
215 * GL_FALSE = failure.
218 _mesa_initialize_visual( GLvisual
*vis
,
221 GLboolean stereoFlag
,
230 GLint accumGreenBits
,
232 GLint accumAlphaBits
,
237 /* This is to catch bad values from device drivers not updated for
238 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
239 * bad value now (a 1-bit depth buffer!?!).
241 assert(depthBits
== 0 || depthBits
> 1);
243 if (depthBits
< 0 || depthBits
> 32) {
246 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
249 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
252 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
255 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
258 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
262 vis
->RGBAflag
= rgbFlag
;
263 vis
->DBflag
= dbFlag
;
264 vis
->StereoFlag
= stereoFlag
;
265 vis
->RedBits
= redBits
;
266 vis
->GreenBits
= greenBits
;
267 vis
->BlueBits
= blueBits
;
268 vis
->AlphaBits
= alphaBits
;
270 vis
->IndexBits
= indexBits
;
271 vis
->DepthBits
= depthBits
;
272 vis
->AccumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
273 vis
->AccumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
274 vis
->AccumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
275 vis
->AccumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
276 vis
->StencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
278 if (depthBits
== 0) {
279 /* Special case. Even if we don't have a depth buffer we need
280 * good values for DepthMax for Z vertex transformation purposes
281 * and for per-fragment fog computation.
283 vis
->DepthMax
= 1 << 16;
284 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
286 else if (depthBits
< 32) {
287 vis
->DepthMax
= (1 << depthBits
) - 1;
288 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
291 /* Special case since shift values greater than or equal to the
292 * number of bits in the left hand expression's type are
295 vis
->DepthMax
= 0xffffffff;
296 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
298 vis
->MRD
= 1; /* XXX temporary value */
305 _mesa_destroy_visual( GLvisual
*vis
)
311 /**********************************************************************/
312 /***** GL Framebuffer allocation/destruction *****/
313 /**********************************************************************/
317 * Create a new framebuffer. A GLframebuffer is a struct which
318 * encapsulates the depth, stencil and accum buffers and related
320 * Input: visual - a GLvisual pointer
321 * softwareDepth - create/use a software depth buffer?
322 * softwareStencil - create/use a software stencil buffer?
323 * softwareAccum - create/use a software accum buffer?
324 * softwareAlpha - create/use a software alpha buffer?
326 * Return: pointer to new GLframebuffer struct or NULL if error.
329 _mesa_create_framebuffer( GLvisual
*visual
,
330 GLboolean softwareDepth
,
331 GLboolean softwareStencil
,
332 GLboolean softwareAccum
,
333 GLboolean softwareAlpha
)
335 GLframebuffer
*buffer
= CALLOC_STRUCT(gl_frame_buffer
);
338 _mesa_initialize_framebuffer(buffer
, visual
,
339 softwareDepth
, softwareStencil
,
340 softwareAccum
, softwareAlpha
);
347 * Initialize a GLframebuffer object.
348 * Input: See _mesa_create_framebuffer() above.
351 _mesa_initialize_framebuffer( GLframebuffer
*buffer
,
353 GLboolean softwareDepth
,
354 GLboolean softwareStencil
,
355 GLboolean softwareAccum
,
356 GLboolean softwareAlpha
)
362 if (softwareDepth
) {
363 assert(visual
->DepthBits
> 0);
365 if (softwareStencil
) {
366 assert(visual
->StencilBits
> 0);
369 assert(visual
->RGBAflag
);
370 assert(visual
->AccumRedBits
> 0);
371 assert(visual
->AccumGreenBits
> 0);
372 assert(visual
->AccumBlueBits
> 0);
375 assert(visual
->RGBAflag
);
376 assert(visual
->AlphaBits
> 0);
379 buffer
->Visual
= visual
;
380 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
381 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
382 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
383 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
388 * Free a framebuffer struct and its buffers.
391 _mesa_destroy_framebuffer( GLframebuffer
*buffer
)
394 if (buffer
->DepthBuffer
) {
395 FREE( buffer
->DepthBuffer
);
398 FREE( buffer
->Accum
);
400 if (buffer
->Stencil
) {
401 FREE( buffer
->Stencil
);
403 if (buffer
->FrontLeftAlpha
) {
404 FREE( buffer
->FrontLeftAlpha
);
406 if (buffer
->BackLeftAlpha
) {
407 FREE( buffer
->BackLeftAlpha
);
409 if (buffer
->FrontRightAlpha
) {
410 FREE( buffer
->FrontRightAlpha
);
412 if (buffer
->BackRightAlpha
) {
413 FREE( buffer
->BackRightAlpha
);
421 /**********************************************************************/
422 /***** Context allocation, initialization, destroying *****/
423 /**********************************************************************/
426 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
430 * This function just calls all the various one-time-init functions in Mesa.
433 one_time_init( void )
435 static GLboolean alreadyCalled
= GL_FALSE
;
436 _glthread_LOCK_MUTEX(OneTimeLock
);
437 if (!alreadyCalled
) {
438 /* do some implementation tests */
439 assert( sizeof(GLbyte
) == 1 );
440 assert( sizeof(GLshort
) >= 2 );
441 assert( sizeof(GLint
) >= 4 );
442 assert( sizeof(GLubyte
) == 1 );
443 assert( sizeof(GLushort
) >= 2 );
444 assert( sizeof(GLuint
) >= 4 );
452 gl_init_transformation();
458 if (getenv("MESA_DEBUG")) {
459 _glapi_noop_enable_warnings(GL_TRUE
);
462 _glapi_noop_enable_warnings(GL_FALSE
);
465 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
466 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
469 alreadyCalled
= GL_TRUE
;
471 _glthread_UNLOCK_MUTEX(OneTimeLock
);
477 * Allocate and initialize a shared context state structure.
479 static struct gl_shared_state
*
480 alloc_shared_state( void )
483 struct gl_shared_state
*ss
;
484 GLboolean outOfMemory
;
486 ss
= CALLOC_STRUCT(gl_shared_state
);
490 _glthread_INIT_MUTEX(ss
->Mutex
);
492 ss
->DisplayList
= _mesa_NewHashTable();
493 ss
->TexObjects
= _mesa_NewHashTable();
495 /* Default Texture objects */
496 outOfMemory
= GL_FALSE
;
497 for (d
= 1 ; d
<= 3 ; d
++) {
498 ss
->DefaultD
[d
] = gl_alloc_texture_object(ss
, 0, d
);
499 if (!ss
->DefaultD
[d
]) {
500 outOfMemory
= GL_TRUE
;
503 ss
->DefaultD
[d
]->RefCount
++; /* don't free if not in use */
506 ss
->DefaultCubeMap
= gl_alloc_texture_object(ss
, 0, 6);
507 if (!ss
->DefaultCubeMap
) {
508 outOfMemory
= GL_TRUE
;
511 ss
->DefaultCubeMap
->RefCount
++;
514 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
515 /* Ran out of memory at some point. Free everything and return NULL */
517 _mesa_DeleteHashTable(ss
->DisplayList
);
519 _mesa_DeleteHashTable(ss
->TexObjects
);
521 gl_free_texture_object(ss
, ss
->DefaultD
[1]);
523 gl_free_texture_object(ss
, ss
->DefaultD
[2]);
525 gl_free_texture_object(ss
, ss
->DefaultD
[3]);
526 if (ss
->DefaultCubeMap
)
527 gl_free_texture_object(ss
, ss
->DefaultCubeMap
);
538 * Deallocate a shared state context and all children structures.
541 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
543 /* Free display lists */
545 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
547 gl_destroy_list(ctx
, list
);
553 _mesa_DeleteHashTable(ss
->DisplayList
);
555 /* Free texture objects */
556 while (ss
->TexObjectList
)
558 if (ctx
->Driver
.DeleteTexture
)
559 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
560 /* this function removes from linked list too! */
561 gl_free_texture_object(ss
, ss
->TexObjectList
);
563 _mesa_DeleteHashTable(ss
->TexObjects
);
571 * Initialize the nth light. Note that the defaults for light 0 are
572 * different than the other lights.
575 init_light( struct gl_light
*l
, GLuint n
)
577 make_empty_list( l
);
579 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
581 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
582 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
585 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
586 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
588 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
589 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
590 l
->SpotExponent
= 0.0;
591 gl_compute_spot_exp_table( l
);
592 l
->SpotCutoff
= 180.0;
593 l
->CosCutoff
= 0.0; /* KW: -ve values not admitted */
594 l
->ConstantAttenuation
= 1.0;
595 l
->LinearAttenuation
= 0.0;
596 l
->QuadraticAttenuation
= 0.0;
597 l
->Enabled
= GL_FALSE
;
603 init_lightmodel( struct gl_lightmodel
*lm
)
605 ASSIGN_4V( lm
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
606 lm
->LocalViewer
= GL_FALSE
;
607 lm
->TwoSide
= GL_FALSE
;
608 lm
->ColorControl
= GL_SINGLE_COLOR
;
613 init_material( struct gl_material
*m
)
615 ASSIGN_4V( m
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
616 ASSIGN_4V( m
->Diffuse
, 0.8, 0.8, 0.8, 1.0 );
617 ASSIGN_4V( m
->Specular
, 0.0, 0.0, 0.0, 1.0 );
618 ASSIGN_4V( m
->Emission
, 0.0, 0.0, 0.0, 1.0 );
622 m
->SpecularIndex
= 1;
628 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
630 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
632 texUnit
->EnvMode
= GL_MODULATE
;
633 texUnit
->CombineModeRGB
= GL_MODULATE
;
634 texUnit
->CombineModeA
= GL_MODULATE
;
635 texUnit
->CombineSourceRGB
[0] = GL_TEXTURE
;
636 texUnit
->CombineSourceRGB
[1] = GL_PREVIOUS_EXT
;
637 texUnit
->CombineSourceRGB
[2] = GL_CONSTANT_EXT
;
638 texUnit
->CombineSourceA
[0] = GL_TEXTURE
;
639 texUnit
->CombineSourceA
[1] = GL_PREVIOUS_EXT
;
640 texUnit
->CombineSourceA
[2] = GL_CONSTANT_EXT
;
641 texUnit
->CombineOperandRGB
[0] = GL_SRC_COLOR
;
642 texUnit
->CombineOperandRGB
[1] = GL_SRC_COLOR
;
643 texUnit
->CombineOperandRGB
[2] = GL_SRC_ALPHA
;
644 texUnit
->CombineOperandA
[0] = GL_SRC_ALPHA
;
645 texUnit
->CombineOperandA
[1] = GL_SRC_ALPHA
;
646 texUnit
->CombineOperandA
[2] = GL_SRC_ALPHA
;
647 texUnit
->CombineScaleShiftRGB
= 0;
648 texUnit
->CombineScaleShiftA
= 0;
650 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
651 texUnit
->TexGenEnabled
= 0;
652 texUnit
->GenModeS
= GL_EYE_LINEAR
;
653 texUnit
->GenModeT
= GL_EYE_LINEAR
;
654 texUnit
->GenModeR
= GL_EYE_LINEAR
;
655 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
656 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
657 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
658 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
659 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
661 /* Yes, these plane coefficients are correct! */
662 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
664 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
665 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
666 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
667 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
668 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
669 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
671 texUnit
->CurrentD
[1] = ctx
->Shared
->DefaultD
[1];
672 texUnit
->CurrentD
[2] = ctx
->Shared
->DefaultD
[2];
673 texUnit
->CurrentD
[3] = ctx
->Shared
->DefaultD
[3];
674 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
679 init_fallback_arrays( GLcontext
*ctx
)
681 struct gl_client_array
*cl
;
684 cl
= &ctx
->Fallback
.Normal
;
689 cl
->Ptr
= (void *) ctx
->Current
.Normal
;
692 cl
= &ctx
->Fallback
.Color
;
694 cl
->Type
= GL_UNSIGNED_BYTE
;
697 cl
->Ptr
= (void *) ctx
->Current
.Color
;
700 cl
= &ctx
->Fallback
.SecondaryColor
;
702 cl
->Type
= GL_UNSIGNED_BYTE
;
705 cl
->Ptr
= (void *) ctx
->Current
.SecondaryColor
;
708 cl
= &ctx
->Fallback
.FogCoord
;
713 cl
->Ptr
= (void *) &ctx
->Current
.FogCoord
;
716 cl
= &ctx
->Fallback
.Index
;
718 cl
->Type
= GL_UNSIGNED_INT
;
721 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
724 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
725 cl
= &ctx
->Fallback
.TexCoord
[i
];
730 cl
->Ptr
= (void *) ctx
->Current
.Texcoord
[i
];
734 cl
= &ctx
->Fallback
.EdgeFlag
;
736 cl
->Type
= GL_UNSIGNED_BYTE
;
739 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
744 /* Initialize a 1-D evaluator map */
746 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
751 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
755 map
->Points
[i
] = initial
[i
];
760 /* Initialize a 2-D evaluator map */
762 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
770 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
774 map
->Points
[i
] = initial
[i
];
780 * Initialize the attribute groups in a GLcontext.
783 init_attrib_groups( GLcontext
*ctx
)
789 /* Constants, may be overriden by device drivers */
790 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
791 ctx
->Const
.MaxTextureSize
= 1 << (MAX_TEXTURE_LEVELS
- 1);
792 ctx
->Const
.MaxCubeTextureSize
= ctx
->Const
.MaxTextureSize
;
793 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
794 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
795 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
796 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
797 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
798 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
799 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
800 ctx
->Const
.PointSizeGranularity
= POINT_SIZE_GRANULARITY
;
801 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
802 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
803 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
804 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
805 ctx
->Const
.LineWidthGranularity
= LINE_WIDTH_GRANULARITY
;
806 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
807 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
808 ctx
->Const
.MaxConvolutionWidth
= MAX_CONVOLUTION_WIDTH
;
809 ctx
->Const
.MaxConvolutionHeight
= MAX_CONVOLUTION_HEIGHT
;
810 ctx
->Const
.NumCompressedTextureFormats
= 0;
812 /* Modelview matrix */
813 gl_matrix_ctr( &ctx
->ModelView
);
814 gl_matrix_alloc_inv( &ctx
->ModelView
);
816 ctx
->ModelViewStackDepth
= 0;
817 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
818 gl_matrix_ctr( &ctx
->ModelViewStack
[i
] );
819 gl_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
822 /* Projection matrix - need inv for user clipping in clip space*/
823 gl_matrix_ctr( &ctx
->ProjectionMatrix
);
824 gl_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
826 gl_matrix_ctr( &ctx
->ModelProjectMatrix
);
828 ctx
->ProjectionStackDepth
= 0;
829 ctx
->NearFarStack
[0][0] = 1.0; /* These values seem weird by make */
830 ctx
->NearFarStack
[0][1] = 0.0; /* sense mathematically. */
832 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
833 gl_matrix_ctr( &ctx
->ProjectionStack
[i
] );
834 gl_matrix_alloc_inv( &ctx
->ProjectionStack
[i
] );
838 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
839 gl_matrix_ctr( &ctx
->TextureMatrix
[i
] );
840 ctx
->TextureStackDepth
[i
] = 0;
841 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
842 gl_matrix_ctr( &ctx
->TextureStack
[i
][j
] );
843 ctx
->TextureStack
[i
][j
].inv
= 0;
848 gl_matrix_ctr(&ctx
->ColorMatrix
);
849 ctx
->ColorStackDepth
= 0;
850 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
851 gl_matrix_ctr(&ctx
->ColorStack
[j
]);
854 /* Accumulate buffer group */
855 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
857 /* Color buffer group */
858 ctx
->Color
.IndexMask
= 0xffffffff;
859 ctx
->Color
.ColorMask
[0] = 0xff;
860 ctx
->Color
.ColorMask
[1] = 0xff;
861 ctx
->Color
.ColorMask
[2] = 0xff;
862 ctx
->Color
.ColorMask
[3] = 0xff;
863 ctx
->Color
.ClearIndex
= 0;
864 ASSIGN_4V( ctx
->Color
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
865 ctx
->Color
.DrawBuffer
= GL_FRONT
;
866 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
867 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
868 ctx
->Color
.AlphaRef
= 0;
869 ctx
->Color
.BlendEnabled
= GL_FALSE
;
870 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
871 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
872 ctx
->Color
.BlendSrcA
= GL_ONE
;
873 ctx
->Color
.BlendDstA
= GL_ZERO
;
874 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
875 ctx
->Color
.BlendFunc
= NULL
; /* this pointer set only when needed */
876 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
877 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
878 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
879 ctx
->Color
.LogicOp
= GL_COPY
;
880 ctx
->Color
.DitherFlag
= GL_TRUE
;
881 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
884 ASSIGN_4V( ctx
->Current
.Color
, CHAN_MAX
, CHAN_MAX
, CHAN_MAX
, CHAN_MAX
);
885 ctx
->Current
.Index
= 1;
886 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
887 ASSIGN_4V( ctx
->Current
.Texcoord
[i
], 0.0, 0.0, 0.0, 1.0 );
888 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
889 ctx
->Current
.RasterDistance
= 0.0;
890 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
891 ctx
->Current
.RasterIndex
= 1;
892 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
893 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
894 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
895 ctx
->Current
.RasterPosValid
= GL_TRUE
;
896 ctx
->Current
.EdgeFlag
= GL_TRUE
;
897 ASSIGN_3V( ctx
->Current
.Normal
, 0.0, 0.0, 1.0 );
898 ctx
->Current
.Primitive
= (GLenum
) (GL_POLYGON
+ 1);
900 ctx
->Current
.Flag
= (VERT_NORM
|
912 init_fallback_arrays( ctx
);
914 /* Depth buffer group */
915 ctx
->Depth
.Test
= GL_FALSE
;
916 ctx
->Depth
.Clear
= 1.0;
917 ctx
->Depth
.Func
= GL_LESS
;
918 ctx
->Depth
.Mask
= GL_TRUE
;
919 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
921 /* Evaluators group */
922 ctx
->Eval
.Map1Color4
= GL_FALSE
;
923 ctx
->Eval
.Map1Index
= GL_FALSE
;
924 ctx
->Eval
.Map1Normal
= GL_FALSE
;
925 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
926 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
927 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
928 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
929 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
930 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
931 ctx
->Eval
.Map2Color4
= GL_FALSE
;
932 ctx
->Eval
.Map2Index
= GL_FALSE
;
933 ctx
->Eval
.Map2Normal
= GL_FALSE
;
934 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
935 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
936 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
937 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
938 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
939 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
940 ctx
->Eval
.AutoNormal
= GL_FALSE
;
941 ctx
->Eval
.MapGrid1un
= 1;
942 ctx
->Eval
.MapGrid1u1
= 0.0;
943 ctx
->Eval
.MapGrid1u2
= 1.0;
944 ctx
->Eval
.MapGrid2un
= 1;
945 ctx
->Eval
.MapGrid2vn
= 1;
946 ctx
->Eval
.MapGrid2u1
= 0.0;
947 ctx
->Eval
.MapGrid2u2
= 1.0;
948 ctx
->Eval
.MapGrid2v1
= 0.0;
949 ctx
->Eval
.MapGrid2v2
= 1.0;
953 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
954 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
955 static GLfloat index
[1] = { 1.0 };
956 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
957 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
959 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
960 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
961 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
962 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
963 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
964 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
965 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
966 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
967 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
969 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
970 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
971 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
972 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
973 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
974 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
975 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
976 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
977 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
981 ctx
->Fog
.Enabled
= GL_FALSE
;
982 ctx
->Fog
.Mode
= GL_EXP
;
983 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
984 ctx
->Fog
.Index
= 0.0;
985 ctx
->Fog
.Density
= 1.0;
986 ctx
->Fog
.Start
= 0.0;
988 ctx
->Fog
.ColorSumEnabled
= GL_FALSE
;
989 ctx
->Fog
.FogCoordinateSource
= GL_FRAGMENT_DEPTH_EXT
;
992 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
993 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
994 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
995 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
996 ctx
->Hint
.Fog
= GL_DONT_CARE
;
997 ctx
->Hint
.AllowDrawWin
= GL_TRUE
;
998 ctx
->Hint
.AllowDrawFrg
= GL_TRUE
;
999 ctx
->Hint
.AllowDrawMem
= GL_TRUE
;
1000 ctx
->Hint
.StrictLighting
= GL_TRUE
;
1001 ctx
->Hint
.ClipVolumeClipping
= GL_DONT_CARE
;
1002 ctx
->Hint
.TextureCompression
= GL_DONT_CARE
;
1004 /* Histogram group */
1005 ctx
->Histogram
.Width
= 0;
1006 ctx
->Histogram
.Format
= GL_RGBA
;
1007 ctx
->Histogram
.Sink
= GL_FALSE
;
1008 ctx
->Histogram
.RedSize
= 0xffffffff;
1009 ctx
->Histogram
.GreenSize
= 0xffffffff;
1010 ctx
->Histogram
.BlueSize
= 0xffffffff;
1011 ctx
->Histogram
.AlphaSize
= 0xffffffff;
1012 ctx
->Histogram
.LuminanceSize
= 0xffffffff;
1013 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
1014 ctx
->Histogram
.Count
[i
][0] = 0;
1015 ctx
->Histogram
.Count
[i
][1] = 0;
1016 ctx
->Histogram
.Count
[i
][2] = 0;
1017 ctx
->Histogram
.Count
[i
][3] = 0;
1021 ctx
->MinMax
.Format
= GL_RGBA
;
1022 ctx
->MinMax
.Sink
= GL_FALSE
;
1023 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
1024 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
1025 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
1026 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
1029 gl_pipeline_init( ctx
);
1033 gl_extensions_ctr( ctx
);
1035 ctx
->AllowVertexCull
= CLIP_CULLED_BIT
;
1037 /* Lighting group */
1038 for (i
=0;i
<MAX_LIGHTS
;i
++) {
1039 init_light( &ctx
->Light
.Light
[i
], i
);
1041 make_empty_list( &ctx
->Light
.EnabledList
);
1043 init_lightmodel( &ctx
->Light
.Model
);
1044 init_material( &ctx
->Light
.Material
[0] );
1045 init_material( &ctx
->Light
.Material
[1] );
1046 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
1047 ctx
->Light
.Enabled
= GL_FALSE
;
1048 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
1049 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
1050 ctx
->Light
.ColorMaterialBitmask
1051 = gl_material_bitmask( ctx
,
1053 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
1055 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1057 /* Lighting miscellaneous */
1058 ctx
->ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1059 make_empty_list( ctx
->ShineTabList
);
1060 for (i
= 0 ; i
< 10 ; i
++) {
1061 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1064 insert_at_tail( ctx
->ShineTabList
, s
);
1066 for (i
= 0 ; i
< 4 ; i
++) {
1067 ctx
->ShineTable
[i
] = ctx
->ShineTabList
->prev
;
1068 ctx
->ShineTable
[i
]->refcount
++;
1071 gl_compute_shine_table( ctx
, 0, ctx
->Light
.Material
[0].Shininess
);
1072 gl_compute_shine_table( ctx
, 2, ctx
->Light
.Material
[0].Shininess
* .5 );
1073 gl_compute_shine_table( ctx
, 1, ctx
->Light
.Material
[1].Shininess
);
1074 gl_compute_shine_table( ctx
, 3, ctx
->Light
.Material
[1].Shininess
* .5 );
1078 ctx
->Line
.SmoothFlag
= GL_FALSE
;
1079 ctx
->Line
.StippleFlag
= GL_FALSE
;
1080 ctx
->Line
.Width
= 1.0;
1081 ctx
->Line
.StipplePattern
= 0xffff;
1082 ctx
->Line
.StippleFactor
= 1;
1084 /* Display List group */
1085 ctx
->List
.ListBase
= 0;
1088 ctx
->Pixel
.RedBias
= 0.0;
1089 ctx
->Pixel
.RedScale
= 1.0;
1090 ctx
->Pixel
.GreenBias
= 0.0;
1091 ctx
->Pixel
.GreenScale
= 1.0;
1092 ctx
->Pixel
.BlueBias
= 0.0;
1093 ctx
->Pixel
.BlueScale
= 1.0;
1094 ctx
->Pixel
.AlphaBias
= 0.0;
1095 ctx
->Pixel
.AlphaScale
= 1.0;
1096 ctx
->Pixel
.DepthBias
= 0.0;
1097 ctx
->Pixel
.DepthScale
= 1.0;
1098 ctx
->Pixel
.IndexOffset
= 0;
1099 ctx
->Pixel
.IndexShift
= 0;
1100 ctx
->Pixel
.ZoomX
= 1.0;
1101 ctx
->Pixel
.ZoomY
= 1.0;
1102 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
1103 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
1104 ctx
->Pixel
.MapStoSsize
= 1;
1105 ctx
->Pixel
.MapItoIsize
= 1;
1106 ctx
->Pixel
.MapItoRsize
= 1;
1107 ctx
->Pixel
.MapItoGsize
= 1;
1108 ctx
->Pixel
.MapItoBsize
= 1;
1109 ctx
->Pixel
.MapItoAsize
= 1;
1110 ctx
->Pixel
.MapRtoRsize
= 1;
1111 ctx
->Pixel
.MapGtoGsize
= 1;
1112 ctx
->Pixel
.MapBtoBsize
= 1;
1113 ctx
->Pixel
.MapAtoAsize
= 1;
1114 ctx
->Pixel
.MapStoS
[0] = 0;
1115 ctx
->Pixel
.MapItoI
[0] = 0;
1116 ctx
->Pixel
.MapItoR
[0] = 0.0;
1117 ctx
->Pixel
.MapItoG
[0] = 0.0;
1118 ctx
->Pixel
.MapItoB
[0] = 0.0;
1119 ctx
->Pixel
.MapItoA
[0] = 0.0;
1120 ctx
->Pixel
.MapItoR8
[0] = 0;
1121 ctx
->Pixel
.MapItoG8
[0] = 0;
1122 ctx
->Pixel
.MapItoB8
[0] = 0;
1123 ctx
->Pixel
.MapItoA8
[0] = 0;
1124 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1125 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1126 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1127 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1128 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
1129 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
1130 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
1131 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1132 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1133 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixScale
, 1.0, 1.0, 1.0, 1.0);
1134 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixBias
, 0.0, 0.0, 0.0, 0.0);
1135 ASSIGN_4V(ctx
->Pixel
.ColorTableScale
, 1.0, 1.0, 1.0, 1.0);
1136 ASSIGN_4V(ctx
->Pixel
.ColorTableBias
, 0.0, 0.0, 0.0, 0.0);
1137 ASSIGN_4V(ctx
->Pixel
.PCCTscale
, 1.0, 1.0, 1.0, 1.0);
1138 ASSIGN_4V(ctx
->Pixel
.PCCTbias
, 0.0, 0.0, 0.0, 0.0);
1139 ASSIGN_4V(ctx
->Pixel
.PCMCTscale
, 1.0, 1.0, 1.0, 1.0);
1140 ASSIGN_4V(ctx
->Pixel
.PCMCTbias
, 0.0, 0.0, 0.0, 0.0);
1141 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1142 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1143 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1144 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
1145 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
1146 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
1147 for (i
= 0; i
< 3; i
++) {
1148 ASSIGN_4V(ctx
->Pixel
.ConvolutionBorderColor
[i
], 0.0, 0.0, 0.0, 0.0);
1149 ctx
->Pixel
.ConvolutionBorderMode
[i
] = GL_REDUCE
;
1150 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterScale
[i
], 1.0, 1.0, 1.0, 1.0);
1151 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterBias
[i
], 0.0, 0.0, 0.0, 0.0);
1153 ASSIGN_4V(ctx
->Pixel
.PostConvolutionScale
, 1.0, 1.0, 1.0, 1.0);
1154 ASSIGN_4V(ctx
->Pixel
.PostConvolutionBias
, 0.0, 0.0, 0.0, 0.0);
1157 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1158 ctx
->Point
.UserSize
= 1.0;
1159 ctx
->Point
.Size
= 1.0;
1160 ctx
->Point
.Params
[0] = 1.0;
1161 ctx
->Point
.Params
[1] = 0.0;
1162 ctx
->Point
.Params
[2] = 0.0;
1163 ctx
->Point
.Attenuated
= GL_FALSE
;
1164 ctx
->Point
.MinSize
= 0.0;
1165 ctx
->Point
.MaxSize
= (GLfloat
) MAX_POINT_SIZE
;
1166 ctx
->Point
.Threshold
= 1.0;
1169 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1170 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1171 ctx
->Polygon
.FrontFace
= GL_CCW
;
1172 ctx
->Polygon
.FrontBit
= 0;
1173 ctx
->Polygon
.FrontMode
= GL_FILL
;
1174 ctx
->Polygon
.BackMode
= GL_FILL
;
1175 ctx
->Polygon
.Unfilled
= GL_FALSE
;
1176 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1177 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1178 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1179 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1180 ctx
->Polygon
.OffsetMRD
= 0.0F
;
1181 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1182 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1183 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1185 /* Polygon Stipple group */
1186 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1189 ctx
->Scissor
.Enabled
= GL_FALSE
;
1192 ctx
->Scissor
.Width
= 0;
1193 ctx
->Scissor
.Height
= 0;
1196 ctx
->Stencil
.Enabled
= GL_FALSE
;
1197 ctx
->Stencil
.Function
= GL_ALWAYS
;
1198 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1199 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1200 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1201 ctx
->Stencil
.Ref
= 0;
1202 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1203 ctx
->Stencil
.Clear
= 0;
1204 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1207 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1208 ctx
->Texture
.CurrentTransformUnit
= 0; /* multitexture */
1209 ctx
->Texture
.ReallyEnabled
= 0;
1210 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1211 init_texture_unit( ctx
, i
);
1212 ctx
->Texture
.SharedPalette
= GL_FALSE
;
1213 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1215 /* Transformation group */
1216 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1217 ctx
->Transform
.Normalize
= GL_FALSE
;
1218 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1219 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1220 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1221 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1223 ctx
->Transform
.AnyClip
= GL_FALSE
;
1225 /* Viewport group */
1226 ctx
->Viewport
.X
= 0;
1227 ctx
->Viewport
.Y
= 0;
1228 ctx
->Viewport
.Width
= 0;
1229 ctx
->Viewport
.Height
= 0;
1230 ctx
->Viewport
.Near
= 0.0;
1231 ctx
->Viewport
.Far
= 1.0;
1232 gl_matrix_ctr(&ctx
->Viewport
.WindowMap
);
1236 ctx
->Viewport
.WindowMap
.m
[Sz
] = 0.5 * ctx
->Visual
.DepthMaxF
;
1237 ctx
->Viewport
.WindowMap
.m
[Tz
] = 0.5 * ctx
->Visual
.DepthMaxF
;
1241 ctx
->Viewport
.WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1242 ctx
->Viewport
.WindowMap
.type
= MATRIX_3D_NO_ROT
;
1245 ctx
->Array
.Vertex
.Size
= 4;
1246 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1247 ctx
->Array
.Vertex
.Stride
= 0;
1248 ctx
->Array
.Vertex
.StrideB
= 0;
1249 ctx
->Array
.Vertex
.Ptr
= NULL
;
1250 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1251 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1252 ctx
->Array
.Normal
.Stride
= 0;
1253 ctx
->Array
.Normal
.StrideB
= 0;
1254 ctx
->Array
.Normal
.Ptr
= NULL
;
1255 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1256 ctx
->Array
.Color
.Size
= 4;
1257 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1258 ctx
->Array
.Color
.Stride
= 0;
1259 ctx
->Array
.Color
.StrideB
= 0;
1260 ctx
->Array
.Color
.Ptr
= NULL
;
1261 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1262 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1263 ctx
->Array
.Index
.Stride
= 0;
1264 ctx
->Array
.Index
.StrideB
= 0;
1265 ctx
->Array
.Index
.Ptr
= NULL
;
1266 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1267 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1268 ctx
->Array
.TexCoord
[i
].Size
= 4;
1269 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1270 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1271 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1272 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1273 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1275 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1276 ctx
->Array
.EdgeFlag
.Stride
= 0;
1277 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1278 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1279 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1280 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1282 /* Pixel transfer */
1283 ctx
->Pack
.Alignment
= 4;
1284 ctx
->Pack
.RowLength
= 0;
1285 ctx
->Pack
.ImageHeight
= 0;
1286 ctx
->Pack
.SkipPixels
= 0;
1287 ctx
->Pack
.SkipRows
= 0;
1288 ctx
->Pack
.SkipImages
= 0;
1289 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1290 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1291 ctx
->Unpack
.Alignment
= 4;
1292 ctx
->Unpack
.RowLength
= 0;
1293 ctx
->Unpack
.ImageHeight
= 0;
1294 ctx
->Unpack
.SkipPixels
= 0;
1295 ctx
->Unpack
.SkipRows
= 0;
1296 ctx
->Unpack
.SkipImages
= 0;
1297 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1298 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1301 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1302 ctx
->Feedback
.Buffer
= NULL
;
1303 ctx
->Feedback
.BufferSize
= 0;
1304 ctx
->Feedback
.Count
= 0;
1306 /* Selection/picking */
1307 ctx
->Select
.Buffer
= NULL
;
1308 ctx
->Select
.BufferSize
= 0;
1309 ctx
->Select
.BufferCount
= 0;
1310 ctx
->Select
.Hits
= 0;
1311 ctx
->Select
.NameStackDepth
= 0;
1313 /* Optimized Accum buffer */
1314 ctx
->IntegerAccumMode
= GL_TRUE
;
1315 ctx
->IntegerAccumScaler
= 0.0;
1317 /* Renderer and client attribute stacks */
1318 ctx
->AttribStackDepth
= 0;
1319 ctx
->ClientAttribStackDepth
= 0;
1323 ctx
->ExecuteFlag
= GL_TRUE
;
1324 ctx
->CompileFlag
= GL_FALSE
;
1325 ctx
->CurrentListPtr
= NULL
;
1326 ctx
->CurrentBlock
= NULL
;
1327 ctx
->CurrentListNum
= 0;
1328 ctx
->CurrentPos
= 0;
1331 _mesa_init_colortable(&ctx
->ColorTable
);
1332 _mesa_init_colortable(&ctx
->ProxyColorTable
);
1333 _mesa_init_colortable(&ctx
->PostConvolutionColorTable
);
1334 _mesa_init_colortable(&ctx
->ProxyPostConvolutionColorTable
);
1335 _mesa_init_colortable(&ctx
->PostColorMatrixColorTable
);
1336 _mesa_init_colortable(&ctx
->ProxyPostColorMatrixColorTable
);
1339 ctx
->NewState
= _NEW_ALL
;
1340 ctx
->RenderMode
= GL_RENDER
;
1341 ctx
->StippleCounter
= 0;
1342 ctx
->NeedNormals
= GL_FALSE
;
1343 ctx
->DoViewportMapping
= GL_TRUE
;
1344 ctx
->ImageTransferState
= 0;
1346 ctx
->NeedEyeCoords
= GL_FALSE
;
1347 ctx
->NeedEyeNormals
= GL_FALSE
;
1348 ctx
->vb_proj_matrix
= &ctx
->ModelProjectMatrix
;
1350 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1352 ctx
->CatchSignals
= GL_TRUE
;
1353 ctx
->OcclusionResult
= GL_FALSE
;
1354 ctx
->OcclusionResultSaved
= GL_FALSE
;
1356 /* For debug/development only */
1357 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1358 ctx
->FirstTimeCurrent
= GL_TRUE
;
1360 /* Dither disable */
1361 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1362 if (ctx
->NoDither
) {
1363 if (getenv("MESA_DEBUG")) {
1364 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1366 ctx
->Color
.DitherFlag
= GL_FALSE
;
1374 * Allocate the proxy textures. If we run out of memory part way through
1375 * the allocations clean up and return GL_FALSE.
1376 * Return: GL_TRUE=success, GL_FALSE=failure
1379 alloc_proxy_textures( GLcontext
*ctx
)
1381 GLboolean out_of_memory
;
1384 ctx
->Texture
.Proxy1D
= gl_alloc_texture_object(NULL
, 0, 1);
1385 if (!ctx
->Texture
.Proxy1D
) {
1389 ctx
->Texture
.Proxy2D
= gl_alloc_texture_object(NULL
, 0, 2);
1390 if (!ctx
->Texture
.Proxy2D
) {
1391 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1395 ctx
->Texture
.Proxy3D
= gl_alloc_texture_object(NULL
, 0, 3);
1396 if (!ctx
->Texture
.Proxy3D
) {
1397 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1398 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1402 out_of_memory
= GL_FALSE
;
1403 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1404 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1405 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1406 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1407 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1408 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1409 || !ctx
->Texture
.Proxy3D
->Image
[i
]) {
1410 out_of_memory
= GL_TRUE
;
1413 if (out_of_memory
) {
1414 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1415 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1416 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1418 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1419 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1421 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1422 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1425 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1426 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1427 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1437 * Initialize a GLcontext struct. This includes allocating all the
1438 * other structs and arrays which hang off of the context by pointers.
1441 _mesa_initialize_context( GLcontext
*ctx
,
1443 GLcontext
*share_list
,
1447 GLuint dispatchSize
;
1449 (void) direct
; /* not used */
1451 /* misc one-time initializations */
1457 if (!ctx
->imports
.malloc
) {
1458 _mesa_InitDefaultImports(&ctx
->imports
, driver_ctx
, NULL
);
1460 /* exports are setup by the device driver */
1462 ctx
->DriverCtx
= driver_ctx
;
1463 ctx
->Visual
= *visual
;
1464 ctx
->DrawBuffer
= NULL
;
1465 ctx
->ReadBuffer
= NULL
;
1467 ctx
->VB
= gl_vb_create_for_immediate( ctx
);
1471 ctx
->input
= ctx
->VB
->IM
;
1473 if (!_swrast_create_context( ctx
)) {
1474 ALIGN_FREE( ctx
->VB
);
1479 /* share the group of display lists of another context */
1480 ctx
->Shared
= share_list
->Shared
;
1483 /* allocate new group of display lists */
1484 ctx
->Shared
= alloc_shared_state();
1486 ALIGN_FREE( ctx
->VB
);
1487 _swrast_destroy_context( ctx
);
1491 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1492 ctx
->Shared
->RefCount
++;
1493 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1495 init_attrib_groups( ctx
);
1497 gl_reset_vb( ctx
->VB
);
1498 gl_reset_input( ctx
);
1500 if (visual
->DBflag
) {
1501 ctx
->Color
.DrawBuffer
= GL_BACK
;
1502 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1503 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1504 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1505 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1508 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1509 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1510 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1511 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1512 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1515 if (!alloc_proxy_textures(ctx
)) {
1516 free_shared_state(ctx
, ctx
->Shared
);
1517 ALIGN_FREE( ctx
->VB
);
1518 _swrast_destroy_context( ctx
);
1522 /* register the most recent extension functions with libGL */
1523 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1524 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1525 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1526 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1527 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1528 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1529 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1530 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1532 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1533 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1534 * Mesa we do this to accomodate different versions of libGL and various
1537 dispatchSize
= MAX2(_glapi_get_dispatch_table_size(),
1538 sizeof(struct _glapi_table
) / sizeof(void *));
1540 /* setup API dispatch tables */
1541 ctx
->Exec
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1542 ctx
->Save
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1543 if (!ctx
->Exec
|| !ctx
->Save
) {
1544 free_shared_state(ctx
, ctx
->Shared
);
1545 ALIGN_FREE( ctx
->VB
);
1546 _swrast_destroy_context( ctx
);
1550 _mesa_init_exec_table(ctx
->Exec
, dispatchSize
);
1551 _mesa_init_dlist_table(ctx
->Save
, dispatchSize
);
1552 ctx
->CurrentDispatch
= ctx
->Exec
;
1554 #if defined(MESA_TRACE)
1555 ctx
->TraceCtx
= CALLOC( sizeof(trace_context_t
) );
1557 /* Brian: do you want to have CreateContext fail here,
1558 or should we just trap in NewTrace (currently done)? */
1559 if (!(ctx
->TraceCtx
)) {
1560 free_shared_state(ctx
, ctx
->Shared
);
1561 ALIGN_FREE( ctx
->VB
);
1562 _swrast_destroy_context( ctx
);
1568 trInitContext(ctx
->TraceCtx
);
1570 ctx
->TraceDispatch
= (struct _glapi_table
*)
1571 CALLOC(dispatchSize
* sizeof(void*));
1573 if (!(ctx
->TraceCtx
)) {
1574 free_shared_state(ctx
, ctx
->Shared
);
1575 ALIGN_FREE( ctx
->VB
);
1576 _swrast_destroy_context( ctx
);
1579 FREE( ctx
->TraceCtx
);
1583 trInitDispatch(ctx
->TraceDispatch
);
1592 * Allocate and initialize a GLcontext structure.
1593 * Input: visual - a GLvisual pointer
1594 * sharelist - another context to share display lists with or NULL
1595 * driver_ctx - pointer to device driver's context state struct
1596 * Return: pointer to a new __GLcontextRec or NULL if error.
1599 _mesa_create_context( GLvisual
*visual
,
1600 GLcontext
*share_list
,
1604 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1609 if (_mesa_initialize_context(ctx
, visual
, share_list
, driver_ctx
, direct
)) {
1621 * Free the data associated with the given context.
1622 * But don't free() the GLcontext struct itself!
1625 _mesa_free_context_data( GLcontext
*ctx
)
1627 struct gl_shine_tab
*s
, *tmps
;
1630 /* if we're destroying the current context, unbind it first */
1631 if (ctx
== _mesa_get_current_context()) {
1632 _mesa_make_current(NULL
, NULL
);
1635 gl_matrix_dtr( &ctx
->ModelView
);
1636 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
1637 gl_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1639 gl_matrix_dtr( &ctx
->ProjectionMatrix
);
1640 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
1641 gl_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1643 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1644 gl_matrix_dtr( &ctx
->TextureMatrix
[i
] );
1645 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
1646 gl_matrix_dtr( &ctx
->TextureStack
[i
][j
] );
1650 _swrast_destroy_context( ctx
);
1652 if (ctx
->input
!= ctx
->VB
->IM
)
1653 gl_immediate_free( ctx
->input
);
1655 gl_vb_free( ctx
->VB
);
1657 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1658 ctx
->Shared
->RefCount
--;
1659 assert(ctx
->Shared
->RefCount
>= 0);
1660 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1661 if (ctx
->Shared
->RefCount
== 0) {
1662 /* free shared state */
1663 free_shared_state( ctx
, ctx
->Shared
);
1666 foreach_s( s
, tmps
, ctx
->ShineTabList
) {
1669 FREE( ctx
->ShineTabList
);
1671 /* Free proxy texture objects */
1672 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1673 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1674 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1676 /* Free evaluator data */
1677 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1678 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1679 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1680 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1681 if (ctx
->EvalMap
.Map1Index
.Points
)
1682 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1683 if (ctx
->EvalMap
.Map1Color4
.Points
)
1684 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1685 if (ctx
->EvalMap
.Map1Normal
.Points
)
1686 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1687 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1688 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1689 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1690 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1691 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1692 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1693 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1694 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1696 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1697 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1698 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1699 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1700 if (ctx
->EvalMap
.Map2Index
.Points
)
1701 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1702 if (ctx
->EvalMap
.Map2Color4
.Points
)
1703 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1704 if (ctx
->EvalMap
.Map2Normal
.Points
)
1705 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1706 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1707 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1708 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1709 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1710 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1711 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1712 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1713 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1715 _mesa_free_colortable_data( &ctx
->ColorTable
);
1716 _mesa_free_colortable_data( &ctx
->PostConvolutionColorTable
);
1717 _mesa_free_colortable_data( &ctx
->PostColorMatrixColorTable
);
1718 _mesa_free_colortable_data( &ctx
->Texture
.Palette
);
1720 /* Free cache of immediate buffers. */
1721 while (ctx
->nr_im_queued
-- > 0) {
1722 struct immediate
* next
= ctx
->freed_im_queue
->next
;
1723 ALIGN_FREE( ctx
->freed_im_queue
);
1724 ctx
->freed_im_queue
= next
;
1726 gl_extensions_dtr(ctx
);
1735 * Destroy a GLcontext structure.
1738 _mesa_destroy_context( GLcontext
*ctx
)
1741 _mesa_free_context_data(ctx
);
1742 FREE( (void *) ctx
);
1749 * Called by the driver after both the context and driver are fully
1750 * initialized. Currently just reads the config file.
1753 _mesa_context_initialize( GLcontext
*ctx
)
1755 gl_read_config_file( ctx
);
1761 * Copy attribute groups from one context to another.
1762 * Input: src - source context
1763 * dst - destination context
1764 * mask - bitwise OR of GL_*_BIT flags
1767 _mesa_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1769 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1770 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1772 if (mask
& GL_COLOR_BUFFER_BIT
) {
1773 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1775 if (mask
& GL_CURRENT_BIT
) {
1776 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1778 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1779 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1781 if (mask
& GL_ENABLE_BIT
) {
1784 if (mask
& GL_EVAL_BIT
) {
1785 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1787 if (mask
& GL_FOG_BIT
) {
1788 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1790 if (mask
& GL_HINT_BIT
) {
1791 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1793 if (mask
& GL_LIGHTING_BIT
) {
1794 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1795 /* gl_reinit_light_attrib( &dst->Light ); */
1797 if (mask
& GL_LINE_BIT
) {
1798 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1800 if (mask
& GL_LIST_BIT
) {
1801 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1803 if (mask
& GL_PIXEL_MODE_BIT
) {
1804 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1806 if (mask
& GL_POINT_BIT
) {
1807 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1809 if (mask
& GL_POLYGON_BIT
) {
1810 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1812 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1813 /* Use loop instead of MEMCPY due to problem with Portland Group's
1814 * C compiler. Reported by John Stone.
1817 for (i
=0;i
<32;i
++) {
1818 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1821 if (mask
& GL_SCISSOR_BIT
) {
1822 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1824 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1825 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1827 if (mask
& GL_TEXTURE_BIT
) {
1828 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1830 if (mask
& GL_TRANSFORM_BIT
) {
1831 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1833 if (mask
& GL_VIEWPORT_BIT
) {
1834 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1836 /* XXX FIXME: Call callbacks?
1838 dst
->NewState
= _NEW_ALL
;
1843 * Set the current context, binding the given frame buffer to the context.
1846 _mesa_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1848 _mesa_make_current2( newCtx
, buffer
, buffer
);
1853 * Bind the given context to the given draw-buffer and read-buffer
1854 * and make it the current context for this thread.
1857 _mesa_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1858 GLframebuffer
*readBuffer
)
1861 GLcontext
*oldCtx
= gl_get_context();
1863 /* Flush the old context
1866 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx
, "_mesa_make_current");
1868 /* unbind frame buffers from context */
1869 if (oldCtx
->DrawBuffer
) {
1870 oldCtx
->DrawBuffer
= NULL
;
1872 if (oldCtx
->ReadBuffer
) {
1873 oldCtx
->ReadBuffer
= NULL
;
1878 /* We call this function periodically (just here for now) in
1879 * order to detect when multithreading has begun.
1881 _glapi_check_multithread();
1883 _glapi_set_context((void *) newCtx
);
1884 ASSERT(_mesa_get_current_context() == newCtx
);
1886 SET_IMMEDIATE(newCtx
, newCtx
->input
);
1887 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1890 _glapi_set_dispatch(NULL
); /* none current */
1893 if (MESA_VERBOSE
) fprintf(stderr
, "_mesa_make_current()\n");
1895 if (newCtx
&& drawBuffer
&& readBuffer
) {
1896 /* TODO: check if newCtx and buffer's visual match??? */
1897 newCtx
->DrawBuffer
= drawBuffer
;
1898 newCtx
->ReadBuffer
= readBuffer
;
1899 newCtx
->NewState
|= _NEW_BUFFERS
;
1900 gl_update_state( newCtx
);
1903 /* We can use this to help debug user's problems. Tell the to set
1904 * the MESA_INFO env variable before running their app. Then the
1905 * first time each context is made current we'll print some useful
1908 if (newCtx
&& newCtx
->FirstTimeCurrent
) {
1909 if (getenv("MESA_INFO")) {
1910 fprintf(stderr
, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION
));
1911 fprintf(stderr
, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER
));
1912 fprintf(stderr
, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR
));
1913 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS
));
1914 #if defined(THREADS)
1915 fprintf(stderr
, "Mesa thread-safe: YES\n");
1917 fprintf(stderr
, "Mesa thread-safe: NO\n");
1919 #if defined(USE_X86_ASM)
1920 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1922 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1925 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1932 * Return current context handle for the calling thread.
1933 * This isn't the fastest way to get the current context.
1934 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1937 _mesa_get_current_context( void )
1939 return (GLcontext
*) _glapi_get_context();
1945 * This should be called by device drivers just before they do a
1946 * swapbuffers. Any pending rendering commands will be executed.
1949 _mesa_swapbuffers(GLcontext
*ctx
)
1951 FLUSH_VB( ctx
, "swap buffers" );
1957 * Return pointer to this context's current API dispatch table.
1958 * It'll either be the immediate-mode execute dispatcher or the
1959 * display list compile dispatcher.
1961 struct _glapi_table
*
1962 _mesa_get_dispatch(GLcontext
*ctx
)
1964 return ctx
->CurrentDispatch
;
1969 /**********************************************************************/
1970 /***** Miscellaneous functions *****/
1971 /**********************************************************************/
1975 * This function is called when the Mesa user has stumbled into a code
1976 * path which may not be implemented fully or correctly.
1978 void gl_problem( const GLcontext
*ctx
, const char *s
)
1980 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
1981 fprintf( stderr
, "Report to Mesa bug database at www.mesa3d.org\n" );
1988 * This is called to inform the user that he or she has tried to do
1989 * something illogical or if there's likely a bug in their program
1990 * (like enabled depth testing without a depth buffer).
1993 _mesa_warning( const GLcontext
*ctx
, const char *s
)
1995 (*ctx
->imports
.warning
)((__GLcontext
*) ctx
, (char *) s
);
2001 * Compile an error into current display list.
2004 _mesa_compile_error( GLcontext
*ctx
, GLenum error
, const char *s
)
2006 if (ctx
->CompileFlag
)
2007 gl_save_error( ctx
, error
, s
);
2009 if (ctx
->ExecuteFlag
)
2010 gl_error( ctx
, error
, s
);
2016 * This is Mesa's error handler. Normally, all that's done is the updating
2017 * of the current error value. If Mesa is compiled with -DDEBUG or if the
2018 * environment variable "MESA_DEBUG" is defined then a real error message
2019 * is printed to stderr.
2020 * Input: ctx - the GL context
2021 * error - the error value
2022 * where - usually the name of function where error was detected
2025 gl_error( GLcontext
*ctx
, GLenum error
, const char *where
)
2027 const char *debugEnv
= getenv("MESA_DEBUG");
2031 if (debugEnv
&& strstr(debugEnv
, "silent"))
2046 errstr
= "GL_NO_ERROR";
2048 case GL_INVALID_VALUE
:
2049 errstr
= "GL_INVALID_VALUE";
2051 case GL_INVALID_ENUM
:
2052 errstr
= "GL_INVALID_ENUM";
2054 case GL_INVALID_OPERATION
:
2055 errstr
= "GL_INVALID_OPERATION";
2057 case GL_STACK_OVERFLOW
:
2058 errstr
= "GL_STACK_OVERFLOW";
2060 case GL_STACK_UNDERFLOW
:
2061 errstr
= "GL_STACK_UNDERFLOW";
2063 case GL_OUT_OF_MEMORY
:
2064 errstr
= "GL_OUT_OF_MEMORY";
2066 case GL_TABLE_TOO_LARGE
:
2067 errstr
= "GL_TABLE_TOO_LARGE";
2073 fprintf(stderr
, "Mesa user error: %s in %s\n", errstr
, where
);
2076 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
2077 ctx
->ErrorValue
= error
;
2080 /* Call device driver's error handler, if any. This is used on the Mac. */
2081 if (ctx
->Driver
.Error
) {
2082 (*ctx
->Driver
.Error
)( ctx
);
2089 _mesa_Finish( void )
2091 GET_CURRENT_CONTEXT(ctx
);
2092 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFinish");
2093 if (ctx
->Driver
.Finish
) {
2094 (*ctx
->Driver
.Finish
)( ctx
);
2103 GET_CURRENT_CONTEXT(ctx
);
2104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFlush");
2105 if (ctx
->Driver
.Flush
) {
2106 (*ctx
->Driver
.Flush
)( ctx
);
2112 const char *_mesa_prim_name
[GL_POLYGON
+2] = {
2118 "GL_TRIANGLE_STRIP",
2127 GLenum gl_reduce_prim
[GL_POLYGON
+1] = {