Mesa (master): mesa/965: add support for GL_EXT_framebuffer_sRGB (v2)

Dave Airlie airlied at kemper.freedesktop.org
Sat Feb 5 07:08:48 UTC 2011


Module: Mesa
Branch: master
Commit: 88ffa9ce5b8e5fe2b93238f8b9a7a888be28324e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=88ffa9ce5b8e5fe2b93238f8b9a7a888be28324e

Author: Dave Airlie <airlied at gmail.com>
Date:   Fri Jan 28 14:16:00 2011 +1000

mesa/965: add support for GL_EXT_framebuffer_sRGB (v2)

This adds i965 support for GL_EXT_framebuffer_sRGB, it introduces a new
constant to say that the driver can support sRGB enabled FBOs since enabling
the extension doesn't mean the driver can actually support sRGB.

Also adds the suggested state flush in the core code suggested by Brian.

fix the ARB_fbo color encoding.

Signed-off-by: Dave Airlie <airlied at redhat.com>

---

 src/mesa/drivers/dri/i965/brw_wm_surface_state.c |    5 ++++-
 src/mesa/drivers/dri/intel/intel_context.c       |    1 +
 src/mesa/drivers/dri/intel/intel_extensions.c    |    1 +
 src/mesa/main/enable.c                           |    7 ++++---
 src/mesa/main/fbobject.c                         |    2 +-
 src/mesa/main/framebuffer.c                      |    2 ++
 src/mesa/main/mtypes.h                           |    3 +++
 7 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index a372554..c931df3 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -446,7 +446,10 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
    case MESA_FORMAT_SARGB8:
       /* without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB
 	 surfaces to the blend/update as sRGB */
-      surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
+      if (ctx->Color.sRGBEnabled)
+	 surf.ss0.surface_format = brw_format_for_mesa_format[irb->Base.Format];
+      else
+	 surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
       break;
    default:
       surf.ss0.surface_format = brw_format_for_mesa_format[irb->Base.Format];
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index 2a50299..432a22a 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -807,6 +807,7 @@ intelInitContext(struct intel_context *intel,
 
    meta_init_metaops(ctx, &intel->meta);
    if (intel->gen >= 4) {
+      ctx->Const.sRGBCapable = GL_TRUE;
       if (MAX_WIDTH > 8192)
 	 ctx->Const.MaxRenderbufferSize = 8192;
    } else {
diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c
index 747e9dc..febc1d4 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.c
+++ b/src/mesa/drivers/dri/intel/intel_extensions.c
@@ -175,6 +175,7 @@ static const struct dri_extension brw_extensions[] = {
    { "GL_ARB_texture_non_power_of_two",   NULL },
    { "GL_ARB_texture_rg",                 NULL },
    { "GL_EXT_draw_buffers2",              GL_EXT_draw_buffers2_functions },
+   { "GL_EXT_framebuffer_sRGB",           NULL },
    { "GL_EXT_shadow_funcs",               NULL },
    { "GL_EXT_stencil_two_side",           GL_EXT_stencil_two_side_functions },
    { "GL_EXT_texture_sRGB",		  NULL },
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index c4c4e1b..d34c6ff 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -970,9 +970,10 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 
       /* GL3.0 - GL_framebuffer_sRGB */
       case GL_FRAMEBUFFER_SRGB_EXT:
-	 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
-	 ctx->Color.sRGBEnabled = state;
-	 break;
+         CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
+         FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+         ctx->Color.sRGBEnabled = state;
+         break;
 
       default:
          goto invalid_enum_error;
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 04f02ce..97cbd3c 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -2157,7 +2157,7 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
                      "glGetFramebufferAttachmentParameterivEXT(pname)");
       }
       else {
-         if (ctx->Extensions.EXT_framebuffer_sRGB) {
+         if (ctx->Extensions.EXT_framebuffer_sRGB && ctx->Const.sRGBCapable) {
             *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
          }
          else {
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 63da71c..948b3b7 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -553,6 +553,8 @@ _mesa_update_framebuffer_visual(struct gl_context *ctx,
                + fb->Visual.greenBits + fb->Visual.blueBits;
             fb->Visual.floatMode = GL_FALSE;
             fb->Visual.samples = rb->NumSamples;
+            if (_mesa_get_format_color_encoding(fmt) == GL_SRGB)
+                fb->Visual.sRGBCapable = ctx->Const.sRGBCapable;
             break;
          }
       }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 37f39ce..4e76212 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2710,6 +2710,9 @@ struct gl_constants
 
    /** GL_EXT_gpu_shader4 */
    GLint MinProgramTexelOffset, MaxProgramTexelOffset;
+
+   /* GL_EXT_framebuffer_sRGB */
+   GLboolean sRGBCapable; /* can enable sRGB blend/update on FBOs */
 };
 
 




More information about the mesa-commit mailing list