mesa/core: Add definitions and translations for EXT_texture_sRGB_R8
authorGert Wollny <gert.wollny@collabora.com>
Thu, 1 Nov 2018 11:59:24 +0000 (12:59 +0100)
committerGert Wollny <gw.fossdev@gmail.com>
Fri, 2 Nov 2018 10:52:44 +0000 (11:52 +0100)
v2: - fix format definition line
    - disable  for desktop GL
    - don't add GL_R8_EXT to glext.h since it is already in
      GLES2/gl2ext.h in glext.h and include this header  where needed
      (all Emil)
v3: - swrast: Fill the function table for sRGB_R8
      The size of the function table is checked at compile time and must
      correspond to the number of mesa texture formats.
      dri/swrast being gles-2.0 doesn't support the extension though
v4: - correct format layout comment (Ilia Mirkin)
    - correct logic for accepting GL_RED only textures (in part Ilia Mirkin)
      EXT_texture_sRGB_R8 requires OpenGL ES 3.0 which includes
      ARB_texture_rg/EXT_texture_rg, so one only must check for the first
      when SR8_EXT is really requested.
v5: - add define for GL_ES8_XT to glheader.h and don't include GLES
      headers  (Ilia Mirkin)

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/mesa/main/extensions_table.h
src/mesa/main/formats.c
src/mesa/main/formats.csv
src/mesa/main/formats.h
src/mesa/main/glformats.c
src/mesa/main/glheader.h
src/mesa/main/mtypes.h
src/mesa/main/texformat.c
src/mesa/swrast/s_texfetch.c
src/mesa/swrast/s_texfetch_tmp.h

index e3bf7c9fcee368bdc32cc6c25a5bc7c41af2271f..a516a1b17f8992c77ab664a64b67daf1f58f5ab7 100644 (file)
@@ -296,6 +296,7 @@ EXT(EXT_texture_object                      , dummy_true
 EXT(EXT_texture_rectangle                   , NV_texture_rectangle                   , GLL,  x ,  x ,  x , 2004)
 EXT(EXT_texture_rg                          , ARB_texture_rg                         ,  x ,  x ,  x , ES2, 2011)
 EXT(EXT_texture_sRGB                        , EXT_texture_sRGB                       , GLL, GLC,  x ,  x , 2004)
+EXT(EXT_texture_sRGB_R8                     , EXT_texture_sRGB_R8                    ,  x ,  x ,  x ,  30, 2015)
 EXT(EXT_texture_sRGB_decode                 , EXT_texture_sRGB_decode                , GLL, GLC,  x ,  30, 2006)
 EXT(EXT_texture_shared_exponent             , EXT_texture_shared_exponent            , GLL, GLC,  x ,  x , 2004)
 EXT(EXT_texture_snorm                       , EXT_texture_snorm                      , GLL, GLC,  x ,  x , 2009)
index d4cd5d2182cfbc5b44bb12fe273e38cf807bc439..cf2d2bc555a127caf688383722642d88a62d8b6e 100644 (file)
@@ -1108,6 +1108,7 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
       *comps = 4;
       return;
    case MESA_FORMAT_L_SRGB8:
+   case MESA_FORMAT_R_SRGB8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 1;
       return;
@@ -1670,6 +1671,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
               (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && littleEndian != swapBytes));
 
    case MESA_FORMAT_R_UNORM8:
+   case MESA_FORMAT_R_SRGB8:
       return format == GL_RED && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_R8G8_UNORM:
       return format == GL_RG && type == GL_UNSIGNED_BYTE && littleEndian;
index ce53f8f056190124092da6740250953662096577..cb821fec62f075895cc4ec75dd4c16076e6f0654 100644 (file)
@@ -158,6 +158,7 @@ MESA_FORMAT_L8A8_SRGB                     , packed, 1, 1, 1, un8 , un8 ,     ,
 MESA_FORMAT_A8L8_SRGB                     , packed, 1, 1, 1, un8 , un8 ,     ,     , yyyx, srgb
 
 # Array sRGB formats
+MESA_FORMAT_R_SRGB8                       , array , 1, 1, 1, un8 ,     ,     ,     , x001, srgb
 MESA_FORMAT_L_SRGB8                       , array , 1, 1, 1, un8 ,     ,     ,     , xxx1, srgb
 MESA_FORMAT_BGR_SRGB8                     , array , 1, 1, 1, un8 , un8 , un8 ,     , zyx1, srgb
 
