2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Mesa context/visual/framebuffer management functions.
33 * \mainpage Mesa Main Module
35 * \section MainIntroduction Introduction
37 * The Mesa Main module consists of all the files in the main/ directory.
38 * Among the features of this module are:
40 * <LI> Structures to represent most GL state </LI>
41 * <LI> State set/get functions </LI>
42 * <LI> Display lists </LI>
43 * <LI> Texture unit, object and image handling </LI>
44 * <LI> Matrix and attribute stacks </LI>
47 * Other modules are responsible for API dispatch, vertex transformation,
48 * point/line/triangle setup, rasterization, vertex array caching,
49 * vertex/fragment programs/shaders, etc.
52 * \section AboutDoxygen About Doxygen
54 * If you're viewing this information as Doxygen-generated HTML you'll
55 * see the documentation index at the top of this page.
57 * The first line lists the Mesa source code modules.
58 * The second line lists the indexes available for viewing the documentation
61 * Selecting the <b>Main page</b> link will display a summary of the module
64 * Selecting <b>Data Structures</b> will list all C structures.
66 * Selecting the <b>File List</b> link will list all the source files in
68 * Selecting a filename will show a list of all functions defined in that file.
70 * Selecting the <b>Data Fields</b> link will display a list of all
71 * documented structure members.
73 * Selecting the <b>Globals</b> link will display a list
74 * of all functions, structures, global variables and macros in the module.
80 #include "mfeatures.h"
88 #include "bufferobj.h"
95 #include "extensions.h"
99 #include "framebuffer.h"
106 #include "multisample.h"
108 #include "pixelstore.h"
114 #include "shaderobj.h"
115 #include "simple_list.h"
118 #include "texstate.h"
122 #include "viewport.h"
124 #include "program/program.h"
125 #include "program/prog_print.h"
127 #include "math/m_matrix.h"
129 #include "main/dispatch.h" /* for _gloffset_COUNT */
132 #include "sparc/sparc.h"
135 #include "glsl_parser_extras.h"
140 int MESA_VERBOSE
= 0;
143 #ifndef MESA_DEBUG_FLAGS
144 int MESA_DEBUG_FLAGS
= 0;
148 /* ubyte -> float conversion */
149 GLfloat _mesa_ubyte_to_float_color_tab
[256];
154 * Swap buffers notification callback.
156 * \param ctx GL context.
158 * Called by window system just before swapping buffers.
159 * We have to finish any pending rendering.
162 _mesa_notifySwapBuffers(struct gl_context
*ctx
)
164 if (MESA_VERBOSE
& VERBOSE_SWAPBUFFERS
)
165 _mesa_debug(ctx
, "SwapBuffers\n");
166 FLUSH_CURRENT( ctx
, 0 );
167 if (ctx
->Driver
.Flush
) {
168 ctx
->Driver
.Flush(ctx
);
173 /**********************************************************************/
174 /** \name GL Visual allocation/destruction */
175 /**********************************************************************/
179 * Allocates a struct gl_config structure and initializes it via
180 * _mesa_initialize_visual().
182 * \param dbFlag double buffering
183 * \param stereoFlag stereo buffer
184 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
185 * is acceptable but the actual depth type will be GLushort or GLuint as
187 * \param stencilBits requested minimum bits per stencil buffer value
188 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number
189 * of bits per color component in accum buffer.
190 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
191 * \param redBits number of bits per color component in frame buffer for RGB(A)
192 * mode. We always use 8 in core Mesa though.
193 * \param greenBits same as above.
194 * \param blueBits same as above.
195 * \param alphaBits same as above.
197 * \return pointer to new struct gl_config or NULL if requested parameters
200 * \note Need to add params for level and numAuxBuffers (at least)
203 _mesa_create_visual( GLboolean dbFlag
,
204 GLboolean stereoFlag
,
212 GLint accumGreenBits
,
214 GLint accumAlphaBits
)
216 struct gl_config
*vis
= CALLOC_STRUCT(gl_config
);
218 if (!_mesa_initialize_visual(vis
, dbFlag
, stereoFlag
,
219 redBits
, greenBits
, blueBits
, alphaBits
,
220 depthBits
, stencilBits
,
221 accumRedBits
, accumGreenBits
,
222 accumBlueBits
, accumAlphaBits
)) {
232 * Makes some sanity checks and fills in the fields of the struct
233 * gl_config object with the given parameters. If the caller needs to
234 * set additional fields, he should just probably init the whole
235 * gl_config object himself.
237 * \return GL_TRUE on success, or GL_FALSE on failure.
239 * \sa _mesa_create_visual() above for the parameter description.
242 _mesa_initialize_visual( struct gl_config
*vis
,
244 GLboolean stereoFlag
,
252 GLint accumGreenBits
,
254 GLint accumAlphaBits
)
258 if (depthBits
< 0 || depthBits
> 32) {
261 if (stencilBits
< 0 || stencilBits
> STENCIL_BITS
) {
264 assert(accumRedBits
>= 0);
265 assert(accumGreenBits
>= 0);
266 assert(accumBlueBits
>= 0);
267 assert(accumAlphaBits
>= 0);
269 vis
->rgbMode
= GL_TRUE
;
270 vis
->doubleBufferMode
= dbFlag
;
271 vis
->stereoMode
= stereoFlag
;
273 vis
->redBits
= redBits
;
274 vis
->greenBits
= greenBits
;
275 vis
->blueBits
= blueBits
;
276 vis
->alphaBits
= alphaBits
;
277 vis
->rgbBits
= redBits
+ greenBits
+ blueBits
;
280 vis
->depthBits
= depthBits
;
281 vis
->stencilBits
= stencilBits
;
283 vis
->accumRedBits
= accumRedBits
;
284 vis
->accumGreenBits
= accumGreenBits
;
285 vis
->accumBlueBits
= accumBlueBits
;
286 vis
->accumAlphaBits
= accumAlphaBits
;
288 vis
->haveAccumBuffer
= accumRedBits
> 0;
289 vis
->haveDepthBuffer
= depthBits
> 0;
290 vis
->haveStencilBuffer
= stencilBits
> 0;
292 vis
->numAuxBuffers
= 0;
300 * Destroy a visual and free its memory.
304 * Frees the visual structure.
307 _mesa_destroy_visual( struct gl_config
*vis
)
315 /**********************************************************************/
316 /** \name Context allocation, initialization, destroying
318 * The purpose of the most initialization functions here is to provide the
319 * default state values according to the OpenGL specification.
321 /**********************************************************************/
326 * This is lame. gdb only seems to recognize enum types that are
327 * actually used somewhere. We want to be able to print/use enum
328 * values such as TEXTURE_2D_INDEX in gdb. But we don't actually use
329 * the gl_texture_index type anywhere. Thus, this lame function.
332 dummy_enum_func(void)
334 gl_buffer_index bi
= BUFFER_FRONT_LEFT
;
335 gl_face_index fi
= FACE_POS_X
;
336 gl_frag_attrib fa
= FRAG_ATTRIB_WPOS
;
337 gl_frag_result fr
= FRAG_RESULT_DEPTH
;
338 gl_vert_attrib va
= VERT_ATTRIB_POS
;
339 gl_vert_result vr
= VERT_RESULT_HPOS
;
351 * One-time initialization mutex lock.
353 * \sa Used by one_time_init().
355 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
360 * Calls all the various one-time-init functions in Mesa.
362 * While holding a global mutex lock, calls several initialization functions,
363 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
369 one_time_init( struct gl_context
*ctx
)
371 static GLboolean api_init
= GL_FALSE
;
373 _glthread_LOCK_MUTEX(OneTimeLock
);
375 /* truly one-time init */
379 /* do some implementation tests */
380 assert( sizeof(GLbyte
) == 1 );
381 assert( sizeof(GLubyte
) == 1 );
382 assert( sizeof(GLshort
) == 2 );
383 assert( sizeof(GLushort
) == 2 );
384 assert( sizeof(GLint
) == 4 );
385 assert( sizeof(GLuint
) == 4 );
387 _mesa_get_cpu_features();
389 _mesa_init_sqrt_table();
391 /* context dependence is never a one-time thing... */
392 _mesa_init_get_hash(ctx
);
394 for (i
= 0; i
< 256; i
++) {
395 _mesa_ubyte_to_float_color_tab
[i
] = (float) i
/ 255.0F
;
398 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
399 if (MESA_VERBOSE
!= 0) {
400 _mesa_debug(ctx
, "Mesa %s DEBUG build %s %s\n",
401 MESA_VERSION_STRING
, __DATE__
, __TIME__
);
406 _mesa_test_formats();
412 _glthread_UNLOCK_MUTEX(OneTimeLock
);
414 /* Hopefully atexit() is widely available. If not, we may need some
417 atexit(_mesa_destroy_shader_compiler
);
424 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
427 _mesa_init_current(struct gl_context
*ctx
)
431 /* Init all to (0,0,0,1) */
432 for (i
= 0; i
< Elements(ctx
->Current
.Attrib
); i
++) {
433 ASSIGN_4V( ctx
->Current
.Attrib
[i
], 0.0, 0.0, 0.0, 1.0 );
436 /* redo special cases: */
437 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_WEIGHT
], 1.0, 0.0, 0.0, 0.0 );
438 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
], 0.0, 0.0, 1.0, 1.0 );
439 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], 1.0, 1.0, 1.0, 1.0 );
440 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
], 0.0, 0.0, 0.0, 1.0 );
441 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR_INDEX
], 1.0, 0.0, 0.0, 1.0 );
442 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
], 1.0, 0.0, 0.0, 1.0 );
447 * Init vertex/fragment/geometry program limits.
448 * Important: drivers should override these with actual limits.
451 init_program_limits(GLenum type
, struct gl_program_constants
*prog
)
453 prog
->MaxInstructions
= MAX_PROGRAM_INSTRUCTIONS
;
454 prog
->MaxAluInstructions
= MAX_PROGRAM_INSTRUCTIONS
;
455 prog
->MaxTexInstructions
= MAX_PROGRAM_INSTRUCTIONS
;
456 prog
->MaxTexIndirections
= MAX_PROGRAM_INSTRUCTIONS
;
457 prog
->MaxTemps
= MAX_PROGRAM_TEMPS
;
458 prog
->MaxEnvParams
= MAX_PROGRAM_ENV_PARAMS
;
459 prog
->MaxLocalParams
= MAX_PROGRAM_LOCAL_PARAMS
;
460 prog
->MaxAddressOffset
= MAX_PROGRAM_LOCAL_PARAMS
;
463 case GL_VERTEX_PROGRAM_ARB
:
464 prog
->MaxParameters
= MAX_VERTEX_PROGRAM_PARAMS
;
465 prog
->MaxAttribs
= MAX_NV_VERTEX_PROGRAM_INPUTS
;
466 prog
->MaxAddressRegs
= MAX_VERTEX_PROGRAM_ADDRESS_REGS
;
467 prog
->MaxUniformComponents
= 4 * MAX_UNIFORMS
;
469 case GL_FRAGMENT_PROGRAM_ARB
:
470 prog
->MaxParameters
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
471 prog
->MaxAttribs
= MAX_NV_FRAGMENT_PROGRAM_INPUTS
;
472 prog
->MaxAddressRegs
= MAX_FRAGMENT_PROGRAM_ADDRESS_REGS
;
473 prog
->MaxUniformComponents
= 4 * MAX_UNIFORMS
;
476 assert(0 && "Bad program type in init_program_limits()");
479 /* Set the native limits to zero. This implies that there is no native
480 * support for shaders. Let the drivers fill in the actual values.
482 prog
->MaxNativeInstructions
= 0;
483 prog
->MaxNativeAluInstructions
= 0;
484 prog
->MaxNativeTexInstructions
= 0;
485 prog
->MaxNativeTexIndirections
= 0;
486 prog
->MaxNativeAttribs
= 0;
487 prog
->MaxNativeTemps
= 0;
488 prog
->MaxNativeAddressRegs
= 0;
489 prog
->MaxNativeParameters
= 0;
494 * Initialize fields of gl_constants (aka ctx->Const.*).
495 * Use defaults from config.h. The device drivers will often override
496 * some of these values (such as number of texture units).
499 _mesa_init_constants(struct gl_context
*ctx
)
503 /* Constants, may be overriden (usually only reduced) by device drivers */
504 ctx
->Const
.MaxTextureMbytes
= MAX_TEXTURE_MBYTES
;
505 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
506 ctx
->Const
.Max3DTextureLevels
= MAX_3D_TEXTURE_LEVELS
;
507 ctx
->Const
.MaxCubeTextureLevels
= MAX_CUBE_TEXTURE_LEVELS
;
508 ctx
->Const
.MaxTextureCoordUnits
= MAX_TEXTURE_COORD_UNITS
;
509 ctx
->Const
.MaxTextureImageUnits
= MAX_TEXTURE_IMAGE_UNITS
;
510 ctx
->Const
.MaxTextureUnits
= MIN2(ctx
->Const
.MaxTextureCoordUnits
,
511 ctx
->Const
.MaxTextureImageUnits
);
512 ctx
->Const
.MaxTextureMaxAnisotropy
= MAX_TEXTURE_MAX_ANISOTROPY
;
513 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
514 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
515 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
516 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
517 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
518 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
519 ctx
->Const
.PointSizeGranularity
= (GLfloat
) POINT_SIZE_GRANULARITY
;
520 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
521 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
522 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
523 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
524 ctx
->Const
.LineWidthGranularity
= (GLfloat
) LINE_WIDTH_GRANULARITY
;
525 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
526 ctx
->Const
.MaxClipPlanes
= 6;
527 ctx
->Const
.MaxLights
= MAX_LIGHTS
;
528 ctx
->Const
.MaxShininess
= 128.0;
529 ctx
->Const
.MaxSpotExponent
= 128.0;
530 ctx
->Const
.MaxViewportWidth
= MAX_WIDTH
;
531 ctx
->Const
.MaxViewportHeight
= MAX_HEIGHT
;
532 #if FEATURE_ARB_vertex_program
533 init_program_limits(GL_VERTEX_PROGRAM_ARB
, &ctx
->Const
.VertexProgram
);
535 #if FEATURE_ARB_fragment_program
536 init_program_limits(GL_FRAGMENT_PROGRAM_ARB
, &ctx
->Const
.FragmentProgram
);
538 ctx
->Const
.MaxProgramMatrices
= MAX_PROGRAM_MATRICES
;
539 ctx
->Const
.MaxProgramMatrixStackDepth
= MAX_PROGRAM_MATRIX_STACK_DEPTH
;
541 /* CheckArrayBounds is overriden by drivers/x11 for X server */
542 ctx
->Const
.CheckArrayBounds
= GL_FALSE
;
544 #if FEATURE_ARB_vertex_shader
545 ctx
->Const
.MaxVertexTextureImageUnits
= MAX_VERTEX_TEXTURE_IMAGE_UNITS
;
546 ctx
->Const
.MaxCombinedTextureImageUnits
= MAX_COMBINED_TEXTURE_IMAGE_UNITS
;
547 ctx
->Const
.MaxVarying
= MAX_VARYING
;
550 ctx
->Const
.GLSLVersion
= 120;
551 _mesa_override_glsl_version(ctx
);
553 /* GL_ATI_envmap_bumpmap */
554 ctx
->Const
.SupportedBumpUnits
= SUPPORTED_ATI_BUMP_UNITS
;
556 /* GL 3.2: hard-coded for now: */
557 ctx
->Const
.ProfileMask
= GL_CONTEXT_COMPATIBILITY_PROFILE_BIT
;
559 /** GL_EXT_gpu_shader4 */
560 ctx
->Const
.MinProgramTexelOffset
= -8;
561 ctx
->Const
.MaxProgramTexelOffset
= 7;
563 /* GL_ARB_robustness */
564 ctx
->Const
.ResetStrategy
= GL_NO_RESET_NOTIFICATION_ARB
;
569 * Do some sanity checks on the limits/constants for the given context.
570 * Only called the first time a context is bound.
573 check_context_limits(struct gl_context
*ctx
)
575 /* check that we don't exceed the size of various bitfields */
576 assert(VERT_RESULT_MAX
<=
577 (8 * sizeof(ctx
->VertexProgram
._Current
->Base
.OutputsWritten
)));
578 assert(FRAG_ATTRIB_MAX
<=
579 (8 * sizeof(ctx
->FragmentProgram
._Current
->Base
.InputsRead
)));
581 assert(MAX_COMBINED_TEXTURE_IMAGE_UNITS
<= 8 * sizeof(GLbitfield
));
583 /* shader-related checks */
584 assert(ctx
->Const
.FragmentProgram
.MaxLocalParams
<= MAX_PROGRAM_LOCAL_PARAMS
);
585 assert(ctx
->Const
.VertexProgram
.MaxLocalParams
<= MAX_PROGRAM_LOCAL_PARAMS
);
587 assert(MAX_NV_FRAGMENT_PROGRAM_TEMPS
<= MAX_PROGRAM_TEMPS
);
588 assert(MAX_NV_VERTEX_PROGRAM_TEMPS
<= MAX_PROGRAM_TEMPS
);
589 assert(MAX_NV_VERTEX_PROGRAM_INPUTS
<= VERT_ATTRIB_MAX
);
590 assert(MAX_NV_VERTEX_PROGRAM_OUTPUTS
<= VERT_RESULT_MAX
);
592 /* Texture unit checks */
593 assert(ctx
->Const
.MaxTextureImageUnits
> 0);
594 assert(ctx
->Const
.MaxTextureImageUnits
<= MAX_TEXTURE_IMAGE_UNITS
);
595 assert(ctx
->Const
.MaxTextureCoordUnits
> 0);
596 assert(ctx
->Const
.MaxTextureCoordUnits
<= MAX_TEXTURE_COORD_UNITS
);
597 assert(ctx
->Const
.MaxTextureUnits
> 0);
598 assert(ctx
->Const
.MaxTextureUnits
<= MAX_TEXTURE_IMAGE_UNITS
);
599 assert(ctx
->Const
.MaxTextureUnits
<= MAX_TEXTURE_COORD_UNITS
);
600 assert(ctx
->Const
.MaxTextureUnits
== MIN2(ctx
->Const
.MaxTextureImageUnits
,
601 ctx
->Const
.MaxTextureCoordUnits
));
602 assert(ctx
->Const
.MaxCombinedTextureImageUnits
> 0);
603 assert(ctx
->Const
.MaxCombinedTextureImageUnits
<= MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
604 assert(ctx
->Const
.MaxTextureCoordUnits
<= MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
605 /* number of coord units cannot be greater than number of image units */
606 assert(ctx
->Const
.MaxTextureCoordUnits
<= ctx
->Const
.MaxTextureImageUnits
);
609 /* Texture size checks */
610 assert(ctx
->Const
.MaxTextureLevels
<= MAX_TEXTURE_LEVELS
);
611 assert(ctx
->Const
.Max3DTextureLevels
<= MAX_3D_TEXTURE_LEVELS
);
612 assert(ctx
->Const
.MaxCubeTextureLevels
<= MAX_CUBE_TEXTURE_LEVELS
);
614 /* make sure largest texture image is <= MAX_WIDTH in size */
615 assert((1 << (ctx
->Const
.MaxTextureLevels
- 1)) <= MAX_WIDTH
);
616 assert((1 << (ctx
->Const
.MaxCubeTextureLevels
- 1)) <= MAX_WIDTH
);
617 assert((1 << (ctx
->Const
.Max3DTextureLevels
- 1)) <= MAX_WIDTH
);
619 /* Texture level checks */
620 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
621 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
623 /* Max texture size should be <= max viewport size (render to texture) */
624 assert((1 << (MAX_TEXTURE_LEVELS
- 1)) <= MAX_WIDTH
);
626 assert(ctx
->Const
.MaxViewportWidth
<= MAX_WIDTH
);
627 assert(ctx
->Const
.MaxViewportHeight
<= MAX_WIDTH
);
632 * Initialize the attribute groups in a GL context.
634 * \param ctx GL context.
636 * Initializes all the attributes, calling the respective <tt>init*</tt>
637 * functions for the more complex data structures.
640 init_attrib_groups(struct gl_context
*ctx
)
645 _mesa_init_constants( ctx
);
648 _mesa_init_extensions( ctx
);
650 /* Attribute Groups */
651 _mesa_init_accum( ctx
);
652 _mesa_init_attrib( ctx
);
653 _mesa_init_buffer_objects( ctx
);
654 _mesa_init_color( ctx
);
655 _mesa_init_current( ctx
);
656 _mesa_init_depth( ctx
);
657 _mesa_init_debug( ctx
);
658 _mesa_init_display_list( ctx
);
659 _mesa_init_eval( ctx
);
660 _mesa_init_feedback( ctx
);
661 _mesa_init_fog( ctx
);
662 _mesa_init_hint( ctx
);
663 _mesa_init_line( ctx
);
664 _mesa_init_lighting( ctx
);
665 _mesa_init_matrix( ctx
);
666 _mesa_init_multisample( ctx
);
667 _mesa_init_pixel( ctx
);
668 _mesa_init_pixelstore( ctx
);
669 _mesa_init_point( ctx
);
670 _mesa_init_polygon( ctx
);
671 _mesa_init_program( ctx
);
672 _mesa_init_rastpos( ctx
);
673 _mesa_init_scissor( ctx
);
674 _mesa_init_shader_state( ctx
);
675 _mesa_init_stencil( ctx
);
676 _mesa_init_transform( ctx
);
677 _mesa_init_varray( ctx
);
678 _mesa_init_viewport( ctx
);
680 if (!_mesa_init_texture( ctx
))
684 ctx
->NewState
= _NEW_ALL
;
685 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
686 ctx
->ResetStatus
= (GLenum
) GL_NO_ERROR
;
687 ctx
->varying_vp_inputs
= VERT_BIT_ALL
;
694 * Update default objects in a GL context with respect to shared state.
696 * \param ctx GL context.
698 * Removes references to old default objects, (texture objects, program
699 * objects, etc.) and changes to reference those from the current shared
703 update_default_objects(struct gl_context
*ctx
)
707 _mesa_update_default_objects_program(ctx
);
708 _mesa_update_default_objects_texture(ctx
);
709 _mesa_update_default_objects_buffer_objects(ctx
);
716 * This is the default function we plug into all dispatch table slots
717 * This helps prevents a segfault when someone calls a GL function without
718 * first checking if the extension's supported.
723 _mesa_warning(NULL
, "User called no-op dispatch function (an unsupported extension function?)");
729 * Allocate and initialize a new dispatch table.
731 struct _glapi_table
*
732 _mesa_alloc_dispatch_table(int size
)
734 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
735 * In practice, this'll be the same for stand-alone Mesa. But for DRI
736 * Mesa we do this to accomodate different versions of libGL and various
739 GLint numEntries
= MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT
);
740 struct _glapi_table
*table
;
742 /* should never happen, but just in case */
743 numEntries
= MAX2(numEntries
, size
);
745 table
= (struct _glapi_table
*) malloc(numEntries
* sizeof(_glapi_proc
));
747 _glapi_proc
*entry
= (_glapi_proc
*) table
;
749 for (i
= 0; i
< numEntries
; i
++) {
750 entry
[i
] = (_glapi_proc
) generic_nop
;
758 * Initialize a struct gl_context struct (rendering context).
760 * This includes allocating all the other structs and arrays which hang off of
761 * the context by pointers.
762 * Note that the driver needs to pass in its dd_function_table here since
763 * we need to at least call driverFunctions->NewTextureObject to create the
764 * default texture objects.
766 * Called by _mesa_create_context().
768 * Performs the imports and exports callback tables initialization, and
769 * miscellaneous one-time initializations. If no shared context is supplied one
770 * is allocated, and increase its reference count. Setups the GL API dispatch
771 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
772 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
775 * \param ctx the context to initialize
776 * \param api the GL API type to create the context for
777 * \param visual describes the visual attributes for this context
778 * \param share_list points to context to share textures, display lists,
780 * \param driverFunctions table of device driver functions for this context
782 * \param driverContext pointer to driver-specific context data
785 _mesa_initialize_context(struct gl_context
*ctx
,
786 const struct gl_config
*visual
,
787 struct gl_context
*share_list
,
788 const struct dd_function_table
*driverFunctions
,
791 struct gl_shared_state
*shared
;
793 /*ASSERT(driverContext);*/
794 assert(driverFunctions
->NewTextureObject
);
795 assert(driverFunctions
->FreeTextureImageBuffer
);
797 ctx
->Visual
= *visual
;
798 ctx
->DrawBuffer
= NULL
;
799 ctx
->ReadBuffer
= NULL
;
800 ctx
->WinSysDrawBuffer
= NULL
;
801 ctx
->WinSysReadBuffer
= NULL
;
803 /* misc one-time initializations */
806 /* Plug in driver functions and context pointer here.
807 * This is important because when we call alloc_shared_state() below
808 * we'll call ctx->Driver.NewTextureObject() to create the default
811 ctx
->Driver
= *driverFunctions
;
812 ctx
->DriverCtx
= driverContext
;
815 /* share state with another context */
816 shared
= share_list
->Shared
;
819 /* allocate new, unshared state */
820 shared
= _mesa_alloc_shared_state(ctx
);
825 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, shared
);
827 if (!init_attrib_groups( ctx
)) {
828 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
832 ctx
->Exec
= _mesa_create_exec_table();
835 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
838 ctx
->CurrentDispatch
= ctx
->Exec
;
840 /* Mesa core handles all the formats that mesa core knows about.
841 * Drivers will want to override this list with just the formats
842 * they can handle, and confirm that appropriate fallbacks exist in
843 * _mesa_choose_tex_format().
845 memset(&ctx
->TextureFormatSupported
, GL_TRUE
,
846 sizeof(ctx
->TextureFormatSupported
));
848 ctx
->Save
= _mesa_create_save_table();
850 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
855 _mesa_install_save_vtxfmt( ctx
, &ctx
->ListState
.ListVtxfmt
);
857 ctx
->FirstTimeCurrent
= GL_TRUE
;
864 * Allocate and initialize a struct gl_context structure.
865 * Note that the driver needs to pass in its dd_function_table here since
866 * we need to at least call driverFunctions->NewTextureObject to initialize
867 * the rendering context.
869 * \param api the GL API type to create the context for
870 * \param visual a struct gl_config pointer (we copy the struct contents)
871 * \param share_list another context to share display lists with or NULL
872 * \param driverFunctions points to the dd_function_table into which the
873 * driver has plugged in all its special functions.
874 * \param driverContext points to the device driver's private context state
876 * \return pointer to a new __struct gl_contextRec or NULL if error.
879 _mesa_create_context(const struct gl_config
*visual
,
880 struct gl_context
*share_list
,
881 const struct dd_function_table
*driverFunctions
,
884 struct gl_context
*ctx
;
887 /*ASSERT(driverContext);*/
889 ctx
= (struct gl_context
*) calloc(1, sizeof(struct gl_context
));
893 if (_mesa_initialize_context(ctx
, visual
, share_list
,
894 driverFunctions
, driverContext
)) {
905 * Free the data associated with the given context.
907 * But doesn't free the struct gl_context struct itself.
909 * \sa _mesa_initialize_context() and init_attrib_groups().
912 _mesa_free_context_data( struct gl_context
*ctx
)
914 if (!_mesa_get_current_context()){
915 /* No current context, but we may need one in order to delete
916 * texture objs, etc. So temporarily bind the context now.
918 _mesa_make_current(ctx
, NULL
, NULL
);
921 /* unreference WinSysDraw/Read buffers */
922 _mesa_reference_framebuffer(&ctx
->WinSysDrawBuffer
, NULL
);
923 _mesa_reference_framebuffer(&ctx
->WinSysReadBuffer
, NULL
);
924 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, NULL
);
925 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, NULL
);
927 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
, NULL
);
928 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
, NULL
);
930 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
, NULL
);
931 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
, NULL
);
933 _mesa_free_attrib_data(ctx
);
934 _mesa_free_buffer_objects(ctx
);
935 _mesa_free_lighting_data( ctx
);
936 _mesa_free_eval_data( ctx
);
937 _mesa_free_texture_data( ctx
);
938 _mesa_free_matrix_data( ctx
);
939 _mesa_free_viewport_data( ctx
);
940 _mesa_free_program_data(ctx
);
941 _mesa_free_shader_state(ctx
);
942 _mesa_free_varray_data(ctx
);
944 _mesa_delete_array_object(ctx
, ctx
->Array
.DefaultArrayObj
);
946 #if FEATURE_ARB_pixel_buffer_object
947 _mesa_reference_buffer_object(ctx
, &ctx
->Pack
.BufferObj
, NULL
);
948 _mesa_reference_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
, NULL
);
949 _mesa_reference_buffer_object(ctx
, &ctx
->DefaultPacking
.BufferObj
, NULL
);
952 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
954 /* free dispatch tables */
958 /* Shared context state (display lists, textures, etc) */
959 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
961 /* needs to be after freeing shared state */
962 _mesa_free_display_list_data(ctx
);
964 if (ctx
->Extensions
.String
)
965 free((void *) ctx
->Extensions
.String
);
967 if (ctx
->VersionString
)
968 free(ctx
->VersionString
);
970 /* unbind the context if it's currently bound */
971 if (ctx
== _mesa_get_current_context()) {
972 _mesa_make_current(NULL
, NULL
, NULL
);
978 * Destroy a struct gl_context structure.
980 * \param ctx GL context.
982 * Calls _mesa_free_context_data() and frees the gl_context object itself.
985 _mesa_destroy_context( struct gl_context
*ctx
)
988 _mesa_free_context_data(ctx
);
989 free( (void *) ctx
);
996 * Copy attribute groups from one context to another.
998 * \param src source context
999 * \param dst destination context
1000 * \param mask bitwise OR of GL_*_BIT flags
1002 * According to the bits specified in \p mask, copies the corresponding
1003 * attributes from \p src into \p dst. For many of the attributes a simple \c
1004 * memcpy is not enough due to the existence of internal pointers in their data
1008 _mesa_copy_context( const struct gl_context
*src
, struct gl_context
*dst
,
1011 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1013 dst
->Accum
= src
->Accum
;
1015 if (mask
& GL_COLOR_BUFFER_BIT
) {
1017 dst
->Color
= src
->Color
;
1019 if (mask
& GL_CURRENT_BIT
) {
1021 dst
->Current
= src
->Current
;
1023 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1025 dst
->Depth
= src
->Depth
;
1027 if (mask
& GL_ENABLE_BIT
) {
1030 if (mask
& GL_EVAL_BIT
) {
1032 dst
->Eval
= src
->Eval
;
1034 if (mask
& GL_FOG_BIT
) {
1036 dst
->Fog
= src
->Fog
;
1038 if (mask
& GL_HINT_BIT
) {
1040 dst
->Hint
= src
->Hint
;
1042 if (mask
& GL_LIGHTING_BIT
) {
1044 /* begin with memcpy */
1045 dst
->Light
= src
->Light
;
1046 /* fixup linked lists to prevent pointer insanity */
1047 make_empty_list( &(dst
->Light
.EnabledList
) );
1048 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
1049 if (dst
->Light
.Light
[i
].Enabled
) {
1050 insert_at_tail(&(dst
->Light
.EnabledList
), &(dst
->Light
.Light
[i
]));
1054 if (mask
& GL_LINE_BIT
) {
1056 dst
->Line
= src
->Line
;
1058 if (mask
& GL_LIST_BIT
) {
1060 dst
->List
= src
->List
;
1062 if (mask
& GL_PIXEL_MODE_BIT
) {
1064 dst
->Pixel
= src
->Pixel
;
1066 if (mask
& GL_POINT_BIT
) {
1068 dst
->Point
= src
->Point
;
1070 if (mask
& GL_POLYGON_BIT
) {
1072 dst
->Polygon
= src
->Polygon
;
1074 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1075 /* Use loop instead of memcpy due to problem with Portland Group's
1076 * C compiler. Reported by John Stone.
1079 for (i
= 0; i
< 32; i
++) {
1080 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1083 if (mask
& GL_SCISSOR_BIT
) {
1085 dst
->Scissor
= src
->Scissor
;
1087 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1089 dst
->Stencil
= src
->Stencil
;
1091 if (mask
& GL_TEXTURE_BIT
) {
1092 /* Cannot memcpy because of pointers */
1093 _mesa_copy_texture_state(src
, dst
);
1095 if (mask
& GL_TRANSFORM_BIT
) {
1097 dst
->Transform
= src
->Transform
;
1099 if (mask
& GL_VIEWPORT_BIT
) {
1100 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1101 dst
->Viewport
.X
= src
->Viewport
.X
;
1102 dst
->Viewport
.Y
= src
->Viewport
.Y
;
1103 dst
->Viewport
.Width
= src
->Viewport
.Width
;
1104 dst
->Viewport
.Height
= src
->Viewport
.Height
;
1105 dst
->Viewport
.Near
= src
->Viewport
.Near
;
1106 dst
->Viewport
.Far
= src
->Viewport
.Far
;
1107 _math_matrix_copy(&dst
->Viewport
._WindowMap
, &src
->Viewport
._WindowMap
);
1110 /* XXX FIXME: Call callbacks?
1112 dst
->NewState
= _NEW_ALL
;
1118 * Check if the given context can render into the given framebuffer
1119 * by checking visual attributes.
1121 * Most of these tests could go away because Mesa is now pretty flexible
1122 * in terms of mixing rendering contexts with framebuffers. As long
1123 * as RGB vs. CI mode agree, we're probably good.
1125 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1128 check_compatible(const struct gl_context
*ctx
,
1129 const struct gl_framebuffer
*buffer
)
1131 const struct gl_config
*ctxvis
= &ctx
->Visual
;
1132 const struct gl_config
*bufvis
= &buffer
->Visual
;
1135 /* disabling this fixes the fgl_glxgears pbuffer demo */
1136 if (ctxvis
->doubleBufferMode
&& !bufvis
->doubleBufferMode
)
1139 if (ctxvis
->stereoMode
&& !bufvis
->stereoMode
)
1141 if (ctxvis
->haveAccumBuffer
&& !bufvis
->haveAccumBuffer
)
1143 if (ctxvis
->haveDepthBuffer
&& !bufvis
->haveDepthBuffer
)
1145 if (ctxvis
->haveStencilBuffer
&& !bufvis
->haveStencilBuffer
)
1147 if (ctxvis
->redMask
&& ctxvis
->redMask
!= bufvis
->redMask
)
1149 if (ctxvis
->greenMask
&& ctxvis
->greenMask
!= bufvis
->greenMask
)
1151 if (ctxvis
->blueMask
&& ctxvis
->blueMask
!= bufvis
->blueMask
)
1154 /* disabled (see bug 11161) */
1155 if (ctxvis
->depthBits
&& ctxvis
->depthBits
!= bufvis
->depthBits
)
1158 if (ctxvis
->stencilBits
&& ctxvis
->stencilBits
!= bufvis
->stencilBits
)
1166 * Do one-time initialization for the given framebuffer. Specifically,
1167 * ask the driver for the window's current size and update the framebuffer
1169 * Really, the device driver should totally take care of this.
1172 initialize_framebuffer_size(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1174 GLuint width
, height
;
1175 if (ctx
->Driver
.GetBufferSize
) {
1176 ctx
->Driver
.GetBufferSize(fb
, &width
, &height
);
1177 if (ctx
->Driver
.ResizeBuffers
)
1178 ctx
->Driver
.ResizeBuffers(ctx
, fb
, width
, height
);
1179 fb
->Initialized
= GL_TRUE
;
1185 * Check if the viewport/scissor size has not yet been initialized.
1186 * Initialize the size if the given width and height are non-zero.
1189 _mesa_check_init_viewport(struct gl_context
*ctx
, GLuint width
, GLuint height
)
1191 if (!ctx
->ViewportInitialized
&& width
> 0 && height
> 0) {
1192 /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
1193 * potential infinite recursion.
1195 ctx
->ViewportInitialized
= GL_TRUE
;
1196 _mesa_set_viewport(ctx
, 0, 0, width
, height
);
1197 _mesa_set_scissor(ctx
, 0, 0, width
, height
);
1203 * Bind the given context to the given drawBuffer and readBuffer and
1204 * make it the current context for the calling thread.
1205 * We'll render into the drawBuffer and read pixels from the
1206 * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
1208 * We check that the context's and framebuffer's visuals are compatible
1209 * and return immediately if they're not.
1211 * \param newCtx the new GL context. If NULL then there will be no current GL
1213 * \param drawBuffer the drawing framebuffer
1214 * \param readBuffer the reading framebuffer
1217 _mesa_make_current( struct gl_context
*newCtx
,
1218 struct gl_framebuffer
*drawBuffer
,
1219 struct gl_framebuffer
*readBuffer
)
1221 GET_CURRENT_CONTEXT(curCtx
);
1223 if (MESA_VERBOSE
& VERBOSE_API
)
1224 _mesa_debug(newCtx
, "_mesa_make_current()\n");
1226 /* Check that the context's and framebuffer's visuals are compatible.
1228 if (newCtx
&& drawBuffer
&& newCtx
->WinSysDrawBuffer
!= drawBuffer
) {
1229 if (!check_compatible(newCtx
, drawBuffer
)) {
1230 _mesa_warning(newCtx
,
1231 "MakeCurrent: incompatible visuals for context and drawbuffer");
1235 if (newCtx
&& readBuffer
&& newCtx
->WinSysReadBuffer
!= readBuffer
) {
1236 if (!check_compatible(newCtx
, readBuffer
)) {
1237 _mesa_warning(newCtx
,
1238 "MakeCurrent: incompatible visuals for context and readbuffer");
1244 (curCtx
->WinSysDrawBuffer
|| curCtx
->WinSysReadBuffer
) &&
1245 /* make sure this context is valid for flushing */
1247 _mesa_flush(curCtx
);
1249 /* We used to call _glapi_check_multithread() here. Now do it in drivers */
1250 _glapi_set_context((void *) newCtx
);
1251 ASSERT(_mesa_get_current_context() == newCtx
);
1254 _glapi_set_dispatch(NULL
); /* none current */
1257 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1259 if (drawBuffer
&& readBuffer
) {
1260 ASSERT(drawBuffer
->Name
== 0);
1261 ASSERT(readBuffer
->Name
== 0);
1262 _mesa_reference_framebuffer(&newCtx
->WinSysDrawBuffer
, drawBuffer
);
1263 _mesa_reference_framebuffer(&newCtx
->WinSysReadBuffer
, readBuffer
);
1266 * Only set the context's Draw/ReadBuffer fields if they're NULL
1267 * or not bound to a user-created FBO.
1269 _mesa_reference_framebuffer(&newCtx
->DrawBuffer
, drawBuffer
);
1270 /* Update the FBO's list of drawbuffers/renderbuffers.
1271 * For winsys FBOs this comes from the GL state (which may have
1272 * changed since the last time this FBO was bound).
1274 _mesa_update_draw_buffer(newCtx
);
1276 _mesa_reference_framebuffer(&newCtx
->ReadBuffer
, readBuffer
);
1278 /* XXX only set this flag if we're really changing the draw/read
1279 * framebuffer bindings.
1281 newCtx
->NewState
|= _NEW_BUFFERS
;
1284 /* We want to get rid of these lines: */
1287 if (!drawBuffer
->Initialized
) {
1288 initialize_framebuffer_size(newCtx
, drawBuffer
);
1290 if (readBuffer
!= drawBuffer
&& !readBuffer
->Initialized
) {
1291 initialize_framebuffer_size(newCtx
, readBuffer
);
1294 _mesa_resizebuffers(newCtx
);
1298 /* We want the drawBuffer and readBuffer to be initialized by
1300 * This generally means the Width and Height match the actual
1301 * window size and the renderbuffers (both hardware and software
1302 * based) are allocated to match. The later can generally be
1303 * done with a call to _mesa_resize_framebuffer().
1305 * It's theoretically possible for a buffer to have zero width
1306 * or height, but for now, assert check that the driver did what's
1309 ASSERT(drawBuffer
->Width
> 0);
1310 ASSERT(drawBuffer
->Height
> 0);
1314 _mesa_check_init_viewport(newCtx
,
1315 drawBuffer
->Width
, drawBuffer
->Height
);
1319 if (newCtx
->FirstTimeCurrent
) {
1320 _mesa_compute_version(newCtx
);
1322 newCtx
->Extensions
.String
= _mesa_make_extension_string(newCtx
);
1324 check_context_limits(newCtx
);
1326 /* We can use this to help debug user's problems. Tell them to set
1327 * the MESA_INFO env variable before running their app. Then the
1328 * first time each context is made current we'll print some useful
1331 if (_mesa_getenv("MESA_INFO")) {
1335 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1344 * Make context 'ctx' share the display lists, textures and programs
1345 * that are associated with 'ctxToShare'.
1346 * Any display lists, textures or programs associated with 'ctx' will
1347 * be deleted if nobody else is sharing them.
1350 _mesa_share_state(struct gl_context
*ctx
, struct gl_context
*ctxToShare
)
1352 if (ctx
&& ctxToShare
&& ctx
->Shared
&& ctxToShare
->Shared
) {
1353 struct gl_shared_state
*oldShared
= NULL
;
1355 /* save ref to old state to prevent it from being deleted immediately */
1356 _mesa_reference_shared_state(ctx
, &oldShared
, ctx
->Shared
);
1358 /* update ctx's Shared pointer */
1359 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, ctxToShare
->Shared
);
1361 update_default_objects(ctx
);
1363 /* release the old shared state */
1364 _mesa_reference_shared_state(ctx
, &oldShared
, NULL
);
1376 * \return pointer to the current GL context for this thread.
1378 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1379 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
1383 _mesa_get_current_context( void )
1385 return (struct gl_context
*) _glapi_get_context();
1390 * Get context's current API dispatch table.
1392 * It'll either be the immediate-mode execute dispatcher or the display list
1393 * compile dispatcher.
1395 * \param ctx GL context.
1397 * \return pointer to dispatch_table.
1399 * Simply returns __struct gl_contextRec::CurrentDispatch.
1401 struct _glapi_table
*
1402 _mesa_get_dispatch(struct gl_context
*ctx
)
1404 return ctx
->CurrentDispatch
;
1410 /**********************************************************************/
1411 /** \name Miscellaneous functions */
1412 /**********************************************************************/
1418 * \param ctx GL context.
1419 * \param error error code.
1421 * Records the given error code and call the driver's dd_function_table::Error
1422 * function if defined.
1425 * This is called via _mesa_error().
1428 _mesa_record_error(struct gl_context
*ctx
, GLenum error
)
1433 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
1434 ctx
->ErrorValue
= error
;
1437 /* Call device driver's error handler, if any. This is used on the Mac. */
1438 if (ctx
->Driver
.Error
) {
1439 ctx
->Driver
.Error(ctx
);
1445 * Flush commands and wait for completion.
1448 _mesa_finish(struct gl_context
*ctx
)
1450 FLUSH_CURRENT( ctx
, 0 );
1451 if (ctx
->Driver
.Finish
) {
1452 ctx
->Driver
.Finish(ctx
);
1461 _mesa_flush(struct gl_context
*ctx
)
1463 FLUSH_CURRENT( ctx
, 0 );
1464 if (ctx
->Driver
.Flush
) {
1465 ctx
->Driver
.Flush(ctx
);
1472 * Execute glFinish().
1474 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1475 * dd_function_table::Finish driver callback, if not NULL.
1480 GET_CURRENT_CONTEXT(ctx
);
1481 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1487 * Execute glFlush().
1489 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1490 * dd_function_table::Flush driver callback, if not NULL.
1495 GET_CURRENT_CONTEXT(ctx
);
1496 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1502 * Set mvp_with_dp4 flag. If a driver has a preference for DP4 over
1503 * MUL/MAD, or vice versa, call this function to register that.
1504 * Otherwise we default to MUL/MAD.
1507 _mesa_set_mvp_with_dp4( struct gl_context
*ctx
,
1510 ctx
->mvp_with_dp4
= flag
;
1516 * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
1517 * is called to see if it's valid to render. This involves checking that
1518 * the current shader is valid and the framebuffer is complete.
1519 * If an error is detected it'll be recorded here.
1520 * \return GL_TRUE if OK to render, GL_FALSE if not
1523 _mesa_valid_to_render(struct gl_context
*ctx
, const char *where
)
1525 bool vert_from_glsl_shader
= false;
1526 bool frag_from_glsl_shader
= false;
1528 /* This depends on having up to date derived state (shaders) */
1530 _mesa_update_state(ctx
);
1532 if (ctx
->Shader
.CurrentVertexProgram
) {
1533 vert_from_glsl_shader
= true;
1535 if (!ctx
->Shader
.CurrentVertexProgram
->LinkStatus
) {
1536 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1537 "%s(shader not linked)", where
);
1540 #if 0 /* not normally enabled */
1543 if (!_mesa_validate_shader_program(ctx
,
1544 ctx
->Shader
.CurrentVertexProgram
,
1546 _mesa_warning(ctx
, "Shader program %u is invalid: %s",
1547 ctx
->Shader
.CurrentVertexProgram
->Name
, errMsg
);
1553 if (ctx
->Shader
.CurrentFragmentProgram
) {
1554 frag_from_glsl_shader
= true;
1556 if (!ctx
->Shader
.CurrentFragmentProgram
->LinkStatus
) {
1557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1558 "%s(shader not linked)", where
);
1561 #if 0 /* not normally enabled */
1564 if (!_mesa_validate_shader_program(ctx
,
1565 ctx
->Shader
.CurrentFragmentProgram
,
1567 _mesa_warning(ctx
, "Shader program %u is invalid: %s",
1568 ctx
->Shader
.CurrentFragmentProgram
->Name
, errMsg
);
1574 /* Any shader stages that are not supplied by the GLSL shader and have
1575 * assembly shaders enabled must now be validated.
1577 if (!vert_from_glsl_shader
1578 && ctx
->VertexProgram
.Enabled
&& !ctx
->VertexProgram
._Enabled
) {
1579 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1580 "%s(vertex program not valid)", where
);
1584 if (!frag_from_glsl_shader
) {
1585 if (ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
) {
1586 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1587 "%s(fragment program not valid)", where
);
1591 /* If drawing to integer-valued color buffers, there must be an
1592 * active fragment shader (GL_EXT_texture_integer).
1594 if (ctx
->DrawBuffer
&& ctx
->DrawBuffer
->_IntegerColor
) {
1595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1596 "%s(integer format but no fragment shader)", where
);
1602 if (ctx
->Shader
.Flags
& GLSL_LOG
) {
1603 struct gl_shader_program
*shProg
[MESA_SHADER_TYPES
];
1606 shProg
[MESA_SHADER_VERTEX
] = ctx
->Shader
.CurrentVertexProgram
;
1607 shProg
[MESA_SHADER_FRAGMENT
] = ctx
->Shader
.CurrentFragmentProgram
;
1609 for (i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
1610 if (shProg
[i
] == NULL
|| shProg
[i
]->_Used
1611 || shProg
[i
]->_LinkedShaders
[i
] == NULL
)
1614 /* This is the first time this shader is being used.
1615 * Append shader's constants/uniforms to log file.
1617 * Only log data for the program target that matches the shader
1618 * target. It's possible to have a program bound to the vertex
1619 * shader target that also supplied a fragment shader. If that
1620 * program isn't also bound to the fragment shader target we don't
1621 * want to log its fragment data.
1623 _mesa_append_uniforms_to_file(shProg
[i
]->_LinkedShaders
[i
]);
1626 for (i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
1627 if (shProg
[i
] != NULL
)
1628 shProg
[i
]->_Used
= GL_TRUE
;