[Mesa-dev] [PATCH] GL_OES_texture_float and GL_OES_texture_half_float support

Matt Turner mattst88 at gmail.com
Tue May 6 09:28:10 PDT 2014


The title should be something like

mesa: Expose GL_OES_texture_float and GL_OES_texture_half_float.

Have you found an application that wants these extensions? That might
be useful to describe in the commit message.

On Tue, May 6, 2014 at 4:02 AM, Kevin Rogovin <kevin.rogovin at intel.com> wrote:
> Add support for GLES2 extentions for floating point and half
> floating point textures (GL_OES_texture_float, GL_OES_texture_half_float,
> GL_OES_texture_float_linear and GL_OES_texture_half_float_linear).
>
> ---
>  src/mesa/main/extensions.c | 12 +++++++++
>  src/mesa/main/glformats.c  | 27 ++++++++++++++++++++
>  src/mesa/main/pack.c       | 17 +++++++++++++
>  src/mesa/main/teximage.c   | 61 ++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 117 insertions(+)
>
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
> index c2ff7e3..58a5a51 100644
> --- a/src/mesa/main/extensions.c
> +++ b/src/mesa/main/extensions.c
> @@ -360,6 +360,18 @@ static const struct extension extension_table[] = {
>     { "GL_SGIS_texture_lod",                        o(dummy_true),                              GLL,            1997 },
>     { "GL_SUN_multi_draw_arrays",                   o(dummy_true),                              GLL,            1999 },
>
> +   /*
> +     TODO:
> +      - rather than have an all or nothing approach for floating point textures,
> +        allow for driver to specify what parts of floating point texture funtionality

functionality

> +        is supported: float/half-float and filtering for each.

For which driver would that be useful?

> +    */
> +   { "GL_OES_texture_float",                       o(ARB_texture_float),                       ES2|ES3,        2005 },
> +   { "GL_OES_texture_half_float",                  o(ARB_texture_float),                       ES2|ES3,        2005 },
> +   { "GL_OES_texture_float_linear",                o(ARB_texture_float),                       ES2|ES3,        2005 },
> +   { "GL_OES_texture_half_float_linear",           o(ARB_texture_float),                       ES2|ES3,        2005 },

The ES3 bit is for extensions that can not be exposed in ES2. ES2
means that it will be exposed in both ES2 and ES3.

The extension table is organized by extension prefix. Put these
extensions in the proper place.

> +
> +
>     { 0, 0, 0, 0 },
>  };
>
> diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
> index 9bb341c..be728f4 100644
> --- a/src/mesa/main/glformats.c
> +++ b/src/mesa/main/glformats.c
> @@ -93,6 +93,7 @@ _mesa_sizeof_type(GLenum type)
>     case GL_DOUBLE:
>        return sizeof(GLdouble);
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        return sizeof(GLhalfARB);
>     case GL_FIXED:
>        return sizeof(GLfixed);
> @@ -125,6 +126,7 @@ _mesa_sizeof_packed_type(GLenum type)
>     case GL_INT:
>        return sizeof(GLint);
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        return sizeof(GLhalfARB);
>     case GL_FLOAT:
>        return sizeof(GLfloat);
> @@ -243,6 +245,7 @@ _mesa_bytes_per_pixel(GLenum format, GLenum type)
>     case GL_FLOAT:
>        return comps * sizeof(GLfloat);
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        return comps * sizeof(GLhalfARB);
>     case GL_UNSIGNED_BYTE_3_3_2:
>     case GL_UNSIGNED_BYTE_2_3_3_REV:
> @@ -1365,6 +1368,11 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
>              case GL_FLOAT:
>              case GL_HALF_FLOAT:
>                 return GL_NO_ERROR;
> +            case GL_HALF_FLOAT_OES:
> +               return (format==GL_LUMINANCE ||
> +                       format==GL_LUMINANCE_ALPHA ||
> +                       format==GL_ALPHA)

Spaces around operators. Repeated below as well.

