1 /* $Id: context.c,v 1.59 2000/04/12 00:27:37 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.
41 #include "extensions.h"
45 #include "glapinoop.h"
56 #include "simple_list.h"
60 #include "translate.h"
77 /**********************************************************************/
78 /***** Context and Thread management *****/
79 /**********************************************************************/
84 struct immediate
*_mesa_CurrentInput
= NULL
;
91 /**********************************************************************/
92 /***** Profiling functions *****/
93 /**********************************************************************/
97 #include <sys/times.h>
98 #include <sys/param.h>
102 * Return system time in seconds.
103 * NOTE: this implementation may not be very portable!
105 GLdouble
gl_time( void )
107 static GLdouble prev_time
= 0.0;
108 static GLdouble time
;
115 time
= (double)clk
/ (double)CLK_TCK
;
117 time
= (double)clk
/ (double)HZ
;
120 if (time
>prev_time
) {
130 * Reset the timing/profiling counters
132 static void init_timings( GLcontext
*ctx
)
134 ctx
->BeginEndCount
= 0;
135 ctx
->BeginEndTime
= 0.0;
136 ctx
->VertexCount
= 0;
137 ctx
->VertexTime
= 0.0;
139 ctx
->PointTime
= 0.0;
142 ctx
->PolygonCount
= 0;
143 ctx
->PolygonTime
= 0.0;
145 ctx
->ClearTime
= 0.0;
152 * Print the accumulated timing/profiling data.
154 static void print_timings( GLcontext
*ctx
)
156 GLdouble beginendrate
;
160 GLdouble polygonrate
;
164 GLdouble avgvertices
;
166 if (ctx
->BeginEndTime
>0.0) {
167 beginendrate
= ctx
->BeginEndCount
/ ctx
->BeginEndTime
;
172 if (ctx
->VertexTime
>0.0) {
173 vertexrate
= ctx
->VertexCount
/ ctx
->VertexTime
;
178 if (ctx
->PointTime
>0.0) {
179 pointrate
= ctx
->PointCount
/ ctx
->PointTime
;
184 if (ctx
->LineTime
>0.0) {
185 linerate
= ctx
->LineCount
/ ctx
->LineTime
;
190 if (ctx
->PolygonTime
>0.0) {
191 polygonrate
= ctx
->PolygonCount
/ ctx
->PolygonTime
;
196 if (ctx
->ClearTime
>0.0) {
197 clearrate
= ctx
->ClearCount
/ ctx
->ClearTime
;
202 if (ctx
->SwapTime
>0.0) {
203 swaprate
= ctx
->SwapCount
/ ctx
->SwapTime
;
209 if (ctx
->BeginEndCount
>0) {
210 avgvertices
= (GLdouble
) ctx
->VertexCount
/ (GLdouble
) ctx
->BeginEndCount
;
216 overhead
= ctx
->BeginEndTime
- ctx
->VertexTime
- ctx
->PointTime
217 - ctx
->LineTime
- ctx
->PolygonTime
;
220 printf(" Count Time (s) Rate (/s) \n");
221 printf("--------------------------------------------------------\n");
222 printf("glBegin/glEnd %7d %8.3f %10.3f\n",
223 ctx
->BeginEndCount
, ctx
->BeginEndTime
, beginendrate
);
224 printf(" vertexes transformed %7d %8.3f %10.3f\n",
225 ctx
->VertexCount
, ctx
->VertexTime
, vertexrate
);
226 printf(" points rasterized %7d %8.3f %10.3f\n",
227 ctx
->PointCount
, ctx
->PointTime
, pointrate
);
228 printf(" lines rasterized %7d %8.3f %10.3f\n",
229 ctx
->LineCount
, ctx
->LineTime
, linerate
);
230 printf(" polygons rasterized %7d %8.3f %10.3f\n",
231 ctx
->PolygonCount
, ctx
->PolygonTime
, polygonrate
);
232 printf(" overhead %8.3f\n", overhead
);
233 printf("glClear %7d %8.3f %10.3f\n",
234 ctx
->ClearCount
, ctx
->ClearTime
, clearrate
);
235 printf("SwapBuffers %7d %8.3f %10.3f\n",
236 ctx
->SwapCount
, ctx
->SwapTime
, swaprate
);
239 printf("Average number of vertices per begin/end: %8.3f\n", avgvertices
);
247 /**********************************************************************/
248 /***** GL Visual allocation/destruction *****/
249 /**********************************************************************/
253 * Allocate a new GLvisual object.
254 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
255 * alphaFlag - alloc software alpha buffers?
256 * dbFlag - double buffering?
257 * stereoFlag - stereo buffer?
258 * depthBits - requested bits per depth buffer value
259 * Any value in [0, 32] is acceptable but the actual
260 * depth type will be GLushort or GLuint as needed.
261 * stencilBits - requested minimum bits per stencil buffer value
262 * accumBits - requested minimum bits per accum buffer component
263 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
264 * red/green/blue/alphaBits - number of bits per color component
265 * in frame buffer for RGB(A) mode.
266 * We always use 8 in core Mesa though.
267 * Return: pointer to new GLvisual or NULL if requested parameters can't
271 _mesa_create_visual( GLboolean rgbFlag
,
274 GLboolean stereoFlag
,
283 GLint accumGreenBits
,
285 GLint accumAlphaBits
,
290 /* This is to catch bad values from device drivers not updated for
291 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
292 * bad value now (a 1-bit depth buffer!?!).
294 assert(depthBits
== 0 || depthBits
> 1);
296 if (depthBits
< 0 || depthBits
> 32) {
299 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
302 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
305 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
308 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
311 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
315 vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
320 vis
->RGBAflag
= rgbFlag
;
321 vis
->DBflag
= dbFlag
;
322 vis
->StereoFlag
= stereoFlag
;
323 vis
->RedBits
= redBits
;
324 vis
->GreenBits
= greenBits
;
325 vis
->BlueBits
= blueBits
;
326 vis
->AlphaBits
= alphaFlag
? (8 * sizeof(GLubyte
)) : alphaBits
;
328 vis
->IndexBits
= indexBits
;
329 vis
->DepthBits
= depthBits
;
330 vis
->AccumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
331 vis
->AccumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
332 vis
->AccumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
333 vis
->AccumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
334 vis
->StencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
336 vis
->SoftwareAlpha
= alphaFlag
;
338 if (depthBits
== 0) {
339 /* Special case. Even if we don't have a depth buffer we need
340 * good values for DepthMax for Z vertex transformation purposes.
343 vis
->DepthMaxF
= 1.0F
;
346 vis
->DepthMax
= (1 << depthBits
) - 1;
347 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
354 /* This function should no longer be used. Use _mesa_create_visual() instead */
355 GLvisual
*gl_create_visual( GLboolean rgbFlag
,
358 GLboolean stereoFlag
,
368 return _mesa_create_visual(rgbFlag
, alphaFlag
, dbFlag
, stereoFlag
,
369 redBits
, greenBits
, blueBits
, alphaBits
,
370 indexBits
, depthBits
, stencilBits
,
371 accumBits
, accumBits
, accumBits
, accumBits
, 0);
376 _mesa_destroy_visual( GLvisual
*vis
)
383 void gl_destroy_visual( GLvisual
*vis
)
385 _mesa_destroy_visual(vis
);
390 /**********************************************************************/
391 /***** GL Framebuffer allocation/destruction *****/
392 /**********************************************************************/
396 * Create a new framebuffer. A GLframebuffer is a struct which
397 * encapsulates the depth, stencil and accum buffers and related
399 * Input: visual - a GLvisual pointer
400 * softwareDepth - create/use a software depth buffer?
401 * softwareStencil - create/use a software stencil buffer?
402 * softwareAccum - create/use a software accum buffer?
403 * softwareAlpha - create/use a software alpha buffer?
405 * Return: pointer to new GLframebuffer struct or NULL if error.
407 GLframebuffer
*gl_create_framebuffer( GLvisual
*visual
,
408 GLboolean softwareDepth
,
409 GLboolean softwareStencil
,
410 GLboolean softwareAccum
,
411 GLboolean softwareAlpha
)
413 GLframebuffer
*buffer
;
415 buffer
= CALLOC_STRUCT(gl_frame_buffer
);
421 if (softwareDepth
) {
422 assert(visual
->DepthBits
> 0);
424 if (softwareStencil
) {
425 assert(visual
->StencilBits
> 0);
428 assert(visual
->RGBAflag
);
429 assert(visual
->AccumRedBits
> 0);
430 assert(visual
->AccumGreenBits
> 0);
431 assert(visual
->AccumBlueBits
> 0);
434 assert(visual
->RGBAflag
);
435 assert(visual
->AlphaBits
> 0);
438 buffer
->Visual
= visual
;
439 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
440 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
441 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
442 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
450 * Free a framebuffer struct and its buffers.
452 void gl_destroy_framebuffer( GLframebuffer
*buffer
)
455 if (buffer
->DepthBuffer
) {
456 FREE( buffer
->DepthBuffer
);
459 FREE( buffer
->Accum
);
461 if (buffer
->Stencil
) {
462 FREE( buffer
->Stencil
);
464 if (buffer
->FrontLeftAlpha
) {
465 FREE( buffer
->FrontLeftAlpha
);
467 if (buffer
->BackLeftAlpha
) {
468 FREE( buffer
->BackLeftAlpha
);
470 if (buffer
->FrontRightAlpha
) {
471 FREE( buffer
->FrontRightAlpha
);
473 if (buffer
->BackRightAlpha
) {
474 FREE( buffer
->BackRightAlpha
);
482 /**********************************************************************/
483 /***** Context allocation, initialization, destroying *****/
484 /**********************************************************************/
487 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
491 * This function just calls all the various one-time-init functions in Mesa.
493 static void one_time_init( void )
495 static GLboolean alreadyCalled
= GL_FALSE
;
496 _glthread_LOCK_MUTEX(OneTimeLock
);
497 if (!alreadyCalled
) {
498 /* do some implementation tests */
499 assert( sizeof(GLbyte
) == 1 );
500 assert( sizeof(GLshort
) >= 2 );
501 assert( sizeof(GLint
) >= 4 );
502 assert( sizeof(GLubyte
) == 1 );
503 assert( sizeof(GLushort
) >= 2 );
504 assert( sizeof(GLuint
) >= 4 );
513 gl_init_transformation();
519 if (getenv("MESA_DEBUG")) {
520 _glapi_noop_enable_warnings(GL_TRUE
);
523 _glapi_noop_enable_warnings(GL_FALSE
);
526 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
527 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
530 alreadyCalled
= GL_TRUE
;
532 _glthread_UNLOCK_MUTEX(OneTimeLock
);
538 * Allocate and initialize a shared context state structure.
540 static struct gl_shared_state
*alloc_shared_state( void )
543 struct gl_shared_state
*ss
;
544 GLboolean outOfMemory
;
546 ss
= CALLOC_STRUCT(gl_shared_state
);
550 ss
->DisplayList
= _mesa_NewHashTable();
552 ss
->TexObjects
= _mesa_NewHashTable();
554 /* Default Texture objects */
555 outOfMemory
= GL_FALSE
;
556 for (d
= 1 ; d
<= 3 ; d
++) {
557 ss
->DefaultD
[d
] = gl_alloc_texture_object(ss
, 0, d
);
558 if (!ss
->DefaultD
[d
]) {
559 outOfMemory
= GL_TRUE
;
562 ss
->DefaultD
[d
]->RefCount
++; /* don't free if not in use */
565 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
566 /* Ran out of memory at some point. Free everything and return NULL */
568 _mesa_DeleteHashTable(ss
->DisplayList
);
570 _mesa_DeleteHashTable(ss
->TexObjects
);
572 gl_free_texture_object(ss
, ss
->DefaultD
[1]);
574 gl_free_texture_object(ss
, ss
->DefaultD
[2]);
576 gl_free_texture_object(ss
, ss
->DefaultD
[3]);
587 * Deallocate a shared state context and all children structures.
589 static void free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
591 /* Free display lists */
593 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
595 gl_destroy_list(ctx
, list
);
601 _mesa_DeleteHashTable(ss
->DisplayList
);
603 /* Free texture objects */
604 while (ss
->TexObjectList
)
606 if (ctx
->Driver
.DeleteTexture
)
607 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
608 /* this function removes from linked list too! */
609 gl_free_texture_object(ss
, ss
->TexObjectList
);
611 _mesa_DeleteHashTable(ss
->TexObjects
);
619 * Initialize the nth light. Note that the defaults for light 0 are
620 * different than the other lights.
622 static void init_light( struct gl_light
*l
, GLuint n
)
624 make_empty_list( l
);
626 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
628 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
629 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
632 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
633 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
635 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
636 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
637 l
->SpotExponent
= 0.0;
638 gl_compute_spot_exp_table( l
);
639 l
->SpotCutoff
= 180.0;
640 l
->CosCutoff
= 0.0; /* KW: -ve values not admitted */
641 l
->ConstantAttenuation
= 1.0;
642 l
->LinearAttenuation
= 0.0;
643 l
->QuadraticAttenuation
= 0.0;
644 l
->Enabled
= GL_FALSE
;
649 static void init_lightmodel( struct gl_lightmodel
*lm
)
651 ASSIGN_4V( lm
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
652 lm
->LocalViewer
= GL_FALSE
;
653 lm
->TwoSide
= GL_FALSE
;
654 lm
->ColorControl
= GL_SINGLE_COLOR
;
658 static void init_material( struct gl_material
*m
)
660 ASSIGN_4V( m
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
661 ASSIGN_4V( m
->Diffuse
, 0.8, 0.8, 0.8, 1.0 );
662 ASSIGN_4V( m
->Specular
, 0.0, 0.0, 0.0, 1.0 );
663 ASSIGN_4V( m
->Emission
, 0.0, 0.0, 0.0, 1.0 );
667 m
->SpecularIndex
= 1;
672 static void init_texture_unit( GLcontext
*ctx
, GLuint unit
)
674 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
676 texUnit
->EnvMode
= GL_MODULATE
;
677 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
678 texUnit
->TexGenEnabled
= 0;
679 texUnit
->GenModeS
= GL_EYE_LINEAR
;
680 texUnit
->GenModeT
= GL_EYE_LINEAR
;
681 texUnit
->GenModeR
= GL_EYE_LINEAR
;
682 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
683 /* Yes, these plane coefficients are correct! */
684 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
685 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
686 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
687 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
688 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
689 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
690 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
691 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
693 texUnit
->CurrentD
[1] = ctx
->Shared
->DefaultD
[1];
694 texUnit
->CurrentD
[2] = ctx
->Shared
->DefaultD
[2];
695 texUnit
->CurrentD
[3] = ctx
->Shared
->DefaultD
[3];
699 static void init_fallback_arrays( GLcontext
*ctx
)
701 struct gl_client_array
*cl
;
704 cl
= &ctx
->Fallback
.Normal
;
709 cl
->Ptr
= (void *) ctx
->Current
.Normal
;
712 cl
= &ctx
->Fallback
.Color
;
714 cl
->Type
= GL_UNSIGNED_BYTE
;
717 cl
->Ptr
= (void *) ctx
->Current
.ByteColor
;
720 cl
= &ctx
->Fallback
.Index
;
722 cl
->Type
= GL_UNSIGNED_INT
;
725 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
728 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
729 cl
= &ctx
->Fallback
.TexCoord
[i
];
734 cl
->Ptr
= (void *) ctx
->Current
.Texcoord
[i
];
738 cl
= &ctx
->Fallback
.EdgeFlag
;
740 cl
->Type
= GL_UNSIGNED_BYTE
;
743 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
748 /* Initialize a 1-D evaluator map */
749 static void init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
754 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
758 map
->Points
[i
] = initial
[i
];
763 /* Initialize a 2-D evaluator map */
764 static void init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
772 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
776 map
->Points
[i
] = initial
[i
];
781 static void init_color_table( struct gl_color_table
*p
)
788 p
->IntFormat
= GL_RGBA
;
794 p
->IntensitySize
= 0;
795 p
->LuminanceSize
= 0;
800 * Initialize the attribute groups in a GLcontext.
802 static void init_attrib_groups( GLcontext
*ctx
)
808 /* Constants, may be overriden by device drivers */
809 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
810 ctx
->Const
.MaxTextureSize
= 1 << (MAX_TEXTURE_LEVELS
- 1);
811 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
812 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
813 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
814 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
815 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
816 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
817 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
818 ctx
->Const
.PointSizeGranularity
= POINT_SIZE_GRANULARITY
;
819 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
820 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
821 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
822 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
823 ctx
->Const
.LineWidthGranularity
= LINE_WIDTH_GRANULARITY
;
824 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
826 /* Modelview matrix */
827 gl_matrix_ctr( &ctx
->ModelView
);
828 gl_matrix_alloc_inv( &ctx
->ModelView
);
830 ctx
->ModelViewStackDepth
= 0;
831 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
832 gl_matrix_ctr( &ctx
->ModelViewStack
[i
] );
833 gl_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
836 /* Projection matrix - need inv for user clipping in clip space*/
837 gl_matrix_ctr( &ctx
->ProjectionMatrix
);
838 gl_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
840 gl_matrix_ctr( &ctx
->ModelProjectMatrix
);
841 gl_matrix_ctr( &ctx
->ModelProjectWinMatrix
);
842 ctx
->ModelProjectWinMatrixUptodate
= GL_FALSE
;
844 ctx
->ProjectionStackDepth
= 0;
845 ctx
->NearFarStack
[0][0] = 1.0; /* These values seem weird by make */
846 ctx
->NearFarStack
[0][1] = 0.0; /* sense mathematically. */
848 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
849 gl_matrix_ctr( &ctx
->ProjectionStack
[i
] );
850 gl_matrix_alloc_inv( &ctx
->ProjectionStack
[i
] );
854 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
855 gl_matrix_ctr( &ctx
->TextureMatrix
[i
] );
856 ctx
->TextureStackDepth
[i
] = 0;
857 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
858 ctx
->TextureStack
[i
][j
].inv
= 0;
863 gl_matrix_ctr(&ctx
->ColorMatrix
);
864 ctx
->ColorStackDepth
= 0;
865 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
866 gl_matrix_ctr(&ctx
->ColorStack
[j
]);
869 /* Accumulate buffer group */
870 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
872 /* Color buffer group */
873 ctx
->Color
.IndexMask
= 0xffffffff;
874 ctx
->Color
.ColorMask
[0] = 0xff;
875 ctx
->Color
.ColorMask
[1] = 0xff;
876 ctx
->Color
.ColorMask
[2] = 0xff;
877 ctx
->Color
.ColorMask
[3] = 0xff;
878 ctx
->Color
.SWmasking
= GL_FALSE
;
879 ctx
->Color
.ClearIndex
= 0;
880 ASSIGN_4V( ctx
->Color
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
881 ctx
->Color
.DrawBuffer
= GL_FRONT
;
882 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
883 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
884 ctx
->Color
.AlphaRef
= 0;
885 ctx
->Color
.BlendEnabled
= GL_FALSE
;
886 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
887 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
888 ctx
->Color
.BlendSrcA
= GL_ONE
;
889 ctx
->Color
.BlendDstA
= GL_ZERO
;
890 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
891 ctx
->Color
.BlendFunc
= NULL
; /* this pointer set only when needed */
892 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
893 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
894 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
895 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
896 ctx
->Color
.LogicOp
= GL_COPY
;
897 ctx
->Color
.DitherFlag
= GL_TRUE
;
898 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
901 ASSIGN_4V( ctx
->Current
.ByteColor
, 255, 255, 255, 255);
902 ctx
->Current
.Index
= 1;
903 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
904 ASSIGN_4V( ctx
->Current
.Texcoord
[i
], 0.0, 0.0, 0.0, 1.0 );
905 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
906 ctx
->Current
.RasterDistance
= 0.0;
907 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
908 ctx
->Current
.RasterIndex
= 1;
909 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
910 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
911 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
912 ctx
->Current
.RasterPosValid
= GL_TRUE
;
913 ctx
->Current
.EdgeFlag
= GL_TRUE
;
914 ASSIGN_3V( ctx
->Current
.Normal
, 0.0, 0.0, 1.0 );
915 ctx
->Current
.Primitive
= (GLenum
) (GL_POLYGON
+ 1);
917 ctx
->Current
.Flag
= (VERT_NORM
|VERT_INDEX
|VERT_RGBA
|VERT_EDGE
|
918 VERT_TEX0_1
|VERT_TEX1_1
|VERT_MATERIAL
);
920 init_fallback_arrays( ctx
);
922 /* Depth buffer group */
923 ctx
->Depth
.Test
= GL_FALSE
;
924 ctx
->Depth
.Clear
= 1.0;
925 ctx
->Depth
.Func
= GL_LESS
;
926 ctx
->Depth
.Mask
= GL_TRUE
;
927 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
929 /* Evaluators group */
930 ctx
->Eval
.Map1Color4
= GL_FALSE
;
931 ctx
->Eval
.Map1Index
= GL_FALSE
;
932 ctx
->Eval
.Map1Normal
= GL_FALSE
;
933 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
934 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
935 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
936 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
937 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
938 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
939 ctx
->Eval
.Map2Color4
= GL_FALSE
;
940 ctx
->Eval
.Map2Index
= GL_FALSE
;
941 ctx
->Eval
.Map2Normal
= GL_FALSE
;
942 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
943 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
944 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
945 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
946 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
947 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
948 ctx
->Eval
.AutoNormal
= GL_FALSE
;
949 ctx
->Eval
.MapGrid1un
= 1;
950 ctx
->Eval
.MapGrid1u1
= 0.0;
951 ctx
->Eval
.MapGrid1u2
= 1.0;
952 ctx
->Eval
.MapGrid2un
= 1;
953 ctx
->Eval
.MapGrid2vn
= 1;
954 ctx
->Eval
.MapGrid2u1
= 0.0;
955 ctx
->Eval
.MapGrid2u2
= 1.0;
956 ctx
->Eval
.MapGrid2v1
= 0.0;
957 ctx
->Eval
.MapGrid2v2
= 1.0;
961 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
962 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
963 static GLfloat index
[1] = { 1.0 };
964 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
965 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
967 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
968 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
969 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
970 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
971 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
972 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
973 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
974 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
975 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
977 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
978 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
979 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
980 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
981 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
982 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
983 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
984 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
985 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
989 ctx
->Fog
.Enabled
= GL_FALSE
;
990 ctx
->Fog
.Mode
= GL_EXP
;
991 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
992 ctx
->Fog
.Index
= 0.0;
993 ctx
->Fog
.Density
= 1.0;
994 ctx
->Fog
.Start
= 0.0;
998 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
999 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
1000 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
1001 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
1002 ctx
->Hint
.Fog
= GL_DONT_CARE
;
1004 ctx
->Hint
.AllowDrawWin
= GL_TRUE
;
1005 ctx
->Hint
.AllowDrawFrg
= GL_TRUE
;
1006 ctx
->Hint
.AllowDrawMem
= GL_TRUE
;
1007 ctx
->Hint
.StrictLighting
= GL_TRUE
;
1009 /* Histogram group */
1010 ctx
->Histogram
.Width
= 0;
1011 ctx
->Histogram
.Format
= GL_RGBA
;
1012 ctx
->Histogram
.Sink
= GL_FALSE
;
1013 ctx
->Histogram
.RedSize
= 0xffffffff;
1014 ctx
->Histogram
.GreenSize
= 0xffffffff;
1015 ctx
->Histogram
.BlueSize
= 0xffffffff;
1016 ctx
->Histogram
.AlphaSize
= 0xffffffff;
1017 ctx
->Histogram
.LuminanceSize
= 0xffffffff;
1018 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
1019 ctx
->Histogram
.Count
[i
][0] = 0;
1020 ctx
->Histogram
.Count
[i
][1] = 0;
1021 ctx
->Histogram
.Count
[i
][2] = 0;
1022 ctx
->Histogram
.Count
[i
][3] = 0;
1026 ctx
->MinMax
.Format
= GL_RGBA
;
1027 ctx
->MinMax
.Sink
= GL_FALSE
;
1028 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
1029 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
1030 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
1031 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
1036 gl_pipeline_init( ctx
);
1040 gl_extensions_ctr( ctx
);
1042 ctx
->AllowVertexCull
= CLIP_CULLED_BIT
;
1044 /* Lighting group */
1045 for (i
=0;i
<MAX_LIGHTS
;i
++) {
1046 init_light( &ctx
->Light
.Light
[i
], i
);
1048 make_empty_list( &ctx
->Light
.EnabledList
);
1050 init_lightmodel( &ctx
->Light
.Model
);
1051 init_material( &ctx
->Light
.Material
[0] );
1052 init_material( &ctx
->Light
.Material
[1] );
1053 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
1054 ctx
->Light
.Enabled
= GL_FALSE
;
1055 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
1056 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
1057 ctx
->Light
.ColorMaterialBitmask
1058 = gl_material_bitmask( ctx
,
1060 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
1062 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1064 /* Lighting miscellaneous */
1065 ctx
->ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1066 make_empty_list( ctx
->ShineTabList
);
1067 for (i
= 0 ; i
< 10 ; i
++) {
1068 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1071 insert_at_tail( ctx
->ShineTabList
, s
);
1073 for (i
= 0 ; i
< 4 ; i
++) {
1074 ctx
->ShineTable
[i
] = ctx
->ShineTabList
->prev
;
1075 ctx
->ShineTable
[i
]->refcount
++;
1080 ctx
->Line
.SmoothFlag
= GL_FALSE
;
1081 ctx
->Line
.StippleFlag
= GL_FALSE
;
1082 ctx
->Line
.Width
= 1.0;
1083 ctx
->Line
.StipplePattern
= 0xffff;
1084 ctx
->Line
.StippleFactor
= 1;
1086 /* Display List group */
1087 ctx
->List
.ListBase
= 0;
1090 ctx
->Pixel
.RedBias
= 0.0;
1091 ctx
->Pixel
.RedScale
= 1.0;
1092 ctx
->Pixel
.GreenBias
= 0.0;
1093 ctx
->Pixel
.GreenScale
= 1.0;
1094 ctx
->Pixel
.BlueBias
= 0.0;
1095 ctx
->Pixel
.BlueScale
= 1.0;
1096 ctx
->Pixel
.AlphaBias
= 0.0;
1097 ctx
->Pixel
.AlphaScale
= 1.0;
1098 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_FALSE
;
1099 ctx
->Pixel
.DepthBias
= 0.0;
1100 ctx
->Pixel
.DepthScale
= 1.0;
1101 ctx
->Pixel
.IndexOffset
= 0;
1102 ctx
->Pixel
.IndexShift
= 0;
1103 ctx
->Pixel
.ZoomX
= 1.0;
1104 ctx
->Pixel
.ZoomY
= 1.0;
1105 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
1106 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
1107 ctx
->Pixel
.MapStoSsize
= 1;
1108 ctx
->Pixel
.MapItoIsize
= 1;
1109 ctx
->Pixel
.MapItoRsize
= 1;
1110 ctx
->Pixel
.MapItoGsize
= 1;
1111 ctx
->Pixel
.MapItoBsize
= 1;
1112 ctx
->Pixel
.MapItoAsize
= 1;
1113 ctx
->Pixel
.MapRtoRsize
= 1;
1114 ctx
->Pixel
.MapGtoGsize
= 1;
1115 ctx
->Pixel
.MapBtoBsize
= 1;
1116 ctx
->Pixel
.MapAtoAsize
= 1;
1117 ctx
->Pixel
.MapStoS
[0] = 0;
1118 ctx
->Pixel
.MapItoI
[0] = 0;
1119 ctx
->Pixel
.MapItoR
[0] = 0.0;
1120 ctx
->Pixel
.MapItoG
[0] = 0.0;
1121 ctx
->Pixel
.MapItoB
[0] = 0.0;
1122 ctx
->Pixel
.MapItoA
[0] = 0.0;
1123 ctx
->Pixel
.MapItoR8
[0] = 0;
1124 ctx
->Pixel
.MapItoG8
[0] = 0;
1125 ctx
->Pixel
.MapItoB8
[0] = 0;
1126 ctx
->Pixel
.MapItoA8
[0] = 0;
1127 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1128 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1129 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1130 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1131 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
1132 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
1133 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
1134 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1135 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1136 ctx
->Pixel
.PostColorMatrixRedBias
= 0.0;
1137 ctx
->Pixel
.PostColorMatrixRedScale
= 1.0;
1138 ctx
->Pixel
.PostColorMatrixGreenBias
= 0.0;
1139 ctx
->Pixel
.PostColorMatrixGreenScale
= 1.0;
1140 ctx
->Pixel
.PostColorMatrixBlueBias
= 0.0;
1141 ctx
->Pixel
.PostColorMatrixBlueScale
= 1.0;
1142 ctx
->Pixel
.PostColorMatrixAlphaBias
= 0.0;
1143 ctx
->Pixel
.PostColorMatrixAlphaScale
= 1.0;
1144 ctx
->Pixel
.ColorTableScale
[0] = 1.0F
;
1145 ctx
->Pixel
.ColorTableScale
[1] = 1.0F
;
1146 ctx
->Pixel
.ColorTableScale
[2] = 1.0F
;
1147 ctx
->Pixel
.ColorTableScale
[3] = 1.0F
;
1148 ctx
->Pixel
.ColorTableBias
[0] = 0.0F
;
1149 ctx
->Pixel
.ColorTableBias
[1] = 0.0F
;
1150 ctx
->Pixel
.ColorTableBias
[2] = 0.0F
;
1151 ctx
->Pixel
.ColorTableBias
[3] = 0.0F
;
1152 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1153 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1154 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1157 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1158 ctx
->Point
.Size
= 1.0;
1159 ctx
->Point
.Params
[0] = 1.0;
1160 ctx
->Point
.Params
[1] = 0.0;
1161 ctx
->Point
.Params
[2] = 0.0;
1162 ctx
->Point
.Attenuated
= GL_FALSE
;
1163 ctx
->Point
.MinSize
= 0.0;
1164 ctx
->Point
.MaxSize
= (GLfloat
) MAX_POINT_SIZE
;
1165 ctx
->Point
.Threshold
= 1.0;
1168 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1169 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1170 ctx
->Polygon
.FrontFace
= GL_CCW
;
1171 ctx
->Polygon
.FrontBit
= 0;
1172 ctx
->Polygon
.FrontMode
= GL_FILL
;
1173 ctx
->Polygon
.BackMode
= GL_FILL
;
1174 ctx
->Polygon
.Unfilled
= GL_FALSE
;
1175 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1176 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1177 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1178 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1179 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1180 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1181 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1183 /* Polygon Stipple group */
1184 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1187 ctx
->Scissor
.Enabled
= GL_FALSE
;
1190 ctx
->Scissor
.Width
= 0;
1191 ctx
->Scissor
.Height
= 0;
1194 ctx
->Stencil
.Enabled
= GL_FALSE
;
1195 ctx
->Stencil
.Function
= GL_ALWAYS
;
1196 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1197 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1198 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1199 ctx
->Stencil
.Ref
= 0;
1200 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1201 ctx
->Stencil
.Clear
= 0;
1202 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1205 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1206 ctx
->Texture
.CurrentTransformUnit
= 0; /* multitexture */
1207 ctx
->Texture
.Enabled
= 0;
1208 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1209 init_texture_unit( ctx
, i
);
1210 init_color_table(&ctx
->Texture
.Palette
);
1212 /* Transformation group */
1213 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1214 ctx
->Transform
.Normalize
= GL_FALSE
;
1215 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1216 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1217 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1218 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1220 ctx
->Transform
.AnyClip
= GL_FALSE
;
1222 /* Viewport group */
1223 ctx
->Viewport
.X
= 0;
1224 ctx
->Viewport
.Y
= 0;
1225 ctx
->Viewport
.Width
= 0;
1226 ctx
->Viewport
.Height
= 0;
1227 ctx
->Viewport
.Near
= 0.0;
1228 ctx
->Viewport
.Far
= 1.0;
1229 gl_matrix_ctr(&ctx
->Viewport
.WindowMap
);
1233 ctx
->Viewport
.WindowMap
.m
[Sz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1234 ctx
->Viewport
.WindowMap
.m
[Tz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1238 ctx
->Viewport
.WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1239 ctx
->Viewport
.WindowMap
.type
= MATRIX_3D_NO_ROT
;
1242 ctx
->Array
.Vertex
.Size
= 4;
1243 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1244 ctx
->Array
.Vertex
.Stride
= 0;
1245 ctx
->Array
.Vertex
.StrideB
= 0;
1246 ctx
->Array
.Vertex
.Ptr
= NULL
;
1247 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1248 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1249 ctx
->Array
.Normal
.Stride
= 0;
1250 ctx
->Array
.Normal
.StrideB
= 0;
1251 ctx
->Array
.Normal
.Ptr
= NULL
;
1252 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1253 ctx
->Array
.Color
.Size
= 4;
1254 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1255 ctx
->Array
.Color
.Stride
= 0;
1256 ctx
->Array
.Color
.StrideB
= 0;
1257 ctx
->Array
.Color
.Ptr
= NULL
;
1258 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1259 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1260 ctx
->Array
.Index
.Stride
= 0;
1261 ctx
->Array
.Index
.StrideB
= 0;
1262 ctx
->Array
.Index
.Ptr
= NULL
;
1263 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1264 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1265 ctx
->Array
.TexCoord
[i
].Size
= 4;
1266 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1267 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1268 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1269 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1270 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1272 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1273 ctx
->Array
.EdgeFlag
.Stride
= 0;
1274 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1275 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1276 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1277 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1279 /* Pixel transfer */
1280 ctx
->Pack
.Alignment
= 4;
1281 ctx
->Pack
.RowLength
= 0;
1282 ctx
->Pack
.ImageHeight
= 0;
1283 ctx
->Pack
.SkipPixels
= 0;
1284 ctx
->Pack
.SkipRows
= 0;
1285 ctx
->Pack
.SkipImages
= 0;
1286 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1287 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1288 ctx
->Unpack
.Alignment
= 4;
1289 ctx
->Unpack
.RowLength
= 0;
1290 ctx
->Unpack
.ImageHeight
= 0;
1291 ctx
->Unpack
.SkipPixels
= 0;
1292 ctx
->Unpack
.SkipRows
= 0;
1293 ctx
->Unpack
.SkipImages
= 0;
1294 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1295 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1298 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1299 ctx
->Feedback
.Buffer
= NULL
;
1300 ctx
->Feedback
.BufferSize
= 0;
1301 ctx
->Feedback
.Count
= 0;
1303 /* Selection/picking */
1304 ctx
->Select
.Buffer
= NULL
;
1305 ctx
->Select
.BufferSize
= 0;
1306 ctx
->Select
.BufferCount
= 0;
1307 ctx
->Select
.Hits
= 0;
1308 ctx
->Select
.NameStackDepth
= 0;
1310 /* Optimized Accum buffer */
1311 ctx
->IntegerAccumMode
= GL_TRUE
;
1312 ctx
->IntegerAccumScaler
= 0.0;
1314 /* Renderer and client attribute stacks */
1315 ctx
->AttribStackDepth
= 0;
1316 ctx
->ClientAttribStackDepth
= 0;
1320 ctx
->ExecuteFlag
= GL_TRUE
;
1321 ctx
->CompileFlag
= GL_FALSE
;
1322 ctx
->CurrentListPtr
= NULL
;
1323 ctx
->CurrentBlock
= NULL
;
1324 ctx
->CurrentListNum
= 0;
1325 ctx
->CurrentPos
= 0;
1328 init_color_table(&ctx
->ColorTable
);
1329 init_color_table(&ctx
->ProxyColorTable
);
1330 init_color_table(&ctx
->PostConvolutionColorTable
);
1331 init_color_table(&ctx
->ProxyPostConvolutionColorTable
);
1332 init_color_table(&ctx
->PostColorMatrixColorTable
);
1333 init_color_table(&ctx
->ProxyPostColorMatrixColorTable
);
1336 ctx
->NewState
= NEW_ALL
;
1337 ctx
->RenderMode
= GL_RENDER
;
1338 ctx
->StippleCounter
= 0;
1339 ctx
->NeedNormals
= GL_FALSE
;
1340 ctx
->DoViewportMapping
= GL_TRUE
;
1342 ctx
->NeedEyeCoords
= GL_FALSE
;
1343 ctx
->NeedEyeNormals
= GL_FALSE
;
1344 ctx
->vb_proj_matrix
= &ctx
->ModelProjectMatrix
;
1346 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1348 ctx
->CatchSignals
= GL_TRUE
;
1349 ctx
->OcclusionResult
= GL_FALSE
;
1350 ctx
->OcclusionResultSaved
= GL_FALSE
;
1352 /* For debug/development only */
1353 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1354 ctx
->FirstTimeCurrent
= GL_TRUE
;
1356 /* Dither disable */
1357 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1358 if (ctx
->NoDither
) {
1359 if (getenv("MESA_DEBUG")) {
1360 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1362 ctx
->Color
.DitherFlag
= GL_FALSE
;
1370 * Allocate the proxy textures. If we run out of memory part way through
1371 * the allocations clean up and return GL_FALSE.
1372 * Return: GL_TRUE=success, GL_FALSE=failure
1374 static GLboolean
alloc_proxy_textures( GLcontext
*ctx
)
1376 GLboolean out_of_memory
;
1379 ctx
->Texture
.Proxy1D
= gl_alloc_texture_object(NULL
, 0, 1);
1380 if (!ctx
->Texture
.Proxy1D
) {
1384 ctx
->Texture
.Proxy2D
= gl_alloc_texture_object(NULL
, 0, 2);
1385 if (!ctx
->Texture
.Proxy2D
) {
1386 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1390 ctx
->Texture
.Proxy3D
= gl_alloc_texture_object(NULL
, 0, 3);
1391 if (!ctx
->Texture
.Proxy3D
) {
1392 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1393 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1397 out_of_memory
= GL_FALSE
;
1398 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1399 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1400 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1401 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1402 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1403 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1404 || !ctx
->Texture
.Proxy3D
->Image
[i
]) {
1405 out_of_memory
= GL_TRUE
;
1408 if (out_of_memory
) {
1409 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1410 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1411 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1413 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1414 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1416 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1417 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1420 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1421 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1422 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1433 * Initialize a GLcontext struct.
1435 GLboolean
gl_initialize_context_data( GLcontext
*ctx
,
1437 GLcontext
*share_list
,
1441 (void) direct
; /* not used */
1443 /* misc one-time initializations */
1446 ctx
->DriverCtx
= driver_ctx
;
1447 ctx
->Visual
= visual
;
1448 ctx
->DrawBuffer
= NULL
;
1449 ctx
->ReadBuffer
= NULL
;
1451 ctx
->VB
= gl_vb_create_for_immediate( ctx
);
1456 ctx
->input
= ctx
->VB
->IM
;
1458 ctx
->PB
= gl_alloc_pb();
1466 /* share the group of display lists of another context */
1467 ctx
->Shared
= share_list
->Shared
;
1470 /* allocate new group of display lists */
1471 ctx
->Shared
= alloc_shared_state();
1479 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1480 ctx
->Shared
->RefCount
++;
1481 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1483 init_attrib_groups( ctx
);
1485 gl_reset_vb( ctx
->VB
);
1486 gl_reset_input( ctx
);
1488 if (visual
->DBflag
) {
1489 ctx
->Color
.DrawBuffer
= GL_BACK
;
1490 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1491 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1492 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1493 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1496 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1497 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1498 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1499 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1500 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1504 init_timings( ctx
);
1507 if (!alloc_proxy_textures(ctx
)) {
1508 free_shared_state(ctx
, ctx
->Shared
);
1515 /* setup API dispatch tables */
1516 ctx
->Exec
= (struct _glapi_table
*) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1517 ctx
->Save
= (struct _glapi_table
*) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1518 if (!ctx
->Exec
|| !ctx
->Save
) {
1519 free_shared_state(ctx
, ctx
->Shared
);
1526 _mesa_init_exec_table( ctx
->Exec
);
1527 _mesa_init_dlist_table( ctx
->Save
);
1528 ctx
->CurrentDispatch
= ctx
->Exec
;
1536 * Allocate and initialize a GLcontext structure.
1537 * Input: visual - a GLvisual pointer
1538 * sharelist - another context to share display lists with or NULL
1539 * driver_ctx - pointer to device driver's context state struct
1540 * Return: pointer to a new gl_context struct or NULL if error.
1542 GLcontext
*gl_create_context( GLvisual
*visual
,
1543 GLcontext
*share_list
,
1547 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1552 if (gl_initialize_context_data(ctx
, visual
, share_list
,
1553 driver_ctx
, direct
)) {
1565 * Free the data associated with the given context.
1566 * But don't free() the GLcontext struct itself!
1568 void gl_free_context_data( GLcontext
*ctx
)
1570 struct gl_shine_tab
*s
, *tmps
;
1573 /* if we're destroying the current context, unbind it first */
1574 if (ctx
== gl_get_current_context()) {
1575 gl_make_current(NULL
, NULL
);
1579 if (getenv("MESA_PROFILE")) {
1580 print_timings( ctx
);
1584 gl_matrix_dtr( &ctx
->ModelView
);
1585 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
1586 gl_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1588 gl_matrix_dtr( &ctx
->ProjectionMatrix
);
1589 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
1590 gl_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1592 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1593 gl_matrix_dtr( &ctx
->TextureMatrix
[i
] );
1594 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
1595 gl_matrix_dtr( &ctx
->TextureStack
[i
][j
] );
1601 if(ctx
->input
!= ctx
->VB
->IM
)
1602 gl_immediate_free( ctx
->input
);
1604 gl_vb_free( ctx
->VB
);
1606 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1607 ctx
->Shared
->RefCount
--;
1608 assert(ctx
->Shared
->RefCount
>= 0);
1609 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1610 if (ctx
->Shared
->RefCount
== 0) {
1611 /* free shared state */
1612 free_shared_state( ctx
, ctx
->Shared
);
1615 foreach_s( s
, tmps
, ctx
->ShineTabList
) {
1618 FREE( ctx
->ShineTabList
);
1620 /* Free proxy texture objects */
1621 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1622 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1623 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1625 /* Free evaluator data */
1626 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1627 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1628 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1629 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1630 if (ctx
->EvalMap
.Map1Index
.Points
)
1631 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1632 if (ctx
->EvalMap
.Map1Color4
.Points
)
1633 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1634 if (ctx
->EvalMap
.Map1Normal
.Points
)
1635 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1636 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1637 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1638 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1639 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1640 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1641 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1642 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1643 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1645 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1646 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1647 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1648 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1649 if (ctx
->EvalMap
.Map2Index
.Points
)
1650 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1651 if (ctx
->EvalMap
.Map2Color4
.Points
)
1652 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1653 if (ctx
->EvalMap
.Map2Normal
.Points
)
1654 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1655 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1656 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1657 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1658 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1659 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1660 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1661 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1662 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1664 /* Free cache of immediate buffers. */
1665 while (ctx
->nr_im_queued
-- > 0) {
1666 struct immediate
* next
= ctx
->freed_im_queue
->next
;
1667 FREE( ctx
->freed_im_queue
);
1668 ctx
->freed_im_queue
= next
;
1670 gl_extensions_dtr(ctx
);
1679 * Destroy a GLcontext structure.
1681 void gl_destroy_context( GLcontext
*ctx
)
1684 gl_free_context_data(ctx
);
1685 FREE( (void *) ctx
);
1692 * Called by the driver after both the context and driver are fully
1693 * initialized. Currently just reads the config file.
1695 void gl_context_initialize( GLcontext
*ctx
)
1697 gl_read_config_file( ctx
);
1703 * Copy attribute groups from one context to another.
1704 * Input: src - source context
1705 * dst - destination context
1706 * mask - bitwise OR of GL_*_BIT flags
1708 void gl_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1710 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1711 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1713 if (mask
& GL_COLOR_BUFFER_BIT
) {
1714 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1716 if (mask
& GL_CURRENT_BIT
) {
1717 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1719 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1720 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1722 if (mask
& GL_ENABLE_BIT
) {
1725 if (mask
& GL_EVAL_BIT
) {
1726 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1728 if (mask
& GL_FOG_BIT
) {
1729 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1731 if (mask
& GL_HINT_BIT
) {
1732 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1734 if (mask
& GL_LIGHTING_BIT
) {
1735 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1736 /* gl_reinit_light_attrib( &dst->Light ); */
1738 if (mask
& GL_LINE_BIT
) {
1739 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1741 if (mask
& GL_LIST_BIT
) {
1742 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1744 if (mask
& GL_PIXEL_MODE_BIT
) {
1745 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1747 if (mask
& GL_POINT_BIT
) {
1748 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1750 if (mask
& GL_POLYGON_BIT
) {
1751 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1753 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1754 /* Use loop instead of MEMCPY due to problem with Portland Group's
1755 * C compiler. Reported by John Stone.
1758 for (i
=0;i
<32;i
++) {
1759 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1762 if (mask
& GL_SCISSOR_BIT
) {
1763 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1765 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1766 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1768 if (mask
& GL_TEXTURE_BIT
) {
1769 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1771 if (mask
& GL_TRANSFORM_BIT
) {
1772 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1774 if (mask
& GL_VIEWPORT_BIT
) {
1775 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1781 * Set the current context, binding the given frame buffer to the context.
1783 void gl_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1785 gl_make_current2( newCtx
, buffer
, buffer
);
1790 * Bind the given context to the given draw-buffer and read-buffer
1791 * and make it the current context for this thread.
1793 void gl_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1794 GLframebuffer
*readBuffer
)
1797 GLcontext
*oldCtx
= gl_get_context();
1799 /* Flush the old context
1802 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx
, "gl_make_current");
1804 /* unbind frame buffers from context */
1805 if (oldCtx
->DrawBuffer
) {
1806 oldCtx
->DrawBuffer
= NULL
;
1808 if (oldCtx
->ReadBuffer
) {
1809 oldCtx
->ReadBuffer
= NULL
;
1814 /* We call this function periodically (just here for now) in
1815 * order to detect when multithreading has begun.
1817 _glapi_check_multithread();
1819 _glapi_set_context((void *) newCtx
);
1820 ASSERT(gl_get_current_context() == newCtx
);
1822 SET_IMMEDIATE(newCtx
, newCtx
->input
);
1823 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1826 _glapi_set_dispatch(NULL
); /* none current */
1829 if (MESA_VERBOSE
) fprintf(stderr
, "gl_make_current()\n");
1831 if (newCtx
&& drawBuffer
&& readBuffer
) {
1832 /* TODO: check if newCtx and buffer's visual match??? */
1833 newCtx
->DrawBuffer
= drawBuffer
;
1834 newCtx
->ReadBuffer
= readBuffer
;
1835 newCtx
->NewState
= NEW_ALL
; /* just to be safe */
1836 gl_update_state( newCtx
);
1839 /* We can use this to help debug user's problems. Tell the to set
1840 * the MESA_INFO env variable before running their app. Then the
1841 * first time each context is made current we'll print some useful
1844 if (newCtx
&& newCtx
->FirstTimeCurrent
) {
1845 if (getenv("MESA_INFO")) {
1846 fprintf(stderr
, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION
));
1847 fprintf(stderr
, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER
));
1848 fprintf(stderr
, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR
));
1849 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS
));
1850 #if defined(THREADS)
1851 fprintf(stderr
, "Mesa thread-safe: YES\n");
1853 fprintf(stderr
, "Mesa thread-safe: NO\n");
1855 #if defined(USE_X86_ASM)
1856 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1858 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1861 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1868 * Return current context handle for the calling thread.
1869 * This isn't the fastest way to get the current context.
1870 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1872 GLcontext
*gl_get_current_context( void )
1874 return (GLcontext
*) _glapi_get_context();
1880 * This should be called by device drivers just before they do a
1881 * swapbuffers. Any pending rendering commands will be executed.
1884 _mesa_swapbuffers(GLcontext
*ctx
)
1886 FLUSH_VB( ctx
, "swap buffers" );
1892 * Return pointer to this context's current API dispatch table.
1893 * It'll either be the immediate-mode execute dispatcher or the
1894 * display list compile dispatcher.
1896 struct _glapi_table
*
1897 _mesa_get_dispatch(GLcontext
*ctx
)
1899 return ctx
->CurrentDispatch
;
1904 /**********************************************************************/
1905 /***** Miscellaneous functions *****/
1906 /**********************************************************************/
1910 * This function is called when the Mesa user has stumbled into a code
1911 * path which may not be implemented fully or correctly.
1913 void gl_problem( const GLcontext
*ctx
, const char *s
)
1915 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
1916 fprintf( stderr
, "Report to mesa-bugs@mesa3d.org\n" );
1923 * This is called to inform the user that he or she has tried to do
1924 * something illogical or if there's likely a bug in their program
1925 * (like enabled depth testing without a depth buffer).
1927 void gl_warning( const GLcontext
*ctx
, const char *s
)
1933 if (getenv("MESA_DEBUG")) {
1941 fprintf( stderr
, "Mesa warning: %s\n", s
);
1949 * Compile an error into current display list.
1951 void gl_compile_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1953 if (ctx
->CompileFlag
)
1954 gl_save_error( ctx
, error
, s
);
1956 if (ctx
->ExecuteFlag
)
1957 gl_error( ctx
, error
, s
);
1963 * This is Mesa's error handler. Normally, all that's done is the updating
1964 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1965 * environment variable "MESA_DEBUG" is defined then a real error message
1966 * is printed to stderr.
1967 * Input: error - the error value
1968 * s - a diagnostic string
1970 void gl_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1977 if (getenv("MESA_DEBUG")) {
1990 strcpy( errstr
, "GL_NO_ERROR" );
1992 case GL_INVALID_VALUE
:
1993 strcpy( errstr
, "GL_INVALID_VALUE" );
1995 case GL_INVALID_ENUM
:
1996 strcpy( errstr
, "GL_INVALID_ENUM" );
1998 case GL_INVALID_OPERATION
:
1999 strcpy( errstr
, "GL_INVALID_OPERATION" );
2001 case GL_STACK_OVERFLOW
:
2002 strcpy( errstr
, "GL_STACK_OVERFLOW" );
2004 case GL_STACK_UNDERFLOW
:
2005 strcpy( errstr
, "GL_STACK_UNDERFLOW" );
2007 case GL_OUT_OF_MEMORY
:
2008 strcpy( errstr
, "GL_OUT_OF_MEMORY" );
2011 strcpy( errstr
, "unknown" );
2014 fprintf( stderr
, "Mesa user error: %s in %s\n", errstr
, s
);
2017 if (ctx
->ErrorValue
==GL_NO_ERROR
) {
2018 ctx
->ErrorValue
= error
;
2021 /* Call device driver's error handler, if any. This is used on the Mac. */
2022 if (ctx
->Driver
.Error
) {
2023 (*ctx
->Driver
.Error
)( ctx
);
2030 _mesa_Finish( void )
2032 GET_CURRENT_CONTEXT(ctx
);
2033 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFinish");
2034 if (ctx
->Driver
.Finish
) {
2035 (*ctx
->Driver
.Finish
)( ctx
);
2044 GET_CURRENT_CONTEXT(ctx
);
2045 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFlush");
2046 if (ctx
->Driver
.Flush
) {
2047 (*ctx
->Driver
.Flush
)( ctx
);