So far this is only compile-tested.  There's still a bit of work to be
done, but this should be about half of it.

Signed-off-by: Ian Romanick <[email protected]>
---
 src/mesa/main/extensions.c    |    1 +
 src/mesa/main/mtypes.h        |    1 +
 src/mesa/main/texformat.c     |  223 ++++++++++++++++++++++++++++++++++++++++-
 src/mesa/main/texformat.h     |   16 +++
 src/mesa/main/texformat_tmp.h |  184 +++++++++++++++++++++++++++++++++
 src/mesa/main/texstore.c      |  122 ++++++++++++++++++++++-
 src/mesa/main/texstore.h      |    4 +
 7 files changed, 548 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 5c4bea9..0b93087 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -74,6 +74,7 @@ static const struct {
    { OFF, "GL_ARB_texture_mirrored_repeat",    F(ARB_texture_mirrored_repeat)},
    { OFF, "GL_ARB_texture_non_power_of_two",   
F(ARB_texture_non_power_of_two)},
    { OFF, "GL_ARB_texture_rectangle",          F(NV_texture_rectangle) },
+   { OFF, "GL_ARB_texture_rg",                 F(ARB_texture_rg) },
    { ON,  "GL_ARB_transpose_matrix",           F(ARB_transpose_matrix) },
    { ON,  "GL_ARB_vertex_buffer_object",       F(ARB_vertex_buffer_object) },
    { OFF, "GL_ARB_vertex_program",             F(ARB_vertex_program) },
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d11df53..62e0d9b 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2446,6 +2446,7 @@ struct gl_extensions
    GLboolean ARB_texture_float;
    GLboolean ARB_texture_mirrored_repeat;
    GLboolean ARB_texture_non_power_of_two;
+   GLboolean ARB_texture_rg;
    GLboolean ARB_transpose_matrix;
    GLboolean ARB_vertex_buffer_object;
    GLboolean ARB_vertex_program;
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index c709004..0cf4ae8 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -187,6 +187,54 @@ const struct gl_texture_format _mesa_texformat_rgb = {
    store_texel_rgb                     /* StoreTexel */
 };
 
+const struct gl_texture_format _mesa_texformat_rg = {
+   MESA_FORMAT_RG,                     /* MesaFormat */
+   GL_RG,                              /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   CHAN_BITS,                          /* RedBits */
+   CHAN_BITS,                          /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   2 * sizeof(GLchan),                 /* TexelBytes */
+   _mesa_texstore_rgba,/*yes*/         /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_rg,                        /* FetchTexel1Df */
+   fetch_texel_2d_f_rg,                        /* FetchTexel2Df */
+   fetch_texel_3d_f_rg,                        /* FetchTexel3Df */
+   store_texel_rg                      /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_r = {
+   MESA_FORMAT_R,                      /* MesaFormat */
+   GL_RED,                             /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   CHAN_BITS,                          /* RedBits */
+   0,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   1 * sizeof(GLchan),                 /* TexelBytes */
+   _mesa_texstore_rgba,/*yes*/         /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_r,                 /* FetchTexel1Df */
+   fetch_texel_2d_f_r,                 /* FetchTexel2Df */
+   fetch_texel_3d_f_r,                 /* FetchTexel3Df */
+   store_texel_r                       /* StoreTexel */
+};
+
 const struct gl_texture_format _mesa_texformat_alpha = {
    MESA_FORMAT_ALPHA,                  /* MesaFormat */
    GL_ALPHA,                           /* BaseFormat */
@@ -1426,6 +1474,150 @@ const struct gl_texture_format _mesa_texformat_z32 = {
    store_texel_z32                     /* StoreTexel */
 };
 
+const struct gl_texture_format _mesa_texformat_rg88 = {
+   MESA_FORMAT_RG88,                   /* MesaFormat */
+   GL_RG,                              /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   8,                                  /* RedBits */
+   8,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   2,                                  /* TexelBytes */
+   _mesa_texstore_rg88,                        /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_rg88,              /* FetchTexel1Df */
+   fetch_texel_2d_f_rg88,              /* FetchTexel2Df */
+   fetch_texel_3d_f_rg88,              /* FetchTexel3Df */
+   store_texel_rg88                    /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_rg88_rev = {
+   MESA_FORMAT_RG88_REV,               /* MesaFormat */
+   GL_RG,                              /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   8,                                  /* RedBits */
+   8,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   2,                                  /* TexelBytes */
+   _mesa_texstore_rg88,                        /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_rg88_rev,          /* FetchTexel1Df */
+   fetch_texel_2d_f_rg88_rev,          /* FetchTexel2Df */
+   fetch_texel_3d_f_rg88_rev,          /* FetchTexel3Df */
+   store_texel_rg88_rev                        /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_rg1616 = {
+   MESA_FORMAT_RG1616,                 /* MesaFormat */
+   GL_RG,                              /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   16,                                 /* RedBits */
+   16,                                 /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   4,                                  /* TexelBytes */
+   _mesa_texstore_rg1616,              /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_rg1616,            /* FetchTexel1Df */
+   fetch_texel_2d_f_rg1616,            /* FetchTexel2Df */
+   fetch_texel_3d_f_rg1616,            /* FetchTexel3Df */
+   store_texel_rg1616                  /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_rg1616_rev = {
+   MESA_FORMAT_RG1616_REV,             /* MesaFormat */
+   GL_RG,                              /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   16,                                 /* RedBits */
+   16,                                 /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   4,                                  /* TexelBytes */
+   _mesa_texstore_rg1616,              /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_rg1616_rev,                /* FetchTexel1Df */
+   fetch_texel_2d_f_rg1616_rev,                /* FetchTexel2Df */
+   fetch_texel_3d_f_rg1616_rev,                /* FetchTexel3Df */
+   store_texel_rg1616_rev              /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_r8 = {
+   MESA_FORMAT_R8,                     /* MesaFormat */
+   GL_RED,                             /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   8,                                  /* RedBits */
+   0,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   1,                                  /* TexelBytes */
+   _mesa_texstore_r8,                  /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_r8,                        /* FetchTexel1Df */
+   fetch_texel_2d_f_r8,                        /* FetchTexel2Df */
+   fetch_texel_3d_f_r8,                        /* FetchTexel3Df */
+   store_texel_r8                      /* StoreTexel */
+};
+
+const struct gl_texture_format _mesa_texformat_r16 = {
+   MESA_FORMAT_R16,                    /* MesaFormat */
+   GL_RED,                             /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   16,                                 /* RedBits */
+   0,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   0,                                  /* DepthBits */
+   0,                                  /* StencilBits */
+   2,                                  /* TexelBytes */
+   _mesa_texstore_r16,                 /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_r16,               /* FetchTexel1Df */
+   fetch_texel_2d_f_r16,               /* FetchTexel2Df */
+   fetch_texel_3d_f_r16,               /* FetchTexel3Df */
+   store_texel_r16                     /* StoreTexel */
+};
+
 /*...@}*/
 
 
@@ -1784,8 +1976,28 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint 
internalFormat,
    }
 #endif /* FEATURE_EXT_texture_sRGB */
 
-   _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
-   return NULL;
+   if (ctx->Extensions.ARB_texture_rg) {
+      switch (internalFormat) {
+      case GL_RG:
+        return &_mesa_texformat_rg;
+      case GL_RG8:
+        return &_mesa_texformat_rg88;
+      case GL_RG16:
+        return &_mesa_texformat_rg1616;
+
+      case GL_RED:
+        return &_mesa_texformat_r;
+      case GL_R8:
+        return &_mesa_texformat_r8;
+      case GL_R16:
+        return &_mesa_texformat_r16;
+
+      default:
+            ; /* fallthrough */
+      }
+      _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
+      return NULL;
+   }
 }
 
 
@@ -1831,6 +2043,8 @@ _mesa_format_to_type_and_comps(const struct 
gl_texture_format *format,
 
    case MESA_FORMAT_AL88:
    case MESA_FORMAT_AL88_REV:
+   case MESA_FORMAT_RG88:
+   case MESA_FORMAT_RG88_REV:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 2;
       return;
@@ -1843,12 +2057,14 @@ _mesa_format_to_type_and_comps(const struct 
gl_texture_format *format,
    case MESA_FORMAT_L8:
    case MESA_FORMAT_I8:
    case MESA_FORMAT_CI8:
+   case MESA_FORMAT_R8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 1;
       return;
 
    case MESA_FORMAT_YCBCR:
    case MESA_FORMAT_YCBCR_REV:
+   case MESA_FORMAT_RG1616:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 2;
       return;
@@ -1864,6 +2080,7 @@ _mesa_format_to_type_and_comps(const struct 
gl_texture_format *format,
       return;
 
    case MESA_FORMAT_Z16:
+   case MESA_FORMAT_R16:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 1;
       return;
@@ -1934,12 +2151,14 @@ _mesa_format_to_type_and_comps(const struct 
gl_texture_format *format,
       *comps = 3;
       return;
    case MESA_FORMAT_LUMINANCE_ALPHA:
+   case MESA_FORMAT_RG:
       *datatype = CHAN_TYPE;
       *comps = 2;
       return;
    case MESA_FORMAT_ALPHA:
    case MESA_FORMAT_LUMINANCE:
    case MESA_FORMAT_INTENSITY:
+   case MESA_FORMAT_R:
       *datatype = CHAN_TYPE;
       *comps = 1;
       return;
diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h
index 5aa1d75..840dc0d 100644
--- a/src/mesa/main/texformat.h
+++ b/src/mesa/main/texformat.h
@@ -77,6 +77,12 @@ enum _format {
    MESA_FORMAT_RGBA5551,        /*                     RRRR RGGG GGBB BBBA */
    MESA_FORMAT_ARGB1555,       /*                     ARRR RRGG GGGB BBBB */
    MESA_FORMAT_ARGB1555_REV,   /*                     GGGB BBBB ARRR RRGG */
+   MESA_FORMAT_RG88,           /*                     RRRR RRRR GGGG GGGG */
+   MESA_FORMAT_RG88_REV,       /*                     GGGG GGGG RRRR RRRR */
+   MESA_FORMAT_RG1616,         /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
+   MESA_FORMAT_RG1616_REV,     /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
+   MESA_FORMAT_R8,             /*                               RRRR RRRR */
+   MESA_FORMAT_R16,            /*                     RRRR RRRR RRRR RRRR */
    MESA_FORMAT_AL88,           /*                     AAAA AAAA LLLL LLLL */
    MESA_FORMAT_AL88_REV,       /*                     LLLL LLLL AAAA AAAA */
    MESA_FORMAT_RGB332,         /*                               RRRG GGBB */
@@ -140,6 +146,8 @@ enum _format {
    /*...@{*/
    MESA_FORMAT_RGBA,
    MESA_FORMAT_RGB,
+   MESA_FORMAT_RG,
+   MESA_FORMAT_R,
    MESA_FORMAT_ALPHA,
    MESA_FORMAT_LUMINANCE,
    MESA_FORMAT_LUMINANCE_ALPHA,
@@ -179,6 +187,8 @@ enum _format {
 /*...@{*/
 extern const struct gl_texture_format _mesa_texformat_rgba;
 extern const struct gl_texture_format _mesa_texformat_rgb;
+extern const struct gl_texture_format _mesa_texformat_rg;
+extern const struct gl_texture_format _mesa_texformat_r;
 extern const struct gl_texture_format _mesa_texformat_alpha;
 extern const struct gl_texture_format _mesa_texformat_luminance;
 extern const struct gl_texture_format _mesa_texformat_luminance_alpha;
@@ -241,6 +251,12 @@ extern const struct gl_texture_format 
_mesa_texformat_argb4444_rev;
 extern const struct gl_texture_format _mesa_texformat_argb1555;
 extern const struct gl_texture_format _mesa_texformat_argb1555_rev;
 extern const struct gl_texture_format _mesa_texformat_rgba5551;
+extern const struct gl_texture_format _mesa_texformat_rg88;
+extern const struct gl_texture_format _mesa_texformat_rg88_rev;
+extern const struct gl_texture_format _mesa_texformat_r8;
+extern const struct gl_texture_format _mesa_texformat_rg1616;
+extern const struct gl_texture_format _mesa_texformat_rg1616_rev;
+extern const struct gl_texture_format _mesa_texformat_r16;
 extern const struct gl_texture_format _mesa_texformat_al88;
 extern const struct gl_texture_format _mesa_texformat_al88_rev;
 extern const struct gl_texture_format _mesa_texformat_rgb332;
diff --git a/src/mesa/main/texformat_tmp.h b/src/mesa/main/texformat_tmp.h
index f3b2fb9..7c1c279 100644
--- a/src/mesa/main/texformat_tmp.h
+++ b/src/mesa/main/texformat_tmp.h
@@ -122,6 +122,53 @@ static void store_texel_rgb(struct gl_texture_image 
*texImage,
 }
 #endif
 
+/* MESA_FORMAT_RG ***********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RG texture, returning 4 GLfloats */
+static void FETCH(f_rg)(const struct gl_texture_image *texImage,
+                       GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
+   texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
+   texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
+   texel[BCOMP] = 0.0F;
+   texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rg(struct gl_texture_image *texImage,
+                          GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLchan *rgba = (const GLchan *) texel;
+   GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
+   dst[0] = rgba[RCOMP];
+   dst[1] = rgba[GCOMP];
+}
+#endif
+
+/* MESA_FORMAT_R ***********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RED texture, returning 4 GLfloats */
+static void FETCH(f_r)(const struct gl_texture_image *texImage,
+                      GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
+   texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
+   texel[GCOMP] = 0.0F;
+   texel[BCOMP] = 0.0F;
+   texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_r(struct gl_texture_image *texImage,
+                         GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLchan *rgba = (const GLchan *) texel;
+   GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
+   dst[0] = rgba[RCOMP];
+}
+#endif
+
 /* MESA_FORMAT_ALPHA *********************************************************/
 
 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
@@ -934,6 +981,143 @@ static void store_texel_argb1555_rev(struct 
gl_texture_image *texImage,
 #endif
 
 
+/* MESA_FORMAT_RG88 **********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
+static void FETCH(f_rg88)(const struct gl_texture_image *texImage,
+                         GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+   texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+   texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+   texel[BCOMP] = 0.0F;
+   texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rg88(struct gl_texture_image *texImage,
+                            GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLubyte *rgba = (const GLubyte *) texel;
+   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+   *dst = PACK_COLOR_88(rgba[GCOMP], rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RG88_REV ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
+static void FETCH(f_rg88_rev)(const struct gl_texture_image *texImage,
+                             GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+   texel[RCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+   texel[GCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+   texel[BCOMP] = 0.0F;
+   texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rg88_rev(struct gl_texture_image *texImage,
+                                GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLubyte *rgba = (const GLubyte *) texel;
+   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+   *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_R8 ************************************************************/
+
+/* Fetch texel from 1D, 2D or 3D r8 texture, return 4 GLchans */
+static void FETCH(f_r8)(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] = UBYTE_TO_FLOAT( src[0] );
+   texel[GCOMP] = 0.0F;
+   texel[BCOMP] = 0.0F;
+   texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_r8(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 = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RG1616 ********************************************************/
+
+/* Fetch depth texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
+static void FETCH(f_rg1616)(const struct gl_texture_image *texImage,
+                           GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   texel[0] = (s >> 16) * (1.0F / 65535.0F);
+   texel[1] = (s & 0xffff) * (1.0F / 65535.0F);
+}
+
+#if DIM == 3
+static void store_texel_rg1616(struct gl_texture_image *texImage,
+                              GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLushort *rgba = (const GLushort *) texel;
+   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   *dst = (((GLuint) rgba[RCOMP]) << 16) | (GLuint) rgba[GCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RG1616_REV ****************************************************/
+
+/* Fetch depth texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
+static void FETCH(f_rg1616_rev)(const struct gl_texture_image *texImage,
+                               GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   texel[0] = (s & 0xffff) * (1.0F / 65535.0F);
+   texel[1] = (s >> 16) * (1.0F / 65535.0F);
+}
+
+#if DIM == 3
+static void store_texel_rg1616_rev(struct gl_texture_image *texImage,
+                                  GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLushort *rgba = (const GLushort *) texel;
+   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   *dst = (((GLuint) rgba[GCOMP]) << 16) | (GLuint) rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_R16 ***********************************************************/
+
+/* Fetch depth texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
+static void FETCH(f_r16)(const struct gl_texture_image *texImage,
+                         GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+   texel[0] = src[0] * (1.0F / 65535.0F);
+}
+
+#if DIM == 3
+static void store_texel_r16(struct gl_texture_image *texImage,
+                            GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLushort *rgba = (const GLushort *) texel;
+   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+   dst[0] = rgba[RCOMP];
+}
+#endif
+
+
 /* MESA_FORMAT_AL88 **********************************************************/
 
 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index f3739f9..cc35ea7 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -2146,6 +2146,125 @@ _mesa_texstore_argb1555(TEXSTORE_PARAMS)
 }
 
 
+/**
+ * Store a texture in MESA_FORMAT_RG88 or MESA_FORMAT_RG88_REV.
+ */
+GLboolean
+_mesa_texstore_rg88(TEXSTORE_PARAMS)
+{
+   const GLboolean littleEndian = _mesa_little_endian();
+
+   ASSERT(dstFormat == &_mesa_texformat_rg88 ||
+          dstFormat == &_mesa_texformat_rg88_rev);
+   ASSERT(dstFormat->TexelBytes == 2);
+
+   if (!ctx->_ImageTransferState &&
+       !srcPacking->SwapBytes &&
+       dstFormat == &_mesa_texformat_rg88 &&
+       baseInternalFormat == GL_RG &&
+      ((srcFormat == GL_RG && srcType == GL_UNSIGNED_BYTE && !littleEndian))) {
+       /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                     dstRowStride,
+                     dstImageOffsets,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else if (!ctx->_ImageTransferState &&
+       !srcPacking->SwapBytes &&
+       dstFormat == &_mesa_texformat_rg88_rev &&
+       baseInternalFormat == GL_RG &&
+      ((srcFormat == GL_RG && srcType == GL_UNSIGNED_BYTE && littleEndian))) {
+      /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                     dstRowStride,
+                     dstImageOffsets,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else if (!ctx->_ImageTransferState &&
+           (srcType == GL_UNSIGNED_BYTE) &&
+           can_swizzle(baseInternalFormat) &&
+           can_swizzle(srcFormat)) {
+
+      GLubyte dstmap[4];
+
+      /* dstmap - how to swizzle from RG to dst format:
+       */
+      if ((littleEndian && dstFormat == &_mesa_texformat_rg88) ||
+         (!littleEndian && dstFormat == &_mesa_texformat_rg88_rev)) {
+        dstmap[1] = 0;
+        dstmap[0] = 1;
+      }
+      else {
+        dstmap[1] = 1;
+        dstmap[0] = 0;
+      }
+      dstmap[2] = ZERO;                /* ? */
+      dstmap[3] = ONE;         /* ? */
+
+      _mesa_swizzle_ubyte_image(ctx, dims,
+                               srcFormat,
+                               srcType,
+                               baseInternalFormat,
+                               dstmap, 2,
+                               dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                               dstRowStride, dstImageOffsets,
+                               srcWidth, srcHeight, srcDepth, srcAddr,
+                               srcPacking);
+   }
+   else {
+      /* general path */
+      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 dstFormat->BaseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLchan *src = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * dstFormat->TexelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLuint *dstUI = (GLuint *) dstRow;
+            if (dstFormat == &_mesa_texformat_rg88) {
+               for (col = 0; col < srcWidth; col++) {
+                  dstUI[col] = PACK_COLOR_88(CHAN_TO_UBYTE(src[RCOMP]),
+                                            CHAN_TO_UBYTE(src[GCOMP]));
+                  src += 2;
+               }
+            }
+            else {
+               for (col = 0; col < srcWidth; col++) {
+                  dstUI[col] = PACK_COLOR_88_REV(CHAN_TO_UBYTE(src[RCOMP]),
+                                                 CHAN_TO_UBYTE(src[GCOMP]));
+                  src += 2;
+               }
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      _mesa_free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
+GLboolean
+_mesa_texstore_rg1616(TEXSTORE_PARAMS)
+{
+   return GL_FALSE;
+}
+
+
 GLboolean
 _mesa_texstore_al88(TEXSTORE_PARAMS)
 {
@@ -2307,7 +2426,8 @@ _mesa_texstore_a8(TEXSTORE_PARAMS)
 {
    ASSERT(dstFormat == &_mesa_texformat_a8 ||
           dstFormat == &_mesa_texformat_l8 ||
-          dstFormat == &_mesa_texformat_i8);
+          dstFormat == &_mesa_texformat_i8 ||
+          dstFormat == &_mesa_texformat_r8);
    ASSERT(dstFormat->TexelBytes == 1);
 
    if (!ctx->_ImageTransferState &&
diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h
index 313f2d6..50d6aea 100644
--- a/src/mesa/main/texstore.h
+++ b/src/mesa/main/texstore.h
@@ -53,6 +53,10 @@ extern GLboolean 
_mesa_texstore_argb4444_rev(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_rgba5551(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_argb1555(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_argb1555_rev(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_r8(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_rg88(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_r16(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_rg1616(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_al88(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_al88_rev(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_rgb332(TEXSTORE_PARAMS);
-- 
1.6.0.6


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to