gallium/hud: use sRGB for nicer AA lines
authorMarek Olšák <marek.olsak@amd.com>
Wed, 17 Aug 2016 16:27:48 +0000 (18:27 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 22 Aug 2016 14:01:35 +0000 (16:01 +0200)
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/hud/hud_context.c

index fb9c8c65af321d845688d4715954833edfbd8175..8ab998ed9ac272a4ccb4021b580a029320940c83 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "cso_cache/cso_context.h"
 #include "util/u_draw_quad.h"
+#include "util/u_format.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_math.h"
@@ -97,6 +98,8 @@ struct hud_context {
       unsigned max_num_vertices;
       unsigned num_vertices;
    } text, bg, whitelines;
+
+   bool has_srgb;
 };
 
 #ifdef PIPE_OS_UNIX
@@ -484,6 +487,18 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
    /* set states */
    memset(&surf_templ, 0, sizeof(surf_templ));
    surf_templ.format = tex->format;
+
+   /* Without this, AA lines look thinner if they are between 2 pixels
+    * because the alpha is 0.5 on both pixels. (it's ugly)
+    *
+    * sRGB makes the width of all AA lines look the same.
+    */
+   if (hud->has_srgb) {
+      enum pipe_format srgb_format = util_format_srgb(tex->format);
+
+      if (srgb_format != PIPE_FORMAT_NONE)
+         surf_templ.format = srgb_format;
+   }
    surf = pipe->create_surface(pipe, tex, &surf_templ);
 
    memset(&fb, 0, sizeof(fb));
@@ -1138,6 +1153,7 @@ print_help(struct pipe_screen *screen)
 struct hud_context *
 hud_create(struct pipe_context *pipe, struct cso_context *cso)
 {
+   struct pipe_screen *screen = pipe->screen;
    struct hud_context *hud;
    struct pipe_sampler_view view_templ;
    unsigned i;
@@ -1173,6 +1189,11 @@ hud_create(struct pipe_context *pipe, struct cso_context *cso)
       return NULL;
    }
 
+   hud->has_srgb = screen->is_format_supported(screen,
+                                               PIPE_FORMAT_B8G8R8A8_SRGB,
+                                               PIPE_TEXTURE_2D, 0,
+                                               PIPE_BIND_RENDER_TARGET) != 0;
+
    /* blend state */
    hud->no_blend.rt[0].colormask = PIPE_MASK_RGBA;