Răsfoiți Sursa

Added DX11RenderTexture

Marko Pintera 13 ani în urmă
părinte
comite
3e20948845

+ 0 - 1
CamelotD3D11RenderSystem/Include/CmD3D11Prerequisites.h

@@ -43,7 +43,6 @@ namespace CamelotEngine
 	class D3D11VertexDeclaration;
 	class D3D11Device;
 	class D3D11HardwareBuffer;
-	class D3D11HardwarePixelBuffer;
 	class D3D11GpuVertexProgram;
 	class D3D11GpuFragmentProgram;
 	class D3D11GpuGeometryProgram;

+ 29 - 14
CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h

@@ -1,23 +1,38 @@
 #pragma once
 
 #include "CmD3D11Prerequisites.h"
+#include "CmTexture.h"
 #include "CmRenderTexture.h"
 
 namespace CamelotEngine
 {
-	class D3D11RenderTexture : public RenderTexture
-	{
-		D3D11Device& mDevice;
-		ID3D11RenderTargetView* mRenderTargetView;
-		ID3D11DepthStencilView* mDepthStencilView;
-	public:
-		D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device& device);
-		virtual ~D3D11RenderTexture();
-
-		void rebind(D3D11HardwarePixelBuffer *buffer);
-
-		virtual void getCustomAttribute(const String& name, void *pData);
-
-		bool requiresTextureFlipping() const { return false; }
+	class D3D11RenderTexture : public RenderTexture
+	{
+	public:
+		D3D11RenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
+			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
+			bool createDepth = true, UINT32 depthBits = 32);
+		D3D11RenderTexture(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer);
+		virtual ~D3D11RenderTexture();
+
+		void setBuffers(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer);
+
+		TexturePtr getTexture() const { return mTexture; }
+		DepthStencilBufferPtr getDepthStencilBuffer() const { return mDepthStencilBuffer; }
+
+		bool requiresTextureFlipping() const { return false; }
+
+	protected:
+		TextureType mType;
+		PixelFormat mFormat;
+		UINT32 mDepthBits;
+
+		TexturePtr mTexture;
+		DepthStencilBufferPtr mDepthStencilBuffer;
+		ID3D11RenderTargetView* mRenderTargetView;
+
+		void createTextureBuffer();
+		void createDepthStencilBuffer();
+		void createResourceView();
 	};
 }

+ 1 - 0
CamelotD3D11RenderSystem/Include/CmD3D11Texture.h

@@ -11,6 +11,7 @@ namespace CamelotEngine
 		~D3D11Texture();
 
 		ID3D11Resource* getDX11Resource() const { return mTex; }
+		const D3D11_SHADER_RESOURCE_VIEW_DESC& getSRVDesc() const { return mSRVDesc; }
 	protected:
 		friend class D3D11TextureManager;
 

+ 152 - 0
CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp

@@ -1,6 +1,158 @@
 #include "CmD3D11RenderTexture.h"
+#include "CmDepthStencilBuffer.h"
+#include "CmD3D11RenderSystem.h"
+#include "CmD3D11Device.h"
+#include "CmD3D11Texture.h"
+#include "CmD3D11Mappings.h"
+#include "CmTextureManager.h"
+#include "CmException.h"
 
 namespace CamelotEngine
 {
+	D3D11RenderTexture::D3D11RenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
+		PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint,
+		bool createDepth, UINT32 depthBits)
+		:mRenderTargetView(nullptr)
+	{
+		mPriority = CM_REND_TO_TEX_RT_GROUP;
 
+		if(textureType != TEX_TYPE_2D)
+			CM_EXCEPT(NotImplementedException, "Render textures are currently only implemented for 2D surfaces.");
+
+		mWidth = width;
+		mHeight = height;
+		mType = textureType;
+		mFormat = format;
+		mColorDepth = CamelotEngine::PixelUtil::getNumElemBits(format);
+		mActive = true;
+		mHwGamma = hwGamma;
+		mFSAA = fsaa;
+		mFSAAHint = fsaaHint;
+		mDepthBits = depthBits;
+
+		createTextureBuffer();
+
+		if(createDepth)
+			createDepthStencilBuffer();
+
+		createResourceView();
+	}
+
+	D3D11RenderTexture::D3D11RenderTexture(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer)
+		:mRenderTargetView(nullptr)
+	{
+		setBuffers(texture, depthStencilbuffer);
+	}
+
+	void D3D11RenderTexture::setBuffers(TexturePtr texture, DepthStencilBufferPtr depthStencilBuffer)
+	{
+		assert(texture != nullptr);
+		assert(depthStencilBuffer != nullptr);
+
+		SAFE_RELEASE(mRenderTargetView)
+		mPriority = CM_REND_TO_TEX_RT_GROUP;
+
+		if(texture->getTextureType() != TEX_TYPE_2D)
+			CM_EXCEPT(NotImplementedException, "Render textures are currently only implemented for 2D surfaces.");
+
+		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());
+		mActive = true;
+		mHwGamma = texture->isHardwareGammaEnabled();
+		mFSAA = texture->getFSAA();
+		mFSAAHint = texture->getFSAAHint();
+		mType = texture->getTextureType();
+		mFormat = texture->getFormat();
+		mDepthBits = depthStencilBuffer->getBitDepth();
+
+		mTexture = texture;
+		mDepthStencilBuffer = depthStencilBuffer;
+
+		createResourceView();
+	}
+
+	D3D11RenderTexture::~D3D11RenderTexture()
+	{
+		SAFE_RELEASE(mRenderTargetView);
+	}
+
+	void D3D11RenderTexture::createTextureBuffer()
+	{
+		mTexture = TextureManager::instance().createTexture(mType, mWidth, mHeight, 0, mFormat, TU_RENDERTARGET, mHwGamma, mFSAA, mFSAAHint);
+	}
+
+	void D3D11RenderTexture::createDepthStencilBuffer()
+	{
+		mDepthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(mDepthBits, mWidth, mHeight, mFSAA, mFSAAHint);
+	}
+
+	void D3D11RenderTexture::createResourceView()
+	{
+		D3D11_RENDER_TARGET_VIEW_DESC RTVDesc;
+		ZeroMemory(&RTVDesc, sizeof(RTVDesc));
+
+		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(mTexture.get());
+
+		D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = d3d11Texture->getSRVDesc();
+		RTVDesc.Format = SRVDesc.Format;
+
+		switch(SRVDesc.ViewDimension)
+		{
+		case D3D11_SRV_DIMENSION_BUFFER:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE1D:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURECUBE:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
+			RTVDesc.Texture2DArray.FirstArraySlice = 0;
+			RTVDesc.Texture2DArray.ArraySize = 6;
+			RTVDesc.Texture2DArray.MipSlice = 0;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2D:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2DMS:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE3D:
+			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
+			break;
+		default:
+			assert(false);
+		}
+
+		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
+		HRESULT hr = device.getD3D11Device()->CreateRenderTargetView(d3d11Texture->getDX11Resource(), &RTVDesc, &mRenderTargetView);
+
+		if (FAILED(hr) || device.hasError())
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Error creating Render Target View\nError Description:" + errorDescription);
+		}
+	}
 }

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -128,7 +128,7 @@ namespace CamelotEngine
 
 		mName = name;
 		mIsFullScreen = fullScreen;
-		mColourDepth = colourDepth;
+		mColorDepth = colourDepth;
 		mWidth = mHeight = mLeft = mTop = 0;
 
 		mActive = true;

+ 108 - 47
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -24,7 +24,7 @@ namespace CamelotEngine
 		, mLockedForReading(false)
 		, mStaticBuffer(nullptr)
 	{
-		ZeroMemory(&mSRVDesc, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
+
 	}
 
 	D3D11Texture::~D3D11Texture()
@@ -152,25 +152,36 @@ namespace CamelotEngine
 	void D3D11Texture::_create1DTex()
 	{
 		// We must have those defined here
-		assert(mWidth > 0 || mHeight > 0);
+		assert(mWidth > 0);
 
 		// Determine which D3D11 pixel format we'll use
 		HRESULT hr;
 		DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(mFormat));
 
-		// Determine total number of mipmaps including main one (d3d11 convention)
-		UINT32 numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > mWidth) ? 0 : mNumMipmaps + 1;
-
 		D3D11_TEXTURE1D_DESC desc;
 		desc.Width			= static_cast<UINT32>(mWidth);
-		desc.MipLevels		= numMips;
 		desc.ArraySize		= 1;
 		desc.Format			= d3dPF;
-		desc.Usage			= D3D11Mappings::_getUsage(mUsage);
-		desc.BindFlags		= D3D11_BIND_SHADER_RESOURCE;
-		desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
 		desc.MiscFlags		= 0;
 
+		if((mUsage & TU_RENDERTARGET) != 0)
+		{
+			desc.Usage			= D3D11_USAGE_DEFAULT;
+			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
+			desc.MipLevels		= 1;
+		}
+		else
+		{
+			desc.Usage			= D3D11Mappings::_getUsage(mUsage);
+			desc.BindFlags		= D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
+
+			// Determine total number of mipmaps including main one (d3d11 convention)
+			UINT32 numMips		= (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > mWidth) ? 0 : mNumMipmaps + 1;
+			desc.MipLevels		= numMips;
+		}
+
 		// Create the texture
 		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
 		hr = device.getD3D11Device()->CreateTexture1D(&desc, nullptr, &m1DTex);
@@ -192,13 +203,13 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Can't get base texture\nError Description:" + errorDescription);
 		}
 
-		// Create texture view
 		m1DTex->GetDesc(&desc);
 		mNumMipmaps = desc.MipLevels - 1;
 
-		ZeroMemory( &mSRVDesc, sizeof(mSRVDesc) );
+		// Create texture view
+		ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
 		mSRVDesc.Format = desc.Format;
-		mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
+		mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; 
 		mSRVDesc.Texture1D.MipLevels = desc.MipLevels;
 		hr = device.getD3D11Device()->CreateShaderResourceView(m1DTex, &mSRVDesc, &mShaderResourceView);
 
@@ -218,29 +229,50 @@ namespace CamelotEngine
 		HRESULT hr;
 		DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(mFormat));
 
-		// Determine total number of mipmaps including main one (d3d11 convention)
-		UINT32 numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > mWidth) ? 0 : mNumMipmaps + 1;
-
-		DXGI_SAMPLE_DESC sampleDesc;
-		sampleDesc.Count = 1;
-		sampleDesc.Quality = 0;
-
 		D3D11_TEXTURE2D_DESC desc;
 		desc.Width			= static_cast<UINT32>(mWidth);
 		desc.Height			= static_cast<UINT32>(mHeight);
-		desc.MipLevels		= numMips;
 		desc.ArraySize		= 1;
 		desc.Format			= d3dPF;
-		desc.SampleDesc		= sampleDesc;
-		desc.Usage			= D3D11Mappings::_getUsage(mUsage);
-		desc.BindFlags		= D3D11_BIND_SHADER_RESOURCE;
-		desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
 		desc.MiscFlags		= 0;
 
-        if (this->getTextureType() == TEX_TYPE_CUBE_MAP)
+		if((mUsage & TU_RENDERTARGET) != 0)
+		{
+			desc.Usage			= D3D11_USAGE_DEFAULT;
+			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
+			desc.MipLevels		= 1;
+
+			DXGI_SAMPLE_DESC sampleDesc;
+			D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
+			rs->determineFSAASettings(mFSAA, mFSAAHint, d3dPF, &sampleDesc);
+			desc.SampleDesc		= sampleDesc;
+
+			if(getTextureType() == TEX_TYPE_CUBE_MAP)
+			{
+				CM_EXCEPT(NotImplementedException, "Cube map not yet supported as a render target."); // TODO: Will be once I add proper texture array support
+			}
+		}
+		else
+		{
+			desc.Usage			= D3D11Mappings::_getUsage(mUsage);
+			desc.BindFlags		= D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
+
+			// Determine total number of mipmaps including main one (d3d11 convention)
+			UINT32 numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > mWidth) ? 0 : mNumMipmaps + 1;
+			desc.MipLevels		= numMips;
+
+			DXGI_SAMPLE_DESC sampleDesc;
+			sampleDesc.Count	= 1;
+			sampleDesc.Quality	= 0;
+			desc.SampleDesc		= sampleDesc;
+		}
+
+        if (getTextureType() == TEX_TYPE_CUBE_MAP)
         {
-                desc.MiscFlags          |= D3D11_RESOURCE_MISC_TEXTURECUBE;
-                desc.ArraySize          = 6;
+            desc.MiscFlags      |= D3D11_RESOURCE_MISC_TEXTURECUBE;
+            desc.ArraySize       = 6;
         }
 
 		// Create the texture
@@ -264,26 +296,44 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Can't get base texture\nError Description:" + errorDescription);
 		}
 
-		// Create texture view
 		m2DTex->GetDesc(&desc);
 		mNumMipmaps = desc.MipLevels - 1;
 
+		// Create shader texture view
 		ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
 		mSRVDesc.Format = desc.Format;
 
-		switch(getTextureType())
+		if((mUsage & TU_RENDERTARGET) != 0)
 		{
-		case TEX_TYPE_CUBE_MAP:
-			mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
-			mSRVDesc.TextureCube.MipLevels = desc.MipLevels;
-			mSRVDesc.TextureCube.MostDetailedMip = 0;
-			break;
-
-		case TEX_TYPE_2D:
-			mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
-			mSRVDesc.Texture2D.MostDetailedMip = 0;
-			mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
-			break;
+			if(mFSAA > 0)
+			{
+				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
+				mSRVDesc.Texture2D.MostDetailedMip = 0;
+				mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+			}
+			else
+			{
+				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+				mSRVDesc.Texture2D.MostDetailedMip = 0;
+				mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+			}
+		}
+		else
+		{
+			switch(getTextureType())
+			{
+			case TEX_TYPE_CUBE_MAP:
+				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
+				mSRVDesc.TextureCube.MipLevels = desc.MipLevels;
+				mSRVDesc.TextureCube.MostDetailedMip = 0;
+				break;
+
+			case TEX_TYPE_2D:
+				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+				mSRVDesc.Texture2D.MostDetailedMip = 0;
+				mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+				break;
+			}
 		}
 
 		hr = device.getD3D11Device()->CreateShaderResourceView(m2DTex, &mSRVDesc, &mShaderResourceView);
