| 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 <[email protected]> |
| 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 |
if (ctx->VertexProgram._Enabled || |
| 61 |
!ctx->Transform.CullVertexFlag) |
| 62 |
return GL_TRUE; |
| 63 |
|
| 64 |
VB->ClipOrMask &= ~CLIP_CULL_BIT; |
| 65 |
VB->ClipAndMask |= CLIP_CULL_BIT; |
| 66 |
|
| 67 |
for (i = 0 ; i < count ; i++) { |
| 68 |
GLfloat dp = (norm[0] * a + |
| 69 |
norm[1] * b + |
| 70 |
norm[2] * c); |
| 71 |
|
| 72 |
if (dp < 0) { |
| 73 |
VB->ClipMask[i] |= CLIP_CULL_BIT; |
| 74 |
VB->ClipOrMask |= CLIP_CULL_BIT; |
| 75 |
} |
| 76 |
else { |
| 77 |
VB->ClipMask[i] &= ~CLIP_CULL_BIT; |
| 78 |
VB->ClipAndMask &= ~CLIP_CULL_BIT; |
| 79 |
} |
| 80 |
|
| 81 |
STRIDE_F(norm, stride); |
| 82 |
} |
| 83 |
|
| 84 |
return !(VB->ClipAndMask & CLIP_CULL_BIT); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
const struct tnl_pipeline_stage _tnl_vertex_cull_stage = |
| 90 |
{ |
| 91 |
"EXT_cull_vertex", |
| 92 |
NULL, /* private data */ |
| 93 |
NULL, /* ctr */ |
| 94 |
NULL, /* destructor */ |
| 95 |
NULL, |
| 96 |
run_cull_stage /* run -- initially set to init */ |
| 97 |
}; |