[Mesa-dev] [PATCH 1/7] mesa: implement glBindBuffersBase() and gl BindBuffersRange()

Ian Romanick idr at freedesktop.org
Mon Jan 6 11:56:52 PST 2014


On 01/02/2014 04:27 PM, Maxence Le Doré wrote:
> ---
>  src/mesa/main/bufferobj.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/mesa/main/bufferobj.h |   9 ++-
>  2 files changed, 165 insertions(+), 2 deletions(-)
> 
> diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
> index a3d8f24..bad8f90 100644
> --- a/src/mesa/main/bufferobj.c
> +++ b/src/mesa/main/bufferobj.c
> @@ -2706,3 +2706,161 @@ _mesa_InvalidateBufferData(GLuint buffer)
>      */
>     return;
>  }
> +
> +void GLAPIENTRY
> +_mesa_BindBuffersBase(GLenum target, GLuint first, GLsizei count,
> +                      const GLuint *buffers)
> +{
> +   GET_CURRENT_CONTEXT(ctx);
> +   int i = 0;
> +   GLboolean exceedMaxBindings = GL_FALSE;

In addition to all of Brian's formatting comments, for things that are
not visible to the GL API, use standard C types instead of GL types.
Use 'bool' here (and some other places) instead of GLboolean.

> +
> +   switch(target) {
> +     case GL_TRANSFORM_FEEDBACK_BUFFER:
> +       first + count > ctx->Const.MaxTransformFeedbackBuffers ?
> +       exceedMaxBindings = GL_TRUE : exceedMaxBindings = GL_FALSE;
> +       break;
> +     case GL_UNIFORM_BUFFER:
> +       first + count > ctx->Const.MaxUniformBufferBindings ?
> +       exceedMaxBindings = GL_TRUE : exceedMaxBindings = GL_FALSE;
> +       break;
> +     case GL_ATOMIC_COUNTER_BUFFER:
> +       first + count > ctx->Const.MaxAtomicBufferBindings ?
> +       exceedMaxBindings = GL_TRUE : exceedMaxBindings = GL_FALSE;
> +       break;
> +     default:
> +       _mesa_error(ctx, GL_INVALID_ENUM,
> +                   "glBindBuffersBase(invalid target)");
> +       return;
> +   }
> +
> +   if(exceedMaxBindings) {
> +     _mesa_error(ctx, GL_INVALID_OPERATION,
> +                   "glBindBuffersBase(first+count)");
> +       return;
> +       }
> +
> +   for(i = 0 ; i < count ; i++) {
> +      GLuint buffer;
> +      struct gl_buffer_object *bufferObj;
> +
> +      if(buffers == NULL)
> +        buffer = 0;
> +      else
> +        buffer = buffers[i];
> +
> +      if(buffer != 0) {
> +        bufferObj = _mesa_lookup_bufferobj(ctx, buffer);
> +        if(bufferObj) {
> +          _mesa_BindBufferBase(target, first+i, buffer);
> +        }
> +        else
> +          _mesa_error(ctx, GL_INVALID_OPERATION,
> +                      "glBindBufferBase(buffer[%i] is invalid)", i);
> +      }
> +      else
> +        _mesa_BindBufferBase(target, first + i, 0);
> +   }
> +}
> +
> +void GLAPIENTRY
> +_mesa_BindBuffersRange(GLenum target, GLuint first, GLsizei count, 
> +                       const GLuint *buffers, const GLintptr *offsets,
> +                       const GLsizeiptr *sizes)
> +{
> +   GET_CURRENT_CONTEXT(ctx);
> +   int i = 0;
> +   GLboolean exceedMaxBindings = GL_FALSE;
> +
> +   switch(target) {
> +     case GL_TRANSFORM_FEEDBACK_BUFFER:
> +       first + count > ctx->Const.MaxTransformFeedbackBuffers ?
> +       exceedMaxBindings = GL_TRUE : exceedMaxBindings = GL_FALSE;
> +       break;
> +     case GL_UNIFORM_BUFFER:
> +       first + count > ctx->Const.MaxUniformBufferBindings ?
> +       exceedMaxBindings = GL_TRUE : exceedMaxBindings = GL_FALSE;
> +       break;
> +     case GL_ATOMIC_COUNTER_BUFFER:
> +       first + count > ctx->Const.MaxAtomicBufferBindings ?
> +       exceedMaxBindings = GL_TRUE : exceedMaxBindings = GL_FALSE;
> +       break;
> +     default:
> +       _mesa_error(ctx, GL_INVALID_ENUM,
> +                   "glBindBuffersRange(invalid target)");
> +       return;
> +   }
> +
> +   if(exceedMaxBindings) {
> +     _mesa_error(ctx, GL_INVALID_OPERATION,
> +                   "glBindBuffersRange(first+count)");
> +       return;
> +       }
> +
> +   for(i = 0 ; i < count ; i++) {
> +      GLuint buffer;
> +      GLintptr offset;
> +      GLsizeiptr size; 
> +      struct gl_buffer_object *bufferObj;
> +
> +      if(buffers == NULL)
> +        buffer = 0;
> +      else {
> +        buffer = buffers[i];
> +        offset = offsets[i];
> +        size = sizes[i];
> +      }
> +
> +      if(buffer != 0) {
> +        bufferObj = _mesa_lookup_bufferobj(ctx, buffer);
> +        if(bufferObj) {
> +          GLboolean validOffet, validSize;
> +
> +          switch(target) {
> +            case GL_TRANSFORM_FEEDBACK_BUFFER:
> +              (offset >= 0) ?
> +              validOffset = GL_TRUE : validOffet = GL_FALSE;
> +              (size >= 0) ?
> +              validSize = GL_TRUE : validSize = GL_FALSE;
> +              /* TODO : add target specific checks */
> +              break;
> +            case GL_UNIFORM_BUFFER:
> +              (offset >= 0) ?
> +              validOffset = GL_TRUE : validOffet = GL_FALSE;
> +              (size >= 0) ?
> +              validSize = GL_TRUE : validSize = GL_FALSE;
> +              /* TODO : add target specific checks */
> +              break;
> +            case GL_ATOMIC_COUNTER_BUFFER:
> +              (offset >= 0) ?
> +              validOffset = GL_TRUE : validOffet = GL_FALSE;
> +              (size >= 0) ?
> +              validSize = GL_TRUE : validSize = GL_FALSE;
> +              /* TODO : add target specific checks */
> +              break;
> +            default:
> +              /* should not get there at this point */
> +              return;
> +          }
> +
> +          if(!validOffet || !validSize) {
> +            _mesa_error(ctx, GL_INVALID_VALUE,
> +                      "glBindBuffersRange(offsets and/or sizes invalid)");
> +            return;
> +          }
> +
> +          if(offset+size > bufferObj->Size) {
> +            _mesa_error(ctx, GL_INVALID_VALUE,
> +                      "glBindBuffersRange(offset+size > GL_BUFFER_SIZE)");
> +            return;
> +          }
> +          _mesa_BindBufferRange(target, first+i, buffer, offset, size);
> +        }
> +        else
> +          _mesa_error(ctx, GL_INVALID_OPERATION,
> +                      "glBindBuffersRange(buffers)");
> +      }
> +      else
> +        _mesa_BindBufferRange(target, first + i, 0, 0, 0);
> +   }
> +}
> diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
> index 71988b0..5bc3734 100644
> --- a/src/mesa/main/bufferobj.h
> +++ b/src/mesa/main/bufferobj.h
> @@ -191,6 +191,11 @@ _mesa_InvalidateBufferSubData(GLuint buffer, GLintptr offset,
>  
>  void GLAPIENTRY
>  _mesa_InvalidateBufferData(GLuint buffer);
> -
> -
> +void GLAPIENTRY
> +_mesa_BindBuffersBase(GLenum target, GLuint first, GLsizei count,
> +                           const GLuint *buffers);
> +void GLAPIENTRY
> +_mesa_BindBuffersRange(GLenum target, GLuint first, GLsizei count, 
> +                       const GLuint *buffers, const GLintptr *offsets,
> +                       const GLsizeiptr *sizes);
>  #endif
> 



More information about the mesa-dev mailing list