-/* $Id: context.c,v 1.28 1999/12/17 12:21:38 brianp Exp $ */
+/* $Id: context.c,v 1.29 1999/12/17 14:52:35 brianp Exp $ */
/*
* Mesa 3-D graphics library
/**********************************************************************/
-#ifdef THREADS
+#if !defined(THREADS)
-#include "glthread.h"
-
-static _glthread_TSD ContextTSD;
-
-static void ctx_thread_init()
-{
- _glthread_InitTSD(&ContextTSD);
-}
-
-#else
-
-/* One Current Context pointer for all threads in the address space */
-GLcontext *_mesa_current_context = NULL;
struct immediate *CURRENT_INPUT = NULL;
-#endif /*THREADS*/
+#endif
+
+/*
+ * Create a new framebuffer. A GLframebuffer is a struct which
+ * encapsulates the depth, stencil and accum buffers and related
+ * parameters.
+ * Input: visual - a GLvisual pointer
+ * 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?
+
+ * Return: pointer to new GLframebuffer struct or NULL if error.
+ */
+GLframebuffer *gl_create_framebuffer( GLvisual *visual,
+ GLboolean softwareDepth,
+ GLboolean softwareStencil,
+ GLboolean softwareAccum,
+ GLboolean softwareAlpha )
+{
+ GLframebuffer *buffer;
+
+ buffer = CALLOC_STRUCT(gl_frame_buffer);
+ if (!buffer) {
+ return NULL;
+ }
+
+ /* sanity checks */
+ if (softwareDepth ) {
+ assert(visual->DepthBits > 0);
+ }
+ if (softwareStencil) {
+ assert(visual->StencilBits > 0);
+ }
+ if (softwareAccum) {
+ assert(visual->RGBAflag);
+ assert(visual->AccumBits > 0);
+ }
+ if (softwareAlpha) {
+ assert(visual->RGBAflag);
+ assert(visual->AlphaBits > 0);
+ }
+
+ buffer->Visual = visual;
+ buffer->UseSoftwareDepthBuffer = softwareDepth;
+ buffer->UseSoftwareStencilBuffer = softwareStencil;
+ buffer->UseSoftwareAccumBuffer = softwareAccum;
+ buffer->UseSoftwareAlphaBuffers = softwareAlpha;
+
+ return buffer;
+}
+
+
+
+/*
+ * Free a framebuffer struct and its buffers.
+ */
+void gl_destroy_framebuffer( GLframebuffer *buffer )
+{
+ if (buffer) {
+ if (buffer->Depth) {
+ FREE( buffer->Depth );
+ }
+ if (buffer->Accum) {
+ FREE( buffer->Accum );
+ }
+ if (buffer->Stencil) {
+ FREE( buffer->Stencil );
+ }
+ if (buffer->FrontLeftAlpha) {
+ FREE( buffer->FrontLeftAlpha );
+ }
+ if (buffer->BackLeftAlpha) {
+ FREE( buffer->BackLeftAlpha );
+ }
+ if (buffer->FrontRightAlpha) {
+ FREE( buffer->FrontRightAlpha );
+ }
+ if (buffer->BackRightAlpha) {
+ FREE( buffer->BackRightAlpha );
+ }
+ FREE(buffer);
+ }
+}
+
+
+
+
/*
* Allocate the proxy textures. If we run out of memory part way through
* the allocations clean up and return GL_FALSE.
return ctx;
}
-/* Just reads the config files...
- */
-void gl_context_initialize( GLcontext *ctx )
-{
- gl_read_config_file( ctx );
-}
-
-
/*
/*
- * Create a new framebuffer. A GLframebuffer is a struct which
- * encapsulates the depth, stencil and accum buffers and related
- * parameters.
- * Input: visual - a GLvisual pointer
- * 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?
-
- * Return: pointer to new GLframebuffer struct or NULL if error.
+ * Just reads the config files...
*/
-GLframebuffer *gl_create_framebuffer( GLvisual *visual,
- GLboolean softwareDepth,
- GLboolean softwareStencil,
- GLboolean softwareAccum,
- GLboolean softwareAlpha )
+void gl_context_initialize( GLcontext *ctx )
{
- GLframebuffer *buffer;
-
- buffer = CALLOC_STRUCT(gl_frame_buffer);
- if (!buffer) {
- return NULL;
- }
-
- /* sanity checks */
- if (softwareDepth ) {
- assert(visual->DepthBits > 0);
- }
- if (softwareStencil) {
- assert(visual->StencilBits > 0);
- }
- if (softwareAccum) {
- assert(visual->RGBAflag);
- assert(visual->AccumBits > 0);
- }
- if (softwareAlpha) {
- assert(visual->RGBAflag);
- assert(visual->AlphaBits > 0);
- }
-
- buffer->Visual = visual;
- buffer->UseSoftwareDepthBuffer = softwareDepth;
- buffer->UseSoftwareStencilBuffer = softwareStencil;
- buffer->UseSoftwareAccumBuffer = softwareAccum;
- buffer->UseSoftwareAlphaBuffers = softwareAlpha;
-
- return buffer;
+ gl_read_config_file( ctx );
}
/*
- * Free a framebuffer struct and its buffers.
+ * Copy attribute groups from one context to another.
+ * Input: src - source context
+ * dst - destination context
+ * mask - bitwise OR of GL_*_BIT flags
*/
-void gl_destroy_framebuffer( GLframebuffer *buffer )
+void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
{
- if (buffer) {
- if (buffer->Depth) {
- FREE( buffer->Depth );
- }
- if (buffer->Accum) {
- FREE( buffer->Accum );
- }
- if (buffer->Stencil) {
- FREE( buffer->Stencil );
- }
- if (buffer->FrontLeftAlpha) {
- FREE( buffer->FrontLeftAlpha );
- }
- if (buffer->BackLeftAlpha) {
- FREE( buffer->BackLeftAlpha );
- }
- if (buffer->FrontRightAlpha) {
- FREE( buffer->FrontRightAlpha );
- }
- if (buffer->BackRightAlpha) {
- FREE( buffer->BackRightAlpha );
+ if (mask & GL_ACCUM_BUFFER_BIT) {
+ MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
+ }
+ if (mask & GL_COLOR_BUFFER_BIT) {
+ MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
+ }
+ if (mask & GL_CURRENT_BIT) {
+ MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
+ }
+ if (mask & GL_DEPTH_BUFFER_BIT) {
+ MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
+ }
+ if (mask & GL_ENABLE_BIT) {
+ /* no op */
+ }
+ if (mask & GL_EVAL_BIT) {
+ MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
+ }
+ if (mask & GL_FOG_BIT) {
+ MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
+ }
+ if (mask & GL_HINT_BIT) {
+ MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
+ }
+ if (mask & GL_LIGHTING_BIT) {
+ MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
+ /* gl_reinit_light_attrib( &dst->Light ); */
+ }
+ if (mask & GL_LINE_BIT) {
+ MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
+ }
+ if (mask & GL_LIST_BIT) {
+ MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
+ }
+ if (mask & GL_PIXEL_MODE_BIT) {
+ MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
+ }
+ if (mask & GL_POINT_BIT) {
+ MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
+ }
+ if (mask & GL_POLYGON_BIT) {
+ MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
+ }
+ if (mask & GL_POLYGON_STIPPLE_BIT) {
+ /* Use loop instead of MEMCPY due to problem with Portland Group's
+ * C compiler. Reported by John Stone.
+ */
+ int i;
+ for (i=0;i<32;i++) {
+ dst->PolygonStipple[i] = src->PolygonStipple[i];
}
- FREE(buffer);
+ }
+ if (mask & GL_SCISSOR_BIT) {
+ MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
+ }
+ if (mask & GL_STENCIL_BUFFER_BIT) {
+ MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
+ }
+ if (mask & GL_TEXTURE_BIT) {
+ MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
+ }
+ if (mask & GL_TRANSFORM_BIT) {
+ MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
+ }
+ if (mask & GL_VIEWPORT_BIT) {
+ MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
}
}
-
/*
* Set the current context, binding the given frame buffer to the context.
*/
}
#endif
+ /* We call this function periodically (just here for now) in
+ * order to detect when multithreading has begun.
+ */
_glapi_check_multithread();
-#ifdef THREADS
- _glthread_SetTSD(&ContextTSD, (void *) newCtx, ctx_thread_init);
+ _glapi_set_current_context((void *) newCtx);
ASSERT(gl_get_current_context() == newCtx);
-#else
- _mesa_current_context = newCtx;
-#endif
if (newCtx) {
SET_IMMEDIATE(newCtx, newCtx->input);
_glapi_set_dispatch(newCtx->CurrentDispatch);
/*
* Return current context handle for the calling thread.
+ * This isn't the fastest way to get the current context.
+ * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
*/
GLcontext *gl_get_current_context( void )
{
-#ifdef THREADS
- GLcontext *c = (GLcontext *) _glthread_GetTSD(&ContextTSD);
- return c;
-#else
- return _mesa_current_context;
-#endif
+ return (GLcontext *) _glapi_get_current_context();
}
-/*
- * Copy attribute groups from one context to another.
- * Input: src - source context
- * dst - destination context
- * mask - bitwise OR of GL_*_BIT flags
- */
-void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
-{
- if (mask & GL_ACCUM_BUFFER_BIT) {
- MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
- }
- if (mask & GL_COLOR_BUFFER_BIT) {
- MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
- }
- if (mask & GL_CURRENT_BIT) {
- MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
- }
- if (mask & GL_DEPTH_BUFFER_BIT) {
- MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
- }
- if (mask & GL_ENABLE_BIT) {
- /* no op */
- }
- if (mask & GL_EVAL_BIT) {
- MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
- }
- if (mask & GL_FOG_BIT) {
- MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
- }
- if (mask & GL_HINT_BIT) {
- MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
- }
- if (mask & GL_LIGHTING_BIT) {
- MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
-/* gl_reinit_light_attrib( &dst->Light ); */
- }
- if (mask & GL_LINE_BIT) {
- MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
- }
- if (mask & GL_LIST_BIT) {
- MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
- }
- if (mask & GL_PIXEL_MODE_BIT) {
- MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
- }
- if (mask & GL_POINT_BIT) {
- MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
- }
- if (mask & GL_POLYGON_BIT) {
- MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
- }
- if (mask & GL_POLYGON_STIPPLE_BIT) {
- /* Use loop instead of MEMCPY due to problem with Portland Group's
- * C compiler. Reported by John Stone.
- */
- int i;
- for (i=0;i<32;i++) {
- dst->PolygonStipple[i] = src->PolygonStipple[i];
- }
- }
- if (mask & GL_SCISSOR_BIT) {
- MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
- }
- if (mask & GL_STENCIL_BUFFER_BIT) {
- MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
- }
- if (mask & GL_TEXTURE_BIT) {
- MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
- }
- if (mask & GL_TRANSFORM_BIT) {
- MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
- }
- if (mask & GL_VIEWPORT_BIT) {
- MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
- }
-}
-
-
/*
* This should be called by device drivers just before they do a
* swapbuffers. Any pending rendering commands will be executed.
}
+
/*
* Return pointer to this context's current API dispatch table.
* It'll either be the immediate-mode execute dispatcher or the
void
_mesa_ResizeBuffersMESA( void )
{
- GET_CURRENT_CONTEXT(ctx);
+ GLcontext *ctx = gl_get_current_context();
GLuint buf_width, buf_height;
/* Reallocate other buffers if needed. */
if (ctx->DrawBuffer->UseSoftwareDepthBuffer) {
- /* reallocate depth buffer */
gl_alloc_depth_buffer( ctx );
}
if (ctx->DrawBuffer->UseSoftwareStencilBuffer) {
- /* reallocate stencil buffer */
gl_alloc_stencil_buffer( ctx );
}
if (ctx->DrawBuffer->UseSoftwareAccumBuffer) {
- /* reallocate accum buffer */
gl_alloc_accum_buffer( ctx );
}
if (ctx->Visual->SoftwareAlpha) {
-/* $Id: context.h,v 1.6 1999/12/17 12:21:39 brianp Exp $ */
+/* $Id: context.h,v 1.7 1999/12/17 14:52:37 brianp Exp $ */
/*
* Mesa 3-D graphics library
#define CONTEXT_H
+#include "glapi.h"
#include "types.h"
extern void gl_destroy_visual( GLvisual *vis );
+/*
+ * Create/destroy a GLframebuffer. A GLframebuffer is like a GLX drawable.
+ * It bundles up the depth buffer, stencil buffer and accum buffers into a
+ * single entity.
+ */
+extern GLframebuffer *gl_create_framebuffer( GLvisual *visual,
+ GLboolean softwareDepth,
+ GLboolean softwareStencil,
+ GLboolean softwareAccum,
+ GLboolean softwareAlpha );
+
+extern void gl_destroy_framebuffer( GLframebuffer *buffer );
+
+
+
/*
* Create/destroy a GLcontext. A GLcontext is like a GLX context. It
* contains the rendering state.
extern void gl_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
-/*
- * Create/destroy a GLframebuffer. A GLframebuffer is like a GLX drawable.
- * It bundles up the depth buffer, stencil buffer and accum buffers into a
- * single entity.
- */
-extern GLframebuffer *gl_create_framebuffer( GLvisual *visual,
- GLboolean softwareDepth,
- GLboolean softwareStencil,
- GLboolean softwareAccum,
- GLboolean softwareAlpha );
-
-extern void gl_destroy_framebuffer( GLframebuffer *buffer );
-
-
-
extern void gl_make_current( GLcontext *ctx, GLframebuffer *buffer );
+
extern void gl_make_current2( GLcontext *ctx, GLframebuffer *drawBuffer,
GLframebuffer *readBuffer );
-extern GLcontext *gl_get_current_context(void);
+extern GLcontext *gl_get_current_context(void);
-#ifdef THREADS
/*
- * A seperate GLcontext for each thread
+ * Macros for fetching current context, input buffer, etc.
*/
-#define GET_CURRENT_CONTEXT(C) GLcontext *C = gl_get_current_context()
-#define GET_IMMEDIATE struct immediate *IM = (gl_get_current_context())->input;
+#ifdef THREADS
+
+#define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_ThreadSafe ? _glapi_get_current_context() : _glapi_CurrentContext)
+
+#define GET_IMMEDIATE struct immediate *IM = ((GLcontext *) _glapi_get_current_context())->input;
#define SET_IMMEDIATE(ctx, im) \
do { \
ctx->input = im; \
#else
-/*
- * All threads use same pointer to current context.
- */
-extern GLcontext *_mesa_current_context;
extern struct immediate *CURRENT_INPUT;
-#define GET_CURRENT_CONTEXT(C) GLcontext *C = _mesa_current_context
+#define GET_CURRENT_CONTEXT(C) GLcontext *C = _glapi_CurrentContext
#define GET_IMMEDIATE struct immediate *IM = CURRENT_INPUT
#define SET_IMMEDIATE(ctx, im) \
do { \
extern void
_mesa_swapbuffers(GLcontext *ctx);
+
extern struct _glapi_table *
_mesa_get_dispatch(GLcontext *ctx);
extern void gl_warning( const GLcontext *ctx, const char *s );
extern void gl_error( GLcontext *ctx, GLenum error, const char *s );
-extern void gl_compile_error( GLcontext *ctx, GLenum error, const char *s );
+extern void gl_compile_error( GLcontext *ctx, GLenum error, const char *s );
extern void gl_update_state( GLcontext *ctx );