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