Răsfoiți Sursa

Refactored RenderTexture initialization and creation

Marko Pintera 13 ani în urmă
părinte
comite
771f1e8e6c
32 a modificat fișierele cu 180 adăugiri și 396 ștergeri
  1. 2 1
      CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h
  2. 1 1
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp
  3. 7 1
      CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp
  4. 0 2
      CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj
  5. 0 6
      CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj.filters
  6. 0 59
      CamelotD3D9Renderer/Include/CmD3D9MultiRenderTarget.h
  7. 1 1
      CamelotD3D9Renderer/Include/CmD3D9RenderTexture.h
  8. 1 1
      CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h
  9. 2 1
      CamelotD3D9Renderer/Include/CmD3D9TextureManager.h
  10. 0 146
      CamelotD3D9Renderer/Source/CmD3D9MultiRenderTarget.cpp
  11. 4 5
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  12. 1 1
      CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp
  13. 1 1
      CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp
  14. 7 1
      CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp
  15. 9 2
      CamelotGLRenderer/Include/CmGLTextureManager.h
  16. 6 1
      CamelotGLRenderer/Source/CmGLTextureManager.cpp
  17. 1 0
      CamelotRenderer/CamelotRenderer.vcxproj
  18. 3 0
      CamelotRenderer/CamelotRenderer.vcxproj.filters
  19. 32 0
      CamelotRenderer/Include/CmMultiRenderTexture.cpp
  20. 1 0
      CamelotRenderer/Include/CmPrerequisites.h
  21. 1 1
      CamelotRenderer/Include/CmRenderTarget.h
  22. 7 80
      CamelotRenderer/Include/CmRenderTexture.h
  23. 1 1
      CamelotRenderer/Include/CmTexture.h
  24. 15 1
      CamelotRenderer/Include/CmTextureManager.h
  25. 1 1
      CamelotRenderer/Source/CmApplication.cpp
  26. 1 1
      CamelotRenderer/Source/CmRenderTarget.cpp
  27. 44 72
      CamelotRenderer/Source/CmRenderTexture.cpp
  28. 1 1
      CamelotRenderer/Source/CmTexture.cpp
  29. 26 2
      CamelotRenderer/Source/CmTextureManager.cpp
  30. 1 1
      CamelotRenderer/Source/CmWindowEventUtilities.cpp
  31. 3 3
      CamelotRenderer/Source/Win32/CmOSCursorImpl.cpp
  32. 0 2
      CamelotRenderer/TODO.txt

+ 2 - 1
CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h

@@ -25,6 +25,7 @@ namespace CamelotEngine
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 
 	protected:		
-		Texture* createImpl();
+		Texture* createTextureImpl();
+		RenderTexture* createRenderTextureImpl();
 	};
 }

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -454,7 +454,7 @@ namespace CamelotEngine
 			return;
 		}
 
-		RenderWindow::getCustomAttribute_internal(name, pData);
+		RenderWindow::getCustomAttribute(name, pData);
 	}
 
 	void D3D11RenderWindow::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)

+ 7 - 1
CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp

@@ -1,5 +1,6 @@
 #include "CmD3D11TextureManager.h"
 #include "CmD3D11Texture.h"
+#include "CmD3D11RenderTexture.h"
 #include "CmD3D11Mappings.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11DepthStencilBuffer.h"
@@ -13,11 +14,16 @@ namespace CamelotEngine
 	D3D11TextureManager::~D3D11TextureManager()
 	{ }
 
-	Texture* D3D11TextureManager::createImpl()
+	Texture* D3D11TextureManager::createTextureImpl()
 	{
 		return new D3D11Texture(); 
 	}
 
