2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * Update derived clip plane state.
31 _mesa_update_clip_plane(struct gl_context
*ctx
, GLuint plane
)
33 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
34 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
36 /* Clip-Space Plane = Eye-Space Plane * Projection Matrix */
37 _mesa_transform_vector(ctx
->Transform
._ClipUserPlane
[plane
],
38 ctx
->Transform
.EyeUserPlane
[plane
],
39 ctx
->ProjectionMatrixStack
.Top
->inv
);
44 _mesa_ClipPlane( GLenum plane
, const GLdouble
*eq
)
46 GET_CURRENT_CONTEXT(ctx
);
49 ASSERT_OUTSIDE_BEGIN_END(ctx
);
51 p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
52 if (p
< 0 || p
>= (GLint
) ctx
->Const
.MaxClipPlanes
) {
53 _mesa_error( ctx
, GL_INVALID_ENUM
, "glClipPlane" );
57 equation
[0] = (GLfloat
) eq
[0];
58 equation
[1] = (GLfloat
) eq
[1];
59 equation
[2] = (GLfloat
) eq
[2];
60 equation
[3] = (GLfloat
) eq
[3];
63 * The equation is transformed by the transpose of the inverse of the
64 * current modelview matrix and stored in the resulting eye coordinates.
66 * KW: Eqn is then transformed to the current clip space, where user
67 * clipping now takes place. The clip-space equations are recalculated
68 * whenever the projection matrix changes.
70 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
71 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
73 _mesa_transform_vector( equation
, equation
,
74 ctx
->ModelviewMatrixStack
.Top
->inv
);
76 if (TEST_EQ_4V(ctx
->Transform
.EyeUserPlane
[p
], equation
))
79 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
80 COPY_4FV(ctx
->Transform
.EyeUserPlane
[p
], equation
);
82 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
83 _mesa_update_clip_plane(ctx
, p
);
86 if (ctx
->Driver
.ClipPlane
)
87 ctx
->Driver
.ClipPlane( ctx
, plane
, equation
);
92 _mesa_GetClipPlane( GLenum plane
, GLdouble
*equation
)
94 GET_CURRENT_CONTEXT(ctx
);
96 ASSERT_OUTSIDE_BEGIN_END(ctx
);
98 p
= (GLint
) (plane
- GL_CLIP_PLANE0
);
99 if (p
< 0 || p
>= (GLint
) ctx
->Const
.MaxClipPlanes
) {
100 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetClipPlane" );
104 equation
[0] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][0];
105 equation
[1] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][1];
106 equation
[2] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][2];
107 equation
[3] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][3];