According to msdn, we must act as if user didn't ask srgb if we don't
support it.

Reviewed-by: David Heidelberg <da...@ixit.cz>
Signed-off-by: Axel Davy <axel.d...@ens.fr>

Cc: "10.4" <mesa-sta...@lists.freedesktop.org>
---
 src/gallium/state_trackers/nine/basetexture9.c | 11 ++++++++++-
 src/gallium/state_trackers/nine/surface9.c     | 10 +++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/nine/basetexture9.c 
b/src/gallium/state_trackers/nine/basetexture9.c
index ccfd199..ffccafd 100644
--- a/src/gallium/state_trackers/nine/basetexture9.c
+++ b/src/gallium/state_trackers/nine/basetexture9.c
@@ -446,8 +446,10 @@ NineBaseTexture9_UpdateSamplerView( struct 
NineBaseTexture9 *This,
 {
     const struct util_format_description *desc;
     struct pipe_context *pipe = This->pipe;
+    struct pipe_screen *screen = pipe->screen;
     struct pipe_resource *resource = This->base.resource;
     struct pipe_sampler_view templ;
+    enum pipe_format srgb_format;
     unsigned i;
     uint8_t swizzle[4];
 
@@ -494,7 +496,14 @@ NineBaseTexture9_UpdateSamplerView( struct 
NineBaseTexture9 *This,
         }
     }
 
-    templ.format = sRGB ? util_format_srgb(resource->format) : 
resource->format;
+    /* if requested and supported, convert to the sRGB format */
+    srgb_format = util_format_srgb(resource->format);
+    if (sRGB && srgb_format != PIPE_FORMAT_NONE &&
+        screen->is_format_supported(screen, srgb_format,
+                                    resource->target, 0, resource->bind))
+        templ.format = srgb_format;
+    else
+        templ.format = resource->format;
     templ.u.tex.first_layer = 0;
     templ.u.tex.last_layer = resource->target == PIPE_TEXTURE_3D ?
                              resource->depth0 - 1 : resource->array_size - 1;
diff --git a/src/gallium/state_trackers/nine/surface9.c 
b/src/gallium/state_trackers/nine/surface9.c
index e19d24b..5928892 100644
--- a/src/gallium/state_trackers/nine/surface9.c
+++ b/src/gallium/state_trackers/nine/surface9.c
@@ -150,14 +150,22 @@ struct pipe_surface *
 NineSurface9_CreatePipeSurface( struct NineSurface9 *This, const int sRGB )
 {
     struct pipe_context *pipe = This->pipe;
+    struct pipe_screen *screen = pipe->screen;
     struct pipe_resource *resource = This->base.resource;
     struct pipe_surface templ;
+    enum pipe_format srgb_format;
 
     assert(This->desc.Pool == D3DPOOL_DEFAULT ||
            This->desc.Pool == D3DPOOL_MANAGED);
     assert(resource);
 
-    templ.format = sRGB ? util_format_srgb(resource->format) : 
resource->format;
+    srgb_format = util_format_srgb(resource->format);
+    if (sRGB && srgb_format != PIPE_FORMAT_NONE &&
+        screen->is_format_supported(screen, srgb_format,
+                                    resource->target, 0, resource->bind))
+        templ.format = srgb_format;
+    else
+        templ.format = resource->format;
     templ.u.tex.level = This->level;
     templ.u.tex.first_layer = This->layer;
     templ.u.tex.last_layer = This->layer;
-- 
2.1.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to