+	RenderTexture* D3D11TextureManager::createRenderTextureImpl()
+	{
+		return new D3D11RenderTexture();
+	}
+
 	DepthStencilBufferPtr D3D11TextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 	{

+ 0 - 2
CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj

@@ -163,7 +163,6 @@
     <ClInclude Include="Include\CmD3D9HLSLProgramFactory.h" />
     <ClInclude Include="Include\CmD3D9HLSLProgramRTTI.h" />
     <ClInclude Include="Include\CmD3D9Mappings.h" />
-    <ClInclude Include="Include\CmD3D9MultiRenderTarget.h" />
     <ClInclude Include="Include\CmD3D9Prerequisites.h" />
     <ClInclude Include="Include\CmD3D9RenderSystem.h" />
     <ClInclude Include="Include\CmD3D9RenderSystemFactory.h" />
@@ -195,7 +194,6 @@
     <ClCompile Include="Source\CmD3D9HLSLProgram.cpp" />
     <ClCompile Include="Source\CmD3D9HLSLProgramFactory.cpp" />
     <ClCompile Include="Source\CmD3D9Mappings.cpp" />
-    <ClCompile Include="Source\CmD3D9MultiRenderTarget.cpp" />
     <ClCompile Include="Source\CmD3D9RenderSystem.cpp" />
     <ClCompile Include="Source\CmD3D9RenderSystemFactory.cpp" />
     <ClCompile Include="Source\CmD3D9RenderTexture.cpp" />

+ 0 - 6
CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj.filters

@@ -60,9 +60,6 @@
     <ClInclude Include="Include\CmD3D9Mappings.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Include\CmD3D9MultiRenderTarget.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmD3D9Prerequisites.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -152,9 +149,6 @@
     <ClCompile Include="Source\CmD3D9Mappings.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Source\CmD3D9MultiRenderTarget.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmD3D9RenderSystem.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>

+ 0 - 59
CamelotD3D9Renderer/Include/CmD3D9MultiRenderTarget.h

@@ -1,59 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9MULTIRENDERTARGET_H__
-#define __D3D9MULTIRENDERTARGET_H__
-
-#include "CmD3D9Prerequisites.h"
-#include "CmTexture.h"
-#include "CmRenderTexture.h"
-#include "CmException.h"
-#include "CmD3D9HardwarePixelBuffer.h"
-
-namespace CamelotEngine {
-	class CM_D3D9_EXPORT D3D9MultiRenderTarget : public MultiRenderTarget
-	{
-	public:
-		D3D9MultiRenderTarget(const String &name);
-		~D3D9MultiRenderTarget();
-
-        virtual void update(bool swapBuffers);
-
-		virtual void getCustomAttribute_internal( const String& name, void *pData );
-
-		bool requiresTextureFlipping() const { return false; }
-	private:
-		D3D9HardwarePixelBuffer *mRenderTargets[CM_MAX_MULTIPLE_RENDER_TARGETS];
-		virtual void bindSurfaceImpl(UINT32 attachment, RenderTexture *target);
-		virtual void unbindSurfaceImpl(UINT32 attachment);
-
-		/** Check surfaces and update RenderTarget extent */
-		void checkAndUpdate();
-	};
-};
-
-#endif

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderTexture.h

@@ -13,7 +13,7 @@ namespace CamelotEngine
 		virtual ~D3D9RenderTexture();
 
 		bool requiresTextureFlipping() const { return false; }
-		virtual void getCustomAttribute_internal(const String& name, void* pData);
+		virtual void getCustomAttribute(const String& name, void* pData);
 
 	protected:
 		IDirect3DSurface9* mColorSurface;

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -63,7 +63,7 @@ namespace CamelotEngine
 		D3D9Device*			getDevice			();
 		void				setDevice			(D3D9Device* device);
 
-		void				getCustomAttribute_internal	(const String& name, void* pData);
+		void				getCustomAttribute	(const String& name, void* pData);
 		
 		/** Overridden - see RenderTarget.
 		*/

+ 2 - 1
CamelotD3D9Renderer/Include/CmD3D9TextureManager.h

@@ -54,7 +54,8 @@ namespace CamelotEngine
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 
 	protected:		
-		Texture* createImpl();
+		Texture* createTextureImpl();
+		RenderTexture* createRenderTextureImpl();
 	};
 }
 #endif

+ 0 - 146
CamelotD3D9Renderer/Source/CmD3D9MultiRenderTarget.cpp

