Browse Source

Separated viewport from RenderTarget

Marko Pintera 13 years ago
parent
commit
08f61d9d01

+ 5 - 11
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -401,9 +401,8 @@ namespace CamelotEngine
 			// NB don't use windowMovedOrResized since Win32 doesn't know
 			// NB don't use windowMovedOrResized since Win32 doesn't know
 			// about the size change yet				
 			// about the size change yet				
 			mDevice->invalidate(this);
 			mDevice->invalidate(this);
-			// Notify viewports of resize
-			ViewportList::iterator it = mViewportList.begin();
-			while(it != mViewportList.end()) (*it++).second->_updateDimensions();
+
+			// TODO - Notify viewports of resize
 		}
 		}
 	} 
 	} 
 
 
@@ -476,10 +475,8 @@ namespace CamelotEngine
 			{
 			{
 				mWidth = mDesiredWidth;
 				mWidth = mDesiredWidth;
 				mHeight = mDesiredHeight;
 				mHeight = mDesiredHeight;
-				// Notify viewports of resize
-				ViewportList::iterator it = mViewportList.begin();
-				while( it != mViewportList.end() )
-					(*it++).second->_updateDimensions();			
+
+				// TODO - Notify viewports of resize		
 			}
 			}
 		}
 		}
 		mSwitchingFullscreen = false;
 		mSwitchingFullscreen = false;
@@ -866,10 +863,7 @@ namespace CamelotEngine
 			mWidth  = rc.right - rc.left;
 			mWidth  = rc.right - rc.left;
 			mHeight = rc.bottom - rc.top;
 			mHeight = rc.bottom - rc.top;
 
 
-			// Notify viewports of resize
-			ViewportList::iterator it = mViewportList.begin();
-			while( it != mViewportList.end() )
-				(*it++).second->_updateDimensions();			
+			// TODO - Notify viewports of resize		
 		}	
 		}	
 
 
 	}
 	}

+ 1 - 10
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -691,11 +691,7 @@ namespace CamelotEngine {
 		mWidth = rc.right - rc.left;
 		mWidth = rc.right - rc.left;
 		mHeight = rc.bottom - rc.top;
 		mHeight = rc.bottom - rc.top;
 
 
-		// Notify viewports of resize
-		ViewportList::iterator it, itend;
-		itend = mViewportList.end();
-		for( it = mViewportList.begin(); it != itend; ++it )
-			(*it).second->_updateDimensions();
+		// TODO - Notify viewports of resize
 	}
 	}
 
 
 	void Win32Window::swapBuffers(bool waitForVSync)
 	void Win32Window::swapBuffers(bool waitForVSync)
@@ -727,11 +723,6 @@ namespace CamelotEngine {
 			CM_EXCEPT(InvalidParametersException, "Unsupported format.");
 			CM_EXCEPT(InvalidParametersException, "Unsupported format.");
 		}
 		}
 
 
-
-		// Switch context if different from current one
-		RenderSystem* rsys = CamelotEngine::RenderSystemManager::getActive();
-		rsys->_setViewport(this->getViewport(0));
-
 		// Must change the packing to ensure no overruns!
 		// Must change the packing to ensure no overruns!
 		glPixelStorei(GL_PACK_ALIGNMENT, 1);
 		glPixelStorei(GL_PACK_ALIGNMENT, 1);
 
 

+ 0 - 63
CamelotRenderer/Include/CmRenderTarget.h

