Quellcode durchsuchen

Ability to specify depth stencil buffer format

Marko Pintera vor 13 Jahren
Ursprung
Commit
e43692cee0
25 geänderte Dateien mit 163 neuen und 83 gelöschten Zeilen
  1. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11DepthStencilBuffer.h
  2. 14 12
      CamelotD3D11RenderSystem/Include/CmD3D11Mappings.h
  3. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h
  4. 5 4
      CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilBuffer.cpp
  5. 19 0
      CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp
  6. 1 1
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp
  7. 32 32
      CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp
  8. 1 1
      CamelotD3D9Renderer/Include/CmD3D9DepthStencilBuffer.h
  9. 2 0
      CamelotD3D9Renderer/Include/CmD3D9Mappings.h
  10. 1 1
      CamelotD3D9Renderer/Include/CmD3D9TextureManager.h
  11. 6 5
      CamelotD3D9Renderer/Source/CmD3D9DepthStencilBuffer.cpp
  12. 17 0
      CamelotD3D9Renderer/Source/CmD3D9Mappings.cpp
  13. 2 2
      CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp
  14. 1 1
      CamelotGLRenderer/Include/CmGLDepthStencilBuffer.h
  15. 9 4
      CamelotGLRenderer/Include/CmGLPixelFormat.h
  16. 1 1
      CamelotGLRenderer/Include/CmGLTextureManager.h
  17. 5 3
      CamelotGLRenderer/Source/CmGLDepthStencilBuffer.cpp
  18. 19 0
      CamelotGLRenderer/Source/CmGLPixelFormat.cpp
  19. 2 2
      CamelotGLRenderer/Source/CmGLTextureManager.cpp
  20. 4 3
      CamelotRenderer/Include/CmDepthStencilBuffer.h
  21. 2 2
      CamelotRenderer/Include/CmRenderTexture.h
  22. 1 1
      CamelotRenderer/Include/CmTextureManager.h
  23. 2 2
      CamelotRenderer/Source/CmDepthStencilBuffer.cpp
  24. 4 4
      CamelotRenderer/Source/CmRenderTexture.cpp
  25. 11 0
      CamelotUtility/Include/CmPixelData.h

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11DepthStencilBuffer.h

@@ -8,7 +8,7 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11DepthStencilBuffer : public DepthStencilBuffer
 	class CM_D3D11_EXPORT D3D11DepthStencilBuffer : public DepthStencilBuffer
 	{
 	{
 	public:
 	public:
-		D3D11DepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
+		D3D11DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
 		~D3D11DepthStencilBuffer();
 		~D3D11DepthStencilBuffer();
 
 
 		bool isCompatible(RenderTarget* renderTarget) const;
 		bool isCompatible(RenderTarget* renderTarget) const;

+ 14 - 12
CamelotD3D11RenderSystem/Include/CmD3D11Mappings.h

@@ -25,24 +25,26 @@ namespace CamelotEngine
 			D3D_FUSAGE_MIP
 			D3D_FUSAGE_MIP
 		};
 		};
 
 
-		/// return a D3D11 equivalent for a Ogre TextureAddressingMode value
+		/// return a D3D11 equivalent for an engine TextureAddressingMode value
 		static D3D11_TEXTURE_ADDRESS_MODE get(TextureAddressingMode tam);
 		static D3D11_TEXTURE_ADDRESS_MODE get(TextureAddressingMode tam);
-		/// return a D3D11 equivalent for a Ogre SceneBlendFactor value
+		/// return a D3D11 equivalent for an engine SceneBlendFactor value
 		static D3D11_BLEND get(SceneBlendFactor sbf);
 		static D3D11_BLEND get(SceneBlendFactor sbf);
-		/// return a D3D11 equivalent for a Ogre SceneBlendOperation value
+		/// return a D3D11 equivalent for an engine SceneBlendOperation value
 		static D3D11_BLEND_OP get(SceneBlendOperation sbo);
 		static D3D11_BLEND_OP get(SceneBlendOperation sbo);
-		/// return a D3D11 equivalent for a Ogre CompareFunction value
+		/// return a D3D11 equivalent for an engine CompareFunction value
 		static D3D11_COMPARISON_FUNC get(CompareFunction cf);
 		static D3D11_COMPARISON_FUNC get(CompareFunction cf);
-		/// return a D3D11 equivalent for a Ogre CillingMode value
+		/// return a D3D11 equivalent for an engine CillingMode value
 		static D3D11_CULL_MODE get(CullingMode cm, bool flip = false);
 		static D3D11_CULL_MODE get(CullingMode cm, bool flip = false);
-		/// return a D3D11 equivalent for a Ogre PolygonMode value
+		/// return a D3D11 equivalent for an engine PolygonMode value
 		static D3D11_FILL_MODE get(PolygonMode level);
 		static D3D11_FILL_MODE get(PolygonMode level);
-		/// return a D3D11 equivalent for a Ogre StencilOperation value
+		/// return a D3D11 equivalent for an engine StencilOperation value
 		static D3D11_STENCIL_OP get(StencilOperation op, bool invert = false);
 		static D3D11_STENCIL_OP get(StencilOperation op, bool invert = false);
-		/// return a D3D11 state type for Ogre FilterType value
+		/// return a D3D11 equivalent for an engine DepthStencilFormat
+		static DXGI_FORMAT get(DepthStencilFormat format);
+		/// return a D3D11 state type for engine FilterType value
 		static DWORD get(FilterType ft);
 		static DWORD get(FilterType ft);
 		static D3D11_FILTER get(const FilterOptions minification, const FilterOptions magnification, const FilterOptions mips, const bool comparison = false);
 		static D3D11_FILTER get(const FilterOptions minification, const FilterOptions magnification, const FilterOptions mips, const bool comparison = false);
-		/// return the combination of D3DUSAGE values for Ogre buffer usage
+		/// return the combination of D3DUSAGE values for engine buffer usage
 		static DWORD get(HardwareBuffer::Usage usage);
 		static DWORD get(HardwareBuffer::Usage usage);
 		/// Get lock options
 		/// Get lock options
 		static D3D11_MAP get(LockOptions options, HardwareBuffer::Usage usage);
 		static D3D11_MAP get(LockOptions options, HardwareBuffer::Usage usage);
@@ -58,9 +60,9 @@ namespace CamelotEngine
 		static bool isMappingRead(D3D11_MAP map);
 		static bool isMappingRead(D3D11_MAP map);
 		static D3D11_BOX toDx11Box(const Box &inBox);
 		static D3D11_BOX toDx11Box(const Box &inBox);
 
 
-		/// utility method, convert D3D11 pixel format to Ogre pixel format
+		/// utility method, convert D3D11 pixel format to engine pixel format
 		static PixelFormat _getPF(DXGI_FORMAT d3dPF);
 		static PixelFormat _getPF(DXGI_FORMAT d3dPF);
-		/// utility method, convert Ogre pixel format to D3D11 pixel format
+		/// utility method, convert engine pixel format to D3D11 pixel format
 		static DXGI_FORMAT _getPF(PixelFormat ogrePF);
 		static DXGI_FORMAT _getPF(PixelFormat ogrePF);
 		//
 		//
 		static D3D11_USAGE _getUsage(HardwareBuffer::Usage mUsage);
 		static D3D11_USAGE _getUsage(HardwareBuffer::Usage mUsage);
@@ -71,7 +73,7 @@ namespace CamelotEngine
 
 
 		static bool _isDynamic(int mUsage);
 		static bool _isDynamic(int mUsage);
 
 
-		/// utility method, find closest Ogre pixel format that D3D11 can support
+		/// utility method, find closest engine pixel format that D3D11 can support
 		static PixelFormat _getClosestSupportedPF(PixelFormat ogrePF);
 		static PixelFormat _getClosestSupportedPF(PixelFormat ogrePF);
 
 
 		static TextureType _getTexType(D3D11_SRV_DIMENSION type);
 		static TextureType _getTexType(D3D11_SRV_DIMENSION type);

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h

@@ -21,7 +21,7 @@ namespace CamelotEngine
 		/**
 		/**
 		 * @copydoc TextureManager::createDepthStencilBuffer()
 		 * @copydoc TextureManager::createDepthStencilBuffer()
 		 */
 		 */
