Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
55 | pj | 1 | /* $Id: clip.c,v 1.1 2003-02-28 11:41:58 pj Exp $ */ |
2 | |||
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 3.5 |
||
6 | * |
||
7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
||
8 | * |
||
9 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
10 | * copy of this software and associated documentation files (the "Software"), |
||
11 | * to deal in the Software without restriction, including without limitation |
||
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
13 | * and/or sell copies of the Software, and to permit persons to whom the |
||
14 | * Software is furnished to do so, subject to the following conditions: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||
23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | */ |
||
26 | |||
27 | |||
28 | #include "glheader.h" |
||
29 | #include "clip.h" |
||
30 | #include "context.h" |
||
31 | #include "macros.h" |
||
32 | #include "mmath.h" |
||
33 | #include "mtypes.h" |
||
34 | |||
35 | #include "math/m_xform.h" |
||
36 | #include "math/m_matrix.h" |
||
37 | |||
38 | |||
39 | |||
40 | /**********************************************************************/ |
||
41 | /* Get/Set User clip-planes. */ |
||
42 | /**********************************************************************/ |
||
43 | |||
44 | |||
45 | |||
46 | void |
||
47 | _mesa_ClipPlane( GLenum plane, const GLdouble *eq ) |
||
48 | { |
||
49 | GET_CURRENT_CONTEXT(ctx); |
||
50 | GLint p; |
||
51 | GLfloat equation[4]; |
||
52 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
||
53 | |||
54 | p = (GLint) plane - (GLint) GL_CLIP_PLANE0; |
||
55 | if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) { |
||
56 | _mesa_error( ctx, GL_INVALID_ENUM, "glClipPlane" ); |
||
57 | return; |
||
58 | } |
||
59 | |||
60 | equation[0] = (GLfloat) eq[0]; |
||
61 | equation[1] = (GLfloat) eq[1]; |
||
62 | equation[2] = (GLfloat) eq[2]; |
||
63 | equation[3] = (GLfloat) eq[3]; |
||
64 | |||
65 | /* |
||
66 | * The equation is transformed by the transpose of the inverse of the |
||
67 | * current modelview matrix and stored in the resulting eye coordinates. |
||
68 | * |
||
69 | * KW: Eqn is then transformed to the current clip space, where user |
||
70 | * clipping now takes place. The clip-space equations are recalculated |
||
71 | * whenever the projection matrix changes. |
||
72 | */ |
||
73 | if (ctx->ModelviewMatrixStack.Top->flags & MAT_DIRTY) |
||
74 | _math_matrix_analyse( ctx->ModelviewMatrixStack.Top ); |
||
75 | |||
76 | _mesa_transform_vector( equation, equation, |
||
77 | ctx->ModelviewMatrixStack.Top->inv ); |
||
78 | |||
79 | if (TEST_EQ_4V(ctx->Transform.EyeUserPlane[p], equation)) |
||
80 | return; |
||
81 | |||
82 | FLUSH_VERTICES(ctx, _NEW_TRANSFORM); |
||
83 | COPY_4FV(ctx->Transform.EyeUserPlane[p], equation); |
||
84 | |||
85 | /* Update derived state. This state also depends on the projection |
||
86 | * matrix, and is recalculated on changes to the projection matrix by |
||
87 | * code in _mesa_update_state(). |
||
88 | */ |
||
89 | if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { |
||
90 | if (ctx->ProjectionMatrixStack.Top->flags & MAT_DIRTY) |
||
91 | _math_matrix_analyse( ctx->ProjectionMatrixStack.Top ); |
||
92 | |||
93 | _mesa_transform_vector( ctx->Transform._ClipUserPlane[p], |
||
94 | ctx->Transform.EyeUserPlane[p], |
||
95 | ctx->ProjectionMatrixStack.Top->inv ); |
||
96 | } |
||
97 | |||
98 | if (ctx->Driver.ClipPlane) |
||
99 | ctx->Driver.ClipPlane( ctx, plane, equation ); |
||
100 | } |
||
101 | |||
102 | |||
103 | void |
||
104 | _mesa_GetClipPlane( GLenum plane, GLdouble *equation ) |
||
105 | { |
||
106 | GET_CURRENT_CONTEXT(ctx); |
||
107 | GLint p; |
||
108 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
||
109 | |||
110 | p = (GLint) (plane - GL_CLIP_PLANE0); |
||
111 | if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) { |
||
112 | _mesa_error( ctx, GL_INVALID_ENUM, "glGetClipPlane" ); |
||
113 | return; |
||
114 | } |
||
115 | |||
116 | equation[0] = (GLdouble) ctx->Transform.EyeUserPlane[p][0]; |
||
117 | equation[1] = (GLdouble) ctx->Transform.EyeUserPlane[p][1]; |
||
118 | equation[2] = (GLdouble) ctx->Transform.EyeUserPlane[p][2]; |
||
119 | equation[3] = (GLdouble) ctx->Transform.EyeUserPlane[p][3]; |
||
120 | } |