@@ -304,20 +354,31 @@ namespace CamelotEngine
 		HRESULT hr;
 		DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(mFormat));
 
-		// Determine total number of mipmaps including main one (d3d11 convention)
-		UINT numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > std::max(std::max(mWidth, mHeight), mDepth)) ? 0 : mNumMipmaps + 1;
-
 		D3D11_TEXTURE3D_DESC desc;
 		desc.Width			= static_cast<UINT32>(mWidth);
 		desc.Height			= static_cast<UINT32>(mHeight);
 		desc.Depth			= static_cast<UINT32>(mDepth);
-		desc.MipLevels		= numMips;
 		desc.Format			= d3dPF;
-		desc.Usage			= D3D11Mappings::_getUsage(mUsage);
-		desc.BindFlags		= D3D11_BIND_SHADER_RESOURCE;
-		desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
 		desc.MiscFlags		= 0;
 
+		if((mUsage & TU_RENDERTARGET) != 0)
+		{
+			desc.Usage			= D3D11_USAGE_DEFAULT;
+			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
+			desc.MipLevels		= 1;
+		}
+		else
+		{
+			desc.Usage			= D3D11Mappings::_getUsage(mUsage);
+			desc.BindFlags		= D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
+
+			// Determine total number of mipmaps including main one (d3d11 convention)
+			UINT numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > std::max(std::max(mWidth, mHeight), mDepth)) ? 0 : mNumMipmaps + 1;
+			desc.MipLevels		= numMips;
+		}
+
 		// Create the texture
 		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
 		hr = device.getD3D11Device()->CreateTexture3D(&desc, nullptr, &m3DTex);

+ 1 - 0
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -119,6 +119,7 @@ namespace CamelotEngine
 		unsigned int				mVSyncInterval;		
 		bool						mUseNVPerfHUD;			// Use NV Perf HUD.
 		DWORD						mStyle;					// Window style currently used for this window.
+		bool						mIsDepthBuffered;
 		// Desired width / height after resizing
 		unsigned int mDesiredWidth;
 		unsigned int mDesiredHeight;

+ 3 - 0
CamelotD3D9Renderer/Include/CmD3D9Texture.h

@@ -212,6 +212,9 @@ namespace CamelotEngine {
 		/// Override needed to deal with FSAA
 		void swapBuffers(bool waitForVSync = true);
 
+	protected:
+		D3D9HardwarePixelBuffer* mBuffer;
+
 	};
 
 }

