blob: 96a8c30106a27e5206f8ede556857790b9a26b87 [file] [log] [blame]
Keith Whitwell6dc85572003-07-17 13:43:59 +00001/**
2 * \file context.c
3 * Mesa context/visual/framebuffer management functions.
4 * \author Brian Paul
5 */
6
jtgafb833d1999-08-19 00:55:39 +00007/*
8 * Mesa 3-D graphics library
Brian145d7622007-08-16 10:05:00 +01009 * Version: 7.1
jtgafb833d1999-08-19 00:55:39 +000010 *
Brian145d7622007-08-16 10:05:00 +010011 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +000012 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included
21 * in all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
27 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
Keith Whitwell6dc85572003-07-17 13:43:59 +000032/**
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 Paul3c634522002-10-24 23:57:19 +000080#include "imports.h"
Brian Paul40d1a402008-06-10 16:13:42 -060081#if FEATURE_accum
Keith Whitwell6dc85572003-07-17 13:43:59 +000082#include "accum.h"
Brian Paul40d1a402008-06-10 16:13:42 -060083#endif
Brian Paulb36e6f02008-06-09 14:49:04 -060084#include "api_exec.h"
Brian Paulc04bb512006-07-11 21:56:43 +000085#include "arrayobj.h"
Brian Paul40d1a402008-06-10 16:13:42 -060086#if FEATURE_attrib_stack
Keith Whitwell6dc85572003-07-17 13:43:59 +000087#include "attrib.h"
Brian Paul40d1a402008-06-10 16:13:42 -060088#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +000089#include "blend.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000090#include "buffers.h"
Brian Paul148a2842003-09-17 03:40:11 +000091#include "bufferobj.h"
Brian Paul40d1a402008-06-10 16:13:42 -060092#if FEATURE_colortable
Brian Paul4bdcfe52000-04-17 17:57:04 +000093#include "colortab.h"
Brian Paul40d1a402008-06-10 16:13:42 -060094#endif
jtgafb833d1999-08-19 00:55:39 +000095#include "context.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +000096#include "debug.h"
97#include "depth.h"
Brian Paul40d1a402008-06-10 16:13:42 -060098#if FEATURE_dlist
jtgafb833d1999-08-19 00:55:39 +000099#include "dlist.h"
Brian Paul40d1a402008-06-10 16:13:42 -0600100#endif
101#if FEATURE_evaluators
jtgafb833d1999-08-19 00:55:39 +0000102#include "eval.h"
Brian Paul40d1a402008-06-10 16:13:42 -0600103#endif
jtgafb833d1999-08-19 00:55:39 +0000104#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +0000105#include "extensions.h"
Brian Paule4b23562005-05-04 20:11:35 +0000106#include "fbobject.h"
Brian Paul40d1a402008-06-10 16:13:42 -0600107#if FEATURE_feedback
Keith Whitwell6dc85572003-07-17 13:43:59 +0000108#include "feedback.h"
Brian Paul40d1a402008-06-10 16:13:42 -0600109#endif
jtgafb833d1999-08-19 00:55:39 +0000110#include "fog.h"
Briane6a93812007-02-26 11:37:37 -0700111#include "framebuffer.h"
Brian Paulb7a43041999-11-30 20:34:51 +0000112#include "get.h"
Brian Paul40d1a402008-06-10 16:13:42 -0600113#if FEATURE_histogram
Keith Whitwell6dc85572003-07-17 13:43:59 +0000114#include "histogram.h"
Brian Paul40d1a402008-06-10 16:13:42 -0600115#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +0000116#include "hint.h"
jtgafb833d1999-08-19 00:55:39 +0000117#include "hash.h"
118#include "light.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000119#include "lines.h"
jtgafb833d1999-08-19 00:55:39 +0000120#include "macros.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000121#include "matrix.h"
Brian Paulbce428c2008-06-09 15:09:21 -0600122#include "multisample.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000123#include "pixel.h"
Brian Paul5f910072008-06-09 14:25:23 -0600124#include "pixelstore.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000125#include "points.h"
126#include "polygon.h"
Brian Paul2b4e2842008-06-13 13:56:53 -0600127#if FEATURE_ARB_occlusion_query
Brian74afcab2007-04-21 12:42:54 -0600128#include "queryobj.h"
Brian Paul2b4e2842008-06-13 13:56:53 -0600129#endif
Brian Paul40d1a402008-06-10 16:13:42 -0600130#if FEATURE_drawpix
Keith Whitwell6dc85572003-07-17 13:43:59 +0000131#include "rastpos.h"
Brian Paul40d1a402008-06-10 16:13:42 -0600132#endif
Brian Paul4be72962008-06-09 14:55:24 -0600133#include "scissor.h"
jtgafb833d1999-08-19 00:55:39 +0000134#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +0000135#include "state.h"
Keith Whitwell6dc85572003-07-17 13:43:59 +0000136#include "stencil.h"
Brian Paul8f04c122004-04-27 13:39:20 +0000137#include "texcompress.h"
jtgafb833d1999-08-19 00:55:39 +0000138#include "teximage.h"
139#include "texobj.h"
Brian Paul85d81602002-06-17 23:36:31 +0000140#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000141#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +0000142#include "varray.h"
Brian Paul363344f2005-09-13 14:48:28 +0000143#include "version.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +0000144#include "vtxfmt.h"
Brianc223c6b2007-07-04 13:15:20 -0600145#include "glapi/glthread.h"
146#include "glapi/glapioffsets.h"
Brian Paul8b11fa42008-06-13 16:45:15 -0600147#include "glapi/glapitable.h"
Brianc223c6b2007-07-04 13:15:20 -0600148#include "shader/program.h"
Brianc223c6b2007-07-04 13:15:20 -0600149#include "shader/shader_api.h"
Brian Paul907c0972008-06-20 08:07:38 -0600150#if FEATURE_ATI_fragment_shader
Brianc223c6b2007-07-04 13:15:20 -0600151#include "shader/atifragshader.h"
Brian Paul907c0972008-06-20 08:07:38 -0600152#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +0000153#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000154#include "math/m_translate.h"
Keith Whitwell23caf202000-11-16 21:05:34 +0000155#include "math/m_matrix.h"
156#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +0000157#include "math/mathmod.h"
Brian Paulddc82ee2005-02-05 19:56:45 +0000158#endif
jtgafb833d1999-08-19 00:55:39 +0000159
davem69775355a2001-06-05 23:54:00 +0000160#ifdef USE_SPARC_ASM
Ian Romanicke16f6e32004-06-26 00:02:51 +0000161#include "sparc/sparc.h"
davem69775355a2001-06-05 23:54:00 +0000162#endif
jtgafb833d1999-08-19 00:55:39 +0000163
Keith Whitwell23caf202000-11-16 21:05:34 +0000164#ifndef MESA_VERBOSE
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000165int MESA_VERBOSE = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000166#endif
167
168#ifndef MESA_DEBUG_FLAGS
Keith Whitwell306d3fc2002-04-09 16:56:50 +0000169int MESA_DEBUG_FLAGS = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000170#endif
Brian Paulb1394fa2000-09-26 20:53:53 +0000171
Brian Paul86b84272001-12-14 02:50:01 +0000172
Brian Paul27558a12003-03-01 01:50:20 +0000173/* ubyte -> float conversion */
174GLfloat _mesa_ubyte_to_float_color_tab[256];
175
Brian Paul9a33a112002-06-13 04:28:29 +0000176
Brian Paul86b84272001-12-14 02:50:01 +0000177
Keith Whitwell6dc85572003-07-17 13:43:59 +0000178/**
179 * Swap buffers notification callback.
180 *
181 * \param gc GL context.
182 *
183 * Called by window system just before swapping buffers.
Brian Paul9a33a112002-06-13 04:28:29 +0000184 * We have to finish any pending rendering.
185 */
186void
Brian96b06ac2007-10-19 10:12:00 -0600187_mesa_notifySwapBuffers(__GLcontext *ctx)
Brian Paul9a33a112002-06-13 04:28:29 +0000188{
Brian96b06ac2007-10-19 10:12:00 -0600189 if (ctx->Driver.Flush) {
190 ctx->Driver.Flush(ctx);
191 }
Brian Paul9a33a112002-06-13 04:28:29 +0000192}
193
Brian Paulb1394fa2000-09-26 20:53:53 +0000194
jtgafb833d1999-08-19 00:55:39 +0000195/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000196/** \name GL Visual allocation/destruction */
Brian Paul4d053dd2000-01-14 04:45:47 +0000197/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000198/*@{*/
Brian Paul4d053dd2000-01-14 04:45:47 +0000199
Keith Whitwell6dc85572003-07-17 13:43:59 +0000200/**
Brian Paul894844a2004-03-21 17:05:03 +0000201 * Allocates a GLvisual structure and initializes it via
202 * _mesa_initialize_visual().
Keith Whitwell6dc85572003-07-17 13:43:59 +0000203 *
204 * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
205 * \param dbFlag double buffering
206 * \param stereoFlag stereo buffer
207 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
208 * is acceptable but the actual depth type will be GLushort or GLuint as
209 * needed.
210 * \param stencilBits requested minimum bits per stencil buffer value
211 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
212 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
213 * \param redBits number of bits per color component in frame buffer for RGB(A)
214 * mode. We always use 8 in core Mesa though.
215 * \param greenBits same as above.
216 * \param blueBits same as above.
217 * \param alphaBits same as above.
218 * \param numSamples not really used.
219 *
220 * \return pointer to new GLvisual or NULL if requested parameters can't be
221 * met.
222 *
Brian Paul894844a2004-03-21 17:05:03 +0000223 * \note Need to add params for level and numAuxBuffers (at least)
Brian Paul4d053dd2000-01-14 04:45:47 +0000224 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000225GLvisual *
226_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000227 GLboolean dbFlag,
228 GLboolean stereoFlag,
229 GLint redBits,
230 GLint greenBits,
231 GLint blueBits,
232 GLint alphaBits,
233 GLint indexBits,
234 GLint depthBits,
235 GLint stencilBits,
236 GLint accumRedBits,
237 GLint accumGreenBits,
238 GLint accumBlueBits,
239 GLint accumAlphaBits,
240 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000241{
Brian Paulc7e164f2006-06-30 15:44:30 +0000242 GLvisual *vis = (GLvisual *) _mesa_calloc(sizeof(GLvisual));
Brian Paul178a1c52000-04-22 01:05:00 +0000243 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000244 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000245 redBits, greenBits, blueBits, alphaBits,
246 indexBits, depthBits, stencilBits,
247 accumRedBits, accumGreenBits,
248 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000249 numSamples)) {
Brian Paulc7e164f2006-06-30 15:44:30 +0000250 _mesa_free(vis);
Brian Paul178a1c52000-04-22 01:05:00 +0000251 return NULL;
252 }
253 }
254 return vis;
255}
256
Keith Whitwell6dc85572003-07-17 13:43:59 +0000257/**
Brian Paul894844a2004-03-21 17:05:03 +0000258 * Makes some sanity checks and fills in the fields of the
Brian Paule4b23562005-05-04 20:11:35 +0000259 * GLvisual object with the given parameters. If the caller needs
260 * to set additional fields, he should just probably init the whole GLvisual
261 * object himself.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000262 * \return GL_TRUE on success, or GL_FALSE on failure.
263 *
264 * \sa _mesa_create_visual() above for the parameter description.
Brian Paul178a1c52000-04-22 01:05:00 +0000265 */
266GLboolean
267_mesa_initialize_visual( GLvisual *vis,
268 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000269 GLboolean dbFlag,
270 GLboolean stereoFlag,
271 GLint redBits,
272 GLint greenBits,
273 GLint blueBits,
274 GLint alphaBits,
275 GLint indexBits,
276 GLint depthBits,
277 GLint stencilBits,
278 GLint accumRedBits,
279 GLint accumGreenBits,
280 GLint accumBlueBits,
281 GLint accumAlphaBits,
282 GLint numSamples )
283{
284 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000285
Brian Pauled30dfa2000-03-03 17:47:39 +0000286 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000287 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000288 }
Brian Paule4b23562005-05-04 20:11:35 +0000289 if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
Brian Paul178a1c52000-04-22 01:05:00 +0000290 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000291 }
Brian Paul978ef2b2005-09-21 03:35:08 +0000292 assert(accumRedBits >= 0);
293 assert(accumGreenBits >= 0);
294 assert(accumBlueBits >= 0);
295 assert(accumAlphaBits >= 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000296
Brian Paulb6bcae52001-01-23 23:39:36 +0000297 vis->rgbMode = rgbFlag;
298 vis->doubleBufferMode = dbFlag;
299 vis->stereoMode = stereoFlag;
Brian Paul153f1542002-10-29 15:04:35 +0000300
Brian Paulb6bcae52001-01-23 23:39:36 +0000301 vis->redBits = redBits;
302 vis->greenBits = greenBits;
303 vis->blueBits = blueBits;
304 vis->alphaBits = alphaBits;
Brian Paule4b23562005-05-04 20:11:35 +0000305 vis->rgbBits = redBits + greenBits + blueBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000306
Brian Paulb6bcae52001-01-23 23:39:36 +0000307 vis->indexBits = indexBits;
308 vis->depthBits = depthBits;
Brian Paule4b23562005-05-04 20:11:35 +0000309 vis->stencilBits = stencilBits;
310
311 vis->accumRedBits = accumRedBits;
312 vis->accumGreenBits = accumGreenBits;
313 vis->accumBlueBits = accumBlueBits;
314 vis->accumAlphaBits = accumAlphaBits;
Brian Pauled30dfa2000-03-03 17:47:39 +0000315
Brian Paul153f1542002-10-29 15:04:35 +0000316 vis->haveAccumBuffer = accumRedBits > 0;
317 vis->haveDepthBuffer = depthBits > 0;
318 vis->haveStencilBuffer = stencilBits > 0;
319
320 vis->numAuxBuffers = 0;
321 vis->level = 0;
322 vis->pixmapMode = 0;
Brian Paule4b23562005-05-04 20:11:35 +0000323 vis->sampleBuffers = numSamples > 0 ? 1 : 0;
Brian Paul894844a2004-03-21 17:05:03 +0000324 vis->samples = numSamples;
Brian Paul153f1542002-10-29 15:04:35 +0000325
Brian Paul178a1c52000-04-22 01:05:00 +0000326 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000327}
328
Brian Paul894844a2004-03-21 17:05:03 +0000329
Keith Whitwell6dc85572003-07-17 13:43:59 +0000330/**
Brian Paul894844a2004-03-21 17:05:03 +0000331 * Destroy a visual and free its memory.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000332 *
333 * \param vis visual.
334 *
335 * Frees the visual structure.
336 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000337void
338_mesa_destroy_visual( GLvisual *vis )
339{
Brian Paulc7e164f2006-06-30 15:44:30 +0000340 _mesa_free(vis);
Brian Paulb371e0d2000-03-31 01:05:51 +0000341}
342
Keith Whitwell6dc85572003-07-17 13:43:59 +0000343/*@}*/
344
Brian Paulb371e0d2000-03-31 01:05:51 +0000345
Brian Paul4d053dd2000-01-14 04:45:47 +0000346/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000347/** \name Context allocation, initialization, destroying
348 *
349 * The purpose of the most initialization functions here is to provide the
350 * default state values according to the OpenGL specification.
351 */
jtgafb833d1999-08-19 00:55:39 +0000352/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +0000353/*@{*/
jtgafb833d1999-08-19 00:55:39 +0000354
Keith Whitwell6dc85572003-07-17 13:43:59 +0000355/**
356 * One-time initialization mutex lock.
357 *
358 * \sa Used by one_time_init().
359 */
Brian Paul9560f052000-01-31 23:11:39 +0000360_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
361
Keith Whitwell6dc85572003-07-17 13:43:59 +0000362/**
363 * Calls all the various one-time-init functions in Mesa.
364 *
365 * While holding a global mutex lock, calls several initialization functions,
366 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
367 * defined.
368 *
Brian Paula764b7e2006-02-26 17:16:37 +0000369 * \sa _math_init().
jtgafb833d1999-08-19 00:55:39 +0000370 */
Brian Paul178a1c52000-04-22 01:05:00 +0000371static void
Brian Paul4753d602002-06-15 02:38:15 +0000372one_time_init( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000373{
374 static GLboolean alreadyCalled = GL_FALSE;
Brian Paula6c423d2004-08-25 15:59:48 +0000375 (void) ctx;
Brian Paul9560f052000-01-31 23:11:39 +0000376 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000377 if (!alreadyCalled) {
Brian Paul27558a12003-03-01 01:50:20 +0000378 GLuint i;
379
Brian Paul4d053dd2000-01-14 04:45:47 +0000380 /* do some implementation tests */
381 assert( sizeof(GLbyte) == 1 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000382 assert( sizeof(GLubyte) == 1 );
Brian Paul894844a2004-03-21 17:05:03 +0000383 assert( sizeof(GLshort) == 2 );
384 assert( sizeof(GLushort) == 2 );
385 assert( sizeof(GLint) == 4 );
386 assert( sizeof(GLuint) == 4 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000387
Brian33c37392007-04-04 22:18:53 -0600388 _mesa_init_sqrt_table();
389
Keith Whitwell6dc85572003-07-17 13:43:59 +0000390#if _HAVE_FULL_GL
Keith Whitwell23caf202000-11-16 21:05:34 +0000391 _math_init();
Brian Paul27558a12003-03-01 01:50:20 +0000392
393 for (i = 0; i < 256; i++) {
394 _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
395 }
Keith Whitwell6dc85572003-07-17 13:43:59 +0000396#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000397
davem69775355a2001-06-05 23:54:00 +0000398#ifdef USE_SPARC_ASM
399 _mesa_init_sparc_glapi_relocs();
400#endif
Brian Paul3c634522002-10-24 23:57:19 +0000401 if (_mesa_getenv("MESA_DEBUG")) {
Brian Paul68ee4bc2000-01-28 19:02:22 +0000402 _glapi_noop_enable_warnings(GL_TRUE);
Brian Paul4e9676f2002-06-29 19:48:15 +0000403 _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
Brian Paul68ee4bc2000-01-28 19:02:22 +0000404 }
405 else {
406 _glapi_noop_enable_warnings(GL_FALSE);
407 }
408
jtgafb833d1999-08-19 00:55:39 +0000409#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
Brian Paul363344f2005-09-13 14:48:28 +0000410 _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
411 MESA_VERSION_STRING, __DATE__, __TIME__);
jtgafb833d1999-08-19 00:55:39 +0000412#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000413
414 alreadyCalled = GL_TRUE;
415 }
Brian Paul9560f052000-01-31 23:11:39 +0000416 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000417}
418
Brian Paul894844a2004-03-21 17:05:03 +0000419
Keith Whitwell6dc85572003-07-17 13:43:59 +0000420/**
jtgafb833d1999-08-19 00:55:39 +0000421 * Allocate and initialize a shared context state structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000422 * Initializes the display list, texture objects and vertex programs hash
423 * tables, allocates the texture objects. If it runs out of memory, frees
424 * everything already allocated before returning NULL.
Brian Paul894844a2004-03-21 17:05:03 +0000425 *
426 * \return pointer to a gl_shared_state structure on success, or NULL on
427 * failure.
jtgafb833d1999-08-19 00:55:39 +0000428 */
Brian Paula3f13702003-04-01 16:41:50 +0000429static GLboolean
430alloc_shared_state( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000431{
Brian Paula3f13702003-04-01 16:41:50 +0000432 struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000433 if (!ss)
Brian Paula3f13702003-04-01 16:41:50 +0000434 return GL_FALSE;
435
436 ctx->Shared = ss;
jtgafb833d1999-08-19 00:55:39 +0000437
Brian Paule4b684c2000-09-12 21:07:40 +0000438 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000439
Brian Paule4b684c2000-09-12 21:07:40 +0000440 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000441 ss->TexObjects = _mesa_NewHashTable();
Brian Paul610d5992003-01-14 04:55:45 +0000442 ss->Programs = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000443
Brian Paul451f3102003-04-17 01:48:19 +0000444#if FEATURE_ARB_vertex_program
Briandf43fb62008-05-06 23:08:51 -0600445 ss->DefaultVertexProgram = (struct gl_vertex_program *)
446 ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000447 if (!ss->DefaultVertexProgram)
448 goto cleanup;
449#endif
450#if FEATURE_ARB_fragment_program
Briandf43fb62008-05-06 23:08:51 -0600451 ss->DefaultFragmentProgram = (struct gl_fragment_program *)
452 ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
Brian Paul451f3102003-04-17 01:48:19 +0000453 if (!ss->DefaultFragmentProgram)
454 goto cleanup;
455#endif
Dave Airlie7f752fe2004-12-19 03:06:59 +0000456#if FEATURE_ATI_fragment_shader
Brian Paul63d68302005-11-19 16:43:04 +0000457 ss->ATIShaders = _mesa_NewHashTable();
458 ss->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
Dave Airlie7f752fe2004-12-19 03:06:59 +0000459 if (!ss->DefaultFragmentShader)
460 goto cleanup;
461#endif
Brian Paul451f3102003-04-17 01:48:19 +0000462
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000463#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
Brian Paulddc82ee2005-02-05 19:56:45 +0000464 ss->BufferObjects = _mesa_NewHashTable();
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000465#endif
466
Ian Romanickee34e6e2006-06-12 16:26:29 +0000467 ss->ArrayObjects = _mesa_NewHashTable();
Brian Paulddc82ee2005-02-05 19:56:45 +0000468
Michal Krol365582d2006-08-01 20:07:31 +0000469#if FEATURE_ARB_shader_objects
Briana90046f2006-12-15 10:07:26 -0700470 ss->ShaderObjects = _mesa_NewHashTable();
Michal Krol365582d2006-08-01 20:07:31 +0000471#endif
Ian Romanick0207b472003-09-09 00:10:12 +0000472
Brian Paula3f13702003-04-01 16:41:50 +0000473 ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
474 if (!ss->Default1D)
475 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000476
Brian Paula3f13702003-04-01 16:41:50 +0000477 ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
478 if (!ss->Default2D)
479 goto cleanup;
jtgafb833d1999-08-19 00:55:39 +0000480
Brian Paula3f13702003-04-01 16:41:50 +0000481 ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
482 if (!ss->Default3D)
483 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000484
Brian Paula3f13702003-04-01 16:41:50 +0000485 ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
486 if (!ss->DefaultCubeMap)
487 goto cleanup;
Brian Paula8523782000-11-19 23:10:25 +0000488
Brian Paula3f13702003-04-01 16:41:50 +0000489 ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
490 if (!ss->DefaultRect)
491 goto cleanup;
Brian Paul413d6a22000-05-26 14:44:59 +0000492
Ian Romanickbb372f12007-05-16 15:34:22 -0700493 ss->Default1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT);
494 if (!ss->Default1DArray)
495 goto cleanup;
496
497 ss->Default2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT);
498 if (!ss->Default2DArray)
499 goto cleanup;
500
Brian9e01b912007-08-13 11:29:46 +0100501 /* sanity check */
502 assert(ss->Default1D->RefCount == 1);
Brian Paula3f13702003-04-01 16:41:50 +0000503
Keith Whitwell5ac93f82006-11-01 14:21:57 +0000504 _glthread_INIT_MUTEX(ss->TexMutex);
505 ss->TextureStateStamp = 0;
506
Brian Paulddc82ee2005-02-05 19:56:45 +0000507#if FEATURE_EXT_framebuffer_object
508 ss->FrameBuffers = _mesa_NewHashTable();
509 if (!ss->FrameBuffers)
510 goto cleanup;
511 ss->RenderBuffers = _mesa_NewHashTable();
512 if (!ss->RenderBuffers)
513 goto cleanup;
514#endif
515
Brian Paula3f13702003-04-01 16:41:50 +0000516 return GL_TRUE;
517
Brian9e01b912007-08-13 11:29:46 +0100518cleanup:
Brian Paula3f13702003-04-01 16:41:50 +0000519 /* Ran out of memory at some point. Free everything and return NULL */
520 if (ss->DisplayList)
521 _mesa_DeleteHashTable(ss->DisplayList);
522 if (ss->TexObjects)
523 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula3f13702003-04-01 16:41:50 +0000524 if (ss->Programs)
525 _mesa_DeleteHashTable(ss->Programs);
Brian Paul451f3102003-04-17 01:48:19 +0000526#if FEATURE_ARB_vertex_program
Briandf43fb62008-05-06 23:08:51 -0600527 _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
Brian Paul451f3102003-04-17 01:48:19 +0000528#endif
529#if FEATURE_ARB_fragment_program
Briandf43fb62008-05-06 23:08:51 -0600530 _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
Brian Paul451f3102003-04-17 01:48:19 +0000531#endif
Dave Airlie7f752fe2004-12-19 03:06:59 +0000532#if FEATURE_ATI_fragment_shader
533 if (ss->DefaultFragmentShader)
Brian Paul63d68302005-11-19 16:43:04 +0000534 _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
Dave Airlie7f752fe2004-12-19 03:06:59 +0000535#endif
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000536#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
Ian Romanick0207b472003-09-09 00:10:12 +0000537 if (ss->BufferObjects)
538 _mesa_DeleteHashTable(ss->BufferObjects);
Brian Paulddc82ee2005-02-05 19:56:45 +0000539#endif
540
Tilman Sauerbeckc0eb7772006-07-11 19:36:27 +0000541 if (ss->ArrayObjects)
542 _mesa_DeleteHashTable (ss->ArrayObjects);
543
Michal Krol365582d2006-08-01 20:07:31 +0000544#if FEATURE_ARB_shader_objects
Brian0bf5dbe2006-12-19 18:02:41 -0700545 if (ss->ShaderObjects)
Briana90046f2006-12-15 10:07:26 -0700546 _mesa_DeleteHashTable (ss->ShaderObjects);
Michal Krol365582d2006-08-01 20:07:31 +0000547#endif
Ian Romanick0207b472003-09-09 00:10:12 +0000548
Brian Paulddc82ee2005-02-05 19:56:45 +0000549#if FEATURE_EXT_framebuffer_object
550 if (ss->FrameBuffers)
551 _mesa_DeleteHashTable(ss->FrameBuffers);
552 if (ss->RenderBuffers)
553 _mesa_DeleteHashTable(ss->RenderBuffers);
554#endif
555
Brian Paula3f13702003-04-01 16:41:50 +0000556 if (ss->Default1D)
557 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
558 if (ss->Default2D)
559 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
560 if (ss->Default3D)
561 (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
562 if (ss->DefaultCubeMap)
563 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
564 if (ss->DefaultRect)
565 (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
Brian6f472502007-08-13 11:09:48 +0100566 if (ss->Default1DArray)
567 (*ctx->Driver.DeleteTexture)(ctx, ss->Default1DArray);
568 if (ss->Default2DArray)
569 (*ctx->Driver.DeleteTexture)(ctx, ss->Default2DArray);
Briana5c84de2008-01-01 10:20:21 -0700570
571 _mesa_free(ss);
572
Brian Paula3f13702003-04-01 16:41:50 +0000573 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000574}
575
Brian Paulc7e164f2006-06-30 15:44:30 +0000576
Keith Whitwell6dc85572003-07-17 13:43:59 +0000577/**
Brian Paulc7e164f2006-06-30 15:44:30 +0000578 * Callback for deleting a display list. Called by _mesa_HashDeleteAll().
579 */
580static void
581delete_displaylist_cb(GLuint id, void *data, void *userData)
582{
Brian Paul40d1a402008-06-10 16:13:42 -0600583#if FEATURE_dlist
Brian Paulc7e164f2006-06-30 15:44:30 +0000584 struct mesa_display_list *list = (struct mesa_display_list *) data;
585 GLcontext *ctx = (GLcontext *) userData;
586 _mesa_delete_list(ctx, list);
Brian Paul40d1a402008-06-10 16:13:42 -0600587#endif
Brian Paulc7e164f2006-06-30 15:44:30 +0000588}
589
590/**
591 * Callback for deleting a texture object. Called by _mesa_HashDeleteAll().
592 */
593static void
594delete_texture_cb(GLuint id, void *data, void *userData)
595{
596 struct gl_texture_object *texObj = (struct gl_texture_object *) data;
597 GLcontext *ctx = (GLcontext *) userData;
598 ctx->Driver.DeleteTexture(ctx, texObj);
599}
600
601/**
602 * Callback for deleting a program object. Called by _mesa_HashDeleteAll().
603 */
604static void
605delete_program_cb(GLuint id, void *data, void *userData)
606{
Brian Paul122629f2006-07-20 16:49:57 +0000607 struct gl_program *prog = (struct gl_program *) data;
Brian Paulc7e164f2006-06-30 15:44:30 +0000608 GLcontext *ctx = (GLcontext *) userData;
Brian Paulfbfe2a52008-05-19 08:43:36 -0600609 ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */
610 prog->RefCount = 0; /* now going away */
Brian Paulc7e164f2006-06-30 15:44:30 +0000611 ctx->Driver.DeleteProgram(ctx, prog);
612}
613
Brian Paule961a5d2008-06-12 16:55:28 -0600614#if FEATURE_ATI_fragment_shader
Brian Paulc7e164f2006-06-30 15:44:30 +0000615/**
616 * Callback for deleting an ATI fragment shader object.
617 * Called by _mesa_HashDeleteAll().
618 */
619static void
620delete_fragshader_cb(GLuint id, void *data, void *userData)
621{
622 struct ati_fragment_shader *shader = (struct ati_fragment_shader *) data;
623 GLcontext *ctx = (GLcontext *) userData;
624 _mesa_delete_ati_fragment_shader(ctx, shader);
625}
Brian Paule961a5d2008-06-12 16:55:28 -0600626#endif
Brian Paulc7e164f2006-06-30 15:44:30 +0000627
628/**
629 * Callback for deleting a buffer object. Called by _mesa_HashDeleteAll().
630 */
631static void
632delete_bufferobj_cb(GLuint id, void *data, void *userData)
633{
634 struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data;
635 GLcontext *ctx = (GLcontext *) userData;
636 ctx->Driver.DeleteBuffer(ctx, bufObj);
637}
638
Brian Paulc04bb512006-07-11 21:56:43 +0000639/**
640 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
641 */
642static void
643delete_arrayobj_cb(GLuint id, void *data, void *userData)
644{
645 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
646 GLcontext *ctx = (GLcontext *) userData;
647 _mesa_delete_array_object(ctx, arrayObj);
648}
649
Brian Paul4d4373b2006-11-18 17:44:28 +0000650/**
Xiang, Haihao63d8a842008-03-31 17:02:47 +0800651 * Callback for freeing shader program data. Call it before delete_shader_cb
652 * to avoid memory access error.
653 */
654static void
655free_shader_program_data_cb(GLuint id, void *data, void *userData)
656{
657 GLcontext *ctx = (GLcontext *) userData;
658 struct gl_shader_program *shProg = (struct gl_shader_program *) data;
659
660 if (shProg->Type == GL_SHADER_PROGRAM_MESA) {
661 _mesa_free_shader_program_data(ctx, shProg);
662 }
663}
664
665/**
Brian9e4bae92006-12-20 09:27:42 -0700666 * Callback for deleting shader and shader programs objects.
667 * Called by _mesa_HashDeleteAll().
Brian Paul4d4373b2006-11-18 17:44:28 +0000668 */
669static void
Brian9e4bae92006-12-20 09:27:42 -0700670delete_shader_cb(GLuint id, void *data, void *userData)
Brian Paul4d4373b2006-11-18 17:44:28 +0000671{
Brian9e4bae92006-12-20 09:27:42 -0700672 GLcontext *ctx = (GLcontext *) userData;
673 struct gl_shader *sh = (struct gl_shader *) data;
Xiang, Haihaoaef47c42008-03-31 16:27:47 +0800674 if (sh->Type == GL_FRAGMENT_SHADER || sh->Type == GL_VERTEX_SHADER) {
675 _mesa_free_shader(ctx, sh);
676 }
677 else {
678 struct gl_shader_program *shProg = (struct gl_shader_program *) data;
679 ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA);
680 _mesa_free_shader_program(ctx, shProg);
681 }
Brian Paul4d4373b2006-11-18 17:44:28 +0000682}
683
Brian393a6252007-08-13 17:37:30 +0100684/**
685 * Callback for deleting a framebuffer object. Called by _mesa_HashDeleteAll()
686 */
687static void
688delete_framebuffer_cb(GLuint id, void *data, void *userData)
689{
690 struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
Briandc732172007-08-14 11:56:59 +0100691 /* The fact that the framebuffer is in the hashtable means its refcount
692 * is one, but we're removing from the hashtable now. So clear refcount.
693 */
694 /*assert(fb->RefCount == 1);*/
695 fb->RefCount = 0;
Brian2f7c8042008-01-30 08:08:23 -0700696
697 /* NOTE: Delete should always be defined but there are two reports
698 * of it being NULL (bugs 13507, 14293). Work-around for now.
699 */
700 if (fb->Delete)
701 fb->Delete(fb);
Brian393a6252007-08-13 17:37:30 +0100702}
703
704/**
705 * Callback for deleting a renderbuffer object. Called by _mesa_HashDeleteAll()
706 */
707static void
708delete_renderbuffer_cb(GLuint id, void *data, void *userData)
709{
710 struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data;
Briandc732172007-08-14 11:56:59 +0100711 rb->RefCount = 0; /* see comment for FBOs above */
Brian Paul61b3ce82008-08-03 11:13:12 -0600712 if (rb->Delete)
713 rb->Delete(rb);
Brian393a6252007-08-13 17:37:30 +0100714}
715
716
Brian Paulc7e164f2006-06-30 15:44:30 +0000717/**
718 * Deallocate a shared state object and all children structures.
Keith Whitwell6dc85572003-07-17 13:43:59 +0000719 *
720 * \param ctx GL context.
721 * \param ss shared state pointer.
722 *
723 * Frees the display lists, the texture objects (calling the driver texture
724 * deletion callback to free its private data) and the vertex programs, as well
725 * as their hash tables.
726 *
727 * \sa alloc_shared_state().
jtgafb833d1999-08-19 00:55:39 +0000728 */
Brian Paul178a1c52000-04-22 01:05:00 +0000729static void
730free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000731{
Brian Paulc7e164f2006-06-30 15:44:30 +0000732 /*
733 * Free display lists
734 */
735 _mesa_HashDeleteAll(ss->DisplayList, delete_displaylist_cb, ctx);
Brian Paulbb797902000-01-24 16:19:54 +0000736 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000737
Brian Paulfbfe2a52008-05-19 08:43:36 -0600738#if FEATURE_ARB_shader_objects
739 _mesa_HashWalk(ss->ShaderObjects, free_shader_program_data_cb, ctx);
740 _mesa_HashDeleteAll(ss->ShaderObjects, delete_shader_cb, ctx);
741 _mesa_DeleteHashTable(ss->ShaderObjects);
742#endif
743
Brian Paulc7e164f2006-06-30 15:44:30 +0000744 _mesa_HashDeleteAll(ss->Programs, delete_program_cb, ctx);
Brian Paul610d5992003-01-14 04:55:45 +0000745 _mesa_DeleteHashTable(ss->Programs);
Brian Paul95c9fc82008-06-20 10:47:38 -0600746
Brian Paul21841f02004-08-14 14:28:11 +0000747#if FEATURE_ARB_vertex_program
Briandf43fb62008-05-06 23:08:51 -0600748 _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
Brian Paul21841f02004-08-14 14:28:11 +0000749#endif
750#if FEATURE_ARB_fragment_program
Briandf43fb62008-05-06 23:08:51 -0600751 _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
Brian Paul21841f02004-08-14 14:28:11 +0000752#endif
Brian Paul1096eae2006-01-16 16:35:13 +0000753
Dave Airlie7f752fe2004-12-19 03:06:59 +0000754#if FEATURE_ATI_fragment_shader
Brian Paulc7e164f2006-06-30 15:44:30 +0000755 _mesa_HashDeleteAll(ss->ATIShaders, delete_fragshader_cb, ctx);
Brian Paul1096eae2006-01-16 16:35:13 +0000756 _mesa_DeleteHashTable(ss->ATIShaders);
757 _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
Dave Airlie7f752fe2004-12-19 03:06:59 +0000758#endif
Brian Paul30f51ae2001-12-18 04:06:44 +0000759
Tilman Sauerbeck17b50632006-07-11 19:03:21 +0000760#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
Brian Paulc7e164f2006-06-30 15:44:30 +0000761 _mesa_HashDeleteAll(ss->BufferObjects, delete_bufferobj_cb, ctx);
Ian Romanick0207b472003-09-09 00:10:12 +0000762 _mesa_DeleteHashTable(ss->BufferObjects);
Brian Paulddc82ee2005-02-05 19:56:45 +0000763#endif
764
Brian Paulc04bb512006-07-11 21:56:43 +0000765 _mesa_HashDeleteAll(ss->ArrayObjects, delete_arrayobj_cb, ctx);
Tilman Sauerbeckc0eb7772006-07-11 19:36:27 +0000766 _mesa_DeleteHashTable(ss->ArrayObjects);
767
Brian Paulddc82ee2005-02-05 19:56:45 +0000768#if FEATURE_EXT_framebuffer_object
Brian393a6252007-08-13 17:37:30 +0100769 _mesa_HashDeleteAll(ss->FrameBuffers, delete_framebuffer_cb, ctx);
Brian Paulddc82ee2005-02-05 19:56:45 +0000770 _mesa_DeleteHashTable(ss->FrameBuffers);
Brian393a6252007-08-13 17:37:30 +0100771 _mesa_HashDeleteAll(ss->RenderBuffers, delete_renderbuffer_cb, ctx);
Brian Paulddc82ee2005-02-05 19:56:45 +0000772 _mesa_DeleteHashTable(ss->RenderBuffers);
773#endif
Michal Krol9b3752c2005-01-13 14:08:47 +0000774
Briandc732172007-08-14 11:56:59 +0100775 /*
776 * Free texture objects (after FBOs since some textures might have
777 * been bound to FBOs).
778 */
779 ASSERT(ctx->Driver.DeleteTexture);
780 /* the default textures */
781 ctx->Driver.DeleteTexture(ctx, ss->Default1D);
782 ctx->Driver.DeleteTexture(ctx, ss->Default2D);
783 ctx->Driver.DeleteTexture(ctx, ss->Default3D);
784 ctx->Driver.DeleteTexture(ctx, ss->DefaultCubeMap);
785 ctx->Driver.DeleteTexture(ctx, ss->DefaultRect);
786 ctx->Driver.DeleteTexture(ctx, ss->Default1DArray);
787 ctx->Driver.DeleteTexture(ctx, ss->Default2DArray);
788 /* all other textures */
789 _mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx);
790 _mesa_DeleteHashTable(ss->TexObjects);
791
Keith Whitwelle15fd852002-12-12 13:03:15 +0000792 _glthread_DESTROY_MUTEX(ss->Mutex);
793
Brian Paulc7e164f2006-06-30 15:44:30 +0000794 _mesa_free(ss);
jtgafb833d1999-08-19 00:55:39 +0000795}
796
797
Brian Paul4d859f72004-01-23 18:57:05 +0000798/**
799 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
800 */
801static void
Briand881a9c2006-12-20 09:31:07 -0700802_mesa_init_current(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +0000803{
Brian Paul88bf0382004-02-13 15:30:08 +0000804 GLuint i;
jtgafb833d1999-08-19 00:55:39 +0000805
Brian Paul94b30dc2006-04-25 00:53:25 +0000806 /* Init all to (0,0,0,1) */
Keith Whitwell6dc85572003-07-17 13:43:59 +0000807 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
808 ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000809 }
Brian Paul94b30dc2006-04-25 00:53:25 +0000810
811 /* redo special cases: */
Markus Amsler507da2472008-03-09 17:51:11 -0600812 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
Keith Whitwell6dc85572003-07-17 13:43:59 +0000813 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
814 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
Brian Paul88bf0382004-02-13 15:30:08 +0000815 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
Keith Whitwellfd275602006-10-30 20:16:35 +0000816 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
817 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000818}
819
820
Brian Paul4d859f72004-01-23 18:57:05 +0000821/**
Brian Paul05051032005-11-01 04:36:33 +0000822 * Init vertex/fragment program native limits from logical limits.
823 */
824static void
825init_natives(struct gl_program_constants *prog)
826{
827 prog->MaxNativeInstructions = prog->MaxInstructions;
828 prog->MaxNativeAluInstructions = prog->MaxAluInstructions;
829 prog->MaxNativeTexInstructions = prog->MaxTexInstructions;
830 prog->MaxNativeTexIndirections = prog->MaxTexIndirections;
831 prog->MaxNativeAttribs = prog->MaxAttribs;
832 prog->MaxNativeTemps = prog->MaxTemps;
833 prog->MaxNativeAddressRegs = prog->MaxAddressRegs;
834 prog->MaxNativeParameters = prog->MaxParameters;
835}
836
837
838/**
Brian Paul4d859f72004-01-23 18:57:05 +0000839 * Initialize fields of gl_constants (aka ctx->Const.*).
840 * Use defaults from config.h. The device drivers will often override
841 * some of these values (such as number of texture units).
842 */
Keith Whitwell6dc85572003-07-17 13:43:59 +0000843static void
Briand881a9c2006-12-20 09:31:07 -0700844_mesa_init_constants(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +0000845{
Brian Paul4d053dd2000-01-14 04:45:47 +0000846 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000847
Brian Paulcd1cefa2001-06-13 14:56:14 +0000848 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
849 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
850
Brian Paulda238ee2006-04-13 19:21:58 +0000851 assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_COORD_UNITS);
852 assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_IMAGE_UNITS);
853
Brian Paul53f82c52004-10-02 16:39:09 +0000854 /* Constants, may be overriden (usually only reduced) by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000855 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +0000856 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
857 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul8afe7de2002-06-15 03:03:06 +0000858 ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
Ian Romanickbb372f12007-05-16 15:34:22 -0700859 ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
Brian Paul610d5992003-01-14 04:55:45 +0000860 ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
861 ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
Brian Paulda238ee2006-04-13 19:21:58 +0000862 ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
863 ctx->Const.MaxTextureImageUnits);
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000864 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +0000865 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000866 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000867 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
868 ctx->Const.MinPointSize = MIN_POINT_SIZE;
869 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
870 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
871 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000872 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000873 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
874 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
875 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
876 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000877 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000878 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000879 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
880 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paula8644322000-11-27 18:22:13 +0000881 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
882 ctx->Const.MaxLights = MAX_LIGHTS;
Ian Romanick882caa12003-05-30 21:37:14 +0000883 ctx->Const.MaxShininess = 128.0;
Brian Paul53f82c52004-10-02 16:39:09 +0000884 ctx->Const.MaxSpotExponent = 128.0;
885 ctx->Const.MaxViewportWidth = MAX_WIDTH;
886 ctx->Const.MaxViewportHeight = MAX_HEIGHT;
Brian Pauld0492cf2003-04-11 01:20:06 +0000887#if FEATURE_ARB_vertex_program
Brian Paul05051032005-11-01 04:36:33 +0000888 ctx->Const.VertexProgram.MaxInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS;
889 ctx->Const.VertexProgram.MaxAluInstructions = 0;
890 ctx->Const.VertexProgram.MaxTexInstructions = 0;
891 ctx->Const.VertexProgram.MaxTexIndirections = 0;
892 ctx->Const.VertexProgram.MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
Brian64e80882007-04-16 10:36:28 -0600893 ctx->Const.VertexProgram.MaxTemps = MAX_PROGRAM_TEMPS;
Brian Paul05051032005-11-01 04:36:33 +0000894 ctx->Const.VertexProgram.MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
895 ctx->Const.VertexProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
Brian64e80882007-04-16 10:36:28 -0600896 ctx->Const.VertexProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
Brian Paul05051032005-11-01 04:36:33 +0000897 ctx->Const.VertexProgram.MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
Briana90046f2006-12-15 10:07:26 -0700898 ctx->Const.VertexProgram.MaxUniformComponents = 4 * MAX_UNIFORMS;
Brian Paul05051032005-11-01 04:36:33 +0000899 init_natives(&ctx->Const.VertexProgram);
Brian Pauld0492cf2003-04-11 01:20:06 +0000900#endif
Briana90046f2006-12-15 10:07:26 -0700901
Brian Pauld0492cf2003-04-11 01:20:06 +0000902#if FEATURE_ARB_fragment_program
Brian Paul05051032005-11-01 04:36:33 +0000903 ctx->Const.FragmentProgram.MaxInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS;
904 ctx->Const.FragmentProgram.MaxAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS;
905 ctx->Const.FragmentProgram.MaxTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS;
906 ctx->Const.FragmentProgram.MaxTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS;
907 ctx->Const.FragmentProgram.MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
Brian64e80882007-04-16 10:36:28 -0600908 ctx->Const.FragmentProgram.MaxTemps = MAX_PROGRAM_TEMPS;
Brian Paul05051032005-11-01 04:36:33 +0000909 ctx->Const.FragmentProgram.MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
910 ctx->Const.FragmentProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
Brian64e80882007-04-16 10:36:28 -0600911 ctx->Const.FragmentProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
Brian Paul05051032005-11-01 04:36:33 +0000912 ctx->Const.FragmentProgram.MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
Briana90046f2006-12-15 10:07:26 -0700913 ctx->Const.FragmentProgram.MaxUniformComponents = 4 * MAX_UNIFORMS;
Brian Paul05051032005-11-01 04:36:33 +0000914 init_natives(&ctx->Const.FragmentProgram);
Brian Pauld0492cf2003-04-11 01:20:06 +0000915#endif
Brian Pauledd67742003-04-18 18:02:43 +0000916 ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
917 ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
Brian Pauld0492cf2003-04-11 01:20:06 +0000918
George Sapountzis507167d2006-12-06 06:54:13 +0200919 /* CheckArrayBounds is overriden by drivers/x11 for X server */
Brian Paula2b9bad2003-11-10 19:08:37 +0000920 ctx->Const.CheckArrayBounds = GL_FALSE;
Brian Paula2b9bad2003-11-10 19:08:37 +0000921
Brian Paul05051032005-11-01 04:36:33 +0000922 /* GL_ARB_draw_buffers */
Brian Paul53f82c52004-10-02 16:39:09 +0000923 ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
924
Brian Paul3deaa012005-02-07 05:08:24 +0000925 /* GL_OES_read_format */
Ian Romanick33899b72004-10-16 01:16:54 +0000926 ctx->Const.ColorReadFormat = GL_RGBA;
927 ctx->Const.ColorReadType = GL_UNSIGNED_BYTE;
928
Brian Paul3deaa012005-02-07 05:08:24 +0000929#if FEATURE_EXT_framebuffer_object
930 ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
931 ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
932#endif
933
Brian Paul90fcf6c2006-11-01 00:12:41 +0000934#if FEATURE_ARB_vertex_shader
935 ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
Briana90046f2006-12-15 10:07:26 -0700936 ctx->Const.MaxVarying = MAX_VARYING;
Brian Paul90fcf6c2006-11-01 00:12:41 +0000937#endif
938
Brian Paul53f82c52004-10-02 16:39:09 +0000939 /* sanity checks */
Brian Paulda238ee2006-04-13 19:21:58 +0000940 ASSERT(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
941 ctx->Const.MaxTextureCoordUnits));
Brian Paul05051032005-11-01 04:36:33 +0000942 ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
943 ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
Briana90046f2006-12-15 10:07:26 -0700944
945 ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
946 ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
947 ASSERT(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
948 ASSERT(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
Keith Whitwell6dc85572003-07-17 13:43:59 +0000949}
jtgafb833d1999-08-19 00:55:39 +0000950
Brian Paul4d859f72004-01-23 18:57:05 +0000951
Keith Whitwell6dc85572003-07-17 13:43:59 +0000952/**
Brian Paul5e2e96b2006-05-15 15:26:04 +0000953 * Do some sanity checks on the limits/constants for the given context.
954 * Only called the first time a context is bound.
955 */
956static void
957check_context_limits(GLcontext *ctx)
958{
959 /* Many context limits/constants are limited by the size of
960 * internal arrays.
961 */
962 assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
963 assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
964 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
965 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
966
967 assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
968 assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
969
970 /* make sure largest texture image is <= MAX_WIDTH in size */
971 assert((1 << (ctx->Const.MaxTextureLevels -1 )) <= MAX_WIDTH);
972 assert((1 << (ctx->Const.MaxCubeTextureLevels -1 )) <= MAX_WIDTH);
973 assert((1 << (ctx->Const.Max3DTextureLevels -1 )) <= MAX_WIDTH);
974
975 assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
976
977 /* XXX probably add more tests */
978}
979
980
981/**
Keith Whitwell6dc85572003-07-17 13:43:59 +0000982 * Initialize the attribute groups in a GL context.
983 *
984 * \param ctx GL context.
985 *
986 * Initializes all the attributes, calling the respective <tt>init*</tt>
987 * functions for the more complex data structures.
988 */
989static GLboolean
Briand881a9c2006-12-20 09:31:07 -0700990init_attrib_groups(GLcontext *ctx)
Keith Whitwell6dc85572003-07-17 13:43:59 +0000991{
992 assert(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +0000993
Keith Whitwell6dc85572003-07-17 13:43:59 +0000994 /* Constants */
995 _mesa_init_constants( ctx );
Brian Paul0771d152000-04-07 00:19:41 +0000996
Brian Paul4d053dd2000-01-14 04:45:47 +0000997 /* Extensions */
Brian Paulde4f4602003-07-03 02:15:06 +0000998 _mesa_init_extensions( ctx );
jtgafb833d1999-08-19 00:55:39 +0000999
Keith Whitwell6dc85572003-07-17 13:43:59 +00001000 /* Attribute Groups */
Brian Paul40d1a402008-06-10 16:13:42 -06001001#if FEATURE_accum
Keith Whitwell6dc85572003-07-17 13:43:59 +00001002 _mesa_init_accum( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001003#endif
1004#if FEATURE_attrib_stack
Keith Whitwell6dc85572003-07-17 13:43:59 +00001005 _mesa_init_attrib( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001006#endif
Brian Paul148a2842003-09-17 03:40:11 +00001007 _mesa_init_buffer_objects( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001008 _mesa_init_color( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001009#if FEATURE_colortable
Brian Paul05944c02003-07-22 03:51:46 +00001010 _mesa_init_colortables( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001011#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001012 _mesa_init_current( ctx );
1013 _mesa_init_depth( ctx );
1014 _mesa_init_debug( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001015#if FEATURE_dlist
Keith Whitwell6dc85572003-07-17 13:43:59 +00001016 _mesa_init_display_list( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001017#endif
1018#if FEATURE_evaluators
Keith Whitwell6dc85572003-07-17 13:43:59 +00001019 _mesa_init_eval( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001020#endif
Brian Paul3dc65912008-07-03 15:40:38 -06001021 _mesa_init_fbobjects( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001022#if FEATURE_feedback
Keith Whitwell6dc85572003-07-17 13:43:59 +00001023 _mesa_init_feedback( ctx );
Brian Paul36aae182008-06-20 14:29:49 -06001024#else
1025 ctx->RenderMode = GL_RENDER;
Brian Paul40d1a402008-06-10 16:13:42 -06001026#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001027 _mesa_init_fog( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001028#if FEATURE_histogram
Keith Whitwell6dc85572003-07-17 13:43:59 +00001029 _mesa_init_histogram( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001030#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001031 _mesa_init_hint( ctx );
1032 _mesa_init_line( ctx );
1033 _mesa_init_lighting( ctx );
1034 _mesa_init_matrix( ctx );
Brian Paul67742382005-02-26 17:16:12 +00001035 _mesa_init_multisample( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001036 _mesa_init_pixel( ctx );
Brian Paul5f910072008-06-09 14:25:23 -06001037 _mesa_init_pixelstore( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001038 _mesa_init_point( ctx );
1039 _mesa_init_polygon( ctx );
Brian Paul05944c02003-07-22 03:51:46 +00001040 _mesa_init_program( ctx );
Brian Paul2b4e2842008-06-13 13:56:53 -06001041#if FEATURE_ARB_occlusion_query
Brian Paul4fb99502005-09-02 13:42:49 +00001042 _mesa_init_query( ctx );
Brian Paul2b4e2842008-06-13 13:56:53 -06001043#endif
Brian Paul40d1a402008-06-10 16:13:42 -06001044#if FEATURE_drawpix
Brian Paulddc82ee2005-02-05 19:56:45 +00001045 _mesa_init_rastpos( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001046#endif
Brian Paul67742382005-02-26 17:16:12 +00001047 _mesa_init_scissor( ctx );
Brian0bf5dbe2006-12-19 18:02:41 -07001048 _mesa_init_shader_state( ctx );
Keith Whitwell6dc85572003-07-17 13:43:59 +00001049 _mesa_init_stencil( ctx );
1050 _mesa_init_transform( ctx );
1051 _mesa_init_varray( ctx );
1052 _mesa_init_viewport( ctx );
jtgafb833d1999-08-19 00:55:39 +00001053
Keith Whitwell6dc85572003-07-17 13:43:59 +00001054 if (!_mesa_init_texture( ctx ))
1055 return GL_FALSE;
Brian Paulb17a7222003-06-13 02:37:27 +00001056
Brian Paul40d1a402008-06-10 16:13:42 -06001057#if FEATURE_texture_s3tc
Brian Paul8f04c122004-04-27 13:39:20 +00001058 _mesa_init_texture_s3tc( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001059#endif
1060#if FEATURE_texture_fxt1
Brian Paul8f04c122004-04-27 13:39:20 +00001061 _mesa_init_texture_fxt1( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001062#endif
Brian Paul8f04c122004-04-27 13:39:20 +00001063
Brian Paul4d053dd2000-01-14 04:45:47 +00001064 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001065 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001066 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
Brian Paul4d053dd2000-01-14 04:45:47 +00001067
Brian Paula3f13702003-04-01 16:41:50 +00001068 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001069}
1070
1071
Brian Paulf44898c2003-07-18 15:44:57 +00001072/**
Brian4b654d42007-08-23 08:53:43 +01001073 * Update default objects in a GL context with respect to shared state.
1074 *
1075 * \param ctx GL context.
1076 *
1077 * Removes references to old default objects, (texture objects, program
1078 * objects, etc.) and changes to reference those from the current shared
1079 * state.
1080 */
1081static GLboolean
1082update_default_objects(GLcontext *ctx)
1083{
1084 assert(ctx);
1085
1086 _mesa_update_default_objects_program(ctx);
1087 _mesa_update_default_objects_texture(ctx);
1088 _mesa_update_default_objects_buffer_objects(ctx);
1089
1090 return GL_TRUE;
1091}
1092
1093
1094/**
Brian Paul21f69782004-11-27 05:05:32 +00001095 * This is the default function we plug into all dispatch table slots
1096 * This helps prevents a segfault when someone calls a GL function without
1097 * first checking if the extension's supported.
1098 */
1099static int
1100generic_nop(void)
1101{
Briancf239ce2007-06-11 10:57:01 -06001102 _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
Brian Paul21f69782004-11-27 05:05:32 +00001103 return 0;
1104}
1105
1106
1107/**
1108 * Allocate and initialize a new dispatch table.
1109 */
1110static struct _glapi_table *
1111alloc_dispatch_table(void)
1112{
1113 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1114 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1115 * Mesa we do this to accomodate different versions of libGL and various
1116 * DRI drivers.
1117 */
1118 GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
1119 sizeof(struct _glapi_table) / sizeof(_glapi_proc));
1120 struct _glapi_table *table =
1121 (struct _glapi_table *) _mesa_malloc(numEntries * sizeof(_glapi_proc));
1122 if (table) {
1123 _glapi_proc *entry = (_glapi_proc *) table;
Brian Paula760ccf2004-12-03 15:24:34 +00001124 GLint i;
Brian Paul21f69782004-11-27 05:05:32 +00001125 for (i = 0; i < numEntries; i++) {
1126 entry[i] = (_glapi_proc) generic_nop;
1127 }
1128 }
1129 return table;
1130}
1131
1132
1133/**
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001134 * Initialize a GLcontext struct (rendering context).
Keith Whitwell6dc85572003-07-17 13:43:59 +00001135 *
1136 * This includes allocating all the other structs and arrays which hang off of
1137 * the context by pointers.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001138 * Note that the driver needs to pass in its dd_function_table here since
1139 * we need to at least call driverFunctions->NewTextureObject to create the
1140 * default texture objects.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001141 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001142 * Called by _mesa_create_context().
Keith Whitwell6dc85572003-07-17 13:43:59 +00001143 *
1144 * Performs the imports and exports callback tables initialization, and
1145 * miscellaneous one-time initializations. If no shared context is supplied one
1146 * is allocated, and increase its reference count. Setups the GL API dispatch
1147 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
1148 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1149 * for debug flags.
1150 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001151 * \param ctx the context to initialize
1152 * \param visual describes the visual attributes for this context
1153 * \param share_list points to context to share textures, display lists,
1154 * etc with, or NULL
1155 * \param driverFunctions table of device driver functions for this context
1156 * to use
1157 * \param driverContext pointer to driver-specific context data
jtgafb833d1999-08-19 00:55:39 +00001158 */
Brian Paul178a1c52000-04-22 01:05:00 +00001159GLboolean
Briand881a9c2006-12-20 09:31:07 -07001160_mesa_initialize_context(GLcontext *ctx,
1161 const GLvisual *visual,
1162 GLcontext *share_list,
1163 const struct dd_function_table *driverFunctions,
1164 void *driverContext)
jtgafb833d1999-08-19 00:55:39 +00001165{
Brian7cafaff2007-11-01 14:51:37 -06001166 /*ASSERT(driverContext);*/
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001167 assert(driverFunctions->NewTextureObject);
Keith Whitwell3e62d3a2005-03-22 14:27:10 +00001168 assert(driverFunctions->FreeTexImageData);
jtgafb833d1999-08-19 00:55:39 +00001169
Brian Paul4753d602002-06-15 02:38:15 +00001170 /* misc one-time initializations */
1171 one_time_init(ctx);
Brian Paul9a33a112002-06-13 04:28:29 +00001172
Brian Paulb1394fa2000-09-26 20:53:53 +00001173 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001174 ctx->DrawBuffer = NULL;
1175 ctx->ReadBuffer = NULL;
Brian Paule4b23562005-05-04 20:11:35 +00001176 ctx->WinSysDrawBuffer = NULL;
1177 ctx->WinSysReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001178
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001179 /* Plug in driver functions and context pointer here.
1180 * This is important because when we call alloc_shared_state() below
1181 * we'll call ctx->Driver.NewTextureObject() to create the default
1182 * textures.
Brian Paula3f13702003-04-01 16:41:50 +00001183 */
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001184 ctx->Driver = *driverFunctions;
1185 ctx->DriverCtx = driverContext;
Brian Paula3f13702003-04-01 16:41:50 +00001186
jtgafb833d1999-08-19 00:55:39 +00001187 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001188 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001189 ctx->Shared = share_list->Shared;
1190 }
1191 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001192 /* allocate new, unshared state */
Brian Paula3f13702003-04-01 16:41:50 +00001193 if (!alloc_shared_state( ctx )) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001194 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001195 }
1196 }
Brian Paul9560f052000-01-31 23:11:39 +00001197 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001198 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001199 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001200
Keith Whitwell6dc85572003-07-17 13:43:59 +00001201 if (!init_attrib_groups( ctx )) {
jtgafb833d1999-08-19 00:55:39 +00001202 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001203 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001204 }
jtgafb833d1999-08-19 00:55:39 +00001205
Brian Paul21f69782004-11-27 05:05:32 +00001206 /* setup the API dispatch tables */
1207 ctx->Exec = alloc_dispatch_table();
1208 ctx->Save = alloc_dispatch_table();
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001209 if (!ctx->Exec || !ctx->Save) {
1210 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001211 if (ctx->Exec)
Brian Paul21f69782004-11-27 05:05:32 +00001212 _mesa_free(ctx->Exec);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001213 }
Brian Paul03d579a2008-06-17 16:56:32 -06001214#if FEATURE_dispatch
Brian Paul21f69782004-11-27 05:05:32 +00001215 _mesa_init_exec_table(ctx->Exec);
Brian Paul03d579a2008-06-17 16:56:32 -06001216#endif
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001217 ctx->CurrentDispatch = ctx->Exec;
Brian Paul40d1a402008-06-10 16:13:42 -06001218#if FEATURE_dlist
Brian Paul21f69782004-11-27 05:05:32 +00001219 _mesa_init_dlist_table(ctx->Save);
Keith Whitwellae0eaf92003-11-24 15:23:18 +00001220 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
Brian Paul40d1a402008-06-10 16:13:42 -06001221#endif
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001222 /* Neutral tnl module stuff */
Keith Whitwell6dc85572003-07-17 13:43:59 +00001223 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001224 ctx->TnlModule.Current = NULL;
1225 ctx->TnlModule.SwapCount = 0;
Brian Paulb6bcae52001-01-23 23:39:36 +00001226
Brian3e45db62007-03-27 09:51:52 -06001227 ctx->FragmentProgram._MaintainTexEnvProgram
1228 = (_mesa_getenv("MESA_TEX_PROG") != NULL);
1229 ctx->FragmentProgram._UseTexEnvProgram = ctx->FragmentProgram._MaintainTexEnvProgram;
1230
Briana90046f2006-12-15 10:07:26 -07001231 ctx->VertexProgram._MaintainTnlProgram
1232 = (_mesa_getenv("MESA_TNL_PROG") != NULL);
Brian3e45db62007-03-27 09:51:52 -06001233 if (ctx->VertexProgram._MaintainTnlProgram) {
Briana90046f2006-12-15 10:07:26 -07001234 /* this is required... */
1235 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
Brian3e45db62007-03-27 09:51:52 -06001236 }
Keith Whitwell47b29f52005-05-04 11:44:44 +00001237
Brian Paul815cdcf2008-08-19 18:14:15 -06001238#ifdef FEATURE_extra_context_init
1239 _mesa_initialize_context_extra(ctx);
1240#endif
1241
Brian Paula96f8892005-09-13 01:19:29 +00001242 ctx->FirstTimeCurrent = GL_TRUE;
1243
Brian Paul4d053dd2000-01-14 04:45:47 +00001244 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001245}
1246
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001247
Brian Paulde4f4602003-07-03 02:15:06 +00001248/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001249 * Allocate and initialize a GLcontext structure.
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001250 * Note that the driver needs to pass in its dd_function_table here since
1251 * we need to at least call driverFunctions->NewTextureObject to initialize
1252 * the rendering context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001253 *
1254 * \param visual a GLvisual pointer (we copy the struct contents)
1255 * \param share_list another context to share display lists with or NULL
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001256 * \param driverFunctions points to the dd_function_table into which the
1257 * driver has plugged in all its special functions.
1258 * \param driverCtx points to the device driver's private context state
Keith Whitwell6dc85572003-07-17 13:43:59 +00001259 *
1260 * \return pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001261 */
Brian Paul178a1c52000-04-22 01:05:00 +00001262GLcontext *
Briand881a9c2006-12-20 09:31:07 -07001263_mesa_create_context(const GLvisual *visual,
1264 GLcontext *share_list,
1265 const struct dd_function_table *driverFunctions,
1266 void *driverContext)
Brian Paul4d053dd2000-01-14 04:45:47 +00001267{
Brian Paul4753d602002-06-15 02:38:15 +00001268 GLcontext *ctx;
1269
1270 ASSERT(visual);
Brian7cafaff2007-11-01 14:51:37 -06001271 /*ASSERT(driverContext);*/
Brian Paul4753d602002-06-15 02:38:15 +00001272
Brian Paul3c634522002-10-24 23:57:19 +00001273 ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
Brian Paul4753d602002-06-15 02:38:15 +00001274 if (!ctx)
Brian Paul4d053dd2000-01-14 04:45:47 +00001275 return NULL;
Brian Paul4753d602002-06-15 02:38:15 +00001276
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001277 if (_mesa_initialize_context(ctx, visual, share_list,
1278 driverFunctions, driverContext)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001279 return ctx;
1280 }
1281 else {
Brian Paul3c634522002-10-24 23:57:19 +00001282 _mesa_free(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001283 return NULL;
1284 }
1285}
1286
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001287
Keith Whitwell6dc85572003-07-17 13:43:59 +00001288/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001289 * Free the data associated with the given context.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001290 *
1291 * But doesn't free the GLcontext struct itself.
1292 *
1293 * \sa _mesa_initialize_context() and init_attrib_groups().
Brian Paul4d053dd2000-01-14 04:45:47 +00001294 */
Brian Paul178a1c52000-04-22 01:05:00 +00001295void
Brian Paulb1394fa2000-09-26 20:53:53 +00001296_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001297{
Briandc732172007-08-14 11:56:59 +01001298 if (!_mesa_get_current_context()){
1299 /* No current context, but we may need one in order to delete
1300 * texture objs, etc. So temporarily bind the context now.
1301 */
1302 _mesa_make_current(ctx, NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001303 }
Briandc732172007-08-14 11:56:59 +01001304
1305 /* unreference WinSysDraw/Read buffers */
1306 _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer);
1307 _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer);
1308 _mesa_unreference_framebuffer(&ctx->DrawBuffer);
1309 _mesa_unreference_framebuffer(&ctx->ReadBuffer);
Brian Paul4d053dd2000-01-14 04:45:47 +00001310
Briandf43fb62008-05-06 23:08:51 -06001311 _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
1312 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
1313 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
1314
1315 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
1316 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
1317 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
1318
Brian145d7622007-08-16 10:05:00 +01001319 _mesa_free_attrib_data(ctx);
Keith Whitwell6dc85572003-07-17 13:43:59 +00001320 _mesa_free_lighting_data( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001321#if FEATURE_evaluators
Keith Whitwell6dc85572003-07-17 13:43:59 +00001322 _mesa_free_eval_data( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001323#endif
Keith Whitwell6dc85572003-07-17 13:43:59 +00001324 _mesa_free_texture_data( ctx );
1325 _mesa_free_matrix_data( ctx );
1326 _mesa_free_viewport_data( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001327#if FEATURE_colortable
Brian Paul05944c02003-07-22 03:51:46 +00001328 _mesa_free_colortables_data( ctx );
Brian Paul40d1a402008-06-10 16:13:42 -06001329#endif
Brian Paul21841f02004-08-14 14:28:11 +00001330 _mesa_free_program_data(ctx);
Brian935f93f2007-03-24 16:20:02 -06001331 _mesa_free_shader_state(ctx);
Brian Paul2b4e2842008-06-13 13:56:53 -06001332#if FEATURE_ARB_occlusion_query
Brian Paul4fb99502005-09-02 13:42:49 +00001333 _mesa_free_query_data(ctx);
Brian Paul2b4e2842008-06-13 13:56:53 -06001334#endif
Brian Paul21841f02004-08-14 14:28:11 +00001335
1336#if FEATURE_ARB_vertex_buffer_object
1337 _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj);
Brian Paul8dfc5b92002-10-16 17:57:51 +00001338#endif
Brian Paulc04bb512006-07-11 21:56:43 +00001339 _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
Brian Paulfd284452001-07-19 15:54:34 +00001340
Brian Paul65a66f52004-11-27 22:47:59 +00001341 /* free dispatch tables */
1342 _mesa_free(ctx->Exec);
1343 _mesa_free(ctx->Save);
1344
Brian Paul30f51ae2001-12-18 04:06:44 +00001345 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001346 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001347 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001348 assert(ctx->Shared->RefCount >= 0);
1349 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1350 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001351 /* free shared state */
1352 free_shared_state( ctx, ctx->Shared );
1353 }
1354
Brian Paul702ca202003-07-18 15:22:16 +00001355 if (ctx->Extensions.String)
Brian Paulc7e164f2006-06-30 15:44:30 +00001356 _mesa_free((void *) ctx->Extensions.String);
Briandc732172007-08-14 11:56:59 +01001357
1358 /* unbind the context if it's currently bound */
1359 if (ctx == _mesa_get_current_context()) {
1360 _mesa_make_current(NULL, NULL, NULL);
1361 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001362}
1363
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001364
Keith Whitwell6dc85572003-07-17 13:43:59 +00001365/**
Brian Paul4d053dd2000-01-14 04:45:47 +00001366 * Destroy a GLcontext structure.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001367 *
1368 * \param ctx GL context.
1369 *
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001370 * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
jtgafb833d1999-08-19 00:55:39 +00001371 */
Brian Paul178a1c52000-04-22 01:05:00 +00001372void
Brian Paulb1394fa2000-09-26 20:53:53 +00001373_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001374{
1375 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001376 _mesa_free_context_data(ctx);
Brian Paulc7e164f2006-06-30 15:44:30 +00001377 _mesa_free( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001378 }
1379}
1380
Brian Pauld3fd7ba2004-01-20 02:49:27 +00001381
Keith Whitwell6dc85572003-07-17 13:43:59 +00001382#if _HAVE_FULL_GL
1383/**
jtgafb833d1999-08-19 00:55:39 +00001384 * Copy attribute groups from one context to another.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001385 *
1386 * \param src source context
1387 * \param dst destination context
1388 * \param mask bitwise OR of GL_*_BIT flags
1389 *
1390 * According to the bits specified in \p mask, copies the corresponding
Jose Fonseca375457b2004-09-09 22:23:24 +00001391 * attributes from \p src into \p dst. For many of the attributes a simple \c
Keith Whitwell6dc85572003-07-17 13:43:59 +00001392 * memcpy is not enough due to the existence of internal pointers in their data
1393 * structures.
jtgafb833d1999-08-19 00:55:39 +00001394 */
Brian Paul178a1c52000-04-22 01:05:00 +00001395void
Brian Paulb1394fa2000-09-26 20:53:53 +00001396_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001397{
1398 if (mask & GL_ACCUM_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001399 /* OK to memcpy */
1400 dst->Accum = src->Accum;
jtgafb833d1999-08-19 00:55:39 +00001401 }
1402 if (mask & GL_COLOR_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001403 /* OK to memcpy */
1404 dst->Color = src->Color;
jtgafb833d1999-08-19 00:55:39 +00001405 }
1406 if (mask & GL_CURRENT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001407 /* OK to memcpy */
1408 dst->Current = src->Current;
jtgafb833d1999-08-19 00:55:39 +00001409 }
1410 if (mask & GL_DEPTH_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001411 /* OK to memcpy */
1412 dst->Depth = src->Depth;
jtgafb833d1999-08-19 00:55:39 +00001413 }
1414 if (mask & GL_ENABLE_BIT) {
1415 /* no op */
1416 }
1417 if (mask & GL_EVAL_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001418 /* OK to memcpy */
1419 dst->Eval = src->Eval;
jtgafb833d1999-08-19 00:55:39 +00001420 }
1421 if (mask & GL_FOG_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001422 /* OK to memcpy */
1423 dst->Fog = src->Fog;
jtgafb833d1999-08-19 00:55:39 +00001424 }
1425 if (mask & GL_HINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001426 /* OK to memcpy */
1427 dst->Hint = src->Hint;
jtgafb833d1999-08-19 00:55:39 +00001428 }
1429 if (mask & GL_LIGHTING_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001430 GLuint i;
1431 /* begin with memcpy */
Brian Paul2aabdc72006-02-24 18:19:11 +00001432 dst->Light = src->Light;
Brian Paul85d81602002-06-17 23:36:31 +00001433 /* fixup linked lists to prevent pointer insanity */
1434 make_empty_list( &(dst->Light.EnabledList) );
1435 for (i = 0; i < MAX_LIGHTS; i++) {
1436 if (dst->Light.Light[i].Enabled) {
1437 insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
1438 }
1439 }
jtgafb833d1999-08-19 00:55:39 +00001440 }
1441 if (mask & GL_LINE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001442 /* OK to memcpy */
1443 dst->Line = src->Line;
jtgafb833d1999-08-19 00:55:39 +00001444 }
1445 if (mask & GL_LIST_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001446 /* OK to memcpy */
1447 dst->List = src->List;
jtgafb833d1999-08-19 00:55:39 +00001448 }
1449 if (mask & GL_PIXEL_MODE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001450 /* OK to memcpy */
1451 dst->Pixel = src->Pixel;
jtgafb833d1999-08-19 00:55:39 +00001452 }
1453 if (mask & GL_POINT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001454 /* OK to memcpy */
1455 dst->Point = src->Point;
jtgafb833d1999-08-19 00:55:39 +00001456 }
1457 if (mask & GL_POLYGON_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001458 /* OK to memcpy */
1459 dst->Polygon = src->Polygon;
jtgafb833d1999-08-19 00:55:39 +00001460 }
1461 if (mask & GL_POLYGON_STIPPLE_BIT) {
1462 /* Use loop instead of MEMCPY due to problem with Portland Group's
1463 * C compiler. Reported by John Stone.
1464 */
Brian Paul85d81602002-06-17 23:36:31 +00001465 GLuint i;
1466 for (i = 0; i < 32; i++) {
jtgafb833d1999-08-19 00:55:39 +00001467 dst->PolygonStipple[i] = src->PolygonStipple[i];
1468 }
1469 }
1470 if (mask & GL_SCISSOR_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001471 /* OK to memcpy */
1472 dst->Scissor = src->Scissor;
jtgafb833d1999-08-19 00:55:39 +00001473 }
1474 if (mask & GL_STENCIL_BUFFER_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001475 /* OK to memcpy */
1476 dst->Stencil = src->Stencil;
jtgafb833d1999-08-19 00:55:39 +00001477 }
1478 if (mask & GL_TEXTURE_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001479 /* Cannot memcpy because of pointers */
1480 _mesa_copy_texture_state(src, dst);
jtgafb833d1999-08-19 00:55:39 +00001481 }
1482 if (mask & GL_TRANSFORM_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001483 /* OK to memcpy */
1484 dst->Transform = src->Transform;
jtgafb833d1999-08-19 00:55:39 +00001485 }
1486 if (mask & GL_VIEWPORT_BIT) {
Brian Paul85d81602002-06-17 23:36:31 +00001487 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1488 dst->Viewport.X = src->Viewport.X;
1489 dst->Viewport.Y = src->Viewport.Y;
1490 dst->Viewport.Width = src->Viewport.Width;
1491 dst->Viewport.Height = src->Viewport.Height;
1492 dst->Viewport.Near = src->Viewport.Near;
1493 dst->Viewport.Far = src->Viewport.Far;
1494 _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001495 }
Brian Paul85d81602002-06-17 23:36:31 +00001496
Keith Whitwella96308c2000-10-30 13:31:59 +00001497 /* XXX FIXME: Call callbacks?
1498 */
1499 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001500}
Keith Whitwell23caf202000-11-16 21:05:34 +00001501#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001502
1503
Brian Paulb1d53d92003-06-11 18:48:19 +00001504/**
1505 * Check if the given context can render into the given framebuffer
1506 * by checking visual attributes.
Brian Paulca007cb2006-03-07 03:01:26 +00001507 *
Brianee170f22007-06-08 14:12:27 -06001508 * Most of these tests could go away because Mesa is now pretty flexible
1509 * in terms of mixing rendering contexts with framebuffers. As long
1510 * as RGB vs. CI mode agree, we're probably good.
Brian Paulca007cb2006-03-07 03:01:26 +00001511 *
Brian Paulb1d53d92003-06-11 18:48:19 +00001512 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1513 */
1514static GLboolean
1515check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
1516{
1517 const GLvisual *ctxvis = &ctx->Visual;
1518 const GLvisual *bufvis = &buffer->Visual;
1519
1520 if (ctxvis == bufvis)
1521 return GL_TRUE;
1522
1523 if (ctxvis->rgbMode != bufvis->rgbMode)
1524 return GL_FALSE;
Brian Pauld75963d2006-03-07 02:57:04 +00001525#if 0
1526 /* disabling this fixes the fgl_glxgears pbuffer demo */
Brian Paulb1d53d92003-06-11 18:48:19 +00001527 if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
1528 return GL_FALSE;
Brian Pauld75963d2006-03-07 02:57:04 +00001529#endif
Brian Paulb1d53d92003-06-11 18:48:19 +00001530 if (ctxvis->stereoMode && !bufvis->stereoMode)
1531 return GL_FALSE;
1532 if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
1533 return GL_FALSE;
1534 if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
1535 return GL_FALSE;
1536 if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
1537 return GL_FALSE;
1538 if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
1539 return GL_FALSE;
1540 if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
1541 return GL_FALSE;
1542 if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
1543 return GL_FALSE;
Brianee170f22007-06-08 14:12:27 -06001544#if 0
1545 /* disabled (see bug 11161) */
Brian Paulb1d53d92003-06-11 18:48:19 +00001546 if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
1547 return GL_FALSE;
Brianee170f22007-06-08 14:12:27 -06001548#endif
Brian Paulb1d53d92003-06-11 18:48:19 +00001549 if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
1550 return GL_FALSE;
1551
1552 return GL_TRUE;
1553}
1554
1555
Keith Whitwell6dc85572003-07-17 13:43:59 +00001556/**
Brian Paula702bbf2005-09-14 03:11:36 +00001557 * Do one-time initialization for the given framebuffer. Specifically,
1558 * ask the driver for the window's current size and update the framebuffer
1559 * object to match.
1560 * Really, the device driver should totally take care of this.
1561 */
1562static void
1563initialize_framebuffer_size(GLcontext *ctx, GLframebuffer *fb)
1564{
1565 GLuint width, height;
Brian Paul55e42e52006-10-17 17:43:47 +00001566 if (ctx->Driver.GetBufferSize) {
1567 ctx->Driver.GetBufferSize(fb, &width, &height);
1568 if (ctx->Driver.ResizeBuffers)
1569 ctx->Driver.ResizeBuffers(ctx, fb, width, height);
1570 fb->Initialized = GL_TRUE;
1571 }
Brian Paula702bbf2005-09-14 03:11:36 +00001572}
1573
1574
1575/**
1576 * Bind the given context to the given drawBuffer and readBuffer and
1577 * make it the current context for the calling thread.
1578 * We'll render into the drawBuffer and read pixels from the
1579 * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
Keith Whitwell6dc85572003-07-17 13:43:59 +00001580 *
Brian Paula702bbf2005-09-14 03:11:36 +00001581 * We check that the context's and framebuffer's visuals are compatible
1582 * and return immediately if they're not.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001583 *
Brian Paula702bbf2005-09-14 03:11:36 +00001584 * \param newCtx the new GL context. If NULL then there will be no current GL
1585 * context.
1586 * \param drawBuffer the drawing framebuffer
1587 * \param readBuffer the reading framebuffer
Brian Paul00037781999-12-17 14:52:35 +00001588 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001589void
Brian Paule4b23562005-05-04 20:11:35 +00001590_mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
1591 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001592{
Keith Whitwell5c728372005-05-12 10:22:29 +00001593 if (MESA_VERBOSE & VERBOSE_API)
Brian Paule4b23562005-05-04 20:11:35 +00001594 _mesa_debug(newCtx, "_mesa_make_current()\n");
Brian Paul00037781999-12-17 14:52:35 +00001595
Brian Paulbe3602d2001-02-28 00:27:48 +00001596 /* Check that the context's and framebuffer's visuals are compatible.
Brian Paulbe3602d2001-02-28 00:27:48 +00001597 */
Brian Paulf1038f82006-03-20 15:20:57 +00001598 if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
Brian Pauld75963d2006-03-07 02:57:04 +00001599 if (!check_compatible(newCtx, drawBuffer)) {
1600 _mesa_warning(newCtx,
1601 "MakeCurrent: incompatible visuals for context and drawbuffer");
Brian Paulb1d53d92003-06-11 18:48:19 +00001602 return;
Brian Pauld75963d2006-03-07 02:57:04 +00001603 }
Brian Paulb1d53d92003-06-11 18:48:19 +00001604 }
Brian Paulf1038f82006-03-20 15:20:57 +00001605 if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
Brian Pauld75963d2006-03-07 02:57:04 +00001606 if (!check_compatible(newCtx, readBuffer)) {
1607 _mesa_warning(newCtx,
1608 "MakeCurrent: incompatible visuals for context and readbuffer");
Brian Paulb1d53d92003-06-11 18:48:19 +00001609 return;
Brian Pauld75963d2006-03-07 02:57:04 +00001610 }
Brian Paulbe3602d2001-02-28 00:27:48 +00001611 }
1612
Brian Paulc6c0f942006-03-16 18:05:25 +00001613 /* We used to call _glapi_check_multithread() here. Now do it in drivers */
Brian Paulf9b97d92000-01-28 20:17:42 +00001614 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001615 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001616
Keith Whitwell23caf202000-11-16 21:05:34 +00001617 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001618 _glapi_set_dispatch(NULL); /* none current */
1619 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001620 else {
1621 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001622
Keith Whitwell23caf202000-11-16 21:05:34 +00001623 if (drawBuffer && readBuffer) {
1624 /* TODO: check if newCtx and buffer's visual match??? */
Brian Paule4b23562005-05-04 20:11:35 +00001625
Brian Paule4b23562005-05-04 20:11:35 +00001626 ASSERT(drawBuffer->Name == 0);
1627 ASSERT(readBuffer->Name == 0);
Briana510bc32007-03-06 10:07:59 -07001628 _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
1629 _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
Brian Paulf1038f82006-03-20 15:20:57 +00001630
1631 /*
1632 * Only set the context's Draw/ReadBuffer fields if they're NULL
1633 * or not bound to a user-created FBO.
1634 */
Brian Paule4b23562005-05-04 20:11:35 +00001635 if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
Keith Whitwell0397b2b2008-09-11 16:05:15 +01001636 /* KW: merge conflict here, revisit.
1637 */
1638 /* fix up the fb fields - these will end up wrong otherwise
1639 * if the DRIdrawable changes, and everything relies on them.
1640 * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
1641 */
José Fonseca53174af2008-05-31 18:14:09 +09001642 unsigned int i;
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001643 GLenum buffers[MAX_DRAW_BUFFERS];
Alan Hourihanee97bedb2008-05-01 14:54:56 +01001644
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001645 _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
Alan Hourihanee97bedb2008-05-01 14:54:56 +01001646
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001647 for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) {
1648 buffers[i] = newCtx->Color.DrawBuffer[i];
1649 }
Alan Hourihanee97bedb2008-05-01 14:54:56 +01001650
Roland Scheideggercbfe29c2007-07-16 18:21:36 +02001651 _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers, buffers, NULL);
Brian Paulf1038f82006-03-20 15:20:57 +00001652 }
1653 if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
Briana510bc32007-03-06 10:07:59 -07001654 _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
Brian Paule4b23562005-05-04 20:11:35 +00001655 }
Brian Paulbb5c84f2005-07-01 01:22:25 +00001656
Brian32d86eb2007-08-16 18:52:48 +01001657 /* XXX only set this flag if we're really changing the draw/read
1658 * framebuffer bindings.
1659 */
Keith Whitwell23caf202000-11-16 21:05:34 +00001660 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul10d7f542002-06-17 23:38:14 +00001661
Brian Paul4d4add02006-10-15 19:26:43 +00001662#if 1
1663 /* We want to get rid of these lines: */
1664
Keith Whitwell6dc85572003-07-17 13:43:59 +00001665#if _HAVE_FULL_GL
Brian Paul65a66f52004-11-27 22:47:59 +00001666 if (!drawBuffer->Initialized) {
Brian Paula702bbf2005-09-14 03:11:36 +00001667 initialize_framebuffer_size(newCtx, drawBuffer);
Brian Paul10d7f542002-06-17 23:38:14 +00001668 }
Brian Paul65a66f52004-11-27 22:47:59 +00001669 if (readBuffer != drawBuffer && !readBuffer->Initialized) {
Brian Paula702bbf2005-09-14 03:11:36 +00001670 initialize_framebuffer_size(newCtx, readBuffer);
Brian Paul10d7f542002-06-17 23:38:14 +00001671 }
Keith Whitwellf9bfdb12006-09-22 11:36:30 +00001672
1673 _mesa_resizebuffers(newCtx);
Keith Whitwell6dc85572003-07-17 13:43:59 +00001674#endif
Brian Paul4d4add02006-10-15 19:26:43 +00001675
1676#else
1677 /* We want the drawBuffer and readBuffer to be initialized by
1678 * the driver.
1679 * This generally means the Width and Height match the actual
1680 * window size and the renderbuffers (both hardware and software
1681 * based) are allocated to match. The later can generally be
1682 * done with a call to _mesa_resize_framebuffer().
1683 *
1684 * It's theoretically possible for a buffer to have zero width
1685 * or height, but for now, assert check that the driver did what's
1686 * expected of it.
1687 */
1688 ASSERT(drawBuffer->Width > 0);
1689 ASSERT(drawBuffer->Height > 0);
1690#endif
1691
Brian Paul65a66f52004-11-27 22:47:59 +00001692 if (newCtx->FirstTimeCurrent) {
1693 /* set initial viewport and scissor size now */
Brian Paula702bbf2005-09-14 03:11:36 +00001694 _mesa_set_viewport(newCtx, 0, 0,
1695 drawBuffer->Width, drawBuffer->Height);
Brian Pauldb79d2a2006-03-29 18:41:19 +00001696 _mesa_set_scissor(newCtx, 0, 0,
1697 drawBuffer->Width, drawBuffer->Height );
Brian Paul5e2e96b2006-05-15 15:26:04 +00001698 check_context_limits(newCtx);
Brian Paul65a66f52004-11-27 22:47:59 +00001699 }
Brian Paul00037781999-12-17 14:52:35 +00001700 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001701
Keith Whitwell23caf202000-11-16 21:05:34 +00001702 /* We can use this to help debug user's problems. Tell them to set
1703 * the MESA_INFO env variable before running their app. Then the
1704 * first time each context is made current we'll print some useful
1705 * information.
1706 */
1707 if (newCtx->FirstTimeCurrent) {
Brian Paul3c634522002-10-24 23:57:19 +00001708 if (_mesa_getenv("MESA_INFO")) {
Keith Whitwell6dc85572003-07-17 13:43:59 +00001709 _mesa_print_info();
Keith Whitwell23caf202000-11-16 21:05:34 +00001710 }
1711 newCtx->FirstTimeCurrent = GL_FALSE;
1712 }
Brian Paul00037781999-12-17 14:52:35 +00001713 }
1714}
1715
Brian Paul635ee2d2005-04-15 17:25:07 +00001716
1717/**
1718 * Make context 'ctx' share the display lists, textures and programs
1719 * that are associated with 'ctxToShare'.
1720 * Any display lists, textures or programs associated with 'ctx' will
1721 * be deleted if nobody else is sharing them.
1722 */
1723GLboolean
1724_mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
1725{
1726 if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
Brian4b654d42007-08-23 08:53:43 +01001727 struct gl_shared_state *oldSharedState = ctx->Shared;
1728
Brian Paul635ee2d2005-04-15 17:25:07 +00001729 ctx->Shared = ctxToShare->Shared;
1730 ctx->Shared->RefCount++;
Brian4b654d42007-08-23 08:53:43 +01001731
1732 update_default_objects(ctx);
1733
1734 oldSharedState->RefCount--;
1735 if (oldSharedState->RefCount == 0) {
1736 free_shared_state(ctx, oldSharedState);
1737 }
1738
Brian Paul635ee2d2005-04-15 17:25:07 +00001739 return GL_TRUE;
1740 }
1741 else {
1742 return GL_FALSE;
1743 }
1744}
1745
1746
1747
Keith Whitwell6dc85572003-07-17 13:43:59 +00001748/**
Briand881a9c2006-12-20 09:31:07 -07001749 * \return pointer to the current GL context for this thread.
Keith Whitwell6dc85572003-07-17 13:43:59 +00001750 *
1751 * Calls _glapi_get_context(). This isn't the fastest way to get the current
Briand881a9c2006-12-20 09:31:07 -07001752 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
1753 * context.h.
Brian Paul00037781999-12-17 14:52:35 +00001754 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001755GLcontext *
1756_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001757{
Brian Paulf9b97d92000-01-28 20:17:42 +00001758 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001759}
1760
Briand881a9c2006-12-20 09:31:07 -07001761
Keith Whitwell6dc85572003-07-17 13:43:59 +00001762/**
1763 * Get context's current API dispatch table.
1764 *
1765 * It'll either be the immediate-mode execute dispatcher or the display list
1766 * compile dispatcher.
1767 *
1768 * \param ctx GL context.
1769 *
1770 * \return pointer to dispatch_table.
1771 *
1772 * Simply returns __GLcontextRec::CurrentDispatch.
Brian Paulfbd8f211999-11-11 01:22:25 +00001773 */
1774struct _glapi_table *
1775_mesa_get_dispatch(GLcontext *ctx)
1776{
1777 return ctx->CurrentDispatch;
1778}
1779
Keith Whitwell6dc85572003-07-17 13:43:59 +00001780/*@}*/
Brian Paulfbd8f211999-11-11 01:22:25 +00001781
1782
jtgafb833d1999-08-19 00:55:39 +00001783/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001784/** \name Miscellaneous functions */
jtgafb833d1999-08-19 00:55:39 +00001785/**********************************************************************/
Keith Whitwell6dc85572003-07-17 13:43:59 +00001786/*@{*/
jtgafb833d1999-08-19 00:55:39 +00001787
Keith Whitwell6dc85572003-07-17 13:43:59 +00001788/**
1789 * Record an error.
1790 *
1791 * \param ctx GL context.
1792 * \param error error code.
1793 *
1794 * Records the given error code and call the driver's dd_function_table::Error
1795 * function if defined.
1796 *
1797 * \sa
Brian Paul4e9676f2002-06-29 19:48:15 +00001798 * This is called via _mesa_error().
jtgafb833d1999-08-19 00:55:39 +00001799 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001800void
Briand881a9c2006-12-20 09:31:07 -07001801_mesa_record_error(GLcontext *ctx, GLenum error)
jtgafb833d1999-08-19 00:55:39 +00001802{
Brian Paul18a285a2002-03-16 00:53:15 +00001803 if (!ctx)
1804 return;
1805
Brian Paul7eb06032000-07-14 04:13:40 +00001806 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00001807 ctx->ErrorValue = error;
1808 }
1809
1810 /* Call device driver's error handler, if any. This is used on the Mac. */
1811 if (ctx->Driver.Error) {
Briand881a9c2006-12-20 09:31:07 -07001812 ctx->Driver.Error(ctx);
jtgafb833d1999-08-19 00:55:39 +00001813 }
1814}
1815
Briand881a9c2006-12-20 09:31:07 -07001816
Keith Whitwell6dc85572003-07-17 13:43:59 +00001817/**
1818 * Execute glFinish().
1819 *
1820 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1821 * dd_function_table::Finish driver callback, if not NULL.
1822 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001823void GLAPIENTRY
Briand881a9c2006-12-20 09:31:07 -07001824_mesa_Finish(void)
jtgafb833d1999-08-19 00:55:39 +00001825{
Brian Paulfa9df402000-02-02 19:16:46 +00001826 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001827 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001828 if (ctx->Driver.Finish) {
Briand881a9c2006-12-20 09:31:07 -07001829 ctx->Driver.Finish(ctx);
jtgafb833d1999-08-19 00:55:39 +00001830 }
1831}
1832
Briand881a9c2006-12-20 09:31:07 -07001833
Keith Whitwell6dc85572003-07-17 13:43:59 +00001834/**
1835 * Execute glFlush().
1836 *
1837 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1838 * dd_function_table::Flush driver callback, if not NULL.
1839 */
Kendall Bennettc40d1dd2003-10-21 22:22:17 +00001840void GLAPIENTRY
Briand881a9c2006-12-20 09:31:07 -07001841_mesa_Flush(void)
jtgafb833d1999-08-19 00:55:39 +00001842{
Brian Paulfa9df402000-02-02 19:16:46 +00001843 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001844 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001845 if (ctx->Driver.Flush) {
Briand881a9c2006-12-20 09:31:07 -07001846 ctx->Driver.Flush(ctx);
jtgafb833d1999-08-19 00:55:39 +00001847 }
jtgafb833d1999-08-19 00:55:39 +00001848}
Brian Paul48c6a6e2000-09-08 21:28:04 +00001849
1850
Keith Whitwell6dc85572003-07-17 13:43:59 +00001851/*@}*/