blob: e3cfd5c3f94fcb1f073d0af8c58aa65823dd429d [file] [log] [blame]
Keith Whitwell6dc85572003-07-17 13:43:59 +00001/**
2 * \file context.c
3 * Mesa context/visual/framebuffer management functions.
4 * \author Brian Paul
5 */
6
jtgafb833d1999-08-19 00:55:39 +00007/*
8 * Mesa 3-D graphics library
Brian Paul4d859f72004-01-23 18:57:05 +00009 * Version: 6.1
jtgafb833d1999-08-19 00:55:39 +000010 *
Brian Paul4d859f72004-01-23 18:57:05 +000011 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +000012 *
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
Keith Whitwell6dc85572003-07-17 13:43:59 +000032/**
33 * \mainpage Mesa Core Module
34 *
35 * \section CoreIntroduction Introduction
36 *
37 * The Mesa core module consists of all the top-level files in the src
38 * directory. The core module basically takes care of API dispatch,
39 * and OpenGL state management.
40 *
41 * For example, calls to glPolygonMode() are routed to _mesa_PolygonMode()
42 * which updates the state related to polygonmode. Furthermore, dirty
43 * state flags related to polygon mode are set and if the device driver
44 * implements a special routine for PolygonMode, it will be called.
45 *
46 *
47 * \section AboutDoxygen About Doxygen
48 *
49 * If you're viewing this information as Doxygen-generated HTML you'll
50 * see the documentation index at the top of this page.
51 *
52 * The first line lists the Mesa source code modules.
53 * The second line lists the indexes available for viewing the documentation
54 * for each module.
55 *
56 * Selecting the <b>Main page</b> link will display a summary of the module
57 * (this page).
58 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000059 * Selecting <b>Data Structures</b> will list all C structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +000060 *
61 * Selecting the <b>File List</b> link will list all the source files in
62 * the module.
63 * Selecting a filename will show a list of all functions defined in that file.
64 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000065 * Selecting the <b>Data Fields</b> link will display a list of all
Keith Whitwell6dc85572003-07-17 13:43:59 +000066 * documented structure members.
67 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000068 * Selecting the <b>Globals</b> link will display a list
Keith Whitwell6dc85572003-07-17 13:43:59 +000069 * of all functions, structures, global variables and macros in the module.
70 *
71 */
72
73
Brian Paulfbd8f211999-11-11 01:22:25 +000074#include "glheader.h"
Brian Paul3c634522002-10-24 23:57:19 +000075#include "imports.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000076#include "accum.h"
77#include "attrib.h"
78#include "blend.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000079#include "buffers.h"
Brian Paul148a2842003-09-17 03:40:11 +000080#include "bufferobj.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000081#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000082#include "context.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000083#include "debug.h"
84#include "depth.h"
jtgafb833d1999-08-19 00:55:39 +000085#include "dlist.h"
86#include "eval.h"
87#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000088#include "extensions.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000089#include "feedback.h"
jtgafb833d1999-08-19 00:55:39 +000090#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000091#include "get.h"
Brian Paul9560f052000-01-31 23:11:39 +000092#include "glthread.h"
Brian Paulf44898c2003-07-18 15:44:57 +000093#include "glapioffsets.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000094#include "histogram.h"
95#include "hint.h"
jtgafb833d1999-08-19 00:55:39 +000096#include "hash.h"
97#include "light.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000098#include "lines.h"
jtgafb833d1999-08-19 00:55:39 +000099#include "macros.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000100#include "matrix.h"
Brian Paul05944c02003-07-22 03:51:46 +0000101#include "occlude.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000102#include "pixel.h"
103#include "points.h"
104#include "polygon.h"
Brian Paul31732772003-09-18 16:39:09 +0000105#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
106#include "program.h"
107#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +0000108#include "rastpos.h"
jtgafb833d1999-08-19 00:55:39 +0000109#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +0000110#include "state.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000111#include "stencil.h"
Brian Paul8f04c122004-04-27 13:39:20 +0000112#include "texcompress.h"
jtgafb833d1999-08-19 00:55:39 +0000113#include "teximage.h"
114#include "texobj.h"
Brian Paul85d81602002-06-17 23:36:31 +0000115#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000116#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +0000117#include "varray.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +0000118#include "vtxfmt.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000119#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000120#include "math/m_translate.h"
Keith Whitwell23caf202000-11-16 21:05:34 +0000121#include "math/m_matrix.h"
122#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +0000123#include "math/mathmod.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000124#endif
jtgafb833d1999-08-19 00:55:39 +0000125
davem69775355a2001-06-05 23:54:00 +0000126#ifdef USE_SPARC_ASM
127#include "SPARC/sparc.h"
128#endif
jtgafb833d1999-08-19 00:55:39 +0000129
Keith Whitwell23caf202000-11-16 21:05:34 +0000130#ifndef MESA_VERBOSE
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000131int MESA_VERBOSE = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000132#endif
133
134#ifndef MESA_DEBUG_FLAGS
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000135int MESA_DEBUG_FLAGS = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000136#endif
Brian Paulb1394fa2000-09-26 20:53:53 +0000137
Brian Paul86b84272001-12-14 02:50:01 +0000138
Brian Paul27558a12003-03-01 01:50:20 +0000139/* ubyte -> float conversion */
140GLfloat _mesa_ubyte_to_float_color_tab[256];
141
Brian Paul9a33a112002-06-13 04:28:29 +0000142static void
143free_shared_state( GLcontext *ctx, struct gl_shared_state *ss );
144
Brian Paul86b84272001-12-14 02:50:01 +0000145
Brian Paulb1394fa2000-09-26 20:53:53 +0000146/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000147/** \name OpenGL SI-style interface (new in Mesa 3.5)
148 *
149 * \if subset
150 * \note Most of these functions are never called in the Mesa subset.
151 * \endif
152 */
153/*@{*/
Brian Paulb1394fa2000-09-26 20:53:53 +0000154
Keith Whitwell6dc85572003-07-17 13:43:59 +0000155/**
156 * Destroy context callback.
157 *
158 * \param gc context.
159 * \return GL_TRUE on success, or GL_FALSE on failure.
160 *
161 * \ifnot subset
162 * Called by window system/device driver (via __GLexports::destroyCurrent) when
163 * the rendering context is to be destroyed.
164 * \endif
165 *
166 * Frees the context data and the context structure.
Brian Paul9a33a112002-06-13 04:28:29 +0000167 */
168GLboolean
169_mesa_destroyContext(__GLcontext *gc)
Brian Paulb1394fa2000-09-26 20:53:53 +0000170{
171 if (gc) {
172 _mesa_free_context_data(gc);
Brian Paul3c634522002-10-24 23:57:19 +0000173 _mesa_free(gc);
Brian Paulb1394fa2000-09-26 20:53:53 +0000174 }
175 return GL_TRUE;
176}
177
Keith Whitwell6dc85572003-07-17 13:43:59 +0000178/**
179 * Unbind context callback.
180 *
181 * \param gc context.
182 * \return GL_TRUE on success, or GL_FALSE on failure.
183 *
184 * \ifnot subset
185 * Called by window system/device driver (via __GLexports::loseCurrent)
Brian Paul9a33a112002-06-13 04:28:29 +0000186 * when the rendering context is made non-current.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000187 * \endif
188 *
189 * No-op
Brian Paul9a33a112002-06-13 04:28:29 +0000190 */
191GLboolean
192_mesa_loseCurrent(__GLcontext *gc)
193{
194 /* XXX unbind context from thread */
195 return GL_TRUE;
196}
197
Keith Whitwell6dc85572003-07-17 13:43:59 +0000198/**
199 * Bind context callback.
200 *
201 * \param gc context.
202 * \return GL_TRUE on success, or GL_FALSE on failure.
203 *
204 * \ifnot subset
205 * Called by window system/device driver (via __GLexports::makeCurrent)
Brian Paul9a33a112002-06-13 04:28:29 +0000206 * when the rendering context is made current.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000207 * \endif
208 *
209 * No-op
Brian Paul9a33a112002-06-13 04:28:29 +0000210 */
211GLboolean
212_mesa_makeCurrent(__GLcontext *gc)
213{
214 /* XXX bind context to thread */
215 return GL_TRUE;
216}
217
Keith Whitwell6dc85572003-07-17 13:43:59 +0000218/**
219 * Share context callback.
220 *
221 * \param gc context.
222 * \param gcShare shared context.
223 * \return GL_TRUE on success, or GL_FALSE on failure.
224 *
225 * \ifnot subset
226 * Called by window system/device driver (via __GLexports::shareContext)
227 * \endif
228 *
229 * Update the shared context reference count, gl_shared_state::RefCount.
Brian Paul9a33a112002-06-13 04:28:29 +0000230 */
231GLboolean
232_mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare)
233{
234 if (gc && gcShare && gc->Shared && gcShare->Shared) {
235 gc->Shared->RefCount--;
236 if (gc->Shared->RefCount == 0) {
237 free_shared_state(gc, gc->Shared);
238 }
239 gc->Shared = gcShare->Shared;
240 gc->Shared->RefCount++;
241 return GL_TRUE;
242 }
243 else {
244 return GL_FALSE;
245 }
246}
247
Keith Whitwell6dc85572003-07-17 13:43:59 +0000248
249#if _HAVE_FULL_GL
250/**
251 * Copy context callback.
252 */
Brian Paul9a33a112002-06-13 04:28:29 +0000253GLboolean
254_mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask)
255{
256 if (dst && src) {
257 _mesa_copy_context( src, dst, mask );
258 return GL_TRUE;
259 }
260 else {
261 return GL_FALSE;
262 }
263}
Keith Whitwell6dc85572003-07-17 13:43:59 +0000264#endif
Brian Paul9a33a112002-06-13 04:28:29 +0000265
Keith Whitwell6dc85572003-07-17 13:43:59 +0000266/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000267GLboolean
268_mesa_forceCurrent(__GLcontext *gc)
269{
270 return GL_TRUE;
271}
272
Keith Whitwell6dc85572003-07-17 13:43:59 +0000273/**
274 * Windows/buffer resizing notification callback.
275 *
276 * \param gc GL context.
277 * \return GL_TRUE on success, or GL_FALSE on failure.
278 */
Brian Paul9a33a112002-06-13 04:28:29 +0000279GLboolean
280_mesa_notifyResize(__GLcontext *gc)
281{
282 GLint x, y;
283 GLuint width, height;
284 __GLdrawablePrivate *d = gc->imports.getDrawablePrivate(gc);
285 if (!d || !d->getDrawableSize)
286 return GL_FALSE;
287 d->getDrawableSize( d, &x, &y, &width, &height );
288 /* update viewport, resize software buffers, etc. */
289 return GL_TRUE;
290}
291
Keith Whitwell6dc85572003-07-17 13:43:59 +0000292/**
293 * Window/buffer destruction notification callback.
294 *
295 * \param gc GL context.
296 *
297 * Called when the context's window/buffer is going to be destroyed.
298 *
299 * No-op
300 */
Brian Paul9a33a112002-06-13 04:28:29 +0000301void
302_mesa_notifyDestroy(__GLcontext *gc)
303{
Brian Paul60b6e4f2002-10-14 17:08:17 +0000304 /* Unbind from it. */
Brian Paul9a33a112002-06-13 04:28:29 +0000305}
306
Keith Whitwell6dc85572003-07-17 13:43:59 +0000307/**
308 * Swap buffers notification callback.
309 *
310 * \param gc GL context.
311 *
312 * Called by window system just before swapping buffers.
Brian Paul9a33a112002-06-13 04:28:29 +0000313 * We have to finish any pending rendering.
314 */
315void
316_mesa_notifySwapBuffers(__GLcontext *gc)
317{
318 FLUSH_VERTICES( gc, 0 );
319}
320
Keith Whitwell6dc85572003-07-17 13:43:59 +0000321/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000322struct __GLdispatchStateRec *
323_mesa_dispatchExec(__GLcontext *gc)
324{
325 return NULL;
326}
327
Keith Whitwell6dc85572003-07-17 13:43:59 +0000328/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000329void
330_mesa_beginDispatchOverride(__GLcontext *gc)
331{
332}
333
Keith Whitwell6dc85572003-07-17 13:43:59 +0000334/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000335void
336_mesa_endDispatchOverride(__GLcontext *gc)
337{
338}
339
Keith Whitwell6dc85572003-07-17 13:43:59 +0000340/**
341 * \ifnot subset
342 * Setup the exports.
343 *
344 * The window system will call these functions when it needs Mesa to do
345 * something.
346 *
347 * \note Device drivers should override these functions! For example,
Brian Paul9a33a112002-06-13 04:28:29 +0000348 * the Xlib driver should plug in the XMesa*-style functions into this
349 * structure. The XMesa-style functions should then call the _mesa_*
350 * version of these functions. This is an approximation to OO design
351 * (inheritance and virtual functions).
Keith Whitwell6dc85572003-07-17 13:43:59 +0000352 * \endif
353 *
354 * \if subset
355 * No-op.
356 *
357 * \endif
Brian Paul9a33a112002-06-13 04:28:29 +0000358 */
359static void
360_mesa_init_default_exports(__GLexports *exports)
361{
Keith Whitwell6dc85572003-07-17 13:43:59 +0000362#if _HAVE_FULL_GL
Brian Paul9a33a112002-06-13 04:28:29 +0000363 exports->destroyContext = _mesa_destroyContext;
364 exports->loseCurrent = _mesa_loseCurrent;
365 exports->makeCurrent = _mesa_makeCurrent;
366 exports->shareContext = _mesa_shareContext;
367 exports->copyContext = _mesa_copyContext;
368 exports->forceCurrent = _mesa_forceCurrent;
369 exports->notifyResize = _mesa_notifyResize;
Brian Paul2f35d5e2002-06-13 04:31:09 +0000370 exports->notifyDestroy = _mesa_notifyDestroy;
Brian Paul9a33a112002-06-13 04:28:29 +0000371 exports->notifySwapBuffers = _mesa_notifySwapBuffers;
372 exports->dispatchExec = _mesa_dispatchExec;
373 exports->beginDispatchOverride = _mesa_beginDispatchOverride;
374 exports->endDispatchOverride = _mesa_endDispatchOverride;
Keith Whitwell6dc85572003-07-17 13:43:59 +0000375#endif
Brian Paul9a33a112002-06-13 04:28:29 +0000376}
377
Keith Whitwell6dc85572003-07-17 13:43:59 +0000378/**
379 * Exported OpenGL SI interface.
380 */
Brian Paulb1394fa2000-09-26 20:53:53 +0000381__GLcontext *
382__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
383{
384 GLcontext *ctx;
385
Brian Paul4753d602002-06-15 02:38:15 +0000386 ctx = (GLcontext *) (*imports->calloc)(NULL, 1, sizeof(GLcontext));
Brian Paulb1394fa2000-09-26 20:53:53 +0000387 if (ctx == NULL) {
388 return NULL;
389 }
Brian Paul60b6e4f2002-10-14 17:08:17 +0000390
Brian Pauld3fd7ba2004-01-20 02:49:27 +0000391 /* XXX doesn't work at this time */
392 _mesa_initialize_context(ctx, modes, NULL, NULL, NULL);
Brian Paulb1394fa2000-09-26 20:53:53 +0000393 ctx->imports = *imports;
Brian Paulb1394fa2000-09-26 20:53:53 +0000394
395 return ctx;
396}
397
Keith Whitwell6dc85572003-07-17 13:43:59 +0000398/**
399 * Exported OpenGL SI interface.
400 */
Brian Paulb1394fa2000-09-26 20:53:53 +0000401void
402__glCoreNopDispatch(void)
403{
404#if 0
405 /* SI */
406 __gl_dispatch = __glNopDispatchState;
407#else
408 /* Mesa */
409 _glapi_set_dispatch(NULL);
410#endif
411}
412
Keith Whitwell6dc85572003-07-17 13:43:59 +0000413/*@}*/
414
Brian Paulb1394fa2000-09-26 20:53:53 +0000415
jtgafb833d1999-08-19 00:55:39 +0000416/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000417/** \name GL Visual allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000418/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000419/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000420
Keith Whitwell6dc85572003-07-17 13:43:59 +0000421/**
Brian Paul894844a2004-03-21 17:05:03 +0000422 * Allocates a GLvisual structure and initializes it via
423 * _mesa_initialize_visual().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000424 *
425 * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
426 * \param dbFlag double buffering
427 * \param stereoFlag stereo buffer
428 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
429 * is acceptable but the actual depth type will be GLushort or GLuint as
430 * needed.
431 * \param stencilBits requested minimum bits per stencil buffer value
432 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
433 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
434 * \param redBits number of bits per color component in frame buffer for RGB(A)
435 * mode. We always use 8 in core Mesa though.
436 * \param greenBits same as above.
437 * \param blueBits same as above.
438 * \param alphaBits same as above.
439 * \param numSamples not really used.
440 *
441 * \return pointer to new GLvisual or NULL if requested parameters can't be
442 * met.
443 *
Brian Paul894844a2004-03-21 17:05:03 +0000444 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul4d053dd2000-01-14 04:45:47 +0000445 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000446GLvisual *
447_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000448 GLboolean dbFlag,
449 GLboolean stereoFlag,
450 GLint redBits,
451 GLint greenBits,
452 GLint blueBits,
453 GLint alphaBits,
454 GLint indexBits,
455 GLint depthBits,
456 GLint stencilBits,
457 GLint accumRedBits,
458 GLint accumGreenBits,
459 GLint accumBlueBits,
460 GLint accumAlphaBits,
461 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000462{
Brian Paul178a1c52000-04-22 01:05:00 +0000463 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
464 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000465 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000466 redBits, greenBits, blueBits, alphaBits,
467 indexBits, depthBits, stencilBits,
468 accumRedBits, accumGreenBits,
469 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000470 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000471 FREE(vis);
472 return NULL;
473 }
474 }
475 return vis;
476}
477
Keith Whitwell6dc85572003-07-17 13:43:59 +0000478/**
Brian Paul894844a2004-03-21 17:05:03 +0000479 * Makes some sanity checks and fills in the fields of the
480 * GLvisual structure with the given parameters.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000481 *
482 * \return GL_TRUE on success, or GL_FALSE on failure.
483 *
484 * \sa _mesa_create_visual() above for the parameter description.
485 *
Brian Paul894844a2004-03-21 17:05:03 +0000486 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul178a1c52000-04-22 01:05:00 +0000487 */
488GLboolean
489_mesa_initialize_visual( GLvisual *vis,
490 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000491 GLboolean dbFlag,
492 GLboolean stereoFlag,
493 GLint redBits,
494 GLint greenBits,
495 GLint blueBits,
496 GLint alphaBits,
497 GLint indexBits,
498 GLint depthBits,
499 GLint stencilBits,
500 GLint accumRedBits,
501 GLint accumGreenBits,
502 GLint accumBlueBits,
503 GLint accumAlphaBits,
504 GLint numSamples )
505{
506 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000507
Brian Pauled30dfa2000-03-03 17:47:39 +0000508 /* This is to catch bad values from device drivers not updated for
509 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
510 * bad value now (a 1-bit depth buffer!?!).
511 */
512 assert(depthBits == 0 || depthBits > 1);
513
514 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000515 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000516 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000517 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000518 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000519 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000520 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000521 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000522 }
523 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000524 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000525 }
526 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000527 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000528 }
529 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000530 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000531 }
532
Brian Paulb6bcae52001-01-23 23:39:36 +0000533 vis->rgbMode = rgbFlag;
534 vis->doubleBufferMode = dbFlag;
535 vis->stereoMode = stereoFlag;
Brian Paul153f1542002-10-29 15:04:35 +0000536
Brian Paulb6bcae52001-01-23 23:39:36 +0000537 vis->redBits = redBits;
538 vis->greenBits = greenBits;
539 vis->blueBits = blueBits;
540 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000541
Brian Paulb6bcae52001-01-23 23:39:36 +0000542 vis->indexBits = indexBits;
543 vis->depthBits = depthBits;
544 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
545 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
546 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
547 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
548 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000549
Brian Paul153f1542002-10-29 15:04:35 +0000550 vis->haveAccumBuffer = accumRedBits > 0;
551 vis->haveDepthBuffer = depthBits > 0;
552 vis->haveStencilBuffer = stencilBits > 0;
553
554 vis->numAuxBuffers = 0;
555 vis->level = 0;
556 vis->pixmapMode = 0;
Brian Paul894844a2004-03-21 17:05:03 +0000557 vis->samples = numSamples;
Brian Paul153f1542002-10-29 15:04:35 +0000558
Brian Paul178a1c52000-04-22 01:05:00 +0000559 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000560}
561
Brian Paul894844a2004-03-21 17:05:03 +0000562
Keith Whitwell6dc85572003-07-17 13:43:59 +0000563/**
Brian Paul894844a2004-03-21 17:05:03 +0000564 * Destroy a visual and free its memory.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000565 *
566 * \param vis visual.
567 *
568 * Frees the visual structure.
569 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000570void
571_mesa_destroy_visual( GLvisual *vis )
572{
573 FREE(vis);
574}
575
Keith Whitwell6dc85572003-07-17 13:43:59 +0000576/*@}*/
577
Brian Paulb371e0d2000-03-31 01:05:51 +0000578
Brian Paul4d053dd2000-01-14 04:45:47 +0000579/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000580/** \name GL Framebuffer allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000581/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000582/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000583
Keith Whitwell6dc85572003-07-17 13:43:59 +0000584/**
Brian Paul894844a2004-03-21 17:05:03 +0000585 * Allocate a GLframebuffer structure and initializes it via
586 * _mesa_initialize_framebuffer().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000587 *
588 * A GLframebuffer is a structure which encapsulates the depth, stencil and
589 * accum buffers and related parameters.
590 *
591 * \param visual a GLvisual pointer (we copy the struct contents)
592 * \param softwareDepth create/use a software depth buffer?
593 * \param softwareStencil create/use a software stencil buffer?
594 * \param softwareAccum create/use a software accum buffer?
595 * \param softwareAlpha create/use a software alpha buffer?
596 *
597 * \return pointer to new GLframebuffer struct or NULL if error.
598 *
Brian Paul894844a2004-03-21 17:05:03 +0000599 * \note Need to add softwareAuxBuffers parameter.
Brian Paul4d053dd2000-01-14 04:45:47 +0000600 */
Brian Paul178a1c52000-04-22 01:05:00 +0000601GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000602_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000603 GLboolean softwareDepth,
604 GLboolean softwareStencil,
605 GLboolean softwareAccum,
606 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000607{
Brian Paul178a1c52000-04-22 01:05:00 +0000608 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
609 assert(visual);
610 if (buffer) {
611 _mesa_initialize_framebuffer(buffer, visual,
612 softwareDepth, softwareStencil,
613 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000614 }
Brian Paul178a1c52000-04-22 01:05:00 +0000615 return buffer;
616}
617
Brian Paul894844a2004-03-21 17:05:03 +0000618
Keith Whitwell6dc85572003-07-17 13:43:59 +0000619/**
Keith Whitwell6dc85572003-07-17 13:43:59 +0000620 * Makes some sanity checks and fills in the fields of the
621 * GLframebuffer structure with the given parameters.
Brian Paul894844a2004-03-21 17:05:03 +0000622 *
623 * \sa _mesa_create_framebuffer() above for the parameter description.
Brian Paul178a1c52000-04-22 01:05:00 +0000624 */
625void
626_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000627 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000628 GLboolean softwareDepth,
629 GLboolean softwareStencil,
630 GLboolean softwareAccum,
631 GLboolean softwareAlpha )
632{
Brian Paul894844a2004-03-21 17:05:03 +0000633 GLboolean softwareAux = GL_FALSE;
Brian Paul178a1c52000-04-22 01:05:00 +0000634 assert(buffer);
635 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000636
Brian Paul6ec6b842002-10-30 19:49:29 +0000637 _mesa_bzero(buffer, sizeof(GLframebuffer));
Brian Paul85d81602002-06-17 23:36:31 +0000638
Brian Paul4d053dd2000-01-14 04:45:47 +0000639 /* sanity checks */
640 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000641 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000642 }
643 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000644 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000645 }
646 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000647 assert(visual->rgbMode);
648 assert(visual->accumRedBits > 0);
649 assert(visual->accumGreenBits > 0);
650 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000651 }
652 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000653 assert(visual->rgbMode);
654 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000655 }
656
Brian Paul75978bd2001-04-27 21:17:20 +0000657 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000658 buffer->UseSoftwareDepthBuffer = softwareDepth;
659 buffer->UseSoftwareStencilBuffer = softwareStencil;
660 buffer->UseSoftwareAccumBuffer = softwareAccum;
661 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul894844a2004-03-21 17:05:03 +0000662 buffer->UseSoftwareAuxBuffers = softwareAux;
Brian Paul4d053dd2000-01-14 04:45:47 +0000663}
664
Brian Paul894844a2004-03-21 17:05:03 +0000665
Keith Whitwell6dc85572003-07-17 13:43:59 +0000666/**
Brian Paul4d053dd2000-01-14 04:45:47 +0000667 * Free a framebuffer struct and its buffers.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000668 *
669 * Calls _mesa_free_framebuffer_data() and frees the structure.
Brian Paul4d053dd2000-01-14 04:45:47 +0000670 */
Brian Paul178a1c52000-04-22 01:05:00 +0000671void
Brian Paulb1394fa2000-09-26 20:53:53 +0000672_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000673{
674 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000675 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000676 FREE(buffer);
677 }
678}
679
Brian Paul894844a2004-03-21 17:05:03 +0000680
Keith Whitwell6dc85572003-07-17 13:43:59 +0000681/**
682 * Free the data hanging off of \p buffer, but not \p buffer itself.
683 *
684 * \param buffer framebuffer.
685 *
686 * Frees all the buffers associated with the structure.
Brian Paul75978bd2001-04-27 21:17:20 +0000687 */
688void
689_mesa_free_framebuffer_data( GLframebuffer *buffer )
690{
691 if (!buffer)
692 return;
693
Brian Paul87506682003-05-27 15:20:43 +0000694 if (buffer->UseSoftwareDepthBuffer && buffer->DepthBuffer) {
Brian Paulaeb44342002-03-19 16:47:04 +0000695 MESA_PBUFFER_FREE( buffer->DepthBuffer );
Brian Paul75978bd2001-04-27 21:17:20 +0000696 buffer->DepthBuffer = NULL;
697 }
Brian Paul87506682003-05-27 15:20:43 +0000698 if (buffer->UseSoftwareAccumBuffer && buffer->Accum) {
Brian Paulaeb44342002-03-19 16:47:04 +0000699 MESA_PBUFFER_FREE( buffer->Accum );
Brian Paul75978bd2001-04-27 21:17:20 +0000700 buffer->Accum = NULL;
701 }
Brian Paul87506682003-05-27 15:20:43 +0000702 if (buffer->UseSoftwareStencilBuffer && buffer->Stencil) {
Brian Paulaeb44342002-03-19 16:47:04 +0000703 MESA_PBUFFER_FREE( buffer->Stencil );
Brian Paul75978bd2001-04-27 21:17:20 +0000704 buffer->Stencil = NULL;
705 }
Brian Paul87506682003-05-27 15:20:43 +0000706 if (buffer->UseSoftwareAlphaBuffers){
707 if (buffer->FrontLeftAlpha) {
708 MESA_PBUFFER_FREE( buffer->FrontLeftAlpha );
709 buffer->FrontLeftAlpha = NULL;
710 }
711 if (buffer->BackLeftAlpha) {
712 MESA_PBUFFER_FREE( buffer->BackLeftAlpha );
713 buffer->BackLeftAlpha = NULL;
714 }
715 if (buffer->FrontRightAlpha) {
716 MESA_PBUFFER_FREE( buffer->FrontRightAlpha );
717 buffer->FrontRightAlpha = NULL;
718 }
719 if (buffer->BackRightAlpha) {
720 MESA_PBUFFER_FREE( buffer->BackRightAlpha );
721 buffer->BackRightAlpha = NULL;
722 }
Brian Paul75978bd2001-04-27 21:17:20 +0000723 }
724}
725
Keith Whitwell6dc85572003-07-17 13:43:59 +0000726/*@}*/
Brian Paul75978bd2001-04-27 21:17:20 +0000727
Brian Paul4d053dd2000-01-14 04:45:47 +0000728
729/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000730/** \name Context allocation, initialization, destroying
731 *
732 * The purpose of the most initialization functions here is to provide the
733 * default state values according to the OpenGL specification.
734 */
jtgafb833d1999-08-19 00:55:39 +0000735/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000736/*@{*/
jtgafb833d1999-08-19 00:55:39 +0000737
Keith Whitwell6dc85572003-07-17 13:43:59 +0000738/**
739 * One-time initialization mutex lock.
740 *
741 * \sa Used by one_time_init().
742 */
Brian Paul9560f052000-01-31 23:11:39 +0000743_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
744
Keith Whitwell6dc85572003-07-17 13:43:59 +0000745/**
746 * Calls all the various one-time-init functions in Mesa.
747 *
748 * While holding a global mutex lock, calls several initialization functions,
749 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
750 * defined.
751 *
752 * \sa _mesa_init_lists(), _math_init().
jtgafb833d1999-08-19 00:55:39 +0000753 */
Brian Paul178a1c52000-04-22 01:05:00 +0000754static void
Brian Paul4753d602002-06-15 02:38:15 +0000755one_time_init( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000756{
757 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000758 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000759 if (!alreadyCalled) {
Brian Paul27558a12003-03-01 01:50:20 +0000760 GLuint i;
761
Brian Paul4d053dd2000-01-14 04:45:47 +0000762 /* do some implementation tests */
763 assert( sizeof(GLbyte) == 1 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000764 assert( sizeof(GLubyte) == 1 );
Brian Paul894844a2004-03-21 17:05:03 +0000765 assert( sizeof(GLshort) == 2 );
766 assert( sizeof(GLushort) == 2 );
767 assert( sizeof(GLint) == 4 );
768 assert( sizeof(GLuint) == 4 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000769
Brian Paul08836342001-03-03 20:33:27 +0000770 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000771
Keith Whitwell6dc85572003-07-17 13:43:59 +0000772#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000773 _math_init();
Brian Paul27558a12003-03-01 01:50:20 +0000774
775 for (i = 0; i < 256; i++) {
776 _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
777 }
Keith Whitwell6dc85572003-07-17 13:43:59 +0000778#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000779
davem69775355a2001-06-05 23:54:00 +0000780#ifdef USE_SPARC_ASM
781 _mesa_init_sparc_glapi_relocs();
782#endif
Brian Paul3c634522002-10-24 23:57:19 +0000783 if (_mesa_getenv("MESA_DEBUG")) {
Brian Paul68ee4bc2000-01-28 19:02:22 +0000784 _glapi_noop_enable_warnings(GL_TRUE);
Brian Paul71072be2002-10-10 00:22:13 +0000785#ifndef GLX_DIRECT_RENDERING
786 /* libGL from before 2002/06/28 don't have this function. Someday,
787 * when newer libGL libs are common, remove the #ifdef test. This
788 * only serves to print warnings when calling undefined GL functions.
789 */
Brian Paul4e9676f2002-06-29 19:48:15 +0000790 _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
Brian Paul71072be2002-10-10 00:22:13 +0000791#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000792 }
793 else {
794 _glapi_noop_enable_warnings(GL_FALSE);
795 }
796
jtgafb833d1999-08-19 00:55:39 +0000797#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
Brian Paul4e9676f2002-06-29 19:48:15 +0000798 _mesa_debug(ctx, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
jtgafb833d1999-08-19 00:55:39 +0000799#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000800
801 alreadyCalled = GL_TRUE;
802 }
Brian Paul9560f052000-01-31 23:11:39 +0000803 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000804}
805
Brian Paul894844a2004-03-21 17:05:03 +0000806
Keith Whitwell6dc85572003-07-17 13:43:59 +0000807/**
jtgafb833d1999-08-19 00:55:39 +0000808 * Allocate and initialize a shared context state structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000809 * Initializes the display list, texture objects and vertex programs hash
810 * tables, allocates the texture objects. If it runs out of memory, frees
811 * everything already allocated before returning NULL.
Brian Paul894844a2004-03-21 17:05:03 +0000812 *
813 * \return pointer to a gl_shared_state structure on success, or NULL on
814 * failure.
jtgafb833d1999-08-19 00:55:39 +0000815 */
Brian Paula3f13702003-04-01 16:41:50 +0000816static GLboolean
817alloc_shared_state( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000818{
Brian Paula3f13702003-04-01 16:41:50 +0000819 struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000820 if (!ss)
Brian Paula3f13702003-04-01 16:41:50 +0000821 return GL_FALSE;
822
823 ctx->Shared = ss;
jtgafb833d1999-08-19 00:55:39 +0000824
Brian Paule4b684c2000-09-12 21:07:40 +0000825 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000826
Brian Paule4b684c2000-09-12 21:07:40 +0000827 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000828 ss->TexObjects = _mesa_NewHashTable();
Brian Paul451f3102003-04-17 01:48:19 +0000829#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
Brian Paul610d5992003-01-14 04:55:45 +0000830 ss->Programs = _mesa_NewHashTable();
Brian Paul8dfc5b92002-10-16 17:57:51 +0000831#endif
jtgafb833d1999-08-19 00:55:39 +0000832
Brian Paul451f3102003-04-17 01:48:19 +0000833#if FEATURE_ARB_vertex_program
Brian Paul4d859f72004-01-23 18:57:05 +0000834 ss->DefaultVertexProgram = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000835 if (!ss->DefaultVertexProgram)
836 goto cleanup;
837#endif
838#if FEATURE_ARB_fragment_program
Brian Paul4d859f72004-01-23 18:57:05 +0000839 ss->DefaultFragmentProgram = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000840 if (!ss->DefaultFragmentProgram)
841 goto cleanup;
842#endif
843
Ian Romanick0207b472003-09-09 00:10:12 +0000844 ss->BufferObjects = _mesa_NewHashTable();
845
Brian Paula3f13702003-04-01 16:41:50 +0000846 ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
847 if (!ss->Default1D)
848 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000849
Brian Paula3f13702003-04-01 16:41:50 +0000850 ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
851 if (!ss->Default2D)
852 goto cleanup;
jtgafb833d1999-08-19 00:55:39 +0000853
Brian Paula3f13702003-04-01 16:41:50 +0000854 ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
855 if (!ss->Default3D)
856 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000857
Brian Paula3f13702003-04-01 16:41:50 +0000858 ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
859 if (!ss->DefaultCubeMap)
860 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000861
Brian Paula3f13702003-04-01 16:41:50 +0000862 ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
863 if (!ss->DefaultRect)
864 goto cleanup;
Brian Paul413d6a22000-05-26 14:44:59 +0000865
Brian Paula3f13702003-04-01 16:41:50 +0000866 /* Effectively bind the default textures to all texture units */
867 ss->Default1D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
868 ss->Default2D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
869 ss->Default3D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
870 ss->DefaultCubeMap->RefCount += MAX_TEXTURE_IMAGE_UNITS;
871 ss->DefaultRect->RefCount += MAX_TEXTURE_IMAGE_UNITS;
872
873 return GL_TRUE;
874
875 cleanup:
876 /* Ran out of memory at some point. Free everything and return NULL */
877 if (ss->DisplayList)
878 _mesa_DeleteHashTable(ss->DisplayList);
879 if (ss->TexObjects)
880 _mesa_DeleteHashTable(ss->TexObjects);
881#if FEATURE_NV_vertex_program
882 if (ss->Programs)
883 _mesa_DeleteHashTable(ss->Programs);
884#endif
Brian Paul451f3102003-04-17 01:48:19 +0000885#if FEATURE_ARB_vertex_program
886 if (ss->DefaultVertexProgram)
Brian Paul4d859f72004-01-23 18:57:05 +0000887 ctx->Driver.DeleteProgram(ctx, ss->DefaultVertexProgram);
Brian Paul451f3102003-04-17 01:48:19 +0000888#endif
889#if FEATURE_ARB_fragment_program
890 if (ss->DefaultFragmentProgram)
Brian Paul4d859f72004-01-23 18:57:05 +0000891 ctx->Driver.DeleteProgram(ctx, ss->DefaultFragmentProgram);
Brian Paul451f3102003-04-17 01:48:19 +0000892#endif
Ian Romanick0207b472003-09-09 00:10:12 +0000893 if (ss->BufferObjects)
894 _mesa_DeleteHashTable(ss->BufferObjects);
895
Brian Paula3f13702003-04-01 16:41:50 +0000896 if (ss->Default1D)
897 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
898 if (ss->Default2D)
899 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
900 if (ss->Default3D)
901 (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
902 if (ss->DefaultCubeMap)
903 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
904 if (ss->DefaultRect)
905 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
906 if (ss)
907 _mesa_free(ss);
908 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000909}
910
Keith Whitwell6dc85572003-07-17 13:43:59 +0000911/**
jtgafb833d1999-08-19 00:55:39 +0000912 * Deallocate a shared state context and all children structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000913 *
914 * \param ctx GL context.
915 * \param ss shared state pointer.
916 *
917 * Frees the display lists, the texture objects (calling the driver texture
918 * deletion callback to free its private data) and the vertex programs, as well
919 * as their hash tables.
920 *
921 * \sa alloc_shared_state().
jtgafb833d1999-08-19 00:55:39 +0000922 */
Brian Paul178a1c52000-04-22 01:05:00 +0000923static void
924free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000925{
926 /* Free display lists */
927 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000928 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000929 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000930 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000931 }
932 else {
933 break;
934 }
935 }
Brian Paulbb797902000-01-24 16:19:54 +0000936 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000937
938 /* Free texture objects */
Brian Paula3f13702003-04-01 16:41:50 +0000939 ASSERT(ctx->Driver.DeleteTexture);
940 while (1) {
941 GLuint texName = _mesa_HashFirstEntry(ss->TexObjects);
942 if (texName) {
943 struct gl_texture_object *texObj = (struct gl_texture_object *)
944 _mesa_HashLookup(ss->TexObjects, texName);
945 ASSERT(texObj);
946 (*ctx->Driver.DeleteTexture)(ctx, texObj);
947 _mesa_HashRemove(ss->TexObjects, texName);
948 }
949 else {
950 break;
951 }
jtgafb833d1999-08-19 00:55:39 +0000952 }
Brian Paulbb797902000-01-24 16:19:54 +0000953 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000954
Brian Paul8dfc5b92002-10-16 17:57:51 +0000955#if FEATURE_NV_vertex_program
Brian Paul30f51ae2001-12-18 04:06:44 +0000956 /* Free vertex programs */
957 while (1) {
Brian Paul610d5992003-01-14 04:55:45 +0000958 GLuint prog = _mesa_HashFirstEntry(ss->Programs);
Brian Paul30f51ae2001-12-18 04:06:44 +0000959 if (prog) {
Brian Paul451f3102003-04-17 01:48:19 +0000960 struct program *p = (struct program *) _mesa_HashLookup(ss->Programs,
961 prog);
962 ASSERT(p);
Brian Paul4d859f72004-01-23 18:57:05 +0000963 ctx->Driver.DeleteProgram(ctx, p);
Brian Paul451f3102003-04-17 01:48:19 +0000964 _mesa_HashRemove(ss->Programs, prog);
Brian Paul30f51ae2001-12-18 04:06:44 +0000965 }
966 else {
967 break;
968 }
969 }
Brian Paul610d5992003-01-14 04:55:45 +0000970 _mesa_DeleteHashTable(ss->Programs);
Brian Paul8dfc5b92002-10-16 17:57:51 +0000971#endif
Brian Paul30f51ae2001-12-18 04:06:44 +0000972
Ian Romanick0207b472003-09-09 00:10:12 +0000973 _mesa_DeleteHashTable(ss->BufferObjects);
974
Keith Whitwelle15fd852002-12-12 13:03:15 +0000975 _glthread_DESTROY_MUTEX(ss->Mutex);
976
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000977 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000978}
979
980
Brian Paul4d859f72004-01-23 18:57:05 +0000981/**
982 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
983 */
984static void
985_mesa_init_current( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000986{
Brian Paul88bf0382004-02-13 15:30:08 +0000987 GLuint i;
jtgafb833d1999-08-19 00:55:39 +0000988
Keith Whitwell6dc85572003-07-17 13:43:59 +0000989 /* Current group */
990 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
991 ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000992 }
Keith Whitwell6dc85572003-07-17 13:43:59 +0000993 /* special cases: */
994 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 1.0 );
995 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
996 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
Brian Paul88bf0382004-02-13 15:30:08 +0000997 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
Keith Whitwell6dc85572003-07-17 13:43:59 +0000998 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 );
Brian Paul88bf0382004-02-13 15:30:08 +0000999
Keith Whitwell6dc85572003-07-17 13:43:59 +00001000 ctx->Current.Index = 1;
1001 ctx->Current.EdgeFlag = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001002}
1003
1004
Brian Paul4d859f72004-01-23 18:57:05 +00001005/**
1006 * Initialize fields of gl_constants (aka ctx->Const.*).
1007 * Use defaults from config.h. The device drivers will often override
1008 * some of these values (such as number of texture units).
1009 */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001010static void
1011_mesa_init_constants( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001012{
Brian Paul4d053dd2000-01-14 04:45:47 +00001013 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +00001014
Brian Paulcd1cefa2001-06-13 14:56:14 +00001015 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
1016 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
1017
Brian Paul539cce52000-02-03 19:40:07 +00001018 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +00001019 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +00001020 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
1021 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul8afe7de2002-06-15 03:03:06 +00001022 ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001023 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Brian Paul610d5992003-01-14 04:55:45 +00001024 ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
1025 ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +00001026 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +00001027 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +00001028 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +00001029 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
1030 ctx->Const.MinPointSize = MIN_POINT_SIZE;
1031 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
1032 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
1033 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +00001034 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +00001035 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
1036 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
1037 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
1038 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +00001039 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001040 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +00001041 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
1042 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paula8644322000-11-27 18:22:13 +00001043 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
1044 ctx->Const.MaxLights = MAX_LIGHTS;
Ian Romanick882caa12003-05-30 21:37:14 +00001045 ctx->Const.MaxSpotExponent = 128.0;
1046 ctx->Const.MaxShininess = 128.0;
Brian Pauld0492cf2003-04-11 01:20:06 +00001047#if FEATURE_ARB_vertex_program
Brian Pauld0492cf2003-04-11 01:20:06 +00001048 ctx->Const.MaxVertexProgramInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS;
Brian Paul451f3102003-04-17 01:48:19 +00001049 ctx->Const.MaxVertexProgramAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
1050 ctx->Const.MaxVertexProgramTemps = MAX_NV_VERTEX_PROGRAM_TEMPS;
1051 ctx->Const.MaxVertexProgramLocalParams = MAX_NV_VERTEX_PROGRAM_PARAMS;
1052 ctx->Const.MaxVertexProgramEnvParams = MAX_NV_VERTEX_PROGRAM_PARAMS;/*XXX*/
1053 ctx->Const.MaxVertexProgramAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
Brian Pauld0492cf2003-04-11 01:20:06 +00001054#endif
1055#if FEATURE_ARB_fragment_program
Brian Pauld0492cf2003-04-11 01:20:06 +00001056 ctx->Const.MaxFragmentProgramInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS;
Brian Paul451f3102003-04-17 01:48:19 +00001057 ctx->Const.MaxFragmentProgramAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
1058 ctx->Const.MaxFragmentProgramTemps = MAX_NV_FRAGMENT_PROGRAM_TEMPS;
1059 ctx->Const.MaxFragmentProgramLocalParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
1060 ctx->Const.MaxFragmentProgramEnvParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;/*XXX*/
1061 ctx->Const.MaxFragmentProgramAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
1062 ctx->Const.MaxFragmentProgramAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS;
1063 ctx->Const.MaxFragmentProgramTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS;
1064 ctx->Const.MaxFragmentProgramTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS;
Brian Pauld0492cf2003-04-11 01:20:06 +00001065#endif
Brian Pauledd67742003-04-18 18:02:43 +00001066 ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
1067 ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
Brian Pauld0492cf2003-04-11 01:20:06 +00001068
Brian Paula2b9bad2003-11-10 19:08:37 +00001069 /* If we're running in the X server, do bounds checking to prevent
1070 * segfaults and server crashes!
1071 */
1072#if defined(XFree86LOADER) && defined(IN_MODULE)
1073 ctx->Const.CheckArrayBounds = GL_TRUE;
1074#else
1075 ctx->Const.CheckArrayBounds = GL_FALSE;
1076#endif
1077
Brian Paul92f97852003-05-01 22:44:02 +00001078 ASSERT(ctx->Const.MaxTextureUnits == MAX2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits));
Keith Whitwell6dc85572003-07-17 13:43:59 +00001079}
jtgafb833d1999-08-19 00:55:39 +00001080
Brian Paul4d859f72004-01-23 18:57:05 +00001081
Keith Whitwell6dc85572003-07-17 13:43:59 +00001082/**
1083 * Initialize the attribute groups in a GL context.
1084 *
1085 * \param ctx GL context.
1086 *
1087 * Initializes all the attributes, calling the respective <tt>init*</tt>
1088 * functions for the more complex data structures.
1089 */
1090static GLboolean
1091init_attrib_groups( GLcontext *ctx )
1092{
1093 assert(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001094
Keith Whitwell6dc85572003-07-17 13:43:59 +00001095 /* Constants */
1096 _mesa_init_constants( ctx );
Brian Paul0771d152000-04-07 00:19:41 +00001097
Brian Paul4d053dd2000-01-14 04:45:47 +00001098 /* Extensions */
Brian Paulde4f4602003-07-03 02:15:06 +00001099 _mesa_init_extensions( ctx );
jtgafb833d1999-08-19 00:55:39 +00001100
Keith Whitwell6dc85572003-07-17 13:43:59 +00001101 /* Attribute Groups */
1102 _mesa_init_accum( ctx );
1103 _mesa_init_attrib( ctx );
1104 _mesa_init_buffers( ctx );
Brian Paul148a2842003-09-17 03:40:11 +00001105 _mesa_init_buffer_objects( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001106 _mesa_init_color( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001107 _mesa_init_colortables( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001108 _mesa_init_current( ctx );
1109 _mesa_init_depth( ctx );
1110 _mesa_init_debug( ctx );
1111 _mesa_init_display_list( ctx );
1112 _mesa_init_eval( ctx );
1113 _mesa_init_feedback( ctx );
1114 _mesa_init_fog( ctx );
1115 _mesa_init_histogram( ctx );
1116 _mesa_init_hint( ctx );
1117 _mesa_init_line( ctx );
1118 _mesa_init_lighting( ctx );
1119 _mesa_init_matrix( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001120 _mesa_init_occlude( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001121 _mesa_init_pixel( ctx );
1122 _mesa_init_point( ctx );
1123 _mesa_init_polygon( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001124 _mesa_init_program( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001125 _mesa_init_rastpos( ctx );
1126 _mesa_init_stencil( ctx );
1127 _mesa_init_transform( ctx );
1128 _mesa_init_varray( ctx );
1129 _mesa_init_viewport( ctx );
jtgafb833d1999-08-19 00:55:39 +00001130
Keith Whitwell6dc85572003-07-17 13:43:59 +00001131 if (!_mesa_init_texture( ctx ))
1132 return GL_FALSE;
Brian Paulb17a7222003-06-13 02:37:27 +00001133
Brian Paul8f04c122004-04-27 13:39:20 +00001134 _mesa_init_texture_s3tc( ctx );
1135 _mesa_init_texture_fxt1( ctx );
1136
Brian Paul4d053dd2000-01-14 04:45:47 +00001137 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001138 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001139 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
Brian Paul4d053dd2000-01-14 04:45:47 +00001140 ctx->CatchSignals = GL_TRUE;
Brian Paulf782b812002-10-04 17:37:45 +00001141 ctx->_Facing = 0;
Brian Paul4923e192004-02-28 22:30:58 +00001142#if CHAN_TYPE == GL_FLOAT
1143 ctx->ClampFragmentColors = GL_FALSE; /* XXX temporary */
1144#else
1145 ctx->ClampFragmentColors = GL_TRUE;
1146#endif
1147 ctx->ClampVertexColors = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001148
Brian Paula3f13702003-04-01 16:41:50 +00001149 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001150}
1151
1152
Brian Paulf44898c2003-07-18 15:44:57 +00001153/**
1154 * If the DRI libGL.so library is old, it may not have the entrypoints for
1155 * some recent OpenGL extensions. Dynamically add them now.
1156 * If we're building stand-alone Mesa where libGL.so has both the dispatcher
1157 * and driver code, this won't be an issue (and calling this function won't
1158 * do any harm).
1159 */
1160static void
1161add_newer_entrypoints(void)
1162{
Ian Romanick3baefe62003-08-22 23:28:03 +00001163 unsigned i;
1164 static const struct {
1165 const char * const name;
1166 unsigned offset;
1167 }
1168 newer_entrypoints[] = {
1169 /* GL_ARB_window_pos aliases with GL_MESA_window_pos */
1170 { "glWindowPos2dARB", 513 },
1171 { "glWindowPos2dvARB", 514 },
1172 { "glWindowPos2fARB", 515 },
1173 { "glWindowPos2fvARB", 516 },
1174 { "glWindowPos2iARB", 517 },
1175 { "glWindowPos2ivARB", 518 },
1176 { "glWindowPos2sARB", 519 },
1177 { "glWindowPos2svARB", 520 },
1178 { "glWindowPos3dARB", 521 },
1179 { "glWindowPos3dvARB", 522 },
1180 { "glWindowPos3fARB", 523 },
1181 { "glWindowPos3fvARB", 524 },
1182 { "glWindowPos3iARB", 525 },
1183 { "glWindowPos3ivARB", 526 },
1184 { "glWindowPos3sARB", 527 },
1185 { "glWindowPos3svARB", 528 },
Brian Paulf44898c2003-07-18 15:44:57 +00001186#if FEATURE_NV_vertex_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001187 { "glAreProgramsResidentNV", 578 },
1188 { "glBindProgramNV", 579 },
1189 { "glDeleteProgramsNV", 580 },
1190 { "glExecuteProgramNV", 581 },
1191 { "glGenProgramsNV", 582 },
1192 { "glGetProgramParameterdvNV", 583 },
1193 { "glGetProgramParameterfvNV", 584 },
1194 { "glGetProgramivNV", 585 },
1195 { "glGetProgramStringNV", 586 },
1196 { "glGetTrackMatrixivNV", 587 },
1197 { "glGetVertexAttribdvNV", 588 },
1198 { "glGetVertexAttribfvNV", 589 },
1199 { "glGetVertexAttribivNV", 590 },
1200 { "glGetVertexAttribPointervNV", 591 },
1201 { "glIsProgramNV", 592 },
1202 { "glLoadProgramNV", 593 },
1203 { "glProgramParameter4dNV", 594 },
1204 { "glProgramParameter4dvNV", 595 },
1205 { "glProgramParameter4fNV", 596 },
1206 { "glProgramParameter4fvNV", 597 },
1207 { "glProgramParameters4dvNV", 598 },
1208 { "glProgramParameters4fvNV", 599 },
1209 { "glRequestResidentProgramsNV", 600 },
1210 { "glTrackMatrixNV", 601 },
1211 { "glVertexAttribPointerNV", 602 },
1212 { "glVertexAttrib1dNV", 603 },
1213 { "glVertexAttrib1dvNV", 604 },
1214 { "glVertexAttrib1fNV", 605 },
1215 { "glVertexAttrib1fvNV", 606 },
1216 { "glVertexAttrib1sNV", 607 },
1217 { "glVertexAttrib1svNV", 608 },
1218 { "glVertexAttrib2dNV", 609 },
1219 { "glVertexAttrib2dvNV", 610 },
1220 { "glVertexAttrib2fNV", 611 },
1221 { "glVertexAttrib2fvNV", 612 },
1222 { "glVertexAttrib2sNV", 613 },
1223 { "glVertexAttrib2svNV", 614 },
1224 { "glVertexAttrib3dNV", 615 },
1225 { "glVertexAttrib3dvNV", 616 },
1226 { "glVertexAttrib3fNV", 617 },
1227 { "glVertexAttrib3fvNV", 618 },
1228 { "glVertexAttrib3sNV", 619 },
1229 { "glVertexAttrib3svNV", 620 },
1230 { "glVertexAttrib4dNV", 621 },
1231 { "glVertexAttrib4dvNV", 622 },
1232 { "glVertexAttrib4fNV", 623 },
1233 { "glVertexAttrib4fvNV", 624 },
1234 { "glVertexAttrib4sNV", 625 },
1235 { "glVertexAttrib4svNV", 626 },
1236 { "glVertexAttrib4ubNV", 627 },
1237 { "glVertexAttrib4ubvNV", 628 },
1238 { "glVertexAttribs1dvNV", 629 },
1239 { "glVertexAttribs1fvNV", 630 },
1240 { "glVertexAttribs1svNV", 631 },
1241 { "glVertexAttribs2dvNV", 632 },
1242 { "glVertexAttribs2fvNV", 633 },
1243 { "glVertexAttribs2svNV", 634 },
1244 { "glVertexAttribs3dvNV", 635 },
1245 { "glVertexAttribs3fvNV", 636 },
1246 { "glVertexAttribs3svNV", 637 },
1247 { "glVertexAttribs4dvNV", 638 },
1248 { "glVertexAttribs4fvNV", 639 },
1249 { "glVertexAttribs4svNV", 640 },
1250 { "glVertexAttribs4ubvNV", 641 },
Brian Paulf44898c2003-07-18 15:44:57 +00001251#endif
Ian Romanick3baefe62003-08-22 23:28:03 +00001252 { "glPointParameteriNV", 642 },
1253 { "glPointParameterivNV", 643 },
1254 { "glMultiDrawArraysEXT", 644 },
1255 { "glMultiDrawElementsEXT", 645 },
1256 { "glMultiDrawArraysSUN", _gloffset_MultiDrawArraysEXT },
1257 { "glMultiDrawElementsSUN", _gloffset_MultiDrawElementsEXT },
1258 { "glActiveStencilFaceEXT", 646 },
Brian Paulf44898c2003-07-18 15:44:57 +00001259#if FEATURE_NV_fence
Ian Romanick3baefe62003-08-22 23:28:03 +00001260 { "glDeleteFencesNV", 647 },
1261 { "glGenFencesNV", 648 },
1262 { "glIsFenceNV", 649 },
1263 { "glTestFenceNV", 650 },
1264 { "glGetFenceivNV", 651 },
1265 { "glFinishFenceNV", 652 },
1266 { "glSetFenceNV", 653 },
Brian Paulf44898c2003-07-18 15:44:57 +00001267#endif
1268#if FEATURE_NV_fragment_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001269 { "glProgramNamedParameter4fNV", 682 },
1270 { "glProgramNamedParameter4dNV", 683 },
1271 { "glProgramNamedParameter4fvNV", 683 },
1272 { "glProgramNamedParameter4dvNV", 684 },
1273 { "glGetProgramNamedParameterfvNV", 685 },
1274 { "glGetProgramNamedParameterdvNV", 686 },
Brian Paulf44898c2003-07-18 15:44:57 +00001275#endif
1276#if FEATURE_ARB_vertex_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001277 { "glVertexAttrib1sARB", _gloffset_VertexAttrib1sNV },
1278 { "glVertexAttrib1fARB", _gloffset_VertexAttrib1fNV },
1279 { "glVertexAttrib1dARB", _gloffset_VertexAttrib1dNV },
1280 { "glVertexAttrib2sARB", _gloffset_VertexAttrib2sNV },
1281 { "glVertexAttrib2fARB", _gloffset_VertexAttrib2fNV },
1282 { "glVertexAttrib2dARB", _gloffset_VertexAttrib2dNV },
1283 { "glVertexAttrib3sARB", _gloffset_VertexAttrib3sNV },
1284 { "glVertexAttrib3fARB", _gloffset_VertexAttrib3fNV },
1285 { "glVertexAttrib3dARB", _gloffset_VertexAttrib3dNV },
1286 { "glVertexAttrib4sARB", _gloffset_VertexAttrib4sNV },
1287 { "glVertexAttrib4fARB", _gloffset_VertexAttrib4fNV },
1288 { "glVertexAttrib4dARB", _gloffset_VertexAttrib4dNV },
1289 { "glVertexAttrib4NubARB", _gloffset_VertexAttrib4ubNV },
1290 { "glVertexAttrib1svARB", _gloffset_VertexAttrib1svNV },
1291 { "glVertexAttrib1fvARB", _gloffset_VertexAttrib1fvNV },
1292 { "glVertexAttrib1dvARB", _gloffset_VertexAttrib1dvNV },
1293 { "glVertexAttrib2svARB", _gloffset_VertexAttrib2svNV },
1294 { "glVertexAttrib2fvARB", _gloffset_VertexAttrib2fvNV },
1295 { "glVertexAttrib2dvARB", _gloffset_VertexAttrib2dvNV },
1296 { "glVertexAttrib3svARB", _gloffset_VertexAttrib3svNV },
1297 { "glVertexAttrib3fvARB", _gloffset_VertexAttrib3fvNV },
1298 { "glVertexAttrib3dvARB", _gloffset_VertexAttrib3dvNV },
1299 { "glVertexAttrib4bvARB", _gloffset_VertexAttrib4bvARB },
1300 { "glVertexAttrib4svARB", _gloffset_VertexAttrib4svNV },
1301 { "glVertexAttrib4ivARB", _gloffset_VertexAttrib4ivARB },
1302 { "glVertexAttrib4ubvARB", _gloffset_VertexAttrib4ubvARB },
1303 { "glVertexAttrib4usvARB", _gloffset_VertexAttrib4usvARB },
1304 { "glVertexAttrib4uivARB", _gloffset_VertexAttrib4uivARB },
1305 { "glVertexAttrib4fvARB", _gloffset_VertexAttrib4fvNV },
1306 { "glVertexAttrib4dvARB", _gloffset_VertexAttrib4dvNV },
1307 { "glVertexAttrib4NbvARB", _gloffset_VertexAttrib4NbvARB },
1308 { "glVertexAttrib4NsvARB", _gloffset_VertexAttrib4NsvARB },
1309 { "glVertexAttrib4NivARB", _gloffset_VertexAttrib4NivARB },
1310 { "glVertexAttrib4NubvARB", _gloffset_VertexAttrib4ubvNV },
1311 { "glVertexAttrib4NusvARB", _gloffset_VertexAttrib4NusvARB },
1312 { "glVertexAttrib4NuivARB", _gloffset_VertexAttrib4NuivARB },
1313 { "glVertexAttribPointerARB", _gloffset_VertexAttribPointerARB },
1314 { "glEnableVertexAttribArrayARB", _gloffset_EnableVertexAttribArrayARB },
1315 { "glDisableVertexAttribArrayARB", _gloffset_DisableVertexAttribArrayARB },
1316 { "glProgramStringARB", _gloffset_ProgramStringARB },
1317 { "glBindProgramARB", _gloffset_BindProgramNV },
1318 { "glDeleteProgramsARB", _gloffset_DeleteProgramsNV },
1319 { "glGenProgramsARB", _gloffset_GenProgramsNV },
1320 { "glIsProgramARB", _gloffset_IsProgramNV },
1321 { "glProgramEnvParameter4dARB", _gloffset_ProgramEnvParameter4dARB },
1322 { "glProgramEnvParameter4dvARB", _gloffset_ProgramEnvParameter4dvARB },
1323 { "glProgramEnvParameter4fARB", _gloffset_ProgramEnvParameter4fARB },
1324 { "glProgramEnvParameter4fvARB", _gloffset_ProgramEnvParameter4fvARB },
1325 { "glProgramLocalParameter4dARB", _gloffset_ProgramLocalParameter4dARB },
1326 { "glProgramLocalParameter4dvARB", _gloffset_ProgramLocalParameter4dvARB },
1327 { "glProgramLocalParameter4fARB", _gloffset_ProgramLocalParameter4fARB },
1328 { "glProgramLocalParameter4fvARB", _gloffset_ProgramLocalParameter4fvARB },
1329 { "glGetProgramEnvParameterdvARB", _gloffset_GetProgramEnvParameterdvARB },
1330 { "glGetProgramEnvParameterfvARB", _gloffset_GetProgramEnvParameterfvARB },
1331 { "glGetProgramLocalParameterdvARB", _gloffset_GetProgramLocalParameterdvARB },
1332 { "glGetProgramLocalParameterfvARB", _gloffset_GetProgramLocalParameterfvARB },
1333 { "glGetProgramivARB", _gloffset_GetProgramivARB },
1334 { "glGetProgramStringARB", _gloffset_GetProgramStringARB },
1335 { "glGetVertexAttribdvARB", _gloffset_GetVertexAttribdvNV },
1336 { "glGetVertexAttribfvARB", _gloffset_GetVertexAttribfvNV },
1337 { "glGetVertexAttribivARB", _gloffset_GetVertexAttribivNV },
1338 { "glGetVertexAttribPointervARB", _gloffset_GetVertexAttribPointervNV },
Brian Paulf44898c2003-07-18 15:44:57 +00001339#endif
Ian Romanick3baefe62003-08-22 23:28:03 +00001340 { "glMultiModeDrawArraysIBM", _gloffset_MultiModeDrawArraysIBM },
1341 { "glMultiModeDrawElementsIBM", _gloffset_MultiModeDrawElementsIBM },
1342 };
1343
1344 for ( i = 0 ; i < Elements(newer_entrypoints) ; i++ ) {
1345 _glapi_add_entrypoint( newer_entrypoints[i].name,
1346 newer_entrypoints[i].offset );
1347 }
Brian Paulf44898c2003-07-18 15:44:57 +00001348}
1349
Keith Whitwell306d3fc2002-04-09 16:56:50 +00001350
Brian Paulde4f4602003-07-03 02:15:06 +00001351/**
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001352 * Initialize a GLcontext struct (rendering context).
Keith Whitwell6dc85572003-07-17 13:43:59 +00001353 *
1354 * This includes allocating all the other structs and arrays which hang off of
1355 * the context by pointers.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001356 * Note that the driver needs to pass in its dd_function_table here since
1357 * we need to at least call driverFunctions->NewTextureObject to create the
1358 * default texture objects.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001359 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001360 * Called by _mesa_create_context().
Keith Whitwell6dc85572003-07-17 13:43:59 +00001361 *
1362 * Performs the imports and exports callback tables initialization, and
1363 * miscellaneous one-time initializations. If no shared context is supplied one
1364 * is allocated, and increase its reference count. Setups the GL API dispatch
1365 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
1366 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1367 * for debug flags.
1368 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001369 * \param ctx the context to initialize
1370 * \param visual describes the visual attributes for this context
1371 * \param share_list points to context to share textures, display lists,
1372 * etc with, or NULL
1373 * \param driverFunctions table of device driver functions for this context
1374 * to use
1375 * \param driverContext pointer to driver-specific context data
jtgafb833d1999-08-19 00:55:39 +00001376 */
Brian Paul178a1c52000-04-22 01:05:00 +00001377GLboolean
1378_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001379 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001380 GLcontext *share_list,
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001381 const struct dd_function_table *driverFunctions,
1382 void *driverContext )
jtgafb833d1999-08-19 00:55:39 +00001383{
Brian Paul5fb84d22000-05-24 15:04:45 +00001384 GLuint dispatchSize;
1385
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001386 ASSERT(driverContext);
1387 assert(driverFunctions->NewTextureObject);
jtgafb833d1999-08-19 00:55:39 +00001388
Brian Paul3c634522002-10-24 23:57:19 +00001389 /* If the driver wants core Mesa to use special imports, it'll have to
1390 * override these defaults.
1391 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001392 _mesa_init_default_imports( &(ctx->imports), driverContext );
jtgafb833d1999-08-19 00:55:39 +00001393
Brian Paul9a33a112002-06-13 04:28:29 +00001394 /* initialize the exports (Mesa functions called by the window system) */
Brian Paul4753d602002-06-15 02:38:15 +00001395 _mesa_init_default_exports( &(ctx->exports) );
1396
1397 /* misc one-time initializations */
1398 one_time_init(ctx);
Brian Paul9a33a112002-06-13 04:28:29 +00001399
Brian Paulb1394fa2000-09-26 20:53:53 +00001400 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001401 ctx->DrawBuffer = NULL;
1402 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001403
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001404 /* Plug in driver functions and context pointer here.
1405 * This is important because when we call alloc_shared_state() below
1406 * we'll call ctx->Driver.NewTextureObject() to create the default
1407 * textures.
Brian Paula3f13702003-04-01 16:41:50 +00001408 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001409 ctx->Driver = *driverFunctions;
1410 ctx->DriverCtx = driverContext;
Brian Paula3f13702003-04-01 16:41:50 +00001411
jtgafb833d1999-08-19 00:55:39 +00001412 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001413 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001414 ctx->Shared = share_list->Shared;
1415 }
1416 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001417 /* allocate new, unshared state */
Brian Paula3f13702003-04-01 16:41:50 +00001418 if (!alloc_shared_state( ctx )) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001419 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001420 }
1421 }
Brian Paul9560f052000-01-31 23:11:39 +00001422 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001423 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001424 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001425
Keith Whitwell6dc85572003-07-17 13:43:59 +00001426 if (!init_attrib_groups( ctx )) {
jtgafb833d1999-08-19 00:55:39 +00001427 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001428 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001429 }
jtgafb833d1999-08-19 00:55:39 +00001430
Brian Paulf44898c2003-07-18 15:44:57 +00001431 /* libGL ABI coordination */
1432 add_newer_entrypoints();
Keith Whitwell6dc85572003-07-17 13:43:59 +00001433
Brian Paul5fb84d22000-05-24 15:04:45 +00001434 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1435 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1436 * Mesa we do this to accomodate different versions of libGL and various
1437 * DRI drivers.
1438 */
1439 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1440 sizeof(struct _glapi_table) / sizeof(void *));
1441
Brian Paulfbd8f211999-11-11 01:22:25 +00001442 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001443 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1444 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001445 if (!ctx->Exec || !ctx->Save) {
1446 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001447 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001448 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001449 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001450 _mesa_init_exec_table(ctx->Exec, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001451 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001452
Keith Whitwell6dc85572003-07-17 13:43:59 +00001453#if _HAVE_FULL_GL
1454 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Keith Whitwellae0eaf92003-11-24 15:23:18 +00001455 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001456
Keith Whitwellad2ac212000-11-24 10:25:05 +00001457
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001458 /* Neutral tnl module stuff */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001459 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001460 ctx->TnlModule.Current = NULL;
1461 ctx->TnlModule.SwapCount = 0;
Keith Whitwell6dc85572003-07-17 13:43:59 +00001462#endif
Brian Paulb6bcae52001-01-23 23:39:36 +00001463
Brian Paul4d053dd2000-01-14 04:45:47 +00001464 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001465}
1466
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001467
Brian Paulde4f4602003-07-03 02:15:06 +00001468/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001469 * Allocate and initialize a GLcontext structure.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001470 * Note that the driver needs to pass in its dd_function_table here since
1471 * we need to at least call driverFunctions->NewTextureObject to initialize
1472 * the rendering context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001473 *
1474 * \param visual a GLvisual pointer (we copy the struct contents)
1475 * \param share_list another context to share display lists with or NULL
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001476 * \param driverFunctions points to the dd_function_table into which the
1477 * driver has plugged in all its special functions.
1478 * \param driverCtx points to the device driver's private context state
Keith Whitwell6dc85572003-07-17 13:43:59 +00001479 *
1480 * \return pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001481 */
Brian Paul178a1c52000-04-22 01:05:00 +00001482GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001483_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001484 GLcontext *share_list,
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001485 const struct dd_function_table *driverFunctions,
1486 void *driverContext )
Brian Paul3c634522002-10-24 23:57:19 +00001487
Brian Paul4d053dd2000-01-14 04:45:47 +00001488{
Brian Paul4753d602002-06-15 02:38:15 +00001489 GLcontext *ctx;
1490
1491 ASSERT(visual);
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001492 ASSERT(driverContext);
Brian Paul4753d602002-06-15 02:38:15 +00001493
Brian Paul3c634522002-10-24 23:57:19 +00001494 ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
Brian Paul4753d602002-06-15 02:38:15 +00001495 if (!ctx)
Brian Paul4d053dd2000-01-14 04:45:47 +00001496 return NULL;
Brian Paul4753d602002-06-15 02:38:15 +00001497
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001498 if (_mesa_initialize_context(ctx, visual, share_list,
1499 driverFunctions, driverContext)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001500 return ctx;
1501 }
1502 else {
Brian Paul3c634522002-10-24 23:57:19 +00001503 _mesa_free(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001504 return NULL;
1505 }
1506}
1507
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001508
Keith Whitwell6dc85572003-07-17 13:43:59 +00001509/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001510 * Free the data associated with the given context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001511 *
1512 * But doesn't free the GLcontext struct itself.
1513 *
1514 * \sa _mesa_initialize_context() and init_attrib_groups().
Brian Paul4d053dd2000-01-14 04:45:47 +00001515 */
Brian Paul178a1c52000-04-22 01:05:00 +00001516void
Brian Paulb1394fa2000-09-26 20:53:53 +00001517_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001518{
Brian Paul4d053dd2000-01-14 04:45:47 +00001519 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001520 if (ctx == _mesa_get_current_context()) {
1521 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001522 }
1523
Keith Whitwell6dc85572003-07-17 13:43:59 +00001524 _mesa_free_lighting_data( ctx );
1525 _mesa_free_eval_data( ctx );
1526 _mesa_free_texture_data( ctx );
1527 _mesa_free_matrix_data( ctx );
1528 _mesa_free_viewport_data( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001529 _mesa_free_colortables_data( ctx );
Brian Paul8dfc5b92002-10-16 17:57:51 +00001530#if FEATURE_NV_vertex_program
Brian Paul30f51ae2001-12-18 04:06:44 +00001531 if (ctx->VertexProgram.Current) {
Brian Paul610d5992003-01-14 04:55:45 +00001532 ctx->VertexProgram.Current->Base.RefCount--;
1533 if (ctx->VertexProgram.Current->Base.RefCount <= 0)
Brian Paul4d859f72004-01-23 18:57:05 +00001534 ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
Brian Paul610d5992003-01-14 04:55:45 +00001535 }
1536#endif
1537#if FEATURE_NV_fragment_program
1538 if (ctx->FragmentProgram.Current) {
1539 ctx->FragmentProgram.Current->Base.RefCount--;
1540 if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
Brian Paul4d859f72004-01-23 18:57:05 +00001541 ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
Brian Paulfd284452001-07-19 15:54:34 +00001542 }
Brian Paul8dfc5b92002-10-16 17:57:51 +00001543#endif
Brian Paulfd284452001-07-19 15:54:34 +00001544
Brian Paul30f51ae2001-12-18 04:06:44 +00001545 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001546 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001547 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001548 assert(ctx->Shared->RefCount >= 0);
1549 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1550 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001551 /* free shared state */
1552 free_shared_state( ctx, ctx->Shared );
1553 }
1554
Brian Paul702ca202003-07-18 15:22:16 +00001555 if (ctx->Extensions.String)
1556 FREE((void *) ctx->Extensions.String);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001557
1558 FREE(ctx->Exec);
1559 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001560}
1561
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001562
Keith Whitwell6dc85572003-07-17 13:43:59 +00001563/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001564 * Destroy a GLcontext structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001565 *
1566 * \param ctx GL context.
1567 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001568 * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
jtgafb833d1999-08-19 00:55:39 +00001569 */
Brian Paul178a1c52000-04-22 01:05:00 +00001570void
Brian Paulb1394fa2000-09-26 20:53:53 +00001571_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001572{
1573 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001574 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001575 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001576 }
1577}
1578
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001579
Keith Whitwell6dc85572003-07-17 13:43:59 +00001580#if _HAVE_FULL_GL
1581/**
jtgafb833d1999-08-19 00:55:39 +00001582 * Copy attribute groups from one context to another.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001583 *
1584 * \param src source context
1585 * \param dst destination context
1586 * \param mask bitwise OR of GL_*_BIT flags
1587 *
1588 * According to the bits specified in \p mask, copies the corresponding
1589 * attributes from \p src into \dst. For many of the attributes a simple \c
1590 * memcpy is not enough due to the existence of internal pointers in their data
1591 * structures.
jtgafb833d1999-08-19 00:55:39 +00001592 */
Brian Paul178a1c52000-04-22 01:05:00 +00001593void
Brian Paulb1394fa2000-09-26 20:53:53 +00001594_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001595{
1596 if (mask & GL_ACCUM_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001597 /* OK to memcpy */
1598 dst->Accum = src->Accum;
jtgafb833d1999-08-19 00:55:39 +00001599 }
1600 if (mask & GL_COLOR_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001601 /* OK to memcpy */
1602 dst->Color = src->Color;
jtgafb833d1999-08-19 00:55:39 +00001603 }
1604 if (mask & GL_CURRENT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001605 /* OK to memcpy */
1606 dst->Current = src->Current;
jtgafb833d1999-08-19 00:55:39 +00001607 }
1608 if (mask & GL_DEPTH_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001609 /* OK to memcpy */
1610 dst->Depth = src->Depth;
jtgafb833d1999-08-19 00:55:39 +00001611 }
1612 if (mask & GL_ENABLE_BIT) {
1613 /* no op */
1614 }
1615 if (mask & GL_EVAL_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001616 /* OK to memcpy */
1617 dst->Eval = src->Eval;
jtgafb833d1999-08-19 00:55:39 +00001618 }
1619 if (mask & GL_FOG_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001620 /* OK to memcpy */
1621 dst->Fog = src->Fog;
jtgafb833d1999-08-19 00:55:39 +00001622 }
1623 if (mask & GL_HINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001624 /* OK to memcpy */
1625 dst->Hint = src->Hint;
jtgafb833d1999-08-19 00:55:39 +00001626 }
1627 if (mask & GL_LIGHTING_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001628 GLuint i;
1629 /* begin with memcpy */
1630 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light) );
1631 /* fixup linked lists to prevent pointer insanity */
1632 make_empty_list( &(dst->Light.EnabledList) );
1633 for (i = 0; i < MAX_LIGHTS; i++) {
1634 if (dst->Light.Light[i].Enabled) {
1635 insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
1636 }
1637 }
jtgafb833d1999-08-19 00:55:39 +00001638 }
1639 if (mask & GL_LINE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001640 /* OK to memcpy */
1641 dst->Line = src->Line;
jtgafb833d1999-08-19 00:55:39 +00001642 }
1643 if (mask & GL_LIST_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001644 /* OK to memcpy */
1645 dst->List = src->List;
jtgafb833d1999-08-19 00:55:39 +00001646 }
1647 if (mask & GL_PIXEL_MODE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001648 /* OK to memcpy */
1649 dst->Pixel = src->Pixel;
jtgafb833d1999-08-19 00:55:39 +00001650 }
1651 if (mask & GL_POINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001652 /* OK to memcpy */
1653 dst->Point = src->Point;
jtgafb833d1999-08-19 00:55:39 +00001654 }
1655 if (mask & GL_POLYGON_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001656 /* OK to memcpy */
1657 dst->Polygon = src->Polygon;
jtgafb833d1999-08-19 00:55:39 +00001658 }
1659 if (mask & GL_POLYGON_STIPPLE_BIT) {
1660 /* Use loop instead of MEMCPY due to problem with Portland Group's
1661 * C compiler. Reported by John Stone.
1662 */
Brian Paul85d81602002-06-17 23:36:31 +00001663 GLuint i;
1664 for (i = 0; i < 32; i++) {
jtgafb833d1999-08-19 00:55:39 +00001665 dst->PolygonStipple[i] = src->PolygonStipple[i];
1666 }
1667 }
1668 if (mask & GL_SCISSOR_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001669 /* OK to memcpy */
1670 dst->Scissor = src->Scissor;
jtgafb833d1999-08-19 00:55:39 +00001671 }
1672 if (mask & GL_STENCIL_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001673 /* OK to memcpy */
1674 dst->Stencil = src->Stencil;
jtgafb833d1999-08-19 00:55:39 +00001675 }
1676 if (mask & GL_TEXTURE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001677 /* Cannot memcpy because of pointers */
1678 _mesa_copy_texture_state(src, dst);
jtgafb833d1999-08-19 00:55:39 +00001679 }
1680 if (mask & GL_TRANSFORM_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001681 /* OK to memcpy */
1682 dst->Transform = src->Transform;
jtgafb833d1999-08-19 00:55:39 +00001683 }
1684 if (mask & GL_VIEWPORT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001685 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1686 dst->Viewport.X = src->Viewport.X;
1687 dst->Viewport.Y = src->Viewport.Y;
1688 dst->Viewport.Width = src->Viewport.Width;
1689 dst->Viewport.Height = src->Viewport.Height;
1690 dst->Viewport.Near = src->Viewport.Near;
1691 dst->Viewport.Far = src->Viewport.Far;
1692 _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001693 }
Brian Paul85d81602002-06-17 23:36:31 +00001694
Keith Whitwella96308c2000-10-30 13:31:59 +00001695 /* XXX FIXME: Call callbacks?
1696 */
1697 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001698}
Keith Whitwell23caf202000-11-16 21:05:34 +00001699#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001700
1701
Brian Paulb1d53d92003-06-11 18:48:19 +00001702/**
1703 * Check if the given context can render into the given framebuffer
1704 * by checking visual attributes.
1705 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1706 */
1707static GLboolean
1708check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
1709{
1710 const GLvisual *ctxvis = &ctx->Visual;
1711 const GLvisual *bufvis = &buffer->Visual;
1712
1713 if (ctxvis == bufvis)
1714 return GL_TRUE;
1715
1716 if (ctxvis->rgbMode != bufvis->rgbMode)
1717 return GL_FALSE;
1718 if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
1719 return GL_FALSE;
1720 if (ctxvis->stereoMode && !bufvis->stereoMode)
1721 return GL_FALSE;
1722 if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
1723 return GL_FALSE;
1724 if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
1725 return GL_FALSE;
1726 if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
1727 return GL_FALSE;
1728 if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
1729 return GL_FALSE;
1730 if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
1731 return GL_FALSE;
1732 if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
1733 return GL_FALSE;
1734 if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
1735 return GL_FALSE;
1736 if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
1737 return GL_FALSE;
1738
1739 return GL_TRUE;
1740}
1741
1742
Keith Whitwell6dc85572003-07-17 13:43:59 +00001743/**
Brian Paul9a33a112002-06-13 04:28:29 +00001744 * Set the current context, binding the given frame buffer to the context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001745 *
1746 * \param newCtx new GL context.
1747 * \param buffer framebuffer.
1748 *
1749 * Calls _mesa_make_current2() with \p buffer as read and write framebuffer.
Brian Paul9a33a112002-06-13 04:28:29 +00001750 */
1751void
1752_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1753{
1754 _mesa_make_current2( newCtx, buffer, buffer );
1755}
1756
Keith Whitwell6dc85572003-07-17 13:43:59 +00001757/**
1758 * Bind the given context to the given draw-buffer and read-buffer and
1759 * make it the current context for this thread.
1760 *
1761 * \param newCtx new GL context. If NULL then there will be no current GL
1762 * context.
1763 * \param drawBuffer draw framebuffer.
1764 * \param readBuffer read framebuffer.
1765 *
1766 * Check that the context's and framebuffer's visuals are compatible, returning
1767 * immediately otherwise. Sets the glapi current context via
1768 * _glapi_set_context(). If \p newCtx is not NULL, associates \p drawBuffer and
1769 * \p readBuffer with it and calls dd_function_table::ResizeBuffers if the buffers size has changed.
1770 * Calls dd_function_table::MakeCurrent callback if defined.
1771 *
1772 * When a context is bound by the first time and the \c MESA_INFO environment
1773 * variable is set it calls print_info() as an aid for remote user
1774 * troubleshooting.
Brian Paul00037781999-12-17 14:52:35 +00001775 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001776void
1777_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1778 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001779{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001780 if (MESA_VERBOSE)
Brian Paul4753d602002-06-15 02:38:15 +00001781 _mesa_debug(newCtx, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001782
Brian Paulbe3602d2001-02-28 00:27:48 +00001783 /* Check that the context's and framebuffer's visuals are compatible.
Brian Paulbe3602d2001-02-28 00:27:48 +00001784 */
Brian Paulb1d53d92003-06-11 18:48:19 +00001785 if (newCtx && drawBuffer && newCtx->DrawBuffer != drawBuffer) {
1786 if (!check_compatible(newCtx, drawBuffer))
1787 return;
1788 }
1789 if (newCtx && readBuffer && newCtx->ReadBuffer != readBuffer) {
1790 if (!check_compatible(newCtx, readBuffer))
1791 return;
Brian Paulbe3602d2001-02-28 00:27:48 +00001792 }
1793
Brian Paul00037781999-12-17 14:52:35 +00001794 /* We call this function periodically (just here for now) in
1795 * order to detect when multithreading has begun.
1796 */
1797 _glapi_check_multithread();
1798
Brian Paulf9b97d92000-01-28 20:17:42 +00001799 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001800 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001801
1802
1803 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001804 _glapi_set_dispatch(NULL); /* none current */
1805 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001806 else {
1807 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001808
Keith Whitwell23caf202000-11-16 21:05:34 +00001809 if (drawBuffer && readBuffer) {
1810 /* TODO: check if newCtx and buffer's visual match??? */
1811 newCtx->DrawBuffer = drawBuffer;
1812 newCtx->ReadBuffer = readBuffer;
1813 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul10d7f542002-06-17 23:38:14 +00001814
Keith Whitwell6dc85572003-07-17 13:43:59 +00001815#if _HAVE_FULL_GL
Brian Paul10d7f542002-06-17 23:38:14 +00001816 if (drawBuffer->Width == 0 && drawBuffer->Height == 0) {
1817 /* get initial window size */
1818 GLuint bufWidth, bufHeight;
1819
1820 /* ask device driver for size of output buffer */
1821 (*newCtx->Driver.GetBufferSize)( drawBuffer, &bufWidth, &bufHeight );
1822
Keith Whitwell6dc85572003-07-17 13:43:59 +00001823 if (drawBuffer->Width != bufWidth ||
1824 drawBuffer->Height != bufHeight) {
Brian Paul10d7f542002-06-17 23:38:14 +00001825
Keith Whitwell6dc85572003-07-17 13:43:59 +00001826 drawBuffer->Width = bufWidth;
1827 drawBuffer->Height = bufHeight;
Brian Paul10d7f542002-06-17 23:38:14 +00001828
Keith Whitwell6dc85572003-07-17 13:43:59 +00001829 newCtx->Driver.ResizeBuffers( drawBuffer );
1830 }
Brian Paul10d7f542002-06-17 23:38:14 +00001831 }
1832
1833 if (readBuffer != drawBuffer &&
1834 readBuffer->Width == 0 && readBuffer->Height == 0) {
1835 /* get initial window size */
1836 GLuint bufWidth, bufHeight;
1837
1838 /* ask device driver for size of output buffer */
1839 (*newCtx->Driver.GetBufferSize)( readBuffer, &bufWidth, &bufHeight );
1840
Keith Whitwell6dc85572003-07-17 13:43:59 +00001841 if (readBuffer->Width != bufWidth ||
1842 readBuffer->Height != bufHeight) {
Brian Paul10d7f542002-06-17 23:38:14 +00001843
Keith Whitwell6dc85572003-07-17 13:43:59 +00001844 readBuffer->Width = bufWidth;
1845 readBuffer->Height = bufHeight;
Brian Paul10d7f542002-06-17 23:38:14 +00001846
Keith Whitwell6dc85572003-07-17 13:43:59 +00001847 newCtx->Driver.ResizeBuffers( readBuffer );
1848 }
Brian Paul10d7f542002-06-17 23:38:14 +00001849 }
Keith Whitwell6dc85572003-07-17 13:43:59 +00001850#endif
Brian Paul00037781999-12-17 14:52:35 +00001851 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001852
Keith Whitwell6dc85572003-07-17 13:43:59 +00001853 /* Alert the driver - usually passed on to the sw t&l module,
1854 * but also used to detect threaded cases in the radeon codegen
1855 * hw t&l module.
1856 */
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001857 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001858 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1859
1860 /* We can use this to help debug user's problems. Tell them to set
1861 * the MESA_INFO env variable before running their app. Then the
1862 * first time each context is made current we'll print some useful
1863 * information.
1864 */
1865 if (newCtx->FirstTimeCurrent) {
Brian Paul3c634522002-10-24 23:57:19 +00001866 if (_mesa_getenv("MESA_INFO")) {
Keith Whitwell6dc85572003-07-17 13:43:59 +00001867 _mesa_print_info();
Keith Whitwell23caf202000-11-16 21:05:34 +00001868 }
1869 newCtx->FirstTimeCurrent = GL_FALSE;
1870 }
Brian Paul00037781999-12-17 14:52:35 +00001871 }
1872}
1873
Keith Whitwell6dc85572003-07-17 13:43:59 +00001874/**
1875 * Get current context for the calling thread.
1876 *
1877 * \return pointer to the current GL context.
1878 *
1879 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1880 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in context.h.
Brian Paul00037781999-12-17 14:52:35 +00001881 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001882GLcontext *
1883_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001884{
Brian Paulf9b97d92000-01-28 20:17:42 +00001885 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001886}
1887
Keith Whitwell6dc85572003-07-17 13:43:59 +00001888/**
1889 * Get context's current API dispatch table.
1890 *
1891 * It'll either be the immediate-mode execute dispatcher or the display list
1892 * compile dispatcher.
1893 *
1894 * \param ctx GL context.
1895 *
1896 * \return pointer to dispatch_table.
1897 *
1898 * Simply returns __GLcontextRec::CurrentDispatch.
Brian Paulfbd8f211999-11-11 01:22:25 +00001899 */
1900struct _glapi_table *
1901_mesa_get_dispatch(GLcontext *ctx)
1902{
1903 return ctx->CurrentDispatch;
1904}
1905
Keith Whitwell6dc85572003-07-17 13:43:59 +00001906/*@}*/
Brian Paulfbd8f211999-11-11 01:22:25 +00001907
1908
jtgafb833d1999-08-19 00:55:39 +00001909/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001910/** \name Miscellaneous functions */
jtgafb833d1999-08-19 00:55:39 +00001911/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001912/*@{*/
jtgafb833d1999-08-19 00:55:39 +00001913
Keith Whitwell6dc85572003-07-17 13:43:59 +00001914/**
1915 * Record an error.
1916 *
1917 * \param ctx GL context.
1918 * \param error error code.
1919 *
1920 * Records the given error code and call the driver's dd_function_table::Error
1921 * function if defined.
1922 *
1923 * \sa
Brian Paul4e9676f2002-06-29 19:48:15 +00001924 * This is called via _mesa_error().
jtgafb833d1999-08-19 00:55:39 +00001925 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001926void
Brian Paul4e9676f2002-06-29 19:48:15 +00001927_mesa_record_error( GLcontext *ctx, GLenum error )
jtgafb833d1999-08-19 00:55:39 +00001928{
Brian Paul18a285a2002-03-16 00:53:15 +00001929 if (!ctx)
1930 return;
1931
Brian Paul7eb06032000-07-14 04:13:40 +00001932 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00001933 ctx->ErrorValue = error;
1934 }
1935
1936 /* Call device driver's error handler, if any. This is used on the Mac. */
1937 if (ctx->Driver.Error) {
1938 (*ctx->Driver.Error)( ctx );
1939 }
1940}
1941
Keith Whitwell6dc85572003-07-17 13:43:59 +00001942/**
1943 * Execute glFinish().
1944 *
1945 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1946 * dd_function_table::Finish driver callback, if not NULL.
1947 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001948void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +00001949_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00001950{
Brian Paulfa9df402000-02-02 19:16:46 +00001951 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001952 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001953 if (ctx->Driver.Finish) {
1954 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001955 }
1956}
1957
Keith Whitwell6dc85572003-07-17 13:43:59 +00001958/**
1959 * Execute glFlush().
1960 *
1961 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1962 * dd_function_table::Flush driver callback, if not NULL.
1963 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001964void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +00001965_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00001966{
Brian Paulfa9df402000-02-02 19:16:46 +00001967 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001968 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001969 if (ctx->Driver.Flush) {
1970 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001971 }
jtgafb833d1999-08-19 00:55:39 +00001972}
Brian Paul48c6a6e2000-09-08 21:28:04 +00001973
1974
Keith Whitwell6dc85572003-07-17 13:43:59 +00001975/*@}*/