diff options
author | marha <marha@users.sourceforge.net> | 2014-05-11 17:43:25 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2014-05-11 17:43:25 +0200 |
commit | 26dfcdba6c306d6312c598e4191449302329be68 (patch) | |
tree | 2bf56b5a0eb2cc554833fdc6e08f2b59f1bfdabd /mesalib/src/mesa/main/texobj.c | |
parent | 2dc2880eacae3d52f4ab4bb5ec43c5bbf50c5c3f (diff) | |
parent | ae06feae7876db47ff0e1fde40cf4a324a412037 (diff) | |
download | vcxsrv-26dfcdba6c306d6312c598e4191449302329be68.tar.gz vcxsrv-26dfcdba6c306d6312c598e4191449302329be68.tar.bz2 vcxsrv-26dfcdba6c306d6312c598e4191449302329be68.zip |
Merge remote-tracking branch 'origin/released'
Conflicts:
mesalib/src/mesa/main/imports.h
Diffstat (limited to 'mesalib/src/mesa/main/texobj.c')
-rw-r--r-- | mesalib/src/mesa/main/texobj.c | 175 |
1 files changed, 166 insertions, 9 deletions
diff --git a/mesalib/src/mesa/main/texobj.c b/mesalib/src/mesa/main/texobj.c index 85246c8ab..2a82c2d4e 100644 --- a/mesalib/src/mesa/main/texobj.c +++ b/mesalib/src/mesa/main/texobj.c @@ -61,6 +61,27 @@ _mesa_lookup_texture(struct gl_context *ctx, GLuint id) } +void +_mesa_begin_texture_lookups(struct gl_context *ctx) +{ + _mesa_HashLockMutex(ctx->Shared->TexObjects); +} + + +void +_mesa_end_texture_lookups(struct gl_context *ctx) +{ + _mesa_HashUnlockMutex(ctx->Shared->TexObjects); +} + + +struct gl_texture_object * +_mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id) +{ + return (struct gl_texture_object *) + _mesa_HashLookupLocked(ctx->Shared->TexObjects, id); +} + /** * Allocate and initialize a new texture object. But don't put it into the @@ -260,6 +281,7 @@ _mesa_copy_texture_object( struct gl_texture_object *dest, const struct gl_texture_object *src ) { dest->Target = src->Target; + dest->TargetIndex = src->TargetIndex; dest->Name = src->Name; dest->Priority = src->Priority; dest->Sampler.BorderColor.f[0] = src->Sampler.BorderColor.f[0]; @@ -1092,17 +1114,20 @@ static void unbind_texobj_from_texunits(struct gl_context *ctx, struct gl_texture_object *texObj) { - GLuint u, tex; + const gl_texture_index index = texObj->TargetIndex; + GLuint u; + + if (texObj->Target == 0) + return; for (u = 0; u < ctx->Texture.NumCurrentTexUsed; u++) { struct gl_texture_unit *unit = &ctx->Texture.Unit[u]; - for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) { - if (texObj == unit->CurrentTex[tex]) { - _mesa_reference_texobj(&unit->CurrentTex[tex], - ctx->Shared->DefaultTex[tex]); - ASSERT(unit->CurrentTex[tex]); - break; - } + + if (texObj == unit->CurrentTex[index]) { + /* Bind the default texture for this unit/target */ + _mesa_reference_texobj(&unit->CurrentTex[index], + ctx->Shared->DefaultTex[index]); + unit->_BoundTextures &= ~(1 << index); } } } @@ -1126,6 +1151,28 @@ unbind_texobj_from_image_units(struct gl_context *ctx, } } +/** + * Unbinds all textures bound to the given texture image unit. + */ +static void +unbind_textures_from_unit(struct gl_context *ctx, GLuint unit) +{ + struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; + + while (texUnit->_BoundTextures) { + const GLuint index = ffs(texUnit->_BoundTextures) - 1; + struct gl_texture_object *texObj = ctx->Shared->DefaultTex[index]; + + _mesa_reference_texobj(&texUnit->CurrentTex[index], texObj); + + /* Pass BindTexture call to device driver */ + if (ctx->Driver.BindTexture) + ctx->Driver.BindTexture(ctx, unit, 0, texObj); + + texUnit->_BoundTextures &= ~(1 << index); + ctx->NewState |= _NEW_TEXTURE; + } +} /** * Delete named textures. @@ -1327,6 +1374,7 @@ _mesa_BindTexture( GLenum target, GLuint texName ) mtx_unlock(&ctx->Shared->Mutex); } newTexObj->Target = target; + newTexObj->TargetIndex = targetIndex; } assert(valid_texture_object(newTexObj)); @@ -1357,9 +1405,118 @@ _mesa_BindTexture( GLenum target, GLuint texName ) ctx->Texture.CurrentUnit + 1); ASSERT(texUnit->CurrentTex[targetIndex]); + if (texName != 0) + texUnit->_BoundTextures |= (1 << targetIndex); + else + texUnit->_BoundTextures &= ~(1 << targetIndex); + /* Pass BindTexture call to device driver */ if (ctx->Driver.BindTexture) - ctx->Driver.BindTexture(ctx, target, newTexObj); + ctx->Driver.BindTexture(ctx, ctx->Texture.CurrentUnit, target, newTexObj); +} + + +void GLAPIENTRY +_mesa_BindTextures(GLuint first, GLsizei count, const GLuint *textures) +{ + GET_CURRENT_CONTEXT(ctx); + GLint i; + + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if <first> + <count> + * is greater than the number of texture image units supported + * by the implementation." + */ + if (first + count > ctx->Const.MaxCombinedTextureImageUnits) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glBindTextures(first=%u + count=%d > the value of " + "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS=%u)", + first, count, ctx->Const.MaxCombinedTextureImageUnits); + return; + } + + /* Flush before changing bindings */ + FLUSH_VERTICES(ctx, 0); + + ctx->Texture.NumCurrentTexUsed = MAX2(ctx->Texture.NumCurrentTexUsed, + first + count); + + if (textures) { + /* Note that the error semantics for multi-bind commands differ from + * those of other GL commands. + * + * The issues section in the ARB_multi_bind spec says: + * + * "(11) Typically, OpenGL specifies that if an error is generated by + * a command, that command has no effect. This is somewhat + * unfortunate for multi-bind commands, because it would require + * a first pass to scan the entire list of bound objects for + * errors and then a second pass to actually perform the + * bindings. Should we have different error semantics? + * + * RESOLVED: Yes. In this specification, when the parameters for + * one of the <count> binding points are invalid, that binding + * point is not updated and an error will be generated. However, + * other binding points in the same command will be updated if + * their parameters are valid and no other error occurs." + */ + + _mesa_begin_texture_lookups(ctx); + + for (i = 0; i < count; i++) { + if (textures[i] != 0) { + struct gl_texture_unit *texUnit = &ctx->Texture.Unit[first + i]; + struct gl_texture_object *current = texUnit->_Current; + struct gl_texture_object *texObj; + + if (current && current->Name == textures[i]) + texObj = current; + else + texObj = _mesa_lookup_texture_locked(ctx, textures[i]); + + if (texObj && texObj->Target != 0) { + const gl_texture_index targetIndex = texObj->TargetIndex; + + if (texUnit->CurrentTex[targetIndex] != texObj) { + /* Do the actual binding. The refcount on the previously + * bound texture object will be decremented. It will be + * deleted if the count hits zero. + */ + _mesa_reference_texobj(&texUnit->CurrentTex[targetIndex], + texObj); + + texUnit->_BoundTextures |= (1 << targetIndex); + ctx->NewState |= _NEW_TEXTURE; + + /* Pass the BindTexture call to the device driver */ + if (ctx->Driver.BindTexture) + ctx->Driver.BindTexture(ctx, first + i, + texObj->Target, texObj); + } + } else { + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if any value + * in <textures> is not zero or the name of an existing + * texture object (per binding)." + */ + _mesa_error(ctx, GL_INVALID_OPERATION, + "glBindTextures(textures[%d]=%u is not zero " + "or the name of an existing texture object)", + i, textures[i]); + } + } else { + unbind_textures_from_unit(ctx, first + i); + } + } + + _mesa_end_texture_lookups(ctx); + } else { + /* Unbind all textures in the range <first> through <first>+<count>-1 */ + for (i = 0; i < count; i++) + unbind_textures_from_unit(ctx, first + i); + } } |