#include "glheader.h"
#include "clip.h"
#include "context.h"
#include "macros.h"
#include "mmath.h"
#include "mtypes.h"
#include "math/m_xform.h"
#include "math/m_matrix.h"
void
_mesa_ClipPlane( GLenum plane, const GLdouble *eq )
{
GET_CURRENT_CONTEXT(ctx);
GLint p;
GLfloat equation[4];
ASSERT_OUTSIDE_BEGIN_END(ctx);
p = (GLint) plane - (GLint) GL_CLIP_PLANE0;
if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
_mesa_error( ctx, GL_INVALID_ENUM, "glClipPlane" );
return;
}
equation[0] = (GLfloat) eq[0];
equation[1] = (GLfloat) eq[1];
equation[2] = (GLfloat) eq[2];
equation[3] = (GLfloat) eq[3];
if (ctx->ModelviewMatrixStack.Top->flags & MAT_DIRTY)
_math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
_mesa_transform_vector( equation, equation,
ctx->ModelviewMatrixStack.Top->inv );
if (TEST_EQ_4V(ctx->Transform.EyeUserPlane[p], equation))
return;
FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
COPY_4FV(ctx->Transform.EyeUserPlane[p], equation);
if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
if (ctx->ProjectionMatrixStack.Top->flags & MAT_DIRTY)
_math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
_mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
ctx->Transform.EyeUserPlane[p],
ctx->ProjectionMatrixStack.Top->inv );
}
if (ctx->Driver.ClipPlane)
ctx->Driver.ClipPlane( ctx, plane, equation );
}
void
_mesa_GetClipPlane( GLenum plane, GLdouble *equation )
{
GET_CURRENT_CONTEXT(ctx);
GLint p;
ASSERT_OUTSIDE_BEGIN_END(ctx);
p = (GLint) (plane - GL_CLIP_PLANE0);
if (p < 0 || p >= (GLint) ctx->Const.MaxClipPlanes) {
_mesa_error( ctx, GL_INVALID_ENUM, "glGetClipPlane" );
return;
}
equation[0] = (GLdouble) ctx->Transform.EyeUserPlane[p][0];
equation[1] = (GLdouble) ctx->Transform.EyeUserPlane[p][1];
equation[2] = (GLdouble) ctx->Transform.EyeUserPlane[p][2];
equation[3] = (GLdouble) ctx->Transform.EyeUserPlane[p][3];
}