OSDN Git Service

Implement user clip planes.
authorNicolas Capens <capn@google.com>
Thu, 2 Jul 2015 21:06:53 +0000 (17:06 -0400)
committerNicolas Capens <capn@google.com>
Fri, 3 Jul 2015 15:10:19 +0000 (15:10 +0000)
Bug 22123818

Change-Id: Icd26392008ce50ad822c2ab961eeb86117ca8544
Reviewed-on: https://swiftshader-review.googlesource.com/3626
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
src/Main/Config.hpp
src/OpenGL/libGLES_CM/Context.cpp
src/OpenGL/libGLES_CM/Context.h
src/OpenGL/libGLES_CM/libGLES_CM.cpp
src/Renderer/Renderer.cpp
src/Renderer/Renderer.hpp

index de266c4..844ebae 100644 (file)
@@ -80,6 +80,7 @@ enum
        MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = MAX_UNIFORM_BLOCKS_COMPONENTS + 4 * VERTEX_UNIFORM_VECTORS,\r
        MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4,\r
        MAX_UNIFORM_BUFFER_BINDINGS = 36,\r
+       MAX_CLIP_PLANES = 6,\r
 };\r
 \r
 #endif   // sw_Config_hpp\r
index 774455d..e47e7e2 100644 (file)
@@ -204,6 +204,8 @@ Context::Context(const egl::Config *config, const Context *shareContext)
        setVertexAttrib(sw::Normal, 0.0f, 0.0f, 1.0f, 1.0f);\r
        setVertexAttrib(sw::PointSize, 1.0f, 1.0f, 1.0f, 1.0f);\r
 \r
+       clipFlags = 0;\r
+\r
     mHasBeenCurrent = false;\r
 \r
     markAllStateDirty();\r
@@ -1309,6 +1311,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
        case GL_MAX_PROJECTION_STACK_DEPTH: *params = MAX_PROJECTION_STACK_DEPTH; break;\r
        case GL_MAX_TEXTURE_STACK_DEPTH:    *params = MAX_TEXTURE_STACK_DEPTH;    break;\r
        case GL_MAX_TEXTURE_UNITS:          *params = MAX_TEXTURE_UNITS;          break;\r
+       case GL_MAX_CLIP_PLANES:            *params = MAX_CLIP_PLANES;            break;\r
     default:\r
         return false;\r
     }\r
@@ -1409,6 +1412,7 @@ int Context::getQueryParameterNum(GLenum pname)
        case GL_MAX_PROJECTION_STACK_DEPTH:\r
        case GL_MAX_TEXTURE_STACK_DEPTH:\r
        case GL_MAX_TEXTURE_UNITS:\r
+       case GL_MAX_CLIP_PLANES:\r
         return 1;\r
        default:\r
                UNREACHABLE(pname);\r
@@ -2979,6 +2983,18 @@ void Context::ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GL
        currentMatrixStack().ortho(left, right, bottom, top, zNear, zFar);\r
 }\r
 \r
+void Context::setClipPlane(int index, const float plane[4])\r
+{\r
+       sw::Plane clipPlane = modelViewStack.current() * sw::Plane(plane);\r
+       device->setClipPlane(index, &clipPlane.A);\r
+}\r
+\r
+void Context::setClipPlaneEnable(int index, bool enable)\r
+{\r
+       clipFlags = clipFlags & ~((int)!enable << index) | ((int)enable << index);\r
+       device->setClipFlags(clipFlags);\r
+}\r
+\r
 void Context::clientActiveTexture(GLenum texture)\r
 {\r
        clientTexture = texture;\r
index 71831e7..d5d4c8f 100644 (file)
@@ -478,6 +478,9 @@ public:
        void frustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);\r
     void ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);\r
 \r
+       void setClipPlane(int index, const float plane[4]);\r
+       void setClipPlaneEnable(int index, bool enable);\r
+\r
 private:\r
        virtual ~Context();\r
 \r
@@ -548,6 +551,8 @@ private:
        bool textureExternalEnabled[MAX_TEXTURE_UNITS];\r
        GLenum clientTexture;\r
 \r
+       int clipFlags;\r
+\r
        Device *device;\r
     ResourceManager *mResourceManager;\r
 };\r
index 749fced..ca80a47 100644 (file)
@@ -555,7 +555,21 @@ void ClientActiveTexture(GLenum texture)
 \r
 void ClipPlanef(GLenum plane, const GLfloat *equation)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(GLenum plane = 0x%X, const GLfloat *equation)", plane);\r
+\r
+       int index = plane - GL_CLIP_PLANE0;\r
+\r
+       if(index < 0 || index >= MAX_CLIP_PLANES)\r
+       {\r
+               return error(GL_INVALID_ENUM);\r
+       }\r
+\r
+       es1::Context *context = es1::getContext();\r
+\r
+       if(context)\r
+       {\r
+               context->setClipPlane(index, equation);\r
+       }\r
 }\r
 \r
 void ClipPlanex(GLenum plane, const GLfixed *equation)\r
@@ -1187,6 +1201,12 @@ void Disable(GLenum cap)
                case GL_TEXTURE_COORD_ARRAY:      UNIMPLEMENTED(); break;\r
                case GL_MULTISAMPLE:              UNIMPLEMENTED(); break;\r
                case GL_SAMPLE_ALPHA_TO_ONE:      UNIMPLEMENTED(); break;\r
+               case GL_CLIP_PLANE0:              context->setClipPlaneEnable(0, false); break;\r
+               case GL_CLIP_PLANE1:              context->setClipPlaneEnable(1, false); break;\r
+               case GL_CLIP_PLANE2:              context->setClipPlaneEnable(2, false); break;\r
+               case GL_CLIP_PLANE3:              context->setClipPlaneEnable(3, false); break;\r
+               case GL_CLIP_PLANE4:              context->setClipPlaneEnable(4, false); break;\r
+               case GL_CLIP_PLANE5:              context->setClipPlaneEnable(5, false); break;\r
                default:\r
                        return error(GL_INVALID_ENUM);\r
                }\r
@@ -1303,6 +1323,12 @@ void Enable(GLenum cap)
                case GL_TEXTURE_COORD_ARRAY:      UNIMPLEMENTED(); break;\r
                case GL_MULTISAMPLE:              UNIMPLEMENTED(); break;\r
                case GL_SAMPLE_ALPHA_TO_ONE:      UNIMPLEMENTED(); break;\r
+               case GL_CLIP_PLANE0:              context->setClipPlaneEnable(0, true); break;\r
+               case GL_CLIP_PLANE1:              context->setClipPlaneEnable(1, true); break;\r
+               case GL_CLIP_PLANE2:              context->setClipPlaneEnable(2, true); break;\r
+               case GL_CLIP_PLANE3:              context->setClipPlaneEnable(3, true); break;\r
+               case GL_CLIP_PLANE4:              context->setClipPlaneEnable(4, true); break;\r
+               case GL_CLIP_PLANE5:              context->setClipPlaneEnable(5, true); break;\r
                default:\r
                        return error(GL_INVALID_ENUM);\r
                }\r
index f14e14a..93c6bf1 100644 (file)
@@ -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;
                }
index 2b6bbe1..cf3474d 100644 (file)
@@ -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;