2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
36 #include "math/m_xform.h"
38 #include "t_context.h"
39 #include "t_pipeline.h"
43 /* EXT_vertex_cull. Not really a big win, but probably depends on
44 * your application. This stage not included in the default pipeline.
46 static GLboolean
run_cull_stage( GLcontext
*ctx
,
47 struct tnl_pipeline_stage
*stage
)
49 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
50 struct vertex_buffer
*VB
= &tnl
->vb
;
52 const GLfloat a
= ctx
->Transform
.CullObjPos
[0];
53 const GLfloat b
= ctx
->Transform
.CullObjPos
[1];
54 const GLfloat c
= ctx
->Transform
.CullObjPos
[2];
55 GLfloat
*norm
= (GLfloat
*)VB
->NormalPtr
->data
;
56 GLuint stride
= VB
->NormalPtr
->stride
;
57 GLuint count
= VB
->Count
;
60 VB
->ClipOrMask
&= ~CLIP_CULL_BIT
;
61 VB
->ClipAndMask
|= CLIP_CULL_BIT
;
63 for (i
= 0 ; i
< count
; i
++) {
64 GLfloat dp
= (norm
[0] * a
+
69 VB
->ClipMask
[i
] |= CLIP_CULL_BIT
;
70 VB
->ClipOrMask
|= CLIP_CULL_BIT
;
73 VB
->ClipMask
[i
] &= ~CLIP_CULL_BIT
;
74 VB
->ClipAndMask
&= ~CLIP_CULL_BIT
;
77 STRIDE_F(norm
, stride
);
80 return !(VB
->ClipAndMask
& CLIP_CULL_BIT
);
84 static void check_cull( GLcontext
*ctx
, struct tnl_pipeline_stage
*stage
)
86 stage
->active
= (!ctx
->VertexProgram
._Enabled
&&
87 ctx
->Transform
.CullVertexFlag
);
91 static void dtr( struct tnl_pipeline_stage
*stage
)
96 const struct tnl_pipeline_stage _tnl_vertex_cull_stage
=
102 GL_TRUE
, /* active */
104 _TNL_BIT_POS
, /* inputs */
105 _TNL_BIT_POS
, /* outputs */
106 0, /* changed_inputs */
107 NULL
, /* private data */
108 dtr
, /* destructor */
109 check_cull
, /* check */
110 run_cull_stage
/* run -- initially set to init */