-		DepthStencilBufferPtr createDepthStencilBuffer(UINT32 bitDepth, UINT32 width, 
+		DepthStencilBufferPtr createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 
 
 	protected:		
 	protected:		

+ 5 - 4
CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilBuffer.cpp

@@ -1,12 +1,13 @@
 #include "CmD3D11DepthStencilBuffer.h"
 #include "CmD3D11DepthStencilBuffer.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11Device.h"
+#include "CmD3D11Mappings.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	D3D11DepthStencilBuffer::D3D11DepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
-		: DepthStencilBuffer(bitDepth, width, height, fsaa, fsaaHint)
+	D3D11DepthStencilBuffer::D3D11DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
+		: DepthStencilBuffer(format, width, height, fsaa, fsaaHint)
 		, mDepthStencil(nullptr)
 		, mDepthStencil(nullptr)
 		, mDepthStencilView(nullptr)
 		, mDepthStencilView(nullptr)
 	{
 	{
@@ -17,14 +18,14 @@ namespace CamelotEngine
 		descDepth.Height = height;
 		descDepth.Height = height;
 		descDepth.MipLevels = 1;
 		descDepth.MipLevels = 1;
 		descDepth.ArraySize = 1;
 		descDepth.ArraySize = 1;
-		descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
+		descDepth.Format = D3D11Mappings::get(format);
 		descDepth.Usage = D3D11_USAGE_DEFAULT;
 		descDepth.Usage = D3D11_USAGE_DEFAULT;
 		descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
 		descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
 		descDepth.CPUAccessFlags = 0;
 		descDepth.CPUAccessFlags = 0;
 		descDepth.MiscFlags = 0;
 		descDepth.MiscFlags = 0;
 
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
-		rs->determineFSAASettings(fsaa, fsaaHint, DXGI_FORMAT_D24_UNORM_S8_UINT, &descDepth.SampleDesc);
+		rs->determineFSAASettings(fsaa, fsaaHint, descDepth.Format, &descDepth.SampleDesc);
 
 
 		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
 		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
 		HRESULT hr = device.getD3D11Device()->CreateTexture2D(&descDepth, NULL, &mDepthStencil);
 		HRESULT hr = device.getD3D11Device()->CreateTexture2D(&descDepth, NULL, &mDepthStencil);

+ 19 - 0
CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp

@@ -149,6 +149,25 @@ namespace CamelotEngine
 		return D3D11_STENCIL_OP_KEEP;
 		return D3D11_STENCIL_OP_KEEP;
 	}
 	}
 
 
+	DXGI_FORMAT D3D11Mappings::get(DepthStencilFormat format)
+	{
+		switch(format)
+		{
+		case DFMT_D32_S8X24:
+			return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
+		case DFMT_D24S8:
+			return DXGI_FORMAT_D24_UNORM_S8_UINT;
+		case DFMT_D32:
+			return DXGI_FORMAT_D32_FLOAT;
+		case DFMT_D16:
+			return DXGI_FORMAT_D16_UNORM;
+		}
+
+		LOGWRN("Requesting unsupported DepthStencilFormat. Using D24S8 format instead.");
+
+		return DXGI_FORMAT_D24_UNORM_S8_UINT;
+	}
+
 	DWORD D3D11Mappings::get(FilterType ft)
 	DWORD D3D11Mappings::get(FilterType ft)
 	{
 	{
 		switch (ft)
 		switch (ft)

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -613,7 +613,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Unable to create rendertagert view\nError Description:" + errorDescription);
 			CM_EXCEPT(RenderingAPIException, "Unable to create rendertagert view\nError Description:" + errorDescription);
 		}
 		}
 
 
-		mDepthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(32, BBDesc.Width, BBDesc.Height, mFSAA, mFSAAHint);
+		mDepthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(DFMT_D24S8, BBDesc.Width, BBDesc.Height, mFSAA, mFSAAHint);
 	}
 	}
 
 
 	void D3D11RenderWindow::_destroySizeDependedD3DResources()
 	void D3D11RenderWindow::_destroySizeDependedD3DResources()

+ 32 - 32
CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp

@@ -6,39 +6,39 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	D3D11TextureManager::D3D11TextureManager() 
-		:TextureManager()
-	{ }
-
-	D3D11TextureManager::~D3D11TextureManager()
-	{ }
-
-	Texture* D3D11TextureManager::createImpl()
-	{
-		return new D3D11Texture(); 
-	}
-
-	DepthStencilBufferPtr D3D11TextureManager::createDepthStencilBuffer(UINT32 bitDepth, UINT32 width, 
+	D3D11TextureManager::D3D11TextureManager() 
+		:TextureManager()
+	{ }
+
+	D3D11TextureManager::~D3D11TextureManager()
+	{ }
+
+	Texture* D3D11TextureManager::createImpl()
+	{
+		return new D3D11Texture(); 
+	}
+
+	DepthStencilBufferPtr D3D11TextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 	{
 	{
-		return DepthStencilBufferPtr(new D3D11DepthStencilBuffer(bitDepth, width, height, fsaa, fsaaHint));
-	}
-
-	PixelFormat D3D11TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
-	{
-		// Basic filtering
-		DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(format));
-
-		return D3D11Mappings::_getPF(d3dPF);
-	}
-
-	bool D3D11TextureManager::isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-		bool preciseFormatOnly)
-	{
-		if (!preciseFormatOnly)
-			format = getNativeFormat(ttype, format, usage);
-
-		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
-		return rs->checkTextureFilteringSupported(ttype, format, usage);
+		return DepthStencilBufferPtr(new D3D11DepthStencilBuffer(format, width, height, fsaa, fsaaHint));
+	}
+
+	PixelFormat D3D11TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
+	{
+		// Basic filtering
+		DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(format));
+
+		return D3D11Mappings::_getPF(d3dPF);
+	}
+
+	bool D3D11TextureManager::isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
+		bool preciseFormatOnly)
+	{
+		if (!preciseFormatOnly)
+			format = getNativeFormat(ttype, format, usage);
+
+		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
+		return rs->checkTextureFilteringSupported(ttype, format, usage);
 	}
 	}
 }
 }

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9DepthStencilBuffer.h

