-/* $Id: context.c,v 1.27 1999/12/10 19:09:21 brianp Exp $ */
+/* $Id: context.c,v 1.28 1999/12/17 12:21:38 brianp Exp $ */
/*
* Mesa 3-D graphics library
*/
-/*
- * If multi-threading is enabled (-DTHREADS) then each thread has it's
- * own rendering context. A thread obtains the pointer to its GLcontext
- * with the gl_get_thread_context() function. Otherwise, the global
- * pointer, CC, points to the current context used by all threads in
- * the address space.
- */
-
-
#ifdef PC_HEADER
#include "all.h"
#else
#ifdef THREADS
-#include "mthreads.h"
-static MesaTSD mesa_ctx_tsd;
-static void mesa_ctx_thread_init() {
- MesaInitTSD(&mesa_ctx_tsd);
+#include "glthread.h"
+
+static _glthread_TSD ContextTSD;
+
+static void ctx_thread_init()
+{
+ _glthread_InitTSD(&ContextTSD);
}
#else
}
- /* Fill in some driver defaults now.
- */
-#if 0
- ctx->Driver.AllocDepthBuffer = gl_alloc_depth_buffer;
- ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float;
- ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int;
-#endif
-
#ifdef PROFILE
init_timings( ctx );
#endif
GLuint i;
struct gl_shine_tab *s, *tmps;
+ /* if we're destroying the current context, unbind it first */
+ if (ctx == gl_get_current_context()) {
+ gl_make_current(NULL, NULL);
+ }
+
#ifdef PROFILE
if (getenv("MESA_PROFILE")) {
print_timings( ctx );
gl_extensions_dtr(ctx);
FREE( (void *) ctx );
-
-#ifndef THREADS
- if (ctx == _mesa_current_context) {
- _mesa_current_context = NULL;
- CURRENT_INPUT = NULL;
- }
-#endif
-
}
}
void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
GLframebuffer *readBuffer )
{
- GET_CURRENT_CONTEXT(oldCtx);
+#if 0
+ GLcontext *oldCtx = gl_get_current_context();
/* Flush the old context
*/
if (oldCtx) {
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
- }
- /* unbind frame buffers from context */
- if (oldCtx && oldCtx->DrawBuffer) {
- oldCtx->DrawBuffer = NULL;
- }
- if (oldCtx && oldCtx->ReadBuffer) {
- oldCtx->ReadBuffer = NULL;
+ /* unbind frame buffers from context */
+ if (oldCtx->DrawBuffer) {
+ oldCtx->DrawBuffer = NULL;
+ }
+ if (oldCtx->ReadBuffer) {
+ oldCtx->ReadBuffer = NULL;
+ }
}
+#endif
+
+ _glapi_check_multithread();
#ifdef THREADS
- /* TODO: unbind old buffer from context? */
- MesaSetTSD(&mesa_ctx_tsd, (void *) newCtx, mesa_ctx_thread_init);
+ _glthread_SetTSD(&ContextTSD, (void *) newCtx, ctx_thread_init);
+ ASSERT(gl_get_current_context() == newCtx);
#else
_mesa_current_context = newCtx;
#endif
if (newCtx) {
SET_IMMEDIATE(newCtx, newCtx->input);
- }
-
- if (newCtx)
_glapi_set_dispatch(newCtx->CurrentDispatch);
- else
+ }
+ else {
_glapi_set_dispatch(NULL); /* none current */
+ }
if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
GLcontext *gl_get_current_context( void )
{
#ifdef THREADS
- return (GLcontext *) MesaGetTSD(&mesa_ctx_tsd);
+ GLcontext *c = (GLcontext *) _glthread_GetTSD(&ContextTSD);
+ return c;
#else
return _mesa_current_context;
#endif
-/* $Id: context.h,v 1.5 1999/12/10 19:09:22 brianp Exp $ */
+/* $Id: context.h,v 1.6 1999/12/17 12:21:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
#ifdef THREADS
- /*
- * A seperate GLcontext for each thread
- */
-
- #define GET_CURRENT_CONTEXT(C) GLcontext *C = gl_get_current_context()
+/*
+ * A seperate GLcontext for each thread
+ */
+#define GET_CURRENT_CONTEXT(C) GLcontext *C = gl_get_current_context()
#define GET_IMMEDIATE struct immediate *IM = (gl_get_current_context())->input;
#define SET_IMMEDIATE(ctx, im) \
do { \
ctx->input = im; \
} while (0)
-
#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
+/*
+ * 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_IMMEDIATE struct immediate *IM = CURRENT_INPUT
#define SET_IMMEDIATE(ctx, im) \
do { \
CURRENT_INPUT = im; \
} while (0)
-
#endif