Added support for EXT_texture_mirror_clamp and the single wrap mode
authorIan Romanick <idr@us.ibm.com>
Tue, 2 Sep 2003 19:25:17 +0000 (19:25 +0000)
committerIan Romanick <idr@us.ibm.com>
Tue, 2 Sep 2003 19:25:17 +0000 (19:25 +0000)
that it addes to ATI_texture_mirror_once.  This includes updating the
texwrap test to exercise the new mode.

include/GL/gl.h
progs/tests/texwrap.c
src/mesa/main/extensions.c
src/mesa/main/mtypes.h
src/mesa/main/texstate.c
src/mesa/swrast/s_texture.c

index 0f59c87..469f464 100644 (file)
@@ -2211,6 +2211,18 @@ typedef void (APIENTRY * PFNGLDEPTHBOUNDSEXTPROC)(GLclampd zmin, GLclampd zmax);
 
 
 /* XXX temporary until glext.h is updated! */
+#ifndef GL_EXT_texture_mirror_clamp
+#define GL_EXT_texture_mirror_clamp 1
+
+#define GL_MIRROR_CLAMP_EXT                            0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_EXT                    0x8743
+#define GL_MIRROR_CLAMP_TO_BORDER_EXT                  0x8912
+
+#endif /* GL_EXT_texture_mirror_clamp */
+
+
+
+/* XXX temporary until glext.h is updated! */
 #ifndef GL_ARB_occlusion_query
 #define GL_ARB_occlusion_query 1
 
index 2602f32..35f5050 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: texwrap.c,v 1.6 2003/05/30 15:30:17 brianp Exp $ */
+/* $Id: texwrap.c,v 1.7 2003/09/02 19:25:18 idr Exp $ */
 
 /*
  * Test texture wrap modes.
 #define GL_MIRRORED_REPEAT 0x8370
 #endif
 
-#ifndef GL_ATI_texture_mirror_once
-#define GL_MIRROR_CLAMP_ATI               0x8742
-#define GL_MIRROR_CLAMP_TO_EDGE_ATI       0x8743
+#ifndef GL_EXT_texture_mirror_clamp
+#define GL_MIRROR_CLAMP_EXT               0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_EXT       0x8743
+#define GL_MIRROR_CLAMP_TO_BORDER_EXT     0x8912
 #endif
 
 #define BORDER_TEXTURE 1
@@ -61,11 +62,14 @@ static struct wrap_mode modes[] = {
    WRAP_EXT ( GL_MIRRORED_REPEAT, "GL_ARB_texture_mirrored_repeat",
                                  "GL_IBM_texture_mirrored_repeat",
              1.4 ),
-   WRAP_EXT ( GL_MIRROR_CLAMP_ATI, "GL_ATI_texture_mirror_once",
-                                  NULL,
+   WRAP_EXT ( GL_MIRROR_CLAMP_EXT, "GL_ATI_texture_mirror_once",
+                                  "GL_EXT_texture_mirror_clamp",
              999.0 ),
-   WRAP_EXT ( GL_MIRROR_CLAMP_TO_EDGE_ATI, "GL_ATI_texture_mirror_once",
-                                          NULL,
+   WRAP_EXT ( GL_MIRROR_CLAMP_TO_EDGE_EXT, "GL_ATI_texture_mirror_once",
+                                          "GL_EXT_texture_mirror_clamp",
+             999.0 ),
+   WRAP_EXT ( GL_MIRROR_CLAMP_TO_BORDER_EXT, "GL_EXT_texture_mirror_clamp",
+                                            NULL,
              999.0 ),
    { 0 }
 };
index 886311e..9928a52 100644 (file)
@@ -100,8 +100,9 @@ static const struct {
    { OFF, "GL_EXT_texture_env_combine",        F(EXT_texture_env_combine) },
    { OFF, "GL_EXT_texture_env_dot3",           F(EXT_texture_env_dot3) },
    { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
-   { ON,  "GL_EXT_texture_object",             0 },
    { OFF, "GL_EXT_texture_lod_bias",           F(EXT_texture_lod_bias) },
+   { OFF, "GL_EXT_texture_mirror_clamp",       F(EXT_texture_mirror_clamp) },
+   { ON,  "GL_EXT_texture_object",             0 },
    { OFF, "GL_EXT_texture_rectangle",          F(NV_texture_rectangle) },
    { ON,  "GL_EXT_vertex_array",               0 },
    { OFF, "GL_EXT_vertex_array_set",           F(EXT_vertex_array_set) },
@@ -196,6 +197,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx)
    ctx->Extensions.EXT_texture_env_add = GL_TRUE;
    ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
    ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
+   ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
    ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
    ctx->Extensions.HP_occlusion_test = GL_TRUE;
    ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;
index 47cb19b..a51a463 100644 (file)
@@ -1770,6 +1770,7 @@ struct gl_extensions
    GLboolean EXT_texture_env_dot3;
    GLboolean EXT_texture_filter_anisotropic;
    GLboolean EXT_texture_lod_bias;
+   GLboolean EXT_texture_mirror_clamp;
    GLboolean EXT_vertex_array_set;
    GLboolean HP_occlusion_test;
    GLboolean IBM_rasterpos_clip;
index a62106a..133b957 100644 (file)
@@ -1048,6 +1048,35 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
 /*                       Texture Parameters                           */
 /**********************************************************************/
 
