2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
32 #include "math/m_matrix.h"
36 * Update derived clip plane state.
39 _mesa_update_clip_plane(struct gl_context
*ctx
, GLuint plane
)
41 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
42 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
44 /* Clip-Space Plane = Eye-Space Plane * Projection Matrix */
45 _mesa_transform_vector(ctx
->Transform
._ClipUserPlane
[plane
],
46 ctx
->Transform
.EyeUserPlane
[plane
],
47 ctx
->ProjectionMatrixStack
.Top
->inv
);
52 _mesa_ClipPlane( GLenum plane
, const GLdouble
*eq
)
54 GET_CURRENT_CONTEXT(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 (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
78 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
80 _mesa_transform_vector( equation
, equation
,
81 ctx
->ModelviewMatrixStack
.Top
->inv
);
83 if (TEST_EQ_4V(ctx
->Transform
.EyeUserPlane
[p
], equation
))
86 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
87 COPY_4FV(ctx
->Transform
.EyeUserPlane
[p
], equation
);
89 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
90 _mesa_update_clip_plane(ctx
, p
);
93 if (ctx
->Driver
.ClipPlane
)
94 ctx
->Driver
.ClipPlane( ctx
, plane
, equation
);
99 _mesa_GetClipPlane( GLenum plane
, GLdouble
*equation
)
101 GET_CURRENT_CONTEXT(ctx
);
104 p
= (GLint
) (plane
- GL_CLIP_PLANE0
);
105 if (p
< 0 || p
>= (GLint
) ctx
->Const
.MaxClipPlanes
) {
106 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetClipPlane" );
110 equation
[0] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][0];
111 equation
[1] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][1];
112 equation
[2] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][2];
113 equation
[3] = (GLdouble
) ctx
->Transform
.EyeUserPlane
[p
][3];