• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
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.
23  */
24 
25 
26 #include "glheader.h"
27 #include "clip.h"
28 #include "context.h"
29 #include "macros.h"
30 #include "mtypes.h"
31 
32 #include "math/m_matrix.h"
33 #include "api_exec_decl.h"
34 
35 #include "state_tracker/st_context.h"
36 
37 /**
38  * Update derived clip plane state.
39  */
40 void
_mesa_update_clip_plane(struct gl_context * ctx,GLuint plane)41 _mesa_update_clip_plane(struct gl_context *ctx, GLuint plane)
42 {
43    /* make sure the inverse is up to date */
44    if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
45       _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
46 
47    /* Clip-Space Plane = Eye-Space Plane * Projection Matrix */
48    _mesa_transform_vector(ctx->Transform._ClipUserPlane[plane],
49                           ctx->Transform.EyeUserPlane[plane],
50                           ctx->ProjectionMatrixStack.Top->inv);
51 }
52 
53 
54 void GLAPIENTRY
_mesa_ClipPlane(GLenum plane,const GLdouble * eq)55 _mesa_ClipPlane( GLenum plane, const GLdouble *eq )
56 {
57    GET_CURRENT_CONTEXT(ctx);
58    GLint p;
59    GLfloat equation[4];
60 
61    p = (GLint) plane - (GLint) GL_CLIP_PLANE0;
62    if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
63       _mesa_error( ctx, GL_INVALID_ENUM, "glClipPlane" );
64       return;
65    }
66 
67    equation[0] = (GLfloat) eq[0];
68    equation[1] = (GLfloat) eq[1];
69    equation[2] = (GLfloat) eq[2];
70    equation[3] = (GLfloat) eq[3];
71 
72    /*
73     * The equation is transformed by the transpose of the inverse of the
74     * current modelview matrix and stored in the resulting eye coordinates.
75     *
76     * KW: Eqn is then transformed to the current clip space, where user
77     * clipping now takes place.  The clip-space equations are recalculated
78     * whenever the projection matrix changes.
79     */
80    if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top))
81       _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
82 
83    _mesa_transform_vector( equation, equation,
84                            ctx->ModelviewMatrixStack.Top->inv );
85 
86    if (TEST_EQ_4V(ctx->Transform.EyeUserPlane[p], equation))
87       return;
88 
89    /* EyeUserPlane is used by program state constants. */
90    FLUSH_VERTICES(ctx, _NEW_TRANSFORM, GL_TRANSFORM_BIT);
91    ctx->NewDriverState |= ST_NEW_CLIP_STATE;
92    COPY_4FV(ctx->Transform.EyeUserPlane[p], equation);
93 
94    if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
95       _mesa_update_clip_plane(ctx, p);
96    }
97 }
98 
99 
100 void GLAPIENTRY
_mesa_GetClipPlane(GLenum plane,GLdouble * equation)101 _mesa_GetClipPlane( GLenum plane, GLdouble *equation )
102 {
103    GET_CURRENT_CONTEXT(ctx);
104    GLint p;
105 
106    p = (GLint) (plane - GL_CLIP_PLANE0);
107    if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
108       _mesa_error( ctx, GL_INVALID_ENUM, "glGetClipPlane" );
109       return;
110    }
111 
112    equation[0] = (GLdouble) ctx->Transform.EyeUserPlane[p][0];
113    equation[1] = (GLdouble) ctx->Transform.EyeUserPlane[p][1];
114    equation[2] = (GLdouble) ctx->Transform.EyeUserPlane[p][2];
115    equation[3] = (GLdouble) ctx->Transform.EyeUserPlane[p][3];
116 }
117