@@ -8,7 +8,7 @@ namespace CamelotEngine
 	class CM_D3D9_EXPORT D3D9DepthStencilBuffer : public DepthStencilBuffer
 	class CM_D3D9_EXPORT D3D9DepthStencilBuffer : public DepthStencilBuffer
 	{
 	{
 	public:
 	public:
-		D3D9DepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
+		D3D9DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
 		~D3D9DepthStencilBuffer();
 		~D3D9DepthStencilBuffer();
 
 
 		IDirect3DSurface9* getSurface() const { return mSurface; }
 		IDirect3DSurface9* getSurface() const { return mSurface; }

+ 2 - 0
CamelotD3D9Renderer/Include/CmD3D9Mappings.h

@@ -93,6 +93,8 @@ namespace CamelotEngine
 		static D3DDECLTYPE get(VertexElementType vType);
 		static D3DDECLTYPE get(VertexElementType vType);
 		/// Get vertex semantic
 		/// Get vertex semantic
 		static D3DDECLUSAGE get(VertexElementSemantic sem);
 		static D3DDECLUSAGE get(VertexElementSemantic sem);
+		/// return a D3D11 equivalent for an engine DepthStencilFormat
+		static D3DFORMAT get(DepthStencilFormat format);
         // Convert matrix to D3D style
         // Convert matrix to D3D style
         static 	D3DXMATRIX makeD3DXMatrix( const Matrix4& mat );
         static 	D3DXMATRIX makeD3DXMatrix( const Matrix4& mat );
         // Convert matrix from D3D style
         // Convert matrix from D3D style

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9TextureManager.h

@@ -50,7 +50,7 @@ namespace CamelotEngine
 		/**
 		/**
 		 * @copydoc TextureManager::createDepthStencilBuffer()
 		 * @copydoc TextureManager::createDepthStencilBuffer()
 		 */
 		 */
-		DepthStencilBufferPtr createDepthStencilBuffer(UINT32 bitDepth, UINT32 width, 
+		DepthStencilBufferPtr createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 
 
 	protected:		
 	protected:		

+ 6 - 5
CamelotD3D9Renderer/Source/CmD3D9DepthStencilBuffer.cpp

@@ -1,25 +1,26 @@
 #include "CmD3D9DepthStencilBuffer.h"
 #include "CmD3D9DepthStencilBuffer.h"
 #include "CmD3D9RenderSystem.h"
 #include "CmD3D9RenderSystem.h"
+#include "CmD3D9Mappings.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	D3D9DepthStencilBuffer::D3D9DepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
-		:DepthStencilBuffer(bitDepth, width, height, fsaa, fsaaHint), mSurface(nullptr)
+	D3D9DepthStencilBuffer::D3D9DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
+		:DepthStencilBuffer(format, width, height, fsaa, fsaaHint), mSurface(nullptr)
 	{
 	{
 		D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(RenderSystem::instancePtr());
 		D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(RenderSystem::instancePtr());
 
 
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
 
 
-		D3DFORMAT format = D3DFMT_D24S8;
+		D3DFORMAT d3dFormat = D3D9Mappings::get(format);
 		D3DMULTISAMPLE_TYPE msType = D3DMULTISAMPLE_NONE;
 		D3DMULTISAMPLE_TYPE msType = D3DMULTISAMPLE_NONE;
 		DWORD msQuality = 0;
 		DWORD msQuality = 0;
-		rs->determineFSAASettings(d3d9Device, fsaa, fsaaHint, format, false, &msType, &msQuality);
+		rs->determineFSAASettings(d3d9Device, fsaa, fsaaHint, d3dFormat, false, &msType, &msQuality);
 
 
 		/// If not, create the depthstencil surface
 		/// If not, create the depthstencil surface
 		HRESULT hr = d3d9Device->CreateDepthStencilSurface( 
 		HRESULT hr = d3d9Device->CreateDepthStencilSurface( 
 			static_cast<UINT>(width), 
 			static_cast<UINT>(width), 
 			static_cast<UINT>(height), 
 			static_cast<UINT>(height), 
-			format, 
+			d3dFormat, 
 			msType, 
 			msType, 
 			msQuality, 
 			msQuality, 
 			TRUE,  // discard true or false?
 			TRUE,  // discard true or false?

+ 17 - 0
CamelotD3D9Renderer/Source/CmD3D9Mappings.cpp

@@ -456,6 +456,23 @@ namespace CamelotEngine
 		return D3DDECLUSAGE_POSITION;
 		return D3DDECLUSAGE_POSITION;
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
+	D3DFORMAT D3D9Mappings::get(DepthStencilFormat format)
+	{
+		switch(format)
+		{
+		case DFMT_D24S8:
+			return D3DFMT_D24S8;
+		case DFMT_D32:
+			return D3DFMT_D32F_LOCKABLE;
+		case DFMT_D16:
+			return D3DFMT_D16;
+		}
+
+		LOGWRN("Requesting unsupported DepthStencilFormat. Using D24S8 format instead.");
+
+		return D3DFMT_D24S8;
+	}
+	//---------------------------------------------------------------------
 	D3DXMATRIX D3D9Mappings::makeD3DXMatrix( const Matrix4& mat )
 	D3DXMATRIX D3D9Mappings::makeD3DXMatrix( const Matrix4& mat )
 	{
 	{
 		// Transpose matrix
 		// Transpose matrix

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp

@@ -49,10 +49,10 @@ namespace CamelotEngine
 		return new D3D9Texture();
 		return new D3D9Texture();
     }
     }
 
 
-	DepthStencilBufferPtr D3D9TextureManager::createDepthStencilBuffer(UINT32 bitDepth, UINT32 width, 
+	DepthStencilBufferPtr D3D9TextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 	{
 	{
-		return DepthStencilBufferPtr(new D3D9DepthStencilBuffer(bitDepth, width, height, fsaa, fsaaHint));
+		return DepthStencilBufferPtr(new D3D9DepthStencilBuffer(format, width, height, fsaa, fsaaHint));
 	}
 	}
 
 
 	PixelFormat D3D9TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
 	PixelFormat D3D9TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)

+ 1 - 1
CamelotGLRenderer/Include/CmGLDepthStencilBuffer.h

@@ -8,7 +8,7 @@ namespace CamelotEngine
 	class CM_RSGL_EXPORT GLDepthStencilBuffer : public DepthStencilBuffer
 	class CM_RSGL_EXPORT GLDepthStencilBuffer : public DepthStencilBuffer
 	{
 	{
 	public:
 	public:
-		GLDepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
+		GLDepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
 		~GLDepthStencilBuffer();
 		~GLDepthStencilBuffer();
 
 
 		GLRenderBufferPtr getGLRenderBuffer() const { return mDepthStencilRenderBuffer; }
 		GLRenderBufferPtr getGLRenderBuffer() const { return mDepthStencilRenderBuffer; }

+ 9 - 4
CamelotGLRenderer/Include/CmGLPixelFormat.h

@@ -38,20 +38,20 @@ namespace CamelotEngine {
 	class CM_RSGL_EXPORT GLPixelUtil
 	class CM_RSGL_EXPORT GLPixelUtil
 	{
 	{
 	public:
 	public:
-		/** Takes the OGRE pixel format and returns the appropriate GL one
+		/** Takes the engine pixel format and returns the appropriate GL one
 			@returns a GLenum describing the format, or 0 if there is no exactly matching 
 			@returns a GLenum describing the format, or 0 if there is no exactly matching 
 			one (and conversion is needed)
 			one (and conversion is needed)
 		*/
 		*/
 		static GLenum getGLOriginFormat(PixelFormat mFormat);
 		static GLenum getGLOriginFormat(PixelFormat mFormat);
 	
 	
-		/** Takes the OGRE pixel format and returns type that must be provided
+		/** Takes the engine pixel format and returns type that must be provided
 			to GL as data type for reading it into the GPU
 			to GL as data type for reading it into the GPU
 			@returns a GLenum describing the data type, or 0 if there is no exactly matching 
 			@returns a GLenum describing the data type, or 0 if there is no exactly matching 
 			one (and conversion is needed)
 			one (and conversion is needed)
 		*/
 		*/
 		static GLenum getGLOriginDataType(PixelFormat mFormat);
 		static GLenum getGLOriginDataType(PixelFormat mFormat);
         
         
-        /**	Takes the OGRE pixel format and returns the type that must be provided
+        /**	Takes the engine pixel format and returns the type that must be provided
 			to GL as internal format. GL_NONE if no match exists.
 			to GL as internal format. GL_NONE if no match exists.
 		@param mFormat The pixel format
 		@param mFormat The pixel format
 		@param hwGamma Whether a hardware gamma-corrected version is requested
 		@param hwGamma Whether a hardware gamma-corrected version is requested
@@ -65,13 +65,18 @@ namespace CamelotEngine {
 		*/
 		*/
 		static GLenum getClosestGLInternalFormat(PixelFormat mFormat, bool hwGamma = false);
 		static GLenum getClosestGLInternalFormat(PixelFormat mFormat, bool hwGamma = false);
 		
 		
-		/**	Function to get the closest matching OGRE format to an internal GL format. To be
+		/**	Function to get the closest matching engine format to an internal GL format. To be
 			precise, the format will be chosen that is most efficient to transfer to the card 
 			precise, the format will be chosen that is most efficient to transfer to the card 
 			without losing precision.
 			without losing precision.
 			@remarks It is valid for this function to always return PF_A8R8G8B8.
 			@remarks It is valid for this function to always return PF_A8R8G8B8.
 		*/
 		*/
 		static PixelFormat getClosestEngineFormat(GLenum fmt);
 		static PixelFormat getClosestEngineFormat(GLenum fmt);
 
 
+		/**
+		 * @brief	Returns closest OpenGL depth/stencil format.
+		 */
+		static GLenum getDepthStencilFormat(DepthStencilFormat fmt);
+
 		/**
 		/**
 		 * @brief	Gets OpenGL format based on a compressed OpenGL internal format.
 		 * @brief	Gets OpenGL format based on a compressed OpenGL internal format.
 		 * 			e.g. GL_COMPRESSED_RGBA_S3TC_DXT1_EXT will return GL_RGBA
 		 * 			e.g. GL_COMPRESSED_RGBA_S3TC_DXT1_EXT will return GL_RGBA

+ 1 - 1
CamelotGLRenderer/Include/CmGLTextureManager.h

@@ -54,7 +54,7 @@ namespace CamelotEngine {
 		/**
 		/**
 		 * @copydoc TextureManager::createDepthStencilBuffer()
 		 * @copydoc TextureManager::createDepthStencilBuffer()
 		 */
 		 */
-		DepthStencilBufferPtr createDepthStencilBuffer(UINT32 bitDepth, UINT32 width, 
+		DepthStencilBufferPtr createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 			UINT32 height, UINT32 fsaa, const String& fsaaHint);
 
 
     protected:
     protected:

+ 5 - 3
CamelotGLRenderer/Source/CmGLDepthStencilBuffer.cpp

@@ -1,12 +1,14 @@
 #include "CmGLDepthStencilBuffer.h"
 #include "CmGLDepthStencilBuffer.h"
 #include "CmGLHardwarePixelBuffer.h"
 #include "CmGLHardwarePixelBuffer.h"
+#include "CmGLPixelFormat.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	GLDepthStencilBuffer::GLDepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
-		:DepthStencilBuffer(bitDepth, width, height, fsaa, fsaaHint)
+	GLDepthStencilBuffer::GLDepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
+		:DepthStencilBuffer(format, width, height, fsaa, fsaaHint)
 	{
 	{
-		mDepthStencilRenderBuffer = GLRenderBufferPtr(new GLRenderBuffer(GL_DEPTH24_STENCIL8_EXT, width, height, fsaa));
+		GLenum glDepthFormat = GLPixelUtil::getDepthStencilFormat(format);
+		mDepthStencilRenderBuffer = GLRenderBufferPtr(new GLRenderBuffer(glDepthFormat, width, height, fsaa));
 	}
 	}
 
 
 	GLDepthStencilBuffer::~GLDepthStencilBuffer()
 	GLDepthStencilBuffer::~GLDepthStencilBuffer()

+ 19 - 0
CamelotGLRenderer/Source/CmGLPixelFormat.cpp

@@ -29,6 +29,7 @@ THE SOFTWARE.
 #include "CmGLPixelFormat.h"
 #include "CmGLPixelFormat.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystem.h"
 #include "CmBitwise.h"
 #include "CmBitwise.h"
+#include "CmDebug.h"
 
 
 namespace CamelotEngine  {
 namespace CamelotEngine  {
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
@@ -371,7 +372,25 @@ namespace CamelotEngine  {
 		};
 		};
 	}
 	}
 	//----------------------------------------------------------------------------- 
 	//----------------------------------------------------------------------------- 
+	GLenum GLPixelUtil::getDepthStencilFormat(DepthStencilFormat fmt)
+	{
+		switch(fmt)
+		{
+		case DFMT_D32_S8X24:
+			return GL_DEPTH32F_STENCIL8;
+		case DFMT_D24S8:
+			return GL_DEPTH24_STENCIL8;
+		case DFMT_D32:
+			return GL_DEPTH_COMPONENT32F;
+		case DFMT_D16:
+			return GL_DEPTH_COMPONENT16;
+		}
 
 
+		LOGWRN("Requesting unsupported DepthStencilFormat. Using D24S8 format instead.");
+
+		return GL_DEPTH24_STENCIL8;
+	}
+	//----------------------------------------------------------------------------- 
 	UINT32 GLPixelUtil::getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
 	UINT32 GLPixelUtil::getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
 	{
 	{
 		UINT32 count = 0;
 		UINT32 count = 0;

+ 2 - 2
CamelotGLRenderer/Source/CmGLTextureManager.cpp

@@ -50,10 +50,10 @@ namespace CamelotEngine {
         return new GLTexture(mGLSupport);
         return new GLTexture(mGLSupport);
     }
     }
 	//----------------------------------------------------------------------------
 	//----------------------------------------------------------------------------
-	DepthStencilBufferPtr GLTextureManager::createDepthStencilBuffer(UINT32 bitDepth, UINT32 width, 
+	DepthStencilBufferPtr GLTextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 		UINT32 height, UINT32 fsaa, const String& fsaaHint)
 	{
 	{
-		return DepthStencilBufferPtr(new GLDepthStencilBuffer(bitDepth, width, height, fsaa, fsaaHint));
+		return DepthStencilBufferPtr(new GLDepthStencilBuffer(format, width, height, fsaa, fsaaHint));
 	}
 	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	void GLTextureManager::createWarningTexture()
 	void GLTextureManager::createWarningTexture()

+ 4 - 3
CamelotRenderer/Include/CmDepthStencilBuffer.h

@@ -1,16 +1,17 @@
 #pragma once
 #pragma once
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
+#include "CmPixelData.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	class CM_EXPORT DepthStencilBuffer
 	class CM_EXPORT DepthStencilBuffer
 	{
 	{
 	public:
 	public:
-		DepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
+		DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
 		virtual ~DepthStencilBuffer();
 		virtual ~DepthStencilBuffer();
 
 
-		UINT32 getBitDepth() const { return mBitDepth; }
+		DepthStencilFormat getFormat() const { return mFormat; }
 		UINT32 getWidth() const { return mWidth; }
 		UINT32 getWidth() const { return mWidth; }
 		UINT32 getHeight() const { return mHeight; }
 		UINT32 getHeight() const { return mHeight; }
 		UINT32 getFsaa() const { return mFsaa; }
 		UINT32 getFsaa() const { return mFsaa; }
@@ -27,7 +28,7 @@ namespace CamelotEngine
 		virtual bool isCompatible(RenderTarget *renderTarget) const;
 		virtual bool isCompatible(RenderTarget *renderTarget) const;
 
 
 	protected:
 	protected:
-		UINT32						mBitDepth;
+		DepthStencilFormat			mFormat;
 		UINT32						mWidth;
 		UINT32						mWidth;
 		UINT32						mHeight;
 		UINT32						mHeight;
 		UINT32						mFsaa;
 		UINT32						mFsaa;

+ 2 - 2
CamelotRenderer/Include/CmRenderTexture.h

@@ -61,7 +61,7 @@ namespace CamelotEngine
 	protected:
 	protected:
 		TextureType mType;
 		TextureType mType;
 		PixelFormat mFormat;
 		PixelFormat mFormat;
-		UINT32 mDepthBits;
+		DepthStencilFormat mDepthStencilFormat;
 		UINT32 mFace;
 		UINT32 mFace;
 		UINT32 mNumFaces;
 		UINT32 mNumFaces;
 		UINT32 mMipLevel;
 		UINT32 mMipLevel;
@@ -73,7 +73,7 @@ namespace CamelotEngine
 
 
 		void initialize(TextureType textureType, UINT32 width, UINT32 height, 
 		void initialize(TextureType textureType, UINT32 width, UINT32 height, 
 			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
 			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
-			bool createDepth = true, UINT32 depthBits = 32);
+			bool createDepth = true, DepthStencilFormat depthStencilFormat = DFMT_D24S8);
 
 
 		void initialize(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer, 
 		void initialize(TexturePtr texture, DepthStencilBufferPtr depthStencilbuffer, 
 			UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
 			UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);

+ 1 - 1
CamelotRenderer/Include/CmTextureManager.h

@@ -175,7 +175,7 @@ namespace CamelotEngine {
 		/**
 		/**
 		 * @brief	Creates a new depth/stencil buffer.
 		 * @brief	Creates a new depth/stencil buffer.
 		 */
 		 */
-		virtual DepthStencilBufferPtr createDepthStencilBuffer(UINT32 bitDepth, UINT32 width, 
+		virtual DepthStencilBufferPtr createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
 			UINT32 height, UINT32 fsaa, const String& fsaaHint) = 0;
 			UINT32 height, UINT32 fsaa, const String& fsaaHint) = 0;
 
 
 
 

+ 2 - 2
CamelotRenderer/Source/CmDepthStencilBuffer.cpp

@@ -3,8 +3,8 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	DepthStencilBuffer::DepthStencilBuffer(UINT32 bitDepth, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
-		: mBitDepth(bitDepth)
+	DepthStencilBuffer::DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
+		: mFormat(format)
 		, mWidth(width)
 		, mWidth(width)
 		, mHeight(height)
 		, mHeight(height)
 		, mFsaa(fsaa)
 		, mFsaa(fsaa)

+ 4 - 4
CamelotRenderer/Source/CmRenderTexture.cpp

@@ -42,7 +42,7 @@ namespace CamelotEngine
 
 
 	void RenderTexture::initialize(TextureType textureType, UINT32 width, UINT32 height, 
 	void RenderTexture::initialize(TextureType textureType, UINT32 width, UINT32 height, 
 		PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint,
 		PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint,
-		bool createDepth, UINT32 depthBits)
+		bool createDepth, DepthStencilFormat depthStencilFormat)
 	{
 	{
 		mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mWidth = width;
 		mWidth = width;
@@ -54,7 +54,7 @@ namespace CamelotEngine
 		mHwGamma = hwGamma;
 		mHwGamma = hwGamma;
 		mFSAA = fsaa;
 		mFSAA = fsaa;
 		mFSAAHint = fsaaHint;
 		mFSAAHint = fsaaHint;
-		mDepthBits = depthBits;
+		mDepthStencilFormat = depthStencilFormat;
 		mFace = 0;
 		mFace = 0;
 		mMipLevel = 0;
 		mMipLevel = 0;
 
 
@@ -98,7 +98,7 @@ namespace CamelotEngine
 
 
 	void RenderTexture::createDepthStencilBuffer()
 	void RenderTexture::createDepthStencilBuffer()
 	{
 	{
-		mDepthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(mDepthBits, mWidth, mHeight, mFSAA, mFSAAHint);
+		mDepthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(mDepthStencilFormat, mWidth, mHeight, mFSAA, mFSAAHint);
 	}
 	}
 
 
 	void RenderTexture::setBuffers(TexturePtr texture, DepthStencilBufferPtr depthStencilBuffer, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	void RenderTexture::setBuffers(TexturePtr texture, DepthStencilBufferPtr depthStencilBuffer, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
@@ -130,7 +130,7 @@ namespace CamelotEngine
 		mFSAAHint = texture->getFSAAHint();
 		mFSAAHint = texture->getFSAAHint();
 		mType = texture->getTextureType();
 		mType = texture->getTextureType();
 		mFormat = texture->getFormat();
 		mFormat = texture->getFormat();
-		mDepthBits = depthStencilBuffer->getBitDepth();
+		mDepthStencilFormat = depthStencilBuffer->getFormat();
 		mFace = face;
 		mFace = face;
 		mNumFaces = face;
 		mNumFaces = face;
 		mMipLevel = mipLevel;
 		mMipLevel = mipLevel;

+ 11 - 0
CamelotUtility/Include/CmPixelData.h

@@ -152,6 +152,17 @@ namespace CamelotEngine
         PCT_FLOAT32 = 3, /// 32 bit float per component
         PCT_FLOAT32 = 3, /// 32 bit float per component
         PCT_COUNT = 4    /// Number of pixel types
         PCT_COUNT = 4    /// Number of pixel types
     };
     };
+
+	/**
+	 * @brief	Available formats for depth/stencil buffer
+	 */
+	enum DepthStencilFormat
+	{
+		DFMT_D32_S8X24,
+		DFMT_D24S8,
+		DFMT_D32,
+		DFMT_D16
+	};
     
     
 	/** A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
 	/** A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
      	In case of a rectangle, depth must be 1. 
      	In case of a rectangle, depth must be 1.