Commits

Murat Sari committed adfa690 Merge

Merge

Comments (0)

Files changed (14)

OgreMain/include/OgreRenderSystem.h

 		start up too.
 		@param func The comparison function applied.
 		@param refValue The reference value used in the comparison
-		@param mask The bitmask applied to both the stencil value and the reference value 
+		@param compareMask The bitmask applied to both the stencil value and the reference value 
 		before comparison
+		@param writeMask The bitmask the controls which bits from refValue will be written to 
+		stencil buffer (valid for operations such as SOP_REPLACE).
+		the stencil
 		@param stencilFailOp The action to perform when the stencil check fails
 		@param depthFailOp The action to perform when the stencil check passes, but the
 		depth buffer check still fails
 		and the inverse of them will happen for back faces (keep remains the same).
 		*/
 		virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-			uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
+			uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF, 
 			StencilOperation stencilFailOp = SOP_KEEP, 
 			StencilOperation depthFailOp = SOP_KEEP,
 			StencilOperation passOp = SOP_KEEP, 

OgreMain/src/OgreCompositorInstance.cpp

 	virtual void execute(SceneManager *sm, RenderSystem *rs)
 	{
 		rs->setStencilCheckEnabled(stencilCheck);
-		rs->setStencilBufferParams(func, refValue, mask, stencilFailOp, depthFailOp, passOp, twoSidedOperation);
+		rs->setStencilBufferParams(func, refValue, mask, 0xFFFFFFFF, stencilFailOp, depthFailOp, passOp, twoSidedOperation);
 	}
 };
 

OgreMain/src/OgreSceneManager.cpp

         mDestRenderSystem->setStencilBufferParams(
             CMPF_ALWAYS_PASS, // always pass stencil check
             0, // no ref value (no compare)
-            0xFFFFFFFF, // no mask
+            0xFFFFFFFF, // no compare mask
+            0xFFFFFFFF, // no write mask
             SOP_KEEP, // stencil test will never fail
             zfail ? incrOp : SOP_KEEP, // back face depth fail
             zfail ? SOP_KEEP : decrOp, // back face pass
         mDestRenderSystem->setStencilBufferParams(
             CMPF_ALWAYS_PASS, // always pass stencil check
             0, // no ref value (no compare)
-            0xFFFFFFFF, // no mask
+			0xFFFFFFFF, // no compare mask
+            0xFFFFFFFF, // no write mask
             SOP_KEEP, // stencil test will never fail
             zfail ? decrOp : SOP_KEEP, // front face depth fail
             zfail ? SOP_KEEP : incrOp, // front face pass

RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h

 		VertexElementType getColourVertexElementType(void) const;
 		void setStencilCheckEnabled(bool enabled);
         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
+            uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
             StencilOperation stencilFailOp = SOP_KEEP, 
             StencilOperation depthFailOp = SOP_KEEP,
             StencilOperation passOp = SOP_KEEP, 

RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp

 	}
     //---------------------------------------------------------------------
     void D3D11RenderSystem::setStencilBufferParams(CompareFunction func, 
-        uint32 refValue, uint32 mask, StencilOperation stencilFailOp, 
+        uint32 refValue, uint32 compareMask, uint32 writeMask, StencilOperation stencilFailOp, 
         StencilOperation depthFailOp, StencilOperation passOp, 
         bool twoSidedOperation)
     {
 		mDepthStencilDesc.BackFace.StencilFunc = D3D11Mappings::get(func);
 
 		mStencilRef = refValue;
-		mDepthStencilDesc.StencilReadMask = refValue;
-		mDepthStencilDesc.StencilWriteMask = mask;
+		mDepthStencilDesc.StencilReadMask = compareMask;
+		mDepthStencilDesc.StencilWriteMask = writeMask;
 
 		mDepthStencilDesc.FrontFace.StencilFailOp = D3D11Mappings::get(stencilFailOp);
 		mDepthStencilDesc.BackFace.StencilFailOp = D3D11Mappings::get(stencilFailOp);

RenderSystems/Direct3D9/include/OgreD3D9RenderSystem.h

 		VertexElementType getColourVertexElementType() const;
 		void setStencilCheckEnabled(bool enabled);
         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
+            uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
             StencilOperation stencilFailOp = SOP_KEEP, 
             StencilOperation depthFailOp = SOP_KEEP,
             StencilOperation passOp = SOP_KEEP, 

RenderSystems/Direct3D9/src/OgreD3D9RenderSystem.cpp

 	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setStencilBufferParams(CompareFunction func, 
-		uint32 refValue, uint32 mask, StencilOperation stencilFailOp, 
+		uint32 refValue, uint32 compareMask, uint32 writeMask, StencilOperation stencilFailOp, 
 		StencilOperation depthFailOp, StencilOperation passOp, 
 		bool twoSidedOperation)
 	{
 			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error setting stencil buffer reference value.",
 			"D3D9RenderSystem::setStencilBufferParams");
 
-		// mask
-		hr = __SetRenderState(D3DRS_STENCILMASK, mask);
+		// compare mask
+		hr = __SetRenderState(D3DRS_STENCILMASK, compareMask);
 		if (FAILED(hr))
-			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error setting stencil buffer mask.",
+			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error setting stencil buffer compare mask.",
+			"D3D9RenderSystem::setStencilBufferParams");
+
+		// compare mask
+		hr = __SetRenderState(D3DRS_STENCILWRITEMASK, writeMask);
+		if (FAILED(hr))
+			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error setting stencil buffer write mask.",
 			"D3D9RenderSystem::setStencilBufferParams");
 
 		// fail op

