diff options
Diffstat (limited to 'src/mesa/main/context.c')
-rw-r--r-- | src/mesa/main/context.c | 255 |
1 files changed, 149 insertions, 106 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index e5ec35c77fd..97ee925c0bb 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); } @@ -352,6 +351,36 @@ _mesa_destroy_visual( GLvisual *vis ) /**********************************************************************/ /*@{*/ + +/** + * This is lame. gdb only seems to recognize enum types that are + * actually used somewhere. We want to be able to print/use enum + * values such as TEXTURE_2D_INDEX in gdb. But we don't actually use + * the gl_texture_index type anywhere. Thus, this lame function. + */ +static void +dummy_enum_func(void) +{ + gl_buffer_index bi; + gl_colortable_index ci; + gl_face_index fi; + gl_frag_attrib fa; + gl_frag_result fr; + gl_texture_index ti; + gl_vert_attrib va; + gl_vert_result vr; + + (void) bi; + (void) ci; + (void) fi; + (void) fa; + (void) fr; + (void) ti; + (void) va; + (void) vr; +} + + /** * One-time initialization mutex lock. * @@ -387,17 +416,10 @@ 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(); -#endif if (_mesa_getenv("MESA_DEBUG")) { _glapi_noop_enable_warnings(GL_TRUE); _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning ); @@ -414,6 +436,8 @@ one_time_init( GLcontext *ctx ) alreadyCalled = GL_TRUE; } _glthread_UNLOCK_MUTEX(OneTimeLock); + + dummy_enum_func(); } @@ -429,6 +453,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 +495,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 +567,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 +585,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 +733,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 +784,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 +811,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 +872,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 +937,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 +968,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 +1076,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 +1083,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 +1239,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 +1307,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 +1328,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 +1368,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 +1604,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 +1628,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 +1647,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 +1666,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 +1738,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 { |