[Mesa-dev] [PATCH 06/18] mesa: Implement glBindSamplers()

Brian Paul brianp at vmware.com
Wed Jan 22 09:00:40 PST 2014


On 01/21/2014 03:35 PM, Fredrik Höglund wrote:
> ---
>   src/mesa/main/samplerobj.c |  115 ++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 115 insertions(+)
>
> diff --git a/src/mesa/main/samplerobj.c b/src/mesa/main/samplerobj.c
> index 077ee9e..f34d95d 100644
> --- a/src/mesa/main/samplerobj.c
> +++ b/src/mesa/main/samplerobj.c
> @@ -51,6 +51,28 @@ _mesa_lookup_samplerobj(struct gl_context *ctx, GLuint name)
>   }
>
>
> +static inline void
> +begin_samplerobj_lookups(struct gl_context *ctx)
> +{
> +   _mesa_HashLockMutex(ctx->Shared->SamplerObjects);
> +}
> +
> +
> +static inline void
> +end_samplerobj_lookups(struct gl_context *ctx)
> +{
> +   _mesa_HashUnlockMutex(ctx->Shared->SamplerObjects);
> +}
> +
> +
> +static inline struct gl_sampler_object *
> +lookup_samplerobj_without_locking(struct gl_context *ctx, GLuint name)
> +{
> +   return (struct gl_sampler_object *)
> +         _mesa_HashLookupWithoutLocking(ctx->Shared->SamplerObjects, name);
> +}
> +
> +
>   /**
>    * Handle reference counting.
>    */
> @@ -288,6 +310,99 @@ _mesa_BindSampler(GLuint unit, GLuint sampler)
>   void GLAPIENTRY
>   _mesa_BindSamplers(GLuint first, GLsizei count, const GLuint *samplers)
>   {
> +   GET_CURRENT_CONTEXT(ctx);
> +   GLuint i;

GLint or GLsizei i, to avoid MSVC warnings about comparing 
signed/unsigned values.


> +
> +   /* The ARB_multi_bind spec says:
> +    *
> +    *   "An INVALID_OPERATION error is generated if <first> + <count> is
> +    *    greater than the number of texture image units supported by
> +    *    the implementation."
> +    */
> +   if (first + count > ctx->Const.MaxCombinedTextureImageUnits) {
> +      _mesa_error(ctx, GL_INVALID_OPERATION,
> +                  "glBindSamplers(first=%u + count=%u > the value of "
> +                  "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS=%u)",
> +                  first, count, ctx->Const.MaxCombinedTextureImageUnits);
> +      return;
> +   }
> +
> +   FLUSH_VERTICES(ctx, 0);
> +
> +   if (samplers) {
> +      /* Note that the error semantics for multi-bind commands differ from
> +       * those of other GL commands.
> +       *
> +       * The issues section in the ARB_multi_bind spec says:
> +       *
> +       *    "(11) Typically, OpenGL specifies that if an error is generated by
> +       *          a command, that command has no effect.  This is somewhat
> +       *          unfortunate for multi-bind commands, because it would require
> +       *          a first pass to scan the entire list of bound objects for
> +       *          errors and then a second pass to actually perform the
> +       *          bindings.  Should we have different error semantics?
> +       *
> +       *       RESOLVED:  Yes.  In this specification, when the parameters for
> +       *       one of the <count> binding points are invalid, that binding
> +       *       point is not updated and an error will be generated.  However,
> +       *       other binding points in the same command will be updated if
> +       *       their parameters are valid and no other error occurs."
> +       */
> +
> +      begin_samplerobj_lookups(ctx);
> +
> +      for (i = 0; i < count; i++) {
> +         const GLuint unit = first + i;
> +         struct gl_sampler_object *currentSampler =
> +             ctx->Texture.Unit[unit].Sampler;

I think that pointer could be const-qualified.


> +         struct gl_sampler_object *sampObj;
> +
> +         if (samplers[i] != 0) {
> +            if (currentSampler && currentSampler->Name == samplers[i])
> +               sampObj = currentSampler;
> +            else
> +               sampObj = lookup_samplerobj_without_locking(ctx, samplers[i]);
> +
> +            /* The ARB_multi_bind spec says:
> +             *
> +             *    "An INVALID_OPERATION error is generated if any value
> +             *     in <samplers> is not zero or the name of an existing
> +             *     sampler object (per binding)."
> +             */
> +            if (!sampObj) {
> +               _mesa_error(ctx, GL_INVALID_OPERATION,
> +                           "glBindSamplers(samplers[%u]=%u is not zero or"
> +                           "the name of an existing sampler object)",

Need a space between "or" and "the".


> +                           i, samplers[i]);
> +               continue;
> +            }
> +         } else {
> +            sampObj = NULL;
> +         }
> +
> +         /* Bind the new sampler */
> +         if (sampObj != currentSampler) {
> +            _mesa_reference_sampler_object(ctx,
> +                                           &ctx->Texture.Unit[unit].Sampler,
> +                                           sampObj);
> +            ctx->NewState |= _NEW_TEXTURE;
> +         }
> +      }
> +
> +      end_samplerobj_lookups(ctx);
> +   } else {
> +      /* Unbind all samplers in the range <first> through <first>+<count>-1 */
> +      for (i = 0; i < count; i++) {
> +         const GLuint unit = first + i;
> +
> +         if (ctx->Texture.Unit[unit].Sampler) {
> +            _mesa_reference_sampler_object(ctx,
> +                                           &ctx->Texture.Unit[unit].Sampler,
> +                                           NULL);
> +            ctx->NewState |= _NEW_TEXTURE;
> +         }
> +      }
> +   }
>   }
>
>
>



More information about the mesa-dev mailing list