[Mesa-dev] Feature testing

Brian Paul brianp at vmware.com
Fri Aug 24 14:12:06 PDT 2012


On 08/24/2012 09:46 AM, Ian Romanick wrote:

> @@ -372,6 +380,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
>         case GL_LIGHT5:
>         case GL_LIGHT6:
>         case GL_LIGHT7:
> +         if (ctx->API != API_OPENGL&&  ctx->API != API_OPENGLES)
> +            goto invalid_enum_error;

[..]

>     case GL_BUFFER_MAP_OFFSET:
> -      if (!ctx->Extensions.ARB_map_buffer_range)
> +      if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_map_buffer_range)
> +          && !_mesa_is_gles3(ctx))
>           goto invalid_pname;
>        *params = (GLint) bufObj->Offset;
>        return;



I think there's opportunity to simplify a bunch of these feature checks.

How about helper macros like:

/** Is fixed-function lighting supported? */
static inline GLboolean
_mesa_have_lighting(const struct gl_context *ctx)
{
    return ctx->API == API_OPENGL || ctx->API == API_OPENGLES;
}


/** Is map-buffer-range supported? */
static inline GLboolean
_mesa_have_map_buffer_range(const struct gl_context *ctx)
{
    return (_mesa_is_desktop_gl(ctx) && 
ctx->Extensions.ARB_map_buffer_range)
     || _mesa_is_gles3(ctx);
}


I know this isn't practical everywhere, but it would improve the 
readability in many places and if we get the logic wrong for some 
feature (or it changes with a new GL version/ext in the future) it can 
be fixed in one place, easily grepped for, etc.

-Brian


More information about the mesa-dev mailing list