[Mesa-dev] [PATCH 2/7] mesa: add an index_to_target_enum() function

Brian Paul brianp at vmware.com
Mon Jan 6 09:37:05 PST 2014


On 01/02/2014 05:27 PM, Maxence Le Doré wrote:
> From: Maxence Le Doré <Maxence Le Doré>
>
> ---
>   src/mesa/main/texobj.c | 40 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 40 insertions(+)
>
> diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
> index d6510fe..bddbc50 100644
> --- a/src/mesa/main/texobj.c
> +++ b/src/mesa/main/texobj.c
> @@ -1218,6 +1218,46 @@ target_enum_to_index(const struct gl_context *ctx, GLenum target)
>
>
>   /**
> + * Convert a Mesa texture target index into the corresponding
> + * GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D.
> + * Note that proxy targets are not valid here.
> + * \return GL_TEXTURE_x or 0x0 if index is invalid
> + */
> +static GLenum
> +index_to_target_enum(struct gl_context *ctx, GLint index)
> +{
> +   switch (index) {
> +     case TEXTURE_2D_MULTISAMPLE_INDEX:
> +       return GL_TEXTURE_2D_MULTISAMPLE;
> +     case TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX:
> +       return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
> +     case TEXTURE_CUBE_ARRAY_INDEX:
> +       return GL_TEXTURE_CUBE_MAP_ARRAY;
> +     case TEXTURE_BUFFER_INDEX:
> +       return GL_TEXTURE_BUFFER_ARB;
> +     case TEXTURE_2D_ARRAY_INDEX:
> +       return GL_TEXTURE_2D_ARRAY_EXT;
> +     case TEXTURE_1D_ARRAY_INDEX:
> +       return GL_TEXTURE_1D_ARRAY_EXT;
> +     case TEXTURE_EXTERNAL_INDEX:
> +       return GL_TEXTURE_EXTERNAL_OES;
> +     case TEXTURE_CUBE_INDEX:
> +       return GL_TEXTURE_CUBE_MAP_ARB;
> +     case TEXTURE_3D_INDEX:
> +       return GL_TEXTURE_3D;
> +     case TEXTURE_RECT_INDEX:
> +       return GL_TEXTURE_RECTANGLE_NV;
> +     case TEXTURE_2D_INDEX:
> +       return GL_TEXTURE_2D;
> +     case TEXTURE_1D_INDEX:
> +       return GL_TEXTURE_1D;
> +     default:
> +       return 0x0;
> +   }
> +}

We use 3-space indentation.

But this function could be done more efficiently:

static GLenum
index_to_target_enum(struct gl_context *ctx, GLint index)
{
    static const GLenum names[] = {
       GL_TEXTURE_2D_MULTISAMPLE,
       GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
       ...
    }
    STATIC_ASSSERT(Elements(names) == NUM_TEXTURE_TARGETS);
    assert(index < NUM_TEXTURE_TARGETS);
    return names[index];
}


And why is this function needed?  I don't see it used in the other 
patches (but maybe I missed it).

-Brian



More information about the mesa-dev mailing list