st/mesa: improve format selection for GLES
authorMarek Olšák <marek.olsak@amd.com>
Sat, 28 Sep 2013 19:28:53 +0000 (21:28 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 8 Oct 2013 14:23:04 +0000 (16:23 +0200)
Reviewed-by: Wladimir J. van der Laan <laanwj@gmail.com>
src/mesa/main/texgetimage.c
src/mesa/main/texgetimage.h
src/mesa/state_tracker/st_format.c

index 7050f1080a4fd013db35aafd13429dac698cd90c..d66ca1abcc63f463325bdcf4e8c08b749f2db6da 100644 (file)
@@ -319,7 +319,7 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
  * Return a base GL format given the user-requested format
  * for glGetTexImage().
  */
-static GLenum
+GLenum
 _mesa_base_pack_format(GLenum format)
 {
    switch (format) {
index 91ae6e2e969389c3a3cc94dc6a5dd669fe261b7f..a292fabc0d47cd1710e6dac9252b0f67b4684643 100644 (file)
@@ -33,6 +33,9 @@ struct gl_context;
 struct gl_texture_image;
 struct gl_texture_object;
 
+extern GLenum
+_mesa_base_pack_format(GLenum format);
+
 extern void
 _mesa_get_teximage(struct gl_context *ctx,
                    GLenum format, GLenum type, GLvoid *pixels,
index 64bfd1faaff9da293cf1d54225fba42aaa2461f9..33c2ca661795a9f7628f4570dfe5645344912cb1 100644 (file)
@@ -35,6 +35,8 @@
 #include "main/imports.h"
 #include "main/context.h"
 #include "main/glformats.h"
+#include "main/texgetimage.h"
+#include "main/teximage.h"
 #include "main/texstore.h"
 #include "main/image.h"
 #include "main/macros.h"
@@ -1745,6 +1747,40 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
         bindings |= PIPE_BIND_RENDER_TARGET;
    }
 
+   /* GLES allows the driver to choose any format which matches
+    * the format+type combo, because GLES only supports unsized internal
+    * formats and expects the driver to choose whatever suits it.
+    */
+   if (_mesa_is_gles(ctx)) {
+      GLenum baseFormat = _mesa_base_tex_format(ctx, internalFormat);
+      GLenum basePackFormat = _mesa_base_pack_format(format);
+      GLenum iformat = internalFormat;
+
+      /* Treat GL_BGRA as GL_RGBA. */
+      if (iformat == GL_BGRA)
+         iformat = GL_RGBA;
+
+      /* Check if the internalformat is unsized and compatible
+       * with the "format".
+       */
+      if (iformat == baseFormat && iformat == basePackFormat) {
+         pFormat = st_choose_matching_format(st->pipe->screen, bindings,
+                                             format, type,
+                                             ctx->Unpack.SwapBytes);
+
+         if (pFormat != PIPE_FORMAT_NONE)
+            return st_pipe_format_to_mesa_format(pFormat);
+
+         /* try choosing format again, this time without render target bindings */
+         pFormat = st_choose_matching_format(st->pipe->screen,
+                                             PIPE_BIND_SAMPLER_VIEW,
+                                             format, type,
+                                             ctx->Unpack.SwapBytes);
+         if (pFormat != PIPE_FORMAT_NONE)
+            return st_pipe_format_to_mesa_format(pFormat);
+      }
+   }
+
    pFormat = st_choose_format(st, internalFormat, format, type,
                               PIPE_TEXTURE_2D, 0, bindings, ctx->Mesa_DXTn);