Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / mesa / main / context.c
1 /**
2 * \file context.c
3 * Mesa context/visual/framebuffer management functions.
4 * \author Brian Paul
5 */
6
7 /*
8 * Mesa 3-D graphics library
9 * Version: 7.1
10 *
11 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included
21 * in all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
27 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
32 /**
33 * \mainpage Mesa Main Module
34 *
35 * \section MainIntroduction Introduction
36 *
37 * The Mesa Main module consists of all the files in the main/ directory.
38 * Among the features of this module are:
39 * <UL>
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>
45 * </UL>
46 *
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.
50 *
51 *
52 * \section AboutDoxygen About Doxygen
53 *
54 * If you're viewing this information as Doxygen-generated HTML you'll
55 * see the documentation index at the top of this page.
56 *
57 * The first line lists the Mesa source code modules.
58 * The second line lists the indexes available for viewing the documentation
59 * for each module.
60 *
61 * Selecting the <b>Main page</b> link will display a summary of the module
62 * (this page).
63 *
64 * Selecting <b>Data Structures</b> will list all C structures.
65 *
66 * Selecting the <b>File List</b> link will list all the source files in
67 * the module.
68 * Selecting a filename will show a list of all functions defined in that file.
69 *
70 * Selecting the <b>Data Fields</b> link will display a list of all
71 * documented structure members.
72 *
73 * Selecting the <b>Globals</b> link will display a list
74 * of all functions, structures, global variables and macros in the module.
75 *
76 */
77
78
79 #include "glheader.h"
80 #include "imports.h"
81 #if FEATURE_accum
82 #include "accum.h"
83 #endif
84 #include "api_exec.h"
85 #include "arrayobj.h"
86 #if FEATURE_attrib_stack
87 #include "attrib.h"
88 #endif
89 #include "blend.h"
90 #include "buffers.h"
91 #include "bufferobj.h"
92 #if FEATURE_colortable
93 #include "colortab.h"
94 #endif
95 #include "context.h"
96 #include "debug.h"
97 #include "depth.h"
98 #if FEATURE_dlist
99 #include "dlist.h"
100 #endif
101 #if FEATURE_evaluators
102 #include "eval.h"
103 #endif
104 #include "enums.h"
105 #include "extensions.h"
106 #include "fbobject.h"
107 #if FEATURE_feedback
108 #include "feedback.h"
109 #endif
110 #include "fog.h"
111 #include "framebuffer.h"
112 #include "get.h"
113 #if FEATURE_histogram
114 #include "histogram.h"
115 #endif
116 #include "hint.h"
117 #include "hash.h"
118 #include "light.h"
119 #include "lines.h"
120 #include "macros.h"
121 #include "matrix.h"
122 #include "multisample.h"
123 #include "pixel.h"
124 #include "pixelstore.h"
125 #include "points.h"
126 #include "polygon.h"
127 #if FEATURE_ARB_occlusion_query
128 #include "queryobj.h"
129 #endif
130 #if FEATURE_drawpix
131 #include "rastpos.h"
132 #endif
133 #include "scissor.h"
134 #include "simple_list.h"
135 #include "state.h"
136 #include "stencil.h"
137 #include "texcompress.h"
138 #include "teximage.h"
139 #include "texobj.h"
140 #include "texstate.h"
141 #include "mtypes.h"
142 #include "varray.h"
143 #include "version.h"
144 #include "vtxfmt.h"
145 #include "glapi/glthread.h"
146 #include "glapi/glapioffsets.h"
147 #include "glapi/glapitable.h"
148 #include "shader/program.h"
149 #include "shader/shader_api.h"
150 #if FEATURE_ATI_fragment_shader
151 #include "shader/atifragshader.h"
152 #endif
153 #if _HAVE_FULL_GL
154 #include "math/m_translate.h"
155 #include "math/m_matrix.h"
156 #include "math/m_xform.h"
157 #include "math/mathmod.h"
158 #endif
159
160 #ifdef USE_SPARC_ASM
161 #include "sparc/sparc.h"
162 #endif
163
164 #ifndef MESA_VERBOSE
165 int MESA_VERBOSE = 0;
166 #endif
167
168 #ifndef MESA_DEBUG_FLAGS
169 int MESA_DEBUG_FLAGS = 0;
170 #endif
171
172
173 /* ubyte -> float conversion */
174 GLfloat _mesa_ubyte_to_float_color_tab[256];
175
176
177
178 /**
179 * Swap buffers notification callback.
180 *
181 * \param gc GL context.
182 *
183 * Called by window system just before swapping buffers.
184 * We have to finish any pending rendering.
185 */
186 void
187 _mesa_notifySwapBuffers(__GLcontext *ctx)
188 {
189 if (ctx->Driver.Flush) {
190 ctx->Driver.Flush(ctx);
191 }
192 }
193
194
195 /**********************************************************************/
196 /** \name GL Visual allocation/destruction */
197 /**********************************************************************/
198 /*@{*/
199
200 /**
201 * Allocates a GLvisual structure and initializes it via
202 * _mesa_initialize_visual().
203 *
204 * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
205 * \param dbFlag double buffering
206 * \param stereoFlag stereo buffer
207 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
208 * is acceptable but the actual depth type will be GLushort or GLuint as
209 * needed.
210 * \param stencilBits requested minimum bits per stencil buffer value
211 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
212 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
213 * \param redBits number of bits per color component in frame buffer for RGB(A)
214 * mode. We always use 8 in core Mesa though.
215 * \param greenBits same as above.
216 * \param blueBits same as above.
217 * \param alphaBits same as above.
218 * \param numSamples not really used.
219 *
220 * \return pointer to new GLvisual or NULL if requested parameters can't be
221 * met.
222 *
223 * \note Need to add params for level and numAuxBuffers (at least)
224 */
225 GLvisual *
226 _mesa_create_visual( GLboolean rgbFlag,
227 GLboolean dbFlag,
228 GLboolean stereoFlag,
229 GLint redBits,
230 GLint greenBits,
231 GLint blueBits,
232 GLint alphaBits,
233 GLint indexBits,
234 GLint depthBits,
235 GLint stencilBits,
236 GLint accumRedBits,
237 GLint accumGreenBits,
238 GLint accumBlueBits,
239 GLint accumAlphaBits,
240 GLint numSamples )
241 {
242 GLvisual *vis = (GLvisual *) _mesa_calloc(sizeof(GLvisual));
243 if (vis) {
244 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
245 redBits, greenBits, blueBits, alphaBits,
246 indexBits, depthBits, stencilBits,
247 accumRedBits, accumGreenBits,
248 accumBlueBits, accumAlphaBits,
249 numSamples)) {
250 _mesa_free(vis);
251 return NULL;
252 }
253 }
254 return vis;
255 }
256
257 /**
258 * Makes some sanity checks and fills in the fields of the
259 * GLvisual object with the given parameters. If the caller needs
260 * to set additional fields, he should just probably init the whole GLvisual
261 * object himself.
262 * \return GL_TRUE on success, or GL_FALSE on failure.
263 *
264 * \sa _mesa_create_visual() above for the parameter description.
265 */
266 GLboolean
267 _mesa_initialize_visual( GLvisual *vis,
268 GLboolean rgbFlag,
269 GLboolean dbFlag,
270 GLboolean stereoFlag,
271 GLint redBits,
272 GLint greenBits,
273 GLint blueBits,
274 GLint alphaBits,
275 GLint indexBits,
276 GLint depthBits,
277 GLint stencilBits,
278 GLint accumRedBits,
279 GLint accumGreenBits,
280 GLint accumBlueBits,
281 GLint accumAlphaBits,
282 GLint numSamples )
283 {
284 assert(vis);
285
286 if (depthBits < 0 || depthBits > 32) {
287 return GL_FALSE;
288 }
289 if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
290 return GL_FALSE;
291 }
292 assert(accumRedBits >= 0);
293 assert(accumGreenBits >= 0);
294 assert(accumBlueBits >= 0);
295 assert(accumAlphaBits >= 0);
296
297 vis->rgbMode = rgbFlag;
298 vis->doubleBufferMode = dbFlag;
299 vis->stereoMode = stereoFlag;
300
301 vis->redBits = redBits;
302 vis->greenBits = greenBits;
303 vis->blueBits = blueBits;
304 vis->alphaBits = alphaBits;
305 vis->rgbBits = redBits + greenBits + blueBits;
306
307 vis->indexBits = indexBits;
308 vis->depthBits = depthBits;
309 vis->stencilBits = stencilBits;
310
311 vis->accumRedBits = accumRedBits;
312 vis->accumGreenBits = accumGreenBits;
313 vis->accumBlueBits = accumBlueBits;
314 vis->accumAlphaBits = accumAlphaBits;
315
316 vis->haveAccumBuffer = accumRedBits > 0;
317 vis->haveDepthBuffer = depthBits > 0;
318 vis->haveStencilBuffer = stencilBits > 0;
319
320 vis->numAuxBuffers = 0;
321 vis->level = 0;
322 vis->pixmapMode = 0;
323 vis->sampleBuffers = numSamples > 0 ? 1 : 0;
324 vis->samples = numSamples;
325
326 return GL_TRUE;
327 }
328
329
330 /**
331 * Destroy a visual and free its memory.
332 *
333 * \param vis visual.
334 *
335 * Frees the visual structure.
336 */
337 void
338 _mesa_destroy_visual( GLvisual *vis )
339 {
340 _mesa_free(vis);
341 }
342
343 /*@}*/
344
345
346 /**********************************************************************/
347 /** \name Context allocation, initialization, destroying
348 *
349 * The purpose of the most initialization functions here is to provide the
350 * default state values according to the OpenGL specification.
351 */
352 /**********************************************************************/
353 /*@{*/
354
355 /**
356 * One-time initialization mutex lock.
357 *
358 * \sa Used by one_time_init().
359 */
360 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
361
362 /**
363 * Calls all the various one-time-init functions in Mesa.
364 *
365 * While holding a global mutex lock, calls several initialization functions,
366 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
367 * defined.
368 *
369 * \sa _math_init().
370 */
371 static void
372 one_time_init( GLcontext *ctx )
373 {
374 static GLboolean alreadyCalled = GL_FALSE;
375 (void) ctx;
376 _glthread_LOCK_MUTEX(OneTimeLock);
377 if (!alreadyCalled) {
378 GLuint i;
379
380 /* do some implementation tests */
381 assert( sizeof(GLbyte) == 1 );
382 assert( sizeof(GLubyte) == 1 );
383 assert( sizeof(GLshort) == 2 );
384 assert( sizeof(GLushort) == 2 );
385 assert( sizeof(GLint) == 4 );
386 assert( sizeof(GLuint) == 4 );
387
388 _mesa_init_sqrt_table();
389
390 #if _HAVE_FULL_GL
391 _math_init();
392
393 for (i = 0; i < 256; i++) {
394 _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
395 }
396 #endif
397
398 #ifdef USE_SPARC_ASM
399 _mesa_init_sparc_glapi_relocs();
400 #endif
401 if (_mesa_getenv("MESA_DEBUG")) {
402 _glapi_noop_enable_warnings(GL_TRUE);
403 _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
404 }
405 else {
406 _glapi_noop_enable_warnings(GL_FALSE);
407 }
408
409 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
410 _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
411 MESA_VERSION_STRING, __DATE__, __TIME__);
412 #endif
413
414 alreadyCalled = GL_TRUE;
415 }
416 _glthread_UNLOCK_MUTEX(OneTimeLock);
417 }
418
419
420 /**
421 * Allocate and initialize a shared context state structure.
422 * Initializes the display list, texture objects and vertex programs hash
423 * tables, allocates the texture objects. If it runs out of memory, frees
424 * everything already allocated before returning NULL.
425 *
426 * \return pointer to a gl_shared_state structure on success, or NULL on
427 * failure.
428 */
429 static GLboolean
430 alloc_shared_state( GLcontext *ctx )
431 {
432 struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
433 if (!ss)
434 return GL_FALSE;
435
436 ctx->Shared = ss;
437
438 _glthread_INIT_MUTEX(ss->Mutex);
439
440 ss->DisplayList = _mesa_NewHashTable();
441 ss->TexObjects = _mesa_NewHashTable();
442 ss->Programs = _mesa_NewHashTable();
443
444 #if FEATURE_ARB_vertex_program
445 ss->DefaultVertexProgram = (struct gl_vertex_program *)
446 ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
447 if (!ss->DefaultVertexProgram)
448 goto cleanup;
449 #endif
450 #if FEATURE_ARB_fragment_program
451 ss->DefaultFragmentProgram = (struct gl_fragment_program *)
452 ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
453 if (!ss->DefaultFragmentProgram)
454 goto cleanup;
455 #endif
456 #if FEATURE_ATI_fragment_shader
457 ss->ATIShaders = _mesa_NewHashTable();
458 ss->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
459 if (!ss->DefaultFragmentShader)
460 goto cleanup;
461 #endif
462
463 #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
464 ss->BufferObjects = _mesa_NewHashTable();
465 #endif
466
467 ss->ArrayObjects = _mesa_NewHashTable();
468
469 #if FEATURE_ARB_shader_objects
470 ss->ShaderObjects = _mesa_NewHashTable();
471 #endif
472
473 ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
474 if (!ss->Default1D)
475 goto cleanup;
476
477 ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
478 if (!ss->Default2D)
479 goto cleanup;
480
481 ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
482 if (!ss->Default3D)
483 goto cleanup;
484
485 ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
486 if (!ss->DefaultCubeMap)
487 goto cleanup;
488
489 ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
490 if (!ss->DefaultRect)
491 goto cleanup;
492
493 ss->Default1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT);
494 if (!ss->Default1DArray)
495 goto cleanup;
496
497 ss->Default2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT);
498 if (!ss->Default2DArray)
499 goto cleanup;
500
501 /* sanity check */
502 assert(ss->Default1D->RefCount == 1);
503
504 _glthread_INIT_MUTEX(ss->TexMutex);
505 ss->TextureStateStamp = 0;
506
507 #if FEATURE_EXT_framebuffer_object
508 ss->FrameBuffers = _mesa_NewHashTable();
509 if (!ss->FrameBuffers)
510 goto cleanup;
511 ss->RenderBuffers = _mesa_NewHashTable();
512 if (!ss->RenderBuffers)
513 goto cleanup;
514 #endif
515
516 return GL_TRUE;
517
518 cleanup:
519 /* Ran out of memory at some point. Free everything and return NULL */
520 if (ss->DisplayList)
521 _mesa_DeleteHashTable(ss->DisplayList);
522 if (ss->TexObjects)
523 _mesa_DeleteHashTable(ss->TexObjects);
524 if (ss->Programs)
525 _mesa_DeleteHashTable(ss->Programs);
526 #if FEATURE_ARB_vertex_program
527 _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
528 #endif
529 #if FEATURE_ARB_fragment_program
530 _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
531 #endif
532 #if FEATURE_ATI_fragment_shader
533 if (ss->DefaultFragmentShader)
534 _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
535 #endif
536 #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
537 if (ss->BufferObjects)
538 _mesa_DeleteHashTable(ss->BufferObjects);
539 #endif
540
541 if (ss->ArrayObjects)
542 _mesa_DeleteHashTable (ss->ArrayObjects);
543
544 #if FEATURE_ARB_shader_objects
545 if (ss->ShaderObjects)
546 _mesa_DeleteHashTable (ss->ShaderObjects);
547 #endif
548
549 #if FEATURE_EXT_framebuffer_object
550 if (ss->FrameBuffers)
551 _mesa_DeleteHashTable(ss->FrameBuffers);
552 if (ss->RenderBuffers)
553 _mesa_DeleteHashTable(ss->RenderBuffers);
554 #endif
555
556 if (ss->Default1D)
557 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
558 if (ss->Default2D)
559 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
560 if (ss->Default3D)
561 (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
562 if (ss->DefaultCubeMap)
563 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
564 if (ss->DefaultRect)
565 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
566 if (ss->Default1DArray)
567 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1DArray);
568 if (ss->Default2DArray)
569 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2DArray);
570
571 _mesa_free(ss);
572
573 return GL_FALSE;
574 }
575
576
577 /**
578 * Callback for deleting a display list. Called by _mesa_HashDeleteAll().
579 */
580 static void
581 delete_displaylist_cb(GLuint id, void *data, void *userData)
582 {
583 #if FEATURE_dlist
584 struct mesa_display_list *list = (struct mesa_display_list *) data;
585 GLcontext *ctx = (GLcontext *) userData;
586 _mesa_delete_list(ctx, list);
587 #endif
588 }
589
590 /**
591 * Callback for deleting a texture object. Called by _mesa_HashDeleteAll().
592 */
593 static void
594 delete_texture_cb(GLuint id, void *data, void *userData)
595 {
596 struct gl_texture_object *texObj = (struct gl_texture_object *) data;
597 GLcontext *ctx = (GLcontext *) userData;
598 ctx->Driver.DeleteTexture(ctx, texObj);
599 }
600
601 /**
602 * Callback for deleting a program object. Called by _mesa_HashDeleteAll().
603 */
604 static void
605 delete_program_cb(GLuint id, void *data, void *userData)
606 {
607 struct gl_program *prog = (struct gl_program *) data;
608 GLcontext *ctx = (GLcontext *) userData;
609 ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */
610 prog->RefCount = 0; /* now going away */
611 ctx->Driver.DeleteProgram(ctx, prog);
612 }
613
614 #if FEATURE_ATI_fragment_shader
615 /**
616 * Callback for deleting an ATI fragment shader object.
617 * Called by _mesa_HashDeleteAll().
618 */
619 static void
620 delete_fragshader_cb(GLuint id, void *data, void *userData)
621 {
622 struct ati_fragment_shader *shader = (struct ati_fragment_shader *) data;
623 GLcontext *ctx = (GLcontext *) userData;
624 _mesa_delete_ati_fragment_shader(ctx, shader);
625 }
626 #endif
627
628 /**
629 * Callback for deleting a buffer object. Called by _mesa_HashDeleteAll().
630 */
631 static void
632 delete_bufferobj_cb(GLuint id, void *data, void *userData)
633 {
634 struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data;
635 GLcontext *ctx = (GLcontext *) userData;
636 ctx->Driver.DeleteBuffer(ctx, bufObj);
637 }
638
639 /**
640 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
641 */
642 static void
643 delete_arrayobj_cb(GLuint id, void *data, void *userData)
644 {
645 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
646 GLcontext *ctx = (GLcontext *) userData;
647 _mesa_delete_array_object(ctx, arrayObj);
648 }
649
650 /**
651 * Callback for freeing shader program data. Call it before delete_shader_cb
652 * to avoid memory access error.
653 */
654 static void
655 free_shader_program_data_cb(GLuint id, void *data, void *userData)
656 {
657 GLcontext *ctx = (GLcontext *) userData;
658 struct gl_shader_program *shProg = (struct gl_shader_program *) data;
659
660 if (shProg->Type == GL_SHADER_PROGRAM_MESA) {
661 _mesa_free_shader_program_data(ctx, shProg);
662 }
663 }
664
665 /**
666 * Callback for deleting shader and shader programs objects.
667 * Called by _mesa_HashDeleteAll().
668 */
669 static void
670 delete_shader_cb(GLuint id, void *data, void *userData)
671 {
672 GLcontext *ctx = (GLcontext *) userData;
673 struct gl_shader *sh = (struct gl_shader *) data;
674 if (sh->Type == GL_FRAGMENT_SHADER || sh->Type == GL_VERTEX_SHADER) {
675 _mesa_free_shader(ctx, sh);
676 }
677 else {
678 struct gl_shader_program *shProg = (struct gl_shader_program *) data;
679 ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA);
680 _mesa_free_shader_program(ctx, shProg);
681 }
682 }
683
684 /**
685 * Callback for deleting a framebuffer object. Called by _mesa_HashDeleteAll()
686 */
687 static void
688 delete_framebuffer_cb(GLuint id, void *data, void *userData)
689 {
690 struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
691 /* The fact that the framebuffer is in the hashtable means its refcount
692 * is one, but we're removing from the hashtable now. So clear refcount.
693 */
694 /*assert(fb->RefCount == 1);*/
695 fb->RefCount = 0;
696
697 /* NOTE: Delete should always be defined but there are two reports
698 * of it being NULL (bugs 13507, 14293). Work-around for now.
699 */
700 if (fb->Delete)
701 fb->Delete(fb);
702 }
703
704 /**
705 * Callback for deleting a renderbuffer object. Called by _mesa_HashDeleteAll()
706 */
707 static void
708 delete_renderbuffer_cb(GLuint id, void *data, void *userData)
709 {
710 struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data;
711 rb->RefCount = 0; /* see comment for FBOs above */
712 if (rb->Delete)
713 rb->Delete(rb);
714 }
715
716
717 /**
718 * Deallocate a shared state object and all children structures.
719 *
720 * \param ctx GL context.
721 * \param ss shared state pointer.
722 *
723 * Frees the display lists, the texture objects (calling the driver texture
724 * deletion callback to free its private data) and the vertex programs, as well
725 * as their hash tables.
726 *
727 * \sa alloc_shared_state().
728 */
729 static void
730 free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
731 {
732 /*
733 * Free display lists
734 */
735 _mesa_HashDeleteAll(ss->DisplayList, delete_displaylist_cb, ctx);
736 _mesa_DeleteHashTable(ss->DisplayList);
737
738 #if FEATURE_ARB_shader_objects
739 _mesa_HashWalk(ss->ShaderObjects, free_shader_program_data_cb, ctx);
740 _mesa_HashDeleteAll(ss->ShaderObjects, delete_shader_cb, ctx);
741 _mesa_DeleteHashTable(ss->ShaderObjects);
742 #endif
743
744 _mesa_HashDeleteAll(ss->Programs, delete_program_cb, ctx);
745 _mesa_DeleteHashTable(ss->Programs);
746
747 #if FEATURE_ARB_vertex_program
748 _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
749 #endif
750 #if FEATURE_ARB_fragment_program
751 _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
752 #endif
753
754 #if FEATURE_ATI_fragment_shader
755 _mesa_HashDeleteAll(ss->ATIShaders, delete_fragshader_cb, ctx);
756 _mesa_DeleteHashTable(ss->ATIShaders);
757 _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
758 #endif
759
760 #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
761 _mesa_HashDeleteAll(ss->BufferObjects, delete_bufferobj_cb, ctx);
762 _mesa_DeleteHashTable(ss->BufferObjects);
763 #endif
764
765 _mesa_HashDeleteAll(ss->ArrayObjects, delete_arrayobj_cb, ctx);
766 _mesa_DeleteHashTable(ss->ArrayObjects);
767
768 #if FEATURE_EXT_framebuffer_object
769 _mesa_HashDeleteAll(ss->FrameBuffers, delete_framebuffer_cb, ctx);
770 _mesa_DeleteHashTable(ss->FrameBuffers);
771 _mesa_HashDeleteAll(ss->RenderBuffers, delete_renderbuffer_cb, ctx);
772 _mesa_DeleteHashTable(ss->RenderBuffers);
773 #endif
774
775 /*
776 * Free texture objects (after FBOs since some textures might have
777 * been bound to FBOs).
778 */
779 ASSERT(ctx->Driver.DeleteTexture);
780 /* the default textures */
781 ctx->Driver.DeleteTexture(ctx, ss->Default1D);
782 ctx->Driver.DeleteTexture(ctx, ss->Default2D);
783 ctx->Driver.DeleteTexture(ctx, ss->Default3D);
784 ctx->Driver.DeleteTexture(ctx, ss->DefaultCubeMap);
785 ctx->Driver.DeleteTexture(ctx, ss->DefaultRect);
786 ctx->Driver.DeleteTexture(ctx, ss->Default1DArray);
787 ctx->Driver.DeleteTexture(ctx, ss->Default2DArray);
788 /* all other textures */
789 _mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx);
790 _mesa_DeleteHashTable(ss->TexObjects);
791
792 _glthread_DESTROY_MUTEX(ss->Mutex);
793
794 _mesa_free(ss);
795 }
796
797
798 /**
799 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
800 */
801 static void
802 _mesa_init_current(GLcontext *ctx)
803 {
804 GLuint i;
805
806 /* Init all to (0,0,0,1) */
807 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
808 ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
809 }
810
811 /* redo special cases: */
812 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
813 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
814 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
815 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
816 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
817 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
818 }
819
820
821 /**
822 * Init vertex/fragment program native limits from logical limits.
823 */
824 static void
825 init_natives(struct gl_program_constants *prog)
826 {
827 prog->MaxNativeInstructions = prog->MaxInstructions;
828 prog->MaxNativeAluInstructions = prog->MaxAluInstructions;
829 prog->MaxNativeTexInstructions = prog->MaxTexInstructions;
830 prog->MaxNativeTexIndirections = prog->MaxTexIndirections;
831 prog->MaxNativeAttribs = prog->MaxAttribs;
832 prog->MaxNativeTemps = prog->MaxTemps;
833 prog->MaxNativeAddressRegs = prog->MaxAddressRegs;
834 prog->MaxNativeParameters = prog->MaxParameters;
835 }
836
837
838 /**
839 * Initialize fields of gl_constants (aka ctx->Const.*).
840 * Use defaults from config.h. The device drivers will often override
841 * some of these values (such as number of texture units).
842 */
843 static void
844 _mesa_init_constants(GLcontext *ctx)
845 {
846 assert(ctx);
847
848 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
849 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
850
851 assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_COORD_UNITS);
852 assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_IMAGE_UNITS);
853
854 /* Constants, may be overriden (usually only reduced) by device drivers */
855 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
856 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
857 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
858 ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
859 ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
860 ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
861 ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
862 ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
863 ctx->Const.MaxTextureImageUnits);
864 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
865 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
866 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
867 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
868 ctx->Const.MinPointSize = MIN_POINT_SIZE;
869 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
870 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
871 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
872 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
873 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
874 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
875 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
876 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
877 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
878 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
879 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
880 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
881 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
882 ctx->Const.MaxLights = MAX_LIGHTS;
883 ctx->Const.MaxShininess = 128.0;
884 ctx->Const.MaxSpotExponent = 128.0;
885 ctx->Const.MaxViewportWidth = MAX_WIDTH;
886 ctx->Const.MaxViewportHeight = MAX_HEIGHT;
887 #if FEATURE_ARB_vertex_program
888 ctx->Const.VertexProgram.MaxInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS;
889 ctx->Const.VertexProgram.MaxAluInstructions = 0;
890 ctx->Const.VertexProgram.MaxTexInstructions = 0;
891 ctx->Const.VertexProgram.MaxTexIndirections = 0;
892 ctx->Const.VertexProgram.MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
893 ctx->Const.VertexProgram.MaxTemps = MAX_PROGRAM_TEMPS;
894 ctx->Const.VertexProgram.MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
895 ctx->Const.VertexProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
896 ctx->Const.VertexProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
897 ctx->Const.VertexProgram.MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
898 ctx->Const.VertexProgram.MaxUniformComponents = 4 * MAX_UNIFORMS;
899 init_natives(&ctx->Const.VertexProgram);
900 #endif
901
902 #if FEATURE_ARB_fragment_program
903 ctx->Const.FragmentProgram.MaxInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS;
904 ctx->Const.FragmentProgram.MaxAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS;
905 ctx->Const.FragmentProgram.MaxTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS;
906 ctx->Const.FragmentProgram.MaxTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS;
907 ctx->Const.FragmentProgram.MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
908 ctx->Const.FragmentProgram.MaxTemps = MAX_PROGRAM_TEMPS;
909 ctx->Const.FragmentProgram.MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
910 ctx->Const.FragmentProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
911 ctx->Const.FragmentProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
912 ctx->Const.FragmentProgram.MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
913 ctx->Const.FragmentProgram.MaxUniformComponents = 4 * MAX_UNIFORMS;
914 init_natives(&ctx->Const.FragmentProgram);
915 #endif
916 ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
917 ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
918
919 /* CheckArrayBounds is overriden by drivers/x11 for X server */
920 ctx->Const.CheckArrayBounds = GL_FALSE;
921
922 /* GL_ARB_draw_buffers */
923 ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
924
925 /* GL_OES_read_format */
926 ctx->Const.ColorReadFormat = GL_RGBA;
927 ctx->Const.ColorReadType = GL_UNSIGNED_BYTE;
928
929 #if FEATURE_EXT_framebuffer_object
930 ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
931 ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
932 #endif
933
934 #if FEATURE_ARB_vertex_shader
935 ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
936 ctx->Const.MaxVarying = MAX_VARYING;
937 #endif
938
939 /* sanity checks */
940 ASSERT(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
941 ctx->Const.MaxTextureCoordUnits));
942 ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
943 ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
944
945 ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
946 ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
947 ASSERT(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
948 ASSERT(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
949 }
950
951
952 /**
953 * Do some sanity checks on the limits/constants for the given context.
954 * Only called the first time a context is bound.
955 */
956 static void
957 check_context_limits(GLcontext *ctx)
958 {
959 /* Many context limits/constants are limited by the size of
960 * internal arrays.
961 */
962 assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
963 assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
964 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
965 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
966
967 assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
968 assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
969
970 /* make sure largest texture image is <= MAX_WIDTH in size */
971 assert((1 << (ctx->Const.MaxTextureLevels -1 )) <= MAX_WIDTH);
972 assert((1 << (ctx->Const.MaxCubeTextureLevels -1 )) <= MAX_WIDTH);
973 assert((1 << (ctx->Const.Max3DTextureLevels -1 )) <= MAX_WIDTH);
974
975 assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
976
977 /* XXX probably add more tests */
978 }
979
980
981 /**
982 * Initialize the attribute groups in a GL context.
983 *
984 * \param ctx GL context.
985 *
986 * Initializes all the attributes, calling the respective <tt>init*</tt>
987 * functions for the more complex data structures.
988 */
989 static GLboolean
990 init_attrib_groups(GLcontext *ctx)
991 {
992 assert(ctx);
993
994 /* Constants */
995 _mesa_init_constants( ctx );
996
997 /* Extensions */
998 _mesa_init_extensions( ctx );
999
1000 /* Attribute Groups */
1001 #if FEATURE_accum
1002 _mesa_init_accum( ctx );
1003 #endif
1004 #if FEATURE_attrib_stack
1005 _mesa_init_attrib( ctx );
1006 #endif
1007 _mesa_init_buffer_objects( ctx );
1008 _mesa_init_color( ctx );
1009 #if FEATURE_colortable
1010 _mesa_init_colortables( ctx );
1011 #endif
1012 _mesa_init_current( ctx );
1013 _mesa_init_depth( ctx );
1014 _mesa_init_debug( ctx );
1015 #if FEATURE_dlist
1016 _mesa_init_display_list( ctx );
1017 #endif
1018 #if FEATURE_evaluators
1019 _mesa_init_eval( ctx );
1020 #endif
1021 _mesa_init_fbobjects( ctx );
1022 #if FEATURE_feedback
1023 _mesa_init_feedback( ctx );
1024 #else
1025 ctx->RenderMode = GL_RENDER;
1026 #endif
1027 _mesa_init_fog( ctx );
1028 #if FEATURE_histogram
1029 _mesa_init_histogram( ctx );
1030 #endif
1031 _mesa_init_hint( ctx );
1032 _mesa_init_line( ctx );
1033 _mesa_init_lighting( ctx );
1034 _mesa_init_matrix( ctx );
1035 _mesa_init_multisample( ctx );
1036 _mesa_init_pixel( ctx );
1037 _mesa_init_pixelstore( ctx );
1038 _mesa_init_point( ctx );
1039 _mesa_init_polygon( ctx );
1040 _mesa_init_program( ctx );
1041 #if FEATURE_ARB_occlusion_query
1042 _mesa_init_query( ctx );
1043 #endif
1044 #if FEATURE_drawpix
1045 _mesa_init_rastpos( ctx );
1046 #endif
1047 _mesa_init_scissor( ctx );
1048 _mesa_init_shader_state( ctx );
1049 _mesa_init_stencil( ctx );
1050 _mesa_init_transform( ctx );
1051 _mesa_init_varray( ctx );
1052 _mesa_init_viewport( ctx );
1053
1054 if (!_mesa_init_texture( ctx ))
1055 return GL_FALSE;
1056
1057 #if FEATURE_texture_s3tc
1058 _mesa_init_texture_s3tc( ctx );
1059 #endif
1060 #if FEATURE_texture_fxt1
1061 _mesa_init_texture_fxt1( ctx );
1062 #endif
1063
1064 /* Miscellaneous */
1065 ctx->NewState = _NEW_ALL;
1066 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1067
1068 return GL_TRUE;
1069 }
1070
1071
1072 /**
1073 * Update default objects in a GL context with respect to shared state.
1074 *
1075 * \param ctx GL context.
1076 *
1077 * Removes references to old default objects, (texture objects, program
1078 * objects, etc.) and changes to reference those from the current shared
1079 * state.
1080 */
1081 static GLboolean
1082 update_default_objects(GLcontext *ctx)
1083 {
1084 assert(ctx);
1085
1086 _mesa_update_default_objects_program(ctx);
1087 _mesa_update_default_objects_texture(ctx);
1088 _mesa_update_default_objects_buffer_objects(ctx);
1089
1090 return GL_TRUE;
1091 }
1092
1093
1094 /**
1095 * This is the default function we plug into all dispatch table slots
1096 * This helps prevents a segfault when someone calls a GL function without
1097 * first checking if the extension's supported.
1098 */
1099 static int
1100 generic_nop(void)
1101 {
1102 _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
1103 return 0;
1104 }
1105
1106
1107 /**
1108 * Allocate and initialize a new dispatch table.
1109 */
1110 static struct _glapi_table *
1111 alloc_dispatch_table(void)
1112 {
1113 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1114 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1115 * Mesa we do this to accomodate different versions of libGL and various
1116 * DRI drivers.
1117 */
1118 GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
1119 sizeof(struct _glapi_table) / sizeof(_glapi_proc));
1120 struct _glapi_table *table =
1121 (struct _glapi_table *) _mesa_malloc(numEntries * sizeof(_glapi_proc));
1122 if (table) {
1123 _glapi_proc *entry = (_glapi_proc *) table;
1124 GLint i;
1125 for (i = 0; i < numEntries; i++) {
1126 entry[i] = (_glapi_proc) generic_nop;
1127 }
1128 }
1129 return table;
1130 }
1131
1132
1133 /**
1134 * Initialize a GLcontext struct (rendering context).
1135 *
1136 * This includes allocating all the other structs and arrays which hang off of
1137 * the context by pointers.
1138 * Note that the driver needs to pass in its dd_function_table here since
1139 * we need to at least call driverFunctions->NewTextureObject to create the
1140 * default texture objects.
1141 *
1142 * Called by _mesa_create_context().
1143 *
1144 * Performs the imports and exports callback tables initialization, and
1145 * miscellaneous one-time initializations. If no shared context is supplied one
1146 * is allocated, and increase its reference count. Setups the GL API dispatch
1147 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
1148 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1149 * for debug flags.
1150 *
1151 * \param ctx the context to initialize
1152 * \param visual describes the visual attributes for this context
1153 * \param share_list points to context to share textures, display lists,
1154 * etc with, or NULL
1155 * \param driverFunctions table of device driver functions for this context
1156 * to use
1157 * \param driverContext pointer to driver-specific context data
1158 */
1159 GLboolean
1160 _mesa_initialize_context(GLcontext *ctx,
1161 const GLvisual *visual,
1162 GLcontext *share_list,
1163 const struct dd_function_table *driverFunctions,
1164 void *driverContext)
1165 {
1166 /*ASSERT(driverContext);*/
1167 assert(driverFunctions->NewTextureObject);
1168 assert(driverFunctions->FreeTexImageData);
1169
1170 /* misc one-time initializations */
1171 one_time_init(ctx);
1172
1173 ctx->Visual = *visual;
1174 ctx->DrawBuffer = NULL;
1175 ctx->ReadBuffer = NULL;
1176 ctx->WinSysDrawBuffer = NULL;
1177 ctx->WinSysReadBuffer = NULL;
1178
1179 /* Plug in driver functions and context pointer here.
1180 * This is important because when we call alloc_shared_state() below
1181 * we'll call ctx->Driver.NewTextureObject() to create the default
1182 * textures.
1183 */
1184 ctx->Driver = *driverFunctions;
1185 ctx->DriverCtx = driverContext;
1186
1187 if (share_list) {
1188 /* share state with another context */
1189 ctx->Shared = share_list->Shared;
1190 }
1191 else {
1192 /* allocate new, unshared state */
1193 if (!alloc_shared_state( ctx )) {
1194 return GL_FALSE;
1195 }
1196 }
1197 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1198 ctx->Shared->RefCount++;
1199 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1200
1201 if (!init_attrib_groups( ctx )) {
1202 free_shared_state(ctx, ctx->Shared);
1203 return GL_FALSE;
1204 }
1205
1206 /* setup the API dispatch tables */
1207 ctx->Exec = alloc_dispatch_table();
1208 ctx->Save = alloc_dispatch_table();
1209 if (!ctx->Exec || !ctx->Save) {
1210 free_shared_state(ctx, ctx->Shared);
1211 if (ctx->Exec)
1212 _mesa_free(ctx->Exec);
1213 }
1214 #if FEATURE_dispatch
1215 _mesa_init_exec_table(ctx->Exec);
1216 #endif
1217 ctx->CurrentDispatch = ctx->Exec;
1218 #if FEATURE_dlist
1219 _mesa_init_dlist_table(ctx->Save);
1220 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
1221 #endif
1222 /* Neutral tnl module stuff */
1223 _mesa_init_exec_vtxfmt( ctx );
1224 ctx->TnlModule.Current = NULL;
1225 ctx->TnlModule.SwapCount = 0;
1226
1227 ctx->FragmentProgram._MaintainTexEnvProgram
1228 = (_mesa_getenv("MESA_TEX_PROG") != NULL);
1229 ctx->FragmentProgram._UseTexEnvProgram = ctx->FragmentProgram._MaintainTexEnvProgram;
1230
1231 ctx->VertexProgram._MaintainTnlProgram
1232 = (_mesa_getenv("MESA_TNL_PROG") != NULL);
1233 if (ctx->VertexProgram._MaintainTnlProgram) {
1234 /* this is required... */
1235 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
1236 }
1237
1238 #ifdef FEATURE_extra_context_init
1239 _mesa_initialize_context_extra(ctx);
1240 #endif
1241
1242 ctx->FirstTimeCurrent = GL_TRUE;
1243
1244 return GL_TRUE;
1245 }
1246
1247
1248 /**
1249 * Allocate and initialize a GLcontext structure.
1250 * Note that the driver needs to pass in its dd_function_table here since
1251 * we need to at least call driverFunctions->NewTextureObject to initialize
1252 * the rendering context.
1253 *
1254 * \param visual a GLvisual pointer (we copy the struct contents)
1255 * \param share_list another context to share display lists with or NULL
1256 * \param driverFunctions points to the dd_function_table into which the
1257 * driver has plugged in all its special functions.
1258 * \param driverCtx points to the device driver's private context state
1259 *
1260 * \return pointer to a new __GLcontextRec or NULL if error.
1261 */
1262 GLcontext *
1263 _mesa_create_context(const GLvisual *visual,
1264 GLcontext *share_list,
1265 const struct dd_function_table *driverFunctions,
1266 void *driverContext)
1267 {
1268 GLcontext *ctx;
1269
1270 ASSERT(visual);
1271 /*ASSERT(driverContext);*/
1272
1273 ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
1274 if (!ctx)
1275 return NULL;
1276
1277 if (_mesa_initialize_context(ctx, visual, share_list,
1278 driverFunctions, driverContext)) {
1279 return ctx;
1280 }
1281 else {
1282 _mesa_free(ctx);
1283 return NULL;
1284 }
1285 }
1286
1287
1288 /**
1289 * Free the data associated with the given context.
1290 *
1291 * But doesn't free the GLcontext struct itself.
1292 *
1293 * \sa _mesa_initialize_context() and init_attrib_groups().
1294 */
1295 void
1296 _mesa_free_context_data( GLcontext *ctx )
1297 {
1298 if (!_mesa_get_current_context()){
1299 /* No current context, but we may need one in order to delete
1300 * texture objs, etc. So temporarily bind the context now.
1301 */
1302 _mesa_make_current(ctx, NULL, NULL);
1303 }
1304
1305 /* unreference WinSysDraw/Read buffers */
1306 _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer);
1307 _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer);
1308 _mesa_unreference_framebuffer(&ctx->DrawBuffer);
1309 _mesa_unreference_framebuffer(&ctx->ReadBuffer);
1310
1311 _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
1312 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
1313 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
1314
1315 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
1316 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
1317 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
1318
1319 _mesa_free_attrib_data(ctx);
1320 _mesa_free_lighting_data( ctx );
1321 #if FEATURE_evaluators
1322 _mesa_free_eval_data( ctx );
1323 #endif
1324 _mesa_free_texture_data( ctx );
1325 _mesa_free_matrix_data( ctx );
1326 _mesa_free_viewport_data( ctx );
1327 #if FEATURE_colortable
1328 _mesa_free_colortables_data( ctx );
1329 #endif
1330 _mesa_free_program_data(ctx);
1331 _mesa_free_shader_state(ctx);
1332 #if FEATURE_ARB_occlusion_query
1333 _mesa_free_query_data(ctx);
1334 #endif
1335
1336 #if FEATURE_ARB_vertex_buffer_object
1337 _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj);
1338 #endif
1339 _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
1340
1341 /* free dispatch tables */
1342 _mesa_free(ctx->Exec);
1343 _mesa_free(ctx->Save);
1344
1345 /* Shared context state (display lists, textures, etc) */
1346 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1347 ctx->Shared->RefCount--;
1348 assert(ctx->Shared->RefCount >= 0);
1349 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1350 if (ctx->Shared->RefCount == 0) {
1351 /* free shared state */
1352 free_shared_state( ctx, ctx->Shared );
1353 }
1354
1355 if (ctx->Extensions.String)
1356 _mesa_free((void *) ctx->Extensions.String);
1357
1358 /* unbind the context if it's currently bound */
1359 if (ctx == _mesa_get_current_context()) {
1360 _mesa_make_current(NULL, NULL, NULL);
1361 }
1362 }
1363
1364
1365 /**
1366 * Destroy a GLcontext structure.
1367 *
1368 * \param ctx GL context.
1369 *
1370 * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
1371 */
1372 void
1373 _mesa_destroy_context( GLcontext *ctx )
1374 {
1375 if (ctx) {
1376 _mesa_free_context_data(ctx);
1377 _mesa_free( (void *) ctx );
1378 }
1379 }
1380
1381
1382 #if _HAVE_FULL_GL
1383 /**
1384 * Copy attribute groups from one context to another.
1385 *
1386 * \param src source context
1387 * \param dst destination context
1388 * \param mask bitwise OR of GL_*_BIT flags
1389 *
1390 * According to the bits specified in \p mask, copies the corresponding
1391 * attributes from \p src into \p dst. For many of the attributes a simple \c
1392 * memcpy is not enough due to the existence of internal pointers in their data
1393 * structures.
1394 */
1395 void
1396 _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
1397 {
1398 if (mask & GL_ACCUM_BUFFER_BIT) {
1399 /* OK to memcpy */
1400 dst->Accum = src->Accum;
1401 }
1402 if (mask & GL_COLOR_BUFFER_BIT) {
1403 /* OK to memcpy */
1404 dst->Color = src->Color;
1405 }
1406 if (mask & GL_CURRENT_BIT) {
1407 /* OK to memcpy */
1408 dst->Current = src->Current;
1409 }
1410 if (mask & GL_DEPTH_BUFFER_BIT) {
1411 /* OK to memcpy */
1412 dst->Depth = src->Depth;
1413 }
1414 if (mask & GL_ENABLE_BIT) {
1415 /* no op */
1416 }
1417 if (mask & GL_EVAL_BIT) {
1418 /* OK to memcpy */
1419 dst->Eval = src->Eval;
1420 }
1421 if (mask & GL_FOG_BIT) {
1422 /* OK to memcpy */
1423 dst->Fog = src->Fog;
1424 }
1425 if (mask & GL_HINT_BIT) {
1426 /* OK to memcpy */
1427 dst->Hint = src->Hint;
1428 }
1429 if (mask & GL_LIGHTING_BIT) {
1430 GLuint i;
1431 /* begin with memcpy */
1432 dst->Light = src->Light;
1433 /* fixup linked lists to prevent pointer insanity */
1434 make_empty_list( &(dst->Light.EnabledList) );
1435 for (i = 0; i < MAX_LIGHTS; i++) {
1436 if (dst->Light.Light[i].Enabled) {
1437 insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
1438 }
1439 }
1440 }
1441 if (mask & GL_LINE_BIT) {
1442 /* OK to memcpy */
1443 dst->Line = src->Line;
1444 }
1445 if (mask & GL_LIST_BIT) {
1446 /* OK to memcpy */
1447 dst->List = src->List;
1448 }
1449 if (mask & GL_PIXEL_MODE_BIT) {
1450 /* OK to memcpy */
1451 dst->Pixel = src->Pixel;
1452 }
1453 if (mask & GL_POINT_BIT) {
1454 /* OK to memcpy */
1455 dst->Point = src->Point;
1456 }
1457 if (mask & GL_POLYGON_BIT) {
1458 /* OK to memcpy */
1459 dst->Polygon = src->Polygon;
1460 }
1461 if (mask & GL_POLYGON_STIPPLE_BIT) {
1462 /* Use loop instead of MEMCPY due to problem with Portland Group's
1463 * C compiler. Reported by John Stone.
1464 */
1465 GLuint i;
1466 for (i = 0; i < 32; i++) {
1467 dst->PolygonStipple[i] = src->PolygonStipple[i];
1468 }
1469 }
1470 if (mask & GL_SCISSOR_BIT) {
1471 /* OK to memcpy */
1472 dst->Scissor = src->Scissor;
1473 }
1474 if (mask & GL_STENCIL_BUFFER_BIT) {
1475 /* OK to memcpy */
1476 dst->Stencil = src->Stencil;
1477 }
1478 if (mask & GL_TEXTURE_BIT) {
1479 /* Cannot memcpy because of pointers */
1480 _mesa_copy_texture_state(src, dst);
1481 }
1482 if (mask & GL_TRANSFORM_BIT) {
1483 /* OK to memcpy */
1484 dst->Transform = src->Transform;
1485 }
1486 if (mask & GL_VIEWPORT_BIT) {
1487 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1488 dst->Viewport.X = src->Viewport.X;
1489 dst->Viewport.Y = src->Viewport.Y;
1490 dst->Viewport.Width = src->Viewport.Width;
1491 dst->Viewport.Height = src->Viewport.Height;
1492 dst->Viewport.Near = src->Viewport.Near;
1493 dst->Viewport.Far = src->Viewport.Far;
1494 _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
1495 }
1496
1497 /* XXX FIXME: Call callbacks?
1498 */
1499 dst->NewState = _NEW_ALL;
1500 }
1501 #endif
1502
1503
1504 /**
1505 * Check if the given context can render into the given framebuffer
1506 * by checking visual attributes.
1507 *
1508 * Most of these tests could go away because Mesa is now pretty flexible
1509 * in terms of mixing rendering contexts with framebuffers. As long
1510 * as RGB vs. CI mode agree, we're probably good.
1511 *
1512 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1513 */
1514 static GLboolean
1515 check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
1516 {
1517 const GLvisual *ctxvis = &ctx->Visual;
1518 const GLvisual *bufvis = &buffer->Visual;
1519
1520 if (ctxvis == bufvis)
1521 return GL_TRUE;
1522
1523 if (ctxvis->rgbMode != bufvis->rgbMode)
1524 return GL_FALSE;
1525 #if 0
1526 /* disabling this fixes the fgl_glxgears pbuffer demo */
1527 if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
1528 return GL_FALSE;
1529 #endif
1530 if (ctxvis->stereoMode && !bufvis->stereoMode)
1531 return GL_FALSE;
1532 if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
1533 return GL_FALSE;
1534 if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
1535 return GL_FALSE;
1536 if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
1537 return GL_FALSE;
1538 if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
1539 return GL_FALSE;
1540 if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
1541 return GL_FALSE;
1542 if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
1543 return GL_FALSE;
1544 #if 0
1545 /* disabled (see bug 11161) */
1546 if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
1547 return GL_FALSE;
1548 #endif
1549 if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
1550 return GL_FALSE;
1551
1552 return GL_TRUE;
1553 }
1554
1555
1556 /**
1557 * Do one-time initialization for the given framebuffer. Specifically,
1558 * ask the driver for the window's current size and update the framebuffer
1559 * object to match.
1560 * Really, the device driver should totally take care of this.
1561 */
1562 static void
1563 initialize_framebuffer_size(GLcontext *ctx, GLframebuffer *fb)
1564 {
1565 GLuint width, height;
1566 if (ctx->Driver.GetBufferSize) {
1567 ctx->Driver.GetBufferSize(fb, &width, &height);
1568 if (ctx->Driver.ResizeBuffers)
1569 ctx->Driver.ResizeBuffers(ctx, fb, width, height);
1570 fb->Initialized = GL_TRUE;
1571 }
1572 }
1573
1574
1575 /**
1576 * Bind the given context to the given drawBuffer and readBuffer and
1577 * make it the current context for the calling thread.
1578 * We'll render into the drawBuffer and read pixels from the
1579 * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
1580 *
1581 * We check that the context's and framebuffer's visuals are compatible
1582 * and return immediately if they're not.
1583 *
1584 * \param newCtx the new GL context. If NULL then there will be no current GL
1585 * context.
1586 * \param drawBuffer the drawing framebuffer
1587 * \param readBuffer the reading framebuffer
1588 */
1589 void
1590 _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
1591 GLframebuffer *readBuffer )
1592 {
1593 if (MESA_VERBOSE & VERBOSE_API)
1594 _mesa_debug(newCtx, "_mesa_make_current()\n");
1595
1596 /* Check that the context's and framebuffer's visuals are compatible.
1597 */
1598 if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
1599 if (!check_compatible(newCtx, drawBuffer)) {
1600 _mesa_warning(newCtx,
1601 "MakeCurrent: incompatible visuals for context and drawbuffer");
1602 return;
1603 }
1604 }
1605 if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
1606 if (!check_compatible(newCtx, readBuffer)) {
1607 _mesa_warning(newCtx,
1608 "MakeCurrent: incompatible visuals for context and readbuffer");
1609 return;
1610 }
1611 }
1612
1613 /* We used to call _glapi_check_multithread() here. Now do it in drivers */
1614 _glapi_set_context((void *) newCtx);
1615 ASSERT(_mesa_get_current_context() == newCtx);
1616
1617 if (!newCtx) {
1618 _glapi_set_dispatch(NULL); /* none current */
1619 }
1620 else {
1621 _glapi_set_dispatch(newCtx->CurrentDispatch);
1622
1623 if (drawBuffer && readBuffer) {
1624 /* TODO: check if newCtx and buffer's visual match??? */
1625
1626 ASSERT(drawBuffer->Name == 0);
1627 ASSERT(readBuffer->Name == 0);
1628 _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
1629 _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
1630
1631 /*
1632 * Only set the context's Draw/ReadBuffer fields if they're NULL
1633 * or not bound to a user-created FBO.
1634 */
1635 if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
1636 /* KW: merge conflict here, revisit.
1637 */
1638 /* fix up the fb fields - these will end up wrong otherwise
1639 * if the DRIdrawable changes, and everything relies on them.
1640 * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
1641 */
1642 unsigned int i;
1643 GLenum buffers[MAX_DRAW_BUFFERS];
1644
1645 _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
1646
1647 for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) {
1648 buffers[i] = newCtx->Color.DrawBuffer[i];
1649 }
1650
1651 _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers, buffers, NULL);
1652 }
1653 if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
1654 _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
1655 }
1656
1657 /* XXX only set this flag if we're really changing the draw/read
1658 * framebuffer bindings.
1659 */
1660 newCtx->NewState |= _NEW_BUFFERS;
1661
1662 #if 1
1663 /* We want to get rid of these lines: */
1664
1665 #if _HAVE_FULL_GL
1666 if (!drawBuffer->Initialized) {
1667 initialize_framebuffer_size(newCtx, drawBuffer);
1668 }
1669 if (readBuffer != drawBuffer && !readBuffer->Initialized) {
1670 initialize_framebuffer_size(newCtx, readBuffer);
1671 }
1672
1673 _mesa_resizebuffers(newCtx);
1674 #endif
1675
1676 #else
1677 /* We want the drawBuffer and readBuffer to be initialized by
1678 * the driver.
1679 * This generally means the Width and Height match the actual
1680 * window size and the renderbuffers (both hardware and software
1681 * based) are allocated to match. The later can generally be
1682 * done with a call to _mesa_resize_framebuffer().
1683 *
1684 * It's theoretically possible for a buffer to have zero width
1685 * or height, but for now, assert check that the driver did what's
1686 * expected of it.
1687 */
1688 ASSERT(drawBuffer->Width > 0);
1689 ASSERT(drawBuffer->Height > 0);
1690 #endif
1691
1692 if (newCtx->FirstTimeCurrent) {
1693 /* set initial viewport and scissor size now */
1694 _mesa_set_viewport(newCtx, 0, 0,
1695 drawBuffer->Width, drawBuffer->Height);
1696 _mesa_set_scissor(newCtx, 0, 0,
1697 drawBuffer->Width, drawBuffer->Height );
1698 check_context_limits(newCtx);
1699 }
1700 }
1701
1702 /* We can use this to help debug user's problems. Tell them to set
1703 * the MESA_INFO env variable before running their app. Then the
1704 * first time each context is made current we'll print some useful
1705 * information.
1706 */
1707 if (newCtx->FirstTimeCurrent) {
1708 if (_mesa_getenv("MESA_INFO")) {
1709 _mesa_print_info();
1710 }
1711 newCtx->FirstTimeCurrent = GL_FALSE;
1712 }
1713 }
1714 }
1715
1716
1717 /**
1718 * Make context 'ctx' share the display lists, textures and programs
1719 * that are associated with 'ctxToShare'.
1720 * Any display lists, textures or programs associated with 'ctx' will
1721 * be deleted if nobody else is sharing them.
1722 */
1723 GLboolean
1724 _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
1725 {
1726 if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
1727 struct gl_shared_state *oldSharedState = ctx->Shared;
1728
1729 ctx->Shared = ctxToShare->Shared;
1730 ctx->Shared->RefCount++;
1731
1732 update_default_objects(ctx);
1733
1734 oldSharedState->RefCount--;
1735 if (oldSharedState->RefCount == 0) {
1736 free_shared_state(ctx, oldSharedState);
1737 }
1738
1739 return GL_TRUE;
1740 }
1741 else {
1742 return GL_FALSE;
1743 }
1744 }
1745
1746
1747
1748 /**
1749 * \return pointer to the current GL context for this thread.
1750 *
1751 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1752 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
1753 * context.h.
1754 */
1755 GLcontext *
1756 _mesa_get_current_context( void )
1757 {
1758 return (GLcontext *) _glapi_get_context();
1759 }
1760
1761
1762 /**
1763 * Get context's current API dispatch table.
1764 *
1765 * It'll either be the immediate-mode execute dispatcher or the display list
1766 * compile dispatcher.
1767 *
1768 * \param ctx GL context.
1769 *
1770 * \return pointer to dispatch_table.
1771 *
1772 * Simply returns __GLcontextRec::CurrentDispatch.
1773 */
1774 struct _glapi_table *
1775 _mesa_get_dispatch(GLcontext *ctx)
1776 {
1777 return ctx->CurrentDispatch;
1778 }
1779
1780 /*@}*/
1781
1782
1783 /**********************************************************************/
1784 /** \name Miscellaneous functions */
1785 /**********************************************************************/
1786 /*@{*/
1787
1788 /**
1789 * Record an error.
1790 *
1791 * \param ctx GL context.
1792 * \param error error code.
1793 *
1794 * Records the given error code and call the driver's dd_function_table::Error
1795 * function if defined.
1796 *
1797 * \sa
1798 * This is called via _mesa_error().
1799 */
1800 void
1801 _mesa_record_error(GLcontext *ctx, GLenum error)
1802 {
1803 if (!ctx)
1804 return;
1805
1806 if (ctx->ErrorValue == GL_NO_ERROR) {
1807 ctx->ErrorValue = error;
1808 }
1809
1810 /* Call device driver's error handler, if any. This is used on the Mac. */
1811 if (ctx->Driver.Error) {
1812 ctx->Driver.Error(ctx);
1813 }
1814 }
1815
1816
1817 /**
1818 * Execute glFinish().
1819 *
1820 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1821 * dd_function_table::Finish driver callback, if not NULL.
1822 */
1823 void GLAPIENTRY
1824 _mesa_Finish(void)
1825 {
1826 GET_CURRENT_CONTEXT(ctx);
1827 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1828 if (ctx->Driver.Finish) {
1829 ctx->Driver.Finish(ctx);
1830 }
1831 }
1832
1833
1834 /**
1835 * Execute glFlush().
1836 *
1837 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1838 * dd_function_table::Flush driver callback, if not NULL.
1839 */
1840 void GLAPIENTRY
1841 _mesa_Flush(void)
1842 {
1843 GET_CURRENT_CONTEXT(ctx);
1844 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1845 if (ctx->Driver.Flush) {
1846 ctx->Driver.Flush(ctx);
1847 }
1848 }
1849
1850
1851 /*@}*/