@@ -129,44 +129,6 @@ namespace CamelotEngine {
         virtual void swapBuffers(bool waitForVSync = true)
         virtual void swapBuffers(bool waitForVSync = true)
         { (void)waitForVSync; }
         { (void)waitForVSync; }
 
 
-        /** Adds a viewport to the rendering target.
-            @remarks
-                A viewport is the rectangle into which rendering output is sent. This method adds
-                a viewport to the render target, rendering from the supplied camera. The
-                rest of the parameters are only required if you wish to add more than one viewport
-                to a single rendering target. Note that size information passed to this method is
-                passed as a parametric, i.e. it is relative rather than absolute. This is to allow
-                viewports to automatically resize along with the target.
-            @param
-                ZOrder The relative order of the viewport with others on the target (allows overlapping
-                viewports i.e. picture-in-picture). Higher ZOrders are on top of lower ones. The actual number
-                is irrelevant, only the relative ZOrder matters (you can leave gaps in the numbering)
-            @param
-                left The relative position of the left of the viewport on the target, as a value between 0 and 1.
-            @param
-                top The relative position of the top of the viewport on the target, as a value between 0 and 1.
-            @param
-                width The relative width of the viewport on the target, as a value between 0 and 1.
-            @param
-                height The relative height of the viewport on the target, as a value between 0 and 1.
-        */
-        virtual Viewport* addViewport(int ZOrder = 0, float left = 0.0f, float top = 0.0f ,
-            float width = 1.0f, float height = 1.0f);
-
-        /** Returns the number of viewports attached to this target.*/
-        virtual unsigned short getNumViewports(void) const;
-
-        /** Retrieves a pointer to the viewport with the given index. */
-        virtual Viewport* getViewport(unsigned short index);
-
-        /** Removes a viewport at a given ZOrder.
-        */
-        virtual void removeViewport(int ZOrder);
-
-        /** Removes all viewports on this target.
-        */
-        virtual void removeAllViewports(void);
-
         /** Gets a custom (maybe platform-specific) attribute.
         /** Gets a custom (maybe platform-specific) attribute.
             @remarks
             @remarks
                 This is a nasty way of satisfying any API's need to see platform-specific details.
                 This is a nasty way of satisfying any API's need to see platform-specific details.
@@ -275,27 +237,6 @@ namespace CamelotEngine {
 			since you are responsible for calling _updateViewport in the correct order.
 			since you are responsible for calling _updateViewport in the correct order.
         */
         */
 		virtual void _beginUpdate();
 		virtual void _beginUpdate();
-
-		/** Method for manual management of rendering - renders the given 
-		viewport (even if it is not autoupdated)
-		@remarks
-		This also fires preViewportUpdate and postViewportUpdate, and manages statistics.
-		You should call it between _beginUpdate() and _endUpdate().
-		@see _beginUpdate for more details.
-		@param zorder The zorder of the viewport to update.
-		@param updateStatistics Whether you want to update statistics or not.
-		*/
-		virtual void _updateViewport(int zorder, bool updateStatistics = true);
-
-		/** Method for manual management of rendering - renders the given viewport (even if it is not autoupdated)
-		@remarks
-		This also fires preViewportUpdate and postViewportUpdate, and manages statistics
-		if needed. You should call it between _beginUpdate() and _endUpdate().
-		@see _beginUpdate for more details.
-		@param viewport The viewport you want to update, it must be bound to the rendertarget.
-		@param updateStatistics Whether you want to update statistics or not.
-		*/
-		virtual void _updateViewport(Viewport* viewport, bool updateStatistics = true);
 		
 		
 		/** Method for manual management of rendering - finishes statistics calculation 
 		/** Method for manual management of rendering - finishes statistics calculation 
 			and fires 'postRenderTargetUpdate'.
 			and fires 'postRenderTargetUpdate'.
@@ -323,10 +264,6 @@ namespace CamelotEngine {
 		// FSAA performed?
 		// FSAA performed?
 		UINT32 mFSAA;
 		UINT32 mFSAA;
 		String mFSAAHint;
 		String mFSAAHint;
-
-		typedef map<int, Viewport*>::type ViewportList;
-        /// List of viewports, map on Z-order
-        ViewportList mViewportList;
 			
 			
 		/// Internal implementation of update()
 		/// Internal implementation of update()
 		virtual void updateImpl();
 		virtual void updateImpl();

+ 0 - 2
CamelotRenderer/Include/CmRenderWindow.h

@@ -179,8 +179,6 @@ namespace CamelotEngine
         /** Indicates that this is the primary window. 
         /** Indicates that this is the primary window. 
         */
         */
         void _setPrimary() { mIsPrimary = true; }
         void _setPrimary() { mIsPrimary = true; }
-        
-        friend class Root;
     };
     };
 	/** @} */
 	/** @} */
 	/** @} */
 	/** @} */

+ 3 - 3
CamelotRenderer/Include/CmViewport.h

