summaryrefslogtreecommitdiff
path: root/src/mesa/tnl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/tnl')
-rw-r--r--src/mesa/tnl/t_context.h1
-rw-r--r--src/mesa/tnl/t_pipeline.h1
-rw-r--r--src/mesa/tnl/t_vb_cull.c111
-rw-r--r--src/mesa/tnl/t_vb_render.c11
-rw-r--r--src/mesa/tnl/t_vb_vertex.c2
5 files changed, 122 insertions, 4 deletions
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index b9fc7b8ea0..3d099b205a 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -432,6 +432,7 @@ struct vertex_buffer
GLvector4f *ClipPtr; /* _TNL_BIT_POS */
GLvector4f *NdcPtr; /* _TNL_BIT_POS */
GLubyte ClipOrMask; /* _TNL_BIT_POS */
+ GLubyte ClipAndMask; /* _TNL_BIT_POS */
GLubyte *ClipMask; /* _TNL_BIT_POS */
GLvector4f *NormalPtr; /* _TNL_BIT_NORMAL */
GLfloat *NormalLengthPtr; /* _TNL_BIT_NORMAL */
diff --git a/src/mesa/tnl/t_pipeline.h b/src/mesa/tnl/t_pipeline.h
index 02128ea8fd..d356ee4532 100644
--- a/src/mesa/tnl/t_pipeline.h
+++ b/src/mesa/tnl/t_pipeline.h
@@ -47,6 +47,7 @@ extern void _tnl_install_pipeline( GLcontext *ctx,
/* These are implemented in the t_vb_*.c files:
*/
extern const struct tnl_pipeline_stage _tnl_vertex_transform_stage;
+extern const struct tnl_pipeline_stage _tnl_vertex_cull_stage;
extern const struct tnl_pipeline_stage _tnl_normal_transform_stage;
extern const struct tnl_pipeline_stage _tnl_lighting_stage;
extern const struct tnl_pipeline_stage _tnl_fog_coordinate_stage;
diff --git a/src/mesa/tnl/t_vb_cull.c b/src/mesa/tnl/t_vb_cull.c
new file mode 100644
index 0000000000..9527ead943
--- /dev/null
+++ b/src/mesa/tnl/t_vb_cull.c
@@ -0,0 +1,111 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.1
+ *
+ * Copyright (C) 1999-2004 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "glheader.h"
+#include "colormac.h"
+#include "context.h"
+#include "macros.h"
+#include "imports.h"
+#include "mtypes.h"
+
+#include "math/m_xform.h"
+
+#include "t_context.h"
+#include "t_pipeline.h"
+
+
+
+/* EXT_vertex_cull. Not really a big win, but probably depends on
+ * your application. This stage not included in the default pipeline.
+ */
+static GLboolean run_cull_stage( GLcontext *ctx,
+ struct tnl_pipeline_stage *stage )
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &tnl->vb;
+
+ const GLfloat a = ctx->Transform.CullObjPos[0];
+ const GLfloat b = ctx->Transform.CullObjPos[1];
+ const GLfloat c = ctx->Transform.CullObjPos[2];
+ GLfloat *norm = (GLfloat *)VB->NormalPtr->data;
+ GLuint stride = VB->NormalPtr->stride;
+ GLuint count = VB->Count;
+ GLuint i;
+
+ VB->ClipOrMask &= ~CLIP_CULL_BIT;
+ VB->ClipAndMask |= CLIP_CULL_BIT;
+
+ for (i = 0 ; i < count ; i++) {
+ GLfloat dp = (norm[0] * a +
+ norm[1] * b +
+ norm[2] * c);
+
+ if (dp < 0) {
+ VB->ClipMask[i] |= CLIP_CULL_BIT;
+ VB->ClipOrMask |= CLIP_CULL_BIT;
+ }
+ else {
+ VB->ClipMask[i] &= ~CLIP_CULL_BIT;
+ VB->ClipAndMask &= ~CLIP_CULL_BIT;
+ }
+
+ STRIDE_F(norm, stride);
+ }
+
+ return !(VB->ClipAndMask & CLIP_CULL_BIT);
+}
+
+
+static void check_cull( GLcontext *ctx, struct tnl_pipeline_stage *stage )
+{
+ stage->active = (!ctx->VertexProgram._Enabled &&
+ ctx->Transform.CullVertexFlag);
+}
+
+
+static void dtr( struct tnl_pipeline_stage *stage )
+{
+}
+
+
+const struct tnl_pipeline_stage _tnl_vertex_cull_stage =
+{
+ "EXT_cull_vertex",
+ _NEW_PROGRAM |
+ _NEW_TRANSFORM,
+ _NEW_TRANSFORM,
+ GL_TRUE, /* active */
+ _TNL_BIT_NORMAL |
+ _TNL_BIT_POS, /* inputs */
+ _TNL_BIT_POS, /* outputs */
+ 0, /* changed_inputs */
+ NULL, /* private data */
+ dtr, /* destructor */
+ check_cull, /* check */
+ run_cull_stage /* run -- initially set to init */
+};
diff --git a/src/mesa/tnl/t_vb_render.c b/src/mesa/tnl/t_vb_render.c
index 1c50168968..f8e41f5d9b 100644
--- a/src/mesa/tnl/t_vb_render.c
+++ b/src/mesa/tnl/t_vb_render.c
@@ -77,6 +77,9 @@
#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
+#define CLIPMASK (CLIP_ALL_BITS|CLIP_CULL_BIT)
+
+
/* Vertices, with the possibility of clipping.
*/
#define RENDER_POINTS( start, count ) \
@@ -88,7 +91,7 @@ do { \
GLubyte ormask = c1|c2; \
if (!ormask) \
LineFunc( ctx, v1, v2 ); \
- else if (!(c1 & c2 & 0x3f)) \
+ else if (!(c1 & c2 & CLIPMASK)) \
clip_line_4( ctx, v1, v2, ormask ); \
} while (0)
@@ -98,7 +101,7 @@ do { \
GLubyte ormask = c1|c2|c3; \
if (!ormask) \
TriangleFunc( ctx, v1, v2, v3 ); \
- else if (!(c1 & c2 & c3 & 0x3f)) \
+ else if (!(c1 & c2 & c3 & CLIPMASK)) \
clip_tri_4( ctx, v1, v2, v3, ormask ); \
} while (0)
@@ -109,7 +112,7 @@ do { \
GLubyte ormask = c1|c2|c3|c4; \
if (!ormask) \
QuadFunc( ctx, v1, v2, v3, v4 ); \
- else if (!(c1 & c2 & c3 & c4 & 0x3f)) \
+ else if (!(c1 & c2 & c3 & c4 & CLIPMASK)) \
clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \
} while (0)
@@ -170,7 +173,7 @@ static void clip_elt_triangles( GLcontext *ctx,
if (ormask) {
if (start < j)
render_tris( ctx, start, j, 0 );
- if (!(c1&c2&c3&0x3f))
+ if (!(c1&c2&c3&CLIPMASK))
clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask );
start = j+3;
}
diff --git a/src/mesa/tnl/t_vb_vertex.c b/src/mesa/tnl/t_vb_vertex.c
index b483a9522d..3d64281882 100644
--- a/src/mesa/tnl/t_vb_vertex.c
+++ b/src/mesa/tnl/t_vb_vertex.c
@@ -208,6 +208,7 @@ static GLboolean run_vertex_stage( GLcontext *ctx,
return GL_FALSE;
}
+ VB->ClipAndMask = store->andmask;
VB->ClipOrMask = store->ormask;
VB->ClipMask = store->clipmask;
@@ -222,6 +223,7 @@ static GLboolean run_vertex_stage( GLcontext *ctx,
VB->ClipPtr = store->save_clipptr;
VB->NdcPtr = store->save_ndcptr;
VB->ClipMask = store->clipmask;
+ VB->ClipAndMask = store->andmask;
VB->ClipOrMask = store->ormask;
if (store->andmask)
return GL_FALSE;