1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Mesa 3-D graphics library
3*61046927SAndroid Build Coastguard Worker *
4*61046927SAndroid Build Coastguard Worker * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
5*61046927SAndroid Build Coastguard Worker *
6*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
7*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
8*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
9*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
11*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
12*61046927SAndroid Build Coastguard Worker *
13*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be included
14*61046927SAndroid Build Coastguard Worker * in all copies or substantial portions of the Software.
15*61046927SAndroid Build Coastguard Worker *
16*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17*61046927SAndroid Build Coastguard Worker * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20*61046927SAndroid Build Coastguard Worker * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21*61046927SAndroid Build Coastguard Worker * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22*61046927SAndroid Build Coastguard Worker * OTHER DEALINGS IN THE SOFTWARE.
23*61046927SAndroid Build Coastguard Worker */
24*61046927SAndroid Build Coastguard Worker
25*61046927SAndroid Build Coastguard Worker
26*61046927SAndroid Build Coastguard Worker #include "util/glheader.h"
27*61046927SAndroid Build Coastguard Worker #include "clip.h"
28*61046927SAndroid Build Coastguard Worker #include "context.h"
29*61046927SAndroid Build Coastguard Worker #include "macros.h"
30*61046927SAndroid Build Coastguard Worker #include "mtypes.h"
31*61046927SAndroid Build Coastguard Worker
32*61046927SAndroid Build Coastguard Worker #include "math/m_matrix.h"
33*61046927SAndroid Build Coastguard Worker #include "api_exec_decl.h"
34*61046927SAndroid Build Coastguard Worker
35*61046927SAndroid Build Coastguard Worker #include "state_tracker/st_context.h"
36*61046927SAndroid Build Coastguard Worker
37*61046927SAndroid Build Coastguard Worker /**
38*61046927SAndroid Build Coastguard Worker * Update derived clip plane state.
39*61046927SAndroid Build Coastguard Worker */
40*61046927SAndroid Build Coastguard Worker void
_mesa_update_clip_plane(struct gl_context * ctx,GLuint plane)41*61046927SAndroid Build Coastguard Worker _mesa_update_clip_plane(struct gl_context *ctx, GLuint plane)
42*61046927SAndroid Build Coastguard Worker {
43*61046927SAndroid Build Coastguard Worker /* make sure the inverse is up to date */
44*61046927SAndroid Build Coastguard Worker if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
45*61046927SAndroid Build Coastguard Worker _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
46*61046927SAndroid Build Coastguard Worker
47*61046927SAndroid Build Coastguard Worker /* Clip-Space Plane = Eye-Space Plane * Projection Matrix */
48*61046927SAndroid Build Coastguard Worker _mesa_transform_vector(ctx->Transform._ClipUserPlane[plane],
49*61046927SAndroid Build Coastguard Worker ctx->Transform.EyeUserPlane[plane],
50*61046927SAndroid Build Coastguard Worker ctx->ProjectionMatrixStack.Top->inv);
51*61046927SAndroid Build Coastguard Worker }
52*61046927SAndroid Build Coastguard Worker
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ClipPlane(GLenum plane,const GLdouble * eq)55*61046927SAndroid Build Coastguard Worker _mesa_ClipPlane( GLenum plane, const GLdouble *eq )
56*61046927SAndroid Build Coastguard Worker {
57*61046927SAndroid Build Coastguard Worker GET_CURRENT_CONTEXT(ctx);
58*61046927SAndroid Build Coastguard Worker GLint p;
59*61046927SAndroid Build Coastguard Worker GLfloat equation[4];
60*61046927SAndroid Build Coastguard Worker
61*61046927SAndroid Build Coastguard Worker p = (GLint) plane - (GLint) GL_CLIP_PLANE0;
62*61046927SAndroid Build Coastguard Worker if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
63*61046927SAndroid Build Coastguard Worker _mesa_error( ctx, GL_INVALID_ENUM, "glClipPlane" );
64*61046927SAndroid Build Coastguard Worker return;
65*61046927SAndroid Build Coastguard Worker }
66*61046927SAndroid Build Coastguard Worker
67*61046927SAndroid Build Coastguard Worker equation[0] = (GLfloat) eq[0];
68*61046927SAndroid Build Coastguard Worker equation[1] = (GLfloat) eq[1];
69*61046927SAndroid Build Coastguard Worker equation[2] = (GLfloat) eq[2];
70*61046927SAndroid Build Coastguard Worker equation[3] = (GLfloat) eq[3];
71*61046927SAndroid Build Coastguard Worker
72*61046927SAndroid Build Coastguard Worker /*
73*61046927SAndroid Build Coastguard Worker * The equation is transformed by the transpose of the inverse of the
74*61046927SAndroid Build Coastguard Worker * current modelview matrix and stored in the resulting eye coordinates.
75*61046927SAndroid Build Coastguard Worker *
76*61046927SAndroid Build Coastguard Worker * KW: Eqn is then transformed to the current clip space, where user
77*61046927SAndroid Build Coastguard Worker * clipping now takes place. The clip-space equations are recalculated
78*61046927SAndroid Build Coastguard Worker * whenever the projection matrix changes.
79*61046927SAndroid Build Coastguard Worker */
80*61046927SAndroid Build Coastguard Worker if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top))
81*61046927SAndroid Build Coastguard Worker _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
82*61046927SAndroid Build Coastguard Worker
83*61046927SAndroid Build Coastguard Worker _mesa_transform_vector( equation, equation,
84*61046927SAndroid Build Coastguard Worker ctx->ModelviewMatrixStack.Top->inv );
85*61046927SAndroid Build Coastguard Worker
86*61046927SAndroid Build Coastguard Worker if (TEST_EQ_4V(ctx->Transform.EyeUserPlane[p], equation))
87*61046927SAndroid Build Coastguard Worker return;
88*61046927SAndroid Build Coastguard Worker
89*61046927SAndroid Build Coastguard Worker /* EyeUserPlane is used by program state constants. */
90*61046927SAndroid Build Coastguard Worker FLUSH_VERTICES(ctx, _NEW_TRANSFORM, GL_TRANSFORM_BIT);
91*61046927SAndroid Build Coastguard Worker ctx->NewDriverState |= ST_NEW_CLIP_STATE;
92*61046927SAndroid Build Coastguard Worker COPY_4FV(ctx->Transform.EyeUserPlane[p], equation);
93*61046927SAndroid Build Coastguard Worker
94*61046927SAndroid Build Coastguard Worker if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
95*61046927SAndroid Build Coastguard Worker _mesa_update_clip_plane(ctx, p);
96*61046927SAndroid Build Coastguard Worker }
97*61046927SAndroid Build Coastguard Worker }
98*61046927SAndroid Build Coastguard Worker
99*61046927SAndroid Build Coastguard Worker
100*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_GetClipPlane(GLenum plane,GLdouble * equation)101*61046927SAndroid Build Coastguard Worker _mesa_GetClipPlane( GLenum plane, GLdouble *equation )
102*61046927SAndroid Build Coastguard Worker {
103*61046927SAndroid Build Coastguard Worker GET_CURRENT_CONTEXT(ctx);
104*61046927SAndroid Build Coastguard Worker GLint p;
105*61046927SAndroid Build Coastguard Worker
106*61046927SAndroid Build Coastguard Worker p = (GLint) (plane - GL_CLIP_PLANE0);
107*61046927SAndroid Build Coastguard Worker if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
108*61046927SAndroid Build Coastguard Worker _mesa_error( ctx, GL_INVALID_ENUM, "glGetClipPlane" );
109*61046927SAndroid Build Coastguard Worker return;
110*61046927SAndroid Build Coastguard Worker }
111*61046927SAndroid Build Coastguard Worker
112*61046927SAndroid Build Coastguard Worker equation[0] = (GLdouble) ctx->Transform.EyeUserPlane[p][0];
113*61046927SAndroid Build Coastguard Worker equation[1] = (GLdouble) ctx->Transform.EyeUserPlane[p][1];
114*61046927SAndroid Build Coastguard Worker equation[2] = (GLdouble) ctx->Transform.EyeUserPlane[p][2];
115*61046927SAndroid Build Coastguard Worker equation[3] = (GLdouble) ctx->Transform.EyeUserPlane[p][3];
116*61046927SAndroid Build Coastguard Worker }
117