context.c

来自「Mesa is an open-source implementation of」· C语言 代码 · 共 1,776 行 · 第 1/4 页

C
1,776
字号
/** * \file context.c * Mesa context/visual/framebuffer management functions. * \author Brian Paul *//* * Mesa 3-D graphics library * Version:  7.1 * * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//** * \mainpage Mesa Main Module * * \section MainIntroduction Introduction * * The Mesa Main module consists of all the files in the main/ directory. * Among the features of this module are: * <UL> * <LI> Structures to represent most GL state </LI> * <LI> State set/get functions </LI> * <LI> Display lists </LI> * <LI> Texture unit, object and image handling </LI> * <LI> Matrix and attribute stacks </LI> * </UL> * * Other modules are responsible for API dispatch, vertex transformation, * point/line/triangle setup, rasterization, vertex array caching, * vertex/fragment programs/shaders, etc. * * * \section AboutDoxygen About Doxygen * * If you're viewing this information as Doxygen-generated HTML you'll * see the documentation index at the top of this page. * * The first line lists the Mesa source code modules. * The second line lists the indexes available for viewing the documentation * for each module. * * Selecting the <b>Main page</b> link will display a summary of the module * (this page). * * Selecting <b>Data Structures</b> will list all C structures. * * Selecting the <b>File List</b> link will list all the source files in * the module. * Selecting a filename will show a list of all functions defined in that file. * * Selecting the <b>Data Fields</b> link will display a list of all * documented structure members. * * Selecting the <b>Globals</b> link will display a list * of all functions, structures, global variables and macros in the module. * */#include "glheader.h"#include "imports.h"#include "accum.h"#include "arrayobj.h"#include "attrib.h"#include "blend.h"#include "buffers.h"#include "bufferobj.h"#include "colortab.h"#include "context.h"#include "debug.h"#include "depth.h"#include "dlist.h"#include "eval.h"#include "enums.h"#include "extensions.h"#include "fbobject.h"#include "feedback.h"#include "fog.h"#include "framebuffer.h"#include "get.h"#include "histogram.h"#include "hint.h"#include "hash.h"#include "light.h"#include "lines.h"#include "macros.h"#include "matrix.h"#include "pixel.h"#include "points.h"#include "polygon.h"#include "queryobj.h"#include "rastpos.h"#include "simple_list.h"#include "state.h"#include "stencil.h"#include "texcompress.h"#include "teximage.h"#include "texobj.h"#include "texstate.h"#include "mtypes.h"#include "varray.h"#include "version.h"#include "vtxfmt.h"#include "glapi/glthread.h"#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program#include "shader/program.h"#endif#include "shader/shader_api.h"#include "shader/atifragshader.h"#if _HAVE_FULL_GL#include "math/m_translate.h"#include "math/m_matrix.h"#include "math/m_xform.h"#include "math/mathmod.h"#endif#ifdef USE_SPARC_ASM#include "sparc/sparc.h"#endif#ifndef MESA_VERBOSEint MESA_VERBOSE = 0;#endif#ifndef MESA_DEBUG_FLAGSint MESA_DEBUG_FLAGS = 0;#endif/* ubyte -> float conversion */GLfloat _mesa_ubyte_to_float_color_tab[256];/** * Swap buffers notification callback. *  * \param gc GL context. * * Called by window system just before swapping buffers. * We have to finish any pending rendering. */void_mesa_notifySwapBuffers(__GLcontext *gc){   FLUSH_VERTICES( gc, 0 );}/**********************************************************************//** \name GL Visual allocation/destruction                            *//**********************************************************************//*@{*//** * Allocates a GLvisual structure and initializes it via * _mesa_initialize_visual(). *  * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode. * \param dbFlag double buffering * \param stereoFlag stereo buffer * \param depthBits requested bits per depth buffer value. Any value in [0, 32] * is acceptable but the actual depth type will be GLushort or GLuint as * needed. * \param stencilBits requested minimum bits per stencil buffer value * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer. * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE * \param redBits number of bits per color component in frame buffer for RGB(A) * mode.  We always use 8 in core Mesa though. * \param greenBits same as above. * \param blueBits same as above. * \param alphaBits same as above. * \param numSamples not really used. *  * \return pointer to new GLvisual or NULL if requested parameters can't be * met. * * \note Need to add params for level and numAuxBuffers (at least) */GLvisual *_mesa_create_visual( GLboolean rgbFlag,                     GLboolean dbFlag,                     GLboolean stereoFlag,                     GLint redBits,                     GLint greenBits,                     GLint blueBits,                     GLint alphaBits,                     GLint indexBits,                     GLint depthBits,                     GLint stencilBits,                     GLint accumRedBits,                     GLint accumGreenBits,                     GLint accumBlueBits,                     GLint accumAlphaBits,                     GLint numSamples ){   GLvisual *vis = (GLvisual *) _mesa_calloc(sizeof(GLvisual));   if (vis) {      if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,                                   redBits, greenBits, blueBits, alphaBits,                                   indexBits, depthBits, stencilBits,                                   accumRedBits, accumGreenBits,                                   accumBlueBits, accumAlphaBits,                                   numSamples)) {         _mesa_free(vis);         return NULL;      }   }   return vis;}/** * Makes some sanity checks and fills in the fields of the * GLvisual object with the given parameters.  If the caller needs * to set additional fields, he should just probably init the whole GLvisual * object himself. * \return GL_TRUE on success, or GL_FALSE on failure. * * \sa _mesa_create_visual() above for the parameter description. */GLboolean_mesa_initialize_visual( GLvisual *vis,                         GLboolean rgbFlag,                         GLboolean dbFlag,                         GLboolean stereoFlag,                         GLint redBits,                         GLint greenBits,                         GLint blueBits,                         GLint alphaBits,                         GLint indexBits,                         GLint depthBits,                         GLint stencilBits,                         GLint accumRedBits,                         GLint accumGreenBits,                         GLint accumBlueBits,                         GLint accumAlphaBits,                         GLint numSamples ){   assert(vis);   if (depthBits < 0 || depthBits > 32) {      return GL_FALSE;   }   if (stencilBits < 0 || stencilBits > STENCIL_BITS) {      return GL_FALSE;   }   assert(accumRedBits >= 0);   assert(accumGreenBits >= 0);   assert(accumBlueBits >= 0);   assert(accumAlphaBits >= 0);   vis->rgbMode          = rgbFlag;   vis->doubleBufferMode = dbFlag;   vis->stereoMode       = stereoFlag;   vis->redBits          = redBits;   vis->greenBits        = greenBits;   vis->blueBits         = blueBits;   vis->alphaBits        = alphaBits;   vis->rgbBits          = redBits + greenBits + blueBits;   vis->indexBits      = indexBits;   vis->depthBits      = depthBits;   vis->stencilBits    = stencilBits;   vis->accumRedBits   = accumRedBits;   vis->accumGreenBits = accumGreenBits;   vis->accumBlueBits  = accumBlueBits;   vis->accumAlphaBits = accumAlphaBits;   vis->haveAccumBuffer   = accumRedBits > 0;   vis->haveDepthBuffer   = depthBits > 0;   vis->haveStencilBuffer = stencilBits > 0;   vis->numAuxBuffers = 0;   vis->level = 0;   vis->pixmapMode = 0;   vis->sampleBuffers = numSamples > 0 ? 1 : 0;   vis->samples = numSamples;   return GL_TRUE;}/** * Destroy a visual and free its memory. * * \param vis visual. *  * Frees the visual structure. */void_mesa_destroy_visual( GLvisual *vis ){   _mesa_free(vis);}/*@}*//**********************************************************************//** \name Context allocation, initialization, destroying * * The purpose of the most initialization functions here is to provide the * default state values according to the OpenGL specification. *//**********************************************************************//*@{*//** * One-time initialization mutex lock. * * \sa Used by one_time_init(). */_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);/** * Calls all the various one-time-init functions in Mesa. * * While holding a global mutex lock, calls several initialization functions, * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is * defined. * * \sa _math_init(). */static voidone_time_init( GLcontext *ctx ){   static GLboolean alreadyCalled = GL_FALSE;   (void) ctx;   _glthread_LOCK_MUTEX(OneTimeLock);   if (!alreadyCalled) {      GLuint i;      /* do some implementation tests */      assert( sizeof(GLbyte) == 1 );      assert( sizeof(GLubyte) == 1 );      assert( sizeof(GLshort) == 2 );      assert( sizeof(GLushort) == 2 );      assert( sizeof(GLint) == 4 );      assert( sizeof(GLuint) == 4 );      _mesa_init_sqrt_table();#if _HAVE_FULL_GL      _math_init();      for (i = 0; i < 256; i++) {         _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;      }#endif#ifdef USE_SPARC_ASM      _mesa_init_sparc_glapi_relocs();#endif      if (_mesa_getenv("MESA_DEBUG")) {         _glapi_noop_enable_warnings(GL_TRUE);         _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );      }      else {         _glapi_noop_enable_warnings(GL_FALSE);      }#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)      _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",                  MESA_VERSION_STRING, __DATE__, __TIME__);#endif      alreadyCalled = GL_TRUE;   }   _glthread_UNLOCK_MUTEX(OneTimeLock);}/** * Allocate and initialize a shared context state structure. * Initializes the display list, texture objects and vertex programs hash * tables, allocates the texture objects. If it runs out of memory, frees * everything already allocated before returning NULL. * * \return pointer to a gl_shared_state structure on success, or NULL on * failure. */static GLbooleanalloc_shared_state( GLcontext *ctx ){   struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);   if (!ss)      return GL_FALSE;   ctx->Shared = ss;   _glthread_INIT_MUTEX(ss->Mutex);   ss->DisplayList = _mesa_NewHashTable();   ss->TexObjects = _mesa_NewHashTable();#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program   ss->Programs = _mesa_NewHashTable();#endif#if FEATURE_ARB_vertex_program   ss->DefaultVertexProgram = (struct gl_vertex_program *)      ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);   if (!ss->DefaultVertexProgram)      goto cleanup;#endif#if FEATURE_ARB_fragment_program   ss->DefaultFragmentProgram = (struct gl_fragment_program *)      ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);   if (!ss->DefaultFragmentProgram)      goto cleanup;#endif#if FEATURE_ATI_fragment_shader   ss->ATIShaders = _mesa_NewHashTable();   ss->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);   if (!ss->DefaultFragmentShader)      goto cleanup;#endif#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object   ss->BufferObjects = _mesa_NewHashTable();#endif   ss->ArrayObjects = _mesa_NewHashTable();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?