mesa: Add support for ARB_depth_clamp.
authorEric Anholt <eric@anholt.net>
Wed, 26 Aug 2009 16:51:15 +0000 (09:51 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 8 Sep 2009 21:30:15 +0000 (14:30 -0700)
This currently doesn't include fixing up the cliptests in the assembly
paths to support ARB_depth_clamp, so enabling depth_clamp forces the C path.

22 files changed:
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/drivers/x11/xm_api.c
src/mesa/glapi/ARB_depth_clamp.xml [new file with mode: 0644]
src/mesa/glapi/Makefile
src/mesa/glapi/gl_API.xml
src/mesa/main/attrib.c
src/mesa/main/enable.c
src/mesa/main/extensions.c
src/mesa/main/get_gen.py
src/mesa/main/mtypes.h
src/mesa/math/m_clip_tmp.h
src/mesa/math/m_debug_clip.c
src/mesa/math/m_xform.h
src/mesa/sparc/clip.S
src/mesa/sparc/sparc.c
src/mesa/swrast/s_depth.c
src/mesa/swrast/s_depth.h
src/mesa/swrast/s_span.c
src/mesa/tnl/t_rasterpos.c
src/mesa/tnl/t_vb_program.c
src/mesa/tnl/t_vb_vertex.c
src/mesa/x86/x86_xform.c

index a858af30c1153ae1e1132526fdd980c560130b18..9a130d61cf4299ea4e8c705b14bebe043e1326ae 100644 (file)
@@ -95,6 +95,7 @@ const struct dri_extension card_extensions[] =
     { "GL_EXT_histogram",              GL_EXT_histogram_functions },
     { "GL_SGI_color_table",            GL_SGI_color_table_functions },
 
+    { "GL_ARB_depth_clamp",            NULL },
     { "GL_ARB_shader_objects",         GL_ARB_shader_objects_functions },
     { "GL_ARB_vertex_array_object",    GL_ARB_vertex_array_object_functions },
     { "GL_ARB_vertex_program",         GL_ARB_vertex_program_functions },
index 2c7be9f182dce7891a9d9675432cd78d5144e9ef..78545d0e17017a8921f0f251ee9925cc05c9043a 100644 (file)
@@ -1347,6 +1347,7 @@ const struct dri_extension card_extensions[] =
    { "GL_EXT_histogram",               GL_EXT_histogram_functions },
    { "GL_SGI_color_table",             GL_SGI_color_table_functions },
 
+   { "GL_ARB_depth_clamp",             NULL },
    { "GL_ARB_shader_objects",          GL_ARB_shader_objects_functions },
    { "GL_ARB_sync",                    GL_ARB_sync_functions },
    { "GL_ARB_vertex_program",          GL_ARB_vertex_program_functions },
diff --git a/src/mesa/glapi/ARB_depth_clamp.xml b/src/mesa/glapi/ARB_depth_clamp.xml
new file mode 100644 (file)
index 0000000..157c9a8
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
+
+<OpenGLAPI>
+
+<category name="GL_ARB_depth_clamp" number="61">
+    <enum name="DEPTH_CLAMP" count="1"  value="0x864F">
+        <size name="Get" mode="get"/>
+    </enum>
+</category>
+
+</OpenGLAPI>
index 65edab7cec9e7c78cf4a400b4635d364d0e92db5..22f65b74c29f1632754048f35de70f04ba481c9e 100644 (file)
@@ -48,6 +48,7 @@ SERVER_OUTPUTS = \
 API_XML = gl_API.xml \
        EXT_framebuffer_object.xml \
        ARB_copy_buffer.xml \
+       ARB_depth_clamp.xml \
        ARB_framebuffer_object.xml \
        ARB_map_buffer_range.xml \
        ARB_seamless_cube_map.xml \
index 1dfd92be080a94623618de9644434ba887cb9f22..920ce80c459c4501cd8faad36b2a0f4466d02cad 100644 (file)
 
 <xi:include href="ARB_copy_buffer.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
+<xi:include href="ARB_depth_clamp.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
 <xi:include href="ARB_map_buffer_range.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
 <xi:include href="ARB_vertex_array_object.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
index ab99ca1c6420cd261beaa2f464918220f1159323..0fb8fa3bba2ade4eeece924f4634abb064d488c2 100644 (file)
@@ -74,6 +74,7 @@ struct gl_enable_attrib
    GLboolean Convolution2D;
    GLboolean Separable2D;
    GLboolean CullFace;
+   GLboolean DepthClamp;
    GLboolean DepthTest;
    GLboolean Dither;
    GLboolean Fog;
@@ -265,6 +266,7 @@ _mesa_PushAttrib(GLbitfield mask)
       attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
       attr->Separable2D = ctx->Pixel.Separable2DEnabled;
       attr->CullFace = ctx->Polygon.CullFlag;
+      attr->DepthClamp = ctx->Transform.DepthClamp;
       attr->DepthTest = ctx->Depth.Test;
       attr->Dither = ctx->Color.DitherFlag;
       attr->Fog = ctx->Fog.Enabled;
@@ -514,6 +516,8 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
                    enable->ColorTable[COLORTABLE_POSTCOLORMATRIX],
                    GL_POST_COLOR_MATRIX_COLOR_TABLE);
    TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
