📄 texobj.c
字号:
} else if (texObj == unit->Current1DArray) { _mesa_reference_texobj(&unit->Current1DArray, ctx->Shared->Default1DArray); } else if (texObj == unit->Current2DArray) { _mesa_reference_texobj(&unit->Current2DArray, ctx->Shared->Default2DArray); } }}/** * Delete named textures. * * \param n number of textures to be deleted. * \param textures array of texture IDs to be deleted. * * \sa glDeleteTextures(). * * If we're about to delete a texture that's currently bound to any * texture unit, unbind the texture first. Decrement the reference * count on the texture object and delete it if it's zero. * Recall that texture objects can be shared among several rendering * contexts. */void GLAPIENTRY_mesa_DeleteTextures( GLsizei n, const GLuint *textures){ GET_CURRENT_CONTEXT(ctx); GLint i; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */ if (!textures) return; for (i = 0; i < n; i++) { if (textures[i] > 0) { struct gl_texture_object *delObj = _mesa_lookup_texture(ctx, textures[i]); if (delObj) { _mesa_lock_texture(ctx, delObj); /* Check if texture is bound to any framebuffer objects. * If so, unbind. * See section 4.4.2.3 of GL_EXT_framebuffer_object. */ unbind_texobj_from_fbo(ctx, delObj); /* Check if this texture is currently bound to any texture units. * If so, unbind it. */ unbind_texobj_from_texunits(ctx, delObj); _mesa_unlock_texture(ctx, delObj); ctx->NewState |= _NEW_TEXTURE; /* The texture _name_ is now free for re-use. * Remove it from the hash table now. */ _glthread_LOCK_MUTEX(ctx->Shared->Mutex); _mesa_HashRemove(ctx->Shared->TexObjects, delObj->Name); _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); /* Unreference the texobj. If refcount hits zero, the texture * will be deleted. */ _mesa_reference_texobj(&delObj, NULL); } } }}/** * Bind a named texture to a texturing target. * * \param target texture target. * \param texName texture name. * * \sa glBindTexture(). * * Determines the old texture object bound and returns immediately if rebinding * the same texture. Get the current texture which is either a default texture * if name is null, a named texture from the hash, or a new texture if the * given texture name is new. Increments its reference count, binds it, and * calls dd_function_table::BindTexture. Decrements the old texture reference * count and deletes it if it reaches zero. */void GLAPIENTRY_mesa_BindTexture( GLenum target, GLuint texName ){ GET_CURRENT_CONTEXT(ctx); const GLuint unit = ctx->Texture.CurrentUnit; struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; struct gl_texture_object *newTexObj = NULL, *defaultTexObj = NULL; ASSERT_OUTSIDE_BEGIN_END(ctx); if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) _mesa_debug(ctx, "glBindTexture %s %d\n", _mesa_lookup_enum_by_nr(target), (GLint) texName); switch (target) { case GL_TEXTURE_1D: defaultTexObj = ctx->Shared->Default1D; break; case GL_TEXTURE_2D: defaultTexObj = ctx->Shared->Default2D; break; case GL_TEXTURE_3D: defaultTexObj = ctx->Shared->Default3D; break; case GL_TEXTURE_CUBE_MAP_ARB: defaultTexObj = ctx->Shared->DefaultCubeMap; break; case GL_TEXTURE_RECTANGLE_NV: defaultTexObj = ctx->Shared->DefaultRect; break; case GL_TEXTURE_1D_ARRAY_EXT: defaultTexObj = ctx->Shared->Default1DArray; break; case GL_TEXTURE_2D_ARRAY_EXT: defaultTexObj = ctx->Shared->Default2DArray; break; default: _mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)"); return; } /* * Get pointer to new texture object (newTexObj) */ if (texName == 0) { newTexObj = defaultTexObj; } else { /* non-default texture object */ newTexObj = _mesa_lookup_texture(ctx, texName); if (newTexObj) { /* error checking */ if (newTexObj->Target != 0 && newTexObj->Target != target) { /* the named texture object's target doesn't match the given target */ _mesa_error( ctx, GL_INVALID_OPERATION, "glBindTexture(target mismatch)" ); return; } if (newTexObj->Target == 0) { finish_texture_init(ctx, target, newTexObj); } } else { /* if this is a new texture id, allocate a texture object now */ newTexObj = (*ctx->Driver.NewTextureObject)(ctx, texName, target); if (!newTexObj) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindTexture"); return; } /* and insert it into hash table */ _glthread_LOCK_MUTEX(ctx->Shared->Mutex); _mesa_HashInsert(ctx->Shared->TexObjects, texName, newTexObj); _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); } newTexObj->Target = target; } assert(valid_texture_object(newTexObj)); /* flush before changing binding */ FLUSH_VERTICES(ctx, _NEW_TEXTURE); /* Do the actual binding. The refcount on the previously bound * texture object will be decremented. It'll be deleted if the * count hits zero. */ switch (target) { case GL_TEXTURE_1D: _mesa_reference_texobj(&texUnit->Current1D, newTexObj); break; case GL_TEXTURE_2D: _mesa_reference_texobj(&texUnit->Current2D, newTexObj); break; case GL_TEXTURE_3D: _mesa_reference_texobj(&texUnit->Current3D, newTexObj); break; case GL_TEXTURE_CUBE_MAP_ARB: _mesa_reference_texobj(&texUnit->CurrentCubeMap, newTexObj); break; case GL_TEXTURE_RECTANGLE_NV: _mesa_reference_texobj(&texUnit->CurrentRect, newTexObj); break; case GL_TEXTURE_1D_ARRAY_EXT: texUnit->Current1DArray = newTexObj; break; case GL_TEXTURE_2D_ARRAY_EXT: texUnit->Current2DArray = newTexObj; break; default: /* Bad target should be caught above */ _mesa_problem(ctx, "bad target in BindTexture"); return; } /* Pass BindTexture call to device driver */ if (ctx->Driver.BindTexture) (*ctx->Driver.BindTexture)( ctx, target, newTexObj );}/** * Set texture priorities. * * \param n number of textures. * \param texName texture names. * \param priorities corresponding texture priorities. * * \sa glPrioritizeTextures(). * * Looks up each texture in the hash, clamps the corresponding priority between * 0.0 and 1.0, and calls dd_function_table::PrioritizeTexture. */void GLAPIENTRY_mesa_PrioritizeTextures( GLsizei n, const GLuint *texName, const GLclampf *priorities ){ GET_CURRENT_CONTEXT(ctx); GLint i; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (n < 0) { _mesa_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" ); return; } if (!priorities) return; for (i = 0; i < n; i++) { if (texName[i] > 0) { struct gl_texture_object *t = _mesa_lookup_texture(ctx, texName[i]); if (t) { t->Priority = CLAMP( priorities[i], 0.0F, 1.0F ); if (ctx->Driver.PrioritizeTexture) ctx->Driver.PrioritizeTexture( ctx, t, t->Priority ); } } } ctx->NewState |= _NEW_TEXTURE;}/** * See if textures are loaded in texture memory. * * \param n number of textures to query. * \param texName array with the texture names. * \param residences array which will hold the residence status. * * \return GL_TRUE if all textures are resident and \p residences is left unchanged, * * \sa glAreTexturesResident(). * * Looks up each texture in the hash and calls * dd_function_table::IsTextureResident. */GLboolean GLAPIENTRY_mesa_AreTexturesResident(GLsizei n, const GLuint *texName, GLboolean *residences){ GET_CURRENT_CONTEXT(ctx); GLboolean allResident = GL_TRUE; GLint i, j; ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); if (n < 0) { _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)"); return GL_FALSE; } if (!texName || !residences) return GL_FALSE; for (i = 0; i < n; i++) { struct gl_texture_object *t; if (texName[i] == 0) { _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident"); return GL_FALSE; } t = _mesa_lookup_texture(ctx, texName[i]); if (!t) { _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident"); return GL_FALSE; } if (!ctx->Driver.IsTextureResident || ctx->Driver.IsTextureResident(ctx, t)) { /* The texture is resident */ if (!allResident) residences[i] = GL_TRUE; } else { /* The texture is not resident */ if (allResident) { allResident = GL_FALSE; for (j = 0; j < i; j++) residences[j] = GL_TRUE; } residences[i] = GL_FALSE; } } return allResident;}/** * See if a name corresponds to a texture. * * \param texture texture name. * * \return GL_TRUE if texture name corresponds to a texture, or GL_FALSE * otherwise. * * \sa glIsTexture(). * * Calls _mesa_HashLookup(). */GLboolean GLAPIENTRY_mesa_IsTexture( GLuint texture ){ struct gl_texture_object *t; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); if (!texture) return GL_FALSE; t = _mesa_lookup_texture(ctx, texture); /* IsTexture is true only after object has been bound once. */ return t && t->Target;}/** * Simplest implementation of texture locking: Grab the a new mutex in * the shared context. Examine the shared context state timestamp and * if there has been a change, set the appropriate bits in * ctx->NewState. * * This is used to deal with synchronizing things when a texture object * is used/modified by different contexts (or threads) which are sharing * the texture. * * See also _mesa_lock/unlock_texture() in teximage.h */void_mesa_lock_context_textures( GLcontext *ctx ){ _glthread_LOCK_MUTEX(ctx->Shared->TexMutex); if (ctx->Shared->TextureStateStamp != ctx->TextureStateTimestamp) { ctx->NewState |= _NEW_TEXTURE; ctx->TextureStateTimestamp = ctx->Shared->TextureStateStamp; }}void_mesa_unlock_context_textures( GLcontext *ctx ){ assert(ctx->Shared->TextureStateStamp == ctx->TextureStateTimestamp); _glthread_UNLOCK_MUTEX(ctx->Shared->TexMutex);}/*@}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -