st/mesa: add support for clip vertex.
authorDave Airlie <airlied@redhat.com>
Wed, 4 Jan 2012 11:49:26 +0000 (11:49 +0000)
committerDave Airlie <airlied@redhat.com>
Sat, 7 Jan 2012 08:36:25 +0000 (08:36 +0000)
We need to pass the pre-projection matrix clip planes into the driver,
instead of the post for the case we have a vertex shader that writes clip
vertex.

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/mesa/state_tracker/st_atom_clip.c
src/mesa/state_tracker/st_program.c

index 1330db843a666b8e59046aab7faf765a503ba240..236d3cf409d814c8ce3b4404ad531322adaf0e75 100644 (file)
@@ -34,7 +34,7 @@
 #include "st_context.h"
 #include "pipe/p_context.h"
 #include "st_atom.h"
-
+#include "st_program.h"
 #include "cso_cache/cso_context.h"
 
 
@@ -45,15 +45,23 @@ static void update_clip( struct st_context *st )
    struct pipe_clip_state clip;
    const struct gl_context *ctx = st->ctx;
    GLuint i;
+   bool use_eye = FALSE;
 
    memset(&clip, 0, sizeof(clip));
 
+   /* if we have a vertex shader that writes clip vertex we need to pass
+      the pre-projection transformed coordinates into the driver. */
+   if (st->vp) {
+      if (ctx->Shader.CurrentVertexProgram)
+         use_eye = TRUE;
+   }
+
    for (i = 0; i < PIPE_MAX_CLIP_PLANES; i++) {
       if (ctx->Transform.ClipPlanesEnabled & (1 << i)) {
-        memcpy(clip.ucp[clip.nr], 
-               ctx->Transform._ClipUserPlane[i], 
-               sizeof(clip.ucp[0]));
-        clip.nr++;
+         memcpy(clip.ucp[clip.nr],
+                use_eye ? ctx->Transform.EyeUserPlane[i] : ctx->Transform._ClipUserPlane[i],
+                sizeof(clip.ucp[0]));
+         clip.nr++;
       }
    }
 
@@ -69,7 +77,7 @@ static void update_clip( struct st_context *st )
 const struct st_tracked_state st_update_clip = {
    "st_update_clip",                                   /* name */
    {                                                   /* dirty */
-      (_NEW_TRANSFORM),                                        /* mesa */
+      (_NEW_TRANSFORM | _NEW_PROGRAM),                 /* mesa */
       0,                                               /* st */
    },
    update_clip                                         /* update */
index 35d0e0fc42f5aa434f96b833c1f4c0d87e8cb2c2..8d7469dfb72ee29c0e8af43149f6cbdba903f638 100644 (file)
@@ -255,6 +255,10 @@ st_prepare_vertex_program(struct gl_context *ctx,
          case VERT_RESULT_EDGE:
             assert(0);
             break;
+         case VERT_RESULT_CLIP_VERTEX:
+            stvp->output_semantic_name[slot] = TGSI_SEMANTIC_CLIPVERTEX;
+            stvp->output_semantic_index[slot] = 0;
+            break;
 
          case VERT_RESULT_TEX0:
          case VERT_RESULT_TEX1: