mesa: Make a Mesa core function for sRGB render encoding handling.
authorEric Anholt <eric@anholt.net>
Thu, 18 Apr 2013 16:20:55 +0000 (09:20 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 30 Apr 2013 18:59:23 +0000 (11:59 -0700)
v2: const-qualify ctx, and add a comment about the function (recommended
    by Brian and Kenneth).

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (v1)
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
src/mesa/main/blend.c
src/mesa/main/blend.h

index f1976391b1a388e0c868ae859c0b19bfa34f17b8..ee2c9f17c1ee1a6e75a5147cad62d133ee201471 100644 (file)
@@ -31,6 +31,7 @@
                    
 
 #include "main/context.h"
+#include "main/blend.h"
 #include "main/mtypes.h"
 #include "main/samplerobj.h"
 #include "program/prog_parameter.h"
@@ -1229,7 +1230,8 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
    uint32_t *surf;
    uint32_t tile_x, tile_y;
    uint32_t format = 0;
-   gl_format rb_format = intel_rb_format(irb);
+   /* _NEW_BUFFERS */
+   gl_format rb_format = _mesa_get_render_format(ctx, intel_rb_format(irb));
 
    if (irb->tex_image && !brw->has_surface_tile_offset) {
       intel_renderbuffer_tile_offsets(irb, &tile_x, &tile_y);
@@ -1251,25 +1253,10 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
    surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,
                          6 * 4, 32, &brw->wm.surf_offset[unit]);
 
-   switch (rb_format) {
-   case MESA_FORMAT_SARGB8:
-      /* _NEW_BUFFERS
-       *
-       * Without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB surfaces to the
-       * blend/update as sRGB.
-       */
-      if (ctx->Color.sRGBEnabled)
-        format = brw_format_for_mesa_format(rb_format);
-      else
-        format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
-      break;
-   default:
-      format = brw->render_target_format[rb_format];
-      if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
-        _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
-                      __FUNCTION__, _mesa_get_format_name(rb_format));
-      }
-      break;
+   format = brw->render_target_format[rb_format];
+   if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
+      _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
+                    __FUNCTION__, _mesa_get_format_name(rb_format));
    }
 
    surf[0] = (BRW_SURFACE_2D << BRW_SURFACE_TYPE_SHIFT |
index 761ceb07d121dba31cfbabd4ab9cea5277b4c1ce..435f9dc00412bf3ef5168c1534cd96439e3b7618 100644 (file)
@@ -21,6 +21,7 @@
  * IN THE SOFTWARE.
  */
 #include "main/mtypes.h"
+#include "main/blend.h"
 #include "main/samplerobj.h"
 #include "program/prog_parameter.h"
 
@@ -529,7 +530,8 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,
    struct intel_region *region = irb->mt->region;
    uint32_t tile_x, tile_y;
    uint32_t format;
-   gl_format rb_format = intel_rb_format(irb);
+   /* _NEW_BUFFERS */
+   gl_format rb_format = _mesa_get_render_format(ctx, intel_rb_format(irb));
 
    uint32_t *surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,
                                     8 * 4, 32, &brw->wm.surf_offset[unit]);
@@ -538,26 +540,11 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,
    /* Render targets can't use IMS layout */
    assert(irb->mt->msaa_layout != INTEL_MSAA_LAYOUT_IMS);
 
-   switch (rb_format) {
-   case MESA_FORMAT_SARGB8:
-      /* _NEW_BUFFERS
-       *
-       * Without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB surfaces to the
-       * blend/update as sRGB.
-       */
-      if (ctx->Color.sRGBEnabled)
-        format = brw_format_for_mesa_format(rb_format);
-      else
-        format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
-      break;
-   default:
-      assert(brw_render_target_supported(intel, rb));
-      format = brw->render_target_format[rb_format];
-      if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
-        _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
-                      __FUNCTION__, _mesa_get_format_name(rb_format));
-      }
-      break;
+   assert(brw_render_target_supported(intel, rb));
+   format = brw->render_target_format[rb_format];
+   if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
+      _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
+                    __FUNCTION__, _mesa_get_format_name(rb_format));
    }
 
    surf[0] = BRW_SURFACE_2D << BRW_SURFACE_TYPE_SHIFT |
index 7413b15623300cbdc39c973f09bb1f476958e233..0c28352b236c91bac03a8e58fb6fc0f084121a4b 100644 (file)
@@ -856,6 +856,23 @@ _mesa_update_clamp_vertex_color(struct gl_context *ctx)
    ctx->Light._ClampVertexColor = _mesa_get_clamp_vertex_color(ctx);
 }
 
+/**
+ * Returns an appropriate gl_format for color rendering based on the
+ * GL_FRAMEBUFFER_SRGB state.
+ *
+ * Some drivers implement GL_FRAMEBUFFER_SRGB using a flag on the blend state
+ * (which GL_FRAMEBUFFER_SRGB maps to reasonably), but some have to do so by
+ * overriding the format of the surface.  This is a helper for doing the
+ * surface format override variant.
+ */
+gl_format
+_mesa_get_render_format(const struct gl_context *ctx, gl_format format)
+{
+   if (ctx->Color.sRGBEnabled)
+      return format;
+   else
+      return _mesa_get_srgb_format_linear(format);
+}
 
 /**********************************************************************/
 /** \name Initialization */
index 5b7a025910279650b6bd5b846e2d2c3e5f06de41..b43b3ccb3159832ff6e39dd8516e942cf1951add 100644 (file)
@@ -35,6 +35,7 @@
 
 
 #include "glheader.h"
+#include "formats.h"
 
 struct gl_context;
 
@@ -115,6 +116,9 @@ _mesa_update_clamp_fragment_color(struct gl_context *ctx);
 extern void
 _mesa_update_clamp_vertex_color(struct gl_context *ctx);
 
+extern gl_format
+_mesa_get_render_format(const struct gl_context *ctx, gl_format format);
+
 extern void  
 _mesa_init_color( struct gl_context * ctx );