+   TEST_AND_UPDATE(ctx->Transform.DepthClamp, enable->DepthClamp,
+                  GL_DEPTH_CLAMP);
    TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
    TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
    TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D,
@@ -1221,6 +1225,9 @@ _mesa_PopAttrib(void)
                if (xform->RescaleNormals != ctx->Transform.RescaleNormals)
                   _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT,
                                    ctx->Transform.RescaleNormals);
+               if (xform->DepthClamp != ctx->Transform.DepthClamp)
+                  _mesa_set_enable(ctx, GL_DEPTH_CLAMP,
+                                   ctx->Transform.DepthClamp);
             }
             break;
          case GL_TEXTURE_BIT:
index 4bc54771e970afd91ce038de84b0cdcaef947931..d066153fc2cf8d136a19ba938ebd40486e7a1458 100644 (file)
@@ -37,6 +37,7 @@
 #include "mtypes.h"
 #include "enums.h"
 #include "math/m_matrix.h"
+#include "math/m_xform.h"
 #include "api_arrayelt.h"
 
 
@@ -947,6 +948,20 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          ctx->Depth.BoundsTest = state;
          break;
 
+      case GL_DEPTH_CLAMP:
+         if (ctx->Transform.DepthClamp == state)
+            return;
+        /* Neither the x86 nor sparc asm cliptest functions have been updated
+         * for ARB_depth_clamp, so force the C paths.
+         */
+        if (state)
+           init_c_cliptest();
+
+        CHECK_EXTENSION(ARB_depth_clamp, cap);
+         FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+        ctx->Transform.DepthClamp = state;
+        break;
+
 #if FEATURE_ATI_fragment_shader
       case GL_FRAGMENT_SHADER_ATI:
         CHECK_EXTENSION(ATI_fragment_shader, cap);
@@ -1395,6 +1410,11 @@ _mesa_IsEnabled( GLenum cap )
          CHECK_EXTENSION(EXT_depth_bounds_test);
          return ctx->Depth.BoundsTest;
 
+      /* GL_ARB_depth_clamp */
+      case GL_DEPTH_CLAMP:
+         CHECK_EXTENSION(ARB_depth_clamp);
+         return ctx->Transform.DepthClamp;
+
 #if FEATURE_ATI_fragment_shader
       case GL_FRAGMENT_SHADER_ATI:
         CHECK_EXTENSION(ATI_fragment_shader);
