aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/context.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
committermarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
commit29b86f9852b2b7ecc31cdfee56679537e40bc6e2 (patch)
tree1e6ec8ccf2dbf773260a1953b8e13c49f9b7c5f5 /mesalib/src/mesa/main/context.c
parent529236591df7366479a6fac30b387667678fd1ba (diff)
downloadvcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.gz
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.bz2
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.zip
svn merge -r524:HEAD "^/branches/released" .
Diffstat (limited to 'mesalib/src/mesa/main/context.c')
-rw-r--r--mesalib/src/mesa/main/context.c154
1 files changed, 68 insertions, 86 deletions
diff --git a/mesalib/src/mesa/main/context.c b/mesalib/src/mesa/main/context.c
index 87eae9663..73126b957 100644
--- a/mesalib/src/mesa/main/context.c
+++ b/mesalib/src/mesa/main/context.c
@@ -93,13 +93,11 @@
#include "depth.h"
#include "dlist.h"
#include "eval.h"
-#include "enums.h"
#include "extensions.h"
#include "fbobject.h"
#include "feedback.h"
#include "fog.h"
#include "framebuffer.h"
-#include "get.h"
#include "histogram.h"
#include "hint.h"
#include "hash.h"
@@ -124,8 +122,6 @@
#include "state.h"
#include "stencil.h"
#include "texcompress_s3tc.h"
-#include "teximage.h"
-#include "texobj.h"
#include "texstate.h"
#include "mtypes.h"
#include "varray.h"
@@ -137,9 +133,6 @@
#include "shader/program.h"
#include "shader/prog_print.h"
#include "shader/shader_api.h"
-#if FEATURE_ATI_fragment_shader
-#include "shader/atifragshader.h"
-#endif
#if _HAVE_FULL_GL
#include "math/m_matrix.h"
#endif
@@ -191,7 +184,6 @@ _mesa_notifySwapBuffers(__GLcontext *ctx)
* Allocates a GLvisual structure and initializes it via
* _mesa_initialize_visual().
*
- * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
* \param dbFlag double buffering
* \param stereoFlag stereo buffer
* \param depthBits requested bits per depth buffer value. Any value in [0, 32]
@@ -213,14 +205,12 @@ _mesa_notifySwapBuffers(__GLcontext *ctx)
* \note Need to add params for level and numAuxBuffers (at least)
*/
GLvisual *
-_mesa_create_visual( GLboolean rgbFlag,
- GLboolean dbFlag,
+_mesa_create_visual( GLboolean dbFlag,
GLboolean stereoFlag,
GLint redBits,
GLint greenBits,
GLint blueBits,
GLint alphaBits,
- GLint indexBits,
GLint depthBits,
GLint stencilBits,
GLint accumRedBits,
@@ -229,15 +219,15 @@ _mesa_create_visual( GLboolean rgbFlag,
GLint accumAlphaBits,
GLint numSamples )
{
- GLvisual *vis = (GLvisual *) _mesa_calloc(sizeof(GLvisual));
+ GLvisual *vis = (GLvisual *) calloc(1, sizeof(GLvisual));
if (vis) {
- if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
+ if (!_mesa_initialize_visual(vis, dbFlag, stereoFlag,
redBits, greenBits, blueBits, alphaBits,
- indexBits, depthBits, stencilBits,
+ depthBits, stencilBits,
accumRedBits, accumGreenBits,
accumBlueBits, accumAlphaBits,
numSamples)) {
- _mesa_free(vis);
+ free(vis);
return NULL;
}
}
@@ -255,14 +245,12 @@ _mesa_create_visual( GLboolean rgbFlag,
*/
GLboolean
_mesa_initialize_visual( GLvisual *vis,
- GLboolean rgbFlag,
GLboolean dbFlag,
GLboolean stereoFlag,
GLint redBits,
GLint greenBits,
GLint blueBits,
GLint alphaBits,
- GLint indexBits,
GLint depthBits,
GLint stencilBits,
GLint accumRedBits,
@@ -284,7 +272,7 @@ _mesa_initialize_visual( GLvisual *vis,
assert(accumBlueBits >= 0);
assert(accumAlphaBits >= 0);
- vis->rgbMode = rgbFlag;
+ vis->rgbMode = GL_TRUE;
vis->doubleBufferMode = dbFlag;
vis->stereoMode = stereoFlag;
@@ -294,7 +282,7 @@ _mesa_initialize_visual( GLvisual *vis,
vis->alphaBits = alphaBits;
vis->rgbBits = redBits + greenBits + blueBits;
- vis->indexBits = indexBits;
+ vis->indexBits = 0;
vis->depthBits = depthBits;
vis->stencilBits = stencilBits;
@@ -327,7 +315,7 @@ _mesa_initialize_visual( GLvisual *vis,
void
_mesa_destroy_visual( GLvisual *vis )
{
- _mesa_free(vis);
+ free(vis);
}
/*@}*/
@@ -415,14 +403,6 @@ one_time_init( GLcontext *ctx )
_mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
}
- if (_mesa_getenv("MESA_DEBUG")) {
- _glapi_noop_enable_warnings(GL_TRUE);
- _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
- }
- else {
- _glapi_noop_enable_warnings(GL_FALSE);
- }
-
#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
_mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
MESA_VERSION_STRING, __DATE__, __TIME__);
@@ -510,12 +490,6 @@ _mesa_init_constants(GLcontext *ctx)
{
assert(ctx);
- assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
- assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
-
- /* 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;
ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
@@ -571,6 +545,7 @@ _mesa_init_constants(GLcontext *ctx)
#if FEATURE_ARB_vertex_shader
ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
+ ctx->Const.MaxCombinedTextureImageUnits = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
ctx->Const.MaxVarying = MAX_VARYING;
#endif
@@ -585,23 +560,6 @@ _mesa_init_constants(GLcontext *ctx)
/* GL_EXT_provoking_vertex */
ctx->Const.QuadsFollowProvokingVertexConvention = GL_TRUE;
-
- /* sanity checks */
- ASSERT(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
- ctx->Const.MaxTextureCoordUnits));
- ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
- ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
-
- ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
- ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
- ASSERT(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
- ASSERT(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
-
- /* check that we don't exceed the size of various bitfields */
- ASSERT(VERT_RESULT_MAX <=
- (8 * sizeof(ctx->VertexProgram._Current->Base.OutputsWritten)));
- ASSERT(FRAG_ATTRIB_MAX <=
- (8 * sizeof(ctx->FragmentProgram._Current->Base.InputsRead)));
}
@@ -612,17 +570,41 @@ _mesa_init_constants(GLcontext *ctx)
static void
check_context_limits(GLcontext *ctx)
{
- /* Many context limits/constants are limited by the size of
- * internal arrays.
- */
+ /* check that we don't exceed the size of various bitfields */
+ assert(VERT_RESULT_MAX <=
+ (8 * sizeof(ctx->VertexProgram._Current->Base.OutputsWritten)));
+ assert(FRAG_ATTRIB_MAX <=
+ (8 * sizeof(ctx->FragmentProgram._Current->Base.InputsRead)));
+
+ assert(MAX_COMBINED_TEXTURE_IMAGE_UNITS <= 8 * sizeof(GLbitfield));
+
+ /* shader-related checks */
+ assert(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
+ assert(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
+
+ assert(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
+ assert(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
+ assert(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
+ assert(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
+
+ /* Texture unit checks */
+ assert(ctx->Const.MaxTextureImageUnits > 0);
assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
+ assert(ctx->Const.MaxTextureCoordUnits > 0);
assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
+ assert(ctx->Const.MaxTextureUnits > 0);
assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
-
+ assert(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
+ ctx->Const.MaxTextureCoordUnits));
+ assert(ctx->Const.MaxCombinedTextureImageUnits > 0);
+ assert(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+ assert(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
/* number of coord units cannot be greater than number of image units */
assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
+
+ /* Texture size checks */
assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
@@ -633,6 +615,13 @@ check_context_limits(GLcontext *ctx)
assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= MAX_WIDTH);
assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= MAX_WIDTH);
+ /* Texture level checks */
+ assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
+ assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
+
+ /* Max texture size should be <= max viewport size (render to texture) */
+ assert((1 << (MAX_TEXTURE_LEVELS - 1)) <= MAX_WIDTH);
+
assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
@@ -761,7 +750,7 @@ alloc_dispatch_table(void)
GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
sizeof(struct _glapi_table) / sizeof(_glapi_proc));
struct _glapi_table *table =
- (struct _glapi_table *) _mesa_malloc(numEntries * sizeof(_glapi_proc));
+ (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
if (table) {
_glapi_proc *entry = (_glapi_proc *) table;
GLint i;
@@ -846,7 +835,7 @@ _mesa_initialize_context(GLcontext *ctx,
_glthread_UNLOCK_MUTEX(shared->Mutex);
if (!init_attrib_groups( ctx )) {
- _mesa_free_shared_state(ctx, ctx->Shared);
+ _mesa_release_shared_state(ctx, ctx->Shared);
return GL_FALSE;
}
@@ -854,9 +843,9 @@ _mesa_initialize_context(GLcontext *ctx,
ctx->Exec = alloc_dispatch_table();
ctx->Save = alloc_dispatch_table();
if (!ctx->Exec || !ctx->Save) {
- _mesa_free_shared_state(ctx, ctx->Shared);
+ _mesa_release_shared_state(ctx, ctx->Shared);
if (ctx->Exec)
- _mesa_free(ctx->Exec);
+ free(ctx->Exec);
return GL_FALSE;
}
#if FEATURE_dispatch
@@ -919,7 +908,7 @@ _mesa_create_context(const GLvisual *visual,
ASSERT(visual);
/*ASSERT(driverContext);*/
- ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
+ ctx = (GLcontext *) calloc(1, sizeof(GLcontext));
if (!ctx)
return NULL;
@@ -928,7 +917,7 @@ _mesa_create_context(const GLvisual *visual,
return ctx;
}
else {
- _mesa_free(ctx);
+ free(ctx);
return NULL;
}
}
@@ -944,8 +933,6 @@ _mesa_create_context(const GLvisual *visual,
void
_mesa_free_context_data( GLcontext *ctx )
{
- GLint RefCount;
-
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.
@@ -968,6 +955,7 @@ _mesa_free_context_data( GLcontext *ctx )
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
_mesa_free_attrib_data(ctx);
+ _mesa_free_buffer_objects(ctx);
_mesa_free_lighting_data( ctx );
_mesa_free_eval_data( ctx );
_mesa_free_texture_data( ctx );
@@ -987,6 +975,7 @@ _mesa_free_context_data( GLcontext *ctx )
#if FEATURE_ARB_pixel_buffer_object
_mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj, NULL);
_mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj, NULL);
+ _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj, NULL);
#endif
#if FEATURE_ARB_vertex_buffer_object
@@ -995,24 +984,20 @@ _mesa_free_context_data( GLcontext *ctx )
#endif
/* free dispatch tables */
- _mesa_free(ctx->Exec);
- _mesa_free(ctx->Save);
+ free(ctx->Exec);
+ free(ctx->Save);
/* Shared context state (display lists, textures, etc) */
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
- RefCount = --ctx->Shared->RefCount;
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
- assert(RefCount >= 0);
- if (RefCount == 0) {
- /* free shared state */
- _mesa_free_shared_state( ctx, ctx->Shared );
- }
+ _mesa_release_shared_state( ctx, ctx->Shared );
/* needs to be after freeing shared state */
_mesa_free_display_list_data(ctx);
if (ctx->Extensions.String)
- _mesa_free((void *) ctx->Extensions.String);
+ free((void *) ctx->Extensions.String);
+
+ if (ctx->VersionString)
+ free(ctx->VersionString);
/* unbind the context if it's currently bound */
if (ctx == _mesa_get_current_context()) {
@@ -1033,7 +1018,7 @@ _mesa_destroy_context( GLcontext *ctx )
{
if (ctx) {
_mesa_free_context_data(ctx);
- _mesa_free( (void *) ctx );
+ free( (void *) ctx );
}
}
@@ -1118,7 +1103,7 @@ _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
dst->Polygon = src->Polygon;
}
if (mask & GL_POLYGON_STIPPLE_BIT) {
- /* Use loop instead of MEMCPY due to problem with Portland Group's
+ /* Use loop instead of memcpy due to problem with Portland Group's
* C compiler. Reported by John Stone.
*/
GLuint i;
@@ -1179,8 +1164,6 @@ check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
if (ctxvis == bufvis)
return GL_TRUE;
- if (ctxvis->rgbMode != bufvis->rgbMode)
- return GL_FALSE;
#if 0
/* disabling this fixes the fgl_glxgears pbuffer demo */
if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
@@ -1373,6 +1356,8 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
}
if (newCtx->FirstTimeCurrent) {
+ _mesa_compute_version(newCtx);
+
check_context_limits(newCtx);
/* We can use this to help debug user's problems. Tell them to set
@@ -1403,7 +1388,6 @@ _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
{
if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
struct gl_shared_state *oldSharedState = ctx->Shared;
- GLint RefCount;
ctx->Shared = ctxToShare->Shared;
@@ -1413,13 +1397,7 @@ _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
update_default_objects(ctx);
- _glthread_LOCK_MUTEX(oldSharedState->Mutex);
- RefCount = --oldSharedState->RefCount;
- _glthread_UNLOCK_MUTEX(oldSharedState->Mutex);
-
- if (RefCount == 0) {
- _mesa_free_shared_state(ctx, oldSharedState);
- }
+ _mesa_release_shared_state(ctx, oldSharedState);
return GL_TRUE;
}
@@ -1580,6 +1558,10 @@ _mesa_set_mvp_with_dp4( GLcontext *ctx,
GLboolean
_mesa_valid_to_render(GLcontext *ctx, const char *where)
{
+ /* This depends on having up to date derived state (shaders) */
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
if (ctx->Shader.CurrentProgram) {
/* using shaders */
if (!ctx->Shader.CurrentProgram->LinkStatus) {