From 60e3bfddaf6ab4f8385561654dfe4e0034d8bc9d Mon Sep 17 00:00:00 2001 From: Laura Ekstrand Date: Wed, 3 Dec 2014 17:47:32 -0800 Subject: [PATCH] main: Added utility function _mesa_lookup_texture_err(). Most ARB_DIRECT_STATE_ACCESS functions take an object's ID and use it to look up the object in its hash table. If the user passes a fake object ID (ie. a non-generated name), the implementation should throw INVALID_OPERATION. This is a convenience function for texture objects. Reviewed-by: Anuj Phogat --- src/mesa/main/texobj.c | 16 ++++++++++++++++ src/mesa/main/texobj.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index d199bd7fdb5..c309eb8d2be 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -60,6 +60,22 @@ _mesa_lookup_texture(struct gl_context *ctx, GLuint id) _mesa_HashLookup(ctx->Shared->TexObjects, id); } +/** + * Wrapper around _mesa_lookup_texture that throws GL_INVALID_OPERATION if id + * is not in the hash table. After calling _mesa_error, it returns NULL. + */ +struct gl_texture_object * +_mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func) +{ + struct gl_texture_object *texObj; + + texObj = _mesa_lookup_texture(ctx, id); /* Returns NULL if not found. */ + + if (!texObj) + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture)", func); + + return texObj; +} void _mesa_begin_texture_lookups(struct gl_context *ctx) diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h index f33991dd2d6..109264e8901 100644 --- a/src/mesa/main/texobj.h +++ b/src/mesa/main/texobj.h @@ -51,6 +51,9 @@ extern "C" { extern struct gl_texture_object * _mesa_lookup_texture(struct gl_context *ctx, GLuint id); +extern struct gl_texture_object * +_mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func); + extern void _mesa_begin_texture_lookups(struct gl_context *ctx); -- 2.30.2