index e3070b1547d070bd2e2c3daacd988374ca08f092..ea67f820af5264eed4d2b12dfa477f45356381ce 100644 (file)
@@ -47,6 +47,7 @@ static const struct {
 } default_extensions[] = {
    { OFF, "GL_ARB_copy_buffer",                F(ARB_copy_buffer) },
    { OFF, "GL_ARB_depth_texture",              F(ARB_depth_texture) },
+   { OFF, "GL_ARB_depth_clamp",                F(ARB_depth_clamp) },
    { ON,  "GL_ARB_draw_buffers",               F(ARB_draw_buffers) },
    { OFF, "GL_ARB_fragment_program",           F(ARB_fragment_program) },
    { OFF, "GL_ARB_fragment_program_shadow",    F(ARB_fragment_program_shadow) },
@@ -192,6 +193,7 @@ void
 _mesa_enable_sw_extensions(GLcontext *ctx)
 {
    ctx->Extensions.ARB_copy_buffer = GL_TRUE;
+   ctx->Extensions.ARB_depth_clamp = GL_TRUE;
    ctx->Extensions.ARB_depth_texture = GL_TRUE;
    /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
 #if FEATURE_ARB_fragment_program
index 2878c1b552637d5b4498fec4c32d55eaf910cbc6..364d8c55c45c291f8228dede5db6005038b2aeeb 100644 (file)
@@ -905,6 +905,10 @@ StateVars = [
          ["ctx->Depth.BoundsMin", "ctx->Depth.BoundsMax"],
          "", ["EXT_depth_bounds_test"] ),
 
+       # GL_ARB_depth_clamp
+       ( "GL_DEPTH_CLAMP", GLboolean, ["ctx->Transform.DepthClamp"], "",
+         ["ARB_depth_clamp"] ),
+
        # GL_ARB_draw_buffers
        ( "GL_MAX_DRAW_BUFFERS_ARB", GLint,
          ["ctx->Const.MaxDrawBuffers"], "", None ),
index 6b64bf8139f49315db5a845a67442190a1c22d85..20cd3aa5c0dc56ef8f2c6dc01ed39d304eb13fc2 100644 (file)
@@ -1482,6 +1482,7 @@ struct gl_transform_attrib
    GLboolean Normalize;                                /**< Normalize all normals? */
    GLboolean RescaleNormals;                   /**< GL_EXT_rescale_normal */
    GLboolean RasterPositionUnclipped;           /**< GL_IBM_rasterpos_clip */
+   GLboolean DepthClamp;                       /**< GL_ARB_depth_clamp */
 
    GLboolean CullVertexFlag;   /**< True if GL_CULL_VERTEX_EXT is enabled */
    GLfloat CullEyePos[4];
@@ -2475,6 +2476,7 @@ struct gl_extensions
    GLboolean dummy;  /* don't remove this! */
    GLboolean ARB_copy_buffer;
    GLboolean ARB_depth_texture;
+   GLboolean ARB_depth_clamp;
    GLboolean ARB_draw_buffers;
    GLboolean ARB_fragment_program;
    GLboolean ARB_fragment_program_shadow;
index f3a589be051ec5da726c83c5414b40e6e7cf15d2..2e30964057c91825839afbdfed5a757b6ac030db 100644 (file)
@@ -44,7 +44,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points4)( GLvector4f *clip_vec,
                                                      GLvector4f *proj_vec,
                                                      GLubyte clipMask[],
                                                      GLubyte *orMask,
-                                                     GLubyte *andMask )
+                                                     GLubyte *andMask,
+                                                    GLboolean viewport_z_clip )
 {
    const GLuint stride = clip_vec->stride;
    const GLfloat *from = (GLfloat *)clip_vec->start;
@@ -66,16 +67,20 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points4)( GLvector4f *clip_vec,
       mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
       mask |= (((cw < cy) << CLIP_TOP_SHIFT));
       mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
-      mask |= (((cw < cz) << CLIP_FAR_SHIFT));
-      mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
+      if (viewport_z_clip) {
+        mask |= (((cw < cz) << CLIP_FAR_SHIFT));
+        mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
+      }
 #else /* !defined(macintosh)) */
       GLubyte mask = 0;
       if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
       if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
       if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
       if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
-      if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
-      if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
+      if (viewport_z_clip) {
+        if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
+        if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
+      }
 #endif /* defined(macintosh) */
 
       clipMask[i] = mask;
@@ -119,7 +124,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec,
                                                        GLvector4f *proj_vec,
                                                        GLubyte clipMask[],
                                                        GLubyte *orMask,
-                                                       GLubyte *andMask )
+                                                       GLubyte *andMask,
+                                                       GLboolean viewport_z_clip )
 {
    const GLuint stride = clip_vec->stride;
    const GLuint count = clip_vec->count;
@@ -141,16 +147,20 @@ static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec,
       mask |= (((cw < -cx) << CLIP_LEFT_SHIFT));
       mask |= (((cw < cy) << CLIP_TOP_SHIFT));
       mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT));
-      mask |= (((cw < cz) << CLIP_FAR_SHIFT));
-      mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
+      if (viewport_z_clip) {
+        mask |= (((cw < cz) << CLIP_FAR_SHIFT));
+        mask |= (((cw < -cz) << CLIP_NEAR_SHIFT));
+      }
 #else /* !defined(macintosh)) */
       GLubyte mask = 0;
       if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT;
       if ( cx + cw < 0) mask |= CLIP_LEFT_BIT;
       if (-cy + cw < 0) mask |= CLIP_TOP_BIT;
       if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT;
-      if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
-      if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
+      if (viewport_z_clip) {
+        if (-cz + cw < 0) mask |= CLIP_FAR_BIT;
+        if ( cz + cw < 0) mask |= CLIP_NEAR_BIT;
+      }
 #endif /* defined(macintosh) */
 
       clipMask[i] = mask;
