more work for GL_EXT_texture_sRGB.
authorBrian Paul <brian.paul@tungstengraphics.com>
Fri, 4 Aug 2006 03:44:53 +0000 (03:44 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Fri, 4 Aug 2006 03:44:53 +0000 (03:44 +0000)
src/mesa/main/texcompress.c
src/mesa/main/teximage.c
src/mesa/main/texstore.c

index 2516339e1127e1c6aee580a4ad975c1f534191ff..d594308024530331eb21b6a8859fb0fed28acef7 100644 (file)
@@ -95,6 +95,19 @@ _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all)
             n += 4;
          }
       }
+#if FEATURE_EXT_texture_sRGB
+      if (ctx->Extensions.EXT_texture_sRGB) {
+         if (formats) {
+            formats[n++] = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
+            formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
+            formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
+            formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
+         }
+         else {
+            n += 4;
+         }
+      }
+#endif /* FEATURE_EXT_texture_sRGB */
    }
    return n;
 }
index 2ada4a8942098cc72eec1b30471dc53745defc7e..14024fec04781ba10dea62b5c157a1d1554574b8 100644 (file)
@@ -348,6 +348,36 @@ _mesa_base_tex_format( GLcontext *ctx, GLint internalFormat )
       }
    }
 
+#if FEATURE_EXT_texture_sRGB
+   if (ctx->Extensions.EXT_texture_sRGB) {
+      switch (internalFormat) {
+      case GL_SRGB_EXT:
+      case GL_SRGB8_EXT:
+      case GL_COMPRESSED_SRGB_EXT:
+      case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+         return GL_RGB;
+      case GL_SRGB_ALPHA_EXT:
+      case GL_SRGB8_ALPHA8_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+         return GL_RGBA;
+      case GL_SLUMINANCE_ALPHA_EXT:
+      case GL_SLUMINANCE8_ALPHA8_EXT:
+      case GL_COMPRESSED_SLUMINANCE_EXT:
+      case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
+         return GL_LUMINANCE_ALPHA;
+      case GL_SLUMINANCE_EXT:
+      case GL_SLUMINANCE8_EXT:
+         return GL_LUMINANCE;
+      default:
+            ; /* fallthrough */
+      }
+   }
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
    return -1; /* error */
 }
 
@@ -440,6 +470,24 @@ is_color_format(GLenum format)
       case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
       case GL_COMPRESSED_RGB_FXT1_3DFX:
       case GL_COMPRESSED_RGBA_FXT1_3DFX:
+#if FEATURE_EXT_texture_sRGB
+      case GL_SRGB_EXT:
+      case GL_SRGB8_EXT:
+      case GL_SRGB_ALPHA_EXT:
+      case GL_SRGB8_ALPHA8_EXT:
+      case GL_SLUMINANCE_ALPHA_EXT:
+      case GL_SLUMINANCE8_ALPHA8_EXT:
+      case GL_SLUMINANCE_EXT:
+      case GL_SLUMINANCE8_EXT:
+      case GL_COMPRESSED_SRGB_EXT:
+      case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
+      case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+      case GL_COMPRESSED_SLUMINANCE_EXT:
+      case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
+#endif /* FEATURE_EXT_texture_sRGB */
          return GL_TRUE;
       case GL_YCBCR_MESA:  /* not considered to be RGB */
       default:
@@ -1646,6 +1694,20 @@ subtexture_error_check( GLcontext *ctx, GLuint dimensions,
       return GL_TRUE;
    }
 
+#if FEATURE_EXT_texture_sRGB
+   if (destTex->InternalFormat == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT ||
+       destTex->InternalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT ||
+       destTex->InternalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT ||
+       destTex->InternalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT) {
+      if ((width & 0x3) || (height & 0x3) ||
+          (xoffset & 0x3) || (yoffset & 0x3))
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glTexSubImage%dD(size or offset not multiple of 4)",
+                     dimensions);
+      return GL_TRUE;
+   }
+#endif
+
    if (destTex->IsCompressed) {
       const struct gl_texture_unit *texUnit;
       const struct gl_texture_image *texImage;
@@ -2951,6 +3013,16 @@ compressed_texture_error_check(GLcontext *ctx, GLint dimensions,
    if (expectedSize != imageSize)
       return GL_INVALID_VALUE;
 
+#if FEATURE_EXT_texture_sRGB
+   if ((internalFormat == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT ||
+        internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT ||
+        internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT ||
+        internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT)
+       && border != 0) {
+      return GL_INVALID_OPERATION;
+   }
+#endif
+
    return GL_NO_ERROR;
 }
 
index 9eb9856b0ce80311e65b714ecc0333167957344b..654047cda80170cb10d40caf92bb6c1dde46ce08 100644 (file)
@@ -4124,6 +4124,27 @@ _mesa_upscale_teximage2d (GLsizei inWidth, GLsizei inHeight,
 }
 
 
+#if FEATURE_EXT_texture_sRGB
+
+/**
+ * Test if given texture image is an sRGB format.
+ */
+static GLboolean
+is_srgb_teximage(const struct gl_texture_image *texImage)
+{
+   switch (texImage->TexFormat->MesaFormat) {
+   case MESA_FORMAT_SRGB8:
+   case MESA_FORMAT_SRGBA8:
+   case MESA_FORMAT_SL8:
+   case MESA_FORMAT_SLA8:
+      return GL_TRUE;
+   default:
+      return GL_FALSE;
+   }
+}
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
 
 /**
  * This is the software fallback for Driver.GetTexImage().
@@ -4238,6 +4259,16 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
                   _mesa_swap2((GLushort *) dest, width);
                }
             }
+#if FEATURE_EXT_texture_sRGB
+            else if (is_srgb_teximage(texImage)) {
+               /* no pixel transfer and no non-linear to linear conversion */
+               const GLint comps = texImage->TexFormat->TexelBytes;
+               const GLint rowstride = comps * texImage->RowStride;
+               MEMCPY(dest,
+                      (const GLubyte *) texImage->Data + row * rowstride,
+                      comps * width * sizeof(GLubyte));
+            }
+#endif /* FEATURE_EXT_texture_sRGB */
             else {
                /* general case:  convert row to RGBA format */
                GLfloat rgba[MAX_WIDTH][4];