OSDN Git Service

main: Added utility function _mesa_lookup_texture_err().
authorLaura Ekstrand <laura@jlekstrand.net>
Thu, 4 Dec 2014 01:47:32 +0000 (17:47 -0800)
committerLaura Ekstrand <laura@jlekstrand.net>
Thu, 8 Jan 2015 19:37:28 +0000 (11:37 -0800)
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 <anuj.phogat@gmail.com>
src/mesa/main/texobj.c
src/mesa/main/texobj.h

index d199bd7..c309eb8 100644 (file)
@@ -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)
index f33991d..109264e 100644 (file)
@@ -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);