summaryrefslogtreecommitdiff
path: root/src/mesa/main/context.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/context.c')
-rw-r--r--src/mesa/main/context.c260
1 files changed, 104 insertions, 156 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 628e734191..cf8bb8bd47 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1,8 +1,8 @@
-/* $Id: context.c,v 1.18 1999/11/08 07:36:43 brianp Exp $ */
+/* $Id: context.c,v 1.19 1999/11/11 01:22:25 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.1
+ * Version: 3.3
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
@@ -25,8 +25,6 @@
*/
-/* $XFree86: xc/lib/GL/mesa/src/context.c,v 1.4 1999/04/04 00:20:21 dawes Exp $ */
-
/*
* If multi-threading is enabled (-DTHREADS) then each thread has it's
* own rendering context. A thread obtains the pointer to its GLcontext
@@ -36,42 +34,34 @@
*/
-
#ifdef PC_HEADER
#include "all.h"
#else
-#ifndef XFree86Server
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#else
-#include "GL/xf86glx.h"
-#endif
+#include "glheader.h"
#include "accum.h"
#include "alphabuf.h"
-#include "api.h"
#include "clip.h"
#include "context.h"
#include "cva.h"
#include "depth.h"
+#include "dispatch.h"
#include "dlist.h"
#include "eval.h"
#include "enums.h"
#include "extensions.h"
#include "fog.h"
+#include "glapi.h"
#include "hash.h"
#include "light.h"
#include "lines.h"
#include "dlist.h"
#include "macros.h"
#include "matrix.h"
+#include "mem.h"
#include "mmath.h"
#include "pb.h"
#include "pipeline.h"
#include "points.h"
-#include "pointers.h"
#include "quads.h"
#include "shade.h"
#include "simple_list.h"
@@ -95,40 +85,6 @@
#endif
-/*
- * Memory allocation functions. Called via the MALLOC, CALLOC and
- * FREE macros when DEBUG symbol is defined.
- * You might want to set breakpoints on these functions or plug in
- * other memory allocation functions. The Mesa sources should only
- * use the MALLOC and FREE macros (which could also be overriden).
- *
- * XXX these functions should probably go into a new glmemory.c file.
- */
-
-/*
- * Allocate memory (uninitialized)
- */
-void *gl_malloc(size_t bytes)
-{
- return malloc(bytes);
-}
-
-/*
- * Allocate memory and initialize to zero.
- */
-void *gl_calloc(size_t bytes)
-{
- return calloc(1, bytes);
-}
-
-/*
- * Free memory
- */
-void gl_free(void *ptr)
-{
- free(ptr);
-}
-
/**********************************************************************/
/***** Context and Thread management *****/
@@ -157,7 +113,7 @@ static void set_thread_context( GLcontext *ctx ) {
#else
/* One Current Context pointer for all threads in the address space */
-GLcontext *CC = NULL;
+GLcontext *_mesa_current_context = NULL;
struct immediate *CURRENT_INPUT = NULL;
#endif /*THREADS*/
@@ -578,7 +534,6 @@ static void init_1d_map( struct gl_1d_map *map, int n, const float *initial )
for (i=0;i<n;i++)
map->Points[i] = initial[i];
}
- map->Retain = GL_FALSE;
}
@@ -597,10 +552,20 @@ static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
for (i=0;i<n;i++)
map->Points[i] = initial[i];
}
- map->Retain = GL_FALSE;
}
+static void init_palette( struct gl_palette *p )
+{
+ p->Table[0] = 255;
+ p->Table[1] = 255;
+ p->Table[2] = 255;
+ p->Table[3] = 255;
+ p->Size = 1;
+ p->IntFormat = GL_RGBA;
+ p->Format = GL_RGBA;
+}
+
/*
* Initialize a gl_context structure to default values.
@@ -929,14 +894,7 @@ static void initialize_context( GLcontext *ctx )
for (i=0; i<MAX_TEXTURE_UNITS; i++)
init_texture_unit( ctx, i );
- ctx->Texture.SharedPalette = GL_FALSE;
- ctx->Texture.Palette[0] = 255;
- ctx->Texture.Palette[1] = 255;
- ctx->Texture.Palette[2] = 255;
- ctx->Texture.Palette[3] = 255;
- ctx->Texture.PaletteSize = 1;
- ctx->Texture.PaletteIntFormat = GL_RGBA;
- ctx->Texture.PaletteFormat = GL_RGBA;
+ init_palette(&ctx->Texture.Palette);
/* Transformation group */
ctx->Transform.MatrixMode = GL_MODELVIEW;
@@ -1331,13 +1289,10 @@ GLcontext *gl_create_context( GLvisual *visual,
ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float;
ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int;
-
-
#ifdef PROFILE
init_timings( ctx );
#endif
-#ifdef GL_VERSION_1_1
if (!alloc_proxy_textures(ctx)) {
free_shared_state(ctx, ctx->Shared);
FREE(ctx->VB);
@@ -1345,10 +1300,11 @@ GLcontext *gl_create_context( GLvisual *visual,
FREE(ctx);
return NULL;
}
-#endif
- gl_init_api_function_pointers( ctx );
- ctx->API = ctx->Exec; /* GL_EXECUTE is default */
+ /* setup API dispatch tables */
+ _mesa_init_exec_table( &ctx->Exec );
+ _mesa_init_dlist_table( &ctx->Save );
+ ctx->CurrentDispatch = &ctx->Exec;
return ctx;
}
@@ -1462,8 +1418,8 @@ void gl_destroy_context( GLcontext *ctx )
FREE( (void *) ctx );
#ifndef THREADS
- if (ctx==CC) {
- CC = NULL;
+ if (ctx == _mesa_current_context) {
+ _mesa_current_context = NULL;
CURRENT_INPUT = NULL;
}
#endif
@@ -1532,37 +1488,42 @@ void gl_destroy_framebuffer( GLframebuffer *buffer )
/*
* Set the current context, binding the given frame buffer to the context.
*/
-void gl_make_current( GLcontext *ctx, GLframebuffer *buffer )
+void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
{
- GET_CONTEXT;
+ GET_CURRENT_CONTEXT(oldCtx);
/* Flush the old context
*/
- if (CC) {
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(CC, "gl_make_current");
+ if (oldCtx) {
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
}
#ifdef THREADS
/* TODO: unbind old buffer from context? */
- set_thread_context( ctx );
+ set_thread_context( newCtx );
#else
- if (CC && CC->Buffer) {
+ if (oldCtx && oldCtx->Buffer) {
/* unbind frame buffer from context */
- CC->Buffer = NULL;
+ oldCtx->Buffer = NULL;
}
- CC = ctx;
- if (ctx) {
- SET_IMMEDIATE(ctx, ctx->input);
+ _mesa_current_context = newCtx;
+ if (newCtx) {
+ SET_IMMEDIATE(newCtx, newCtx->input);
}
#endif
+ if (newCtx)
+ _glapi_set_dispatch(newCtx->CurrentDispatch);
+ else
+ _glapi_set_dispatch(NULL); /* none current */
+
if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
- if (ctx && buffer) {
- /* TODO: check if ctx and buffer's visual match??? */
- ctx->Buffer = buffer; /* Bind the frame buffer to the context */
- ctx->NewState = NEW_ALL; /* just to be safe */
- gl_update_state( ctx );
+ if (newCtx && buffer) {
+ /* TODO: check if newCtx and buffer's visual match??? */
+ newCtx->Buffer = buffer; /* Bind the frame buffer to the context */
+ newCtx->NewState = NEW_ALL; /* just to be safe */
+ gl_update_state( newCtx );
}
}
@@ -1575,7 +1536,7 @@ GLcontext *gl_get_current_context( void )
#ifdef THREADS
return gl_get_thread_context();
#else
- return CC;
+ return _mesa_current_context;
#endif
}
@@ -1659,27 +1620,74 @@ void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
}
+/*
+ * This should be called by device drivers just before they do a
+ * swapbuffers. Any pending rendering commands will be executed.
+ */
+void
+_mesa_swapbuffers(GLcontext *ctx)
+{
+ FLUSH_VB( ctx, "swap buffers" );
+}
+
/*
- * Someday a GLS library or OpenGL-like debugger may call this function
- * to register it's own set of API entry points.
- * Input: ctx - the context to set API pointers for
- * api - if NULL, restore original API pointers
- * else, set API function table to this table.
+ * Return pointer to this context's current API dispatch table.
+ * It'll either be the immediate-mode execute dispatcher or the
+ * display list compile dispatcher.
*/
-void gl_set_api_table( GLcontext *ctx, const struct gl_api_table *api )
+struct _glapi_table *
+_mesa_get_dispatch(GLcontext *ctx)
+{
+ return ctx->CurrentDispatch;
+}
+
+
+
+void
+_mesa_ResizeBuffersMESA( void )
{
- if (api) {
- MEMCPY( &ctx->API, api, sizeof(struct gl_api_table) );
+ GET_CURRENT_CONTEXT(ctx);
+
+ GLuint buf_width, buf_height;
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ fprintf(stderr, "glResizeBuffersMESA\n");
+
+ /* ask device driver for size of output buffer */
+ (*ctx->Driver.GetBufferSize)( ctx, &buf_width, &buf_height );
+
+ /* see if size of device driver's color buffer (window) has changed */
+ if (ctx->Buffer->Width == (GLint) buf_width &&
+ ctx->Buffer->Height == (GLint) buf_height)
+ return;
+
+ ctx->NewState |= NEW_RASTER_OPS; /* to update scissor / window bounds */
+
+ /* save buffer size */
+ ctx->Buffer->Width = buf_width;
+ ctx->Buffer->Height = buf_height;
+
+ /* Reallocate other buffers if needed. */
+ if (ctx->Visual->DepthBits>0) {
+ /* reallocate depth buffer */
+ (*ctx->Driver.AllocDepthBuffer)( ctx );
}
- else {
- MEMCPY( &ctx->API, &ctx->Exec, sizeof(struct gl_api_table) );
+ if (ctx->Visual->StencilBits>0) {
+ /* reallocate stencil buffer */
+ gl_alloc_stencil_buffer( ctx );
+ }
+ if (ctx->Visual->AccumBits>0) {
+ /* reallocate accum buffer */
+ gl_alloc_accum_buffer( ctx );
+ }
+ if (ctx->Visual->SoftwareAlpha) {
+ gl_alloc_alpha_buffers( ctx );
}
}
-
/**********************************************************************/
/***** Miscellaneous functions *****/
/**********************************************************************/
@@ -1801,66 +1809,6 @@ void gl_error( GLcontext *ctx, GLenum error, const char *s )
-/*
- * Execute a glGetError command
- */
-GLenum gl_GetError( GLcontext *ctx )
-{
- GLenum e = ctx->ErrorValue;
-
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL( ctx, "glGetError", (GLenum) 0);
-
- if (MESA_VERBOSE & VERBOSE_API)
- fprintf(stderr, "glGetError <-- %s\n", gl_lookup_enum_by_nr(e));
-
- ctx->ErrorValue = (GLenum) GL_NO_ERROR;
- return e;
-}
-
-
-
-void gl_ResizeBuffersMESA( GLcontext *ctx )
-{
- GLuint buf_width, buf_height;
-
- if (MESA_VERBOSE & VERBOSE_API)
- fprintf(stderr, "glResizeBuffersMESA\n");
-
- /* ask device driver for size of output buffer */
- (*ctx->Driver.GetBufferSize)( ctx, &buf_width, &buf_height );
-
- /* see if size of device driver's color buffer (window) has changed */
- if (ctx->Buffer->Width == (GLint) buf_width &&
- ctx->Buffer->Height == (GLint) buf_height)
- return;
-
- ctx->NewState |= NEW_RASTER_OPS; /* to update scissor / window bounds */
-
- /* save buffer size */
- ctx->Buffer->Width = buf_width;
- ctx->Buffer->Height = buf_height;
-
- /* Reallocate other buffers if needed. */
- if (ctx->Visual->DepthBits>0) {
- /* reallocate depth buffer */
- (*ctx->Driver.AllocDepthBuffer)( ctx );
- }
- if (ctx->Visual->StencilBits>0) {
- /* reallocate stencil buffer */
- gl_alloc_stencil_buffer( ctx );
- }
- if (ctx->Visual->AccumBits>0) {
- /* reallocate accum buffer */
- gl_alloc_accum_buffer( ctx );
- }
- if (ctx->Visual->SoftwareAlpha) {
- gl_alloc_alpha_buffers( ctx );
- }
-}
-
-
-
-
/**********************************************************************/
/***** State update logic *****/
/**********************************************************************/