@@ -80,9 +80,9 @@ namespace CamelotEngine {
         */
         */
         Viewport(
         Viewport(
             RenderTarget* target,
             RenderTarget* target,
-            float left, float top,
-            float width, float height,
-            int ZOrder);
+            float left = 0.0f, float top = 0.0f,
+            float width = 1.0f, float height = 1.0f,
+            int ZOrder = 0);
 
 
         /** Default destructor.
         /** Default destructor.
         */
         */

+ 1 - 1
CamelotRenderer/Source/CmApplication.cpp

@@ -45,7 +45,7 @@ namespace CamelotEngine
 		mCamera->setNearClipDistance(5);
 		mCamera->setNearClipDistance(5);
 		mCamera->setAspectRatio(600.0f / 800.0f);
 		mCamera->setAspectRatio(600.0f / 800.0f);
 
 
-		mViewport = mRenderWindow->addViewport();
+		mViewport = new Viewport(mRenderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
 
 
 		/////////////////// HLSL SHADERS //////////////////////////
 		/////////////////// HLSL SHADERS //////////////////////////
 		//String fragShaderCode = "sampler2D diffuseMap;			\
 		//String fragShaderCode = "sampler2D diffuseMap;			\

+ 1 - 91
CamelotRenderer/Source/CmRenderTarget.cpp

@@ -45,12 +45,6 @@ namespace CamelotEngine {
 
 
     RenderTarget::~RenderTarget()
     RenderTarget::~RenderTarget()
     {
     {
-        // Delete viewports
-        for (ViewportList::iterator i = mViewportList.begin();
-            i != mViewportList.end(); ++i)
-        {
-            delete (*i).second;
-        }
     }
     }
 
 
     const String& RenderTarget::getName(void) const
     const String& RenderTarget::getName(void) const
@@ -93,95 +87,11 @@ namespace CamelotEngine {
 	{
 	{
 	}
 	}
 
 
-	void RenderTarget::_updateViewport(Viewport* viewport, bool updateStatistics)
-	{
-		assert(viewport->getTarget() == this &&
-				"RenderTarget::_updateViewport the requested viewport is "
-				"not bound to the rendertarget!");
-
-		viewport->update();
-	}
-
-	void RenderTarget::_updateViewport(int zorder, bool updateStatistics)
-	{
-		ViewportList::iterator it = mViewportList.find(zorder);
-        if (it != mViewportList.end())
-        {
-			_updateViewport((*it).second,updateStatistics);
-		}
-		else
-		{
-			CM_EXCEPT(ItemIdentityException,"No viewport with given zorder : "
-				+ toString(zorder));
-		}
-	}
-
-    Viewport* RenderTarget::addViewport(int ZOrder, float left, float top ,
-        float width , float height)
-    {
-        // Check no existing viewport with this Z-order
-        ViewportList::iterator it = mViewportList.find(ZOrder);
-
-        if (it != mViewportList.end())
-        {
-			StringUtil::StrStreamType str;
-			str << "Can't create another viewport for "
-				<< mName << " with Z-Order " << ZOrder
-				<< " because a viewport exists with this Z-Order already.";
-			CM_EXCEPT(InvalidParametersException, str.str());
-        }
-        // Add viewport to list
-        // Order based on Z-Order
-        Viewport* vp = new Viewport(this, left, top, width, height, ZOrder);
-
-        mViewportList.insert(ViewportList::value_type(ZOrder, vp));
-
-        return vp;
-    }
-	//-----------------------------------------------------------------------
-    void RenderTarget::removeViewport(int ZOrder)
-    {
-        ViewportList::iterator it = mViewportList.find(ZOrder);
-
-        if (it != mViewportList.end())
-        {
-            delete (*it).second;
-            mViewportList.erase(ZOrder);
-        }
-    }
-
-    void RenderTarget::removeAllViewports(void)
-    {
-        for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
-        {
-            delete (*it).second;
-        }
-
-        mViewportList.clear();
-
-    }
-
-    void RenderTarget::getCustomAttribute(const String& name, void* pData)
+	void RenderTarget::getCustomAttribute(const String& name, void* pData)
     {
     {
         CM_EXCEPT(InvalidParametersException, "Attribute not found.");
         CM_EXCEPT(InvalidParametersException, "Attribute not found.");
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    unsigned short RenderTarget::getNumViewports(void) const
-    {
-        return (unsigned short)mViewportList.size();
-
-    }
-    //-----------------------------------------------------------------------
-    Viewport* RenderTarget::getViewport(unsigned short index)
-    {
-        assert (index < mViewportList.size() && "Index out of bounds");
-
-        ViewportList::iterator i = mViewportList.begin();
-        while (index--)
-            ++i;
-        return i->second;
-    }
-    //-----------------------------------------------------------------------
     bool RenderTarget::isActive() const
     bool RenderTarget::isActive() const
     {
     {
         return mActive;
         return mActive;

+ 1 - 0
CamelotRenderer/TODO.txt

@@ -24,6 +24,7 @@ TODO FILES:
 
 
 Camera - MERGE WITH VIEWPORT
 Camera - MERGE WITH VIEWPORT
  - Position/rotation should be inherit from transform
  - Position/rotation should be inherit from transform
+ - Viewport needs to be updated when I call RenderTarget::setFullscreen/finishSwitchingFullscreen/updateWindowRect/windowMovedOrResized. Currently it's not
 
 
 Frustum
 Frustum
  - World space methods need to be updated. I still need them but they need to get their data from Transform
  - World space methods need to be updated. I still need them but they need to get their data from Transform