3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "math/m_xform.h"
34 #include "math/m_matrix.h"
38 /**********************************************************************/
39 /* Get/Set User clip-planes. */
40 /**********************************************************************/
45 _mesa_ClipPlane( GLenum plane
, const GLdouble
*eq
)
47 GET_CURRENT_CONTEXT(ctx
);
50 ASSERT_OUTSIDE_BEGIN_END(ctx
);
52 p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
53 if (p
< 0 || p
>= (GLint
) ctx
->Const
.MaxClipPlanes
) {
54 _mesa_error( ctx
, GL_INVALID_ENUM
, "glClipPlane" );
58 equation
[0] = (GLfloat
) eq
[0];
59 equation
[1] = (GLfloat
) eq
[1];
60 equation
[2] = (GLfloat
) eq
[2];
61 equation
[3] = (GLfloat
) eq
[3];
64 * The equation is transformed by the transpose of the inverse of the
65 * current modelview matrix and stored in the resulting eye coordinates.
67 * KW: Eqn is then transformed to the current clip space, where user
68 * clipping now takes place. The clip-space equations are recalculated
69 * whenever the projection matrix changes.
71 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY
)
72 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
74 _mesa_transform_vector( equation
, equation
,
75 ctx
->ModelviewMatrixStack
.Top
->inv
);
77 if (TEST_EQ_4V(ctx
->Transform
.EyeUserPlane
[p
], equation
))
80 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
81 COPY_4FV(ctx
->Transform
.EyeUserPlane
[p
], equation
);
83 /* Update derived state. This state also depends on the projection
84 * matrix, and is recalculated on changes to the projection matrix by
85 * code in _mesa_update_state().
87 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
88 if (ctx
->ProjectionMatrixStack
.Top
->flags
& MAT_DIRTY
)
89 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
91 _mesa_transform_vector( ctx
->Transform
._ClipUserPlane
[p
],
92 ctx
->Transform
.EyeUserPlane
[p
],
93 ctx
->ProjectionMatrixStack
.Top
->inv
);
96 if (ctx
->Driver
.ClipPlane
)
97 ctx
->Driver
.ClipPlane( ctx
, plane
, equation
);
102 _mesa_GetClipPlane( GLenum plane
, GLdouble
*equation
)
104 GET_CURRENT_CONTEXT(ctx
);
106 ASSERT_OUTSIDE_BEGIN_END(ctx
);
108 p
= (GLint
) (plane
- GL_CLIP_PLANE0
);
109 if (p
< 0 || p
>= (GLint
) ctx
->Const
.MaxClipPlanes
) {
110 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetClipPlane" );
114 equation
[0] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][0];
115 equation
[1] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][1];
116 equation
[2] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][2];
117 equation
[3] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][3];