2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 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>
29 #include "main/glheader.h"
30 #include "main/colormac.h"
31 #include "main/context.h"
32 #include "main/macros.h"
33 #include "main/imports.h"
34 #include "main/mtypes.h"
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
->AttribPtr
[_TNL_ATTRIB_NORMAL
]->data
;
56 GLuint stride
= VB
->AttribPtr
[_TNL_ATTRIB_NORMAL
]->stride
;
57 GLuint count
= VB
->Count
;
60 if (ctx
->VertexProgram
._Current
||
61 !ctx
->Transform
.CullVertexFlag
)
64 VB
->ClipOrMask
&= ~CLIP_CULL_BIT
;
65 VB
->ClipAndMask
|= CLIP_CULL_BIT
;
67 for (i
= 0 ; i
< count
; i
++) {
68 GLfloat dp
= (norm
[0] * a
+
73 VB
->ClipMask
[i
] |= CLIP_CULL_BIT
;
74 VB
->ClipOrMask
|= CLIP_CULL_BIT
;
77 VB
->ClipMask
[i
] &= ~CLIP_CULL_BIT
;
78 VB
->ClipAndMask
&= ~CLIP_CULL_BIT
;
81 STRIDE_F(norm
, stride
);
84 return !(VB
->ClipAndMask
& CLIP_CULL_BIT
);
89 const struct tnl_pipeline_stage _tnl_vertex_cull_stage
=
92 NULL
, /* private data */
94 NULL
, /* destructor */
96 run_cull_stage
/* run -- initially set to init */