index 335e4de9955c4e02ebe11f7724e4fc401fb01f4f..15c561225d6a1f567db8e777a6b0729d535c0750 100644 (file)
@@ -440,6 +440,7 @@ typedef enum
    MESA_FORMAT_X8B8G8R8_SRGB,    /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
    MESA_FORMAT_L8A8_SRGB,                            /* AAAA AAAA LLLL LLLL */
    MESA_FORMAT_A8L8_SRGB,                            /* LLLL LLLL AAAA AAAA */
+   MESA_FORMAT_R_SRGB8,          /* RRRR RRRR */
 
    /* Array sRGB formats */
    MESA_FORMAT_L_SRGB8,       /* ubyte[i] = L */
index f8fc36e93117927584cc2f07ff5317b3b152d06a..6cdc7818756c5ee2704654807f7b48b7e7e70546 100644 (file)
@@ -2486,6 +2486,15 @@ _mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat)
       }
    }
 
+   if (ctx->Extensions.EXT_texture_sRGB_R8) {
+      switch (internalFormat) {
+      case GL_SR8_EXT:
+         return GL_RED;
+      default:
+         ; /* fallthrough */
+      }
+   }
+
    if (ctx->Version >= 30 ||
        ctx->Extensions.EXT_texture_integer) {
       switch (internalFormat) {
@@ -3215,9 +3224,11 @@ _mesa_es3_error_check_format_and_type(const struct gl_context *ctx,
          return GL_INVALID_OPERATION;
       switch (type) {
       case GL_UNSIGNED_BYTE:
-         if (internalFormat != GL_R8)
-            return GL_INVALID_OPERATION;
-         break;
+         if (internalFormat == GL_R8 ||
+             ((internalFormat == GL_SR8_EXT) &&
+              ctx->Extensions.EXT_texture_sRGB_R8))
+            break;
+         return GL_INVALID_OPERATION;
 
       case GL_BYTE:
          if (internalFormat != GL_R8_SNORM)
index e95fc9fb4fe5a31b3e829a1f891a6c3b05a5c022..4dd9a182be12b941770cd896622e27f11aef5b92 100644 (file)
@@ -138,6 +138,9 @@ typedef int GLclampx;
 #define GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI                   0x8837
 #endif
 
+#ifndef GL_EXT_texture_sRGB_R8
+#define GL_SR8_EXT                                              0x8FBD
+#endif
 
 /**
  * Internal token to represent a GLSL shader program (a collection of
index 9ed49b7ff24c1a873ea631ad1eee731035e85d2e..656e1226f94447cb0de9377fb5994edee2473089 100644 (file)
@@ -4264,6 +4264,7 @@ struct gl_extensions
    GLboolean EXT_texture_shared_exponent;
    GLboolean EXT_texture_snorm;
    GLboolean EXT_texture_sRGB;
+   GLboolean EXT_texture_sRGB_R8;
    GLboolean EXT_texture_sRGB_decode;
    GLboolean EXT_texture_swizzle;
    GLboolean EXT_texture_type_2_10_10_10_REV;
index 822f80f89edbf0dae1c037c853b8780eeb96f8ea..381edd554513ef61d2c258d19df22e9bdc2c468f 100644 (file)
@@ -477,6 +477,9 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
       RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
       break;
+   case GL_SR8_EXT:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R_SRGB8);
+      break;
    case GL_SLUMINANCE_EXT:
    case GL_SLUMINANCE8_EXT:
       RETURN_IF_SUPPORTED(MESA_FORMAT_L_SRGB8);
index fec8728a7a1220e468175e75706f86c4e0ed84c9..e8f4eb598a534f4c851abdc9a9cc40d4bc320974 100644 (file)
@@ -257,6 +257,7 @@ texfetch_funcs[] =
    FETCH_FUNCS(A8L8_SRGB),
 
    /* Array sRGB formats */
+   FETCH_FUNCS(R_SRGB8),
    FETCH_FUNCS(L_SRGB8),
    FETCH_FUNCS(BGR_SRGB8),
 
index 45bd8395048a1ddc99be26e6bbdf1ed43ae34c62..8261ebf46ef3532cbe2be5305c1ccb9c419dc898 100644 (file)
@@ -153,6 +153,7 @@ FETCH_RGBA(A8R8G8B8_SRGB, GLuint, 1)
 FETCH_RGBA(R8G8B8A8_SRGB, GLuint, 1)
 FETCH_RGBA(R8G8B8X8_SRGB, GLuint, 1)
 FETCH_RGBA(X8B8G8R8_SRGB, GLuint, 1)
+FETCH_RGBA(R_SRGB8, GLubyte, 1)
 FETCH_RGBA(L_SRGB8, GLubyte, 1)
 FETCH_RGBA(L8A8_SRGB, GLushort, 1)
 FETCH_RGBA(A8L8_SRGB, GLushort, 2)