1 /* $Id: context.c,v 1.60 2000/04/17 17:57:04 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 #include "extensions.h"
46 #include "glapinoop.h"
57 #include "simple_list.h"
61 #include "translate.h"
78 /**********************************************************************/
79 /***** Context and Thread management *****/
80 /**********************************************************************/
85 struct immediate
*_mesa_CurrentInput
= NULL
;
92 /**********************************************************************/
93 /***** Profiling functions *****/
94 /**********************************************************************/
98 #include <sys/times.h>
99 #include <sys/param.h>
103 * Return system time in seconds.
104 * NOTE: this implementation may not be very portable!
106 GLdouble
gl_time( void )
108 static GLdouble prev_time
= 0.0;
109 static GLdouble time
;
116 time
= (double)clk
/ (double)CLK_TCK
;
118 time
= (double)clk
/ (double)HZ
;
121 if (time
>prev_time
) {
131 * Reset the timing/profiling counters
133 static void init_timings( GLcontext
*ctx
)
135 ctx
->BeginEndCount
= 0;
136 ctx
->BeginEndTime
= 0.0;
137 ctx
->VertexCount
= 0;
138 ctx
->VertexTime
= 0.0;
140 ctx
->PointTime
= 0.0;
143 ctx
->PolygonCount
= 0;
144 ctx
->PolygonTime
= 0.0;
146 ctx
->ClearTime
= 0.0;
153 * Print the accumulated timing/profiling data.
155 static void print_timings( GLcontext
*ctx
)
157 GLdouble beginendrate
;
161 GLdouble polygonrate
;
165 GLdouble avgvertices
;
167 if (ctx
->BeginEndTime
>0.0) {
168 beginendrate
= ctx
->BeginEndCount
/ ctx
->BeginEndTime
;
173 if (ctx
->VertexTime
>0.0) {
174 vertexrate
= ctx
->VertexCount
/ ctx
->VertexTime
;
179 if (ctx
->PointTime
>0.0) {
180 pointrate
= ctx
->PointCount
/ ctx
->PointTime
;
185 if (ctx
->LineTime
>0.0) {
186 linerate
= ctx
->LineCount
/ ctx
->LineTime
;
191 if (ctx
->PolygonTime
>0.0) {
192 polygonrate
= ctx
->PolygonCount
/ ctx
->PolygonTime
;
197 if (ctx
->ClearTime
>0.0) {
198 clearrate
= ctx
->ClearCount
/ ctx
->ClearTime
;
203 if (ctx
->SwapTime
>0.0) {
204 swaprate
= ctx
->SwapCount
/ ctx
->SwapTime
;
210 if (ctx
->BeginEndCount
>0) {
211 avgvertices
= (GLdouble
) ctx
->VertexCount
/ (GLdouble
) ctx
->BeginEndCount
;
217 overhead
= ctx
->BeginEndTime
- ctx
->VertexTime
- ctx
->PointTime
218 - ctx
->LineTime
- ctx
->PolygonTime
;
221 printf(" Count Time (s) Rate (/s) \n");
222 printf("--------------------------------------------------------\n");
223 printf("glBegin/glEnd %7d %8.3f %10.3f\n",
224 ctx
->BeginEndCount
, ctx
->BeginEndTime
, beginendrate
);
225 printf(" vertexes transformed %7d %8.3f %10.3f\n",
226 ctx
->VertexCount
, ctx
->VertexTime
, vertexrate
);
227 printf(" points rasterized %7d %8.3f %10.3f\n",
228 ctx
->PointCount
, ctx
->PointTime
, pointrate
);
229 printf(" lines rasterized %7d %8.3f %10.3f\n",
230 ctx
->LineCount
, ctx
->LineTime
, linerate
);
231 printf(" polygons rasterized %7d %8.3f %10.3f\n",
232 ctx
->PolygonCount
, ctx
->PolygonTime
, polygonrate
);
233 printf(" overhead %8.3f\n", overhead
);
234 printf("glClear %7d %8.3f %10.3f\n",
235 ctx
->ClearCount
, ctx
->ClearTime
, clearrate
);
236 printf("SwapBuffers %7d %8.3f %10.3f\n",
237 ctx
->SwapCount
, ctx
->SwapTime
, swaprate
);
240 printf("Average number of vertices per begin/end: %8.3f\n", avgvertices
);
248 /**********************************************************************/
249 /***** GL Visual allocation/destruction *****/
250 /**********************************************************************/
254 * Allocate a new GLvisual object.
255 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
256 * alphaFlag - alloc software alpha buffers?
257 * dbFlag - double buffering?
258 * stereoFlag - stereo buffer?
259 * depthBits - requested bits per depth buffer value
260 * Any value in [0, 32] is acceptable but the actual
261 * depth type will be GLushort or GLuint as needed.
262 * stencilBits - requested minimum bits per stencil buffer value
263 * accumBits - requested minimum bits per accum buffer component
264 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
265 * red/green/blue/alphaBits - number of bits per color component
266 * in frame buffer for RGB(A) mode.
267 * We always use 8 in core Mesa though.
268 * Return: pointer to new GLvisual or NULL if requested parameters can't
272 _mesa_create_visual( GLboolean rgbFlag
,
275 GLboolean stereoFlag
,
284 GLint accumGreenBits
,
286 GLint accumAlphaBits
,
291 /* This is to catch bad values from device drivers not updated for
292 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
293 * bad value now (a 1-bit depth buffer!?!).
295 assert(depthBits
== 0 || depthBits
> 1);
297 if (depthBits
< 0 || depthBits
> 32) {
300 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
303 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
306 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
309 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
312 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
316 vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
321 vis
->RGBAflag
= rgbFlag
;
322 vis
->DBflag
= dbFlag
;
323 vis
->StereoFlag
= stereoFlag
;
324 vis
->RedBits
= redBits
;
325 vis
->GreenBits
= greenBits
;
326 vis
->BlueBits
= blueBits
;
327 vis
->AlphaBits
= alphaFlag
? (8 * sizeof(GLubyte
)) : alphaBits
;
329 vis
->IndexBits
= indexBits
;
330 vis
->DepthBits
= depthBits
;
331 vis
->AccumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
332 vis
->AccumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
333 vis
->AccumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
334 vis
->AccumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
335 vis
->StencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
337 vis
->SoftwareAlpha
= alphaFlag
;
339 if (depthBits
== 0) {
340 /* Special case. Even if we don't have a depth buffer we need
341 * good values for DepthMax for Z vertex transformation purposes.
344 vis
->DepthMaxF
= 1.0F
;
347 vis
->DepthMax
= (1 << depthBits
) - 1;
348 vis
->DepthMaxF
= (GLfloat
) vis
->DepthMax
;
355 /* This function should no longer be used. Use _mesa_create_visual() instead */
356 GLvisual
*gl_create_visual( GLboolean rgbFlag
,
359 GLboolean stereoFlag
,
369 return _mesa_create_visual(rgbFlag
, alphaFlag
, dbFlag
, stereoFlag
,
370 redBits
, greenBits
, blueBits
, alphaBits
,
371 indexBits
, depthBits
, stencilBits
,
372 accumBits
, accumBits
, accumBits
, accumBits
, 0);
377 _mesa_destroy_visual( GLvisual
*vis
)
384 void gl_destroy_visual( GLvisual
*vis
)
386 _mesa_destroy_visual(vis
);
391 /**********************************************************************/
392 /***** GL Framebuffer allocation/destruction *****/
393 /**********************************************************************/
397 * Create a new framebuffer. A GLframebuffer is a struct which
398 * encapsulates the depth, stencil and accum buffers and related
400 * Input: visual - a GLvisual pointer
401 * softwareDepth - create/use a software depth buffer?
402 * softwareStencil - create/use a software stencil buffer?
403 * softwareAccum - create/use a software accum buffer?
404 * softwareAlpha - create/use a software alpha buffer?
406 * Return: pointer to new GLframebuffer struct or NULL if error.
408 GLframebuffer
*gl_create_framebuffer( GLvisual
*visual
,
409 GLboolean softwareDepth
,
410 GLboolean softwareStencil
,
411 GLboolean softwareAccum
,
412 GLboolean softwareAlpha
)
414 GLframebuffer
*buffer
;
416 buffer
= CALLOC_STRUCT(gl_frame_buffer
);
422 if (softwareDepth
) {
423 assert(visual
->DepthBits
> 0);
425 if (softwareStencil
) {
426 assert(visual
->StencilBits
> 0);
429 assert(visual
->RGBAflag
);
430 assert(visual
->AccumRedBits
> 0);
431 assert(visual
->AccumGreenBits
> 0);
432 assert(visual
->AccumBlueBits
> 0);
435 assert(visual
->RGBAflag
);
436 assert(visual
->AlphaBits
> 0);
439 buffer
->Visual
= visual
;
440 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
441 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
442 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
443 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
451 * Free a framebuffer struct and its buffers.
453 void gl_destroy_framebuffer( GLframebuffer
*buffer
)
456 if (buffer
->DepthBuffer
) {
457 FREE( buffer
->DepthBuffer
);
460 FREE( buffer
->Accum
);
462 if (buffer
->Stencil
) {
463 FREE( buffer
->Stencil
);
465 if (buffer
->FrontLeftAlpha
) {
466 FREE( buffer
->FrontLeftAlpha
);
468 if (buffer
->BackLeftAlpha
) {
469 FREE( buffer
->BackLeftAlpha
);
471 if (buffer
->FrontRightAlpha
) {
472 FREE( buffer
->FrontRightAlpha
);
474 if (buffer
->BackRightAlpha
) {
475 FREE( buffer
->BackRightAlpha
);
483 /**********************************************************************/
484 /***** Context allocation, initialization, destroying *****/
485 /**********************************************************************/
488 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
492 * This function just calls all the various one-time-init functions in Mesa.
494 static void one_time_init( void )
496 static GLboolean alreadyCalled
= GL_FALSE
;
497 _glthread_LOCK_MUTEX(OneTimeLock
);
498 if (!alreadyCalled
) {
499 /* do some implementation tests */
500 assert( sizeof(GLbyte
) == 1 );
501 assert( sizeof(GLshort
) >= 2 );
502 assert( sizeof(GLint
) >= 4 );
503 assert( sizeof(GLubyte
) == 1 );
504 assert( sizeof(GLushort
) >= 2 );
505 assert( sizeof(GLuint
) >= 4 );
514 gl_init_transformation();
520 if (getenv("MESA_DEBUG")) {
521 _glapi_noop_enable_warnings(GL_TRUE
);
524 _glapi_noop_enable_warnings(GL_FALSE
);
527 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
528 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
531 alreadyCalled
= GL_TRUE
;
533 _glthread_UNLOCK_MUTEX(OneTimeLock
);
539 * Allocate and initialize a shared context state structure.
541 static struct gl_shared_state
*alloc_shared_state( void )
544 struct gl_shared_state
*ss
;
545 GLboolean outOfMemory
;
547 ss
= CALLOC_STRUCT(gl_shared_state
);
551 ss
->DisplayList
= _mesa_NewHashTable();
553 ss
->TexObjects
= _mesa_NewHashTable();
555 /* Default Texture objects */
556 outOfMemory
= GL_FALSE
;
557 for (d
= 1 ; d
<= 3 ; d
++) {
558 ss
->DefaultD
[d
] = gl_alloc_texture_object(ss
, 0, d
);
559 if (!ss
->DefaultD
[d
]) {
560 outOfMemory
= GL_TRUE
;
563 ss
->DefaultD
[d
]->RefCount
++; /* don't free if not in use */
566 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
567 /* Ran out of memory at some point. Free everything and return NULL */
569 _mesa_DeleteHashTable(ss
->DisplayList
);
571 _mesa_DeleteHashTable(ss
->TexObjects
);
573 gl_free_texture_object(ss
, ss
->DefaultD
[1]);
575 gl_free_texture_object(ss
, ss
->DefaultD
[2]);
577 gl_free_texture_object(ss
, ss
->DefaultD
[3]);
588 * Deallocate a shared state context and all children structures.
590 static void free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
592 /* Free display lists */
594 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
596 gl_destroy_list(ctx
, list
);
602 _mesa_DeleteHashTable(ss
->DisplayList
);
604 /* Free texture objects */
605 while (ss
->TexObjectList
)
607 if (ctx
->Driver
.DeleteTexture
)
608 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
609 /* this function removes from linked list too! */
610 gl_free_texture_object(ss
, ss
->TexObjectList
);
612 _mesa_DeleteHashTable(ss
->TexObjects
);
620 * Initialize the nth light. Note that the defaults for light 0 are
621 * different than the other lights.
623 static void init_light( struct gl_light
*l
, GLuint n
)
625 make_empty_list( l
);
627 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
629 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
630 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
633 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
634 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
636 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
637 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
638 l
->SpotExponent
= 0.0;
639 gl_compute_spot_exp_table( l
);
640 l
->SpotCutoff
= 180.0;
641 l
->CosCutoff
= 0.0; /* KW: -ve values not admitted */
642 l
->ConstantAttenuation
= 1.0;
643 l
->LinearAttenuation
= 0.0;
644 l
->QuadraticAttenuation
= 0.0;
645 l
->Enabled
= GL_FALSE
;
650 static void init_lightmodel( struct gl_lightmodel
*lm
)
652 ASSIGN_4V( lm
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
653 lm
->LocalViewer
= GL_FALSE
;
654 lm
->TwoSide
= GL_FALSE
;
655 lm
->ColorControl
= GL_SINGLE_COLOR
;
659 static void init_material( struct gl_material
*m
)
661 ASSIGN_4V( m
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
662 ASSIGN_4V( m
->Diffuse
, 0.8, 0.8, 0.8, 1.0 );
663 ASSIGN_4V( m
->Specular
, 0.0, 0.0, 0.0, 1.0 );
664 ASSIGN_4V( m
->Emission
, 0.0, 0.0, 0.0, 1.0 );
668 m
->SpecularIndex
= 1;
673 static void init_texture_unit( GLcontext
*ctx
, GLuint unit
)
675 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
677 texUnit
->EnvMode
= GL_MODULATE
;
678 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
679 texUnit
->TexGenEnabled
= 0;
680 texUnit
->GenModeS
= GL_EYE_LINEAR
;
681 texUnit
->GenModeT
= GL_EYE_LINEAR
;
682 texUnit
->GenModeR
= GL_EYE_LINEAR
;
683 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
684 /* Yes, these plane coefficients are correct! */
685 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
686 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
687 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
688 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
689 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
690 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
691 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
692 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
694 texUnit
->CurrentD
[1] = ctx
->Shared
->DefaultD
[1];
695 texUnit
->CurrentD
[2] = ctx
->Shared
->DefaultD
[2];
696 texUnit
->CurrentD
[3] = ctx
->Shared
->DefaultD
[3];
700 static void init_fallback_arrays( GLcontext
*ctx
)
702 struct gl_client_array
*cl
;
705 cl
= &ctx
->Fallback
.Normal
;
710 cl
->Ptr
= (void *) ctx
->Current
.Normal
;
713 cl
= &ctx
->Fallback
.Color
;
715 cl
->Type
= GL_UNSIGNED_BYTE
;
718 cl
->Ptr
= (void *) ctx
->Current
.ByteColor
;
721 cl
= &ctx
->Fallback
.Index
;
723 cl
->Type
= GL_UNSIGNED_INT
;
726 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
729 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
730 cl
= &ctx
->Fallback
.TexCoord
[i
];
735 cl
->Ptr
= (void *) ctx
->Current
.Texcoord
[i
];
739 cl
= &ctx
->Fallback
.EdgeFlag
;
741 cl
->Type
= GL_UNSIGNED_BYTE
;
744 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
749 /* Initialize a 1-D evaluator map */
750 static void init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
755 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
759 map
->Points
[i
] = initial
[i
];
764 /* Initialize a 2-D evaluator map */
765 static void init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
773 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
777 map
->Points
[i
] = initial
[i
];
783 * Initialize the attribute groups in a GLcontext.
785 static void init_attrib_groups( GLcontext
*ctx
)
791 /* Constants, may be overriden by device drivers */
792 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
793 ctx
->Const
.MaxTextureSize
= 1 << (MAX_TEXTURE_LEVELS
- 1);
794 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
795 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
796 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
797 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
798 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
799 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
800 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
801 ctx
->Const
.PointSizeGranularity
= POINT_SIZE_GRANULARITY
;
802 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
803 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
804 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
805 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
806 ctx
->Const
.LineWidthGranularity
= LINE_WIDTH_GRANULARITY
;
807 ctx
->Const
.NumAuxBuffers
= NUM_AUX_BUFFERS
;
808 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
810 /* Modelview matrix */
811 gl_matrix_ctr( &ctx
->ModelView
);
812 gl_matrix_alloc_inv( &ctx
->ModelView
);
814 ctx
->ModelViewStackDepth
= 0;
815 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
816 gl_matrix_ctr( &ctx
->ModelViewStack
[i
] );
817 gl_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
820 /* Projection matrix - need inv for user clipping in clip space*/
821 gl_matrix_ctr( &ctx
->ProjectionMatrix
);
822 gl_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
824 gl_matrix_ctr( &ctx
->ModelProjectMatrix
);
825 gl_matrix_ctr( &ctx
->ModelProjectWinMatrix
);
826 ctx
->ModelProjectWinMatrixUptodate
= GL_FALSE
;
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 ctx
->TextureStack
[i
][j
].inv
= 0;
847 gl_matrix_ctr(&ctx
->ColorMatrix
);
848 ctx
->ColorStackDepth
= 0;
849 for (j
= 0; j
< MAX_COLOR_STACK_DEPTH
- 1; j
++) {
850 gl_matrix_ctr(&ctx
->ColorStack
[j
]);
853 /* Accumulate buffer group */
854 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
856 /* Color buffer group */
857 ctx
->Color
.IndexMask
= 0xffffffff;
858 ctx
->Color
.ColorMask
[0] = 0xff;
859 ctx
->Color
.ColorMask
[1] = 0xff;
860 ctx
->Color
.ColorMask
[2] = 0xff;
861 ctx
->Color
.ColorMask
[3] = 0xff;
862 ctx
->Color
.SWmasking
= GL_FALSE
;
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
.SWLogicOpEnabled
= GL_FALSE
;
880 ctx
->Color
.LogicOp
= GL_COPY
;
881 ctx
->Color
.DitherFlag
= GL_TRUE
;
882 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
885 ASSIGN_4V( ctx
->Current
.ByteColor
, 255, 255, 255, 255);
886 ctx
->Current
.Index
= 1;
887 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
888 ASSIGN_4V( ctx
->Current
.Texcoord
[i
], 0.0, 0.0, 0.0, 1.0 );
889 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
890 ctx
->Current
.RasterDistance
= 0.0;
891 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
892 ctx
->Current
.RasterIndex
= 1;
893 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
894 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
895 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
896 ctx
->Current
.RasterPosValid
= GL_TRUE
;
897 ctx
->Current
.EdgeFlag
= GL_TRUE
;
898 ASSIGN_3V( ctx
->Current
.Normal
, 0.0, 0.0, 1.0 );
899 ctx
->Current
.Primitive
= (GLenum
) (GL_POLYGON
+ 1);
901 ctx
->Current
.Flag
= (VERT_NORM
|VERT_INDEX
|VERT_RGBA
|VERT_EDGE
|
902 VERT_TEX0_1
|VERT_TEX1_1
|VERT_MATERIAL
);
904 init_fallback_arrays( ctx
);
906 /* Depth buffer group */
907 ctx
->Depth
.Test
= GL_FALSE
;
908 ctx
->Depth
.Clear
= 1.0;
909 ctx
->Depth
.Func
= GL_LESS
;
910 ctx
->Depth
.Mask
= GL_TRUE
;
911 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
913 /* Evaluators group */
914 ctx
->Eval
.Map1Color4
= GL_FALSE
;
915 ctx
->Eval
.Map1Index
= GL_FALSE
;
916 ctx
->Eval
.Map1Normal
= GL_FALSE
;
917 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
918 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
919 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
920 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
921 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
922 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
923 ctx
->Eval
.Map2Color4
= GL_FALSE
;
924 ctx
->Eval
.Map2Index
= GL_FALSE
;
925 ctx
->Eval
.Map2Normal
= GL_FALSE
;
926 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
927 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
928 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
929 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
930 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
931 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
932 ctx
->Eval
.AutoNormal
= GL_FALSE
;
933 ctx
->Eval
.MapGrid1un
= 1;
934 ctx
->Eval
.MapGrid1u1
= 0.0;
935 ctx
->Eval
.MapGrid1u2
= 1.0;
936 ctx
->Eval
.MapGrid2un
= 1;
937 ctx
->Eval
.MapGrid2vn
= 1;
938 ctx
->Eval
.MapGrid2u1
= 0.0;
939 ctx
->Eval
.MapGrid2u2
= 1.0;
940 ctx
->Eval
.MapGrid2v1
= 0.0;
941 ctx
->Eval
.MapGrid2v2
= 1.0;
945 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
946 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
947 static GLfloat index
[1] = { 1.0 };
948 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
949 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
951 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
952 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
953 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
954 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
955 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
956 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
957 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
958 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
959 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
961 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
962 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
963 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
964 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
965 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
966 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
967 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
968 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
969 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
973 ctx
->Fog
.Enabled
= GL_FALSE
;
974 ctx
->Fog
.Mode
= GL_EXP
;
975 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
976 ctx
->Fog
.Index
= 0.0;
977 ctx
->Fog
.Density
= 1.0;
978 ctx
->Fog
.Start
= 0.0;
982 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
983 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
984 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
985 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
986 ctx
->Hint
.Fog
= GL_DONT_CARE
;
988 ctx
->Hint
.AllowDrawWin
= GL_TRUE
;
989 ctx
->Hint
.AllowDrawFrg
= GL_TRUE
;
990 ctx
->Hint
.AllowDrawMem
= GL_TRUE
;
991 ctx
->Hint
.StrictLighting
= GL_TRUE
;
993 /* Histogram group */
994 ctx
->Histogram
.Width
= 0;
995 ctx
->Histogram
.Format
= GL_RGBA
;
996 ctx
->Histogram
.Sink
= GL_FALSE
;
997 ctx
->Histogram
.RedSize
= 0xffffffff;
998 ctx
->Histogram
.GreenSize
= 0xffffffff;
999 ctx
->Histogram
.BlueSize
= 0xffffffff;
1000 ctx
->Histogram
.AlphaSize
= 0xffffffff;
1001 ctx
->Histogram
.LuminanceSize
= 0xffffffff;
1002 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
1003 ctx
->Histogram
.Count
[i
][0] = 0;
1004 ctx
->Histogram
.Count
[i
][1] = 0;
1005 ctx
->Histogram
.Count
[i
][2] = 0;
1006 ctx
->Histogram
.Count
[i
][3] = 0;
1010 ctx
->MinMax
.Format
= GL_RGBA
;
1011 ctx
->MinMax
.Sink
= GL_FALSE
;
1012 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
1013 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
1014 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
1015 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
1020 gl_pipeline_init( ctx
);
1024 gl_extensions_ctr( ctx
);
1026 ctx
->AllowVertexCull
= CLIP_CULLED_BIT
;
1028 /* Lighting group */
1029 for (i
=0;i
<MAX_LIGHTS
;i
++) {
1030 init_light( &ctx
->Light
.Light
[i
], i
);
1032 make_empty_list( &ctx
->Light
.EnabledList
);
1034 init_lightmodel( &ctx
->Light
.Model
);
1035 init_material( &ctx
->Light
.Material
[0] );
1036 init_material( &ctx
->Light
.Material
[1] );
1037 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
1038 ctx
->Light
.Enabled
= GL_FALSE
;
1039 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
1040 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
1041 ctx
->Light
.ColorMaterialBitmask
1042 = gl_material_bitmask( ctx
,
1044 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
1046 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1048 /* Lighting miscellaneous */
1049 ctx
->ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1050 make_empty_list( ctx
->ShineTabList
);
1051 for (i
= 0 ; i
< 10 ; i
++) {
1052 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1055 insert_at_tail( ctx
->ShineTabList
, s
);
1057 for (i
= 0 ; i
< 4 ; i
++) {
1058 ctx
->ShineTable
[i
] = ctx
->ShineTabList
->prev
;
1059 ctx
->ShineTable
[i
]->refcount
++;
1064 ctx
->Line
.SmoothFlag
= GL_FALSE
;
1065 ctx
->Line
.StippleFlag
= GL_FALSE
;
1066 ctx
->Line
.Width
= 1.0;
1067 ctx
->Line
.StipplePattern
= 0xffff;
1068 ctx
->Line
.StippleFactor
= 1;
1070 /* Display List group */
1071 ctx
->List
.ListBase
= 0;
1074 ctx
->Pixel
.RedBias
= 0.0;
1075 ctx
->Pixel
.RedScale
= 1.0;
1076 ctx
->Pixel
.GreenBias
= 0.0;
1077 ctx
->Pixel
.GreenScale
= 1.0;
1078 ctx
->Pixel
.BlueBias
= 0.0;
1079 ctx
->Pixel
.BlueScale
= 1.0;
1080 ctx
->Pixel
.AlphaBias
= 0.0;
1081 ctx
->Pixel
.AlphaScale
= 1.0;
1082 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_FALSE
;
1083 ctx
->Pixel
.DepthBias
= 0.0;
1084 ctx
->Pixel
.DepthScale
= 1.0;
1085 ctx
->Pixel
.IndexOffset
= 0;
1086 ctx
->Pixel
.IndexShift
= 0;
1087 ctx
->Pixel
.ZoomX
= 1.0;
1088 ctx
->Pixel
.ZoomY
= 1.0;
1089 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
1090 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
1091 ctx
->Pixel
.MapStoSsize
= 1;
1092 ctx
->Pixel
.MapItoIsize
= 1;
1093 ctx
->Pixel
.MapItoRsize
= 1;
1094 ctx
->Pixel
.MapItoGsize
= 1;
1095 ctx
->Pixel
.MapItoBsize
= 1;
1096 ctx
->Pixel
.MapItoAsize
= 1;
1097 ctx
->Pixel
.MapRtoRsize
= 1;
1098 ctx
->Pixel
.MapGtoGsize
= 1;
1099 ctx
->Pixel
.MapBtoBsize
= 1;
1100 ctx
->Pixel
.MapAtoAsize
= 1;
1101 ctx
->Pixel
.MapStoS
[0] = 0;
1102 ctx
->Pixel
.MapItoI
[0] = 0;
1103 ctx
->Pixel
.MapItoR
[0] = 0.0;
1104 ctx
->Pixel
.MapItoG
[0] = 0.0;
1105 ctx
->Pixel
.MapItoB
[0] = 0.0;
1106 ctx
->Pixel
.MapItoA
[0] = 0.0;
1107 ctx
->Pixel
.MapItoR8
[0] = 0;
1108 ctx
->Pixel
.MapItoG8
[0] = 0;
1109 ctx
->Pixel
.MapItoB8
[0] = 0;
1110 ctx
->Pixel
.MapItoA8
[0] = 0;
1111 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1112 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1113 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1114 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1115 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
1116 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
1117 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
1118 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1119 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
1120 ctx
->Pixel
.PostColorMatrixRedBias
= 0.0;
1121 ctx
->Pixel
.PostColorMatrixRedScale
= 1.0;
1122 ctx
->Pixel
.PostColorMatrixGreenBias
= 0.0;
1123 ctx
->Pixel
.PostColorMatrixGreenScale
= 1.0;
1124 ctx
->Pixel
.PostColorMatrixBlueBias
= 0.0;
1125 ctx
->Pixel
.PostColorMatrixBlueScale
= 1.0;
1126 ctx
->Pixel
.PostColorMatrixAlphaBias
= 0.0;
1127 ctx
->Pixel
.PostColorMatrixAlphaScale
= 1.0;
1128 ctx
->Pixel
.ColorTableScale
[0] = 1.0F
;
1129 ctx
->Pixel
.ColorTableScale
[1] = 1.0F
;
1130 ctx
->Pixel
.ColorTableScale
[2] = 1.0F
;
1131 ctx
->Pixel
.ColorTableScale
[3] = 1.0F
;
1132 ctx
->Pixel
.ColorTableBias
[0] = 0.0F
;
1133 ctx
->Pixel
.ColorTableBias
[1] = 0.0F
;
1134 ctx
->Pixel
.ColorTableBias
[2] = 0.0F
;
1135 ctx
->Pixel
.ColorTableBias
[3] = 0.0F
;
1136 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
1137 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
1138 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
1141 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1142 ctx
->Point
.Size
= 1.0;
1143 ctx
->Point
.Params
[0] = 1.0;
1144 ctx
->Point
.Params
[1] = 0.0;
1145 ctx
->Point
.Params
[2] = 0.0;
1146 ctx
->Point
.Attenuated
= GL_FALSE
;
1147 ctx
->Point
.MinSize
= 0.0;
1148 ctx
->Point
.MaxSize
= (GLfloat
) MAX_POINT_SIZE
;
1149 ctx
->Point
.Threshold
= 1.0;
1152 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1153 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1154 ctx
->Polygon
.FrontFace
= GL_CCW
;
1155 ctx
->Polygon
.FrontBit
= 0;
1156 ctx
->Polygon
.FrontMode
= GL_FILL
;
1157 ctx
->Polygon
.BackMode
= GL_FILL
;
1158 ctx
->Polygon
.Unfilled
= GL_FALSE
;
1159 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1160 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1161 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1162 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1163 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1164 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1165 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1167 /* Polygon Stipple group */
1168 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1171 ctx
->Scissor
.Enabled
= GL_FALSE
;
1174 ctx
->Scissor
.Width
= 0;
1175 ctx
->Scissor
.Height
= 0;
1178 ctx
->Stencil
.Enabled
= GL_FALSE
;
1179 ctx
->Stencil
.Function
= GL_ALWAYS
;
1180 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1181 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1182 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1183 ctx
->Stencil
.Ref
= 0;
1184 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1185 ctx
->Stencil
.Clear
= 0;
1186 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1189 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1190 ctx
->Texture
.CurrentTransformUnit
= 0; /* multitexture */
1191 ctx
->Texture
.Enabled
= 0;
1192 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1193 init_texture_unit( ctx
, i
);
1194 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1196 /* Transformation group */
1197 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1198 ctx
->Transform
.Normalize
= GL_FALSE
;
1199 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1200 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1201 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1202 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1204 ctx
->Transform
.AnyClip
= GL_FALSE
;
1206 /* Viewport group */
1207 ctx
->Viewport
.X
= 0;
1208 ctx
->Viewport
.Y
= 0;
1209 ctx
->Viewport
.Width
= 0;
1210 ctx
->Viewport
.Height
= 0;
1211 ctx
->Viewport
.Near
= 0.0;
1212 ctx
->Viewport
.Far
= 1.0;
1213 gl_matrix_ctr(&ctx
->Viewport
.WindowMap
);
1217 ctx
->Viewport
.WindowMap
.m
[Sz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1218 ctx
->Viewport
.WindowMap
.m
[Tz
] = 0.5 * ctx
->Visual
->DepthMaxF
;
1222 ctx
->Viewport
.WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1223 ctx
->Viewport
.WindowMap
.type
= MATRIX_3D_NO_ROT
;
1226 ctx
->Array
.Vertex
.Size
= 4;
1227 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1228 ctx
->Array
.Vertex
.Stride
= 0;
1229 ctx
->Array
.Vertex
.StrideB
= 0;
1230 ctx
->Array
.Vertex
.Ptr
= NULL
;
1231 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1232 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1233 ctx
->Array
.Normal
.Stride
= 0;
1234 ctx
->Array
.Normal
.StrideB
= 0;
1235 ctx
->Array
.Normal
.Ptr
= NULL
;
1236 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1237 ctx
->Array
.Color
.Size
= 4;
1238 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1239 ctx
->Array
.Color
.Stride
= 0;
1240 ctx
->Array
.Color
.StrideB
= 0;
1241 ctx
->Array
.Color
.Ptr
= NULL
;
1242 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1243 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1244 ctx
->Array
.Index
.Stride
= 0;
1245 ctx
->Array
.Index
.StrideB
= 0;
1246 ctx
->Array
.Index
.Ptr
= NULL
;
1247 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1248 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1249 ctx
->Array
.TexCoord
[i
].Size
= 4;
1250 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1251 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1252 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1253 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1254 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1256 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1257 ctx
->Array
.EdgeFlag
.Stride
= 0;
1258 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1259 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1260 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1261 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1263 /* Pixel transfer */
1264 ctx
->Pack
.Alignment
= 4;
1265 ctx
->Pack
.RowLength
= 0;
1266 ctx
->Pack
.ImageHeight
= 0;
1267 ctx
->Pack
.SkipPixels
= 0;
1268 ctx
->Pack
.SkipRows
= 0;
1269 ctx
->Pack
.SkipImages
= 0;
1270 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1271 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1272 ctx
->Unpack
.Alignment
= 4;
1273 ctx
->Unpack
.RowLength
= 0;
1274 ctx
->Unpack
.ImageHeight
= 0;
1275 ctx
->Unpack
.SkipPixels
= 0;
1276 ctx
->Unpack
.SkipRows
= 0;
1277 ctx
->Unpack
.SkipImages
= 0;
1278 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1279 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1282 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1283 ctx
->Feedback
.Buffer
= NULL
;
1284 ctx
->Feedback
.BufferSize
= 0;
1285 ctx
->Feedback
.Count
= 0;
1287 /* Selection/picking */
1288 ctx
->Select
.Buffer
= NULL
;
1289 ctx
->Select
.BufferSize
= 0;
1290 ctx
->Select
.BufferCount
= 0;
1291 ctx
->Select
.Hits
= 0;
1292 ctx
->Select
.NameStackDepth
= 0;
1294 /* Optimized Accum buffer */
1295 ctx
->IntegerAccumMode
= GL_TRUE
;
1296 ctx
->IntegerAccumScaler
= 0.0;
1298 /* Renderer and client attribute stacks */
1299 ctx
->AttribStackDepth
= 0;
1300 ctx
->ClientAttribStackDepth
= 0;
1304 ctx
->ExecuteFlag
= GL_TRUE
;
1305 ctx
->CompileFlag
= GL_FALSE
;
1306 ctx
->CurrentListPtr
= NULL
;
1307 ctx
->CurrentBlock
= NULL
;
1308 ctx
->CurrentListNum
= 0;
1309 ctx
->CurrentPos
= 0;
1312 _mesa_init_colortable(&ctx
->ColorTable
);
1313 _mesa_init_colortable(&ctx
->ProxyColorTable
);
1314 _mesa_init_colortable(&ctx
->PostConvolutionColorTable
);
1315 _mesa_init_colortable(&ctx
->ProxyPostConvolutionColorTable
);
1316 _mesa_init_colortable(&ctx
->PostColorMatrixColorTable
);
1317 _mesa_init_colortable(&ctx
->ProxyPostColorMatrixColorTable
);
1320 ctx
->NewState
= NEW_ALL
;
1321 ctx
->RenderMode
= GL_RENDER
;
1322 ctx
->StippleCounter
= 0;
1323 ctx
->NeedNormals
= GL_FALSE
;
1324 ctx
->DoViewportMapping
= GL_TRUE
;
1326 ctx
->NeedEyeCoords
= GL_FALSE
;
1327 ctx
->NeedEyeNormals
= GL_FALSE
;
1328 ctx
->vb_proj_matrix
= &ctx
->ModelProjectMatrix
;
1330 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1332 ctx
->CatchSignals
= GL_TRUE
;
1333 ctx
->OcclusionResult
= GL_FALSE
;
1334 ctx
->OcclusionResultSaved
= GL_FALSE
;
1336 /* For debug/development only */
1337 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1338 ctx
->FirstTimeCurrent
= GL_TRUE
;
1340 /* Dither disable */
1341 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1342 if (ctx
->NoDither
) {
1343 if (getenv("MESA_DEBUG")) {
1344 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1346 ctx
->Color
.DitherFlag
= GL_FALSE
;
1354 * Allocate the proxy textures. If we run out of memory part way through
1355 * the allocations clean up and return GL_FALSE.
1356 * Return: GL_TRUE=success, GL_FALSE=failure
1358 static GLboolean
alloc_proxy_textures( GLcontext
*ctx
)
1360 GLboolean out_of_memory
;
1363 ctx
->Texture
.Proxy1D
= gl_alloc_texture_object(NULL
, 0, 1);
1364 if (!ctx
->Texture
.Proxy1D
) {
1368 ctx
->Texture
.Proxy2D
= gl_alloc_texture_object(NULL
, 0, 2);
1369 if (!ctx
->Texture
.Proxy2D
) {
1370 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1374 ctx
->Texture
.Proxy3D
= gl_alloc_texture_object(NULL
, 0, 3);
1375 if (!ctx
->Texture
.Proxy3D
) {
1376 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1377 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1381 out_of_memory
= GL_FALSE
;
1382 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1383 ctx
->Texture
.Proxy1D
->Image
[i
] = _mesa_alloc_texture_image();
1384 ctx
->Texture
.Proxy2D
->Image
[i
] = _mesa_alloc_texture_image();
1385 ctx
->Texture
.Proxy3D
->Image
[i
] = _mesa_alloc_texture_image();
1386 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1387 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1388 || !ctx
->Texture
.Proxy3D
->Image
[i
]) {
1389 out_of_memory
= GL_TRUE
;
1392 if (out_of_memory
) {
1393 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1394 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1395 _mesa_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1397 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1398 _mesa_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1400 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1401 _mesa_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1404 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1405 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1406 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1417 * Initialize a GLcontext struct.
1419 GLboolean
gl_initialize_context_data( GLcontext
*ctx
,
1421 GLcontext
*share_list
,
1425 (void) direct
; /* not used */
1427 /* misc one-time initializations */
1430 ctx
->DriverCtx
= driver_ctx
;
1431 ctx
->Visual
= visual
;
1432 ctx
->DrawBuffer
= NULL
;
1433 ctx
->ReadBuffer
= NULL
;
1435 ctx
->VB
= gl_vb_create_for_immediate( ctx
);
1440 ctx
->input
= ctx
->VB
->IM
;
1442 ctx
->PB
= gl_alloc_pb();
1450 /* share the group of display lists of another context */
1451 ctx
->Shared
= share_list
->Shared
;
1454 /* allocate new group of display lists */
1455 ctx
->Shared
= alloc_shared_state();
1463 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1464 ctx
->Shared
->RefCount
++;
1465 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1467 init_attrib_groups( ctx
);
1469 gl_reset_vb( ctx
->VB
);
1470 gl_reset_input( ctx
);
1472 if (visual
->DBflag
) {
1473 ctx
->Color
.DrawBuffer
= GL_BACK
;
1474 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1475 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1476 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1477 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1480 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1481 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1482 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1483 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1484 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1488 init_timings( ctx
);
1491 if (!alloc_proxy_textures(ctx
)) {
1492 free_shared_state(ctx
, ctx
->Shared
);
1499 /* setup API dispatch tables */
1500 ctx
->Exec
= (struct _glapi_table
*) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1501 ctx
->Save
= (struct _glapi_table
*) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1502 if (!ctx
->Exec
|| !ctx
->Save
) {
1503 free_shared_state(ctx
, ctx
->Shared
);
1510 _mesa_init_exec_table( ctx
->Exec
);
1511 _mesa_init_dlist_table( ctx
->Save
);
1512 ctx
->CurrentDispatch
= ctx
->Exec
;
1520 * Allocate and initialize a GLcontext structure.
1521 * Input: visual - a GLvisual pointer
1522 * sharelist - another context to share display lists with or NULL
1523 * driver_ctx - pointer to device driver's context state struct
1524 * Return: pointer to a new gl_context struct or NULL if error.
1526 GLcontext
*gl_create_context( GLvisual
*visual
,
1527 GLcontext
*share_list
,
1531 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1536 if (gl_initialize_context_data(ctx
, visual
, share_list
,
1537 driver_ctx
, direct
)) {
1549 * Free the data associated with the given context.
1550 * But don't free() the GLcontext struct itself!
1552 void gl_free_context_data( GLcontext
*ctx
)
1554 struct gl_shine_tab
*s
, *tmps
;
1557 /* if we're destroying the current context, unbind it first */
1558 if (ctx
== gl_get_current_context()) {
1559 gl_make_current(NULL
, NULL
);
1563 if (getenv("MESA_PROFILE")) {
1564 print_timings( ctx
);
1568 gl_matrix_dtr( &ctx
->ModelView
);
1569 for (i
= 0; i
< MAX_MODELVIEW_STACK_DEPTH
- 1; i
++) {
1570 gl_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1572 gl_matrix_dtr( &ctx
->ProjectionMatrix
);
1573 for (i
= 0; i
< MAX_PROJECTION_STACK_DEPTH
- 1; i
++) {
1574 gl_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1576 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1577 gl_matrix_dtr( &ctx
->TextureMatrix
[i
] );
1578 for (j
= 0; j
< MAX_TEXTURE_STACK_DEPTH
- 1; j
++) {
1579 gl_matrix_dtr( &ctx
->TextureStack
[i
][j
] );
1585 if (ctx
->input
!= ctx
->VB
->IM
)
1586 gl_immediate_free( ctx
->input
);
1588 gl_vb_free( ctx
->VB
);
1590 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1591 ctx
->Shared
->RefCount
--;
1592 assert(ctx
->Shared
->RefCount
>= 0);
1593 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1594 if (ctx
->Shared
->RefCount
== 0) {
1595 /* free shared state */
1596 free_shared_state( ctx
, ctx
->Shared
);
1599 foreach_s( s
, tmps
, ctx
->ShineTabList
) {
1602 FREE( ctx
->ShineTabList
);
1604 /* Free proxy texture objects */
1605 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1606 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1607 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1609 /* Free evaluator data */
1610 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1611 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1612 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1613 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1614 if (ctx
->EvalMap
.Map1Index
.Points
)
1615 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1616 if (ctx
->EvalMap
.Map1Color4
.Points
)
1617 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1618 if (ctx
->EvalMap
.Map1Normal
.Points
)
1619 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1620 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1621 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1622 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1623 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1624 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1625 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1626 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1627 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1629 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1630 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1631 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1632 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1633 if (ctx
->EvalMap
.Map2Index
.Points
)
1634 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1635 if (ctx
->EvalMap
.Map2Color4
.Points
)
1636 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1637 if (ctx
->EvalMap
.Map2Normal
.Points
)
1638 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1639 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1640 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1641 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1642 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1643 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1644 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1645 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1646 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1648 _mesa_free_colortable_data( &ctx
->ColorTable
);
1649 _mesa_free_colortable_data( &ctx
->PostConvolutionColorTable
);
1650 _mesa_free_colortable_data( &ctx
->PostColorMatrixColorTable
);
1651 _mesa_free_colortable_data( &ctx
->Texture
.Palette
);
1653 /* Free cache of immediate buffers. */
1654 while (ctx
->nr_im_queued
-- > 0) {
1655 struct immediate
* next
= ctx
->freed_im_queue
->next
;
1656 FREE( ctx
->freed_im_queue
);
1657 ctx
->freed_im_queue
= next
;
1659 gl_extensions_dtr(ctx
);
1668 * Destroy a GLcontext structure.
1670 void gl_destroy_context( GLcontext
*ctx
)
1673 gl_free_context_data(ctx
);
1674 FREE( (void *) ctx
);
1681 * Called by the driver after both the context and driver are fully
1682 * initialized. Currently just reads the config file.
1684 void gl_context_initialize( GLcontext
*ctx
)
1686 gl_read_config_file( ctx
);
1692 * Copy attribute groups from one context to another.
1693 * Input: src - source context
1694 * dst - destination context
1695 * mask - bitwise OR of GL_*_BIT flags
1697 void gl_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1699 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1700 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1702 if (mask
& GL_COLOR_BUFFER_BIT
) {
1703 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1705 if (mask
& GL_CURRENT_BIT
) {
1706 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1708 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1709 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1711 if (mask
& GL_ENABLE_BIT
) {
1714 if (mask
& GL_EVAL_BIT
) {
1715 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1717 if (mask
& GL_FOG_BIT
) {
1718 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1720 if (mask
& GL_HINT_BIT
) {
1721 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1723 if (mask
& GL_LIGHTING_BIT
) {
1724 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1725 /* gl_reinit_light_attrib( &dst->Light ); */
1727 if (mask
& GL_LINE_BIT
) {
1728 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1730 if (mask
& GL_LIST_BIT
) {
1731 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1733 if (mask
& GL_PIXEL_MODE_BIT
) {
1734 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1736 if (mask
& GL_POINT_BIT
) {
1737 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1739 if (mask
& GL_POLYGON_BIT
) {
1740 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1742 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1743 /* Use loop instead of MEMCPY due to problem with Portland Group's
1744 * C compiler. Reported by John Stone.
1747 for (i
=0;i
<32;i
++) {
1748 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1751 if (mask
& GL_SCISSOR_BIT
) {
1752 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1754 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1755 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1757 if (mask
& GL_TEXTURE_BIT
) {
1758 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1760 if (mask
& GL_TRANSFORM_BIT
) {
1761 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1763 if (mask
& GL_VIEWPORT_BIT
) {
1764 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1770 * Set the current context, binding the given frame buffer to the context.
1772 void gl_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1774 gl_make_current2( newCtx
, buffer
, buffer
);
1779 * Bind the given context to the given draw-buffer and read-buffer
1780 * and make it the current context for this thread.
1782 void gl_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1783 GLframebuffer
*readBuffer
)
1786 GLcontext
*oldCtx
= gl_get_context();
1788 /* Flush the old context
1791 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx
, "gl_make_current");
1793 /* unbind frame buffers from context */
1794 if (oldCtx
->DrawBuffer
) {
1795 oldCtx
->DrawBuffer
= NULL
;
1797 if (oldCtx
->ReadBuffer
) {
1798 oldCtx
->ReadBuffer
= NULL
;
1803 /* We call this function periodically (just here for now) in
1804 * order to detect when multithreading has begun.
1806 _glapi_check_multithread();
1808 _glapi_set_context((void *) newCtx
);
1809 ASSERT(gl_get_current_context() == newCtx
);
1811 SET_IMMEDIATE(newCtx
, newCtx
->input
);
1812 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1815 _glapi_set_dispatch(NULL
); /* none current */
1818 if (MESA_VERBOSE
) fprintf(stderr
, "gl_make_current()\n");
1820 if (newCtx
&& drawBuffer
&& readBuffer
) {
1821 /* TODO: check if newCtx and buffer's visual match??? */
1822 newCtx
->DrawBuffer
= drawBuffer
;
1823 newCtx
->ReadBuffer
= readBuffer
;
1824 newCtx
->NewState
= NEW_ALL
; /* just to be safe */
1825 gl_update_state( newCtx
);
1828 /* We can use this to help debug user's problems. Tell the to set
1829 * the MESA_INFO env variable before running their app. Then the
1830 * first time each context is made current we'll print some useful
1833 if (newCtx
&& newCtx
->FirstTimeCurrent
) {
1834 if (getenv("MESA_INFO")) {
1835 fprintf(stderr
, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION
));
1836 fprintf(stderr
, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER
));
1837 fprintf(stderr
, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR
));
1838 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS
));
1839 #if defined(THREADS)
1840 fprintf(stderr
, "Mesa thread-safe: YES\n");
1842 fprintf(stderr
, "Mesa thread-safe: NO\n");
1844 #if defined(USE_X86_ASM)
1845 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1847 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1850 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1857 * Return current context handle for the calling thread.
1858 * This isn't the fastest way to get the current context.
1859 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1861 GLcontext
*gl_get_current_context( void )
1863 return (GLcontext
*) _glapi_get_context();
1869 * This should be called by device drivers just before they do a
1870 * swapbuffers. Any pending rendering commands will be executed.
1873 _mesa_swapbuffers(GLcontext
*ctx
)
1875 FLUSH_VB( ctx
, "swap buffers" );
1881 * Return pointer to this context's current API dispatch table.
1882 * It'll either be the immediate-mode execute dispatcher or the
1883 * display list compile dispatcher.
1885 struct _glapi_table
*
1886 _mesa_get_dispatch(GLcontext
*ctx
)
1888 return ctx
->CurrentDispatch
;
1893 /**********************************************************************/
1894 /***** Miscellaneous functions *****/
1895 /**********************************************************************/
1899 * This function is called when the Mesa user has stumbled into a code
1900 * path which may not be implemented fully or correctly.
1902 void gl_problem( const GLcontext
*ctx
, const char *s
)
1904 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
1905 fprintf( stderr
, "Report to mesa-bugs@mesa3d.org\n" );
1912 * This is called to inform the user that he or she has tried to do
1913 * something illogical or if there's likely a bug in their program
1914 * (like enabled depth testing without a depth buffer).
1916 void gl_warning( const GLcontext
*ctx
, const char *s
)
1922 if (getenv("MESA_DEBUG")) {
1930 fprintf( stderr
, "Mesa warning: %s\n", s
);
1938 * Compile an error into current display list.
1940 void gl_compile_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1942 if (ctx
->CompileFlag
)
1943 gl_save_error( ctx
, error
, s
);
1945 if (ctx
->ExecuteFlag
)
1946 gl_error( ctx
, error
, s
);
1952 * This is Mesa's error handler. Normally, all that's done is the updating
1953 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1954 * environment variable "MESA_DEBUG" is defined then a real error message
1955 * is printed to stderr.
1956 * Input: error - the error value
1957 * s - a diagnostic string
1959 void gl_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1966 if (getenv("MESA_DEBUG")) {
1979 strcpy( errstr
, "GL_NO_ERROR" );
1981 case GL_INVALID_VALUE
:
1982 strcpy( errstr
, "GL_INVALID_VALUE" );
1984 case GL_INVALID_ENUM
:
1985 strcpy( errstr
, "GL_INVALID_ENUM" );
1987 case GL_INVALID_OPERATION
:
1988 strcpy( errstr
, "GL_INVALID_OPERATION" );
1990 case GL_STACK_OVERFLOW
:
1991 strcpy( errstr
, "GL_STACK_OVERFLOW" );
1993 case GL_STACK_UNDERFLOW
:
1994 strcpy( errstr
, "GL_STACK_UNDERFLOW" );
1996 case GL_OUT_OF_MEMORY
:
1997 strcpy( errstr
, "GL_OUT_OF_MEMORY" );
2000 strcpy( errstr
, "unknown" );
2003 fprintf( stderr
, "Mesa user error: %s in %s\n", errstr
, s
);
2006 if (ctx
->ErrorValue
==GL_NO_ERROR
) {
2007 ctx
->ErrorValue
= error
;
2010 /* Call device driver's error handler, if any. This is used on the Mac. */
2011 if (ctx
->Driver
.Error
) {
2012 (*ctx
->Driver
.Error
)( ctx
);
2019 _mesa_Finish( void )
2021 GET_CURRENT_CONTEXT(ctx
);
2022 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFinish");
2023 if (ctx
->Driver
.Finish
) {
2024 (*ctx
->Driver
.Finish
)( ctx
);
2033 GET_CURRENT_CONTEXT(ctx
);
2034 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFlush");
2035 if (ctx
->Driver
.Flush
) {
2036 (*ctx
->Driver
.Flush
)( ctx
);