[Mesa-dev] [PATCH 02/23] main: Add entry point for TextureBufferRange.

Ian Romanick idr at freedesktop.org
Wed Feb 18 10:41:54 PST 2015


On 02/11/2015 06:05 PM, Laura Ekstrand wrote:
> ---
>  src/mapi/glapi/gen/ARB_direct_state_access.xml |  8 +++
>  src/mesa/main/tests/dispatch_sanity.cpp        |  1 +
>  src/mesa/main/teximage.c                       | 90 ++++++++++++++++++++++++++
>  src/mesa/main/teximage.h                       |  4 ++
>  4 files changed, 103 insertions(+)
> 
> diff --git a/src/mapi/glapi/gen/ARB_direct_state_access.xml b/src/mapi/glapi/gen/ARB_direct_state_access.xml
> index 2fe1638..86c00f9 100644
> --- a/src/mapi/glapi/gen/ARB_direct_state_access.xml
> +++ b/src/mapi/glapi/gen/ARB_direct_state_access.xml
> @@ -21,6 +21,14 @@
>        <param name="buffer" type="GLuint" />
>     </function>
>  
> +   <function name="TextureBufferRange" offset="assign">
> +      <param name="texture" type="GLuint" />
> +      <param name="internalformat" type="GLenum" />
> +      <param name="buffer" type="GLuint" />
> +      <param name="offset" type="GLintptr" />
> +      <param name="size" type="GLsizeiptr" />
> +   </function>
> +
>     <function name="TextureStorage1D" offset="assign">
>        <param name="texture" type="GLuint" />
>        <param name="levels" type="GLsizei" />
> diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
> index 1f1a3a8..b78c1ce 100644
> --- a/src/mesa/main/tests/dispatch_sanity.cpp
> +++ b/src/mesa/main/tests/dispatch_sanity.cpp
> @@ -987,6 +987,7 @@ const struct function gl_core_functions_possible[] = {
>     { "glTextureStorage2DMultisample", 45, -1 },
>     { "glTextureStorage3DMultisample", 45, -1 },
>     { "glTextureBuffer", 45, -1 },
> +   { "glTextureBufferRange", 45, -1 },
>  
>     /* GL_EXT_polygon_offset_clamp */
>     { "glPolygonOffsetClampEXT", 11, -1 },
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 336feff..ce6f446 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -5197,6 +5197,96 @@ _mesa_TextureBuffer(GLuint texture, GLenum internalFormat, GLuint buffer)
>                                bufObj, 0, buffer ? -1 : 0, false, true);
>  }
>  
> +void GLAPIENTRY
> +_mesa_TextureBufferRange(GLuint texture, GLenum internalFormat, GLuint buffer,
> +                         GLintptr offset, GLsizeiptr size)
> +{
> +   struct gl_texture_object *texObj;
> +   struct gl_buffer_object *bufObj;
> +
> +   GET_CURRENT_CONTEXT(ctx);
> +
> +   /* NOTE: ARB_texture_buffer_object has interactions with
> +    * the compatibility profile that are not implemented.
> +    */
> +   if (!(ctx->API == API_OPENGL_CORE &&
> +         ctx->Extensions.ARB_texture_buffer_object)) {
> +      _mesa_error(ctx, GL_INVALID_OPERATION,
> +                  "glTextureBufferRange(ARB_texture_buffer_object is not"
> +                  " implemented for the compatibility profile)");
> +      return;
> +   }
> +
> +   bufObj = _mesa_lookup_bufferobj(ctx, buffer);
> +   if (bufObj) {
> +      /* OpenGL 4.5 core spec (30.10.2014) says in Section 8.9 Buffer
> +       * Textures:
> +       *    "An INVALID_VALUE error is generated if offset is negative, if
> +       *    size is less than or equal to zero, or if offset + size is greater
> +       *    than the value of BUFFER_SIZE for the buffer bound to target."
> +       */
> +      if (offset < 0) {
> +         _mesa_error(ctx, GL_INVALID_VALUE,
> +                     "glTextureBufferRange(offset %d < 0)", (int) offset);
> +         return;
> +      }
> +
> +      if (size <= 0) {
> +         _mesa_error(ctx, GL_INVALID_VALUE,
> +                     "glTextureBufferRange(size %d <= 0)", (int) size);
> +         return;
> +      }
> +
> +      if (offset + size > bufObj->Size) {
> +         _mesa_error(ctx, GL_INVALID_VALUE,
> +                     "glTextureBufferRange("
> +                     "offset %d + size %d > buffer_size %d)", (int) offset,
> +                     (int) size, (int) bufObj->Size);
> +         return;
> +      }
> +
> +      /* OpenGL 4.5 core spec (30.10.2014) says in Section 8.9 Buffer
> +       * Textures:
> +       *    "An INVALID_VALUE error is generated if offset is not an integer
> +       *    multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
> +       */
> +      if (offset % ctx->Const.TextureBufferOffsetAlignment) {
> +         _mesa_error(ctx, GL_INVALID_VALUE,
> +                     "glTextureBufferRange(invalid offset alignment)");
> +         return;
> +      }
> +   } else if (buffer) {
> +      _mesa_error(ctx, GL_INVALID_OPERATION,
> +                  "glTextureBufferRange(unrecognized buffer %u)", buffer);
> +      return;
> +   } else {
> +
> +      /* OpenGL 4.5 core spec (30.10.2014) says in Section 8.9 Buffer
> +       * Textures:
> +       *    "If buffer is zero, then any buffer object attached to the buffer
> +       *    texture is detached, the values offset and size are ignored and
> +       *    the state for offset and size for the buffer texture are reset to
> +       *    zero."
> +       */
> +      offset = 0;
> +      size = 0;
> +   }

We usually try to keep flow control for error checking more flat.  It
makes it easier to follow.  For example, the above block would be much
better as

   struct gl_buffer_object *bufObj = NULL;

   ...

   if (buffer == 0) {
      /* OpenGL 4.5 core spec (30.10.2014) says in Section 8.9 Buffer
       * Textures:
       *    "If buffer is zero, then any buffer object attached to the buffer
       *    texture is detached, the values offset and size are ignored and
       *    the state for offset and size for the buffer texture are reset to
       *    zero."
       */
      offset = 0;
      size = 0;
   } else {
      bufObj = _mesa_lookup_bufferobj(ctx, buffer);
      if (!bufObj) {
         _mesa_error(ctx, GL_INVALID_OPERATION,
                     "glTextureBufferRange(unrecognized buffer %u)", buffer);
         return;
   }

   /* OpenGL 4.5 core spec (30.10.2014) says in Section 8.9 Buffer
    * Textures:
    *    "An INVALID_VALUE error is generated if offset is negative, if
    *    size is less than or equal to zero, or if offset + size is greater
    *    than the value of BUFFER_SIZE for the buffer bound to target."
    */
   if (offset < 0) {
      _mesa_error(ctx, GL_INVALID_VALUE,
                  "glTextureBufferRange(offset %d < 0)", (int) offset);
      return;
   }

   if (size <= 0) {
      _mesa_error(ctx, GL_INVALID_VALUE,
                  "glTextureBufferRange(size %d <= 0)", (int) size);
      return;
   }

   if (bufObj && offset + size > bufObj->Size) {
      _mesa_error(ctx, GL_INVALID_VALUE,
                  "glTextureBufferRange("
                  "offset %d + size %d > buffer_size %d)", (int) offset,
                  (int) size, (int) bufObj->Size);
      return;
   }

   /* OpenGL 4.5 core spec (30.10.2014) says in Section 8.9 Buffer
    * Textures:
    *    "An INVALID_VALUE error is generated if offset is not an integer
    *    multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
    */
   if (offset % ctx->Const.TextureBufferOffsetAlignment) {
      _mesa_error(ctx, GL_INVALID_VALUE,
                  "glTextureBufferRange(invalid offset alignment)");
      return;
   }

> +
> +   /* Get the texture object by Name. */
> +   texObj = _mesa_lookup_texture_err(ctx, texture, "glTextureBufferRange");
> +   if (!texObj)
> +      return;
> +

   /* The ARB_texture_buffer_object spec says:
    *
    *     "<target> must be TEXTURE_BUFFER_ARB."
    *
    * From this we infer that the target of the supplied texture must be
    * GL_TEXTURE_BUFFER.
    */
> +   if (texObj->Target != GL_TEXTURE_BUFFER_ARB) {

Prefer the non _ARB name.

> +      _mesa_error(ctx, GL_INVALID_ENUM, "glTextureBufferRange(texture target"
> +                                        " is not GL_TEXTURE_BUFFER)");
> +      return;
> +   }
> +
> +   _mesa_texture_buffer_range(ctx, texObj, texObj->Target, internalFormat,
> +                              bufObj, offset, size, true, true);
> +}
> +
>  static GLboolean
>  is_renderable_texture_format(struct gl_context *ctx, GLenum internalformat)
>  {
> diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
> index 02b0eda..a4e6c2e 100644
> --- a/src/mesa/main/teximage.h
> +++ b/src/mesa/main/teximage.h
> @@ -405,6 +405,10 @@ _mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
>  extern void GLAPIENTRY
>  _mesa_TextureBuffer(GLuint texture, GLenum internalFormat, GLuint buffer);
>  
> +extern void GLAPIENTRY
> +_mesa_TextureBufferRange(GLuint texture, GLenum internalFormat, GLuint buffer,
> +                         GLintptr offset, GLsizeiptr size);
> +
>  
>  extern void GLAPIENTRY
>  _mesa_TexImage2DMultisample(GLenum target, GLsizei samples,
> 



More information about the mesa-dev mailing list