> +                  ? GL_NO_ERROR: GL_INVALID_ENUM;
>              default:
>                 return GL_INVALID_ENUM;
>           }
> @@ -1401,6 +1409,9 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
>              case GL_UNSIGNED_SHORT_5_6_5_REV:
>              case GL_HALF_FLOAT:
>                 return GL_NO_ERROR;
> +            case GL_HALF_FLOAT_OES:
> +               return (format==GL_RGB)
> +                  ? GL_NO_ERROR: GL_INVALID_ENUM;
>              case GL_UNSIGNED_INT_2_10_10_10_REV:
>                 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
>                 return (ctx->API == API_OPENGLES2)
> @@ -1454,6 +1465,9 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
>              case GL_UNSIGNED_INT_2_10_10_10_REV:
>              case GL_HALF_FLOAT:
>                 return GL_NO_ERROR;
> +            case GL_HALF_FLOAT_OES:
> +               return (format==GL_RGBA)
> +                  ? GL_NO_ERROR: GL_INVALID_ENUM;
>              default:
>                 return GL_INVALID_ENUM;
>           }
> @@ -1666,6 +1680,7 @@ _mesa_es_error_check_format_and_type(GLenum format, GLenum type,
>     return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION;
>  }
>
> +

Stray whitespace change.