@@ -1,146 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#include "CmD3D9MultiRenderTarget.h"
-#include "CmD3D9HardwarePixelBuffer.h"
-#include "CmException.h"
-#include "CmBitwise.h"
-#include "CmD3D9RenderSystem.h"
-#include "CmD3D9Device.h"
-#include "CmD3D9DeviceManager.h"
-
-namespace CamelotEngine 
-{
-	D3D9MultiRenderTarget::D3D9MultiRenderTarget(const String &name):
-		MultiRenderTarget(name)
-	{
-		/// Clear targets
-		for(UINT32 x=0; x<CM_MAX_MULTIPLE_RENDER_TARGETS; ++x)
-		{
-			mRenderTargets[x] = 0;
-		}
-	}
-	D3D9MultiRenderTarget::~D3D9MultiRenderTarget()
-	{
-	}
-
-	void D3D9MultiRenderTarget::bindSurfaceImpl(UINT32 attachment, RenderTexture *target)
-	{
-		assert(attachment<CM_MAX_MULTIPLE_RENDER_TARGETS);
-		/// Get buffer and surface to bind to
-		D3D9HardwarePixelBuffer *buffer = 0;
-		target->getCustomAttribute_internal("BUFFER", &buffer);
-		assert(buffer);
-
-		/// Find first non-null target
-		int y;
-		for(y=0; y<CM_MAX_MULTIPLE_RENDER_TARGETS && !mRenderTargets[y]; ++y) ;
-		
-		if(y!=CM_MAX_MULTIPLE_RENDER_TARGETS)
-		{
-			/// If there is another target bound, compare sizes
-			if (mRenderTargets[y]->getWidth() != buffer->getWidth() ||
-				mRenderTargets[y]->getHeight() != buffer->getHeight())
-			{
-				CM_EXCEPT(InvalidParametersException, "MultiRenderTarget surfaces are not of same size");
-			}
-
-			if (!CamelotEngine::RenderSystem::instancePtr()->getCapabilities()->hasCapability(RSC_MRT_DIFFERENT_BIT_DEPTHS)
-				&& (PixelUtil::getNumElemBits(mRenderTargets[y]->getFormat()) != 
-				PixelUtil::getNumElemBits(buffer->getFormat())))
-			{
-				CM_EXCEPT(InvalidParametersException, "MultiRenderTarget surfaces are not of same bit depth and hardware requires it");
-			}
-		}
-
-		mRenderTargets[attachment] = buffer;
-		checkAndUpdate();
-	}
-
-	void D3D9MultiRenderTarget::unbindSurfaceImpl(UINT32 attachment)
-	{
-		assert(attachment<CM_MAX_MULTIPLE_RENDER_TARGETS);
-		mRenderTargets[attachment] = 0;
-		checkAndUpdate();
-	}
-
-    void D3D9MultiRenderTarget::update(bool swapBuffers)
-    {     
-		D3D9DeviceManager* deviceManager = D3D9RenderSystem::getDeviceManager();       	
-		D3D9Device* currRenderWindowDevice = deviceManager->getActiveRenderTargetDevice();
-
-		if (currRenderWindowDevice != NULL)
-		{
-			if (currRenderWindowDevice->isDeviceLost() == false)
-				MultiRenderTarget::update(swapBuffers);
-		}
-		else
-		{
-			for (UINT i=0; i < deviceManager->getDeviceCount(); ++i)
-			{
-				D3D9Device* device = deviceManager->getDevice(i);
-
-				if (device->isDeviceLost() == false)
-				{
-					deviceManager->setActiveRenderTargetDevice(device);
-					MultiRenderTarget::update(swapBuffers);
-					deviceManager->setActiveRenderTargetDevice(NULL);
-				}								
-			}
-		}		
-    }
-
-	void D3D9MultiRenderTarget::getCustomAttribute_internal(const String& name, void *pData)
-    {
-		if(name == "DDBACKBUFFER")
-        {
-            IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
-			/// Transfer surfaces
-			for(UINT32 x=0; x<CM_MAX_MULTIPLE_RENDER_TARGETS; ++x)
-			{
-				if(mRenderTargets[x] != NULL)								
-					pSurf[x] = mRenderTargets[x]->getSurface(D3D9RenderSystem::getActiveD3D9Device());			
-			}
-			return;
-        }
-	}
-
-	void D3D9MultiRenderTarget::checkAndUpdate()
-	{
-		if(mRenderTargets[0])
-		{
-			mWidth  = (unsigned int)mRenderTargets[0]->getWidth();
-			mHeight = (unsigned int)mRenderTargets[0]->getHeight();
-		}
-		else
-		{
-			mWidth = 0;
-			mHeight = 0;
-		}
-	}
-}
-

+ 4 - 5
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -44,7 +44,6 @@ THE SOFTWARE.
 #include "CmD3D9GpuProgramManager.h"
 #include "CmD3D9HLSLProgramFactory.h"
 #include "CmD3D9HardwareOcclusionQuery.h"
-#include "CmD3D9MultiRenderTarget.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9RenderWindowManager.h"
@@ -1075,14 +1074,14 @@ namespace CamelotEngine
 		// Retrieve render surfaces (up to CM_MAX_MULTIPLE_RENDER_TARGETS)
 		IDirect3DSurface9* pBack[CM_MAX_MULTIPLE_RENDER_TARGETS];
 		memset(pBack, 0, sizeof(pBack));
-		target->getCustomAttribute_internal( "DDBACKBUFFER", &pBack );
+		target->getCustomAttribute( "DDBACKBUFFER", &pBack );
 		if (!pBack[0])
 			return;
 
 		IDirect3DSurface9* pDepth = NULL;
 
 		if (!pDepth)
-			target->getCustomAttribute_internal( "D3DZBUFFER", &pDepth );
+			target->getCustomAttribute( "D3DZBUFFER", &pDepth );
 		
 		// Bind render targets
 		UINT32 count = mCurrentCapabilities->getNumMultiRenderTargets();
@@ -2089,7 +2088,7 @@ namespace CamelotEngine
 			D3DFMT_A16B16G16R16F, D3DFMT_R32F, D3DFMT_G32R32F, 
 			D3DFMT_A32B32G32R32F};
 		IDirect3DSurface9* bbSurf;
-		renderWindow->getCustomAttribute_internal("DDBACKBUFFER", &bbSurf);
+		renderWindow->getCustomAttribute("DDBACKBUFFER", &bbSurf);
 		D3DSURFACE_DESC bbSurfDesc;
 		bbSurf->GetDesc(&bbSurfDesc);
 