RenderSystems/GL/include/OgreGLRenderSystem.h

         /// Store last depth write state
         bool mDepthWrite;
 		/// Store last stencil mask state
-		uint32 mStencilMask;
+		uint32 mStencilWriteMask;
 		/// Store last colour write state
 		bool mColourWrite[4];
 
           RenderSystem.
          */
         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
-            StencilOperation stencilFailOp = SOP_KEEP, 
+            uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
+			StencilOperation stencilFailOp = SOP_KEEP, 
             StencilOperation depthFailOp = SOP_KEEP,
             StencilOperation passOp = SOP_KEEP, 
             bool twoSidedOperation = false);

RenderSystems/GL/src/OgreGLRenderSystem.cpp

 	}
 
 	GLRenderSystem::GLRenderSystem()
-		: mDepthWrite(true), mStencilMask(0xFFFFFFFF), mHardwareBufferManager(0),
+		: mDepthWrite(true), mStencilWriteMask(0xFFFFFFFF), mHardwareBufferManager(0),
 		mGpuProgramManager(0),
 		mGLSLProgramFactory(0),
 		mRTTManager(0),
 	}
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setStencilBufferParams(CompareFunction func, 
-		uint32 refValue, uint32 mask, StencilOperation stencilFailOp, 
+		uint32 refValue, uint32 compareMask, uint32 writeMask, StencilOperation stencilFailOp, 
 		StencilOperation depthFailOp, StencilOperation passOp, 
 		bool twoSidedOperation)
 	{
 		bool flip;
-		mStencilMask = refValue;
+		mStencilWriteMask = writeMask;
 
 		if (twoSidedOperation)
 		{
 			if(GLEW_VERSION_2_0) // New GL2 commands
 			{
 				// Back
-				glStencilMaskSeparate(GL_BACK, mask);
-				glStencilFuncSeparate(GL_BACK, convertCompareFunction(func), refValue, mask);
+				glStencilMaskSeparate(GL_BACK, writeMask);
+				glStencilFuncSeparate(GL_BACK, convertCompareFunction(func), refValue, compareMask);
 				glStencilOpSeparate(GL_BACK, 
 					convertStencilOp(stencilFailOp, !flip), 
 					convertStencilOp(depthFailOp, !flip), 
 					convertStencilOp(passOp, !flip));
 				// Front
-				glStencilMaskSeparate(GL_FRONT, mask);
-				glStencilFuncSeparate(GL_FRONT, convertCompareFunction(func), refValue, mask);
+				glStencilMaskSeparate(GL_FRONT, writeMask);
+				glStencilFuncSeparate(GL_FRONT, convertCompareFunction(func), refValue, compareMask);
 				glStencilOpSeparate(GL_FRONT, 
 					convertStencilOp(stencilFailOp, flip),
 					convertStencilOp(depthFailOp, flip), 
 				glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
 				// Back
 				glActiveStencilFaceEXT(GL_BACK);
-				glStencilMask(refValue);
-				glStencilFunc(convertCompareFunction(func), refValue, mask);
+				glStencilMask(writeMask);
+				glStencilFunc(convertCompareFunction(func), refValue, compareMask);
 				glStencilOp(
 					convertStencilOp(stencilFailOp, !flip), 
 					convertStencilOp(depthFailOp, !flip), 
 					convertStencilOp(passOp, !flip));
 				// Front
 				glActiveStencilFaceEXT(GL_FRONT);
-				glStencilMask(refValue);
-				glStencilFunc(convertCompareFunction(func), refValue, mask);
+				glStencilMask(writeMask);
+				glStencilFunc(convertCompareFunction(func), refValue, compareMask);
 				glStencilOp(
 					convertStencilOp(stencilFailOp, flip),
 					convertStencilOp(depthFailOp, flip), 
                 glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
 
 			flip = false;
-			glStencilMask(refValue);
-			glStencilFunc(convertCompareFunction(func), refValue, mask);
+			glStencilMask(writeMask);
+			glStencilFunc(convertCompareFunction(func), refValue, compareMask);
 			glStencilOp(
 				convertStencilOp(stencilFailOp, flip),
 				convertStencilOp(depthFailOp, flip), 
 		}
 		if (buffers & FBT_STENCIL)
 		{
-			glStencilMask(mStencilMask);
+			glStencilMask(mStencilWriteMask);
 		}
 	}
 	// ------------------------------------------------------------------
 		// difference with the really state stored in GL context.
 		glDepthMask(mDepthWrite);
 		glColorMask(mColourWrite[0], mColourWrite[1], mColourWrite[2], mColourWrite[3]);
-		glStencilMask(mStencilMask);
+		glStencilMask(mStencilWriteMask);
 
 	}
 	//---------------------------------------------------------------------

RenderSystems/GLES/include/OgreGLESRenderSystem.h

              RenderSystem
              */
             void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-                    uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
+                    uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF, 
                     StencilOperation stencilFailOp = SOP_KEEP,
                     StencilOperation depthFailOp = SOP_KEEP,
                     StencilOperation passOp = SOP_KEEP,

RenderSystems/GLES/src/OgreGLESRenderSystem.cpp

     }
 
     void GLESRenderSystem::setStencilBufferParams(CompareFunction func,
-                                                uint32 refValue, uint32 mask,
+                                                uint32 refValue, uint32 compareMask, uint32 writeMask, 
                                                 StencilOperation stencilFailOp,
                                                 StencilOperation depthFailOp,
                                                 StencilOperation passOp,
                                                 bool twoSidedOperation)
     {
-        mStateCacheManager->setStencilMask(mask);
-        glStencilFunc(convertCompareFunction(func), refValue, mask);
+        mStateCacheManager->setStencilMask(writeMask);
+        glStencilFunc(convertCompareFunction(func), refValue, compareMask);
         glStencilOp(
             convertStencilOp(stencilFailOp, false),
             convertStencilOp(depthFailOp, false), 

RenderSystems/GLES2/include/OgreGLES2RenderSystem.h

              RenderSystem
              */
             void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-                    uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
+                    uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
                     StencilOperation stencilFailOp = SOP_KEEP,
                     StencilOperation depthFailOp = SOP_KEEP,
                     StencilOperation passOp = SOP_KEEP,

RenderSystems/GLES2/src/EAGL/OgreEAGL2Window.mm

         
         OgreAssert(mContext != nil, "EAGL2Window: Failed to create OpenGL ES context");
 
-        [mWindow addSubview:mViewController.view];
+        if(!mUsingExternalViewController)
+            [mWindow addSubview:mViewController.view];
         
         mViewController.mGLSupport = mGLSupport;
         
         if(!mUsingExternalView)
             [mView release];
     
-        [mWindow makeKeyAndVisible];
+        if(!mUsingExternalViewController)
+            [mWindow makeKeyAndVisible];
 
         mContext->createFramebuffer();
         

RenderSystems/GLES2/src/OgreGLES2RenderSystem.cpp

     }
 
     void GLES2RenderSystem::setStencilBufferParams(CompareFunction func,
-                                                uint32 refValue, uint32 mask,
+                                                uint32 refValue, uint32 compareMask, uint32 writeMask,
                                                 StencilOperation stencilFailOp,
                                                 StencilOperation depthFailOp,
                                                 StencilOperation passOp,
 			flip = (mInvertVertexWinding && !mActiveRenderTarget->requiresTextureFlipping()) ||
             (!mInvertVertexWinding && mActiveRenderTarget->requiresTextureFlipping());
             // Back
-            glStencilMaskSeparate(GL_BACK, mask);
+            glStencilMaskSeparate(GL_BACK, writeMask);
             GL_CHECK_ERROR;
-            glStencilFuncSeparate(GL_BACK, convertCompareFunction(func), refValue, mask);
+            glStencilFuncSeparate(GL_BACK, convertCompareFunction(func), refValue, compareMask);
             GL_CHECK_ERROR;
             glStencilOpSeparate(GL_BACK, 
                                 convertStencilOp(stencilFailOp, !flip), 
 
             GL_CHECK_ERROR;
             // Front
-            glStencilMaskSeparate(GL_FRONT, mask);
+            glStencilMaskSeparate(GL_FRONT, writeMask);
             GL_CHECK_ERROR;
-            glStencilFuncSeparate(GL_FRONT, convertCompareFunction(func), refValue, mask);
+            glStencilFuncSeparate(GL_FRONT, convertCompareFunction(func), refValue, compareMask);
             GL_CHECK_ERROR;
             glStencilOpSeparate(GL_FRONT, 
                                 convertStencilOp(stencilFailOp, flip),
 		else
 		{
 			flip = false;
-			mStateCacheManager->setStencilMask(mask);
-			glStencilFunc(convertCompareFunction(func), refValue, mask);
+			mStateCacheManager->setStencilMask(writeMask);
+			glStencilFunc(convertCompareFunction(func), refValue, compareMask);
             GL_CHECK_ERROR;
 			glStencilOp(
                         convertStencilOp(stencilFailOp, flip),