context.c revision cdc920a0
17117f1b4Smrg/*
27117f1b4Smrg * Mesa 3-D graphics library
3c1f859d4Smrg * Version:  7.3
47117f1b4Smrg *
57117f1b4Smrg * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6c1f859d4Smrg * Copyright (C) 2008  VMware, Inc.  All Rights Reserved.
77117f1b4Smrg *
87117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
97117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
107117f1b4Smrg * to deal in the Software without restriction, including without limitation
117117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
127117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
137117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
147117f1b4Smrg *
157117f1b4Smrg * The above copyright notice and this permission notice shall be included
167117f1b4Smrg * in all copies or substantial portions of the Software.
177117f1b4Smrg *
187117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
197117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
217117f1b4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
227117f1b4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
237117f1b4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
247117f1b4Smrg */
257117f1b4Smrg
26c1f859d4Smrg/**
27c1f859d4Smrg * \file context.c
28c1f859d4Smrg * Mesa context/visual/framebuffer management functions.
29c1f859d4Smrg * \author Brian Paul
30c1f859d4Smrg */
317117f1b4Smrg
327117f1b4Smrg/**
337117f1b4Smrg * \mainpage Mesa Main Module
347117f1b4Smrg *
357117f1b4Smrg * \section MainIntroduction Introduction
367117f1b4Smrg *
377117f1b4Smrg * The Mesa Main module consists of all the files in the main/ directory.
387117f1b4Smrg * Among the features of this module are:
397117f1b4Smrg * <UL>
407117f1b4Smrg * <LI> Structures to represent most GL state </LI>
417117f1b4Smrg * <LI> State set/get functions </LI>
427117f1b4Smrg * <LI> Display lists </LI>
437117f1b4Smrg * <LI> Texture unit, object and image handling </LI>
447117f1b4Smrg * <LI> Matrix and attribute stacks </LI>
457117f1b4Smrg * </UL>
467117f1b4Smrg *
477117f1b4Smrg * Other modules are responsible for API dispatch, vertex transformation,
487117f1b4Smrg * point/line/triangle setup, rasterization, vertex array caching,
497117f1b4Smrg * vertex/fragment programs/shaders, etc.
507117f1b4Smrg *
517117f1b4Smrg *
527117f1b4Smrg * \section AboutDoxygen About Doxygen
537117f1b4Smrg *
547117f1b4Smrg * If you're viewing this information as Doxygen-generated HTML you'll
557117f1b4Smrg * see the documentation index at the top of this page.
567117f1b4Smrg *
577117f1b4Smrg * The first line lists the Mesa source code modules.
587117f1b4Smrg * The second line lists the indexes available for viewing the documentation
597117f1b4Smrg * for each module.
607117f1b4Smrg *
617117f1b4Smrg * Selecting the <b>Main page</b> link will display a summary of the module
627117f1b4Smrg * (this page).
637117f1b4Smrg *
647117f1b4Smrg * Selecting <b>Data Structures</b> will list all C structures.
657117f1b4Smrg *
667117f1b4Smrg * Selecting the <b>File List</b> link will list all the source files in
677117f1b4Smrg * the module.
687117f1b4Smrg * Selecting a filename will show a list of all functions defined in that file.
697117f1b4Smrg *
707117f1b4Smrg * Selecting the <b>Data Fields</b> link will display a list of all
717117f1b4Smrg * documented structure members.
727117f1b4Smrg *
737117f1b4Smrg * Selecting the <b>Globals</b> link will display a list
747117f1b4Smrg * of all functions, structures, global variables and macros in the module.
757117f1b4Smrg *
767117f1b4Smrg */
777117f1b4Smrg
787117f1b4Smrg
797117f1b4Smrg#include "glheader.h"
804a49301eSmrg#include "mfeatures.h"
817117f1b4Smrg#include "imports.h"
827117f1b4Smrg#include "accum.h"
83c1f859d4Smrg#include "api_exec.h"
847117f1b4Smrg#include "arrayobj.h"
857117f1b4Smrg#include "attrib.h"
867117f1b4Smrg#include "blend.h"
877117f1b4Smrg#include "buffers.h"
887117f1b4Smrg#include "bufferobj.h"
897117f1b4Smrg#include "colortab.h"
907117f1b4Smrg#include "context.h"
914a49301eSmrg#include "cpuinfo.h"
927117f1b4Smrg#include "debug.h"
937117f1b4Smrg#include "depth.h"
947117f1b4Smrg#include "dlist.h"
957117f1b4Smrg#include "eval.h"
967117f1b4Smrg#include "extensions.h"
977117f1b4Smrg#include "fbobject.h"
987117f1b4Smrg#include "feedback.h"
997117f1b4Smrg#include "fog.h"
1007117f1b4Smrg#include "framebuffer.h"
1017117f1b4Smrg#include "histogram.h"
1027117f1b4Smrg#include "hint.h"
1037117f1b4Smrg#include "hash.h"
1047117f1b4Smrg#include "light.h"
1057117f1b4Smrg#include "lines.h"
1067117f1b4Smrg#include "macros.h"
1077117f1b4Smrg#include "matrix.h"
108c1f859d4Smrg#include "multisample.h"
1097117f1b4Smrg#include "pixel.h"
110c1f859d4Smrg#include "pixelstore.h"
1117117f1b4Smrg#include "points.h"
1127117f1b4Smrg#include "polygon.h"
1137117f1b4Smrg#include "queryobj.h"
1144a49301eSmrg#if FEATURE_ARB_sync
1154a49301eSmrg#include "syncobj.h"
116c1f859d4Smrg#endif
1177117f1b4Smrg#include "rastpos.h"
1184a49301eSmrg#include "remap.h"
119c1f859d4Smrg#include "scissor.h"
1204a49301eSmrg#include "shared.h"
1217117f1b4Smrg#include "simple_list.h"
1227117f1b4Smrg#include "state.h"
1237117f1b4Smrg#include "stencil.h"
1244a49301eSmrg#include "texcompress_s3tc.h"
1257117f1b4Smrg#include "texstate.h"
1267117f1b4Smrg#include "mtypes.h"
1277117f1b4Smrg#include "varray.h"
1287117f1b4Smrg#include "version.h"
1294a49301eSmrg#include "viewport.h"
1307117f1b4Smrg#include "vtxfmt.h"
131c1f859d4Smrg#include "glapi/glthread.h"
132c1f859d4Smrg#include "glapi/glapitable.h"
133c1f859d4Smrg#include "shader/program.h"
1344a49301eSmrg#include "shader/prog_print.h"
135c1f859d4Smrg#include "shader/shader_api.h"
1367117f1b4Smrg#if _HAVE_FULL_GL
1377117f1b4Smrg#include "math/m_matrix.h"
1387117f1b4Smrg#endif
1397117f1b4Smrg
1407117f1b4Smrg#ifdef USE_SPARC_ASM
1417117f1b4Smrg#include "sparc/sparc.h"
1427117f1b4Smrg#endif
1437117f1b4Smrg
1447117f1b4Smrg#ifndef MESA_VERBOSE
1457117f1b4Smrgint MESA_VERBOSE = 0;
1467117f1b4Smrg#endif
1477117f1b4Smrg
1487117f1b4Smrg#ifndef MESA_DEBUG_FLAGS
1497117f1b4Smrgint MESA_DEBUG_FLAGS = 0;
1507117f1b4Smrg#endif
1517117f1b4Smrg
1527117f1b4Smrg
1537117f1b4Smrg/* ubyte -> float conversion */
1547117f1b4SmrgGLfloat _mesa_ubyte_to_float_color_tab[256];
1557117f1b4Smrg
1567117f1b4Smrg
1577117f1b4Smrg
1587117f1b4Smrg/**
1597117f1b4Smrg * Swap buffers notification callback.
1607117f1b4Smrg *
1614a49301eSmrg * \param ctx GL context.
1627117f1b4Smrg *
1637117f1b4Smrg * Called by window system just before swapping buffers.
1647117f1b4Smrg * We have to finish any pending rendering.
1657117f1b4Smrg */
1667117f1b4Smrgvoid
1674a49301eSmrg_mesa_notifySwapBuffers(__GLcontext *ctx)
1687117f1b4Smrg{
1694a49301eSmrg   if (MESA_VERBOSE & VERBOSE_SWAPBUFFERS)
1704a49301eSmrg      _mesa_debug(ctx, "SwapBuffers\n");
1714a49301eSmrg   FLUSH_CURRENT( ctx, 0 );
1724a49301eSmrg   if (ctx->Driver.Flush) {
1734a49301eSmrg      ctx->Driver.Flush(ctx);
1744a49301eSmrg   }
1757117f1b4Smrg}
1767117f1b4Smrg
1777117f1b4Smrg
1787117f1b4Smrg/**********************************************************************/
1797117f1b4Smrg/** \name GL Visual allocation/destruction                            */
1807117f1b4Smrg/**********************************************************************/
1817117f1b4Smrg/*@{*/
1827117f1b4Smrg
1837117f1b4Smrg/**
1847117f1b4Smrg * Allocates a GLvisual structure and initializes it via
1857117f1b4Smrg * _mesa_initialize_visual().
1867117f1b4Smrg *
1877117f1b4Smrg * \param dbFlag double buffering
1887117f1b4Smrg * \param stereoFlag stereo buffer
1897117f1b4Smrg * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
1907117f1b4Smrg * is acceptable but the actual depth type will be GLushort or GLuint as
1917117f1b4Smrg * needed.
1927117f1b4Smrg * \param stencilBits requested minimum bits per stencil buffer value
1937117f1b4Smrg * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
1947117f1b4Smrg * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
1957117f1b4Smrg * \param redBits number of bits per color component in frame buffer for RGB(A)
1967117f1b4Smrg * mode.  We always use 8 in core Mesa though.
1977117f1b4Smrg * \param greenBits same as above.
1987117f1b4Smrg * \param blueBits same as above.
1997117f1b4Smrg * \param alphaBits same as above.
2007117f1b4Smrg * \param numSamples not really used.
2017117f1b4Smrg *
2027117f1b4Smrg * \return pointer to new GLvisual or NULL if requested parameters can't be
2037117f1b4Smrg * met.
2047117f1b4Smrg *
2057117f1b4Smrg * \note Need to add params for level and numAuxBuffers (at least)
2067117f1b4Smrg */
2077117f1b4SmrgGLvisual *
208cdc920a0Smrg_mesa_create_visual( GLboolean dbFlag,
2097117f1b4Smrg                     GLboolean stereoFlag,
2107117f1b4Smrg                     GLint redBits,
2117117f1b4Smrg                     GLint greenBits,
2127117f1b4Smrg                     GLint blueBits,
2137117f1b4Smrg                     GLint alphaBits,
2147117f1b4Smrg                     GLint depthBits,
2157117f1b4Smrg                     GLint stencilBits,
2167117f1b4Smrg                     GLint accumRedBits,
2177117f1b4Smrg                     GLint accumGreenBits,
2187117f1b4Smrg                     GLint accumBlueBits,
2197117f1b4Smrg                     GLint accumAlphaBits,
2207117f1b4Smrg                     GLint numSamples )
2217117f1b4Smrg{
222cdc920a0Smrg   GLvisual *vis = (GLvisual *) calloc(1, sizeof(GLvisual));
2237117f1b4Smrg   if (vis) {
224cdc920a0Smrg      if (!_mesa_initialize_visual(vis, dbFlag, stereoFlag,
2257117f1b4Smrg                                   redBits, greenBits, blueBits, alphaBits,
226cdc920a0Smrg                                   depthBits, stencilBits,
2277117f1b4Smrg                                   accumRedBits, accumGreenBits,
2287117f1b4Smrg                                   accumBlueBits, accumAlphaBits,
2297117f1b4Smrg                                   numSamples)) {
230cdc920a0Smrg         free(vis);
2317117f1b4Smrg         return NULL;
2327117f1b4Smrg      }
2337117f1b4Smrg   }
2347117f1b4Smrg   return vis;
2357117f1b4Smrg}
2367117f1b4Smrg
2377117f1b4Smrg/**
2387117f1b4Smrg * Makes some sanity checks and fills in the fields of the
2397117f1b4Smrg * GLvisual object with the given parameters.  If the caller needs
2407117f1b4Smrg * to set additional fields, he should just probably init the whole GLvisual
2417117f1b4Smrg * object himself.
2427117f1b4Smrg * \return GL_TRUE on success, or GL_FALSE on failure.
2437117f1b4Smrg *
2447117f1b4Smrg * \sa _mesa_create_visual() above for the parameter description.
2457117f1b4Smrg */
2467117f1b4SmrgGLboolean
2477117f1b4Smrg_mesa_initialize_visual( GLvisual *vis,
2487117f1b4Smrg                         GLboolean dbFlag,
2497117f1b4Smrg                         GLboolean stereoFlag,
2507117f1b4Smrg                         GLint redBits,
2517117f1b4Smrg                         GLint greenBits,
2527117f1b4Smrg                         GLint blueBits,
2537117f1b4Smrg                         GLint alphaBits,
2547117f1b4Smrg                         GLint depthBits,
2557117f1b4Smrg                         GLint stencilBits,
2567117f1b4Smrg                         GLint accumRedBits,
2577117f1b4Smrg                         GLint accumGreenBits,
2587117f1b4Smrg                         GLint accumBlueBits,
2597117f1b4Smrg                         GLint accumAlphaBits,
2607117f1b4Smrg                         GLint numSamples )
2617117f1b4Smrg{
2627117f1b4Smrg   assert(vis);
2637117f1b4Smrg
2647117f1b4Smrg   if (depthBits < 0 || depthBits > 32) {
2657117f1b4Smrg      return GL_FALSE;
2667117f1b4Smrg   }
2677117f1b4Smrg   if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
2687117f1b4Smrg      return GL_FALSE;
2697117f1b4Smrg   }
2707117f1b4Smrg   assert(accumRedBits >= 0);
2717117f1b4Smrg   assert(accumGreenBits >= 0);
2727117f1b4Smrg   assert(accumBlueBits >= 0);
2737117f1b4Smrg   assert(accumAlphaBits >= 0);
2747117f1b4Smrg
275cdc920a0Smrg   vis->rgbMode          = GL_TRUE;
2767117f1b4Smrg   vis->doubleBufferMode = dbFlag;
2777117f1b4Smrg   vis->stereoMode       = stereoFlag;
2787117f1b4Smrg
2797117f1b4Smrg   vis->redBits          = redBits;
2807117f1b4Smrg   vis->greenBits        = greenBits;
2817117f1b4Smrg   vis->blueBits         = blueBits;
2827117f1b4Smrg   vis->alphaBits        = alphaBits;
2837117f1b4Smrg   vis->rgbBits          = redBits + greenBits + blueBits;
2847117f1b4Smrg
285cdc920a0Smrg   vis->indexBits      = 0;
2867117f1b4Smrg   vis->depthBits      = depthBits;
2877117f1b4Smrg   vis->stencilBits    = stencilBits;
2887117f1b4Smrg
2897117f1b4Smrg   vis->accumRedBits   = accumRedBits;
2907117f1b4Smrg   vis->accumGreenBits = accumGreenBits;
2917117f1b4Smrg   vis->accumBlueBits  = accumBlueBits;
2927117f1b4Smrg   vis->accumAlphaBits = accumAlphaBits;
2937117f1b4Smrg
2947117f1b4Smrg   vis->haveAccumBuffer   = accumRedBits > 0;
2957117f1b4Smrg   vis->haveDepthBuffer   = depthBits > 0;
2967117f1b4Smrg   vis->haveStencilBuffer = stencilBits > 0;
2977117f1b4Smrg
2987117f1b4Smrg   vis->numAuxBuffers = 0;
2997117f1b4Smrg   vis->level = 0;
3007117f1b4Smrg   vis->pixmapMode = 0;
3017117f1b4Smrg   vis->sampleBuffers = numSamples > 0 ? 1 : 0;
3027117f1b4Smrg   vis->samples = numSamples;
3037117f1b4Smrg
3047117f1b4Smrg   return GL_TRUE;
3057117f1b4Smrg}
3067117f1b4Smrg
3077117f1b4Smrg
3087117f1b4Smrg/**
3097117f1b4Smrg * Destroy a visual and free its memory.
3107117f1b4Smrg *
3117117f1b4Smrg * \param vis visual.
3127117f1b4Smrg *
3137117f1b4Smrg * Frees the visual structure.
3147117f1b4Smrg */
3157117f1b4Smrgvoid
3167117f1b4Smrg_mesa_destroy_visual( GLvisual *vis )
3177117f1b4Smrg{
318cdc920a0Smrg   free(vis);
3197117f1b4Smrg}
3207117f1b4Smrg
3217117f1b4Smrg/*@}*/
3227117f1b4Smrg
3237117f1b4Smrg
3247117f1b4Smrg/**********************************************************************/
3257117f1b4Smrg/** \name Context allocation, initialization, destroying
3267117f1b4Smrg *
3277117f1b4Smrg * The purpose of the most initialization functions here is to provide the
3287117f1b4Smrg * default state values according to the OpenGL specification.
3297117f1b4Smrg */
3307117f1b4Smrg/**********************************************************************/
3317117f1b4Smrg/*@{*/
3327117f1b4Smrg
3334a49301eSmrg
3344a49301eSmrg/**
3354a49301eSmrg * This is lame.  gdb only seems to recognize enum types that are
3364a49301eSmrg * actually used somewhere.  We want to be able to print/use enum
3374a49301eSmrg * values such as TEXTURE_2D_INDEX in gdb.  But we don't actually use
3384a49301eSmrg * the gl_texture_index type anywhere.  Thus, this lame function.
3394a49301eSmrg */
3404a49301eSmrgstatic void
3414a49301eSmrgdummy_enum_func(void)
3424a49301eSmrg{
3434a49301eSmrg   gl_buffer_index bi;
3444a49301eSmrg   gl_colortable_index ci;
3454a49301eSmrg   gl_face_index fi;
3464a49301eSmrg   gl_frag_attrib fa;
3474a49301eSmrg   gl_frag_result fr;
3484a49301eSmrg   gl_texture_index ti;
3494a49301eSmrg   gl_vert_attrib va;
3504a49301eSmrg   gl_vert_result vr;
3514a49301eSmrg
3524a49301eSmrg   (void) bi;
3534a49301eSmrg   (void) ci;
3544a49301eSmrg   (void) fi;
3554a49301eSmrg   (void) fa;
3564a49301eSmrg   (void) fr;
3574a49301eSmrg   (void) ti;
3584a49301eSmrg   (void) va;
3594a49301eSmrg   (void) vr;
3604a49301eSmrg}
3614a49301eSmrg
3624a49301eSmrg
3637117f1b4Smrg/**
3647117f1b4Smrg * One-time initialization mutex lock.
3657117f1b4Smrg *
3667117f1b4Smrg * \sa Used by one_time_init().
3677117f1b4Smrg */
3687117f1b4Smrg_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
3697117f1b4Smrg
3707117f1b4Smrg/**
3717117f1b4Smrg * Calls all the various one-time-init functions in Mesa.
3727117f1b4Smrg *
3737117f1b4Smrg * While holding a global mutex lock, calls several initialization functions,
3747117f1b4Smrg * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
3757117f1b4Smrg * defined.
3767117f1b4Smrg *
3777117f1b4Smrg * \sa _math_init().
3787117f1b4Smrg */
3797117f1b4Smrgstatic void
3807117f1b4Smrgone_time_init( GLcontext *ctx )
3817117f1b4Smrg{
3827117f1b4Smrg   static GLboolean alreadyCalled = GL_FALSE;
3837117f1b4Smrg   (void) ctx;
3847117f1b4Smrg   _glthread_LOCK_MUTEX(OneTimeLock);
3857117f1b4Smrg   if (!alreadyCalled) {
3867117f1b4Smrg      GLuint i;
3877117f1b4Smrg
3887117f1b4Smrg      /* do some implementation tests */
3897117f1b4Smrg      assert( sizeof(GLbyte) == 1 );
3907117f1b4Smrg      assert( sizeof(GLubyte) == 1 );
3917117f1b4Smrg      assert( sizeof(GLshort) == 2 );
3927117f1b4Smrg      assert( sizeof(GLushort) == 2 );
3937117f1b4Smrg      assert( sizeof(GLint) == 4 );
3947117f1b4Smrg      assert( sizeof(GLuint) == 4 );
3957117f1b4Smrg
3964a49301eSmrg      _mesa_get_cpu_features();
3977117f1b4Smrg
3984a49301eSmrg      _mesa_init_remap_table();
3994a49301eSmrg
4004a49301eSmrg      _mesa_init_sqrt_table();
4017117f1b4Smrg
4027117f1b4Smrg      for (i = 0; i < 256; i++) {
4037117f1b4Smrg         _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
4047117f1b4Smrg      }
4057117f1b4Smrg
4067117f1b4Smrg#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
4077117f1b4Smrg      _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
4087117f1b4Smrg                  MESA_VERSION_STRING, __DATE__, __TIME__);
4097117f1b4Smrg#endif
4107117f1b4Smrg
4117117f1b4Smrg      alreadyCalled = GL_TRUE;
4127117f1b4Smrg   }
4137117f1b4Smrg   _glthread_UNLOCK_MUTEX(OneTimeLock);
4147117f1b4Smrg
4154a49301eSmrg   dummy_enum_func();
4167117f1b4Smrg}
4177117f1b4Smrg
4187117f1b4Smrg
4197117f1b4Smrg/**
4207117f1b4Smrg * Initialize fields of gl_current_attrib (aka ctx->Current.*)
4217117f1b4Smrg */
4227117f1b4Smrgstatic void
4237117f1b4Smrg_mesa_init_current(GLcontext *ctx)
4247117f1b4Smrg{
4257117f1b4Smrg   GLuint i;
4267117f1b4Smrg
4277117f1b4Smrg   /* Init all to (0,0,0,1) */
4284a49301eSmrg   for (i = 0; i < Elements(ctx->Current.Attrib); i++) {
4297117f1b4Smrg      ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
4307117f1b4Smrg   }
4317117f1b4Smrg
4327117f1b4Smrg   /* redo special cases: */
4337117f1b4Smrg   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
4347117f1b4Smrg   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
4357117f1b4Smrg   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
4367117f1b4Smrg   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
4377117f1b4Smrg   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
4387117f1b4Smrg   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
4397117f1b4Smrg}
4407117f1b4Smrg
4417117f1b4Smrg
4427117f1b4Smrg/**
4434a49301eSmrg * Init vertex/fragment program limits.
4444a49301eSmrg * Important: drivers should override these with actual limits.
4457117f1b4Smrg */
4467117f1b4Smrgstatic void
4474a49301eSmrginit_program_limits(GLenum type, struct gl_program_constants *prog)
4487117f1b4Smrg{
4494a49301eSmrg   prog->MaxInstructions = MAX_PROGRAM_INSTRUCTIONS;
4504a49301eSmrg   prog->MaxAluInstructions = MAX_PROGRAM_INSTRUCTIONS;
4514a49301eSmrg   prog->MaxTexInstructions = MAX_PROGRAM_INSTRUCTIONS;
4524a49301eSmrg   prog->MaxTexIndirections = MAX_PROGRAM_INSTRUCTIONS;
4534a49301eSmrg   prog->MaxTemps = MAX_PROGRAM_TEMPS;
4544a49301eSmrg   prog->MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
4554a49301eSmrg   prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
4564a49301eSmrg   prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
4574a49301eSmrg
4584a49301eSmrg   if (type == GL_VERTEX_PROGRAM_ARB) {
4594a49301eSmrg      prog->MaxParameters = MAX_VERTEX_PROGRAM_PARAMS;
4604a49301eSmrg      prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
4614a49301eSmrg      prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
4624a49301eSmrg   }
4634a49301eSmrg   else {
4644a49301eSmrg      prog->MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
4654a49301eSmrg      prog->MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
4664a49301eSmrg      prog->MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
4674a49301eSmrg   }
4684a49301eSmrg
4694a49301eSmrg   /* Set the native limits to zero.  This implies that there is no native
4704a49301eSmrg    * support for shaders.  Let the drivers fill in the actual values.
4714a49301eSmrg    */
4724a49301eSmrg   prog->MaxNativeInstructions = 0;
4734a49301eSmrg   prog->MaxNativeAluInstructions = 0;
4744a49301eSmrg   prog->MaxNativeTexInstructions = 0;
4754a49301eSmrg   prog->MaxNativeTexIndirections = 0;
4764a49301eSmrg   prog->MaxNativeAttribs = 0;
4774a49301eSmrg   prog->MaxNativeTemps = 0;
4784a49301eSmrg   prog->MaxNativeAddressRegs = 0;
4794a49301eSmrg   prog->MaxNativeParameters = 0;
4807117f1b4Smrg}
4817117f1b4Smrg
4827117f1b4Smrg
4837117f1b4Smrg/**
4847117f1b4Smrg * Initialize fields of gl_constants (aka ctx->Const.*).
4857117f1b4Smrg * Use defaults from config.h.  The device drivers will often override
4867117f1b4Smrg * some of these values (such as number of texture units).
4877117f1b4Smrg */
4887117f1b4Smrgstatic void
4897117f1b4Smrg_mesa_init_constants(GLcontext *ctx)
4907117f1b4Smrg{
4917117f1b4Smrg   assert(ctx);
4927117f1b4Smrg
4937117f1b4Smrg   /* Constants, may be overriden (usually only reduced) by device drivers */
4947117f1b4Smrg   ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
4957117f1b4Smrg   ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
4967117f1b4Smrg   ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
4977117f1b4Smrg   ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
498c1f859d4Smrg   ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
4997117f1b4Smrg   ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
5007117f1b4Smrg   ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
5017117f1b4Smrg   ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
5027117f1b4Smrg                                     ctx->Const.MaxTextureImageUnits);
5037117f1b4Smrg   ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
5047117f1b4Smrg   ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
5057117f1b4Smrg   ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
5067117f1b4Smrg   ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
5077117f1b4Smrg   ctx->Const.MinPointSize = MIN_POINT_SIZE;
5087117f1b4Smrg   ctx->Const.MaxPointSize = MAX_POINT_SIZE;
5097117f1b4Smrg   ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
5107117f1b4Smrg   ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
5117117f1b4Smrg   ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
5127117f1b4Smrg   ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
5137117f1b4Smrg   ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
5147117f1b4Smrg   ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
5157117f1b4Smrg   ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
5167117f1b4Smrg   ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
5177117f1b4Smrg   ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
5187117f1b4Smrg   ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
5197117f1b4Smrg   ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
5207117f1b4Smrg   ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
5217117f1b4Smrg   ctx->Const.MaxLights = MAX_LIGHTS;
5227117f1b4Smrg   ctx->Const.MaxShininess = 128.0;
5237117f1b4Smrg   ctx->Const.MaxSpotExponent = 128.0;
5247117f1b4Smrg   ctx->Const.MaxViewportWidth = MAX_WIDTH;
5257117f1b4Smrg   ctx->Const.MaxViewportHeight = MAX_HEIGHT;
5267117f1b4Smrg#if FEATURE_ARB_vertex_program
5274a49301eSmrg   init_program_limits(GL_VERTEX_PROGRAM_ARB, &ctx->Const.VertexProgram);
5287117f1b4Smrg#endif
5297117f1b4Smrg#if FEATURE_ARB_fragment_program
5304a49301eSmrg   init_program_limits(GL_FRAGMENT_PROGRAM_ARB, &ctx->Const.FragmentProgram);
5317117f1b4Smrg#endif
5327117f1b4Smrg   ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
5337117f1b4Smrg   ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
5347117f1b4Smrg
5357117f1b4Smrg   /* CheckArrayBounds is overriden by drivers/x11 for X server */
5367117f1b4Smrg   ctx->Const.CheckArrayBounds = GL_FALSE;
5377117f1b4Smrg
5387117f1b4Smrg   /* GL_ARB_draw_buffers */
5397117f1b4Smrg   ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
5407117f1b4Smrg
5417117f1b4Smrg#if FEATURE_EXT_framebuffer_object
5427117f1b4Smrg   ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
5437117f1b4Smrg   ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
5447117f1b4Smrg#endif
5457117f1b4Smrg
5467117f1b4Smrg#if FEATURE_ARB_vertex_shader
5477117f1b4Smrg   ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
548cdc920a0Smrg   ctx->Const.MaxCombinedTextureImageUnits = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
5497117f1b4Smrg   ctx->Const.MaxVarying = MAX_VARYING;
5507117f1b4Smrg#endif
5517117f1b4Smrg
5524a49301eSmrg   /* GL_ARB_framebuffer_object */
5534a49301eSmrg   ctx->Const.MaxSamples = 0;
5544a49301eSmrg
5554a49301eSmrg   /* GL_ARB_sync */
5564a49301eSmrg   ctx->Const.MaxServerWaitTimeout = (GLuint64) ~0;
5574a49301eSmrg
5584a49301eSmrg   /* GL_ATI_envmap_bumpmap */
5594a49301eSmrg   ctx->Const.SupportedBumpUnits = SUPPORTED_ATI_BUMP_UNITS;
5604a49301eSmrg
5614a49301eSmrg   /* GL_EXT_provoking_vertex */
5624a49301eSmrg   ctx->Const.QuadsFollowProvokingVertexConvention = GL_TRUE;
5637117f1b4Smrg}
5647117f1b4Smrg
5657117f1b4Smrg
5667117f1b4Smrg/**
5677117f1b4Smrg * Do some sanity checks on the limits/constants for the given context.
5687117f1b4Smrg * Only called the first time a context is bound.
5697117f1b4Smrg */
5707117f1b4Smrgstatic void
5717117f1b4Smrgcheck_context_limits(GLcontext *ctx)
5727117f1b4Smrg{
573cdc920a0Smrg   /* check that we don't exceed the size of various bitfields */
574cdc920a0Smrg   assert(VERT_RESULT_MAX <=
575cdc920a0Smrg	  (8 * sizeof(ctx->VertexProgram._Current->Base.OutputsWritten)));
576cdc920a0Smrg   assert(FRAG_ATTRIB_MAX <=
577cdc920a0Smrg	  (8 * sizeof(ctx->FragmentProgram._Current->Base.InputsRead)));
578cdc920a0Smrg
579cdc920a0Smrg   assert(MAX_COMBINED_TEXTURE_IMAGE_UNITS <= 8 * sizeof(GLbitfield));
580cdc920a0Smrg
581cdc920a0Smrg   /* shader-related checks */
582cdc920a0Smrg   assert(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
583cdc920a0Smrg   assert(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
584cdc920a0Smrg
585cdc920a0Smrg   assert(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
586cdc920a0Smrg   assert(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
587cdc920a0Smrg   assert(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
588cdc920a0Smrg   assert(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
589cdc920a0Smrg
590cdc920a0Smrg   /* Texture unit checks */
591cdc920a0Smrg   assert(ctx->Const.MaxTextureImageUnits > 0);
5927117f1b4Smrg   assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
593cdc920a0Smrg   assert(ctx->Const.MaxTextureCoordUnits > 0);
5947117f1b4Smrg   assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
595cdc920a0Smrg   assert(ctx->Const.MaxTextureUnits > 0);
5967117f1b4Smrg   assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
5977117f1b4Smrg   assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
598cdc920a0Smrg   assert(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
599cdc920a0Smrg                                             ctx->Const.MaxTextureCoordUnits));
600cdc920a0Smrg   assert(ctx->Const.MaxCombinedTextureImageUnits > 0);
601cdc920a0Smrg   assert(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
602cdc920a0Smrg   assert(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
603c1f859d4Smrg   /* number of coord units cannot be greater than number of image units */
604c1f859d4Smrg   assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
605c1f859d4Smrg
606cdc920a0Smrg
607cdc920a0Smrg   /* Texture size checks */
6084a49301eSmrg   assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
6094a49301eSmrg   assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
6104a49301eSmrg   assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
6114a49301eSmrg   assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
6127117f1b4Smrg
6137117f1b4Smrg   /* make sure largest texture image is <= MAX_WIDTH in size */
6144a49301eSmrg   assert((1 << (ctx->Const.MaxTextureLevels - 1)) <= MAX_WIDTH);
6154a49301eSmrg   assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= MAX_WIDTH);
6164a49301eSmrg   assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= MAX_WIDTH);
6174a49301eSmrg
618cdc920a0Smrg   /* Texture level checks */
619cdc920a0Smrg   assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
620cdc920a0Smrg   assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
621cdc920a0Smrg
622cdc920a0Smrg   /* Max texture size should be <= max viewport size (render to texture) */
623cdc920a0Smrg   assert((1 << (MAX_TEXTURE_LEVELS - 1)) <= MAX_WIDTH);
624cdc920a0Smrg
6254a49301eSmrg   assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
6264a49301eSmrg   assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
6277117f1b4Smrg
6287117f1b4Smrg   assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
6297117f1b4Smrg
6307117f1b4Smrg   /* XXX probably add more tests */
6317117f1b4Smrg}
6327117f1b4Smrg
6337117f1b4Smrg
6347117f1b4Smrg/**
6357117f1b4Smrg * Initialize the attribute groups in a GL context.
6367117f1b4Smrg *
6377117f1b4Smrg * \param ctx GL context.
6387117f1b4Smrg *
6397117f1b4Smrg * Initializes all the attributes, calling the respective <tt>init*</tt>
6407117f1b4Smrg * functions for the more complex data structures.
6417117f1b4Smrg */
6427117f1b4Smrgstatic GLboolean
6437117f1b4Smrginit_attrib_groups(GLcontext *ctx)
6447117f1b4Smrg{
6457117f1b4Smrg   assert(ctx);
6467117f1b4Smrg
6477117f1b4Smrg   /* Constants */
6487117f1b4Smrg   _mesa_init_constants( ctx );
6497117f1b4Smrg
6507117f1b4Smrg   /* Extensions */
6517117f1b4Smrg   _mesa_init_extensions( ctx );
6527117f1b4Smrg
6537117f1b4Smrg   /* Attribute Groups */
6547117f1b4Smrg   _mesa_init_accum( ctx );
6557117f1b4Smrg   _mesa_init_attrib( ctx );
6567117f1b4Smrg   _mesa_init_buffer_objects( ctx );
6577117f1b4Smrg   _mesa_init_color( ctx );
6587117f1b4Smrg   _mesa_init_colortables( ctx );
6597117f1b4Smrg   _mesa_init_current( ctx );
6607117f1b4Smrg   _mesa_init_depth( ctx );
6617117f1b4Smrg   _mesa_init_debug( ctx );
6627117f1b4Smrg   _mesa_init_display_list( ctx );
6637117f1b4Smrg   _mesa_init_eval( ctx );
664c1f859d4Smrg   _mesa_init_fbobjects( ctx );
6657117f1b4Smrg   _mesa_init_feedback( ctx );
6667117f1b4Smrg   _mesa_init_fog( ctx );
6677117f1b4Smrg   _mesa_init_histogram( ctx );
6687117f1b4Smrg   _mesa_init_hint( ctx );
6697117f1b4Smrg   _mesa_init_line( ctx );
6707117f1b4Smrg   _mesa_init_lighting( ctx );
6717117f1b4Smrg   _mesa_init_matrix( ctx );
6727117f1b4Smrg   _mesa_init_multisample( ctx );
6737117f1b4Smrg   _mesa_init_pixel( ctx );
674c1f859d4Smrg   _mesa_init_pixelstore( ctx );
6757117f1b4Smrg   _mesa_init_point( ctx );
6767117f1b4Smrg   _mesa_init_polygon( ctx );
6777117f1b4Smrg   _mesa_init_program( ctx );
6784a49301eSmrg   _mesa_init_queryobj( ctx );
6794a49301eSmrg#if FEATURE_ARB_sync
6804a49301eSmrg   _mesa_init_sync( ctx );
681c1f859d4Smrg#endif
6827117f1b4Smrg   _mesa_init_rastpos( ctx );
6837117f1b4Smrg   _mesa_init_scissor( ctx );
6847117f1b4Smrg   _mesa_init_shader_state( ctx );
6857117f1b4Smrg   _mesa_init_stencil( ctx );
6867117f1b4Smrg   _mesa_init_transform( ctx );
6877117f1b4Smrg   _mesa_init_varray( ctx );
6887117f1b4Smrg   _mesa_init_viewport( ctx );
6897117f1b4Smrg
6907117f1b4Smrg   if (!_mesa_init_texture( ctx ))
6917117f1b4Smrg      return GL_FALSE;
6927117f1b4Smrg
6937117f1b4Smrg   _mesa_init_texture_s3tc( ctx );
6947117f1b4Smrg
6957117f1b4Smrg   /* Miscellaneous */
6967117f1b4Smrg   ctx->NewState = _NEW_ALL;
6977117f1b4Smrg   ctx->ErrorValue = (GLenum) GL_NO_ERROR;
6984a49301eSmrg   ctx->varying_vp_inputs = ~0;
6997117f1b4Smrg
7007117f1b4Smrg   return GL_TRUE;
7017117f1b4Smrg}
7027117f1b4Smrg
7037117f1b4Smrg
704c1f859d4Smrg/**
705c1f859d4Smrg * Update default objects in a GL context with respect to shared state.
706c1f859d4Smrg *
707c1f859d4Smrg * \param ctx GL context.
708c1f859d4Smrg *
709c1f859d4Smrg * Removes references to old default objects, (texture objects, program
710c1f859d4Smrg * objects, etc.) and changes to reference those from the current shared
711c1f859d4Smrg * state.
712c1f859d4Smrg */
713c1f859d4Smrgstatic GLboolean
714c1f859d4Smrgupdate_default_objects(GLcontext *ctx)
715c1f859d4Smrg{
716c1f859d4Smrg   assert(ctx);
717c1f859d4Smrg
718c1f859d4Smrg   _mesa_update_default_objects_program(ctx);
719c1f859d4Smrg   _mesa_update_default_objects_texture(ctx);
720c1f859d4Smrg   _mesa_update_default_objects_buffer_objects(ctx);
721c1f859d4Smrg
722c1f859d4Smrg   return GL_TRUE;
723c1f859d4Smrg}
724c1f859d4Smrg
725c1f859d4Smrg
7267117f1b4Smrg/**
7277117f1b4Smrg * This is the default function we plug into all dispatch table slots
7287117f1b4Smrg * This helps prevents a segfault when someone calls a GL function without
7297117f1b4Smrg * first checking if the extension's supported.
7307117f1b4Smrg */
7317117f1b4Smrgstatic int
7327117f1b4Smrggeneric_nop(void)
7337117f1b4Smrg{
734c1f859d4Smrg   _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
7357117f1b4Smrg   return 0;
7367117f1b4Smrg}
7377117f1b4Smrg
7387117f1b4Smrg
7397117f1b4Smrg/**
7407117f1b4Smrg * Allocate and initialize a new dispatch table.
7417117f1b4Smrg */
7427117f1b4Smrgstatic struct _glapi_table *
7437117f1b4Smrgalloc_dispatch_table(void)
7447117f1b4Smrg{
7457117f1b4Smrg   /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
7467117f1b4Smrg    * In practice, this'll be the same for stand-alone Mesa.  But for DRI
7477117f1b4Smrg    * Mesa we do this to accomodate different versions of libGL and various
7487117f1b4Smrg    * DRI drivers.
7497117f1b4Smrg    */
7507117f1b4Smrg   GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
7517117f1b4Smrg                           sizeof(struct _glapi_table) / sizeof(_glapi_proc));
7527117f1b4Smrg   struct _glapi_table *table =
753cdc920a0Smrg      (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
7547117f1b4Smrg   if (table) {
7557117f1b4Smrg      _glapi_proc *entry = (_glapi_proc *) table;
7567117f1b4Smrg      GLint i;
7577117f1b4Smrg      for (i = 0; i < numEntries; i++) {
7587117f1b4Smrg         entry[i] = (_glapi_proc) generic_nop;
7597117f1b4Smrg      }
7607117f1b4Smrg   }
7617117f1b4Smrg   return table;
7627117f1b4Smrg}
7637117f1b4Smrg
7647117f1b4Smrg
7657117f1b4Smrg/**
7667117f1b4Smrg * Initialize a GLcontext struct (rendering context).
7677117f1b4Smrg *
7687117f1b4Smrg * This includes allocating all the other structs and arrays which hang off of
7697117f1b4Smrg * the context by pointers.
7707117f1b4Smrg * Note that the driver needs to pass in its dd_function_table here since
7717117f1b4Smrg * we need to at least call driverFunctions->NewTextureObject to create the
7727117f1b4Smrg * default texture objects.
7737117f1b4Smrg *
7747117f1b4Smrg * Called by _mesa_create_context().
7757117f1b4Smrg *
7767117f1b4Smrg * Performs the imports and exports callback tables initialization, and
7777117f1b4Smrg * miscellaneous one-time initializations. If no shared context is supplied one
7787117f1b4Smrg * is allocated, and increase its reference count.  Setups the GL API dispatch
7797117f1b4Smrg * tables.  Initialize the TNL module. Sets the maximum Z buffer depth.
7807117f1b4Smrg * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
7817117f1b4Smrg * for debug flags.
7827117f1b4Smrg *
7837117f1b4Smrg * \param ctx the context to initialize
7847117f1b4Smrg * \param visual describes the visual attributes for this context
7857117f1b4Smrg * \param share_list points to context to share textures, display lists,
7867117f1b4Smrg *        etc with, or NULL
7877117f1b4Smrg * \param driverFunctions table of device driver functions for this context
7887117f1b4Smrg *        to use
7897117f1b4Smrg * \param driverContext pointer to driver-specific context data
7907117f1b4Smrg */
7917117f1b4SmrgGLboolean
7927117f1b4Smrg_mesa_initialize_context(GLcontext *ctx,
7937117f1b4Smrg                         const GLvisual *visual,
7947117f1b4Smrg                         GLcontext *share_list,
7957117f1b4Smrg                         const struct dd_function_table *driverFunctions,
7967117f1b4Smrg                         void *driverContext)
7977117f1b4Smrg{
7984a49301eSmrg   struct gl_shared_state *shared;
7994a49301eSmrg
8004a49301eSmrg   /*ASSERT(driverContext);*/
8017117f1b4Smrg   assert(driverFunctions->NewTextureObject);
8027117f1b4Smrg   assert(driverFunctions->FreeTexImageData);
8037117f1b4Smrg
8047117f1b4Smrg   /* misc one-time initializations */
8057117f1b4Smrg   one_time_init(ctx);
8067117f1b4Smrg
8077117f1b4Smrg   ctx->Visual = *visual;
8087117f1b4Smrg   ctx->DrawBuffer = NULL;
8097117f1b4Smrg   ctx->ReadBuffer = NULL;
8107117f1b4Smrg   ctx->WinSysDrawBuffer = NULL;
8117117f1b4Smrg   ctx->WinSysReadBuffer = NULL;
8127117f1b4Smrg
8137117f1b4Smrg   /* Plug in driver functions and context pointer here.
8147117f1b4Smrg    * This is important because when we call alloc_shared_state() below
8157117f1b4Smrg    * we'll call ctx->Driver.NewTextureObject() to create the default
8167117f1b4Smrg    * textures.
8177117f1b4Smrg    */
8187117f1b4Smrg   ctx->Driver = *driverFunctions;
8197117f1b4Smrg   ctx->DriverCtx = driverContext;
8207117f1b4Smrg
8217117f1b4Smrg   if (share_list) {
8227117f1b4Smrg      /* share state with another context */
8234a49301eSmrg      shared = share_list->Shared;
8247117f1b4Smrg   }
8257117f1b4Smrg   else {
8267117f1b4Smrg      /* allocate new, unshared state */
8274a49301eSmrg      shared = _mesa_alloc_shared_state(ctx);
8284a49301eSmrg      if (!shared)
8297117f1b4Smrg         return GL_FALSE;
8307117f1b4Smrg   }
8314a49301eSmrg
8324a49301eSmrg   _glthread_LOCK_MUTEX(shared->Mutex);
8334a49301eSmrg   ctx->Shared = shared;
8344a49301eSmrg   shared->RefCount++;
8354a49301eSmrg   _glthread_UNLOCK_MUTEX(shared->Mutex);
8367117f1b4Smrg
8377117f1b4Smrg   if (!init_attrib_groups( ctx )) {
8384a49301eSmrg      _mesa_release_shared_state(ctx, ctx->Shared);
8397117f1b4Smrg      return GL_FALSE;
8407117f1b4Smrg   }
8417117f1b4Smrg
8427117f1b4Smrg   /* setup the API dispatch tables */
8437117f1b4Smrg   ctx->Exec = alloc_dispatch_table();
8447117f1b4Smrg   ctx->Save = alloc_dispatch_table();
8457117f1b4Smrg   if (!ctx->Exec || !ctx->Save) {
8464a49301eSmrg      _mesa_release_shared_state(ctx, ctx->Shared);
8477117f1b4Smrg      if (ctx->Exec)
848cdc920a0Smrg         free(ctx->Exec);
8494a49301eSmrg      return GL_FALSE;
8507117f1b4Smrg   }
851c1f859d4Smrg#if FEATURE_dispatch
8527117f1b4Smrg   _mesa_init_exec_table(ctx->Exec);
853c1f859d4Smrg#endif
8547117f1b4Smrg   ctx->CurrentDispatch = ctx->Exec;
8554a49301eSmrg
856c1f859d4Smrg#if FEATURE_dlist
8574a49301eSmrg   _mesa_init_save_table(ctx->Save);
8587117f1b4Smrg   _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
859c1f859d4Smrg#endif
8604a49301eSmrg
8617117f1b4Smrg   /* Neutral tnl module stuff */
8627117f1b4Smrg   _mesa_init_exec_vtxfmt( ctx );
8637117f1b4Smrg   ctx->TnlModule.Current = NULL;
8647117f1b4Smrg   ctx->TnlModule.SwapCount = 0;
8657117f1b4Smrg
8667117f1b4Smrg   ctx->FragmentProgram._MaintainTexEnvProgram
8677117f1b4Smrg      = (_mesa_getenv("MESA_TEX_PROG") != NULL);
8687117f1b4Smrg
8697117f1b4Smrg   ctx->VertexProgram._MaintainTnlProgram
8707117f1b4Smrg      = (_mesa_getenv("MESA_TNL_PROG") != NULL);
8717117f1b4Smrg   if (ctx->VertexProgram._MaintainTnlProgram) {
8727117f1b4Smrg      /* this is required... */
8737117f1b4Smrg      ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
8747117f1b4Smrg   }
8757117f1b4Smrg
876c1f859d4Smrg#ifdef FEATURE_extra_context_init
877c1f859d4Smrg   _mesa_initialize_context_extra(ctx);
878c1f859d4Smrg#endif
879c1f859d4Smrg
8807117f1b4Smrg   ctx->FirstTimeCurrent = GL_TRUE;
8817117f1b4Smrg
8827117f1b4Smrg   return GL_TRUE;
8837117f1b4Smrg}
8847117f1b4Smrg
8857117f1b4Smrg
8867117f1b4Smrg/**
8877117f1b4Smrg * Allocate and initialize a GLcontext structure.
8887117f1b4Smrg * Note that the driver needs to pass in its dd_function_table here since
8897117f1b4Smrg * we need to at least call driverFunctions->NewTextureObject to initialize
8907117f1b4Smrg * the rendering context.
8917117f1b4Smrg *
8927117f1b4Smrg * \param visual a GLvisual pointer (we copy the struct contents)
8937117f1b4Smrg * \param share_list another context to share display lists with or NULL
8947117f1b4Smrg * \param driverFunctions points to the dd_function_table into which the
8957117f1b4Smrg *        driver has plugged in all its special functions.
8964a49301eSmrg * \param driverContext points to the device driver's private context state
8977117f1b4Smrg *
8987117f1b4Smrg * \return pointer to a new __GLcontextRec or NULL if error.
8997117f1b4Smrg */
9007117f1b4SmrgGLcontext *
9017117f1b4Smrg_mesa_create_context(const GLvisual *visual,
9027117f1b4Smrg                     GLcontext *share_list,
9037117f1b4Smrg                     const struct dd_function_table *driverFunctions,
9047117f1b4Smrg                     void *driverContext)
9057117f1b4Smrg{
9067117f1b4Smrg   GLcontext *ctx;
9077117f1b4Smrg
9087117f1b4Smrg   ASSERT(visual);
9094a49301eSmrg   /*ASSERT(driverContext);*/
9107117f1b4Smrg
911cdc920a0Smrg   ctx = (GLcontext *) calloc(1, sizeof(GLcontext));
9127117f1b4Smrg   if (!ctx)
9137117f1b4Smrg      return NULL;
9147117f1b4Smrg
9157117f1b4Smrg   if (_mesa_initialize_context(ctx, visual, share_list,
9167117f1b4Smrg                                driverFunctions, driverContext)) {
9177117f1b4Smrg      return ctx;
9187117f1b4Smrg   }
9197117f1b4Smrg   else {
920cdc920a0Smrg      free(ctx);
9217117f1b4Smrg      return NULL;
9227117f1b4Smrg   }
9237117f1b4Smrg}
9247117f1b4Smrg
9257117f1b4Smrg
9267117f1b4Smrg/**
9277117f1b4Smrg * Free the data associated with the given context.
9287117f1b4Smrg *
9297117f1b4Smrg * But doesn't free the GLcontext struct itself.
9307117f1b4Smrg *
9317117f1b4Smrg * \sa _mesa_initialize_context() and init_attrib_groups().
9327117f1b4Smrg */
9337117f1b4Smrgvoid
9347117f1b4Smrg_mesa_free_context_data( GLcontext *ctx )
9357117f1b4Smrg{
9367117f1b4Smrg   if (!_mesa_get_current_context()){
9377117f1b4Smrg      /* No current context, but we may need one in order to delete
9387117f1b4Smrg       * texture objs, etc.  So temporarily bind the context now.
9397117f1b4Smrg       */
9407117f1b4Smrg      _mesa_make_current(ctx, NULL, NULL);
9417117f1b4Smrg   }
9427117f1b4Smrg
9437117f1b4Smrg   /* unreference WinSysDraw/Read buffers */
9444a49301eSmrg   _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL);
9454a49301eSmrg   _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL);
9464a49301eSmrg   _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL);
9474a49301eSmrg   _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL);
9487117f1b4Smrg
949c1f859d4Smrg   _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
950c1f859d4Smrg   _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
951c1f859d4Smrg   _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
952c1f859d4Smrg
953c1f859d4Smrg   _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
954c1f859d4Smrg   _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
955c1f859d4Smrg   _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
956c1f859d4Smrg
9577117f1b4Smrg   _mesa_free_attrib_data(ctx);
9584a49301eSmrg   _mesa_free_buffer_objects(ctx);
9597117f1b4Smrg   _mesa_free_lighting_data( ctx );
9607117f1b4Smrg   _mesa_free_eval_data( ctx );
9617117f1b4Smrg   _mesa_free_texture_data( ctx );
9627117f1b4Smrg   _mesa_free_matrix_data( ctx );
9637117f1b4Smrg   _mesa_free_viewport_data( ctx );
9647117f1b4Smrg   _mesa_free_colortables_data( ctx );
9657117f1b4Smrg   _mesa_free_program_data(ctx);
9667117f1b4Smrg   _mesa_free_shader_state(ctx);
9674a49301eSmrg   _mesa_free_queryobj_data(ctx);
9684a49301eSmrg#if FEATURE_ARB_sync
9694a49301eSmrg   _mesa_free_sync_data(ctx);
9704a49301eSmrg#endif
9714a49301eSmrg   _mesa_free_varray_data(ctx);
9724a49301eSmrg
9734a49301eSmrg   _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
9744a49301eSmrg
9754a49301eSmrg#if FEATURE_ARB_pixel_buffer_object
9764a49301eSmrg   _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj, NULL);
9774a49301eSmrg   _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj, NULL);
9784a49301eSmrg   _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj, NULL);
979c1f859d4Smrg#endif
9807117f1b4Smrg
9817117f1b4Smrg#if FEATURE_ARB_vertex_buffer_object
9824a49301eSmrg   _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
9834a49301eSmrg   _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, NULL);
9847117f1b4Smrg#endif
9857117f1b4Smrg
9867117f1b4Smrg   /* free dispatch tables */
987cdc920a0Smrg   free(ctx->Exec);
988cdc920a0Smrg   free(ctx->Save);
9897117f1b4Smrg
9907117f1b4Smrg   /* Shared context state (display lists, textures, etc) */
9914a49301eSmrg   _mesa_release_shared_state( ctx, ctx->Shared );
9924a49301eSmrg
9934a49301eSmrg   /* needs to be after freeing shared state */
9944a49301eSmrg   _mesa_free_display_list_data(ctx);
9957117f1b4Smrg
9967117f1b4Smrg   if (ctx->Extensions.String)
997cdc920a0Smrg      free((void *) ctx->Extensions.String);
998cdc920a0Smrg
999cdc920a0Smrg   if (ctx->VersionString)
1000cdc920a0Smrg      free(ctx->VersionString);
10017117f1b4Smrg
10027117f1b4Smrg   /* unbind the context if it's currently bound */
10037117f1b4Smrg   if (ctx == _mesa_get_current_context()) {
10047117f1b4Smrg      _mesa_make_current(NULL, NULL, NULL);
10057117f1b4Smrg   }
10067117f1b4Smrg}
10077117f1b4Smrg
10087117f1b4Smrg
10097117f1b4Smrg/**
10107117f1b4Smrg * Destroy a GLcontext structure.
10117117f1b4Smrg *
10127117f1b4Smrg * \param ctx GL context.
10137117f1b4Smrg *
10147117f1b4Smrg * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
10157117f1b4Smrg */
10167117f1b4Smrgvoid
10177117f1b4Smrg_mesa_destroy_context( GLcontext *ctx )
10187117f1b4Smrg{
10197117f1b4Smrg   if (ctx) {
10207117f1b4Smrg      _mesa_free_context_data(ctx);
1021cdc920a0Smrg      free( (void *) ctx );
10227117f1b4Smrg   }
10237117f1b4Smrg}
10247117f1b4Smrg
10257117f1b4Smrg
10267117f1b4Smrg#if _HAVE_FULL_GL
10277117f1b4Smrg/**
10287117f1b4Smrg * Copy attribute groups from one context to another.
10297117f1b4Smrg *
10307117f1b4Smrg * \param src source context
10317117f1b4Smrg * \param dst destination context
10327117f1b4Smrg * \param mask bitwise OR of GL_*_BIT flags
10337117f1b4Smrg *
10347117f1b4Smrg * According to the bits specified in \p mask, copies the corresponding
10357117f1b4Smrg * attributes from \p src into \p dst.  For many of the attributes a simple \c
10367117f1b4Smrg * memcpy is not enough due to the existence of internal pointers in their data
10377117f1b4Smrg * structures.
10387117f1b4Smrg */
10397117f1b4Smrgvoid
10407117f1b4Smrg_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
10417117f1b4Smrg{
10427117f1b4Smrg   if (mask & GL_ACCUM_BUFFER_BIT) {
10437117f1b4Smrg      /* OK to memcpy */
10447117f1b4Smrg      dst->Accum = src->Accum;
10457117f1b4Smrg   }
10467117f1b4Smrg   if (mask & GL_COLOR_BUFFER_BIT) {
10477117f1b4Smrg      /* OK to memcpy */
10487117f1b4Smrg      dst->Color = src->Color;
10497117f1b4Smrg   }
10507117f1b4Smrg   if (mask & GL_CURRENT_BIT) {
10517117f1b4Smrg      /* OK to memcpy */
10527117f1b4Smrg      dst->Current = src->Current;
10537117f1b4Smrg   }
10547117f1b4Smrg   if (mask & GL_DEPTH_BUFFER_BIT) {
10557117f1b4Smrg      /* OK to memcpy */
10567117f1b4Smrg      dst->Depth = src->Depth;
10577117f1b4Smrg   }
10587117f1b4Smrg   if (mask & GL_ENABLE_BIT) {
10597117f1b4Smrg      /* no op */
10607117f1b4Smrg   }
10617117f1b4Smrg   if (mask & GL_EVAL_BIT) {
10627117f1b4Smrg      /* OK to memcpy */
10637117f1b4Smrg      dst->Eval = src->Eval;
10647117f1b4Smrg   }
10657117f1b4Smrg   if (mask & GL_FOG_BIT) {
10667117f1b4Smrg      /* OK to memcpy */
10677117f1b4Smrg      dst->Fog = src->Fog;
10687117f1b4Smrg   }
10697117f1b4Smrg   if (mask & GL_HINT_BIT) {
10707117f1b4Smrg      /* OK to memcpy */
10717117f1b4Smrg      dst->Hint = src->Hint;
10727117f1b4Smrg   }
10737117f1b4Smrg   if (mask & GL_LIGHTING_BIT) {
10747117f1b4Smrg      GLuint i;
10757117f1b4Smrg      /* begin with memcpy */
10767117f1b4Smrg      dst->Light = src->Light;
10777117f1b4Smrg      /* fixup linked lists to prevent pointer insanity */
10787117f1b4Smrg      make_empty_list( &(dst->Light.EnabledList) );
10797117f1b4Smrg      for (i = 0; i < MAX_LIGHTS; i++) {
10807117f1b4Smrg         if (dst->Light.Light[i].Enabled) {
10817117f1b4Smrg            insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
10827117f1b4Smrg         }
10837117f1b4Smrg      }
10847117f1b4Smrg   }
10857117f1b4Smrg   if (mask & GL_LINE_BIT) {
10867117f1b4Smrg      /* OK to memcpy */
10877117f1b4Smrg      dst->Line = src->Line;
10887117f1b4Smrg   }
10897117f1b4Smrg   if (mask & GL_LIST_BIT) {
10907117f1b4Smrg      /* OK to memcpy */
10917117f1b4Smrg      dst->List = src->List;
10927117f1b4Smrg   }
10937117f1b4Smrg   if (mask & GL_PIXEL_MODE_BIT) {
10947117f1b4Smrg      /* OK to memcpy */
10957117f1b4Smrg      dst->Pixel = src->Pixel;
10967117f1b4Smrg   }
10977117f1b4Smrg   if (mask & GL_POINT_BIT) {
10987117f1b4Smrg      /* OK to memcpy */
10997117f1b4Smrg      dst->Point = src->Point;
11007117f1b4Smrg   }
11017117f1b4Smrg   if (mask & GL_POLYGON_BIT) {
11027117f1b4Smrg      /* OK to memcpy */
11037117f1b4Smrg      dst->Polygon = src->Polygon;
11047117f1b4Smrg   }
11057117f1b4Smrg   if (mask & GL_POLYGON_STIPPLE_BIT) {
1106cdc920a0Smrg      /* Use loop instead of memcpy due to problem with Portland Group's
11077117f1b4Smrg       * C compiler.  Reported by John Stone.
11087117f1b4Smrg       */
11097117f1b4Smrg      GLuint i;
11107117f1b4Smrg      for (i = 0; i < 32; i++) {
11117117f1b4Smrg         dst->PolygonStipple[i] = src->PolygonStipple[i];
11127117f1b4Smrg      }
11137117f1b4Smrg   }
11147117f1b4Smrg   if (mask & GL_SCISSOR_BIT) {
11157117f1b4Smrg      /* OK to memcpy */
11167117f1b4Smrg      dst->Scissor = src->Scissor;
11177117f1b4Smrg   }
11187117f1b4Smrg   if (mask & GL_STENCIL_BUFFER_BIT) {
11197117f1b4Smrg      /* OK to memcpy */
11207117f1b4Smrg      dst->Stencil = src->Stencil;
11217117f1b4Smrg   }
11227117f1b4Smrg   if (mask & GL_TEXTURE_BIT) {
11237117f1b4Smrg      /* Cannot memcpy because of pointers */
11247117f1b4Smrg      _mesa_copy_texture_state(src, dst);
11257117f1b4Smrg   }
11267117f1b4Smrg   if (mask & GL_TRANSFORM_BIT) {
11277117f1b4Smrg      /* OK to memcpy */
11287117f1b4Smrg      dst->Transform = src->Transform;
11297117f1b4Smrg   }
11307117f1b4Smrg   if (mask & GL_VIEWPORT_BIT) {
11317117f1b4Smrg      /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
11327117f1b4Smrg      dst->Viewport.X = src->Viewport.X;
11337117f1b4Smrg      dst->Viewport.Y = src->Viewport.Y;
11347117f1b4Smrg      dst->Viewport.Width = src->Viewport.Width;
11357117f1b4Smrg      dst->Viewport.Height = src->Viewport.Height;
11367117f1b4Smrg      dst->Viewport.Near = src->Viewport.Near;
11377117f1b4Smrg      dst->Viewport.Far = src->Viewport.Far;
11387117f1b4Smrg      _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
11397117f1b4Smrg   }
11407117f1b4Smrg
11417117f1b4Smrg   /* XXX FIXME:  Call callbacks?
11427117f1b4Smrg    */
11437117f1b4Smrg   dst->NewState = _NEW_ALL;
11447117f1b4Smrg}
11457117f1b4Smrg#endif
11467117f1b4Smrg
11477117f1b4Smrg
11487117f1b4Smrg/**
11497117f1b4Smrg * Check if the given context can render into the given framebuffer
11507117f1b4Smrg * by checking visual attributes.
11517117f1b4Smrg *
1152c1f859d4Smrg * Most of these tests could go away because Mesa is now pretty flexible
1153c1f859d4Smrg * in terms of mixing rendering contexts with framebuffers.  As long
1154c1f859d4Smrg * as RGB vs. CI mode agree, we're probably good.
11557117f1b4Smrg *
11567117f1b4Smrg * \return GL_TRUE if compatible, GL_FALSE otherwise.
11577117f1b4Smrg */
11587117f1b4Smrgstatic GLboolean
11597117f1b4Smrgcheck_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
11607117f1b4Smrg{
11617117f1b4Smrg   const GLvisual *ctxvis = &ctx->Visual;
11627117f1b4Smrg   const GLvisual *bufvis = &buffer->Visual;
11637117f1b4Smrg
11647117f1b4Smrg   if (ctxvis == bufvis)
11657117f1b4Smrg      return GL_TRUE;
11667117f1b4Smrg
11677117f1b4Smrg#if 0
11687117f1b4Smrg   /* disabling this fixes the fgl_glxgears pbuffer demo */
11697117f1b4Smrg   if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
11707117f1b4Smrg      return GL_FALSE;
11717117f1b4Smrg#endif
11727117f1b4Smrg   if (ctxvis->stereoMode && !bufvis->stereoMode)
11737117f1b4Smrg      return GL_FALSE;
11747117f1b4Smrg   if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
11757117f1b4Smrg      return GL_FALSE;
11767117f1b4Smrg   if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
11777117f1b4Smrg      return GL_FALSE;
11787117f1b4Smrg   if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
11797117f1b4Smrg      return GL_FALSE;
11807117f1b4Smrg   if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
11817117f1b4Smrg      return GL_FALSE;
11827117f1b4Smrg   if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
11837117f1b4Smrg      return GL_FALSE;
11847117f1b4Smrg   if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
11857117f1b4Smrg      return GL_FALSE;
11867117f1b4Smrg#if 0
11877117f1b4Smrg   /* disabled (see bug 11161) */
11887117f1b4Smrg   if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
11897117f1b4Smrg      return GL_FALSE;
11907117f1b4Smrg#endif
11917117f1b4Smrg   if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
11927117f1b4Smrg      return GL_FALSE;
11937117f1b4Smrg
11947117f1b4Smrg   return GL_TRUE;
11957117f1b4Smrg}
11967117f1b4Smrg
11977117f1b4Smrg
11987117f1b4Smrg/**
11997117f1b4Smrg * Do one-time initialization for the given framebuffer.  Specifically,
12007117f1b4Smrg * ask the driver for the window's current size and update the framebuffer
12017117f1b4Smrg * object to match.
12027117f1b4Smrg * Really, the device driver should totally take care of this.
12037117f1b4Smrg */
12047117f1b4Smrgstatic void
12057117f1b4Smrginitialize_framebuffer_size(GLcontext *ctx, GLframebuffer *fb)
12067117f1b4Smrg{
12077117f1b4Smrg   GLuint width, height;
12087117f1b4Smrg   if (ctx->Driver.GetBufferSize) {
12097117f1b4Smrg      ctx->Driver.GetBufferSize(fb, &width, &height);
12107117f1b4Smrg      if (ctx->Driver.ResizeBuffers)
12117117f1b4Smrg         ctx->Driver.ResizeBuffers(ctx, fb, width, height);
12127117f1b4Smrg      fb->Initialized = GL_TRUE;
12137117f1b4Smrg   }
12147117f1b4Smrg}
12157117f1b4Smrg
12167117f1b4Smrg
1217c7037ccdSmrg/**
1218c7037ccdSmrg * Check if the viewport/scissor size has not yet been initialized.
1219c7037ccdSmrg * Initialize the size if the given width and height are non-zero.
1220c7037ccdSmrg */
1221c7037ccdSmrgvoid
1222c7037ccdSmrg_mesa_check_init_viewport(GLcontext *ctx, GLuint width, GLuint height)
1223c7037ccdSmrg{
1224c7037ccdSmrg   if (!ctx->ViewportInitialized && width > 0 && height > 0) {
1225c7037ccdSmrg      /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
1226c7037ccdSmrg       * potential infinite recursion.
1227c7037ccdSmrg       */
1228c7037ccdSmrg      ctx->ViewportInitialized = GL_TRUE;
1229c7037ccdSmrg      _mesa_set_viewport(ctx, 0, 0, width, height);
1230c7037ccdSmrg      _mesa_set_scissor(ctx, 0, 0, width, height);
1231c7037ccdSmrg   }
1232c7037ccdSmrg}
1233c7037ccdSmrg
1234c7037ccdSmrg
12357117f1b4Smrg/**
12367117f1b4Smrg * Bind the given context to the given drawBuffer and readBuffer and
12377117f1b4Smrg * make it the current context for the calling thread.
12387117f1b4Smrg * We'll render into the drawBuffer and read pixels from the
12397117f1b4Smrg * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
12407117f1b4Smrg *
12417117f1b4Smrg * We check that the context's and framebuffer's visuals are compatible
12427117f1b4Smrg * and return immediately if they're not.
12437117f1b4Smrg *
12447117f1b4Smrg * \param newCtx  the new GL context. If NULL then there will be no current GL
12457117f1b4Smrg *                context.
12467117f1b4Smrg * \param drawBuffer  the drawing framebuffer
12477117f1b4Smrg * \param readBuffer  the reading framebuffer
12487117f1b4Smrg */
12494a49301eSmrgGLboolean
12507117f1b4Smrg_mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
12517117f1b4Smrg                    GLframebuffer *readBuffer )
12527117f1b4Smrg{
12537117f1b4Smrg   if (MESA_VERBOSE & VERBOSE_API)
12547117f1b4Smrg      _mesa_debug(newCtx, "_mesa_make_current()\n");
12557117f1b4Smrg
12567117f1b4Smrg   /* Check that the context's and framebuffer's visuals are compatible.
12577117f1b4Smrg    */
12587117f1b4Smrg   if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
12597117f1b4Smrg      if (!check_compatible(newCtx, drawBuffer)) {
12607117f1b4Smrg         _mesa_warning(newCtx,
12617117f1b4Smrg              "MakeCurrent: incompatible visuals for context and drawbuffer");
12624a49301eSmrg         return GL_FALSE;
12637117f1b4Smrg      }
12647117f1b4Smrg   }
12657117f1b4Smrg   if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
12667117f1b4Smrg      if (!check_compatible(newCtx, readBuffer)) {
12677117f1b4Smrg         _mesa_warning(newCtx,
12687117f1b4Smrg              "MakeCurrent: incompatible visuals for context and readbuffer");
12694a49301eSmrg         return GL_FALSE;
12707117f1b4Smrg      }
12717117f1b4Smrg   }
12727117f1b4Smrg
12737117f1b4Smrg   /* We used to call _glapi_check_multithread() here.  Now do it in drivers */
12747117f1b4Smrg   _glapi_set_context((void *) newCtx);
12757117f1b4Smrg   ASSERT(_mesa_get_current_context() == newCtx);
12767117f1b4Smrg
12777117f1b4Smrg   if (!newCtx) {
12787117f1b4Smrg      _glapi_set_dispatch(NULL);  /* none current */
12797117f1b4Smrg   }
12807117f1b4Smrg   else {
12817117f1b4Smrg      _glapi_set_dispatch(newCtx->CurrentDispatch);
12827117f1b4Smrg
12837117f1b4Smrg      if (drawBuffer && readBuffer) {
12847117f1b4Smrg	 /* TODO: check if newCtx and buffer's visual match??? */
12857117f1b4Smrg
12867117f1b4Smrg         ASSERT(drawBuffer->Name == 0);
12877117f1b4Smrg         ASSERT(readBuffer->Name == 0);
12887117f1b4Smrg         _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
12897117f1b4Smrg         _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
12907117f1b4Smrg
12917117f1b4Smrg         /*
12927117f1b4Smrg          * Only set the context's Draw/ReadBuffer fields if they're NULL
12937117f1b4Smrg          * or not bound to a user-created FBO.
12947117f1b4Smrg          */
12957117f1b4Smrg         if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
12964a49301eSmrg            /* KW: merge conflict here, revisit.
12974a49301eSmrg             */
12984a49301eSmrg            /* fix up the fb fields - these will end up wrong otherwise
12994a49301eSmrg             * if the DRIdrawable changes, and everything relies on them.
13004a49301eSmrg             * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
13014a49301eSmrg             */
13024a49301eSmrg            unsigned int i;
13034a49301eSmrg            GLenum buffers[MAX_DRAW_BUFFERS];
13044a49301eSmrg
13057117f1b4Smrg            _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
13064a49301eSmrg
13074a49301eSmrg            for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) {
13084a49301eSmrg               buffers[i] = newCtx->Color.DrawBuffer[i];
13094a49301eSmrg            }
13104a49301eSmrg
13114a49301eSmrg            _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers, buffers, NULL);
13127117f1b4Smrg         }
13137117f1b4Smrg         if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
13147117f1b4Smrg            _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
13157117f1b4Smrg         }
13167117f1b4Smrg
1317c1f859d4Smrg         /* XXX only set this flag if we're really changing the draw/read
1318c1f859d4Smrg          * framebuffer bindings.
1319c1f859d4Smrg          */
13207117f1b4Smrg	 newCtx->NewState |= _NEW_BUFFERS;
13217117f1b4Smrg
13227117f1b4Smrg#if 1
13237117f1b4Smrg         /* We want to get rid of these lines: */
13247117f1b4Smrg
13257117f1b4Smrg#if _HAVE_FULL_GL
13267117f1b4Smrg         if (!drawBuffer->Initialized) {
13277117f1b4Smrg            initialize_framebuffer_size(newCtx, drawBuffer);
13287117f1b4Smrg         }
13297117f1b4Smrg         if (readBuffer != drawBuffer && !readBuffer->Initialized) {
13307117f1b4Smrg            initialize_framebuffer_size(newCtx, readBuffer);
13317117f1b4Smrg         }
13327117f1b4Smrg
13337117f1b4Smrg	 _mesa_resizebuffers(newCtx);
13347117f1b4Smrg#endif
13357117f1b4Smrg
13367117f1b4Smrg#else
13377117f1b4Smrg         /* We want the drawBuffer and readBuffer to be initialized by
13387117f1b4Smrg          * the driver.
13397117f1b4Smrg          * This generally means the Width and Height match the actual
13407117f1b4Smrg          * window size and the renderbuffers (both hardware and software
13417117f1b4Smrg          * based) are allocated to match.  The later can generally be
13427117f1b4Smrg          * done with a call to _mesa_resize_framebuffer().
13437117f1b4Smrg          *
13447117f1b4Smrg          * It's theoretically possible for a buffer to have zero width
13457117f1b4Smrg          * or height, but for now, assert check that the driver did what's
13467117f1b4Smrg          * expected of it.
13477117f1b4Smrg          */
13487117f1b4Smrg         ASSERT(drawBuffer->Width > 0);
13497117f1b4Smrg         ASSERT(drawBuffer->Height > 0);
13507117f1b4Smrg#endif
13517117f1b4Smrg
1352c7037ccdSmrg         if (drawBuffer) {
1353c7037ccdSmrg            _mesa_check_init_viewport(newCtx,
1354c7037ccdSmrg                                      drawBuffer->Width, drawBuffer->Height);
13557117f1b4Smrg         }
13567117f1b4Smrg      }
13577117f1b4Smrg
13587117f1b4Smrg      if (newCtx->FirstTimeCurrent) {
1359cdc920a0Smrg         _mesa_compute_version(newCtx);
1360cdc920a0Smrg
1361c7037ccdSmrg         check_context_limits(newCtx);
1362c7037ccdSmrg
1363c7037ccdSmrg         /* We can use this to help debug user's problems.  Tell them to set
1364c7037ccdSmrg          * the MESA_INFO env variable before running their app.  Then the
1365c7037ccdSmrg          * first time each context is made current we'll print some useful
1366c7037ccdSmrg          * information.
1367c7037ccdSmrg          */
13687117f1b4Smrg	 if (_mesa_getenv("MESA_INFO")) {
13697117f1b4Smrg	    _mesa_print_info();
13707117f1b4Smrg	 }
1371c7037ccdSmrg
13727117f1b4Smrg	 newCtx->FirstTimeCurrent = GL_FALSE;
13737117f1b4Smrg      }
13747117f1b4Smrg   }
13754a49301eSmrg
13764a49301eSmrg   return GL_TRUE;
13777117f1b4Smrg}
13787117f1b4Smrg
13797117f1b4Smrg
13807117f1b4Smrg/**
13817117f1b4Smrg * Make context 'ctx' share the display lists, textures and programs
13827117f1b4Smrg * that are associated with 'ctxToShare'.
13837117f1b4Smrg * Any display lists, textures or programs associated with 'ctx' will
13847117f1b4Smrg * be deleted if nobody else is sharing them.
13857117f1b4Smrg */
13867117f1b4SmrgGLboolean
13877117f1b4Smrg_mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
13887117f1b4Smrg{
13897117f1b4Smrg   if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
1390c1f859d4Smrg      struct gl_shared_state *oldSharedState = ctx->Shared;
1391c1f859d4Smrg
13927117f1b4Smrg      ctx->Shared = ctxToShare->Shared;
13934a49301eSmrg
13944a49301eSmrg      _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
13957117f1b4Smrg      ctx->Shared->RefCount++;
13964a49301eSmrg      _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1397c1f859d4Smrg
1398c1f859d4Smrg      update_default_objects(ctx);
1399c1f859d4Smrg
14004a49301eSmrg      _mesa_release_shared_state(ctx, oldSharedState);
1401c1f859d4Smrg
14027117f1b4Smrg      return GL_TRUE;
14037117f1b4Smrg   }
14047117f1b4Smrg   else {
14057117f1b4Smrg      return GL_FALSE;
14067117f1b4Smrg   }
14077117f1b4Smrg}
14087117f1b4Smrg
14097117f1b4Smrg
14107117f1b4Smrg
14117117f1b4Smrg/**
14127117f1b4Smrg * \return pointer to the current GL context for this thread.
14137117f1b4Smrg *
14147117f1b4Smrg * Calls _glapi_get_context(). This isn't the fastest way to get the current
14157117f1b4Smrg * context.  If you need speed, see the #GET_CURRENT_CONTEXT macro in
14167117f1b4Smrg * context.h.
14177117f1b4Smrg */
14187117f1b4SmrgGLcontext *
14197117f1b4Smrg_mesa_get_current_context( void )
14207117f1b4Smrg{
14217117f1b4Smrg   return (GLcontext *) _glapi_get_context();
14227117f1b4Smrg}
14237117f1b4Smrg
14247117f1b4Smrg
14257117f1b4Smrg/**
14267117f1b4Smrg * Get context's current API dispatch table.
14277117f1b4Smrg *
14287117f1b4Smrg * It'll either be the immediate-mode execute dispatcher or the display list
14297117f1b4Smrg * compile dispatcher.
14307117f1b4Smrg *
14317117f1b4Smrg * \param ctx GL context.
14327117f1b4Smrg *
14337117f1b4Smrg * \return pointer to dispatch_table.
14347117f1b4Smrg *
14357117f1b4Smrg * Simply returns __GLcontextRec::CurrentDispatch.
14367117f1b4Smrg */
14377117f1b4Smrgstruct _glapi_table *
14387117f1b4Smrg_mesa_get_dispatch(GLcontext *ctx)
14397117f1b4Smrg{
14407117f1b4Smrg   return ctx->CurrentDispatch;
14417117f1b4Smrg}
14427117f1b4Smrg
14437117f1b4Smrg/*@}*/
14447117f1b4Smrg
14457117f1b4Smrg
14467117f1b4Smrg/**********************************************************************/
14477117f1b4Smrg/** \name Miscellaneous functions                                     */
14487117f1b4Smrg/**********************************************************************/
14497117f1b4Smrg/*@{*/
14507117f1b4Smrg
14517117f1b4Smrg/**
14527117f1b4Smrg * Record an error.
14537117f1b4Smrg *
14547117f1b4Smrg * \param ctx GL context.
14557117f1b4Smrg * \param error error code.
14567117f1b4Smrg *
14577117f1b4Smrg * Records the given error code and call the driver's dd_function_table::Error
14587117f1b4Smrg * function if defined.
14597117f1b4Smrg *
14607117f1b4Smrg * \sa
14617117f1b4Smrg * This is called via _mesa_error().
14627117f1b4Smrg */
14637117f1b4Smrgvoid
14647117f1b4Smrg_mesa_record_error(GLcontext *ctx, GLenum error)
14657117f1b4Smrg{
14667117f1b4Smrg   if (!ctx)
14677117f1b4Smrg      return;
14687117f1b4Smrg
14697117f1b4Smrg   if (ctx->ErrorValue == GL_NO_ERROR) {
14707117f1b4Smrg      ctx->ErrorValue = error;
14717117f1b4Smrg   }
14727117f1b4Smrg
14737117f1b4Smrg   /* Call device driver's error handler, if any.  This is used on the Mac. */
14747117f1b4Smrg   if (ctx->Driver.Error) {
14757117f1b4Smrg      ctx->Driver.Error(ctx);
14767117f1b4Smrg   }
14777117f1b4Smrg}
14787117f1b4Smrg
14797117f1b4Smrg
14804a49301eSmrg/**
14814a49301eSmrg * Flush commands and wait for completion.
14824a49301eSmrg */
14834a49301eSmrgvoid
14844a49301eSmrg_mesa_finish(GLcontext *ctx)
14854a49301eSmrg{
14864a49301eSmrg   FLUSH_CURRENT( ctx, 0 );
14874a49301eSmrg   if (ctx->Driver.Finish) {
14884a49301eSmrg      ctx->Driver.Finish(ctx);
14894a49301eSmrg   }
14904a49301eSmrg}
14914a49301eSmrg
14924a49301eSmrg
14934a49301eSmrg/**
14944a49301eSmrg * Flush commands.
14954a49301eSmrg */
14964a49301eSmrgvoid
14974a49301eSmrg_mesa_flush(GLcontext *ctx)
14984a49301eSmrg{
14994a49301eSmrg   FLUSH_CURRENT( ctx, 0 );
15004a49301eSmrg   if (ctx->Driver.Flush) {
15014a49301eSmrg      ctx->Driver.Flush(ctx);
15024a49301eSmrg   }
15034a49301eSmrg}
15044a49301eSmrg
15054a49301eSmrg
15064a49301eSmrg
15077117f1b4Smrg/**
15087117f1b4Smrg * Execute glFinish().
15097117f1b4Smrg *
15107117f1b4Smrg * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
15117117f1b4Smrg * dd_function_table::Finish driver callback, if not NULL.
15127117f1b4Smrg */
15137117f1b4Smrgvoid GLAPIENTRY
15147117f1b4Smrg_mesa_Finish(void)
15157117f1b4Smrg{
15167117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
15177117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
15184a49301eSmrg   _mesa_finish(ctx);
15197117f1b4Smrg}
15207117f1b4Smrg
15217117f1b4Smrg
15227117f1b4Smrg/**
15237117f1b4Smrg * Execute glFlush().
15247117f1b4Smrg *
15257117f1b4Smrg * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
15267117f1b4Smrg * dd_function_table::Flush driver callback, if not NULL.
15277117f1b4Smrg */
15287117f1b4Smrgvoid GLAPIENTRY
15297117f1b4Smrg_mesa_Flush(void)
15307117f1b4Smrg{
15317117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
15327117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
15334a49301eSmrg   _mesa_flush(ctx);
15344a49301eSmrg}
15354a49301eSmrg
15364a49301eSmrg
15374a49301eSmrg/**
15384a49301eSmrg * Set mvp_with_dp4 flag.  If a driver has a preference for DP4 over
15394a49301eSmrg * MUL/MAD, or vice versa, call this function to register that.
15404a49301eSmrg * Otherwise we default to MUL/MAD.
15414a49301eSmrg */
15424a49301eSmrgvoid
15434a49301eSmrg_mesa_set_mvp_with_dp4( GLcontext *ctx,
15444a49301eSmrg                        GLboolean flag )
15454a49301eSmrg{
15464a49301eSmrg   ctx->mvp_with_dp4 = flag;
15474a49301eSmrg}
15484a49301eSmrg
15494a49301eSmrg
15504a49301eSmrg
15514a49301eSmrg/**
15524a49301eSmrg * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
15534a49301eSmrg * is called to see if it's valid to render.  This involves checking that
15544a49301eSmrg * the current shader is valid and the framebuffer is complete.
15554a49301eSmrg * If an error is detected it'll be recorded here.
15564a49301eSmrg * \return GL_TRUE if OK to render, GL_FALSE if not
15574a49301eSmrg */
15584a49301eSmrgGLboolean
15594a49301eSmrg_mesa_valid_to_render(GLcontext *ctx, const char *where)
15604a49301eSmrg{
15614a49301eSmrg   /* This depends on having up to date derived state (shaders) */
15624a49301eSmrg   if (ctx->NewState)
15634a49301eSmrg      _mesa_update_state(ctx);
15644a49301eSmrg
15654a49301eSmrg   if (ctx->Shader.CurrentProgram) {
15664a49301eSmrg      /* using shaders */
15674a49301eSmrg      if (!ctx->Shader.CurrentProgram->LinkStatus) {
15684a49301eSmrg         _mesa_error(ctx, GL_INVALID_OPERATION,
15694a49301eSmrg                     "%s(shader not linked), where");
15704a49301eSmrg         return GL_FALSE;
15714a49301eSmrg      }
15724a49301eSmrg#if 0 /* not normally enabled */
15734a49301eSmrg      {
15744a49301eSmrg         char errMsg[100];
15754a49301eSmrg         if (!_mesa_validate_shader_program(ctx, ctx->Shader.CurrentProgram,
15764a49301eSmrg                                            errMsg)) {
15774a49301eSmrg            _mesa_warning(ctx, "Shader program %u is invalid: %s",
15784a49301eSmrg                          ctx->Shader.CurrentProgram->Name, errMsg);
15794a49301eSmrg         }
15804a49301eSmrg      }
15814a49301eSmrg#endif
15824a49301eSmrg   }
15834a49301eSmrg   else {
15844a49301eSmrg      if (ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) {
15854a49301eSmrg         _mesa_error(ctx, GL_INVALID_OPERATION,
15864a49301eSmrg                     "%s(vertex program not valid)", where);
15874a49301eSmrg         return GL_FALSE;
15884a49301eSmrg      }
15894a49301eSmrg      if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
15904a49301eSmrg         _mesa_error(ctx, GL_INVALID_OPERATION,
15914a49301eSmrg                     "%s(fragment program not valid)", where);
15924a49301eSmrg         return GL_FALSE;
15934a49301eSmrg      }
15947117f1b4Smrg   }
15954a49301eSmrg
15964a49301eSmrg   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
15974a49301eSmrg      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
15984a49301eSmrg                  "%s(incomplete framebuffer)", where);
15994a49301eSmrg      return GL_FALSE;
16004a49301eSmrg   }
16014a49301eSmrg
16024a49301eSmrg#ifdef DEBUG
16034a49301eSmrg   if (ctx->Shader.Flags & GLSL_LOG) {
16044a49301eSmrg      struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
16054a49301eSmrg      if (shProg) {
16064a49301eSmrg         if (!shProg->_Used) {
16074a49301eSmrg            /* This is the first time this shader is being used.
16084a49301eSmrg             * Append shader's constants/uniforms to log file.
16094a49301eSmrg             */
16104a49301eSmrg            GLuint i;
16114a49301eSmrg            for (i = 0; i < shProg->NumShaders; i++) {
16124a49301eSmrg               struct gl_shader *sh = shProg->Shaders[i];
16134a49301eSmrg               if (sh->Type == GL_VERTEX_SHADER) {
16144a49301eSmrg                  _mesa_append_uniforms_to_file(sh,
16154a49301eSmrg                                                &shProg->VertexProgram->Base);
16164a49301eSmrg               }
16174a49301eSmrg               else if (sh->Type == GL_FRAGMENT_SHADER) {
16184a49301eSmrg                  _mesa_append_uniforms_to_file(sh,
16194a49301eSmrg                                                &shProg->FragmentProgram->Base);
16204a49301eSmrg               }
16214a49301eSmrg            }
16224a49301eSmrg            shProg->_Used = GL_TRUE;
16234a49301eSmrg         }
16244a49301eSmrg      }
16254a49301eSmrg   }
16264a49301eSmrg#endif
16274a49301eSmrg
16284a49301eSmrg   return GL_TRUE;
16297117f1b4Smrg}
16307117f1b4Smrg
16317117f1b4Smrg
16327117f1b4Smrg/*@}*/
1633