Initial work for GL_EXT_texture_sRGB.
authorBrian Paul <brian.paul@tungstengraphics.com>
Thu, 3 Aug 2006 03:20:52 +0000 (03:20 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Thu, 3 Aug 2006 03:20:52 +0000 (03:20 +0000)
src/mesa/main/config.h
src/mesa/main/extensions.c
src/mesa/main/extensions.h
src/mesa/main/mtypes.h
src/mesa/main/texformat.c
src/mesa/main/texformat.h
src/mesa/main/texformat_tmp.h
src/mesa/main/texstore.c
src/mesa/main/texstore.h

index 95555cb..6d4c413 100644 (file)
@@ -5,7 +5,7 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.1
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
 #define FEATURE_ATI_fragment_shader _HAVE_FULL_GL
 #define FEATURE_EXT_framebuffer_object _HAVE_FULL_GL
 #define FEATURE_EXT_framebuffer_blit _HAVE_FULL_GL
+#define FEATURE_EXT_texture_sRGB _HAVE_FULL_GL
 /*@}*/
 
 
index 3c85022..1517539 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.1
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
@@ -122,6 +122,7 @@ static const struct {
    { OFF, "GL_EXT_texture_mirror_clamp",       F(EXT_texture_mirror_clamp) },
    { ON,  "GL_EXT_texture_object",             F(EXT_texture_object) },
    { OFF, "GL_EXT_texture_rectangle",          F(NV_texture_rectangle) },
+   { OFF, "GL_EXT_texture_sRGB",               F(EXT_texture_sRGB) },
    { OFF, "GL_EXT_timer_query",                F(EXT_timer_query) },
    { ON,  "GL_EXT_vertex_array",               F(EXT_vertex_array) },
    { OFF, "GL_EXT_vertex_array_set",           F(EXT_vertex_array_set) },
@@ -253,6 +254,9 @@ _mesa_enable_sw_extensions(GLcontext *ctx)
    ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
    ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
    ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
+#if FEATURE_EXT_texture_sRGB
+   ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+#endif
    ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;
    ctx->Extensions.MESA_pack_invert = GL_TRUE;
 #if FEATURE_MESA_program_debug
@@ -387,6 +391,23 @@ _mesa_enable_2_0_extensions(GLcontext *ctx)
 }
 
 
+/**
+ * Enable all OpenGL 2.1 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_2_1_extensions(GLcontext *ctx)
+{
+#if FEATURE_EXT_pixel_buffer_object
+   ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
+#endif
+#if FEATURE_EXT_texture_sRGB
+   ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+#endif
+   /* plus: shading language extensions, non-square uniform matrices */
+}
+
+
 
 /**
  * Either enable or disable the named extension.
index 9d843a8..05ad859 100644 (file)
@@ -10,9 +10,9 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5.1
  *
- * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -52,6 +52,8 @@ extern void _mesa_enable_1_5_extensions(GLcontext *ctx);
 
 extern void _mesa_enable_2_0_extensions(GLcontext *ctx);
 
+extern void _mesa_enable_2_1_extensions(GLcontext *ctx);
+
 extern void _mesa_enable_extension(GLcontext *ctx, const char *name);
 
 extern void _mesa_disable_extension(GLcontext *ctx, const char *name);
index 5e872d9..5424afc 100644 (file)
@@ -2112,7 +2112,9 @@ struct gl_shared_state
    struct _mesa_HashTable *BufferObjects;
 #endif
 
+#if FEATURE_ARB_shader_objects
    struct _mesa_HashTable *GL2Objects;
+#endif
 
 #if FEATURE_EXT_framebuffer_object
    struct _mesa_HashTable *RenderBuffers;
@@ -2473,6 +2475,7 @@ struct gl_extensions
    GLboolean EXT_texture_filter_anisotropic;
    GLboolean EXT_texture_lod_bias;
    GLboolean EXT_texture_mirror_clamp;
+   GLboolean EXT_texture_sRGB;
    GLboolean EXT_timer_query;
    GLboolean EXT_vertex_array;
    GLboolean EXT_vertex_array_set;
index 792bfbc..acc268e 100644 (file)
 #include "texstore.h"
 
 
+#if FEATURE_EXT_texture_sRGB
+
+/**
+ * Convert an 8-bit sRGB value from non-linear space to a
+ * linear RGB value in [0, 1].
+ * Implemented with a 256-entry lookup table.
+ */
+static INLINE GLfloat
+nonlinear_to_linear(GLubyte cs8)
+{
+   static GLfloat table[256];
+   static GLboolean tableReady = GL_FALSE;
+   if (!tableReady) {
+      /* compute lookup table now */
+      GLuint i;
+      for (i = 0; i < 256; i++) {
+         const GLfloat cs = UBYTE_TO_FLOAT(i);
+         if (cs <= 0.04045) {
+            table[i] = cs / 12.92;
+         }
+         else {
+            table[i] = _mesa_pow((cs + 0.055) / 1.055, 2.4);
+         }
+      }
+      tableReady = GL_TRUE;
+   }
+   return table[cs8];
+}
+
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
 
 /* Texel fetch routines for all supported formats
  */
