Commit d2264145 by Nicolas Capens

Implement user clip planes.

Bug 22123818 Change-Id: Icd26392008ce50ad822c2ab961eeb86117ca8544 Reviewed-on: https://swiftshader-review.googlesource.com/3626Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 5ce0ea65
......@@ -80,6 +80,7 @@ enum
MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = MAX_UNIFORM_BLOCKS_COMPONENTS + 4 * VERTEX_UNIFORM_VECTORS,
MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4,
MAX_UNIFORM_BUFFER_BINDINGS = 36,
MAX_CLIP_PLANES = 6,
};
#endif // sw_Config_hpp
......@@ -204,6 +204,8 @@ Context::Context(const egl::Config *config, const Context *shareContext)
setVertexAttrib(sw::Normal, 0.0f, 0.0f, 1.0f, 1.0f);
setVertexAttrib(sw::PointSize, 1.0f, 1.0f, 1.0f, 1.0f);
clipFlags = 0;
mHasBeenCurrent = false;
markAllStateDirty();
......@@ -1309,6 +1311,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_MAX_PROJECTION_STACK_DEPTH: *params = MAX_PROJECTION_STACK_DEPTH; break;
case GL_MAX_TEXTURE_STACK_DEPTH: *params = MAX_TEXTURE_STACK_DEPTH; break;
case GL_MAX_TEXTURE_UNITS: *params = MAX_TEXTURE_UNITS; break;
case GL_MAX_CLIP_PLANES: *params = MAX_CLIP_PLANES; break;
default:
return false;
}
......@@ -1409,6 +1412,7 @@ int Context::getQueryParameterNum(GLenum pname)
case GL_MAX_PROJECTION_STACK_DEPTH:
case GL_MAX_TEXTURE_STACK_DEPTH:
case GL_MAX_TEXTURE_UNITS:
case GL_MAX_CLIP_PLANES:
return 1;
default:
UNREACHABLE(pname);
......@@ -2979,6 +2983,18 @@ void Context::ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GL
currentMatrixStack().ortho(left, right, bottom, top, zNear, zFar);
}
void Context::setClipPlane(int index, const float plane[4])
{
sw::Plane clipPlane = modelViewStack.current() * sw::Plane(plane);
device->setClipPlane(index, &clipPlane.A);
}
void Context::setClipPlaneEnable(int index, bool enable)
{
clipFlags = clipFlags & ~((int)!enable << index) | ((int)enable << index);
device->setClipFlags(clipFlags);
}
void Context::clientActiveTexture(GLenum texture)
{
clientTexture = texture;
......
......@@ -478,6 +478,9 @@ public:
void frustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
void ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
void setClipPlane(int index, const float plane[4]);
void setClipPlaneEnable(int index, bool enable);
private:
virtual ~Context();
......@@ -548,6 +551,8 @@ private:
bool textureExternalEnabled[MAX_TEXTURE_UNITS];
GLenum clientTexture;
int clipFlags;
Device *device;
ResourceManager *mResourceManager;
};
......
......@@ -555,7 +555,21 @@ void ClientActiveTexture(GLenum texture)
void ClipPlanef(GLenum plane, const GLfloat *equation)
{
UNIMPLEMENTED();
TRACE("(GLenum plane = 0x%X, const GLfloat *equation)", plane);
int index = plane - GL_CLIP_PLANE0;
if(index < 0 || index >= MAX_CLIP_PLANES)
{
return error(GL_INVALID_ENUM);
}
es1::Context *context = es1::getContext();
if(context)
{
context->setClipPlane(index, equation);
}
}
void ClipPlanex(GLenum plane, const GLfixed *equation)
......@@ -1187,6 +1201,12 @@ void Disable(GLenum cap)
case GL_TEXTURE_COORD_ARRAY: UNIMPLEMENTED(); break;
case GL_MULTISAMPLE: UNIMPLEMENTED(); break;
case GL_SAMPLE_ALPHA_TO_ONE: UNIMPLEMENTED(); break;
case GL_CLIP_PLANE0: context->setClipPlaneEnable(0, false); break;
case GL_CLIP_PLANE1: context->setClipPlaneEnable(1, false); break;
case GL_CLIP_PLANE2: context->setClipPlaneEnable(2, false); break;
case GL_CLIP_PLANE3: context->setClipPlaneEnable(3, false); break;
case GL_CLIP_PLANE4: context->setClipPlaneEnable(4, false); break;
case GL_CLIP_PLANE5: context->setClipPlaneEnable(5, false); break;
default:
return error(GL_INVALID_ENUM);
}
......@@ -1303,6 +1323,12 @@ void Enable(GLenum cap)
case GL_TEXTURE_COORD_ARRAY: UNIMPLEMENTED(); break;
case GL_MULTISAMPLE: UNIMPLEMENTED(); break;
case GL_SAMPLE_ALPHA_TO_ONE: UNIMPLEMENTED(); break;
case GL_CLIP_PLANE0: context->setClipPlaneEnable(0, true); break;
case GL_CLIP_PLANE1: context->setClipPlaneEnable(1, true); break;
case GL_CLIP_PLANE2: context->setClipPlaneEnable(2, true); break;
case GL_CLIP_PLANE3: context->setClipPlaneEnable(3, true); break;
case GL_CLIP_PLANE4: context->setClipPlaneEnable(4, true); break;
case GL_CLIP_PLANE5: context->setClipPlaneEnable(5, true); break;
default:
return error(GL_INVALID_ENUM);
}
......
......@@ -2442,7 +2442,7 @@ namespace sw
void Renderer::setClipPlane(unsigned int index, const float plane[4])
{
if(index < 6)
if(index < MAX_CLIP_PLANES)
{
userPlane[index] = plane;
}
......
......@@ -398,8 +398,8 @@ namespace sw
Primitive *primitiveBatch[16];
// User-defined clipping planes
Plane userPlane[6];
Plane clipPlane[6]; // Tranformed to clip space
Plane userPlane[MAX_CLIP_PLANES];
Plane clipPlane[MAX_CLIP_PLANES]; // Tranformed to clip space
bool updateClipPlanes;
volatile bool exitThreads;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment