clip.c revision 19dff5efc1e348d037b1b3cdfb9ac91020ecde4d
1/* 2 * Mesa 3-D graphics library 3 * Version: 6.3 4 * 5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. 6 * 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: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 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. 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 34 35 36/**********************************************************************/ 37/* Get/Set User clip-planes. */ 38/**********************************************************************/ 39 40 41 42void GLAPIENTRY 43_mesa_ClipPlane( GLenum plane, const GLdouble *eq ) 44{ 45 GET_CURRENT_CONTEXT(ctx); 46 GLint p; 47 GLfloat equation[4]; 48 ASSERT_OUTSIDE_BEGIN_END(ctx); 49 50 p = (GLint) plane - (GLint) GL_CLIP_PLANE0; 51 if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) { 52 _mesa_error( ctx, GL_INVALID_ENUM, "glClipPlane" ); 53 return; 54 } 55 56 equation[0] = (GLfloat) eq[0]; 57 equation[1] = (GLfloat) eq[1]; 58 equation[2] = (GLfloat) eq[2]; 59 equation[3] = (GLfloat) eq[3]; 60 61 /* 62 * The equation is transformed by the transpose of the inverse of the 63 * current modelview matrix and stored in the resulting eye coordinates. 64 * 65 * KW: Eqn is then transformed to the current clip space, where user 66 * clipping now takes place. The clip-space equations are recalculated 67 * whenever the projection matrix changes. 68 */ 69 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) 70 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top ); 71 72 _mesa_transform_vector( equation, equation, 73 ctx->ModelviewMatrixStack.Top->inv ); 74 75 if (TEST_EQ_4V(ctx->Transform.EyeUserPlane[p], equation)) 76 return; 77 78 FLUSH_VERTICES(ctx, _NEW_TRANSFORM); 79 COPY_4FV(ctx->Transform.EyeUserPlane[p], equation); 80 81 /* Update derived state. This state also depends on the projection 82 * matrix, and is recalculated on changes to the projection matrix by 83 * code in _mesa_update_state(). 84 */ 85 if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { 86 if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top)) 87 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top ); 88 89 _mesa_transform_vector( ctx->Transform._ClipUserPlane[p], 90 ctx->Transform.EyeUserPlane[p], 91 ctx->ProjectionMatrixStack.Top->inv ); 92 } 93 94 if (ctx->Driver.ClipPlane) 95 ctx->Driver.ClipPlane( ctx, plane, equation ); 96} 97 98 99void GLAPIENTRY 100_mesa_GetClipPlane( GLenum plane, GLdouble *equation ) 101{ 102 GET_CURRENT_CONTEXT(ctx); 103 GLint p; 104 ASSERT_OUTSIDE_BEGIN_END(ctx); 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 118void GLAPIENTRY 119_mesa_CullParameterfvEXT (GLenum cap, GLfloat *v) 120{ 121 GET_CURRENT_CONTEXT(ctx); 122 ASSERT_OUTSIDE_BEGIN_END(ctx); 123 124 switch (cap) { 125 case GL_CULL_VERTEX_EYE_POSITION_EXT: 126 FLUSH_VERTICES(ctx, _NEW_TRANSFORM); 127 COPY_4FV(ctx->Transform.CullEyePos, v); 128 129 _mesa_transform_vector( ctx->Transform.CullObjPos, 130 ctx->Transform.CullEyePos, 131 ctx->ModelviewMatrixStack.Top->inv ); 132 break; 133 134 case GL_CULL_VERTEX_OBJECT_POSITION_EXT: 135 FLUSH_VERTICES(ctx, _NEW_TRANSFORM); 136 COPY_4FV(ctx->Transform.CullObjPos, v); 137 138 _mesa_transform_vector( ctx->Transform.CullEyePos, 139 ctx->Transform.CullObjPos, 140 ctx->ModelviewMatrixStack.Top->m ); 141 break; 142 default: 143 _mesa_error( ctx, GL_INVALID_ENUM, "glCullParameterfvEXT" ); 144 } 145} 146 147void GLAPIENTRY 148_mesa_CullParameterdvEXT (GLenum cap, GLdouble *v) 149{ 150 GLfloat f[4]; 151 152 f[0] = (GLfloat)v[0]; 153 f[1] = (GLfloat)v[1]; 154 f[2] = (GLfloat)v[2]; 155 f[3] = (GLfloat)v[3]; 156 157 _mesa_CullParameterfvEXT(cap, f); 158} 159 160