1 /* $Id: clip.c,v 1.23 2001/09/15 18:02:49 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
38 #include "math/m_xform.h"
39 #include "math/m_matrix.h"
44 /**********************************************************************/
45 /* Get/Set User clip-planes. */
46 /**********************************************************************/
51 _mesa_ClipPlane( GLenum plane
, const GLdouble
*eq
)
53 GET_CURRENT_CONTEXT(ctx
);
56 ASSERT_OUTSIDE_BEGIN_END(ctx
);
58 p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
59 if (p
< 0 || p
>= (GLint
) ctx
->Const
.MaxClipPlanes
) {
60 _mesa_error( ctx
, GL_INVALID_ENUM
, "glClipPlane" );
64 equation
[0] = (GLfloat
) eq
[0];
65 equation
[1] = (GLfloat
) eq
[1];
66 equation
[2] = (GLfloat
) eq
[2];
67 equation
[3] = (GLfloat
) eq
[3];
70 * The equation is transformed by the transpose of the inverse of the
71 * current modelview matrix and stored in the resulting eye coordinates.
73 * KW: Eqn is then transformed to the current clip space, where user
74 * clipping now takes place. The clip-space equations are recalculated
75 * whenever the projection matrix changes.
77 if (ctx
->ModelView
.flags
& MAT_DIRTY
)
78 _math_matrix_analyse( &ctx
->ModelView
);
80 _mesa_transform_vector( equation
, equation
, ctx
->ModelView
.inv
);
82 if (TEST_EQ_4V(ctx
->Transform
.EyeUserPlane
[p
], equation
))
85 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
86 COPY_4FV(ctx
->Transform
.EyeUserPlane
[p
], equation
);
88 /* Update derived state. This state also depends on the projection
89 * matrix, and is recalculated on changes to the projection matrix by
90 * code in _mesa_update_state().
92 if (ctx
->Transform
.ClipEnabled
[p
]) {
93 if (ctx
->ProjectionMatrix
.flags
& MAT_DIRTY
)
94 _math_matrix_analyse( &ctx
->ProjectionMatrix
);
96 _mesa_transform_vector( ctx
->Transform
._ClipUserPlane
[p
],
97 ctx
->Transform
.EyeUserPlane
[p
],
98 ctx
->ProjectionMatrix
.inv
);
101 if (ctx
->Driver
.ClipPlane
)
102 ctx
->Driver
.ClipPlane( ctx
, plane
, equation
);
107 _mesa_GetClipPlane( GLenum plane
, GLdouble
*equation
)
109 GET_CURRENT_CONTEXT(ctx
);
111 ASSERT_OUTSIDE_BEGIN_END(ctx
);
113 p
= (GLint
) (plane
- GL_CLIP_PLANE0
);
114 if (p
< 0 || p
>= (GLint
) ctx
->Const
.MaxClipPlanes
) {
115 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetClipPlane" );
119 equation
[0] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][0];
120 equation
[1] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][1];
121 equation
[2] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][2];
122 equation
[3] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][3];