@@ -2424,7 +2423,7 @@ namespace CamelotEngine
 		bool anySupported = false;
 
 		IDirect3DSurface9* bbSurf;
-		renderWindow->getCustomAttribute_internal("DDBACKBUFFER", &bbSurf);
+		renderWindow->getCustomAttribute("DDBACKBUFFER", &bbSurf);
 		D3DSURFACE_DESC bbSurfDesc;
 		bbSurf->GetDesc(&bbSurfDesc);
 

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp

@@ -17,7 +17,7 @@ namespace CamelotEngine
 
 	}
 
-	void D3D9RenderTexture::getCustomAttribute_internal(const String& name, void* pData)
+	void D3D9RenderTexture::getCustomAttribute(const String& name, void* pData)
 	{
 		if(name == "DDBACKBUFFER")
 		{

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -688,7 +688,7 @@ namespace CamelotEngine
 			mDevice->present(this);		
 	}
 
-	void D3D9RenderWindow::getCustomAttribute_internal( const String& name, void* pData )
+	void D3D9RenderWindow::getCustomAttribute( const String& name, void* pData )
 	{
 		// Valid attributes and their equvalent native functions:
 		// D3DDEVICE			: getD3DDevice

+ 7 - 1
CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp

@@ -27,6 +27,7 @@ THE SOFTWARE.
 */
 #include "CmD3D9TextureManager.h"
 #include "CmD3D9Texture.h"
+#include "CmD3D9RenderTexture.h"
 #include "CmException.h"
 #include "CmD3D9Mappings.h"
 #include "CmD3D9RenderSystem.h"
@@ -44,11 +45,16 @@ namespace CamelotEngine
 
 	}
 
-    Texture* D3D9TextureManager::createImpl()
+    Texture* D3D9TextureManager::createTextureImpl()
     {
 		return new D3D9Texture();
     }
 
+	RenderTexture* D3D9TextureManager::createRenderTextureImpl()
+	{
+		return new D3D9RenderTexture();
+	}
+
 	DepthStencilBufferPtr D3D9TextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 	{

+ 9 - 2
CamelotGLRenderer/Include/CmGLTextureManager.h

@@ -58,8 +58,15 @@ namespace CamelotEngine {
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 
     protected:
-        /// @copydoc ResourceManager::createImpl
-        Texture* createImpl();
+        /**
+         * @copydoc ResourceManager::createTextureImpl
+         */
+        Texture* createTextureImpl();
+
+		/**
+         * @copydoc ResourceManager::createRenderTextureImpl
+         */
+		RenderTexture* createRenderTextureImpl();
 
 		/// Internal method to create a warning texture (bound when a texture unit is blank)
 		void createWarningTexture();

+ 6 - 1
CamelotGLRenderer/Source/CmGLTextureManager.cpp

@@ -45,10 +45,15 @@ namespace CamelotEngine {
 		glDeleteTextures(1, &mWarningTextureID);
     }
     //-----------------------------------------------------------------------------
-    Texture* GLTextureManager::createImpl()
+    Texture* GLTextureManager::createTextureImpl()
     {
         return new GLTexture(mGLSupport);
     }
+	//-----------------------------------------------------------------------------
+	RenderTexture* GLTextureManager::createRenderTextureImpl()
+	{
+		return new GLRenderTexture();
+	}
 	//----------------------------------------------------------------------------
 	DepthStencilBufferPtr GLTextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)

+ 1 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -264,6 +264,7 @@
     <ClInclude Include="Source\CmMeshRTTI.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="Include\CmMultiRenderTexture.cpp" />
     <ClCompile Include="Source\CamelotRenderer.cpp" />
     <ClCompile Include="Source\CmApplication.cpp" />
     <ClCompile Include="Source\CmBlendState.cpp" />

+ 3 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -520,5 +520,8 @@
     <ClCompile Include="Source\CmDepthStencilBuffer.cpp">
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
+    <ClCompile Include="Include\CmMultiRenderTexture.cpp">
+      <Filter>Header Files\RenderSystem</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 32 - 0
CamelotRenderer/Include/CmMultiRenderTexture.cpp

@@ -0,0 +1,32 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRenderTarget.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT MultiRenderTexture : public RenderTarget
+	{
+	public:
+		virtual ~MultiRenderTexture() {}
+
+		void setColorSurface(UINT32 surfaceIndex, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
+		void setDepthStencil(DepthStencilBufferPtr depthStencilbuffer);
+
+		TexturePtr getTexture(UINT32 index) const { return mTextures.at(index); }
+		DepthStencilBufferPtr getDepthStencilBuffer() const { return mDepthStencilBuffer; }
+
+		bool requiresTextureFlipping() const { return false; }
+
+	protected:
+		vector<TexturePtr>::type mTextures;
+		DepthStencilBufferPtr mDepthStencilBuffer;
+
+		MultiRenderTexture();
+
+		void initialize();
+
+		void createInternalResources();
+		virtual void createInternalResourcesImpl() = 0;
+	};
+}

+ 1 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -168,6 +168,7 @@ namespace CamelotEngine
 	typedef std::shared_ptr<BlendState> BlendStatePtr;
 	typedef std::shared_ptr<RenderWindow> RenderWindowPtr;
 	typedef std::shared_ptr<RenderTarget> RenderTargetPtr;
+	typedef std::shared_ptr<RenderTexture> RenderTexturePtr;
 	typedef std::shared_ptr<DepthStencilBuffer> DepthStencilBufferPtr;
 }
 

+ 1 - 1
CamelotRenderer/Include/CmRenderTarget.h

@@ -138,7 +138,7 @@ namespace CamelotEngine {
             @param
                 pData Pointer to memory of the right kind of structure to receive the info.
         */
-        virtual void getCustomAttribute_internal(const String& name, void* pData);
+        virtual void getCustomAttribute(const String& name, void* pData);
 
 		/** Sets the priority of this render target in relation to the others. 
         @remarks

+ 7 - 80
CamelotRenderer/Include/CmRenderTexture.h

@@ -30,6 +30,7 @@ THE SOFTWARE.
 
 #include "CmPrerequisites.h"
 #include "CmTexture.h"
+#include "CmDepthStencilBuffer.h"
 #include "CmRenderTarget.h"
 
 namespace CamelotEngine
@@ -45,13 +46,13 @@ namespace CamelotEngine
         RenderTargets rendering to different mipmaps, faces (for cubemaps) or slices (for 3D textures)
         of the same Texture.
     */
-    class CM_EXPORT RenderTexture: public RenderTarget
+    class CM_EXPORT RenderTexture : public RenderTarget
     {
 	public:
 		virtual ~RenderTexture() {}
 
-		void setBuffers(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer, 
-			UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
+		void setColorSurface(TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
+		void setDepthStencil(DepthStencilBufferPtr depthStencilbuffer);
 
 		TexturePtr getTexture() const { return mTexture; }
 		DepthStencilBufferPtr getDepthStencilBuffer() const { return mDepthStencilBuffer; }
@@ -71,87 +72,13 @@ namespace CamelotEngine
 
 		RenderTexture();
 
-		void initialize(TextureType textureType, UINT32 width, UINT32 height, 
-			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
-			bool createDepth = true, DepthStencilFormat depthStencilFormat = DFMT_D24S8);
-
-		void initialize(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer, 
-			UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
-
-		void createTextureBuffer();
-		void createDepthStencilBuffer();
-
 		void createInternalResources();
 		virtual void createInternalResourcesImpl() = 0;
-    };
-
-	/** This class represents a render target that renders to multiple RenderTextures
-		at once. Surfaces can be bound and unbound at will, as long as the following constraints
-		are met:
-		- All bound surfaces have the same size
-		- All bound surfaces have the same bit depth
-		- Target 0 is bound
-	*/
-	class CM_EXPORT MultiRenderTarget: public RenderTarget
-	{
-	public:
-		MultiRenderTarget(const String &name);
-
-		/** Bind a surface to a certain attachment point.
-            @param attachment	0 .. mCapabilities->getNumMultiRenderTargets()-1
-			@param target		RenderTexture to bind.
-
-			It does not bind the surface and fails with an exception (ERR_INVALIDPARAMS) if:
-			- Not all bound surfaces have the same size
-			- Not all bound surfaces have the same internal format 
-		*/
-
-		virtual void bindSurface(UINT32 attachment, RenderTexture *target)
-		{
-			for (UINT32 i = (UINT32)mBoundSurfaces.size(); i <= attachment; ++i)
-			{
-				mBoundSurfaces.push_back(0);
-			}
-			mBoundSurfaces[attachment] = target;
-
-			bindSurfaceImpl(attachment, target);
-		}
-
-		/** Unbind attachment.
-		*/
-		virtual void unbindSurface(UINT32 attachment)
-		{
-			if (attachment < (UINT32)mBoundSurfaces.size())
-				mBoundSurfaces[attachment] = 0;
-			unbindSurfaceImpl(attachment);
-		}
-
-		/** Error throwing implementation, it's not possible to write a MultiRenderTarget
-			to disk. 
-		*/
-		virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
-
-		/// Irrelevant implementation since cannot copy
-		PixelFormat suggestPixelFormat() const { return PF_UNKNOWN; }
-
-		typedef vector<RenderTexture*>::type BoundSufaceList;
-		/// Get a list of the surfaces which have been bound
-		const BoundSufaceList& getBoundSurfaceList() const { return mBoundSurfaces; }
-
-		/** Get a pointer to a bound surface */
-		RenderTexture* getBoundSurface(UINT32 index)
-		{
-			assert (index < mBoundSurfaces.size());
-			return mBoundSurfaces[index];
-		}
 
-	protected:
-		BoundSufaceList mBoundSurfaces;
+	private:
+		void throwIfBuffersDontMatch() const;
 
-		/// implementation of bindSurface, must be provided
-		virtual void bindSurfaceImpl(UINT32 attachment, RenderTexture *target) = 0;
-		/// implementation of unbindSurface, must be provided
-		virtual void unbindSurfaceImpl(UINT32 attachment) = 0;
+		virtual void copyContentsToMemory( const PixelData &dst, FrameBuffer buffer = FB_AUTO );
 	};
 	/** @} */
 	/** @} */

+ 1 - 1
CamelotRenderer/Include/CmTexture.h

@@ -142,7 +142,7 @@ namespace CamelotEngine {
 		 @param name The name of the attribute to retrieve
 		 @param pData Pointer to memory matching the type of data you want to retrieve.
 		*/
-		virtual void getCustomAttribute_internal(const String& name, void* pData);
+		virtual void getCustomAttribute(const String& name, void* pData);
 
 		/**
 		 * @brief	Sets raw texture pixels for the specified mip level and texture face. Pixel format

+ 15 - 1
CamelotRenderer/Include/CmTextureManager.h

@@ -59,7 +59,8 @@ namespace CamelotEngine {
     class CM_EXPORT TextureManager : public Module<TextureManager>
     {
 	protected:
-		virtual Texture* createImpl() = 0;
+		virtual Texture* createTextureImpl() = 0;
+		virtual RenderTexture* createRenderTextureImpl() = 0;
 
 		void destroy(Texture* texture);
 		virtual void destroy_internal(Texture* texture);
@@ -178,6 +179,19 @@ namespace CamelotEngine {
 		virtual DepthStencilBufferPtr createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 			UINT32 height, UINT32 fsaa, const String& fsaaHint) = 0;
 
+		/**
+		 * @brief	Creates a new RenderTexture and automatically generates a color surface
+		 * 			and (optionally) a depth/stencil surface
+		 */
+		virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
+			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
+			bool createDepth = true, DepthStencilFormat depthStencilFormat = DFMT_D24S8);
+
+		/**
+		 * @brief	Creates an empty RenderTexture. You need to assign color and depth/stencil buffers to
+		 * 			it manually before using it.
+		 */
+		virtual RenderTexturePtr createEmptyRenderTexture();
 
 		/** Returns whether this render system can natively support the precise texture 
 			format requested with the given usage options.

+ 1 - 1
CamelotRenderer/Source/CmApplication.cpp

@@ -141,7 +141,7 @@ namespace CamelotEngine
 		}
 
 		UINT64 windowId = 0;
-		mPrimaryRenderWindow->getCustomAttribute_internal("WINDOW", &windowId);
+		mPrimaryRenderWindow->getCustomAttribute("WINDOW", &windowId);
 
 		return windowId;
 	}

+ 1 - 1
CamelotRenderer/Source/CmRenderTarget.cpp

@@ -85,7 +85,7 @@ namespace CamelotEngine {
 	{
 	}
 
-	void RenderTarget::getCustomAttribute_internal(const String& name, void* pData)
+	void RenderTarget::getCustomAttribute(const String& name, void* pData)
     {
         CM_EXCEPT(InvalidParametersException, "Attribute not found.");
     }

+ 44 - 72
CamelotRenderer/Source/CmRenderTexture.cpp

@@ -40,37 +40,6 @@ namespace CamelotEngine
 
 	}
 
-	void RenderTexture::initialize(TextureType textureType, UINT32 width, UINT32 height, 
-		PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint,
-		bool createDepth, DepthStencilFormat depthStencilFormat)
-	{
-		mPriority = CM_REND_TO_TEX_RT_GROUP;
-		mWidth = width;
-		mHeight = height;
-		mType = textureType;
-		mFormat = format;
-		mColorDepth = CamelotEngine::PixelUtil::getNumElemBits(format);
-		mActive = true;
-		mHwGamma = hwGamma;
-		mFSAA = fsaa;
-		mFSAAHint = fsaaHint;
-		mDepthStencilFormat = depthStencilFormat;
-		mFace = 0;
-		mMipLevel = 0;
-
-		createTextureBuffer();
-
-		if(createDepth)
-			createDepthStencilBuffer();
-
-		createInternalResourcesImpl();
-	}
-
-	void RenderTexture::initialize(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
-	{
-		setBuffers(texture, depthStencilbuffer, face, numFaces, mipLevel);
-	}
-
 	void RenderTexture::createInternalResources()
 	{
 		if(mTexture->getTextureType() != TEX_TYPE_2D)
@@ -91,36 +60,14 @@ namespace CamelotEngine
 		createInternalResourcesImpl();
 	}
 
-	void RenderTexture::createTextureBuffer()
+	void RenderTexture::setColorSurface(TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
-		mTexture = TextureManager::instance().createTexture(mType, mWidth, mHeight, 0, mFormat, TU_RENDERTARGET, mHwGamma, mFSAA, mFSAAHint);
-	}
+		mTexture = texture;
 
-	void RenderTexture::createDepthStencilBuffer()
-	{
-		mDepthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(mDepthStencilFormat, mWidth, mHeight, mFSAA, mFSAAHint);
-	}
-
-	void RenderTexture::setBuffers(TexturePtr texture, DepthStencilBufferPtr depthStencilBuffer, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
-	{
-		assert(texture != nullptr);
-		assert(depthStencilBuffer != nullptr);
+		if(mTexture == nullptr)
+			return;
 
 		mPriority = CM_REND_TO_TEX_RT_GROUP;
-
-		if(texture->getWidth() != depthStencilBuffer->getWidth() ||
-			texture->getHeight() != depthStencilBuffer->getWidth() ||
-			texture->getFSAA() != depthStencilBuffer->getFsaa() ||
-			texture->getFSAAHint() != depthStencilBuffer->getFsaaHint())
-		{
-			String errorInfo = "\nWidth: " + toString(texture->getWidth()) + "/" + toString(depthStencilBuffer->getWidth());
-			errorInfo += "\nHeight: " + toString(texture->getHeight()) + "/" + toString(depthStencilBuffer->getHeight());
-			errorInfo += "\nFSAA: " + toString(texture->getFSAA()) + "/" + toString(depthStencilBuffer->getFsaa());
-			errorInfo += "\nFSAAHint: " + texture->getFSAAHint() + "/" + depthStencilBuffer->getFsaaHint();
-
-			CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
-		}
-
 		mWidth = texture->getWidth();
 		mHeight = texture->getWidth();
 		mColorDepth = CamelotEngine::PixelUtil::getNumElemBits(texture->getFormat());
@@ -130,28 +77,53 @@ namespace CamelotEngine
 		mFSAAHint = texture->getFSAAHint();
 		mType = texture->getTextureType();
 		mFormat = texture->getFormat();
-		mDepthStencilFormat = depthStencilBuffer->getFormat();
+		
 		mFace = face;
 		mNumFaces = face;
 		mMipLevel = mipLevel;
 
-		mTexture = texture;
+		throwIfBuffersDontMatch();
+
+		if(mDepthStencilBuffer != nullptr && mTexture != nullptr)
+			createInternalResourcesImpl();
+	}
+
+	void RenderTexture::setDepthStencil(DepthStencilBufferPtr depthStencilBuffer)
+	{
 		mDepthStencilBuffer = depthStencilBuffer;
 
-		createInternalResourcesImpl();
+		if(mDepthStencilBuffer == nullptr)
+			return;
+
+		mDepthStencilFormat = depthStencilBuffer->getFormat();
+
+		throwIfBuffersDontMatch();
+
+		if(mDepthStencilBuffer != nullptr && mTexture != nullptr)
+			createInternalResourcesImpl();
 	}
-	//-----------------------------------------------------------------------------
-	MultiRenderTarget::MultiRenderTarget(const String &name)
-    {
-        mPriority = CM_REND_TO_TEX_RT_GROUP;
-		mName = name;
-		/// Width and height is unknown with no targets attached
-		mWidth = mHeight = 0;
-    }
-	//-----------------------------------------------------------------------------
-	void MultiRenderTarget::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)
+
+	void RenderTexture::throwIfBuffersDontMatch() const
+	{
+		if(mTexture == nullptr || mDepthStencilBuffer == nullptr)
+			return;
+
+		if(mTexture->getWidth() != mDepthStencilBuffer->getWidth() ||
+			mTexture->getHeight() != mDepthStencilBuffer->getWidth() ||
+			mTexture->getFSAA() != mDepthStencilBuffer->getFsaa() ||
+			mTexture->getFSAAHint() != mDepthStencilBuffer->getFsaaHint())
+		{
+			String errorInfo = "\nWidth: " + toString(mTexture->getWidth()) + "/" + toString(mDepthStencilBuffer->getWidth());
+			errorInfo += "\nHeight: " + toString(mTexture->getHeight()) + "/" + toString(mDepthStencilBuffer->getHeight());
+			errorInfo += "\nFSAA: " + toString(mTexture->getFSAA()) + "/" + toString(mDepthStencilBuffer->getFsaa());
+			errorInfo += "\nFSAAHint: " + mTexture->getFSAAHint() + "/" + mDepthStencilBuffer->getFsaaHint();
+
+			CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
+		}
+	}
+
+	void RenderTexture::copyContentsToMemory( const PixelData &dst, FrameBuffer buffer /*= FB_AUTO */ )
 	{
-		CM_EXCEPT(InvalidParametersException, 
-					"Cannot get MultiRenderTargets pixels");
+		throw std::exception("The method or operation is not implemented.");
 	}
 }

+ 1 - 1
CamelotRenderer/Source/CmTexture.cpp

@@ -91,7 +91,7 @@ namespace CamelotEngine {
 		return getTextureType() == TEX_TYPE_CUBE_MAP ? 6 : 1;
 	}
 	//-------------------------------------------------------------------------
-	void Texture::getCustomAttribute_internal(const String& name, void* pData)
+	void Texture::getCustomAttribute(const String& name, void* pData)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 	}

+ 26 - 2
CamelotRenderer/Source/CmTextureManager.cpp

@@ -56,7 +56,7 @@ namespace CamelotEngine {
         PixelFormat format, int usage, bool hwGamma, 
 		UINT32 fsaa, const String& fsaaHint)
     {
-        TexturePtr ret = TexturePtr(createImpl(), boost::bind(&TextureManager::destroy, this, _1));
+        TexturePtr ret = TexturePtr(createTextureImpl(), boost::bind(&TextureManager::destroy, this, _1));
 		ret->initialize(texType, width, height, depth, static_cast<size_t>(numMipmaps), format, usage, hwGamma, fsaa, fsaaHint);
 
 		return ret;
@@ -64,10 +64,34 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------
 	TexturePtr TextureManager::createEmpty()
 	{
-		TexturePtr ret = TexturePtr(createImpl(), boost::bind(&TextureManager::destroy, this, _1));
+		TexturePtr ret = TexturePtr(createTextureImpl(), boost::bind(&TextureManager::destroy, this, _1));
 
 		return ret;
 	}
+	//-----------------------------------------------------------------------
+	RenderTexturePtr TextureManager::createRenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
+			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
+			bool createDepth, DepthStencilFormat depthStencilFormat)
+	{
+		TexturePtr texture = createTexture(textureType, width, height, 0, format, TU_RENDERTARGET, hwGamma, fsaa, fsaaHint);
+
+		DepthStencilBufferPtr depthStencilBuffer = nullptr;
+		if(createDepth)
+			depthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(depthStencilFormat, width, height, fsaa, fsaaHint);
+
+		RenderTexturePtr newRT = RenderTexturePtr(createRenderTextureImpl());
+		newRT->setColorSurface(texture, 0, 1, 0);
+		newRT->setDepthStencil(depthStencilBuffer);
+
+		return newRT;
+	}
+	//-----------------------------------------------------------------------
+	RenderTexturePtr TextureManager::createEmptyRenderTexture()
+	{
+		RenderTexturePtr newRT = RenderTexturePtr(createRenderTextureImpl());
+
+		return newRT;
+	}
     //-----------------------------------------------------------------------
 	bool TextureManager::isFormatSupported(TextureType ttype, PixelFormat format, int usage)
 	{

+ 1 - 1
CamelotRenderer/Source/CmWindowEventUtilities.cpp

@@ -262,7 +262,7 @@ void GLXProc( RenderWindow *win, const XEvent &event )
 	case ClientMessage:
 	{
 		::Atom atom;
-		win->getCustomAttribute_internal("ATOM", &atom);
+		win->getCustomAttribute("ATOM", &atom);
 		if(event.xclient.format == 32 && event.xclient.data.l[0] == (long)atom)
 		{	//Window closed by window manager
 			//Send message first, to allow app chance to unregister things that need done before

+ 3 - 3
CamelotRenderer/Source/Win32/CmOSCursorImpl.cpp

@@ -11,7 +11,7 @@ namespace CamelotEngine
 
 		RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
 		HWND hwnd;
-		primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
+		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 
 		ScreenToClient(hwnd, &screenPos);
 
@@ -28,7 +28,7 @@ namespace CamelotEngine
 
 		RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
 		HWND hwnd;
-		primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
+		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 
 		ClientToScreen(hwnd, &screenPos);
 
@@ -43,7 +43,7 @@ namespace CamelotEngine
 
 		RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
 		HWND hwnd;
-		primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
+		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 
 		// Clip cursor to the window
 		if( GetWindowRect(hwnd, &clipWindowRect))

+ 0 - 2
CamelotRenderer/TODO.txt

@@ -18,10 +18,8 @@
 
 /////
 
-Make separate DepthStencilBuffer object for OpenGL and assign it in GLRenderTexture & GLFrameBufferObject. Right now a new one is created or taken from a pool
 Add support for MultiRenderTexture
 Enhance TextureManager so it creates RenderTextures and MultiRenderTextures
-Create DX9 and OpenGL RenderTextures
 
 waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
 Drop OpenGL support for low level shaders? (See if cg can translate to GLSL)