Mesa (master): st/mesa: allow rendering to sRGB textures if EXT_fb_srgb is unsupported

Marek Olšák mareko at kemper.freedesktop.org
Fri Feb 11 00:09:59 UTC 2011


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

Author: Marek Olšák <maraeo at gmail.com>
Date:   Thu Feb 10 02:16:58 2011 +0100

st/mesa: allow rendering to sRGB textures if EXT_fb_srgb is unsupported

In this case, we always use the corresponding linear format in create_surface,
therefore we should check for linear format support as well.

---

 src/mesa/state_tracker/st_cb_fbo.c |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index 398e32a..0b0ad16 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -448,11 +448,14 @@ st_finish_render_texture(struct gl_context *ctx,
  * Validate a renderbuffer attachment for a particular set of bindings.
  */
 static GLboolean
-st_validate_attachment(struct pipe_screen *screen,
+st_validate_attachment(struct gl_context *ctx,
+		       struct pipe_screen *screen,
 		       const struct gl_renderbuffer_attachment *att,
 		       unsigned bindings)
 {
    const struct st_texture_object *stObj = st_texture_object(att->Texture);
+   enum pipe_format format;
+   gl_format texFormat;
 
    /* Only validate texture attachments for now, since
     * st_renderbuffer_alloc_storage makes sure that
@@ -464,7 +467,20 @@ st_validate_attachment(struct pipe_screen *screen,
    if (!stObj)
       return GL_FALSE;
 
-   return screen->is_format_supported(screen, stObj->pt->format,
+   format = stObj->pt->format;
+   texFormat =
+      stObj->base.Image[att->CubeMapFace][att->TextureLevel]->TexFormat;
+
+   /* If the encoding is sRGB and sRGB rendering cannot be enabled,
+    * check for linear format support instead.
+    * Later when we create a surface, we change the format to a linear one. */
+   if (!ctx->Const.sRGBCapable &&
+       _mesa_get_format_color_encoding(texFormat) == GL_SRGB) {
+      const gl_format linearFormat = _mesa_get_srgb_format_linear(texFormat);
+      format = st_mesa_format_to_pipe_format(linearFormat);
+   }
+
+   return screen->is_format_supported(screen, format,
                                       PIPE_TEXTURE_2D,
                                       stObj->pt->nr_samples, bindings, 0);
 }
@@ -528,20 +544,23 @@ st_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
       return;
    }
 
-   if (!st_validate_attachment(screen,
+   if (!st_validate_attachment(ctx,
+                               screen,
                                depth,
 			       PIPE_BIND_DEPTH_STENCIL)) {
       fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
       return;
    }
-   if (!st_validate_attachment(screen,
+   if (!st_validate_attachment(ctx,
+                               screen,
                                stencil,
 			       PIPE_BIND_DEPTH_STENCIL)) {
       fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
       return;
    }
    for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
-      if (!st_validate_attachment(screen,
+      if (!st_validate_attachment(ctx,
+                                  screen,
 				  &fb->Attachment[BUFFER_COLOR0 + i],
 				  PIPE_BIND_RENDER_TARGET)) {
 	 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;




More information about the mesa-commit mailing list