blob: 9cb54e41aa02bb3ca2221a570f0e7171fd66e305 [file] [log] [blame]
Keith Whitwell6dc85572003-07-17 13:43:59 +00001/**
2 * \file context.c
3 * Mesa context/visual/framebuffer management functions.
4 * \author Brian Paul
5 */
6
jtgafb833d1999-08-19 00:55:39 +00007/*
8 * Mesa 3-D graphics library
Brian Paul4d859f72004-01-23 18:57:05 +00009 * Version: 6.1
jtgafb833d1999-08-19 00:55:39 +000010 *
Brian Paul4d859f72004-01-23 18:57:05 +000011 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +000012 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included
21 * in all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
27 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
Keith Whitwell6dc85572003-07-17 13:43:59 +000032/**
33 * \mainpage Mesa Core Module
34 *
35 * \section CoreIntroduction Introduction
36 *
37 * The Mesa core module consists of all the top-level files in the src
38 * directory. The core module basically takes care of API dispatch,
39 * and OpenGL state management.
40 *
41 * For example, calls to glPolygonMode() are routed to _mesa_PolygonMode()
42 * which updates the state related to polygonmode. Furthermore, dirty
43 * state flags related to polygon mode are set and if the device driver
44 * implements a special routine for PolygonMode, it will be called.
45 *
46 *
47 * \section AboutDoxygen About Doxygen
48 *
49 * If you're viewing this information as Doxygen-generated HTML you'll
50 * see the documentation index at the top of this page.
51 *
52 * The first line lists the Mesa source code modules.
53 * The second line lists the indexes available for viewing the documentation
54 * for each module.
55 *
56 * Selecting the <b>Main page</b> link will display a summary of the module
57 * (this page).
58 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000059 * Selecting <b>Data Structures</b> will list all C structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +000060 *
61 * Selecting the <b>File List</b> link will list all the source files in
62 * the module.
63 * Selecting a filename will show a list of all functions defined in that file.
64 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000065 * Selecting the <b>Data Fields</b> link will display a list of all
Keith Whitwell6dc85572003-07-17 13:43:59 +000066 * documented structure members.
67 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000068 * Selecting the <b>Globals</b> link will display a list
Keith Whitwell6dc85572003-07-17 13:43:59 +000069 * of all functions, structures, global variables and macros in the module.
70 *
71 */
72
73
Brian Paulfbd8f211999-11-11 01:22:25 +000074#include "glheader.h"
Brian Paul3c634522002-10-24 23:57:19 +000075#include "imports.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000076#include "accum.h"
77#include "attrib.h"
78#include "blend.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000079#include "buffers.h"
Brian Paul148a2842003-09-17 03:40:11 +000080#include "bufferobj.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000081#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000082#include "context.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000083#include "debug.h"
84#include "depth.h"
jtgafb833d1999-08-19 00:55:39 +000085#include "dlist.h"
86#include "eval.h"
87#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000088#include "extensions.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000089#include "feedback.h"
jtgafb833d1999-08-19 00:55:39 +000090#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000091#include "get.h"
Brian Paul9560f052000-01-31 23:11:39 +000092#include "glthread.h"
Brian Paulf44898c2003-07-18 15:44:57 +000093#include "glapioffsets.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000094#include "histogram.h"
95#include "hint.h"
jtgafb833d1999-08-19 00:55:39 +000096#include "hash.h"
97#include "light.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000098#include "lines.h"
jtgafb833d1999-08-19 00:55:39 +000099#include "macros.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000100#include "matrix.h"
Brian Paul05944c02003-07-22 03:51:46 +0000101#include "occlude.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000102#include "pixel.h"
103#include "points.h"
104#include "polygon.h"
Brian Paul31732772003-09-18 16:39:09 +0000105#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
106#include "program.h"
107#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +0000108#include "rastpos.h"
jtgafb833d1999-08-19 00:55:39 +0000109#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +0000110#include "state.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000111#include "stencil.h"
Brian Paul8f04c122004-04-27 13:39:20 +0000112#include "texcompress.h"
jtgafb833d1999-08-19 00:55:39 +0000113#include "teximage.h"
114#include "texobj.h"
Brian Paul85d81602002-06-17 23:36:31 +0000115#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000116#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +0000117#include "varray.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +0000118#include "vtxfmt.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000119#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000120#include "math/m_translate.h"
Keith Whitwell23caf202000-11-16 21:05:34 +0000121#include "math/m_matrix.h"
122#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +0000123#include "math/mathmod.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000124#endif
jtgafb833d1999-08-19 00:55:39 +0000125
davem69775355a2001-06-05 23:54:00 +0000126#ifdef USE_SPARC_ASM
Ian Romanicke16f6e32004-06-26 00:02:51 +0000127#include "sparc/sparc.h"
davem69775355a2001-06-05 23:54:00 +0000128#endif
jtgafb833d1999-08-19 00:55:39 +0000129
Keith Whitwell23caf202000-11-16 21:05:34 +0000130#ifndef MESA_VERBOSE
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000131int MESA_VERBOSE = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000132#endif
133
134#ifndef MESA_DEBUG_FLAGS
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000135int MESA_DEBUG_FLAGS = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000136#endif
Brian Paulb1394fa2000-09-26 20:53:53 +0000137
Brian Paul86b84272001-12-14 02:50:01 +0000138
Brian Paul27558a12003-03-01 01:50:20 +0000139/* ubyte -> float conversion */
140GLfloat _mesa_ubyte_to_float_color_tab[256];
141
Brian Paul9a33a112002-06-13 04:28:29 +0000142static void
143free_shared_state( GLcontext *ctx, struct gl_shared_state *ss );
144
Brian Paul86b84272001-12-14 02:50:01 +0000145
Brian Paulb1394fa2000-09-26 20:53:53 +0000146/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000147/** \name OpenGL SI-style interface (new in Mesa 3.5)
148 *
149 * \if subset
150 * \note Most of these functions are never called in the Mesa subset.
151 * \endif
152 */
153/*@{*/
Brian Paulb1394fa2000-09-26 20:53:53 +0000154
Keith Whitwell6dc85572003-07-17 13:43:59 +0000155/**
156 * Destroy context callback.
157 *
158 * \param gc context.
159 * \return GL_TRUE on success, or GL_FALSE on failure.
160 *
161 * \ifnot subset
162 * Called by window system/device driver (via __GLexports::destroyCurrent) when
163 * the rendering context is to be destroyed.
164 * \endif
165 *
166 * Frees the context data and the context structure.
Brian Paul9a33a112002-06-13 04:28:29 +0000167 */
168GLboolean
169_mesa_destroyContext(__GLcontext *gc)
Brian Paulb1394fa2000-09-26 20:53:53 +0000170{
171 if (gc) {
172 _mesa_free_context_data(gc);
Brian Paul3c634522002-10-24 23:57:19 +0000173 _mesa_free(gc);
Brian Paulb1394fa2000-09-26 20:53:53 +0000174 }
175 return GL_TRUE;
176}
177
Keith Whitwell6dc85572003-07-17 13:43:59 +0000178/**
179 * Unbind context callback.
180 *
181 * \param gc context.
182 * \return GL_TRUE on success, or GL_FALSE on failure.
183 *
184 * \ifnot subset
185 * Called by window system/device driver (via __GLexports::loseCurrent)
Brian Paul9a33a112002-06-13 04:28:29 +0000186 * when the rendering context is made non-current.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000187 * \endif
188 *
189 * No-op
Brian Paul9a33a112002-06-13 04:28:29 +0000190 */
191GLboolean
192_mesa_loseCurrent(__GLcontext *gc)
193{
194 /* XXX unbind context from thread */
Brian Paula6c423d2004-08-25 15:59:48 +0000195 (void) gc;
Brian Paul9a33a112002-06-13 04:28:29 +0000196 return GL_TRUE;
197}
198
Keith Whitwell6dc85572003-07-17 13:43:59 +0000199/**
200 * Bind context callback.
201 *
202 * \param gc context.
203 * \return GL_TRUE on success, or GL_FALSE on failure.
204 *
205 * \ifnot subset
206 * Called by window system/device driver (via __GLexports::makeCurrent)
Brian Paul9a33a112002-06-13 04:28:29 +0000207 * when the rendering context is made current.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000208 * \endif
209 *
210 * No-op
Brian Paul9a33a112002-06-13 04:28:29 +0000211 */
212GLboolean
213_mesa_makeCurrent(__GLcontext *gc)
214{
215 /* XXX bind context to thread */
Brian Paula6c423d2004-08-25 15:59:48 +0000216 (void) gc;
Brian Paul9a33a112002-06-13 04:28:29 +0000217 return GL_TRUE;
218}
219
Keith Whitwell6dc85572003-07-17 13:43:59 +0000220/**
221 * Share context callback.
222 *
223 * \param gc context.
224 * \param gcShare shared context.
225 * \return GL_TRUE on success, or GL_FALSE on failure.
226 *
227 * \ifnot subset
228 * Called by window system/device driver (via __GLexports::shareContext)
229 * \endif
230 *
231 * Update the shared context reference count, gl_shared_state::RefCount.
Brian Paul9a33a112002-06-13 04:28:29 +0000232 */
233GLboolean
234_mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare)
235{
236 if (gc && gcShare && gc->Shared && gcShare->Shared) {
237 gc->Shared->RefCount--;
238 if (gc->Shared->RefCount == 0) {
239 free_shared_state(gc, gc->Shared);
240 }
241 gc->Shared = gcShare->Shared;
242 gc->Shared->RefCount++;
243 return GL_TRUE;
244 }
245 else {
246 return GL_FALSE;
247 }
248}
249
Keith Whitwell6dc85572003-07-17 13:43:59 +0000250
251#if _HAVE_FULL_GL
252/**
253 * Copy context callback.
254 */
Brian Paul9a33a112002-06-13 04:28:29 +0000255GLboolean
256_mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask)
257{
258 if (dst && src) {
259 _mesa_copy_context( src, dst, mask );
260 return GL_TRUE;
261 }
262 else {
263 return GL_FALSE;
264 }
265}
Keith Whitwell6dc85572003-07-17 13:43:59 +0000266#endif
Brian Paul9a33a112002-06-13 04:28:29 +0000267
Keith Whitwell6dc85572003-07-17 13:43:59 +0000268/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000269GLboolean
270_mesa_forceCurrent(__GLcontext *gc)
271{
Brian Paula6c423d2004-08-25 15:59:48 +0000272 (void) gc;
Brian Paul9a33a112002-06-13 04:28:29 +0000273 return GL_TRUE;
274}
275
Keith Whitwell6dc85572003-07-17 13:43:59 +0000276/**
277 * Windows/buffer resizing notification callback.
278 *
279 * \param gc GL context.
280 * \return GL_TRUE on success, or GL_FALSE on failure.
281 */
Brian Paul9a33a112002-06-13 04:28:29 +0000282GLboolean
283_mesa_notifyResize(__GLcontext *gc)
284{
285 GLint x, y;
286 GLuint width, height;
287 __GLdrawablePrivate *d = gc->imports.getDrawablePrivate(gc);
288 if (!d || !d->getDrawableSize)
289 return GL_FALSE;
290 d->getDrawableSize( d, &x, &y, &width, &height );
291 /* update viewport, resize software buffers, etc. */
292 return GL_TRUE;
293}
294
Keith Whitwell6dc85572003-07-17 13:43:59 +0000295/**
296 * Window/buffer destruction notification callback.
297 *
298 * \param gc GL context.
299 *
300 * Called when the context's window/buffer is going to be destroyed.
301 *
302 * No-op
303 */
Brian Paul9a33a112002-06-13 04:28:29 +0000304void
305_mesa_notifyDestroy(__GLcontext *gc)
306{
Brian Paul60b6e4f2002-10-14 17:08:17 +0000307 /* Unbind from it. */
Brian Paula6c423d2004-08-25 15:59:48 +0000308 (void) gc;
Brian Paul9a33a112002-06-13 04:28:29 +0000309}
310
Keith Whitwell6dc85572003-07-17 13:43:59 +0000311/**
312 * Swap buffers notification callback.
313 *
314 * \param gc GL context.
315 *
316 * Called by window system just before swapping buffers.
Brian Paul9a33a112002-06-13 04:28:29 +0000317 * We have to finish any pending rendering.
318 */
319void
320_mesa_notifySwapBuffers(__GLcontext *gc)
321{
322 FLUSH_VERTICES( gc, 0 );
323}
324
Keith Whitwell6dc85572003-07-17 13:43:59 +0000325/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000326struct __GLdispatchStateRec *
327_mesa_dispatchExec(__GLcontext *gc)
328{
Brian Paula6c423d2004-08-25 15:59:48 +0000329 (void) gc;
Brian Paul9a33a112002-06-13 04:28:29 +0000330 return NULL;
331}
332
Keith Whitwell6dc85572003-07-17 13:43:59 +0000333/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000334void
335_mesa_beginDispatchOverride(__GLcontext *gc)
336{
Brian Paula6c423d2004-08-25 15:59:48 +0000337 (void) gc;
Brian Paul9a33a112002-06-13 04:28:29 +0000338}
339
Keith Whitwell6dc85572003-07-17 13:43:59 +0000340/** No-op */
Brian Paul9a33a112002-06-13 04:28:29 +0000341void
342_mesa_endDispatchOverride(__GLcontext *gc)
343{
Brian Paula6c423d2004-08-25 15:59:48 +0000344 (void) gc;
Brian Paul9a33a112002-06-13 04:28:29 +0000345}
346
Keith Whitwell6dc85572003-07-17 13:43:59 +0000347/**
348 * \ifnot subset
349 * Setup the exports.
350 *
351 * The window system will call these functions when it needs Mesa to do
352 * something.
353 *
354 * \note Device drivers should override these functions! For example,
Brian Paul9a33a112002-06-13 04:28:29 +0000355 * the Xlib driver should plug in the XMesa*-style functions into this
356 * structure. The XMesa-style functions should then call the _mesa_*
357 * version of these functions. This is an approximation to OO design
358 * (inheritance and virtual functions).
Keith Whitwell6dc85572003-07-17 13:43:59 +0000359 * \endif
360 *
361 * \if subset
362 * No-op.
363 *
364 * \endif
Brian Paul9a33a112002-06-13 04:28:29 +0000365 */
366static void
367_mesa_init_default_exports(__GLexports *exports)
368{
Keith Whitwell6dc85572003-07-17 13:43:59 +0000369#if _HAVE_FULL_GL
Brian Paul9a33a112002-06-13 04:28:29 +0000370 exports->destroyContext = _mesa_destroyContext;
371 exports->loseCurrent = _mesa_loseCurrent;
372 exports->makeCurrent = _mesa_makeCurrent;
373 exports->shareContext = _mesa_shareContext;
374 exports->copyContext = _mesa_copyContext;
375 exports->forceCurrent = _mesa_forceCurrent;
376 exports->notifyResize = _mesa_notifyResize;
Brian Paul2f35d5e2002-06-13 04:31:09 +0000377 exports->notifyDestroy = _mesa_notifyDestroy;
Brian Paul9a33a112002-06-13 04:28:29 +0000378 exports->notifySwapBuffers = _mesa_notifySwapBuffers;
379 exports->dispatchExec = _mesa_dispatchExec;
380 exports->beginDispatchOverride = _mesa_beginDispatchOverride;
381 exports->endDispatchOverride = _mesa_endDispatchOverride;
Brian Paula6c423d2004-08-25 15:59:48 +0000382#else
383 (void) exports;
Keith Whitwell6dc85572003-07-17 13:43:59 +0000384#endif
Brian Paul9a33a112002-06-13 04:28:29 +0000385}
386
Keith Whitwell6dc85572003-07-17 13:43:59 +0000387/**
388 * Exported OpenGL SI interface.
389 */
Brian Paulb1394fa2000-09-26 20:53:53 +0000390__GLcontext *
391__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
392{
393 GLcontext *ctx;
394
Brian Paul4753d602002-06-15 02:38:15 +0000395 ctx = (GLcontext *) (*imports->calloc)(NULL, 1, sizeof(GLcontext));
Brian Paulb1394fa2000-09-26 20:53:53 +0000396 if (ctx == NULL) {
397 return NULL;
398 }
Brian Paul60b6e4f2002-10-14 17:08:17 +0000399
Brian Pauld3fd7ba2004-01-20 02:49:27 +0000400 /* XXX doesn't work at this time */
401 _mesa_initialize_context(ctx, modes, NULL, NULL, NULL);
Brian Paulb1394fa2000-09-26 20:53:53 +0000402 ctx->imports = *imports;
Brian Paulb1394fa2000-09-26 20:53:53 +0000403
404 return ctx;
405}
406
Keith Whitwell6dc85572003-07-17 13:43:59 +0000407/**
408 * Exported OpenGL SI interface.
409 */
Brian Paulb1394fa2000-09-26 20:53:53 +0000410void
411__glCoreNopDispatch(void)
412{
413#if 0
414 /* SI */
415 __gl_dispatch = __glNopDispatchState;
416#else
417 /* Mesa */
418 _glapi_set_dispatch(NULL);
419#endif
420}
421
Keith Whitwell6dc85572003-07-17 13:43:59 +0000422/*@}*/
423
Brian Paulb1394fa2000-09-26 20:53:53 +0000424
jtgafb833d1999-08-19 00:55:39 +0000425/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000426/** \name GL Visual allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000427/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000428/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000429
Keith Whitwell6dc85572003-07-17 13:43:59 +0000430/**
Brian Paul894844a2004-03-21 17:05:03 +0000431 * Allocates a GLvisual structure and initializes it via
432 * _mesa_initialize_visual().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000433 *
434 * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
435 * \param dbFlag double buffering
436 * \param stereoFlag stereo buffer
437 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
438 * is acceptable but the actual depth type will be GLushort or GLuint as
439 * needed.
440 * \param stencilBits requested minimum bits per stencil buffer value
441 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
442 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
443 * \param redBits number of bits per color component in frame buffer for RGB(A)
444 * mode. We always use 8 in core Mesa though.
445 * \param greenBits same as above.
446 * \param blueBits same as above.
447 * \param alphaBits same as above.
448 * \param numSamples not really used.
449 *
450 * \return pointer to new GLvisual or NULL if requested parameters can't be
451 * met.
452 *
Brian Paul894844a2004-03-21 17:05:03 +0000453 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul4d053dd2000-01-14 04:45:47 +0000454 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000455GLvisual *
456_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000457 GLboolean dbFlag,
458 GLboolean stereoFlag,
459 GLint redBits,
460 GLint greenBits,
461 GLint blueBits,
462 GLint alphaBits,
463 GLint indexBits,
464 GLint depthBits,
465 GLint stencilBits,
466 GLint accumRedBits,
467 GLint accumGreenBits,
468 GLint accumBlueBits,
469 GLint accumAlphaBits,
470 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000471{
Brian Paul178a1c52000-04-22 01:05:00 +0000472 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
473 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000474 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000475 redBits, greenBits, blueBits, alphaBits,
476 indexBits, depthBits, stencilBits,
477 accumRedBits, accumGreenBits,
478 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000479 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000480 FREE(vis);
481 return NULL;
482 }
483 }
484 return vis;
485}
486
Keith Whitwell6dc85572003-07-17 13:43:59 +0000487/**
Brian Paul894844a2004-03-21 17:05:03 +0000488 * Makes some sanity checks and fills in the fields of the
489 * GLvisual structure with the given parameters.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000490 *
491 * \return GL_TRUE on success, or GL_FALSE on failure.
492 *
493 * \sa _mesa_create_visual() above for the parameter description.
494 *
Brian Paul894844a2004-03-21 17:05:03 +0000495 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul178a1c52000-04-22 01:05:00 +0000496 */
497GLboolean
498_mesa_initialize_visual( GLvisual *vis,
499 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000500 GLboolean dbFlag,
501 GLboolean stereoFlag,
502 GLint redBits,
503 GLint greenBits,
504 GLint blueBits,
505 GLint alphaBits,
506 GLint indexBits,
507 GLint depthBits,
508 GLint stencilBits,
509 GLint accumRedBits,
510 GLint accumGreenBits,
511 GLint accumBlueBits,
512 GLint accumAlphaBits,
513 GLint numSamples )
514{
515 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000516
Brian Pauled30dfa2000-03-03 17:47:39 +0000517 /* This is to catch bad values from device drivers not updated for
518 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
519 * bad value now (a 1-bit depth buffer!?!).
520 */
521 assert(depthBits == 0 || depthBits > 1);
522
523 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000524 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000525 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000526 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000527 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000528 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000529 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000530 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000531 }
532 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000533 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000534 }
535 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000536 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000537 }
538 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000539 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000540 }
541
Brian Paulb6bcae52001-01-23 23:39:36 +0000542 vis->rgbMode = rgbFlag;
543 vis->doubleBufferMode = dbFlag;
544 vis->stereoMode = stereoFlag;
Brian Paul153f1542002-10-29 15:04:35 +0000545
Brian Paulb6bcae52001-01-23 23:39:36 +0000546 vis->redBits = redBits;
547 vis->greenBits = greenBits;
548 vis->blueBits = blueBits;
549 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000550
Brian Paulb6bcae52001-01-23 23:39:36 +0000551 vis->indexBits = indexBits;
552 vis->depthBits = depthBits;
553 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
554 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
555 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
556 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
557 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000558
Brian Paul153f1542002-10-29 15:04:35 +0000559 vis->haveAccumBuffer = accumRedBits > 0;
560 vis->haveDepthBuffer = depthBits > 0;
561 vis->haveStencilBuffer = stencilBits > 0;
562
563 vis->numAuxBuffers = 0;
564 vis->level = 0;
565 vis->pixmapMode = 0;
Brian Paul894844a2004-03-21 17:05:03 +0000566 vis->samples = numSamples;
Brian Paul153f1542002-10-29 15:04:35 +0000567
Brian Paul178a1c52000-04-22 01:05:00 +0000568 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000569}
570
Brian Paul894844a2004-03-21 17:05:03 +0000571
Keith Whitwell6dc85572003-07-17 13:43:59 +0000572/**
Brian Paul894844a2004-03-21 17:05:03 +0000573 * Destroy a visual and free its memory.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000574 *
575 * \param vis visual.
576 *
577 * Frees the visual structure.
578 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000579void
580_mesa_destroy_visual( GLvisual *vis )
581{
582 FREE(vis);
583}
584
Keith Whitwell6dc85572003-07-17 13:43:59 +0000585/*@}*/
586
Brian Paulb371e0d2000-03-31 01:05:51 +0000587
Brian Paul4d053dd2000-01-14 04:45:47 +0000588/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000589/** \name GL Framebuffer allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000590/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000591/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000592
Keith Whitwell6dc85572003-07-17 13:43:59 +0000593/**
Brian Paul894844a2004-03-21 17:05:03 +0000594 * Allocate a GLframebuffer structure and initializes it via
595 * _mesa_initialize_framebuffer().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000596 *
597 * A GLframebuffer is a structure which encapsulates the depth, stencil and
598 * accum buffers and related parameters.
599 *
Brian Paul8b332582004-06-11 22:44:22 +0000600 * Note that the actual depth/stencil/accum/etc buffers are not allocated
601 * at this time. It's up to the device driver and/or swrast module to
602 * allocate them as needed.
603 *
Keith Whitwell6dc85572003-07-17 13:43:59 +0000604 * \param visual a GLvisual pointer (we copy the struct contents)
605 * \param softwareDepth create/use a software depth buffer?
606 * \param softwareStencil create/use a software stencil buffer?
607 * \param softwareAccum create/use a software accum buffer?
608 * \param softwareAlpha create/use a software alpha buffer?
609 *
610 * \return pointer to new GLframebuffer struct or NULL if error.
611 *
Brian Paul894844a2004-03-21 17:05:03 +0000612 * \note Need to add softwareAuxBuffers parameter.
Brian Paul4d053dd2000-01-14 04:45:47 +0000613 */
Brian Paul178a1c52000-04-22 01:05:00 +0000614GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000615_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000616 GLboolean softwareDepth,
617 GLboolean softwareStencil,
618 GLboolean softwareAccum,
619 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000620{
Brian Paul178a1c52000-04-22 01:05:00 +0000621 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
622 assert(visual);
623 if (buffer) {
624 _mesa_initialize_framebuffer(buffer, visual,
625 softwareDepth, softwareStencil,
626 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000627 }
Brian Paul178a1c52000-04-22 01:05:00 +0000628 return buffer;
629}
630
Brian Paul894844a2004-03-21 17:05:03 +0000631
Keith Whitwell6dc85572003-07-17 13:43:59 +0000632/**
Keith Whitwell6dc85572003-07-17 13:43:59 +0000633 * Makes some sanity checks and fills in the fields of the
634 * GLframebuffer structure with the given parameters.
Brian Paul894844a2004-03-21 17:05:03 +0000635 *
636 * \sa _mesa_create_framebuffer() above for the parameter description.
Brian Paul178a1c52000-04-22 01:05:00 +0000637 */
638void
639_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000640 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000641 GLboolean softwareDepth,
642 GLboolean softwareStencil,
643 GLboolean softwareAccum,
644 GLboolean softwareAlpha )
645{
Brian Paul894844a2004-03-21 17:05:03 +0000646 GLboolean softwareAux = GL_FALSE;
Brian Paul178a1c52000-04-22 01:05:00 +0000647 assert(buffer);
648 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000649
Brian Paul6ec6b842002-10-30 19:49:29 +0000650 _mesa_bzero(buffer, sizeof(GLframebuffer));
Brian Paul85d81602002-06-17 23:36:31 +0000651
Brian Paul4d053dd2000-01-14 04:45:47 +0000652 /* sanity checks */
653 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000654 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000655 }
656 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000657 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000658 }
659 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000660 assert(visual->rgbMode);
661 assert(visual->accumRedBits > 0);
662 assert(visual->accumGreenBits > 0);
663 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000664 }
665 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000666 assert(visual->rgbMode);
667 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000668 }
669
Brian Paul75978bd2001-04-27 21:17:20 +0000670 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000671 buffer->UseSoftwareDepthBuffer = softwareDepth;
672 buffer->UseSoftwareStencilBuffer = softwareStencil;
673 buffer->UseSoftwareAccumBuffer = softwareAccum;
674 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul894844a2004-03-21 17:05:03 +0000675 buffer->UseSoftwareAuxBuffers = softwareAux;
Brian Paul4d053dd2000-01-14 04:45:47 +0000676}
677
Brian Paul894844a2004-03-21 17:05:03 +0000678
Keith Whitwell6dc85572003-07-17 13:43:59 +0000679/**
Brian Paul4d053dd2000-01-14 04:45:47 +0000680 * Free a framebuffer struct and its buffers.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000681 *
682 * Calls _mesa_free_framebuffer_data() and frees the structure.
Brian Paul4d053dd2000-01-14 04:45:47 +0000683 */
Brian Paul178a1c52000-04-22 01:05:00 +0000684void
Brian Paulb1394fa2000-09-26 20:53:53 +0000685_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000686{
687 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000688 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000689 FREE(buffer);
690 }
691}
692
Brian Paul894844a2004-03-21 17:05:03 +0000693
Keith Whitwell6dc85572003-07-17 13:43:59 +0000694/**
695 * Free the data hanging off of \p buffer, but not \p buffer itself.
696 *
697 * \param buffer framebuffer.
698 *
699 * Frees all the buffers associated with the structure.
Brian Paul75978bd2001-04-27 21:17:20 +0000700 */
701void
702_mesa_free_framebuffer_data( GLframebuffer *buffer )
703{
704 if (!buffer)
705 return;
706
Brian Paul87506682003-05-27 15:20:43 +0000707 if (buffer->UseSoftwareDepthBuffer && buffer->DepthBuffer) {
Brian Paulaeb44342002-03-19 16:47:04 +0000708 MESA_PBUFFER_FREE( buffer->DepthBuffer );
Brian Paul75978bd2001-04-27 21:17:20 +0000709 buffer->DepthBuffer = NULL;
710 }
Brian Paul87506682003-05-27 15:20:43 +0000711 if (buffer->UseSoftwareAccumBuffer && buffer->Accum) {
Brian Paulaeb44342002-03-19 16:47:04 +0000712 MESA_PBUFFER_FREE( buffer->Accum );
Brian Paul75978bd2001-04-27 21:17:20 +0000713 buffer->Accum = NULL;
714 }
Brian Paul87506682003-05-27 15:20:43 +0000715 if (buffer->UseSoftwareStencilBuffer && buffer->Stencil) {
Brian Paulaeb44342002-03-19 16:47:04 +0000716 MESA_PBUFFER_FREE( buffer->Stencil );
Brian Paul75978bd2001-04-27 21:17:20 +0000717 buffer->Stencil = NULL;
718 }
Brian Paul87506682003-05-27 15:20:43 +0000719 if (buffer->UseSoftwareAlphaBuffers){
720 if (buffer->FrontLeftAlpha) {
721 MESA_PBUFFER_FREE( buffer->FrontLeftAlpha );
722 buffer->FrontLeftAlpha = NULL;
723 }
724 if (buffer->BackLeftAlpha) {
725 MESA_PBUFFER_FREE( buffer->BackLeftAlpha );
726 buffer->BackLeftAlpha = NULL;
727 }
728 if (buffer->FrontRightAlpha) {
729 MESA_PBUFFER_FREE( buffer->FrontRightAlpha );
730 buffer->FrontRightAlpha = NULL;
731 }
732 if (buffer->BackRightAlpha) {
733 MESA_PBUFFER_FREE( buffer->BackRightAlpha );
734 buffer->BackRightAlpha = NULL;
735 }
Brian Paul75978bd2001-04-27 21:17:20 +0000736 }
737}
738
Keith Whitwell6dc85572003-07-17 13:43:59 +0000739/*@}*/
Brian Paul75978bd2001-04-27 21:17:20 +0000740
Brian Paul4d053dd2000-01-14 04:45:47 +0000741
742/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000743/** \name Context allocation, initialization, destroying
744 *
745 * The purpose of the most initialization functions here is to provide the
746 * default state values according to the OpenGL specification.
747 */
jtgafb833d1999-08-19 00:55:39 +0000748/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000749/*@{*/
jtgafb833d1999-08-19 00:55:39 +0000750
Keith Whitwell6dc85572003-07-17 13:43:59 +0000751/**
752 * One-time initialization mutex lock.
753 *
754 * \sa Used by one_time_init().
755 */
Brian Paul9560f052000-01-31 23:11:39 +0000756_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
757
Keith Whitwell6dc85572003-07-17 13:43:59 +0000758/**
759 * Calls all the various one-time-init functions in Mesa.
760 *
761 * While holding a global mutex lock, calls several initialization functions,
762 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
763 * defined.
764 *
765 * \sa _mesa_init_lists(), _math_init().
jtgafb833d1999-08-19 00:55:39 +0000766 */
Brian Paul178a1c52000-04-22 01:05:00 +0000767static void
Brian Paul4753d602002-06-15 02:38:15 +0000768one_time_init( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000769{
770 static GLboolean alreadyCalled = GL_FALSE;
Brian Paula6c423d2004-08-25 15:59:48 +0000771 (void) ctx;
Brian Paul9560f052000-01-31 23:11:39 +0000772 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000773 if (!alreadyCalled) {
Brian Paul27558a12003-03-01 01:50:20 +0000774 GLuint i;
775
Brian Paul4d053dd2000-01-14 04:45:47 +0000776 /* do some implementation tests */
777 assert( sizeof(GLbyte) == 1 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000778 assert( sizeof(GLubyte) == 1 );
Brian Paul894844a2004-03-21 17:05:03 +0000779 assert( sizeof(GLshort) == 2 );
780 assert( sizeof(GLushort) == 2 );
781 assert( sizeof(GLint) == 4 );
782 assert( sizeof(GLuint) == 4 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000783
Brian Paul08836342001-03-03 20:33:27 +0000784 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000785
Keith Whitwell6dc85572003-07-17 13:43:59 +0000786#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000787 _math_init();
Brian Paul27558a12003-03-01 01:50:20 +0000788
789 for (i = 0; i < 256; i++) {
790 _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
791 }
Keith Whitwell6dc85572003-07-17 13:43:59 +0000792#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000793
davem69775355a2001-06-05 23:54:00 +0000794#ifdef USE_SPARC_ASM
795 _mesa_init_sparc_glapi_relocs();
796#endif
Brian Paul3c634522002-10-24 23:57:19 +0000797 if (_mesa_getenv("MESA_DEBUG")) {
Brian Paul68ee4bc2000-01-28 19:02:22 +0000798 _glapi_noop_enable_warnings(GL_TRUE);
Brian Paul71072be2002-10-10 00:22:13 +0000799#ifndef GLX_DIRECT_RENDERING
800 /* libGL from before 2002/06/28 don't have this function. Someday,
801 * when newer libGL libs are common, remove the #ifdef test. This
802 * only serves to print warnings when calling undefined GL functions.
803 */
Brian Paul4e9676f2002-06-29 19:48:15 +0000804 _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
Brian Paul71072be2002-10-10 00:22:13 +0000805#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000806 }
807 else {
808 _glapi_noop_enable_warnings(GL_FALSE);
809 }
810
jtgafb833d1999-08-19 00:55:39 +0000811#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
Brian Paul4e9676f2002-06-29 19:48:15 +0000812 _mesa_debug(ctx, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
jtgafb833d1999-08-19 00:55:39 +0000813#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000814
815 alreadyCalled = GL_TRUE;
816 }
Brian Paul9560f052000-01-31 23:11:39 +0000817 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000818}
819
Brian Paul894844a2004-03-21 17:05:03 +0000820
Keith Whitwell6dc85572003-07-17 13:43:59 +0000821/**
jtgafb833d1999-08-19 00:55:39 +0000822 * Allocate and initialize a shared context state structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000823 * Initializes the display list, texture objects and vertex programs hash
824 * tables, allocates the texture objects. If it runs out of memory, frees
825 * everything already allocated before returning NULL.
Brian Paul894844a2004-03-21 17:05:03 +0000826 *
827 * \return pointer to a gl_shared_state structure on success, or NULL on
828 * failure.
jtgafb833d1999-08-19 00:55:39 +0000829 */
Brian Paula3f13702003-04-01 16:41:50 +0000830static GLboolean
831alloc_shared_state( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000832{
Brian Paula3f13702003-04-01 16:41:50 +0000833 struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000834 if (!ss)
Brian Paula3f13702003-04-01 16:41:50 +0000835 return GL_FALSE;
836
837 ctx->Shared = ss;
jtgafb833d1999-08-19 00:55:39 +0000838
Brian Paule4b684c2000-09-12 21:07:40 +0000839 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000840
Brian Paule4b684c2000-09-12 21:07:40 +0000841 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000842 ss->TexObjects = _mesa_NewHashTable();
Brian Paul451f3102003-04-17 01:48:19 +0000843#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
Brian Paul610d5992003-01-14 04:55:45 +0000844 ss->Programs = _mesa_NewHashTable();
Brian Paul8dfc5b92002-10-16 17:57:51 +0000845#endif
jtgafb833d1999-08-19 00:55:39 +0000846
Brian Paul451f3102003-04-17 01:48:19 +0000847#if FEATURE_ARB_vertex_program
Brian Paul4d859f72004-01-23 18:57:05 +0000848 ss->DefaultVertexProgram = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000849 if (!ss->DefaultVertexProgram)
850 goto cleanup;
851#endif
852#if FEATURE_ARB_fragment_program
Brian Paul4d859f72004-01-23 18:57:05 +0000853 ss->DefaultFragmentProgram = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000854 if (!ss->DefaultFragmentProgram)
855 goto cleanup;
856#endif
857
Ian Romanick0207b472003-09-09 00:10:12 +0000858 ss->BufferObjects = _mesa_NewHashTable();
859
Brian Paula3f13702003-04-01 16:41:50 +0000860 ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
861 if (!ss->Default1D)
862 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000863
Brian Paula3f13702003-04-01 16:41:50 +0000864 ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
865 if (!ss->Default2D)
866 goto cleanup;
jtgafb833d1999-08-19 00:55:39 +0000867
Brian Paula3f13702003-04-01 16:41:50 +0000868 ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
869 if (!ss->Default3D)
870 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000871
Brian Paula3f13702003-04-01 16:41:50 +0000872 ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
873 if (!ss->DefaultCubeMap)
874 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000875
Brian Paula3f13702003-04-01 16:41:50 +0000876 ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
877 if (!ss->DefaultRect)
878 goto cleanup;
Brian Paul413d6a22000-05-26 14:44:59 +0000879
Brian Paula3f13702003-04-01 16:41:50 +0000880 /* Effectively bind the default textures to all texture units */
881 ss->Default1D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
882 ss->Default2D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
883 ss->Default3D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
884 ss->DefaultCubeMap->RefCount += MAX_TEXTURE_IMAGE_UNITS;
885 ss->DefaultRect->RefCount += MAX_TEXTURE_IMAGE_UNITS;
886
887 return GL_TRUE;
888
889 cleanup:
890 /* Ran out of memory at some point. Free everything and return NULL */
891 if (ss->DisplayList)
892 _mesa_DeleteHashTable(ss->DisplayList);
893 if (ss->TexObjects)
894 _mesa_DeleteHashTable(ss->TexObjects);
895#if FEATURE_NV_vertex_program
896 if (ss->Programs)
897 _mesa_DeleteHashTable(ss->Programs);
898#endif
Brian Paul451f3102003-04-17 01:48:19 +0000899#if FEATURE_ARB_vertex_program
900 if (ss->DefaultVertexProgram)
Brian Paul4d859f72004-01-23 18:57:05 +0000901 ctx->Driver.DeleteProgram(ctx, ss->DefaultVertexProgram);
Brian Paul451f3102003-04-17 01:48:19 +0000902#endif
903#if FEATURE_ARB_fragment_program
904 if (ss->DefaultFragmentProgram)
Brian Paul4d859f72004-01-23 18:57:05 +0000905 ctx->Driver.DeleteProgram(ctx, ss->DefaultFragmentProgram);
Brian Paul451f3102003-04-17 01:48:19 +0000906#endif
Brian Paul21841f02004-08-14 14:28:11 +0000907#if FEATURE_ARB_vertex_buffer_object
Ian Romanick0207b472003-09-09 00:10:12 +0000908 if (ss->BufferObjects)
909 _mesa_DeleteHashTable(ss->BufferObjects);
Brian Paul21841f02004-08-14 14:28:11 +0000910#endif
Ian Romanick0207b472003-09-09 00:10:12 +0000911
Brian Paula3f13702003-04-01 16:41:50 +0000912 if (ss->Default1D)
913 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
914 if (ss->Default2D)
915 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
916 if (ss->Default3D)
917 (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
918 if (ss->DefaultCubeMap)
919 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
920 if (ss->DefaultRect)
921 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
922 if (ss)
923 _mesa_free(ss);
924 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000925}
926
Keith Whitwell6dc85572003-07-17 13:43:59 +0000927/**
jtgafb833d1999-08-19 00:55:39 +0000928 * Deallocate a shared state context and all children structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000929 *
930 * \param ctx GL context.
931 * \param ss shared state pointer.
932 *
933 * Frees the display lists, the texture objects (calling the driver texture
934 * deletion callback to free its private data) and the vertex programs, as well
935 * as their hash tables.
936 *
937 * \sa alloc_shared_state().
jtgafb833d1999-08-19 00:55:39 +0000938 */
Brian Paul178a1c52000-04-22 01:05:00 +0000939static void
940free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000941{
942 /* Free display lists */
943 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000944 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000945 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000946 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000947 }
948 else {
949 break;
950 }
951 }
Brian Paulbb797902000-01-24 16:19:54 +0000952 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000953
954 /* Free texture objects */
Brian Paula3f13702003-04-01 16:41:50 +0000955 ASSERT(ctx->Driver.DeleteTexture);
Brian Paul21841f02004-08-14 14:28:11 +0000956 /* the default textures */
957 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
958 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
959 (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
960 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
961 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
962 /* all other textures */
Brian Paula3f13702003-04-01 16:41:50 +0000963 while (1) {
964 GLuint texName = _mesa_HashFirstEntry(ss->TexObjects);
965 if (texName) {
966 struct gl_texture_object *texObj = (struct gl_texture_object *)
967 _mesa_HashLookup(ss->TexObjects, texName);
968 ASSERT(texObj);
969 (*ctx->Driver.DeleteTexture)(ctx, texObj);
970 _mesa_HashRemove(ss->TexObjects, texName);
971 }
972 else {
973 break;
974 }
jtgafb833d1999-08-19 00:55:39 +0000975 }
Brian Paulbb797902000-01-24 16:19:54 +0000976 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000977
Brian Paul8dfc5b92002-10-16 17:57:51 +0000978#if FEATURE_NV_vertex_program
Brian Paul30f51ae2001-12-18 04:06:44 +0000979 /* Free vertex programs */
980 while (1) {
Brian Paul610d5992003-01-14 04:55:45 +0000981 GLuint prog = _mesa_HashFirstEntry(ss->Programs);
Brian Paul30f51ae2001-12-18 04:06:44 +0000982 if (prog) {
Brian Paul451f3102003-04-17 01:48:19 +0000983 struct program *p = (struct program *) _mesa_HashLookup(ss->Programs,
984 prog);
985 ASSERT(p);
Brian Paul4d859f72004-01-23 18:57:05 +0000986 ctx->Driver.DeleteProgram(ctx, p);
Brian Paul451f3102003-04-17 01:48:19 +0000987 _mesa_HashRemove(ss->Programs, prog);
Brian Paul30f51ae2001-12-18 04:06:44 +0000988 }
989 else {
990 break;
991 }
992 }
Brian Paul610d5992003-01-14 04:55:45 +0000993 _mesa_DeleteHashTable(ss->Programs);
Brian Paul8dfc5b92002-10-16 17:57:51 +0000994#endif
Brian Paul21841f02004-08-14 14:28:11 +0000995#if FEATURE_ARB_vertex_program
996 _mesa_delete_program(ctx, ss->DefaultVertexProgram);
997#endif
998#if FEATURE_ARB_fragment_program
999 _mesa_delete_program(ctx, ss->DefaultFragmentProgram);
1000#endif
Brian Paul30f51ae2001-12-18 04:06:44 +00001001
Brian Paul21841f02004-08-14 14:28:11 +00001002#if FEATURE_ARB_vertex_buffer_object
Ian Romanick0207b472003-09-09 00:10:12 +00001003 _mesa_DeleteHashTable(ss->BufferObjects);
Brian Paul21841f02004-08-14 14:28:11 +00001004#endif
Keith Whitwelle15fd852002-12-12 13:03:15 +00001005 _glthread_DESTROY_MUTEX(ss->Mutex);
1006
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001007 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +00001008}
1009
1010
Brian Paul4d859f72004-01-23 18:57:05 +00001011/**
1012 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
1013 */
1014static void
1015_mesa_init_current( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001016{
Brian Paul88bf0382004-02-13 15:30:08 +00001017 GLuint i;
jtgafb833d1999-08-19 00:55:39 +00001018
Keith Whitwell6dc85572003-07-17 13:43:59 +00001019 /* Current group */
1020 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
1021 ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +00001022 }
Keith Whitwell6dc85572003-07-17 13:43:59 +00001023 /* special cases: */
1024 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 1.0 );
1025 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
1026 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
Brian Paul88bf0382004-02-13 15:30:08 +00001027 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001028 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 );
Brian Paul88bf0382004-02-13 15:30:08 +00001029
Keith Whitwell6dc85572003-07-17 13:43:59 +00001030 ctx->Current.Index = 1;
1031 ctx->Current.EdgeFlag = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001032}
1033
1034
Brian Paul4d859f72004-01-23 18:57:05 +00001035/**
1036 * Initialize fields of gl_constants (aka ctx->Const.*).
1037 * Use defaults from config.h. The device drivers will often override
1038 * some of these values (such as number of texture units).
1039 */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001040static void
1041_mesa_init_constants( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001042{
Brian Paul4d053dd2000-01-14 04:45:47 +00001043 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +00001044
Brian Paulcd1cefa2001-06-13 14:56:14 +00001045 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
1046 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
1047
Brian Paul539cce52000-02-03 19:40:07 +00001048 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +00001049 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +00001050 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
1051 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul8afe7de2002-06-15 03:03:06 +00001052 ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001053 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Brian Paul610d5992003-01-14 04:55:45 +00001054 ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
1055 ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +00001056 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +00001057 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +00001058 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +00001059 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
1060 ctx->Const.MinPointSize = MIN_POINT_SIZE;
1061 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
1062 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
1063 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +00001064 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +00001065 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
1066 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
1067 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
1068 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +00001069 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001070 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +00001071 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
1072 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paula8644322000-11-27 18:22:13 +00001073 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
1074 ctx->Const.MaxLights = MAX_LIGHTS;
Ian Romanick882caa12003-05-30 21:37:14 +00001075 ctx->Const.MaxSpotExponent = 128.0;
1076 ctx->Const.MaxShininess = 128.0;
Brian Pauld0492cf2003-04-11 01:20:06 +00001077#if FEATURE_ARB_vertex_program
Brian Pauld0492cf2003-04-11 01:20:06 +00001078 ctx->Const.MaxVertexProgramInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS;
Brian Paul451f3102003-04-17 01:48:19 +00001079 ctx->Const.MaxVertexProgramAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
1080 ctx->Const.MaxVertexProgramTemps = MAX_NV_VERTEX_PROGRAM_TEMPS;
1081 ctx->Const.MaxVertexProgramLocalParams = MAX_NV_VERTEX_PROGRAM_PARAMS;
1082 ctx->Const.MaxVertexProgramEnvParams = MAX_NV_VERTEX_PROGRAM_PARAMS;/*XXX*/
1083 ctx->Const.MaxVertexProgramAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
Brian Pauld0492cf2003-04-11 01:20:06 +00001084#endif
1085#if FEATURE_ARB_fragment_program
Brian Pauld0492cf2003-04-11 01:20:06 +00001086 ctx->Const.MaxFragmentProgramInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS;
Brian Paul451f3102003-04-17 01:48:19 +00001087 ctx->Const.MaxFragmentProgramAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
1088 ctx->Const.MaxFragmentProgramTemps = MAX_NV_FRAGMENT_PROGRAM_TEMPS;
1089 ctx->Const.MaxFragmentProgramLocalParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
1090 ctx->Const.MaxFragmentProgramEnvParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;/*XXX*/
1091 ctx->Const.MaxFragmentProgramAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
1092 ctx->Const.MaxFragmentProgramAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS;
1093 ctx->Const.MaxFragmentProgramTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS;
1094 ctx->Const.MaxFragmentProgramTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS;
Brian Pauld0492cf2003-04-11 01:20:06 +00001095#endif
Brian Pauledd67742003-04-18 18:02:43 +00001096 ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
1097 ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
Brian Pauld0492cf2003-04-11 01:20:06 +00001098
Brian Paula2b9bad2003-11-10 19:08:37 +00001099 /* If we're running in the X server, do bounds checking to prevent
1100 * segfaults and server crashes!
1101 */
1102#if defined(XFree86LOADER) && defined(IN_MODULE)
1103 ctx->Const.CheckArrayBounds = GL_TRUE;
1104#else
1105 ctx->Const.CheckArrayBounds = GL_FALSE;
1106#endif
1107
Brian Paul92f97852003-05-01 22:44:02 +00001108 ASSERT(ctx->Const.MaxTextureUnits == MAX2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits));
Keith Whitwell6dc85572003-07-17 13:43:59 +00001109}
jtgafb833d1999-08-19 00:55:39 +00001110
Brian Paul4d859f72004-01-23 18:57:05 +00001111
Keith Whitwell6dc85572003-07-17 13:43:59 +00001112/**
1113 * Initialize the attribute groups in a GL context.
1114 *
1115 * \param ctx GL context.
1116 *
1117 * Initializes all the attributes, calling the respective <tt>init*</tt>
1118 * functions for the more complex data structures.
1119 */
1120static GLboolean
1121init_attrib_groups( GLcontext *ctx )
1122{
1123 assert(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001124
Keith Whitwell6dc85572003-07-17 13:43:59 +00001125 /* Constants */
1126 _mesa_init_constants( ctx );
Brian Paul0771d152000-04-07 00:19:41 +00001127
Brian Paul4d053dd2000-01-14 04:45:47 +00001128 /* Extensions */
Brian Paulde4f4602003-07-03 02:15:06 +00001129 _mesa_init_extensions( ctx );
jtgafb833d1999-08-19 00:55:39 +00001130
Keith Whitwell6dc85572003-07-17 13:43:59 +00001131 /* Attribute Groups */
1132 _mesa_init_accum( ctx );
1133 _mesa_init_attrib( ctx );
1134 _mesa_init_buffers( ctx );
Brian Paul148a2842003-09-17 03:40:11 +00001135 _mesa_init_buffer_objects( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001136 _mesa_init_color( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001137 _mesa_init_colortables( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001138 _mesa_init_current( ctx );
1139 _mesa_init_depth( ctx );
1140 _mesa_init_debug( ctx );
1141 _mesa_init_display_list( ctx );
1142 _mesa_init_eval( ctx );
1143 _mesa_init_feedback( ctx );
1144 _mesa_init_fog( ctx );
1145 _mesa_init_histogram( ctx );
1146 _mesa_init_hint( ctx );
1147 _mesa_init_line( ctx );
1148 _mesa_init_lighting( ctx );
1149 _mesa_init_matrix( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001150 _mesa_init_occlude( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001151 _mesa_init_pixel( ctx );
1152 _mesa_init_point( ctx );
1153 _mesa_init_polygon( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001154 _mesa_init_program( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001155 _mesa_init_rastpos( ctx );
1156 _mesa_init_stencil( ctx );
1157 _mesa_init_transform( ctx );
1158 _mesa_init_varray( ctx );
1159 _mesa_init_viewport( ctx );
jtgafb833d1999-08-19 00:55:39 +00001160
Keith Whitwell6dc85572003-07-17 13:43:59 +00001161 if (!_mesa_init_texture( ctx ))
1162 return GL_FALSE;
Brian Paulb17a7222003-06-13 02:37:27 +00001163
Brian Paul8f04c122004-04-27 13:39:20 +00001164 _mesa_init_texture_s3tc( ctx );
1165 _mesa_init_texture_fxt1( ctx );
1166
Brian Paul4d053dd2000-01-14 04:45:47 +00001167 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001168 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001169 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
Brian Paulf782b812002-10-04 17:37:45 +00001170 ctx->_Facing = 0;
Brian Paul4923e192004-02-28 22:30:58 +00001171#if CHAN_TYPE == GL_FLOAT
1172 ctx->ClampFragmentColors = GL_FALSE; /* XXX temporary */
1173#else
1174 ctx->ClampFragmentColors = GL_TRUE;
1175#endif
1176 ctx->ClampVertexColors = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001177
Brian Paula3f13702003-04-01 16:41:50 +00001178 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001179}
1180
1181
Brian Paulf44898c2003-07-18 15:44:57 +00001182/**
1183 * If the DRI libGL.so library is old, it may not have the entrypoints for
1184 * some recent OpenGL extensions. Dynamically add them now.
1185 * If we're building stand-alone Mesa where libGL.so has both the dispatcher
1186 * and driver code, this won't be an issue (and calling this function won't
1187 * do any harm).
1188 */
1189static void
1190add_newer_entrypoints(void)
1191{
Ian Romanick3baefe62003-08-22 23:28:03 +00001192 unsigned i;
1193 static const struct {
1194 const char * const name;
1195 unsigned offset;
1196 }
1197 newer_entrypoints[] = {
1198 /* GL_ARB_window_pos aliases with GL_MESA_window_pos */
1199 { "glWindowPos2dARB", 513 },
1200 { "glWindowPos2dvARB", 514 },
1201 { "glWindowPos2fARB", 515 },
1202 { "glWindowPos2fvARB", 516 },
1203 { "glWindowPos2iARB", 517 },
1204 { "glWindowPos2ivARB", 518 },
1205 { "glWindowPos2sARB", 519 },
1206 { "glWindowPos2svARB", 520 },
1207 { "glWindowPos3dARB", 521 },
1208 { "glWindowPos3dvARB", 522 },
1209 { "glWindowPos3fARB", 523 },
1210 { "glWindowPos3fvARB", 524 },
1211 { "glWindowPos3iARB", 525 },
1212 { "glWindowPos3ivARB", 526 },
1213 { "glWindowPos3sARB", 527 },
1214 { "glWindowPos3svARB", 528 },
Brian Paulf44898c2003-07-18 15:44:57 +00001215#if FEATURE_NV_vertex_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001216 { "glAreProgramsResidentNV", 578 },
1217 { "glBindProgramNV", 579 },
1218 { "glDeleteProgramsNV", 580 },
1219 { "glExecuteProgramNV", 581 },
1220 { "glGenProgramsNV", 582 },
1221 { "glGetProgramParameterdvNV", 583 },
1222 { "glGetProgramParameterfvNV", 584 },
1223 { "glGetProgramivNV", 585 },
1224 { "glGetProgramStringNV", 586 },
1225 { "glGetTrackMatrixivNV", 587 },
1226 { "glGetVertexAttribdvNV", 588 },
1227 { "glGetVertexAttribfvNV", 589 },
1228 { "glGetVertexAttribivNV", 590 },
1229 { "glGetVertexAttribPointervNV", 591 },
1230 { "glIsProgramNV", 592 },
1231 { "glLoadProgramNV", 593 },
1232 { "glProgramParameter4dNV", 594 },
1233 { "glProgramParameter4dvNV", 595 },
1234 { "glProgramParameter4fNV", 596 },
1235 { "glProgramParameter4fvNV", 597 },
1236 { "glProgramParameters4dvNV", 598 },
1237 { "glProgramParameters4fvNV", 599 },
1238 { "glRequestResidentProgramsNV", 600 },
1239 { "glTrackMatrixNV", 601 },
1240 { "glVertexAttribPointerNV", 602 },
1241 { "glVertexAttrib1dNV", 603 },
1242 { "glVertexAttrib1dvNV", 604 },
1243 { "glVertexAttrib1fNV", 605 },
1244 { "glVertexAttrib1fvNV", 606 },
1245 { "glVertexAttrib1sNV", 607 },
1246 { "glVertexAttrib1svNV", 608 },
1247 { "glVertexAttrib2dNV", 609 },
1248 { "glVertexAttrib2dvNV", 610 },
1249 { "glVertexAttrib2fNV", 611 },
1250 { "glVertexAttrib2fvNV", 612 },
1251 { "glVertexAttrib2sNV", 613 },
1252 { "glVertexAttrib2svNV", 614 },
1253 { "glVertexAttrib3dNV", 615 },
1254 { "glVertexAttrib3dvNV", 616 },
1255 { "glVertexAttrib3fNV", 617 },
1256 { "glVertexAttrib3fvNV", 618 },
1257 { "glVertexAttrib3sNV", 619 },
1258 { "glVertexAttrib3svNV", 620 },
1259 { "glVertexAttrib4dNV", 621 },
1260 { "glVertexAttrib4dvNV", 622 },
1261 { "glVertexAttrib4fNV", 623 },
1262 { "glVertexAttrib4fvNV", 624 },
1263 { "glVertexAttrib4sNV", 625 },
1264 { "glVertexAttrib4svNV", 626 },
1265 { "glVertexAttrib4ubNV", 627 },
1266 { "glVertexAttrib4ubvNV", 628 },
1267 { "glVertexAttribs1dvNV", 629 },
1268 { "glVertexAttribs1fvNV", 630 },
1269 { "glVertexAttribs1svNV", 631 },
1270 { "glVertexAttribs2dvNV", 632 },
1271 { "glVertexAttribs2fvNV", 633 },
1272 { "glVertexAttribs2svNV", 634 },
1273 { "glVertexAttribs3dvNV", 635 },
1274 { "glVertexAttribs3fvNV", 636 },
1275 { "glVertexAttribs3svNV", 637 },
1276 { "glVertexAttribs4dvNV", 638 },
1277 { "glVertexAttribs4fvNV", 639 },
1278 { "glVertexAttribs4svNV", 640 },
1279 { "glVertexAttribs4ubvNV", 641 },
Brian Paulf44898c2003-07-18 15:44:57 +00001280#endif
Ian Romanick3baefe62003-08-22 23:28:03 +00001281 { "glPointParameteriNV", 642 },
1282 { "glPointParameterivNV", 643 },
1283 { "glMultiDrawArraysEXT", 644 },
1284 { "glMultiDrawElementsEXT", 645 },
1285 { "glMultiDrawArraysSUN", _gloffset_MultiDrawArraysEXT },
1286 { "glMultiDrawElementsSUN", _gloffset_MultiDrawElementsEXT },
1287 { "glActiveStencilFaceEXT", 646 },
Brian Paulf44898c2003-07-18 15:44:57 +00001288#if FEATURE_NV_fence
Ian Romanick3baefe62003-08-22 23:28:03 +00001289 { "glDeleteFencesNV", 647 },
1290 { "glGenFencesNV", 648 },
1291 { "glIsFenceNV", 649 },
1292 { "glTestFenceNV", 650 },
1293 { "glGetFenceivNV", 651 },
1294 { "glFinishFenceNV", 652 },
1295 { "glSetFenceNV", 653 },
Brian Paulf44898c2003-07-18 15:44:57 +00001296#endif
1297#if FEATURE_NV_fragment_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001298 { "glProgramNamedParameter4fNV", 682 },
1299 { "glProgramNamedParameter4dNV", 683 },
1300 { "glProgramNamedParameter4fvNV", 683 },
1301 { "glProgramNamedParameter4dvNV", 684 },
1302 { "glGetProgramNamedParameterfvNV", 685 },
1303 { "glGetProgramNamedParameterdvNV", 686 },
Brian Paulf44898c2003-07-18 15:44:57 +00001304#endif
1305#if FEATURE_ARB_vertex_program
Ian Romanick3baefe62003-08-22 23:28:03 +00001306 { "glVertexAttrib1sARB", _gloffset_VertexAttrib1sNV },
1307 { "glVertexAttrib1fARB", _gloffset_VertexAttrib1fNV },
1308 { "glVertexAttrib1dARB", _gloffset_VertexAttrib1dNV },
1309 { "glVertexAttrib2sARB", _gloffset_VertexAttrib2sNV },
1310 { "glVertexAttrib2fARB", _gloffset_VertexAttrib2fNV },
1311 { "glVertexAttrib2dARB", _gloffset_VertexAttrib2dNV },
1312 { "glVertexAttrib3sARB", _gloffset_VertexAttrib3sNV },
1313 { "glVertexAttrib3fARB", _gloffset_VertexAttrib3fNV },
1314 { "glVertexAttrib3dARB", _gloffset_VertexAttrib3dNV },
1315 { "glVertexAttrib4sARB", _gloffset_VertexAttrib4sNV },
1316 { "glVertexAttrib4fARB", _gloffset_VertexAttrib4fNV },
1317 { "glVertexAttrib4dARB", _gloffset_VertexAttrib4dNV },
1318 { "glVertexAttrib4NubARB", _gloffset_VertexAttrib4ubNV },
1319 { "glVertexAttrib1svARB", _gloffset_VertexAttrib1svNV },
1320 { "glVertexAttrib1fvARB", _gloffset_VertexAttrib1fvNV },
1321 { "glVertexAttrib1dvARB", _gloffset_VertexAttrib1dvNV },
1322 { "glVertexAttrib2svARB", _gloffset_VertexAttrib2svNV },
1323 { "glVertexAttrib2fvARB", _gloffset_VertexAttrib2fvNV },
1324 { "glVertexAttrib2dvARB", _gloffset_VertexAttrib2dvNV },
1325 { "glVertexAttrib3svARB", _gloffset_VertexAttrib3svNV },
1326 { "glVertexAttrib3fvARB", _gloffset_VertexAttrib3fvNV },
1327 { "glVertexAttrib3dvARB", _gloffset_VertexAttrib3dvNV },
1328 { "glVertexAttrib4bvARB", _gloffset_VertexAttrib4bvARB },
1329 { "glVertexAttrib4svARB", _gloffset_VertexAttrib4svNV },
1330 { "glVertexAttrib4ivARB", _gloffset_VertexAttrib4ivARB },
1331 { "glVertexAttrib4ubvARB", _gloffset_VertexAttrib4ubvARB },
1332 { "glVertexAttrib4usvARB", _gloffset_VertexAttrib4usvARB },
1333 { "glVertexAttrib4uivARB", _gloffset_VertexAttrib4uivARB },
1334 { "glVertexAttrib4fvARB", _gloffset_VertexAttrib4fvNV },
1335 { "glVertexAttrib4dvARB", _gloffset_VertexAttrib4dvNV },
1336 { "glVertexAttrib4NbvARB", _gloffset_VertexAttrib4NbvARB },
1337 { "glVertexAttrib4NsvARB", _gloffset_VertexAttrib4NsvARB },
1338 { "glVertexAttrib4NivARB", _gloffset_VertexAttrib4NivARB },
1339 { "glVertexAttrib4NubvARB", _gloffset_VertexAttrib4ubvNV },
1340 { "glVertexAttrib4NusvARB", _gloffset_VertexAttrib4NusvARB },
1341 { "glVertexAttrib4NuivARB", _gloffset_VertexAttrib4NuivARB },
1342 { "glVertexAttribPointerARB", _gloffset_VertexAttribPointerARB },
1343 { "glEnableVertexAttribArrayARB", _gloffset_EnableVertexAttribArrayARB },
1344 { "glDisableVertexAttribArrayARB", _gloffset_DisableVertexAttribArrayARB },
1345 { "glProgramStringARB", _gloffset_ProgramStringARB },
1346 { "glBindProgramARB", _gloffset_BindProgramNV },
1347 { "glDeleteProgramsARB", _gloffset_DeleteProgramsNV },
1348 { "glGenProgramsARB", _gloffset_GenProgramsNV },
1349 { "glIsProgramARB", _gloffset_IsProgramNV },
1350 { "glProgramEnvParameter4dARB", _gloffset_ProgramEnvParameter4dARB },
1351 { "glProgramEnvParameter4dvARB", _gloffset_ProgramEnvParameter4dvARB },
1352 { "glProgramEnvParameter4fARB", _gloffset_ProgramEnvParameter4fARB },
1353 { "glProgramEnvParameter4fvARB", _gloffset_ProgramEnvParameter4fvARB },
1354 { "glProgramLocalParameter4dARB", _gloffset_ProgramLocalParameter4dARB },
1355 { "glProgramLocalParameter4dvARB", _gloffset_ProgramLocalParameter4dvARB },
1356 { "glProgramLocalParameter4fARB", _gloffset_ProgramLocalParameter4fARB },
1357 { "glProgramLocalParameter4fvARB", _gloffset_ProgramLocalParameter4fvARB },
1358 { "glGetProgramEnvParameterdvARB", _gloffset_GetProgramEnvParameterdvARB },
1359 { "glGetProgramEnvParameterfvARB", _gloffset_GetProgramEnvParameterfvARB },
1360 { "glGetProgramLocalParameterdvARB", _gloffset_GetProgramLocalParameterdvARB },
1361 { "glGetProgramLocalParameterfvARB", _gloffset_GetProgramLocalParameterfvARB },
1362 { "glGetProgramivARB", _gloffset_GetProgramivARB },
1363 { "glGetProgramStringARB", _gloffset_GetProgramStringARB },
1364 { "glGetVertexAttribdvARB", _gloffset_GetVertexAttribdvNV },
1365 { "glGetVertexAttribfvARB", _gloffset_GetVertexAttribfvNV },
1366 { "glGetVertexAttribivARB", _gloffset_GetVertexAttribivNV },
1367 { "glGetVertexAttribPointervARB", _gloffset_GetVertexAttribPointervNV },
Brian Paulf44898c2003-07-18 15:44:57 +00001368#endif
Ian Romanick3baefe62003-08-22 23:28:03 +00001369 { "glMultiModeDrawArraysIBM", _gloffset_MultiModeDrawArraysIBM },
1370 { "glMultiModeDrawElementsIBM", _gloffset_MultiModeDrawElementsIBM },
1371 };
1372
1373 for ( i = 0 ; i < Elements(newer_entrypoints) ; i++ ) {
1374 _glapi_add_entrypoint( newer_entrypoints[i].name,
1375 newer_entrypoints[i].offset );
1376 }
Brian Paulf44898c2003-07-18 15:44:57 +00001377}
1378
Keith Whitwell306d3fc2002-04-09 16:56:50 +00001379
Brian Paulde4f4602003-07-03 02:15:06 +00001380/**
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001381 * Initialize a GLcontext struct (rendering context).
Keith Whitwell6dc85572003-07-17 13:43:59 +00001382 *
1383 * This includes allocating all the other structs and arrays which hang off of
1384 * the context by pointers.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001385 * Note that the driver needs to pass in its dd_function_table here since
1386 * we need to at least call driverFunctions->NewTextureObject to create the
1387 * default texture objects.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001388 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001389 * Called by _mesa_create_context().
Keith Whitwell6dc85572003-07-17 13:43:59 +00001390 *
1391 * Performs the imports and exports callback tables initialization, and
1392 * miscellaneous one-time initializations. If no shared context is supplied one
1393 * is allocated, and increase its reference count. Setups the GL API dispatch
1394 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
1395 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1396 * for debug flags.
1397 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001398 * \param ctx the context to initialize
1399 * \param visual describes the visual attributes for this context
1400 * \param share_list points to context to share textures, display lists,
1401 * etc with, or NULL
1402 * \param driverFunctions table of device driver functions for this context
1403 * to use
1404 * \param driverContext pointer to driver-specific context data
jtgafb833d1999-08-19 00:55:39 +00001405 */
Brian Paul178a1c52000-04-22 01:05:00 +00001406GLboolean
1407_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001408 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001409 GLcontext *share_list,
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001410 const struct dd_function_table *driverFunctions,
1411 void *driverContext )
jtgafb833d1999-08-19 00:55:39 +00001412{
Brian Paul5fb84d22000-05-24 15:04:45 +00001413 GLuint dispatchSize;
1414
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001415 ASSERT(driverContext);
1416 assert(driverFunctions->NewTextureObject);
jtgafb833d1999-08-19 00:55:39 +00001417
Brian Paul3c634522002-10-24 23:57:19 +00001418 /* If the driver wants core Mesa to use special imports, it'll have to
1419 * override these defaults.
1420 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001421 _mesa_init_default_imports( &(ctx->imports), driverContext );
jtgafb833d1999-08-19 00:55:39 +00001422
Brian Paul9a33a112002-06-13 04:28:29 +00001423 /* initialize the exports (Mesa functions called by the window system) */
Brian Paul4753d602002-06-15 02:38:15 +00001424 _mesa_init_default_exports( &(ctx->exports) );
1425
1426 /* misc one-time initializations */
1427 one_time_init(ctx);
Brian Paul9a33a112002-06-13 04:28:29 +00001428
Brian Paulb1394fa2000-09-26 20:53:53 +00001429 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001430 ctx->DrawBuffer = NULL;
1431 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001432
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001433 /* Plug in driver functions and context pointer here.
1434 * This is important because when we call alloc_shared_state() below
1435 * we'll call ctx->Driver.NewTextureObject() to create the default
1436 * textures.
Brian Paula3f13702003-04-01 16:41:50 +00001437 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001438 ctx->Driver = *driverFunctions;
1439 ctx->DriverCtx = driverContext;
Brian Paula3f13702003-04-01 16:41:50 +00001440
jtgafb833d1999-08-19 00:55:39 +00001441 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001442 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001443 ctx->Shared = share_list->Shared;
1444 }
1445 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001446 /* allocate new, unshared state */
Brian Paula3f13702003-04-01 16:41:50 +00001447 if (!alloc_shared_state( ctx )) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001448 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001449 }
1450 }
Brian Paul9560f052000-01-31 23:11:39 +00001451 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001452 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001453 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001454
Keith Whitwell6dc85572003-07-17 13:43:59 +00001455 if (!init_attrib_groups( ctx )) {
jtgafb833d1999-08-19 00:55:39 +00001456 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001457 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001458 }
jtgafb833d1999-08-19 00:55:39 +00001459
Brian Paulf44898c2003-07-18 15:44:57 +00001460 /* libGL ABI coordination */
1461 add_newer_entrypoints();
Keith Whitwell6dc85572003-07-17 13:43:59 +00001462
Brian Paul5fb84d22000-05-24 15:04:45 +00001463 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1464 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1465 * Mesa we do this to accomodate different versions of libGL and various
1466 * DRI drivers.
1467 */
1468 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1469 sizeof(struct _glapi_table) / sizeof(void *));
1470
Brian Paulfbd8f211999-11-11 01:22:25 +00001471 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001472 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1473 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001474 if (!ctx->Exec || !ctx->Save) {
1475 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001476 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001477 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001478 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001479 _mesa_init_exec_table(ctx->Exec, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001480 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001481
Keith Whitwell6dc85572003-07-17 13:43:59 +00001482#if _HAVE_FULL_GL
1483 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Keith Whitwellae0eaf92003-11-24 15:23:18 +00001484 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001485
Keith Whitwellad2ac212000-11-24 10:25:05 +00001486
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001487 /* Neutral tnl module stuff */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001488 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001489 ctx->TnlModule.Current = NULL;
1490 ctx->TnlModule.SwapCount = 0;
Keith Whitwell6dc85572003-07-17 13:43:59 +00001491#endif
Brian Paulb6bcae52001-01-23 23:39:36 +00001492
Brian Paul4d053dd2000-01-14 04:45:47 +00001493 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001494}
1495
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001496
Brian Paulde4f4602003-07-03 02:15:06 +00001497/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001498 * Allocate and initialize a GLcontext structure.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001499 * Note that the driver needs to pass in its dd_function_table here since
1500 * we need to at least call driverFunctions->NewTextureObject to initialize
1501 * the rendering context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001502 *
1503 * \param visual a GLvisual pointer (we copy the struct contents)
1504 * \param share_list another context to share display lists with or NULL
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001505 * \param driverFunctions points to the dd_function_table into which the
1506 * driver has plugged in all its special functions.
1507 * \param driverCtx points to the device driver's private context state
Keith Whitwell6dc85572003-07-17 13:43:59 +00001508 *
1509 * \return pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001510 */
Brian Paul178a1c52000-04-22 01:05:00 +00001511GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001512_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001513 GLcontext *share_list,
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001514 const struct dd_function_table *driverFunctions,
1515 void *driverContext )
Brian Paul3c634522002-10-24 23:57:19 +00001516
Brian Paul4d053dd2000-01-14 04:45:47 +00001517{
Brian Paul4753d602002-06-15 02:38:15 +00001518 GLcontext *ctx;
1519
1520 ASSERT(visual);
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001521 ASSERT(driverContext);
Brian Paul4753d602002-06-15 02:38:15 +00001522
Brian Paul3c634522002-10-24 23:57:19 +00001523 ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
Brian Paul4753d602002-06-15 02:38:15 +00001524 if (!ctx)
Brian Paul4d053dd2000-01-14 04:45:47 +00001525 return NULL;
Brian Paul4753d602002-06-15 02:38:15 +00001526
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001527 if (_mesa_initialize_context(ctx, visual, share_list,
1528 driverFunctions, driverContext)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001529 return ctx;
1530 }
1531 else {
Brian Paul3c634522002-10-24 23:57:19 +00001532 _mesa_free(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001533 return NULL;
1534 }
1535}
1536
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001537
Keith Whitwell6dc85572003-07-17 13:43:59 +00001538/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001539 * Free the data associated with the given context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001540 *
1541 * But doesn't free the GLcontext struct itself.
1542 *
1543 * \sa _mesa_initialize_context() and init_attrib_groups().
Brian Paul4d053dd2000-01-14 04:45:47 +00001544 */
Brian Paul178a1c52000-04-22 01:05:00 +00001545void
Brian Paulb1394fa2000-09-26 20:53:53 +00001546_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001547{
Brian Paul4d053dd2000-01-14 04:45:47 +00001548 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001549 if (ctx == _mesa_get_current_context()) {
1550 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001551 }
1552
Keith Whitwell6dc85572003-07-17 13:43:59 +00001553 _mesa_free_lighting_data( ctx );
1554 _mesa_free_eval_data( ctx );
1555 _mesa_free_texture_data( ctx );
1556 _mesa_free_matrix_data( ctx );
1557 _mesa_free_viewport_data( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001558 _mesa_free_colortables_data( ctx );
Brian Paul21841f02004-08-14 14:28:11 +00001559 _mesa_free_program_data(ctx);
1560 _mesa_free_occlude_data(ctx);
1561
1562#if FEATURE_ARB_vertex_buffer_object
1563 _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj);
Brian Paul8dfc5b92002-10-16 17:57:51 +00001564#endif
Brian Paulfd284452001-07-19 15:54:34 +00001565
Brian Paul30f51ae2001-12-18 04:06:44 +00001566 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001567 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001568 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001569 assert(ctx->Shared->RefCount >= 0);
1570 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1571 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001572 /* free shared state */
1573 free_shared_state( ctx, ctx->Shared );
1574 }
1575
Brian Paul702ca202003-07-18 15:22:16 +00001576 if (ctx->Extensions.String)
1577 FREE((void *) ctx->Extensions.String);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001578
1579 FREE(ctx->Exec);
1580 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001581}
1582
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001583
Keith Whitwell6dc85572003-07-17 13:43:59 +00001584/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001585 * Destroy a GLcontext structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001586 *
1587 * \param ctx GL context.
1588 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001589 * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
jtgafb833d1999-08-19 00:55:39 +00001590 */
Brian Paul178a1c52000-04-22 01:05:00 +00001591void
Brian Paulb1394fa2000-09-26 20:53:53 +00001592_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001593{
1594 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001595 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001596 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001597 }
1598}
1599
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001600
Keith Whitwell6dc85572003-07-17 13:43:59 +00001601#if _HAVE_FULL_GL
1602/**
jtgafb833d1999-08-19 00:55:39 +00001603 * Copy attribute groups from one context to another.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001604 *
1605 * \param src source context
1606 * \param dst destination context
1607 * \param mask bitwise OR of GL_*_BIT flags
1608 *
1609 * According to the bits specified in \p mask, copies the corresponding
Jose Fonseca375457b2004-09-09 22:23:24 +00001610 * attributes from \p src into \p dst. For many of the attributes a simple \c
Keith Whitwell6dc85572003-07-17 13:43:59 +00001611 * memcpy is not enough due to the existence of internal pointers in their data
1612 * structures.
jtgafb833d1999-08-19 00:55:39 +00001613 */
Brian Paul178a1c52000-04-22 01:05:00 +00001614void
Brian Paulb1394fa2000-09-26 20:53:53 +00001615_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001616{
1617 if (mask & GL_ACCUM_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001618 /* OK to memcpy */
1619 dst->Accum = src->Accum;
jtgafb833d1999-08-19 00:55:39 +00001620 }
1621 if (mask & GL_COLOR_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001622 /* OK to memcpy */
1623 dst->Color = src->Color;
jtgafb833d1999-08-19 00:55:39 +00001624 }
1625 if (mask & GL_CURRENT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001626 /* OK to memcpy */
1627 dst->Current = src->Current;
jtgafb833d1999-08-19 00:55:39 +00001628 }
1629 if (mask & GL_DEPTH_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001630 /* OK to memcpy */
1631 dst->Depth = src->Depth;
jtgafb833d1999-08-19 00:55:39 +00001632 }
1633 if (mask & GL_ENABLE_BIT) {
1634 /* no op */
1635 }
1636 if (mask & GL_EVAL_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001637 /* OK to memcpy */
1638 dst->Eval = src->Eval;
jtgafb833d1999-08-19 00:55:39 +00001639 }
1640 if (mask & GL_FOG_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001641 /* OK to memcpy */
1642 dst->Fog = src->Fog;
jtgafb833d1999-08-19 00:55:39 +00001643 }
1644 if (mask & GL_HINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001645 /* OK to memcpy */
1646 dst->Hint = src->Hint;
jtgafb833d1999-08-19 00:55:39 +00001647 }
1648 if (mask & GL_LIGHTING_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001649 GLuint i;
1650 /* begin with memcpy */
1651 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light) );
1652 /* fixup linked lists to prevent pointer insanity */
1653 make_empty_list( &(dst->Light.EnabledList) );
1654 for (i = 0; i < MAX_LIGHTS; i++) {
1655 if (dst->Light.Light[i].Enabled) {
1656 insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
1657 }
1658 }
jtgafb833d1999-08-19 00:55:39 +00001659 }
1660 if (mask & GL_LINE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001661 /* OK to memcpy */
1662 dst->Line = src->Line;
jtgafb833d1999-08-19 00:55:39 +00001663 }
1664 if (mask & GL_LIST_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001665 /* OK to memcpy */
1666 dst->List = src->List;
jtgafb833d1999-08-19 00:55:39 +00001667 }
1668 if (mask & GL_PIXEL_MODE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001669 /* OK to memcpy */
1670 dst->Pixel = src->Pixel;
jtgafb833d1999-08-19 00:55:39 +00001671 }
1672 if (mask & GL_POINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001673 /* OK to memcpy */
1674 dst->Point = src->Point;
jtgafb833d1999-08-19 00:55:39 +00001675 }
1676 if (mask & GL_POLYGON_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001677 /* OK to memcpy */
1678 dst->Polygon = src->Polygon;
jtgafb833d1999-08-19 00:55:39 +00001679 }
1680 if (mask & GL_POLYGON_STIPPLE_BIT) {
1681 /* Use loop instead of MEMCPY due to problem with Portland Group's
1682 * C compiler. Reported by John Stone.
1683 */
Brian Paul85d81602002-06-17 23:36:31 +00001684 GLuint i;
1685 for (i = 0; i < 32; i++) {
jtgafb833d1999-08-19 00:55:39 +00001686 dst->PolygonStipple[i] = src->PolygonStipple[i];
1687 }
1688 }
1689 if (mask & GL_SCISSOR_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001690 /* OK to memcpy */
1691 dst->Scissor = src->Scissor;
jtgafb833d1999-08-19 00:55:39 +00001692 }
1693 if (mask & GL_STENCIL_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001694 /* OK to memcpy */
1695 dst->Stencil = src->Stencil;
jtgafb833d1999-08-19 00:55:39 +00001696 }
1697 if (mask & GL_TEXTURE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001698 /* Cannot memcpy because of pointers */
1699 _mesa_copy_texture_state(src, dst);
jtgafb833d1999-08-19 00:55:39 +00001700 }
1701 if (mask & GL_TRANSFORM_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001702 /* OK to memcpy */
1703 dst->Transform = src->Transform;
jtgafb833d1999-08-19 00:55:39 +00001704 }
1705 if (mask & GL_VIEWPORT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001706 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1707 dst->Viewport.X = src->Viewport.X;
1708 dst->Viewport.Y = src->Viewport.Y;
1709 dst->Viewport.Width = src->Viewport.Width;
1710 dst->Viewport.Height = src->Viewport.Height;
1711 dst->Viewport.Near = src->Viewport.Near;
1712 dst->Viewport.Far = src->Viewport.Far;
1713 _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001714 }
Brian Paul85d81602002-06-17 23:36:31 +00001715
Keith Whitwella96308c2000-10-30 13:31:59 +00001716 /* XXX FIXME: Call callbacks?
1717 */
1718 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001719}
Keith Whitwell23caf202000-11-16 21:05:34 +00001720#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001721
1722
Brian Paulb1d53d92003-06-11 18:48:19 +00001723/**
1724 * Check if the given context can render into the given framebuffer
1725 * by checking visual attributes.
1726 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1727 */
1728static GLboolean
1729check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
1730{
1731 const GLvisual *ctxvis = &ctx->Visual;
1732 const GLvisual *bufvis = &buffer->Visual;
1733
1734 if (ctxvis == bufvis)
1735 return GL_TRUE;
1736
1737 if (ctxvis->rgbMode != bufvis->rgbMode)
1738 return GL_FALSE;
1739 if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
1740 return GL_FALSE;
1741 if (ctxvis->stereoMode && !bufvis->stereoMode)
1742 return GL_FALSE;
1743 if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
1744 return GL_FALSE;
1745 if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
1746 return GL_FALSE;
1747 if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
1748 return GL_FALSE;
1749 if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
1750 return GL_FALSE;
1751 if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
1752 return GL_FALSE;
1753 if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
1754 return GL_FALSE;
1755 if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
1756 return GL_FALSE;
1757 if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
1758 return GL_FALSE;
1759
1760 return GL_TRUE;
1761}
1762
1763
Keith Whitwell6dc85572003-07-17 13:43:59 +00001764/**
Brian Paul9a33a112002-06-13 04:28:29 +00001765 * Set the current context, binding the given frame buffer to the context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001766 *
1767 * \param newCtx new GL context.
1768 * \param buffer framebuffer.
1769 *
1770 * Calls _mesa_make_current2() with \p buffer as read and write framebuffer.
Brian Paul9a33a112002-06-13 04:28:29 +00001771 */
1772void
1773_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1774{
1775 _mesa_make_current2( newCtx, buffer, buffer );
1776}
1777
Keith Whitwell6dc85572003-07-17 13:43:59 +00001778/**
1779 * Bind the given context to the given draw-buffer and read-buffer and
1780 * make it the current context for this thread.
1781 *
1782 * \param newCtx new GL context. If NULL then there will be no current GL
1783 * context.
1784 * \param drawBuffer draw framebuffer.
1785 * \param readBuffer read framebuffer.
1786 *
1787 * Check that the context's and framebuffer's visuals are compatible, returning
1788 * immediately otherwise. Sets the glapi current context via
1789 * _glapi_set_context(). If \p newCtx is not NULL, associates \p drawBuffer and
1790 * \p readBuffer with it and calls dd_function_table::ResizeBuffers if the buffers size has changed.
1791 * Calls dd_function_table::MakeCurrent callback if defined.
1792 *
1793 * When a context is bound by the first time and the \c MESA_INFO environment
1794 * variable is set it calls print_info() as an aid for remote user
1795 * troubleshooting.
Brian Paul00037781999-12-17 14:52:35 +00001796 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001797void
1798_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1799 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001800{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001801 if (MESA_VERBOSE)
Brian Paul4753d602002-06-15 02:38:15 +00001802 _mesa_debug(newCtx, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001803
Brian Paulbe3602d2001-02-28 00:27:48 +00001804 /* Check that the context's and framebuffer's visuals are compatible.
Brian Paulbe3602d2001-02-28 00:27:48 +00001805 */
Brian Paulb1d53d92003-06-11 18:48:19 +00001806 if (newCtx && drawBuffer && newCtx->DrawBuffer != drawBuffer) {
1807 if (!check_compatible(newCtx, drawBuffer))
1808 return;
1809 }
1810 if (newCtx && readBuffer && newCtx->ReadBuffer != readBuffer) {
1811 if (!check_compatible(newCtx, readBuffer))
1812 return;
Brian Paulbe3602d2001-02-28 00:27:48 +00001813 }
1814
Brian Paul00037781999-12-17 14:52:35 +00001815 /* We call this function periodically (just here for now) in
1816 * order to detect when multithreading has begun.
1817 */
1818 _glapi_check_multithread();
1819
Brian Paulf9b97d92000-01-28 20:17:42 +00001820 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001821 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001822
1823
1824 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001825 _glapi_set_dispatch(NULL); /* none current */
1826 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001827 else {
1828 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001829
Keith Whitwell23caf202000-11-16 21:05:34 +00001830 if (drawBuffer && readBuffer) {
1831 /* TODO: check if newCtx and buffer's visual match??? */
1832 newCtx->DrawBuffer = drawBuffer;
1833 newCtx->ReadBuffer = readBuffer;
1834 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul10d7f542002-06-17 23:38:14 +00001835
Keith Whitwell6dc85572003-07-17 13:43:59 +00001836#if _HAVE_FULL_GL
Brian Paul10d7f542002-06-17 23:38:14 +00001837 if (drawBuffer->Width == 0 && drawBuffer->Height == 0) {
1838 /* get initial window size */
1839 GLuint bufWidth, bufHeight;
1840
1841 /* ask device driver for size of output buffer */
1842 (*newCtx->Driver.GetBufferSize)( drawBuffer, &bufWidth, &bufHeight );
1843
Keith Whitwell6dc85572003-07-17 13:43:59 +00001844 if (drawBuffer->Width != bufWidth ||
1845 drawBuffer->Height != bufHeight) {
Brian Paul10d7f542002-06-17 23:38:14 +00001846
Keith Whitwell6dc85572003-07-17 13:43:59 +00001847 drawBuffer->Width = bufWidth;
1848 drawBuffer->Height = bufHeight;
Brian Paul10d7f542002-06-17 23:38:14 +00001849
Keith Whitwell6dc85572003-07-17 13:43:59 +00001850 newCtx->Driver.ResizeBuffers( drawBuffer );
1851 }
Brian Paul10d7f542002-06-17 23:38:14 +00001852 }
1853
1854 if (readBuffer != drawBuffer &&
1855 readBuffer->Width == 0 && readBuffer->Height == 0) {
1856 /* get initial window size */
1857 GLuint bufWidth, bufHeight;
1858
1859 /* ask device driver for size of output buffer */
1860 (*newCtx->Driver.GetBufferSize)( readBuffer, &bufWidth, &bufHeight );
1861
Keith Whitwell6dc85572003-07-17 13:43:59 +00001862 if (readBuffer->Width != bufWidth ||
1863 readBuffer->Height != bufHeight) {
Brian Paul10d7f542002-06-17 23:38:14 +00001864
Keith Whitwell6dc85572003-07-17 13:43:59 +00001865 readBuffer->Width = bufWidth;
1866 readBuffer->Height = bufHeight;
Brian Paul10d7f542002-06-17 23:38:14 +00001867
Keith Whitwell6dc85572003-07-17 13:43:59 +00001868 newCtx->Driver.ResizeBuffers( readBuffer );
1869 }
Brian Paul10d7f542002-06-17 23:38:14 +00001870 }
Keith Whitwell6dc85572003-07-17 13:43:59 +00001871#endif
Brian Paul00037781999-12-17 14:52:35 +00001872 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001873
Keith Whitwell6dc85572003-07-17 13:43:59 +00001874 /* Alert the driver - usually passed on to the sw t&l module,
1875 * but also used to detect threaded cases in the radeon codegen
1876 * hw t&l module.
1877 */
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001878 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001879 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1880
1881 /* We can use this to help debug user's problems. Tell them to set
1882 * the MESA_INFO env variable before running their app. Then the
1883 * first time each context is made current we'll print some useful
1884 * information.
1885 */
1886 if (newCtx->FirstTimeCurrent) {
Brian Paul3c634522002-10-24 23:57:19 +00001887 if (_mesa_getenv("MESA_INFO")) {
Keith Whitwell6dc85572003-07-17 13:43:59 +00001888 _mesa_print_info();
Keith Whitwell23caf202000-11-16 21:05:34 +00001889 }
1890 newCtx->FirstTimeCurrent = GL_FALSE;
1891 }
Brian Paul00037781999-12-17 14:52:35 +00001892 }
1893}
1894
Keith Whitwell6dc85572003-07-17 13:43:59 +00001895/**
1896 * Get current context for the calling thread.
1897 *
1898 * \return pointer to the current GL context.
1899 *
1900 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1901 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in context.h.
Brian Paul00037781999-12-17 14:52:35 +00001902 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001903GLcontext *
1904_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001905{
Brian Paulf9b97d92000-01-28 20:17:42 +00001906 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001907}
1908
Keith Whitwell6dc85572003-07-17 13:43:59 +00001909/**
1910 * Get context's current API dispatch table.
1911 *
1912 * It'll either be the immediate-mode execute dispatcher or the display list
1913 * compile dispatcher.
1914 *
1915 * \param ctx GL context.
1916 *
1917 * \return pointer to dispatch_table.
1918 *
1919 * Simply returns __GLcontextRec::CurrentDispatch.
Brian Paulfbd8f211999-11-11 01:22:25 +00001920 */
1921struct _glapi_table *
1922_mesa_get_dispatch(GLcontext *ctx)
1923{
1924 return ctx->CurrentDispatch;
1925}
1926
Keith Whitwell6dc85572003-07-17 13:43:59 +00001927/*@}*/
Brian Paulfbd8f211999-11-11 01:22:25 +00001928
1929
jtgafb833d1999-08-19 00:55:39 +00001930/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001931/** \name Miscellaneous functions */
jtgafb833d1999-08-19 00:55:39 +00001932/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001933/*@{*/
jtgafb833d1999-08-19 00:55:39 +00001934
Keith Whitwell6dc85572003-07-17 13:43:59 +00001935/**
1936 * Record an error.
1937 *
1938 * \param ctx GL context.
1939 * \param error error code.
1940 *
1941 * Records the given error code and call the driver's dd_function_table::Error
1942 * function if defined.
1943 *
1944 * \sa
Brian Paul4e9676f2002-06-29 19:48:15 +00001945 * This is called via _mesa_error().
jtgafb833d1999-08-19 00:55:39 +00001946 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001947void
Brian Paul4e9676f2002-06-29 19:48:15 +00001948_mesa_record_error( GLcontext *ctx, GLenum error )
jtgafb833d1999-08-19 00:55:39 +00001949{
Brian Paul18a285a2002-03-16 00:53:15 +00001950 if (!ctx)
1951 return;
1952
Brian Paul7eb06032000-07-14 04:13:40 +00001953 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00001954 ctx->ErrorValue = error;
1955 }
1956
1957 /* Call device driver's error handler, if any. This is used on the Mac. */
1958 if (ctx->Driver.Error) {
1959 (*ctx->Driver.Error)( ctx );
1960 }
1961}
1962
Keith Whitwell6dc85572003-07-17 13:43:59 +00001963/**
1964 * Execute glFinish().
1965 *
1966 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1967 * dd_function_table::Finish driver callback, if not NULL.
1968 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001969void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +00001970_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00001971{
Brian Paulfa9df402000-02-02 19:16:46 +00001972 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001973 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001974 if (ctx->Driver.Finish) {
1975 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001976 }
1977}
1978
Keith Whitwell6dc85572003-07-17 13:43:59 +00001979/**
1980 * Execute glFlush().
1981 *
1982 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1983 * dd_function_table::Flush driver callback, if not NULL.
1984 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001985void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +00001986_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00001987{
Brian Paulfa9df402000-02-02 19:16:46 +00001988 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001989 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001990 if (ctx->Driver.Flush) {
1991 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001992 }
jtgafb833d1999-08-19 00:55:39 +00001993}
Brian Paul48c6a6e2000-09-08 21:28:04 +00001994
1995
Keith Whitwell6dc85572003-07-17 13:43:59 +00001996/*@}*/