+ 4 - 4
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -37,7 +37,7 @@ THE SOFTWARE.
 namespace CamelotEngine
 {
 	D3D9RenderWindow::D3D9RenderWindow(HINSTANCE instance)
-        : mInstance(instance)        
+        : mInstance(instance), mIsDepthBuffered(true)  
 	{
 		mDevice = NULL;
 		mIsFullScreen = false;		
@@ -329,7 +329,7 @@ namespace CamelotEngine
 		mName = name;
 		mIsDepthBuffered = depthBuffer;
 		mIsFullScreen = fullScreen;
-		mColourDepth = colourDepth;
+		mColorDepth = colourDepth;
 									
 		mActive = true;
 		mClosed = false;
@@ -560,10 +560,10 @@ namespace CamelotEngine
 		}
 
 		presentParams->BackBufferFormat		= D3DFMT_R5G6B5;
-		if( mColourDepth > 16 )
+		if( mColorDepth > 16 )
 			presentParams->BackBufferFormat = D3DFMT_X8R8G8B8;
 
-		if (mColourDepth > 16 )
+		if (mColorDepth > 16 )
 		{
 			// Try to create a 32-bit depth, 8-bit stencil
 			if( FAILED( pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -1218,7 +1218,7 @@ namespace CamelotEngine
 	D3D9RenderTexture::D3D9RenderTexture(const String &name, 
 		D3D9HardwarePixelBuffer *buffer, 
 		bool writeGamma, 
-		UINT32 fsaa) : RenderTexture(buffer, 0)
+		UINT32 fsaa) : mBuffer(buffer)
 	{
 		mName = name;
 		mHwGamma = writeGamma;

+ 1 - 1
CamelotGLRenderer/Include/CmGLPixelFormat.h

@@ -70,7 +70,7 @@ namespace CamelotEngine {
 			without losing precision.
 			@remarks It is valid for this function to always return PF_A8R8G8B8.
 		*/
-		static PixelFormat getClosestOGREFormat(GLenum fmt);
+		static PixelFormat getClosestEngineFormat(GLenum fmt);
 	
 		/** Returns the maximum number of Mipmaps that can be generated until we reach
 			the mininum format possible. This does not count the base level.

+ 0 - 2
CamelotGLRenderer/Include/CmGLTexture.h

@@ -74,8 +74,6 @@ namespace CamelotEngine {
 		*/
 		void createSurfaceList();
 
-		void createRenderTexture();
-
 		/** Return hardware pixel buffer for a surface. This buffer can then
 			be used to copy data from and to a particular level of the texture.
 			@param face 	Face number, in case of a cubemap texture. Must be 0

+ 2 - 2
CamelotGLRenderer/Source/CmGLHardwarePixelBuffer.cpp

@@ -224,7 +224,7 @@ GLTextureBuffer::GLTextureBuffer(const String &baseName, GLenum target, GLuint i
 	// Get format
 	glGetTexLevelParameteriv(mFaceTarget, level, GL_TEXTURE_INTERNAL_FORMAT, &value);
 	mGLInternalFormat = value;
-	mFormat = GLPixelUtil::getClosestOGREFormat(value);
+	mFormat = GLPixelUtil::getClosestEngineFormat(value);
 	
 	// Default
 	mRowPitch = mWidth;
@@ -784,7 +784,7 @@ void GLTextureBuffer::blitFromMemory(const PixelData &src_orig, const Box &dstBo
 //********* GLRenderBuffer
 //----------------------------------------------------------------------------- 
 GLRenderBuffer::GLRenderBuffer(GLenum format, UINT32 width, UINT32 height, GLsizei numSamples):
-    GLHardwarePixelBuffer(width, height, 1, GLPixelUtil::getClosestOGREFormat(format),HBU_WRITE_ONLY),
+    GLHardwarePixelBuffer(width, height, 1, GLPixelUtil::getClosestEngineFormat(format),HBU_WRITE_ONLY),
     mRenderbufferID(0)
 {
     mGLInternalFormat = format;

+ 1 - 1
CamelotGLRenderer/Source/CmGLPixelFormat.cpp

@@ -277,7 +277,7 @@ namespace CamelotEngine  {
     }
 	
 	//----------------------------------------------------------------------------- 	
-	PixelFormat GLPixelUtil::getClosestOGREFormat(GLenum fmt)
+	PixelFormat GLPixelUtil::getClosestEngineFormat(GLenum fmt)
 	{
 		switch(fmt) 
 		{

+ 1 - 1
CamelotGLRenderer/Source/CmGLRenderTexture.cpp

@@ -33,7 +33,7 @@ THE SOFTWARE.
 namespace CamelotEngine 
 {
 	GLRenderTexture::GLRenderTexture(GLRTTManager* manager, const String &name, const GLSurfaceDesc &target, bool writeGamma, UINT32 fsaa):
-		RenderTexture(target.buffer, target.zoffset), mFB(manager, fsaa)
+		mFB(manager, fsaa)
 	{
 		mName = name;
 		mHwGamma = writeGamma;

+ 1 - 16
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -74,11 +74,6 @@ namespace CamelotEngine {
 	{
 		createInternalResources();
 
-		if( mUsage & TU_RENDERTARGET )
-		{
-			createRenderTexture();
-		}
-
 		Resource::initialize_internal();
 	}
 
@@ -278,22 +273,12 @@ namespace CamelotEngine {
 		// Get final internal format
 		mFormat = getBuffer(0,0)->getFormat();
 	}
-	
-    void GLTexture::createRenderTexture(void)
-    {
-        // Create the GL texture
-		// This already does everything neccessary
-        createInternalResources();
-    }
-	//*************************************************************************
-    
+	//--------------------------------------------------------------------------------------------
     void GLTexture::freeInternalResourcesImpl()
     {
 		mSurfaceList.clear();
         glDeleteTextures( 1, &mTextureID );
     }
-
-	
 	//---------------------------------------------------------------------------------------------
 	void GLTexture::createSurfaceList()
 	{

+ 11 - 15
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -81,8 +81,7 @@ namespace CamelotEngine {
 		mIsFullScreen = fullScreen;
 		mClosed = false;		
 		mDisplayFrequency = 0;
-		mIsDepthBuffered = true;
-		mColourDepth = mIsFullScreen? 32 : GetDeviceCaps(GetDC(0), BITSPIXEL);
+		mColorDepth = mIsFullScreen? 32 : GetDeviceCaps(GetDC(0), BITSPIXEL);
 		int left = -1; // Defaults to screen center
 		int top = -1; // Defaults to screen center
 		HWND parent = 0;
@@ -110,9 +109,6 @@ namespace CamelotEngine {
 			if ((opt = miscParams->find("top")) != end)
 				top = parseInt(opt->second);
 
-			if ((opt = miscParams->find("depthBuffer")) != end)
-				mIsDepthBuffered = parseBool(opt->second);
-
 			if ((opt = miscParams->find("vsync")) != end)
 				vsync = parseBool(opt->second);
 
@@ -162,12 +158,12 @@ namespace CamelotEngine {
 				mDisplayFrequency = parseUnsignedInt(opt->second);
 			if ((opt = miscParams->find("colourDepth")) != end)
 			{
-				mColourDepth = parseUnsignedInt(opt->second);
+				mColorDepth = parseUnsignedInt(opt->second);
 				if (!mIsFullScreen)
 				{
 					// make sure we don't exceed desktop colour depth
-					if ((int)mColourDepth > GetDeviceCaps(GetDC(0), BITSPIXEL))
-						mColourDepth = GetDeviceCaps(GetDC(0), BITSPIXEL);
+					if ((int)mColorDepth > GetDeviceCaps(GetDC(0), BITSPIXEL))
+						mColorDepth = GetDeviceCaps(GetDC(0), BITSPIXEL);
 				}
 			}
 
@@ -313,7 +309,7 @@ namespace CamelotEngine {
 
 				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 				displayDeviceMode.dmSize = sizeof(DEVMODE);
-				displayDeviceMode.dmBitsPerPel = mColourDepth;
+				displayDeviceMode.dmBitsPerPel = mColorDepth;
 				displayDeviceMode.dmPelsWidth = mWidth;
 				displayDeviceMode.dmPelsHeight = mHeight;
 				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
@@ -362,14 +358,14 @@ namespace CamelotEngine {
 		{
 			int testFsaa = mFSAA;
 			bool testHwGamma = hwGamma;
-			bool formatOk = mGLSupport.selectPixelFormat(mHDC, mColourDepth, testFsaa, testHwGamma);
+			bool formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 			if (!formatOk)
 			{
 				if (mFSAA > 0)
 				{
 					// try without FSAA
 					testFsaa = 0;
-					formatOk = mGLSupport.selectPixelFormat(mHDC, mColourDepth, testFsaa, testHwGamma);
+					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 				}
 
 				if (!formatOk && hwGamma)
@@ -377,7 +373,7 @@ namespace CamelotEngine {
 					// try without sRGB
 					testHwGamma = false;
 					testFsaa = mFSAA;
-					formatOk = mGLSupport.selectPixelFormat(mHDC, mColourDepth, testFsaa, testHwGamma);
+					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 				}
 
 				if (!formatOk && hwGamma && (mFSAA > 0))
@@ -385,7 +381,7 @@ namespace CamelotEngine {
 					// try without both
 					testHwGamma = false;
 					testFsaa = 0;
-					formatOk = mGLSupport.selectPixelFormat(mHDC, mColourDepth, testFsaa, testHwGamma);
+					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 				}
 
 				if (!formatOk)
@@ -483,7 +479,7 @@ namespace CamelotEngine {
 
 				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 				displayDeviceMode.dmSize = sizeof(DEVMODE);
-				displayDeviceMode.dmBitsPerPel = mColourDepth;
+				displayDeviceMode.dmBitsPerPel = mColorDepth;
 				displayDeviceMode.dmPelsWidth = width;
 				displayDeviceMode.dmPelsHeight = height;
 				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
@@ -795,7 +791,7 @@ namespace CamelotEngine {
 
 				memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
 				displayDeviceMode.dmSize = sizeof(DEVMODE);
-				displayDeviceMode.dmBitsPerPel = mColourDepth;
+				displayDeviceMode.dmBitsPerPel = mColorDepth;
 				displayDeviceMode.dmPelsWidth = mWidth;
 				displayDeviceMode.dmPelsHeight = mHeight;
 				displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

+ 1 - 3
CamelotRenderer/Include/CmRenderTarget.h

@@ -239,11 +239,9 @@ namespace CamelotEngine {
 
         unsigned int mWidth;
         unsigned int mHeight;
-        unsigned int mColourDepth;
-        bool mIsDepthBuffered;
+        unsigned int mColorDepth;
 
         bool mActive;
-        bool mAutoUpdate;
 		// Hardware sRGB gamma conversion done on write?
 		bool mHwGamma;
 		// FSAA performed?

+ 1 - 8
CamelotRenderer/Include/CmRenderTexture.h

@@ -48,20 +48,13 @@ namespace CamelotEngine
     class CM_EXPORT RenderTexture: public RenderTarget
     {
     public:
-        RenderTexture(HardwarePixelBuffer *buffer, UINT32 zoffset);
+        RenderTexture();
         virtual ~RenderTexture();
 
 		virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
 		PixelFormat suggestPixelFormat() const;
 
-		/**
-		 * @brief	Sets the depth stencil buffer attached to this render target.
-		 */
-		//virtual void setDepthStencilBuffer(DepthStencilBufferPtr depthStencil) = 0;
-
 	protected:
-		HardwarePixelBuffer *mBuffer;
-		UINT32 mZOffset;
     };
 
 	/** This class represents a render target that renders to multiple RenderTextures

+ 3 - 3
CamelotRenderer/Include/CmTextureManager.h

@@ -111,7 +111,7 @@ namespace CamelotEngine {
 				if usage does not include TU_RENDERTARGET or if the device does
 				not support it.
         */
-        TexturePtr create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
+        TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
 			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
 			
@@ -157,11 +157,11 @@ namespace CamelotEngine {
 				if usage does not include TU_RENDERTARGET or if the device does
 				not support it.
         */
-        TexturePtr create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
+        TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int num_mips,
             PixelFormat format, int usage = TU_DEFAULT,
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK)
 		{
-			return create(texType, width, height, 1, 
+			return createTexture(texType, width, height, 1, 
 				num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 		}
 

+ 2 - 3
CamelotRenderer/Source/CmRenderTarget.cpp

@@ -36,7 +36,6 @@ namespace CamelotEngine {
     RenderTarget::RenderTarget()
 		:mPriority(CM_DEFAULT_RT_GROUP),
 		mActive(true),
-		mAutoUpdate(true),
 		mHwGamma(false), 
 		mFSAA(0)
     {
@@ -56,7 +55,7 @@ namespace CamelotEngine {
     {
         width = mWidth;
         height = mHeight;
-        colourDepth = mColourDepth;
+        colourDepth = mColorDepth;
     }
 
     unsigned int RenderTarget::getWidth(void) const
@@ -69,7 +68,7 @@ namespace CamelotEngine {
     }
     unsigned int RenderTarget::getColourDepth(void) const
     {
-        return mColourDepth;
+        return mColorDepth;
     }
 
     void RenderTarget::updateImpl(void)

+ 3 - 16
CamelotRenderer/Source/CmRenderTexture.cpp

@@ -34,14 +34,8 @@ namespace CamelotEngine
 {
 
     //-----------------------------------------------------------------------------
-	RenderTexture::RenderTexture(HardwarePixelBuffer *buffer, UINT32 zoffset):
-		mBuffer(buffer), mZOffset(zoffset)
+	RenderTexture::RenderTexture()
     {
-        mPriority = CM_REND_TO_TEX_RT_GROUP;
-		mWidth = static_cast<unsigned int>(mBuffer->getWidth());
-		mHeight = static_cast<unsigned int>(mBuffer->getHeight());
-        mColourDepth = static_cast<unsigned int>(
-			CamelotEngine::PixelUtil::getNumElemBits(mBuffer->getFormat()));
     }
     RenderTexture::~RenderTexture()
     {
@@ -50,19 +44,12 @@ namespace CamelotEngine
 
 	void RenderTexture::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)
     {
-		if (buffer == FB_AUTO) buffer = FB_FRONT;
-		if (buffer != FB_FRONT)
-		{
-			CM_EXCEPT(InvalidParametersException,
-						"Invalid buffer.");
-		}
-
-		mBuffer->blitToMemory(dst);
+		CM_EXCEPT(NotImplementedException, "Not implemented");
 	}
 	//---------------------------------------------------------------------
 	PixelFormat RenderTexture::suggestPixelFormat() const
 	{
-		return mBuffer->getFormat();
+		CM_EXCEPT(NotImplementedException, "Not implemented");
 	}
 	//-----------------------------------------------------------------------------
 	MultiRenderTarget::MultiRenderTarget(const String &name)

+ 1 - 1
CamelotRenderer/Source/CmRenderWindow.cpp

@@ -45,7 +45,7 @@ namespace CamelotEngine {
     {
         width = mWidth;
         height = mHeight;
-        colourDepth = mColourDepth;
+        colourDepth = mColorDepth;
         left = mLeft;
         top = mTop;
     }

+ 2 - 2
CamelotRenderer/Source/CmTexture.cpp

@@ -254,14 +254,14 @@ namespace CamelotEngine {
 	TexturePtr Texture::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
 		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
 	{
-		return TextureManager::instance().create(texType, 
+		return TextureManager::instance().createTexture(texType, 
 			width, height, depth, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 	}
 	
 	TexturePtr Texture::create(TextureType texType, UINT32 width, UINT32 height, 
 		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
 	{
-		return TextureManager::instance().create(texType, 
+		return TextureManager::instance().createTexture(texType, 
 			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 	}
 }

+ 1 - 1
CamelotRenderer/Source/CmTextureManager.cpp

@@ -52,7 +52,7 @@ namespace CamelotEngine {
 		delete texture;
 	}
     //-----------------------------------------------------------------------
-    TexturePtr TextureManager::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
+    TexturePtr TextureManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
         PixelFormat format, int usage, bool hwGamma, 
 		UINT32 fsaa, const String& fsaaHint)
     {

+ 7 - 34
CamelotRenderer/TODO.txt

@@ -17,13 +17,7 @@
 
 
 /////
-DX11 Render Textures are not implemented. I need to rethink render textures (and multi render textures) completely (Get rid of TU_RENDERTARGET enum)
- - Ability to create MultiRenderTarget (currently there is no method that does it)
-
 waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
-
-Move createRenderTexture to TextureManager? (also createMultiRenderTexture)
- - Right now its created with a special texture usage flag, which I don't like (Textures have slices and other weird stuff)
 Drop OpenGL support for low level shaders? (See if cg can translate to GLSL)
 
 Keeping a list of all render targets in RenderSystem shouldn't be needed (and calling attach/detach renderTarget). Renderer should determine in what order are render targets presented.
@@ -31,34 +25,30 @@ Keeping a list of all render targets in RenderSystem shouldn't be needed (and ca
 Constant buffers are created in a weird way. Maybe they should only be created internally by GpuProgramParameters?
  - Multiple GpuProgramParameters get returned from GpuProgram after createParameters() is called, in a map, each with its own name
 
-setDepthBuffer method on RenderTexture
-All render targets need to create DepthStencilBuffer internally, so that getDepthStencilBuffer can return something. Right now only D3D11 render window does this
-
 Make CommandQueue not use mutexes and use atomics instead??
 Make sure that the simulation can't run faster then the render thread! (Block the main thread until previous render finishes)
 Figure out how to handle accessing texture from a non-render thread?
 /////
 
-
-
-
-
-
 RenderSystem needed modifications
  - Right now HLSL11 CANNOT SPECIFY TEXTURE PARAMETERS! (Pass needs to be extended)
  - Generic buffers (Normal/Structured/Raw/Append/Consume/Indirect)
+ - Unordered access view for OM and CS stages
  - Ability to bind buffers and texture with different type of view (SHADER_RESOURCE & UNORDERED_ACCESS primarily, major others too)
  - Pass needs to be modified
   - Needs to support bool/double/texture1D/textue3D/textureCUBE/texture arrays/MS textures/all types of buffers/structs
+  - Needs to support (*void) data type for setting structs in constant buffers
  - TextureBuffer support? (Use for bones when skinning for exaple, as constant buffers are too slow)
  - RW buffers?
  - Tesselation (hull/domain) shader
  - Compute pipeline
  - Stream out (write vertex buffers)
- - Instancing
+ - Instancing (DrawInstanced, also check DrawIndirect)
  - Dynamic shader linkage (Interfaces and similar)
  - Append/Consume buffer
  - 1D/2D/Cube texture arrays
+ - Rendertargets that aren't just 2D
+ - Readable DepthStencil (needs to be assignable to a shader)
  - Multisampled texture resources
  - Multiple adapters (multi gpu)
  - DX11 allows detachable and reusable depthStencil buffers but right now DX9 and OpenGL just ignore them
@@ -73,25 +63,6 @@ RenderSystem needed modifications
 	- HLSL11 shader equivalents (domain/hull/compute shaders), and advanced shader parameters
  - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes
 
- RenderSystem modifications, yet another list:
-   - DepthStencilView & RenderTargetView are automatically created for any RenderTarget (no special mechanism for setting them needed)
-
-   - Extend pass with "struct" (void*) parameters to that they can be assigned to constant buffers
-   - Extend pass so it accepts "GenericBuffers"
-
-   - Add support for "GenericBuffers" (normal/structured/raw/append/consume/indirect)
-   - Add support for texture buffer
-
-   - Ability to set vertex buffer as a stream output buffer (also added to Pass)
-
-   - Set viewport & scissor rect to rasterizer (should probably be part of RenderTarget. If so, modify DX9 and GL so they act the same)
-
-   - Ability to create & assign unordered access views to OM and CS stages. (Extend pass and HardwareBufferManager)
-
-   - Extend render system with DrawInstanced (Also with DrawIndirect?)
-
-   - (Separate Pass parameters so that they are accepted per GpuProgramType, instead of using a global name?)
-
 Command buffer TODO:
  - When importing a resource, and registering it with Resources I don't think it properly gets added to the loaded resources array? For some reason shaders get created twice.
  - My current approach doesn't allow multiple threads to use the RenderSystem (contexts should be handled differently)
@@ -164,6 +135,8 @@ Low priority TODO:
  - Fix up WorkQueue as it doesn't lock when initializing, to make sure threads are actually started before returning
  - D3D9HLSLProgram stuff that isn't used (it needs to be initialized before initializing the shader, which currently isn't possible). Maybe adding it to HighLevelGpuProgramFactory?
      - setPreprocessorDefines, setColumnMajorMatrices, setOptimisationLevel
+ - OpenGL seems to generate a mip pyramid regardless of the setting (in createInternalResourcesImpl)
+ - DepthStencilBuffer & Texture should possibly share the same interface instead of being two separate classes? I'll need to assign DepthStencil to shaders sometimes. Not possible in DX9 but possible in DX11.
 
 Optional TODO:
  - Add precompiled headers to all projects