@@ -251,6 +283,106 @@ const struct gl_texture_format _mesa_texformat_intensity = {
 };
 
 
+#if FEATURE_EXT_texture_sRGB
+
+const struct gl_texture_format _mesa_texformat_srgb8 = {
+   MESA_FORMAT_SRGB8,                  /* MesaFormat */
+   GL_RGB,                             /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   8,                                  /* RedBits */
+   8,                                  /* GreenBits */
+   8,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   3,                                  /* TexelBytes */
+   _mesa_texstore_srgb8,               /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_srgb8,               /* FetchTexel1Df */
+   fetch_texel_2d_srgb8,               /* FetchTexel2Df */
+   fetch_texel_3d_srgb8,               /* FetchTexel3Df */
+   store_texel_srgb8                   /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_srgba8 = {
+   MESA_FORMAT_SRGBA8,                 /* MesaFormat */
+   GL_RGBA,                            /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   8,                                  /* RedBits */
+   8,                                  /* GreenBits */
+   8,                                  /* BlueBits */
+   8,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   4,                                  /* TexelBytes */
+   _mesa_texstore_srgba8,              /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_srgba8,              /* FetchTexel1Df */
+   fetch_texel_2d_srgba8,              /* FetchTexel2Df */
+   fetch_texel_3d_srgba8,              /* FetchTexel3Df */
+   store_texel_srgba8                  /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_sl8 = {
+   MESA_FORMAT_SL8,                    /* MesaFormat */
+   GL_LUMINANCE,                       /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   0,                                  /* RedBits */
+   0,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   8,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   1,                                  /* TexelBytes */
+   _mesa_texstore_sl8,                 /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_sl8,                 /* FetchTexel1Df */
+   fetch_texel_2d_sl8,                 /* FetchTexel2Df */
+   fetch_texel_3d_sl8,                 /* FetchTexel3Df */
+   store_texel_sl8                     /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_sla8 = {
+   MESA_FORMAT_SLA8,                   /* MesaFormat */
+   GL_LUMINANCE_ALPHA,                 /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   0,                                  /* RedBits */
+   0,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   8,                                  /* AlphaBits */
+   8,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   2,                                  /* TexelBytes */
+   _mesa_texstore_sla8,                        /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_sla8,                        /* FetchTexel1Df */
+   fetch_texel_2d_sla8,                        /* FetchTexel2Df */
+   fetch_texel_3d_sla8,                        /* FetchTexel3Df */
+   store_texel_sla8                    /* StoreTexel */
+};
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
 const struct gl_texture_format _mesa_texformat_rgba_float32 = {
    MESA_FORMAT_RGBA_FLOAT32,           /* MesaFormat */
    GL_RGBA,                            /* BaseFormat */
@@ -1398,6 +1530,42 @@ _mesa_choose_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:
+            return &_mesa_texformat_srgb8;
+         case GL_SRGB_ALPHA_EXT:
+         case GL_SRGB8_ALPHA8_EXT:
+            return &_mesa_texformat_srgba8;
+         case GL_SLUMINANCE_EXT:
+         case GL_SLUMINANCE8_EXT:
+            return &_mesa_texformat_sl8;
+         case GL_SLUMINANCE_ALPHA_EXT:
+         case GL_SLUMINANCE8_ALPHA8_EXT:
+            return &_mesa_texformat_sla8;
+         /* NOTE: not supporting any compression of sRGB at this time */
+         case GL_COMPRESSED_SRGB_EXT:
+            return &_mesa_texformat_srgb8;
+         case GL_COMPRESSED_SRGB_ALPHA_EXT:
+            return &_mesa_texformat_srgba8;
+         case GL_COMPRESSED_SLUMINANCE_EXT:
+            return &_mesa_texformat_sl8;
+         case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
+            return &_mesa_texformat_sla8;
+         case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+            return &_mesa_texformat_srgb8;
+         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 &_mesa_texformat_srgba8;
+         default:
+            ; /* fallthrough */
+      }
+   }
+#endif /* FEATURE_EXT_texture_sRGB */
+
    _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
    return NULL;
 }
index b7e5fc2..2aae5c1 100644 (file)
@@ -88,6 +88,18 @@ enum _format {
    MESA_FORMAT_Z32,             /*ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    /*@}*/
 
+#if FEATURE_EXT_texture_sRGB
+   /**
+    * \name 8-bit/channel sRGB formats
+    */
+   /*@{*/
+   MESA_FORMAT_SRGB8,
+   MESA_FORMAT_SRGBA8,
+   MESA_FORMAT_SL8,
+   MESA_FORMAT_SLA8,
+   /*@}*/
+#endif
+
    /**
     * \name Compressed texture formats.
     */
@@ -149,6 +161,16 @@ extern const struct gl_texture_format _mesa_texformat_luminance_alpha;
 extern const struct gl_texture_format _mesa_texformat_intensity;
 /*@}*/
 
+#if FEATURE_EXT_texture_sRGB
+/** sRGB (nonlinear) formats */
+/*@{*/
+extern const struct gl_texture_format _mesa_texformat_srgb8;
+extern const struct gl_texture_format _mesa_texformat_srgba8;
+extern const struct gl_texture_format _mesa_texformat_s8;
+extern const struct gl_texture_format _mesa_texformat_sla8;
+/*@}*/
+#endif
+
 /** Floating point texture formats */
 /*@{*/
 extern const struct gl_texture_format _mesa_texformat_rgba_float32;
index 186fe23..0d35191 100644 (file)
@@ -1174,6 +1174,103 @@ static void store_texel_ci8(struct gl_texture_image *texImage,
 #endif
 
 
+#if FEATURE_EXT_texture_sRGB
+
+/* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
+static void FETCH(srgb8)(const struct gl_texture_image *texImage,
+                         GLint i, GLint j, GLint k, GLfloat *texel )
+{
+   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+   texel[RCOMP] = nonlinear_to_linear(src[0]);
+   texel[GCOMP] = nonlinear_to_linear(src[1]);
+   texel[BCOMP] = nonlinear_to_linear(src[2]);
+   texel[ACOMP] = CHAN_MAX;
+}
+
+#if DIM == 3
+static void store_texel_srgb8(struct gl_texture_image *texImage,
+                              GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLubyte *rgba = (const GLubyte *) texel;
+   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+   dst[0] = rgba[RCOMP]; /* no conversion */
+   dst[1] = rgba[GCOMP];
+   dst[2] = rgba[BCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
+static void FETCH(srgba8)(const struct gl_texture_image *texImage,
+                          GLint i, GLint j, GLint k, GLfloat *texel )
+{
+   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
+   texel[RCOMP] = nonlinear_to_linear(src[0]);
+   texel[GCOMP] = nonlinear_to_linear(src[1]);
+   texel[BCOMP] = nonlinear_to_linear(src[2]);
+   texel[ACOMP] = UBYTE_TO_FLOAT(src[3]); /* linear! */
+}
+
+#if DIM == 3
+static void store_texel_srgba8(struct gl_texture_image *texImage,
+                               GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLubyte *rgba = (const GLubyte *) texel;
+   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
+   dst[0] = rgba[RCOMP];
+   dst[1] = rgba[GCOMP];
+   dst[2] = rgba[BCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
+static void FETCH(sl8)(const struct gl_texture_image *texImage,
+                       GLint i, GLint j, GLint k, GLfloat *texel )
+{
+   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+   texel[RCOMP] = 
+   texel[GCOMP] = 
+   texel[BCOMP] = nonlinear_to_linear(src[0]);
+   texel[ACOMP] = CHAN_MAX;
+}
+
+#if DIM == 3
+static void store_texel_sl8(struct gl_texture_image *texImage,
+                            GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLubyte *rgba = (const GLubyte *) texel;
+   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+   dst[0] = rgba[RCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
+static void FETCH(sla8)(const struct gl_texture_image *texImage,
+                       GLint i, GLint j, GLint k, GLfloat *texel )
+{
+   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
+   texel[RCOMP] =
+   texel[GCOMP] =
+   texel[BCOMP] = nonlinear_to_linear(src[0]);
+   texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
+}
+
+#if DIM == 3
+static void store_texel_sla8(struct gl_texture_image *texImage,
+                            GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLubyte *rgba = (const GLubyte *) texel;
+   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
+   dst[0] = rgba[RCOMP];
+   dst[1] = rgba[ACOMP];
+}
+#endif
+
+
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
+
+
 /* MESA_FORMAT_YCBCR *********************************************************/
 
 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
index 3280051..9eb9856 100644 (file)
@@ -2164,6 +2164,41 @@ _mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
 }
 
 
+#if FEATURE_EXT_texture_sRGB
+GLboolean
+_mesa_texstore_srgb8(TEXSTORE_PARAMS)
+{
+   /* XXX to do */
+   _mesa_problem(ctx, "_mesa_texstore_srgb8 not finished");
+   return GL_FALSE;
+}
+
+GLboolean
+_mesa_texstore_srgba8(TEXSTORE_PARAMS)
+{
+   /* XXX to do */
+   _mesa_problem(ctx, "_mesa_texstore_srgb8 not finished");
+   return GL_FALSE;
+}
+
+GLboolean
+_mesa_texstore_sl8(TEXSTORE_PARAMS)
+{
+   /* XXX to do */
+   _mesa_problem(ctx, "_mesa_texstore_srgb8 not finished");
+   return GL_FALSE;
+}
+
+GLboolean
+_mesa_texstore_sla8(TEXSTORE_PARAMS)
+{
+   /* XXX to do */
+   _mesa_problem(ctx, "_mesa_texstore_srgb8 not finished");
+   return GL_FALSE;
+}
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
 
 /**
  * Check if an unpack PBO is active prior to fetching a texture image.
index 3f5b7b0..7dc82a5 100644 (file)
@@ -67,6 +67,12 @@ extern GLboolean _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS);
+#if FEATURE_EXT_texture_sRGB
+extern GLboolean _mesa_texstore_srgb8(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_srgba8(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_sl8(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_sla8(TEXSTORE_PARAMS);
+#endif
 
 
 extern GLchan *