📄 context.c
字号:
/** * \file context.c * Mesa context/visual/framebuffer management functions. * \author Brian Paul *//* * Mesa 3-D graphics library * Version: 6.5 * * Copyright (C) 1999-2006 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 "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 "get.h"#include "glthread.h"#include "glapioffsets.h"#include "histogram.h"#include "hint.h"#include "hash.h"#include "atifragshader.h"#include "light.h"#include "lines.h"#include "macros.h"#include "matrix.h"#include "occlude.h"#include "pixel.h"#include "points.h"#include "polygon.h"#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program#include "program.h"#endif#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"#if _HAVE_FULL_GL#include "math/m_translate.h"#include "math/m_matrix.h"#include "math/m_xform.h"#include "math/mathmod.h"#endif#include "shaderobjects.h"#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];static voidfree_shared_state( GLcontext *ctx, struct gl_shared_state *ss );/**********************************************************************//** \name OpenGL SI-style interface (new in Mesa 3.5) * * \if subset * \note Most of these functions are never called in the Mesa subset. * \endif *//*@{*//** * Destroy context callback. * * \param gc context. * \return GL_TRUE on success, or GL_FALSE on failure. * * \ifnot subset * Called by window system/device driver (via __GLexports::destroyCurrent) when * the rendering context is to be destroyed. * \endif * * Frees the context data and the context structure. */GLboolean_mesa_destroyContext(__GLcontext *gc){ if (gc) { _mesa_free_context_data(gc); _mesa_free(gc); } return GL_TRUE;}/** * Unbind context callback. * * \param gc context. * \return GL_TRUE on success, or GL_FALSE on failure. * * \ifnot subset * Called by window system/device driver (via __GLexports::loseCurrent) * when the rendering context is made non-current. * \endif * * No-op */GLboolean_mesa_loseCurrent(__GLcontext *gc){ /* XXX unbind context from thread */ (void) gc; return GL_TRUE;}/** * Bind context callback. * * \param gc context. * \return GL_TRUE on success, or GL_FALSE on failure. * * \ifnot subset * Called by window system/device driver (via __GLexports::makeCurrent) * when the rendering context is made current. * \endif * * No-op */GLboolean_mesa_makeCurrent(__GLcontext *gc){ /* XXX bind context to thread */ (void) gc; return GL_TRUE;}/** * Share context callback. * * \param gc context. * \param gcShare shared context. * \return GL_TRUE on success, or GL_FALSE on failure. * * \ifnot subset * Called by window system/device driver (via __GLexports::shareContext) * \endif * * Update the shared context reference count, gl_shared_state::RefCount. */GLboolean_mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare){ if (gc && gcShare && gc->Shared && gcShare->Shared) { gc->Shared->RefCount--; if (gc->Shared->RefCount == 0) { free_shared_state(gc, gc->Shared); } gc->Shared = gcShare->Shared; gc->Shared->RefCount++; return GL_TRUE; } else { return GL_FALSE; }}#if _HAVE_FULL_GL/** * Copy context callback. */GLboolean_mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask){ if (dst && src) { _mesa_copy_context( src, dst, mask ); return GL_TRUE; } else { return GL_FALSE; }}#endif/** No-op */GLboolean_mesa_forceCurrent(__GLcontext *gc){ (void) gc; return GL_TRUE;}/** * Windows/buffer resizing notification callback. * * \param gc GL context. * \return GL_TRUE on success, or GL_FALSE on failure. */GLboolean_mesa_notifyResize(__GLcontext *gc){ GLint x, y; GLuint width, height; __GLdrawablePrivate *d = gc->imports.getDrawablePrivate(gc); if (!d || !d->getDrawableSize) return GL_FALSE; d->getDrawableSize( d, &x, &y, &width, &height ); /* update viewport, resize software buffers, etc. */ return GL_TRUE;}/** * Window/buffer destruction notification callback. * * \param gc GL context. * * Called when the context's window/buffer is going to be destroyed. * * No-op */void_mesa_notifyDestroy(__GLcontext *gc){ /* Unbind from it. */ (void) gc;}/** * 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 );}/** No-op */struct __GLdispatchStateRec *_mesa_dispatchExec(__GLcontext *gc){ (void) gc; return NULL;}/** No-op */void_mesa_beginDispatchOverride(__GLcontext *gc){ (void) gc;}/** No-op */void_mesa_endDispatchOverride(__GLcontext *gc){ (void) gc;}/** * \ifnot subset * Setup the exports. * * The window system will call these functions when it needs Mesa to do * something. * * \note Device drivers should override these functions! For example, * the Xlib driver should plug in the XMesa*-style functions into this * structure. The XMesa-style functions should then call the _mesa_* * version of these functions. This is an approximation to OO design * (inheritance and virtual functions). * \endif * * \if subset * No-op. * * \endif */static void_mesa_init_default_exports(__GLexports *exports){#if _HAVE_FULL_GL exports->destroyContext = _mesa_destroyContext; exports->loseCurrent = _mesa_loseCurrent; exports->makeCurrent = _mesa_makeCurrent; exports->shareContext = _mesa_shareContext; exports->copyContext = _mesa_copyContext; exports->forceCurrent = _mesa_forceCurrent; exports->notifyResize = _mesa_notifyResize; exports->notifyDestroy = _mesa_notifyDestroy; exports->notifySwapBuffers = _mesa_notifySwapBuffers; exports->dispatchExec = _mesa_dispatchExec; exports->beginDispatchOverride = _mesa_beginDispatchOverride; exports->endDispatchOverride = _mesa_endDispatchOverride;#else (void) exports;#endif}/** * Exported OpenGL SI interface. */__GLcontext *__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes){ GLcontext *ctx; ctx = (GLcontext *) (*imports->calloc)(NULL, 1, sizeof(GLcontext)); if (ctx == NULL) { return NULL; } /* XXX doesn't work at this time */ _mesa_initialize_context(ctx, modes, NULL, NULL, NULL); ctx->imports = *imports; return ctx;}/** * Exported OpenGL SI interface. */void__glCoreNopDispatch(void){#if 0 /* SI */ __gl_dispatch = __glNopDispatchState;#else /* Mesa */ _glapi_set_dispatch(NULL);#endif}/*@}*//**********************************************************************//** \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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -