core  array_cache  math  swrast  swrast_setup  tnl  tnl_dd 
Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

context.c File Reference

Mesa context/visual/framebuffer management functions. More...

#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 "feedback.h"
#include "fog.h"
#include "get.h"
#include "glthread.h"
#include "glapioffsets.h"
#include "histogram.h"
#include "hint.h"
#include "hash.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"
#include "program.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 "vtxfmt.h"
#include "math/m_translate.h"
#include "math/m_matrix.h"
#include "math/m_xform.h"
#include "math/mathmod.h"

Context allocation, initialization, destroying

The purpose of the most initialization functions here is to provide the default state values according to the OpenGL specification.

void free_shared_state (GLcontext *ctx, struct gl_shared_state *ss)
 Deallocate a shared state context and all children structures. More...

 _glthread_DECLARE_STATIC_MUTEX (OneTimeLock)
 One-time initialization mutex lock. More...

void one_time_init (GLcontext *ctx)
 Calls all the various one-time-init functions in Mesa. More...

GLboolean alloc_shared_state (GLcontext *ctx)
 Allocate and initialize a shared context state structure. More...

void _mesa_init_current (GLcontext *ctx)
 Initialize fields of gl_current_attrib (aka ctx->Current.*). More...

void _mesa_init_constants (GLcontext *ctx)
 Initialize fields of gl_constants (aka ctx->Const.*). More...

GLboolean init_attrib_groups (GLcontext *ctx)
 Initialize the attribute groups in a GL context. More...

void add_newer_entrypoints (void)
 If the DRI libGL.so library is old, it may not have the entrypoints for some recent OpenGL extensions. More...

GLboolean _mesa_initialize_context (GLcontext *ctx, const GLvisual *visual, GLcontext *share_list, const struct dd_function_table *driverFunctions, void *driverContext)
 Initialize a GLcontext struct (rendering context). More...

GLcontext_mesa_create_context (const GLvisual *visual, GLcontext *share_list, const struct dd_function_table *driverFunctions, void *driverContext)
 Allocate and initialize a GLcontext structure. More...

void _mesa_free_context_data (GLcontext *ctx)
 Free the data associated with the given context. More...

void _mesa_destroy_context (GLcontext *ctx)
 Destroy a GLcontext structure. More...

void _mesa_copy_context (const GLcontext *src, GLcontext *dst, GLuint mask)
 Copy attribute groups from one context to another. More...

GLboolean check_compatible (const GLcontext *ctx, const GLframebuffer *buffer)
 Check if the given context can render into the given framebuffer by checking visual attributes. More...

void _mesa_make_current (GLcontext *newCtx, GLframebuffer *buffer)
 Set the current context, binding the given frame buffer to the context. More...

void _mesa_make_current2 (GLcontext *newCtx, GLframebuffer *drawBuffer, GLframebuffer *readBuffer)
 Bind the given context to the given draw-buffer and read-buffer and make it the current context for this thread. More...

GLcontext_mesa_get_current_context (void)
 Get current context for the calling thread. More...

_glapi_table * _mesa_get_dispatch (GLcontext *ctx)
 Get context's current API dispatch table. More...


OpenGL SI-style interface (new in Mesa 3.5)

GLboolean _mesa_destroyContext (__GLcontext *gc)
 Destroy context callback. More...

GLboolean _mesa_loseCurrent (__GLcontext *gc)
 Unbind context callback. More...

GLboolean _mesa_makeCurrent (__GLcontext *gc)
 Bind context callback. More...

GLboolean _mesa_shareContext (__GLcontext *gc, __GLcontext *gcShare)
 Share context callback. More...

GLboolean _mesa_copyContext (__GLcontext *dst, const __GLcontext *src, GLuint mask)
 Copy context callback. More...

GLboolean _mesa_forceCurrent (__GLcontext *gc)
 No-op. More...

GLboolean _mesa_notifyResize (__GLcontext *gc)
 Windows/buffer resizing notification callback. More...

void _mesa_notifyDestroy (__GLcontext *gc)
 Window/buffer destruction notification callback. More...

void _mesa_notifySwapBuffers (__GLcontext *gc)
 Swap buffers notification callback. More...

__GLdispatchStateRec * _mesa_dispatchExec (__GLcontext *gc)
 No-op. More...

void _mesa_beginDispatchOverride (__GLcontext *gc)
 No-op. More...

void _mesa_endDispatchOverride (__GLcontext *gc)
 No-op. More...

void _mesa_init_default_exports (__GLexports *exports)
 Setup the exports. More...

__GLcontext * __glCoreCreateContext (__GLimports *imports, __GLcontextModes *modes)
 Exported OpenGL SI interface. More...

void __glCoreNopDispatch (void)
 Exported OpenGL SI interface. More...


GL Visual allocation/destruction

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)
 Allocates a GLvisual structure and initializes it via _mesa_initialize_visual(). More...

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)
 Makes some sanity checks and fills in the fields of the GLvisual structure with the given parameters. More...

void _mesa_destroy_visual (GLvisual *vis)
 Destroy a visual and free its memory. More...


GL Framebuffer allocation/destruction

GLframebuffer_mesa_create_framebuffer (const GLvisual *visual, GLboolean softwareDepth, GLboolean softwareStencil, GLboolean softwareAccum, GLboolean softwareAlpha)
 Allocate a GLframebuffer structure and initializes it via _mesa_initialize_framebuffer(). More...

void _mesa_initialize_framebuffer (GLframebuffer *buffer, const GLvisual *visual, GLboolean softwareDepth, GLboolean softwareStencil, GLboolean softwareAccum, GLboolean softwareAlpha)
 Makes some sanity checks and fills in the fields of the GLframebuffer structure with the given parameters. More...

void _mesa_destroy_framebuffer (GLframebuffer *buffer)
 Free a framebuffer struct and its buffers. More...

void _mesa_free_framebuffer_data (GLframebuffer *buffer)
 Free the data hanging off of buffer, but not buffer itself. More...


Miscellaneous functions

void _mesa_record_error (GLcontext *ctx, GLenum error)
 Record an error. More...

void GLAPIENTRY _mesa_Finish (void)
 Execute glFinish(). More...

void GLAPIENTRY _mesa_Flush (void)
 Execute glFlush(). More...


Variables

GLfloat _mesa_ubyte_to_float_color_tab [256]
 Convert GLubyte in [0,255] to GLfloat in [0.0,1.0]. More...


Detailed Description

Mesa context/visual/framebuffer management functions.

Author:
Brian Paul

Function Documentation

__GLcontext* __glCoreCreateContext __GLimports *    imports,
__GLcontextModes *    modes
 

Exported OpenGL SI interface.

void __glCoreNopDispatch void   
 

Exported OpenGL SI interface.

_glthread_DECLARE_STATIC_MUTEX OneTimeLock   
 

One-time initialization mutex lock.

See also:
Used by one_time_init().

void _mesa_beginDispatchOverride __GLcontext *    gc
 

No-op.

void _mesa_copy_context const GLcontext   src,
GLcontext   dst,
GLuint    mask
 

Copy attribute groups from one context to another.

Parameters:
src  source context
dst  destination context
mask  bitwise OR of GL_*_BIT flags
According to the bits specified in mask, copies the corresponding attributes from src into \dst. For many of the attributes a simple memcpy is not enough due to the existence of internal pointers in their data structures.

GLboolean _mesa_copyContext __GLcontext *    dst,
const __GLcontext *    src,
GLuint    mask
 

Copy context callback.

GLcontext* _mesa_create_context const GLvisual   visual,
GLcontext   share_list,
const struct dd_function_table   driverFunctions,
void   driverContext
 

Allocate and initialize a GLcontext structure.

Note that the driver needs to pass in its dd_function_table here since we need to at least call driverFunctions->NewTextureObject to initialize the rendering context.

Parameters:
visual  a GLvisual pointer (we copy the struct contents)
share_list  another context to share display lists with or NULL
driverFunctions  points to the dd_function_table into which the driver has plugged in all its special functions.
driverCtx  points to the device driver's private context state
Returns:
pointer to a new __GLcontextRec or NULL if error.

GLframebuffer* _mesa_create_framebuffer const GLvisual   visual,
GLboolean    softwareDepth,
GLboolean    softwareStencil,
GLboolean    softwareAccum,
GLboolean    softwareAlpha
 

Allocate a GLframebuffer structure and initializes it via _mesa_initialize_framebuffer().

A GLframebuffer is a structure which encapsulates the depth, stencil and accum buffers and related parameters.

Parameters:
visual  a GLvisual pointer (we copy the struct contents)
softwareDepth  create/use a software depth buffer?
softwareStencil  create/use a software stencil buffer?
softwareAccum  create/use a software accum buffer?
softwareAlpha  create/use a software alpha buffer?
Returns:
pointer to new GLframebuffer struct or NULL if error.
Note:
Need to add softwareAuxBuffers parameter.

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
 

Allocates a GLvisual structure and initializes it via _mesa_initialize_visual().

Parameters:
rgbFlag  GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
dbFlag  double buffering
stereoFlag  stereo buffer
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.
stencilBits  requested minimum bits per stencil buffer value
accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits  number of bits per color component in accum buffer.
indexBits  number of bits per pixel if rgbFlag is GL_FALSE
redBits  number of bits per color component in frame buffer for RGB(A) mode. We always use 8 in core Mesa though.
greenBits  same as above.
blueBits  same as above.
alphaBits  same as above.
numSamples  not really used.
Returns:
pointer to new GLvisual or NULL if requested parameters can't be met.
Note:
Need to add params for level and numAuxBuffers (at least)

void _mesa_destroy_context GLcontext   ctx
 

Destroy a GLcontext structure.

Parameters:
ctx  GL context.
Calls _mesa_free_context_data() and frees the GLcontext structure itself.

void _mesa_destroy_framebuffer GLframebuffer   buffer
 

Free a framebuffer struct and its buffers.

Calls _mesa_free_framebuffer_data() and frees the structure.

void _mesa_destroy_visual GLvisual   vis
 

Destroy a visual and free its memory.

Parameters:
vis  visual.
Frees the visual structure.

GLboolean _mesa_destroyContext __GLcontext *    gc
 

Destroy context callback.

Parameters:
gc  context.
Returns:
GL_TRUE on success, or GL_FALSE on failure.
Called by window system/device driver (via __GLexports::destroyCurrent) when the rendering context is to be destroyed.

Frees the context data and the context structure.

struct __GLdispatchStateRec* _mesa_dispatchExec __GLcontext *    gc
 

No-op.

void _mesa_endDispatchOverride __GLcontext *    gc
 

No-op.

void GLAPIENTRY _mesa_Finish void   
 

Execute glFinish().

Calls the ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the dd_function_table::Finish driver callback, if not NULL.

void GLAPIENTRY _mesa_Flush void   
 

Execute glFlush().

Calls the ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the dd_function_table::Flush driver callback, if not NULL.

GLboolean _mesa_forceCurrent __GLcontext *    gc
 

No-op.

void _mesa_free_context_data GLcontext   ctx
 

Free the data associated with the given context.

But doesn't free the GLcontext struct itself.

See also:
_mesa_initialize_context() and init_attrib_groups().

void _mesa_free_framebuffer_data GLframebuffer   buffer
 

Free the data hanging off of buffer, but not buffer itself.

Parameters:
buffer  framebuffer.
Frees all the buffers associated with the structure.

GLcontext* _mesa_get_current_context void   
 

Get current context for the calling thread.

Returns:
pointer to the current GL context.
Calls _glapi_get_context(). This isn't the fastest way to get the current context. If you need speed, see the GET_CURRENT_CONTEXT macro in context.h.

struct _glapi_table* _mesa_get_dispatch GLcontext   ctx
 

Get context's current API dispatch table.

It'll either be the immediate-mode execute dispatcher or the display list compile dispatcher.

Parameters:
ctx  GL context.
Returns:
pointer to dispatch_table.
Simply returns __GLcontextRec::CurrentDispatch.

void _mesa_init_constants GLcontext   ctx [static]
 

Initialize fields of gl_constants (aka ctx->Const.*).

Use defaults from config.h. The device drivers will often override some of these values (such as number of texture units).

void _mesa_init_current GLcontext   ctx [static]
 

Initialize fields of gl_current_attrib (aka ctx->Current.*).

void _mesa_init_default_exports __GLexports *    exports [static]
 

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).

GLboolean _mesa_initialize_context GLcontext   ctx,
const GLvisual   visual,
GLcontext   share_list,
const struct dd_function_table   driverFunctions,
void   driverContext
 

Initialize a GLcontext struct (rendering context).

This includes allocating all the other structs and arrays which hang off of the context by pointers. Note that the driver needs to pass in its dd_function_table here since we need to at least call driverFunctions->NewTextureObject to create the default texture objects.

Called by _mesa_create_context().

Performs the imports and exports callback tables initialization, and miscellaneous one-time initializations. If no shared context is supplied one is allocated, and increase its reference count. Setups the GL API dispatch tables. Initialize the TNL module. Sets the maximum Z buffer depth. Finally queries the MESA_DEBUG and MESA_VERBOSE environment variables for debug flags.

Parameters:
ctx  the context to initialize
visual  describes the visual attributes for this context
share_list  points to context to share textures, display lists, etc with, or NULL
driverFunctions  table of device driver functions for this context to use
driverContext  pointer to driver-specific context data

void _mesa_initialize_framebuffer GLframebuffer   fb,
const GLvisual   visual,
GLboolean    softwareDepth,
GLboolean    softwareStencil,
GLboolean    softwareAccum,
GLboolean    softwareAlpha
 

Makes some sanity checks and fills in the fields of the GLframebuffer structure with the given parameters.

See also:
_mesa_create_framebuffer() above for the parameter description.

GLboolean _mesa_initialize_visual GLvisual   v,
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
 

Makes some sanity checks and fills in the fields of the GLvisual structure with the given parameters.

