1 /* $Id: context.c,v 1.36 2000/01/28 20:17:42 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"
60 #include "simple_list.h"
64 #include "translate.h"
82 /**********************************************************************/
83 /***** Context and Thread management *****/
84 /**********************************************************************/
89 struct immediate
*_mesa_CurrentInput
= NULL
;
96 /**********************************************************************/
97 /***** Profiling functions *****/
98 /**********************************************************************/
102 #include <sys/times.h>
103 #include <sys/param.h>
107 * Return system time in seconds.
108 * NOTE: this implementation may not be very portable!
110 GLdouble
gl_time( void )
112 static GLdouble prev_time
= 0.0;
113 static GLdouble time
;
120 time
= (double)clk
/ (double)CLK_TCK
;
122 time
= (double)clk
/ (double)HZ
;
125 if (time
>prev_time
) {
135 * Reset the timing/profiling counters
137 static void init_timings( GLcontext
*ctx
)
139 ctx
->BeginEndCount
= 0;
140 ctx
->BeginEndTime
= 0.0;
141 ctx
->VertexCount
= 0;
142 ctx
->VertexTime
= 0.0;
144 ctx
->PointTime
= 0.0;
147 ctx
->PolygonCount
= 0;
148 ctx
->PolygonTime
= 0.0;
150 ctx
->ClearTime
= 0.0;
157 * Print the accumulated timing/profiling data.
159 static void print_timings( GLcontext
*ctx
)
161 GLdouble beginendrate
;
165 GLdouble polygonrate
;
169 GLdouble avgvertices
;
171 if (ctx
->BeginEndTime
>0.0) {
172 beginendrate
= ctx
->BeginEndCount
/ ctx
->BeginEndTime
;
177 if (ctx
->VertexTime
>0.0) {
178 vertexrate
= ctx
->VertexCount
/ ctx
->VertexTime
;
183 if (ctx
->PointTime
>0.0) {
184 pointrate
= ctx
->PointCount
/ ctx
->PointTime
;
189 if (ctx
->LineTime
>0.0) {
190 linerate
= ctx
->LineCount
/ ctx
->LineTime
;
195 if (ctx
->PolygonTime
>0.0) {
196 polygonrate
= ctx
->PolygonCount
/ ctx
->PolygonTime
;
201 if (ctx
->ClearTime
>0.0) {
202 clearrate
= ctx
->ClearCount
/ ctx
->ClearTime
;
207 if (ctx
->SwapTime
>0.0) {
208 swaprate
= ctx
->SwapCount
/ ctx
->SwapTime
;
214 if (ctx
->BeginEndCount
>0) {
215 avgvertices
= (GLdouble
) ctx
->VertexCount
/ (GLdouble
) ctx
->BeginEndCount
;
221 overhead
= ctx
->BeginEndTime
- ctx
->VertexTime
- ctx
->PointTime
222 - ctx
->LineTime
- ctx
->PolygonTime
;
225 printf(" Count Time (s) Rate (/s) \n");
226 printf("--------------------------------------------------------\n");
227 printf("glBegin/glEnd %7d %8.3f %10.3f\n",
228 ctx
->BeginEndCount
, ctx
->BeginEndTime
, beginendrate
);
229 printf(" vertexes transformed %7d %8.3f %10.3f\n",
230 ctx
->VertexCount
, ctx
->VertexTime
, vertexrate
);
231 printf(" points rasterized %7d %8.3f %10.3f\n",
232 ctx
->PointCount
, ctx
->PointTime
, pointrate
);
233 printf(" lines rasterized %7d %8.3f %10.3f\n",
234 ctx
->LineCount
, ctx
->LineTime
, linerate
);
235 printf(" polygons rasterized %7d %8.3f %10.3f\n",
236 ctx
->PolygonCount
, ctx
->PolygonTime
, polygonrate
);
237 printf(" overhead %8.3f\n", overhead
);
238 printf("glClear %7d %8.3f %10.3f\n",
239 ctx
->ClearCount
, ctx
->ClearTime
, clearrate
);
240 printf("SwapBuffers %7d %8.3f %10.3f\n",
241 ctx
->SwapCount
, ctx
->SwapTime
, swaprate
);
244 printf("Average number of vertices per begin/end: %8.3f\n", avgvertices
);
252 /**********************************************************************/
253 /***** GL Visual allocation/destruction *****/
254 /**********************************************************************/
258 * Allocate a new GLvisual object.
259 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
260 * alphaFlag - alloc software alpha buffers?
261 * dbFlag - double buffering?
262 * stereoFlag - stereo buffer?
263 * depthFits - requested minimum bits per depth buffer value
264 * stencilFits - requested minimum bits per stencil buffer value
265 * accumFits - requested minimum bits per accum buffer component
266 * indexFits - number of bits per pixel if rgbFlag==GL_FALSE
267 * red/green/blue/alphaFits - number of bits per color component
268 * in frame buffer for RGB(A) mode.
269 * Return: pointer to new GLvisual or NULL if requested parameters can't
272 GLvisual
*gl_create_visual( GLboolean rgbFlag
,
275 GLboolean stereoFlag
,
287 if (depthBits
> (GLint
) (8*sizeof(GLdepth
))) {
288 /* can't meet depth buffer requirements */
291 if (stencilBits
> (GLint
) (8*sizeof(GLstencil
))) {
292 /* can't meet stencil buffer requirements */
295 if (accumBits
> (GLint
) (8*sizeof(GLaccum
))) {
296 /* can't meet accum buffer requirements */
300 vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
305 vis
->RGBAflag
= rgbFlag
;
306 vis
->DBflag
= dbFlag
;
307 vis
->StereoFlag
= stereoFlag
;
308 vis
->RedBits
= redBits
;
309 vis
->GreenBits
= greenBits
;
310 vis
->BlueBits
= blueBits
;
311 vis
->AlphaBits
= alphaFlag
? 8*sizeof(GLubyte
) : alphaBits
;
313 vis
->IndexBits
= indexBits
;
314 vis
->DepthBits
= (depthBits
>0) ? 8*sizeof(GLdepth
) : 0;
315 vis
->AccumBits
= (accumBits
>0) ? 8*sizeof(GLaccum
) : 0;
316 vis
->StencilBits
= (stencilBits
>0) ? 8*sizeof(GLstencil
) : 0;
318 vis
->SoftwareAlpha
= alphaFlag
;
325 void gl_destroy_visual( GLvisual
*vis
)
332 /**********************************************************************/
333 /***** GL Framebuffer allocation/destruction *****/
334 /**********************************************************************/
338 * Create a new framebuffer. A GLframebuffer is a struct which
339 * encapsulates the depth, stencil and accum buffers and related
341 * Input: visual - a GLvisual pointer
342 * softwareDepth - create/use a software depth buffer?
343 * softwareStencil - create/use a software stencil buffer?
344 * softwareAccum - create/use a software accum buffer?
345 * softwareAlpha - create/use a software alpha buffer?
347 * Return: pointer to new GLframebuffer struct or NULL if error.
349 GLframebuffer
*gl_create_framebuffer( GLvisual
*visual
,
350 GLboolean softwareDepth
,
351 GLboolean softwareStencil
,
352 GLboolean softwareAccum
,
353 GLboolean softwareAlpha
)
355 GLframebuffer
*buffer
;
357 buffer
= CALLOC_STRUCT(gl_frame_buffer
);
363 if (softwareDepth
) {
364 assert(visual
->DepthBits
> 0);
366 if (softwareStencil
) {
367 assert(visual
->StencilBits
> 0);
370 assert(visual
->RGBAflag
);
371 assert(visual
->AccumBits
> 0);
374 assert(visual
->RGBAflag
);
375 assert(visual
->AlphaBits
> 0);
378 buffer
->Visual
= visual
;
379 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
380 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
381 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
382 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
390 * Free a framebuffer struct and its buffers.
392 void gl_destroy_framebuffer( GLframebuffer
*buffer
)
396 FREE( buffer
->Depth
);
399 FREE( buffer
->Accum
);
401 if (buffer
->Stencil
) {
402 FREE( buffer
->Stencil
);
404 if (buffer
->FrontLeftAlpha
) {
405 FREE( buffer
->FrontLeftAlpha
);
407 if (buffer
->BackLeftAlpha
) {
408 FREE( buffer
->BackLeftAlpha
);
410 if (buffer
->FrontRightAlpha
) {
411 FREE( buffer
->FrontRightAlpha
);
413 if (buffer
->BackRightAlpha
) {
414 FREE( buffer
->BackRightAlpha
);
422 /**********************************************************************/
423 /***** Context allocation, initialization, destroying *****/
424 /**********************************************************************/
428 * This function just calls all the various one-time-init functions in Mesa.
430 static void one_time_init( void )
432 static GLboolean alreadyCalled
= GL_FALSE
;
433 if (!alreadyCalled
) {
434 /* do some implementation tests */
435 assert( sizeof(GLbyte
) == 1 );
436 assert( sizeof(GLshort
) >= 2 );
437 assert( sizeof(GLint
) >= 4 );
438 assert( sizeof(GLubyte
) == 1 );
439 assert( sizeof(GLushort
) >= 2 );
440 assert( sizeof(GLuint
) >= 4 );
449 gl_init_transformation();
455 if (getenv("MESA_DEBUG")) {
456 _glapi_noop_enable_warnings(GL_TRUE
);
459 _glapi_noop_enable_warnings(GL_FALSE
);
462 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
463 fprintf(stderr
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
466 alreadyCalled
= GL_TRUE
;
473 * Allocate and initialize a shared context state structure.
475 static struct gl_shared_state
*alloc_shared_state( void )
478 struct gl_shared_state
*ss
;
479 GLboolean outOfMemory
;
481 ss
= CALLOC_STRUCT(gl_shared_state
);
485 ss
->DisplayList
= _mesa_NewHashTable();
487 ss
->TexObjects
= _mesa_NewHashTable();
489 /* Default Texture objects */
490 outOfMemory
= GL_FALSE
;
491 for (d
= 1 ; d
<= 3 ; d
++) {
492 ss
->DefaultD
[d
] = gl_alloc_texture_object(ss
, 0, d
);
493 if (!ss
->DefaultD
[d
]) {
494 outOfMemory
= GL_TRUE
;
497 ss
->DefaultD
[d
]->RefCount
++; /* don't free if not in use */
500 if (!ss
->DisplayList
|| !ss
->TexObjects
|| outOfMemory
) {
501 /* Ran out of memory at some point. Free everything and return NULL */
503 _mesa_DeleteHashTable(ss
->DisplayList
);
505 _mesa_DeleteHashTable(ss
->TexObjects
);
507 gl_free_texture_object(ss
, ss
->DefaultD
[1]);
509 gl_free_texture_object(ss
, ss
->DefaultD
[2]);
511 gl_free_texture_object(ss
, ss
->DefaultD
[3]);
522 * Deallocate a shared state context and all children structures.
524 static void free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
526 /* Free display lists */
528 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
530 gl_destroy_list(ctx
, list
);
536 _mesa_DeleteHashTable(ss
->DisplayList
);
538 /* Free texture objects */
539 while (ss
->TexObjectList
)
541 if (ctx
->Driver
.DeleteTexture
)
542 (*ctx
->Driver
.DeleteTexture
)( ctx
, ss
->TexObjectList
);
543 /* this function removes from linked list too! */
544 gl_free_texture_object(ss
, ss
->TexObjectList
);
546 _mesa_DeleteHashTable(ss
->TexObjects
);
554 * Initialize the nth light. Note that the defaults for light 0 are
555 * different than the other lights.
557 static void init_light( struct gl_light
*l
, GLuint n
)
559 make_empty_list( l
);
561 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
563 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
564 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
567 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
568 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
570 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
571 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
572 l
->SpotExponent
= 0.0;
573 gl_compute_spot_exp_table( l
);
574 l
->SpotCutoff
= 180.0;
575 l
->CosCutoff
= 0.0; /* KW: -ve values not admitted */
576 l
->ConstantAttenuation
= 1.0;
577 l
->LinearAttenuation
= 0.0;
578 l
->QuadraticAttenuation
= 0.0;
579 l
->Enabled
= GL_FALSE
;
584 static void init_lightmodel( struct gl_lightmodel
*lm
)
586 ASSIGN_4V( lm
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
587 lm
->LocalViewer
= GL_FALSE
;
588 lm
->TwoSide
= GL_FALSE
;
589 lm
->ColorControl
= GL_SINGLE_COLOR
;
593 static void init_material( struct gl_material
*m
)
595 ASSIGN_4V( m
->Ambient
, 0.2, 0.2, 0.2, 1.0 );
596 ASSIGN_4V( m
->Diffuse
, 0.8, 0.8, 0.8, 1.0 );
597 ASSIGN_4V( m
->Specular
, 0.0, 0.0, 0.0, 1.0 );
598 ASSIGN_4V( m
->Emission
, 0.0, 0.0, 0.0, 1.0 );
602 m
->SpecularIndex
= 1;
607 static void init_texture_unit( GLcontext
*ctx
, GLuint unit
)
609 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
611 texUnit
->EnvMode
= GL_MODULATE
;
612 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
613 texUnit
->TexGenEnabled
= 0;
614 texUnit
->GenModeS
= GL_EYE_LINEAR
;
615 texUnit
->GenModeT
= GL_EYE_LINEAR
;
616 texUnit
->GenModeR
= GL_EYE_LINEAR
;
617 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
618 /* Yes, these plane coefficients are correct! */
619 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
620 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
621 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
622 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
623 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
624 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
625 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
626 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
628 texUnit
->CurrentD
[1] = ctx
->Shared
->DefaultD
[1];
629 texUnit
->CurrentD
[2] = ctx
->Shared
->DefaultD
[2];
630 texUnit
->CurrentD
[3] = ctx
->Shared
->DefaultD
[3];
634 static void init_fallback_arrays( GLcontext
*ctx
)
636 struct gl_client_array
*cl
;
639 cl
= &ctx
->Fallback
.Normal
;
644 cl
->Ptr
= (void *) ctx
->Current
.Normal
;
647 cl
= &ctx
->Fallback
.Color
;
649 cl
->Type
= GL_UNSIGNED_BYTE
;
652 cl
->Ptr
= (void *) ctx
->Current
.ByteColor
;
655 cl
= &ctx
->Fallback
.Index
;
657 cl
->Type
= GL_UNSIGNED_INT
;
660 cl
->Ptr
= (void *) &ctx
->Current
.Index
;
663 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++) {
664 cl
= &ctx
->Fallback
.TexCoord
[i
];
669 cl
->Ptr
= (void *) ctx
->Current
.Texcoord
[i
];
673 cl
= &ctx
->Fallback
.EdgeFlag
;
675 cl
->Type
= GL_UNSIGNED_BYTE
;
678 cl
->Ptr
= (void *) &ctx
->Current
.EdgeFlag
;
683 /* Initialize a 1-D evaluator map */
684 static void init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
689 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
693 map
->Points
[i
] = initial
[i
];
698 /* Initialize a 2-D evaluator map */
699 static void init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
707 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
711 map
->Points
[i
] = initial
[i
];
716 static void init_color_table( struct gl_color_table
*p
)
723 p
->IntFormat
= GL_RGBA
;
729 * Initialize the attribute groups in a GLcontext.
731 static void init_attrib_groups( GLcontext
*ctx
)
737 /* Constants, may be overriden by device driver */
738 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
739 ctx
->Const
.MaxTextureSize
= 1 << (MAX_TEXTURE_LEVELS
- 1);
740 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
741 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
743 /* Modelview matrix */
744 gl_matrix_ctr( &ctx
->ModelView
);
745 gl_matrix_alloc_inv( &ctx
->ModelView
);
747 ctx
->ModelViewStackDepth
= 0;
748 for (i
= 0 ; i
< MAX_MODELVIEW_STACK_DEPTH
; i
++) {
749 gl_matrix_ctr( &ctx
->ModelViewStack
[i
] );
750 gl_matrix_alloc_inv( &ctx
->ModelViewStack
[i
] );
753 /* Projection matrix - need inv for user clipping in clip space*/
754 gl_matrix_ctr( &ctx
->ProjectionMatrix
);
755 gl_matrix_alloc_inv( &ctx
->ProjectionMatrix
);
757 gl_matrix_ctr( &ctx
->ModelProjectMatrix
);
758 gl_matrix_ctr( &ctx
->ModelProjectWinMatrix
);
759 ctx
->ModelProjectWinMatrixUptodate
= GL_FALSE
;
761 ctx
->ProjectionStackDepth
= 0;
762 ctx
->NearFarStack
[0][0] = 1.0; /* These values seem weird by make */
763 ctx
->NearFarStack
[0][1] = 0.0; /* sense mathematically. */
765 for (i
= 0 ; i
< MAX_PROJECTION_STACK_DEPTH
; i
++) {
766 gl_matrix_ctr( &ctx
->ProjectionStack
[i
] );
767 gl_matrix_alloc_inv( &ctx
->ProjectionStack
[i
] );
771 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
772 gl_matrix_ctr( &ctx
->TextureMatrix
[i
] );
773 ctx
->TextureStackDepth
[i
] = 0;
774 for (j
= 0 ; j
< MAX_TEXTURE_STACK_DEPTH
; j
++) {
775 ctx
->TextureStack
[i
][j
].inv
= 0;
779 /* Accumulate buffer group */
780 ASSIGN_4V( ctx
->Accum
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
782 /* Color buffer group */
783 ctx
->Color
.IndexMask
= 0xffffffff;
784 ctx
->Color
.ColorMask
[0] = 0xff;
785 ctx
->Color
.ColorMask
[1] = 0xff;
786 ctx
->Color
.ColorMask
[2] = 0xff;
787 ctx
->Color
.ColorMask
[3] = 0xff;
788 ctx
->Color
.SWmasking
= GL_FALSE
;
789 ctx
->Color
.ClearIndex
= 0;
790 ASSIGN_4V( ctx
->Color
.ClearColor
, 0.0, 0.0, 0.0, 0.0 );
791 ctx
->Color
.DrawBuffer
= GL_FRONT
;
792 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
793 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
794 ctx
->Color
.AlphaRef
= 0;
795 ctx
->Color
.BlendEnabled
= GL_FALSE
;
796 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
797 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
798 ctx
->Color
.BlendSrcA
= GL_ONE
;
799 ctx
->Color
.BlendDstA
= GL_ZERO
;
800 ctx
->Color
.BlendEquation
= GL_FUNC_ADD_EXT
;
801 ctx
->Color
.BlendFunc
= NULL
; /* this pointer set only when needed */
802 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
803 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
804 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
805 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
806 ctx
->Color
.LogicOp
= GL_COPY
;
807 ctx
->Color
.DitherFlag
= GL_TRUE
;
808 ctx
->Color
.MultiDrawBuffer
= GL_FALSE
;
811 ASSIGN_4V( ctx
->Current
.ByteColor
, 255, 255, 255, 255);
812 ctx
->Current
.Index
= 1;
813 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
814 ASSIGN_4V( ctx
->Current
.Texcoord
[i
], 0.0, 0.0, 0.0, 1.0 );
815 ASSIGN_4V( ctx
->Current
.RasterPos
, 0.0, 0.0, 0.0, 1.0 );
816 ctx
->Current
.RasterDistance
= 0.0;
817 ASSIGN_4V( ctx
->Current
.RasterColor
, 1.0, 1.0, 1.0, 1.0 );
818 ctx
->Current
.RasterIndex
= 1;
819 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
820 ASSIGN_4V( ctx
->Current
.RasterMultiTexCoord
[i
], 0.0, 0.0, 0.0, 1.0 );
821 ctx
->Current
.RasterTexCoord
= ctx
->Current
.RasterMultiTexCoord
[0];
822 ctx
->Current
.RasterPosValid
= GL_TRUE
;
823 ctx
->Current
.EdgeFlag
= GL_TRUE
;
824 ASSIGN_3V( ctx
->Current
.Normal
, 0.0, 0.0, 1.0 );
825 ctx
->Current
.Primitive
= (GLenum
) (GL_POLYGON
+ 1);
827 ctx
->Current
.Flag
= (VERT_NORM
|VERT_INDEX
|VERT_RGBA
|VERT_EDGE
|
828 VERT_TEX0_1
|VERT_TEX1_1
|VERT_MATERIAL
);
830 init_fallback_arrays( ctx
);
832 /* Depth buffer group */
833 ctx
->Depth
.Test
= GL_FALSE
;
834 ctx
->Depth
.Clear
= 1.0;
835 ctx
->Depth
.Func
= GL_LESS
;
836 ctx
->Depth
.Mask
= GL_TRUE
;
838 /* Evaluators group */
839 ctx
->Eval
.Map1Color4
= GL_FALSE
;
840 ctx
->Eval
.Map1Index
= GL_FALSE
;
841 ctx
->Eval
.Map1Normal
= GL_FALSE
;
842 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
843 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
844 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
845 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
846 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
847 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
848 ctx
->Eval
.Map2Color4
= GL_FALSE
;
849 ctx
->Eval
.Map2Index
= GL_FALSE
;
850 ctx
->Eval
.Map2Normal
= GL_FALSE
;
851 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
852 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
853 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
854 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
855 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
856 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
857 ctx
->Eval
.AutoNormal
= GL_FALSE
;
858 ctx
->Eval
.MapGrid1un
= 1;
859 ctx
->Eval
.MapGrid1u1
= 0.0;
860 ctx
->Eval
.MapGrid1u2
= 1.0;
861 ctx
->Eval
.MapGrid2un
= 1;
862 ctx
->Eval
.MapGrid2vn
= 1;
863 ctx
->Eval
.MapGrid2u1
= 0.0;
864 ctx
->Eval
.MapGrid2u2
= 1.0;
865 ctx
->Eval
.MapGrid2v1
= 0.0;
866 ctx
->Eval
.MapGrid2v2
= 1.0;
870 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
871 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
872 static GLfloat index
[1] = { 1.0 };
873 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
874 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
876 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
877 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
878 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
879 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
880 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
881 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
882 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
883 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
884 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
886 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
887 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
888 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
889 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
890 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
891 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
892 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
893 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
894 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
898 ctx
->Fog
.Enabled
= GL_FALSE
;
899 ctx
->Fog
.Mode
= GL_EXP
;
900 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
901 ctx
->Fog
.Index
= 0.0;
902 ctx
->Fog
.Density
= 1.0;
903 ctx
->Fog
.Start
= 0.0;
907 ctx
->Hint
.PerspectiveCorrection
= GL_DONT_CARE
;
908 ctx
->Hint
.PointSmooth
= GL_DONT_CARE
;
909 ctx
->Hint
.LineSmooth
= GL_DONT_CARE
;
910 ctx
->Hint
.PolygonSmooth
= GL_DONT_CARE
;
911 ctx
->Hint
.Fog
= GL_DONT_CARE
;
913 ctx
->Hint
.AllowDrawWin
= GL_TRUE
;
914 ctx
->Hint
.AllowDrawSpn
= GL_TRUE
;
915 ctx
->Hint
.AllowDrawMem
= GL_TRUE
;
916 ctx
->Hint
.StrictLighting
= GL_TRUE
;
919 gl_pipeline_init( ctx
);
923 gl_extensions_ctr( ctx
);
925 ctx
->AllowVertexCull
= CLIP_CULLED_BIT
;
928 for (i
=0;i
<MAX_LIGHTS
;i
++) {
929 init_light( &ctx
->Light
.Light
[i
], i
);
931 make_empty_list( &ctx
->Light
.EnabledList
);
933 init_lightmodel( &ctx
->Light
.Model
);
934 init_material( &ctx
->Light
.Material
[0] );
935 init_material( &ctx
->Light
.Material
[1] );
936 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
937 ctx
->Light
.Enabled
= GL_FALSE
;
938 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
939 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
940 ctx
->Light
.ColorMaterialBitmask
941 = gl_material_bitmask( ctx
,
943 GL_AMBIENT_AND_DIFFUSE
, ~0, 0 );
945 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
947 /* Lighting miscellaneous */
948 ctx
->ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
949 make_empty_list( ctx
->ShineTabList
);
950 for (i
= 0 ; i
< 10 ; i
++) {
951 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
954 insert_at_tail( ctx
->ShineTabList
, s
);
956 for (i
= 0 ; i
< 4 ; i
++) {
957 ctx
->ShineTable
[i
] = ctx
->ShineTabList
->prev
;
958 ctx
->ShineTable
[i
]->refcount
++;
963 ctx
->Line
.SmoothFlag
= GL_FALSE
;
964 ctx
->Line
.StippleFlag
= GL_FALSE
;
965 ctx
->Line
.Width
= 1.0;
966 ctx
->Line
.StipplePattern
= 0xffff;
967 ctx
->Line
.StippleFactor
= 1;
969 /* Display List group */
970 ctx
->List
.ListBase
= 0;
973 ctx
->Pixel
.RedBias
= 0.0;
974 ctx
->Pixel
.RedScale
= 1.0;
975 ctx
->Pixel
.GreenBias
= 0.0;
976 ctx
->Pixel
.GreenScale
= 1.0;
977 ctx
->Pixel
.BlueBias
= 0.0;
978 ctx
->Pixel
.BlueScale
= 1.0;
979 ctx
->Pixel
.AlphaBias
= 0.0;
980 ctx
->Pixel
.AlphaScale
= 1.0;
981 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_FALSE
;
982 ctx
->Pixel
.DepthBias
= 0.0;
983 ctx
->Pixel
.DepthScale
= 1.0;
984 ctx
->Pixel
.IndexOffset
= 0;
985 ctx
->Pixel
.IndexShift
= 0;
986 ctx
->Pixel
.ZoomX
= 1.0;
987 ctx
->Pixel
.ZoomY
= 1.0;
988 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
989 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
990 ctx
->Pixel
.MapStoSsize
= 1;
991 ctx
->Pixel
.MapItoIsize
= 1;
992 ctx
->Pixel
.MapItoRsize
= 1;
993 ctx
->Pixel
.MapItoGsize
= 1;
994 ctx
->Pixel
.MapItoBsize
= 1;
995 ctx
->Pixel
.MapItoAsize
= 1;
996 ctx
->Pixel
.MapRtoRsize
= 1;
997 ctx
->Pixel
.MapGtoGsize
= 1;
998 ctx
->Pixel
.MapBtoBsize
= 1;
999 ctx
->Pixel
.MapAtoAsize
= 1;
1000 ctx
->Pixel
.MapStoS
[0] = 0;
1001 ctx
->Pixel
.MapItoI
[0] = 0;
1002 ctx
->Pixel
.MapItoR
[0] = 0.0;
1003 ctx
->Pixel
.MapItoG
[0] = 0.0;
1004 ctx
->Pixel
.MapItoB
[0] = 0.0;
1005 ctx
->Pixel
.MapItoA
[0] = 0.0;
1006 ctx
->Pixel
.MapItoR8
[0] = 0;
1007 ctx
->Pixel
.MapItoG8
[0] = 0;
1008 ctx
->Pixel
.MapItoB8
[0] = 0;
1009 ctx
->Pixel
.MapItoA8
[0] = 0;
1010 ctx
->Pixel
.MapRtoR
[0] = 0.0;
1011 ctx
->Pixel
.MapGtoG
[0] = 0.0;
1012 ctx
->Pixel
.MapBtoB
[0] = 0.0;
1013 ctx
->Pixel
.MapAtoA
[0] = 0.0;
1016 ctx
->Point
.SmoothFlag
= GL_FALSE
;
1017 ctx
->Point
.Size
= 1.0;
1018 ctx
->Point
.Params
[0] = 1.0;
1019 ctx
->Point
.Params
[1] = 0.0;
1020 ctx
->Point
.Params
[2] = 0.0;
1021 ctx
->Point
.Attenuated
= GL_FALSE
;
1022 ctx
->Point
.MinSize
= 0.0;
1023 ctx
->Point
.MaxSize
= (GLfloat
) MAX_POINT_SIZE
;
1024 ctx
->Point
.Threshold
= 1.0;
1027 ctx
->Polygon
.CullFlag
= GL_FALSE
;
1028 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
1029 ctx
->Polygon
.FrontFace
= GL_CCW
;
1030 ctx
->Polygon
.FrontBit
= 0;
1031 ctx
->Polygon
.FrontMode
= GL_FILL
;
1032 ctx
->Polygon
.BackMode
= GL_FILL
;
1033 ctx
->Polygon
.Unfilled
= GL_FALSE
;
1034 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
1035 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
1036 ctx
->Polygon
.OffsetFactor
= 0.0F
;
1037 ctx
->Polygon
.OffsetUnits
= 0.0F
;
1038 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
1039 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
1040 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
1042 /* Polygon Stipple group */
1043 MEMSET( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );
1046 ctx
->Scissor
.Enabled
= GL_FALSE
;
1049 ctx
->Scissor
.Width
= 0;
1050 ctx
->Scissor
.Height
= 0;
1053 ctx
->Stencil
.Enabled
= GL_FALSE
;
1054 ctx
->Stencil
.Function
= GL_ALWAYS
;
1055 ctx
->Stencil
.FailFunc
= GL_KEEP
;
1056 ctx
->Stencil
.ZPassFunc
= GL_KEEP
;
1057 ctx
->Stencil
.ZFailFunc
= GL_KEEP
;
1058 ctx
->Stencil
.Ref
= 0;
1059 ctx
->Stencil
.ValueMask
= STENCIL_MAX
;
1060 ctx
->Stencil
.Clear
= 0;
1061 ctx
->Stencil
.WriteMask
= STENCIL_MAX
;
1064 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1065 ctx
->Texture
.CurrentTransformUnit
= 0; /* multitexture */
1066 ctx
->Texture
.Enabled
= 0;
1067 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1068 init_texture_unit( ctx
, i
);
1069 init_color_table(&ctx
->Texture
.Palette
);
1071 /* Transformation group */
1072 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
1073 ctx
->Transform
.Normalize
= GL_FALSE
;
1074 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
1075 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
1076 ctx
->Transform
.ClipEnabled
[i
] = GL_FALSE
;
1077 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
1079 ctx
->Transform
.AnyClip
= GL_FALSE
;
1081 /* Viewport group */
1082 ctx
->Viewport
.X
= 0;
1083 ctx
->Viewport
.Y
= 0;
1084 ctx
->Viewport
.Width
= 0;
1085 ctx
->Viewport
.Height
= 0;
1086 ctx
->Viewport
.Near
= 0.0;
1087 ctx
->Viewport
.Far
= 1.0;
1088 gl_matrix_ctr(&ctx
->Viewport
.WindowMap
);
1092 ctx
->Viewport
.WindowMap
.m
[Sz
] = 0.5 * DEPTH_SCALE
;
1093 ctx
->Viewport
.WindowMap
.m
[Tz
] = 0.5 * DEPTH_SCALE
;
1097 ctx
->Viewport
.WindowMap
.flags
= MAT_FLAG_GENERAL_SCALE
|MAT_FLAG_TRANSLATION
;
1098 ctx
->Viewport
.WindowMap
.type
= MATRIX_3D_NO_ROT
;
1101 ctx
->Array
.Vertex
.Size
= 4;
1102 ctx
->Array
.Vertex
.Type
= GL_FLOAT
;
1103 ctx
->Array
.Vertex
.Stride
= 0;
1104 ctx
->Array
.Vertex
.StrideB
= 0;
1105 ctx
->Array
.Vertex
.Ptr
= NULL
;
1106 ctx
->Array
.Vertex
.Enabled
= GL_FALSE
;
1107 ctx
->Array
.Normal
.Type
= GL_FLOAT
;
1108 ctx
->Array
.Normal
.Stride
= 0;
1109 ctx
->Array
.Normal
.StrideB
= 0;
1110 ctx
->Array
.Normal
.Ptr
= NULL
;
1111 ctx
->Array
.Normal
.Enabled
= GL_FALSE
;
1112 ctx
->Array
.Color
.Size
= 4;
1113 ctx
->Array
.Color
.Type
= GL_FLOAT
;
1114 ctx
->Array
.Color
.Stride
= 0;
1115 ctx
->Array
.Color
.StrideB
= 0;
1116 ctx
->Array
.Color
.Ptr
= NULL
;
1117 ctx
->Array
.Color
.Enabled
= GL_FALSE
;
1118 ctx
->Array
.Index
.Type
= GL_FLOAT
;
1119 ctx
->Array
.Index
.Stride
= 0;
1120 ctx
->Array
.Index
.StrideB
= 0;
1121 ctx
->Array
.Index
.Ptr
= NULL
;
1122 ctx
->Array
.Index
.Enabled
= GL_FALSE
;
1123 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
1124 ctx
->Array
.TexCoord
[i
].Size
= 4;
1125 ctx
->Array
.TexCoord
[i
].Type
= GL_FLOAT
;
1126 ctx
->Array
.TexCoord
[i
].Stride
= 0;
1127 ctx
->Array
.TexCoord
[i
].StrideB
= 0;
1128 ctx
->Array
.TexCoord
[i
].Ptr
= NULL
;
1129 ctx
->Array
.TexCoord
[i
].Enabled
= GL_FALSE
;
1131 ctx
->Array
.TexCoordInterleaveFactor
= 1;
1132 ctx
->Array
.EdgeFlag
.Stride
= 0;
1133 ctx
->Array
.EdgeFlag
.StrideB
= 0;
1134 ctx
->Array
.EdgeFlag
.Ptr
= NULL
;
1135 ctx
->Array
.EdgeFlag
.Enabled
= GL_FALSE
;
1136 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1138 /* Pixel transfer */
1139 ctx
->Pack
.Alignment
= 4;
1140 ctx
->Pack
.RowLength
= 0;
1141 ctx
->Pack
.ImageHeight
= 0;
1142 ctx
->Pack
.SkipPixels
= 0;
1143 ctx
->Pack
.SkipRows
= 0;
1144 ctx
->Pack
.SkipImages
= 0;
1145 ctx
->Pack
.SwapBytes
= GL_FALSE
;
1146 ctx
->Pack
.LsbFirst
= GL_FALSE
;
1147 ctx
->Unpack
.Alignment
= 4;
1148 ctx
->Unpack
.RowLength
= 0;
1149 ctx
->Unpack
.ImageHeight
= 0;
1150 ctx
->Unpack
.SkipPixels
= 0;
1151 ctx
->Unpack
.SkipRows
= 0;
1152 ctx
->Unpack
.SkipImages
= 0;
1153 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
1154 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
1157 ctx
->Feedback
.Type
= GL_2D
; /* TODO: verify */
1158 ctx
->Feedback
.Buffer
= NULL
;
1159 ctx
->Feedback
.BufferSize
= 0;
1160 ctx
->Feedback
.Count
= 0;
1162 /* Selection/picking */
1163 ctx
->Select
.Buffer
= NULL
;
1164 ctx
->Select
.BufferSize
= 0;
1165 ctx
->Select
.BufferCount
= 0;
1166 ctx
->Select
.Hits
= 0;
1167 ctx
->Select
.NameStackDepth
= 0;
1169 /* Optimized Accum buffer */
1170 ctx
->IntegerAccumMode
= GL_TRUE
;
1171 ctx
->IntegerAccumScaler
= 0.0;
1173 /* Renderer and client attribute stacks */
1174 ctx
->AttribStackDepth
= 0;
1175 ctx
->ClientAttribStackDepth
= 0;
1178 ctx
->NewState
= NEW_ALL
;
1179 ctx
->RenderMode
= GL_RENDER
;
1180 ctx
->StippleCounter
= 0;
1181 ctx
->NeedNormals
= GL_FALSE
;
1182 ctx
->DoViewportMapping
= GL_TRUE
;
1184 ctx
->NeedEyeCoords
= GL_FALSE
;
1185 ctx
->NeedEyeNormals
= GL_FALSE
;
1186 ctx
->vb_proj_matrix
= &ctx
->ModelProjectMatrix
;
1190 ctx
->ExecuteFlag
= GL_TRUE
;
1191 ctx
->CompileFlag
= GL_FALSE
;
1192 ctx
->CurrentListPtr
= NULL
;
1193 ctx
->CurrentBlock
= NULL
;
1194 ctx
->CurrentListNum
= 0;
1195 ctx
->CurrentPos
= 0;
1197 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1199 ctx
->CatchSignals
= GL_TRUE
;
1201 /* For debug/development only */
1202 ctx
->NoRaster
= getenv("MESA_NO_RASTER") ? GL_TRUE
: GL_FALSE
;
1203 ctx
->FirstTimeCurrent
= GL_TRUE
;
1205 /* Dither disable */
1206 ctx
->NoDither
= getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
1207 if (ctx
->NoDither
) {
1208 if (getenv("MESA_DEBUG")) {
1209 fprintf(stderr
, "MESA_NO_DITHER set - dithering disabled\n");
1211 ctx
->Color
.DitherFlag
= GL_FALSE
;
1219 * Allocate the proxy textures. If we run out of memory part way through
1220 * the allocations clean up and return GL_FALSE.
1221 * Return: GL_TRUE=success, GL_FALSE=failure
1223 static GLboolean
alloc_proxy_textures( GLcontext
*ctx
)
1225 GLboolean out_of_memory
;
1228 ctx
->Texture
.Proxy1D
= gl_alloc_texture_object(NULL
, 0, 1);
1229 if (!ctx
->Texture
.Proxy1D
) {
1233 ctx
->Texture
.Proxy2D
= gl_alloc_texture_object(NULL
, 0, 2);
1234 if (!ctx
->Texture
.Proxy2D
) {
1235 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1239 ctx
->Texture
.Proxy3D
= gl_alloc_texture_object(NULL
, 0, 3);
1240 if (!ctx
->Texture
.Proxy3D
) {
1241 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1242 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1246 out_of_memory
= GL_FALSE
;
1247 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1248 ctx
->Texture
.Proxy1D
->Image
[i
] = gl_alloc_texture_image();
1249 ctx
->Texture
.Proxy2D
->Image
[i
] = gl_alloc_texture_image();
1250 ctx
->Texture
.Proxy3D
->Image
[i
] = gl_alloc_texture_image();
1251 if (!ctx
->Texture
.Proxy1D
->Image
[i
]
1252 || !ctx
->Texture
.Proxy2D
->Image
[i
]
1253 || !ctx
->Texture
.Proxy3D
->Image
[i
]) {
1254 out_of_memory
= GL_TRUE
;
1257 if (out_of_memory
) {
1258 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
1259 if (ctx
->Texture
.Proxy1D
->Image
[i
]) {
1260 gl_free_texture_image(ctx
->Texture
.Proxy1D
->Image
[i
]);
1262 if (ctx
->Texture
.Proxy2D
->Image
[i
]) {
1263 gl_free_texture_image(ctx
->Texture
.Proxy2D
->Image
[i
]);
1265 if (ctx
->Texture
.Proxy3D
->Image
[i
]) {
1266 gl_free_texture_image(ctx
->Texture
.Proxy3D
->Image
[i
]);
1269 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy1D
);
1270 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy2D
);
1271 gl_free_texture_object(NULL
, ctx
->Texture
.Proxy3D
);
1282 * Initialize a GLcontext struct.
1284 GLboolean
gl_initialize_context_data( GLcontext
*ctx
,
1286 GLcontext
*share_list
,
1290 (void) direct
; /* not used */
1292 /* misc one-time initializations */
1295 ctx
->DriverCtx
= driver_ctx
;
1296 ctx
->Visual
= visual
;
1297 ctx
->DrawBuffer
= NULL
;
1298 ctx
->ReadBuffer
= NULL
;
1300 ctx
->VB
= gl_vb_create_for_immediate( ctx
);
1305 ctx
->input
= ctx
->VB
->IM
;
1307 ctx
->PB
= gl_alloc_pb();
1315 /* share the group of display lists of another context */
1316 ctx
->Shared
= share_list
->Shared
;
1319 /* allocate new group of display lists */
1320 ctx
->Shared
= alloc_shared_state();
1328 ctx
->Shared
->RefCount
++;
1330 init_attrib_groups( ctx
);
1332 gl_reset_vb( ctx
->VB
);
1333 gl_reset_input( ctx
);
1335 if (visual
->DBflag
) {
1336 ctx
->Color
.DrawBuffer
= GL_BACK
;
1337 ctx
->Color
.DriverDrawBuffer
= GL_BACK_LEFT
;
1338 ctx
->Color
.DrawDestMask
= BACK_LEFT_BIT
;
1339 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
1340 ctx
->Pixel
.DriverReadBuffer
= GL_BACK_LEFT
;
1343 ctx
->Color
.DrawBuffer
= GL_FRONT
;
1344 ctx
->Color
.DriverDrawBuffer
= GL_FRONT_LEFT
;
1345 ctx
->Color
.DrawDestMask
= FRONT_LEFT_BIT
;
1346 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
1347 ctx
->Pixel
.DriverReadBuffer
= GL_FRONT_LEFT
;
1351 init_timings( ctx
);
1354 if (!alloc_proxy_textures(ctx
)) {
1355 free_shared_state(ctx
, ctx
->Shared
);
1362 /* setup API dispatch tables */
1363 _mesa_init_exec_table( &ctx
->Exec
);
1364 _mesa_init_dlist_table( &ctx
->Save
);
1365 ctx
->CurrentDispatch
= &ctx
->Exec
;
1373 * Allocate and initialize a GLcontext structure.
1374 * Input: visual - a GLvisual pointer
1375 * sharelist - another context to share display lists with or NULL
1376 * driver_ctx - pointer to device driver's context state struct
1377 * Return: pointer to a new gl_context struct or NULL if error.
1379 GLcontext
*gl_create_context( GLvisual
*visual
,
1380 GLcontext
*share_list
,
1384 GLcontext
*ctx
= (GLcontext
*) CALLOC( sizeof(GLcontext
) );
1389 if (gl_initialize_context_data(ctx
, visual
, share_list
,
1390 driver_ctx
, direct
)) {
1402 * Free the data associated with the given context.
1403 * But don't free() the GLcontext struct itself!
1405 void gl_free_context_data( GLcontext
*ctx
)
1408 struct gl_shine_tab
*s
, *tmps
;
1410 /* if we're destroying the current context, unbind it first */
1411 if (ctx
== gl_get_current_context()) {
1412 gl_make_current(NULL
, NULL
);
1416 if (getenv("MESA_PROFILE")) {
1417 print_timings( ctx
);
1421 gl_matrix_dtr( &ctx
->ModelView
);
1422 for (i
= 0 ; i
< MAX_MODELVIEW_STACK_DEPTH
; i
++) {
1423 gl_matrix_dtr( &ctx
->ModelViewStack
[i
] );
1425 gl_matrix_dtr( &ctx
->ProjectionMatrix
);
1426 for (i
= 0 ; i
< MAX_PROJECTION_STACK_DEPTH
; i
++) {
1427 gl_matrix_dtr( &ctx
->ProjectionStack
[i
] );
1432 if(ctx
->input
!= ctx
->VB
->IM
)
1433 gl_immediate_free( ctx
->input
);
1435 gl_vb_free( ctx
->VB
);
1437 ctx
->Shared
->RefCount
--;
1438 assert(ctx
->Shared
->RefCount
>=0);
1439 if (ctx
->Shared
->RefCount
==0) {
1440 /* free shared state */
1441 free_shared_state( ctx
, ctx
->Shared
);
1444 foreach_s( s
, tmps
, ctx
->ShineTabList
) {
1447 FREE( ctx
->ShineTabList
);
1449 /* Free proxy texture objects */
1450 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy1D
);
1451 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy2D
);
1452 gl_free_texture_object( NULL
, ctx
->Texture
.Proxy3D
);
1454 /* Free evaluator data */
1455 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
1456 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
1457 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
1458 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
1459 if (ctx
->EvalMap
.Map1Index
.Points
)
1460 FREE( ctx
->EvalMap
.Map1Index
.Points
);
1461 if (ctx
->EvalMap
.Map1Color4
.Points
)
1462 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
1463 if (ctx
->EvalMap
.Map1Normal
.Points
)
1464 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
1465 if (ctx
->EvalMap
.Map1Texture1
.Points
)
1466 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
1467 if (ctx
->EvalMap
.Map1Texture2
.Points
)
1468 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
1469 if (ctx
->EvalMap
.Map1Texture3
.Points
)
1470 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
1471 if (ctx
->EvalMap
.Map1Texture4
.Points
)
1472 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
1474 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
1475 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
1476 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
1477 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
1478 if (ctx
->EvalMap
.Map2Index
.Points
)
1479 FREE( ctx
->EvalMap
.Map2Index
.Points
);
1480 if (ctx
->EvalMap
.Map2Color4
.Points
)
1481 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
1482 if (ctx
->EvalMap
.Map2Normal
.Points
)
1483 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
1484 if (ctx
->EvalMap
.Map2Texture1
.Points
)
1485 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
1486 if (ctx
->EvalMap
.Map2Texture2
.Points
)
1487 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
1488 if (ctx
->EvalMap
.Map2Texture3
.Points
)
1489 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
1490 if (ctx
->EvalMap
.Map2Texture4
.Points
)
1491 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1493 /* Free cache of immediate buffers. */
1494 while (ctx
->nr_im_queued
-- > 0) {
1495 struct immediate
* next
= ctx
->freed_im_queue
->next
;
1496 FREE( ctx
->freed_im_queue
);
1497 ctx
->freed_im_queue
= next
;
1499 gl_extensions_dtr(ctx
);
1505 * Destroy a GLcontext structure.
1507 void gl_destroy_context( GLcontext
*ctx
)
1510 gl_free_context_data(ctx
);
1511 FREE( (void *) ctx
);
1518 * Called by the driver after both the context and driver are fully
1519 * initialized. Currently just reads the config file.
1521 void gl_context_initialize( GLcontext
*ctx
)
1523 gl_read_config_file( ctx
);
1529 * Copy attribute groups from one context to another.
1530 * Input: src - source context
1531 * dst - destination context
1532 * mask - bitwise OR of GL_*_BIT flags
1534 void gl_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1536 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1537 MEMCPY( &dst
->Accum
, &src
->Accum
, sizeof(struct gl_accum_attrib
) );
1539 if (mask
& GL_COLOR_BUFFER_BIT
) {
1540 MEMCPY( &dst
->Color
, &src
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
1542 if (mask
& GL_CURRENT_BIT
) {
1543 MEMCPY( &dst
->Current
, &src
->Current
, sizeof(struct gl_current_attrib
) );
1545 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1546 MEMCPY( &dst
->Depth
, &src
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
1548 if (mask
& GL_ENABLE_BIT
) {
1551 if (mask
& GL_EVAL_BIT
) {
1552 MEMCPY( &dst
->Eval
, &src
->Eval
, sizeof(struct gl_eval_attrib
) );
1554 if (mask
& GL_FOG_BIT
) {
1555 MEMCPY( &dst
->Fog
, &src
->Fog
, sizeof(struct gl_fog_attrib
) );
1557 if (mask
& GL_HINT_BIT
) {
1558 MEMCPY( &dst
->Hint
, &src
->Hint
, sizeof(struct gl_hint_attrib
) );
1560 if (mask
& GL_LIGHTING_BIT
) {
1561 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light_attrib
) );
1562 /* gl_reinit_light_attrib( &dst->Light ); */
1564 if (mask
& GL_LINE_BIT
) {
1565 MEMCPY( &dst
->Line
, &src
->Line
, sizeof(struct gl_line_attrib
) );
1567 if (mask
& GL_LIST_BIT
) {
1568 MEMCPY( &dst
->List
, &src
->List
, sizeof(struct gl_list_attrib
) );
1570 if (mask
& GL_PIXEL_MODE_BIT
) {
1571 MEMCPY( &dst
->Pixel
, &src
->Pixel
, sizeof(struct gl_pixel_attrib
) );
1573 if (mask
& GL_POINT_BIT
) {
1574 MEMCPY( &dst
->Point
, &src
->Point
, sizeof(struct gl_point_attrib
) );
1576 if (mask
& GL_POLYGON_BIT
) {
1577 MEMCPY( &dst
->Polygon
, &src
->Polygon
, sizeof(struct gl_polygon_attrib
) );
1579 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1580 /* Use loop instead of MEMCPY due to problem with Portland Group's
1581 * C compiler. Reported by John Stone.
1584 for (i
=0;i
<32;i
++) {
1585 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1588 if (mask
& GL_SCISSOR_BIT
) {
1589 MEMCPY( &dst
->Scissor
, &src
->Scissor
, sizeof(struct gl_scissor_attrib
) );
1591 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1592 MEMCPY( &dst
->Stencil
, &src
->Stencil
, sizeof(struct gl_stencil_attrib
) );
1594 if (mask
& GL_TEXTURE_BIT
) {
1595 MEMCPY( &dst
->Texture
, &src
->Texture
, sizeof(struct gl_texture_attrib
) );
1597 if (mask
& GL_TRANSFORM_BIT
) {
1598 MEMCPY( &dst
->Transform
, &src
->Transform
, sizeof(struct gl_transform_attrib
) );
1600 if (mask
& GL_VIEWPORT_BIT
) {
1601 MEMCPY( &dst
->Viewport
, &src
->Viewport
, sizeof(struct gl_viewport_attrib
) );
1607 * Set the current context, binding the given frame buffer to the context.
1609 void gl_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1611 gl_make_current2( newCtx
, buffer
, buffer
);
1616 * Bind the given context to the given draw-buffer and read-buffer
1617 * and make it the current context for this thread.
1619 void gl_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1620 GLframebuffer
*readBuffer
)
1623 GLcontext
*oldCtx
= gl_get_context();
1625 /* Flush the old context
1628 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx
, "gl_make_current");
1630 /* unbind frame buffers from context */
1631 if (oldCtx
->DrawBuffer
) {
1632 oldCtx
->DrawBuffer
= NULL
;
1634 if (oldCtx
->ReadBuffer
) {
1635 oldCtx
->ReadBuffer
= NULL
;
1640 /* We call this function periodically (just here for now) in
1641 * order to detect when multithreading has begun.
1643 _glapi_check_multithread();
1645 _glapi_set_context((void *) newCtx
);
1646 ASSERT(gl_get_current_context() == newCtx
);
1648 SET_IMMEDIATE(newCtx
, newCtx
->input
);
1649 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1652 _glapi_set_dispatch(NULL
); /* none current */
1655 if (MESA_VERBOSE
) fprintf(stderr
, "gl_make_current()\n");
1657 if (newCtx
&& drawBuffer
&& readBuffer
) {
1658 /* TODO: check if newCtx and buffer's visual match??? */
1659 newCtx
->DrawBuffer
= drawBuffer
;
1660 newCtx
->ReadBuffer
= readBuffer
;
1661 newCtx
->NewState
= NEW_ALL
; /* just to be safe */
1662 gl_update_state( newCtx
);
1665 /* We can use this to help debug user's problems. Tell the to set
1666 * the MESA_INFO env variable before running their app. Then the
1667 * first time each context is made current we'll print some useful
1670 if (newCtx
&& newCtx
->FirstTimeCurrent
) {
1671 if (getenv("MESA_INFO")) {
1672 fprintf(stderr
, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION
));
1673 fprintf(stderr
, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER
));
1674 fprintf(stderr
, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR
));
1675 fprintf(stderr
, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS
));
1676 #if defined(THREADS)
1677 fprintf(stderr
, "Mesa thread-safe: YES\n");
1679 fprintf(stderr
, "Mesa thread-safe: NO\n");
1681 #if defined(USE_X86_ASM)
1682 fprintf(stderr
, "Mesa x86-optimized: YES\n");
1684 fprintf(stderr
, "Mesa x86-optimized: NO\n");
1687 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1694 * Return current context handle for the calling thread.
1695 * This isn't the fastest way to get the current context.
1696 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1698 GLcontext
*gl_get_current_context( void )
1700 return (GLcontext
*) _glapi_get_context();
1706 * This should be called by device drivers just before they do a
1707 * swapbuffers. Any pending rendering commands will be executed.
1710 _mesa_swapbuffers(GLcontext
*ctx
)
1712 FLUSH_VB( ctx
, "swap buffers" );
1718 * Return pointer to this context's current API dispatch table.
1719 * It'll either be the immediate-mode execute dispatcher or the
1720 * display list compile dispatcher.
1722 struct _glapi_table
*
1723 _mesa_get_dispatch(GLcontext
*ctx
)
1725 return ctx
->CurrentDispatch
;
1731 _mesa_ResizeBuffersMESA( void )
1733 GLcontext
*ctx
= gl_get_current_context();
1735 GLuint buf_width
, buf_height
;
1737 if (MESA_VERBOSE
& VERBOSE_API
)
1738 fprintf(stderr
, "glResizeBuffersMESA\n");
1740 /* ask device driver for size of output buffer */
1741 (*ctx
->Driver
.GetBufferSize
)( ctx
, &buf_width
, &buf_height
);
1743 /* see if size of device driver's color buffer (window) has changed */
1744 if (ctx
->DrawBuffer
->Width
== (GLint
) buf_width
&&
1745 ctx
->DrawBuffer
->Height
== (GLint
) buf_height
)
1748 ctx
->NewState
|= NEW_RASTER_OPS
; /* to update scissor / window bounds */
1750 /* save buffer size */
1751 ctx
->DrawBuffer
->Width
= buf_width
;
1752 ctx
->DrawBuffer
->Height
= buf_height
;
1754 /* Reallocate other buffers if needed. */
1755 if (ctx
->DrawBuffer
->UseSoftwareDepthBuffer
) {
1756 gl_alloc_depth_buffer( ctx
);
1758 if (ctx
->DrawBuffer
->UseSoftwareStencilBuffer
) {
1759 gl_alloc_stencil_buffer( ctx
);
1761 if (ctx
->DrawBuffer
->UseSoftwareAccumBuffer
) {
1762 gl_alloc_accum_buffer( ctx
);
1764 if (ctx
->Visual
->SoftwareAlpha
) {
1765 gl_alloc_alpha_buffers( ctx
);
1771 /**********************************************************************/
1772 /***** Miscellaneous functions *****/
1773 /**********************************************************************/
1777 * This function is called when the Mesa user has stumbled into a code
1778 * path which may not be implemented fully or correctly.
1780 void gl_problem( const GLcontext
*ctx
, const char *s
)
1782 fprintf( stderr
, "Mesa implementation error: %s\n", s
);
1783 fprintf( stderr
, "Report to mesa-bugs@mesa3d.org\n" );
1790 * This is called to inform the user that he or she has tried to do
1791 * something illogical or if there's likely a bug in their program
1792 * (like enabled depth testing without a depth buffer).
1794 void gl_warning( const GLcontext
*ctx
, const char *s
)
1800 if (getenv("MESA_DEBUG")) {
1808 fprintf( stderr
, "Mesa warning: %s\n", s
);
1815 void gl_compile_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1817 if (ctx
->CompileFlag
)
1818 gl_save_error( ctx
, error
, s
);
1820 if (ctx
->ExecuteFlag
)
1821 gl_error( ctx
, error
, s
);
1826 * This is Mesa's error handler. Normally, all that's done is the updating
1827 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1828 * environment variable "MESA_DEBUG" is defined then a real error message
1829 * is printed to stderr.
1830 * Input: error - the error value
1831 * s - a diagnostic string
1833 void gl_error( GLcontext
*ctx
, GLenum error
, const char *s
)
1840 if (getenv("MESA_DEBUG")) {
1853 strcpy( errstr
, "GL_NO_ERROR" );
1855 case GL_INVALID_VALUE
:
1856 strcpy( errstr
, "GL_INVALID_VALUE" );
1858 case GL_INVALID_ENUM
:
1859 strcpy( errstr
, "GL_INVALID_ENUM" );
1861 case GL_INVALID_OPERATION
:
1862 strcpy( errstr
, "GL_INVALID_OPERATION" );
1864 case GL_STACK_OVERFLOW
:
1865 strcpy( errstr
, "GL_STACK_OVERFLOW" );
1867 case GL_STACK_UNDERFLOW
:
1868 strcpy( errstr
, "GL_STACK_UNDERFLOW" );
1870 case GL_OUT_OF_MEMORY
:
1871 strcpy( errstr
, "GL_OUT_OF_MEMORY" );
1874 strcpy( errstr
, "unknown" );
1877 fprintf( stderr
, "Mesa user error: %s in %s\n", errstr
, s
);
1880 if (ctx
->ErrorValue
==GL_NO_ERROR
) {
1881 ctx
->ErrorValue
= error
;
1884 /* Call device driver's error handler, if any. This is used on the Mac. */
1885 if (ctx
->Driver
.Error
) {
1886 (*ctx
->Driver
.Error
)( ctx
);
1892 /**********************************************************************/
1893 /***** State update logic *****/
1894 /**********************************************************************/
1898 * Since the device driver may or may not support pixel logic ops we
1899 * have to make some extensive tests to determine whether or not
1900 * software-implemented logic operations have to be used.
1902 static void update_pixel_logic( GLcontext
*ctx
)
1904 if (ctx
->Visual
->RGBAflag
) {
1905 /* RGBA mode blending w/ Logic Op */
1906 if (ctx
->Color
.ColorLogicOpEnabled
) {
1907 if (ctx
->Driver
.LogicOp
1908 && (*ctx
->Driver
.LogicOp
)( ctx
, ctx
->Color
.LogicOp
)) {
1909 /* Device driver can do logic, don't have to do it in software */
1910 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
1913 /* Device driver can't do logic op so we do it in software */
1914 ctx
->Color
.SWLogicOpEnabled
= GL_TRUE
;
1919 if (ctx
->Driver
.LogicOp
) {
1920 (void) (*ctx
->Driver
.LogicOp
)( ctx
, GL_COPY
);
1922 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
1926 /* CI mode Logic Op */
1927 if (ctx
->Color
.IndexLogicOpEnabled
) {
1928 if (ctx
->Driver
.LogicOp
1929 && (*ctx
->Driver
.LogicOp
)( ctx
, ctx
->Color
.LogicOp
)) {
1930 /* Device driver can do logic, don't have to do it in software */
1931 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
1934 /* Device driver can't do logic op so we do it in software */
1935 ctx
->Color
.SWLogicOpEnabled
= GL_TRUE
;
1940 if (ctx
->Driver
.LogicOp
) {
1941 (void) (*ctx
->Driver
.LogicOp
)( ctx
, GL_COPY
);
1943 ctx
->Color
.SWLogicOpEnabled
= GL_FALSE
;
1951 * Check if software implemented RGBA or Color Index masking is needed.
1953 static void update_pixel_masking( GLcontext
*ctx
)
1955 if (ctx
->Visual
->RGBAflag
) {
1956 GLuint
*colorMask
= (GLuint
*) ctx
->Color
.ColorMask
;
1957 if (*colorMask
== 0xffffffff) {
1958 /* disable masking */
1959 if (ctx
->Driver
.ColorMask
) {
1960 (void) (*ctx
->Driver
.ColorMask
)( ctx
, GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
1962 ctx
->Color
.SWmasking
= GL_FALSE
;
1965 /* Ask driver to do color masking, if it can't then
1968 GLboolean red
= ctx
->Color
.ColorMask
[RCOMP
] ? GL_TRUE
: GL_FALSE
;
1969 GLboolean green
= ctx
->Color
.ColorMask
[GCOMP
] ? GL_TRUE
: GL_FALSE
;
1970 GLboolean blue
= ctx
->Color
.ColorMask
[BCOMP
] ? GL_TRUE
: GL_FALSE
;
1971 GLboolean alpha
= ctx
->Color
.ColorMask
[ACOMP
] ? GL_TRUE
: GL_FALSE
;
1972 if (ctx
->Driver
.ColorMask
1973 && (*ctx
->Driver
.ColorMask
)( ctx
, red
, green
, blue
, alpha
)) {
1974 ctx
->Color
.SWmasking
= GL_FALSE
;
1977 ctx
->Color
.SWmasking
= GL_TRUE
;
1982 if (ctx
->Color
.IndexMask
==0xffffffff) {
1983 /* disable masking */
1984 if (ctx
->Driver
.IndexMask
) {
1985 (void) (*ctx
->Driver
.IndexMask
)( ctx
, 0xffffffff );
1987 ctx
->Color
.SWmasking
= GL_FALSE
;
1990 /* Ask driver to do index masking, if it can't then
1993 if (ctx
->Driver
.IndexMask
1994 && (*ctx
->Driver
.IndexMask
)( ctx
, ctx
->Color
.IndexMask
)) {
1995 ctx
->Color
.SWmasking
= GL_FALSE
;
1998 ctx
->Color
.SWmasking
= GL_TRUE
;
2005 static void update_fog_mode( GLcontext
*ctx
)
2007 int old_mode
= ctx
->FogMode
;
2009 if (ctx
->Fog
.Enabled
) {
2010 if (ctx
->Texture
.Enabled
)
2011 ctx
->FogMode
= FOG_FRAGMENT
;
2012 else if (ctx
->Hint
.Fog
== GL_NICEST
)
2013 ctx
->FogMode
= FOG_FRAGMENT
;
2015 ctx
->FogMode
= FOG_VERTEX
;
2017 if (ctx
->Driver
.GetParameteri
)
2018 if ((ctx
->Driver
.GetParameteri
)( ctx
, DD_HAVE_HARDWARE_FOG
))
2019 ctx
->FogMode
= FOG_FRAGMENT
;
2022 ctx
->FogMode
= FOG_NONE
;
2025 if (old_mode
!= ctx
->FogMode
)
2026 ctx
->NewState
|= NEW_FOG
;
2031 * Recompute the value of ctx->RasterMask, etc. according to
2032 * the current context.
2034 static void update_rasterflags( GLcontext
*ctx
)
2036 ctx
->RasterMask
= 0;
2038 if (ctx
->Color
.AlphaEnabled
) ctx
->RasterMask
|= ALPHATEST_BIT
;
2039 if (ctx
->Color
.BlendEnabled
) ctx
->RasterMask
|= BLEND_BIT
;
2040 if (ctx
->Depth
.Test
) ctx
->RasterMask
|= DEPTH_BIT
;
2041 if (ctx
->FogMode
==FOG_FRAGMENT
) ctx
->RasterMask
|= FOG_BIT
;
2042 if (ctx
->Color
.SWLogicOpEnabled
) ctx
->RasterMask
|= LOGIC_OP_BIT
;
2043 if (ctx
->Scissor
.Enabled
) ctx
->RasterMask
|= SCISSOR_BIT
;
2044 if (ctx
->Stencil
.Enabled
) ctx
->RasterMask
|= STENCIL_BIT
;
2045 if (ctx
->Color
.SWmasking
) ctx
->RasterMask
|= MASKING_BIT
;
2047 if (ctx
->Visual
->SoftwareAlpha
&& ctx
->Color
.ColorMask
[ACOMP
]
2048 && ctx
->Color
.DrawBuffer
!= GL_NONE
)
2049 ctx
->RasterMask
|= ALPHABUF_BIT
;
2051 if ( ctx
->Viewport
.X
<0
2052 || ctx
->Viewport
.X
+ ctx
->Viewport
.Width
> ctx
->DrawBuffer
->Width
2053 || ctx
->Viewport
.Y
<0
2054 || ctx
->Viewport
.Y
+ ctx
->Viewport
.Height
> ctx
->DrawBuffer
->Height
) {
2055 ctx
->RasterMask
|= WINCLIP_BIT
;
2058 /* If we're not drawing to exactly one color buffer set the
2059 * MULTI_DRAW_BIT flag. Also set it if we're drawing to no
2060 * buffers or the RGBA or CI mask disables all writes.
2063 ctx
->TriangleCaps
&= ~DD_MULTIDRAW
;
2065 if (ctx
->Color
.MultiDrawBuffer
) {
2066 ctx
->RasterMask
|= MULTI_DRAW_BIT
;
2067 ctx
->TriangleCaps
|= DD_MULTIDRAW
;
2069 else if (ctx
->Color
.DrawBuffer
==GL_NONE
) {
2070 ctx
->RasterMask
|= MULTI_DRAW_BIT
;
2071 ctx
->TriangleCaps
|= DD_MULTIDRAW
;
2073 else if (ctx
->Visual
->RGBAflag
&& ctx
->Color
.ColorMask
==0) {
2074 /* all RGBA channels disabled */
2075 ctx
->RasterMask
|= MULTI_DRAW_BIT
;
2076 ctx
->TriangleCaps
|= DD_MULTIDRAW
;
2077 ctx
->Color
.DrawDestMask
= 0;
2079 else if (!ctx
->Visual
->RGBAflag
&& ctx
->Color
.IndexMask
==0) {
2080 /* all color index bits disabled */
2081 ctx
->RasterMask
|= MULTI_DRAW_BIT
;
2082 ctx
->TriangleCaps
|= DD_MULTIDRAW
;
2083 ctx
->Color
.DrawDestMask
= 0;
2088 void gl_print_state( const char *msg
, GLuint state
)
2091 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2094 (state
& NEW_LIGHTING
) ? "lighting, " : "",
2095 (state
& NEW_RASTER_OPS
) ? "raster-ops, " : "",
2096 (state
& NEW_TEXTURING
) ? "texturing, " : "",
2097 (state
& NEW_POLYGON
) ? "polygon, " : "",
2098 (state
& NEW_DRVSTATE0
) ? "driver-0, " : "",
2099 (state
& NEW_DRVSTATE1
) ? "driver-1, " : "",
2100 (state
& NEW_DRVSTATE2
) ? "driver-2, " : "",
2101 (state
& NEW_DRVSTATE3
) ? "driver-3, " : "",
2102 (state
& NEW_MODELVIEW
) ? "modelview, " : "",
2103 (state
& NEW_PROJECTION
) ? "projection, " : "",
2104 (state
& NEW_TEXTURE_MATRIX
) ? "texture-matrix, " : "",
2105 (state
& NEW_USER_CLIP
) ? "user-clip, " : "",
2106 (state
& NEW_TEXTURE_ENV
) ? "texture-env, " : "",
2107 (state
& NEW_CLIENT_STATE
) ? "client-state, " : "",
2108 (state
& NEW_FOG
) ? "fog, " : "",
2109 (state
& NEW_NORMAL_TRANSFORM
) ? "normal-transform, " : "",
2110 (state
& NEW_VIEWPORT
) ? "viewport, " : "",
2111 (state
& NEW_TEXTURE_ENABLE
) ? "texture-enable, " : "");
2114 void gl_print_enable_flags( const char *msg
, GLuint flags
)
2117 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s\n",
2120 (flags
& ENABLE_TEX0
) ? "tex-0, " : "",
2121 (flags
& ENABLE_TEX1
) ? "tex-1, " : "",
2122 (flags
& ENABLE_LIGHT
) ? "light, " : "",
2123 (flags
& ENABLE_FOG
) ? "fog, " : "",
2124 (flags
& ENABLE_USERCLIP
) ? "userclip, " : "",
2125 (flags
& ENABLE_TEXGEN0
) ? "tex-gen-0, " : "",
2126 (flags
& ENABLE_TEXGEN1
) ? "tex-gen-1, " : "",
2127 (flags
& ENABLE_TEXMAT0
) ? "tex-mat-0, " : "",
2128 (flags
& ENABLE_TEXMAT1
) ? "tex-mat-1, " : "",
2129 (flags
& ENABLE_NORMALIZE
) ? "normalize, " : "",
2130 (flags
& ENABLE_RESCALE
) ? "rescale, " : "");
2135 * If ctx->NewState is non-zero then this function MUST be called before
2136 * rendering any primitive. Basically, function pointers and miscellaneous
2137 * flags are updated to reflect the current state of the state machine.
2139 void gl_update_state( GLcontext
*ctx
)
2143 if (MESA_VERBOSE
& VERBOSE_STATE
)
2144 gl_print_state("", ctx
->NewState
);
2146 if (ctx
->NewState
& NEW_CLIENT_STATE
)
2147 gl_update_client_state( ctx
);
2149 if ((ctx
->NewState
& NEW_TEXTURE_ENABLE
) &&
2150 (ctx
->Enabled
& ENABLE_TEX_ANY
) != ctx
->Texture
.Enabled
)
2151 ctx
->NewState
|= NEW_TEXTURING
| NEW_RASTER_OPS
;
2153 if (ctx
->NewState
& NEW_TEXTURE_ENV
) {
2154 if (ctx
->Texture
.Unit
[0].EnvMode
== ctx
->Texture
.Unit
[0].LastEnvMode
&&
2155 ctx
->Texture
.Unit
[1].EnvMode
== ctx
->Texture
.Unit
[1].LastEnvMode
)
2156 ctx
->NewState
&= ~NEW_TEXTURE_ENV
;
2157 ctx
->Texture
.Unit
[0].LastEnvMode
= ctx
->Texture
.Unit
[0].EnvMode
;
2158 ctx
->Texture
.Unit
[1].LastEnvMode
= ctx
->Texture
.Unit
[1].EnvMode
;
2161 if (ctx
->NewState
& NEW_TEXTURE_MATRIX
) {
2162 ctx
->Enabled
&= ~(ENABLE_TEXMAT0
|ENABLE_TEXMAT1
);
2164 for (i
=0; i
< MAX_TEXTURE_UNITS
; i
++) {
2165 if (ctx
->TextureMatrix
[i
].flags
& MAT_DIRTY_ALL_OVER
)
2167 gl_matrix_analyze( &ctx
->TextureMatrix
[i
] );
2168 ctx
->TextureMatrix
[i
].flags
&= ~MAT_DIRTY_DEPENDENTS
;
2170 if (ctx
->Texture
.Unit
[i
].Enabled
&&
2171 ctx
->TextureMatrix
[i
].type
!= MATRIX_IDENTITY
)
2172 ctx
->Enabled
|= ENABLE_TEXMAT0
<< i
;
2177 if (ctx
->NewState
& (NEW_TEXTURING
| NEW_TEXTURE_ENABLE
)) {
2178 ctx
->Texture
.NeedNormals
= GL_FALSE
;
2179 gl_update_dirty_texobjs(ctx
);
2180 ctx
->Enabled
&= ~(ENABLE_TEXGEN0
|ENABLE_TEXGEN1
);
2181 ctx
->Texture
.ReallyEnabled
= 0;
2183 for (i
=0; i
< MAX_TEXTURE_UNITS
; i
++) {
2184 if (ctx
->Texture
.Unit
[i
].Enabled
) {
2185 gl_update_texture_unit( ctx
, &ctx
->Texture
.Unit
[i
] );
2187 ctx
->Texture
.ReallyEnabled
|=
2188 ctx
->Texture
.Unit
[i
].ReallyEnabled
<<(i
*4);
2190 if (ctx
->Texture
.Unit
[i
].GenFlags
!= 0) {
2191 ctx
->Enabled
|= ENABLE_TEXGEN0
<< i
;
2193 if (ctx
->Texture
.Unit
[i
].GenFlags
& TEXGEN_NEED_NORMALS
)
2195 ctx
->Texture
.NeedNormals
= GL_TRUE
;
2196 ctx
->Texture
.NeedEyeCoords
= GL_TRUE
;
2199 if (ctx
->Texture
.Unit
[i
].GenFlags
& TEXGEN_NEED_EYE_COORD
)
2201 ctx
->Texture
.NeedEyeCoords
= GL_TRUE
;
2207 ctx
->Texture
.Enabled
= ctx
->Enabled
& ENABLE_TEX_ANY
;
2208 ctx
->NeedNormals
= (ctx
->Light
.Enabled
|| ctx
->Texture
.NeedNormals
);
2211 if (ctx
->NewState
& (NEW_RASTER_OPS
| NEW_LIGHTING
| NEW_FOG
)) {
2214 if (ctx
->NewState
& NEW_RASTER_OPS
) {
2215 update_pixel_logic(ctx
);
2216 update_pixel_masking(ctx
);
2217 update_fog_mode(ctx
);
2218 update_rasterflags(ctx
);
2219 if (ctx
->Driver
.Dither
) {
2220 (*ctx
->Driver
.Dither
)( ctx
, ctx
->Color
.DitherFlag
);
2223 /* Check if incoming colors can be modified during rasterization */
2224 if (ctx
->Fog
.Enabled
||
2225 ctx
->Texture
.Enabled
||
2226 ctx
->Color
.BlendEnabled
||
2227 ctx
->Color
.SWmasking
||
2228 ctx
->Color
.SWLogicOpEnabled
) {
2229 ctx
->MutablePixels
= GL_TRUE
;
2232 ctx
->MutablePixels
= GL_FALSE
;
2235 /* update scissor region */
2237 ctx
->DrawBuffer
->Xmin
= 0;
2238 ctx
->DrawBuffer
->Ymin
= 0;
2239 ctx
->DrawBuffer
->Xmax
= ctx
->DrawBuffer
->Width
-1;
2240 ctx
->DrawBuffer
->Ymax
= ctx
->DrawBuffer
->Height
-1;
2241 if (ctx
->Scissor
.Enabled
) {
2242 if (ctx
->Scissor
.X
> ctx
->DrawBuffer
->Xmin
) {
2243 ctx
->DrawBuffer
->Xmin
= ctx
->Scissor
.X
;
2245 if (ctx
->Scissor
.Y
> ctx
->DrawBuffer
->Ymin
) {
2246 ctx
->DrawBuffer
->Ymin
= ctx
->Scissor
.Y
;
2248 if (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
- 1 < ctx
->DrawBuffer
->Xmax
) {
2249 ctx
->DrawBuffer
->Xmax
= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
- 1;
2251 if (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
- 1 < ctx
->DrawBuffer
->Ymax
) {
2252 ctx
->DrawBuffer
->Ymax
= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
- 1;
2257 if (ctx
->NewState
& NEW_LIGHTING
) {
2258 ctx
->TriangleCaps
&= ~(DD_TRI_LIGHT_TWOSIDE
|DD_LIGHTING_CULL
);
2259 if (ctx
->Light
.Enabled
) {
2260 if (ctx
->Light
.Model
.TwoSide
)
2261 ctx
->TriangleCaps
|= (DD_TRI_LIGHT_TWOSIDE
|DD_LIGHTING_CULL
);
2262 gl_update_lighting(ctx
);
2267 if (ctx
->NewState
& (NEW_POLYGON
| NEW_LIGHTING
)) {
2269 ctx
->TriangleCaps
&= ~DD_TRI_CULL_FRONT_BACK
;
2271 if (ctx
->NewState
& NEW_POLYGON
) {
2272 /* Setup CullBits bitmask */
2273 if (ctx
->Polygon
.CullFlag
) {
2274 ctx
->backface_sign
= 1;
2275 switch(ctx
->Polygon
.CullFaceMode
) {
2277 if(ctx
->Polygon
.FrontFace
==GL_CCW
)
2278 ctx
->backface_sign
= -1;
2279 ctx
->Polygon
.CullBits
= 1;
2282 if(ctx
->Polygon
.FrontFace
!=GL_CCW
)
2283 ctx
->backface_sign
= -1;
2284 ctx
->Polygon
.CullBits
= 2;
2287 case GL_FRONT_AND_BACK
:
2288 ctx
->backface_sign
= 0;
2289 ctx
->Polygon
.CullBits
= 0;
2290 ctx
->TriangleCaps
|= DD_TRI_CULL_FRONT_BACK
;
2295 ctx
->Polygon
.CullBits
= 3;
2296 ctx
->backface_sign
= 0;
2299 /* Any Polygon offsets enabled? */
2300 ctx
->TriangleCaps
&= ~DD_TRI_OFFSET
;
2302 if (ctx
->Polygon
.OffsetPoint
||
2303 ctx
->Polygon
.OffsetLine
||
2304 ctx
->Polygon
.OffsetFill
)
2305 ctx
->TriangleCaps
|= DD_TRI_OFFSET
;
2307 /* reset Z offsets now */
2308 ctx
->PointZoffset
= 0.0;
2309 ctx
->LineZoffset
= 0.0;
2310 ctx
->PolygonZoffset
= 0.0;
2314 if (ctx
->NewState
& ~(NEW_CLIENT_STATE
|
2315 NEW_DRIVER_STATE
|NEW_USER_CLIP
|
2317 gl_update_clipmask(ctx
);
2319 if (ctx
->NewState
& (NEW_LIGHTING
|
2331 ctx
->IndirectTriangles
= ctx
->TriangleCaps
& ~ctx
->Driver
.TriangleCaps
;
2332 ctx
->IndirectTriangles
|= DD_SW_RASTERIZE
;
2334 if (MESA_VERBOSE
&VERBOSE_CULL
)
2335 gl_print_tri_caps("initial indirect tris", ctx
->IndirectTriangles
);
2337 ctx
->Driver
.PointsFunc
= NULL
;
2338 ctx
->Driver
.LineFunc
= NULL
;
2339 ctx
->Driver
.TriangleFunc
= NULL
;
2340 ctx
->Driver
.QuadFunc
= NULL
;
2341 ctx
->Driver
.RectFunc
= NULL
;
2342 ctx
->Driver
.RenderVBClippedTab
= NULL
;
2343 ctx
->Driver
.RenderVBCulledTab
= NULL
;
2344 ctx
->Driver
.RenderVBRawTab
= NULL
;
2347 * Here the driver sets up all the ctx->Driver function pointers to
2348 * it's specific, private functions.
2350 ctx
->Driver
.UpdateState(ctx
);
2352 if (MESA_VERBOSE
&VERBOSE_CULL
)
2353 gl_print_tri_caps("indirect tris", ctx
->IndirectTriangles
);
2356 * In case the driver didn't hook in an optimized point, line or
2357 * triangle function we'll now select "core/fallback" point, line
2358 * and triangle functions.
2360 if (ctx
->IndirectTriangles
& DD_SW_RASTERIZE
) {
2361 gl_set_point_function(ctx
);
2362 gl_set_line_function(ctx
);
2363 gl_set_triangle_function(ctx
);
2364 gl_set_quad_function(ctx
);
2366 if ((ctx
->IndirectTriangles
&
2367 (DD_TRI_SW_RASTERIZE
|DD_QUAD_SW_RASTERIZE
|DD_TRI_CULL
)) ==
2368 (DD_TRI_SW_RASTERIZE
|DD_QUAD_SW_RASTERIZE
|DD_TRI_CULL
))
2369 ctx
->IndirectTriangles
&= ~DD_TRI_CULL
;
2372 if (MESA_VERBOSE
&VERBOSE_CULL
)
2373 gl_print_tri_caps("indirect tris 2", ctx
->IndirectTriangles
);
2375 gl_set_render_vb_function(ctx
);
2378 /* Should only be calc'd when !need_eye_coords and not culling.
2380 if (ctx
->NewState
& (NEW_MODELVIEW
|NEW_PROJECTION
)) {
2381 if (ctx
->NewState
& NEW_MODELVIEW
) {
2382 gl_matrix_analyze( &ctx
->ModelView
);
2383 ctx
->ProjectionMatrix
.flags
&= ~MAT_DIRTY_DEPENDENTS
;
2386 if (ctx
->NewState
& NEW_PROJECTION
) {
2387 gl_matrix_analyze( &ctx
->ProjectionMatrix
);
2388 ctx
->ProjectionMatrix
.flags
&= ~MAT_DIRTY_DEPENDENTS
;
2390 if (ctx
->Transform
.AnyClip
) {
2391 gl_update_userclip( ctx
);
2395 gl_calculate_model_project_matrix( ctx
);
2396 ctx
->ModelProjectWinMatrixUptodate
= 0;
2399 /* Figure out whether we can light in object space or not. If we
2400 * can, find the current positions of the lights in object space
2402 if ((ctx
->Enabled
& (ENABLE_POINT_ATTEN
| ENABLE_LIGHT
| ENABLE_FOG
|
2403 ENABLE_TEXGEN0
| ENABLE_TEXGEN1
)) &&
2404 (ctx
->NewState
& (NEW_LIGHTING
|
2412 GLboolean oldcoord
, oldnorm
;
2414 oldcoord
= ctx
->NeedEyeCoords
;
2415 oldnorm
= ctx
->NeedEyeNormals
;
2417 ctx
->NeedNormals
= (ctx
->Light
.Enabled
|| ctx
->Texture
.NeedNormals
);
2418 ctx
->NeedEyeCoords
= ((ctx
->Fog
.Enabled
&& ctx
->Hint
.Fog
!= GL_NICEST
) ||
2419 ctx
->Point
.Attenuated
);
2420 ctx
->NeedEyeNormals
= GL_FALSE
;
2422 if (ctx
->Light
.Enabled
) {
2423 if (ctx
->Light
.Flags
& LIGHT_POSITIONAL
) {
2424 /* Need length for attenuation */
2425 if (!TEST_MAT_FLAGS( &ctx
->ModelView
, MAT_FLAGS_LENGTH_PRESERVING
))
2426 ctx
->NeedEyeCoords
= GL_TRUE
;
2427 } else if (ctx
->Light
.NeedVertices
) {
2428 /* Need angle for spot calculations */
2429 if (!TEST_MAT_FLAGS( &ctx
->ModelView
, MAT_FLAGS_ANGLE_PRESERVING
))
2430 ctx
->NeedEyeCoords
= GL_TRUE
;
2432 ctx
->NeedEyeNormals
= ctx
->NeedEyeCoords
;
2434 if (ctx
->Texture
.Enabled
|| ctx
->RenderMode
==GL_FEEDBACK
) {
2435 if (ctx
->Texture
.NeedEyeCoords
) ctx
->NeedEyeCoords
= GL_TRUE
;
2436 if (ctx
->Texture
.NeedNormals
)
2437 ctx
->NeedNormals
= ctx
->NeedEyeNormals
= GL_TRUE
;
2440 ctx
->vb_proj_matrix
= &ctx
->ModelProjectMatrix
;
2442 if (ctx
->NeedEyeCoords
)
2443 ctx
->vb_proj_matrix
= &ctx
->ProjectionMatrix
;
2445 if (ctx
->Light
.Enabled
) {
2446 gl_update_lighting_function(ctx
);
2448 if ( (ctx
->NewState
& NEW_LIGHTING
) ||
2449 ((ctx
->NewState
& (NEW_MODELVIEW
| NEW_PROJECTION
)) &&
2450 !ctx
->NeedEyeCoords
) ||
2451 oldcoord
!= ctx
->NeedEyeCoords
||
2452 oldnorm
!= ctx
->NeedEyeNormals
) {
2453 gl_compute_light_positions(ctx
);
2456 ctx
->rescale_factor
= 1.0F
;
2458 if (ctx
->ModelView
.flags
& (MAT_FLAG_UNIFORM_SCALE
|
2459 MAT_FLAG_GENERAL_SCALE
|
2460 MAT_FLAG_GENERAL_3D
|
2464 GLfloat
*m
= ctx
->ModelView
.inv
;
2465 GLfloat f
= m
[2]*m
[2] + m
[6]*m
[6] + m
[10]*m
[10];
2466 if (f
> 1e-12 && (f
-1)*(f
-1) > 1e-12)
2467 ctx
->rescale_factor
= 1.0/GL_SQRT(f
);
2471 gl_update_normal_transform( ctx
);
2474 gl_update_pipelines(ctx
);