@@ -171,7 +181,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec,
                                                      GLvector4f *proj_vec,
                                                      GLubyte clipMask[],
                                                      GLubyte *orMask,
-                                                     GLubyte *andMask )
+                                                     GLubyte *andMask,
+                                                    GLboolean viewport_z_clip )
 {
    const GLuint stride = clip_vec->stride;
    const GLuint count = clip_vec->count;
@@ -187,8 +198,10 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec,
       else if (cx < -1.0)  mask |= CLIP_LEFT_BIT;
       if (cy >  1.0)       mask |= CLIP_TOP_BIT;
       else if (cy < -1.0)  mask |= CLIP_BOTTOM_BIT;
-      if (cz >  1.0)       mask |= CLIP_FAR_BIT;
-      else if (cz < -1.0)  mask |= CLIP_NEAR_BIT;
+      if (viewport_z_clip) {
+        if (cz >  1.0)       mask |= CLIP_FAR_BIT;
+        else if (cz < -1.0)  mask |= CLIP_NEAR_BIT;
+      }
       clipMask[i] = mask;
       tmpOrMask |= mask;
       tmpAndMask &= mask;
@@ -204,7 +217,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec,
                                                      GLvector4f *proj_vec,
                                                      GLubyte clipMask[],
                                                      GLubyte *orMask,
-                                                     GLubyte *andMask )
+                                                     GLubyte *andMask,
+                                                    GLboolean viewport_z_clip )
 {
    const GLuint stride = clip_vec->stride;
    const GLuint count = clip_vec->count;
@@ -231,7 +245,7 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec,
 }
 
 
-static void TAG(init_c_cliptest)( void )
+void TAG(init_c_cliptest)( void )
 {
    _mesa_clip_tab[4] = TAG(cliptest_points4);
    _mesa_clip_tab[3] = TAG(cliptest_points3);
index 460fed4a7547365d088f245cb7df7e30da13dbee..f2b757a91b8b683b857dda478909b324544dfc46 100644 (file)
@@ -67,7 +67,8 @@ static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec,
                                         GLvector4f *proj_vec,
                                         GLubyte clipMask[],
                                         GLubyte *orMask,
-                                        GLubyte *andMask )
+                                        GLubyte *andMask,
+                                        GLboolean viewport_z_clip )
 {
    const GLuint stride = clip_vec->stride;
    const GLuint count = clip_vec->count;
@@ -87,8 +88,10 @@ static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec,
       if (  cx + cw < 0 ) mask |= CLIP_LEFT_BIT;
       if ( -cy + cw < 0 ) mask |= CLIP_TOP_BIT;
       if (  cy + cw < 0 ) mask |= CLIP_BOTTOM_BIT;
-      if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT;
-      if (  cz + cw < 0 ) mask |= CLIP_NEAR_BIT;
+      if (viewport_z_clip) {
+        if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT;
+        if (  cz + cw < 0 ) mask |= CLIP_NEAR_BIT;
+      }
       clipMask[i] = mask;
       if ( mask ) {
         c++;
index 7ef76e0b926becf9077d347ba9789e62eada8b07..33421ad1c0af0c6c55e5b35f8bc8562e8bd8eab4 100644 (file)
@@ -43,7 +43,8 @@
 
 extern void
 _math_init_transformation(void);
-
+extern void
+init_c_cliptest(void);
 
 /* KW: Clip functions now do projective divide as well.  The projected
  * coordinates are very useful to us because they let us cull
@@ -102,7 +103,8 @@ typedef GLvector4f * (_XFORMAPIP clip_func)( GLvector4f *vClip,
                                             GLvector4f *vProj,
                                             GLubyte clipMask[],
                                             GLubyte *orMask,
-                                            GLubyte *andMask );
+                                            GLubyte *andMask,
+                                            GLboolean viewport_z_clip );
 
 typedef void (*dotprod_func)( GLfloat *out,
                              GLuint out_stride,
index 208843c606905ce3b8685c9062170e8e595256ce..dc239171ff96de3b26c42b998d8519cc143c0493 100644 (file)
@@ -58,7 +58,8 @@ clip_table:
        .byte   31, 29, 31, 30, 27, 25, 27, 26
 
 /* GLvector4f *clip_vec, GLvector4f *proj_vec, 
-   GLubyte clipMask[], GLubyte *orMask, GLubyte *andMask */
+   GLubyte clipMask[], GLubyte *orMask, GLubyte *andMask,
+   GLboolean viewport_z_enable */
 
        .align          64
 __pc_tramp:
index d2286a2c8372c9cc1203714a295004770dbce21f..cea0c7cecf1fd58a6afbcba2b46a61371afb5cf7 100644 (file)
@@ -78,13 +78,15 @@ extern GLvector4f  *_mesa_sparc_cliptest_points4(GLvector4f *clip_vec,
                                                 GLvector4f *proj_vec,
                                                 GLubyte clipMask[],
                                                 GLubyte *orMask,
-                                                GLubyte *andMask);
+                                                GLubyte *andMask,
+                                                GLboolean viewport_z_clip);
 
 extern GLvector4f  *_mesa_sparc_cliptest_points4_np(GLvector4f *clip_vec,
                                                    GLvector4f *proj_vec,
                                                    GLubyte clipMask[],
                                                    GLubyte *orMask,
-                                                   GLubyte *andMask);
+                                                   GLubyte *andMask,
+                                                   GLboolean viewport_z_clip);
 
 #define NORM_ARGS      const GLmatrix *mat,                            \
                        GLfloat scale,                                  \