Returns:
GL_TRUE on success, or GL_FALSE on failure.
See also:
_mesa_create_visual() above for the parameter description.
Note:
Need to add params for level and numAuxBuffers (at least)

GLboolean _mesa_loseCurrent __GLcontext *    gc
 

Unbind context callback.

Parameters:
gc  context.
Returns:
GL_TRUE on success, or GL_FALSE on failure.
Called by window system/device driver (via __GLexports::loseCurrent) when the rendering context is made non-current.

No-op

void _mesa_make_current GLcontext   ctx,
GLframebuffer   buffer
 

Set the current context, binding the given frame buffer to the context.

Parameters:
newCtx  new GL context.
buffer  framebuffer.
Calls _mesa_make_current2() with buffer as read and write framebuffer.

void _mesa_make_current2 GLcontext   ctx,
GLframebuffer   drawBuffer,
GLframebuffer   readBuffer
 

Bind the given context to the given draw-buffer and read-buffer and make it the current context for this thread.

Parameters:
newCtx  new GL context. If NULL then there will be no current GL context.
drawBuffer  draw framebuffer.
readBuffer  read framebuffer.
Check that the context's and framebuffer's visuals are compatible, returning immediately otherwise. Sets the glapi current context via _glapi_set_context(). If newCtx is not NULL, associates drawBuffer and readBuffer with it and calls dd_function_table::ResizeBuffers if the buffers size has changed. Calls dd_function_table::MakeCurrent callback if defined.

When a context is bound by the first time and the MESA_INFO environment variable is set it calls print_info() as an aid for remote user troubleshooting.

GLboolean _mesa_makeCurrent __GLcontext *    gc
 

Bind context callback.

Parameters:
gc  context.
Returns:
GL_TRUE on success, or GL_FALSE on failure.
Called by window system/device driver (via __GLexports::makeCurrent) when the rendering context is made current.

No-op

void _mesa_notifyDestroy __GLcontext *    gc
 

Window/buffer destruction notification callback.

Parameters:
gc  GL context.
Called when the context's window/buffer is going to be destroyed.

No-op

GLboolean _mesa_notifyResize __GLcontext *    gc
 

Windows/buffer resizing notification callback.

Parameters:
gc  GL context.
Returns:
GL_TRUE on success, or GL_FALSE on failure.

void _mesa_notifySwapBuffers __GLcontext *    gc
 

Swap buffers notification callback.

Parameters:
gc  GL context.
Called by window system just before swapping buffers. We have to finish any pending rendering.

void _mesa_record_error GLcontext   ctx,
GLenum    error
 

Record an error.

Parameters:
ctx  GL context.
error  error code.
Records the given error code and call the driver's dd_function_table::Error function if defined.

See also:
This is called via _mesa_error().

GLboolean _mesa_shareContext __GLcontext *    gc,
__GLcontext *    gcShare
 

Share context callback.

Parameters:
gc  context.
gcShare  shared context.
Returns:
GL_TRUE on success, or GL_FALSE on failure.
Called by window system/device driver (via __GLexports::shareContext)

Update the shared context reference count, gl_shared_state::RefCount.

void add_newer_entrypoints void    [static]
 

If the DRI libGL.so library is old, it may not have the entrypoints for some recent OpenGL extensions.

Dynamically add them now. If we're building stand-alone Mesa where libGL.so has both the dispatcher and driver code, this won't be an issue (and calling this function won't do any harm).

GLboolean alloc_shared_state GLcontext   ctx [static]
 

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.

Returns:
pointer to a gl_shared_state structure on success, or NULL on failure.

GLboolean check_compatible const GLcontext   ctx,
const GLframebuffer   buffer
[static]
 

Check if the given context can render into the given framebuffer by checking visual attributes.

Returns:
GL_TRUE if compatible, GL_FALSE otherwise.

void free_shared_state GLcontext   ctx,
struct gl_shared_state   ss
[static]
 

Deallocate a shared state context and all children structures.

Parameters:
ctx  GL context.
ss  shared state pointer.
Frees the display lists, the texture objects (calling the driver texture deletion callback to free its private data) and the vertex programs, as well as their hash tables.

See also:
alloc_shared_state().

GLboolean init_attrib_groups GLcontext   ctx [static]
 

Initialize the attribute groups in a GL context.

Parameters:
ctx  GL context.
Initializes all the attributes, calling the respective init* functions for the more complex data structures.

void one_time_init GLcontext   ctx [static]
 

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 MESA_DEBUG environment variable is defined.

See also:
_mesa_init_lists(), _math_init().


Variable Documentation

GLfloat _mesa_ubyte_to_float_color_tab[256]
 

Convert GLubyte in [0,255] to GLfloat in [0.0,1.0].


Generated on Sun May 16 15:55:11 2004 for Mesa Core by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001