+static GLboolean 
+_mesa_validate_texture_wrap_mode(GLcontext * ctx,
+                                GLenum target, GLenum eparam)
+{
+   const struct gl_extensions * const e = & ctx->Extensions;
+
+   if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
+       (eparam == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
+      /* any texture target */
+      return GL_TRUE;
+   }
+   else if (target != GL_TEXTURE_RECTANGLE_NV &&
+           (eparam == GL_REPEAT ||
+            (eparam == GL_MIRRORED_REPEAT &&
+             e->ARB_texture_mirrored_repeat) ||
+            (eparam == GL_MIRROR_CLAMP_EXT &&
+             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+            (eparam == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
+             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+            (eparam == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
+             (e->EXT_texture_mirror_clamp)))) {
+      /* non-rectangle texture */
+      return GL_TRUE;
+   }
+
+   _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
+   return GL_FALSE;
+}
+
 
 void
 _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
@@ -1141,81 +1170,34 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
       case GL_TEXTURE_WRAP_S:
          if (texObj->WrapS == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapS = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapS = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
             return;
          }
          break;
       case GL_TEXTURE_WRAP_T:
          if (texObj->WrapT == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapT = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapT = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
             return;
          }
          break;
       case GL_TEXTURE_WRAP_R:
          if (texObj->WrapR == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapR = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapR = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
+           return;
          }
          break;
       case GL_TEXTURE_BORDER_COLOR:
index 6f38aab..a196f34 100644 (file)
@@ -122,7 +122,7 @@ repeat_remainder(GLint a, GLint b)
       if (I1 >= (GLint) SIZE)                                          \
          I1 = SIZE - 1;                                                        \
    }                                                                   \
-   else if (wrapMode == GL_MIRROR_CLAMP_ATI) {                         \
+   else if (wrapMode == GL_MIRROR_CLAMP_EXT) {                         \
       U = (GLfloat) fabs(S);                                           \
       if (U >= 1.0F)                                                   \
          U = (GLfloat) SIZE;                                           \
@@ -132,7 +132,7 @@ repeat_remainder(GLint a, GLint b)
       I0 = IFLOOR(U);                                                  \
       I1 = I0 + 1;                                                     \
    }                                                                   \
-   else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_ATI) {                 \
+   else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_EXT) {                 \
       U = (GLfloat) fabs(S);                                           \
       if (U >= 1.0F)                                                   \
          U = (GLfloat) SIZE;                                           \
@@ -146,6 +146,20 @@ repeat_remainder(GLint a, GLint b)
       if (I1 >= (GLint) SIZE)                                          \
          I1 = SIZE - 1;                                                        \
    }                                                                   \
+   else if (wrapMode == GL_MIRROR_CLAMP_TO_BORDER_EXT) {               \
+      const GLfloat min = -1.0F / (2.0F * SIZE);                       \
+      const GLfloat max = 1.0F - min;                                  \
+      U = (GLfloat) fabs(S);                                           \
+      if (U <= min)                                                    \
+         U = min * SIZE;                                               \
+      else if (U >= max)                                               \
+         U = max * SIZE;                                               \
+      else                                                             \
+         U *= SIZE;                                                    \
+      U -= 0.5F;                                                       \
+      I0 = IFLOOR(U);                                                  \
+      I1 = I0 + 1;                                                     \
+   }                                                                   \
    else {                                                              \
       ASSERT(wrapMode == GL_CLAMP);                                    \
       if (S <= 0.0F)                                                   \
@@ -215,7 +229,7 @@ repeat_remainder(GLint a, GLint b)
       else                                                             \
          I = IFLOOR(u * SIZE);                                         \
    }                                                                   \
-   else if (wrapMode == GL_MIRROR_CLAMP_ATI) {                         \
+   else if (wrapMode == GL_MIRROR_CLAMP_EXT) {                         \
       /* s limited to [0,1] */                                         \
       /* i limited to [0,size-1] */                                    \
       const GLfloat u = (GLfloat) fabs(S);                             \
@@ -226,7 +240,7 @@ repeat_remainder(GLint a, GLint b)
       else                                                             \
          I = IFLOOR(u * SIZE);                                         \
    }                                                                   \
-   else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_ATI) {                 \
+   else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_EXT) {                 \
       /* s limited to [min,max] */                                     \
       /* i limited to [0, size-1] */                                   \
       const GLfloat min = 1.0F / (2.0F * SIZE);                                \
@@ -239,6 +253,19 @@ repeat_remainder(GLint a, GLint b)
       else                                                             \
          I = IFLOOR(u * SIZE);                                         \
    }                                                                   \
+   else if (wrapMode == GL_MIRROR_CLAMP_TO_BORDER_EXT) {               \
+      /* s limited to [min,max] */                                     \
+      /* i limited to [0, size-1] */                                   \
+      const GLfloat min = -1.0F / (2.0F * SIZE);                       \
+      const GLfloat max = 1.0F - min;                                  \
+      const GLfloat u = (GLfloat) fabs(S);                             \
+      if (u < min)                                                     \
+         I = -1;                                                       \
+      else if (u > max)                                                        \
+         I = SIZE;                                                     \
+      else                                                             \
+         I = IFLOOR(u * SIZE);                                         \
+   }                                                                   \
    else {                                                              \
       ASSERT(wrapMode == GL_CLAMP);                                    \
       /* s limited to [0,1] */                                         \