blob: 2328b3726ec38f989ad14d7f8d868467029aabf1 [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"
jtgafb833d1999-08-19 00:55:39 +0000112#include "teximage.h"
113#include "texobj.h"
Brian Paul85d81602002-06-17 23:36:31 +0000114#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000115#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +0000116#include "varray.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +0000117#include "vtxfmt.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000118#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000119#include "math/m_translate.h"
Keith Whitwell23caf202000-11-16 21:05:34 +0000120#include "math/m_matrix.h"
121#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +0000122#include "math/mathmod.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000123#endif
jtgafb833d1999-08-19 00:55:39 +0000124
davem69775355a2001-06-05 23:54:00 +0000125#ifdef USE_SPARC_ASM
126#include "SPARC/sparc.h"
127#endif
jtgafb833d1999-08-19 00:55:39 +0000128
Keith Whitwell23caf202000-11-16 21:05:34 +0000129#ifndef MESA_VERBOSE
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000130int MESA_VERBOSE = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000131#endif
132
133#ifndef MESA_DEBUG_FLAGS
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000134int MESA_DEBUG_FLAGS = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000135#endif
Brian Paulb1394fa2000-09-26 20:53:53 +0000136
Brian Paul86b84272001-12-14 02:50:01 +0000137
Brian Paul27558a12003-03-01 01:50:20 +0000138/* ubyte -> float conversion */
139GLfloat _mesa_ubyte_to_float_color_tab[256];
140
Brian Paul9a33a112002-06-13 04:28:29 +0000141static void
142free_shared_state( GLcontext *ctx, struct gl_shared_state *ss );
143
Brian Paul86b84272001-12-14 02:50:01 +0000144
Brian Paulb1394fa2000-09-26 20:53:53 +0000145/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000146/** \name OpenGL SI-style interface (new in Mesa 3.5)
147 *
148 * \if subset
149 * \note Most of these functions are never called in the Mesa subset.
150 * \endif
151 */
152/*@{*/
Brian Paulb1394fa2000-09-26 20:53:53 +0000153
Keith Whitwell6dc85572003-07-17 13:43:59 +0000154/**
155 * Destroy context callback.
156 *
157 * \param gc context.
158 * \return GL_TRUE on success, or GL_FALSE on failure.
159 *
160 * \ifnot subset
161 * Called by window system/device driver (via __GLexports::destroyCurrent) when
162 * the rendering context is to be destroyed.
163 * \endif
164 *
165 * Frees the context data and the context structure.
Brian Paul9a33a112002-06-13 04:28:29 +0000166 */
167GLboolean
168_mesa_destroyContext(__GLcontext *gc)
Brian Paulb1394fa2000-09-26 20:53:53 +0000169{
170 if (gc) {
171 _mesa_free_context_data(gc);
Brian Paul3c634522002-10-24 23:57:19 +0000172 _mesa_free(gc);
Brian Paulb1394fa2000-09-26 20:53:53 +0000173 }
174 return GL_TRUE;
175}
176
Keith Whitwell6dc85572003-07-17 13:43:59 +0000177/**
178 * Unbind context callback.
179 *
180 * \param gc context.
181 * \return GL_TRUE on success, or GL_FALSE on failure.
182 *
183 * \ifnot subset
184 * Called by window system/device driver (via __GLexports::loseCurrent)
Brian Paul9a33a112002-06-13 04:28:29 +0000185 * when the rendering context is made non-current.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000186 * \endif
187 *
188 * No-op
Brian Paul9a33a112002-06-13 04:28:29 +0000189 */
190GLboolean
191_mesa_loseCurrent(__GLcontext *gc)
192{
193 /* XXX unbind context from thread */
194 return GL_TRUE;
195}
196
Keith Whitwell6dc85572003-07-17 13:43:59 +0000197/**
198 * Bind context callback.
199 *
200 * \param gc context.
201 * \return GL_TRUE on success, or GL_FALSE on failure.
202 *
203 * \ifnot subset
204 * Called by window system/device driver (via __GLexports::makeCurrent)
Brian Paul9a33a112002-06-13 04:28:29 +0000205 * when the rendering context is made current.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000206 * \endif
207 *
208 * No-op
Brian Paul9a33a112002-06-13 04:28:29 +0000209 */
210GLboolean
211_mesa_makeCurrent(__GLcontext *gc)
212{
213 /* XXX bind context to thread */
214 return GL_TRUE;
215}
216
Keith Whitwell6dc85572003-07-17 13:43:59 +0000217/**
218 * Share context callback.
219 *
220 * \param gc context.
221 * \param gcShare shared context.
222 * \return GL_TRUE on success, or GL_FALSE on failure.
223 *
224 * \ifnot subset
225 * Called by window system/device driver (via __GLexports::shareContext)
226 * \endif
227 *
228 * Update the shared context reference count, gl_shared_state::RefCount.
Brian Paul9a33a112002-06-13 04:28:29 +0000229 */
230GLboolean
231_mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare)
232{
233 if (gc && gcShare && gc->Shared && gcShare->Shared) {
234 gc->Shared->RefCount--;
235 if (gc->Shared->RefCount == 0) {
236 free_shared_state(gc, gc->Shared);
237 }
238 gc->Shared = gcShare->Shared;
239 gc->Shared->RefCount++;
240 return GL_TRUE;
241 }
242 else {
243 return GL_FALSE;
244 }
245}
246
Keith Whitwell6dc85572003-07-17 13:43:59 +0000247
248#if _HAVE_FULL_GL
249/**
250 * Copy context callback.
251 */
Brian Paul9a33a112002-06-13 04:28:29 +0000252GLboolean
253_mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask)
254{
255 if (dst && src) {
256 _mesa_copy_context( src, dst, mask );
257 return GL_TRUE;
258 }
259 else {
260 return GL_FALSE;
261 }
262}
Keith Whitwell6dc85572003-07-17 13:43:59 +0000263#endif
Brian Paul9a33a112002-06-13 04:28:29 +0000264
Keith Whitwell6dc85572003-07-17 13:43:59 +0000265/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000266GLboolean
267_mesa_forceCurrent(__GLcontext *gc)
268{
269 return GL_TRUE;
270}
271
Keith Whitwell6dc85572003-07-17 13:43:59 +0000272/**
273 * Windows/buffer resizing notification callback.
274 *
275 * \param gc GL context.
276 * \return GL_TRUE on success, or GL_FALSE on failure.
277 */
Brian Paul9a33a112002-06-13 04:28:29 +0000278GLboolean
279_mesa_notifyResize(__GLcontext *gc)
280{
281 GLint x, y;
282 GLuint width, height;
283 __GLdrawablePrivate *d = gc->imports.getDrawablePrivate(gc);
284 if (!d || !d->getDrawableSize)
285 return GL_FALSE;
286 d->getDrawableSize( d, &x, &y, &width, &height );
287 /* update viewport, resize software buffers, etc. */
288 return GL_TRUE;
289}
290
Keith Whitwell6dc85572003-07-17 13:43:59 +0000291/**
292 * Window/buffer destruction notification callback.
293 *
294 * \param gc GL context.
295 *
296 * Called when the context's window/buffer is going to be destroyed.
297 *
298 * No-op
299 */
Brian Paul9a33a112002-06-13 04:28:29 +0000300void
301_mesa_notifyDestroy(__GLcontext *gc)
302{
Brian Paul60b6e4f2002-10-14 17:08:17 +0000303 /* Unbind from it. */
Brian Paul9a33a112002-06-13 04:28:29 +0000304}
305
Keith Whitwell6dc85572003-07-17 13:43:59 +0000306/**
307 * Swap buffers notification callback.
308 *
309 * \param gc GL context.
310 *
311 * Called by window system just before swapping buffers.
Brian Paul9a33a112002-06-13 04:28:29 +0000312 * We have to finish any pending rendering.
313 */
314void
315_mesa_notifySwapBuffers(__GLcontext *gc)
316{
317 FLUSH_VERTICES( gc, 0 );
318}
319
Keith Whitwell6dc85572003-07-17 13:43:59 +0000320/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000321struct __GLdispatchStateRec *
322_mesa_dispatchExec(__GLcontext *gc)
323{
324 return NULL;
325}
326
Keith Whitwell6dc85572003-07-17 13:43:59 +0000327/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000328void
329_mesa_beginDispatchOverride(__GLcontext *gc)
330{
331}
332
Keith Whitwell6dc85572003-07-17 13:43:59 +0000333/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000334void
335_mesa_endDispatchOverride(__GLcontext *gc)
336{
337}
338
Keith Whitwell6dc85572003-07-17 13:43:59 +0000339/**
340 * \ifnot subset
341 * Setup the exports.
342 *
343 * The window system will call these functions when it needs Mesa to do
344 * something.
345 *
346 * \note Device drivers should override these functions! For example,
Brian Paul9a33a112002-06-13 04:28:29 +0000347 * the Xlib driver should plug in the XMesa*-style functions into this
348 * structure. The XMesa-style functions should then call the _mesa_*
349 * version of these functions. This is an approximation to OO design
350 * (inheritance and virtual functions).
Keith Whitwell6dc85572003-07-17 13:43:59 +0000351 * \endif
352 *
353 * \if subset
354 * No-op.
355 *
356 * \endif
Brian Paul9a33a112002-06-13 04:28:29 +0000357 */
358static void
359_mesa_init_default_exports(__GLexports *exports)
360{
Keith Whitwell6dc85572003-07-17 13:43:59 +0000361#if _HAVE_FULL_GL
Brian Paul9a33a112002-06-13 04:28:29 +0000362 exports->destroyContext = _mesa_destroyContext;
363 exports->loseCurrent = _mesa_loseCurrent;
364 exports->makeCurrent = _mesa_makeCurrent;
365 exports->shareContext = _mesa_shareContext;
366 exports->copyContext = _mesa_copyContext;
367 exports->forceCurrent = _mesa_forceCurrent;
368 exports->notifyResize = _mesa_notifyResize;
Brian Paul2f35d5e2002-06-13 04:31:09 +0000369 exports->notifyDestroy = _mesa_notifyDestroy;
Brian Paul9a33a112002-06-13 04:28:29 +0000370 exports->notifySwapBuffers = _mesa_notifySwapBuffers;
371 exports->dispatchExec = _mesa_dispatchExec;
372 exports->beginDispatchOverride = _mesa_beginDispatchOverride;
373 exports->endDispatchOverride = _mesa_endDispatchOverride;
Keith Whitwell6dc85572003-07-17 13:43:59 +0000374#endif
Brian Paul9a33a112002-06-13 04:28:29 +0000375}
376
Keith Whitwell6dc85572003-07-17 13:43:59 +0000377/**
378 * Exported OpenGL SI interface.
379 */
Brian Paulb1394fa2000-09-26 20:53:53 +0000380__GLcontext *
381__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
382{
383 GLcontext *ctx;
384
Brian Paul4753d602002-06-15 02:38:15 +0000385 ctx = (GLcontext *) (*imports->calloc)(NULL, 1, sizeof(GLcontext));
Brian Paulb1394fa2000-09-26 20:53:53 +0000386 if (ctx == NULL) {
387 return NULL;
388 }
Brian Paul60b6e4f2002-10-14 17:08:17 +0000389
Brian Pauld3fd7ba2004-01-20 02:49:27 +0000390 /* XXX doesn't work at this time */
391 _mesa_initialize_context(ctx, modes, NULL, NULL, NULL);
Brian Paulb1394fa2000-09-26 20:53:53 +0000392 ctx->imports = *imports;
Brian Paulb1394fa2000-09-26 20:53:53 +0000393
394 return ctx;
395}
396
Keith Whitwell6dc85572003-07-17 13:43:59 +0000397/**
398 * Exported OpenGL SI interface.
399 */
Brian Paulb1394fa2000-09-26 20:53:53 +0000400void
401__glCoreNopDispatch(void)
402{
403#if 0
404 /* SI */
405 __gl_dispatch = __glNopDispatchState;
406#else
407 /* Mesa */
408 _glapi_set_dispatch(NULL);
409#endif
410}
411
Keith Whitwell6dc85572003-07-17 13:43:59 +0000412/*@}*/
413
Brian Paulb1394fa2000-09-26 20:53:53 +0000414
jtgafb833d1999-08-19 00:55:39 +0000415/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000416/** \name GL Visual allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000417/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000418/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000419
Keith Whitwell6dc85572003-07-17 13:43:59 +0000420/**
Brian Paul894844a2004-03-21 17:05:03 +0000421 * Allocates a GLvisual structure and initializes it via
422 * _mesa_initialize_visual().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000423 *
424 * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
425 * \param dbFlag double buffering
426 * \param stereoFlag stereo buffer
427 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
428 * is acceptable but the actual depth type will be GLushort or GLuint as
429 * needed.
430 * \param stencilBits requested minimum bits per stencil buffer value
431 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
432 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
433 * \param redBits number of bits per color component in frame buffer for RGB(A)
434 * mode. We always use 8 in core Mesa though.
435 * \param greenBits same as above.
436 * \param blueBits same as above.
437 * \param alphaBits same as above.
438 * \param numSamples not really used.
439 *
440 * \return pointer to new GLvisual or NULL if requested parameters can't be
441 * met.
442 *
Brian Paul894844a2004-03-21 17:05:03 +0000443 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul4d053dd2000-01-14 04:45:47 +0000444 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000445GLvisual *
446_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000447 GLboolean dbFlag,
448 GLboolean stereoFlag,
449 GLint redBits,
450 GLint greenBits,
451 GLint blueBits,
452 GLint alphaBits,
453 GLint indexBits,
454 GLint depthBits,
455 GLint stencilBits,
456 GLint accumRedBits,
457 GLint accumGreenBits,
458 GLint accumBlueBits,
459 GLint accumAlphaBits,
460 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000461{
Brian Paul178a1c52000-04-22 01:05:00 +0000462 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
463 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000464 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000465 redBits, greenBits, blueBits, alphaBits,
466 indexBits, depthBits, stencilBits,
467 accumRedBits, accumGreenBits,
468 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000469 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000470 FREE(vis);
471 return NULL;
472 }
473 }
474 return vis;
475}
476
Keith Whitwell6dc85572003-07-17 13:43:59 +0000477/**
Brian Paul894844a2004-03-21 17:05:03 +0000478 * Makes some sanity checks and fills in the fields of the
479 * GLvisual structure with the given parameters.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000480 *
481 * \return GL_TRUE on success, or GL_FALSE on failure.
482 *
483 * \sa _mesa_create_visual() above for the parameter description.
484 *
Brian Paul894844a2004-03-21 17:05:03 +0000485 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul178a1c52000-04-22 01:05:00 +0000486 */
487GLboolean
488_mesa_initialize_visual( GLvisual *vis,
489 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000490 GLboolean dbFlag,
491 GLboolean stereoFlag,
492 GLint redBits,
493 GLint greenBits,
494 GLint blueBits,
495 GLint alphaBits,
496 GLint indexBits,
497 GLint depthBits,
498 GLint stencilBits,
499 GLint accumRedBits,
500 GLint accumGreenBits,
501 GLint accumBlueBits,
502 GLint accumAlphaBits,
503 GLint numSamples )
504{
505 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000506
Brian Pauled30dfa2000-03-03 17:47:39 +0000507 /* This is to catch bad values from device drivers not updated for
508 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
509 * bad value now (a 1-bit depth buffer!?!).
510 */
511 assert(depthBits == 0 || depthBits > 1);
512
513 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000514 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000515 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000516 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000517 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000518 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000519 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000520 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000521 }
522 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000523 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000524 }
525 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000526 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000527 }
528 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000529 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000530 }
531
Brian Paulb6bcae52001-01-23 23:39:36 +0000532 vis->rgbMode = rgbFlag;
533 vis->doubleBufferMode = dbFlag;
534 vis->stereoMode = stereoFlag;
Brian Paul153f1542002-10-29 15:04:35 +0000535
Brian Paulb6bcae52001-01-23 23:39:36 +0000536 vis->redBits = redBits;
537 vis->greenBits = greenBits;
538 vis->blueBits = blueBits;
539 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000540
Brian Paulb6bcae52001-01-23 23:39:36 +0000541 vis->indexBits = indexBits;
542 vis->depthBits = depthBits;
543 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
544 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
545 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
546 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
547 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000548
Brian Paul153f1542002-10-29 15:04:35 +0000549 vis->haveAccumBuffer = accumRedBits > 0;
550 vis->haveDepthBuffer = depthBits > 0;
551 vis->haveStencilBuffer = stencilBits > 0;
552
553 vis->numAuxBuffers = 0;
554 vis->level = 0;
555 vis->pixmapMode = 0;
Brian Paul894844a2004-03-21 17:05:03 +0000556 vis->samples = numSamples;
Brian Paul153f1542002-10-29 15:04:35 +0000557
Brian Paul178a1c52000-04-22 01:05:00 +0000558 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000559}
560
Brian Paul894844a2004-03-21 17:05:03 +0000561
Keith Whitwell6dc85572003-07-17 13:43:59 +0000562/**
Brian Paul894844a2004-03-21 17:05:03 +0000563 * Destroy a visual and free its memory.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000564 *
565 * \param vis visual.
566 *
567 * Frees the visual structure.
568 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000569void
570_mesa_destroy_visual( GLvisual *vis )
571{
572 FREE(vis);
573}
574
Keith Whitwell6dc85572003-07-17 13:43:59 +0000575/*@}*/
576
Brian Paulb371e0d2000-03-31 01:05:51 +0000577
Brian Paul4d053dd2000-01-14 04:45:47 +0000578/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000579/** \name GL Framebuffer allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000580/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000581/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000582
Keith Whitwell6dc85572003-07-17 13:43:59 +0000583/**
Brian Paul894844a2004-03-21 17:05:03 +0000584 * Allocate a GLframebuffer structure and initializes it via
585 * _mesa_initialize_framebuffer().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000586 *
587 * A GLframebuffer is a structure which encapsulates the depth, stencil and
588 * accum buffers and related parameters.
589 *
590 * \param visual a GLvisual pointer (we copy the struct contents)
591 * \param softwareDepth create/use a software depth buffer?
592 * \param softwareStencil create/use a software stencil buffer?
593 * \param softwareAccum create/use a software accum buffer?
594 * \param softwareAlpha create/use a software alpha buffer?
595 *
596 * \return pointer to new GLframebuffer struct or NULL if error.
597 *
Brian Paul894844a2004-03-21 17:05:03 +0000598 * \note Need to add softwareAuxBuffers parameter.
Brian Paul4d053dd2000-01-14 04:45:47 +0000599 */
Brian Paul178a1c52000-04-22 01:05:00 +0000600GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000601_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000602 GLboolean softwareDepth,
603 GLboolean softwareStencil,
604 GLboolean softwareAccum,
605 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000606{
Brian Paul178a1c52000-04-22 01:05:00 +0000607 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
608 assert(visual);
609 if (buffer) {
610 _mesa_initialize_framebuffer(buffer, visual,
611 softwareDepth, softwareStencil,
612 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000613 }
Brian Paul178a1c52000-04-22 01:05:00 +0000614 return buffer;
615}
616
Brian Paul894844a2004-03-21 17:05:03 +0000617
Keith Whitwell6dc85572003-07-17 13:43:59 +0000618/**
Keith Whitwell6dc85572003-07-17 13:43:59 +0000619 * Makes some sanity checks and fills in the fields of the
620 * GLframebuffer structure with the given parameters.
Brian Paul894844a2004-03-21 17:05:03 +0000621 *
622 * \sa _mesa_create_framebuffer() above for the parameter description.
Brian Paul178a1c52000-04-22 01:05:00 +0000623 */
624void
625_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000626 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000627 GLboolean softwareDepth,
628 GLboolean softwareStencil,
629 GLboolean softwareAccum,
630 GLboolean softwareAlpha )
631{
Brian Paul894844a2004-03-21 17:05:03 +0000632 GLboolean softwareAux = GL_FALSE;
Brian Paul178a1c52000-04-22 01:05:00 +0000633 assert(buffer);
634 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000635
Brian Paul6ec6b842002-10-30 19:49:29 +0000636 _mesa_bzero(buffer, sizeof(GLframebuffer));
Brian Paul85d81602002-06-17 23:36:31 +0000637
Brian Paul4d053dd2000-01-14 04:45:47 +0000638 /* sanity checks */
639 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000640 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000641 }
642 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000643 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000644 }
645 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000646 assert(visual->rgbMode);
647 assert(visual->accumRedBits > 0);
648 assert(visual->accumGreenBits > 0);
649 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000650 }
651 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000652 assert(visual->rgbMode);
653 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000654 }
655
Brian Paul75978bd2001-04-27 21:17:20 +0000656 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000657 buffer->UseSoftwareDepthBuffer = softwareDepth;
658 buffer->UseSoftwareStencilBuffer = softwareStencil;
659 buffer->UseSoftwareAccumBuffer = softwareAccum;
660 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul894844a2004-03-21 17:05:03 +0000661 buffer->UseSoftwareAuxBuffers = softwareAux;
Brian Paul4d053dd2000-01-14 04:45:47 +0000662}
663
Brian Paul894844a2004-03-21 17:05:03 +0000664
Keith Whitwell6dc85572003-07-17 13:43:59 +0000665/**
Brian Paul4d053dd2000-01-14 04:45:47 +0000666 * Free a framebuffer struct and its buffers.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000667 *
668 * Calls _mesa_free_framebuffer_data() and frees the structure.
Brian Paul4d053dd2000-01-14 04:45:47 +0000669 */
Brian Paul178a1c52000-04-22 01:05:00 +0000670void
Brian Paulb1394fa2000-09-26 20:53:53 +0000671_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000672{
673 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000674 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000675 FREE(buffer);
676 }
677}
678
Brian Paul894844a2004-03-21 17:05:03 +0000679
Keith Whitwell6dc85572003-07-17 13:43:59 +0000680/**
681 * Free the data hanging off of \p buffer, but not \p buffer itself.
682 *
683 * \param buffer framebuffer.
684 *
685 * Frees all the buffers associated with the structure.
Brian Paul75978bd2001-04-27 21:17:20 +0000686 */
687void
688_mesa_free_framebuffer_data( GLframebuffer *buffer )
689{
690 if (!buffer)
691 return;
692
Brian Paul87506682003-05-27 15:20:43 +0000693 if (buffer->UseSoftwareDepthBuffer && buffer->DepthBuffer) {
Brian Paulaeb44342002-03-19 16:47:04 +0000694 MESA_PBUFFER_FREE( buffer->DepthBuffer );
Brian Paul75978bd2001-04-27 21:17:20 +0000695 buffer->DepthBuffer = NULL;
696 }
Brian Paul87506682003-05-27 15:20:43 +0000697 if (buffer->UseSoftwareAccumBuffer && buffer->Accum) {
Brian Paulaeb44342002-03-19 16:47:04 +0000698 MESA_PBUFFER_FREE( buffer->Accum );
Brian Paul75978bd2001-04-27 21:17:20 +0000699 buffer->Accum = NULL;
700 }
Brian Paul87506682003-05-27 15:20:43 +0000701 if (buffer->UseSoftwareStencilBuffer && buffer->Stencil) {
Brian Paulaeb44342002-03-19 16:47:04 +0000702 MESA_PBUFFER_FREE( buffer->Stencil );
Brian Paul75978bd2001-04-27 21:17:20 +0000703 buffer->Stencil = NULL;
704 }
Brian Paul87506682003-05-27 15:20:43 +0000705 if (buffer->UseSoftwareAlphaBuffers){
706 if (buffer->FrontLeftAlpha) {
707 MESA_PBUFFER_FREE( buffer->FrontLeftAlpha );
708 buffer->FrontLeftAlpha = NULL;
709 }
710 if (buffer->BackLeftAlpha) {
711 MESA_PBUFFER_FREE( buffer->BackLeftAlpha );
712 buffer->BackLeftAlpha = NULL;
713 }
714 if (buffer->FrontRightAlpha) {
715 MESA_PBUFFER_FREE( buffer->FrontRightAlpha );
716 buffer->FrontRightAlpha = NULL;
717 }
718 if (buffer->BackRightAlpha) {
719 MESA_PBUFFER_FREE( buffer->BackRightAlpha );
720 buffer->BackRightAlpha = NULL;
721 }
Brian Paul75978bd2001-04-27 21:17:20 +0000722 }
723}
724
Keith Whitwell6dc85572003-07-17 13:43:59 +0000725/*@}*/
Brian Paul75978bd2001-04-27 21:17:20 +0000726
Brian Paul4d053dd2000-01-14 04:45:47 +0000727
728/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000729/** \name Context allocation, initialization, destroying
730 *
731 * The purpose of the most initialization functions here is to provide the
732 * default state values according to the OpenGL specification.
733 */
jtgafb833d1999-08-19 00:55:39 +0000734/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000735/*@{*/
jtgafb833d1999-08-19 00:55:39 +0000736
Keith Whitwell6dc85572003-07-17 13:43:59 +0000737/**
738 * One-time initialization mutex lock.
739 *
740 * \sa Used by one_time_init().
741 */
Brian Paul9560f052000-01-31 23:11:39 +0000742_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
743
Keith Whitwell6dc85572003-07-17 13:43:59 +0000744/**
745 * Calls all the various one-time-init functions in Mesa.
746 *
747 * While holding a global mutex lock, calls several initialization functions,
748 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
749 * defined.
750 *
751 * \sa _mesa_init_lists(), _math_init().
jtgafb833d1999-08-19 00:55:39 +0000752 */
Brian Paul178a1c52000-04-22 01:05:00 +0000753static void
Brian Paul4753d602002-06-15 02:38:15 +0000754one_time_init( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000755{
756 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000757 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000758 if (!alreadyCalled) {
Brian Paul27558a12003-03-01 01:50:20 +0000759 GLuint i;
760
Brian Paul4d053dd2000-01-14 04:45:47 +0000761 /* do some implementation tests */
762 assert( sizeof(GLbyte) == 1 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000763 assert( sizeof(GLubyte) == 1 );
Brian Paul894844a2004-03-21 17:05:03 +0000764 assert( sizeof(GLshort) == 2 );
765 assert( sizeof(GLushort) == 2 );
766 assert( sizeof(GLint) == 4 );
767 assert( sizeof(GLuint) == 4 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000768
Brian Paul08836342001-03-03 20:33:27 +0000769 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000770
Keith Whitwell6dc85572003-07-17 13:43:59 +0000771#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000772 _math_init();
Brian Paul27558a12003-03-01 01:50:20 +0000773
774 for (i = 0; i < 256; i++) {
775 _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
776 }
Keith Whitwell6dc85572003-07-17 13:43:59 +0000777#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000778
davem69775355a2001-06-05 23:54:00 +0000779#ifdef USE_SPARC_ASM
780 _mesa_init_sparc_glapi_relocs();
781#endif
Brian Paul3c634522002-10-24 23:57:19 +0000782 if (_mesa_getenv("MESA_DEBUG")) {
Brian Paul68ee4bc2000-01-28 19:02:22 +0000783 _glapi_noop_enable_warnings(GL_TRUE);
Brian Paul71072be2002-10-10 00:22:13 +0000784#ifndef GLX_DIRECT_RENDERING
785 /* libGL from before 2002/06/28 don't have this function. Someday,
786 * when newer libGL libs are common, remove the #ifdef test. This
787 * only serves to print warnings when calling undefined GL functions.
788 */
Brian Paul4e9676f2002-06-29 19:48:15 +0000789 _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
Brian Paul71072be2002-10-10 00:22:13 +0000790#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000791 }
792 else {
793 _glapi_noop_enable_warnings(GL_FALSE);
794 }
795
jtgafb833d1999-08-19 00:55:39 +0000796#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
Brian Paul4e9676f2002-06-29 19:48:15 +0000797 _mesa_debug(ctx, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
jtgafb833d1999-08-19 00:55:39 +0000798#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000799
800 alreadyCalled = GL_TRUE;
801 }
Brian Paul9560f052000-01-31 23:11:39 +0000802 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000803}
804
Brian Paul894844a2004-03-21 17:05:03 +0000805
Keith Whitwell6dc85572003-07-17 13:43:59 +0000806/**
jtgafb833d1999-08-19 00:55:39 +0000807 * Allocate and initialize a shared context state structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000808 * Initializes the display list, texture objects and vertex programs hash
809 * tables, allocates the texture objects. If it runs out of memory, frees
810 * everything already allocated before returning NULL.
Brian Paul894844a2004-03-21 17:05:03 +0000811 *
812 * \return pointer to a gl_shared_state structure on success, or NULL on
813 * failure.
jtgafb833d1999-08-19 00:55:39 +0000814 */
Brian Paula3f13702003-04-01 16:41:50 +0000815static GLboolean
816alloc_shared_state( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000817{
Brian Paula3f13702003-04-01 16:41:50 +0000818 struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000819 if (!ss)
Brian Paula3f13702003-04-01 16:41:50 +0000820 return GL_FALSE;
821
822 ctx->Shared = ss;
jtgafb833d1999-08-19 00:55:39 +0000823
Brian Paule4b684c2000-09-12 21:07:40 +0000824 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000825
Brian Paule4b684c2000-09-12 21:07:40 +0000826 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000827 ss->TexObjects = _mesa_NewHashTable();
Brian Paul451f3102003-04-17 01:48:19 +0000828#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
Brian Paul610d5992003-01-14 04:55:45 +0000829 ss->Programs = _mesa_NewHashTable();
Brian Paul8dfc5b92002-10-16 17:57:51 +0000830#endif
jtgafb833d1999-08-19 00:55:39 +0000831
Brian Paul451f3102003-04-17 01:48:19 +0000832#if FEATURE_ARB_vertex_program
Brian Paul4d859f72004-01-23 18:57:05 +0000833 ss->DefaultVertexProgram = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000834 if (!ss->DefaultVertexProgram)
835 goto cleanup;
836#endif
837#if FEATURE_ARB_fragment_program
Brian Paul4d859f72004-01-23 18:57:05 +0000838 ss->DefaultFragmentProgram = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000839 if (!ss->DefaultFragmentProgram)
840 goto cleanup;
841#endif
842
Ian Romanick0207b472003-09-09 00:10:12 +0000843 ss->BufferObjects = _mesa_NewHashTable();
844
Brian Paula3f13702003-04-01 16:41:50 +0000845 ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
846 if (!ss->Default1D)
847 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000848
Brian Paula3f13702003-04-01 16:41:50 +0000849 ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
850 if (!ss->Default2D)
851 goto cleanup;
jtgafb833d1999-08-19 00:55:39 +0000852
Brian Paula3f13702003-04-01 16:41:50 +0000853 ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
854 if (!ss->Default3D)
855 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000856
Brian Paula3f13702003-04-01 16:41:50 +0000857 ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
858 if (!ss->DefaultCubeMap)
859 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000860
Brian Paula3f13702003-04-01 16:41:50 +0000861 ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
862 if (!ss->DefaultRect)
863 goto cleanup;
Brian Paul413d6a22000-05-26 14:44:59 +0000864
Brian Paula3f13702003-04-01 16:41:50 +0000865 /* Effectively bind the default textures to all texture units */
866 ss->Default1D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
867 ss->Default2D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
868 ss->Default3D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
869 ss->DefaultCubeMap->RefCount += MAX_TEXTURE_IMAGE_UNITS;
870 ss->DefaultRect->RefCount += MAX_TEXTURE_IMAGE_UNITS;
871
872 return GL_TRUE;
873
874 cleanup:
875 /* Ran out of memory at some point. Free everything and return NULL */
876 if (ss->DisplayList)
877 _mesa_DeleteHashTable(ss->DisplayList);
878 if (ss->TexObjects)
879 _mesa_DeleteHashTable(ss->TexObjects);
880#if FEATURE_NV_vertex_program
881 if (ss->Programs)
882 _mesa_DeleteHashTable(ss->Programs);
883#endif
Brian Paul451f3102003-04-17 01:48:19 +0000884#if FEATURE_ARB_vertex_program
885 if (ss->DefaultVertexProgram)
Brian Paul4d859f72004-01-23 18:57:05 +0000886 ctx->Driver.DeleteProgram(ctx, ss->DefaultVertexProgram);
Brian Paul451f3102003-04-17 01:48:19 +0000887#endif
888#if FEATURE_ARB_fragment_program
889 if (ss->DefaultFragmentProgram)
Brian Paul4d859f72004-01-23 18:57:05 +0000890 ctx->Driver.DeleteProgram(ctx, ss->DefaultFragmentProgram);
Brian Paul451f3102003-04-17 01:48:19 +0000891#endif
Ian Romanick0207b472003-09-09 00:10:12 +0000892 if (ss->BufferObjects)
893 _mesa_DeleteHashTable(ss->BufferObjects);
894
Brian Paula3f13702003-04-01 16:41:50 +0000895 if (ss->Default1D)
896 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
897 if (ss->Default2D)
898 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
899 if (ss->Default3D)
900 (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
901 if (ss->DefaultCubeMap)
902 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
903 if (ss->DefaultRect)
904 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
905 if (ss)
906 _mesa_free(ss);
907 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000908}
909
Keith Whitwell6dc85572003-07-17 13:43:59 +0000910/**
jtgafb833d1999-08-19 00:55:39 +0000911 * Deallocate a shared state context and all children structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000912 *
913 * \param ctx GL context.
914 * \param ss shared state pointer.
915 *
916 * Frees the display lists, the texture objects (calling the driver texture
917 * deletion callback to free its private data) and the vertex programs, as well
918 * as their hash tables.
919 *
920 * \sa alloc_shared_state().
jtgafb833d1999-08-19 00:55:39 +0000921 */
Brian Paul178a1c52000-04-22 01:05:00 +0000922static void
923free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000924{
925 /* Free display lists */
926 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000927 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000928 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000929 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000930 }
931 else {
932 break;
933 }
934 }
Brian Paulbb797902000-01-24 16:19:54 +0000935 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000936
937 /* Free texture objects */
Brian Paula3f13702003-04-01 16:41:50 +0000938 ASSERT(ctx->Driver.DeleteTexture);
939 while (1) {
940 GLuint texName = _mesa_HashFirstEntry(ss->TexObjects);
941 if (texName) {
942 struct gl_texture_object *texObj = (struct gl_texture_object *)
943 _mesa_HashLookup(ss->TexObjects, texName);
944 ASSERT(texObj);
945 (*ctx->Driver.DeleteTexture)(ctx, texObj);
946 _mesa_HashRemove(ss->TexObjects, texName);
947 }
948 else {
949 break;
950 }
jtgafb833d1999-08-19 00:55:39 +0000951 }
Brian Paulbb797902000-01-24 16:19:54 +0000952 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000953
Brian Paul8dfc5b92002-10-16 17:57:51 +0000954#if FEATURE_NV_vertex_program
Brian Paul30f51ae2001-12-18 04:06:44 +0000955 /* Free vertex programs */
956 while (1) {
Brian Paul610d5992003-01-14 04:55:45 +0000957 GLuint prog = _mesa_HashFirstEntry(ss->Programs);
Brian Paul30f51ae2001-12-18 04:06:44 +0000958 if (prog) {
Brian Paul451f3102003-04-17 01:48:19 +0000959 struct program *p = (struct program *) _mesa_HashLookup(ss->Programs,
960 prog);
961 ASSERT(p);
Brian Paul4d859f72004-01-23 18:57:05 +0000962 ctx->Driver.DeleteProgram(ctx, p);
Brian Paul451f3102003-04-17 01:48:19 +0000963 _mesa_HashRemove(ss->Programs, prog);
Brian Paul30f51ae2001-12-18 04:06:44 +0000964 }
965 else {
966 break;
967 }
968 }
Brian Paul610d5992003-01-14 04:55:45 +0000969 _mesa_DeleteHashTable(ss->Programs);
Brian Paul8dfc5b92002-10-16 17:57:51 +0000970#endif
Brian Paul30f51ae2001-12-18 04:06:44 +0000971
Ian Romanick0207b472003-09-09 00:10:12 +0000972 _mesa_DeleteHashTable(ss->BufferObjects);
973
Keith Whitwelle15fd852002-12-12 13:03:15 +0000974 _glthread_DESTROY_MUTEX(ss->Mutex);
975
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000976 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000977}
978
979
Brian Paul4d859f72004-01-23 18:57:05 +0000980/**
981 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
982 */
983static void
984_mesa_init_current( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000985{
Brian Paul88bf0382004-02-13 15:30:08 +0000986 GLuint i;
jtgafb833d1999-08-19 00:55:39 +0000987
Keith Whitwell6dc85572003-07-17 13:43:59 +0000988 /* Current group */
989 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
990 ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000991 }
Keith Whitwell6dc85572003-07-17 13:43:59 +0000992 /* special cases: */
993 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 1.0 );
994 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
995 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
Brian Paul88bf0382004-02-13 15:30:08 +0000996 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
Keith Whitwell6dc85572003-07-17 13:43:59 +0000997 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 );
Brian Paul88bf0382004-02-13 15:30:08 +0000998
Keith Whitwell6dc85572003-07-17 13:43:59 +0000999 ctx->Current.Index = 1;
1000 ctx->Current.EdgeFlag = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001001}
1002
1003
Brian Paul4d859f72004-01-23 18:57:05 +00001004/**
1005 * Initialize fields of gl_constants (aka ctx->Const.*).
1006 * Use defaults from config.h. The device drivers will often override
1007 * some of these values (such as number of texture units).
1008 */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001009static void
1010_mesa_init_constants( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001011{
Brian Paul4d053dd2000-01-14 04:45:47 +00001012 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +00001013
Brian Paulcd1cefa2001-06-13 14:56:14 +00001014 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
1015 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
1016
Brian Paul539cce52000-02-03 19:40:07 +00001017 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +00001018 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +00001019 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
1020 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul8afe7de2002-06-15 03:03:06 +00001021 ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001022 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Brian Paul610d5992003-01-14 04:55:45 +00001023 ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
1024 ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +00001025 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +00001026 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +00001027 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +00001028 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
1029 ctx->Const.MinPointSize = MIN_POINT_SIZE;
1030 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
1031 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
1032 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +00001033 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +00001034 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
1035 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
1036 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
1037 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +00001038 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001039 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +00001040 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
1041 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paula8644322000-11-27 18:22:13 +00001042 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
1043 ctx->Const.MaxLights = MAX_LIGHTS;
Ian Romanick882caa12003-05-30 21:37:14 +00001044 ctx->Const.MaxSpotExponent = 128.0;
1045 ctx->Const.MaxShininess = 128.0;
Brian Pauld0492cf2003-04-11 01:20:06 +00001046#if FEATURE_ARB_vertex_program
Brian Pauld0492cf2003-04-11 01:20:06 +00001047 ctx->Const.MaxVertexProgramInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS;
Brian Paul451f3102003-04-17 01:48:19 +00001048 ctx->Const.MaxVertexProgramAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
1049 ctx->Const.MaxVertexProgramTemps = MAX_NV_VERTEX_PROGRAM_TEMPS;
1050 ctx->Const.MaxVertexProgramLocalParams = MAX_NV_VERTEX_PROGRAM_PARAMS;
1051 ctx->Const.MaxVertexProgramEnvParams = MAX_NV_VERTEX_PROGRAM_PARAMS;/*XXX*/
1052 ctx->Const.MaxVertexProgramAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
Brian Pauld0492cf2003-04-11 01:20:06 +00001053#endif
1054#if FEATURE_ARB_fragment_program
Brian Pauld0492cf2003-04-11 01:20:06 +00001055 ctx->Const.MaxFragmentProgramInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS;
Brian Paul451f3102003-04-17 01:48:19 +00001056 ctx->Const.MaxFragmentProgramAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
1057 ctx->Const.MaxFragmentProgramTemps = MAX_NV_FRAGMENT_PROGRAM_TEMPS;
1058 ctx->Const.MaxFragmentProgramLocalParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
1059 ctx->Const.MaxFragmentProgramEnvParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;/*XXX*/
1060 ctx->Const.MaxFragmentProgramAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
1061 ctx->Const.MaxFragmentProgramAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS;
1062 ctx->Const.MaxFragmentProgramTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS;
1063 ctx->Const.MaxFragmentProgramTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS;
Brian Pauld0492cf2003-04-11 01:20:06 +00001064#endif
Brian Pauledd67742003-04-18 18:02:43 +00001065 ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
1066 ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
Brian Pauld0492cf2003-04-11 01:20:06 +00001067
Brian Paula2b9bad2003-11-10 19:08:37 +00001068 /* If we're running in the X server, do bounds checking to prevent
1069 * segfaults and server crashes!
1070 */
1071#if defined(XFree86LOADER) && defined(IN_MODULE)
1072 ctx->Const.CheckArrayBounds = GL_TRUE;
1073#else
1074 ctx->Const.CheckArrayBounds = GL_FALSE;
1075#endif
1076
Brian Paul92f97852003-05-01 22:44:02 +00001077 ASSERT(ctx->Const.MaxTextureUnits == MAX2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits));
Keith Whitwell6dc85572003-07-17 13:43:59 +00001078}
jtgafb833d1999-08-19 00:55:39 +00001079
Brian Paul4d859f72004-01-23 18:57:05 +00001080
Keith Whitwell6dc85572003-07-17 13:43:59 +00001081/**
1082 * Initialize the attribute groups in a GL context.
1083 *
1084 * \param ctx GL context.
1085 *
1086 * Initializes all the attributes, calling the respective <tt>init*</tt>
1087 * functions for the more complex data structures.
1088 */
1089static GLboolean
1090init_attrib_groups( GLcontext *ctx )
1091{
1092 assert(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001093
Keith Whitwell6dc85572003-07-17 13:43:59 +00001094 /* Constants */
1095 _mesa_init_constants( ctx );
Brian Paul0771d152000-04-07 00:19:41 +00001096
Brian Paul4d053dd2000-01-14 04:45:47 +00001097 /* Extensions */
Brian Paulde4f4602003-07-03 02:15:06 +00001098 _mesa_init_extensions( ctx );
jtgafb833d1999-08-19 00:55:39 +00001099
Keith Whitwell6dc85572003-07-17 13:43:59 +00001100 /* Attribute Groups */
1101 _mesa_init_accum( ctx );
1102 _mesa_init_attrib( ctx );
1103 _mesa_init_buffers( ctx );
Brian Paul148a2842003-09-17 03:40:11 +00001104 _mesa_init_buffer_objects( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001105 _mesa_init_color( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001106 _mesa_init_colortables( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001107 _mesa_init_current( ctx );
1108 _mesa_init_depth( ctx );
1109 _mesa_init_debug( ctx );
1110 _mesa_init_display_list( ctx );
1111 _mesa_init_eval( ctx );
1112 _mesa_init_feedback( ctx );
1113 _mesa_init_fog( ctx );
1114 _mesa_init_histogram( ctx );
1115 _mesa_init_hint( ctx );
1116 _mesa_init_line( ctx );
1117 _mesa_init_lighting( ctx );
1118 _mesa_init_matrix( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001119 _mesa_init_occlude( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001120 _mesa_init_pixel( ctx );
1121 _mesa_init_point( ctx );
1122 _mesa_init_polygon( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001123 _mesa_init_program( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001124 _mesa_init_rastpos( ctx );
1125 _mesa_init_stencil( ctx );
1126 _mesa_init_transform( ctx );
1127 _mesa_init_varray( ctx );
1128 _mesa_init_viewport( ctx );
jtgafb833d1999-08-19 00:55:39 +00001129
Keith Whitwell6dc85572003-07-17 13:43:59 +00001130 if (!_mesa_init_texture( ctx ))
1131 return GL_FALSE;
Brian Paulb17a7222003-06-13 02:37:27 +00001132
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001134 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001135 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
Brian Paul4d053dd2000-01-14 04:45:47 +00001136 ctx->CatchSignals = GL_TRUE;
Brian Paulf782b812002-10-04 17:37:45 +00001137 ctx->_Facing = 0;
Brian Paul4923e192004-02-28 22:30:58 +00001138#if CHAN_TYPE == GL_FLOAT
1139 ctx->ClampFragmentColors = GL_FALSE; /* XXX temporary */
1140#else
1141 ctx->ClampFragmentColors = GL_TRUE;
1142#endif
1143 ctx->ClampVertexColors = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001144
Brian Paula3f13702003-04-01 16:41:50 +00001145 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001146}
1147
1148
Brian Paulf44898c2003-07-18 15:44:57 +00001149/**
1150 * If the DRI libGL.so library is old, it may not have the entrypoints for
1151 * some recent OpenGL extensions. Dynamically add them now.
1152 * If we're building stand-alone Mesa where libGL.so has both the dispatcher
1153 * and driver code, this won't be an issue (and calling this function won't
1154 * do any harm).
1155 */
1156static void
1157add_newer_entrypoints(void)
1158{
Ian Romanick3baefe62003-08-22 23:28:03 +00001159 unsigned i;
1160 static const struct {
1161 const char * const name;
1162 unsigned offset;
1163 }
1164 newer_entrypoints[] = {
1165 /* GL_ARB_window_pos aliases with GL_MESA_window_pos */
1166 { "glWindowPos2dARB", 513 },
1167 { "glWindowPos2dvARB", 514 },
1168 { "glWindowPos2fARB", 515 },
1169 { "glWindowPos2fvARB", 516 },
1170 { "glWindowPos2iARB", 517 },
1171 { "glWindowPos2ivARB", 518 },
1172 { "glWindowPos2sARB", 519 },
1173 { "glWindowPos2svARB", 520 },
1174 { "glWindowPos3dARB", 521 },
1175 { "glWindowPos3dvARB", 522 },
1176 { "glWindowPos3fARB", 523 },
1177 { "glWindowPos3fvARB", 524 },
1178 { "glWindowPos3iARB", 525 },
1179 { "glWindowPos3ivARB", 526 },
1180 { "glWindowPos3sARB", 527 },
1181 { "glWindowPos3svARB", 528 },
Brian Paulf44898c2003-07-18 15:44:57 +00001182#if FEATURE_NV_vertex_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001183 { "glAreProgramsResidentNV", 578 },
1184 { "glBindProgramNV", 579 },
1185 { "glDeleteProgramsNV", 580 },
1186 { "glExecuteProgramNV", 581 },
1187 { "glGenProgramsNV", 582 },
1188 { "glGetProgramParameterdvNV", 583 },
1189 { "glGetProgramParameterfvNV", 584 },
1190 { "glGetProgramivNV", 585 },
1191 { "glGetProgramStringNV", 586 },
1192 { "glGetTrackMatrixivNV", 587 },
1193 { "glGetVertexAttribdvNV", 588 },
1194 { "glGetVertexAttribfvNV", 589 },
1195 { "glGetVertexAttribivNV", 590 },
1196 { "glGetVertexAttribPointervNV", 591 },
1197 { "glIsProgramNV", 592 },
1198 { "glLoadProgramNV", 593 },
1199 { "glProgramParameter4dNV", 594 },
1200 { "glProgramParameter4dvNV", 595 },
1201 { "glProgramParameter4fNV", 596 },
1202 { "glProgramParameter4fvNV", 597 },
1203 { "glProgramParameters4dvNV", 598 },
1204 { "glProgramParameters4fvNV", 599 },
1205 { "glRequestResidentProgramsNV", 600 },
1206 { "glTrackMatrixNV", 601 },
1207 { "glVertexAttribPointerNV", 602 },
1208 { "glVertexAttrib1dNV", 603 },
1209 { "glVertexAttrib1dvNV", 604 },
1210 { "glVertexAttrib1fNV", 605 },
1211 { "glVertexAttrib1fvNV", 606 },
1212 { "glVertexAttrib1sNV", 607 },
1213 { "glVertexAttrib1svNV", 608 },
1214 { "glVertexAttrib2dNV", 609 },
1215 { "glVertexAttrib2dvNV", 610 },
1216 { "glVertexAttrib2fNV", 611 },
1217 { "glVertexAttrib2fvNV", 612 },
1218 { "glVertexAttrib2sNV", 613 },
1219 { "glVertexAttrib2svNV", 614 },
1220 { "glVertexAttrib3dNV", 615 },
1221 { "glVertexAttrib3dvNV", 616 },
1222 { "glVertexAttrib3fNV", 617 },
1223 { "glVertexAttrib3fvNV", 618 },
1224 { "glVertexAttrib3sNV", 619 },
1225 { "glVertexAttrib3svNV", 620 },
1226 { "glVertexAttrib4dNV", 621 },
1227 { "glVertexAttrib4dvNV", 622 },
1228 { "glVertexAttrib4fNV", 623 },
1229 { "glVertexAttrib4fvNV", 624 },
1230 { "glVertexAttrib4sNV", 625 },
1231 { "glVertexAttrib4svNV", 626 },
1232 { "glVertexAttrib4ubNV", 627 },
1233 { "glVertexAttrib4ubvNV", 628 },
1234 { "glVertexAttribs1dvNV", 629 },
1235 { "glVertexAttribs1fvNV", 630 },
1236 { "glVertexAttribs1svNV", 631 },
1237 { "glVertexAttribs2dvNV", 632 },
1238 { "glVertexAttribs2fvNV", 633 },
1239 { "glVertexAttribs2svNV", 634 },
1240 { "glVertexAttribs3dvNV", 635 },
1241 { "glVertexAttribs3fvNV", 636 },
1242 { "glVertexAttribs3svNV", 637 },
1243 { "glVertexAttribs4dvNV", 638 },
1244 { "glVertexAttribs4fvNV", 639 },
1245 { "glVertexAttribs4svNV", 640 },
1246 { "glVertexAttribs4ubvNV", 641 },
Brian Paulf44898c2003-07-18 15:44:57 +00001247#endif
Ian Romanick3baefe62003-08-22 23:28:03 +00001248 { "glPointParameteriNV", 642 },
1249 { "glPointParameterivNV", 643 },
1250 { "glMultiDrawArraysEXT", 644 },
1251 { "glMultiDrawElementsEXT", 645 },
1252 { "glMultiDrawArraysSUN", _gloffset_MultiDrawArraysEXT },
1253 { "glMultiDrawElementsSUN", _gloffset_MultiDrawElementsEXT },
1254 { "glActiveStencilFaceEXT", 646 },
Brian Paulf44898c2003-07-18 15:44:57 +00001255#if FEATURE_NV_fence
Ian Romanick3baefe62003-08-22 23:28:03 +00001256 { "glDeleteFencesNV", 647 },
1257 { "glGenFencesNV", 648 },
1258 { "glIsFenceNV", 649 },
1259 { "glTestFenceNV", 650 },
1260 { "glGetFenceivNV", 651 },
1261 { "glFinishFenceNV", 652 },
1262 { "glSetFenceNV", 653 },
Brian Paulf44898c2003-07-18 15:44:57 +00001263#endif
1264#if FEATURE_NV_fragment_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001265 { "glProgramNamedParameter4fNV", 682 },
1266 { "glProgramNamedParameter4dNV", 683 },
1267 { "glProgramNamedParameter4fvNV", 683 },
1268 { "glProgramNamedParameter4dvNV", 684 },
1269 { "glGetProgramNamedParameterfvNV", 685 },
1270 { "glGetProgramNamedParameterdvNV", 686 },
Brian Paulf44898c2003-07-18 15:44:57 +00001271#endif
1272#if FEATURE_ARB_vertex_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001273 { "glVertexAttrib1sARB", _gloffset_VertexAttrib1sNV },
1274 { "glVertexAttrib1fARB", _gloffset_VertexAttrib1fNV },
1275 { "glVertexAttrib1dARB", _gloffset_VertexAttrib1dNV },
1276 { "glVertexAttrib2sARB", _gloffset_VertexAttrib2sNV },
1277 { "glVertexAttrib2fARB", _gloffset_VertexAttrib2fNV },
1278 { "glVertexAttrib2dARB", _gloffset_VertexAttrib2dNV },
1279 { "glVertexAttrib3sARB", _gloffset_VertexAttrib3sNV },
1280 { "glVertexAttrib3fARB", _gloffset_VertexAttrib3fNV },
1281 { "glVertexAttrib3dARB", _gloffset_VertexAttrib3dNV },
1282 { "glVertexAttrib4sARB", _gloffset_VertexAttrib4sNV },
1283 { "glVertexAttrib4fARB", _gloffset_VertexAttrib4fNV },
1284 { "glVertexAttrib4dARB", _gloffset_VertexAttrib4dNV },
1285 { "glVertexAttrib4NubARB", _gloffset_VertexAttrib4ubNV },
1286 { "glVertexAttrib1svARB", _gloffset_VertexAttrib1svNV },
1287 { "glVertexAttrib1fvARB", _gloffset_VertexAttrib1fvNV },
1288 { "glVertexAttrib1dvARB", _gloffset_VertexAttrib1dvNV },
1289 { "glVertexAttrib2svARB", _gloffset_VertexAttrib2svNV },
1290 { "glVertexAttrib2fvARB", _gloffset_VertexAttrib2fvNV },
1291 { "glVertexAttrib2dvARB", _gloffset_VertexAttrib2dvNV },
1292 { "glVertexAttrib3svARB", _gloffset_VertexAttrib3svNV },
1293 { "glVertexAttrib3fvARB", _gloffset_VertexAttrib3fvNV },
1294 { "glVertexAttrib3dvARB", _gloffset_VertexAttrib3dvNV },
1295 { "glVertexAttrib4bvARB", _gloffset_VertexAttrib4bvARB },
1296 { "glVertexAttrib4svARB", _gloffset_VertexAttrib4svNV },
1297 { "glVertexAttrib4ivARB", _gloffset_VertexAttrib4ivARB },
1298 { "glVertexAttrib4ubvARB", _gloffset_VertexAttrib4ubvARB },
1299 { "glVertexAttrib4usvARB", _gloffset_VertexAttrib4usvARB },
1300 { "glVertexAttrib4uivARB", _gloffset_VertexAttrib4uivARB },
1301 { "glVertexAttrib4fvARB", _gloffset_VertexAttrib4fvNV },
1302 { "glVertexAttrib4dvARB", _gloffset_VertexAttrib4dvNV },
1303 { "glVertexAttrib4NbvARB", _gloffset_VertexAttrib4NbvARB },
1304 { "glVertexAttrib4NsvARB", _gloffset_VertexAttrib4NsvARB },
1305 { "glVertexAttrib4NivARB", _gloffset_VertexAttrib4NivARB },
1306 { "glVertexAttrib4NubvARB", _gloffset_VertexAttrib4ubvNV },
1307 { "glVertexAttrib4NusvARB", _gloffset_VertexAttrib4NusvARB },
1308 { "glVertexAttrib4NuivARB", _gloffset_VertexAttrib4NuivARB },
1309 { "glVertexAttribPointerARB", _gloffset_VertexAttribPointerARB },
1310 { "glEnableVertexAttribArrayARB", _gloffset_EnableVertexAttribArrayARB },
1311 { "glDisableVertexAttribArrayARB", _gloffset_DisableVertexAttribArrayARB },
1312 { "glProgramStringARB", _gloffset_ProgramStringARB },
1313 { "glBindProgramARB", _gloffset_BindProgramNV },
1314 { "glDeleteProgramsARB", _gloffset_DeleteProgramsNV },
1315 { "glGenProgramsARB", _gloffset_GenProgramsNV },
1316 { "glIsProgramARB", _gloffset_IsProgramNV },
1317 { "glProgramEnvParameter4dARB", _gloffset_ProgramEnvParameter4dARB },
1318 { "glProgramEnvParameter4dvARB", _gloffset_ProgramEnvParameter4dvARB },
1319 { "glProgramEnvParameter4fARB", _gloffset_ProgramEnvParameter4fARB },
1320 { "glProgramEnvParameter4fvARB", _gloffset_ProgramEnvParameter4fvARB },
1321 { "glProgramLocalParameter4dARB", _gloffset_ProgramLocalParameter4dARB },
1322 { "glProgramLocalParameter4dvARB", _gloffset_ProgramLocalParameter4dvARB },
1323 { "glProgramLocalParameter4fARB", _gloffset_ProgramLocalParameter4fARB },
1324 { "glProgramLocalParameter4fvARB", _gloffset_ProgramLocalParameter4fvARB },
1325 { "glGetProgramEnvParameterdvARB", _gloffset_GetProgramEnvParameterdvARB },
1326 { "glGetProgramEnvParameterfvARB", _gloffset_GetProgramEnvParameterfvARB },
1327 { "glGetProgramLocalParameterdvARB", _gloffset_GetProgramLocalParameterdvARB },
1328 { "glGetProgramLocalParameterfvARB", _gloffset_GetProgramLocalParameterfvARB },
1329 { "glGetProgramivARB", _gloffset_GetProgramivARB },
1330 { "glGetProgramStringARB", _gloffset_GetProgramStringARB },
1331 { "glGetVertexAttribdvARB", _gloffset_GetVertexAttribdvNV },
1332 { "glGetVertexAttribfvARB", _gloffset_GetVertexAttribfvNV },
1333 { "glGetVertexAttribivARB", _gloffset_GetVertexAttribivNV },
1334 { "glGetVertexAttribPointervARB", _gloffset_GetVertexAttribPointervNV },
Brian Paulf44898c2003-07-18 15:44:57 +00001335#endif
Ian Romanick3baefe62003-08-22 23:28:03 +00001336 { "glMultiModeDrawArraysIBM", _gloffset_MultiModeDrawArraysIBM },
1337 { "glMultiModeDrawElementsIBM", _gloffset_MultiModeDrawElementsIBM },
1338 };
1339
1340 for ( i = 0 ; i < Elements(newer_entrypoints) ; i++ ) {
1341 _glapi_add_entrypoint( newer_entrypoints[i].name,
1342 newer_entrypoints[i].offset );
1343 }
Brian Paulf44898c2003-07-18 15:44:57 +00001344}
1345
Keith Whitwell306d3fc2002-04-09 16:56:50 +00001346
Brian Paulde4f4602003-07-03 02:15:06 +00001347/**
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001348 * Initialize a GLcontext struct (rendering context).
Keith Whitwell6dc85572003-07-17 13:43:59 +00001349 *
1350 * This includes allocating all the other structs and arrays which hang off of
1351 * the context by pointers.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001352 * Note that the driver needs to pass in its dd_function_table here since
1353 * we need to at least call driverFunctions->NewTextureObject to create the
1354 * default texture objects.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001355 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001356 * Called by _mesa_create_context().
Keith Whitwell6dc85572003-07-17 13:43:59 +00001357 *
1358 * Performs the imports and exports callback tables initialization, and
1359 * miscellaneous one-time initializations. If no shared context is supplied one
1360 * is allocated, and increase its reference count. Setups the GL API dispatch
1361 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
1362 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1363 * for debug flags.
1364 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001365 * \param ctx the context to initialize
1366 * \param visual describes the visual attributes for this context
1367 * \param share_list points to context to share textures, display lists,
1368 * etc with, or NULL
1369 * \param driverFunctions table of device driver functions for this context
1370 * to use
1371 * \param driverContext pointer to driver-specific context data
jtgafb833d1999-08-19 00:55:39 +00001372 */
Brian Paul178a1c52000-04-22 01:05:00 +00001373GLboolean
1374_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001375 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001376 GLcontext *share_list,
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001377 const struct dd_function_table *driverFunctions,
1378 void *driverContext )
jtgafb833d1999-08-19 00:55:39 +00001379{
Brian Paul5fb84d22000-05-24 15:04:45 +00001380 GLuint dispatchSize;
1381
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001382 ASSERT(driverContext);
1383 assert(driverFunctions->NewTextureObject);
jtgafb833d1999-08-19 00:55:39 +00001384
Brian Paul3c634522002-10-24 23:57:19 +00001385 /* If the driver wants core Mesa to use special imports, it'll have to
1386 * override these defaults.
1387 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001388 _mesa_init_default_imports( &(ctx->imports), driverContext );
jtgafb833d1999-08-19 00:55:39 +00001389
Brian Paul9a33a112002-06-13 04:28:29 +00001390 /* initialize the exports (Mesa functions called by the window system) */
Brian Paul4753d602002-06-15 02:38:15 +00001391 _mesa_init_default_exports( &(ctx->exports) );
1392
1393 /* misc one-time initializations */
1394 one_time_init(ctx);
Brian Paul9a33a112002-06-13 04:28:29 +00001395
Brian Paulb1394fa2000-09-26 20:53:53 +00001396 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001397 ctx->DrawBuffer = NULL;
1398 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001399
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001400 /* Plug in driver functions and context pointer here.
1401 * This is important because when we call alloc_shared_state() below
1402 * we'll call ctx->Driver.NewTextureObject() to create the default
1403 * textures.
Brian Paula3f13702003-04-01 16:41:50 +00001404 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001405 ctx->Driver = *driverFunctions;
1406 ctx->DriverCtx = driverContext;
Brian Paula3f13702003-04-01 16:41:50 +00001407
jtgafb833d1999-08-19 00:55:39 +00001408 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001409 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001410 ctx->Shared = share_list->Shared;
1411 }
1412 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001413 /* allocate new, unshared state */
Brian Paula3f13702003-04-01 16:41:50 +00001414 if (!alloc_shared_state( ctx )) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001415 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001416 }
1417 }
Brian Paul9560f052000-01-31 23:11:39 +00001418 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001419 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001420 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001421
Keith Whitwell6dc85572003-07-17 13:43:59 +00001422 if (!init_attrib_groups( ctx )) {
jtgafb833d1999-08-19 00:55:39 +00001423 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001424 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001425 }
jtgafb833d1999-08-19 00:55:39 +00001426
Brian Paulf44898c2003-07-18 15:44:57 +00001427 /* libGL ABI coordination */
1428 add_newer_entrypoints();
Keith Whitwell6dc85572003-07-17 13:43:59 +00001429
Brian Paul5fb84d22000-05-24 15:04:45 +00001430 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1431 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1432 * Mesa we do this to accomodate different versions of libGL and various
1433 * DRI drivers.
1434 */
1435 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1436 sizeof(struct _glapi_table) / sizeof(void *));
1437
Brian Paulfbd8f211999-11-11 01:22:25 +00001438 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001439 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1440 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001441 if (!ctx->Exec || !ctx->Save) {
1442 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001443 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001444 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001445 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001446 _mesa_init_exec_table(ctx->Exec, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001447 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001448
Keith Whitwell6dc85572003-07-17 13:43:59 +00001449#if _HAVE_FULL_GL
1450 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Keith Whitwellae0eaf92003-11-24 15:23:18 +00001451 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001452
Keith Whitwellad2ac212000-11-24 10:25:05 +00001453
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001454 /* Neutral tnl module stuff */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001455 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001456 ctx->TnlModule.Current = NULL;
1457 ctx->TnlModule.SwapCount = 0;
Keith Whitwell6dc85572003-07-17 13:43:59 +00001458#endif
Brian Paulb6bcae52001-01-23 23:39:36 +00001459
Brian Paul4d053dd2000-01-14 04:45:47 +00001460 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001461}
1462
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001463
Brian Paulde4f4602003-07-03 02:15:06 +00001464/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001465 * Allocate and initialize a GLcontext structure.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001466 * Note that the driver needs to pass in its dd_function_table here since
1467 * we need to at least call driverFunctions->NewTextureObject to initialize
1468 * the rendering context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001469 *
1470 * \param visual a GLvisual pointer (we copy the struct contents)
1471 * \param share_list another context to share display lists with or NULL
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001472 * \param driverFunctions points to the dd_function_table into which the
1473 * driver has plugged in all its special functions.
1474 * \param driverCtx points to the device driver's private context state
Keith Whitwell6dc85572003-07-17 13:43:59 +00001475 *
1476 * \return pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001477 */
Brian Paul178a1c52000-04-22 01:05:00 +00001478GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001479_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001480 GLcontext *share_list,
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001481 const struct dd_function_table *driverFunctions,
1482 void *driverContext )
Brian Paul3c634522002-10-24 23:57:19 +00001483
Brian Paul4d053dd2000-01-14 04:45:47 +00001484{
Brian Paul4753d602002-06-15 02:38:15 +00001485 GLcontext *ctx;
1486
1487 ASSERT(visual);
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001488 ASSERT(driverContext);
Brian Paul4753d602002-06-15 02:38:15 +00001489
Brian Paul3c634522002-10-24 23:57:19 +00001490 ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
Brian Paul4753d602002-06-15 02:38:15 +00001491 if (!ctx)
Brian Paul4d053dd2000-01-14 04:45:47 +00001492 return NULL;
Brian Paul4753d602002-06-15 02:38:15 +00001493
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001494 if (_mesa_initialize_context(ctx, visual, share_list,
1495 driverFunctions, driverContext)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001496 return ctx;
1497 }
1498 else {
Brian Paul3c634522002-10-24 23:57:19 +00001499 _mesa_free(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001500 return NULL;
1501 }
1502}
1503
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001504
Keith Whitwell6dc85572003-07-17 13:43:59 +00001505/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001506 * Free the data associated with the given context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001507 *
1508 * But doesn't free the GLcontext struct itself.
1509 *
1510 * \sa _mesa_initialize_context() and init_attrib_groups().
Brian Paul4d053dd2000-01-14 04:45:47 +00001511 */
Brian Paul178a1c52000-04-22 01:05:00 +00001512void
Brian Paulb1394fa2000-09-26 20:53:53 +00001513_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001514{
Brian Paul4d053dd2000-01-14 04:45:47 +00001515 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001516 if (ctx == _mesa_get_current_context()) {
1517 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001518 }
1519
Keith Whitwell6dc85572003-07-17 13:43:59 +00001520 _mesa_free_lighting_data( ctx );
1521 _mesa_free_eval_data( ctx );
1522 _mesa_free_texture_data( ctx );
1523 _mesa_free_matrix_data( ctx );
1524 _mesa_free_viewport_data( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001525 _mesa_free_colortables_data( ctx );
Brian Paul8dfc5b92002-10-16 17:57:51 +00001526#if FEATURE_NV_vertex_program
Brian Paul30f51ae2001-12-18 04:06:44 +00001527 if (ctx->VertexProgram.Current) {
Brian Paul610d5992003-01-14 04:55:45 +00001528 ctx->VertexProgram.Current->Base.RefCount--;
1529 if (ctx->VertexProgram.Current->Base.RefCount <= 0)
Brian Paul4d859f72004-01-23 18:57:05 +00001530 ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
Brian Paul610d5992003-01-14 04:55:45 +00001531 }
1532#endif
1533#if FEATURE_NV_fragment_program
1534 if (ctx->FragmentProgram.Current) {
1535 ctx->FragmentProgram.Current->Base.RefCount--;
1536 if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
Brian Paul4d859f72004-01-23 18:57:05 +00001537 ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
Brian Paulfd284452001-07-19 15:54:34 +00001538 }
Brian Paul8dfc5b92002-10-16 17:57:51 +00001539#endif
Brian Paulfd284452001-07-19 15:54:34 +00001540
Brian Paul30f51ae2001-12-18 04:06:44 +00001541 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001542 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001543 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001544 assert(ctx->Shared->RefCount >= 0);
1545 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1546 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001547 /* free shared state */
1548 free_shared_state( ctx, ctx->Shared );
1549 }
1550
Brian Paul702ca202003-07-18 15:22:16 +00001551 if (ctx->Extensions.String)
1552 FREE((void *) ctx->Extensions.String);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001553
1554 FREE(ctx->Exec);
1555 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001556}
1557
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001558
Keith Whitwell6dc85572003-07-17 13:43:59 +00001559/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001560 * Destroy a GLcontext structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001561 *
1562 * \param ctx GL context.
1563 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001564 * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
jtgafb833d1999-08-19 00:55:39 +00001565 */
Brian Paul178a1c52000-04-22 01:05:00 +00001566void
Brian Paulb1394fa2000-09-26 20:53:53 +00001567_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001568{
1569 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001570 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001571 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001572 }
1573}
1574
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001575
Keith Whitwell6dc85572003-07-17 13:43:59 +00001576#if _HAVE_FULL_GL
1577/**
jtgafb833d1999-08-19 00:55:39 +00001578 * Copy attribute groups from one context to another.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001579 *
1580 * \param src source context
1581 * \param dst destination context
1582 * \param mask bitwise OR of GL_*_BIT flags
1583 *
1584 * According to the bits specified in \p mask, copies the corresponding
1585 * attributes from \p src into \dst. For many of the attributes a simple \c
1586 * memcpy is not enough due to the existence of internal pointers in their data
1587 * structures.
jtgafb833d1999-08-19 00:55:39 +00001588 */
Brian Paul178a1c52000-04-22 01:05:00 +00001589void
Brian Paulb1394fa2000-09-26 20:53:53 +00001590_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001591{
1592 if (mask & GL_ACCUM_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001593 /* OK to memcpy */
1594 dst->Accum = src->Accum;
jtgafb833d1999-08-19 00:55:39 +00001595 }
1596 if (mask & GL_COLOR_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001597 /* OK to memcpy */
1598 dst->Color = src->Color;
jtgafb833d1999-08-19 00:55:39 +00001599 }
1600 if (mask & GL_CURRENT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001601 /* OK to memcpy */
1602 dst->Current = src->Current;
jtgafb833d1999-08-19 00:55:39 +00001603 }
1604 if (mask & GL_DEPTH_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001605 /* OK to memcpy */
1606 dst->Depth = src->Depth;
jtgafb833d1999-08-19 00:55:39 +00001607 }
1608 if (mask & GL_ENABLE_BIT) {
1609 /* no op */
1610 }
1611 if (mask & GL_EVAL_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001612 /* OK to memcpy */
1613 dst->Eval = src->Eval;
jtgafb833d1999-08-19 00:55:39 +00001614 }
1615 if (mask & GL_FOG_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001616 /* OK to memcpy */
1617 dst->Fog = src->Fog;
jtgafb833d1999-08-19 00:55:39 +00001618 }
1619 if (mask & GL_HINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001620 /* OK to memcpy */
1621 dst->Hint = src->Hint;
jtgafb833d1999-08-19 00:55:39 +00001622 }
1623 if (mask & GL_LIGHTING_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001624 GLuint i;
1625 /* begin with memcpy */
1626 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light) );
1627 /* fixup linked lists to prevent pointer insanity */
1628 make_empty_list( &(dst->Light.EnabledList) );
1629 for (i = 0; i < MAX_LIGHTS; i++) {
1630 if (dst->Light.Light[i].Enabled) {
1631 insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
1632 }
1633 }
jtgafb833d1999-08-19 00:55:39 +00001634 }
1635 if (mask & GL_LINE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001636 /* OK to memcpy */
1637 dst->Line = src->Line;
jtgafb833d1999-08-19 00:55:39 +00001638 }
1639 if (mask & GL_LIST_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001640 /* OK to memcpy */
1641 dst->List = src->List;
jtgafb833d1999-08-19 00:55:39 +00001642 }
1643 if (mask & GL_PIXEL_MODE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001644 /* OK to memcpy */
1645 dst->Pixel = src->Pixel;
jtgafb833d1999-08-19 00:55:39 +00001646 }
1647 if (mask & GL_POINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001648 /* OK to memcpy */
1649 dst->Point = src->Point;
jtgafb833d1999-08-19 00:55:39 +00001650 }
1651 if (mask & GL_POLYGON_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001652 /* OK to memcpy */
1653 dst->Polygon = src->Polygon;
jtgafb833d1999-08-19 00:55:39 +00001654 }
1655 if (mask & GL_POLYGON_STIPPLE_BIT) {
1656 /* Use loop instead of MEMCPY due to problem with Portland Group's
1657 * C compiler. Reported by John Stone.
1658 */
Brian Paul85d81602002-06-17 23:36:31 +00001659 GLuint i;
1660 for (i = 0; i < 32; i++) {
jtgafb833d1999-08-19 00:55:39 +00001661 dst->PolygonStipple[i] = src->PolygonStipple[i];
1662 }
1663 }
1664 if (mask & GL_SCISSOR_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001665 /* OK to memcpy */
1666 dst->Scissor = src->Scissor;
jtgafb833d1999-08-19 00:55:39 +00001667 }
1668 if (mask & GL_STENCIL_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001669 /* OK to memcpy */
1670 dst->Stencil = src->Stencil;
jtgafb833d1999-08-19 00:55:39 +00001671 }
1672 if (mask & GL_TEXTURE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001673 /* Cannot memcpy because of pointers */
1674 _mesa_copy_texture_state(src, dst);
jtgafb833d1999-08-19 00:55:39 +00001675 }
1676 if (mask & GL_TRANSFORM_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001677 /* OK to memcpy */
1678 dst->Transform = src->Transform;
jtgafb833d1999-08-19 00:55:39 +00001679 }
1680 if (mask & GL_VIEWPORT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001681 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1682 dst->Viewport.X = src->Viewport.X;
1683 dst->Viewport.Y = src->Viewport.Y;
1684 dst->Viewport.Width = src->Viewport.Width;
1685 dst->Viewport.Height = src->Viewport.Height;
1686 dst->Viewport.Near = src->Viewport.Near;
1687 dst->Viewport.Far = src->Viewport.Far;
1688 _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001689 }
Brian Paul85d81602002-06-17 23:36:31 +00001690
Keith Whitwella96308c2000-10-30 13:31:59 +00001691 /* XXX FIXME: Call callbacks?
1692 */
1693 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001694}
Keith Whitwell23caf202000-11-16 21:05:34 +00001695#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001696
1697
Brian Paulb1d53d92003-06-11 18:48:19 +00001698/**
1699 * Check if the given context can render into the given framebuffer
1700 * by checking visual attributes.
1701 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1702 */
1703static GLboolean
1704check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
1705{
1706 const GLvisual *ctxvis = &ctx->Visual;
1707 const GLvisual *bufvis = &buffer->Visual;
1708
1709 if (ctxvis == bufvis)
1710 return GL_TRUE;
1711
1712 if (ctxvis->rgbMode != bufvis->rgbMode)
1713 return GL_FALSE;
1714 if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
1715 return GL_FALSE;
1716 if (ctxvis->stereoMode && !bufvis->stereoMode)
1717 return GL_FALSE;
1718 if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
1719 return GL_FALSE;
1720 if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
1721 return GL_FALSE;
1722 if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
1723 return GL_FALSE;
1724 if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
1725 return GL_FALSE;
1726 if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
1727 return GL_FALSE;
1728 if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
1729 return GL_FALSE;
1730 if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
1731 return GL_FALSE;
1732 if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
1733 return GL_FALSE;
1734
1735 return GL_TRUE;
1736}
1737
1738
Keith Whitwell6dc85572003-07-17 13:43:59 +00001739/**
Brian Paul9a33a112002-06-13 04:28:29 +00001740 * Set the current context, binding the given frame buffer to the context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001741 *
1742 * \param newCtx new GL context.
1743 * \param buffer framebuffer.
1744 *
1745 * Calls _mesa_make_current2() with \p buffer as read and write framebuffer.
Brian Paul9a33a112002-06-13 04:28:29 +00001746 */
1747void
1748_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1749{
1750 _mesa_make_current2( newCtx, buffer, buffer );
1751}
1752
Keith Whitwell6dc85572003-07-17 13:43:59 +00001753/**
1754 * Bind the given context to the given draw-buffer and read-buffer and
1755 * make it the current context for this thread.
1756 *
1757 * \param newCtx new GL context. If NULL then there will be no current GL
1758 * context.
1759 * \param drawBuffer draw framebuffer.
1760 * \param readBuffer read framebuffer.
1761 *
1762 * Check that the context's and framebuffer's visuals are compatible, returning
1763 * immediately otherwise. Sets the glapi current context via
1764 * _glapi_set_context(). If \p newCtx is not NULL, associates \p drawBuffer and
1765 * \p readBuffer with it and calls dd_function_table::ResizeBuffers if the buffers size has changed.
1766 * Calls dd_function_table::MakeCurrent callback if defined.
1767 *
1768 * When a context is bound by the first time and the \c MESA_INFO environment
1769 * variable is set it calls print_info() as an aid for remote user
1770 * troubleshooting.
Brian Paul00037781999-12-17 14:52:35 +00001771 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001772void
1773_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1774 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001775{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001776 if (MESA_VERBOSE)
Brian Paul4753d602002-06-15 02:38:15 +00001777 _mesa_debug(newCtx, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001778
Brian Paulbe3602d2001-02-28 00:27:48 +00001779 /* Check that the context's and framebuffer's visuals are compatible.
Brian Paulbe3602d2001-02-28 00:27:48 +00001780 */
Brian Paulb1d53d92003-06-11 18:48:19 +00001781 if (newCtx && drawBuffer && newCtx->DrawBuffer != drawBuffer) {
1782 if (!check_compatible(newCtx, drawBuffer))
1783 return;
1784 }
1785 if (newCtx && readBuffer && newCtx->ReadBuffer != readBuffer) {
1786 if (!check_compatible(newCtx, readBuffer))
1787 return;
Brian Paulbe3602d2001-02-28 00:27:48 +00001788 }
1789
Brian Paul00037781999-12-17 14:52:35 +00001790 /* We call this function periodically (just here for now) in
1791 * order to detect when multithreading has begun.
1792 */
1793 _glapi_check_multithread();
1794
Brian Paulf9b97d92000-01-28 20:17:42 +00001795 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001796 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001797
1798
1799 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001800 _glapi_set_dispatch(NULL); /* none current */
1801 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001802 else {
1803 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001804
Keith Whitwell23caf202000-11-16 21:05:34 +00001805 if (drawBuffer && readBuffer) {
1806 /* TODO: check if newCtx and buffer's visual match??? */
1807 newCtx->DrawBuffer = drawBuffer;
1808 newCtx->ReadBuffer = readBuffer;
1809 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul10d7f542002-06-17 23:38:14 +00001810
Keith Whitwell6dc85572003-07-17 13:43:59 +00001811#if _HAVE_FULL_GL
Brian Paul10d7f542002-06-17 23:38:14 +00001812 if (drawBuffer->Width == 0 && drawBuffer->Height == 0) {
1813 /* get initial window size */
1814 GLuint bufWidth, bufHeight;
1815
1816 /* ask device driver for size of output buffer */
1817 (*newCtx->Driver.GetBufferSize)( drawBuffer, &bufWidth, &bufHeight );
1818
Keith Whitwell6dc85572003-07-17 13:43:59 +00001819 if (drawBuffer->Width != bufWidth ||
1820 drawBuffer->Height != bufHeight) {
Brian Paul10d7f542002-06-17 23:38:14 +00001821
Keith Whitwell6dc85572003-07-17 13:43:59 +00001822 drawBuffer->Width = bufWidth;
1823 drawBuffer->Height = bufHeight;
Brian Paul10d7f542002-06-17 23:38:14 +00001824
Keith Whitwell6dc85572003-07-17 13:43:59 +00001825 newCtx->Driver.ResizeBuffers( drawBuffer );
1826 }
Brian Paul10d7f542002-06-17 23:38:14 +00001827 }
1828
1829 if (readBuffer != drawBuffer &&
1830 readBuffer->Width == 0 && readBuffer->Height == 0) {
1831 /* get initial window size */
1832 GLuint bufWidth, bufHeight;
1833
1834 /* ask device driver for size of output buffer */
1835 (*newCtx->Driver.GetBufferSize)( readBuffer, &bufWidth, &bufHeight );
1836
Keith Whitwell6dc85572003-07-17 13:43:59 +00001837 if (readBuffer->Width != bufWidth ||
1838 readBuffer->Height != bufHeight) {
Brian Paul10d7f542002-06-17 23:38:14 +00001839
Keith Whitwell6dc85572003-07-17 13:43:59 +00001840 readBuffer->Width = bufWidth;
1841 readBuffer->Height = bufHeight;
Brian Paul10d7f542002-06-17 23:38:14 +00001842
Keith Whitwell6dc85572003-07-17 13:43:59 +00001843 newCtx->Driver.ResizeBuffers( readBuffer );
1844 }
Brian Paul10d7f542002-06-17 23:38:14 +00001845 }
Keith Whitwell6dc85572003-07-17 13:43:59 +00001846#endif
Brian Paul00037781999-12-17 14:52:35 +00001847 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001848
Keith Whitwell6dc85572003-07-17 13:43:59 +00001849 /* Alert the driver - usually passed on to the sw t&l module,
1850 * but also used to detect threaded cases in the radeon codegen
1851 * hw t&l module.
1852 */
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001853 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001854 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1855
1856 /* We can use this to help debug user's problems. Tell them to set
1857 * the MESA_INFO env variable before running their app. Then the
1858 * first time each context is made current we'll print some useful
1859 * information.
1860 */
1861 if (newCtx->FirstTimeCurrent) {
Brian Paul3c634522002-10-24 23:57:19 +00001862 if (_mesa_getenv("MESA_INFO")) {
Keith Whitwell6dc85572003-07-17 13:43:59 +00001863 _mesa_print_info();
Keith Whitwell23caf202000-11-16 21:05:34 +00001864 }
1865 newCtx->FirstTimeCurrent = GL_FALSE;
1866 }
Brian Paul00037781999-12-17 14:52:35 +00001867 }
1868}
1869
Keith Whitwell6dc85572003-07-17 13:43:59 +00001870/**
1871 * Get current context for the calling thread.
1872 *
1873 * \return pointer to the current GL context.
1874 *
1875 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1876 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in context.h.
Brian Paul00037781999-12-17 14:52:35 +00001877 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001878GLcontext *
1879_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001880{
Brian Paulf9b97d92000-01-28 20:17:42 +00001881 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001882}
1883
Keith Whitwell6dc85572003-07-17 13:43:59 +00001884/**
1885 * Get context's current API dispatch table.
1886 *
1887 * It'll either be the immediate-mode execute dispatcher or the display list
1888 * compile dispatcher.
1889 *
1890 * \param ctx GL context.
1891 *
1892 * \return pointer to dispatch_table.
1893 *
1894 * Simply returns __GLcontextRec::CurrentDispatch.
Brian Paulfbd8f211999-11-11 01:22:25 +00001895 */
1896struct _glapi_table *
1897_mesa_get_dispatch(GLcontext *ctx)
1898{
1899 return ctx->CurrentDispatch;
1900}
1901
Keith Whitwell6dc85572003-07-17 13:43:59 +00001902/*@}*/
Brian Paulfbd8f211999-11-11 01:22:25 +00001903
1904
jtgafb833d1999-08-19 00:55:39 +00001905/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001906/** \name Miscellaneous functions */
jtgafb833d1999-08-19 00:55:39 +00001907/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001908/*@{*/
jtgafb833d1999-08-19 00:55:39 +00001909
Keith Whitwell6dc85572003-07-17 13:43:59 +00001910/**
1911 * Record an error.
1912 *
1913 * \param ctx GL context.
1914 * \param error error code.
1915 *
1916 * Records the given error code and call the driver's dd_function_table::Error
1917 * function if defined.
1918 *
1919 * \sa
Brian Paul4e9676f2002-06-29 19:48:15 +00001920 * This is called via _mesa_error().
jtgafb833d1999-08-19 00:55:39 +00001921 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001922void
Brian Paul4e9676f2002-06-29 19:48:15 +00001923_mesa_record_error( GLcontext *ctx, GLenum error )
jtgafb833d1999-08-19 00:55:39 +00001924{
Brian Paul18a285a2002-03-16 00:53:15 +00001925 if (!ctx)
1926 return;
1927
Brian Paul7eb06032000-07-14 04:13:40 +00001928 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00001929 ctx->ErrorValue = error;
1930 }
1931
1932 /* Call device driver's error handler, if any. This is used on the Mac. */
1933 if (ctx->Driver.Error) {
1934 (*ctx->Driver.Error)( ctx );
1935 }
1936}
1937
Keith Whitwell6dc85572003-07-17 13:43:59 +00001938/**
1939 * Execute glFinish().
1940 *
1941 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1942 * dd_function_table::Finish driver callback, if not NULL.
1943 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001944void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +00001945_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00001946{
Brian Paulfa9df402000-02-02 19:16:46 +00001947 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001948 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001949 if (ctx->Driver.Finish) {
1950 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001951 }
1952}
1953
Keith Whitwell6dc85572003-07-17 13:43:59 +00001954/**
1955 * Execute glFlush().
1956 *
1957 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1958 * dd_function_table::Flush driver callback, if not NULL.
1959 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001960void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +00001961_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00001962{
Brian Paulfa9df402000-02-02 19:16:46 +00001963 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001964 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001965 if (ctx->Driver.Flush) {
1966 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001967 }
jtgafb833d1999-08-19 00:55:39 +00001968}
Brian Paul48c6a6e2000-09-08 21:28:04 +00001969
1970
Keith Whitwell6dc85572003-07-17 13:43:59 +00001971/*@}*/