index 26e23f02d597e62503aba443f5ce4e3f845d09b0..1a428fb1a286c3398d71757bce5627d392e674a1 100644 (file)
@@ -497,6 +497,33 @@ depth_test_span32( GLcontext *ctx, GLuint n,
    return passed;
 }
 
+/* Apply ARB_depth_clamp to span of fragments. */
+void
+_swrast_depth_clamp_span( GLcontext *ctx, SWspan *span )
+{
+   struct gl_framebuffer *fb = ctx->DrawBuffer;
+   struct gl_renderbuffer *rb = fb->_DepthBuffer;
+   const GLuint count = span->end;
+   GLuint *zValues = span->array->z;
+   GLuint near, far;
+   int i;
+
+   if (rb->DataType == GL_UNSIGNED_SHORT) {
+      near = FLOAT_TO_UINT(ctx->Viewport.Near);
+      far = FLOAT_TO_UINT(ctx->Viewport.Far);
+   } else {
+      assert(rb->DataType == GL_UNSIGNED_INT);
+      CLAMPED_FLOAT_TO_USHORT(near, ctx->Viewport.Near);
+      CLAMPED_FLOAT_TO_USHORT(far, ctx->Viewport.Far);
+   }
+   for (i = 0; i < count; i++) {
+      if (zValues[i] < near)
+        zValues[i] = near;
+      if (zValues[i] > far)
+        zValues[i] = far;
+   }
+}
+
 
 
 /*
index 368862568303a560326701058b13c71c5a875c9b..7eae36674283fdbeef26de0f6264e70ac37b6fbf 100644 (file)
@@ -33,6 +33,8 @@
 extern GLuint
 _swrast_depth_test_span( GLcontext *ctx, SWspan *span);
 
+extern void
+_swrast_depth_clamp_span( GLcontext *ctx, SWspan *span );
 
 extern GLboolean
 _swrast_depth_bounds_test( GLcontext *ctx, SWspan *span );
index 0e2793b47403fde0cc50484320a1d91d2e7afdb6..a45eac438e493e5b76ee02664efe99d80059b4a8 100644 (file)
@@ -880,6 +880,9 @@ _swrast_write_index_span( GLcontext *ctx, SWspan *span)
       stipple_polygon_span(ctx, span);
    }
 
+   if (ctx->Transform.DepthClamp)
+      _swrast_depth_clamp_span(ctx, span);
+
    /* Stencil and Z testing */
    if (ctx->Stencil._Enabled || ctx->Depth.Test) {
       if (!(span->arrayMask & SPAN_Z))
index f1fdddf0f5a4ff4103fff14b55735614a89dcb15..99b678745565ec1b622ca29d448f89b616605df9 100644 (file)
  * \return zero if outside view volume, or one if inside.
  */
 static GLuint
-viewclip_point( const GLfloat v[] )
+viewclip_point_xy( const GLfloat v[] )
 {
    if (   v[0] > v[3] || v[0] < -v[3]
-       || v[1] > v[3] || v[1] < -v[3]
-       || v[2] > v[3] || v[2] < -v[3] ) {
+       || v[1] > v[3] || v[1] < -v[3] ) {
       return 0;
    }
    else {
@@ -408,18 +407,18 @@ _tnl_RasterPos(GLcontext *ctx, const GLfloat vObj[4])
       /* apply projection matrix:  clip = Proj * eye */
       TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye );
 
-      /* clip to view volume */
-      if (ctx->Transform.RasterPositionUnclipped) {
-         /* GL_IBM_rasterpos_clip: only clip against Z */
+      /* clip to view volume. */
+      if (!ctx->Transform.DepthClamp) {
          if (viewclip_point_z(clip) == 0) {
             ctx->Current.RasterPosValid = GL_FALSE;
             return;
          }
       }
-      else if (viewclip_point(clip) == 0) {
-         /* Normal OpenGL behaviour */
-         ctx->Current.RasterPosValid = GL_FALSE;
-         return;
+      if (!ctx->Transform.RasterPositionUnclipped) {
+         if (viewclip_point_xy(clip) == 0) {
+            ctx->Current.RasterPosValid = GL_FALSE;
+            return;
+         }
       }
 
       /* clip to user clipping planes */
@@ -443,6 +442,12 @@ _tnl_RasterPos(GLcontext *ctx, const GLfloat vObj[4])
                                   / ctx->DrawBuffer->_DepthMaxF;
       ctx->Current.RasterPos[3] = clip[3];
 
+      if (ctx->Transform.DepthClamp) {
+        ctx->Current.RasterPos[3] = CLAMP(ctx->Current.RasterPos[3],
+                                          ctx->Viewport.Near,
+                                          ctx->Viewport.Far);
+      }
+
       /* compute raster distance */
       if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
          ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
index dc954bcba148046f89f553360d30c411d677701c..5d89f8bc313a6ed3901b83df769f7dd75bfae768 100644 (file)
@@ -137,7 +137,8 @@ do_ndc_cliptest(GLcontext *ctx, struct vp_stage_data *store)
                                             &store->ndcCoords,
                                             store->clipmask,
                                             &store->ormask,
-                                            &store->andmask );
+                                            &store->andmask,
+                                           !ctx->Transform.DepthClamp );
    }
    else {
       VB->NdcPtr = NULL;
@@ -145,7 +146,8 @@ do_ndc_cliptest(GLcontext *ctx, struct vp_stage_data *store)
                                             NULL,
                                             store->clipmask,
                                             &store->ormask,
-                                            &store->andmask );
+                                            &store->andmask,
+                                           !ctx->Transform.DepthClamp );
    }
 
    if (store->andmask) {
index 30aa7c4086835b880466844b06e312e373b5aa4a..6a746417c87904e0135535ea06b154172199ea99 100644 (file)
@@ -173,7 +173,8 @@ static GLboolean run_vertex_stage( GLcontext *ctx,
                                            &store->proj,
                                            store->clipmask,
                                            &store->ormask,
-                                           &store->andmask );
+                                           &store->andmask,
+                                           !ctx->Transform.DepthClamp );
    }
    else {
       VB->NdcPtr = NULL;
@@ -181,7 +182,8 @@ static GLboolean run_vertex_stage( GLcontext *ctx,
                                            NULL,
                                            store->clipmask,
                                            &store->ormask,
-                                           &store->andmask );
+                                           &store->andmask,
+                                           !ctx->Transform.DepthClamp );
    }
 
    if (store->andmask)