>
>  /**
>   * Do error checking of format/type combinations for OpenGL ES 3
> @@ -1676,6 +1691,18 @@ GLenum
>  _mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
>                                        GLenum internalFormat)
>  {
> +   /*
> +     special case checking for support the GLES2 extension
> +     GL_OES_texture_float and GL_OES_texture_half_float
> +    */
> +   if(format==internalFormat
> +      && (type==GL_HALF_FLOAT_OES || type==GL_FLOAT)
> +      && (format==GL_RGBA || format==GL_RGB ||
> +          format==GL_LUMINANCE || format==GL_ALPHA ||
> +          format==GL_LUMINANCE_ALPHA) ) {
> +      return GL_NO_ERROR;
> +   }
> +
>     switch (format) {
>     case GL_RGBA:
>        switch (type) {
> diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
> index 1df6568..4b298ea 100644
> --- a/src/mesa/main/pack.c
> +++ b/src/mesa/main/pack.c
> @@ -2355,6 +2355,7 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
>           }
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           {
>              GLhalfARB *dst = (GLhalfARB *) dstAddr;
>              switch (dstFormat) {
> @@ -2785,6 +2786,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
>            srcType == GL_INT ||
>            srcType == GL_UNSIGNED_INT_24_8_EXT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
>
> @@ -2924,6 +2926,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
>           }
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           {
>              GLuint i;
>              const GLhalfARB *s = (const GLhalfARB *) src;
> @@ -3172,6 +3175,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -3289,6 +3293,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
>           PROCESS(aSrc, ACOMP, 1.0F, 1.0F, GLfloat, (GLfloat));
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           PROCESS(rSrc, RCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
>           PROCESS(gSrc, GCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
>           PROCESS(bSrc, BCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
> @@ -3789,6 +3794,7 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -3886,6 +3892,7 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
>           PROCESS(aSrc, ACOMP, 1, GLfloat, clamp_float_to_uint);
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           PROCESS(rSrc, RCOMP, 0, GLhalfARB, clamp_half_to_uint);
>           PROCESS(gSrc, GCOMP, 0, GLhalfARB, clamp_half_to_uint);
>           PROCESS(bSrc, BCOMP, 0, GLhalfARB, clamp_half_to_uint);
> @@ -4290,6 +4297,7 @@ _mesa_unpack_color_span_ubyte(struct gl_context *ctx,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -4543,6 +4551,7 @@ _mesa_unpack_color_span_float( struct gl_context *ctx,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -4747,6 +4756,7 @@ _mesa_unpack_color_span_uint(struct gl_context *ctx,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -4870,6 +4880,7 @@ _mesa_unpack_dudv_span_byte( struct gl_context *ctx,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT);
>
>     /* general solution */
> @@ -4940,6 +4951,7 @@ _mesa_unpack_index_span( struct gl_context *ctx, GLuint n,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT);
>
>     ASSERT(dstType == GL_UNSIGNED_BYTE ||
> @@ -5111,6 +5123,7 @@ _mesa_pack_index_span( struct gl_context *ctx, GLuint n,
>        }
>        break;
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        {
>           GLhalfARB *dst = (GLhalfARB *) dest;
>           GLuint i;
> @@ -5160,6 +5173,7 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
>            srcType == GL_INT ||
>            srcType == GL_UNSIGNED_INT_24_8_EXT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
>
> @@ -5350,6 +5364,7 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
>        }
>        break;
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        {
>           GLhalfARB *dst = (GLhalfARB *) dest;
>           GLuint i;
> @@ -5567,6 +5582,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
>           needClamp = GL_TRUE;
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           {
>              GLuint i;
>              const GLhalfARB *src = (const GLhalfARB *) source;
> @@ -5756,6 +5772,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
>        }
>        break;
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        {
>           GLhalfARB *dst = (GLhalfARB *) dest;
>           GLuint i;
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index c7f301c..79098ee 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -61,6 +61,58 @@
>  #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
>
>
> +/**
> + * Modify a texture format from as expected by GL_OES_texture_float
> + * and/or GL_OES_texture_half_float to as expected by GLES3 or GL3
> + */
> +static
> +void

static and void on the same line

> +adjust_for_oes_float_texture(GLenum *internalFormat,
> +                             GLenum *format, GLenum *type)
> +{
> +   if(*format==*internalFormat)

Space between if and (. Same comment for switch( below.

> +      switch(*type) {
> +      case GL_FLOAT:
> +         switch(*format) {
> +         case GL_RGBA:
> +            *internalFormat = GL_RGBA32F;
> +            break;
> +         case GL_RGB:
> +            *internalFormat = GL_RGB32F;
> +            break;
> +         case GL_ALPHA:
> +            *internalFormat = GL_ALPHA32F_ARB;
> +            break;
> +         case GL_LUMINANCE:
> +            *internalFormat = GL_LUMINANCE32F_ARB;
> +            break;
> +         case GL_LUMINANCE_ALPHA:
> +            *internalFormat = GL_LUMINANCE_ALPHA32F_ARB;
> +            break;
> +         }
> +         break;
> +
> +      case GL_HALF_FLOAT_OES:
> +         switch(*format) {
> +         case GL_RGBA:
> +            *internalFormat = GL_RGBA16F;
> +            break;
> +         case GL_RGB:
> +            *internalFormat = GL_RGB16F;
> +            break;
> +         case GL_ALPHA:
> +            *internalFormat = GL_ALPHA16F_ARB;
> +            break;
> +         case GL_LUMINANCE:
> +            *internalFormat = GL_LUMINANCE16F_ARB;
> +            break;
> +         case GL_LUMINANCE_ALPHA:
> +            *internalFormat = GL_LUMINANCE_ALPHA16F_ARB;
> +            break;
> +         }
> +         break;
> +      }
> +}
>
>  /**
>   * Return the simple base format for a given internal texture format.
> @@ -2976,6 +3028,15 @@ _mesa_choose_texture_format(struct gl_context *ctx,
>  {
>     mesa_format f;
>
> +   /*
> +     Change internalFormat and type to support floating
> +     point textures from GLES2 extensions
> +     GL_OES_texture_half_float and GL_OES_texture_float
> +    */

Comment style is

/* Comments comments comments
 * More comments
 */

> +   if(_mesa_is_gles(ctx)) {
> +      adjust_for_oes_float_texture(&internalFormat, &format, &type);
> +   }
> +
>     /* see if we've already chosen a format for the previous level */
>     if (level > 0) {
>        struct gl_texture_image *prevImage =
> --


More information about the mesa-dev mailing list