test version of startmenu root with big icons
[reactos.git] / reactos / lib / mesa32 / src / tnl / t_vb_cull.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28
29 #include "glheader.h"
30 #include "colormac.h"
31 #include "context.h"
32 #include "macros.h"
33 #include "imports.h"
34 #include "mtypes.h"
35
36 #include "math/m_xform.h"
37
38 #include "t_context.h"
39 #include "t_pipeline.h"
40
41
42
43 /* EXT_vertex_cull. Not really a big win, but probably depends on
44 * your application. This stage not included in the default pipeline.
45 */
46 static GLboolean run_cull_stage( GLcontext *ctx,
47 struct tnl_pipeline_stage *stage )
48 {
49 TNLcontext *tnl = TNL_CONTEXT(ctx);
50 struct vertex_buffer *VB = &tnl->vb;
51
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;
58 GLuint i;
59
60 VB->ClipOrMask &= ~CLIP_CULL_BIT;
61 VB->ClipAndMask |= CLIP_CULL_BIT;
62
63 for (i = 0 ; i < count ; i++) {
64 GLfloat dp = (norm[0] * a +
65 norm[1] * b +
66 norm[2] * c);
67
68 if (dp < 0) {
69 VB->ClipMask[i] |= CLIP_CULL_BIT;
70 VB->ClipOrMask |= CLIP_CULL_BIT;
71 }
72 else {
73 VB->ClipMask[i] &= ~CLIP_CULL_BIT;
74 VB->ClipAndMask &= ~CLIP_CULL_BIT;
75 }
76
77 STRIDE_F(norm, stride);
78 }
79
80 return !(VB->ClipAndMask & CLIP_CULL_BIT);
81 }
82
83
84 static void check_cull( GLcontext *ctx, struct tnl_pipeline_stage *stage )
85 {
86 stage->active = (!ctx->VertexProgram._Enabled &&
87 ctx->Transform.CullVertexFlag);
88 }
89
90
91 static void dtr( struct tnl_pipeline_stage *stage )
92 {
93 }
94
95
96 const struct tnl_pipeline_stage _tnl_vertex_cull_stage =
97 {
98 "EXT_cull_vertex",
99 _NEW_PROGRAM |
100 _NEW_TRANSFORM,
101 _NEW_TRANSFORM,
102 GL_TRUE, /* active */
103 _TNL_BIT_NORMAL |
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 */
111 };