index 16b2b26bcc8587eed509aa179d966abc03564b43..52f6b25d817fd193ef0b21de41ef337ef6720901 100644 (file)
@@ -60,21 +60,24 @@ _mesa_x86_cliptest_points4( GLvector4f *clip_vec,
                            GLvector4f *proj_vec,
                            GLubyte clipMask[],
                            GLubyte *orMask,
-                           GLubyte *andMask );
+                           GLubyte *andMask,
+                           GLboolean viewport_z_clip );
 
 extern GLvector4f * _ASMAPI
 _mesa_x86_cliptest_points4_np( GLvector4f *clip_vec,
                               GLvector4f *proj_vec,
                               GLubyte clipMask[],
                               GLubyte *orMask,
-                              GLubyte *andMask );
+                              GLubyte *andMask,
+                              GLboolean viewport_z_clip );
 
 extern void _ASMAPI
 _mesa_v16_x86_cliptest_points4( GLfloat *first_vert,
                                GLfloat *last_vert,
                                GLubyte *or_mask,
                                GLubyte *and_mask,
-                               GLubyte *clip_mask );
+                               GLubyte *clip_mask,
+                               GLboolean viewport_z_clip );
 
 extern void _ASMAPI
 _mesa_v16_x86_general_xform( GLfloat *dest,