summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaura Ekstrand <[email protected]>2014-10-24 15:02:16 -0700
committerLaura Ekstrand <[email protected]>2015-01-08 11:37:28 -0800
commit97c838cf856e478401be9526ab028aea3aacad26 (patch)
tree08c39e39396983d26d3b91e3905bad7f4ff12d94
parent15ddc2d94b0ac23bf23e166530e46be4ee9570a2 (diff)
main: Added entry point for glCreateTextures.
Reviewed-by: Anuj Phogat <[email protected]>
-rw-r--r--src/mapi/glapi/gen/ARB_direct_state_access.xml8
-rw-r--r--src/mesa/main/tests/dispatch_sanity.cpp3
-rw-r--r--src/mesa/main/texobj.c109
-rw-r--r--src/mesa/main/texobj.h4
4 files changed, 98 insertions, 26 deletions
diff --git a/src/mapi/glapi/gen/ARB_direct_state_access.xml b/src/mapi/glapi/gen/ARB_direct_state_access.xml
index fcec6080647..9f2eacb2d48 100644
--- a/src/mapi/glapi/gen/ARB_direct_state_access.xml
+++ b/src/mapi/glapi/gen/ARB_direct_state_access.xml
@@ -7,5 +7,13 @@
<enum name="QUERY_TARGET" value="0x82EA"/>
<enum name="TEXTURE_BINDING" value="0x82EB"/>
+ <!-- Texture object functions -->
+
+ <function name="CreateTextures" offset="assign">
+ <param name="target" type="GLenum" />
+ <param name="n" type="GLsizei" />
+ <param name="textures" type="GLuint *" />
+ </function>
+
</category>
</OpenGLAPI>
diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
index 03428dd7281..f301b59344b 100644
--- a/src/mesa/main/tests/dispatch_sanity.cpp
+++ b/src/mesa/main/tests/dispatch_sanity.cpp
@@ -954,6 +954,9 @@ const struct function gl_core_functions_possible[] = {
/* GL_ARB_clip_control */
{ "glClipControl", 45, -1 },
+ /* GL_ARB_direct_state_access */
+ { "glCreateTextures", 45, -1 },
+
{ NULL, 0, -1 }
};
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index a17aaa662e8..416b7df20c9 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1118,38 +1118,25 @@ invalidate_tex_image_error_check(struct gl_context *ctx, GLuint texture,
return t;
}
-/*@}*/
-
-
-/***********************************************************************/
-/** \name API functions */
-/*@{*/
-
-
/**
- * Generate texture names.
- *
- * \param n number of texture names to be generated.
- * \param textures an array in which will hold the generated texture names.
- *
- * \sa glGenTextures().
- *
- * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
- * IDs which are stored in \p textures. Corresponding empty texture
- * objects are also generated.
+ * Helper function for glCreateTextures and glGenTextures. Need this because
+ * glCreateTextures should throw errors if target = 0. This is not exposed to
+ * the rest of Mesa to encourage Mesa internals to use nameless textures,
+ * which do not require expensive hash lookups.
*/
-void GLAPIENTRY
-_mesa_GenTextures( GLsizei n, GLuint *textures )
+static void
+create_textures(struct gl_context *ctx, GLenum target,
+ GLsizei n, GLuint *textures, bool dsa)
{
- GET_CURRENT_CONTEXT(ctx);
GLuint first;
GLint i;
+ const char *func = dsa ? "Create" : "Gen";
if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
- _mesa_debug(ctx, "glGenTextures %d\n", n);
+ _mesa_debug(ctx, "gl%sTextures %d\n", func, n);
if (n < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glGenTextures" );
+ _mesa_error( ctx, GL_INVALID_VALUE, "gl%sTextures(n < 0)", func );
return;
}
@@ -1166,15 +1153,28 @@ _mesa_GenTextures( GLsizei n, GLuint *textures )
/* Allocate new, empty texture objects */
for (i = 0; i < n; i++) {
struct gl_texture_object *texObj;
+ GLint targetIndex;
GLuint name = first + i;
- GLenum target = 0;
texObj = ctx->Driver.NewTextureObject(ctx, name, target);
if (!texObj) {
mtx_unlock(&ctx->Shared->Mutex);
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenTextures");
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "gl%sTextures", func);
return;
}
+ /* Initialize the target index if target is non-zero. */
+ if (target != 0) {
+ targetIndex = _mesa_tex_target_to_index(ctx, texObj->Target);
+ if (targetIndex < 0) { /* Bad Target */
+ mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_error(ctx, GL_INVALID_ENUM, "gl%sTextures(target = %s)",
+ func, _mesa_lookup_enum_by_nr(texObj->Target));
+ return;
+ }
+ assert(targetIndex < NUM_TEXTURE_TARGETS);
+ texObj->TargetIndex = targetIndex;
+ }
+
/* insert into hash table */
_mesa_HashInsert(ctx->Shared->TexObjects, texObj->Name, texObj);
@@ -1184,6 +1184,65 @@ _mesa_GenTextures( GLsizei n, GLuint *textures )
mtx_unlock(&ctx->Shared->Mutex);
}
+/*@}*/
+
+
+/***********************************************************************/
+/** \name API functions */
+/*@{*/
+
+
+/**
+ * Generate texture names.
+ *
+ * \param n number of texture names to be generated.
+ * \param textures an array in which will hold the generated texture names.
+ *
+ * \sa glGenTextures(), glCreateTextures().
+ *
+ * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
+ * IDs which are stored in \p textures. Corresponding empty texture
+ * objects are also generated.
+ */
+void GLAPIENTRY
+_mesa_GenTextures(GLsizei n, GLuint *textures)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ create_textures(ctx, 0, n, textures, false);
+}
+
+/**
+ * Create texture objects.
+ *
+ * \param target the texture target for each name to be generated.
+ * \param n number of texture names to be generated.
+ * \param textures an array in which will hold the generated texture names.
+ *
+ * \sa glCreateTextures(), glGenTextures().
+ *
+ * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
+ * IDs which are stored in \p textures. Corresponding empty texture
+ * objects are also generated.
+ */
+void GLAPIENTRY
+_mesa_CreateTextures(GLenum target, GLsizei n, GLuint *textures)
+{
+ GLint targetIndex;
+ GET_CURRENT_CONTEXT(ctx);
+
+ /*
+ * The 4.5 core profile spec (30.10.2014) doesn't specify what
+ * glCreateTextures should do with invalid targets, which was probably an
+ * oversight. This conforms to the spec for glBindTexture.
+ */
+ targetIndex = _mesa_tex_target_to_index(ctx, target);
+ if (targetIndex < 0) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCreateTextures(target)");
+ return;
+ }
+
+ create_textures(ctx, target, n, textures, true);
+}
/**
* Check if the given texture object is bound to the current draw or
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 456dcf9ed3d..e7aabbe8912 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -206,8 +206,10 @@ _mesa_lock_context_textures( struct gl_context *ctx );
/*@{*/
extern void GLAPIENTRY
-_mesa_GenTextures( GLsizei n, GLuint *textures );
+_mesa_GenTextures(GLsizei n, GLuint *textures);
+extern void GLAPIENTRY
+_mesa_CreateTextures(GLenum target, GLsizei n, GLuint *textures);
extern void GLAPIENTRY
_mesa_DeleteTextures( GLsizei n, const GLuint *textures );