fixed a bunch of g++ warnings/errors. Compiling with g++ can help find lots of poten...
[mesa.git] / src / mesa / main / clip.c
1 /* $Id: clip.c,v 1.21 2001/03/07 05:06:11 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 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 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "clip.h"
33 #include "context.h"
34 #include "macros.h"
35 #include "mmath.h"
36 #include "mtypes.h"
37
38 #include "math/m_xform.h"
39 #include "math/m_matrix.h"
40 #endif
41
42
43
44
45
46
47 /**********************************************************************/
48 /* Get/Set User clip-planes. */
49 /**********************************************************************/
50
51
52
53 void
54 _mesa_ClipPlane( GLenum plane, const GLdouble *eq )
55 {
56 GET_CURRENT_CONTEXT(ctx);
57 GLint p;
58 GLfloat equation[4];
59 ASSERT_OUTSIDE_BEGIN_END(ctx);
60
61 p = (GLint) plane - (GLint) GL_CLIP_PLANE0;
62 if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
63 _mesa_error( ctx, GL_INVALID_ENUM, "glClipPlane" );
64 return;
65 }
66
67 equation[0] = eq[0];
68 equation[1] = eq[1];
69 equation[2] = eq[2];
70 equation[3] = eq[3];
71
72 /*
73 * The equation is transformed by the transpose of the inverse of the
74 * current modelview matrix and stored in the resulting eye coordinates.
75 *
76 * KW: Eqn is then transformed to the current clip space, where user
77 * clipping now takes place. The clip-space equations are recalculated
78 * whenever the projection matrix changes.
79 */
80 if (ctx->ModelView.flags & MAT_DIRTY)
81 _math_matrix_analyse( &ctx->ModelView );
82
83 _mesa_transform_vector( equation, equation, ctx->ModelView.inv );
84
85 if (TEST_EQ_4V(ctx->Transform.EyeUserPlane[p], equation))
86 return;
87
88 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
89 COPY_4FV(ctx->Transform.EyeUserPlane[p], equation);
90
91 /* Update derived state. This state also depends on the projection
92 * matrix, and is recalculated on changes to the projection matrix by
93 * code in _mesa_update_state().
94 */
95 if (ctx->Transform.ClipEnabled[p]) {
96 if (ctx->ProjectionMatrix.flags & MAT_DIRTY)
97 _math_matrix_analyse( &ctx->ProjectionMatrix );
98
99 _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
100 ctx->Transform.EyeUserPlane[p],
101 ctx->ProjectionMatrix.inv );
102 }
103
104 if (ctx->Driver.ClipPlane)
105 ctx->Driver.ClipPlane( ctx, plane, equation );
106 }
107
108
109 void
110 _mesa_GetClipPlane( GLenum plane, GLdouble *equation )
111 {
112 GET_CURRENT_CONTEXT(ctx);
113 GLint p;
114 ASSERT_OUTSIDE_BEGIN_END(ctx);
115
116 p = (GLint) (plane - GL_CLIP_PLANE0);
117 if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
118 _mesa_error( ctx, GL_INVALID_ENUM, "glGetClipPlane" );
119 return;
120 }
121
122 equation[0] = (GLdouble) ctx->Transform.EyeUserPlane[p][0];
123 equation[1] = (GLdouble) ctx->Transform.EyeUserPlane[p][1];
124 equation[2] = (GLdouble) ctx->Transform.EyeUserPlane[p][2];
125 equation[3] = (GLdouble) ctx->Transform.EyeUserPlane[p][3];
126 }