blob: fb43054cdddb8de5d77787ab8e82cc9ef1fe52b1 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001/*
2 * Mesa 3-D graphics library
Brian Paule9b34882008-12-31 11:54:02 -07003 * Version: 7.3
jtgafb833d1999-08-19 00:55:39 +00004 *
Brian145d7622007-08-16 10:05:00 +01005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Brian Paule9b34882008-12-31 11:54:02 -07006 * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00007 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
Brian Paule9b34882008-12-31 11:54:02 -070026/**
27 * \file context.c
28 * Mesa context/visual/framebuffer management functions.
29 * \author Brian Paul
30 */
jtgafb833d1999-08-19 00:55:39 +000031
Keith Whitwell6dc85572003-07-17 13:43:59 +000032/**
Brian Paul253204f2004-09-10 00:45:12 +000033 * \mainpage Mesa Main Module
Keith Whitwell6dc85572003-07-17 13:43:59 +000034 *
Brian Paul253204f2004-09-10 00:45:12 +000035 * \section MainIntroduction Introduction
Keith Whitwell6dc85572003-07-17 13:43:59 +000036 *
Brian Paul253204f2004-09-10 00:45:12 +000037 * The Mesa Main module consists of all the files in the main/ directory.
38 * Among the features of this module are:
39 * <UL>
40 * <LI> Structures to represent most GL state </LI>
41 * <LI> State set/get functions </LI>
42 * <LI> Display lists </LI>
43 * <LI> Texture unit, object and image handling </LI>
44 * <LI> Matrix and attribute stacks </LI>
45 * </UL>
Keith Whitwell6dc85572003-07-17 13:43:59 +000046 *
Brian Paul253204f2004-09-10 00:45:12 +000047 * Other modules are responsible for API dispatch, vertex transformation,
48 * point/line/triangle setup, rasterization, vertex array caching,
49 * vertex/fragment programs/shaders, etc.
Keith Whitwell6dc85572003-07-17 13:43:59 +000050 *
51 *
52 * \section AboutDoxygen About Doxygen
53 *
54 * If you're viewing this information as Doxygen-generated HTML you'll
55 * see the documentation index at the top of this page.
56 *
57 * The first line lists the Mesa source code modules.
58 * The second line lists the indexes available for viewing the documentation
59 * for each module.
60 *
61 * Selecting the <b>Main page</b> link will display a summary of the module
62 * (this page).
63 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000064 * Selecting <b>Data Structures</b> will list all C structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +000065 *
66 * Selecting the <b>File List</b> link will list all the source files in
67 * the module.
68 * Selecting a filename will show a list of all functions defined in that file.
69 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000070 * Selecting the <b>Data Fields</b> link will display a list of all
Keith Whitwell6dc85572003-07-17 13:43:59 +000071 * documented structure members.
72 *
Jose Fonseca1a5709d2003-09-17 17:14:11 +000073 * Selecting the <b>Globals</b> link will display a list
Keith Whitwell6dc85572003-07-17 13:43:59 +000074 * of all functions, structures, global variables and macros in the module.
75 *
76 */
77
78
Brian Paulfbd8f211999-11-11 01:22:25 +000079#include "glheader.h"
Brian Paulf2c02322009-02-22 15:43:29 -070080#include "mfeatures.h"
Brian Paul3c634522002-10-24 23:57:19 +000081#include "imports.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -070082#if FEATURE_accum
Keith Whitwell6dc85572003-07-17 13:43:59 +000083#include "accum.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -070084#endif
Brian Paulc9e56712008-06-09 14:49:04 -060085#include "api_exec.h"
Brian Paulc04bb512006-07-11 21:56:43 +000086#include "arrayobj.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -070087#if FEATURE_attrib_stack
Keith Whitwell6dc85572003-07-17 13:43:59 +000088#include "attrib.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -070089#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +000090#include "blend.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000091#include "buffers.h"
Brian Paul148a2842003-09-17 03:40:11 +000092#include "bufferobj.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -070093#if FEATURE_colortable
Brian Paul4bdcfe52000-04-17 17:57:04 +000094#include "colortab.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -070095#endif
jtgafb833d1999-08-19 00:55:39 +000096#include "context.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000097#include "debug.h"
98#include "depth.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -070099#if FEATURE_dlist
jtgafb833d1999-08-19 00:55:39 +0000100#include "dlist.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -0700101#endif
102#if FEATURE_evaluators
jtgafb833d1999-08-19 00:55:39 +0000103#include "eval.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -0700104#endif
jtgafb833d1999-08-19 00:55:39 +0000105#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +0000106#include "extensions.h"
Brian Paule4b23562005-05-04 20:11:35 +0000107#include "fbobject.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -0700108#if FEATURE_feedback
Keith Whitwell6dc85572003-07-17 13:43:59 +0000109#include "feedback.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -0700110#endif
jtgafb833d1999-08-19 00:55:39 +0000111#include "fog.h"
Briane6a93812007-02-26 11:37:37 -0700112#include "framebuffer.h"
Brian Paulb7a43041999-11-30 20:34:51 +0000113#include "get.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -0700114#if FEATURE_histogram
Keith Whitwell6dc85572003-07-17 13:43:59 +0000115#include "histogram.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -0700116#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +0000117#include "hint.h"
jtgafb833d1999-08-19 00:55:39 +0000118#include "hash.h"
119#include "light.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000120#include "lines.h"
jtgafb833d1999-08-19 00:55:39 +0000121#include "macros.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000122#include "matrix.h"
Brian Paulc132e2b2008-06-09 15:09:21 -0600123#include "multisample.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000124#include "pixel.h"
Brian Paul533c1db2008-06-09 14:25:23 -0600125#include "pixelstore.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000126#include "points.h"
127#include "polygon.h"
Brian Paul4e3ae762008-06-13 13:56:53 -0600128#if FEATURE_ARB_occlusion_query
Brian74afcab2007-04-21 12:42:54 -0600129#include "queryobj.h"
Brian Paul4e3ae762008-06-13 13:56:53 -0600130#endif
Keith Whitwell34a61c62008-09-21 19:29:15 -0700131#if FEATURE_drawpix
Keith Whitwell6dc85572003-07-17 13:43:59 +0000132#include "rastpos.h"
Keith Whitwell34a61c62008-09-21 19:29:15 -0700133#endif
Brian Paul55e341c2008-06-09 14:55:24 -0600134#include "scissor.h"
jtgafb833d1999-08-19 00:55:39 +0000135#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +0000136#include "state.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000137#include "stencil.h"
Brian Paul8f04c122004-04-27 13:39:20 +0000138#include "texcompress.h"
jtgafb833d1999-08-19 00:55:39 +0000139#include "teximage.h"
140#include "texobj.h"
Brian Paul85d81602002-06-17 23:36:31 +0000141#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000142#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +0000143#include "varray.h"
Brian Paul363344f2005-09-13 14:48:28 +0000144#include "version.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +0000145#include "vtxfmt.h"
Brianc223c6b2007-07-04 13:15:20 -0600146#include "glapi/glthread.h"
Brian Paul2dbc5152008-06-13 16:45:15 -0600147#include "glapi/glapioffsets.h"
148#include "glapi/glapitable.h"
Brianc223c6b2007-07-04 13:15:20 -0600149#include "shader/program.h"
Brianc223c6b2007-07-04 13:15:20 -0600150#include "shader/shader_api.h"
Brian Paulb51d73d2008-06-20 08:07:38 -0600151#if FEATURE_ATI_fragment_shader
Brianc223c6b2007-07-04 13:15:20 -0600152#include "shader/atifragshader.h"
Brian Paulb51d73d2008-06-20 08:07:38 -0600153#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +0000154#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000155#include "math/m_matrix.h"
Brian Paulddc82ee2005-02-05 19:56:45 +0000156#endif
jtgafb833d1999-08-19 00:55:39 +0000157
davem69775355a2001-06-05 23:54:00 +0000158#ifdef USE_SPARC_ASM
Ian Romanicke16f6e32004-06-26 00:02:51 +0000159#include "sparc/sparc.h"
davem69775355a2001-06-05 23:54:00 +0000160#endif
jtgafb833d1999-08-19 00:55:39 +0000161
Keith Whitwell23caf202000-11-16 21:05:34 +0000162#ifndef MESA_VERBOSE
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000163int MESA_VERBOSE = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000164#endif
165
166#ifndef MESA_DEBUG_FLAGS
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000167int MESA_DEBUG_FLAGS = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000168#endif
Brian Paulb1394fa2000-09-26 20:53:53 +0000169
Brian Paul86b84272001-12-14 02:50:01 +0000170
Brian Paul27558a12003-03-01 01:50:20 +0000171/* ubyte -> float conversion */
172GLfloat _mesa_ubyte_to_float_color_tab[256];
173
Brian Paul9a33a112002-06-13 04:28:29 +0000174
Brian Paul86b84272001-12-14 02:50:01 +0000175
Keith Whitwell6dc85572003-07-17 13:43:59 +0000176/**
177 * Swap buffers notification callback.
178 *
179 * \param gc GL context.
180 *
181 * Called by window system just before swapping buffers.
Brian Paul9a33a112002-06-13 04:28:29 +0000182 * We have to finish any pending rendering.
183 */
184void
Brian96b06ac2007-10-19 10:12:00 -0600185_mesa_notifySwapBuffers(__GLcontext *ctx)
Brian Paul9a33a112002-06-13 04:28:29 +0000186{
Brian Paule8cd8be2009-02-12 08:58:12 -0700187 FLUSH_VERTICES( ctx, 0 );
Brian96b06ac2007-10-19 10:12:00 -0600188 if (ctx->Driver.Flush) {
189 ctx->Driver.Flush(ctx);
190 }
Brian Paul9a33a112002-06-13 04:28:29 +0000191}
192
Brian Paulb1394fa2000-09-26 20:53:53 +0000193
jtgafb833d1999-08-19 00:55:39 +0000194/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000195/** \name GL Visual allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000196/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000197/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000198
Keith Whitwell6dc85572003-07-17 13:43:59 +0000199/**
Brian Paul894844a2004-03-21 17:05:03 +0000200 * Allocates a GLvisual structure and initializes it via
201 * _mesa_initialize_visual().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000202 *
203 * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
204 * \param dbFlag double buffering
205 * \param stereoFlag stereo buffer
206 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
207 * is acceptable but the actual depth type will be GLushort or GLuint as
208 * needed.
209 * \param stencilBits requested minimum bits per stencil buffer value
210 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
211 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
212 * \param redBits number of bits per color component in frame buffer for RGB(A)
213 * mode. We always use 8 in core Mesa though.
214 * \param greenBits same as above.
215 * \param blueBits same as above.
216 * \param alphaBits same as above.
217 * \param numSamples not really used.
218 *
219 * \return pointer to new GLvisual or NULL if requested parameters can't be
220 * met.
221 *
Brian Paul894844a2004-03-21 17:05:03 +0000222 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul4d053dd2000-01-14 04:45:47 +0000223 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000224GLvisual *
225_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000226 GLboolean dbFlag,
227 GLboolean stereoFlag,
228 GLint redBits,
229 GLint greenBits,
230 GLint blueBits,
231 GLint alphaBits,
232 GLint indexBits,
233 GLint depthBits,
234 GLint stencilBits,
235 GLint accumRedBits,
236 GLint accumGreenBits,
237 GLint accumBlueBits,
238 GLint accumAlphaBits,
239 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000240{
Brian Paulc7e164f2006-06-30 15:44:30 +0000241 GLvisual *vis = (GLvisual *) _mesa_calloc(sizeof(GLvisual));
Brian Paul178a1c52000-04-22 01:05:00 +0000242 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000243 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000244 redBits, greenBits, blueBits, alphaBits,
245 indexBits, depthBits, stencilBits,
246 accumRedBits, accumGreenBits,
247 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000248 numSamples)) {
Brian Paulc7e164f2006-06-30 15:44:30 +0000249 _mesa_free(vis);
Brian Paul178a1c52000-04-22 01:05:00 +0000250 return NULL;
251 }
252 }
253 return vis;
254}
255
Keith Whitwell6dc85572003-07-17 13:43:59 +0000256/**
Brian Paul894844a2004-03-21 17:05:03 +0000257 * Makes some sanity checks and fills in the fields of the
Brian Paule4b23562005-05-04 20:11:35 +0000258 * GLvisual object with the given parameters. If the caller needs
259 * to set additional fields, he should just probably init the whole GLvisual
260 * object himself.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000261 * \return GL_TRUE on success, or GL_FALSE on failure.
262 *
263 * \sa _mesa_create_visual() above for the parameter description.
Brian Paul178a1c52000-04-22 01:05:00 +0000264 */
265GLboolean
266_mesa_initialize_visual( GLvisual *vis,
267 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000268 GLboolean dbFlag,
269 GLboolean stereoFlag,
270 GLint redBits,
271 GLint greenBits,
272 GLint blueBits,
273 GLint alphaBits,
274 GLint indexBits,
275 GLint depthBits,
276 GLint stencilBits,
277 GLint accumRedBits,
278 GLint accumGreenBits,
279 GLint accumBlueBits,
280 GLint accumAlphaBits,
281 GLint numSamples )
282{
283 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000284
Brian Pauled30dfa2000-03-03 17:47:39 +0000285 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000286 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000287 }
Brian Paule4b23562005-05-04 20:11:35 +0000288 if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
Brian Paul178a1c52000-04-22 01:05:00 +0000289 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000290 }
Brian Paul978ef2b2005-09-21 03:35:08 +0000291 assert(accumRedBits >= 0);
292 assert(accumGreenBits >= 0);
293 assert(accumBlueBits >= 0);
294 assert(accumAlphaBits >= 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000295
Brian Paulb6bcae52001-01-23 23:39:36 +0000296 vis->rgbMode = rgbFlag;
297 vis->doubleBufferMode = dbFlag;
298 vis->stereoMode = stereoFlag;
Brian Paul153f1542002-10-29 15:04:35 +0000299
Brian Paulb6bcae52001-01-23 23:39:36 +0000300 vis->redBits = redBits;
301 vis->greenBits = greenBits;
302 vis->blueBits = blueBits;
303 vis->alphaBits = alphaBits;
Brian Paule4b23562005-05-04 20:11:35 +0000304 vis->rgbBits = redBits + greenBits + blueBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000305
Brian Paulb6bcae52001-01-23 23:39:36 +0000306 vis->indexBits = indexBits;
307 vis->depthBits = depthBits;
Brian Paule4b23562005-05-04 20:11:35 +0000308 vis->stencilBits = stencilBits;
309
310 vis->accumRedBits = accumRedBits;
311 vis->accumGreenBits = accumGreenBits;
312 vis->accumBlueBits = accumBlueBits;
313 vis->accumAlphaBits = accumAlphaBits;
Brian Pauled30dfa2000-03-03 17:47:39 +0000314
Brian Paul153f1542002-10-29 15:04:35 +0000315 vis->haveAccumBuffer = accumRedBits > 0;
316 vis->haveDepthBuffer = depthBits > 0;
317 vis->haveStencilBuffer = stencilBits > 0;
318
319 vis->numAuxBuffers = 0;
320 vis->level = 0;
321 vis->pixmapMode = 0;
Brian Paule4b23562005-05-04 20:11:35 +0000322 vis->sampleBuffers = numSamples > 0 ? 1 : 0;
Brian Paul894844a2004-03-21 17:05:03 +0000323 vis->samples = numSamples;
Brian Paul153f1542002-10-29 15:04:35 +0000324
Brian Paul178a1c52000-04-22 01:05:00 +0000325 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000326}
327
Brian Paul894844a2004-03-21 17:05:03 +0000328
Keith Whitwell6dc85572003-07-17 13:43:59 +0000329/**
Brian Paul894844a2004-03-21 17:05:03 +0000330 * Destroy a visual and free its memory.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000331 *
332 * \param vis visual.
333 *
334 * Frees the visual structure.
335 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000336void
337_mesa_destroy_visual( GLvisual *vis )
338{
Brian Paulc7e164f2006-06-30 15:44:30 +0000339 _mesa_free(vis);
Brian Paulb371e0d2000-03-31 01:05:51 +0000340}
341
Keith Whitwell6dc85572003-07-17 13:43:59 +0000342/*@}*/
343
Brian Paulb371e0d2000-03-31 01:05:51 +0000344
Brian Paul4d053dd2000-01-14 04:45:47 +0000345/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000346/** \name Context allocation, initialization, destroying
347 *
348 * The purpose of the most initialization functions here is to provide the
349 * default state values according to the OpenGL specification.
350 */
jtgafb833d1999-08-19 00:55:39 +0000351/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000352/*@{*/
jtgafb833d1999-08-19 00:55:39 +0000353
Keith Whitwell6dc85572003-07-17 13:43:59 +0000354/**
355 * One-time initialization mutex lock.
356 *
357 * \sa Used by one_time_init().
358 */
Brian Paul9560f052000-01-31 23:11:39 +0000359_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
360
Keith Whitwell6dc85572003-07-17 13:43:59 +0000361/**
362 * Calls all the various one-time-init functions in Mesa.
363 *
364 * While holding a global mutex lock, calls several initialization functions,
365 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
366 * defined.
367 *
Brian Paula764b7e2006-02-26 17:16:37 +0000368 * \sa _math_init().
jtgafb833d1999-08-19 00:55:39 +0000369 */
Brian Paul178a1c52000-04-22 01:05:00 +0000370static void
Brian Paul4753d602002-06-15 02:38:15 +0000371one_time_init( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000372{
373 static GLboolean alreadyCalled = GL_FALSE;
Brian Paula6c423d2004-08-25 15:59:48 +0000374 (void) ctx;
Brian Paul9560f052000-01-31 23:11:39 +0000375 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000376 if (!alreadyCalled) {
Brian Paul27558a12003-03-01 01:50:20 +0000377 GLuint i;
378
Brian Paul4d053dd2000-01-14 04:45:47 +0000379 /* do some implementation tests */
380 assert( sizeof(GLbyte) == 1 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000381 assert( sizeof(GLubyte) == 1 );
Brian Paul894844a2004-03-21 17:05:03 +0000382 assert( sizeof(GLshort) == 2 );
383 assert( sizeof(GLushort) == 2 );
384 assert( sizeof(GLint) == 4 );
385 assert( sizeof(GLuint) == 4 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000386
Brian33c37392007-04-04 22:18:53 -0600387 _mesa_init_sqrt_table();
388
Brian Paul27558a12003-03-01 01:50:20 +0000389 for (i = 0; i < 256; i++) {
390 _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
391 }
Brian Paul68ee4bc2000-01-28 19:02:22 +0000392
Brian Paul3c634522002-10-24 23:57:19 +0000393 if (_mesa_getenv("MESA_DEBUG")) {
Brian Paul68ee4bc2000-01-28 19:02:22 +0000394 _glapi_noop_enable_warnings(GL_TRUE);
Brian Paul4e9676f2002-06-29 19:48:15 +0000395 _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
Brian Paul68ee4bc2000-01-28 19:02:22 +0000396 }
397 else {
398 _glapi_noop_enable_warnings(GL_FALSE);
399 }
400
jtgafb833d1999-08-19 00:55:39 +0000401#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
Brian Paul363344f2005-09-13 14:48:28 +0000402 _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
403 MESA_VERSION_STRING, __DATE__, __TIME__);
jtgafb833d1999-08-19 00:55:39 +0000404#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000405
406 alreadyCalled = GL_TRUE;
407 }
Brian Paul9560f052000-01-31 23:11:39 +0000408 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000409}
410
Brian Paul894844a2004-03-21 17:05:03 +0000411
Keith Whitwell6dc85572003-07-17 13:43:59 +0000412/**
jtgafb833d1999-08-19 00:55:39 +0000413 * Allocate and initialize a shared context state structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000414 * Initializes the display list, texture objects and vertex programs hash
415 * tables, allocates the texture objects. If it runs out of memory, frees
416 * everything already allocated before returning NULL.
Brian Paul894844a2004-03-21 17:05:03 +0000417 *
418 * \return pointer to a gl_shared_state structure on success, or NULL on
419 * failure.
jtgafb833d1999-08-19 00:55:39 +0000420 */
Brian Paula3f13702003-04-01 16:41:50 +0000421static GLboolean
422alloc_shared_state( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000423{
Brian Paul4d24b632009-02-21 13:59:29 -0700424 GLuint i;
Brian Paula3f13702003-04-01 16:41:50 +0000425 struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000426 if (!ss)
Brian Paula3f13702003-04-01 16:41:50 +0000427 return GL_FALSE;
428
429 ctx->Shared = ss;
jtgafb833d1999-08-19 00:55:39 +0000430
Brian Paule4b684c2000-09-12 21:07:40 +0000431 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000432
Brian Paule4b684c2000-09-12 21:07:40 +0000433 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000434 ss->TexObjects = _mesa_NewHashTable();
Brian Paul610d5992003-01-14 04:55:45 +0000435 ss->Programs = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000436
Brian Paul451f3102003-04-17 01:48:19 +0000437#if FEATURE_ARB_vertex_program
Briandf43fb62008-05-06 23:08:51 -0600438 ss->DefaultVertexProgram = (struct gl_vertex_program *)
439 ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000440 if (!ss->DefaultVertexProgram)
441 goto cleanup;
442#endif
443#if FEATURE_ARB_fragment_program
Briandf43fb62008-05-06 23:08:51 -0600444 ss->DefaultFragmentProgram = (struct gl_fragment_program *)
445 ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000446 if (!ss->DefaultFragmentProgram)
447 goto cleanup;
448#endif
Dave Airlie7f752fe2004-12-19 03:06:59 +0000449#if FEATURE_ATI_fragment_shader
Brian Paul63d68302005-11-19 16:43:04 +0000450 ss->ATIShaders = _mesa_NewHashTable();
451 ss->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
Dave Airlie7f752fe2004-12-19 03:06:59 +0000452 if (!ss->DefaultFragmentShader)
453 goto cleanup;
454#endif
Brian Paul451f3102003-04-17 01:48:19 +0000455
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000456#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
Brian Paulddc82ee2005-02-05 19:56:45 +0000457 ss->BufferObjects = _mesa_NewHashTable();
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000458#endif
459
Ian Romanickee34e6e2006-06-12 16:26:29 +0000460 ss->ArrayObjects = _mesa_NewHashTable();
Brian Paulddc82ee2005-02-05 19:56:45 +0000461
Michal Krol365582d2006-08-01 20:07:31 +0000462#if FEATURE_ARB_shader_objects
Briana90046f2006-12-15 10:07:26 -0700463 ss->ShaderObjects = _mesa_NewHashTable();
Michal Krol365582d2006-08-01 20:07:31 +0000464#endif
Ian Romanick0207b472003-09-09 00:10:12 +0000465
Brian Paul4d24b632009-02-21 13:59:29 -0700466 /* Create default texture objects */
467 for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
Brian Pauld059d032009-02-21 15:15:20 -0700468 /* NOTE: the order of these enums matches the TEXTURE_x_INDEX values */
Brian Paul4d24b632009-02-21 13:59:29 -0700469 static const GLenum targets[NUM_TEXTURE_TARGETS] = {
Brian Pauld059d032009-02-21 15:15:20 -0700470 GL_TEXTURE_2D_ARRAY_EXT,
Brian Paul4d24b632009-02-21 13:59:29 -0700471 GL_TEXTURE_1D_ARRAY_EXT,
Brian Pauld059d032009-02-21 15:15:20 -0700472 GL_TEXTURE_CUBE_MAP,
473 GL_TEXTURE_3D,
474 GL_TEXTURE_RECTANGLE_NV,
475 GL_TEXTURE_2D,
476 GL_TEXTURE_1D
Brian Paul4d24b632009-02-21 13:59:29 -0700477 };
478 ss->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]);
479 if (!ss->DefaultTex[i])
480 goto cleanup;
481 }
Ian Romanickbb372f12007-05-16 15:34:22 -0700482
Brian9e01b912007-08-13 11:29:46 +0100483 /* sanity check */
Brian Paul4d24b632009-02-21 13:59:29 -0700484 assert(ss->DefaultTex[TEXTURE_1D_INDEX]->RefCount == 1);
Brian Paula3f13702003-04-01 16:41:50 +0000485
Keith Whitwell5ac93f82006-11-01 14:21:57 +0000486 _glthread_INIT_MUTEX(ss->TexMutex);
487 ss->TextureStateStamp = 0;
488
Brian Paulddc82ee2005-02-05 19:56:45 +0000489#if FEATURE_EXT_framebuffer_object
490 ss->FrameBuffers = _mesa_NewHashTable();
491 if (!ss->FrameBuffers)
492 goto cleanup;
493 ss->RenderBuffers = _mesa_NewHashTable();
494 if (!ss->RenderBuffers)
495 goto cleanup;
496#endif
497
Brian Paula3f13702003-04-01 16:41:50 +0000498 return GL_TRUE;
499
Brian9e01b912007-08-13 11:29:46 +0100500cleanup:
Brian Paula3f13702003-04-01 16:41:50 +0000501 /* Ran out of memory at some point. Free everything and return NULL */
502 if (ss->DisplayList)
503 _mesa_DeleteHashTable(ss->DisplayList);
504 if (ss->TexObjects)
505 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula3f13702003-04-01 16:41:50 +0000506 if (ss->Programs)
507 _mesa_DeleteHashTable(ss->Programs);
Brian Paul451f3102003-04-17 01:48:19 +0000508#if FEATURE_ARB_vertex_program
Briandf43fb62008-05-06 23:08:51 -0600509 _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
Brian Paul451f3102003-04-17 01:48:19 +0000510#endif
511#if FEATURE_ARB_fragment_program
Briandf43fb62008-05-06 23:08:51 -0600512 _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
Brian Paul451f3102003-04-17 01:48:19 +0000513#endif
Dave Airlie7f752fe2004-12-19 03:06:59 +0000514#if FEATURE_ATI_fragment_shader
515 if (ss->DefaultFragmentShader)
Brian Paul63d68302005-11-19 16:43:04 +0000516 _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
Dave Airlie7f752fe2004-12-19 03:06:59 +0000517#endif
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000518#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
Ian Romanick0207b472003-09-09 00:10:12 +0000519 if (ss->BufferObjects)
520 _mesa_DeleteHashTable(ss->BufferObjects);
Brian Paulddc82ee2005-02-05 19:56:45 +0000521#endif
522
Tilman Sauerbeckc0eb7772006-07-11 19:36:27 +0000523 if (ss->ArrayObjects)
524 _mesa_DeleteHashTable (ss->ArrayObjects);
525
Michal Krol365582d2006-08-01 20:07:31 +0000526#if FEATURE_ARB_shader_objects
Brian0bf5dbe2006-12-19 18:02:41 -0700527 if (ss->ShaderObjects)
Briana90046f2006-12-15 10:07:26 -0700528 _mesa_DeleteHashTable (ss->ShaderObjects);
Michal Krol365582d2006-08-01 20:07:31 +0000529#endif
Ian Romanick0207b472003-09-09 00:10:12 +0000530
Brian Paulddc82ee2005-02-05 19:56:45 +0000531#if FEATURE_EXT_framebuffer_object
532 if (ss->FrameBuffers)
533 _mesa_DeleteHashTable(ss->FrameBuffers);
534 if (ss->RenderBuffers)
535 _mesa_DeleteHashTable(ss->RenderBuffers);
536#endif
537
Brian Paul4d24b632009-02-21 13:59:29 -0700538 for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
539 if (ss->DefaultTex[i])
540 ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
541 }
Briana5c84de2008-01-01 10:20:21 -0700542
543 _mesa_free(ss);
544
Brian Paula3f13702003-04-01 16:41:50 +0000545 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000546}
547
Brian Paulc7e164f2006-06-30 15:44:30 +0000548
Keith Whitwell6dc85572003-07-17 13:43:59 +0000549/**
Brian Paulc7e164f2006-06-30 15:44:30 +0000550 * Callback for deleting a display list. Called by _mesa_HashDeleteAll().
551 */
552static void
553delete_displaylist_cb(GLuint id, void *data, void *userData)
554{
Keith Whitwell34a61c62008-09-21 19:29:15 -0700555#if FEATURE_dlist
Brian446abc22009-01-31 11:57:22 -0700556 struct gl_display_list *list = (struct gl_display_list *) data;
Brian Paulc7e164f2006-06-30 15:44:30 +0000557 GLcontext *ctx = (GLcontext *) userData;
558 _mesa_delete_list(ctx, list);
Keith Whitwell34a61c62008-09-21 19:29:15 -0700559#endif
Brian Paulc7e164f2006-06-30 15:44:30 +0000560}
561
562/**
563 * Callback for deleting a texture object. Called by _mesa_HashDeleteAll().
564 */
565static void
566delete_texture_cb(GLuint id, void *data, void *userData)
567{
568 struct gl_texture_object *texObj = (struct gl_texture_object *) data;
569 GLcontext *ctx = (GLcontext *) userData;
570 ctx->Driver.DeleteTexture(ctx, texObj);
571}
572
573/**
574 * Callback for deleting a program object. Called by _mesa_HashDeleteAll().
575 */
576static void
577delete_program_cb(GLuint id, void *data, void *userData)
578{
Brian Paul122629f2006-07-20 16:49:57 +0000579 struct gl_program *prog = (struct gl_program *) data;
Brian Paulc7e164f2006-06-30 15:44:30 +0000580 GLcontext *ctx = (GLcontext *) userData;
Brian Paulfbfe2a52008-05-19 08:43:36 -0600581 ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */
582 prog->RefCount = 0; /* now going away */
Brian Paulc7e164f2006-06-30 15:44:30 +0000583 ctx->Driver.DeleteProgram(ctx, prog);
584}
585
Brian Paule961a5d2008-06-12 16:55:28 -0600586#if FEATURE_ATI_fragment_shader
Brian Paulc7e164f2006-06-30 15:44:30 +0000587/**
588 * Callback for deleting an ATI fragment shader object.
589 * Called by _mesa_HashDeleteAll().
590 */
591static void
592delete_fragshader_cb(GLuint id, void *data, void *userData)
593{
594 struct ati_fragment_shader *shader = (struct ati_fragment_shader *) data;
595 GLcontext *ctx = (GLcontext *) userData;
596 _mesa_delete_ati_fragment_shader(ctx, shader);
597}
Brian Paule961a5d2008-06-12 16:55:28 -0600598#endif
Brian Paulc7e164f2006-06-30 15:44:30 +0000599
600/**
601 * Callback for deleting a buffer object. Called by _mesa_HashDeleteAll().
602 */
603static void
604delete_bufferobj_cb(GLuint id, void *data, void *userData)
605{
606 struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data;
607 GLcontext *ctx = (GLcontext *) userData;
608 ctx->Driver.DeleteBuffer(ctx, bufObj);
609}
610
Brian Paulc04bb512006-07-11 21:56:43 +0000611/**
612 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
613 */
614static void
615delete_arrayobj_cb(GLuint id, void *data, void *userData)
616{
617 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
618 GLcontext *ctx = (GLcontext *) userData;
619 _mesa_delete_array_object(ctx, arrayObj);
620}
621
Brian Paul4d4373b2006-11-18 17:44:28 +0000622/**
Xiang, Haihao63d8a842008-03-31 17:02:47 +0800623 * Callback for freeing shader program data. Call it before delete_shader_cb
624 * to avoid memory access error.
625 */
626static void
627free_shader_program_data_cb(GLuint id, void *data, void *userData)
628{
629 GLcontext *ctx = (GLcontext *) userData;
630 struct gl_shader_program *shProg = (struct gl_shader_program *) data;
631
632 if (shProg->Type == GL_SHADER_PROGRAM_MESA) {
633 _mesa_free_shader_program_data(ctx, shProg);
634 }
635}
636
637/**
Brian9e4bae92006-12-20 09:27:42 -0700638 * Callback for deleting shader and shader programs objects.
639 * Called by _mesa_HashDeleteAll().
Brian Paul4d4373b2006-11-18 17:44:28 +0000640 */
641static void
Brian9e4bae92006-12-20 09:27:42 -0700642delete_shader_cb(GLuint id, void *data, void *userData)
Brian Paul4d4373b2006-11-18 17:44:28 +0000643{
Brian9e4bae92006-12-20 09:27:42 -0700644 GLcontext *ctx = (GLcontext *) userData;
645 struct gl_shader *sh = (struct gl_shader *) data;
Xiang, Haihaoaef47c42008-03-31 16:27:47 +0800646 if (sh->Type == GL_FRAGMENT_SHADER || sh->Type == GL_VERTEX_SHADER) {
647 _mesa_free_shader(ctx, sh);
648 }
649 else {
650 struct gl_shader_program *shProg = (struct gl_shader_program *) data;
651 ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA);
652 _mesa_free_shader_program(ctx, shProg);
653 }
Brian Paul4d4373b2006-11-18 17:44:28 +0000654}
655
Brian393a6252007-08-13 17:37:30 +0100656/**
657 * Callback for deleting a framebuffer object. Called by _mesa_HashDeleteAll()
658 */
659static void
660delete_framebuffer_cb(GLuint id, void *data, void *userData)
661{
662 struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
Briandc732172007-08-14 11:56:59 +0100663 /* The fact that the framebuffer is in the hashtable means its refcount
664 * is one, but we're removing from the hashtable now. So clear refcount.
665 */
666 /*assert(fb->RefCount == 1);*/
667 fb->RefCount = 0;
Brian2f7c8042008-01-30 08:08:23 -0700668
669 /* NOTE: Delete should always be defined but there are two reports
670 * of it being NULL (bugs 13507, 14293). Work-around for now.
671 */
672 if (fb->Delete)
673 fb->Delete(fb);
Brian393a6252007-08-13 17:37:30 +0100674}
675
676/**
677 * Callback for deleting a renderbuffer object. Called by _mesa_HashDeleteAll()
678 */
679static void
680delete_renderbuffer_cb(GLuint id, void *data, void *userData)
681{
682 struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data;
Briandc732172007-08-14 11:56:59 +0100683 rb->RefCount = 0; /* see comment for FBOs above */
Brian Paul61b3ce82008-08-03 11:13:12 -0600684 if (rb->Delete)
685 rb->Delete(rb);
Brian393a6252007-08-13 17:37:30 +0100686}
687
688
Brian Paulc7e164f2006-06-30 15:44:30 +0000689/**
690 * Deallocate a shared state object and all children structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000691 *
692 * \param ctx GL context.
693 * \param ss shared state pointer.
694 *
695 * Frees the display lists, the texture objects (calling the driver texture
696 * deletion callback to free its private data) and the vertex programs, as well
697 * as their hash tables.
698 *
699 * \sa alloc_shared_state().
jtgafb833d1999-08-19 00:55:39 +0000700 */
Brian Paul178a1c52000-04-22 01:05:00 +0000701static void
702free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000703{
Brian Paul4d24b632009-02-21 13:59:29 -0700704 GLuint i;
705
Brian Paulc7e164f2006-06-30 15:44:30 +0000706 /*
707 * Free display lists
708 */
709 _mesa_HashDeleteAll(ss->DisplayList, delete_displaylist_cb, ctx);
Brian Paulbb797902000-01-24 16:19:54 +0000710 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000711
Brian Paulfbfe2a52008-05-19 08:43:36 -0600712#if FEATURE_ARB_shader_objects
713 _mesa_HashWalk(ss->ShaderObjects, free_shader_program_data_cb, ctx);
714 _mesa_HashDeleteAll(ss->ShaderObjects, delete_shader_cb, ctx);
715 _mesa_DeleteHashTable(ss->ShaderObjects);
716#endif
717
Brian Paulc7e164f2006-06-30 15:44:30 +0000718 _mesa_HashDeleteAll(ss->Programs, delete_program_cb, ctx);
Brian Paul610d5992003-01-14 04:55:45 +0000719 _mesa_DeleteHashTable(ss->Programs);
Brian Paul85f553d2008-06-20 10:47:38 -0600720
Brian Paul21841f02004-08-14 14:28:11 +0000721#if FEATURE_ARB_vertex_program
Briandf43fb62008-05-06 23:08:51 -0600722 _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
Brian Paul21841f02004-08-14 14:28:11 +0000723#endif
724#if FEATURE_ARB_fragment_program
Briandf43fb62008-05-06 23:08:51 -0600725 _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
Brian Paul21841f02004-08-14 14:28:11 +0000726#endif
Brian Paul1096eae2006-01-16 16:35:13 +0000727
Dave Airlie7f752fe2004-12-19 03:06:59 +0000728#if FEATURE_ATI_fragment_shader
Brian Paulc7e164f2006-06-30 15:44:30 +0000729 _mesa_HashDeleteAll(ss->ATIShaders, delete_fragshader_cb, ctx);
Brian Paul1096eae2006-01-16 16:35:13 +0000730 _mesa_DeleteHashTable(ss->ATIShaders);
731 _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
Dave Airlie7f752fe2004-12-19 03:06:59 +0000732#endif
Brian Paul30f51ae2001-12-18 04:06:44 +0000733
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000734#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
Brian Paulc7e164f2006-06-30 15:44:30 +0000735 _mesa_HashDeleteAll(ss->BufferObjects, delete_bufferobj_cb, ctx);
Ian Romanick0207b472003-09-09 00:10:12 +0000736 _mesa_DeleteHashTable(ss->BufferObjects);
Brian Paulddc82ee2005-02-05 19:56:45 +0000737#endif
738
Brian Paulc04bb512006-07-11 21:56:43 +0000739 _mesa_HashDeleteAll(ss->ArrayObjects, delete_arrayobj_cb, ctx);
Tilman Sauerbeckc0eb7772006-07-11 19:36:27 +0000740 _mesa_DeleteHashTable(ss->ArrayObjects);
741
Brian Paulddc82ee2005-02-05 19:56:45 +0000742#if FEATURE_EXT_framebuffer_object
Brian393a6252007-08-13 17:37:30 +0100743 _mesa_HashDeleteAll(ss->FrameBuffers, delete_framebuffer_cb, ctx);
Brian Paulddc82ee2005-02-05 19:56:45 +0000744 _mesa_DeleteHashTable(ss->FrameBuffers);
Brian393a6252007-08-13 17:37:30 +0100745 _mesa_HashDeleteAll(ss->RenderBuffers, delete_renderbuffer_cb, ctx);
Brian Paulddc82ee2005-02-05 19:56:45 +0000746 _mesa_DeleteHashTable(ss->RenderBuffers);
747#endif
Michal Krol9b3752c2005-01-13 14:08:47 +0000748
Briandc732172007-08-14 11:56:59 +0100749 /*
750 * Free texture objects (after FBOs since some textures might have
751 * been bound to FBOs).
752 */
753 ASSERT(ctx->Driver.DeleteTexture);
754 /* the default textures */
Brian Paul4d24b632009-02-21 13:59:29 -0700755 for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
756 ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
757 }
Briandc732172007-08-14 11:56:59 +0100758 /* all other textures */
759 _mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx);
760 _mesa_DeleteHashTable(ss->TexObjects);
761
Keith Whitwelle15fd852002-12-12 13:03:15 +0000762 _glthread_DESTROY_MUTEX(ss->Mutex);
763
Brian Paulc7e164f2006-06-30 15:44:30 +0000764 _mesa_free(ss);
jtgafb833d1999-08-19 00:55:39 +0000765}
766
767
Brian Paul4d859f72004-01-23 18:57:05 +0000768/**
769 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
770 */
771static void
Briand881a9c2006-12-20 09:31:07 -0700772_mesa_init_current(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +0000773{
Brian Paul88bf0382004-02-13 15:30:08 +0000774 GLuint i;
jtgafb833d1999-08-19 00:55:39 +0000775
Brian Paul94b30dc2006-04-25 00:53:25 +0000776 /* Init all to (0,0,0,1) */
Keith Whitwell6dc85572003-07-17 13:43:59 +0000777 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
778 ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000779 }
Brian Paul94b30dc2006-04-25 00:53:25 +0000780
781 /* redo special cases: */
Markus Amsler507da2472008-03-09 17:51:11 -0600782 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
Keith Whitwell6dc85572003-07-17 13:43:59 +0000783 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
784 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
Brian Paul88bf0382004-02-13 15:30:08 +0000785 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
Keith Whitwellfd275602006-10-30 20:16:35 +0000786 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
787 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000788}
789
790
Brian Paul4d859f72004-01-23 18:57:05 +0000791/**
Brian Paulf51cca72008-09-25 19:22:29 -0600792 * Init vertex/fragment program limits.
793 * Important: drivers should override these with actual limits.
Brian Paul05051032005-11-01 04:36:33 +0000794 */
795static void
Brian Paulf51cca72008-09-25 19:22:29 -0600796init_program_limits(GLenum type, struct gl_program_constants *prog)
Brian Paul05051032005-11-01 04:36:33 +0000797{
Brian Paulf51cca72008-09-25 19:22:29 -0600798 prog->MaxInstructions = MAX_PROGRAM_INSTRUCTIONS;
799 prog->MaxAluInstructions = MAX_PROGRAM_INSTRUCTIONS;
800 prog->MaxTexInstructions = MAX_PROGRAM_INSTRUCTIONS;
801 prog->MaxTexIndirections = MAX_PROGRAM_INSTRUCTIONS;
802 prog->MaxTemps = MAX_PROGRAM_TEMPS;
803 prog->MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
804 prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
805 prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
806
807 if (type == GL_VERTEX_PROGRAM_ARB) {
808 prog->MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
809 prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
810 prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
811 }
812 else {
813 prog->MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
814 prog->MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
815 prog->MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
816 }
817
818 /* copy the above limits to init native limits */
Brian Paul05051032005-11-01 04:36:33 +0000819 prog->MaxNativeInstructions = prog->MaxInstructions;
820 prog->MaxNativeAluInstructions = prog->MaxAluInstructions;
821 prog->MaxNativeTexInstructions = prog->MaxTexInstructions;
822 prog->MaxNativeTexIndirections = prog->MaxTexIndirections;
823 prog->MaxNativeAttribs = prog->MaxAttribs;
824 prog->MaxNativeTemps = prog->MaxTemps;
825 prog->MaxNativeAddressRegs = prog->MaxAddressRegs;
826 prog->MaxNativeParameters = prog->MaxParameters;
827}
828
829
830/**
Brian Paul4d859f72004-01-23 18:57:05 +0000831 * Initialize fields of gl_constants (aka ctx->Const.*).
832 * Use defaults from config.h. The device drivers will often override
833 * some of these values (such as number of texture units).
834 */
Keith Whitwell6dc85572003-07-17 13:43:59 +0000835static void
Briand881a9c2006-12-20 09:31:07 -0700836_mesa_init_constants(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +0000837{
Brian Paul4d053dd2000-01-14 04:45:47 +0000838 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000839
Brian Paulcd1cefa2001-06-13 14:56:14 +0000840 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
841 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
842
Brian Paul65591072009-02-13 07:44:02 -0700843 /* Max texture size should be <= max viewport size (render to texture) */
844 assert((1 << (MAX_TEXTURE_LEVELS - 1)) <= MAX_WIDTH);
845
Brian Paul53f82c52004-10-02 16:39:09 +0000846 /* Constants, may be overriden (usually only reduced) by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000847 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +0000848 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
849 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul8afe7de2002-06-15 03:03:06 +0000850 ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
Ian Romanickbb372f12007-05-16 15:34:22 -0700851 ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
Brian Paul610d5992003-01-14 04:55:45 +0000852 ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
853 ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
Brian Paulda238ee2006-04-13 19:21:58 +0000854 ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
855 ctx->Const.MaxTextureImageUnits);
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000856 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +0000857 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000858 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000859 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
860 ctx->Const.MinPointSize = MIN_POINT_SIZE;
861 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
862 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
863 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000864 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000865 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
866 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
867 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
868 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000869 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000870 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000871 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
872 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paula8644322000-11-27 18:22:13 +0000873 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
874 ctx->Const.MaxLights = MAX_LIGHTS;
Ian Romanick882caa12003-05-30 21:37:14 +0000875 ctx->Const.MaxShininess = 128.0;
Brian Paul53f82c52004-10-02 16:39:09 +0000876 ctx->Const.MaxSpotExponent = 128.0;
877 ctx->Const.MaxViewportWidth = MAX_WIDTH;
878 ctx->Const.MaxViewportHeight = MAX_HEIGHT;
Brian Pauld0492cf2003-04-11 01:20:06 +0000879#if FEATURE_ARB_vertex_program
Brian Paulf51cca72008-09-25 19:22:29 -0600880 init_program_limits(GL_VERTEX_PROGRAM_ARB, &ctx->Const.VertexProgram);
Brian Pauld0492cf2003-04-11 01:20:06 +0000881#endif
882#if FEATURE_ARB_fragment_program
Brian Paulf51cca72008-09-25 19:22:29 -0600883 init_program_limits(GL_FRAGMENT_PROGRAM_ARB, &ctx->Const.FragmentProgram);
Brian Pauld0492cf2003-04-11 01:20:06 +0000884#endif
Brian Pauledd67742003-04-18 18:02:43 +0000885 ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
886 ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
Brian Pauld0492cf2003-04-11 01:20:06 +0000887
George Sapountzis507167d2006-12-06 06:54:13 +0200888 /* CheckArrayBounds is overriden by drivers/x11 for X server */
Brian Paula2b9bad2003-11-10 19:08:37 +0000889 ctx->Const.CheckArrayBounds = GL_FALSE;
Brian Paula2b9bad2003-11-10 19:08:37 +0000890
Brian Paul05051032005-11-01 04:36:33 +0000891 /* GL_ARB_draw_buffers */
Brian Paul53f82c52004-10-02 16:39:09 +0000892 ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
893
Brian Paul3deaa012005-02-07 05:08:24 +0000894 /* GL_OES_read_format */
Ian Romanick33899b72004-10-16 01:16:54 +0000895 ctx->Const.ColorReadFormat = GL_RGBA;
896 ctx->Const.ColorReadType = GL_UNSIGNED_BYTE;
897
Brian Paul3deaa012005-02-07 05:08:24 +0000898#if FEATURE_EXT_framebuffer_object
899 ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
900 ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
901#endif
902
Brian Paul90fcf6c2006-11-01 00:12:41 +0000903#if FEATURE_ARB_vertex_shader
904 ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
Briana90046f2006-12-15 10:07:26 -0700905 ctx->Const.MaxVarying = MAX_VARYING;
Brian Paul90fcf6c2006-11-01 00:12:41 +0000906#endif
907
Brian Paul8fb88552009-01-20 15:29:08 -0700908 /* GL_ARB_framebuffer_object */
909 ctx->Const.MaxSamples = 0;
910
Brian Paul53f82c52004-10-02 16:39:09 +0000911 /* sanity checks */
Brian Paulda238ee2006-04-13 19:21:58 +0000912 ASSERT(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
913 ctx->Const.MaxTextureCoordUnits));
Brian Paul05051032005-11-01 04:36:33 +0000914 ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
915 ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
Briana90046f2006-12-15 10:07:26 -0700916
917 ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
918 ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
919 ASSERT(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
920 ASSERT(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
Keith Whitwell6dc85572003-07-17 13:43:59 +0000921}
jtgafb833d1999-08-19 00:55:39 +0000922
Brian Paul4d859f72004-01-23 18:57:05 +0000923
Keith Whitwell6dc85572003-07-17 13:43:59 +0000924/**
Brian Paul5e2e96b2006-05-15 15:26:04 +0000925 * Do some sanity checks on the limits/constants for the given context.
926 * Only called the first time a context is bound.
927 */
928static void
929check_context_limits(GLcontext *ctx)
930{
931 /* Many context limits/constants are limited by the size of
932 * internal arrays.
933 */
934 assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
935 assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
936 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
937 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
938
Brian Paule9b34882008-12-31 11:54:02 -0700939 /* number of coord units cannot be greater than number of image units */
940 assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
941
Brian Paul65591072009-02-13 07:44:02 -0700942 assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
943 assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
944 assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
945 assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
Brian Paul5e2e96b2006-05-15 15:26:04 +0000946
947 /* make sure largest texture image is <= MAX_WIDTH in size */
Brian Paul65591072009-02-13 07:44:02 -0700948 assert((1 << (ctx->Const.MaxTextureLevels - 1)) <= MAX_WIDTH);
949 assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= MAX_WIDTH);
950 assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= MAX_WIDTH);
951
952 assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
953 assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
Brian Paul5e2e96b2006-05-15 15:26:04 +0000954
955 assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
956
957 /* XXX probably add more tests */
958}
959
960
961/**
Keith Whitwell6dc85572003-07-17 13:43:59 +0000962 * Initialize the attribute groups in a GL context.
963 *
964 * \param ctx GL context.
965 *
966 * Initializes all the attributes, calling the respective <tt>init*</tt>
967 * functions for the more complex data structures.
968 */
969static GLboolean
Briand881a9c2006-12-20 09:31:07 -0700970init_attrib_groups(GLcontext *ctx)
Keith Whitwell6dc85572003-07-17 13:43:59 +0000971{
972 assert(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +0000973
Keith Whitwell6dc85572003-07-17 13:43:59 +0000974 /* Constants */
975 _mesa_init_constants( ctx );
Brian Paul0771d152000-04-07 00:19:41 +0000976
Brian Paul4d053dd2000-01-14 04:45:47 +0000977 /* Extensions */
Brian Paulde4f4602003-07-03 02:15:06 +0000978 _mesa_init_extensions( ctx );
jtgafb833d1999-08-19 00:55:39 +0000979
Keith Whitwell6dc85572003-07-17 13:43:59 +0000980 /* Attribute Groups */
Keith Whitwell34a61c62008-09-21 19:29:15 -0700981#if FEATURE_accum
Keith Whitwell6dc85572003-07-17 13:43:59 +0000982 _mesa_init_accum( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -0700983#endif
984#if FEATURE_attrib_stack
Keith Whitwell6dc85572003-07-17 13:43:59 +0000985 _mesa_init_attrib( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -0700986#endif
Brian Paul148a2842003-09-17 03:40:11 +0000987 _mesa_init_buffer_objects( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +0000988 _mesa_init_color( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -0700989#if FEATURE_colortable
Brian Paul05944c02003-07-22 03:51:46 +0000990 _mesa_init_colortables( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -0700991#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +0000992 _mesa_init_current( ctx );
993 _mesa_init_depth( ctx );
994 _mesa_init_debug( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -0700995#if FEATURE_dlist
Keith Whitwell6dc85572003-07-17 13:43:59 +0000996 _mesa_init_display_list( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -0700997#endif
998#if FEATURE_evaluators
Keith Whitwell6dc85572003-07-17 13:43:59 +0000999 _mesa_init_eval( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001000#endif
Brian Paul3dc65912008-07-03 15:40:38 -06001001 _mesa_init_fbobjects( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001002#if FEATURE_feedback
Keith Whitwell6dc85572003-07-17 13:43:59 +00001003 _mesa_init_feedback( ctx );
Brian Paulc1156162008-06-20 14:29:49 -06001004#else
1005 ctx->RenderMode = GL_RENDER;
Keith Whitwell34a61c62008-09-21 19:29:15 -07001006#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001007 _mesa_init_fog( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001008#if FEATURE_histogram
Keith Whitwell6dc85572003-07-17 13:43:59 +00001009 _mesa_init_histogram( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001010#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001011 _mesa_init_hint( ctx );
1012 _mesa_init_line( ctx );
1013 _mesa_init_lighting( ctx );
1014 _mesa_init_matrix( ctx );
Brian Paul67742382005-02-26 17:16:12 +00001015 _mesa_init_multisample( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001016 _mesa_init_pixel( ctx );
Brian Paul533c1db2008-06-09 14:25:23 -06001017 _mesa_init_pixelstore( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001018 _mesa_init_point( ctx );
1019 _mesa_init_polygon( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001020 _mesa_init_program( ctx );
Brian Paul4e3ae762008-06-13 13:56:53 -06001021#if FEATURE_ARB_occlusion_query
Brian Paul4fb99502005-09-02 13:42:49 +00001022 _mesa_init_query( ctx );
Brian Paul4e3ae762008-06-13 13:56:53 -06001023#endif
Keith Whitwell34a61c62008-09-21 19:29:15 -07001024#if FEATURE_drawpix
Brian Paulddc82ee2005-02-05 19:56:45 +00001025 _mesa_init_rastpos( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001026#endif
Brian Paul67742382005-02-26 17:16:12 +00001027 _mesa_init_scissor( ctx );
Brian0bf5dbe2006-12-19 18:02:41 -07001028 _mesa_init_shader_state( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001029 _mesa_init_stencil( ctx );
1030 _mesa_init_transform( ctx );
1031 _mesa_init_varray( ctx );
1032 _mesa_init_viewport( ctx );
jtgafb833d1999-08-19 00:55:39 +00001033
Keith Whitwell6dc85572003-07-17 13:43:59 +00001034 if (!_mesa_init_texture( ctx ))
1035 return GL_FALSE;
Brian Paulb17a7222003-06-13 02:37:27 +00001036
Keith Whitwell34a61c62008-09-21 19:29:15 -07001037#if FEATURE_texture_s3tc
Brian Paul8f04c122004-04-27 13:39:20 +00001038 _mesa_init_texture_s3tc( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001039#endif
1040#if FEATURE_texture_fxt1
Brian Paul8f04c122004-04-27 13:39:20 +00001041 _mesa_init_texture_fxt1( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001042#endif
Brian Paul8f04c122004-04-27 13:39:20 +00001043
Brian Paul4d053dd2000-01-14 04:45:47 +00001044 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001045 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001046 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
Keith Whitwell568e96b2008-10-14 14:15:26 +01001047 ctx->varying_vp_inputs = ~0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001048
Brian Paula3f13702003-04-01 16:41:50 +00001049 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001050}
1051
1052
Brian Paulf44898c2003-07-18 15:44:57 +00001053/**
Brian4b654d42007-08-23 08:53:43 +01001054 * Update default objects in a GL context with respect to shared state.
1055 *
1056 * \param ctx GL context.
1057 *
1058 * Removes references to old default objects, (texture objects, program
1059 * objects, etc.) and changes to reference those from the current shared
1060 * state.
1061 */
1062static GLboolean
1063update_default_objects(GLcontext *ctx)
1064{
1065 assert(ctx);
1066
1067 _mesa_update_default_objects_program(ctx);
1068 _mesa_update_default_objects_texture(ctx);
1069 _mesa_update_default_objects_buffer_objects(ctx);
1070
1071 return GL_TRUE;
1072}
1073
1074
1075/**
Brian Paul21f69782004-11-27 05:05:32 +00001076 * This is the default function we plug into all dispatch table slots
1077 * This helps prevents a segfault when someone calls a GL function without
1078 * first checking if the extension's supported.
1079 */
1080static int
1081generic_nop(void)
1082{
Briancf239ce2007-06-11 10:57:01 -06001083 _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
Brian Paul21f69782004-11-27 05:05:32 +00001084 return 0;
1085}
1086
1087
1088/**
1089 * Allocate and initialize a new dispatch table.
1090 */
1091static struct _glapi_table *
1092alloc_dispatch_table(void)
1093{
1094 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1095 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1096 * Mesa we do this to accomodate different versions of libGL and various
1097 * DRI drivers.
1098 */
1099 GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
1100 sizeof(struct _glapi_table) / sizeof(_glapi_proc));
1101 struct _glapi_table *table =
1102 (struct _glapi_table *) _mesa_malloc(numEntries * sizeof(_glapi_proc));
1103 if (table) {
1104 _glapi_proc *entry = (_glapi_proc *) table;
Brian Paula760ccf2004-12-03 15:24:34 +00001105 GLint i;
Brian Paul21f69782004-11-27 05:05:32 +00001106 for (i = 0; i < numEntries; i++) {
1107 entry[i] = (_glapi_proc) generic_nop;
1108 }
1109 }
1110 return table;
1111}
1112
1113
1114/**
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001115 * Initialize a GLcontext struct (rendering context).
Keith Whitwell6dc85572003-07-17 13:43:59 +00001116 *
1117 * This includes allocating all the other structs and arrays which hang off of
1118 * the context by pointers.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001119 * Note that the driver needs to pass in its dd_function_table here since
1120 * we need to at least call driverFunctions->NewTextureObject to create the
1121 * default texture objects.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001122 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001123 * Called by _mesa_create_context().
Keith Whitwell6dc85572003-07-17 13:43:59 +00001124 *
1125 * Performs the imports and exports callback tables initialization, and
1126 * miscellaneous one-time initializations. If no shared context is supplied one
1127 * is allocated, and increase its reference count. Setups the GL API dispatch
1128 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
1129 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1130 * for debug flags.
1131 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001132 * \param ctx the context to initialize
1133 * \param visual describes the visual attributes for this context
1134 * \param share_list points to context to share textures, display lists,
1135 * etc with, or NULL
1136 * \param driverFunctions table of device driver functions for this context
1137 * to use
1138 * \param driverContext pointer to driver-specific context data
jtgafb833d1999-08-19 00:55:39 +00001139 */
Brian Paul178a1c52000-04-22 01:05:00 +00001140GLboolean
Briand881a9c2006-12-20 09:31:07 -07001141_mesa_initialize_context(GLcontext *ctx,
1142 const GLvisual *visual,
1143 GLcontext *share_list,
1144 const struct dd_function_table *driverFunctions,
1145 void *driverContext)
jtgafb833d1999-08-19 00:55:39 +00001146{
Brian7cafaff2007-11-01 14:51:37 -06001147 /*ASSERT(driverContext);*/
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001148 assert(driverFunctions->NewTextureObject);
Keith Whitwell3e62d3a2005-03-22 14:27:10 +00001149 assert(driverFunctions->FreeTexImageData);
jtgafb833d1999-08-19 00:55:39 +00001150
Brian Paul4753d602002-06-15 02:38:15 +00001151 /* misc one-time initializations */
1152 one_time_init(ctx);
Brian Paul9a33a112002-06-13 04:28:29 +00001153
Brian Paulb1394fa2000-09-26 20:53:53 +00001154 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001155 ctx->DrawBuffer = NULL;
1156 ctx->ReadBuffer = NULL;
Brian Paule4b23562005-05-04 20:11:35 +00001157 ctx->WinSysDrawBuffer = NULL;
1158 ctx->WinSysReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001159
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001160 /* Plug in driver functions and context pointer here.
1161 * This is important because when we call alloc_shared_state() below
1162 * we'll call ctx->Driver.NewTextureObject() to create the default
1163 * textures.
Brian Paula3f13702003-04-01 16:41:50 +00001164 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001165 ctx->Driver = *driverFunctions;
1166 ctx->DriverCtx = driverContext;
Brian Paula3f13702003-04-01 16:41:50 +00001167
jtgafb833d1999-08-19 00:55:39 +00001168 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001169 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001170 ctx->Shared = share_list->Shared;
1171 }
1172 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001173 /* allocate new, unshared state */
Brian Paula3f13702003-04-01 16:41:50 +00001174 if (!alloc_shared_state( ctx )) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001175 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001176 }
1177 }
Brian Paul9560f052000-01-31 23:11:39 +00001178 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001179 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001180 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001181
Keith Whitwell6dc85572003-07-17 13:43:59 +00001182 if (!init_attrib_groups( ctx )) {
jtgafb833d1999-08-19 00:55:39 +00001183 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001184 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001185 }
jtgafb833d1999-08-19 00:55:39 +00001186
Brian Paul21f69782004-11-27 05:05:32 +00001187 /* setup the API dispatch tables */
1188 ctx->Exec = alloc_dispatch_table();
1189 ctx->Save = alloc_dispatch_table();
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001190 if (!ctx->Exec || !ctx->Save) {
1191 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001192 if (ctx->Exec)
Brian Paul21f69782004-11-27 05:05:32 +00001193 _mesa_free(ctx->Exec);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001194 }
Brian Paulcd4d4f52008-06-17 16:56:32 -06001195#if FEATURE_dispatch
Brian Paul21f69782004-11-27 05:05:32 +00001196 _mesa_init_exec_table(ctx->Exec);
Brian Paulcd4d4f52008-06-17 16:56:32 -06001197#endif
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001198 ctx->CurrentDispatch = ctx->Exec;
Keith Whitwell34a61c62008-09-21 19:29:15 -07001199#if FEATURE_dlist
Brian Paul21f69782004-11-27 05:05:32 +00001200 _mesa_init_dlist_table(ctx->Save);
Keith Whitwellae0eaf92003-11-24 15:23:18 +00001201 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001202#endif
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001203 /* Neutral tnl module stuff */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001204 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001205 ctx->TnlModule.Current = NULL;
1206 ctx->TnlModule.SwapCount = 0;
Brian Paulb6bcae52001-01-23 23:39:36 +00001207
Brian3e45db62007-03-27 09:51:52 -06001208 ctx->FragmentProgram._MaintainTexEnvProgram
1209 = (_mesa_getenv("MESA_TEX_PROG") != NULL);
Brian3e45db62007-03-27 09:51:52 -06001210
Briana90046f2006-12-15 10:07:26 -07001211 ctx->VertexProgram._MaintainTnlProgram
1212 = (_mesa_getenv("MESA_TNL_PROG") != NULL);
Brian3e45db62007-03-27 09:51:52 -06001213 if (ctx->VertexProgram._MaintainTnlProgram) {
Briana90046f2006-12-15 10:07:26 -07001214 /* this is required... */
1215 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
Brian3e45db62007-03-27 09:51:52 -06001216 }
Keith Whitwell47b29f52005-05-04 11:44:44 +00001217
Brian Paul6fd15dd2008-08-19 18:14:15 -06001218#ifdef FEATURE_extra_context_init
1219 _mesa_initialize_context_extra(ctx);
1220#endif
1221
Brian Paula96f8892005-09-13 01:19:29 +00001222 ctx->FirstTimeCurrent = GL_TRUE;
1223
Brian Paul4d053dd2000-01-14 04:45:47 +00001224 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001225}
1226
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001227
Brian Paulde4f4602003-07-03 02:15:06 +00001228/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001229 * Allocate and initialize a GLcontext structure.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001230 * Note that the driver needs to pass in its dd_function_table here since
1231 * we need to at least call driverFunctions->NewTextureObject to initialize
1232 * the rendering context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001233 *
1234 * \param visual a GLvisual pointer (we copy the struct contents)
1235 * \param share_list another context to share display lists with or NULL
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001236 * \param driverFunctions points to the dd_function_table into which the
1237 * driver has plugged in all its special functions.
1238 * \param driverCtx points to the device driver's private context state
Keith Whitwell6dc85572003-07-17 13:43:59 +00001239 *
1240 * \return pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001241 */
Brian Paul178a1c52000-04-22 01:05:00 +00001242GLcontext *
Briand881a9c2006-12-20 09:31:07 -07001243_mesa_create_context(const GLvisual *visual,
1244 GLcontext *share_list,
1245 const struct dd_function_table *driverFunctions,
1246 void *driverContext)
Brian Paul4d053dd2000-01-14 04:45:47 +00001247{
Brian Paul4753d602002-06-15 02:38:15 +00001248 GLcontext *ctx;
1249
1250 ASSERT(visual);
Brian7cafaff2007-11-01 14:51:37 -06001251 /*ASSERT(driverContext);*/
Brian Paul4753d602002-06-15 02:38:15 +00001252
Brian Paul3c634522002-10-24 23:57:19 +00001253 ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
Brian Paul4753d602002-06-15 02:38:15 +00001254 if (!ctx)
Brian Paul4d053dd2000-01-14 04:45:47 +00001255 return NULL;
Brian Paul4753d602002-06-15 02:38:15 +00001256
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001257 if (_mesa_initialize_context(ctx, visual, share_list,
1258 driverFunctions, driverContext)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001259 return ctx;
1260 }
1261 else {
Brian Paul3c634522002-10-24 23:57:19 +00001262 _mesa_free(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001263 return NULL;
1264 }
1265}
1266
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001267
Keith Whitwell6dc85572003-07-17 13:43:59 +00001268/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001269 * Free the data associated with the given context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001270 *
1271 * But doesn't free the GLcontext struct itself.
1272 *
1273 * \sa _mesa_initialize_context() and init_attrib_groups().
Brian Paul4d053dd2000-01-14 04:45:47 +00001274 */
Brian Paul178a1c52000-04-22 01:05:00 +00001275void
Brian Paulb1394fa2000-09-26 20:53:53 +00001276_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001277{
Briandc732172007-08-14 11:56:59 +01001278 if (!_mesa_get_current_context()){
1279 /* No current context, but we may need one in order to delete
1280 * texture objs, etc. So temporarily bind the context now.
1281 */
1282 _mesa_make_current(ctx, NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001283 }
Briandc732172007-08-14 11:56:59 +01001284
1285 /* unreference WinSysDraw/Read buffers */
Brian Pauld5229442009-02-09 08:30:55 -07001286 _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL);
1287 _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL);
1288 _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL);
1289 _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001290
Briandf43fb62008-05-06 23:08:51 -06001291 _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
1292 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
1293 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
1294
1295 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
1296 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
1297 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
1298
Alan Hourihane13e7e4b2008-09-19 14:55:49 +01001299#if FEATURE_attrib_stack
Brian145d7622007-08-16 10:05:00 +01001300 _mesa_free_attrib_data(ctx);
Alan Hourihane13e7e4b2008-09-19 14:55:49 +01001301#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001302 _mesa_free_lighting_data( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001303#if FEATURE_evaluators
Keith Whitwell6dc85572003-07-17 13:43:59 +00001304 _mesa_free_eval_data( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001305#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001306 _mesa_free_texture_data( ctx );
1307 _mesa_free_matrix_data( ctx );
1308 _mesa_free_viewport_data( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001309#if FEATURE_colortable
Brian Paul05944c02003-07-22 03:51:46 +00001310 _mesa_free_colortables_data( ctx );
Keith Whitwell34a61c62008-09-21 19:29:15 -07001311#endif
Brian Paul21841f02004-08-14 14:28:11 +00001312 _mesa_free_program_data(ctx);
Brian935f93f2007-03-24 16:20:02 -06001313 _mesa_free_shader_state(ctx);
Brian Paul4e3ae762008-06-13 13:56:53 -06001314#if FEATURE_ARB_occlusion_query
Brian Paul4fb99502005-09-02 13:42:49 +00001315 _mesa_free_query_data(ctx);
Brian Paul4e3ae762008-06-13 13:56:53 -06001316#endif
Brian Paul21841f02004-08-14 14:28:11 +00001317
1318#if FEATURE_ARB_vertex_buffer_object
1319 _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj);
Brian Paul8dfc5b92002-10-16 17:57:51 +00001320#endif
Brian Paulc04bb512006-07-11 21:56:43 +00001321 _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
Brian Paulfd284452001-07-19 15:54:34 +00001322
Brian Paul65a66f52004-11-27 22:47:59 +00001323 /* free dispatch tables */
1324 _mesa_free(ctx->Exec);
1325 _mesa_free(ctx->Save);
1326
Brian Paul30f51ae2001-12-18 04:06:44 +00001327 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001328 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001329 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001330 assert(ctx->Shared->RefCount >= 0);
1331 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1332 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001333 /* free shared state */
1334 free_shared_state( ctx, ctx->Shared );
1335 }
1336
Brian Paul702ca202003-07-18 15:22:16 +00001337 if (ctx->Extensions.String)
Brian Paulc7e164f2006-06-30 15:44:30 +00001338 _mesa_free((void *) ctx->Extensions.String);
Briandc732172007-08-14 11:56:59 +01001339
1340 /* unbind the context if it's currently bound */
1341 if (ctx == _mesa_get_current_context()) {
1342 _mesa_make_current(NULL, NULL, NULL);
1343 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001344}
1345
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001346
Keith Whitwell6dc85572003-07-17 13:43:59 +00001347/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001348 * Destroy a GLcontext structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001349 *
1350 * \param ctx GL context.
1351 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001352 * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
jtgafb833d1999-08-19 00:55:39 +00001353 */
Brian Paul178a1c52000-04-22 01:05:00 +00001354void
Brian Paulb1394fa2000-09-26 20:53:53 +00001355_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001356{
1357 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001358 _mesa_free_context_data(ctx);
Brian Paulc7e164f2006-06-30 15:44:30 +00001359 _mesa_free( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001360 }
1361}
1362
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001363
Keith Whitwell6dc85572003-07-17 13:43:59 +00001364#if _HAVE_FULL_GL
1365/**
jtgafb833d1999-08-19 00:55:39 +00001366 * Copy attribute groups from one context to another.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001367 *
1368 * \param src source context
1369 * \param dst destination context
1370 * \param mask bitwise OR of GL_*_BIT flags
1371 *
1372 * According to the bits specified in \p mask, copies the corresponding
Jose Fonseca375457b2004-09-09 22:23:24 +00001373 * attributes from \p src into \p dst. For many of the attributes a simple \c
Keith Whitwell6dc85572003-07-17 13:43:59 +00001374 * memcpy is not enough due to the existence of internal pointers in their data
1375 * structures.
jtgafb833d1999-08-19 00:55:39 +00001376 */
Brian Paul178a1c52000-04-22 01:05:00 +00001377void
Brian Paulb1394fa2000-09-26 20:53:53 +00001378_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001379{
1380 if (mask & GL_ACCUM_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001381 /* OK to memcpy */
1382 dst->Accum = src->Accum;
jtgafb833d1999-08-19 00:55:39 +00001383 }
1384 if (mask & GL_COLOR_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001385 /* OK to memcpy */
1386 dst->Color = src->Color;
jtgafb833d1999-08-19 00:55:39 +00001387 }
1388 if (mask & GL_CURRENT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001389 /* OK to memcpy */
1390 dst->Current = src->Current;
jtgafb833d1999-08-19 00:55:39 +00001391 }
1392 if (mask & GL_DEPTH_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001393 /* OK to memcpy */
1394 dst->Depth = src->Depth;
jtgafb833d1999-08-19 00:55:39 +00001395 }
1396 if (mask & GL_ENABLE_BIT) {
1397 /* no op */
1398 }
1399 if (mask & GL_EVAL_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001400 /* OK to memcpy */
1401 dst->Eval = src->Eval;
jtgafb833d1999-08-19 00:55:39 +00001402 }
1403 if (mask & GL_FOG_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001404 /* OK to memcpy */
1405 dst->Fog = src->Fog;
jtgafb833d1999-08-19 00:55:39 +00001406 }
1407 if (mask & GL_HINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001408 /* OK to memcpy */
1409 dst->Hint = src->Hint;
jtgafb833d1999-08-19 00:55:39 +00001410 }
1411 if (mask & GL_LIGHTING_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001412 GLuint i;
1413 /* begin with memcpy */
Brian Paul2aabdc72006-02-24 18:19:11 +00001414 dst->Light = src->Light;
Brian Paul85d81602002-06-17 23:36:31 +00001415 /* fixup linked lists to prevent pointer insanity */
1416 make_empty_list( &(dst->Light.EnabledList) );
1417 for (i = 0; i < MAX_LIGHTS; i++) {
1418 if (dst->Light.Light[i].Enabled) {
1419 insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
1420 }
1421 }
jtgafb833d1999-08-19 00:55:39 +00001422 }
1423 if (mask & GL_LINE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001424 /* OK to memcpy */
1425 dst->Line = src->Line;
jtgafb833d1999-08-19 00:55:39 +00001426 }
1427 if (mask & GL_LIST_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001428 /* OK to memcpy */
1429 dst->List = src->List;
jtgafb833d1999-08-19 00:55:39 +00001430 }
1431 if (mask & GL_PIXEL_MODE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001432 /* OK to memcpy */
1433 dst->Pixel = src->Pixel;
jtgafb833d1999-08-19 00:55:39 +00001434 }
1435 if (mask & GL_POINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001436 /* OK to memcpy */
1437 dst->Point = src->Point;
jtgafb833d1999-08-19 00:55:39 +00001438 }
1439 if (mask & GL_POLYGON_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001440 /* OK to memcpy */
1441 dst->Polygon = src->Polygon;
jtgafb833d1999-08-19 00:55:39 +00001442 }
1443 if (mask & GL_POLYGON_STIPPLE_BIT) {
1444 /* Use loop instead of MEMCPY due to problem with Portland Group's
1445 * C compiler. Reported by John Stone.
1446 */
Brian Paul85d81602002-06-17 23:36:31 +00001447 GLuint i;
1448 for (i = 0; i < 32; i++) {
jtgafb833d1999-08-19 00:55:39 +00001449 dst->PolygonStipple[i] = src->PolygonStipple[i];
1450 }
1451 }
1452 if (mask & GL_SCISSOR_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001453 /* OK to memcpy */
1454 dst->Scissor = src->Scissor;
jtgafb833d1999-08-19 00:55:39 +00001455 }
1456 if (mask & GL_STENCIL_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001457 /* OK to memcpy */
1458 dst->Stencil = src->Stencil;
jtgafb833d1999-08-19 00:55:39 +00001459 }
1460 if (mask & GL_TEXTURE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001461 /* Cannot memcpy because of pointers */
1462 _mesa_copy_texture_state(src, dst);
jtgafb833d1999-08-19 00:55:39 +00001463 }
1464 if (mask & GL_TRANSFORM_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001465 /* OK to memcpy */
1466 dst->Transform = src->Transform;
jtgafb833d1999-08-19 00:55:39 +00001467 }
1468 if (mask & GL_VIEWPORT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001469 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1470 dst->Viewport.X = src->Viewport.X;
1471 dst->Viewport.Y = src->Viewport.Y;
1472 dst->Viewport.Width = src->Viewport.Width;
1473 dst->Viewport.Height = src->Viewport.Height;
1474 dst->Viewport.Near = src->Viewport.Near;
1475 dst->Viewport.Far = src->Viewport.Far;
1476 _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001477 }
Brian Paul85d81602002-06-17 23:36:31 +00001478
Keith Whitwella96308c2000-10-30 13:31:59 +00001479 /* XXX FIXME: Call callbacks?
1480 */
1481 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001482}
Keith Whitwell23caf202000-11-16 21:05:34 +00001483#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001484
1485
Brian Paulb1d53d92003-06-11 18:48:19 +00001486/**
1487 * Check if the given context can render into the given framebuffer
1488 * by checking visual attributes.
Brian Paulca007cb2006-03-07 03:01:26 +00001489 *
Brianee170f22007-06-08 14:12:27 -06001490 * Most of these tests could go away because Mesa is now pretty flexible
1491 * in terms of mixing rendering contexts with framebuffers. As long
1492 * as RGB vs. CI mode agree, we're probably good.
Brian Paulca007cb2006-03-07 03:01:26 +00001493 *
Brian Paulb1d53d92003-06-11 18:48:19 +00001494 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1495 */
1496static GLboolean
1497check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
1498{
1499 const GLvisual *ctxvis = &ctx->Visual;
1500 const GLvisual *bufvis = &buffer->Visual;
1501
1502 if (ctxvis == bufvis)
1503 return GL_TRUE;
1504
1505 if (ctxvis->rgbMode != bufvis->rgbMode)
1506 return GL_FALSE;
Brian Pauld75963d2006-03-07 02:57:04 +00001507#if 0
1508 /* disabling this fixes the fgl_glxgears pbuffer demo */
Brian Paulb1d53d92003-06-11 18:48:19 +00001509 if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
1510 return GL_FALSE;
Brian Pauld75963d2006-03-07 02:57:04 +00001511#endif
Brian Paulb1d53d92003-06-11 18:48:19 +00001512 if (ctxvis->stereoMode && !bufvis->stereoMode)
1513 return GL_FALSE;
1514 if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
1515 return GL_FALSE;
1516 if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
1517 return GL_FALSE;
1518 if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
1519 return GL_FALSE;
1520 if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
1521 return GL_FALSE;
1522 if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
1523 return GL_FALSE;
1524 if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
1525 return GL_FALSE;
Brianee170f22007-06-08 14:12:27 -06001526#if 0
1527 /* disabled (see bug 11161) */
Brian Paulb1d53d92003-06-11 18:48:19 +00001528 if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
1529 return GL_FALSE;
Brianee170f22007-06-08 14:12:27 -06001530#endif
Brian Paulb1d53d92003-06-11 18:48:19 +00001531 if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
1532 return GL_FALSE;
1533
1534 return GL_TRUE;
1535}
1536
1537
Keith Whitwell6dc85572003-07-17 13:43:59 +00001538/**
Brian Paula702bbf2005-09-14 03:11:36 +00001539 * Do one-time initialization for the given framebuffer. Specifically,
1540 * ask the driver for the window's current size and update the framebuffer
1541 * object to match.
1542 * Really, the device driver should totally take care of this.
1543 */
1544static void
1545initialize_framebuffer_size(GLcontext *ctx, GLframebuffer *fb)
1546{
1547 GLuint width, height;
Brian Paul55e42e52006-10-17 17:43:47 +00001548 if (ctx->Driver.GetBufferSize) {
1549 ctx->Driver.GetBufferSize(fb, &width, &height);
1550 if (ctx->Driver.ResizeBuffers)
1551 ctx->Driver.ResizeBuffers(ctx, fb, width, height);
1552 fb->Initialized = GL_TRUE;
1553 }
Brian Paula702bbf2005-09-14 03:11:36 +00001554}
1555
1556
1557/**
1558 * Bind the given context to the given drawBuffer and readBuffer and
1559 * make it the current context for the calling thread.
1560 * We'll render into the drawBuffer and read pixels from the
1561 * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
Keith Whitwell6dc85572003-07-17 13:43:59 +00001562 *
Brian Paula702bbf2005-09-14 03:11:36 +00001563 * We check that the context's and framebuffer's visuals are compatible
1564 * and return immediately if they're not.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001565 *
Brian Paula702bbf2005-09-14 03:11:36 +00001566 * \param newCtx the new GL context. If NULL then there will be no current GL
1567 * context.
1568 * \param drawBuffer the drawing framebuffer
1569 * \param readBuffer the reading framebuffer
Brian Paul00037781999-12-17 14:52:35 +00001570 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001571void
Brian Paule4b23562005-05-04 20:11:35 +00001572_mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
1573 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001574{
Keith Whitwell5c728372005-05-12 10:22:29 +00001575 if (MESA_VERBOSE & VERBOSE_API)
Brian Paule4b23562005-05-04 20:11:35 +00001576 _mesa_debug(newCtx, "_mesa_make_current()\n");
Brian Paul00037781999-12-17 14:52:35 +00001577
Brian Paulbe3602d2001-02-28 00:27:48 +00001578 /* Check that the context's and framebuffer's visuals are compatible.
Brian Paulbe3602d2001-02-28 00:27:48 +00001579 */
Brian Paulf1038f82006-03-20 15:20:57 +00001580 if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
Brian Pauld75963d2006-03-07 02:57:04 +00001581 if (!check_compatible(newCtx, drawBuffer)) {
1582 _mesa_warning(newCtx,
1583 "MakeCurrent: incompatible visuals for context and drawbuffer");
Brian Paulb1d53d92003-06-11 18:48:19 +00001584 return;
Brian Pauld75963d2006-03-07 02:57:04 +00001585 }
Brian Paulb1d53d92003-06-11 18:48:19 +00001586 }
Brian Paulf1038f82006-03-20 15:20:57 +00001587 if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
Brian Pauld75963d2006-03-07 02:57:04 +00001588 if (!check_compatible(newCtx, readBuffer)) {
1589 _mesa_warning(newCtx,
1590 "MakeCurrent: incompatible visuals for context and readbuffer");
Brian Paulb1d53d92003-06-11 18:48:19 +00001591 return;
Brian Pauld75963d2006-03-07 02:57:04 +00001592 }
Brian Paulbe3602d2001-02-28 00:27:48 +00001593 }
1594
Brian Paulc6c0f942006-03-16 18:05:25 +00001595 /* We used to call _glapi_check_multithread() here. Now do it in drivers */
Brian Paulf9b97d92000-01-28 20:17:42 +00001596 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001597 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001598
Keith Whitwell23caf202000-11-16 21:05:34 +00001599 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001600 _glapi_set_dispatch(NULL); /* none current */
1601 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001602 else {
1603 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001604
Keith Whitwell23caf202000-11-16 21:05:34 +00001605 if (drawBuffer && readBuffer) {
1606 /* TODO: check if newCtx and buffer's visual match??? */
Brian Paule4b23562005-05-04 20:11:35 +00001607
Brian Paule4b23562005-05-04 20:11:35 +00001608 ASSERT(drawBuffer->Name == 0);
1609 ASSERT(readBuffer->Name == 0);
Briana510bc32007-03-06 10:07:59 -07001610 _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
1611 _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
Brian Paulf1038f82006-03-20 15:20:57 +00001612
1613 /*
1614 * Only set the context's Draw/ReadBuffer fields if they're NULL
1615 * or not bound to a user-created FBO.
1616 */
Brian Paule4b23562005-05-04 20:11:35 +00001617 if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
Keith Whitwell0397b2b2008-09-11 16:05:15 +01001618 /* KW: merge conflict here, revisit.
1619 */
1620 /* fix up the fb fields - these will end up wrong otherwise
1621 * if the DRIdrawable changes, and everything relies on them.
1622 * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
1623 */
José Fonseca53174af2008-05-31 18:14:09 +09001624 unsigned int i;
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001625 GLenum buffers[MAX_DRAW_BUFFERS];
Alan Hourihanee97bedb2008-05-01 14:54:56 +01001626
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001627 _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
Alan Hourihanee97bedb2008-05-01 14:54:56 +01001628
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001629 for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) {
1630 buffers[i] = newCtx->Color.DrawBuffer[i];
1631 }
Alan Hourihanee97bedb2008-05-01 14:54:56 +01001632
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001633 _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers, buffers, NULL);
Brian Paulf1038f82006-03-20 15:20:57 +00001634 }
1635 if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
Briana510bc32007-03-06 10:07:59 -07001636 _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
Brian Paule4b23562005-05-04 20:11:35 +00001637 }
Brian Paulbb5c84f2005-07-01 01:22:25 +00001638
Brian32d86eb2007-08-16 18:52:48 +01001639 /* XXX only set this flag if we're really changing the draw/read
1640 * framebuffer bindings.
1641 */
Keith Whitwell23caf202000-11-16 21:05:34 +00001642 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul10d7f542002-06-17 23:38:14 +00001643
Brian Paul4d4add02006-10-15 19:26:43 +00001644#if 1
1645 /* We want to get rid of these lines: */
1646
Keith Whitwell6dc85572003-07-17 13:43:59 +00001647#if _HAVE_FULL_GL
Brian Paul65a66f52004-11-27 22:47:59 +00001648 if (!drawBuffer->Initialized) {
Brian Paula702bbf2005-09-14 03:11:36 +00001649 initialize_framebuffer_size(newCtx, drawBuffer);
Brian Paul10d7f542002-06-17 23:38:14 +00001650 }
Brian Paul65a66f52004-11-27 22:47:59 +00001651 if (readBuffer != drawBuffer && !readBuffer->Initialized) {
Brian Paula702bbf2005-09-14 03:11:36 +00001652 initialize_framebuffer_size(newCtx, readBuffer);
Brian Paul10d7f542002-06-17 23:38:14 +00001653 }
Keith Whitwellf9bfdb12006-09-22 11:36:30 +00001654
1655 _mesa_resizebuffers(newCtx);
Keith Whitwell6dc85572003-07-17 13:43:59 +00001656#endif
Brian Paul4d4add02006-10-15 19:26:43 +00001657
1658#else
1659 /* We want the drawBuffer and readBuffer to be initialized by
1660 * the driver.
1661 * This generally means the Width and Height match the actual
1662 * window size and the renderbuffers (both hardware and software
1663 * based) are allocated to match. The later can generally be
1664 * done with a call to _mesa_resize_framebuffer().
1665 *
1666 * It's theoretically possible for a buffer to have zero width
1667 * or height, but for now, assert check that the driver did what's
1668 * expected of it.
1669 */
1670 ASSERT(drawBuffer->Width > 0);
1671 ASSERT(drawBuffer->Height > 0);
1672#endif
1673
Brian Paul65a66f52004-11-27 22:47:59 +00001674 if (newCtx->FirstTimeCurrent) {
1675 /* set initial viewport and scissor size now */
Brian Paula702bbf2005-09-14 03:11:36 +00001676 _mesa_set_viewport(newCtx, 0, 0,
1677 drawBuffer->Width, drawBuffer->Height);
Brian Pauldb79d2a2006-03-29 18:41:19 +00001678 _mesa_set_scissor(newCtx, 0, 0,
1679 drawBuffer->Width, drawBuffer->Height );
Brian Paul5e2e96b2006-05-15 15:26:04 +00001680 check_context_limits(newCtx);
Brian Paul65a66f52004-11-27 22:47:59 +00001681 }
Brian Paul00037781999-12-17 14:52:35 +00001682 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001683
Keith Whitwell23caf202000-11-16 21:05:34 +00001684 /* We can use this to help debug user's problems. Tell them to set
1685 * the MESA_INFO env variable before running their app. Then the
1686 * first time each context is made current we'll print some useful
1687 * information.
1688 */
1689 if (newCtx->FirstTimeCurrent) {
Brian Paul3c634522002-10-24 23:57:19 +00001690 if (_mesa_getenv("MESA_INFO")) {
Keith Whitwell6dc85572003-07-17 13:43:59 +00001691 _mesa_print_info();
Keith Whitwell23caf202000-11-16 21:05:34 +00001692 }
1693 newCtx->FirstTimeCurrent = GL_FALSE;
1694 }
Brian Paul00037781999-12-17 14:52:35 +00001695 }
1696}
1697
Brian Paul635ee2d2005-04-15 17:25:07 +00001698
1699/**
1700 * Make context 'ctx' share the display lists, textures and programs
1701 * that are associated with 'ctxToShare'.
1702 * Any display lists, textures or programs associated with 'ctx' will
1703 * be deleted if nobody else is sharing them.
1704 */
1705GLboolean
1706_mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
1707{
1708 if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
Brian4b654d42007-08-23 08:53:43 +01001709 struct gl_shared_state *oldSharedState = ctx->Shared;
1710
Brian Paul635ee2d2005-04-15 17:25:07 +00001711 ctx->Shared = ctxToShare->Shared;
1712 ctx->Shared->RefCount++;
Brian4b654d42007-08-23 08:53:43 +01001713
1714 update_default_objects(ctx);
1715
1716 oldSharedState->RefCount--;
1717 if (oldSharedState->RefCount == 0) {
1718 free_shared_state(ctx, oldSharedState);
1719 }
1720
Brian Paul635ee2d2005-04-15 17:25:07 +00001721 return GL_TRUE;
1722 }
1723 else {
1724 return GL_FALSE;
1725 }
1726}
1727
1728
1729
Keith Whitwell6dc85572003-07-17 13:43:59 +00001730/**
Briand881a9c2006-12-20 09:31:07 -07001731 * \return pointer to the current GL context for this thread.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001732 *
1733 * Calls _glapi_get_context(). This isn't the fastest way to get the current
Briand881a9c2006-12-20 09:31:07 -07001734 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
1735 * context.h.
Brian Paul00037781999-12-17 14:52:35 +00001736 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001737GLcontext *
1738_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001739{
Brian Paulf9b97d92000-01-28 20:17:42 +00001740 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001741}
1742
Briand881a9c2006-12-20 09:31:07 -07001743
Keith Whitwell6dc85572003-07-17 13:43:59 +00001744/**
1745 * Get context's current API dispatch table.
1746 *
1747 * It'll either be the immediate-mode execute dispatcher or the display list
1748 * compile dispatcher.
1749 *
1750 * \param ctx GL context.
1751 *
1752 * \return pointer to dispatch_table.
1753 *
1754 * Simply returns __GLcontextRec::CurrentDispatch.
Brian Paulfbd8f211999-11-11 01:22:25 +00001755 */
1756struct _glapi_table *
1757_mesa_get_dispatch(GLcontext *ctx)
1758{
1759 return ctx->CurrentDispatch;
1760}
1761
Keith Whitwell6dc85572003-07-17 13:43:59 +00001762/*@}*/
Brian Paulfbd8f211999-11-11 01:22:25 +00001763
1764
jtgafb833d1999-08-19 00:55:39 +00001765/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001766/** \name Miscellaneous functions */
jtgafb833d1999-08-19 00:55:39 +00001767/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001768/*@{*/
jtgafb833d1999-08-19 00:55:39 +00001769
Keith Whitwell6dc85572003-07-17 13:43:59 +00001770/**
1771 * Record an error.
1772 *
1773 * \param ctx GL context.
1774 * \param error error code.
1775 *
1776 * Records the given error code and call the driver's dd_function_table::Error
1777 * function if defined.
1778 *
1779 * \sa
Brian Paul4e9676f2002-06-29 19:48:15 +00001780 * This is called via _mesa_error().
jtgafb833d1999-08-19 00:55:39 +00001781 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001782void
Briand881a9c2006-12-20 09:31:07 -07001783_mesa_record_error(GLcontext *ctx, GLenum error)
jtgafb833d1999-08-19 00:55:39 +00001784{
Brian Paul18a285a2002-03-16 00:53:15 +00001785 if (!ctx)
1786 return;
1787
Brian Paul7eb06032000-07-14 04:13:40 +00001788 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00001789 ctx->ErrorValue = error;
1790 }
1791
1792 /* Call device driver's error handler, if any. This is used on the Mac. */
1793 if (ctx->Driver.Error) {
Briand881a9c2006-12-20 09:31:07 -07001794 ctx->Driver.Error(ctx);
jtgafb833d1999-08-19 00:55:39 +00001795 }
1796}
1797
Briand881a9c2006-12-20 09:31:07 -07001798
Keith Whitwell6dc85572003-07-17 13:43:59 +00001799/**
1800 * Execute glFinish().
1801 *
1802 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1803 * dd_function_table::Finish driver callback, if not NULL.
1804 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001805void GLAPIENTRY
Briand881a9c2006-12-20 09:31:07 -07001806_mesa_Finish(void)
jtgafb833d1999-08-19 00:55:39 +00001807{
Brian Paulfa9df402000-02-02 19:16:46 +00001808 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001809 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001810 if (ctx->Driver.Finish) {
Briand881a9c2006-12-20 09:31:07 -07001811 ctx->Driver.Finish(ctx);
jtgafb833d1999-08-19 00:55:39 +00001812 }
1813}
1814
Briand881a9c2006-12-20 09:31:07 -07001815
Keith Whitwell6dc85572003-07-17 13:43:59 +00001816/**
1817 * Execute glFlush().
1818 *
1819 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1820 * dd_function_table::Flush driver callback, if not NULL.
1821 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001822void GLAPIENTRY
Briand881a9c2006-12-20 09:31:07 -07001823_mesa_Flush(void)
jtgafb833d1999-08-19 00:55:39 +00001824{
Brian Paulfa9df402000-02-02 19:16:46 +00001825 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001826 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001827 if (ctx->Driver.Flush) {
Briand881a9c2006-12-20 09:31:07 -07001828 ctx->Driver.Flush(ctx);
jtgafb833d1999-08-19 00:55:39 +00001829 }
jtgafb833d1999-08-19 00:55:39 +00001830}
Brian Paul48c6a6e2000-09-08 21:28:04 +00001831
1832
Keith Whitwell6dc85572003-07-17 13:43:59 +00001833/*@}*/