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"
94 #include "extensions.h"
98 #include "framebuffer.h"
105 #include "multisample.h"
107 #include "pixelstore.h"
113 #include "shaderobj.h"
114 #include "simple_list.h"
117 #include "texstate.h"
121 #include "viewport.h"
123 #include "program/program.h"
124 #include "program/prog_print.h"
126 #include "math/m_matrix.h"
128 #include "main/dispatch.h" /* for _gloffset_COUNT */
131 #include "sparc/sparc.h"
134 #include "glsl_parser_extras.h"
139 int MESA_VERBOSE
= 0;
142 #ifndef MESA_DEBUG_FLAGS
143 int MESA_DEBUG_FLAGS
= 0;
147 /* ubyte -> float conversion */
148 GLfloat _mesa_ubyte_to_float_color_tab
[256];
153 * Swap buffers notification callback.
155 * \param ctx GL context.
157 * Called by window system just before swapping buffers.
158 * We have to finish any pending rendering.
161 _mesa_notifySwapBuffers(struct gl_context
*ctx
)
163 if (MESA_VERBOSE
& VERBOSE_SWAPBUFFERS
)
164 _mesa_debug(ctx
, "SwapBuffers\n");
165 FLUSH_CURRENT( ctx
, 0 );
166 if (ctx
->Driver
.Flush
) {
167 ctx
->Driver
.Flush(ctx
);
172 /**********************************************************************/
173 /** \name GL Visual allocation/destruction */
174 /**********************************************************************/
178 * Allocates a struct gl_config structure and initializes it via
179 * _mesa_initialize_visual().
181 * \param dbFlag double buffering
182 * \param stereoFlag stereo buffer
183 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
184 * is acceptable but the actual depth type will be GLushort or GLuint as
186 * \param stencilBits requested minimum bits per stencil buffer value
187 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number
188 * of bits per color component in accum buffer.
189 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
190 * \param redBits number of bits per color component in frame buffer for RGB(A)
191 * mode. We always use 8 in core Mesa though.
192 * \param greenBits same as above.
193 * \param blueBits same as above.
194 * \param alphaBits same as above.
196 * \return pointer to new struct gl_config or NULL if requested parameters
199 * \note Need to add params for level and numAuxBuffers (at least)
202 _mesa_create_visual( GLboolean dbFlag
,
203 GLboolean stereoFlag
,
211 GLint accumGreenBits
,
213 GLint accumAlphaBits
)
215 struct gl_config
*vis
= CALLOC_STRUCT(gl_config
);
217 if (!_mesa_initialize_visual(vis
, dbFlag
, stereoFlag
,
218 redBits
, greenBits
, blueBits
, alphaBits
,
219 depthBits
, stencilBits
,
220 accumRedBits
, accumGreenBits
,
221 accumBlueBits
, accumAlphaBits
)) {
231 * Makes some sanity checks and fills in the fields of the struct
232 * gl_config object with the given parameters. If the caller needs to
233 * set additional fields, he should just probably init the whole
234 * gl_config object himself.
236 * \return GL_TRUE on success, or GL_FALSE on failure.
238 * \sa _mesa_create_visual() above for the parameter description.
241 _mesa_initialize_visual( struct gl_config
*vis
,
243 GLboolean stereoFlag
,
251 GLint accumGreenBits
,
253 GLint accumAlphaBits
)
257 if (depthBits
< 0 || depthBits
> 32) {
260 if (stencilBits
< 0 || stencilBits
> STENCIL_BITS
) {
263 assert(accumRedBits
>= 0);
264 assert(accumGreenBits
>= 0);
265 assert(accumBlueBits
>= 0);
266 assert(accumAlphaBits
>= 0);
268 vis
->rgbMode
= GL_TRUE
;
269 vis
->doubleBufferMode
= dbFlag
;
270 vis
->stereoMode
= stereoFlag
;
272 vis
->redBits
= redBits
;
273 vis
->greenBits
= greenBits
;
274 vis
->blueBits
= blueBits
;
275 vis
->alphaBits
= alphaBits
;
276 vis
->rgbBits
= redBits
+ greenBits
+ blueBits
;
279 vis
->depthBits
= depthBits
;
280 vis
->stencilBits
= stencilBits
;
282 vis
->accumRedBits
= accumRedBits
;
283 vis
->accumGreenBits
= accumGreenBits
;
284 vis
->accumBlueBits
= accumBlueBits
;
285 vis
->accumAlphaBits
= accumAlphaBits
;
287 vis
->haveAccumBuffer
= accumRedBits
> 0;
288 vis
->haveDepthBuffer
= depthBits
> 0;
289 vis
->haveStencilBuffer
= stencilBits
> 0;
291 vis
->numAuxBuffers
= 0;
299 * Destroy a visual and free its memory.
303 * Frees the visual structure.
306 _mesa_destroy_visual( struct gl_config
*vis
)
314 /**********************************************************************/
315 /** \name Context allocation, initialization, destroying
317 * The purpose of the most initialization functions here is to provide the
318 * default state values according to the OpenGL specification.
320 /**********************************************************************/
325 * This is lame. gdb only seems to recognize enum types that are
326 * actually used somewhere. We want to be able to print/use enum
327 * values such as TEXTURE_2D_INDEX in gdb. But we don't actually use
328 * the gl_texture_index type anywhere. Thus, this lame function.
331 dummy_enum_func(void)
333 gl_buffer_index bi
= BUFFER_FRONT_LEFT
;
334 gl_face_index fi
= FACE_POS_X
;
335 gl_frag_attrib fa
= FRAG_ATTRIB_WPOS
;
336 gl_frag_result fr
= FRAG_RESULT_DEPTH
;
337 gl_vert_attrib va
= VERT_ATTRIB_POS
;
338 gl_vert_result vr
= VERT_RESULT_HPOS
;
350 * One-time initialization mutex lock.
352 * \sa Used by one_time_init().
354 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
359 * Calls all the various one-time-init functions in Mesa.
361 * While holding a global mutex lock, calls several initialization functions,
362 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
368 one_time_init( struct gl_context
*ctx
)
370 static GLboolean api_init
= GL_FALSE
;
372 _glthread_LOCK_MUTEX(OneTimeLock
);
374 /* truly one-time init */
378 /* do some implementation tests */
379 assert( sizeof(GLbyte
) == 1 );
380 assert( sizeof(GLubyte
) == 1 );
381 assert( sizeof(GLshort
) == 2 );
382 assert( sizeof(GLushort
) == 2 );
383 assert( sizeof(GLint
) == 4 );
384 assert( sizeof(GLuint
) == 4 );
386 _mesa_get_cpu_features();
388 _mesa_init_sqrt_table();
390 /* context dependence is never a one-time thing... */
391 _mesa_init_get_hash(ctx
);
393 for (i
= 0; i
< 256; i
++) {
394 _mesa_ubyte_to_float_color_tab
[i
] = (float) i
/ 255.0F
;
397 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
398 if (MESA_VERBOSE
!= 0) {
399 _mesa_debug(ctx
, "Mesa %s DEBUG build %s %s\n",
400 MESA_VERSION_STRING
, __DATE__
, __TIME__
);
405 _mesa_test_formats();
411 _glthread_UNLOCK_MUTEX(OneTimeLock
);
413 /* Hopefully atexit() is widely available. If not, we may need some
416 atexit(_mesa_destroy_shader_compiler
);
423 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
426 _mesa_init_current(struct gl_context
*ctx
)
430 /* Init all to (0,0,0,1) */
431 for (i
= 0; i
< Elements(ctx
->Current
.Attrib
); i
++) {
432 ASSIGN_4V( ctx
->Current
.Attrib
[i
], 0.0, 0.0, 0.0, 1.0 );
435 /* redo special cases: */
436 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_WEIGHT
], 1.0, 0.0, 0.0, 0.0 );
437 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
], 0.0, 0.0, 1.0, 1.0 );
438 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], 1.0, 1.0, 1.0, 1.0 );
439 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
], 0.0, 0.0, 0.0, 1.0 );
440 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR_INDEX
], 1.0, 0.0, 0.0, 1.0 );
441 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
], 1.0, 0.0, 0.0, 1.0 );
446 * Init vertex/fragment/geometry program limits.
447 * Important: drivers should override these with actual limits.
450 init_program_limits(GLenum type
, struct gl_program_constants
*prog
)
452 prog
->MaxInstructions
= MAX_PROGRAM_INSTRUCTIONS
;
453 prog
->MaxAluInstructions
= MAX_PROGRAM_INSTRUCTIONS
;
454 prog
->MaxTexInstructions
= MAX_PROGRAM_INSTRUCTIONS
;
455 prog
->MaxTexIndirections
= MAX_PROGRAM_INSTRUCTIONS
;
456 prog
->MaxTemps
= MAX_PROGRAM_TEMPS
;
457 prog
->MaxEnvParams
= MAX_PROGRAM_ENV_PARAMS
;
458 prog
->MaxLocalParams
= MAX_PROGRAM_LOCAL_PARAMS
;
459 prog
->MaxAddressOffset
= MAX_PROGRAM_LOCAL_PARAMS
;
462 case GL_VERTEX_PROGRAM_ARB
:
463 prog
->MaxParameters
= MAX_VERTEX_PROGRAM_PARAMS
;
464 prog
->MaxAttribs
= MAX_NV_VERTEX_PROGRAM_INPUTS
;
465 prog
->MaxAddressRegs
= MAX_VERTEX_PROGRAM_ADDRESS_REGS
;
466 prog
->MaxUniformComponents
= 4 * MAX_UNIFORMS
;
468 case GL_FRAGMENT_PROGRAM_ARB
:
469 prog
->MaxParameters
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
470 prog
->MaxAttribs
= MAX_NV_FRAGMENT_PROGRAM_INPUTS
;
471 prog
->MaxAddressRegs
= MAX_FRAGMENT_PROGRAM_ADDRESS_REGS
;
472 prog
->MaxUniformComponents
= 4 * MAX_UNIFORMS
;
475 assert(0 && "Bad program type in init_program_limits()");
478 /* Set the native limits to zero. This implies that there is no native
479 * support for shaders. Let the drivers fill in the actual values.
481 prog
->MaxNativeInstructions
= 0;
482 prog
->MaxNativeAluInstructions
= 0;
483 prog
->MaxNativeTexInstructions
= 0;
484 prog
->MaxNativeTexIndirections
= 0;
485 prog
->MaxNativeAttribs
= 0;
486 prog
->MaxNativeTemps
= 0;
487 prog
->MaxNativeAddressRegs
= 0;
488 prog
->MaxNativeParameters
= 0;
493 * Initialize fields of gl_constants (aka ctx->Const.*).
494 * Use defaults from config.h. The device drivers will often override
495 * some of these values (such as number of texture units).
498 _mesa_init_constants(struct gl_context
*ctx
)
502 /* Constants, may be overriden (usually only reduced) by device drivers */
503 ctx
->Const
.MaxTextureMbytes
= MAX_TEXTURE_MBYTES
;
504 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
505 ctx
->Const
.Max3DTextureLevels
= MAX_3D_TEXTURE_LEVELS
;
506 ctx
->Const
.MaxCubeTextureLevels
= MAX_CUBE_TEXTURE_LEVELS
;
507 ctx
->Const
.MaxTextureCoordUnits
= MAX_TEXTURE_COORD_UNITS
;
508 ctx
->Const
.MaxTextureImageUnits
= MAX_TEXTURE_IMAGE_UNITS
;
509 ctx
->Const
.MaxTextureUnits
= MIN2(ctx
->Const
.MaxTextureCoordUnits
,
510 ctx
->Const
.MaxTextureImageUnits
);
511 ctx
->Const
.MaxTextureMaxAnisotropy
= MAX_TEXTURE_MAX_ANISOTROPY
;
512 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
513 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
514 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
515 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
516 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
517 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
518 ctx
->Const
.PointSizeGranularity
= (GLfloat
) POINT_SIZE_GRANULARITY
;
519 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
520 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
521 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
522 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
523 ctx
->Const
.LineWidthGranularity
= (GLfloat
) LINE_WIDTH_GRANULARITY
;
524 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
525 ctx
->Const
.MaxClipPlanes
= 6;
526 ctx
->Const
.MaxLights
= MAX_LIGHTS
;
527 ctx
->Const
.MaxShininess
= 128.0;
528 ctx
->Const
.MaxSpotExponent
= 128.0;
529 ctx
->Const
.MaxViewportWidth
= MAX_WIDTH
;
530 ctx
->Const
.MaxViewportHeight
= MAX_HEIGHT
;
531 #if FEATURE_ARB_vertex_program
532 init_program_limits(GL_VERTEX_PROGRAM_ARB
, &ctx
->Const
.VertexProgram
);
534 #if FEATURE_ARB_fragment_program
535 init_program_limits(GL_FRAGMENT_PROGRAM_ARB
, &ctx
->Const
.FragmentProgram
);
537 ctx
->Const
.MaxProgramMatrices
= MAX_PROGRAM_MATRICES
;
538 ctx
->Const
.MaxProgramMatrixStackDepth
= MAX_PROGRAM_MATRIX_STACK_DEPTH
;
540 /* CheckArrayBounds is overriden by drivers/x11 for X server */
541 ctx
->Const
.CheckArrayBounds
= GL_FALSE
;
543 #if FEATURE_ARB_vertex_shader
544 ctx
->Const
.MaxVertexTextureImageUnits
= MAX_VERTEX_TEXTURE_IMAGE_UNITS
;
545 ctx
->Const
.MaxCombinedTextureImageUnits
= MAX_COMBINED_TEXTURE_IMAGE_UNITS
;
546 ctx
->Const
.MaxVarying
= MAX_VARYING
;
549 ctx
->Const
.GLSLVersion
= 120;
550 _mesa_override_glsl_version(ctx
);
552 /* GL_ATI_envmap_bumpmap */
553 ctx
->Const
.SupportedBumpUnits
= SUPPORTED_ATI_BUMP_UNITS
;
555 /* GL 3.2: hard-coded for now: */
556 ctx
->Const
.ProfileMask
= GL_CONTEXT_COMPATIBILITY_PROFILE_BIT
;
558 /** GL_EXT_gpu_shader4 */
559 ctx
->Const
.MinProgramTexelOffset
= -8;
560 ctx
->Const
.MaxProgramTexelOffset
= 7;
562 /* GL_ARB_robustness */
563 ctx
->Const
.ResetStrategy
= GL_NO_RESET_NOTIFICATION_ARB
;
568 * Do some sanity checks on the limits/constants for the given context.
569 * Only called the first time a context is bound.
572 check_context_limits(struct gl_context
*ctx
)
574 /* check that we don't exceed the size of various bitfields */
575 assert(VERT_RESULT_MAX
<=
576 (8 * sizeof(ctx
->VertexProgram
._Current
->Base
.OutputsWritten
)));
577 assert(FRAG_ATTRIB_MAX
<=
578 (8 * sizeof(ctx
->FragmentProgram
._Current
->Base
.InputsRead
)));
580 assert(MAX_COMBINED_TEXTURE_IMAGE_UNITS
<= 8 * sizeof(GLbitfield
));
582 /* shader-related checks */
583 assert(ctx
->Const
.FragmentProgram
.MaxLocalParams
<= MAX_PROGRAM_LOCAL_PARAMS
);
584 assert(ctx
->Const
.VertexProgram
.MaxLocalParams
<= MAX_PROGRAM_LOCAL_PARAMS
);
586 assert(MAX_NV_FRAGMENT_PROGRAM_TEMPS
<= MAX_PROGRAM_TEMPS
);
587 assert(MAX_NV_VERTEX_PROGRAM_TEMPS
<= MAX_PROGRAM_TEMPS
);
588 assert(MAX_NV_VERTEX_PROGRAM_INPUTS
<= VERT_ATTRIB_MAX
);
589 assert(MAX_NV_VERTEX_PROGRAM_OUTPUTS
<= VERT_RESULT_MAX
);
591 /* Texture unit checks */
592 assert(ctx
->Const
.MaxTextureImageUnits
> 0);
593 assert(ctx
->Const
.MaxTextureImageUnits
<= MAX_TEXTURE_IMAGE_UNITS
);
594 assert(ctx
->Const
.MaxTextureCoordUnits
> 0);
595 assert(ctx
->Const
.MaxTextureCoordUnits
<= MAX_TEXTURE_COORD_UNITS
);
596 assert(ctx
->Const
.MaxTextureUnits
> 0);
597 assert(ctx
->Const
.MaxTextureUnits
<= MAX_TEXTURE_IMAGE_UNITS
);
598 assert(ctx
->Const
.MaxTextureUnits
<= MAX_TEXTURE_COORD_UNITS
);
599 assert(ctx
->Const
.MaxTextureUnits
== MIN2(ctx
->Const
.MaxTextureImageUnits
,
600 ctx
->Const
.MaxTextureCoordUnits
));
601 assert(ctx
->Const
.MaxCombinedTextureImageUnits
> 0);
602 assert(ctx
->Const
.MaxCombinedTextureImageUnits
<= MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
603 assert(ctx
->Const
.MaxTextureCoordUnits
<= MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
604 /* number of coord units cannot be greater than number of image units */
605 assert(ctx
->Const
.MaxTextureCoordUnits
<= ctx
->Const
.MaxTextureImageUnits
);
608 /* Texture size checks */
609 assert(ctx
->Const
.MaxTextureLevels
<= MAX_TEXTURE_LEVELS
);
610 assert(ctx
->Const
.Max3DTextureLevels
<= MAX_3D_TEXTURE_LEVELS
);
611 assert(ctx
->Const
.MaxCubeTextureLevels
<= MAX_CUBE_TEXTURE_LEVELS
);
613 /* make sure largest texture image is <= MAX_WIDTH in size */
614 assert((1 << (ctx
->Const
.MaxTextureLevels
- 1)) <= MAX_WIDTH
);
615 assert((1 << (ctx
->Const
.MaxCubeTextureLevels
- 1)) <= MAX_WIDTH
);
616 assert((1 << (ctx
->Const
.Max3DTextureLevels
- 1)) <= MAX_WIDTH
);
618 /* Texture level checks */
619 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
620 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
622 /* Max texture size should be <= max viewport size (render to texture) */
623 assert((1 << (MAX_TEXTURE_LEVELS
- 1)) <= MAX_WIDTH
);
625 assert(ctx
->Const
.MaxViewportWidth
<= MAX_WIDTH
);
626 assert(ctx
->Const
.MaxViewportHeight
<= MAX_WIDTH
);
631 * Initialize the attribute groups in a GL context.
633 * \param ctx GL context.
635 * Initializes all the attributes, calling the respective <tt>init*</tt>
636 * functions for the more complex data structures.
639 init_attrib_groups(struct gl_context
*ctx
)
644 _mesa_init_constants( ctx
);
647 _mesa_init_extensions( ctx
);
649 /* Attribute Groups */
650 _mesa_init_accum( ctx
);
651 _mesa_init_attrib( ctx
);
652 _mesa_init_buffer_objects( ctx
);
653 _mesa_init_color( ctx
);
654 _mesa_init_current( ctx
);
655 _mesa_init_depth( ctx
);
656 _mesa_init_display_list( ctx
);
657 _mesa_init_eval( ctx
);
658 _mesa_init_feedback( ctx
);
659 _mesa_init_fog( ctx
);
660 _mesa_init_hint( ctx
);
661 _mesa_init_line( ctx
);
662 _mesa_init_lighting( ctx
);
663 _mesa_init_matrix( ctx
);
664 _mesa_init_multisample( ctx
);
665 _mesa_init_pixel( ctx
);
666 _mesa_init_pixelstore( ctx
);
667 _mesa_init_point( ctx
);
668 _mesa_init_polygon( ctx
);
669 _mesa_init_program( ctx
);
670 _mesa_init_rastpos( ctx
);
671 _mesa_init_scissor( ctx
);
672 _mesa_init_shader_state( ctx
);
673 _mesa_init_stencil( ctx
);
674 _mesa_init_transform( ctx
);
675 _mesa_init_varray( ctx
);
676 _mesa_init_viewport( ctx
);
678 if (!_mesa_init_texture( ctx
))
682 ctx
->NewState
= _NEW_ALL
;
683 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
684 ctx
->ResetStatus
= (GLenum
) GL_NO_ERROR
;
685 ctx
->varying_vp_inputs
= VERT_BIT_ALL
;
692 * Update default objects in a GL context with respect to shared state.
694 * \param ctx GL context.
696 * Removes references to old default objects, (texture objects, program
697 * objects, etc.) and changes to reference those from the current shared
701 update_default_objects(struct gl_context
*ctx
)
705 _mesa_update_default_objects_program(ctx
);
706 _mesa_update_default_objects_texture(ctx
);
707 _mesa_update_default_objects_buffer_objects(ctx
);
714 * This is the default function we plug into all dispatch table slots
715 * This helps prevents a segfault when someone calls a GL function without
716 * first checking if the extension's supported.
721 _mesa_warning(NULL
, "User called no-op dispatch function (an unsupported extension function?)");
727 * Allocate and initialize a new dispatch table.
729 struct _glapi_table
*
730 _mesa_alloc_dispatch_table(int size
)
732 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
733 * In practice, this'll be the same for stand-alone Mesa. But for DRI
734 * Mesa we do this to accomodate different versions of libGL and various
737 GLint numEntries
= MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT
);
738 struct _glapi_table
*table
;
740 /* should never happen, but just in case */
741 numEntries
= MAX2(numEntries
, size
);
743 table
= (struct _glapi_table
*) malloc(numEntries
* sizeof(_glapi_proc
));
745 _glapi_proc
*entry
= (_glapi_proc
*) table
;
747 for (i
= 0; i
< numEntries
; i
++) {
748 entry
[i
] = (_glapi_proc
) generic_nop
;
756 * Initialize a struct gl_context struct (rendering context).
758 * This includes allocating all the other structs and arrays which hang off of
759 * the context by pointers.
760 * Note that the driver needs to pass in its dd_function_table here since
761 * we need to at least call driverFunctions->NewTextureObject to create the
762 * default texture objects.
764 * Called by _mesa_create_context().
766 * Performs the imports and exports callback tables initialization, and
767 * miscellaneous one-time initializations. If no shared context is supplied one
768 * is allocated, and increase its reference count. Setups the GL API dispatch
769 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
770 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
773 * \param ctx the context to initialize
774 * \param api the GL API type to create the context for
775 * \param visual describes the visual attributes for this context
776 * \param share_list points to context to share textures, display lists,
778 * \param driverFunctions table of device driver functions for this context
780 * \param driverContext pointer to driver-specific context data
783 _mesa_initialize_context(struct gl_context
*ctx
,
784 const struct gl_config
*visual
,
785 struct gl_context
*share_list
,
786 const struct dd_function_table
*driverFunctions
,
789 struct gl_shared_state
*shared
;
791 /*ASSERT(driverContext);*/
792 assert(driverFunctions
->NewTextureObject
);
793 assert(driverFunctions
->FreeTextureImageBuffer
);
795 ctx
->Visual
= *visual
;
796 ctx
->DrawBuffer
= NULL
;
797 ctx
->ReadBuffer
= NULL
;
798 ctx
->WinSysDrawBuffer
= NULL
;
799 ctx
->WinSysReadBuffer
= NULL
;
801 /* misc one-time initializations */
804 /* Plug in driver functions and context pointer here.
805 * This is important because when we call alloc_shared_state() below
806 * we'll call ctx->Driver.NewTextureObject() to create the default
809 ctx
->Driver
= *driverFunctions
;
810 ctx
->DriverCtx
= driverContext
;
813 /* share state with another context */
814 shared
= share_list
->Shared
;
817 /* allocate new, unshared state */
818 shared
= _mesa_alloc_shared_state(ctx
);
823 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, shared
);
825 if (!init_attrib_groups( ctx
)) {
826 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
830 ctx
->Exec
= _mesa_create_exec_table();
833 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
836 ctx
->CurrentDispatch
= ctx
->Exec
;
838 /* Mesa core handles all the formats that mesa core knows about.
839 * Drivers will want to override this list with just the formats
840 * they can handle, and confirm that appropriate fallbacks exist in
841 * _mesa_choose_tex_format().
843 memset(&ctx
->TextureFormatSupported
, GL_TRUE
,
844 sizeof(ctx
->TextureFormatSupported
));
846 ctx
->Save
= _mesa_create_save_table();
848 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
853 _mesa_install_save_vtxfmt( ctx
, &ctx
->ListState
.ListVtxfmt
);
855 ctx
->FirstTimeCurrent
= GL_TRUE
;
862 * Allocate and initialize a struct gl_context structure.
863 * Note that the driver needs to pass in its dd_function_table here since
864 * we need to at least call driverFunctions->NewTextureObject to initialize
865 * the rendering context.
867 * \param api the GL API type to create the context for
868 * \param visual a struct gl_config pointer (we copy the struct contents)
869 * \param share_list another context to share display lists with or NULL
870 * \param driverFunctions points to the dd_function_table into which the
871 * driver has plugged in all its special functions.
872 * \param driverContext points to the device driver's private context state
874 * \return pointer to a new __struct gl_contextRec or NULL if error.
877 _mesa_create_context(const struct gl_config
*visual
,
878 struct gl_context
*share_list
,
879 const struct dd_function_table
*driverFunctions
,
882 struct gl_context
*ctx
;
885 /*ASSERT(driverContext);*/
887 ctx
= (struct gl_context
*) calloc(1, sizeof(struct gl_context
));
891 if (_mesa_initialize_context(ctx
, visual
, share_list
,
892 driverFunctions
, driverContext
)) {
903 * Free the data associated with the given context.
905 * But doesn't free the struct gl_context struct itself.
907 * \sa _mesa_initialize_context() and init_attrib_groups().
910 _mesa_free_context_data( struct gl_context
*ctx
)
912 if (!_mesa_get_current_context()){
913 /* No current context, but we may need one in order to delete
914 * texture objs, etc. So temporarily bind the context now.
916 _mesa_make_current(ctx
, NULL
, NULL
);
919 /* unreference WinSysDraw/Read buffers */
920 _mesa_reference_framebuffer(&ctx
->WinSysDrawBuffer
, NULL
);
921 _mesa_reference_framebuffer(&ctx
->WinSysReadBuffer
, NULL
);
922 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, NULL
);
923 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, NULL
);
925 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
, NULL
);
926 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
, NULL
);
928 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
, NULL
);
929 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
, NULL
);
931 _mesa_free_attrib_data(ctx
);
932 _mesa_free_buffer_objects(ctx
);
933 _mesa_free_lighting_data( ctx
);
934 _mesa_free_eval_data( ctx
);
935 _mesa_free_texture_data( ctx
);
936 _mesa_free_matrix_data( ctx
);
937 _mesa_free_viewport_data( ctx
);
938 _mesa_free_program_data(ctx
);
939 _mesa_free_shader_state(ctx
);
940 _mesa_free_varray_data(ctx
);
942 _mesa_delete_array_object(ctx
, ctx
->Array
.DefaultArrayObj
);
944 #if FEATURE_ARB_pixel_buffer_object
945 _mesa_reference_buffer_object(ctx
, &ctx
->Pack
.BufferObj
, NULL
);
946 _mesa_reference_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
, NULL
);
947 _mesa_reference_buffer_object(ctx
, &ctx
->DefaultPacking
.BufferObj
, NULL
);
950 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
952 /* free dispatch tables */
956 /* Shared context state (display lists, textures, etc) */
957 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, NULL
);
959 /* needs to be after freeing shared state */
960 _mesa_free_display_list_data(ctx
);
962 if (ctx
->Extensions
.String
)
963 free((void *) ctx
->Extensions
.String
);
965 if (ctx
->VersionString
)
966 free(ctx
->VersionString
);
968 /* unbind the context if it's currently bound */
969 if (ctx
== _mesa_get_current_context()) {
970 _mesa_make_current(NULL
, NULL
, NULL
);
976 * Destroy a struct gl_context structure.
978 * \param ctx GL context.
980 * Calls _mesa_free_context_data() and frees the gl_context object itself.
983 _mesa_destroy_context( struct gl_context
*ctx
)
986 _mesa_free_context_data(ctx
);
987 free( (void *) ctx
);
994 * Copy attribute groups from one context to another.
996 * \param src source context
997 * \param dst destination context
998 * \param mask bitwise OR of GL_*_BIT flags
1000 * According to the bits specified in \p mask, copies the corresponding
1001 * attributes from \p src into \p dst. For many of the attributes a simple \c
1002 * memcpy is not enough due to the existence of internal pointers in their data
1006 _mesa_copy_context( const struct gl_context
*src
, struct gl_context
*dst
,
1009 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1011 dst
->Accum
= src
->Accum
;
1013 if (mask
& GL_COLOR_BUFFER_BIT
) {
1015 dst
->Color
= src
->Color
;
1017 if (mask
& GL_CURRENT_BIT
) {
1019 dst
->Current
= src
->Current
;
1021 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1023 dst
->Depth
= src
->Depth
;
1025 if (mask
& GL_ENABLE_BIT
) {
1028 if (mask
& GL_EVAL_BIT
) {
1030 dst
->Eval
= src
->Eval
;
1032 if (mask
& GL_FOG_BIT
) {
1034 dst
->Fog
= src
->Fog
;
1036 if (mask
& GL_HINT_BIT
) {
1038 dst
->Hint
= src
->Hint
;
1040 if (mask
& GL_LIGHTING_BIT
) {
1042 /* begin with memcpy */
1043 dst
->Light
= src
->Light
;
1044 /* fixup linked lists to prevent pointer insanity */
1045 make_empty_list( &(dst
->Light
.EnabledList
) );
1046 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
1047 if (dst
->Light
.Light
[i
].Enabled
) {
1048 insert_at_tail(&(dst
->Light
.EnabledList
), &(dst
->Light
.Light
[i
]));
1052 if (mask
& GL_LINE_BIT
) {
1054 dst
->Line
= src
->Line
;
1056 if (mask
& GL_LIST_BIT
) {
1058 dst
->List
= src
->List
;
1060 if (mask
& GL_PIXEL_MODE_BIT
) {
1062 dst
->Pixel
= src
->Pixel
;
1064 if (mask
& GL_POINT_BIT
) {
1066 dst
->Point
= src
->Point
;
1068 if (mask
& GL_POLYGON_BIT
) {
1070 dst
->Polygon
= src
->Polygon
;
1072 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1073 /* Use loop instead of memcpy due to problem with Portland Group's
1074 * C compiler. Reported by John Stone.
1077 for (i
= 0; i
< 32; i
++) {
1078 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1081 if (mask
& GL_SCISSOR_BIT
) {
1083 dst
->Scissor
= src
->Scissor
;
1085 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1087 dst
->Stencil
= src
->Stencil
;
1089 if (mask
& GL_TEXTURE_BIT
) {
1090 /* Cannot memcpy because of pointers */
1091 _mesa_copy_texture_state(src
, dst
);
1093 if (mask
& GL_TRANSFORM_BIT
) {
1095 dst
->Transform
= src
->Transform
;
1097 if (mask
& GL_VIEWPORT_BIT
) {
1098 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1099 dst
->Viewport
.X
= src
->Viewport
.X
;
1100 dst
->Viewport
.Y
= src
->Viewport
.Y
;
1101 dst
->Viewport
.Width
= src
->Viewport
.Width
;
1102 dst
->Viewport
.Height
= src
->Viewport
.Height
;
1103 dst
->Viewport
.Near
= src
->Viewport
.Near
;
1104 dst
->Viewport
.Far
= src
->Viewport
.Far
;
1105 _math_matrix_copy(&dst
->Viewport
._WindowMap
, &src
->Viewport
._WindowMap
);
1108 /* XXX FIXME: Call callbacks?
1110 dst
->NewState
= _NEW_ALL
;
1116 * Check if the given context can render into the given framebuffer
1117 * by checking visual attributes.
1119 * Most of these tests could go away because Mesa is now pretty flexible
1120 * in terms of mixing rendering contexts with framebuffers. As long
1121 * as RGB vs. CI mode agree, we're probably good.
1123 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1126 check_compatible(const struct gl_context
*ctx
,
1127 const struct gl_framebuffer
*buffer
)
1129 const struct gl_config
*ctxvis
= &ctx
->Visual
;
1130 const struct gl_config
*bufvis
= &buffer
->Visual
;
1133 /* disabling this fixes the fgl_glxgears pbuffer demo */
1134 if (ctxvis
->doubleBufferMode
&& !bufvis
->doubleBufferMode
)
1137 if (ctxvis
->stereoMode
&& !bufvis
->stereoMode
)
1139 if (ctxvis
->haveAccumBuffer
&& !bufvis
->haveAccumBuffer
)
1141 if (ctxvis
->haveDepthBuffer
&& !bufvis
->haveDepthBuffer
)
1143 if (ctxvis
->haveStencilBuffer
&& !bufvis
->haveStencilBuffer
)
1145 if (ctxvis
->redMask
&& ctxvis
->redMask
!= bufvis
->redMask
)
1147 if (ctxvis
->greenMask
&& ctxvis
->greenMask
!= bufvis
->greenMask
)
1149 if (ctxvis
->blueMask
&& ctxvis
->blueMask
!= bufvis
->blueMask
)
1152 /* disabled (see bug 11161) */
1153 if (ctxvis
->depthBits
&& ctxvis
->depthBits
!= bufvis
->depthBits
)
1156 if (ctxvis
->stencilBits
&& ctxvis
->stencilBits
!= bufvis
->stencilBits
)
1164 * Do one-time initialization for the given framebuffer. Specifically,
1165 * ask the driver for the window's current size and update the framebuffer
1167 * Really, the device driver should totally take care of this.
1170 initialize_framebuffer_size(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1172 GLuint width
, height
;
1173 if (ctx
->Driver
.GetBufferSize
) {
1174 ctx
->Driver
.GetBufferSize(fb
, &width
, &height
);
1175 if (ctx
->Driver
.ResizeBuffers
)
1176 ctx
->Driver
.ResizeBuffers(ctx
, fb
, width
, height
);
1177 fb
->Initialized
= GL_TRUE
;
1183 * Check if the viewport/scissor size has not yet been initialized.
1184 * Initialize the size if the given width and height are non-zero.
1187 _mesa_check_init_viewport(struct gl_context
*ctx
, GLuint width
, GLuint height
)
1189 if (!ctx
->ViewportInitialized
&& width
> 0 && height
> 0) {
1190 /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
1191 * potential infinite recursion.
1193 ctx
->ViewportInitialized
= GL_TRUE
;
1194 _mesa_set_viewport(ctx
, 0, 0, width
, height
);
1195 _mesa_set_scissor(ctx
, 0, 0, width
, height
);
1201 * Bind the given context to the given drawBuffer and readBuffer and
1202 * make it the current context for the calling thread.
1203 * We'll render into the drawBuffer and read pixels from the
1204 * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
1206 * We check that the context's and framebuffer's visuals are compatible
1207 * and return immediately if they're not.
1209 * \param newCtx the new GL context. If NULL then there will be no current GL
1211 * \param drawBuffer the drawing framebuffer
1212 * \param readBuffer the reading framebuffer
1215 _mesa_make_current( struct gl_context
*newCtx
,
1216 struct gl_framebuffer
*drawBuffer
,
1217 struct gl_framebuffer
*readBuffer
)
1219 GET_CURRENT_CONTEXT(curCtx
);
1221 if (MESA_VERBOSE
& VERBOSE_API
)
1222 _mesa_debug(newCtx
, "_mesa_make_current()\n");
1224 /* Check that the context's and framebuffer's visuals are compatible.
1226 if (newCtx
&& drawBuffer
&& newCtx
->WinSysDrawBuffer
!= drawBuffer
) {
1227 if (!check_compatible(newCtx
, drawBuffer
)) {
1228 _mesa_warning(newCtx
,
1229 "MakeCurrent: incompatible visuals for context and drawbuffer");
1233 if (newCtx
&& readBuffer
&& newCtx
->WinSysReadBuffer
!= readBuffer
) {
1234 if (!check_compatible(newCtx
, readBuffer
)) {
1235 _mesa_warning(newCtx
,
1236 "MakeCurrent: incompatible visuals for context and readbuffer");
1242 (curCtx
->WinSysDrawBuffer
|| curCtx
->WinSysReadBuffer
) &&
1243 /* make sure this context is valid for flushing */
1245 _mesa_flush(curCtx
);
1247 /* We used to call _glapi_check_multithread() here. Now do it in drivers */
1248 _glapi_set_context((void *) newCtx
);
1249 ASSERT(_mesa_get_current_context() == newCtx
);
1252 _glapi_set_dispatch(NULL
); /* none current */
1255 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1257 if (drawBuffer
&& readBuffer
) {
1258 ASSERT(drawBuffer
->Name
== 0);
1259 ASSERT(readBuffer
->Name
== 0);
1260 _mesa_reference_framebuffer(&newCtx
->WinSysDrawBuffer
, drawBuffer
);
1261 _mesa_reference_framebuffer(&newCtx
->WinSysReadBuffer
, readBuffer
);
1264 * Only set the context's Draw/ReadBuffer fields if they're NULL
1265 * or not bound to a user-created FBO.
1267 _mesa_reference_framebuffer(&newCtx
->DrawBuffer
, drawBuffer
);
1268 /* Update the FBO's list of drawbuffers/renderbuffers.
1269 * For winsys FBOs this comes from the GL state (which may have
1270 * changed since the last time this FBO was bound).
1272 _mesa_update_draw_buffer(newCtx
);
1274 _mesa_reference_framebuffer(&newCtx
->ReadBuffer
, readBuffer
);
1276 /* XXX only set this flag if we're really changing the draw/read
1277 * framebuffer bindings.
1279 newCtx
->NewState
|= _NEW_BUFFERS
;
1282 /* We want to get rid of these lines: */
1285 if (!drawBuffer
->Initialized
) {
1286 initialize_framebuffer_size(newCtx
, drawBuffer
);
1288 if (readBuffer
!= drawBuffer
&& !readBuffer
->Initialized
) {
1289 initialize_framebuffer_size(newCtx
, readBuffer
);
1292 _mesa_resizebuffers(newCtx
);
1296 /* We want the drawBuffer and readBuffer to be initialized by
1298 * This generally means the Width and Height match the actual
1299 * window size and the renderbuffers (both hardware and software
1300 * based) are allocated to match. The later can generally be
1301 * done with a call to _mesa_resize_framebuffer().
1303 * It's theoretically possible for a buffer to have zero width
1304 * or height, but for now, assert check that the driver did what's
1307 ASSERT(drawBuffer
->Width
> 0);
1308 ASSERT(drawBuffer
->Height
> 0);
1312 _mesa_check_init_viewport(newCtx
,
1313 drawBuffer
->Width
, drawBuffer
->Height
);
1317 if (newCtx
->FirstTimeCurrent
) {
1318 _mesa_compute_version(newCtx
);
1320 newCtx
->Extensions
.String
= _mesa_make_extension_string(newCtx
);
1322 check_context_limits(newCtx
);
1324 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1333 * Make context 'ctx' share the display lists, textures and programs
1334 * that are associated with 'ctxToShare'.
1335 * Any display lists, textures or programs associated with 'ctx' will
1336 * be deleted if nobody else is sharing them.
1339 _mesa_share_state(struct gl_context
*ctx
, struct gl_context
*ctxToShare
)
1341 if (ctx
&& ctxToShare
&& ctx
->Shared
&& ctxToShare
->Shared
) {
1342 struct gl_shared_state
*oldShared
= NULL
;
1344 /* save ref to old state to prevent it from being deleted immediately */
1345 _mesa_reference_shared_state(ctx
, &oldShared
, ctx
->Shared
);
1347 /* update ctx's Shared pointer */
1348 _mesa_reference_shared_state(ctx
, &ctx
->Shared
, ctxToShare
->Shared
);
1350 update_default_objects(ctx
);
1352 /* release the old shared state */
1353 _mesa_reference_shared_state(ctx
, &oldShared
, NULL
);
1365 * \return pointer to the current GL context for this thread.
1367 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1368 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
1372 _mesa_get_current_context( void )
1374 return (struct gl_context
*) _glapi_get_context();
1379 * Get context's current API dispatch table.
1381 * It'll either be the immediate-mode execute dispatcher or the display list
1382 * compile dispatcher.
1384 * \param ctx GL context.
1386 * \return pointer to dispatch_table.
1388 * Simply returns __struct gl_contextRec::CurrentDispatch.
1390 struct _glapi_table
*
1391 _mesa_get_dispatch(struct gl_context
*ctx
)
1393 return ctx
->CurrentDispatch
;
1399 /**********************************************************************/
1400 /** \name Miscellaneous functions */
1401 /**********************************************************************/
1407 * \param ctx GL context.
1408 * \param error error code.
1410 * Records the given error code and call the driver's dd_function_table::Error
1411 * function if defined.
1414 * This is called via _mesa_error().
1417 _mesa_record_error(struct gl_context
*ctx
, GLenum error
)
1422 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
1423 ctx
->ErrorValue
= error
;
1426 /* Call device driver's error handler, if any. This is used on the Mac. */
1427 if (ctx
->Driver
.Error
) {
1428 ctx
->Driver
.Error(ctx
);
1434 * Flush commands and wait for completion.
1437 _mesa_finish(struct gl_context
*ctx
)
1439 FLUSH_CURRENT( ctx
, 0 );
1440 if (ctx
->Driver
.Finish
) {
1441 ctx
->Driver
.Finish(ctx
);
1450 _mesa_flush(struct gl_context
*ctx
)
1452 FLUSH_CURRENT( ctx
, 0 );
1453 if (ctx
->Driver
.Flush
) {
1454 ctx
->Driver
.Flush(ctx
);
1461 * Execute glFinish().
1463 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1464 * dd_function_table::Finish driver callback, if not NULL.
1469 GET_CURRENT_CONTEXT(ctx
);
1470 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1476 * Execute glFlush().
1478 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1479 * dd_function_table::Flush driver callback, if not NULL.
1484 GET_CURRENT_CONTEXT(ctx
);
1485 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1491 * Set mvp_with_dp4 flag. If a driver has a preference for DP4 over
1492 * MUL/MAD, or vice versa, call this function to register that.
1493 * Otherwise we default to MUL/MAD.
1496 _mesa_set_mvp_with_dp4( struct gl_context
*ctx
,
1499 ctx
->mvp_with_dp4
= flag
;
1505 * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
1506 * is called to see if it's valid to render. This involves checking that
1507 * the current shader is valid and the framebuffer is complete.
1508 * If an error is detected it'll be recorded here.
1509 * \return GL_TRUE if OK to render, GL_FALSE if not
1512 _mesa_valid_to_render(struct gl_context
*ctx
, const char *where
)
1514 bool vert_from_glsl_shader
= false;
1515 bool frag_from_glsl_shader
= false;
1517 /* This depends on having up to date derived state (shaders) */
1519 _mesa_update_state(ctx
);
1521 if (ctx
->Shader
.CurrentVertexProgram
) {
1522 vert_from_glsl_shader
= true;
1524 if (!ctx
->Shader
.CurrentVertexProgram
->LinkStatus
) {
1525 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1526 "%s(shader not linked)", where
);
1529 #if 0 /* not normally enabled */
1532 if (!_mesa_validate_shader_program(ctx
,
1533 ctx
->Shader
.CurrentVertexProgram
,
1535 _mesa_warning(ctx
, "Shader program %u is invalid: %s",
1536 ctx
->Shader
.CurrentVertexProgram
->Name
, errMsg
);
1542 if (ctx
->Shader
.CurrentFragmentProgram
) {
1543 frag_from_glsl_shader
= true;
1545 if (!ctx
->Shader
.CurrentFragmentProgram
->LinkStatus
) {
1546 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1547 "%s(shader not linked)", where
);
1550 #if 0 /* not normally enabled */
1553 if (!_mesa_validate_shader_program(ctx
,
1554 ctx
->Shader
.CurrentFragmentProgram
,
1556 _mesa_warning(ctx
, "Shader program %u is invalid: %s",
1557 ctx
->Shader
.CurrentFragmentProgram
->Name
, errMsg
);
1563 /* Any shader stages that are not supplied by the GLSL shader and have
1564 * assembly shaders enabled must now be validated.
1566 if (!vert_from_glsl_shader
1567 && ctx
->VertexProgram
.Enabled
&& !ctx
->VertexProgram
._Enabled
) {
1568 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1569 "%s(vertex program not valid)", where
);
1573 if (!frag_from_glsl_shader
) {
1574 if (ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
) {
1575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1576 "%s(fragment program not valid)", where
);
1580 /* If drawing to integer-valued color buffers, there must be an
1581 * active fragment shader (GL_EXT_texture_integer).
1583 if (ctx
->DrawBuffer
&& ctx
->DrawBuffer
->_IntegerColor
) {
1584 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1585 "%s(integer format but no fragment shader)", where
);
1591 if (ctx
->Shader
.Flags
& GLSL_LOG
) {
1592 struct gl_shader_program
*shProg
[MESA_SHADER_TYPES
];
1595 shProg
[MESA_SHADER_VERTEX
] = ctx
->Shader
.CurrentVertexProgram
;
1596 shProg
[MESA_SHADER_FRAGMENT
] = ctx
->Shader
.CurrentFragmentProgram
;
1598 for (i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
1599 if (shProg
[i
] == NULL
|| shProg
[i
]->_Used
1600 || shProg
[i
]->_LinkedShaders
[i
] == NULL
)
1603 /* This is the first time this shader is being used.
1604 * Append shader's constants/uniforms to log file.
1606 * Only log data for the program target that matches the shader
1607 * target. It's possible to have a program bound to the vertex
1608 * shader target that also supplied a fragment shader. If that
1609 * program isn't also bound to the fragment shader target we don't
1610 * want to log its fragment data.
1612 _mesa_append_uniforms_to_file(shProg
[i
]->_LinkedShaders
[i
]);
1615 for (i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
1616 if (shProg
[i
] != NULL
)
1617 shProg
[i
]->_Used
= GL_TRUE
;