[Mesa-dev] [PATCH 10/41] main: Added entry point for glCreateTextures.

Brian Paul brianp at vmware.com
Tue Dec 16 07:45:42 PST 2014


On 12/15/2014 06:22 PM, Laura Ekstrand wrote:
> ---
>   src/mapi/glapi/gen/ARB_direct_state_access.xml |   8 ++
>   src/mesa/main/texobj.c                         | 109 +++++++++++++++++++------
>   src/mesa/main/texobj.h                         |   2 +
>   3 files changed, 92 insertions(+), 27 deletions(-)
>
> diff --git a/src/mapi/glapi/gen/ARB_direct_state_access.xml b/src/mapi/glapi/gen/ARB_direct_state_access.xml
> index fcec608..9f2eacb 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/texobj.c b/src/mesa/main/texobj.c
> index 6215fe3..26d07ee 100644
> --- a/src/mesa/main/texobj.c
> +++ b/src/mesa/main/texobj.c
> @@ -1100,38 +1100,23 @@ 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.
> - */
> -void GLAPIENTRY
> -_mesa_GenTextures( GLsizei n, GLuint *textures )
> +/* 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. */
> +static void
> +create_textures( struct gl_context *ctx, GLenum target,
> +   GLsizei n, GLuint *textures, bool dsa )

Minor formatting nits.  We try to use the doxygen style for function 
comments:

/**
  * Helper function...
  */

And indent continued function parameters according to the opening paren:

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", func );
>         return;
>      }
>
> @@ -1148,15 +1133,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)
> +      {

Put opening brace on same line as the conditional.


> +         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)", func);
> +            return;
> +         }
> +         assert(targetIndex < NUM_TEXTURE_TARGETS);
> +         texObj->TargetIndex = targetIndex;
> +      }
> +
>         /* insert into hash table */
>         _mesa_HashInsert(ctx->Shared->TexObjects, texObj->Name, texObj);
>
> @@ -1166,6 +1164,63 @@ _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);

Maybe pass GL_NONE for target instead of 0 since it's a GLenum parameter.


> +}
> +
> +/**
> + * 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 (20141030) doesn't specify what
> +    * glCreateTextures should do with invalid targets, which was probably an
> +    * oversight.  This conforms to the spec for glBindTexture. */

Closing */ on next line.


> +   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 90cb51a..b957ac5 100644
> --- a/src/mesa/main/texobj.h
> +++ b/src/mesa/main/texobj.h
> @@ -200,6 +200,8 @@ _mesa_lock_context_textures( struct gl_context *ctx );
>   extern void GLAPIENTRY
>   _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 );
>



More information about the mesa-dev mailing list