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.c220
1 files changed, 117 insertions, 103 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index e5ec35c77f..a94bbf3fdf 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1,14 +1,9 @@
-/**
- * \file context.c
- * Mesa context/visual/framebuffer management functions.
- * \author Brian Paul
- */
-
/*
* Mesa 3-D graphics library
- * Version: 6.5
+ * Version: 7.3
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ * Copyright (C) 2008 VMware, Inc. 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"),
@@ -28,6 +23,11 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+/**
+ * \file context.c
+ * Mesa context/visual/framebuffer management functions.
+ * \author Brian Paul
+ */
/**
* \mainpage Mesa Main Module
@@ -77,6 +77,7 @@
#include "glheader.h"
+#include "mfeatures.h"
#include "imports.h"
#if FEATURE_accum
#include "accum.h"
@@ -151,10 +152,7 @@
#include "shader/atifragshader.h"
#endif
#if _HAVE_FULL_GL
-#include "math/m_translate.h"
#include "math/m_matrix.h"
-#include "math/m_xform.h"
-#include "math/mathmod.h"
#endif
#ifdef USE_SPARC_ASM
@@ -186,6 +184,7 @@ GLfloat _mesa_ubyte_to_float_color_tab[256];
void
_mesa_notifySwapBuffers(__GLcontext *ctx)
{
+ FLUSH_VERTICES( ctx, 0 );
if (ctx->Driver.Flush) {
ctx->Driver.Flush(ctx);
}
@@ -387,13 +386,9 @@ one_time_init( GLcontext *ctx )
_mesa_init_sqrt_table();
-#if _HAVE_FULL_GL
- _math_init();
-
for (i = 0; i < 256; i++) {
_mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
}
-#endif
#ifdef USE_SPARC_ASM
_mesa_init_sparc_glapi_relocs();
@@ -429,6 +424,7 @@ one_time_init( GLcontext *ctx )
static GLboolean
alloc_shared_state( GLcontext *ctx )
{
+ GLuint i;
struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
if (!ss)
return GL_FALSE;
@@ -470,36 +466,25 @@ alloc_shared_state( GLcontext *ctx )
ss->ShaderObjects = _mesa_NewHashTable();
#endif
- ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
- if (!ss->Default1D)
- goto cleanup;
-
- ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
- if (!ss->Default2D)
- goto cleanup;
-
- ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
- if (!ss->Default3D)
- goto cleanup;
-
- ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
- if (!ss->DefaultCubeMap)
- goto cleanup;
-
- ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
- if (!ss->DefaultRect)
- goto cleanup;
-
- ss->Default1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT);
- if (!ss->Default1DArray)
- goto cleanup;
-
- ss->Default2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT);
- if (!ss->Default2DArray)
- goto cleanup;
+ /* Create default texture objects */
+ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
+ /* NOTE: the order of these enums matches the TEXTURE_x_INDEX values */
+ static const GLenum targets[NUM_TEXTURE_TARGETS] = {
+ GL_TEXTURE_2D_ARRAY_EXT,
+ GL_TEXTURE_1D_ARRAY_EXT,
+ GL_TEXTURE_CUBE_MAP,
+ GL_TEXTURE_3D,
+ GL_TEXTURE_RECTANGLE_NV,
+ GL_TEXTURE_2D,
+ GL_TEXTURE_1D
+ };
+ ss->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]);
+ if (!ss->DefaultTex[i])
+ goto cleanup;
+ }
/* sanity check */
- assert(ss->Default1D->RefCount == 1);
+ assert(ss->DefaultTex[TEXTURE_1D_INDEX]->RefCount == 1);
_glthread_INIT_MUTEX(ss->TexMutex);
ss->TextureStateStamp = 0;
@@ -553,20 +538,10 @@ cleanup:
_mesa_DeleteHashTable(ss->RenderBuffers);
#endif
- if (ss->Default1D)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
- if (ss->Default2D)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
- if (ss->Default3D)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
- if (ss->DefaultCubeMap)
- (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
- if (ss->DefaultRect)
- (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
- if (ss->Default1DArray)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default1DArray);
- if (ss->Default2DArray)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default2DArray);
+ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
+ if (ss->DefaultTex[i])
+ ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
+ }
_mesa_free(ss);
@@ -581,7 +556,7 @@ static void
delete_displaylist_cb(GLuint id, void *data, void *userData)
{
#if FEATURE_dlist
- struct mesa_display_list *list = (struct mesa_display_list *) data;
+ struct gl_display_list *list = (struct gl_display_list *) data;
GLcontext *ctx = (GLcontext *) userData;
_mesa_delete_list(ctx, list);
#endif
@@ -729,6 +704,8 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData)
static void
free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
{
+ GLuint i;
+
/*
* Free display lists
*/
@@ -778,13 +755,9 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
*/
ASSERT(ctx->Driver.DeleteTexture);
/* the default textures */
- ctx->Driver.DeleteTexture(ctx, ss->Default1D);
- ctx->Driver.DeleteTexture(ctx, ss->Default2D);
- ctx->Driver.DeleteTexture(ctx, ss->Default3D);
- ctx->Driver.DeleteTexture(ctx, ss->DefaultCubeMap);
- ctx->Driver.DeleteTexture(ctx, ss->DefaultRect);
- ctx->Driver.DeleteTexture(ctx, ss->Default1DArray);
- ctx->Driver.DeleteTexture(ctx, ss->Default2DArray);
+ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
+ ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
+ }
/* all other textures */
_mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx);
_mesa_DeleteHashTable(ss->TexObjects);
@@ -809,7 +782,7 @@ _mesa_init_current(GLcontext *ctx)
}
/* redo special cases: */
- ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 1.0 );
+ ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
@@ -870,8 +843,8 @@ _mesa_init_constants(GLcontext *ctx)
assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
- assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_COORD_UNITS);
- assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_IMAGE_UNITS);
+ /* Max texture size should be <= max viewport size (render to texture) */
+ assert((1 << (MAX_TEXTURE_LEVELS - 1)) <= MAX_WIDTH);
/* Constants, may be overriden (usually only reduced) by device drivers */
ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
@@ -935,6 +908,9 @@ _mesa_init_constants(GLcontext *ctx)
ctx->Const.MaxVarying = MAX_VARYING;
#endif
+ /* GL_ARB_framebuffer_object */
+ ctx->Const.MaxSamples = 0;
+
/* sanity checks */
ASSERT(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
ctx->Const.MaxTextureCoordUnits));
@@ -963,13 +939,21 @@ check_context_limits(GLcontext *ctx)
assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
- assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
- assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
+ /* number of coord units cannot be greater than number of image units */
+ assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
+
+ assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
+ assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
+ assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
+ assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
/* make sure largest texture image is <= MAX_WIDTH in size */
- assert((1 << (ctx->Const.MaxTextureLevels -1 )) <= MAX_WIDTH);
- assert((1 << (ctx->Const.MaxCubeTextureLevels -1 )) <= MAX_WIDTH);
- assert((1 << (ctx->Const.Max3DTextureLevels -1 )) <= MAX_WIDTH);
+ assert((1 << (ctx->Const.MaxTextureLevels - 1)) <= MAX_WIDTH);
+ assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= MAX_WIDTH);
+ assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= MAX_WIDTH);
+
+ assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
+ assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
@@ -1063,7 +1047,6 @@ init_attrib_groups(GLcontext *ctx)
/* Miscellaneous */
ctx->NewState = _NEW_ALL;
ctx->ErrorValue = (GLenum) GL_NO_ERROR;
- ctx->_Facing = 0;
ctx->varying_vp_inputs = ~0;
return GL_TRUE;
@@ -1071,6 +1054,28 @@ init_attrib_groups(GLcontext *ctx)
/**
+ * Update default objects in a GL context with respect to shared state.
+ *
+ * \param ctx GL context.
+ *
+ * Removes references to old default objects, (texture objects, program
+ * objects, etc.) and changes to reference those from the current shared
+ * state.
+ */
+static GLboolean
+update_default_objects(GLcontext *ctx)
+{
+ assert(ctx);
+
+ _mesa_update_default_objects_program(ctx);
+ _mesa_update_default_objects_texture(ctx);
+ _mesa_update_default_objects_buffer_objects(ctx);
+
+ return GL_TRUE;
+}
+
+
+/**
* This is the default function we plug into all dispatch table slots
* This helps prevents a segfault when someone calls a GL function without
* first checking if the extension's supported.
@@ -1205,7 +1210,6 @@ _mesa_initialize_context(GLcontext *ctx,
ctx->FragmentProgram._MaintainTexEnvProgram
= (_mesa_getenv("MESA_TEX_PROG") != NULL);
- ctx->FragmentProgram._UseTexEnvProgram = ctx->FragmentProgram._MaintainTexEnvProgram;
ctx->VertexProgram._MaintainTnlProgram
= (_mesa_getenv("MESA_TNL_PROG") != NULL);
@@ -1274,18 +1278,19 @@ _mesa_create_context(const GLvisual *visual,
void
_mesa_free_context_data( GLcontext *ctx )
{
- /* if we're destroying the current context, unbind it first */
- if (ctx == _mesa_get_current_context()) {
- _mesa_make_current(NULL, NULL, NULL);
- }
- else {
- /* unreference WinSysDraw/Read buffers */
- _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer);
- _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer);
- _mesa_unreference_framebuffer(&ctx->DrawBuffer);
- _mesa_unreference_framebuffer(&ctx->ReadBuffer);
+ if (!_mesa_get_current_context()){
+ /* No current context, but we may need one in order to delete
+ * texture objs, etc. So temporarily bind the context now.
+ */
+ _mesa_make_current(ctx, NULL, NULL);
}
+ /* unreference WinSysDraw/Read buffers */
+ _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL);
+ _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL);
+ _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL);
+ _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL);
+
_mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
@@ -1294,6 +1299,9 @@ _mesa_free_context_data( GLcontext *ctx )
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
+#if FEATURE_attrib_stack
+ _mesa_free_attrib_data(ctx);
+#endif
_mesa_free_lighting_data( ctx );
#if FEATURE_evaluators
_mesa_free_eval_data( ctx );
@@ -1331,6 +1339,11 @@ _mesa_free_context_data( GLcontext *ctx )
if (ctx->Extensions.String)
_mesa_free((void *) ctx->Extensions.String);
+
+ /* unbind the context if it's currently bound */
+ if (ctx == _mesa_get_current_context()) {
+ _mesa_make_current(NULL, NULL, NULL);
+ }
}
@@ -1562,8 +1575,6 @@ void
_mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
GLframebuffer *readBuffer )
{
- GET_CURRENT_CONTEXT(oldCtx);
-
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(newCtx, "_mesa_make_current()\n");
@@ -1588,13 +1599,6 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
_glapi_set_context((void *) newCtx);
ASSERT(_mesa_get_current_context() == newCtx);
- if (oldCtx) {
- _mesa_unreference_framebuffer(&oldCtx->WinSysDrawBuffer);
- _mesa_unreference_framebuffer(&oldCtx->WinSysReadBuffer);
- _mesa_unreference_framebuffer(&oldCtx->DrawBuffer);
- _mesa_unreference_framebuffer(&oldCtx->ReadBuffer);
- }
-
if (!newCtx) {
_glapi_set_dispatch(NULL); /* none current */
}
@@ -1614,10 +1618,12 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
* or not bound to a user-created FBO.
*/
if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
- /* fix up the fb fields - these will end up wrong otherwise
- * if the DRIdrawable changes, and everything relies on them.
- * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
- */
+ /* KW: merge conflict here, revisit.
+ */
+ /* fix up the fb fields - these will end up wrong otherwise
+ * if the DRIdrawable changes, and everything relies on them.
+ * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
+ */
unsigned int i;
GLenum buffers[MAX_DRAW_BUFFERS];
@@ -1631,9 +1637,11 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
}
if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
_mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
- _mesa_readbuffer_update_fields(newCtx, newCtx->Pixel.ReadBuffer);
}
+ /* XXX only set this flag if we're really changing the draw/read
+ * framebuffer bindings.
+ */
newCtx->NewState |= _NEW_BUFFERS;
#if 1
@@ -1701,12 +1709,18 @@ GLboolean
_mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
{
if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
- ctx->Shared->RefCount--;
- if (ctx->Shared->RefCount == 0) {
- free_shared_state(ctx, ctx->Shared);
- }
+ struct gl_shared_state *oldSharedState = ctx->Shared;
+
ctx->Shared = ctxToShare->Shared;
ctx->Shared->RefCount++;
+
+ update_default_objects(ctx);
+
+ oldSharedState->RefCount--;
+ if (oldSharedState->RefCount == 0) {
+ free_shared_state(ctx, oldSharedState);
+ }
+
return GL_TRUE;
}
else {