Explorar o código

Dropping DirectX 9 support

BearishSun %!s(int64=9) %!d(string=hai) anos
pai
achega
11407c6afa
Modificáronse 66 ficheiros con 11 adicións e 12019 borrados
  1. 6 7
      Documentation/GitHub/compiling.md
  2. 1 1
      Documentation/GitHub/features.md
  3. 0 39
      Source/BansheeD3D9RenderAPI/CMakeLists.txt
  4. 0 74
      Source/BansheeD3D9RenderAPI/CMakeSources.cmake
  5. 0 191
      Source/BansheeD3D9RenderAPI/Include/BsD3D9Device.h
  6. 0 66
      Source/BansheeD3D9RenderAPI/Include/BsD3D9DeviceManager.h
  7. 0 47
      Source/BansheeD3D9RenderAPI/Include/BsD3D9Driver.h
  8. 0 39
      Source/BansheeD3D9RenderAPI/Include/BsD3D9DriverList.h
  9. 0 39
      Source/BansheeD3D9RenderAPI/Include/BsD3D9EmulatedParamBlocks.h
  10. 0 54
      Source/BansheeD3D9RenderAPI/Include/BsD3D9EventQuery.h
  11. 0 57
      Source/BansheeD3D9RenderAPI/Include/BsD3D9GpuBuffer.h
  12. 0 114
      Source/BansheeD3D9RenderAPI/Include/BsD3D9GpuProgram.h
  13. 0 373
      Source/BansheeD3D9RenderAPI/Include/BsD3D9HLSLParamParser.h
  14. 0 38
      Source/BansheeD3D9RenderAPI/Include/BsD3D9HLSLProgramFactory.h
  15. 0 36
      Source/BansheeD3D9RenderAPI/Include/BsD3D9HardwareBufferManager.h
  16. 0 78
      Source/BansheeD3D9RenderAPI/Include/BsD3D9IndexBuffer.h
  17. 0 103
      Source/BansheeD3D9RenderAPI/Include/BsD3D9Mappings.h
  18. 0 67
      Source/BansheeD3D9RenderAPI/Include/BsD3D9MultiRenderTexture.h
  19. 0 67
      Source/BansheeD3D9RenderAPI/Include/BsD3D9OcclusionQuery.h
  20. 0 119
      Source/BansheeD3D9RenderAPI/Include/BsD3D9PixelBuffer.h
  21. 0 86
      Source/BansheeD3D9RenderAPI/Include/BsD3D9Prerequisites.h
  22. 0 29
      Source/BansheeD3D9RenderAPI/Include/BsD3D9QueryManager.h
  23. 0 449
      Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderAPI.h
  24. 0 48
      Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderAPIFactory.h
  25. 0 87
      Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderTexture.h
  26. 0 186
      Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderWindow.h
  27. 0 43
      Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderWindowManager.h
  28. 0 49
      Source/BansheeD3D9RenderAPI/Include/BsD3D9Resource.h
  29. 0 75
      Source/BansheeD3D9RenderAPI/Include/BsD3D9ResourceManager.h
  30. 0 171
      Source/BansheeD3D9RenderAPI/Include/BsD3D9Texture.h
  31. 0 50
      Source/BansheeD3D9RenderAPI/Include/BsD3D9TextureManager.h
  32. 0 72
      Source/BansheeD3D9RenderAPI/Include/BsD3D9TimerQuery.h
  33. 0 78
      Source/BansheeD3D9RenderAPI/Include/BsD3D9VertexBuffer.h
  34. 0 43
      Source/BansheeD3D9RenderAPI/Include/BsD3D9VertexDeclaration.h
  35. 0 45
      Source/BansheeD3D9RenderAPI/Include/BsD3D9VideoModeInfo.h
  36. 0 1247
      Source/BansheeD3D9RenderAPI/Source/BsD3D9Device.cpp
  37. 0 235
      Source/BansheeD3D9RenderAPI/Source/BsD3D9DeviceManager.cpp
  38. 0 46
      Source/BansheeD3D9RenderAPI/Source/BsD3D9Driver.cpp
  39. 0 57
      Source/BansheeD3D9RenderAPI/Source/BsD3D9DriverList.cpp
  40. 0 51
      Source/BansheeD3D9RenderAPI/Source/BsD3D9EmulatedParamBlocks.cpp
  41. 0 84
      Source/BansheeD3D9RenderAPI/Source/BsD3D9EventQuery.cpp
  42. 0 56
      Source/BansheeD3D9RenderAPI/Source/BsD3D9GpuBuffer.cpp
  43. 0 379
      Source/BansheeD3D9RenderAPI/Source/BsD3D9GpuProgram.cpp
  44. 0 73
      Source/BansheeD3D9RenderAPI/Source/BsD3D9HLSLProgramFactory.cpp
  45. 0 63
      Source/BansheeD3D9RenderAPI/Source/BsD3D9HardwareBufferManager.cpp
  46. 0 307
      Source/BansheeD3D9RenderAPI/Source/BsD3D9IndexBuffer.cpp
  47. 0 587
      Source/BansheeD3D9RenderAPI/Source/BsD3D9Mappings.cpp
  48. 0 91
      Source/BansheeD3D9RenderAPI/Source/BsD3D9MultiRenderTexture.cpp
  49. 0 121
      Source/BansheeD3D9RenderAPI/Source/BsD3D9OcclusionQuery.cpp
  50. 0 371
      Source/BansheeD3D9RenderAPI/Source/BsD3D9PixelBuffer.cpp
  51. 0 12
      Source/BansheeD3D9RenderAPI/Source/BsD3D9Plugin.cpp
  52. 0 33
      Source/BansheeD3D9RenderAPI/Source/BsD3D9QueryManager.cpp
  53. 0 2302
      Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderAPI.cpp
  54. 0 22
      Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderAPIFactory.cpp
  55. 0 90
      Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderTexture.cpp
  56. 0 591
      Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderWindow.cpp
  57. 0 47
      Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderWindowManager.cpp
  58. 0 30
      Source/BansheeD3D9RenderAPI/Source/BsD3D9Resource.cpp
  59. 0 105
      Source/BansheeD3D9RenderAPI/Source/BsD3D9ResourceManager.cpp
  60. 0 1145
      Source/BansheeD3D9RenderAPI/Source/BsD3D9Texture.cpp
  61. 0 79
      Source/BansheeD3D9RenderAPI/Source/BsD3D9TextureManager.cpp
  62. 0 171
      Source/BansheeD3D9RenderAPI/Source/BsD3D9TimerQuery.cpp
  63. 0 303
      Source/BansheeD3D9RenderAPI/Source/BsD3D9VertexBuffer.cpp
  64. 0 113
      Source/BansheeD3D9RenderAPI/Source/BsD3D9VertexDeclaration.cpp
  65. 0 78
      Source/BansheeD3D9RenderAPI/Source/BsD3D9VideoModeInfo.cpp
  66. 4 10
      Source/CMakeLists.txt

+ 6 - 7
Documentation/GitHub/compiling.md

@@ -28,29 +28,28 @@ For older versions of pre-compiled dependencies check the git release tag descri
 ## Other dependencies
 ## Other dependencies
 The following dependencies will need to be installed manually regardless if you used pre-compiled dependency package or have compiled them yourself.
 The following dependencies will need to be installed manually regardless if you used pre-compiled dependency package or have compiled them yourself.
 
 
-**DirectX SDK**
+**DirectX SDK** (Optional if not using DirectX)
  - Only needed if on Windows 7 or earlier and using DirectX 11 render API
  - Only needed if on Windows 7 or earlier and using DirectX 11 render API
- - Or for all Windows versions if using DirectX 9 render API
  - Set up DXSDK_DIR environment variable pointing to the DirectX instalation
  - Set up DXSDK_DIR environment variable pointing to the DirectX instalation
  
  
-**Windows SDK**
+**Windows SDK** (Optional if not using DirectX)
  - Only needed if on Windows 8 or later and using DirectX 11 render API
  - Only needed if on Windows 8 or later and using DirectX 11 render API
  
  
-**DirectX Debug Layer**
+**DirectX Debug Layer** (Optional if not using DirectX)
  - Only needed if on Windows 10 and using DirectX 11 render API
  - Only needed if on Windows 10 and using DirectX 11 render API
  - Go to Settings panel (type "Settings" in Start)->System->Apps & features->Manage optional Features->Add a feature->Select "Graphics Tools"
  - Go to Settings panel (type "Settings" in Start)->System->Apps & features->Manage optional Features->Add a feature->Select "Graphics Tools"
  
  
-**Python 3.5**
+**Python 3.5** (Optional)
  - Only needed if you plan on running Python scripts in the /Scripts folder
  - Only needed if you plan on running Python scripts in the /Scripts folder
  - https://www.python.org/downloads/
  - https://www.python.org/downloads/
 
 
-**FMOD Low Level Programmer API**
+**FMOD Low Level Programmer API** (Optional)
  - Only needed if you selected the FMOD audio module during build configuration (not selected by default)
  - Only needed if you selected the FMOD audio module during build configuration (not selected by default)
  - http://www.fmod.org/download/
  - http://www.fmod.org/download/
  - If CMake complains it cannot find FMOD, manually set the FMOD_INSTALL_DIRS to your installation directory 
  - If CMake complains it cannot find FMOD, manually set the FMOD_INSTALL_DIRS to your installation directory 
  - Copy the dynamic libraries from {INSTALLDIR}/api/lowlevel/lib into /bin folder in Banshee source code folder
  - Copy the dynamic libraries from {INSTALLDIR}/api/lowlevel/lib into /bin folder in Banshee source code folder
   - Use logging libraries for the Debug builds, and non-logging for OptimizedDebug and Release builds
   - Use logging libraries for the Debug builds, and non-logging for OptimizedDebug and Release builds
   
   
-**Mono 4.2**
+**Mono 4.2** (Optional)
  - If you wish to compile managed assemblies using a Microsoft compiler (e.g. using Visual Studio) yet still be able to debug the generated assemblies, you must install Mono 4.2. and set up an environment variable MONO_INSTALL_DIR pointing to the Mono installation directory. When this is set up "pdb2mdb" script will trigger on next compile generating the needed debug symbols.
  - If you wish to compile managed assemblies using a Microsoft compiler (e.g. using Visual Studio) yet still be able to debug the generated assemblies, you must install Mono 4.2. and set up an environment variable MONO_INSTALL_DIR pointing to the Mono installation directory. When this is set up "pdb2mdb" script will trigger on next compile generating the needed debug symbols.
  - http://www.mono-project.com/download/
  - http://www.mono-project.com/download/

+ 1 - 1
Documentation/GitHub/features.md

@@ -13,7 +13,7 @@ All features listed here are the ones currently available (implemented). If you
   * Minimal third-party dependencies
   * Minimal third-party dependencies
   * Multiplatform ready
   * Multiplatform ready
 * __Renderer__
 * __Renderer__
-  * DX9, DX11 and OpenGL 4.3 render systems
+  * DX11 and OpenGL 4.5 render systems
   * Multi-threaded rendering
   * Multi-threaded rendering
   * Powerful material system
   * Powerful material system
     * BansheeFX language for material definitions
     * BansheeFX language for material definitions

+ 0 - 39
Source/BansheeD3D9RenderAPI/CMakeLists.txt

@@ -1,39 +0,0 @@
-# Source files and their filters
-include(CMakeSources.cmake)
-
-# Includes
-set(BansheeD3D9RenderAPI_INC 
-	"Include" 
-	"../BansheeUtility/Include" 
-	"../BansheeCore/Include"
-	"$ENV{DXSDK_DIR}Include")
-
-include_directories(${BansheeD3D9RenderAPI_INC})	
-	
-# Target
-add_library(BansheeD3D9RenderAPI SHARED ${BS_BANSHEED3D9RENDERAPI_SRC})
-
-# Defines
-target_compile_definitions(BansheeD3D9RenderAPI PRIVATE -DBS_RSD3D9_EXPORTS)
-
-# Libraries
-
-if(BS_64BIT)
-	set(BS_DX9_LIB_PATH "$ENV{DXSDK_DIR}Lib/x64/")
-else()
-	set(BS_DX9_LIB_PATH "$ENV{DXSDK_DIR}Lib/x86/")
-endif()
-	
-## External lib: DirectX 9
-target_link_libraries(BansheeD3D9RenderAPI 
-	${BS_DX9_LIB_PATH}d3d9.lib
-	${BS_DX9_LIB_PATH}d3dx9.lib
-	${BS_DX9_LIB_PATH}DxErr.lib
-	${BS_DX9_LIB_PATH}dxguid.lib
-	legacy_stdio_definitions.lib)	
-	
-## Local libs
-target_link_libraries(BansheeD3D9RenderAPI BansheeUtility BansheeCore)
-
-# IDE specific
-set_property(TARGET BansheeD3D9RenderAPI PROPERTY FOLDER Plugins)

+ 0 - 74
Source/BansheeD3D9RenderAPI/CMakeSources.cmake

@@ -1,74 +0,0 @@
-set(BS_BANSHEED3D9RENDERAPI_INC_NOFILTER
-	"Include/BsD3D9VideoModeInfo.h"
-	"Include/BsD3D9VertexDeclaration.h"
-	"Include/BsD3D9VertexBuffer.h"
-	"Include/BsD3D9TimerQuery.h"
-	"Include/BsD3D9TextureManager.h"
-	"Include/BsD3D9Texture.h"
-	"Include/BsD3D9ResourceManager.h"
-	"Include/BsD3D9Resource.h"
-	"Include/BsD3D9RenderWindowManager.h"
-	"Include/BsD3D9RenderWindow.h"
-	"Include/BsD3D9RenderTexture.h"
-	"Include/BsD3D9QueryManager.h"
-	"Include/BsD3D9Prerequisites.h"
-	"Include/BsD3D9PixelBuffer.h"
-	"Include/BsD3D9OcclusionQuery.h"
-	"Include/BsD3D9MultiRenderTexture.h"
-	"Include/BsD3D9Mappings.h"
-	"Include/BsD3D9IndexBuffer.h"
-	"Include/BsD3D9HLSLProgramFactory.h"
-	"Include/BsD3D9HLSLParamParser.h"
-	"Include/BsD3D9HardwareBufferManager.h"
-	"Include/BsD3D9GpuProgram.h"
-	"Include/BsD3D9GpuBuffer.h"
-	"Include/BsD3D9EventQuery.h"
-	"Include/BsD3D9DriverList.h"
-	"Include/BsD3D9Driver.h"
-	"Include/BsD3D9DeviceManager.h"
-	"Include/BsD3D9Device.h"
-	"Include/BsD3D9EmulatedParamBlocks.h"
-	"Include/BsD3D9RenderAPI.h"
-	"Include/BsD3D9RenderAPIFactory.h"
-)
-
-set(BS_BANSHEED3D9RENDERAPI_SRC_NOFILTER
-	"Source/BsD3D9VideoModeInfo.cpp"
-	"Source/BsD3D9VertexDeclaration.cpp"
-	"Source/BsD3D9VertexBuffer.cpp"
-	"Source/BsD3D9TimerQuery.cpp"
-	"Source/BsD3D9TextureManager.cpp"
-	"Source/BsD3D9Texture.cpp"
-	"Source/BsD3D9ResourceManager.cpp"
-	"Source/BsD3D9Resource.cpp"
-	"Source/BsD3D9RenderWindowManager.cpp"
-	"Source/BsD3D9RenderWindow.cpp"
-	"Source/BsD3D9RenderTexture.cpp"
-	"Source/BsD3D9QueryManager.cpp"
-	"Source/BsD3D9PixelBuffer.cpp"
-	"Source/BsD3D9OcclusionQuery.cpp"
-	"Source/BsD3D9MultiRenderTexture.cpp"
-	"Source/BsD3D9Mappings.cpp"
-	"Source/BsD3D9IndexBuffer.cpp"
-	"Source/BsD3D9HLSLProgramFactory.cpp"
-	"Source/BsD3D9HardwareBufferManager.cpp"
-	"Source/BsD3D9GpuProgram.cpp"
-	"Source/BsD3D9GpuBuffer.cpp"
-	"Source/BsD3D9EventQuery.cpp"
-	"Source/BsD3D9DriverList.cpp"
-	"Source/BsD3D9Driver.cpp"
-	"Source/BsD3D9DeviceManager.cpp"
-	"Source/BsD3D9Device.cpp"
-	"Source/BsD3D9EmulatedParamBlocks.cpp"
-	"Source/BsD3D9RenderAPI.cpp"
-	"Source/BsD3D9RenderAPIFactory.cpp"
-	"Source/BsD3D9Plugin.cpp"
-)
-
-source_group("Header Files" FILES ${BS_BANSHEED3D9RENDERAPI_INC_NOFILTER})
-source_group("Source Files" FILES ${BS_BANSHEED3D9RENDERAPI_SRC_NOFILTER})
-
-set(BS_BANSHEED3D9RENDERAPI_SRC
-	${BS_BANSHEED3D9RENDERAPI_INC_NOFILTER}
-	${BS_BANSHEED3D9RENDERAPI_SRC_NOFILTER}
-)

+ 0 - 191
Source/BansheeD3D9RenderAPI/Include/BsD3D9Device.h

@@ -1,191 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsRenderTarget.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** High level interface for a DX9 device. Each device represents a hardware adapter or a software emulation device. */
-	class BS_D3D9_EXPORT D3D9Device
-	{
-	protected:
-		/**	Holds device specific render window resources. */
-		struct RenderWindowResources
-		{
-			IDirect3DSwapChain9* swapChain;	/**< Swap chain interface. */
-			UINT32 adapterOrdinalInGroupIndex; /**< Relative index of the render window in the group. */
-			UINT32 presentParametersIndex; /**< Index of present parameter in the shared array of the device. */
-			IDirect3DSurface9* backBuffer; /**< The back buffer of the render window. */
-			IDirect3DSurface9* depthBuffer;	/**< The depth buffer of the render window. */
-			D3DPRESENT_PARAMETERS presentParameters; /**< Present parameters of the render window. */
-			bool acquired; /**< True if resources acquired. */	
-		};
-
-	public:
-		D3D9Device(D3D9DeviceManager* deviceManager, UINT adapterNumber, HMONITOR hMonitor,
-			D3DDEVTYPE devType, DWORD behaviorFlags);
-		~D3D9Device();
-
-		/**
-		 * Attaches a new render window to this device. Caller must ensure the window is not attached to multiple devices.
-		 */
-		void attachRenderWindow(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Detaches the render window from this device. */
-		void detachRenderWindow(const D3D9RenderWindowCore* renderWindow);
-	
-		/**	Acquires the device. This will cause a device reset in case present parameters changed. */
-		bool acquire();
-		
-		/**	Release the device and all resources directly managed by it. */
-		void release();
-
-		/**	Destroys the device and all resources directly managed by it. */
-		void destroy();		
-		
-		/**	Checks is the device lost. If lost you will need to "acquire" the device. */
-		bool isDeviceLost();				
-		
-		/**	Return internal DX9 device object. */
-		IDirect3DDevice9* getD3D9Device() const;
-
-		/**
-		 * Returns adapter number this device is tied to. This number corresponds to the adapter index returned by DX9 API.
-		 */
-		UINT getAdapterNumber() const;
-
-		/**	Returns type of the device. */
-		D3DDEVTYPE getDeviceType() const;
-
-		/**	Checks is the device multihead (manages multiple full-screen outputs). */
-		bool isMultihead() const;					
-
-		/**	Returns true if depth/stencil format can be automatically determined. */
-		bool isAutoDepthStencil() const;
-		
-		/**	Returns DX9 device capabilities. */
-		const D3DCAPS9& getD3D9DeviceCaps() const;
-
-		/**	Returns DX9 format of the back buffer used by the primary window for this device. */
-		D3DFORMAT getBackBufferFormat() const;
-
-		/**	Returns DX9 format of the depth stencil buffer used by the primary window for this device. */
-		D3DFORMAT getDepthStencilFormat() const;
-
-		/**	Validates that the window is valid for this device. Will reset device if needed. */
-		bool validate(D3D9RenderWindowCore* renderWindow);
-
-		/**	Invalidates the window so on the next call to validate, the device will be re-acquired. */
-		void invalidate(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Swap back and front buffers for the specified window. */
-		void present(const D3D9RenderWindowCore* renderWindow);
-		
-		/**	Returns internal DX9 represention of the depth/stencil buffer. */
-		IDirect3DSurface9* getDepthBuffer(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Returns internal DX9 represention of the backbuffer. */
-		IDirect3DSurface9* getBackBuffer(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Sets adapter index for the specified window. */
-		void setAdapterOrdinalIndex(const D3D9RenderWindowCore* renderWindow, UINT32 adapterOrdinalInGroupIndex);
-
-		/**	Copies contents of the back or depth/stencil buffer in to the provided object. */
-		void copyContentsToMemory(const D3D9RenderWindowCore* window, PixelData &dst, RenderTargetCore::FrameBuffer buffer);
-
-		/**	Resets bound pipeline states/streams to null. */
-		void clearDeviceStreams();
-	
-	protected:
-		friend class D3D9DeviceManager;
-		friend class D3D9RenderAPI;
-
-		typedef Map<const D3D9RenderWindowCore*, RenderWindowResources*> RenderWindowToResorucesMap;
-		typedef RenderWindowToResorucesMap::iterator RenderWindowToResorucesIterator;
-
-		/**	Find iterator for the specified window in the render window resource list. */
-		RenderWindowToResorucesIterator getRenderWindowIterator(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Acquires the device for the provided render window. */
-		bool acquire(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Forcibly reset the device. */
-		bool reset();
-
-		/**	Update presentation parameters from the active render window. */
-		void updatePresentationParameters();
-
-		/**	Updates presentation parameter indices for all windows attached to this device. */
-		void updateRenderWindowsIndices();
-
-		/**	Creates a new DX9 device object. */
-		void createD3D9Device();
-
-		/**	Releases the DX9 device object. */
-		void releaseD3D9Device();
-
-		/**	Releases all render window resources in the provided object. */
-		void releaseRenderWindowResources(RenderWindowResources* renderWindowResources);
-
-		/**
-		 * Acquires all render window resources from the provided render window, and stores them in the provided render
-		 * window resources object.
-		 */
-		void acquireRenderWindowResources(RenderWindowToResorucesIterator it);
-
-		/**	Called when it has been detected that device has been lost. */
-		void notifyDeviceLost();
-
-		/**	Checks if focus window changed and should device be reacquired. */
-		void validateFocusWindow();
-
-		/**	Checks if back buffer size has changed and invalidates the window if it has. */
-		void validateBackBufferSize(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Checks if window monitor changed and re-links the window if needed. */
-		bool validateDisplayMonitor(D3D9RenderWindowCore* renderWindow);
-
-		/**	Checks if device has been lost or active window invalidated and acquires the device if needed. */
-		bool validateDeviceState(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Checks if the render window contains a custom swap chain. */
-		bool isSwapChainWindow(const D3D9RenderWindowCore* renderWindow);
-
-		/**	Returns primary window for this device. */
-		const D3D9RenderWindowCore*	getPrimaryWindow();
-
-		/**	Sets the shared window handle. */
-		void setSharedWindowHandle(HWND hSharedHWND);
-
-	protected:			
-		D3D9DeviceManager* mpDeviceManager;	/**< The manager of this device instance. */
-		IDirect3DDevice9* mpDevice;	/**< Will hold the device interface. */
-		UINT mAdapterNumber; /**< The adapter that this device belongs to. */
-		HMONITOR mMonitor; /**< The monitor that this device belongs to. */
-		D3DDEVTYPE mDeviceType; /**< Device type. */
-		static HWND	msSharedFocusWindow; /**< The shared focus window in case of multiple full screen render windows. */
-		HWND mFocusWindow; /**< The focus window this device attached to. */	
-		DWORD mBehaviorFlags; /**< The behavior of this device.	*/
-		
-		/** 
-		 * Presentation parameters which the device was created with. May be an array of presentation parameters in case of
-		 * multi-head device.
-		 */
-		D3DPRESENT_PARAMETERS* mPresentationParams;
-		UINT mPresentationParamsCount; /**< Number of presentation parameters elements.	 */
-		D3DCAPS9 mD3D9DeviceCaps; /**< Device caps. */
-		bool mD3D9DeviceCapsValid; /**< True if device caps initialized. */
-		D3DDEVICE_CREATION_PARAMETERS mCreationParams; /**< Creation parameters. */
-		bool mDeviceLost; /**< True if device entered lost state. */
-	
-		RenderWindowToResorucesMap mMapRenderWindowToResoruces;	/**< Map between render window to resources. */
-	};
-
-	/** @} */
-}

+ 0 - 66
Source/BansheeD3D9RenderAPI/Include/BsD3D9DeviceManager.h

@@ -1,66 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** Handles creation of DirectX 9 devices. Also links the devices with created render targets. */
-	class BS_D3D9_EXPORT D3D9DeviceManager
-	{	
-	public:
-		D3D9DeviceManager();
-		~D3D9DeviceManager();
-
-		/**	Changes the active device to the provided device. Must be not null. */
-		void setActiveDevice(D3D9Device* device);
-
-		/**	Retrieves the currently active device. */
-		D3D9Device*	getActiveDevice();
-
-		/**	Sets the device used by the currently active render target. */
-		void setActiveRenderTargetDevice(D3D9Device* device);
-
-		/**	Retrieves the device used by the currently active render target. */
-		D3D9Device*	getActiveRenderTargetDevice();		
-
-		/**	Returns the total number of devices available. */
-		UINT getDeviceCount();
-
-		/**	Returns the device under the specified index. */
-		D3D9Device*	getDevice(UINT index);
-
-		/**
-		 * Links the provided render window with a device. The window will be assigned an existing device if a match one
-		 * can be found, otherwise a new device will be created.
-		 */
-		void linkRenderWindow(D3D9RenderWindowCore* renderWindow);
-
-		/**	Called by the devices when they're are being destroyed. */
-		void notifyOnDeviceDestroy(D3D9Device* device);
-
-		/**	Retrieves engine device from DX9 device. */
-		D3D9Device*	getDeviceFromD3D9Device(IDirect3DDevice9* d3d9Device);
-
-	protected:
-		/**
-		 * Attempts to find a matching device for the provided render window. If one cannot be found a new device is
-		 * created. Found/created device is returned, as well as a list of all render windows using that device.
-		 */
-		D3D9Device*	selectDevice(D3D9RenderWindowCore* renderWindow, Vector<D3D9RenderWindowCore*>& renderWindowsGroup);
-
-		/**	Finds the driver the render window belongs to. */
-		D3D9Driver*	findDriver(D3D9RenderWindowCore* renderWindow);
-
-		Vector<D3D9Device*> mRenderDevices;
-		D3D9Device*	mActiveDevice;
-		D3D9Device*	mActiveRenderWindowDevice;		
-	};
-
-	/** @} */
-}

+ 0 - 47
Source/BansheeD3D9RenderAPI/Include/BsD3D9Driver.h

@@ -1,47 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	class D3D9VideoModeList;
-	class D3D9VideoMode;
-
-	/**	Holds data about a DX9 driver (adapter). */
-	class BS_D3D9_EXPORT D3D9Driver
-	{
-	public:
-		D3D9Driver();
-		D3D9Driver(const D3D9Driver &ob);
-		D3D9Driver(UINT32 adapterNumber, const D3DCAPS9& deviceCaps, const D3DADAPTER_IDENTIFIER9& adapterIdentifer);
-		~D3D9Driver();
-
-		/**	Returns hardware capabilities for this driver. */
-		const D3DCAPS9&	getD3D9DeviceCaps() const { return mD3D9DeviceCaps; }
-
-		/**	Returns name of the driver. */
-		String getDriverName() const;
-
-		/**	Returns description of the driver. */
-		String getDriverDescription() const;
-
-		/** Returns adapter number which corresponds to adapter number returned by DX9 API. */
-		UINT32 getAdapterNumber() const { return mAdapterNumber; }
-
-		/**	Returns DX9 adapter identifier. */
-		const D3DADAPTER_IDENTIFIER9& getAdapterIdentifier() const { return mAdapterIdentifier; }
-
-	private:				
-		UINT32 mAdapterNumber;
-		D3DCAPS9 mD3D9DeviceCaps;		
-		D3DADAPTER_IDENTIFIER9 mAdapterIdentifier;
-	};
-
-	/** @} */
-}

+ 0 - 39
Source/BansheeD3D9RenderAPI/Include/BsD3D9DriverList.h

@@ -1,39 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9Driver.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Holds a list of all drivers (adapters) and video modes. */
-	class BS_D3D9_EXPORT D3D9DriverList
-	{
-	public:
-		D3D9DriverList();
-		~D3D9DriverList();
-
-		/**	Returns the number of drivers (adapters) available. */
-		UINT32 count() const;
-
-		/**	Returns driver with the specified index. */
-		D3D9Driver* item(UINT32 index);
-
-		/**	Returns drivers with the specified name or null if it cannot be found. */
-		D3D9Driver* item(const String &name);
-
-		/**	Returns available video modes for all drivers and output devices. */
-		SPtr<VideoModeInfo> getVideoModeInfo() const { return mVideoModeInfo; }
-
-	private:
-		Vector<D3D9Driver> mDriverList;
-		SPtr<VideoModeInfo> mVideoModeInfo;
-	};
-
-	/** @} */
-}

+ 0 - 39
Source/BansheeD3D9RenderAPI/Include/BsD3D9EmulatedParamBlocks.h

@@ -1,39 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**
-	 * Represents a parameter block that can be used with GPU programs that do not support them natively. Each block is
-	 * defined with a unique name (user defined) and a set of parameter names belonging to that block (names must reference
-	 * actual GPU variables).
-	 */
-	struct D3D9EmulatedParamBlock
-	{
-		String blockName;
-		Vector<String> paramNames;
-	};
-
-	/**	Parses GPU program source and retrieves parameter blocks from it. */
-	class D3D9EmulatedParamBlockParser
-	{
-	public:
-		/**
-		 * Parses GPU program source and retrieves parameter blocks from it. Returns
-		 * source without parameter block code.
-		 *
-		 * Parameter blocks can be anywhere in the source file and they must follow this exact structure:
-		 *  BS_PARAM_BLOCK blockName { param1, param2, etc }
-		 */
-		static String parse(const String& gpuProgSource, Vector<D3D9EmulatedParamBlock>& paramBlocks);
-	};
-
-	/** @} */
-}

+ 0 - 54
Source/BansheeD3D9RenderAPI/Include/BsD3D9EventQuery.h

@@ -1,54 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9Resource.h"
-#include "BsEventQuery.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** @copydoc EventQuery */
-	class BS_D3D9_EXPORT D3D9EventQuery : public EventQuery, public D3D9Resource
-	{
-	public:
-		D3D9EventQuery();
-		~D3D9EventQuery();
-
-		/** @copydoc EventQuery::begin */
-		void begin() override;
-
-		/** @copydoc EventQuery::isReady */
-		bool isReady() const override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceLost */
-		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceReset */
-		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
-
-	private:
-		/**	Creates the internal DX9 query. */
-		void createQuery();
-
-		/**	Releases the internal DX9 query. */
-		void releaseQuery();
-
-	private:
-		bool mQueryIssued;
-		IDirect3DQuery9* mQuery;
-		IDirect3DDevice9* mDevice;
-	};
-
-	/** @} */
-}

+ 0 - 57
Source/BansheeD3D9RenderAPI/Include/BsD3D9GpuBuffer.h

@@ -1,57 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsGpuBuffer.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**
-	 * Represents a generic GPU buffer in DX9. This class is just a dummy in order to conform to the interface as DX9
-	 * supports no such buffers.
-	 */
-	class BS_D3D9_EXPORT D3D9GpuBufferCore : public GpuBufferCore
-	{
-	public:
-		~D3D9GpuBufferCore();
-
-		/** @copydoc GpuBufferCore::lock */
-		void* lock(UINT32 offset, UINT32 length, GpuLockOptions options) override;
-
-		/** @copydoc GpuBufferCore::unlock */
-		void unlock() override;
-
-		/** @copydoc GpuBufferCore::readData */
-        void readData(UINT32 offset, UINT32 length, void* pDest) override;
-
-		/** @copydoc GpuBufferCore::writeData */
-        void writeData(UINT32 offset, UINT32 length, const void* pSource,
-				BufferWriteType writeFlags = BufferWriteType::Normal) override;
-
-		/** @copydoc GpuBufferCore::copyData */
-		void copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
-			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false) override;
-
-	protected:
-		friend class D3D9HardwareBufferCoreManager;
-
-		D3D9GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferFormat format, 
-			GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
-
-		/** @copydoc GpuBufferCore::createView */
-		GpuBufferView* createView() override;
-
-		/** @copydoc GpuBufferCore::destroyView */
-		void destroyView(GpuBufferView* view) override;
-
-		/** @copydoc GpuBufferCore::initialize */
-		void initialize() override;	
-	};
-
-	/** @} */
-}

+ 0 - 114
Source/BansheeD3D9RenderAPI/Include/BsD3D9GpuProgram.h

@@ -1,114 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsGpuProgram.h"
-#include "BsD3D9Resource.h"
-#include "BsD3D9EmulatedParamBlocks.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Available optimization levels when compiling a GPU program. */
-	enum OptimizationLevel
-	{
-		OPT_DEFAULT,
-		OPT_NONE,
-		OPT_0,
-		OPT_1,
-		OPT_2,
-		OPT_3
-	};
-
-	/**	DirectX 9 implementation of a GPU program. */
-    class BS_D3D9_EXPORT D3D9GpuProgramCore : public GpuProgramCore, public D3D9Resource
-    {   
-    public:
-		virtual ~D3D9GpuProgramCore();
-
-		/**	Sets the preprocessor defines use to compile the program. */
-		void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
-
-		/**	Sets optimization level to use when compiling the shader. */
-		void setOptimizationLevel(OptimizationLevel opt) { mOptimisationLevel = opt; }
-
-    protected:
-		friend class D3D9HLSLProgramFactory;
-
-		D3D9GpuProgramCore(const String& source, const String& entryPoint,
-			GpuProgramType gptype, GpuProgramProfile profile);
-
-		/** @copydoc GpuProgramCore::initialize */
-		void initialize() override;
-      
-		/**	Loads the GPU program from compiled microcode. */
-        virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
-
-	protected:    
-		OptimizationLevel mOptimisationLevel;
-		String mPreprocessorDefines;
-		Vector<D3D9EmulatedParamBlock> mBlocks;
-		bool mColumnMajorMatrices;
-		ID3DXBuffer* mMicrocode;
-    };
-
-	/**	DirectX 9 implementation of a vertex GPU program. */
-    class BS_D3D9_EXPORT D3D9GpuVertexProgramCore : public D3D9GpuProgramCore
-    {  
-    public:
-		~D3D9GpuVertexProgramCore();
-        
-		/**	Returns internal DX9 vertex shader object. */
-        IDirect3DVertexShader9* getVertexShader();
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-    protected:
-		friend class D3D9HLSLProgramFactory;
-
-		D3D9GpuVertexProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
-
-		/** @copydoc D3D9GpuProgramCore::loadFromMicrocode */
-		void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) override;
-
-	protected:
-		Map<IDirect3DDevice9*, IDirect3DVertexShader9*>	mMapDeviceToVertexShader;
-    };
-
-    /** Direct3D implementation of low-level fragment programs. */
-    class BS_D3D9_EXPORT D3D9GpuFragmentProgramCore : public D3D9GpuProgramCore
-    {  
-    public:
-		~D3D9GpuFragmentProgramCore();
-
-		/**	Returns internal DX9 pixel shader object. */
-        IDirect3DPixelShader9* getPixelShader();
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-    protected:
-		friend class D3D9HLSLProgramFactory;
-
-		D3D9GpuFragmentProgramCore(const String& source, const String& entryPoint, GpuProgramProfile profile);
-
-		/** @copydoc D3D9GpuProgramCore::loadFromMicrocode */
-		void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) override;
-
-	protected:
-		Map<IDirect3DDevice9*, IDirect3DPixelShader9*> mMapDeviceToPixelShader;
-    };
-
-	/** @} */
-}

+ 0 - 373
Source/BansheeD3D9RenderAPI/Include/BsD3D9HLSLParamParser.h

@@ -1,373 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9GpuProgram.h"
-#include "BsGpuParamDesc.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**
-	 * Helper class that parses GPU program constant table and returns parameters used by the program, as well as their
-	 * type, size and other information.
-	 */
-	class D3D9HLSLParamParser
-	{
-	public:
-		/**
-		 * Initializes the parameter parser with the specified constant table, and an optional list of parameter blocks.
-		 * DirectX 9 does not support parameter blocks internally, but we can emulate the functionality by providing a list
-		 * of user-defined blocks and the parameters they contain.
-		 */
-		D3D9HLSLParamParser(LPD3DXCONSTANTTABLE constTable, const Vector<D3D9EmulatedParamBlock>& blocks)
-			:mpConstTable(constTable), mBlocks(blocks)
-		{ }
-
-		/**	Builds parameter descriptions and returns an object containing all relevant information. */
-		SPtr<GpuParamDesc> buildParameterDescriptions();
-
-	private:
-		/**
-		 * Determines information about the specified parameter and places it in the provided parameter block, as well as
-		 * any children of the parameter.
-		 *
-		 * @param[in]	blockDesc	Parent block into which to add the new parameter.
-		 * @param[in]	paramName	Name of the parameter.
-		 * @param[in]	constant	Parameter handle in the constant table.
-		 * @param[in]	prefix		Prefix to append to the parameter and any child parameters.	
-		 */
-		void processParameter(GpuParamBlockDesc& blockDesc, const String& paramName, D3DXHANDLE constant, String prefix);
-
-		/**
-		 * Populates information about the parameter in @p memberDesc from the data in d3dDesc. Esentially converts DX9
-		 * parameter data to engine data.
-		 */
-		void populateParamMemberDesc(GpuParamDataDesc& memberDesc, D3DXCONSTANT_DESC& d3dDesc);
-
-		/**	Returns the name of the parameter with the specified constant table handle. */
-		String getParamName(D3DXHANDLE constant);
-
-	private:
-		LPD3DXCONSTANTTABLE mpConstTable;
-		Vector<D3D9EmulatedParamBlock> mBlocks;
-		SPtr<GpuParamDesc> mParamDesc;
-	};
-
-	String D3D9HLSLParamParser::getParamName(D3DXHANDLE constant)
-	{
-		D3DXCONSTANT_DESC desc;
-		UINT32 numParams = 1;
-		HRESULT hr = mpConstTable->GetConstantDesc(constant, &desc, &numParams);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(InternalErrorException, "Cannot retrieve constant description from HLSL program.");
-		}
-
-		String paramName = desc.Name;
-		// trim the odd '$' which appears at the start of the names in HLSL
-		if (paramName.at(0) == '$')
-			paramName.erase(paramName.begin());
-
-		// Also trim the '[0]' suffix if it exists, we will add our own indexing later
-		if (StringUtil::endsWith(paramName, "[0]", false))
-			paramName.erase(paramName.size() - 3);
-
-		return paramName;
-	}
-
-	SPtr<GpuParamDesc> D3D9HLSLParamParser::buildParameterDescriptions()
-	{
-		// Derive parameter names from const table
-		assert(mpConstTable && "Program not loaded!");
-
-		mParamDesc = bs_shared_ptr_new<GpuParamDesc>();
-
-		// Get contents of the constant table
-		D3DXCONSTANTTABLE_DESC desc;
-		HRESULT hr = mpConstTable->GetDesc(&desc);
-
-		if (FAILED(hr))
-			BS_EXCEPT(InternalErrorException, "Cannot retrieve constant descriptions from HLSL program.");
-
-		// DX9 has no concept of parameter blocks so we emulate them if needed
-		String name = "BS_INTERNAL_Globals";
-		mParamDesc->paramBlocks.insert(std::make_pair(name, GpuParamBlockDesc()));
-		GpuParamBlockDesc& globalBlockDesc = mParamDesc->paramBlocks[name];
-		globalBlockDesc.name = name;
-		globalBlockDesc.slot = 0;
-		globalBlockDesc.blockSize = 0;
-		globalBlockDesc.isShareable = false;
-
-		UnorderedMap<String, String> nonGlobalBlocks;
-		UINT32 curSlot = 1;
-		for (auto& block : mBlocks)
-		{
-			mParamDesc->paramBlocks.insert(std::make_pair(block.blockName, GpuParamBlockDesc()));
-			GpuParamBlockDesc& blockDesc = mParamDesc->paramBlocks[block.blockName];
-			blockDesc.name = block.blockName;
-			blockDesc.slot = curSlot++;
-			blockDesc.blockSize = 0;
-			blockDesc.isShareable = true;
-
-			for (auto& fieldName : block.paramNames)
-			{
-				nonGlobalBlocks.insert(std::make_pair(fieldName, block.blockName));
-			}
-		}
-
-		// Iterate over the constants
-		for (UINT32 i = 0; i < desc.Constants; ++i)
-		{
-			D3DXHANDLE constantHandle = mpConstTable->GetConstant(NULL, i);
-			String paramName = getParamName(constantHandle);
-
-			// Recursively descend through the structure levels
-			auto findIter = nonGlobalBlocks.find(paramName);
-			if (findIter == nonGlobalBlocks.end())
-				processParameter(globalBlockDesc, paramName, constantHandle, "");
-			else
-				processParameter(mParamDesc->paramBlocks[findIter->second], paramName, constantHandle, "");
-		}
-
-		return mParamDesc;
-	}
-
-	void D3D9HLSLParamParser::processParameter(GpuParamBlockDesc& blockDesc, const String& paramName, D3DXHANDLE constant, String prefix)
-	{
-		// Since D3D HLSL doesn't deal with naming of array and struct parameters
-		// automatically, we have to do it by hand
-
-		D3DXCONSTANT_DESC desc;
-		UINT32 numParams = 1;
-		HRESULT hr = mpConstTable->GetConstantDesc(constant, &desc, &numParams);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(InternalErrorException, "Cannot retrieve constant description from HLSL program.");
-		}
-
-		if (desc.Class == D3DXPC_STRUCT)
-		{
-			// work out a new prefix for nested members, if it's an array, we need an index
-			prefix = prefix + paramName + ".";
-			// Cascade into struct
-			for (UINT32 i = 0; i < desc.StructMembers; ++i)
-			{
-				D3DXHANDLE childHandle = mpConstTable->GetConstant(constant, i);
-				String childParamName = getParamName(childHandle);
-
-				processParameter(blockDesc, childParamName, childHandle, prefix);
-			}
-		}
-		else
-		{
-			// Process params
-			if (desc.Type == D3DXPT_FLOAT || desc.Type == D3DXPT_INT || desc.Type == D3DXPT_BOOL)
-			{
-				GpuParamDataDesc memberDesc;
-				memberDesc.gpuMemOffset = desc.RegisterIndex;
-				memberDesc.cpuMemOffset = blockDesc.blockSize;
-				memberDesc.paramBlockSlot = blockDesc.slot;
-				memberDesc.arraySize = 1;
-
-				String name = prefix + paramName;
-				memberDesc.name = name;
-
-				populateParamMemberDesc(memberDesc, desc);
-				mParamDesc->params.insert(std::make_pair(name, memberDesc));
-
-				blockDesc.blockSize += memberDesc.arrayElementStride * memberDesc.arraySize;
-			}
-			else if(desc.Type == D3DXPT_SAMPLER1D || desc.Type == D3DXPT_SAMPLER2D || desc.Type == D3DXPT_SAMPLER3D || desc.Type == D3DXPT_SAMPLERCUBE)
-			{
-				GpuParamObjectDesc samplerDesc;
-				samplerDesc.name = paramName;
-				samplerDesc.slot = desc.RegisterIndex;
-
-				GpuParamObjectDesc textureDesc;
-				textureDesc.name = paramName;
-				textureDesc.slot = desc.RegisterIndex;
-
-				switch(desc.Type)
-				{
-				case D3DXPT_SAMPLER1D:
-					samplerDesc.type = GPOT_SAMPLER1D;
-					textureDesc.type = GPOT_TEXTURE1D;
-					break;
-				case D3DXPT_SAMPLER2D:
-					samplerDesc.type = GPOT_SAMPLER2D;
-					textureDesc.type = GPOT_TEXTURE2D;
-					break;
-				case D3DXPT_SAMPLER3D:
-					samplerDesc.type = GPOT_SAMPLER3D;
-					textureDesc.type = GPOT_TEXTURE3D;
-					break;
-				case D3DXPT_SAMPLERCUBE:
-					samplerDesc.type = GPOT_SAMPLERCUBE;
-					textureDesc.type = GPOT_TEXTURECUBE;
-					break;
-				default:
-					BS_EXCEPT(InternalErrorException, "Invalid sampler type: " + toString(desc.Type) + " for parameter " + paramName);
-				}
-
-				mParamDesc->samplers.insert(std::make_pair(paramName, samplerDesc));
-				mParamDesc->textures.insert(std::make_pair(paramName, textureDesc));
-			}
-			else
-			{
-				BS_EXCEPT(InternalErrorException, "Invalid shader parameter type: " + toString(desc.Type) + " for parameter " + paramName);
-			}
-		}
-	}
-
-	void D3D9HLSLParamParser::populateParamMemberDesc(GpuParamDataDesc& memberDesc, D3DXCONSTANT_DESC& d3dDesc)
-	{
-		memberDesc.arraySize = d3dDesc.Elements;
-		switch(d3dDesc.Type)
-		{
-		case D3DXPT_INT:
-			switch(d3dDesc.Columns)
-			{
-			case 1:
-				memberDesc.type = GPDT_INT1;
-				break;
-			case 2:
-				memberDesc.type = GPDT_INT2;
-				break;
-			case 3:
-				memberDesc.type = GPDT_INT3;
-				break;
-			case 4:
-				memberDesc.type = GPDT_INT4;
-				break;
-			} 
-
-			memberDesc.elementSize = 4;
-			memberDesc.arrayElementStride = 4;
-
-			break;
-		case D3DXPT_FLOAT:
-			switch(d3dDesc.Class)
-			{
-			case D3DXPC_MATRIX_COLUMNS:
-			case D3DXPC_MATRIX_ROWS:
-				{
-					int firstDim, secondDim;
-					int firstActualDim; // Actual size might be less than requested because of optimization, we need to know both
-					firstActualDim = d3dDesc.RegisterCount / d3dDesc.Elements;
-
-					if (d3dDesc.Class == D3DXPC_MATRIX_ROWS)
-					{
-						firstDim = d3dDesc.Rows;
-						secondDim = d3dDesc.Columns;
-					}
-					else
-					{
-						firstDim = d3dDesc.Columns;
-						secondDim = d3dDesc.Rows;
-					}
-
-					switch (firstActualDim)
-					{
-					case 2:
-						memberDesc.elementSize = 8; // HLSL always padds regardless of row size
-						memberDesc.arrayElementStride = 8;
-						break;
-					case 3:
-						memberDesc.elementSize = 12; // HLSL always padds regardless of row size
-						memberDesc.arrayElementStride = 12;
-						break;
-					case 4:
-						memberDesc.elementSize = 16; // HLSL always padds regardless of row size
-						memberDesc.arrayElementStride = 16;
-						break;
-
-					}
-
-					switch (firstDim)
-					{
-					case 2:
-						switch (secondDim)
-						{
-						case 2:
-							memberDesc.type = GPDT_MATRIX_2X2;
-							break;
-						case 3:
-							memberDesc.type = GPDT_MATRIX_2X3;
-							break;
-						case 4:
-							memberDesc.type = GPDT_MATRIX_2X4;
-							break;
-						} 
-						break;
-					case 3:
-						switch (secondDim)
-						{
-						case 2:
-							memberDesc.type = GPDT_MATRIX_3X2;
-							break;
-						case 3:
-							memberDesc.type = GPDT_MATRIX_3X3;
-							break;
-						case 4:
-							memberDesc.type = GPDT_MATRIX_3X4;
-							break;
-						} 
-						break;
-					case 4:
-						switch (secondDim)
-						{
-						case 2:
-							memberDesc.type = GPDT_MATRIX_4X2;
-							break;
-						case 3:
-							memberDesc.type = GPDT_MATRIX_4X3;
-							break;
-						case 4:
-							memberDesc.type = GPDT_MATRIX_4X4;
-							break;
-						}
-						break;
-					}
-				}
-				break;
-			case D3DXPC_SCALAR:
-			case D3DXPC_VECTOR:
-				switch(d3dDesc.Columns)
-				{
-				case 1:
-					memberDesc.type = GPDT_FLOAT1;
-					break;
-				case 2:
-					memberDesc.type = GPDT_FLOAT2;
-					break;
-				case 3:
-					memberDesc.type = GPDT_FLOAT3;
-					break;
-				case 4:
-					memberDesc.type = GPDT_FLOAT4;
-					break;
-				}
-
-				memberDesc.elementSize = 4;
-				memberDesc.arrayElementStride = 4;
-
-				break;
-			}
-			break;
-		case D3DXPT_BOOL:
-			memberDesc.type = GPDT_BOOL;
-			memberDesc.elementSize = 4;
-			memberDesc.arrayElementStride = 4;
-			break;
-		default:
-			break;
-		};
-	}
-
-	/** @} */
-}

+ 0 - 38
Source/BansheeD3D9RenderAPI/Include/BsD3D9HLSLProgramFactory.h

@@ -1,38 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsGpuProgramManager.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Handles creation of HLSL GPU programs. */
-    class BS_D3D9_EXPORT D3D9HLSLProgramFactory : public GpuProgramFactory
-    {
-    public:
-        D3D9HLSLProgramFactory();
-        ~D3D9HLSLProgramFactory();
-
-		/** @copydoc GpuProgramFactory::getLanguage */
-		const String& getLanguage() const override;
-
-		/**
-		 * @copydoc	GpuProgramFactory::create(const String&, const String&, GpuProgramType, GpuProgramProfile, bool)
-		 */
-        SPtr<GpuProgramCore> create(const String& source, const String& entryPoint, GpuProgramType gptype, 
-			GpuProgramProfile profile, bool requiresAdjacency) override;
-
-		/** @copydoc	GpuProgramFactory::create(GpuProgramType) */
-		SPtr<GpuProgramCore> create(GpuProgramType type) override;
-
-	protected:
-		static String LANGUAGE_NAME;
-    };
-
-	/** @} */
-}

+ 0 - 36
Source/BansheeD3D9RenderAPI/Include/BsD3D9HardwareBufferManager.h

@@ -1,36 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsHardwareBufferManager.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Manages creation of DX9 hardware buffers. */
-    class BS_D3D9_EXPORT D3D9HardwareBufferCoreManager : public HardwareBufferCoreManager
-    {
-	protected:     
-		/** @copydoc HardwareBufferCoreManager::createVertexBufferInternal */
-		SPtr<VertexBufferCore> createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) override;
-
-		/** @copydoc HardwareBufferCoreManager::createIndexBufferInternal */
-		SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndices, GpuBufferUsage usage) override;
-
-		/** @copydoc	HardwareBufferCoreManager::createVertexDeclarationInternal */
-		SPtr<VertexDeclarationCore> createVertexDeclarationInternal(const List<VertexElement>& elements) override;
-
-		/** @copydoc HardwareBufferCoreManager::createGpuParamBlockBufferInternal */
-		SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC) override;
-
-		/** @copydoc HardwareBufferCoreManager::createGpuBufferInternal */
-		SPtr<GpuBufferCore> createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, 
-			GpuBufferFormat format, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false) override;
-    };
-
-	/** @} */
-}

+ 0 - 78
Source/BansheeD3D9RenderAPI/Include/BsD3D9IndexBuffer.h

@@ -1,78 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsIndexBuffer.h"
-#include "BsD3D9Resource.h"
-
-namespace BansheeEngine 
-{ 
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	DirectX 9 implementation of an index buffer. */
-    class BS_D3D9_EXPORT D3D9IndexBufferCore : public IndexBufferCore, public D3D9Resource
-    {
-	protected:
-		/**	Container for internal buffer resources. */
-		struct BufferResources
-		{
-			IDirect3DIndexBuffer9* mBuffer;
-			bool mOutOfDate;
-			UINT32 mLockOffset;
-			UINT32 mLockLength;
-			GpuLockOptions mLockOptions;
-		};
-
-    public:
-		D3D9IndexBufferCore(IndexType idxType, UINT32 numIndices, GpuBufferUsage usage);
-		~D3D9IndexBufferCore();
-
-		/** @copydoc IndexBufferCore::readData */
-        void readData(UINT32 offset, UINT32 length, void* dest) override;
-
-		/** @copydoc IndexBufferCore::writeData */
-		void writeData(UINT32 offset, UINT32 length, const void* source, 
-			BufferWriteType writeFlags = BufferWriteType::Normal) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceLost */
-		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceReset */
-		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
-
-		/**	Creates a DX9 index buffer object in the provided memory pool. */
-		void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool);
-	
-		/**	Returns the DX9 index buffer object. */
-        IDirect3DIndexBuffer9* getD3DIndexBuffer();		
-
-	protected:
-		/** @copydoc IndexBufferCore::lockImpl */
-		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options) override;
-
-		/** @copydoc IndexBufferCore::unlockImpl */
-		void unlockImpl() override;
-
-		/**	Updates buffer resources from cached system memory buffer. */
-		bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);
-
-		/** @copydoc IndexBufferCore::initialize */
-		void initialize() override;
-		
-	protected:		
-		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
-		D3DINDEXBUFFER_DESC	mBufferDesc;	
-		UINT8* mSystemMemoryBuffer;
-    };
-
-	/** @} */
-}

+ 0 - 103
Source/BansheeD3D9RenderAPI/Include/BsD3D9Mappings.h

@@ -1,103 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsRenderAPI.h"
-#include "BsHardwareBuffer.h"
-#include "BsIndexBuffer.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Provides helper methods for mapping between engine and DirectX 9 types. */
-	class BS_D3D9_EXPORT D3D9Mappings
-	{
-	public:
-		/**	DirectX 9 texture types. */
-		enum D3DTexType
-		{
-			D3D_TEX_TYPE_NORMAL,
-			D3D_TEX_TYPE_CUBE,
-			D3D_TEX_TYPE_VOLUME,
-			D3D_TEX_TYPE_NONE
-		};
-
-		/** Returns DirectX 9 texture addressing mode. Returns exact mode if supported, or nearest available if not. */
-		static D3DTEXTUREADDRESS get(TextureAddressingMode tam, const D3DCAPS9& devCaps);
-
-		/**	Returns DirectX 9 blend factor. */
-		static D3DBLEND get(BlendFactor sbf);
-
-		/**	Returns DirectX 9 blend operation. */
-		static D3DBLENDOP get(BlendOperation sbo);
-
-		/**	Return DirectX 9 compare function. */
-		static DWORD get(CompareFunction cf);
-
-		/** Returns DirectX 9 culling mode. Optionally flip the mode so that engine CCW is DX9 CW and reverse. */
-		static DWORD get(CullingMode cm, bool flip);
-
-		/**	Return DirectX 9 fill mode depending on provided polygon mode. */
-		static D3DFILLMODE get(PolygonMode level);
-
-		/** Return DirectX 9 stencil operation and optionally invert it (greater than becomes less than, etc.). */
-		static DWORD get(StencilOperation op, bool invert = false);
-
-		/**	Returns DirectX 9 sampler state based on provided filter type. */
-		static D3DSAMPLERSTATETYPE get(FilterType ft);
-
-		/**
-		 * Returns a DirectX 9 texture filter type based on provided filter type, options and texture type. If wanted
-		 * filter type is not available closest type will be returned.
-		 */
-		static DWORD get(FilterType ft, FilterOptions fo, const D3DCAPS9& devCaps, D3DTexType texType);
-		
-		/**	Returns DirectX 9 texture type. */
-		static D3DTexType get(TextureType textype);
-        
-		/**	Return DirectX 9 buffer usage. */
-        static DWORD get(GpuBufferUsage usage);
-        
-		/**	Returns DirectX 9 lock options, constrained by the provided usage. */
-        static DWORD get(GpuLockOptions options, GpuBufferUsage usage);
-        
-		/**	Returns DirectX 9 index buffer type. */
-        static D3DFORMAT get(IndexType itype);
-		
-		/**	Returns DirectX 9 vertex element type. */
-		static D3DDECLTYPE get(VertexElementType vType);
-
-		/**	Returns DirectX9 vertex element semantic. */
-		static D3DDECLUSAGE get(VertexElementSemantic sem);
-        
-		/**	Converts DirectX9 vertex element semantic to engine vertex element semantic. */
-		static VertexElementSemantic get(D3DDECLUSAGE sem);
-
-		/**	Converts a matrix to one usable by DirectX 9 API. */
-        static 	D3DXMATRIX makeD3DXMatrix(const Matrix4& mat);
-        
-		/**	Converts matrix returned by DirectX 9 API to engine matrix. */
-        static Matrix4 convertD3DXMatrix(const D3DXMATRIX& mat);
-
-		/**	Converts DirectX 9 pixel format to engine pixel format. */
-		static PixelFormat _getPF(D3DFORMAT d3dPF);
-		
-		/**	Converts engine pixel format to DirectX 9 pixel format. */
-		static D3DFORMAT _getPF(PixelFormat pf);
-
-		/**	Returns closest pixel format supported by DirectX 9. */
-		static PixelFormat _getClosestSupportedPF(PixelFormat pf);
-
-		/**	Returns closest color render target pixel format supported by DirectX 9. */
-		static PixelFormat _getClosestSupportedRenderTargetPF(PixelFormat pf);
-
-		/**	Returns closest depth/stencil format supported by DirectX 9. */
-		static PixelFormat _getClosestSupportedDepthStencilPF(PixelFormat pf);
-	};
-
-	/** @} */
-}

+ 0 - 67
Source/BansheeD3D9RenderAPI/Include/BsD3D9MultiRenderTexture.h

@@ -1,67 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsMultiRenderTexture.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	class D3D9MultiRenderTexture;
-
-	/**
-	 * DirectX 9 implementation of a render texture with multiple color surfaces.
-	 *
-	 * @note	Core thread only.
-	 */
-	class BS_D3D9_EXPORT D3D9MultiRenderTextureCore : public MultiRenderTextureCore
-	{
-	public:
-		D3D9MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
-		virtual ~D3D9MultiRenderTextureCore();
-		
-		/** @copydoc MultiRenderTextureCore::getCustomAttribute */
-		void getCustomAttribute(const String& name, void* pData) const override;
-
-	protected:
-		friend class D3D9MultiRenderTexture;
-
-		/** @copydoc CoreObjectCore::initialize */
-		void initialize() override;
-
-		/** @copydoc MultiRenderTextureCore::getProperties */
-		const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
-
-		Vector<IDirect3DSurface9*> mDX9ColorSurfaces;
-		IDirect3DSurface9* mDX9DepthStencilSurface;
-
-		MultiRenderTextureProperties mProperties;
-	};
-
-	/**
-	 * DirectX 9 implementation of a render texture with multiple color surfaces.
-	 *
-	 * @note	Sim thread only.
-	 */
-	class BS_D3D9_EXPORT D3D9MultiRenderTexture : public MultiRenderTexture
-	{
-	public:
-		virtual ~D3D9MultiRenderTexture() { }
-
-	protected:
-		friend class D3D9TextureManager;
-
-		D3D9MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
-
-		/** @copydoc MultiRenderTexture::getProperties */
-		const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
-
-		MultiRenderTextureProperties mProperties;
-	};
-
-	/** @} */
-}

+ 0 - 67
Source/BansheeD3D9RenderAPI/Include/BsD3D9OcclusionQuery.h

@@ -1,67 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9Resource.h"
-#include "BsOcclusionQuery.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** @copydoc OcclusionQuery */
-	class BS_D3D9_EXPORT D3D9OcclusionQuery : public OcclusionQuery, public D3D9Resource
-	{
-	public:
-		D3D9OcclusionQuery(bool binary);
-		~D3D9OcclusionQuery();
-
-		/** @copydoc OcclusionQuery::begin */
-		void begin() override;
-
-		/** @copydoc OcclusionQuery::end */
-		void end() override;
-
-		/** @copydoc OcclusionQuery::isReady */
-		bool isReady() const override;
-
-		/** @copydoc OcclusionQuery::getNumSamples */
-		UINT32 getNumSamples() override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceLost */
-		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceReset */
-		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
-
-	private:
-		friend class QueryManager;
-
-		/**	Creates the internal DX9 query. */
-		void createQuery();
-
-		/**	Releases the internal DX9 query. */
-		void releaseQuery();
-
-		/**	Resolves query results after it is ready. */
-		void finalize();
-	private:
-		IDirect3DDevice9* mDevice;
-		IDirect3DQuery9* mQuery;
-		bool mQueryIssued;
-		bool mFinalized;
-
-		UINT32 mNumSamples;
-	};
-
-	/** @} */
-}

+ 0 - 119
Source/BansheeD3D9RenderAPI/Include/BsD3D9PixelBuffer.h

@@ -1,119 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsPixelBuffer.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** DirectX9 implementation of a pixel buffer. Represents a hardware buffer containing a surface of pixels. */
-	class BS_D3D9_EXPORT D3D9PixelBuffer : public PixelBuffer
-	{
-	protected:
-		/**	Internal DX9 buffer resources container. */
-		struct BufferResources
-		{
-			IDirect3DSurface9* surface;
-			IDirect3DVolume9* volume;
-			IDirect3DSurface9* tempSurface;
-			IDirect3DVolume9* tempVolume;
-			IDirect3DBaseTexture9* mipTex;
-		};
-
-	public:
-		D3D9PixelBuffer(GpuBufferUsage usage, D3D9TextureCore* ownerTexture);
-		~D3D9PixelBuffer();
-
-		/**
-		 * Binds the specified surface object to this buffer. This needs to be called in order to initialize the pixel
-		 * buffer.
-		 *
-		 * @param[in]	dev			Device the surface was created on.
-		 * @param[in]	surface		DirectX 9 object representing the surface.
-		 * @param[in]	mipTex		Base texture that will be used for generating mipmaps. Usually the parent texture of
-		 *							the surface.
-		 */
-		void bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, IDirect3DBaseTexture9* mipTex);
-
-		/**
-		 * Binds the specified volume object to this buffer. This needs to be called in order to initialize the pixel
-		 * buffer.
-		 *
-		 * @param[in]	dev			Device the volume was created on.
-		 * @param[in]	volume		DirectX 9 object representing the volume.
-		 * @param[in]	mipTex		Base texture that will be used for generating mipmaps. Usually the parent texture of
-		 *							the volume.
-		 */
-		void bind(IDirect3DDevice9* dev, IDirect3DVolume9* volume, IDirect3DBaseTexture9* mipTex);
-
-		/**
-		 * Enables/disabled automatic mipmap generation on updates.
-		 *
-		 * @param[in]	doMipmapGen	If true, mipmaps will be regenerated whenever data is written to the buffer.
-		 * @param[in]	HWMipmaps	If true the mipmaps will be generated by the hardware, otherwise software (slower).
-		 */
-		void setMipmapping(bool doMipmapGen, bool HWMipmaps);
-
-		/**	Returns internal DirectX 9 surface object for this buffer. */
-		IDirect3DSurface9* getSurface(IDirect3DDevice9* d3d9Device);
-
-		/**	Release all surface objects held by this buffer for the specified device. */
-		void releaseSurfaces(IDirect3DDevice9* d3d9Device);
-
-		/**	Destroy all resources associated with the specified device. */
-		void destroyBufferResources(IDirect3DDevice9* d3d9Device);
-
-		/**	Called when device state is changing. Access to any device should be locked. */
-		static void lockDeviceAccess();
-
-		/**	Called when device state change completed. Access to any device is allowed. */
-		static void unlockDeviceAccess();
-
-		/**	Initializes the provided pixel data buffer with information provided in the D3D9 locked rectangle. */
-		static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_RECT& lrect);
-
-		/**	Initializes the provided pixel data buffer with information provided in the D3D9 locked box. */
-		static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_BOX& lrect);
-
-	protected:
-		/** @copydoc PixelBuffer::lockImpl */
-		PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) override;
-
-		/** @copydoc PixelBuffer::unlockImpl */
-		void unlockImpl() override;
-
-		/**
-		 * Locks the specified volume of the provided buffer objects and returns a data buffer that you may use to access
-		 * it.
-		 */
-		PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
-
-		/**	Unlocks the specified buffer objects. */
-		void unlockBuffer(BufferResources* bufferResources);
-
-		/**	Generates mip-map chain for the specified texture. */
-		void genMipmaps(IDirect3DBaseTexture9* mipTex);
-
-		/** Retrieves buffer resources for the specified device, or null if they do not exist. */
-		BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
-
-		/**	Creates a new empty set of buffer resources. */
-		BufferResources* createBufferResources();
-
-	protected:
-		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
-
-		bool mDoMipmapGen;
-		bool mHWMipmaps;
-
-		D3D9TextureCore* mOwnerTexture;
-		DWORD mLockFlags;
-	};
-
-	/** @} */
-};

+ 0 - 86
Source/BansheeD3D9RenderAPI/Include/BsD3D9Prerequisites.h

@@ -1,86 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsCorePrerequisites.h"
-
-#define D3D9_DEVICE_ACCESS_LOCK	
-#define D3D9_DEVICE_ACCESS_UNLOCK
-#define D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-#define DIRECT3D_VERSION 0x0900
-
-#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
-
-#if BS_DEBUG_MODE
-#	define D3D_DEBUG_INFO
-#endif
-
-#define WIN32_LEAN_AND_MEAN
-#if !defined(NOMINMAX) && defined(_MSC_VER)
-#	define NOMINMAX // required to stop windows.h messing up std::min
-#endif
-
-#include <d3d9.h>
-#include <d3dx9.h>
-#include <DxErr.h>
-
-/** @addtogroup Plugins
- *  @{
- */
-
-/** @defgroup D3D9 BansheeD3D9RenderAPI
- *	Wrapper around the DirectX 9 render API.
- */
-
-/** @} */
-
-namespace BansheeEngine
-{
-	// Predefine classes
-	class D3D9RenderAPI;
-	class D3D9RenderWindow;
-	class D3D9RenderWindowCore;
-	class D3D9TextureCore;
-	class D3D9TextureManager;
-	class D3D9Driver;
-	class D3D9DriverList;
-	class D3D9VideoMode;
-	class D3D9VideoModeList;
-	class D3D9Device;
-	class D3D9DeviceManager;
-	class D3D9ResourceManager;
-	class D3D9GpuProgram;
-	class D3D9GpuProgramManager;
-    class D3D9IndexBuffer;
-    class D3D9HLSLProgramFactory;
-    class D3D9HLSLProgramCore;
-    class D3D9VertexDeclarationCore;
-	class D3D9Resource;
-
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	DirectX 9 specific types to track resource statistics for. */
-	enum D3D9RenderStatResourceType
-	{
-		RenderStatObject_VertexDeclaration = 100
-	};
-
-	/** @} */
-
-#if (BS_PLATFORM == BS_PLATFORM_WIN32) && !defined(BS_STATIC_LIB)
-#	ifdef BS_RSD3D9_EXPORTS
-#		define BS_D3D9_EXPORT __declspec(dllexport)
-#	else
-#       if defined( __MINGW32__ )
-#           define BS_D3D9_EXPORT
-#       else
-#    		define BS_D3D9_EXPORT __declspec(dllimport)
-#       endif
-#	endif
-#else
-#	define BS_D3D9_EXPORT
-#endif
-}

+ 0 - 29
Source/BansheeD3D9RenderAPI/Include/BsD3D9QueryManager.h

@@ -1,29 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsQueryManager.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Handles creation of DirectX 9 queries. */
-	class BS_D3D9_EXPORT D3D9QueryManager : public QueryManager
-	{
-	public:
-		/** @copydoc QueryManager::createEventQuery */
-		SPtr<EventQuery> createEventQuery() const override;
-
-		/** @copydoc QueryManager::createTimerQuery */
-		SPtr<TimerQuery> createTimerQuery() const override;
-
-		/** @copydoc QueryManager::createOcclusionQuery */
-		SPtr<OcclusionQuery> createOcclusionQuery(bool binary) const override;
-	};
-
-	/** @} */
-}

+ 0 - 449
Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderAPI.h

@@ -1,449 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsRenderAPI.h"
-#include "BsRenderAPICapabilities.h"
-#include "BsD3D9Mappings.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** Implementation of a render system using DirectX 9. Provides abstracted access to various low level DX9 methods. */
-	class BS_D3D9_EXPORT D3D9RenderAPI : public RenderAPICore
-	{
-	public:
-		/**	Constructs a new instance of the render system using the provided module instance. */
-		D3D9RenderAPI(HINSTANCE hInstance);
-		~D3D9RenderAPI();
-
-		/** @copydoc RenderAPICore::getName() */
-		const StringID& getName() const override;
-
-		/** @copydoc RenderAPICore::getShadingLanguageName() */
-		const String& getShadingLanguageName() const override;
-
-		/** @copydoc RenderAPICore::setRenderTarget() */
-		void setRenderTarget(const SPtr<RenderTargetCore>& target, bool readOnlyDepthStencil = false) override;
-
-		/** @copydoc RenderAPICore::bindGpuProgram() */
-		void bindGpuProgram(const SPtr<GpuProgramCore>& prg) override;
-
-		/** @copydoc RenderAPICore::unbindGpuProgram() */
-		void unbindGpuProgram(GpuProgramType gptype) override;
-
-		/** @copydoc RenderAPICore::setParamBuffer */
-		void setParamBuffer(GpuProgramType gptype, UINT32 slot, const SPtr<GpuParamBlockBufferCore>& buffer,
-			const GpuParamDesc& paramDesc) override;
-
-		/** @copydoc RenderAPICore::setVertexBuffers() */
-		void setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers) override;
-
-		/** @copydoc RenderAPICore::setIndexBuffer() */
-		void setIndexBuffer(const SPtr<IndexBufferCore>& buffer) override;
-
-		/** @copydoc RenderAPICore::setVertexDeclaration() */
-		void setVertexDeclaration(const SPtr<VertexDeclarationCore>& vertexDeclaration) override;
-
-		/** @copydoc RenderAPICore::setDrawOperation() */
-		void setDrawOperation(DrawOperationType op) override;
-
-		/** @copydoc RenderAPICore::setTexture() */
-		void setTexture(GpuProgramType gptype, UINT16 texUnit, const SPtr<TextureCore>& texture) override;
-
-		/** @copydoc RenderAPICore::setBuffer */
-		void setBuffer(GpuProgramType gptype, UINT16 unit, const SPtr<GpuBufferCore>& buffer, bool loadStore = false) override;
-
-		/** @copydoc RenderAPICore::setLoadStoreTexture() */
-		void setLoadStoreTexture(GpuProgramType gptype, UINT16 texUnit, bool enabled, const SPtr<TextureCore>& texture,
-			const TextureSurface& surface) override;
-
-		/** @copydoc RenderAPICore::setSamplerState() */
-		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SPtr<SamplerStateCore>& samplerState) override;
-
-		/** @copydoc RenderAPICore::setBlendState() */
-		void setBlendState(const SPtr<BlendStateCore>& blendState) override;
-
-		/** @copydoc RenderAPICore::setRasterizerState() */
-		void setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState) override;
-
-		/** @copydoc RenderAPICore::setDepthStencilState() */
-		void setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue) override;
-
-		/** @copydoc RenderAPICore::setViewport() */
-		void setViewport(const Rect2& area) override;
-
-		/** @copydoc RenderAPICore::beginFrame() */
-		void beginFrame() override;
-
-		/** @copydoc RenderAPICore::endFrame() */
-		void endFrame() override;
-
-		/** @copydoc RenderAPICore::draw() */
-		void draw(UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount = 0) override;
-
-		/** @copydoc RenderAPICore::drawIndexed() */
-		void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount,
-			UINT32 instanceCount = 0) override;
-
-		/** @copydoc RenderAPICore::dispatchCompute() */
-		void dispatchCompute(UINT32 numGroupsX, UINT32 numGroupsY = 1, UINT32 numGroupsZ = 1) override;
-
-		/** @copydoc RenderAPICore::setScissorRect() */
-		void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom) override;
-
-		/** @copydoc RenderAPICore::clearRenderTarget() */
-		void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, 
-			UINT8 targetMask = 0xFF) override;
-
-		/** @copydoc RenderAPICore::clearViewport() */
-		void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, 
-			UINT8 targetMask = 0xFF) override;
-
-		/** @copydoc RenderAPICore::convertProjectionMatrix() */
-		void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest) override;
-
-		/** @copydoc RenderAPICore::getAPIInfo */
-		const RenderAPIInfo& getAPIInfo() const override;
-
-		/** @copydoc RenderAPICore::generateParamBlockDesc() */
-		GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) override;
-
-		/************************************************************************/
-		/* 				Internal use by DX9 RenderAPI only                   */
-		/************************************************************************/
-
-		/**	Returns the resource manager instance. */
-		static D3D9ResourceManager* getResourceManager();
-
-		/**	Returns the device manager instance. */
-		static D3D9DeviceManager* getDeviceManager();
-
-		/**	Returns the internal DirectX 9 device object. */
-		static IDirect3D9* getDirect3D9();
-
-		/**	Returns the number of devices that resources should be created on. */
-		static UINT	getResourceCreationDeviceCount();
-
-		/**	Returns DirectX 9 device used for resource creation at the specified index. */
-		static IDirect3DDevice9* getResourceCreationDevice(UINT index);
-
-		/**	Returns the currently active DirectX 9 device. */
-		static IDirect3DDevice9* getActiveD3D9Device();
-
-		/**
-		 * Converts engine multisample options into DirectX 9 specific ones. Also test for multi-sample support on the
-		 * device and returns nearest supported type if requested type is not available.
-		 *
-		 * @param[in]	d3d9Device				Device to check for multisampling.
-		 * @param[in]	multisampleCount		Number of requested samples.
-		 * @param[in]	d3dPixelFormat			Pixel format used by the render target.
-		 * @param[in]	fullscreen				Are we testing multisampling for a full-screen render target.
-		 * @param[in]	outMultisampleType		Output parameter containing DirectX type representing valid multisample type.
-		 * @param[in]	outMultisampleQuality	Output parameter containing multisample quality.
-		 */
-		void determineMultisampleSettings(IDirect3DDevice9* d3d9Device, UINT32 multisampleCount, D3DFORMAT d3dPixelFormat,
-			bool fullscreen, D3DMULTISAMPLE_TYPE* outMultisampleType, DWORD* outMultisampleQuality) const;
-
-		/**	Register a newly open window with the render system. */
-		void registerWindow(RenderWindowCore& renderWindow);
-
-	private:
-		friend class D3D9Texture;
-		friend class D3D9RenderWindow;
-		friend class D3D9Device;
-		friend class D3D9TextureManager;
-		friend class D3D9TextureCoreManager;
-		friend class D3D9DeviceManager;
-		friend class D3D9RenderWindowManager;
-		friend class D3D9RenderWindowCoreManager;
-
-		/** @copydoc RenderAPICore::initializePrepare */
-		void initializePrepare() override;
-
-		/** @copydoc RenderAPICore::initializeFinalize */
-		void initializeFinalize(const SPtr<RenderWindowCore>& primaryWindow) override;
-
-		/** @copydoc RenderAPICore::destroy_internal */
-		void destroyCore() override;
-
-		/**	Returns a list of available drivers and their properties. */
-		D3D9DriverList* getDirect3DDrivers() const;
-				
-		/**	Sets DirectX 9 render state option. */
-		HRESULT setRenderState(D3DRENDERSTATETYPE state, DWORD value);
-
-		/**	Sets DirectX 9 sampler state option for a sampler at the specified index. */
-		HRESULT setSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value);
-
-		/**	Sets DirectX 9 texture state option for a texture unit at the specified index. */
-		HRESULT setTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
-
-		/**	Set a floating point render state option. */
-		HRESULT setFloatRenderState(D3DRENDERSTATETYPE state, float value)
-		{
-			return setRenderState(state, *((LPDWORD)(&value)));
-		}
-
-		/**	Returns currently active anisotropy level for the provided texture unit. */
-		DWORD getCurrentAnisotropy(UINT32 unit);
-
-		/**
-		 * Updates active render system capabilities. Requires active render window to check certain capabilities.
-		 *
-		 * @note	Also performs an initialization step when called the first time.
-		 */
-		RenderAPICapabilities* updateRenderSystemCapabilities(D3D9RenderWindowCore* renderWindow);
-
-		/**	Updates render system capabilities with vertex shader related data. */
-        void updateVertexShaderCaps(RenderAPICapabilities* rsc) const;
-
-		/**	Updates render system capabilities with pixel shader related data. */
-        void updatePixelShaderCaps(RenderAPICapabilities* rsc) const;
-
-		/** @copydoc RenderAPICore::setClipPlanesImpl */
-		void setClipPlanesImpl(const PlaneList& clipPlanes) override;
-
-		/**	Converts a HRESULT error number into an error description. */
-		String getErrorDescription(long errorNumber) const;
-
-		/**	Sets a clip plane with the specified index. */
-		void setClipPlane(UINT16 index, float A, float B, float C, float D);
-
-		/**	Enables or disables a clip plane at the specified index. */
-		void enableClipPlane(UINT16 index, bool enable);
-
-		/**	Returns current module instance. */
-		HINSTANCE getInstanceHandle() const { return mhInstance; }
-
-		/** Returns the D3D9 specific mode used for drawing, depending on the currently set draw operation. */
-		D3DPRIMITIVETYPE getD3D9PrimitiveType() const;
-
-		/************************************************************************/
-		/* 							Sampler states                     			*/
-		/************************************************************************/
-
-		/**
-		 * Sets the texture addressing mode for a texture unit. This determines how are UV address values outside of [0, 1]
-		 * range handled when sampling from texture.
-		 */
-		void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
-
-		/**
-		 * Allows you to specify how is the texture bound to the specified texture unit filtered. Different filter types are
-		 * used for different situations like magnifying or minifying a texture.
-		 */
-		void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter);
-
-		/**	Sets anisotropy value for the specified texture unit. */
-		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
-
-		/**
-		 * Sets the texture border color for a texture unit. Border color determines color returned by the texture sampler
-		 * when border addressing mode is used and texture address is outside of [0, 1] range.
-		 */
-		void setTextureBorderColor(UINT16 stage, const Color& color);
-
-		/**
-		 * Sets the mipmap bias value for a given texture unit. Bias allows you to adjust the mipmap selection calculation.
-		 * Negative values force a larger mipmap to be used, and positive values smaller. Units are in values of mip levels,
-		 * so -1 means use a mipmap one level higher than default.
-		 */
-		void setTextureMipmapBias(UINT16 unit, float bias);
-
-		/************************************************************************/
-		/* 								Blend states                      		*/
-		/************************************************************************/
-
-		/**
-		 * Sets up blending mode that allows you to combine new pixels with pixels already in the render target. Final pixel
-		 * value = (renderTargetPixel * sourceFactor) op (pixel * destFactor).
-		 */
-		void setSceneBlending(BlendFactor sourceFactor, BlendFactor destFactor, BlendOperation op);
-
-		/**
-		 * Sets up blending mode that allows you to combine new pixels with pixels already in the render target. Allows you
-		 * to set up separate blend operations for alpha values.
-		 *	
-		 *	Final pixel value = (renderTargetPixel * sourceFactor) op (pixel * destFactor). (And the same for alpha)
-		 */
-		void setSceneBlending(BlendFactor sourceFactor, BlendFactor destFactor, BlendFactor sourceFactorAlpha, 
-			BlendFactor destFactorAlpha, BlendOperation op, BlendOperation alphaOp);
-
-		/**
-		 * Sets alpha test that allows you to reject pixels that fail the comparison function versus the provided reference
-		 * value.
-		 */
-		void setAlphaTest(CompareFunction func, unsigned char value);
-
-		/**
-		 * Enable alpha to coverage. Alpha to coverage allows you to perform blending without needing to worry about order
-		 * of rendering like regular blending does. It requires multi-sampling to be active in order to work, and you need
-		 * to supply an alpha texture that determines object transparency.
-		 */
-		void setAlphaToCoverage(bool enabled);
-
-		/**	Enables or disables writing to certain color channels of the render target. */
-		void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
-
-		/************************************************************************/
-		/* 								Rasterizer states                  		*/
-		/************************************************************************/
-
-		/** Sets vertex winding order. Normally you would use this to cull back facing polygons. */
-		void setCullingMode(CullingMode mode);
-
-		/**	Sets the polygon rasterization mode. Determines how are polygons interpreted. */
-		void setPolygonMode(PolygonMode level);
-
-		/**
-		 * Sets a depth bias that will offset the depth values of new pixels by the specified amount. Final depth bias value
-		 * is a combination of the constant depth bias and slope depth bias. Slope depth bias has more effect the higher the
-		 * slope of the rendered polygon.
-		 *
-		 * @note	This is useful if you want to avoid z fighting for objects at the same or similar depth.
-		 */
-		void setDepthBias(float constantBias, float slopeScaleBias);
-
-		/**
-		 * Scissor test allows you to mask off rendering in all but a given rectangular area identified by the rectangle
-		 * set by setScissorRect().
-		 */
-		void setScissorTestEnable(bool enable);
-
-		/**
-		 * Only applies when rendering to a multisample render target. If disabled all of the samples will be taken from the
-		 * center of the pixel, effectively making the image aliased. Default value is true where samples are picked
-		 * randomly within the pixel.
-		 */
-		void setMultisampleAntialiasEnable(bool enable);
-
-		/**	
-		 * Only applies when rendering to a non-multisample render target. If enabled, lines will be antialiased. Default
-		 * state is disabled.
-		 */
-		void setAntialiasedLineEnable(bool enable);
-
-		/************************************************************************/
-		/* 						Depth stencil state                      		*/
-		/************************************************************************/
-		
-		/** Should new pixels perform depth testing using the set depth comparison function before being written. */
-		void setDepthBufferCheckEnabled(bool enabled = true);
-
-		/**	Should new pixels write to the depth buffer. */
-		void setDepthBufferWriteEnabled(bool enabled = true);
-
-		/**
-		 * Sets comparison function used for depth testing. Determines how are new and existing pixel values compared - if
-		 * comparison function returns true the new pixel is written.
-		 */
-		void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
-
-		/**
-		 * Turns stencil tests on or off. By default this is disabled. Stencil testing allow you to mask out a part of the
-		 * rendered image by using various stencil operations provided.
-		 */
-		void setStencilCheckEnabled(bool enabled);
-
-		/**
-		 * Allows you to set stencil operations that are performed when stencil test passes or fails.
-		 *
-		 * @param[in]	stencilFailOp	Operation executed when stencil test fails.
-		 * @param[in]	depthFailOp		Operation executed when stencil test succeeds but depth test fails.
-		 * @param[in]	passOp			Operation executed when stencil test succeeds and depth test succeeds.
-		 * @param[in]	front			Should the stencil operations be applied to front or back facing polygons.
-		 */
-		void setStencilBufferOperations(StencilOperation stencilFailOp = SOP_KEEP,
-			StencilOperation depthFailOp = SOP_KEEP, StencilOperation passOp = SOP_KEEP,
-			bool ccw = true);
-
-		/**
-		 * Sets a stencil buffer comparison function. The result of this will cause one of 3 actions depending on whether
-		 * the test fails, succeeds but with the depth buffer check still failing, or succeeds with the depth buffer check
-		 * passing too.
-		 *
-		 * @param[in] func	Comparison function that determines whether a stencil test fails or passes. Reference value
-		 *					gets compared to the value already in the buffer using this function.
-		 * @param[in] ccw	If set to true, the stencil operations will be applied to counterclockwise
-		 *					faces. Otherwise they will be applied to clockwise faces.
-		 */
-		void setStencilBufferFunc(CompareFunction func = CMPF_ALWAYS_PASS, bool ccw = true);
-
-		/** The bitmask applied to both the stencil value and the reference value before comparison. */
-		void setStencilBufferReadMask(UINT32 mask = 0xFFFFFFFF);
-
-		/**	The bitmask applied to the stencil value before writing it to the stencil buffer. */
-		void setStencilBufferWriteMask(UINT32 mask = 0xFFFFFFFF);
-
-		/**
-		 * Sets a reference values used for stencil buffer comparisons. Actual comparison function and stencil operations
-		 * are set by setting the DepthStencilState.
-		 */
-		void setStencilRefValue(UINT32 refValue);
-
-		/**
-		 * Clears an area of the currently active render target.
-		 *
-		 * @param[in]	buffers			Combination of one or more elements of FrameBufferType denoting which buffers are
-		 *								to be cleared.
-		 * @param[in]	color			(optional) The color to clear the color buffer with, if enabled.
-		 * @param[in]	depth			(optional) The value to initialize the depth buffer with, if enabled.
-		 * @param[in]	stencil			(optional) The value to initialize the stencil buffer with, if enabled.
-		 * @param[in]	clearArea		(optional) Area in pixels to clear.
-		 */
-		void clearArea(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, const Rect2I& clearArea = Rect2I::EMPTY);
-
-		/**
-		 * Recalculates actual viewport dimensions based on currently set viewport normalized dimensions and render target
-		 * and applies them for further rendering.
-		 */
-		void applyViewport();
-
-		/**	Triggered when device has been lost. */
-		void notifyOnDeviceLost(D3D9Device* device);
-
-		/**	Triggered when device is being reset. */
-		void notifyOnDeviceReset(D3D9Device* device);
-
-	private:
-		/**	Holds texture unit settings. */
-		struct sD3DTextureStageDesc
-		{
-			D3D9Mappings::D3DTexType texType;
-			size_t coordIndex;
-			IDirect3DBaseTexture9 *pTex;
-			IDirect3DBaseTexture9 *pVertexTex;
-		};
-
-		static D3D9RenderAPI* msD3D9RenderSystem;
-
-		IDirect3D9*	mpD3D;
-		D3D9HLSLProgramFactory* mHLSLProgramFactory;
-		D3D9ResourceManager* mResourceManager;
-		D3D9DeviceManager* mDeviceManager;
-
-		mutable D3D9DriverList* mDriverList;
-		D3D9Driver* mActiveD3DDriver;
-
-		UINT32 mNumTexStages;
-		sD3DTextureStageDesc* mTexStageDesc;
-
-		bool mIsFrameInProgress;
-		bool mRestoreFrameOnReset;
-
-		HINSTANCE mhInstance;
-
-		Rect2 mViewportNorm;
-		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
-		RECT mScissorRect;
-
-		DrawOperationType mCurrentDrawOperation;
-	};
-
-	/** @} */
-}

+ 0 - 48
Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderAPIFactory.h

@@ -1,48 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include <string>
-#include "BsRenderAPIFactory.h"
-#include "BsRenderAPIManager.h"
-#include "BsD3D9RenderAPI.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	extern const char* SystemName;
-
-	/**	Handles creation of the DX9 render system. */
-	class D3D9RenderAPIFactory : public RenderAPIFactory
-	{
-	public:
-		/** @copydoc RenderAPIFactory::create */
-		void create() override;
-
-		/** @copydoc RenderAPIFactory::name */
-		const char* name() const override { return SystemName; }
-
-	private:
-		/**	Registers the factory with the render system manager when constructed. */
-		class InitOnStart
-		{
-			public:
-				InitOnStart() 
-				{ 
-					static SPtr<RenderAPIFactory> newFactory;
-					if(newFactory == nullptr)
-					{
-						newFactory = bs_shared_ptr_new<D3D9RenderAPIFactory>();
-						RenderAPIManager::instance().registerFactory(newFactory);
-					}
-				}
-		};
-
-		static InitOnStart initOnStart; // Makes sure factory is registered on program start
-	};
-
-	/** @} */
-}

+ 0 - 87
Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderTexture.h

@@ -1,87 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9Resource.h"
-#include "BsRenderTexture.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	class D3D9RenderTexture;
-
-	/**
-	 * DirectX 9 implementation of a render texture.
-	 *
-	 * @note	Core thread only.
-	 */
-	class BS_D3D9_EXPORT D3D9RenderTextureCore : public RenderTextureCore, public D3D9Resource
-	{
-	public:
-		D3D9RenderTextureCore(const RENDER_TEXTURE_CORE_DESC& desc);
-
-		virtual ~D3D9RenderTextureCore();
-
-		/** @copydoc RenderTextureCore::getCustomAttribute */
-		void getCustomAttribute(const String& name, void* data) const override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceLost */
-		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceReset */
-		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
-
-	protected:
-		friend class D3D9RenderTexture;
-
-		/** @copydoc CoreObjectCore::initialize */
-		void initialize() override;
-
-		/**	Initializes the internal color and depth surfaces. */
-		void initializeSurfaces();
-
-		/**	Releases the internal color and depth surfaces. */
-		void releaseSurfaces();
-
-		/** @copydoc RenderTextureCore::getProperties */
-		const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
-
-		IDirect3DSurface9* mDX9ColorSurface;
-		IDirect3DSurface9* mDX9DepthStencilSurface;
-		bool mIsBindableToShader;
-		RenderTextureProperties mProperties;
-	};
-
-	/**
-	 * DirectX 9 implementation of a render texture.
-	 *
-	 * @note	Sim thread only.
-	 */
-	class D3D9RenderTexture : public RenderTexture
-	{
-	public:
-		virtual ~D3D9RenderTexture() { }
-
-	protected:
-		friend class D3D9TextureManager;
-
-		D3D9RenderTexture(const RENDER_TEXTURE_DESC& desc);
-
-		/** @copydoc RenderTexture::getProperties */
-		const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
-
-		RenderTextureProperties mProperties;
-	};
-
-	/** @} */
-}

+ 0 - 186
Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderWindow.h

@@ -1,186 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsRenderWindow.h"
-#include "BsD3D9Device.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	class D3D9RenderWindow;
-
-	/**	Contains various properties that describe a render window. */
-	class BS_D3D9_EXPORT D3D9RenderWindowProperties : public RenderWindowProperties
-	{
-	public:
-		D3D9RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
-		virtual ~D3D9RenderWindowProperties() { }
-
-	private:
-		friend class D3D9RenderWindowCore;
-		friend class D3D9RenderWindow;
-	};
-
-	/**
-	 * Render window implementation for Windows.
-	 *
-	 * @note	Core thread only.
-	 */
-	class BS_D3D9_EXPORT D3D9RenderWindowCore : public RenderWindowCore
-	{
-	public:
-		D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
-		~D3D9RenderWindowCore();
-		
-		/** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
-		void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) override;
-
-		/** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
-		void setFullscreen(const VideoMode& videoMode) override;
-
-		/** @copydoc RenderWindowCore::setWindowed */
-		void setWindowed(UINT32 width, UINT32 height) override;
-
-		/** @copydoc RenderWindowCore::setActive */
-		virtual void setActive(bool state) override;
-
-		/** @copydoc RenderWindowCore::setHidden */
-		void setHidden(bool hidden) override;
-
-		/** @copydoc RenderWindowCore::minimize */
-		void minimize() override;
-
-		/** @copydoc RenderWindowCore::maximize */
-		void maximize() override;
-
-		/** @copydoc RenderWindowCore::restore */
-		void restore() override;
-
-		/** @copydoc RenderWindowCore::move */
-		void move(INT32 left, INT32 top) override;
-
-		/** @copydoc RenderWindowCore::resize */
-		void resize(UINT32 width, UINT32 height) override;
-
-		/** @copydoc RenderWindowCore::getCustomAttribute */
-		void getCustomAttribute(const String& name, void* pData) const override;
-
-		/** 
-		 * Copies the contents of a frame buffer into the pre-allocated buffer. 
-		 *
-		 * @param[out]	dst		Previously allocated buffer to read the contents into. Must be of valid size.
-		 * @param[in]	buffer	Frame buffer to read the contents from.
-		 */
-		void copyToMemory(PixelData& dst, FrameBuffer buffer);
-
-		/** @copydoc RenderWindowCore::swapBuffers */
-		void swapBuffers() override;
-
-		/** @copydoc RenderWindowCore::_windowMovedOrResized */
-		void _windowMovedOrResized() override;
-
-		/**	Gets internal Win32 window handle. */
-		HWND _getWindowHandle() const;
-
-		/**	Gets the DirectX 9 device object that manages this window. */
-		IDirect3DDevice9* _getD3D9Device() const;
-
-		/**	Gets the device that manages this window. */
-		D3D9Device* _getDevice() const;
-
-		/**	Sets the device that manages this window. */
-		void _setDevice(D3D9Device* device);
-
-		/**	Build the presentation parameters used with this window. */
-		void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
-
-		/**	Accessor for render surface. */
-		IDirect3DSurface9* _getRenderSurface() const;
-	
-		/**	Returns true if this window use depth buffer. */
-		bool _isDepthBuffered() const;
-
-		/**	Validate the device for this window. */
-		bool _validateDevice();
-		
-	protected:
-		friend class D3D9RenderWindow;
-
-		/** @copydoc CoreObjectCore::initialize */
-		virtual void initialize() override;
-
-		/** @copydoc RenderWindowCore::getProperties */
-		const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
-
-		/** @copydoc RenderWindowCore::getSyncedProperties */
-		RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
-
-		/** @copydoc RenderWindowCore::syncProperties */
-		void syncProperties() override;
-
-	protected:
-		Win32Window* mWindow;
-		HINSTANCE mInstance;
-		D3D9Device* mDevice;
-		bool mDeviceValid;
-		D3DMULTISAMPLE_TYPE	mMultisampleType;
-		DWORD mMultisampleQuality;
-		UINT mDisplayFrequency;
-		unsigned int mVSyncInterval;
-		bool mIsDepthBuffered;
-		bool mIsChild;
-		bool mShowOnSwap;
-		
-		D3D9RenderWindowProperties mProperties;
-		D3D9RenderWindowProperties mSyncedProperties;
-	};
-
-	/**
-	 * Render window implementation for Windows.
-	 *
-	 * @note	Sim thread only.
-	 */
-	class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
-	{
-	public:
-		~D3D9RenderWindow() { }
-
-		/** @copydoc RenderWindow::screenToWindowPos */
-		void getCustomAttribute(const String& name, void* pData) const override;
-
-		/** @copydoc RenderWindow::screenToWindowPos */
-		Vector2I screenToWindowPos(const Vector2I& screenPos) const override;
-
-		/** @copydoc RenderWindow::windowToScreenPos */
-		Vector2I windowToScreenPos(const Vector2I& windowPos) const override;
-
-		/** @copydoc RenderWindow::getCore */
-		SPtr<D3D9RenderWindowCore> getCore() const;
-
-	protected:
-		friend class D3D9RenderWindowManager;
-		friend class D3D9RenderWindowCore;
-
-		D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
-
-		/** @copydoc RenderWindowCore::getProperties */
-		const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
-
-		/** @copydoc RenderWindow::syncProperties */
-		void syncProperties() override;
-
-		/**	Retrieves internal window handle. */
-		HWND getHWnd() const;
-
-	private:
-		HINSTANCE mInstance;
-		D3D9RenderWindowProperties mProperties;
-	};
-
-	/** @} */
-}

+ 0 - 43
Source/BansheeD3D9RenderAPI/Include/BsD3D9RenderWindowManager.h

@@ -1,43 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsRenderWindowManager.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Handles creation of windows for DirectX 9. */
-	class BS_D3D9_EXPORT D3D9RenderWindowManager : public RenderWindowManager
-	{
-	public:
-		D3D9RenderWindowManager(D3D9RenderAPI* renderSystem);
-
-	protected:
-		/** @copydoc RenderWindowManager::createImpl() */
-		SPtr<RenderWindow> createImpl(RENDER_WINDOW_DESC& desc, UINT32 windowId, const SPtr<RenderWindow>& parentWindow) override;
-
-	private:
-		D3D9RenderAPI* mRenderSystem;
-	};
-
-	/**	Handles creation of windows for DirectX 9. */
-	class BS_D3D9_EXPORT D3D9RenderWindowCoreManager : public RenderWindowCoreManager
-	{
-	public:
-		D3D9RenderWindowCoreManager(D3D9RenderAPI* renderSystem);
-
-	protected:
-		/** @copydoc RenderWindowCoreManager::createInternal */
-		SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc, UINT32 windowId) override;
-
-	private:
-		D3D9RenderAPI* mRenderSystem;
-	};
-
-	/** @} */
-}

+ 0 - 49
Source/BansheeD3D9RenderAPI/Include/BsD3D9Resource.h

@@ -1,49 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** Provides an interface for dealing with DX9 resources. Primarily notifying the resources of any changed states. */
-	class BS_D3D9_EXPORT D3D9Resource
-	{
-	public:
-		D3D9Resource();
-		virtual ~D3D9Resource();
-
-		/**	Called immediately after the Direct3D device has been created. */
-		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) {}
-
-		/**	Called before the Direct3D device is going to be destroyed. */
-		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) {}
-
-		/**	Called immediately after the Direct3D device has entered a lost state. */
-		virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) {}
-
-		/**	Called immediately after the Direct3D device has been reset. */
-		virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) {}
-
-		/**
-		 * Called when device state is changing. Access to any device should be locked. Relevant for multi thread
-		 * application.
-		 */
-		static void lockDeviceAccess();
-
-		/**
-		 * Called when device state change completed. Access to any device is allowed. Relevant for multi thread
-		 * application.
-		 */
-		static void unlockDeviceAccess();
-
-	protected:
-		static Mutex msDeviceAccessMutex;
-	};
-
-	/** @} */
-}

+ 0 - 75
Source/BansheeD3D9RenderAPI/Include/BsD3D9ResourceManager.h

@@ -1,75 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Types of resource creation policies. */
-	enum D3D9ResourceCreationPolicy
-	{
-		/**
-		 *	Creates resources only on active device. Meaning those resources will be unavailable
-		 *	for other devices.
-		 */
-		RCP_CREATE_ON_ACTIVE_DEVICE,
-
-		/**
-		 *	Creates resources on all devices making them available to all of them.
-		 */
-		RCP_CREATE_ON_ALL_DEVICES
-	};
-	
-	/** Handles DirectX 9 resource life, notifying them about relevant device changes. */
-	class BS_D3D9_EXPORT D3D9ResourceManager
-	{
-	public:
-		D3D9ResourceManager();
-		~D3D9ResourceManager();
-
-		/**	Called after the device has been created. */
-		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
-
-		/**	Called before the device is destroyed. */
-		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
-
-		/**	Called after the device has entered the lost state. */
-		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
-
-		/**	Called after the device has been reset. */
-		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
-
-		/**	Called when device state is changing. Access to any device should be locked. */
-		void lockDeviceAccess();
-
-		/**	Called when device state change completed. Access to any device is allowed. */
-		void unlockDeviceAccess();
-		
-		/**	Called when new resource is created. */
-		void _notifyResourceCreated(D3D9Resource* pResource);
-
-		/**	Called before resource is destroyed. */
-		void _notifyResourceDestroyed(D3D9Resource* pResource);
-
-		/**	Sets creation policy that specifies on what devices will resources be created on. */
-		void setCreationPolicy(D3D9ResourceCreationPolicy creationPolicy);
-
-		/**	Returns creation policy that specifies on what devices will resources be created on. */
-		D3D9ResourceCreationPolicy getCreationPolicy() const;
-		
-	protected:
-		friend class D3D9Resource;
-		
-		Mutex mResourcesMutex;
-		Vector<D3D9Resource*> mResources;
-		D3D9ResourceCreationPolicy mResourceCreationPolicy;
-		long mDeviceAccessLockCount;		
-	};
-
-	/** @} */
-}

+ 0 - 171
Source/BansheeD3D9RenderAPI/Include/BsD3D9Texture.h

@@ -1,171 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsTexture.h"
-#include "BsD3D9PixelBuffer.h"
-#include "BsD3D9Resource.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	DirectX 9 implementation of a texture. */
-	class BS_D3D9_EXPORT D3D9TextureCore : public TextureCore, public D3D9Resource
-	{
-	protected:
-		/**	Container for internal resources. */
-		struct TextureResources
-		{
-			IDirect3DTexture9* pNormTex;
-			IDirect3DCubeTexture9* pCubeTex;
-			IDirect3DVolumeTexture9* pVolumeTex;
-			IDirect3DBaseTexture9* pBaseTex;
-			IDirect3DSurface9* pMultisampleSurface;
-			IDirect3DSurface9* pDepthStencilSurface;
-		};
-
-	public:
-		~D3D9TextureCore();
-
-		/** @copydoc TextureCore::isBindableAsShaderResource */
-		bool isBindableAsShaderResource() const override { return mIsBindableAsShaderResource; }
-
-		/**	Returns internal DirectX 9 texture object. */
-		IDirect3DBaseTexture9* getTexture_internal();	
-
-		/**	Returns internal DirectX 9 texture object pointing to a 1D or 2D texture. */
-		IDirect3DTexture9* getNormTexture_internal();
-
-		/**	Returns internal DirectX 9 texture object pointing to a cube texture. */
-		IDirect3DCubeTexture9* getCubeTexture_internal();
-
-		/**	Indicates whether the hardware gamma is enabled and supported. */
-		bool isHardwareGammaReadToBeUsed() const { return mProperties.isHardwareGammaEnabled() && mHwGammaReadSupported; }
-					
-		/**
-		 * Returns a hardware pixel buffer for a certain face and level of the texture.
-		 * 
-		 * @param[in]	face	Index of the texture face, if texture has more than one. Array index for texture arrays and
-		 *						a cube face for cube textures.
-		 * @param[in]	mipmap	Index of the mip level. 0 being the largest mip level.
-		 *
-		 * @note	Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
-		 */
-		SPtr<PixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceLost */
-		virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceReset */
-		virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
-
-	protected:	
-		friend class D3D9TextureCoreManager;
-		friend class D3D9PixelBuffer;
-
-		D3D9TextureCore(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
-			PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount, UINT32 numArraySlices, 
-			const SPtr<PixelData>& initialData);
-
-		/** @copydoc TextureCore::initialize */
-		void initialize() override;
-		
-		/** @copydoc TextureCore::lock */
-		PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) override;
-
-		/** @copydoc TextureCore::unlock */
-		void unlockImpl() override;
-
-		/** @copydoc TextureCore::copyImpl */
-		void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target) override;
-
-		/** @copydoc TextureCore::readData */
-		void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) override;
-
-		/** @copydoc TextureCore::writeData */
-		void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) override;
-
-		/**	Returns true if the texture should be allocated in the default pool. */
-		bool useDefaultPool();
-
-		/**	Creates a DirectX object for blank normal 1D/2D texture. */
-		void createNormTex(IDirect3DDevice9* d3d9Device);
-
-		/**	Creates a DirectX object for blank cube texture. */
-		void createCubeTex(IDirect3DDevice9* d3d9Device);
-
-		/**	Creates a DirectX object for blank volume (3D) texture. */	
-		void createVolumeTex(IDirect3DDevice9* d3d9Device);
-
-		/**	Selects a DirectX 9 pixel format depending on requested format and device capabilities. */
-		D3DFORMAT chooseD3DFormat(IDirect3DDevice9* d3d9Device);
-
-		/** @copydoc Texture::calculateSize */
-		UINT32 calculateSize() const;
-
-		/**	Creates internal resources for the texture for the specified device. */
-		void createInternalResources(IDirect3DDevice9* d3d9Device);
-
-		/** Updates texture attributes with final attributes provided by the API after the texture has been created. */
-		void setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources, 
-			UINT32 width, UINT32 height, UINT32 depth, PixelFormat format);
-
-		/**	Returns best texture filtering method. */
-		D3DTEXTUREFILTERTYPE getBestFilterMethod(IDirect3DDevice9* d3d9Device);
-
-		/**	Returns if the specified combination of texture type, format and usage supports dynamic texture usage. */
-		bool canUseDynamicTextures(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
-
-		/**	Returns if the specified combination of texture type, format and usage supports automatic mipmap generation. */
-		bool canAutoGenMipmaps(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
-
-		/**	Returns if the specified combination of texture type, format and usage supports hardware gamma. */
-		bool canUseHardwareGammaCorrection(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat, bool forwriting);
-
-		/**
-		 * Creates a list of pixel buffers for all surfaces in the texture. This must be called after the texture has been
-		 * created.
-		 */
-		void createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
-	 
-		/**	Retrieves texture resources for the device, or null if they don't exist. */
-		TextureResources* getTextureResources(IDirect3DDevice9* d3d9Device);
-
-		/**	Allocates a new set of texture resources for the device. */
-		TextureResources* allocateTextureResources(IDirect3DDevice9* d3d9Device);
-
-		/**	Frees all the given texture resources. */
-		void freeTextureResources(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
-
-		/**	Determines the pool in which to create the texture in. */
-		void determinePool();
-
-	protected:
-		Map<IDirect3DDevice9*, TextureResources*> mMapDeviceToTextureResources;
-
-		Vector<SPtr<PixelBuffer>> mSurfaceList;
-
-		D3DPOOL	mD3DPool;
-		bool mDynamicTextures;
-		bool mIsBindableAsShaderResource;
-
-		SPtr<PixelBuffer> mLockedBuffer;
-
-		bool mHwGammaReadSupported;
-		bool mHwGammaWriteSupported;
-		D3DMULTISAMPLE_TYPE mMultisampleType;
-		DWORD mMultisampleQuality;
-    };
-
-	/** @} */
-}

+ 0 - 50
Source/BansheeD3D9RenderAPI/Include/BsD3D9TextureManager.h

@@ -1,50 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9Texture.h"
-#include "BsTextureManager.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	Handles creation of DirectX 9 textures. */
-	class BS_D3D9_EXPORT D3D9TextureManager : public TextureManager
-	{
-	public:
-		D3D9TextureManager();
-		~D3D9TextureManager();
-
-		/** @copydoc TextureManager::getNativeFormat */
-		PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) override;
-
-	protected:	
-		/** @copydoc TextureManager::createRenderTextureImpl */
-		SPtr<RenderTexture> createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) override;
-
-		/** @copydoc TextureManager::createMultiRenderTextureImpl */
-		SPtr<MultiRenderTexture> createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc) override;
-	};
-
-	/**	Handles creation of DirectX 9 textures. */
-	class BS_D3D9_EXPORT D3D9TextureCoreManager : public TextureCoreManager
-	{
-	protected:		
-		/** @copydoc TextureCoreManager::createTextureInternal */
-		SPtr<TextureCore> createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
-			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
-			UINT32 multisampleCount = 0, UINT32 numArraySlices = 1, const SPtr<PixelData>& initialData = nullptr) override;
-
-		/** @copydoc TextureCoreManager::createRenderTextureInternal */
-		SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_CORE_DESC& desc) override;
-
-		/** @copydoc TextureCoreManager::createMultiRenderTextureInternal */
-		SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_CORE_DESC& desc) override;
-	};
-
-	/** @} */
-}

+ 0 - 72
Source/BansheeD3D9RenderAPI/Include/BsD3D9TimerQuery.h

@@ -1,72 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9Resource.h"
-#include "BsTimerQuery.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** @copydoc TimerQuery */
-	class BS_D3D9_EXPORT D3D9TimerQuery : public TimerQuery, public D3D9Resource
-	{
-	public:
-		D3D9TimerQuery();
-		~D3D9TimerQuery();
-
-		/** @copydoc TimerQuery::begin */
-		void begin() override;
-
-		/** @copydoc TimerQuery::end */
-		void end() override;
-
-		/** @copydoc TimerQuery::isReady */
-		bool isReady() const override;
-
-		/** @copydoc TimerQuery::getTimeMs */
-		float getTimeMs() override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceLost */
-		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceReset */
-		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
-
-	private:
-		/**	Resolve timing information after the query has finished. */
-		void finalize();
-
-		/**	Creates the internal DX9 query. */
-		void createQuery();
-
-		/**	Releases the internal DX9 query. */
-		void releaseQuery();
-
-		/**	Checks if the internal query object is valid. */
-		bool isQueryValid() const;
-
-	private:
-		bool mFinalized;
-		bool mQueryIssued;
-		float mTimeDelta;
-
-		IDirect3DDevice9* mDevice;
-		IDirect3DQuery9* mBeginQuery;
-		IDirect3DQuery9* mEndQuery;
-		IDirect3DQuery9* mDisjointQuery;
-		IDirect3DQuery9* mFreqQuery;
-	};
-
-	/** @} */
-}

+ 0 - 78
Source/BansheeD3D9RenderAPI/Include/BsD3D9VertexBuffer.h

@@ -1,78 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsVertexBuffer.h"
-#include "BsD3D9Resource.h"
-
-namespace BansheeEngine 
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	DirectX 9 implementation of a vertex buffer. */
-    class BS_D3D9_EXPORT D3D9VertexBufferCore : public VertexBufferCore, public D3D9Resource
-    {   
-	protected:
-		/**	Container for internal buffer resources. */
-		struct BufferResources
-		{
-			IDirect3DVertexBuffer9*	mBuffer;
-			bool mOutOfDate;
-			UINT32 mLockOffset;
-			UINT32 mLockLength;
-			GpuLockOptions mLockOptions;
-		};
-
-    public:
-		D3D9VertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut);
-		~D3D9VertexBufferCore();
-
-		/** @copydoc VertexBufferCore::readData */
-        void readData(UINT32 offset, UINT32 length, void* dest) override;
-
-		/** @copydoc VertexBufferCore::writeData */
-        void writeData(UINT32 offset, UINT32 length, const void* source, 
-			BufferWriteType writeFlags = BufferWriteType::Normal) override;
-	
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceLost */
-		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceReset */
-		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
-
-		/**	Creates a DX9 vertex buffer object in the provided memory pool. */
-		void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL pool);
-		
-		/**	Returns the DX9 vertex buffer object. */
-        IDirect3DVertexBuffer9* getD3D9VertexBuffer();
-
-	protected:	
-		/** @copydoc VertexBufferCore::initialize */
-		void initialize() override;
-		
-		/** @copydoc VertexBufferCore::lockImpl */
-		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options) override;
-
-		/** @copydoc VertexBufferCore::unlockImpl */
-		void unlockImpl() override;
-
-		/**	Updates buffer resources from cached system memory buffer. */
-		bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);		
-
-	protected:
-		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
-		D3DVERTEXBUFFER_DESC mBufferDesc;	
-		UINT8* mSystemMemoryBuffer;
-    };
-
-	/** @} */
-}

+ 0 - 43
Source/BansheeD3D9RenderAPI/Include/BsD3D9VertexDeclaration.h

@@ -1,43 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsVertexDeclaration.h"
-#include "BsD3D9Resource.h"
-
-namespace BansheeEngine 
-{ 
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/**	DirectX 9 implementation of a vertex declaration. */
-    class BS_D3D9_EXPORT D3D9VertexDeclarationCore : public VertexDeclarationCore, public D3D9Resource
-    {
-    public:
-		~D3D9VertexDeclarationCore();
-        
-		/** @copydoc D3D9Resource::notifyOnDeviceCreate */
-		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
-
-		/** @copydoc D3D9Resource::notifyOnDeviceDestroy */
-		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
-
-		/**	Creates a DirectX 9 vertex declaration object. */
-        IDirect3DVertexDeclaration9* getD3DVertexDeclaration();
-
-	protected:
-		friend class D3D9HardwareBufferCoreManager;
-
-		D3D9VertexDeclarationCore(const List<VertexElement>& elements);
-
-		/**	Releases the internal DirectX 9 vertex declaration object. */
-		void releaseDeclaration();
-
-	protected:        
-		Map<IDirect3DDevice9*, IDirect3DVertexDeclaration9*> mMapDeviceToDeclaration;
-    };
-
-	/** @} */
-}

+ 0 - 45
Source/BansheeD3D9RenderAPI/Include/BsD3D9VideoModeInfo.h

@@ -1,45 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsD3D9Prerequisites.h"
-#include "BsVideoModeInfo.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup D3D9
-	 *  @{
-	 */
-
-	/** @copydoc VideoMode */
-	class BS_D3D9_EXPORT D3D9VideoMode : public VideoMode
-	{
-	public:
-		D3D9VideoMode(UINT32 width, UINT32 height, float refreshRate, UINT32 outputIdx);
-
-	private:
-		friend class D3D9VideoOutputInfo;
-	};
-
-	/** @copydoc VideoOutputInfo	*/
-	class BS_D3D9_EXPORT D3D9VideoOutputInfo : public VideoOutputInfo
-	{
-	public:
-		D3D9VideoOutputInfo(IDirect3D9* d3d9device, UINT32 adapterIdx);
-
-		/**	Gets a Win32 handle to the monitor referenced by this object. */
-		HMONITOR getMonitorHandle() const { return mMonitorHandle; }
-
-	private:
-		HMONITOR mMonitorHandle;
-	};
-
-	/** @copydoc VideoModeInfo */
-	class BS_D3D9_EXPORT D3D9VideoModeInfo : public VideoModeInfo
-	{
-	public:
-		D3D9VideoModeInfo(IDirect3D9* d3d9device);
-	};
-
-	/** @} */
-}

+ 0 - 1247
Source/BansheeD3D9RenderAPI/Source/BsD3D9Device.cpp

@@ -1,1247 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9Device.h"
-#include "BsD3D9DeviceManager.h"
-#include "BsD3D9Driver.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsD3D9RenderWindow.h"
-#include "BsHardwareBufferManager.h"
-#include "BsException.h"
-
-namespace BansheeEngine
-{
-	HWND D3D9Device::msSharedFocusWindow = 0;
-
-	D3D9Device::D3D9Device(D3D9DeviceManager* deviceManager, UINT adapterNumber, HMONITOR hMonitor, 
-		D3DDEVTYPE devType, DWORD behaviorFlags)
-	{
-		mpDeviceManager	= deviceManager;
-		mpDevice = nullptr;		
-		mAdapterNumber = adapterNumber;
-		mMonitor = hMonitor;
-		mDeviceType = devType;
-		mFocusWindow = 0;
-		mBehaviorFlags = behaviorFlags;	
-		mD3D9DeviceCapsValid = false;
-		mDeviceLost = false;
-		mPresentationParamsCount = 0;
-		mPresentationParams	= nullptr;
-		memset(&mD3D9DeviceCaps, 0, sizeof(mD3D9DeviceCaps));
-		memset(&mCreationParams, 0, sizeof(mCreationParams));		
-	}
-
-	D3D9Device::~D3D9Device()
-	{
-
-	}
-
-	D3D9Device::RenderWindowToResorucesIterator D3D9Device::getRenderWindowIterator(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.find(renderWindow);
-
-		if (it == mMapRenderWindowToResoruces.end())
-			BS_EXCEPT(RenderingAPIException, "Render window was not attached to this device.");
-
-		return it;
-	}
-
-	void D3D9Device::attachRenderWindow(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.find(renderWindow);
-
-		if (it == mMapRenderWindowToResoruces.end())
-		{
-			RenderWindowResources* renderWindowResources = bs_new<RenderWindowResources>();
-
-			memset(renderWindowResources, 0, sizeof(RenderWindowResources));						
-			renderWindowResources->adapterOrdinalInGroupIndex = 0;					
-			renderWindowResources->acquired = false;
-			mMapRenderWindowToResoruces[renderWindow] = renderWindowResources;			
-		}
-
-		updateRenderWindowsIndices();
-	}
-
-	void D3D9Device::detachRenderWindow(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.find(renderWindow);
-
-		if (it != mMapRenderWindowToResoruces.end())
-		{		
-			// The focus window in which the d3d9 device created on is detached.
-			// resources must be acquired again.
-			if (mFocusWindow == renderWindow->_getWindowHandle())
-			{
-				mFocusWindow = 0;				
-			}
-
-			// Case this is the shared focus window.
-			if (renderWindow->_getWindowHandle() == msSharedFocusWindow)			
-				setSharedWindowHandle(0);		
-			
-			RenderWindowResources* renderWindowResources = it->second;
-
-			releaseRenderWindowResources(renderWindowResources);
-
-			if(renderWindowResources != nullptr)
-				bs_delete(renderWindowResources);
-			
-			mMapRenderWindowToResoruces.erase(it);		
-		}
-
-		updateRenderWindowsIndices();
-	}
-
-	bool D3D9Device::acquire()
-	{	
-		updatePresentationParameters();
-
-		bool resetDevice = false;
-			
-		// Create device if need to.
-		if (mpDevice == nullptr)
-		{			
-			createD3D9Device();
-		}
-		else
-		{
-			RenderWindowToResorucesIterator itPrimary = getRenderWindowIterator(getPrimaryWindow());
-
-			if (itPrimary->second->swapChain != nullptr)
-			{
-				D3DPRESENT_PARAMETERS currentPresentParams;
-				HRESULT hr;
-
-				hr = itPrimary->second->swapChain->GetPresentParameters(&currentPresentParams);
-				if (FAILED(hr))
-				{
-					BS_EXCEPT(RenderingAPIException, "GetPresentParameters failed");
-				}
-				
-				// Desired parameters are different then current parameters.
-				// Possible scenario is that primary window resized and in the mean while another
-				// window attached to this device.
-				if (memcmp(&currentPresentParams, &mPresentationParams[0], sizeof(D3DPRESENT_PARAMETERS)) != 0)
-				{
-					resetDevice = true;					
-				}				
-			}
-
-			// Make sure depth stencil is set to valid surface. It is going to be
-			// grabbed by the primary window using the GetDepthStencilSurface method.
-			if (resetDevice == false)
-			{
-				mpDevice->SetDepthStencilSurface(itPrimary->second->depthBuffer);
-			}
-			
-		}
-
-		// Reset device will update all render window resources.
-		if (resetDevice)
-		{
-			reset();
-		}
-		else // No need to reset -> just acquire resources.
-		{
-			// Update resources of each window.
-			RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-
-			while (it != mMapRenderWindowToResoruces.end())
-			{
-				acquireRenderWindowResources(it);
-				++it;
-			}
-		}
-									
-		return true;
-	}
-
-	void D3D9Device::release()
-	{
-		if (mpDevice != nullptr)
-		{
-			D3D9RenderAPI* renderSystem = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-
-			RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-
-			while (it != mMapRenderWindowToResoruces.end())
-			{
-				RenderWindowResources* renderWindowResources = it->second;
-
-				releaseRenderWindowResources(renderWindowResources);
-				++it;
-			}
-
-			releaseD3D9Device();
-		}				
-	}
-
-	bool D3D9Device::acquire(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-		
-		acquireRenderWindowResources(it);
-
-		return true;
-	}
-
-	void D3D9Device::notifyDeviceLost()
-	{
-		// Case this device is already in lost state.
-		if (mDeviceLost)
-			return;
-
-		// Case we just moved from valid state to lost state.
-		mDeviceLost = true;	
-
-		D3D9RenderAPI* renderSystem = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-		renderSystem->notifyOnDeviceLost(this);
-	}	
-
-	IDirect3DSurface9* D3D9Device::getDepthBuffer(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);		
-
-		return it->second->depthBuffer;
-	}
-
-	IDirect3DSurface9* D3D9Device::getBackBuffer(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-	
-		return it->second->backBuffer;		
-	}
-
-	void D3D9Device::setAdapterOrdinalIndex(const D3D9RenderWindowCore* renderWindow, UINT32 adapterOrdinalInGroupIndex)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-
-		it->second->adapterOrdinalInGroupIndex = adapterOrdinalInGroupIndex;
-
-		updateRenderWindowsIndices();
-	}
-	
-	void D3D9Device::destroy()
-	{	
-		// Lock access to rendering device.
-		D3D9RenderAPI::getResourceManager()->lockDeviceAccess();
-		
-		release();
-		
-		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-
-		if (it != mMapRenderWindowToResoruces.end())
-		{	
-			if (it->first->_getWindowHandle() == msSharedFocusWindow)
-				setSharedWindowHandle(0);
-
-			if(it->second != nullptr)
-				bs_delete(it->second);
-
-			++it;
-		}
-		mMapRenderWindowToResoruces.clear();
-		
-		// Reset dynamic attributes.		
-		mFocusWindow = 0;		
-		mD3D9DeviceCapsValid = false;
-
-		if(mPresentationParams != nullptr)
-			bs_deleteN(mPresentationParams, mPresentationParamsCount);
-
-		mPresentationParamsCount = 0;
-
-		// Notify the device manager on this instance destruction.	
-		mpDeviceManager->notifyOnDeviceDestroy(this);
-
-		// UnLock access to rendering device.
-		D3D9RenderAPI::getResourceManager()->unlockDeviceAccess();
-	}	
-
-	bool D3D9Device::isDeviceLost()
-	{		
-		HRESULT hr;
-
-		hr = mpDevice->TestCooperativeLevel();
-
-		if (hr == D3DERR_DEVICELOST ||
-			hr == D3DERR_DEVICENOTRESET)
-		{
-			return true;
-		}
-		
-		return false;
-	}
-
-	bool D3D9Device::reset()
-	{
-		HRESULT hr;
-
-		// Check that device is in valid state for reset.
-		hr = mpDevice->TestCooperativeLevel();
-		if (hr == D3DERR_DEVICELOST ||
-			hr == D3DERR_DRIVERINTERNALERROR)
-		{
-			return false;
-		}
-
-		// Lock access to rendering device.
-		D3D9RenderAPI::getResourceManager()->lockDeviceAccess();
-					
-		D3D9RenderAPI* renderSystem = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-
-		// Inform all resources that device lost.
-		D3D9RenderAPI::getResourceManager()->notifyOnDeviceLost(mpDevice);
-
-		// Notify all listener before device is rested
-		renderSystem->notifyOnDeviceLost(this);
-
-		updatePresentationParameters();
-
-		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-
-		while (it != mMapRenderWindowToResoruces.end())
-		{
-			RenderWindowResources* renderWindowResources = it->second;
-
-			releaseRenderWindowResources(renderWindowResources);
-			++it;
-		}
-
-		clearDeviceStreams();
-
-		// Reset the device using the presentation parameters.
-		hr = mpDevice->Reset(mPresentationParams);
-	
-		if (hr == D3DERR_DEVICELOST)
-		{
-			// UnLock access to rendering device.
-			D3D9RenderAPI::getResourceManager()->unlockDeviceAccess();
-
-			// Don't continue
-			return false;
-		}
-		else if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Cannot reset device!");
-		}
-
-		mDeviceLost = false;
-
-		// Update resources of each window.
-		it = mMapRenderWindowToResoruces.begin();
-
-		while (it != mMapRenderWindowToResoruces.end())
-		{
-			acquireRenderWindowResources(it);
-			++it;
-		}		
-
-		D3D9Device* pCurActiveDevice = mpDeviceManager->getActiveDevice();
-
-		mpDeviceManager->setActiveDevice(this);
-
-		// Inform all resources that device has been reset.
-		D3D9RenderAPI::getResourceManager()->notifyOnDeviceReset(mpDevice);
-
-		mpDeviceManager->setActiveDevice(pCurActiveDevice);
-		
-		renderSystem->notifyOnDeviceReset(this);
-
-		// UnLock access to rendering device.
-		D3D9RenderAPI::getResourceManager()->unlockDeviceAccess();
-	
-		return true;
-	}
-
-	bool D3D9Device::isAutoDepthStencil() const
-	{
-		const D3DPRESENT_PARAMETERS& primaryPresentationParams = mPresentationParams[0];
-		
-		// Check if auto depth stencil can be used.
-		for (unsigned int i = 1; i < mPresentationParamsCount; i++)
-		{			
-			// disable AutoDepthStencil if these parameters are not all the same.
-			if(primaryPresentationParams.BackBufferHeight != mPresentationParams[i].BackBufferHeight || 
-				primaryPresentationParams.BackBufferWidth != mPresentationParams[i].BackBufferWidth	|| 
-				primaryPresentationParams.BackBufferFormat != mPresentationParams[i].BackBufferFormat || 
-				primaryPresentationParams.AutoDepthStencilFormat != mPresentationParams[i].AutoDepthStencilFormat ||
-				primaryPresentationParams.MultiSampleQuality != mPresentationParams[i].MultiSampleQuality ||
-				primaryPresentationParams.MultiSampleType != mPresentationParams[i].MultiSampleType)
-			{
-				return false;
-			}
-		}
-
-		return true;
-	}
-
-	const D3DCAPS9& D3D9Device::getD3D9DeviceCaps() const
-	{
-		if (mD3D9DeviceCapsValid == false)
-		{
-			BS_EXCEPT(RenderingAPIException, "Device caps are invalid!");
-		}
-
-		return mD3D9DeviceCaps;
-	}
-
-	D3DFORMAT D3D9Device::getBackBufferFormat() const
-	{		
-		if (mPresentationParams == NULL || mPresentationParamsCount == 0)
-		{
-			BS_EXCEPT(RenderingAPIException, "Presentation parameters are invalid!");
-		}
-
-		return mPresentationParams[0].BackBufferFormat;
-	}
-
-	D3DFORMAT D3D9Device::getDepthStencilFormat() const
-	{		
-		if (mPresentationParams == NULL || mPresentationParamsCount == 0)
-		{
-			BS_EXCEPT(RenderingAPIException, "Presentation parameters are invalid!");
-		}
-
-		return mPresentationParams[0].AutoDepthStencilFormat;
-	}
-
-	IDirect3DDevice9* D3D9Device::getD3D9Device() const
-	{
-		return mpDevice;
-	}
-
-	void D3D9Device::updatePresentationParameters()
-	{		
-		// Clear old presentation parameters.
-		if(mPresentationParams != nullptr)
-			bs_deleteN(mPresentationParams, mPresentationParamsCount);
-
-		mPresentationParamsCount = 0;		
-
-		if (mMapRenderWindowToResoruces.size() > 0)
-		{
-			mPresentationParams = bs_newN<D3DPRESENT_PARAMETERS>((UINT32)mMapRenderWindowToResoruces.size());
-
-			RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-
-			while (it != mMapRenderWindowToResoruces.end())
-			{
-				const D3D9RenderWindowCore* renderWindow = it->first;
-				RenderWindowResources* renderWindowResources = it->second;
-
-				// Ask the render window to build it's own parameters.
-				renderWindow->_buildPresentParameters(&renderWindowResources->presentParameters);
-				
-				// Update shared focus window handle.
-				if (renderWindow->getProperties().isFullScreen() && renderWindowResources->presentParametersIndex == 0 && msSharedFocusWindow == NULL)
-					setSharedWindowHandle(renderWindow->_getWindowHandle());					
-
-				// This is the primary window or a full screen window that is part of multi head device.
-				if (renderWindowResources->presentParametersIndex == 0 || renderWindow->getProperties().isFullScreen())
-				{
-					mPresentationParams[renderWindowResources->presentParametersIndex] = renderWindowResources->presentParameters;
-					mPresentationParamsCount++;
-				}
-															
-				++it;
-			}
-		}
-
-		// Case we have to cancel auto depth stencil.
-		if (isMultihead() && isAutoDepthStencil() == false)
-		{
-			for(unsigned int i = 0; i < mPresentationParamsCount; i++)
-			{
-				mPresentationParams[i].EnableAutoDepthStencil = false;
-			}
-		}
-	}	
-
-	UINT D3D9Device::getAdapterNumber() const
-	{
-		return mAdapterNumber;
-	}
-
-	D3DDEVTYPE D3D9Device::getDeviceType() const
-	{
-		return mDeviceType;
-	}
-
-	bool D3D9Device::isMultihead() const
-	{
-		for (auto& resourceData : mMapRenderWindowToResoruces)
-		{
-			RenderWindowResources* renderWindowResources = resourceData.second;
-
-			if (renderWindowResources->adapterOrdinalInGroupIndex > 0 && resourceData.first->getProperties().isFullScreen())
-				return true;
-		}
-
-		return false;
-	}
-
-	void D3D9Device::clearDeviceStreams()
-	{
-		D3D9RenderAPI* renderSystem = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-
-		// Set all texture units to nothing to release texture surfaces
-		for (DWORD stage = 0; stage < mD3D9DeviceCaps.MaxSimultaneousTextures; ++stage)
-		{
-			DWORD dwCurValue = D3DTOP_FORCE_DWORD;
-			HRESULT hr;
-
-			hr = mpDevice->SetTexture(stage, nullptr);
-			if( hr != S_OK )
-			{
-				String str = "Unable to disable texture '" + toString((unsigned int)stage) + "' in D3D9";
-				BS_EXCEPT(RenderingAPIException, str);
-			}
-		
-			mpDevice->GetTextureStageState(static_cast<DWORD>(stage), D3DTSS_COLOROP, &dwCurValue);
-
-			if (dwCurValue != D3DTOP_DISABLE)
-			{
-				hr = mpDevice->SetTextureStageState(static_cast<DWORD>(stage), D3DTSS_COLOROP, D3DTOP_DISABLE);
-				if( hr != S_OK )
-				{
-					String str = "Unable to disable texture '" + toString((unsigned)stage) + "' in D3D9";
-					BS_EXCEPT(RenderingAPIException, str);
-				}
-			}			
-		
-			// set stage desc. to defaults
-			renderSystem->mTexStageDesc[stage].pTex = 0;
-			renderSystem->mTexStageDesc[stage].coordIndex = 0;
-			renderSystem->mTexStageDesc[stage].texType = D3D9Mappings::D3D_TEX_TYPE_NORMAL;
-		}
-
-		// Unbind any vertex streams to avoid memory leaks				
-		for (unsigned int i = 0; i < mD3D9DeviceCaps.MaxStreams; ++i)
-		{
-			mpDevice->SetStreamSource(i, nullptr, 0, 0);
-		}
-	}
-
-	void D3D9Device::createD3D9Device()
-	{		
-		// Update focus window.
-		const D3D9RenderWindowCore* primaryRenderWindow = getPrimaryWindow();
-
-		// Case we have to share the same focus window.
-		if (msSharedFocusWindow != NULL)
-			mFocusWindow = msSharedFocusWindow;
-		else
-			mFocusWindow = primaryRenderWindow->_getWindowHandle();		
-
-		IDirect3D9* pD3D9 = D3D9RenderAPI::getDirect3D9();
-		HRESULT hr;
-
-		if (isMultihead())
-		{
-			mBehaviorFlags |= D3DCREATE_ADAPTERGROUP_DEVICE;
-		}		
-		else
-		{
-			mBehaviorFlags &= ~D3DCREATE_ADAPTERGROUP_DEVICE;
-		}
-
-		// Try to create the device with hardware vertex processing. 
-		mBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
-		hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
-			mBehaviorFlags, mPresentationParams, &mpDevice);
-
-		if (FAILED(hr))
-		{
-			// Try a second time, may fail the first time due to back buffer count,
-			// which will be corrected down to 1 by the runtime
-			hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
-				mBehaviorFlags, mPresentationParams, &mpDevice);
-		}
-
-		// Case hardware vertex processing failed.
-		if (FAILED(hr))
-		{
-			// Try to create the device with mixed vertex processing.
-			mBehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
-			mBehaviorFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
-
-			hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
-				mBehaviorFlags, mPresentationParams, &mpDevice);
-		}
-
-		if (FAILED(hr))
-		{
-			// Try to create the device with software vertex processing.
-			mBehaviorFlags &= ~D3DCREATE_MIXED_VERTEXPROCESSING;
-			mBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
-			hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
-				mBehaviorFlags, mPresentationParams, &mpDevice);
-		}
-
-		if (FAILED(hr))
-		{
-			// Try reference device
-			mDeviceType = D3DDEVTYPE_REF;
-			hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
-				mBehaviorFlags, mPresentationParams, &mpDevice);
-
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Cannot create device!");
-			}
-		}
-
-		// Get current device caps.
-		hr = mpDevice->GetDeviceCaps(&mD3D9DeviceCaps);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Cannot get device caps!");
-		}
-
-		// Get current creation parameters caps.
-		hr = mpDevice->GetCreationParameters(&mCreationParams);
-		if (FAILED(hr) )
-		{
-			BS_EXCEPT(RenderingAPIException, "Error Get Creation Parameters");
-		}
-
-		mD3D9DeviceCapsValid = true;
-
-		// Lock access to rendering device.
-		D3D9RenderAPI::getResourceManager()->lockDeviceAccess();
-
-		D3D9Device* pCurActiveDevice = mpDeviceManager->getActiveDevice();
-
-		mpDeviceManager->setActiveDevice(this);
-
-		// Inform all resources that new device created.
-		D3D9RenderAPI::getResourceManager()->notifyOnDeviceCreate(mpDevice);
-
-		mpDeviceManager->setActiveDevice(pCurActiveDevice);
-
-		// UnLock access to rendering device.
-		D3D9RenderAPI::getResourceManager()->unlockDeviceAccess();
-	}
-
-	void D3D9Device::releaseD3D9Device()
-	{
-		if (mpDevice != nullptr)
-		{
-			// Lock access to rendering device.
-			D3D9RenderAPI::getResourceManager()->lockDeviceAccess();
-
-			D3D9Device* pCurActiveDevice = mpDeviceManager->getActiveDevice();
-
-			mpDeviceManager->setActiveDevice(this);
-
-			// Inform all resources that device is going to be destroyed.
-			D3D9RenderAPI::getResourceManager()->notifyOnDeviceDestroy(mpDevice);
-
-			mpDeviceManager->setActiveDevice(pCurActiveDevice);
-			
-			// Release device.
-			SAFE_RELEASE(mpDevice);	
-			
-			// UnLock access to rendering device.
-			D3D9RenderAPI::getResourceManager()->unlockDeviceAccess();
-		}
-	}
-
-	void D3D9Device::releaseRenderWindowResources(RenderWindowResources* renderWindowResources)
-	{
-		SAFE_RELEASE(renderWindowResources->backBuffer);
-		SAFE_RELEASE(renderWindowResources->depthBuffer);
-		SAFE_RELEASE(renderWindowResources->swapChain);
-		renderWindowResources->acquired = false;
-	}
-
-	void D3D9Device::invalidate(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-
-		it->second->acquired = false;		
-	}
-
-	bool D3D9Device::validate(D3D9RenderWindowCore* renderWindow)
-	{
-		// Validate that the render window should run on this device.
-		if (!validateDisplayMonitor(renderWindow))
-			return false;
-		
-		// Validate that this device created on the correct target focus window handle		
-		validateFocusWindow();		
-		
-		// Validate that the render window dimensions matches to back buffer dimensions.
-		validateBackBufferSize(renderWindow);
-
-		// Validate that this device is in valid rendering state.
-		if (!validateDeviceState(renderWindow))
-			return false;
-
-		return true;
-	}
-
-	void D3D9Device::validateFocusWindow()
-	{
-		// Focus window changed -> device should be re-acquired.
-		if ((msSharedFocusWindow != NULL && mCreationParams.hFocusWindow != msSharedFocusWindow) ||
-			(msSharedFocusWindow == NULL && mCreationParams.hFocusWindow != getPrimaryWindow()->_getWindowHandle()))
-		{
-			// Lock access to rendering device.
-			D3D9RenderAPI::getResourceManager()->lockDeviceAccess();
-
-			release();
-			acquire();
-
-			// UnLock access to rendering device.
-			D3D9RenderAPI::getResourceManager()->unlockDeviceAccess();
-		}
-	}
-
-	bool D3D9Device::validateDeviceState(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);		
-		RenderWindowResources* renderWindowResources =  it->second;
-		HRESULT hr;
-
-		hr = mpDevice->TestCooperativeLevel();	
-
-		// Case device is not valid for rendering. 
-		if (FAILED(hr))
-		{					
-			// device lost, and we can't reset
-			// can't do anything about it here, wait until we get 
-			// D3DERR_DEVICENOTRESET; rendering calls will silently fail until 
-			// then (except Present, but we ignore device lost there too)
-			if (hr == D3DERR_DEVICELOST)
-			{						
-				releaseRenderWindowResources(renderWindowResources);
-				notifyDeviceLost();							
-				return false;
-			}
-
-			// device lost, and we can reset
-			else if (hr == D3DERR_DEVICENOTRESET)
-			{					
-				bool deviceRestored = reset();
-
-				// Device was not restored yet.
-				if (deviceRestored == false)
-				{
-					// Wait a while
-					Sleep(50);					
-					return false;
-				}																								
-			}						
-		}
-
-		// Render window resources explicitly invalidated. (Resize or window mode switch) 
-		if (renderWindowResources->acquired == false)
-		{
-			if (getPrimaryWindow() == renderWindow)
-			{
-				bool deviceRestored = reset();
-
-				// Device was not restored yet.
-				if (deviceRestored == false)
-				{
-					// Wait a while
-					Sleep(50);					
-					return false;
-				}	
-			}
-			else
-			{
-				acquire(renderWindow);
-			}
-		}
-
-		return true;
-	}
-		
-	void D3D9Device::validateBackBufferSize(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-		RenderWindowResources*	renderWindowResources = it->second;
-	
-		const RenderWindowProperties& props = renderWindow->getProperties();
-
-		// Case size has been changed.
-		if (props.getWidth() != renderWindowResources->presentParameters.BackBufferWidth ||
-			props.getHeight() != renderWindowResources->presentParameters.BackBufferHeight)
-		{			
-			if (props.getWidth() > 0)
-				renderWindowResources->presentParameters.BackBufferWidth = props.getWidth();
-
-			if (props.getHeight() > 0)
-				renderWindowResources->presentParameters.BackBufferHeight = props.getHeight();
-
-			invalidate(renderWindow);
-		}				
-	}
-
-	bool D3D9Device::validateDisplayMonitor(D3D9RenderWindowCore* renderWindow)
-	{
-		// Ignore full screen since it doesn't really move and it is possible 
-		// that it created using multi-head adapter so for a subordinate the
-		// native monitor handle and this device handle will be different.
-		if (renderWindow->getProperties().isFullScreen())
-			return true;
-
-		HMONITOR	hRenderWindowMonitor = NULL;
-
-		// Find the monitor this render window belongs to.
-		hRenderWindowMonitor = MonitorFromWindow(renderWindow->_getWindowHandle(), MONITOR_DEFAULTTONULL);
-
-		// This window doesn't intersect with any of the display monitor
-		if (hRenderWindowMonitor == NULL)		
-			return false;		
-		
-
-		// Case this window changed monitor.
-		if (hRenderWindowMonitor != mMonitor)
-		{	
-			// Lock access to rendering device.
-			D3D9RenderAPI::getResourceManager()->lockDeviceAccess();
-
-			mpDeviceManager->linkRenderWindow(renderWindow);
-
-			// UnLock access to rendering device.
-			D3D9RenderAPI::getResourceManager()->unlockDeviceAccess();
-
-			return false;
-		}
-
-		return true;
-	}
-
-	void D3D9Device::present(const D3D9RenderWindowCore* renderWindow)
-	{		
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-		RenderWindowResources*	renderWindowResources = it->second;				
-
-		// Skip present while current device state is invalid.
-		if (mDeviceLost || 
-			renderWindowResources->acquired == false || 
-			isDeviceLost())		
-			return;		
-
-
-		HRESULT hr;
-
-		if (isMultihead())
-		{
-			// Only the master will call present method results in synchronized
-			// buffer swap for the rest of the implicit swap chain.
-			if (getPrimaryWindow() == renderWindow)
-				hr = mpDevice->Present( NULL, NULL, NULL, NULL );
-			else
-				hr = S_OK;
-		}
-		else
-		{
-			hr = renderWindowResources->swapChain->Present(NULL, NULL, NULL, NULL, 0);			
-		}
-
-
-		if(D3DERR_DEVICELOST == hr)
-		{
-			releaseRenderWindowResources(renderWindowResources);
-			notifyDeviceLost();
-		}
-		else if( FAILED(hr) )
-		{
-			BS_EXCEPT(RenderingAPIException, "Error Presenting surfaces");
-		}
-	}
-
-	void D3D9Device::acquireRenderWindowResources(RenderWindowToResorucesIterator it)
-	{
-		RenderWindowResources*	renderWindowResources = it->second;
-		const D3D9RenderWindowCore*	renderWindow = it->first;
-		
-		releaseRenderWindowResources(renderWindowResources);
-
-		// Create additional swap chain
-		if (isSwapChainWindow(renderWindow) && !isMultihead())
-		{
-			// Create swap chain
-			HRESULT hr = mpDevice->CreateAdditionalSwapChain(&renderWindowResources->presentParameters, 
-				&renderWindowResources->swapChain);
-
-			if (FAILED(hr))
-			{
-				// Try a second time, may fail the first time due to back buffer count,
-				// which will be corrected by the runtime
-				hr = mpDevice->CreateAdditionalSwapChain(&renderWindowResources->presentParameters, 
-					&renderWindowResources->swapChain);
-			}
-
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to create an additional swap chain");
-			}
-		}
-		else
-		{
-			// The swap chain is already created by the device
-			HRESULT hr = mpDevice->GetSwapChain(renderWindowResources->presentParametersIndex, 
-				&renderWindowResources->swapChain);
-			if (FAILED(hr)) 
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to get the swap chain");
-			}
-		}
-
-		// Store references to buffers for convenience		
-		renderWindowResources->swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, 
-			&renderWindowResources->backBuffer);
-
-		// Additional swap chains need their own depth buffer
-		// to support resizing them
-		if (renderWindow->_isDepthBuffered()) 
-		{
-			// if multihead is enabled, depth buffer can be created automatically for 
-			// all the adapters. if multihead is not enabled, depth buffer is just
-			// created for the main swap chain
-			if (isMultihead() && isAutoDepthStencil() || 
-			    isMultihead() == false && isSwapChainWindow(renderWindow) == false)
-			{
-				mpDevice->GetDepthStencilSurface(&renderWindowResources->depthBuffer);
-			}
-			else
-			{
-				UINT32 targetWidth  = renderWindow->getProperties().getWidth();
-				UINT32 targetHeight = renderWindow->getProperties().getHeight();
-
-				if (targetWidth == 0)
-					targetWidth = 1;
-
-				if (targetHeight == 0)
-					targetHeight = 1;
-
-				HRESULT hr = mpDevice->CreateDepthStencilSurface(
-					targetWidth, targetHeight,
-					renderWindowResources->presentParameters.AutoDepthStencilFormat,
-					renderWindowResources->presentParameters.MultiSampleType,
-					renderWindowResources->presentParameters.MultiSampleQuality, 
-					(renderWindowResources->presentParameters.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL),
-					&renderWindowResources->depthBuffer, NULL
-					);
-
-				if (FAILED(hr)) 
-				{
-					BS_EXCEPT(RenderingAPIException, "Unable to create a depth buffer for the swap chain");
-				}
-
-				if (isSwapChainWindow(renderWindow) == false)
-				{
-					mpDevice->SetDepthStencilSurface(renderWindowResources->depthBuffer);
-				}
-			}
-		}
-
-		renderWindowResources->acquired = true; 
-	}
-
-	bool D3D9Device::isSwapChainWindow(const D3D9RenderWindowCore* renderWindow)
-	{
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-		
-		if (it->second->presentParametersIndex == 0 || renderWindow->getProperties().isFullScreen())			
-			return false;
-			
-		return true;
-	}
-
-	const D3D9RenderWindowCore* D3D9Device::getPrimaryWindow()
-	{		
-		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-	
-		while (it != mMapRenderWindowToResoruces.end() && it->second->presentParametersIndex != 0)				
-			++it;		
-
-		assert(it != mMapRenderWindowToResoruces.end());
-
-		return it->first;
-	}
-
-	void D3D9Device::setSharedWindowHandle(HWND hSharedHWND)
-	{
-		if (hSharedHWND != msSharedFocusWindow)					
-			msSharedFocusWindow = hSharedHWND;					
-	}
-
-	void D3D9Device::updateRenderWindowsIndices()
-	{
-		// Update present parameters index attribute per render window.
-		if (isMultihead())
-		{
-			RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-
-			// Multi head device case -  
-			// Present parameter index is based on adapter ordinal in group index.
-			while (it != mMapRenderWindowToResoruces.end())			
-			{
-				it->second->presentParametersIndex = it->second->adapterOrdinalInGroupIndex;
-				++it;
-			}
-		}
-		else
-		{
-			// Single head device case - 
-			// Just assign index in incremental order - 
-			// NOTE: It suppose to cover both cases that possible here:
-			// 1. Single full screen window - only one allowed per device (this is not multi-head case).
-			// 2. Multiple window mode windows.
-
-			UINT32 nextPresParamIndex = 0;
-
-			RenderWindowToResorucesIterator it;
-			const D3D9RenderWindowCore* deviceFocusWindow = NULL;
-
-			// In case a d3d9 device exists - try to keep the present parameters order
-			// so that the window that the device is focused on will stay the same and we
-			// will avoid device re-creation.
-			if (mpDevice != NULL)
-			{
-				it = mMapRenderWindowToResoruces.begin();
-				while (it != mMapRenderWindowToResoruces.end())			
-				{
-					if (it->first->_getWindowHandle() == mCreationParams.hFocusWindow)
-					{
-						deviceFocusWindow = it->first;
-						it->second->presentParametersIndex = nextPresParamIndex;
-						++nextPresParamIndex;
-						break;
-					}					
-					++it;
-				}
-			}
-			
-		
-
-			it = mMapRenderWindowToResoruces.begin();
-			while (it != mMapRenderWindowToResoruces.end())			
-			{
-				if (it->first != deviceFocusWindow)
-				{
-					it->second->presentParametersIndex = nextPresParamIndex;
-					++nextPresParamIndex;
-				}								
-				++it;
-			}
-		}
-	}
-
-	void D3D9Device::copyContentsToMemory(const D3D9RenderWindowCore* renderWindow,
-		PixelData &dst, RenderTargetCore::FrameBuffer buffer)
-	{
-		const RenderWindowProperties& props = renderWindow->getProperties();
-
-		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
-		RenderWindowResources* resources = it->second;
-		bool swapChain = isSwapChainWindow(renderWindow);
-
-		if ((dst.getLeft() < 0) || (dst.getRight() > props.getWidth()) ||
-			(dst.getTop() < 0) || (dst.getBottom() > props.getHeight()) ||
-			(dst.getFront() != 0) || (dst.getBack() != 1))
-		{
-			BS_EXCEPT(InvalidParametersException, "Invalid box.");
-		}
-
-		HRESULT hr;
-		IDirect3DSurface9* pSurf = NULL;
-		IDirect3DSurface9* pTempSurf = NULL;
-		D3DSURFACE_DESC desc;
-		D3DLOCKED_RECT lockedRect;
-
-
-		if (buffer == RenderTargetCore::FB_AUTO)
-		{
-			buffer = RenderTargetCore::FB_FRONT;
-		}
-
-		if (buffer == RenderTargetCore::FB_FRONT)
-		{
-			D3DDISPLAYMODE dm;
-
-			if (FAILED(hr = mpDevice->GetDisplayMode(0, &dm)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't get display mode: TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-			}
-
-			desc.Width = dm.Width;
-			desc.Height = dm.Height;
-			desc.Format = D3DFMT_A8R8G8B8;
-			if (FAILED(hr = mpDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height,
-				desc.Format,
-				D3DPOOL_SYSTEMMEM,
-				&pTempSurf,
-				0)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't create offscreen buffer: TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-			}
-
-			if (FAILED(hr = swapChain ? resources->swapChain->GetFrontBufferData(pTempSurf) :
-				mpDevice->GetFrontBufferData(0, pTempSurf)))
-			{
-				SAFE_RELEASE(pTempSurf);
-				BS_EXCEPT(RenderingAPIException, "Can't get front buffer: TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-			}
-
-			if (props.isFullScreen())
-			{
-				if ((dst.getLeft() == 0) && (dst.getRight() == props.getWidth()) && (dst.getTop() == 0) && (dst.getBottom() == props.getHeight()))
-				{
-					hr = pTempSurf->LockRect(&lockedRect, 0, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK);
-				}
-				else
-				{
-					RECT rect;
-
-					rect.left = static_cast<LONG>(dst.getLeft());
-					rect.right = static_cast<LONG>(dst.getRight());
-					rect.top = static_cast<LONG>(dst.getTop());
-					rect.bottom = static_cast<LONG>(dst.getBottom());
-
-					hr = pTempSurf->LockRect(&lockedRect, &rect, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK);
-				}
-				if (FAILED(hr))
-				{
-					SAFE_RELEASE(pTempSurf);
-					BS_EXCEPT(RenderingAPIException, "Can't lock rect:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-				} 
-			}
-			else
-			{
-				RECT srcRect;
-				//GetClientRect(mHWnd, &srcRect);
-				srcRect.left = static_cast<LONG>(dst.getLeft());
-				srcRect.top = static_cast<LONG>(dst.getTop());
-				srcRect.right = static_cast<LONG>(dst.getRight());
-				srcRect.bottom = static_cast<LONG>(dst.getBottom());
-				POINT point;
-				point.x = srcRect.left;
-				point.y = srcRect.top;
-				ClientToScreen(renderWindow->_getWindowHandle(), &point);
-				srcRect.top = point.y;
-				srcRect.left = point.x;
-				srcRect.bottom += point.y;
-				srcRect.right += point.x;
-
-				desc.Width = srcRect.right - srcRect.left;
-				desc.Height = srcRect.bottom - srcRect.top;
-
-				if (FAILED(hr = pTempSurf->LockRect(&lockedRect, &srcRect, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK)))
-				{
-					SAFE_RELEASE(pTempSurf);
-					BS_EXCEPT(RenderingAPIException, "Can't lock rect:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-				} 
-			}
-		}
-		else
-		{
-			SAFE_RELEASE(pSurf);
-			if(FAILED(hr = swapChain? resources->swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurf) :
-				mpDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurf)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't get back buffer:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-			}
-
-			if(FAILED(hr = pSurf->GetDesc(&desc)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't get description:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-			}
-
-			if (FAILED(hr = mpDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height,
-				desc.Format,
-				D3DPOOL_SYSTEMMEM,
-				&pTempSurf,
-				0)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't create offscreen surface:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-			}
-
-			if (desc.MultiSampleType == D3DMULTISAMPLE_NONE)
-			{
-				if (FAILED(hr = mpDevice->GetRenderTargetData(pSurf, pTempSurf)))
-				{
-					SAFE_RELEASE(pTempSurf);
-					BS_EXCEPT(RenderingAPIException, "Can't get render target data:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-				}
-			}
-			else
-			{
-				IDirect3DSurface9* pStretchSurf = 0;
-
-				if (FAILED(hr = mpDevice->CreateRenderTarget(desc.Width, desc.Height,
-					desc.Format,
-					D3DMULTISAMPLE_NONE,
-					0,
-					false,
-					&pStretchSurf,
-					0)))
-				{
-					SAFE_RELEASE(pTempSurf);
-					BS_EXCEPT(RenderingAPIException, "Can't create render target:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-				}
-
-				if (FAILED(hr = mpDevice->StretchRect(pSurf, 0, pStretchSurf, 0, D3DTEXF_NONE)))
-				{
-					SAFE_RELEASE(pTempSurf);
-					SAFE_RELEASE(pStretchSurf);
-					BS_EXCEPT(RenderingAPIException, "Can't stretch rect:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-				}
-				if (FAILED(hr = mpDevice->GetRenderTargetData(pStretchSurf, pTempSurf)))
-				{
-					SAFE_RELEASE(pTempSurf);
-					SAFE_RELEASE(pStretchSurf);
-					BS_EXCEPT(RenderingAPIException, "Can't get render target data:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-				}
-				SAFE_RELEASE(pStretchSurf);
-			}
-
-			if ((dst.getLeft() == 0) && (dst.getRight() == props.getWidth()) && (dst.getTop() == 0) && (dst.getBottom() == props.getHeight()))
-			{
-				hr = pTempSurf->LockRect(&lockedRect, 0, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK);
-			}
-			else
-			{
-				RECT rect;
-
-				rect.left = static_cast<LONG>(dst.getLeft());
-				rect.right = static_cast<LONG>(dst.getRight());
-				rect.top = static_cast<LONG>(dst.getTop());
-				rect.bottom = static_cast<LONG>(dst.getBottom());
-
-				hr = pTempSurf->LockRect(&lockedRect, &rect, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK);
-			}
-			if (FAILED(hr))
-			{
-				SAFE_RELEASE(pTempSurf);
-				BS_EXCEPT(RenderingAPIException, "Can't lock rect:  TODO PORT NO ERROR"); // TODO PORT - Translate HR to error
-			}
-		}
-
-		PixelFormat format = BansheeEngine::D3D9Mappings::_getPF(desc.Format);
-
-		if (format == PF_UNKNOWN)
-		{
-			SAFE_RELEASE(pTempSurf);
-			BS_EXCEPT(RenderingAPIException, "Unsupported format");
-		}
-
-		PixelData src(dst.getWidth(), dst.getHeight(), 1, format);
-		src.setExternalBuffer((UINT8*)lockedRect.pBits);
-		src.setRowPitch(lockedRect.Pitch / PixelUtil::getNumElemBytes(format));
-		src.setSlicePitch(desc.Height * src.getRowPitch());
-
-		PixelUtil::bulkPixelConversion(src, dst);
-
-		SAFE_RELEASE(pTempSurf);
-		SAFE_RELEASE(pSurf);
-	}
-}

+ 0 - 235
Source/BansheeD3D9RenderAPI/Source/BsD3D9DeviceManager.cpp

@@ -1,235 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9DeviceManager.h"
-#include "BsD3D9Device.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9RenderWindow.h"
-#include "BsD3D9Driver.h"
-#include "BsD3D9DriverList.h"
-#include "BsException.h"
-
-namespace BansheeEngine
-{
-	D3D9DeviceManager::D3D9DeviceManager()
-		:mActiveDevice(nullptr), mActiveRenderWindowDevice(nullptr)
-	{
-
-	}
-
-	D3D9DeviceManager::~D3D9DeviceManager()
-	{
-		while (mRenderDevices.size() > 0)	
-			mRenderDevices[0]->destroy();						
-
-		mActiveDevice = nullptr;
-		mActiveRenderWindowDevice = nullptr;
-	}
-
-	void D3D9DeviceManager::setActiveDevice(D3D9Device* device)
-	{
-		if (mActiveDevice != device)
-		{
-			mActiveDevice = device;
-
-			D3D9RenderAPI* renderSystem = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-			D3D9DriverList*	driverList = renderSystem->getDirect3DDrivers();
-
-			// Update the active driver member.
-			for (UINT32 i=0; i < driverList->count(); ++i)
-			{
-				D3D9Driver* currDriver = driverList->item(i);
-				if (currDriver->getAdapterNumber() == mActiveDevice->getAdapterNumber())
-				{
-					renderSystem->mActiveD3DDriver = currDriver;
-					break;
-				}				
-			}	
-		}						
-	}
-
-	D3D9Device* D3D9DeviceManager::getActiveDevice()
-	{	
-		if (mActiveDevice == nullptr)
-			BS_EXCEPT(InvalidParametersException, "Current active device is null." );
-
-		return mActiveDevice;		
-	}
-
-	void D3D9DeviceManager::setActiveRenderTargetDevice(D3D9Device* device)
-	{
-		mActiveRenderWindowDevice = device;
-		if (mActiveRenderWindowDevice != nullptr)
-			setActiveDevice(mActiveRenderWindowDevice);			
-	}
-
-	D3D9Device* D3D9DeviceManager::getActiveRenderTargetDevice()
-	{
-		return mActiveRenderWindowDevice;
-	}
-
-	UINT D3D9DeviceManager::getDeviceCount()
-	{
-		return static_cast<UINT>(mRenderDevices.size());
-	}
-
-	D3D9Device* D3D9DeviceManager::getDevice(UINT index)
-	{
-		return mRenderDevices[index];
-	}
-
-	void D3D9DeviceManager::linkRenderWindow(D3D9RenderWindowCore* renderWindow)
-	{		
-		D3D9Device* renderDevice;
-
-		// Detach from previous device.
-		renderDevice = renderWindow->_getDevice();		
-		if (renderDevice != nullptr)
-			renderDevice->detachRenderWindow(renderWindow);						
-
-		Vector<D3D9RenderWindowCore*> renderWindowsGroup;
-
-		// Select new device for this window.		
-		renderDevice = selectDevice(renderWindow, renderWindowsGroup);
-
-		// Link the windows group to the new device.
-		for (UINT32 i = 0; i < renderWindowsGroup.size(); ++i)
-		{
-			D3D9RenderWindowCore* currWindow = renderWindowsGroup[i];
-
-			currWindow->_setDevice(renderDevice);
-			renderDevice->attachRenderWindow(currWindow);
-			renderDevice->setAdapterOrdinalIndex(currWindow, i);
-		}
-				
-		renderDevice->acquire();
-		if (mActiveDevice == nullptr)
-			setActiveDevice(renderDevice);		
-	}
-
-	D3D9Device* D3D9DeviceManager::selectDevice(D3D9RenderWindowCore* renderWindow, Vector<D3D9RenderWindowCore*>& renderWindowsGroup)
-	{
-		D3D9RenderAPI* renderSystem = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-		D3D9Device*	renderDevice = nullptr;	
-		IDirect3D9*	direct3D9 = D3D9RenderAPI::getDirect3D9();
-		UINT adapterOrdinal = D3DADAPTER_DEFAULT;
-		D3DDEVTYPE devType = D3DDEVTYPE_HAL;						
-		DWORD extraFlags = 0;					
-		D3D9DriverList* driverList = renderSystem->getDirect3DDrivers();
-
-		// Default group includes at least the given render window.
-		renderWindowsGroup.push_back(renderWindow);
-
-		// Try to find a matching device from current device list.
-		if (renderDevice == nullptr)
-		{
-			for (UINT32 i = 0; i < mRenderDevices.size(); ++i)
-			{
-				D3D9Device* currDevice = mRenderDevices[i];
-
-				if (currDevice->getAdapterNumber() == adapterOrdinal &&
-					currDevice->getDeviceType() == devType)
-				{
-					renderDevice = currDevice;
-					break;
-				}			
-			}
-		}
-
-		// No matching device found -> try reference device type (might have been 
-		// previously created as a fallback, but don't change devType because HAL
-		// should be preferred on creation)
-		if (renderDevice == nullptr)
-		{
-			for (UINT32 i = 0; i < mRenderDevices.size(); ++i)
-			{
-				D3D9Device* currDevice = mRenderDevices[i];
-
-				if (currDevice->getAdapterNumber() == adapterOrdinal &&
-					currDevice->getDeviceType() == D3DDEVTYPE_REF)
-				{
-					renderDevice = currDevice;
-					break;
-				}			
-			}
-		}
-
-
-		// No matching device found -> create new one.
-		if (renderDevice == nullptr)
-		{
-			renderDevice = bs_new<D3D9Device>(this, adapterOrdinal, direct3D9->GetAdapterMonitor(adapterOrdinal), devType, extraFlags);
-			mRenderDevices.push_back(renderDevice);
-
-			if (mActiveDevice == nullptr)
-				setActiveDevice(renderDevice);											
-		}				
-
-		return renderDevice;	
-	}
-
-	D3D9Driver* D3D9DeviceManager::findDriver(D3D9RenderWindowCore* renderWindow)
-	{
-		D3D9RenderAPI* renderSystem = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());		
-		IDirect3D9*	direct3D9 = D3D9RenderAPI::getDirect3D9();				
-		HMONITOR renderWindowMonitor = NULL;			
-		D3D9DriverList* driverList = renderSystem->getDirect3DDrivers();
-
-		// Find the monitor this render window belongs to.
-		renderWindowMonitor = MonitorFromWindow(renderWindow->_getWindowHandle(), MONITOR_DEFAULTTONEAREST);
-
-		// Find the matching driver using window monitor handle.
-		for (UINT32 i = 0; i < driverList->count(); ++i)
-		{
-			D3D9Driver* currDriver = driverList->item(i);
-			HMONITOR hCurrAdpaterMonitor = direct3D9->GetAdapterMonitor(currDriver->getAdapterNumber());
-
-			if (hCurrAdpaterMonitor == renderWindowMonitor)
-			{
-				return currDriver;				
-			}
-		}
-
-		return nullptr;
-	}
-
-	void D3D9DeviceManager::notifyOnDeviceDestroy(D3D9Device* device)
-	{
-		if (device != nullptr)
-		{						
-			if (device == mActiveDevice)			
-				mActiveDevice = nullptr;
-
-			auto iter = mRenderDevices.begin();
-			while (iter != mRenderDevices.end())
-			{			
-				if (*iter == device)
-				{					
-					if(device != nullptr)
-						bs_delete(device);
-
-					mRenderDevices.erase(iter);
-					break;
-				}												
-				++iter;
-			}
-
-			if (mActiveDevice == nullptr)
-			{
-				auto iter = mRenderDevices.begin();
-				if (iter != mRenderDevices.end())				
-					mActiveDevice = (*iter);
-			}
-		}
-	}
-
-	D3D9Device*	D3D9DeviceManager::getDeviceFromD3D9Device(IDirect3DDevice9* d3d9Device)
-	{
-		for (auto& device : mRenderDevices)
-		{
-			if (device->getD3D9Device() == d3d9Device)
-				return device;
-		}
-
-		return nullptr;
-	}
-}

+ 0 - 46
Source/BansheeD3D9RenderAPI/Source/BsD3D9Driver.cpp

@@ -1,46 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9Driver.h"
-
-namespace BansheeEngine
-{   
-	D3D9Driver::D3D9Driver()
-	{						
-		mAdapterNumber = 0;
-		ZeroMemory(&mD3D9DeviceCaps, sizeof(mD3D9DeviceCaps));
-		ZeroMemory(&mAdapterIdentifier, sizeof(mAdapterIdentifier));			
-	}
-
-	D3D9Driver::D3D9Driver(const D3D9Driver &ob)
-	{			
-		mAdapterNumber = ob.mAdapterNumber;
-		mD3D9DeviceCaps	= ob.mD3D9DeviceCaps;
-		mAdapterIdentifier = ob.mAdapterIdentifier;		
-	}
-
-	D3D9Driver::D3D9Driver(UINT32 adapterNumber, const D3DCAPS9& deviceCaps,
-		const D3DADAPTER_IDENTIFIER9& adapterIdentifier)
-	{				
-		mAdapterNumber = adapterNumber;
-		mD3D9DeviceCaps	= deviceCaps;
-		mAdapterIdentifier = adapterIdentifier;		
-	}
-
-	D3D9Driver::~D3D9Driver()
-	{ }
-
-	String D3D9Driver::getDriverName() const
-	{
-		return String(mAdapterIdentifier.Driver);
-	}
-
-	String D3D9Driver::getDriverDescription() const
-	{       
-		StringStream str;
-		str << "Monitor-" << (mAdapterNumber+1) << "-" << mAdapterIdentifier.Description;
-		String driverDescription(str.str());
-		StringUtil::trim(driverDescription);
-
-        return driverDescription;
-	}
-}

+ 0 - 57
Source/BansheeD3D9RenderAPI/Source/BsD3D9DriverList.cpp

@@ -1,57 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9DriverList.h"
-#include "BsD3D9VideoModeInfo.h"
-#include "BsException.h"
-#include "BsD3D9RenderAPI.h"
-
-namespace BansheeEngine 
-{
-	D3D9DriverList::D3D9DriverList()
-	{
-		IDirect3D9* lpD3D9 = D3D9RenderAPI::getDirect3D9();
-
-		for (UINT32 i = 0; i < lpD3D9->GetAdapterCount(); i++)
-		{
-			D3DADAPTER_IDENTIFIER9 adapterIdentifier;
-			D3DCAPS9 d3dcaps9;
-
-			lpD3D9->GetAdapterIdentifier(i, 0, &adapterIdentifier);
-			lpD3D9->GetDeviceCaps(i, D3DDEVTYPE_HAL, &d3dcaps9);
-
-			mDriverList.push_back(D3D9Driver(i, d3dcaps9, adapterIdentifier));
-		}
-
-		mVideoModeInfo = bs_shared_ptr_new<D3D9VideoModeInfo>(lpD3D9);
-	}
-
-	D3D9DriverList::~D3D9DriverList()
-	{
-		mDriverList.clear();
-	}
-
-	UINT32 D3D9DriverList::count() const
-	{
-		return (UINT32)mDriverList.size();
-	}
-
-	D3D9Driver* D3D9DriverList::item(UINT32 index)
-	{
-		return &mDriverList.at(index);
-	}
-
-	D3D9Driver* D3D9DriverList::item(const String &name)
-	{
-		Vector<D3D9Driver>::iterator it = mDriverList.begin();
-		if (it == mDriverList.end())
-			return nullptr;
-
-		for (;it != mDriverList.end(); ++it)
-		{
-			if (it->getDriverDescription() == name)
-				return &(*it);
-		}
-
-		return nullptr;
-	}
-}

+ 0 - 51
Source/BansheeD3D9RenderAPI/Source/BsD3D9EmulatedParamBlocks.cpp

@@ -1,51 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9EmulatedParamBlocks.h"
-#include <regex>
-
-namespace BansheeEngine
-{
-	String D3D9EmulatedParamBlockParser::parse(const String& gpuProgSource, Vector<D3D9EmulatedParamBlock>& paramBlocks)
-	{
-		static std::regex paramBlockRegex("BS_PARAM_BLOCK\\s*(.*\\})");
-		static std::regex blockNameRegex("([^\\s\\{]*)");
-		static std::regex paramNameRegex("(?:\\{ *([^\\, ]*))|(?:\\, *([^\\, \\}]*))");
-		static std::regex replaceRegex("BS_PARAM_BLOCK\\s*(.*\\}\\n?)");
-
-		std::sregex_iterator paramBlockIter(gpuProgSource.begin(), gpuProgSource.end(), paramBlockRegex);
-		std::sregex_iterator iterEnd;
-
-		while (paramBlockIter != iterEnd)
-		{
-			std::string stdString = (*paramBlockIter)[1];
-			String paramBlockString = String(stdString.begin(), stdString.end());
-
-			paramBlocks.push_back(D3D9EmulatedParamBlock());
-			D3D9EmulatedParamBlock& block = paramBlocks.back();
-
-			std::smatch nameMatch;
-			if (std::regex_search(paramBlockString, nameMatch, blockNameRegex))
-			{
-				stdString = nameMatch[1];
-				block.blockName = String(stdString.begin(), stdString.end());
-			}
-
-			std::sregex_iterator paramNameIter(paramBlockString.begin(), paramBlockString.end(), paramNameRegex);
-			while (paramNameIter != iterEnd)
-			{
-				if((*paramNameIter)[1].matched)
-					stdString = (*paramNameIter)[1];
-				else
-					stdString = (*paramNameIter)[2];
-
-				block.paramNames.push_back(String(stdString.begin(), stdString.end()));
-				++paramNameIter;
-			}
-
-			++paramBlockIter;
-		}
-
-		// Return string without param block definitions
-		return std::regex_replace(gpuProgSource, replaceRegex, "");
-	}
-}

+ 0 - 84
Source/BansheeD3D9RenderAPI/Source/BsD3D9EventQuery.cpp

@@ -1,84 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9EventQuery.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsD3D9Device.h"
-#include "BsRenderStats.h"
-#include "BsException.h"
-
-namespace BansheeEngine
-{
-	D3D9EventQuery::D3D9EventQuery()
-		:mQuery(nullptr), mDevice(nullptr), mQueryIssued(false)
-	{
-		createQuery();
-	}
-
-	D3D9EventQuery::~D3D9EventQuery()
-	{
-		releaseQuery();
-	}
-
-	void D3D9EventQuery::createQuery()
-	{
-		mDevice = D3D9RenderAPI::getActiveD3D9Device();
-
-		HRESULT hr = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &mQuery);
-		if (hr != S_OK)
-		{
-			BS_EXCEPT(RenderingAPIException, "Failed to create an Event query.");
-		}
-
-		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Query);
-	}
-
-	void D3D9EventQuery::releaseQuery()
-	{
-		SAFE_RELEASE(mQuery);
-
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_Query);
-	}
-
-	void D3D9EventQuery::begin()
-	{
-		if (mQuery != nullptr)
-			mQuery->Issue(D3DISSUE_END);
-
-		setActive(true);
-		mQueryIssued = true;
-	}
-
-	bool D3D9EventQuery::isReady() const
-	{
-		if (mQuery == nullptr) // Possibly device reset, in which case query is done
-			return mQueryIssued;
-
-		BOOL queryData;
-		return mQuery->GetData(&queryData, sizeof(BOOL), 0) == S_OK;
-	}
-
-	void D3D9EventQuery::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			createQuery();
-	}
-
-	void D3D9EventQuery::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			releaseQuery();
-	}
-
-	void D3D9EventQuery::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			releaseQuery();
-	}
-
-	void D3D9EventQuery::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			createQuery();
-	}
-}

+ 0 - 56
Source/BansheeD3D9RenderAPI/Source/BsD3D9GpuBuffer.cpp

@@ -1,56 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9GpuBuffer.h"
-#include "BsDebug.h"
-
-namespace BansheeEngine
-{
-	D3D9GpuBufferCore::D3D9GpuBufferCore(UINT32 elementCount, UINT32 elementSize, GpuBufferType type,
-		GpuBufferFormat format, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
-		: GpuBufferCore(elementCount, elementSize, type, format, usage, randomGpuWrite, useCounter)
-	{
-	}
-
-	D3D9GpuBufferCore::~D3D9GpuBufferCore()
-	{ 
-		clearBufferViews();
-	}
-
-	void D3D9GpuBufferCore::initialize()
-	{
-		LOGWRN("Generic buffers are not supported in DirectX 9. Creating a dummy buffer. All operations on it will either be no-op or return a nullptr.");
-
-		GpuBufferCore::initialize();
-	}
-
-	void* D3D9GpuBufferCore::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
-	{
-		return nullptr;
-	}
-
-	void D3D9GpuBufferCore::unlock()
-	{
-	}
-
-	void D3D9GpuBufferCore::readData(UINT32 offset, UINT32 length, void* pDest)
-	{
-	}
-
-	void D3D9GpuBufferCore::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
-	{
-	}
-
-	void D3D9GpuBufferCore::copyData(GpuBufferCore& srcBuffer, UINT32 srcOffset,
-		UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
-	{
-	}
-
-	GpuBufferView* D3D9GpuBufferCore::createView()
-	{
-		return nullptr;
-	}
-
-	void D3D9GpuBufferCore::destroyView(GpuBufferView* view)
-	{
-	}
-}

+ 0 - 379
Source/BansheeD3D9RenderAPI/Source/BsD3D9GpuProgram.cpp

@@ -1,379 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9GpuProgram.h"
-#include "BsMatrix4.h"
-#include "BsException.h"
-#include "BsD3D9Mappings.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsGpuParams.h"
-#include "BsAsyncOp.h"
-#include "BsGpuProgramManager.h"
-#include "BsD3D9HLSLParamParser.h"
-#include "BsRenderStats.h"
-#include "BsHardwareBufferManager.h"
-
-namespace BansheeEngine 
-{
-    D3D9GpuProgramCore::D3D9GpuProgramCore(const String& source, const String& entryPoint, 
-		GpuProgramType gptype, GpuProgramProfile profile)
-		: GpuProgramCore(source, entryPoint, gptype, profile, false),
-		mMicrocode(nullptr), mOptimisationLevel(OPT_DEFAULT)
-    { }
-
-	D3D9GpuProgramCore::~D3D9GpuProgramCore()
-	{ 
-		SAFE_RELEASE(mMicrocode);
-
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_GpuProgram);
-	}
-
-	void D3D9GpuProgramCore::initialize()
-	{
-		if (!isSupported())
-		{
-			mIsCompiled = false;
-			mCompileError = "Specified program is not supported by the current render system.";
-
-			GpuProgramCore::initialize();
-			return;
-		}
-
-		// Populate preprocessor defines
-		String stringBuffer;
-
-		Vector<D3DXMACRO> defines;
-		const D3DXMACRO* pDefines = 0;
-		if (!mPreprocessorDefines.empty())
-		{
-			stringBuffer = mPreprocessorDefines;
-
-			// Split preprocessor defines and build up macro array
-			D3DXMACRO macro;
-			String::size_type pos = 0;
-			while (pos != String::npos)
-			{
-				macro.Name = &stringBuffer[pos];
-				macro.Definition = 0;
-
-				String::size_type start_pos = pos;
-
-				// Find delims
-				pos = stringBuffer.find_first_of(";,=", pos);
-
-				if (start_pos == pos)
-				{
-					if (pos == stringBuffer.length())
-					{
-						break;
-					}
-					pos++;
-					continue;
-				}
-
-				if (pos != String::npos)
-				{
-					// Check definition part
-					if (stringBuffer[pos] == '=')
-					{
-						// Setup null character for macro name
-						stringBuffer[pos++] = '\0';
-						macro.Definition = &stringBuffer[pos];
-						pos = stringBuffer.find_first_of(";,", pos);
-					}
-					else
-					{
-						// No definition part, define as "1"
-						macro.Definition = "1";
-					}
-
-					if (pos != String::npos)
-					{
-						// Setup null character for macro name or definition
-						stringBuffer[pos++] = '\0';
-					}
-				}
-				else
-				{
-					macro.Definition = "1";
-				}
-				if (strlen(macro.Name) > 0)
-				{
-					defines.push_back(macro);
-				}
-				else
-				{
-					break;
-				}
-			}
-
-			// Add NULL terminator
-			macro.Name = 0;
-			macro.Definition = 0;
-			defines.push_back(macro);
-
-			pDefines = &defines[0];
-		}
-
-		// Populate compile flags
-		DWORD compileFlags = 0;
-		compileFlags |= D3DXSHADER_PACKMATRIX_ROWMAJOR;
-
-#if BS_DEBUG_MODE
-		compileFlags |= D3DXSHADER_DEBUG;
-#endif
-		switch (mOptimisationLevel)
-		{
-		case OPT_DEFAULT:
-			compileFlags |= D3DXSHADER_OPTIMIZATION_LEVEL1;
-			break;
-		case OPT_NONE:
-			compileFlags |= D3DXSHADER_SKIPOPTIMIZATION;
-			break;
-		case OPT_0:
-			compileFlags |= D3DXSHADER_OPTIMIZATION_LEVEL0;
-			break;
-		case OPT_1:
-			compileFlags |= D3DXSHADER_OPTIMIZATION_LEVEL1;
-			break;
-		case OPT_2:
-			compileFlags |= D3DXSHADER_OPTIMIZATION_LEVEL2;
-			break;
-		case OPT_3:
-			compileFlags |= D3DXSHADER_OPTIMIZATION_LEVEL3;
-			break;
-		}
-
-		LPD3DXBUFFER errors = 0;
-
-		// include handler
-		LPD3DXCONSTANTTABLE constTable;
-
-		String hlslProfile = D3D9RenderAPI::instance().getCapabilities()->gpuProgProfileToRSSpecificProfile(getProperties().getProfile());
-
-		String parsedSource = D3D9EmulatedParamBlockParser::parse(getProperties().getSource(), mBlocks);
-
-		// Compile & assemble into microcode
-		HRESULT hr = D3DXCompileShader(
-			parsedSource.c_str(),
-			static_cast<UINT>(parsedSource.length()),
-			pDefines,
-			nullptr,
-			getProperties().getEntryPoint().c_str(),
-			hlslProfile.c_str(),
-			compileFlags,
-			&mMicrocode,
-			&errors,
-			&constTable);
-
-		if (FAILED(hr))
-		{
-			String message = "Cannot compile D3D9 high-level shader ";
-
-			if (errors)
-			{
-				message += String(" Errors:\n") + static_cast<const char*>(errors->GetBufferPointer());
-				errors->Release();
-			}
-
-			mIsCompiled = false;
-			mCompileError = message;
-
-			SAFE_RELEASE(mMicrocode);
-			mMicrocode = nullptr;
-		}
-		else
-		{
-			for (UINT32 i = 0; i < D3D9RenderAPI::getResourceCreationDeviceCount(); ++i)
-			{
-				IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getResourceCreationDevice(i);
-				loadFromMicrocode(d3d9Device, mMicrocode);
-			}
-
-			D3D9HLSLParamParser paramParser(constTable, mBlocks);
-			mParametersDesc = paramParser.buildParameterDescriptions();
-
-			// Get input declaration
-			if (mProperties.getType() == GPT_VERTEX_PROGRAM)
-			{
-				UINT32 numInputs = 0;
-				D3DXGetShaderInputSemantics((DWORD*)mMicrocode->GetBufferPointer(), nullptr, &numInputs);
-
-				List<VertexElement> elements;
-				if (numInputs > 0)
-				{
-					D3DXSEMANTIC* semantics = bs_stack_alloc<D3DXSEMANTIC>(numInputs);
-
-					for (UINT32 i = 0; i < numInputs; i++)
-					{
-						elements.push_back(VertexElement(0, 0, VET_FLOAT4, 
-							D3D9Mappings::get((D3DDECLUSAGE)semantics[i].Usage), semantics[i].UsageIndex));
-					}
-
-					bs_stack_free(semantics);
-				}
-
-				mInputDeclaration = HardwareBufferCoreManager::instance().createVertexDeclaration(elements);
-			}
-
-			mIsCompiled = true;
-			mCompileError = "";
-
-			SAFE_RELEASE(constTable);
-		}
-
-		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_GpuProgram);
-		GpuProgramCore::initialize();
-	}
-
-	D3D9GpuVertexProgramCore::D3D9GpuVertexProgramCore(const String& source, const String& entryPoint,
-		GpuProgramProfile profile)
-		: D3D9GpuProgramCore(source, entryPoint, GPT_VERTEX_PROGRAM, profile)
-    {
-
-    }
-
-	D3D9GpuVertexProgramCore::~D3D9GpuVertexProgramCore()
-	{	
-		auto it = mMapDeviceToVertexShader.begin();
-
-		while (it != mMapDeviceToVertexShader.end())
-		{
-			SAFE_RELEASE(it->second);
-			++it;
-		}
-		mMapDeviceToVertexShader.clear();
-	}
-
-    void D3D9GpuVertexProgramCore::loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode)
-    {		 
-		auto it = mMapDeviceToVertexShader.find(d3d9Device);
-
-		if (it != mMapDeviceToVertexShader.end())
-			SAFE_RELEASE(it->second);
-
-		// Create the shader
-		IDirect3DVertexShader9* pVertexShader;
-		HRESULT hr;
-			
-		hr = d3d9Device->CreateVertexShader( 
-			static_cast<DWORD*>(microcode->GetBufferPointer()), 
-			&pVertexShader);
-
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Cannot create D3D9 vertex shader from microcode");
-		}
-
-		mMapDeviceToVertexShader[d3d9Device] = pVertexShader;
-    }
-
-	void D3D9GpuVertexProgramCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{
-		
-	}
-
-	void D3D9GpuVertexProgramCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		auto it = mMapDeviceToVertexShader.find(d3d9Device);
-
-		// Case shader found -> release it and erase from map.
-		if (it != mMapDeviceToVertexShader.end())
-		{
-			SAFE_RELEASE(it->second);
-			mMapDeviceToVertexShader.erase(it);
-		}
-	}
-
-	IDirect3DVertexShader9* D3D9GpuVertexProgramCore::getVertexShader()
-	{
-		if (!isCompiled())
-			return nullptr;
-
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-		auto it = mMapDeviceToVertexShader.find(d3d9Device);
-
-		// Shader was not found -> load it.
-		if (it == mMapDeviceToVertexShader.end())		
-		{
-			loadFromMicrocode(d3d9Device, mMicrocode);
-			it = mMapDeviceToVertexShader.find(d3d9Device);
-		}
-	
-		return it->second;
-	}
-
-	D3D9GpuFragmentProgramCore::D3D9GpuFragmentProgramCore(const String& source, const String& entryPoint,
-		GpuProgramProfile profile)
-		: D3D9GpuProgramCore(source, entryPoint, GPT_FRAGMENT_PROGRAM, profile)
-    {
-
-    }
-
-	D3D9GpuFragmentProgramCore::~D3D9GpuFragmentProgramCore()
-	{
-		auto it = mMapDeviceToPixelShader.begin();
-
-		while (it != mMapDeviceToPixelShader.end())
-		{
-			SAFE_RELEASE(it->second);
-			++it;
-		}
-		mMapDeviceToPixelShader.clear();
-	}
-
-	void D3D9GpuFragmentProgramCore::loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode)
-    {
-		auto it = mMapDeviceToPixelShader.find(d3d9Device);
-
-		if (it != mMapDeviceToPixelShader.end())
-			SAFE_RELEASE(it->second);
-
-		// Create the shader
-		IDirect3DPixelShader9* pPixelShader;
-		HRESULT hr;
-
-		hr = d3d9Device->CreatePixelShader(static_cast<DWORD*>(microcode->GetBufferPointer()), &pPixelShader);
-
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Cannot create D3D9 pixel shader from microcode.");
-
-		mMapDeviceToPixelShader[d3d9Device] = pPixelShader;
-    }
-
-	void D3D9GpuFragmentProgramCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{
-		
-	}
-
-	void D3D9GpuFragmentProgramCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		auto it = mMapDeviceToPixelShader.find(d3d9Device);
-
-		// Case shader found -> release it and erase from map.
-		if (it != mMapDeviceToPixelShader.end())
-		{
-			SAFE_RELEASE(it->second);
-			mMapDeviceToPixelShader.erase(it);
-		}
-	}
-
-	IDirect3DPixelShader9* D3D9GpuFragmentProgramCore::getPixelShader()
-	{
-		if (!isCompiled())
-			return nullptr;
-
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-		auto it = mMapDeviceToPixelShader.find(d3d9Device);
-
-		// Shader was not found -> load it.
-		if (it == mMapDeviceToPixelShader.end())		
-		{
-			loadFromMicrocode(d3d9Device, mMicrocode);
-			it = mMapDeviceToPixelShader.find(d3d9Device);
-		}
-
-		return it->second;
-	}
-}
-

+ 0 - 73
Source/BansheeD3D9RenderAPI/Source/BsD3D9HLSLProgramFactory.cpp

@@ -1,73 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9HLSLProgramFactory.h"
-#include "BsD3D9GpuProgram.h"
-
-namespace BansheeEngine
-{
-    String D3D9HLSLProgramFactory::LANGUAGE_NAME = "hlsl9";
-
-    D3D9HLSLProgramFactory::D3D9HLSLProgramFactory()
-    {
-    }
-
-    D3D9HLSLProgramFactory::~D3D9HLSLProgramFactory()
-    {
-    }
-
-    const String& D3D9HLSLProgramFactory::getLanguage() const
-    {
-        return LANGUAGE_NAME;
-    }
-
-	SPtr<GpuProgramCore> D3D9HLSLProgramFactory::create(const String& source, const String& entryPoint,
-		GpuProgramType gptype, GpuProgramProfile profile, bool requiresAdjacency)
-    {
-		SPtr<GpuProgramCore> gpuProg;
-
-		if (gptype == GPT_VERTEX_PROGRAM)
-		{
-			D3D9GpuVertexProgramCore* prog = new (bs_alloc<D3D9GpuVertexProgramCore>())
-				D3D9GpuVertexProgramCore(source, entryPoint, profile);
-
-			gpuProg = bs_shared_ptr<D3D9GpuVertexProgramCore>(prog);
-		}
-		else if (gptype == GPT_FRAGMENT_PROGRAM)
-		{
-			D3D9GpuFragmentProgramCore* prog = new (bs_alloc<D3D9GpuFragmentProgramCore>())
-				D3D9GpuFragmentProgramCore(source, entryPoint, profile);
-
-			gpuProg = bs_shared_ptr<D3D9GpuFragmentProgramCore>(prog);
-		}
-
-		if (gpuProg != nullptr)
-			gpuProg->_setThisPtr(gpuProg);
-
-		return gpuProg;
-    }
-
-	SPtr<GpuProgramCore> D3D9HLSLProgramFactory::create(GpuProgramType type)
-	{
-		SPtr<GpuProgramCore> gpuProg;
-
-		if (type == GPT_VERTEX_PROGRAM)
-		{
-			D3D9GpuVertexProgramCore* prog = new (bs_alloc<D3D9GpuVertexProgramCore>())
-				D3D9GpuVertexProgramCore("", "", GPP_NONE);
-
-			gpuProg = bs_shared_ptr<D3D9GpuVertexProgramCore>(prog);
-		}
-		else if (type == GPT_FRAGMENT_PROGRAM)
-		{
-			D3D9GpuFragmentProgramCore* prog = new (bs_alloc<D3D9GpuFragmentProgramCore>())
-				D3D9GpuFragmentProgramCore("", "", GPP_NONE);
-
-			gpuProg = bs_shared_ptr<D3D9GpuFragmentProgramCore>(prog);
-		}
-
-		if (gpuProg != nullptr)
-			gpuProg->_setThisPtr(gpuProg);
-
-		return gpuProg;
-	}
-}

+ 0 - 63
Source/BansheeD3D9RenderAPI/Source/BsD3D9HardwareBufferManager.cpp

@@ -1,63 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9HardwareBufferManager.h"
-#include "BsD3D9VertexBuffer.h"
-#include "BsD3D9IndexBuffer.h"
-#include "BsD3D9VertexDeclaration.h"
-#include "BsD3D9GpuBuffer.h"
-#include "BsGpuParamBlockBuffer.h"
-#include "BsException.h"
-
-namespace BansheeEngine 
-{
-	SPtr<VertexBufferCore> D3D9HardwareBufferCoreManager::createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
-	{
-		assert(numVerts > 0);
-
-		SPtr<D3D9VertexBufferCore> ret = bs_shared_ptr_new<D3D9VertexBufferCore>(vertexSize, numVerts, usage, streamOut);
-		ret->_setThisPtr(ret);
-
-		return ret;
-	}
-
-	SPtr<IndexBufferCore> D3D9HardwareBufferCoreManager::createIndexBufferInternal(IndexType itype, UINT32 numIndices, GpuBufferUsage usage)
-	{
-		assert(numIndices > 0);
-
-		SPtr<D3D9IndexBufferCore> ret = bs_shared_ptr_new<D3D9IndexBufferCore>(itype, numIndices, usage);
-		ret->_setThisPtr(ret);
-
-		return ret;
-	}
-
-	SPtr<VertexDeclarationCore> D3D9HardwareBufferCoreManager::createVertexDeclarationInternal(const List<VertexElement>& elements)
-	{
-		D3D9VertexDeclarationCore* decl = new (bs_alloc<D3D9VertexDeclarationCore>()) D3D9VertexDeclarationCore(elements);
-		
-		SPtr<D3D9VertexDeclarationCore> declPtr = bs_shared_ptr<D3D9VertexDeclarationCore>(decl);
-		declPtr->_setThisPtr(declPtr);
-
-		return declPtr;
-	}
-
-	SPtr<GpuParamBlockBufferCore> D3D9HardwareBufferCoreManager::createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage)
-	{
-		GenericGpuParamBlockBufferCore* paramBlockBuffer = new (bs_alloc<GenericGpuParamBlockBufferCore>()) GenericGpuParamBlockBufferCore(size, usage);
-
-		SPtr<GpuParamBlockBufferCore> paramBlockBufferPtr = bs_shared_ptr<GenericGpuParamBlockBufferCore>(paramBlockBuffer);
-		paramBlockBufferPtr->_setThisPtr(paramBlockBufferPtr);
-
-		return paramBlockBufferPtr;
-	}
-
-	SPtr<GpuBufferCore> D3D9HardwareBufferCoreManager::createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
-		GpuBufferType type, GpuBufferFormat format, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
-	{
-		D3D9GpuBufferCore* buffer = new (bs_alloc<D3D9GpuBufferCore>()) D3D9GpuBufferCore(elementCount, elementSize, type, format, usage, randomGpuWrite, useCounter);
-
-		SPtr<GpuBufferCore> bufferPtr = bs_shared_ptr<D3D9GpuBufferCore>(buffer);
-		bufferPtr->_setThisPtr(bufferPtr);
-
-		return bufferPtr;
-	}
-}

+ 0 - 307
Source/BansheeD3D9RenderAPI/Source/BsD3D9IndexBuffer.cpp

@@ -1,307 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9IndexBuffer.h"
-#include "BsD3D9Mappings.h"
-#include "BsException.h"
-#include "BsD3D9HardwareBufferManager.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9Device.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsRenderStats.h"
-
-namespace BansheeEngine 
-{
-	D3D9IndexBufferCore::D3D9IndexBufferCore(IndexType idxType, UINT32 numIndices, GpuBufferUsage usage)
-		: IndexBufferCore(idxType, numIndices, usage), mSystemMemoryBuffer(nullptr)
-	{ }
-
-	D3D9IndexBufferCore::~D3D9IndexBufferCore()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
-
-		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
-		{
-			BufferResources* bufferResources = bufferResourcesPair.second;
-
-			SAFE_RELEASE(bufferResources->mBuffer);
-
-			if (bufferResources != nullptr)
-				bs_delete(bufferResources);
-		}
-
-		mMapDeviceToBufferResources.clear();
-
-		if (mSystemMemoryBuffer != nullptr)
-			bs_free(mSystemMemoryBuffer);
-
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
-	}
-
-	void D3D9IndexBufferCore::initialize()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
-
-		// Set the desired memory pool.
-		mBufferDesc.Pool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
-
-		// Allocate the system memory buffer.
-		mSystemMemoryBuffer = (UINT8*) bs_alloc(getSizeInBytes());
-		memset(mSystemMemoryBuffer, 0, getSizeInBytes());
-
-		// Case we have to create this buffer resource on loading.
-		if (D3D9RenderAPI::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-		{
-			for (UINT32 i = 0; i < D3D9RenderAPI::getResourceCreationDeviceCount(); ++i)
-			{
-				IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getResourceCreationDevice(i);
-
-				createBuffer(d3d9Device, mBufferDesc.Pool);
-			}
-		}	
-
-		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
-		IndexBufferCore::initialize();
-	}
-
-	void* D3D9IndexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
-    {		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-#if BS_PROFILING_ENABLED
-		if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
-		{
-			BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
-		}
-
-		if (options == GBL_READ_WRITE || options == GBL_WRITE_ONLY || options == GBL_WRITE_ONLY_DISCARD || options == GBL_WRITE_ONLY_NO_OVERWRITE)
-		{
-			BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
-		}
-#endif
-
-		if (options != GBL_READ_ONLY)
-		{
-			for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
-			{
-				BufferResources* bufferResources = bufferResourcesPair.second;
-				bufferResources->mOutOfDate = true;
-
-				if(bufferResources->mLockLength > 0)
-				{
-					UINT32 highPoint = std::max(offset + length, 
-						bufferResources->mLockOffset + bufferResources->mLockLength);
-					bufferResources->mLockOffset = std::min(bufferResources->mLockOffset, offset);
-					bufferResources->mLockLength = highPoint - bufferResources->mLockOffset;
-				}
-				else
-				{
-					if (offset < bufferResources->mLockOffset)
-						bufferResources->mLockOffset = offset;
-					if (length > bufferResources->mLockLength)
-						bufferResources->mLockLength = length;
-				}
-			
-				if (bufferResources->mLockOptions != GBL_WRITE_ONLY_DISCARD)
-					bufferResources->mLockOptions = options;
-			}
-		}
-
-		return mSystemMemoryBuffer + offset;		
-    }
-
-	void D3D9IndexBufferCore::unlockImpl()
-    {	
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
-		{
-			BufferResources* bufferResources = bufferResourcesPair.second;
-
-			if (bufferResources->mOutOfDate && bufferResources->mBuffer != nullptr)
-				updateBufferResources(mSystemMemoryBuffer, bufferResources);
-		}			
-    }
-
-	void D3D9IndexBufferCore::readData(UINT32 offset, UINT32 length, void* dest)
-    {
-        void* pSrc = this->lock(offset, length, GBL_READ_ONLY);
-        memcpy(dest, pSrc, length);
-        this->unlock();
-    }
-
-	void D3D9IndexBufferCore::writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags)
-    {
-		GpuLockOptions lockOption = GBL_WRITE_ONLY;
-		if(writeFlags == BufferWriteType::Discard)
-			lockOption = GBL_WRITE_ONLY_DISCARD;
-		else if(writeFlags == BufferWriteType::NoOverwrite)
-			lockOption = GBL_WRITE_ONLY_NO_OVERWRITE;
-
-        void* pDst = this->lock(offset, length, lockOption);
-        memcpy(pDst, source, length);
-        this->unlock();    
-	}
-
-	void D3D9IndexBufferCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{			
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (D3D9RenderAPI::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-			createBuffer(d3d9Device, mBufferDesc.Pool);	
-
-	}
-
-	void D3D9IndexBufferCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-		if (iterFind != mMapDeviceToBufferResources.end())	
-		{									
-			SAFE_RELEASE(iterFind->second->mBuffer);
-
-			if(iterFind->second != nullptr)
-				bs_delete(iterFind->second);
-
-			mMapDeviceToBufferResources.erase(iterFind);
-		}
-	}
-
-	void D3D9IndexBufferCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (mBufferDesc.Pool == D3DPOOL_DEFAULT)
-		{
-			auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-			if (iterFind != mMapDeviceToBufferResources.end())
-			{			
-				SAFE_RELEASE(iterFind->second->mBuffer);	
-			}					
-		}
-	}
-
-	void D3D9IndexBufferCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (mBufferDesc.Pool == D3DPOOL_DEFAULT)
-		{
-			if (D3D9RenderAPI::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-				createBuffer(d3d9Device, mBufferDesc.Pool);
-		}
-	}
-
-	void D3D9IndexBufferCore::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL pool)
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		BufferResources* bufferResources;		
-		HRESULT hr;
-
-		// Find the vertex buffer of this device.
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-		if (iterFind != mMapDeviceToBufferResources.end())
-		{
-			bufferResources = iterFind->second;
-			SAFE_RELEASE(bufferResources->mBuffer);
-		}
-		else
-		{
-			bufferResources = bs_new<BufferResources>();			
-			mMapDeviceToBufferResources[d3d9Device] = bufferResources;
-		}
-
-		bufferResources->mBuffer = nullptr;
-		bufferResources->mOutOfDate = true;
-		bufferResources->mLockOffset = 0;
-		bufferResources->mLockLength = getSizeInBytes();
-		bufferResources->mLockOptions = GBL_READ_WRITE;
-
-		// Create the Index buffer				
-		hr = d3d9Device->CreateIndexBuffer(
-			static_cast<UINT>(mSizeInBytes),
-			D3D9Mappings::get(mUsage),
-			D3D9Mappings::get(mProperties.getType()),
-			pool,
-			&bufferResources->mBuffer,
-			nullptr
-			);
-
-		if (FAILED(hr))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Cannot create D3D9 Index buffer: " + msg);
-		}
-
-		hr = bufferResources->mBuffer->GetDesc(&mBufferDesc);
-		if (FAILED(hr))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Cannot get D3D9 Index buffer desc: " + msg);
-		}		
-	}
-
-	IDirect3DIndexBuffer9* D3D9IndexBufferCore::getD3DIndexBuffer()
-	{		
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-
-		// Find the index buffer of this device.
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-
-		// Case index buffer was not found for the current device -> create it.		
-		if (iterFind == mMapDeviceToBufferResources.end() || iterFind->second->mBuffer == nullptr)
-		{						
-			createBuffer(d3d9Device, mBufferDesc.Pool);
-			iterFind = mMapDeviceToBufferResources.find(d3d9Device);						
-		}
-
-		if (iterFind->second->mOutOfDate)
-			updateBufferResources(mSystemMemoryBuffer, iterFind->second);
-
-		return iterFind->second->mBuffer;
-	}
-
-	bool D3D9IndexBufferCore::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
-	{
-		assert(bufferResources != nullptr);
-		assert(bufferResources->mBuffer != nullptr);
-		assert(bufferResources->mOutOfDate);
-		
-		if (bufferResources->mLockLength != 0)
-		{
-			void* dstBytes;
-			HRESULT hr;
-
-			// Lock the buffer.
-			hr = bufferResources->mBuffer->Lock(
-				static_cast<UINT>(bufferResources->mLockOffset),
-				static_cast<UINT>(bufferResources->mLockLength),
-				&dstBytes,
-				D3D9Mappings::get(bufferResources->mLockOptions, mUsage));
-
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Cannot lock D3D9 vertex buffer: " + msg);
-			}
-
-			memcpy(dstBytes, systemMemoryBuffer + bufferResources->mLockOffset, bufferResources->mLockLength);
-
-			// Unlock the buffer.
-			hr = bufferResources->mBuffer->Unlock();
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Cannot unlock D3D9 vertex buffer: " + msg);
-			}
-		}
-
-		bufferResources->mOutOfDate = false;
-		bufferResources->mLockOffset = mSizeInBytes;
-		bufferResources->mLockLength = 0;
-		bufferResources->mLockOptions = GBL_READ_WRITE;
-
-		return true;			
-	}
-}

+ 0 - 587
Source/BansheeD3D9RenderAPI/Source/BsD3D9Mappings.cpp

@@ -1,587 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9Mappings.h"
-#include "BsException.h"
-#include "BsMatrix4.h"
-
-namespace BansheeEngine 
-{
-	D3DTEXTUREADDRESS D3D9Mappings::get(TextureAddressingMode tam, const D3DCAPS9& devCaps)
-	{
-		switch(tam)
-		{
-		case TAM_WRAP:
-			return D3DTADDRESS_WRAP;
-		case TAM_MIRROR:
-			return D3DTADDRESS_MIRROR;
-		case TAM_CLAMP:
-			return D3DTADDRESS_CLAMP;
-        case TAM_BORDER:
-            if (devCaps.TextureAddressCaps & D3DPTADDRESSCAPS_BORDER)
-                return D3DTADDRESS_BORDER;
-            else
-                return D3DTADDRESS_CLAMP;
-		}
-
-		return D3DTADDRESS_FORCE_DWORD;
-	}
-
-	D3DBLEND D3D9Mappings::get(BlendFactor sbf)
-	{
-		switch(sbf)
-		{
-		case BF_ONE:
-			return D3DBLEND_ONE;
-		case BF_ZERO:
-			return D3DBLEND_ZERO;
-		case BF_DEST_COLOR:
-			return D3DBLEND_DESTCOLOR;
-		case BF_SOURCE_COLOR:
-			return D3DBLEND_SRCCOLOR;
-		case BF_INV_DEST_COLOR:
-			return D3DBLEND_INVDESTCOLOR;
-		case BF_INV_SOURCE_COLOR:
-			return D3DBLEND_INVSRCCOLOR;
-		case BF_DEST_ALPHA:
-			return D3DBLEND_DESTALPHA;
-		case BF_SOURCE_ALPHA:
-			return D3DBLEND_SRCALPHA;
-		case BF_INV_DEST_ALPHA:
-			return D3DBLEND_INVDESTALPHA;
-		case BF_INV_SOURCE_ALPHA:
-			return D3DBLEND_INVSRCALPHA;
-		}
-
-		return D3DBLEND_FORCE_DWORD;
-	}
-
-	D3DBLENDOP D3D9Mappings::get(BlendOperation sbo)
-	{
-		switch(sbo)
-		{
-		case BO_ADD:
-			return D3DBLENDOP_ADD;
-		case BO_SUBTRACT:
-			return D3DBLENDOP_SUBTRACT;
-		case BO_REVERSE_SUBTRACT:
-			return D3DBLENDOP_REVSUBTRACT;
-		case BO_MIN:
-			return D3DBLENDOP_MIN;
-		case BO_MAX:
-			return D3DBLENDOP_MAX;
-		}
-
-		return D3DBLENDOP_FORCE_DWORD;
-	}
-
-	DWORD D3D9Mappings::get(CompareFunction cf)
-	{
-		switch(cf)
-		{
-		case CMPF_ALWAYS_FAIL:
-			return D3DCMP_NEVER;
-		case CMPF_ALWAYS_PASS:
-			return D3DCMP_ALWAYS;
-		case CMPF_LESS:
-			return D3DCMP_LESS;
-		case CMPF_LESS_EQUAL:
-			return D3DCMP_LESSEQUAL;
-		case CMPF_EQUAL:
-			return D3DCMP_EQUAL;
-		case CMPF_NOT_EQUAL:
-			return D3DCMP_NOTEQUAL;
-		case CMPF_GREATER_EQUAL:
-			return D3DCMP_GREATEREQUAL;
-		case CMPF_GREATER:
-			return D3DCMP_GREATER;
-		};
-
-		return 0;
-	}
-
-	DWORD D3D9Mappings::get(CullingMode cm, bool flip)
-	{
-		switch(cm)
-		{
-		case CULL_NONE:
-			return D3DCULL_NONE;
-		case CULL_CLOCKWISE:
-			if(flip)
-				return D3DCULL_CCW;
-			else
-				return D3DCULL_CW;
-		case CULL_COUNTERCLOCKWISE:
-			if(flip)
-				return D3DCULL_CW;
-			else
-				return D3DCULL_CCW;
-		}
-
-		return 0;
-	}
-
-	D3DFILLMODE D3D9Mappings::get(PolygonMode level)
-	{
-		switch(level)
-		{
-		case PM_WIREFRAME:
-			return D3DFILL_WIREFRAME;
-		case PM_SOLID:
-			return D3DFILL_SOLID;
-		}
-
-		return D3DFILL_FORCE_DWORD;
-	}
-
-	DWORD D3D9Mappings::get(StencilOperation op, bool invert)
-	{
-		switch(op)
-		{
-		case SOP_KEEP:
-			return D3DSTENCILOP_KEEP;
-		case SOP_ZERO:
-			return D3DSTENCILOP_ZERO;
-		case SOP_REPLACE:
-			return D3DSTENCILOP_REPLACE;
-		case SOP_INCREMENT:
-            return invert ? D3DSTENCILOP_DECRSAT : D3DSTENCILOP_INCRSAT;
-		case SOP_DECREMENT:
-            return invert ? D3DSTENCILOP_INCRSAT : D3DSTENCILOP_DECRSAT;
-		case SOP_INCREMENT_WRAP:
-            return invert ? D3DSTENCILOP_DECR : D3DSTENCILOP_INCR;
-		case SOP_DECREMENT_WRAP:
-            return invert ? D3DSTENCILOP_INCR : D3DSTENCILOP_DECR;
-		case SOP_INVERT:
-			return D3DSTENCILOP_INVERT;
-		}
-
-		return 0;
-	}
-
-	D3DSAMPLERSTATETYPE D3D9Mappings::get(FilterType ft)
-    {
-        switch (ft)
-        {
-        case FT_MIN:
-            return D3DSAMP_MINFILTER;
-            break;
-        case FT_MAG:
-            return D3DSAMP_MAGFILTER;
-            break;
-        case FT_MIP:
-            return D3DSAMP_MIPFILTER;
-            break;
-        }
-
-        return D3DSAMP_MINFILTER;
-    }
-
-	DWORD D3D9Mappings::get(FilterType ft, FilterOptions fo, const D3DCAPS9& devCaps, D3DTexType texType)
-	{
-		// Assume normal
-		DWORD capsType = devCaps.TextureFilterCaps;
-
-		switch( texType )
-		{
-		case D3D_TEX_TYPE_NORMAL:
-			capsType = devCaps.TextureFilterCaps;
-			break;
-		case D3D_TEX_TYPE_CUBE:
-			capsType = devCaps.CubeTextureFilterCaps;
-			break;
-		case D3D_TEX_TYPE_VOLUME:
-			capsType = devCaps.VolumeTextureFilterCaps;
-			break;
-		}
-
-        switch (ft)
-        {
-        case FT_MIN:
-            switch(fo)
-            {
-                // NOTE: Fall through if device doesn't support requested type
-            case FO_ANISOTROPIC:
-                if(capsType & D3DPTFILTERCAPS_MINFANISOTROPIC)
-                {
-                    return D3DTEXF_ANISOTROPIC;
-                    break;
-                }
-            case FO_LINEAR:
-                if(capsType & D3DPTFILTERCAPS_MINFLINEAR)
-                {
-                    return D3DTEXF_LINEAR;
-                    break;
-                }
-            case FO_POINT:
-            case FO_NONE:
-                return D3DTEXF_POINT;
-                break;
-            }
-            break;
-        case FT_MAG:
-            switch( fo )
-            {
-            // NOTE: Fall through if device doesn't support requested type
-            case FO_ANISOTROPIC:
-                if(capsType & D3DPTFILTERCAPS_MAGFANISOTROPIC)
-                {
-                    return D3DTEXF_ANISOTROPIC;
-                    break;
-                }
-            case FO_LINEAR:
-                if(capsType & D3DPTFILTERCAPS_MAGFLINEAR)
-                {
-                    return D3DTEXF_LINEAR;
-                    break;
-                }
-            case FO_POINT:
-            case FO_NONE:
-                return D3DTEXF_POINT;
-                break;
-            }
-            break;
-        case FT_MIP:
-            switch( fo )
-            {
-            case FO_ANISOTROPIC:
-            case FO_LINEAR:
-                if(capsType & D3DPTFILTERCAPS_MIPFLINEAR)
-                {
-                    return D3DTEXF_LINEAR;
-                    break;
-                }
-            case FO_POINT:
-                if(capsType & D3DPTFILTERCAPS_MIPFPOINT)
-                {
-                    return D3DTEXF_POINT;
-                    break;
-                }
-            case FO_NONE:
-                return D3DTEXF_NONE;
-                break;
-            }
-            break;
-        }
-
-        return 0;
-	}
-
-	D3D9Mappings::D3DTexType D3D9Mappings::get(TextureType texType)
-	{
-		switch( texType )
-		{
-		case TEX_TYPE_1D :
-		case TEX_TYPE_2D :
-			return D3D9Mappings::D3D_TEX_TYPE_NORMAL;
-		case TEX_TYPE_CUBE_MAP :
-			return D3D9Mappings::D3D_TEX_TYPE_CUBE;
-		case TEX_TYPE_3D :
-            return D3D9Mappings::D3D_TEX_TYPE_VOLUME;
-		}
-		return D3D9Mappings::D3D_TEX_TYPE_NONE;
-	}
-
-    DWORD D3D9Mappings::get(GpuBufferUsage usage)
-    {
-        DWORD ret = 0;
-        if (usage & GBU_DYNAMIC)
-        {
-            ret |= D3DUSAGE_DYNAMIC;
-        }
-
-        return ret;
-    }
-
-    DWORD D3D9Mappings::get(GpuLockOptions options, GpuBufferUsage usage)
-    {
-        DWORD ret = 0;
-        if (options == GBL_WRITE_ONLY_DISCARD)
-        {
-            // D3D doesn't like discard or no_overwrite on non-dynamic buffers
-            if (usage & GBU_DYNAMIC)
-                ret |= D3DLOCK_DISCARD;
-        }
-        
-		if (options == GBL_READ_ONLY)
-        {
-			ret |= D3DLOCK_READONLY;
-        }
-
-        if (options == GBL_WRITE_ONLY_NO_OVERWRITE)
-        {
-            // D3D doesn't like discard or no_overwrite on non-dynamic buffers
-            if (usage & GBU_DYNAMIC)
-                ret |= D3DLOCK_NOOVERWRITE;
-        }
-
-        return ret;
-    }
-
-    D3DFORMAT D3D9Mappings::get(IndexType itype)
-    {
-        if (itype == IT_32BIT)
-        {
-            return D3DFMT_INDEX32;
-        }
-        else
-        {
-            return D3DFMT_INDEX16;
-        }
-    }
-
-	D3DDECLTYPE D3D9Mappings::get(VertexElementType vType)
-	{
-		switch (vType)
-		{
-		case VET_COLOR:
-		case VET_COLOR_ABGR:
-		case VET_COLOR_ARGB:
-		case VET_UBYTE4_NORM:
-			return D3DDECLTYPE_D3DCOLOR;
-		case VET_FLOAT1:
-			return D3DDECLTYPE_FLOAT1;
-		case VET_FLOAT2:
-			return D3DDECLTYPE_FLOAT2;
-		case VET_FLOAT3:
-			return D3DDECLTYPE_FLOAT3;
-		case VET_FLOAT4:
-			return D3DDECLTYPE_FLOAT4;
-        case VET_SHORT2:
-			return D3DDECLTYPE_SHORT2;
-        case VET_SHORT4:
-			return D3DDECLTYPE_SHORT4;
-        case VET_UBYTE4:
-            return D3DDECLTYPE_UBYTE4;
-		default:
-			LOGWRN("Invalid vertex element type for DX9.");
-			break;
-		}
-
-		return D3DDECLTYPE_FLOAT3;
-	}
-
-	D3DDECLUSAGE D3D9Mappings::get(VertexElementSemantic sem)
-	{
-		switch (sem)
-		{
-		case VES_BLEND_INDICES:
-			return D3DDECLUSAGE_BLENDINDICES;
-		case VES_BLEND_WEIGHTS:
-			return D3DDECLUSAGE_BLENDWEIGHT;
-		case VES_COLOR:
-			return D3DDECLUSAGE_COLOR;
-		case VES_NORMAL:
-			return D3DDECLUSAGE_NORMAL;
-		case VES_POSITION:
-			return D3DDECLUSAGE_POSITION;
-		case VES_TEXCOORD:
-			return D3DDECLUSAGE_TEXCOORD;
-		case VES_BITANGENT:
-			return D3DDECLUSAGE_BINORMAL;
-		case VES_TANGENT:
-			return D3DDECLUSAGE_TANGENT;
-		default:
-			BS_EXCEPT(RenderingAPIException, "Invalid semantic for D3D9 render system: " + toString(sem));
-		}
-
-		return D3DDECLUSAGE_POSITION;
-	}
-
-	VertexElementSemantic D3D9Mappings::get(D3DDECLUSAGE sem)
-	{
-		switch (sem)
-		{
-		case D3DDECLUSAGE_BLENDINDICES:
-			return VES_BLEND_INDICES;
-		case D3DDECLUSAGE_BLENDWEIGHT:
-			return VES_BLEND_WEIGHTS;
-		case D3DDECLUSAGE_COLOR:
-			return VES_COLOR;
-		case D3DDECLUSAGE_NORMAL:
-			return VES_NORMAL;
-		case D3DDECLUSAGE_POSITION:
-			return VES_POSITION;
-		case D3DDECLUSAGE_TEXCOORD:
-			return VES_TEXCOORD;
-		case D3DDECLUSAGE_BINORMAL:
-			return VES_BITANGENT;
-		case D3DDECLUSAGE_TANGENT:
-			return VES_TANGENT;
-		default:
-			BS_EXCEPT(RenderingAPIException, "Invalid semantic for D3D9 render system: " + toString(sem));
-		}
-
-		return VES_POSITION;
-	}
-
-	D3DXMATRIX D3D9Mappings::makeD3DXMatrix(const Matrix4& mat)
-	{
-		// Transpose matrix
-		// D3D9 uses row vectors i.e. V*M
-		return D3DXMATRIX(
-            mat[0][0], mat[1][0], mat[2][0], mat[3][0],
-            mat[0][1], mat[1][1], mat[2][1], mat[3][1],
-            mat[0][2], mat[1][2], mat[2][2], mat[3][2],
-            mat[0][3], mat[1][3], mat[2][3], mat[3][3]);
-	}
-
-	Matrix4 D3D9Mappings::convertD3DXMatrix(const D3DXMATRIX& mat)
-	{
-		return Matrix4(
-            mat.m[0][0], mat.m[1][0], mat.m[2][0], mat.m[3][0],
-            mat.m[0][1], mat.m[1][1], mat.m[2][1], mat.m[3][1],
-            mat.m[0][2], mat.m[1][2], mat.m[2][2], mat.m[3][2],
-            mat.m[0][3], mat.m[1][3], mat.m[2][3], mat.m[3][3]);
-	}
-
-	PixelFormat D3D9Mappings::_getPF(D3DFORMAT d3dPF)
-	{
-		switch(d3dPF)
-		{
-		case D3DFMT_R8G8B8:
-			return PF_B8G8R8;
-		case D3DFMT_A8R8G8B8:
-			return PF_B8G8R8A8;
-		case D3DFMT_A8B8G8R8:
-			return PF_R8G8B8A8;
-		case D3DFMT_X8B8G8R8:
-			return PF_R8G8B8X8;
-		case D3DFMT_X8R8G8B8:
-			return PF_B8G8R8X8;
-		case D3DFMT_R16F:
-			return PF_FLOAT16_R;
-		case D3DFMT_A16B16G16R16F:
-			return PF_FLOAT16_RGBA;
-		case D3DFMT_R32F:
-			return PF_FLOAT32_R;
-		case D3DFMT_G32R32F: // TODO - For some reason G and R are flipped in DX9 which might not be compatible with other render systems directly
-			return PF_FLOAT32_RG;
-		case D3DFMT_A32B32G32R32F:
-			return PF_FLOAT32_RGBA;
-		case D3DFMT_G16R16F: // TODO - For some reason G and R are flipped in DX9 which might not be compatible with other render systems directly
-			return PF_FLOAT16_RG;
-		case D3DFMT_DXT1:
-			return PF_BC1;
-		case D3DFMT_DXT3:
-			return PF_BC2;
-		case D3DFMT_DXT5:
-			return PF_BC3;
-		case D3DFMT_D24S8:
-			return PF_D24S8;
-		case D3DFMT_D32F_LOCKABLE:
-			return PF_D32;
-		case D3DFMT_D16:
-			return PF_D16;
-		case D3DFMT_A2B10G10R10:
-			return PF_UNORM_R10G10B10A2;
-		default:
-			return PF_UNKNOWN;
-		}
-	}
-
-	D3DFORMAT D3D9Mappings::_getPF(PixelFormat pf)
-	{
-		// DX9 uses different format semantics than most render systems, where most significant bit is signified by the
-		// first channel letter. For example in RGBA8 format, R is most-significant byte. Which is why most formats map to their
-		// reverse version in-engine as seen below.
-		// (This is not the case for floating point formats, EXCEPT for green-red one)
-		switch(pf)
-		{
-		case PF_B8G8R8A8:
-			return D3DFMT_A8R8G8B8;
-		case PF_R8G8B8X8:
-			return D3DFMT_X8B8G8R8;
-		case PF_B8G8R8X8:
-			return D3DFMT_X8R8G8B8;
-		case PF_FLOAT16_R:
-			return D3DFMT_R16F;
-		case PF_FLOAT16_RG:
-			return D3DFMT_G16R16F;
-		case PF_FLOAT16_RGBA:
-			return D3DFMT_A16B16G16R16F;
-		case PF_FLOAT32_R:
-			return D3DFMT_R32F;
-		case PF_FLOAT32_RG:
-			return D3DFMT_G32R32F;
-		case PF_FLOAT32_RGBA:
-			return D3DFMT_A32B32G32R32F;
-		case PF_BC1:
-		case PF_BC1a:
-			return D3DFMT_DXT1;
-		case PF_BC2:
-			return D3DFMT_DXT3;
-		case PF_BC3:
-			return D3DFMT_DXT5;
-		case PF_D24S8:
-			return D3DFMT_D24S8;
-		case PF_D32:
-			return D3DFMT_D32F_LOCKABLE;
-		case PF_D16:
-			return D3DFMT_D16;
-		case PF_UNORM_R10G10B10A2:
-			return D3DFMT_A2B10G10R10;
-		case PF_UNKNOWN:
-		default:
-			return D3DFMT_UNKNOWN;
-		}
-	}
-
-	PixelFormat D3D9Mappings::_getClosestSupportedPF(PixelFormat enginePF)
-	{
-		if (_getPF(enginePF) != D3DFMT_UNKNOWN)
-			return enginePF;
-
-		switch(enginePF)
-		{
-		case PF_R8:
-			return PF_B8G8R8X8;
-		case PF_R8G8:
-			return PF_B8G8R8X8;
-		case PF_B8G8R8:
-			return PF_B8G8R8X8;
-		case PF_A8R8G8B8:
-			return PF_B8G8R8A8;
-		case PF_A8B8G8R8:
-			return PF_R8G8B8A8;
-		case PF_R8G8B8:
-			return PF_B8G8R8;
-		case PF_FLOAT16_RGB:
-			return PF_FLOAT16_RGBA;
-		case PF_FLOAT32_RGB:
-			return PF_FLOAT32_RGBA;
-		case PF_D32_S8X24:
-			return PF_D24S8;
-		case PF_UNKNOWN:
-		default:
-			return PF_B8G8R8A8;
-		}
-	}
-
-	PixelFormat D3D9Mappings::_getClosestSupportedRenderTargetPF(PixelFormat enginePF)
-	{
-		switch(enginePF)
-		{
-		case PF_B8G8R8A8:
-			return PF_B8G8R8A8;
-		case PF_B8G8R8X8:
-			return PF_B8G8R8X8;
-		default:
-			return PF_B8G8R8A8;
-		}
-	}
-
-	PixelFormat D3D9Mappings::_getClosestSupportedDepthStencilPF(PixelFormat enginePF)
-	{
-		switch(enginePF)
-		{
-		case PF_D24S8:
-			return PF_D24S8;
-		case PF_D32:
-			return PF_D32;
-		case PF_D16:
-			return PF_D16;
-		default:
-			return PF_D24S8;
-		}
-	}
-}

+ 0 - 91
Source/BansheeD3D9RenderAPI/Source/BsD3D9MultiRenderTexture.cpp

@@ -1,91 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9MultiRenderTexture.h"
-#include "BsD3D9Texture.h"
-#include "BsD3D9RenderAPI.h"
-
-namespace BansheeEngine
-{
-	D3D9MultiRenderTextureCore::D3D9MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
-		:MultiRenderTextureCore(desc), mProperties(desc), mDX9DepthStencilSurface(nullptr)
-	{ }
-
-	D3D9MultiRenderTextureCore::~D3D9MultiRenderTextureCore()
-	{ }
-
-	void D3D9MultiRenderTextureCore::initialize()
-	{
-		MultiRenderTextureCore::initialize();
-
-		mDX9ColorSurfaces.resize(mColorSurfaces.size());
-
-		for (size_t i = 0; i < mColorSurfaces.size(); i++)
-		{
-			if (mColorSurfaces[i] != nullptr)
-			{
-				D3D9TextureCore* d3d9texture = static_cast<D3D9TextureCore*>(mColorSurfaces[i]->getTexture().get());
-				if (d3d9texture->getProperties().getTextureType() != TEX_TYPE_3D)
-				{
-					D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
-						d3d9texture->getBuffer(mColorSurfaces[i]->getDesc().firstArraySlice, mColorSurfaces[i]->getDesc().mostDetailMip).get());
-					mDX9ColorSurfaces[i] = pixelBuffer->getSurface(D3D9RenderAPI::getActiveD3D9Device());
-				}
-				else
-					mDX9ColorSurfaces[i] = nullptr;
-			}
-			else
-			{
-				mDX9ColorSurfaces[i] = nullptr;
-			}
-		}
-
-		if (mDepthStencilSurface != nullptr)
-		{
-			D3D9TextureCore* d3d9DepthStencil = static_cast<D3D9TextureCore*>(mDepthStencilSurface->getTexture().get());
-
-			if (d3d9DepthStencil->getProperties().getTextureType() != TEX_TYPE_3D)
-			{
-				D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
-					d3d9DepthStencil->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice, mDepthStencilSurface->getDesc().mostDetailMip).get());
-				mDX9DepthStencilSurface = pixelBuffer->getSurface(D3D9RenderAPI::getActiveD3D9Device());
-			}
-			else
-				mDX9DepthStencilSurface = nullptr;
-		}
-		else
-		{
-			mDX9DepthStencilSurface = nullptr;
-		}
-	}
-
-	void D3D9MultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
-	{
-		if(name == "DDBACKBUFFER")
-		{
-			IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
-
-			for(size_t x = 0; x < mDX9ColorSurfaces.size(); ++x)							
-				pSurf[x] = mDX9ColorSurfaces[x];			
-
-			return;
-		}
-		else if(name == "D3DZBUFFER")
-		{
-			IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
-			*pSurf = mDX9DepthStencilSurface;
-			return;
-		}
-		else if(name == "HWND")
-		{
-			HWND *pHwnd = (HWND*)pData;
-			*pHwnd = NULL;
-			return;
-		}
-	}
-
-	D3D9MultiRenderTexture::D3D9MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
-		:MultiRenderTexture(desc), mProperties(desc)
-	{
-
-	}
-}

+ 0 - 121
Source/BansheeD3D9RenderAPI/Source/BsD3D9OcclusionQuery.cpp

@@ -1,121 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9OcclusionQuery.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsRenderStats.h"
-#include "BsMath.h"
-
-namespace BansheeEngine
-{
-	D3D9OcclusionQuery::D3D9OcclusionQuery(bool binary)
-		:OcclusionQuery(binary), mQuery(nullptr), mNumSamples(0), 
-		mFinalized(false), mDevice(nullptr), mQueryIssued(false)
-	{
-		createQuery();
-	}
-
-	D3D9OcclusionQuery::~D3D9OcclusionQuery()
-	{
-		releaseQuery();
-	}
-
-	void D3D9OcclusionQuery::createQuery()
-	{
-		mDevice = D3D9RenderAPI::getActiveD3D9Device();
-
-		HRESULT hr = mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &mQuery);
-		if (hr != S_OK)
-		{
-			BS_EXCEPT(RenderingAPIException, "Failed to create an occlusion query.");
-		}
-
-		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Query);
-	}
-
-	void D3D9OcclusionQuery::releaseQuery()
-	{
-		SAFE_RELEASE(mQuery);
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_Query);
-	}
-
-	void D3D9OcclusionQuery::begin()
-	{
-		if (mQuery != nullptr)
-			mQuery->Issue(D3DISSUE_BEGIN);
-
-		mNumSamples = 0;
-		mQueryIssued = false;
-		setActive(true);
-	}
-
-	void D3D9OcclusionQuery::end()
-	{
-		if (mQuery != nullptr)
-			mQuery->Issue(D3DISSUE_END);
-
-		mQueryIssued = true;
-		mFinalized = false;
-	}
-
-	bool D3D9OcclusionQuery::isReady() const
-	{
-		if (mQuery == nullptr)
-			return mQueryIssued; // If we lost the query, return as ready if it was ever issued
-
-		if (!mQueryIssued)
-			return false;
-
-		BOOL queryData;
-		return mQuery->GetData(&queryData, sizeof(BOOL), 0) == S_OK;
-	}
-
-	UINT32 D3D9OcclusionQuery::getNumSamples()
-	{
-		if (!mFinalized && isReady())
-		{
-			finalize();
-		}
-
-		return mNumSamples;
-	}
-
-	void D3D9OcclusionQuery::finalize()
-	{
-		mFinalized = true;
-
-		if (mQuery == nullptr)
-		{
-			mNumSamples = 0;
-			return;
-		}
-
-		DWORD numSamples;
-		mQuery->GetData(&numSamples, sizeof(DWORD), 0);
-
-		mNumSamples = (UINT32)numSamples;
-	}
-
-	void D3D9OcclusionQuery::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			createQuery();
-	}
-
-	void D3D9OcclusionQuery::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			releaseQuery();
-	}
-
-	void D3D9OcclusionQuery::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			releaseQuery();
-	}
-
-	void D3D9OcclusionQuery::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			createQuery();
-	}
-}

+ 0 - 371
Source/BansheeD3D9RenderAPI/Source/BsD3D9PixelBuffer.cpp

@@ -1,371 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9PixelBuffer.h"
-#include "BsD3D9Texture.h"
-#include "BsD3D9Mappings.h"
-#include "BsException.h"
-#include "BsBitwise.h"
-#include "BsRenderAPI.h"
-#include "BsRenderStats.h"
-
-namespace BansheeEngine 
-{
-	RECT toD3DRECT(const PixelVolume &lockBox)
-	{
-		RECT prect;
-		assert(lockBox.getDepth() == 1);
-		prect.left = (LONG)lockBox.left;
-		prect.right = (LONG)lockBox.right;
-		prect.top = (LONG)lockBox.top;
-		prect.bottom = (LONG)lockBox.bottom;
-
-		return prect;
-	}
-
-	D3DBOX toD3DBOX(const PixelVolume &lockBox)
-	{
-		D3DBOX pbox;
-
-		pbox.Left = (UINT)lockBox.left;
-		pbox.Right = (UINT)lockBox.right;
-		pbox.Top = (UINT)lockBox.top;
-		pbox.Bottom = (UINT)lockBox.bottom;
-		pbox.Front = (UINT)lockBox.front;
-		pbox.Back = (UINT)lockBox.back;
-
-		return pbox;
-	}
-
-	D3D9PixelBuffer::D3D9PixelBuffer(GpuBufferUsage usage, D3D9TextureCore* ownerTexture)
-		:PixelBuffer(0, 0, 0, PF_UNKNOWN, usage, false),
-		 mDoMipmapGen(0), mHWMipmaps(0), mOwnerTexture(ownerTexture)
-	{ }
-
-	D3D9PixelBuffer::~D3D9PixelBuffer()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
-
-		auto iter = mMapDeviceToBufferResources.begin();
-
-		while (iter != mMapDeviceToBufferResources.end())
-		{
-			SAFE_RELEASE(iter->second->surface);
-			SAFE_RELEASE(iter->second->volume);
-
-			if(iter->second != nullptr)
-				bs_delete(iter->second);
-
-			auto toRemove = iter++;
-			mMapDeviceToBufferResources.erase(toRemove);
-		}
-	}
-
-	void D3D9PixelBuffer::bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, IDirect3DBaseTexture9* mipTex)
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		BufferResources* bufferResources = getBufferResources(dev);
-		bool isNewBuffer = false;
-
-		if (bufferResources == NULL)
-		{
-			bufferResources = createBufferResources();		
-			mMapDeviceToBufferResources[dev] = bufferResources;
-			isNewBuffer = true;
-		}
-		
-		bufferResources->mipTex = mipTex;
-		bufferResources->surface = surface;
-		bufferResources->surface->AddRef();
-
-		D3DSURFACE_DESC desc;
-		if(surface->GetDesc(&desc) != D3D_OK)
-			BS_EXCEPT(RenderingAPIException, "Could not get surface information");
-
-		mWidth = desc.Width;
-		mHeight = desc.Height;
-		mDepth = 1;
-		mFormat = D3D9Mappings::_getPF(desc.Format);
-
-		mRowPitch = mWidth;
-		mSlicePitch = mHeight*mWidth;
-		mSizeInBytes = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);	
-	}
-
-	void D3D9PixelBuffer::bind(IDirect3DDevice9* dev, IDirect3DVolume9* volume, IDirect3DBaseTexture9* mipTex)
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		BufferResources* bufferResources = getBufferResources(dev);
-		bool isNewBuffer = false;
-
-		if (bufferResources == NULL)
-		{
-			bufferResources = createBufferResources();
-			mMapDeviceToBufferResources[dev] = bufferResources;
-			isNewBuffer = true;
-		}
-
-		bufferResources->mipTex = mipTex;
-		bufferResources->volume = volume;
-		bufferResources->volume->AddRef();
-	
-		D3DVOLUME_DESC desc;
-		if(volume->GetDesc(&desc) != D3D_OK)
-			BS_EXCEPT(RenderingAPIException, "Could not get volume information");
-
-		mWidth = desc.Width;
-		mHeight = desc.Height;
-		mDepth = desc.Depth;
-		mFormat = D3D9Mappings::_getPF(desc.Format);
-
-		mRowPitch = mWidth;
-		mSlicePitch = mHeight*mWidth;
-		mSizeInBytes = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
-	}
-
-	D3D9PixelBuffer::BufferResources* D3D9PixelBuffer::getBufferResources(IDirect3DDevice9* d3d9Device)
-	{
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-
-		if (iterFind != mMapDeviceToBufferResources.end())	
-			return iterFind->second;
-	
-		return nullptr;
-	}
-
-	D3D9PixelBuffer::BufferResources* D3D9PixelBuffer::createBufferResources()
-	{
-		BufferResources* newResources = bs_new<BufferResources>();
-		memset(newResources, 0, sizeof(BufferResources));
-
-		return newResources;
-	}
-
-	void D3D9PixelBuffer::destroyBufferResources(IDirect3DDevice9* d3d9Device)
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-
-		if (iterFind != mMapDeviceToBufferResources.end())
-		{
-			SAFE_RELEASE(iterFind->second->surface);
-			SAFE_RELEASE(iterFind->second->volume);	
-
-			if(iterFind->second != nullptr)
-				bs_delete(iterFind->second);
-
-			mMapDeviceToBufferResources.erase(iterFind);
-		}
-	}
-
-	void D3D9PixelBuffer::lockDeviceAccess()
-	{
-		D3D9_DEVICE_ACCESS_LOCK;			
-	}
-
-	void D3D9PixelBuffer::unlockDeviceAccess()
-	{
-		D3D9_DEVICE_ACCESS_UNLOCK;								
-	}
-
-	PixelData D3D9PixelBuffer::lockImpl(PixelVolume lockBox, GpuLockOptions options)
-	{	
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-#if BS_PROFILING_ENABLED
-		if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
-		{
-			BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_Texture);
-		}
-
-		if (options == GBL_READ_WRITE || options == GBL_WRITE_ONLY || options == GBL_WRITE_ONLY_DISCARD || options == GBL_WRITE_ONLY_NO_OVERWRITE)
-		{
-			BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_Texture);
-		}
-#endif
-
-		DWORD flags = 0;
-		switch(options)
-		{
-		case GBL_WRITE_ONLY_DISCARD:
-			if (mUsage & GBU_DYNAMIC)
-				flags |= D3DLOCK_DISCARD;
-			break;
-		case GBL_READ_ONLY:
-			flags |= D3DLOCK_READONLY;
-			break;
-		default: 
-			break;
-		};
-
-		if (mMapDeviceToBufferResources.size() == 0)
-		{
-			BS_EXCEPT(RenderingAPIException, "There are no resources attached to this pixel buffer !!");	
-		}
-	
-		mLockedBox = lockBox;
-		mLockFlags = flags;
-
-		BufferResources* bufferResources = mMapDeviceToBufferResources.begin()->second;
-	
-		return lockBuffer(bufferResources, lockBox, flags);
-	}
-
-	PixelData D3D9PixelBuffer::lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags)
-	{
-		PixelData rval(lockBox.getWidth(), lockBox.getHeight(), lockBox.getDepth(), mFormat);
-
-		if (bufferResources->surface != nullptr)
-		{
-			D3DLOCKED_RECT lrect;
-			HRESULT hr;
-
-			if (lockBox.left == 0 && lockBox.top == 0 && lockBox.right == mWidth && lockBox.bottom == mHeight)
-			{
-				hr = bufferResources->surface->LockRect(&lrect, nullptr, flags);
-			}
-			else
-			{
-				RECT prect = toD3DRECT(lockBox);
-				hr = bufferResources->surface->LockRect(&lrect, &prect, flags);
-			}
-
-			if (FAILED(hr))		
-				BS_EXCEPT(RenderingAPIException, "Surface locking failed");
-
-			initPixelDataFromD3DLock(rval, lrect);
-		} 
-		else if(bufferResources->volume) 
-		{
-			D3DBOX pbox = toD3DBOX(lockBox);
-			D3DLOCKED_BOX lbox;
-
-			if(bufferResources->volume->LockBox(&lbox, &pbox, flags) != D3D_OK)
-				BS_EXCEPT(RenderingAPIException, "Volume locking failed");
-
-			initPixelDataFromD3DLock(rval, lbox);
-		}
-
-		return rval;
-	}
-
-	void D3D9PixelBuffer::unlockImpl()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (mMapDeviceToBufferResources.size() == 0)
-			BS_EXCEPT(RenderingAPIException, "There are no resources attached to this pixel buffer.");	
-
-		auto it = mMapDeviceToBufferResources.begin();							
-		unlockBuffer(it->second);	
-
-		if(mDoMipmapGen)
-			genMipmaps(it->second->mipTex);	
-	}
-
-	void D3D9PixelBuffer::unlockBuffer(BufferResources* bufferResources)
-	{
-		if(bufferResources->surface) 
-		{
-			bufferResources->surface->UnlockRect();
-		} 
-		else if(bufferResources->volume) 
-		{
-			bufferResources->volume->UnlockBox();
-		}
-	}
-
-	void D3D9PixelBuffer::genMipmaps(IDirect3DBaseTexture9* mipTex)
-	{
-		assert(mipTex != nullptr);
-
-		if (mHWMipmaps)
-		{
-			mipTex->GenerateMipSubLevels();
-		}
-		else
-		{
-			if(D3DXFilterTexture(mipTex, nullptr, D3DX_DEFAULT, D3DX_DEFAULT) != D3D_OK)
-			{
-				BS_EXCEPT(RenderingAPIException, "Failed to generate mipmaps.");
-			}
-		}
-	}
-
-	void D3D9PixelBuffer::setMipmapping(bool doMipmapGen, bool HWMipmaps)
-	{	
-		mDoMipmapGen = doMipmapGen;
-		mHWMipmaps = HWMipmaps;	
-	}
-
-	void D3D9PixelBuffer::releaseSurfaces(IDirect3DDevice9* d3d9Device)
-	{
-		BufferResources* bufferResources = getBufferResources(d3d9Device);
-
-		if (bufferResources != nullptr)
-		{
-			SAFE_RELEASE(bufferResources->surface);
-			SAFE_RELEASE(bufferResources->volume);
-		}
-	}
-
-	IDirect3DSurface9* D3D9PixelBuffer::getSurface(IDirect3DDevice9* d3d9Device)
-	{
-		BufferResources* bufferResources = getBufferResources(d3d9Device);
-
-		if (bufferResources	== nullptr)
-		{
-			mOwnerTexture->createInternalResources(d3d9Device);
-			bufferResources = getBufferResources(d3d9Device);
-		}
-
-		return bufferResources->surface;
-	}
-
-	void D3D9PixelBuffer::initPixelDataFromD3DLock(PixelData& rval, const D3DLOCKED_RECT& lrect)
-	{
-		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
-		if (bpp != 0)
-		{
-			rval.setRowPitch(lrect.Pitch / bpp);
-			rval.setSlicePitch(rval.getRowPitch() * rval.getHeight());
-			assert((lrect.Pitch % bpp) == 0);
-		}
-		else if (PixelUtil::isCompressed(rval.getFormat()))
-		{
-			rval.setRowPitch(rval.getWidth());
-			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
-		}
-		else
-		{
-			BS_EXCEPT(InvalidParametersException, "Invalid pixel format.");
-		}
-
-		rval.setExternalBuffer((UINT8*)lrect.pBits);
-	}
-
-	void D3D9PixelBuffer::initPixelDataFromD3DLock(PixelData& rval, const D3DLOCKED_BOX& lbox)
-	{
-		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
-		if (bpp != 0)
-		{
-			rval.setRowPitch(lbox.RowPitch / bpp);
-			rval.setSlicePitch(lbox.SlicePitch / bpp);
-			assert((lbox.RowPitch % bpp) == 0);
-			assert((lbox.SlicePitch % bpp) == 0);
-		}
-		else if (PixelUtil::isCompressed(rval.getFormat()))
-		{
-			rval.setRowPitch(rval.getWidth());
-			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
-		}
-		else
-		{
-			BS_EXCEPT(InvalidParametersException, "Invalid pixel format.");
-		}
-
-		rval.setExternalBuffer((UINT8*)lbox.pBits);
-	}
-};

+ 0 - 12
Source/BansheeD3D9RenderAPI/Source/BsD3D9Plugin.cpp

@@ -1,12 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9RenderAPIFactory.h"
-
-namespace BansheeEngine
-{
-	extern "C" BS_D3D9_EXPORT const char* getPluginName()
-	{
-		return SystemName;
-	}
-}

+ 0 - 33
Source/BansheeD3D9RenderAPI/Source/BsD3D9QueryManager.cpp

@@ -1,33 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9QueryManager.h"
-#include "BsD3D9EventQuery.h"
-#include "BsD3D9TimerQuery.h"
-#include "BsD3D9OcclusionQuery.h"
-
-namespace BansheeEngine
-{
-	SPtr<EventQuery> D3D9QueryManager::createEventQuery() const
-	{
-		SPtr<EventQuery> query = SPtr<D3D9EventQuery>(bs_new<D3D9EventQuery>(), &QueryManager::deleteEventQuery, StdAlloc<D3D9EventQuery>());
-		mEventQueries.push_back(query.get());
-
-		return query;
-	}
-
-	SPtr<TimerQuery> D3D9QueryManager::createTimerQuery() const
-	{
-		SPtr<TimerQuery> query = SPtr<D3D9TimerQuery>(bs_new<D3D9TimerQuery>(), &QueryManager::deleteTimerQuery, StdAlloc<D3D9TimerQuery>());
-		mTimerQueries.push_back(query.get());
-
-		return query;
-	}
-
-	SPtr<OcclusionQuery> D3D9QueryManager::createOcclusionQuery(bool binary) const
-	{
-		SPtr<OcclusionQuery> query = SPtr<D3D9OcclusionQuery>(bs_new<D3D9OcclusionQuery>(binary), &QueryManager::deleteOcclusionQuery, StdAlloc<D3D9OcclusionQuery>());
-		mOcclusionQueries.push_back(query.get());
-
-		return query;
-	}
-}

+ 0 - 2302
Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderAPI.cpp

@@ -1,2302 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9Prerequisites.h"
-#include "BsD3D9DriverList.h"
-#include "BsD3D9Driver.h"
-#include "BsD3D9RenderWindow.h"
-#include "BsD3D9TextureManager.h"
-#include "BsD3D9Texture.h"
-#include "BsMath.h"
-#include "BsD3D9HardwareBufferManager.h"
-#include "BsD3D9IndexBuffer.h"
-#include "BsD3D9VertexBuffer.h"
-#include "BsD3D9VertexDeclaration.h"
-#include "BsD3D9GpuProgram.h"
-#include "BsD3D9HLSLProgramFactory.h"
-#include "BsD3D9OcclusionQuery.h"
-#include "BsD3D9DeviceManager.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsD3D9RenderWindowManager.h"
-#include "BsGpuProgramManager.h"
-#include "BsRenderStateManager.h"
-#include "BsAsyncOp.h"
-#include "BsBlendState.h"
-#include "BsRasterizerState.h"
-#include "BsDepthStencilState.h"
-#include "BsGpuParams.h"
-#include "BsGpuParamDesc.h"
-#include "BsGpuParamBlockBuffer.h"
-#include "BsCoreThread.h"
-#include "BsD3D9QueryManager.h"
-#include "BsDebug.h"
-#include "BsRenderStats.h"
-
-namespace BansheeEngine 
-{
-	D3D9RenderAPI* D3D9RenderAPI::msD3D9RenderSystem = nullptr;
-
-	D3D9RenderAPI::D3D9RenderAPI(HINSTANCE hInstance)
-		: mTexStageDesc(nullptr), mNumTexStages(0), mCurrentDrawOperation(DOT_TRIANGLE_LIST), 
-		mViewportLeft(0), mViewportTop(0), mViewportWidth(0), mViewportHeight(0),
-		mIsFrameInProgress(false), mRestoreFrameOnReset(false), mhInstance(hInstance),
-		mpD3D(nullptr), mDriverList(nullptr), mActiveD3DDriver(nullptr), mHLSLProgramFactory(nullptr),
-		mDeviceManager(nullptr), mResourceManager(nullptr), mViewportNorm(0.0f, 0.0f, 1.0f, 1.0f)
-	{
-		msD3D9RenderSystem = this;
-
-		mScissorRect.left = 0;
-		mScissorRect.right = 1280;
-		mScissorRect.top = 0;
-		mScissorRect.bottom = 720;
-	}
-
-	D3D9RenderAPI::~D3D9RenderAPI()
-	{
-
-	}
-
-	const StringID& D3D9RenderAPI::getName() const
-	{
-		static StringID strName("D3D9RenderAPI");
-		return strName;
-	}
-
-	const String& D3D9RenderAPI::getShadingLanguageName() const
-	{
-		static String strName("hlsl9");
-		return strName;
-	}
-
-	void D3D9RenderAPI::initializePrepare()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		// Create the resource manager.
-		mResourceManager = bs_new<D3D9ResourceManager>();
-
-		// Create our Direct3D object
-		if((mpD3D = Direct3DCreate9(D3D_SDK_VERSION)) == nullptr)
-			BS_EXCEPT(InternalErrorException, "Failed to create Direct3D9 object");
-
-		// Init using current settings
-		mActiveD3DDriver = getDirect3DDrivers()->item(0); // TODO - We always use the first driver
-
-		if(mActiveD3DDriver == nullptr)
-			BS_EXCEPT(InvalidParametersException, "Problems finding requested Direct3D driver!" );
-
-		// get driver version
-		mDriverVersion.major = HIWORD(mActiveD3DDriver->getAdapterIdentifier().DriverVersion.HighPart);
-		mDriverVersion.minor = LOWORD(mActiveD3DDriver->getAdapterIdentifier().DriverVersion.HighPart);
-		mDriverVersion.release = HIWORD(mActiveD3DDriver->getAdapterIdentifier().DriverVersion.LowPart);
-		mDriverVersion.build = LOWORD(mActiveD3DDriver->getAdapterIdentifier().DriverVersion.LowPart);
-
-		mVideoModeInfo = getDirect3DDrivers()->getVideoModeInfo();
-
-		// Create the device manager.
-		mDeviceManager = bs_new<D3D9DeviceManager>();
-
-		// Also create hardware buffer manager		
-		HardwareBufferManager::startUp();
-		HardwareBufferCoreManager::startUp<D3D9HardwareBufferCoreManager>();
-
-		// Create & register HLSL factory		
-		mHLSLProgramFactory = bs_new<D3D9HLSLProgramFactory>();
-
-		// Create render window manager
-		RenderWindowManager::startUp<D3D9RenderWindowManager>(this);
-		RenderWindowCoreManager::startUp<D3D9RenderWindowCoreManager>(this);
-
-		// Create render state manager
-		RenderStateCoreManager::startUp();
-
-		RenderAPICore::initializePrepare();
-	}
-
-	void D3D9RenderAPI::initializeFinalize(const SPtr<RenderWindowCore>& primaryWindow)
-	{
-		D3D9RenderWindowCore* d3d9window = static_cast<D3D9RenderWindowCore*>(primaryWindow.get());
-		updateRenderSystemCapabilities(d3d9window);
-
-		// Create the texture manager for use by others		
-		TextureManager::startUp<D3D9TextureManager>();
-		TextureCoreManager::startUp<D3D9TextureCoreManager>();
-
-		QueryManager::startUp<D3D9QueryManager>();
-
-		RenderAPICore::initializeFinalize(primaryWindow);
-	}
-
-	void D3D9RenderAPI::destroyCore()
-	{
-		if(mTexStageDesc != nullptr)
-		{
-			bs_deleteN(mTexStageDesc, mNumTexStages);
-			mTexStageDesc = nullptr;
-		}
-
-		RenderAPICore::destroyCore();
-
-		if(mDeviceManager != nullptr)
-		{
-			bs_delete(mDeviceManager);
-			mDeviceManager = nullptr;
-		}
-
-		if(mDriverList != nullptr)
-		{
-			bs_delete(mDriverList);
-			mDriverList = nullptr;
-		}
-		mActiveD3DDriver = NULL;	
-
-		QueryManager::shutDown();
-		TextureCoreManager::shutDown();
-		TextureManager::shutDown();
-		HardwareBufferCoreManager::shutDown();
-		HardwareBufferManager::shutDown();
-		RenderWindowCoreManager::shutDown();
-		RenderWindowManager::shutDown();
-		RenderStateCoreManager::shutDown();
-
-		// Deleting the HLSL program factory
-		if (mHLSLProgramFactory)
-		{
-			GpuProgramCoreManager::instance().removeFactory(mHLSLProgramFactory);
-			bs_delete(mHLSLProgramFactory);
-			mHLSLProgramFactory = 0;
-		}
-
-		SAFE_RELEASE(mpD3D);
-
-		if(mResourceManager != nullptr)
-		{
-			bs_delete(mResourceManager);
-			mResourceManager = nullptr;
-		}
-
-		msD3D9RenderSystem = NULL;
-	}
-
-	void D3D9RenderAPI::registerWindow(RenderWindowCore& renderWindow)
-	{		
-		THROW_IF_NOT_CORE_THREAD;
-
-		D3D9RenderWindowCore* d3d9renderWindow = static_cast<D3D9RenderWindowCore*>(&renderWindow);
-
-		String msg;
-
-		mResourceManager->lockDeviceAccess();
-		mDeviceManager->linkRenderWindow(d3d9renderWindow);
-
-		mResourceManager->unlockDeviceAccess();
-	}	
-
-	void D3D9RenderAPI::bindGpuProgram(const SPtr<GpuProgramCore>& prg)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		switch (prg->getProperties().getType())
-		{
-		case GPT_VERTEX_PROGRAM:
-			hr = getActiveD3D9Device()->SetVertexShader(
-				static_cast<D3D9GpuVertexProgramCore*>(prg.get())->getVertexShader());
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Error calling SetVertexShader");
-			}
-			break;
-		case GPT_FRAGMENT_PROGRAM:
-			hr = getActiveD3D9Device()->SetPixelShader(
-				static_cast<D3D9GpuFragmentProgramCore*>(prg.get())->getPixelShader());
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Error calling SetPixelShader");
-			}
-			break;
-		};
-
-		// Make sure texcoord index is equal to stage value, As SDK Doc suggests:
-		// "When rendering using vertex shaders, each stage's texture coordinate index must be set to its default value."
-		// This solves such an errors when working with the Debug runtime -
-		// "Direct3D9: (ERROR) :Stage 1 - Texture coordinate index in the stage must be equal to the stage index when programmable vertex pipeline is used".
-		for (unsigned int nStage=0; nStage < 8; ++nStage)
-			setTextureStageState(nStage, D3DTSS_TEXCOORDINDEX, nStage);
-
-		BS_INC_RENDER_STAT(NumGpuProgramBinds);
-
-		RenderAPICore::bindGpuProgram(prg);
-	}
-
-	void D3D9RenderAPI::unbindGpuProgram(GpuProgramType gptype)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		switch(gptype)
-		{
-		case GPT_VERTEX_PROGRAM:
-			hr = getActiveD3D9Device()->SetVertexShader(NULL);
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Error resetting SetVertexShader to NULL");
-			}
-			break;
-		case GPT_FRAGMENT_PROGRAM:
-			hr = getActiveD3D9Device()->SetPixelShader(NULL);
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Error resetting SetPixelShader to NULL");
-			}
-			break;
-		};
-
-		BS_INC_RENDER_STAT(NumGpuProgramBinds);
-
-		RenderAPICore::unbindGpuProgram(gptype);
-	}
-
-	void D3D9RenderAPI::setParamBuffer(GpuProgramType gptype, UINT32 slot, const SPtr<GpuParamBlockBufferCore>& buffer,
-		const GpuParamDesc& paramDesc)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if (buffer == nullptr)
-			return;
-
-		// Read all the buffer data so we can assign it. Not the most efficient way of accessing data
-		// but it is required in order to have standardized buffer interface.
-		UINT8* uniformBufferData = (UINT8*)bs_stack_alloc(buffer->getSize());
-		buffer->readFromGPU(uniformBufferData);
-
-		HRESULT hr;
-
-		switch(gptype)
-		{
-		case GPT_VERTEX_PROGRAM:
-			{
-				for(auto iter = paramDesc.params.begin(); iter != paramDesc.params.end(); ++iter)
-				{
-					const GpuParamDataDesc& param = iter->second;
-
-					const UINT8* ptrData = uniformBufferData+ param.cpuMemOffset * sizeof(UINT32);
-
-					switch(param.type)
-					{
-					case GPDT_FLOAT1:
-					case GPDT_FLOAT2:
-					case GPDT_FLOAT3:
-					case GPDT_FLOAT4:
-					case GPDT_MATRIX_2X2:
-					case GPDT_MATRIX_2X3:
-					case GPDT_MATRIX_2X4:
-					case GPDT_MATRIX_3X2:
-					case GPDT_MATRIX_3X3:
-					case GPDT_MATRIX_3X4:
-					case GPDT_MATRIX_4X2:
-					case GPDT_MATRIX_4X3:
-					case GPDT_MATRIX_4X4:
-						{
-							UINT32 slotCount = (param.elementSize / 4) * param.arraySize;
-							assert (param.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
-
-							if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantF(param.gpuMemOffset, (const float*)ptrData, slotCount))) 
-								BS_EXCEPT(RenderingAPIException, "Unable to upload vertex shader float parameters.");
-							break;
-						}
-					case GPDT_INT1:
-					case GPDT_INT2:
-					case GPDT_INT3:
-					case GPDT_INT4:
-						{
-							UINT32 slotCount = (param.elementSize / 4) * param.arraySize;
-							assert (param.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
-
-							if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantI(param.gpuMemOffset, (const INT32*)ptrData, slotCount))) 
-								BS_EXCEPT(RenderingAPIException, "Unable to upload vertex shader int parameters.");
-							break;
-						}
-					case GPDT_BOOL:
-						if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantB(param.gpuMemOffset, (const BOOL*)ptrData, param.arraySize))) 
-							BS_EXCEPT(RenderingAPIException, "Unable to upload vertex shader bool parameters.");
-						break;
-					}
-				}
-			}
-			break;
-		case GPT_FRAGMENT_PROGRAM:
-			{
-				for(auto iter = paramDesc.params.begin(); iter != paramDesc.params.end(); ++iter)
-				{
-					const GpuParamDataDesc& param = iter->second;
-
-					const UINT8* ptrData = uniformBufferData + param.cpuMemOffset * sizeof(UINT32);
-
-					switch(param.type)
-					{
-					case GPDT_FLOAT1:
-					case GPDT_FLOAT2:
-					case GPDT_FLOAT3:
-					case GPDT_FLOAT4:
-					case GPDT_MATRIX_2X2:
-					case GPDT_MATRIX_2X3:
-					case GPDT_MATRIX_2X4:
-					case GPDT_MATRIX_3X2:
-					case GPDT_MATRIX_3X3:
-					case GPDT_MATRIX_3X4:
-					case GPDT_MATRIX_4X2:
-					case GPDT_MATRIX_4X3:
-					case GPDT_MATRIX_4X4:
-						{
-							UINT32 slotCount = (param.elementSize / 4) * param.arraySize;
-							assert (param.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
-
-							if (FAILED(hr = getActiveD3D9Device()->SetPixelShaderConstantF(param.gpuMemOffset, (const float*)ptrData, slotCount))) 
-								BS_EXCEPT(RenderingAPIException, "Unable to upload pixel shader float parameters.");
-							break;
-						}
-					case GPDT_INT1:
-					case GPDT_INT2:
-					case GPDT_INT3:
-					case GPDT_INT4:
-						{
-							UINT32 slotCount = (param.elementSize / 4) * param.arraySize;
-							assert (param.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
-
-							if (FAILED(hr = getActiveD3D9Device()->SetPixelShaderConstantI(param.gpuMemOffset, (const INT32*)ptrData, slotCount))) 
-								BS_EXCEPT(RenderingAPIException, "Unable to upload pixel shader int parameters.");
-							break;
-						}
-					case GPDT_BOOL:
-						if (FAILED(hr = getActiveD3D9Device()->SetPixelShaderConstantB(param.gpuMemOffset, (const BOOL*)ptrData, param.arraySize))) 
-							BS_EXCEPT(RenderingAPIException, "Unable to upload pixel shader bool parameters.");
-						break;
-					}
-				}
-			}
-			break;
-		};
-
-		bs_stack_free(uniformBufferData);
-
-		BS_INC_RENDER_STAT(NumGpuParamBufferBinds);
-	}
-
-	void D3D9RenderAPI::setTexture(GpuProgramType gptype, UINT16 unit, const SPtr<TextureCore>& tex)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if (tex != nullptr && !tex->isBindableAsShaderResource())
-			BS_EXCEPT(InvalidParametersException, "Texture you have specified cannot be bound to a shader.");
-
-		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)
-		{
-			LOGWRN("D3D9 cannot assign textures to this gpu program type: " + toString(gptype));
-			return;
-		}
-
-		if(gptype == GPT_VERTEX_PROGRAM)
-		{
-			unit = D3DVERTEXTEXTURESAMPLER0 + unit; // Vertex stage uses special samplers
-		}
-
-		HRESULT hr;
-		SPtr<D3D9TextureCore> dt = std::static_pointer_cast<D3D9TextureCore>(tex);
-		if (dt != nullptr)
-		{
-			IDirect3DBaseTexture9 *pTex = dt->getTexture_internal();
-			if (mTexStageDesc[unit].pTex != pTex)
-			{
-				hr = getActiveD3D9Device()->SetTexture(static_cast<DWORD>(unit), pTex);
-				if( hr != S_OK )
-				{
-					String str = "Unable to set texture in D3D9";
-					BS_EXCEPT(RenderingAPIException, str);
-				}
-
-				// set stage desc.
-				mTexStageDesc[unit].pTex = pTex;
-				mTexStageDesc[unit].texType = D3D9Mappings::get(dt->getProperties().getTextureType());
-
-				// Set gamma now too
-				if (dt->isHardwareGammaReadToBeUsed())
-				{
-					setSamplerState(static_cast<DWORD>(unit), D3DSAMP_SRGBTEXTURE, TRUE);
-				}
-				else
-				{
-					setSamplerState(static_cast<DWORD>(unit), D3DSAMP_SRGBTEXTURE, FALSE);
-				}
-
-				BS_INC_RENDER_STAT(NumTextureBinds);
-				BS_INC_RENDER_STAT(NumSamplerBinds);
-			}
-		}
-		else
-		{
-			if (mTexStageDesc[unit].pTex != 0)
-			{
-				hr = getActiveD3D9Device()->SetTexture(static_cast<DWORD>(unit), 0);
-				if( hr != S_OK )
-				{
-					String str = "Unable to disable texture '" + toString(unit) + "' in D3D9";
-					BS_EXCEPT(RenderingAPIException, str);
-				}
-
-				BS_INC_RENDER_STAT(NumTextureBinds);
-			}
-
-			hr = setTextureStageState(static_cast<DWORD>(unit), D3DTSS_COLOROP, D3DTOP_DISABLE);
-			if( hr != S_OK )
-			{
-				String str = "Unable to disable texture '" + toString(unit) + "' in D3D9";
-				BS_EXCEPT(RenderingAPIException, str);
-			}
-
-			// set stage desc. to defaults
-			mTexStageDesc[unit].pTex = 0;
-			mTexStageDesc[unit].coordIndex = 0;
-			mTexStageDesc[unit].texType = D3D9Mappings::D3D_TEX_TYPE_NORMAL;
-		}
-	}
-
-	void D3D9RenderAPI::setLoadStoreTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const SPtr<TextureCore>& texPtr,
-		const TextureSurface& surface)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		LOGWRN("Texture random load/store not supported on DX9.");
-	}
-
-	void D3D9RenderAPI::setBuffer(GpuProgramType gptype, UINT16 unit, const SPtr<GpuBufferCore>& buffer, bool loadStore)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		LOGWRN("Generic GPU buffers not supported on DX9.");
-	}
-
-	void D3D9RenderAPI::setSamplerState(GpuProgramType gptype, UINT16 unit, const SPtr<SamplerStateCore>& state)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)
-		{
-			LOGWRN("D3D9 doesn't support this gpu program type: " + toString(gptype));
-			return;
-		}
-
-		if(gptype == GPT_VERTEX_PROGRAM)
-		{
-			unit = D3DVERTEXTEXTURESAMPLER0 + unit; // Vertex stage uses special samplers
-		}
-
-		const SamplerProperties& sampProps = state->getProperties();
-
-		// Set texture layer filtering
-		setTextureFiltering(unit, FT_MIN, sampProps.getTextureFiltering(FT_MIN));
-		setTextureFiltering(unit, FT_MAG, sampProps.getTextureFiltering(FT_MAG));
-		setTextureFiltering(unit, FT_MIP, sampProps.getTextureFiltering(FT_MIP));
-
-		// Set texture layer filtering
-		if (sampProps.getTextureAnisotropy() > 0)
-			setTextureAnisotropy(unit, sampProps.getTextureAnisotropy());
-
-		// Set mipmap biasing
-		setTextureMipmapBias(unit, sampProps.getTextureMipmapBias());
-
-		// Texture addressing mode
-		const UVWAddressingMode& uvw = sampProps.getTextureAddressingMode();
-		setTextureAddressingMode(unit, uvw);
-
-		// Set border color
-		setTextureBorderColor(unit, sampProps.getBorderColor());
-
-		BS_INC_RENDER_STAT(NumSamplerBinds);
-	}
-
-	void D3D9RenderAPI::setBlendState(const SPtr<BlendStateCore>& blendState)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		const BlendProperties& stateProps = blendState->getProperties();
-
-		// Alpha to coverage
-		setAlphaToCoverage(stateProps.getAlphaToCoverageEnabled());
-
-		// Blend states
-		// DirectX 9 doesn't allow us to specify blend state per render target, so we just use the first one.
-		if (stateProps.getBlendEnabled(0))
-		{
-			setSceneBlending(stateProps.getSrcBlend(0), stateProps.getDstBlend(0), stateProps.getAlphaSrcBlend(0), stateProps.getAlphaDstBlend(0)
-				, stateProps.getBlendOperation(0), stateProps.getAlphaBlendOperation(0));
-		}
-		else
-		{
-			setSceneBlending(BF_ONE, BF_ZERO, BO_ADD);
-		}
-
-		// Color write mask
-		UINT8 writeMask = stateProps.getRenderTargetWriteMask(0);
-		setColorBufferWriteEnabled((writeMask & 0x1) != 0, (writeMask & 0x2) != 0, (writeMask & 0x4) != 0, (writeMask & 0x8) != 0);
-
-		BS_INC_RENDER_STAT(NumBlendStateChanges);
-	}
-
-	void D3D9RenderAPI::setRasterizerState(const SPtr<RasterizerStateCore>& rasterizerState)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		const RasterizerProperties& stateProps = rasterizerState->getProperties();
-
-		setDepthBias(stateProps.getDepthBias(), stateProps.getSlopeScaledDepthBias());
-
-		setCullingMode(stateProps.getCullMode());
-
-		setPolygonMode(stateProps.getPolygonMode());
-
-		setScissorTestEnable(stateProps.getScissorEnable());
-
-		setMultisampleAntialiasEnable(stateProps.getMultisampleEnable());
-
-		setAntialiasedLineEnable(stateProps.getAntialiasedLineEnable());
-
-		BS_INC_RENDER_STAT(NumRasterizerStateChanges);
-	}
-
-	void D3D9RenderAPI::setDepthStencilState(const SPtr<DepthStencilStateCore>& depthStencilState, UINT32 stencilRefValue)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		const DepthStencilProperties& stateProps = depthStencilState->getProperties();
-
-		// Set stencil buffer options
-		setStencilCheckEnabled(stateProps.getStencilEnable());
-
-		setStencilBufferOperations(stateProps.getStencilFrontFailOp(), stateProps.getStencilFrontZFailOp(), stateProps.getStencilFrontPassOp(), true);
-		setStencilBufferFunc(stateProps.getStencilFrontCompFunc(), true);
-
-		setStencilBufferOperations(stateProps.getStencilBackFailOp(), stateProps.getStencilBackZFailOp(), stateProps.getStencilBackPassOp(), false);
-		setStencilBufferFunc(stateProps.getStencilBackCompFunc(), false);
-
-		setStencilBufferReadMask(stateProps.getStencilReadMask());
-		setStencilBufferWriteMask(stateProps.getStencilWriteMask());
-
-		// Set depth buffer options
-		setDepthBufferCheckEnabled(stateProps.getDepthReadEnable());
-		setDepthBufferWriteEnabled(stateProps.getDepthWriteEnable());
-		setDepthBufferFunction(stateProps.getDepthComparisonFunc());
-
-		// Set stencil ref value
-		setStencilRefValue(stencilRefValue);
-
-		BS_INC_RENDER_STAT(NumDepthStencilStateChanges);
-	}
-
-	void D3D9RenderAPI::setTextureMipmapBias(UINT16 unit, float bias)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if (mCurrentCapabilities->hasCapability(RSC_MIPMAP_LOD_BIAS))
-		{
-			// ugh - have to pass float data through DWORD with no conversion
-			HRESULT hr = setSamplerState(static_cast<DWORD>(unit), D3DSAMP_MIPMAPLODBIAS, 
-				*(DWORD*)&bias);
-			if(FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Unable to set texture mipmap bias");
-		}
-	}
-
-	void D3D9RenderAPI::setTextureAddressingMode( UINT16 stage, 
-		const UVWAddressingMode& uvw )
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSU, D3D9Mappings::get(uvw.u, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set texture addressing mode for U" );
-		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSV, D3D9Mappings::get(uvw.v, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set texture addressing mode for V");
-		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSW, D3D9Mappings::get(uvw.w, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set texture addressing mode for W");
-	}
-
-	void D3D9RenderAPI::setTextureBorderColor(UINT16 stage, const Color& colour)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_BORDERCOLOR, colour.getAsBGRA()) ) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set texture border colour");
-	}
-
-	void D3D9RenderAPI::setSceneBlending( BlendFactor sourceFactor, BlendFactor destFactor, BlendOperation op )
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if( sourceFactor == BF_ONE && destFactor == BF_ZERO)
-		{
-			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, FALSE)))
-				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
-		}
-		else
-		{
-			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, TRUE)))
-				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
-			if (FAILED(hr = setRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE)))
-				BS_EXCEPT(RenderingAPIException, "Failed to set separate alpha blending option");
-			if( FAILED( hr = setRenderState( D3DRS_SRCBLEND, D3D9Mappings::get(sourceFactor) ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to set source blend");
-			if( FAILED( hr = setRenderState( D3DRS_DESTBLEND, D3D9Mappings::get(destFactor) ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to set destination blend");
-		}
-
-		if (FAILED(hr = setRenderState(D3DRS_BLENDOP, D3D9Mappings::get(op))))
-			BS_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
-		if (FAILED(hr = setRenderState(D3DRS_BLENDOPALPHA, D3D9Mappings::get(op))))
-			BS_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
-	}
-
-	void D3D9RenderAPI::setSceneBlending( BlendFactor sourceFactor, BlendFactor destFactor, BlendFactor sourceFactorAlpha, 
-		BlendFactor destFactorAlpha, BlendOperation op, BlendOperation alphaOp )
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if( sourceFactor == BF_ONE && destFactor == BF_ZERO && 
-			sourceFactorAlpha == BF_ONE && destFactorAlpha == BF_ZERO)
-		{
-			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, FALSE)))
-				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
-		}
-		else
-		{
-			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, TRUE)))
-				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
-			if (FAILED(hr = setRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE)))
-				BS_EXCEPT(RenderingAPIException, "Failed to set separate alpha blending option");
-			if( FAILED( hr = setRenderState( D3DRS_SRCBLEND, D3D9Mappings::get(sourceFactor) ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to set source blend");
-			if( FAILED( hr = setRenderState( D3DRS_DESTBLEND, D3D9Mappings::get(destFactor) ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to set destination blend");
-			if( FAILED( hr = setRenderState( D3DRS_SRCBLENDALPHA, D3D9Mappings::get(sourceFactorAlpha) ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to set alpha source blend");
-			if( FAILED( hr = setRenderState( D3DRS_DESTBLENDALPHA, D3D9Mappings::get(destFactorAlpha) ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to set alpha destination blend");
-		}
-
-		if (FAILED(hr = setRenderState(D3DRS_BLENDOP, D3D9Mappings::get(op))))
-			BS_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
-		if (FAILED(hr = setRenderState(D3DRS_BLENDOPALPHA, D3D9Mappings::get(alphaOp))))
-			BS_EXCEPT(RenderingAPIException, "Failed to set alpha scene blending operation option");
-	}
-
-	void D3D9RenderAPI::setAlphaTest(CompareFunction func, unsigned char value)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-
-		if (func != CMPF_ALWAYS_PASS)
-		{
-			if( FAILED( hr = setRenderState( D3DRS_ALPHATESTENABLE,  TRUE ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to enable alpha testing");
-		}
-		else
-		{
-			if( FAILED( hr = setRenderState( D3DRS_ALPHATESTENABLE,  FALSE ) ) )
-				BS_EXCEPT(RenderingAPIException, "Failed to disable alpha testing");
-		}
-		// Set always just be sure
-		if( FAILED( hr = setRenderState( D3DRS_ALPHAFUNC, D3D9Mappings::get(func) ) ) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set alpha reject function");
-		if( FAILED( hr = setRenderState( D3DRS_ALPHAREF, value ) ) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set render state D3DRS_ALPHAREF");
-	}
-
-	void D3D9RenderAPI::setAlphaToCoverage(bool enable)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		static bool lasta2c = false;
-
-		// Alpha to coverage
-		if (getCapabilities()->hasCapability(RSC_ALPHA_TO_COVERAGE))
-		{
-			// Vendor-specific hacks on renderstate, gotta love 'em
-			if (getCapabilities()->getVendor() == GPU_NVIDIA)
-			{
-				if (enable)
-				{
-					if( FAILED( hr = setRenderState( D3DRS_ADAPTIVETESS_Y,  (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C') ) ) )
-						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
-				}
-				else
-				{
-					if( FAILED( hr = setRenderState( D3DRS_ADAPTIVETESS_Y,  D3DFMT_UNKNOWN ) ) )
-						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
-				}
-
-			}
-			else if ((getCapabilities()->getVendor() == GPU_AMD))
-			{
-				if (enable)
-				{
-					if( FAILED( hr = setRenderState( D3DRS_POINTSIZE,  MAKEFOURCC('A','2','M','1') ) ) )
-						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
-				}
-				else
-				{
-					// discovered this through trial and error, seems to work
-					if( FAILED( hr = setRenderState( D3DRS_POINTSIZE,  MAKEFOURCC('A','2','M','0') ) ) )
-						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
-				}
-			}
-
-			lasta2c = enable;
-		}
-	}
-
-	void D3D9RenderAPI::setCullingMode(CullingMode mode)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mCullingMode = mode;
-		HRESULT hr;
-
-		if( FAILED (hr = setRenderState(D3DRS_CULLMODE, 
-			D3D9Mappings::get(mode, false))) )
-			BS_EXCEPT(RenderingAPIException, "Failed to set culling mode");
-	}
-
-	void D3D9RenderAPI::setDepthBufferCheckEnabled(bool enabled)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-
-		if( enabled )
-			hr = setRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
-		else
-			hr = setRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
-
-		if(FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error setting depth buffer test state");
-	}
-
-	void D3D9RenderAPI::setDepthBufferWriteEnabled(bool enabled)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-
-		if( FAILED( hr = setRenderState( D3DRS_ZWRITEENABLE, enabled ) ) )
-			BS_EXCEPT(RenderingAPIException, "Error setting depth buffer write state");
-	}
-
-	void D3D9RenderAPI::setDepthBufferFunction(CompareFunction func)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if( FAILED( hr = setRenderState( D3DRS_ZFUNC, D3D9Mappings::get(func) ) ) )
-			BS_EXCEPT(RenderingAPIException, "Error setting depth buffer test function");
-	}
-
-	void D3D9RenderAPI::setDepthBias(float constantBias, float slopeScaleBias)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if ((mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().RasterCaps & D3DPRASTERCAPS_DEPTHBIAS) != 0)
-		{
-			// Negate bias since D3D is backward
-			constantBias = -constantBias;
-			HRESULT hr = setRenderState(D3DRS_DEPTHBIAS, *((DWORD*)&constantBias));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting constant depth bias");
-		}
-
-		if ((mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().RasterCaps & D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS) != 0)
-		{
-			// Negate bias since D3D is backward
-			slopeScaleBias = -slopeScaleBias;
-			HRESULT hr = setRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&slopeScaleBias));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting slope scale depth bias");
-		}
-
-
-	}
-
-	void D3D9RenderAPI::setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		DWORD val = 0;
-		if (red) 
-			val |= D3DCOLORWRITEENABLE_RED;
-		if (green)
-			val |= D3DCOLORWRITEENABLE_GREEN;
-		if (blue)
-			val |= D3DCOLORWRITEENABLE_BLUE;
-		if (alpha)
-			val |= D3DCOLORWRITEENABLE_ALPHA;
-
-		HRESULT hr = setRenderState(D3DRS_COLORWRITEENABLE, val); 
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error setting colour write enable flags");
-	}
-
-	void D3D9RenderAPI::setPolygonMode(PolygonMode level)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr = setRenderState(D3DRS_FILLMODE, D3D9Mappings::get(level));
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error setting polygon mode.");
-	}
-
-	void D3D9RenderAPI::setStencilCheckEnabled(bool enabled)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		// Allow stencilling
-		HRESULT hr = setRenderState(D3DRS_STENCILENABLE, enabled);
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error enabling / disabling stencilling.");
-
-		if (mCurrentCapabilities->hasCapability(RSC_TWO_SIDED_STENCIL))
-		{
-			hr = setRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
-
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting 2-sided stencil mode.");
-		}
-		else
-		{
-			hr = setRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE);
-
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting 1-sided stencil mode.");
-		}
-	}
-
-	void D3D9RenderAPI::setStencilBufferOperations(StencilOperation stencilFailOp, StencilOperation depthFailOp, StencilOperation passOp, bool ccw)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-
-		// 2-sided operation
-		if (ccw)
-		{
-			// fail op
-			hr = setRenderState(D3DRS_CCW_STENCILFAIL, D3D9Mappings::get(stencilFailOp));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting stencil fail operation (ccw).");
-
-			// depth fail op
-			hr = setRenderState(D3DRS_CCW_STENCILZFAIL, D3D9Mappings::get(depthFailOp));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting stencil depth fail operation (ccw).");
-
-			// pass op
-			hr = setRenderState(D3DRS_CCW_STENCILPASS, D3D9Mappings::get(passOp));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting stencil pass operation (ccw).");
-		}
-		else
-		{
-			// fail op
-			hr = setRenderState(D3DRS_STENCILFAIL, D3D9Mappings::get(stencilFailOp, true));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting stencil fail operation (cw).");
-
-			// depth fail op
-			hr = setRenderState(D3DRS_STENCILZFAIL, D3D9Mappings::get(depthFailOp, true));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting stencil depth fail operation (cw).");
-
-			// pass op
-			hr = setRenderState(D3DRS_STENCILPASS, D3D9Mappings::get(passOp, true));
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Error setting stencil pass operation (cw).");
-		}
-	}
-
-	void D3D9RenderAPI::setStencilBufferFunc(CompareFunction func, bool ccw)
-	{
-		HRESULT hr;
-		
-		if(ccw)
-			hr = setRenderState(D3DRS_CCW_STENCILFUNC, D3D9Mappings::get(func));
-		else
-			hr = setRenderState(D3DRS_STENCILFUNC, D3D9Mappings::get(func));
-
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer test function.");
-	}
-
-	void D3D9RenderAPI::setStencilBufferReadMask(UINT32 mask)
-	{
-		HRESULT hr = setRenderState(D3DRS_STENCILMASK, mask);
-
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer mask.");
-	}
-
-	void D3D9RenderAPI::setStencilBufferWriteMask(UINT32 mask)
-	{
-		HRESULT hr = setRenderState(D3DRS_STENCILWRITEMASK, mask);
-
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer write mask.");
-	}
-
-	void D3D9RenderAPI::setStencilRefValue(UINT32 refValue)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr = setRenderState(D3DRS_STENCILREF, refValue);
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer reference value.");
-	}
-
-	void D3D9RenderAPI::setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		D3D9Mappings::D3DTexType texType = mTexStageDesc[unit].texType;
-		hr = setSamplerState( static_cast<DWORD>(unit), D3D9Mappings::get(ftype), 
-			D3D9Mappings::get(ftype, filter, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps(), texType));
-
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Failed to set texture filter ");
-	}
-
-
-	void D3D9RenderAPI::setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if (static_cast<DWORD>(maxAnisotropy) > mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy)
-			maxAnisotropy = mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy;
-
-		if (getCurrentAnisotropy(unit) != maxAnisotropy)
-			setSamplerState( static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, maxAnisotropy );
-	}
-
-	void D3D9RenderAPI::setRenderTarget(const SPtr<RenderTargetCore>& target, bool readOnlyDepthStencil)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mActiveRenderTarget = target;
-		const RenderTargetProperties& rtProps = target->getProperties();
-
-		HRESULT hr;
-
-		// Possibly change device if the target is a window
-		if (rtProps.isWindow())
-		{
-			D3D9RenderWindowCore* window = static_cast<D3D9RenderWindowCore*>(target.get());
-			mDeviceManager->setActiveRenderTargetDevice(window->_getDevice());
-			window->_validateDevice();
-		}
-
-		// Retrieve render surfaces
-		UINT32 maxRenderTargets = mCurrentCapabilities->getNumMultiRenderTargets();
-		IDirect3DSurface9** pBack = bs_newN<IDirect3DSurface9*>(maxRenderTargets);
-		memset(pBack, 0, sizeof(IDirect3DSurface9*) * maxRenderTargets);
-		target->getCustomAttribute("DDBACKBUFFER", pBack);
-		if (!pBack[0])
-		{
-			bs_deleteN(pBack, maxRenderTargets);
-			return;
-		}
-
-		IDirect3DSurface9* pDepth = NULL;
-
-		if (!pDepth)
-			target->getCustomAttribute("D3DZBUFFER", &pDepth);
-		
-		// Bind render targets
-		for(UINT32 x = 0; x < maxRenderTargets; ++x)
-		{
-			hr = getActiveD3D9Device()->SetRenderTarget(x, pBack[x]);
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Failed to setRenderTarget : " + msg);
-			}
-		}
-
-		bs_deleteN(pBack, maxRenderTargets);
-
-		hr = getActiveD3D9Device()->SetDepthStencilSurface(pDepth);
-		if (FAILED(hr))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Failed to setDepthStencil : " + msg);
-		}
-
-		// Set sRGB write mode
-		setRenderState(D3DRS_SRGBWRITEENABLE, rtProps.isHwGammaEnabled());
-		applyViewport();
-
-		BS_INC_RENDER_STAT(NumRenderTargetChanges);
-	}
-
-	void D3D9RenderAPI::setViewport(const Rect2& vp)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mViewportNorm = vp;
-		applyViewport();
-	}
-
-	void D3D9RenderAPI::beginFrame()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if(FAILED(hr = getActiveD3D9Device()->BeginScene()))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Error beginning frame :" + msg);
-		}
-
- 		mDeviceManager->getActiveDevice()->clearDeviceStreams();
-		mIsFrameInProgress = true;
-	}
-
-	void D3D9RenderAPI::endFrame()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if(FAILED(hr = getActiveD3D9Device()->EndScene()))
-			BS_EXCEPT(RenderingAPIException, "Error ending frame");
-
-		mIsFrameInProgress = false;
-	}
-
-	void D3D9RenderAPI::setVertexDeclaration(const SPtr<VertexDeclarationCore>& decl)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		SPtr<D3D9VertexDeclarationCore> d3ddecl = std::static_pointer_cast<D3D9VertexDeclarationCore>(decl);
-
-		HRESULT hr;
-		if (FAILED(hr = getActiveD3D9Device()->SetVertexDeclaration(d3ddecl->getD3DVertexDeclaration())))
-		{
-			BS_EXCEPT(RenderingAPIException, "Unable to set D3D9 vertex declaration");
-		}
-	}
-
-	void D3D9RenderAPI::setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		UINT32 maxBoundVertexBuffers = mCurrentCapabilities->getMaxBoundVertexBuffers();
-		if(index < 0 || (index + numBuffers) > maxBoundVertexBuffers)
-			BS_EXCEPT(InvalidParametersException, "Invalid vertex index: " + toString(index) + ". Valid range is 0 .. " + toString(maxBoundVertexBuffers - 1));
-
-		HRESULT hr;
-
-		for(UINT32 i = 0; i < numBuffers; i++)
-		{
-			if(buffers[i] != nullptr)
-			{
-				SPtr<D3D9VertexBufferCore> d3d9buf = std::static_pointer_cast<D3D9VertexBufferCore>(buffers[i]);
-				const VertexBufferProperties& vbProps = d3d9buf->getProperties();
-
-				hr = getActiveD3D9Device()->SetStreamSource(
-					static_cast<UINT>(index + i),
-					d3d9buf->getD3D9VertexBuffer(),
-					0,
-					static_cast<UINT>(vbProps.getVertexSize()) // stride
-					);
-			}
-			else
-			{
-				hr = getActiveD3D9Device()->SetStreamSource(static_cast<UINT>(index + i), nullptr, 0, 0);
-			}
-
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Unable to set D3D9 stream source for buffer binding");
-
-			BS_INC_RENDER_STAT(NumVertexBufferBinds);
-		}
-	}
-
-	void D3D9RenderAPI::setIndexBuffer(const SPtr<IndexBufferCore>& buffer)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		SPtr<D3D9IndexBufferCore> d3dIdxBuf = std::static_pointer_cast<D3D9IndexBufferCore>(buffer);
-
-		HRESULT hr = getActiveD3D9Device()->SetIndices( d3dIdxBuf->getD3DIndexBuffer() );
-		if (FAILED(hr))
-			BS_EXCEPT(RenderingAPIException, "Failed to set index buffer");
-
-		BS_INC_RENDER_STAT(NumIndexBufferBinds);
-	}
-
-	void D3D9RenderAPI::setDrawOperation(DrawOperationType op)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mCurrentDrawOperation = op;
-	}
-
-	void D3D9RenderAPI::draw(UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount)
-	{
-		// Note: Not supporting instanced drawing
-
-		UINT32 primCount = vertexCountToPrimCount(mCurrentDrawOperation, vertexCount);
-
-		HRESULT hr = getActiveD3D9Device()->DrawPrimitive(getD3D9PrimitiveType(), static_cast<UINT>(vertexOffset), static_cast<UINT>(primCount)); 
-
-		if(FAILED(hr))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Failed to DrawPrimitive : " + msg);
-		}
-
-		BS_INC_RENDER_STAT(NumDrawCalls);
-		BS_ADD_RENDER_STAT(NumVertices, vertexCount);
-		BS_ADD_RENDER_STAT(NumPrimitives, primCount);
-	}
-
-	void D3D9RenderAPI::drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount, 
-		UINT32 instanceCount)
-	{
-		// Note: Not supporting instanced drawing
-
-		UINT32 primCount = vertexCountToPrimCount(mCurrentDrawOperation, indexCount);
-
-		// do indexed draw operation
-		HRESULT hr = getActiveD3D9Device()->DrawIndexedPrimitive(
-			getD3D9PrimitiveType(), 
-			static_cast<UINT>(vertexOffset), 
-			0, 
-			static_cast<UINT>(vertexCount), 
-			static_cast<UINT>(startIndex), 
-			static_cast<UINT>(primCount)
-			);
-
-		if(FAILED(hr))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Failed to DrawIndexedPrimitive : " + msg);
-		}
-
-		BS_INC_RENDER_STAT(NumDrawCalls);
-		BS_ADD_RENDER_STAT(NumVertices, vertexCount);
-		BS_ADD_RENDER_STAT(NumPrimitives, primCount);
-	}
-
-	void D3D9RenderAPI::dispatchCompute(UINT32 numGroupsX, UINT32 numGroupsY, UINT32 numGroupsZ)
-	{
-		// Not supported on DX9
-	}
-
-	void D3D9RenderAPI::setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mScissorRect.left = static_cast<LONG>(left);
-		mScissorRect.top = static_cast<LONG>(top);
-		mScissorRect.bottom = static_cast<LONG>(bottom);
-		mScissorRect.right = static_cast<LONG>(right);
-	}
-
-	void D3D9RenderAPI::setScissorTestEnable(bool enable)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		HRESULT hr;
-		if (enable)
-		{
-			if (FAILED(hr = setRenderState(D3DRS_SCISSORTESTENABLE, TRUE)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to enable scissor rendering state; " + getErrorDescription(hr));
-			}
-
-			if (FAILED(hr = getActiveD3D9Device()->SetScissorRect(&mScissorRect)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to set scissor rectangle; " + getErrorDescription(hr));
-			}
-		}
-		else
-		{
-			if (FAILED(hr = setRenderState(D3DRS_SCISSORTESTENABLE, FALSE)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to disable scissor rendering state; " + getErrorDescription(hr));
-			}
-		}
-	}
-
-	void D3D9RenderAPI::setMultisampleAntialiasEnable(bool enable)
-	{
-		HRESULT hr;
-		if(enable)
-		{
-			if (FAILED(hr = setRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to enable multisample antialiasing. Error description: " + getErrorDescription(hr));
-			}
-		}
-		else
-		{
-			if (FAILED(hr = setRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to disable multisample antialiasing. Error description: " + getErrorDescription(hr));
-			}
-		}
-	}
-
-	void D3D9RenderAPI::setAntialiasedLineEnable(bool enable)
-	{
-		HRESULT hr;
-		if(enable)
-		{
-			if (FAILED(hr = setRenderState(D3DRS_ANTIALIASEDLINEENABLE, TRUE)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to enable line antialiasing. Error description: " + getErrorDescription(hr));
-			}
-		}
-		else
-		{
-			if (FAILED(hr = setRenderState(D3DRS_ANTIALIASEDLINEENABLE, FALSE)))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to disable line antialiasing. Error description: " + getErrorDescription(hr));
-			}
-		}
-	}
-
-	void D3D9RenderAPI::clearRenderTarget(UINT32 buffers, const Color& color, float depth, UINT16 stencil, UINT8 targetMask)
-	{
-		if(mActiveRenderTarget == nullptr)
-			return;
-
-		if (targetMask != 0xFF)
-			LOGWRN("DirectX 9 ignoring target mask for clearRenderTarget(). Only 0xFF is supported.");
-
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
-		Rect2I clearRect(0, 0, rtProps.getWidth(), rtProps.getHeight());
-
-		clearArea(buffers, color, depth, stencil, clearRect);
-	}
-
-	void D3D9RenderAPI::clearViewport(UINT32 buffers, const Color& color, float depth, UINT16 stencil, UINT8 targetMask)
-	{
-		if (targetMask != 0xFF)
-			LOGWRN("DirectX 9 ignoring target mask for clearRenderTarget(). Only 0xFF is supported.");
-
-		Rect2I clearRect(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
-		clearArea(buffers, color, depth, stencil, clearRect);
-	}
-
-	void D3D9RenderAPI::clearArea(UINT32 buffers, const Color& color, float depth, UINT16 stencil, const Rect2I& clearRect)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if(mActiveRenderTarget == nullptr)
-			return;
-
-		DWORD flags = 0;
-		if (buffers & FBT_COLOR)
-		{
-			flags |= D3DCLEAR_TARGET;
-		}
-		if (buffers & FBT_DEPTH)
-		{
-			flags |= D3DCLEAR_ZBUFFER;
-		}
-
-		// Only try to clear the stencil buffer if supported
-		if (buffers & FBT_STENCIL)
-		{
-			flags |= D3DCLEAR_STENCIL;
-		}
-
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
-
-		bool clearEntireTarget = clearRect.width == 0 || clearRect.height == 0;
-		clearEntireTarget |= (clearRect.x == 0 && clearRect.y == 0 && clearRect.width == rtProps.getWidth() && clearRect.height == rtProps.getHeight());
-
-		if(!clearEntireTarget)
-		{
-			D3DRECT clearD3DRect;
-			clearD3DRect.x1 = (LONG)Math::clamp(clearRect.x, 0, (INT32)rtProps.getWidth() - 1);
-			clearD3DRect.x2 = (LONG)Math::clamp((INT32)clearD3DRect.x1 + clearRect.width, 0, (INT32)rtProps.getWidth() - 1);
-
-			clearD3DRect.y1 = (LONG)Math::clamp(clearRect.y, 0, (INT32)rtProps.getHeight() - 1);
-			clearD3DRect.y2 = (LONG)Math::clamp((INT32)clearD3DRect.y1 + clearRect.height, 0, (INT32)rtProps.getHeight() - 1);
-
-			HRESULT hr;
-			if(FAILED(hr = getActiveD3D9Device()->Clear(1, &clearD3DRect, flags, color.getAsBGRA(), depth, stencil)))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Error clearing frame buffer : " + msg);
-			}
-		}
-		else
-		{
-			HRESULT hr;
-			if(FAILED(hr = getActiveD3D9Device()->Clear(0, nullptr, flags, color.getAsBGRA(), depth, stencil)))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Error clearing frame buffer : " + msg);
-			}
-		}
-
-		BS_INC_RENDER_STAT(NumClears);
-	}
-
-	IDirect3D9*	D3D9RenderAPI::getDirect3D9()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		return msD3D9RenderSystem->mpD3D;
-	}
-
-	UINT D3D9RenderAPI::getResourceCreationDeviceCount()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		D3D9ResourceCreationPolicy creationPolicy = msD3D9RenderSystem->mResourceManager->getCreationPolicy();
-
-		if (creationPolicy == RCP_CREATE_ON_ACTIVE_DEVICE)
-		{
-			return 1;
-		}
-		else if (creationPolicy == RCP_CREATE_ON_ALL_DEVICES)
-		{
-			return msD3D9RenderSystem->mDeviceManager->getDeviceCount();
-		}
-
-		BS_EXCEPT(InvalidParametersException, "Invalid resource creation policy.");
-
-		return 0;
-	}
-
-	IDirect3DDevice9* D3D9RenderAPI::getResourceCreationDevice(UINT index)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		D3D9ResourceCreationPolicy creationPolicy = msD3D9RenderSystem->mResourceManager->getCreationPolicy();
-		IDirect3DDevice9* d3d9Device = NULL;
-
-		if (creationPolicy == RCP_CREATE_ON_ACTIVE_DEVICE)
-		{
-			d3d9Device = msD3D9RenderSystem->getActiveD3D9Device();
-		}
-		else if (creationPolicy == RCP_CREATE_ON_ALL_DEVICES) 
-		{
-			d3d9Device = msD3D9RenderSystem->mDeviceManager->getDevice(index)->getD3D9Device();
-		}
-		else
-		{
-			BS_EXCEPT(InvalidParametersException, "Invalid resource creation policy.");
-		}
-
-		return d3d9Device;
-	}
-
-	IDirect3DDevice9* D3D9RenderAPI::getActiveD3D9Device()
-	{	
-		THROW_IF_NOT_CORE_THREAD;
-
-		D3D9Device* activeDevice = msD3D9RenderSystem->mDeviceManager->getActiveDevice();
-		IDirect3DDevice9* d3d9Device;
-
-		d3d9Device = activeDevice->getD3D9Device();
-
-		if (d3d9Device == nullptr)
-			BS_EXCEPT(InvalidParametersException, "Current d3d9 device is null.");
-
-		return d3d9Device;
-	}	
-
-	D3D9ResourceManager* D3D9RenderAPI::getResourceManager()
-	{
-		// No need to check if we're on core thread as this is synced up internally
-
-		return msD3D9RenderSystem->mResourceManager;
-	}
-
-	D3D9DeviceManager* D3D9RenderAPI::getDeviceManager()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		return msD3D9RenderSystem->mDeviceManager;
-	}
-
-	/************************************************************************/
-	/* 								UTILITY METHODS                    		*/
-	/************************************************************************/
-
-	void D3D9RenderAPI::convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest)
-	{
-		dest = matrix;
-
-		// Convert depth range from [-1,+1] to [0,1]
-		dest[2][0] = (dest[2][0] + dest[3][0]) / 2;
-		dest[2][1] = (dest[2][1] + dest[3][1]) / 2;
-		dest[2][2] = (dest[2][2] + dest[3][2]) / 2;
-		dest[2][3] = (dest[2][3] + dest[3][3]) / 2;
-	}
-
-	const RenderAPIInfo& D3D9RenderAPI::getAPIInfo() const
-	{
-		static RenderAPIInfo info(-0.5f, 0.5f, 0.0f, 1.0f, VET_COLOR_ARGB, true, true, false);
-
-		return info;
-	}
-
-	GpuParamBlockDesc D3D9RenderAPI::generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params)
-	{
-		GpuParamBlockDesc block;
-		block.blockSize = 0;
-		block.isShareable = true;
-		block.name = name;
-		block.slot = 0;
-
-		// DX9 doesn't natively support parameter blocks but Banshee's emulation expects everything to be 16 byte aligned.
-		// Iterate in reverse order because DX9's shader reflection API reports the variables in reverse order then they
-		// appear in code, and we want to match the auto-generated buffers that result from that layout.
-		for (auto riter = params.rbegin(); riter != params.rend(); ++riter)
-		{
-			GpuParamDataDesc& param = *riter;
-
-			const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[param.type];
-			UINT32 size = typeInfo.size / 4;
-
-			UINT32 alignOffset = size % 4;
-			if (alignOffset != 0)
-				size += 4 - alignOffset;
-
-			param.elementSize = size;
-			param.arrayElementStride = size;
-			param.cpuMemOffset = block.blockSize;
-			param.gpuMemOffset = 0;
-			param.paramBlockSlot = 0;
-
-			if (param.arraySize > 0)
-				block.blockSize += size * param.arraySize;
-			else
-				block.blockSize += size;
-		}
-
-		return block;
-	}
-
-	/************************************************************************/
-	/* 								PRIVATE		                     		*/
-	/************************************************************************/
-
-	D3D9DriverList* D3D9RenderAPI::getDirect3DDrivers() const
-	{
-		if( !mDriverList )
-			mDriverList = bs_new<D3D9DriverList>();
-
-		return mDriverList;
-	}
-
-	D3DPRIMITIVETYPE D3D9RenderAPI::getD3D9PrimitiveType() const
-	{
-		switch(mCurrentDrawOperation)
-		{
-		case DOT_POINT_LIST:
-			return D3DPT_POINTLIST;
-		case DOT_LINE_LIST:
-			return D3DPT_LINELIST;
-		case DOT_LINE_STRIP:
-			return D3DPT_LINESTRIP;
-		case DOT_TRIANGLE_LIST:
-			return D3DPT_TRIANGLELIST;
-		case DOT_TRIANGLE_STRIP:
-			return D3DPT_TRIANGLESTRIP;
-		case DOT_TRIANGLE_FAN:
-			return D3DPT_TRIANGLEFAN;
-		}
-
-		return D3DPT_TRIANGLELIST;
-	}
-
-	RenderAPICapabilities* D3D9RenderAPI::updateRenderSystemCapabilities(D3D9RenderWindowCore* renderWindow)
-	{			
-		RenderAPICapabilities* rsc = mCurrentCapabilities;
-		if (rsc == nullptr)
-			rsc = bs_new<RenderAPICapabilities>();
-
-		rsc->setDriverVersion(mDriverVersion);
-		rsc->setDeviceName(mActiveD3DDriver->getDriverDescription());
-		rsc->setRenderAPIName(getName());
-
-		// Init caps to maximum.		
-		rsc->setCapability(RSC_ANISOTROPY);
-		rsc->setCapability(RSC_AUTOMIPMAP);
-		rsc->setCapability(RSC_CUBEMAPPING);			
-		rsc->setCapability(RSC_TWO_SIDED_STENCIL);		
-		rsc->setCapability(RSC_STENCIL_WRAP);
-		rsc->setCapability(RSC_HWOCCLUSION);		
-		rsc->setCapability(RSC_USER_CLIP_PLANES);			
-		rsc->setCapability(RSC_VERTEX_FORMAT_UBYTE4);			
-		rsc->setCapability(RSC_TEXTURE_3D);			
-		rsc->setCapability(RSC_NON_POWER_OF_2_TEXTURES);
-		rsc->setNumMultiRenderTargets(BS_MAX_MULTIPLE_RENDER_TARGETS);
-		rsc->setCapability(RSC_MRT_DIFFERENT_BIT_DEPTHS);		
-		rsc->setCapability(RSC_POINT_SPRITES);			
-		rsc->setCapability(RSC_POINT_EXTENDED_PARAMETERS);								
-		rsc->setMaxPointSize(10.0);
-		rsc->setCapability(RSC_MIPMAP_LOD_BIAS);				
-		rsc->setCapability(RSC_PERSTAGECONSTANT);
-		rsc->setStencilBufferBitDepth(8);
-		rsc->setCapability(RSC_ADVANCED_BLEND_OPERATIONS);
-
-		for (UINT32 i=0; i < mDeviceManager->getDeviceCount(); ++i)
-		{
-			D3D9Device* device			 = mDeviceManager->getDevice(i);
-			IDirect3DDevice9* d3d9Device = device->getD3D9Device();
-
-			IDirect3DSurface9* pSurf;
-
-
-			// Check for hardware stencil support
-			d3d9Device->GetDepthStencilSurface(&pSurf);
-
-			if (pSurf != nullptr)
-			{
-				D3DSURFACE_DESC surfDesc;
-
-				pSurf->GetDesc(&surfDesc);
-				pSurf->Release();
-			}																	
-
-			// Check for hardware occlusion support
-			HRESULT hr = d3d9Device->CreateQuery(D3DQUERYTYPE_OCCLUSION,  NULL);
-
-			if (FAILED(hr))
-				rsc->unsetCapability(RSC_HWOCCLUSION);
-		}
-
-		// Update RS caps using the minimum value found in adapter list.
-		for (unsigned int i=0; i < mDriverList->count(); ++i)
-		{
-			D3D9Driver* pCurDriver       = mDriverList->item(i);			
-			const D3DCAPS9& rkCurCaps    = pCurDriver->getD3D9DeviceCaps();
-
-			rsc->setNumTextureUnits(GPT_FRAGMENT_PROGRAM, 16); // We don't support anything lower than SM3, and 16 is the sampler count determined by the specification
-
-			rsc->setMaxBoundVertexBuffers(static_cast<UINT32>(rkCurCaps.MaxStreams));
-
-			// Check for Anisotropy.
-			if (rkCurCaps.MaxAnisotropy <= 1)
-				rsc->unsetCapability(RSC_ANISOTROPY);
-
-			// Check automatic mipmap generation.
-			if ((rkCurCaps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP) == 0)
-				rsc->unsetCapability(RSC_AUTOMIPMAP);
-
-			// Two-sided stencil
-			if ((rkCurCaps.StencilCaps & D3DSTENCILCAPS_TWOSIDED) == 0)
-				rsc->unsetCapability(RSC_TWO_SIDED_STENCIL);
-
-			// stencil wrap
-			if ((rkCurCaps.StencilCaps & D3DSTENCILCAPS_INCR) == 0 ||
-				(rkCurCaps.StencilCaps & D3DSTENCILCAPS_DECR) == 0)
-				rsc->unsetCapability(RSC_STENCIL_WRAP);
-
-			// User clip planes
-			if (rkCurCaps.MaxUserClipPlanes == 0)			
-				rsc->unsetCapability(RSC_USER_CLIP_PLANES);			
-
-			// UBYTE4 type?
-			if ((rkCurCaps.DeclTypes & D3DDTCAPS_UBYTE4) == 0)			
-				rsc->unsetCapability(RSC_VERTEX_FORMAT_UBYTE4);	
-
-			// Check cube map support.
-			if ((rkCurCaps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) == 0)
-				rsc->unsetCapability(RSC_CUBEMAPPING);
-
-			// 3D textures?
-			if ((rkCurCaps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) == 0)			
-				rsc->unsetCapability(RSC_TEXTURE_3D);			
-
-			if (rkCurCaps.TextureCaps & D3DPTEXTURECAPS_POW2)
-			{
-				// Conditional support for non POW2
-				if (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))							
-					rsc->unsetCapability(RSC_NON_POWER_OF_2_TEXTURES);				
-			}	
-
-			// Number of render targets
-			if (rkCurCaps.NumSimultaneousRTs < rsc->getNumMultiRenderTargets())
-			{
-				rsc->setNumMultiRenderTargets(std::min((UINT16)rkCurCaps.NumSimultaneousRTs, (UINT16)BS_MAX_MULTIPLE_RENDER_TARGETS));
-			}	
-
-			if((rkCurCaps.PrimitiveMiscCaps & D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS) == 0)
-			{
-				rsc->unsetCapability(RSC_MRT_DIFFERENT_BIT_DEPTHS);
-			}
-
-			// Point sprites 
-			if (rkCurCaps.MaxPointSize <= 1.0f)
-			{
-				rsc->unsetCapability(RSC_POINT_SPRITES);
-				// sprites and extended parameters go together in D3D
-				rsc->unsetCapability(RSC_POINT_EXTENDED_PARAMETERS);				
-			}
-
-			// Take the minimum point size.
-			if (rkCurCaps.MaxPointSize < rsc->getMaxPointSize())
-				rsc->setMaxPointSize(rkCurCaps.MaxPointSize);	
-
-			// Mipmap LOD biasing?
-			if ((rkCurCaps.RasterCaps & D3DPRASTERCAPS_MIPMAPLODBIAS) == 0)			
-				rsc->unsetCapability(RSC_MIPMAP_LOD_BIAS);			
-
-
-			// Do we support per-stage src_manual constants?
-			// HACK - ATI drivers seem to be buggy and don't support per-stage constants properly?
-			// TODO: move this to RSC
-			if((rkCurCaps.PrimitiveMiscCaps & D3DPMISCCAPS_PERSTAGECONSTANT) == 0)
-				rsc->unsetCapability(RSC_PERSTAGECONSTANT);
-
-			// Advanced blend operations? min max subtract rev 
-			if((rkCurCaps.PrimitiveMiscCaps & D3DPMISCCAPS_BLENDOP) == 0)
-				rsc->unsetCapability(RSC_ADVANCED_BLEND_OPERATIONS);
-		}				
-
-		// We always support compression, D3DX will decompress if device does not support
-		rsc->setCapability(RSC_TEXTURE_COMPRESSION);
-		rsc->setCapability(RSC_TEXTURE_COMPRESSION_DXT);
-
-		updateVertexShaderCaps(rsc);
-		updatePixelShaderCaps(rsc);
-
-		// Adapter details
-		const D3DADAPTER_IDENTIFIER9& adapterID = mActiveD3DDriver->getAdapterIdentifier();
-
-		// determine vendor
-		// Full list of vendors here: http://www.pcidatabase.com/vendors.php?sort=id
-		switch(adapterID.VendorId)
-		{
-		case 0x10DE:
-			rsc->setVendor(GPU_NVIDIA);
-			break;
-		case 0x1002:
-			rsc->setVendor(GPU_AMD);
-			break;
-		case 0x163C:
-		case 0x8086:
-			rsc->setVendor(GPU_INTEL);
-			break;
-		default:
-			rsc->setVendor(GPU_UNKNOWN);
-			break;
-		};
-
-		rsc->setCapability(RSC_INFINITE_FAR_PLANE);
-
-		// We always support rendertextures bigger than the frame buffer
-		rsc->setCapability(RSC_HWRENDER_TO_TEXTURE);
-
-		// Determine if any floating point texture format is supported
-		D3DFORMAT floatFormats[6] = {D3DFMT_R16F, D3DFMT_G16R16F, 
-			D3DFMT_A16B16G16R16F, D3DFMT_R32F, D3DFMT_G32R32F, 
-			D3DFMT_A32B32G32R32F};
-		IDirect3DSurface9* bbSurf;
-		renderWindow->getCustomAttribute("DDBACKBUFFER", &bbSurf);
-		D3DSURFACE_DESC bbSurfDesc;
-		bbSurf->GetDesc(&bbSurfDesc);
-
-		for (int i = 0; i < 6; ++i)
-		{
-			if (SUCCEEDED(mpD3D->CheckDeviceFormat(mActiveD3DDriver->getAdapterNumber(), 
-				D3DDEVTYPE_HAL, bbSurfDesc.Format, 
-				0, D3DRTYPE_TEXTURE, floatFormats[i])))
-			{
-				rsc->setCapability(RSC_TEXTURE_FLOAT);
-				break;
-			}
-
-		}
-
-		// Vertex textures
-		if (rsc->isShaderProfileSupported("vs_3_0"))
-		{
-			rsc->setCapability(RSC_VERTEX_TEXTURE_FETCH);
-			rsc->setNumTextureUnits(GPT_VERTEX_PROGRAM, 4);
-			rsc->setNumCombinedTextureUnits(rsc->getNumTextureUnits(GPT_FRAGMENT_PROGRAM) +
-				rsc->getNumTextureUnits(GPT_VERTEX_PROGRAM));
-		}		
-		else
-		{
-			rsc->setNumCombinedTextureUnits(rsc->getNumTextureUnits(GPT_FRAGMENT_PROGRAM));
-		}
-
-		// Check alpha to coverage support
-		// this varies per vendor! But at least SM3 is required
-		if (rsc->isShaderProfileSupported("ps_3_0"))
-		{
-			// NVIDIA needs a separate check
-			if (rsc->getVendor() == GPU_NVIDIA)
-			{
-				if (mpD3D->CheckDeviceFormat(
-					D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0,D3DRTYPE_SURFACE, 
-					(D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C')) == S_OK)
-				{
-					rsc->setCapability(RSC_ALPHA_TO_COVERAGE);
-				}
-
-			}
-			else if (rsc->getVendor() == GPU_AMD)
-			{
-				// There is no check on ATI, we have to assume SM3 == support
-				rsc->setCapability(RSC_ALPHA_TO_COVERAGE);
-			}
-
-			// no other cards have Dx9 hacks for alpha to coverage, as far as I know
-		}
-
-
-		if (mCurrentCapabilities == nullptr)
-		{		
-			mCurrentCapabilities = rsc;
-			mCurrentCapabilities->addShaderProfile("hlsl");
-
-			if (mCurrentCapabilities->isShaderProfileSupported("hlsl"))
-				GpuProgramCoreManager::instance().addFactory(mHLSLProgramFactory);
-
-			mNumTexStages = mCurrentCapabilities->getNumCombinedTextureUnits();
-			mTexStageDesc = bs_newN<sD3DTextureStageDesc>(mNumTexStages);
-
-			// set stages desc. to defaults
-			for (UINT32 n = 0; n < mNumTexStages; n++)
-			{
-				mTexStageDesc[n].coordIndex = 0;
-				mTexStageDesc[n].texType = D3D9Mappings::D3D_TEX_TYPE_NORMAL;
-				mTexStageDesc[n].pTex = 0;
-				mTexStageDesc[n].pVertexTex = 0;
-			}
-		}
-
-		return rsc;
-	}
-
-	void D3D9RenderAPI::updateVertexShaderCaps(RenderAPICapabilities* rsc) const
-	{
-		UINT16 major = 0xFF;
-		UINT16 minor = 0xFF;
-		D3DCAPS9 minVSCaps;
-
-		// Find the device with the lowest vertex shader caps.
-		for (unsigned int i=0; i < mDriverList->count(); ++i)
-		{
-			D3D9Driver* pCurDriver      = mDriverList->item(i);			
-			const D3DCAPS9& rkCurCaps   = pCurDriver->getD3D9DeviceCaps();
-			UINT16 currMajor			= static_cast<UINT16>((rkCurCaps.VertexShaderVersion & 0x0000FF00) >> 8);
-			UINT16 currMinor			= static_cast<UINT16>(rkCurCaps.VertexShaderVersion & 0x000000FF);
-
-			if (currMajor < major)	
-			{
-				major = currMajor;
-				minor = currMinor;
-				minVSCaps = rkCurCaps;
-			}
-			else if (currMajor == major && currMinor < minor)
-			{
-				minor = currMinor;
-				minVSCaps = rkCurCaps;
-			}			
-		}
-
-		// In case we didn't found any vertex shader support
-		// try the IDirect3DDevice9 caps instead of the IDirect3D9
-		// software vertex processing is reported there
-		if (major == 0 && minor == 0)
-		{
-			IDirect3DDevice9* lpD3DDevice9 = getActiveD3D9Device();
-			D3DCAPS9 d3dDeviceCaps9;
-			lpD3DDevice9->GetDeviceCaps(&d3dDeviceCaps9);
-			major = static_cast<UINT16>((d3dDeviceCaps9.VertexShaderVersion & 0x0000FF00) >> 8);
-			minor = static_cast<UINT16>(d3dDeviceCaps9.VertexShaderVersion & 0x000000FF);
-		}
-
-		bool vs2x = false;
-		bool vs2a = false;
-
-		// Special case detection for vs_2_x/a support
-		if (major >= 2)
-		{
-			if ((minVSCaps.VS20Caps.Caps & D3DVS20CAPS_PREDICATION) &&
-				(minVSCaps.VS20Caps.DynamicFlowControlDepth > 0) &&
-				(minVSCaps.VS20Caps.NumTemps >= 12))
-			{
-				vs2x = true;
-			}
-
-			if ((minVSCaps.VS20Caps.Caps & D3DVS20CAPS_PREDICATION) &&
-				(minVSCaps.VS20Caps.DynamicFlowControlDepth > 0) &&
-				(minVSCaps.VS20Caps.NumTemps >= 13))
-			{
-				vs2a = true;
-			}
-		}
-
-		// Populate max param count
-		switch (major)
-		{
-		case 1:
-			// No boolean params allowed
-			rsc->setVertexProgramConstantBoolCount(0);
-			// No integer params allowed
-			rsc->setVertexProgramConstantIntCount(0);
-			// float params, always 4D
-			rsc->setVertexProgramConstantFloatCount(static_cast<UINT16>(minVSCaps.MaxVertexShaderConst));
-
-			break;
-		case 2:
-			// 16 boolean params allowed
-			rsc->setVertexProgramConstantBoolCount(16);
-			// 16 integer params allowed, 4D
-			rsc->setVertexProgramConstantIntCount(16);
-			// float params, always 4D
-			rsc->setVertexProgramConstantFloatCount(static_cast<UINT16>(minVSCaps.MaxVertexShaderConst));
-			break;
-		case 3:
-			// 16 boolean params allowed
-			rsc->setVertexProgramConstantBoolCount(16);
-			// 16 integer params allowed, 4D
-			rsc->setVertexProgramConstantIntCount(16);
-			// float params, always 4D
-			rsc->setVertexProgramConstantFloatCount(static_cast<UINT16>(minVSCaps.MaxVertexShaderConst));
-			break;
-		}
-
-		// populate syntax codes in program manager (no breaks in this one so it falls through)
-		switch(major)
-		{
-		case 3:
-			rsc->addShaderProfile("vs_3_0");
-			rsc->addGpuProgramProfile(GPP_VS_3_0, "vs_3_0");
-		case 2:
-			if (vs2x)
-			{
-				rsc->addShaderProfile("vs_2_x");
-				rsc->addGpuProgramProfile(GPP_VS_2_x, "vs_2_x");
-			}
-			if (vs2a)
-			{
-				rsc->addShaderProfile("vs_2_a");
-				rsc->addGpuProgramProfile(GPP_VS_2_a, "vs_2_a");
-			}
-
-			rsc->addShaderProfile("vs_2_0");
-			rsc->addGpuProgramProfile(GPP_VS_2_0, "vs_2_0");
-		case 1:
-			rsc->addShaderProfile("vs_1_1");
-			rsc->addGpuProgramProfile(GPP_VS_1_1, "vs_1_1");
-		}
-	}
-
-	void D3D9RenderAPI::updatePixelShaderCaps(RenderAPICapabilities* rsc) const
-	{
-		UINT16 major = 0xFF;
-		UINT16 minor = 0xFF;
-		D3DCAPS9 minPSCaps;
-
-		// Find the device with the lowest pixel shader caps.
-		for (unsigned int i=0; i < mDriverList->count(); ++i)
-		{
-			D3D9Driver* pCurDriver      = mDriverList->item(i);			
-			const D3DCAPS9& currCaps    = pCurDriver->getD3D9DeviceCaps();
-			UINT16 currMajor			= static_cast<UINT16>((currCaps.PixelShaderVersion & 0x0000FF00) >> 8);
-			UINT16 currMinor			= static_cast<UINT16>(currCaps.PixelShaderVersion & 0x000000FF);
-
-			if (currMajor < major)	
-			{
-				major = currMajor;
-				minor = currMinor;
-				minPSCaps = currCaps;
-			}
-			else if (currMajor == major && currMinor < minor)
-			{
-				minor = currMinor;
-				minPSCaps = currCaps;
-			}			
-		}
-
-		bool ps2a = false;
-		bool ps2b = false;
-		bool ps2x = false;
-
-		// Special case detection for ps_2_x/a/b support
-		if (major >= 2)
-		{
-			if ((minPSCaps.PS20Caps.Caps & D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT) &&
-				(minPSCaps.PS20Caps.NumTemps >= 32))
-			{
-				ps2b = true;
-			}
-
-			if ((minPSCaps.PS20Caps.Caps & D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT) &&
-				(minPSCaps.PS20Caps.Caps & D3DPS20CAPS_NODEPENDENTREADLIMIT) &&
-				(minPSCaps.PS20Caps.Caps & D3DPS20CAPS_ARBITRARYSWIZZLE) &&
-				(minPSCaps.PS20Caps.Caps & D3DPS20CAPS_GRADIENTINSTRUCTIONS) &&
-				(minPSCaps.PS20Caps.Caps & D3DPS20CAPS_PREDICATION) &&
-				(minPSCaps.PS20Caps.NumTemps >= 22))
-			{
-				ps2a = true;
-			}
-
-			// Does this enough?
-			if (ps2a || ps2b)
-			{
-				ps2x = true;
-			}
-		}
-
-		switch (major)
-		{
-		case 1:
-			// no boolean params allowed
-			rsc->setFragmentProgramConstantBoolCount(0);
-			// no integer params allowed
-			rsc->setFragmentProgramConstantIntCount(0);
-			// float params, always 4D
-			rsc->setFragmentProgramConstantFloatCount(8);
-			break;
-		case 2:
-			// 16 boolean params allowed
-			rsc->setFragmentProgramConstantBoolCount(16);
-			// 16 integer params allowed, 4D
-			rsc->setFragmentProgramConstantIntCount(16);
-			// float params, always 4D
-			rsc->setFragmentProgramConstantFloatCount(32);
-			break;
-		case 3:
-			// 16 boolean params allowed
-			rsc->setFragmentProgramConstantBoolCount(16);
-			// 16 integer params allowed, 4D
-			rsc->setFragmentProgramConstantIntCount(16);
-			// float params, always 4D
-			rsc->setFragmentProgramConstantFloatCount(224);
-			break;
-		}
-
-		// populate syntax codes in program manager (no breaks in this one so it falls through)
-		switch(major)
-		{
-		case 3:
-			if (minor > 0)
-			{
-				rsc->addShaderProfile("ps_3_x");
-				rsc->addGpuProgramProfile(GPP_FS_3_x, "ps_3_x");
-			}
-
-			rsc->addShaderProfile("ps_3_0");
-			rsc->addGpuProgramProfile(GPP_FS_3_0, "ps_3_0");
-		case 2:
-			if (ps2x)
-			{
-				rsc->addShaderProfile("ps_2_x");
-				rsc->addGpuProgramProfile(GPP_FS_2_x, "ps_2_x");
-			}
-			if (ps2a)
-			{
-				rsc->addShaderProfile("ps_2_a");
-				rsc->addGpuProgramProfile(GPP_FS_2_a, "ps_2_a");
-			}
-			if (ps2b)
-			{
-				rsc->addShaderProfile("ps_2_b");
-				rsc->addGpuProgramProfile(GPP_FS_2_b, "ps_2_b");
-			}
-
-			rsc->addShaderProfile("ps_2_0");
-			rsc->addGpuProgramProfile(GPP_FS_2_0, "ps_2_0");
-		case 1:
-			if (major > 1 || minor >= 4)
-			{
-				rsc->addShaderProfile("ps_1_4");
-				rsc->addGpuProgramProfile(GPP_FS_1_4, "ps_1_4");
-			}
-			if (major > 1 || minor >= 3)
-			{
-				rsc->addShaderProfile("ps_1_3");
-				rsc->addGpuProgramProfile(GPP_FS_1_3, "ps_1_3");
-			}
-			if (major > 1 || minor >= 2)
-			{
-				rsc->addShaderProfile("ps_1_2");
-				rsc->addGpuProgramProfile(GPP_FS_1_2, "ps_1_2");
-			}
-
-			rsc->addShaderProfile("ps_1_1");
-			rsc->addGpuProgramProfile(GPP_FS_1_1, "ps_1_1");
-		}
-	}
-
-	String D3D9RenderAPI::getErrorDescription(long errorNumber) const
-	{
-		const String errMsg = DXGetErrorDescription(errorNumber);
-		return errMsg;
-	}
-
-	void D3D9RenderAPI::setClipPlane (UINT16 index, float A, float B, float C, float D)
-	{
-		float plane[4] = { A, B, C, D };
-		getActiveD3D9Device()->SetClipPlane (index, plane);
-	}
-
-	void D3D9RenderAPI::enableClipPlane (UINT16 index, bool enable)
-	{
-		DWORD prev;
-		getActiveD3D9Device()->GetRenderState(D3DRS_CLIPPLANEENABLE, &prev);
-		setRenderState(D3DRS_CLIPPLANEENABLE, enable?
-			(prev | (1 << index)) : (prev & ~(1 << index)));
-	}
-
-	void D3D9RenderAPI::notifyOnDeviceLost(D3D9Device* device)
-	{	
-		if (mIsFrameInProgress)
-		{
-			endFrame();
-			mRestoreFrameOnReset = true;
-		}
-	}
-
-	void D3D9RenderAPI::notifyOnDeviceReset(D3D9Device* device)
-	{		
-		// Reset state attributes.	
-		mVertexProgramBound = false;
-		mFragmentProgramBound = false;
-
-		if (mRestoreFrameOnReset)
-		{
-			beginFrame();
-			mRestoreFrameOnReset = false;
-		}
-	}
-
-	void D3D9RenderAPI::determineMultisampleSettings(IDirect3DDevice9* d3d9Device, UINT32 multisampleCount, D3DFORMAT d3dPixelFormat, 
-		bool fullScreen, D3DMULTISAMPLE_TYPE *outMultisampleType, DWORD *outMultisampleQuality) const
-	{
-		bool tryCSAA = false; // Note: Disabled for now, but leaving the code for later so it might be useful
-		enum CSAAMode { CSAA_Normal, CSAA_Quality };
-		CSAAMode csaaMode = CSAA_Normal;
-
-		D3D9DriverList* driverList = getDirect3DDrivers();
-		D3D9Driver* deviceDriver = mActiveD3DDriver;
-		D3D9Device* device = mDeviceManager->getDeviceFromD3D9Device(d3d9Device);
-
-		for (UINT32 i = 0; i < driverList->count(); ++i)
-		{
-			D3D9Driver* currDriver = driverList->item(i);
-
-			if (currDriver->getAdapterNumber() == device->getAdapterNumber())
-			{
-				deviceDriver = currDriver;
-				break;
-			}
-		}
-
-		UINT32 origNumSamples = multisampleCount;
-		bool foundValid = false;
-		while (!foundValid)
-		{
-			// Deal with special cases
-			if (tryCSAA)
-			{
-				switch(multisampleCount)
-				{
-				case 8:
-					if (csaaMode == CSAA_Quality)
-					{
-						*outMultisampleType = D3DMULTISAMPLE_8_SAMPLES;
-						*outMultisampleQuality = 0;
-					}
-					else
-					{
-						*outMultisampleType = D3DMULTISAMPLE_4_SAMPLES;
-						*outMultisampleQuality = 2;
-					}
-					break;
-				case 16:
-					if (csaaMode == CSAA_Quality)
-					{
-						*outMultisampleType = D3DMULTISAMPLE_8_SAMPLES;
-						*outMultisampleQuality = 2;
-					}
-					else
-					{
-						*outMultisampleType = D3DMULTISAMPLE_4_SAMPLES;
-						*outMultisampleQuality = 4;
-					}
-					break;
-				}
-			}
-			else // !CSAA
-			{
-				*outMultisampleType = D3DMULTISAMPLE_NONE;
-				*outMultisampleQuality = 0;
-			}
-
-
-			HRESULT hr;
-			DWORD outQuality;
-			hr = mpD3D->CheckDeviceMultiSampleType( 
-				deviceDriver->getAdapterNumber(), 
-				D3DDEVTYPE_HAL, 
-				d3dPixelFormat, 
-				!fullScreen, 
-				*outMultisampleType, 
-				&outQuality);
-
-			if (SUCCEEDED(hr) && 
-				(!tryCSAA || outQuality > *outMultisampleQuality))
-			{
-				foundValid = true;
-			}
-			else
-			{
-				// Downgrade
-				if (tryCSAA && multisampleCount == 8)
-				{
-					// For CSAA, we'll try downgrading with quality mode at all samples.
-					// then try without quality, then drop CSAA
-					if (csaaMode == CSAA_Quality)
-					{
-						// Drop quality first
-						csaaMode = CSAA_Normal;
-					}
-					else
-					{
-						// Drop CSAA entirely 
-						tryCSAA = false;
-					}
-
-					// Return to original requested samples
-					multisampleCount = origNumSamples;
-				}
-				else
-				{
-					// Drop samples
-					multisampleCount--;
-
-					if (multisampleCount == 1)
-					{
-						// Ran out of options, no multisampling
-						multisampleCount = 0;
-						foundValid = true;
-					}
-				}
-			}
-		}
-	}
-
-	void D3D9RenderAPI::setClipPlanesImpl(const PlaneList& clipPlanes)
-	{
-		size_t i;
-		size_t numClipPlanes;
-		D3DXPLANE dx9ClipPlane;
-		DWORD mask = 0;
-		HRESULT hr;
-
-		numClipPlanes = clipPlanes.size();
-		for (i = 0; i < numClipPlanes; ++i)
-		{
-			const Plane& plane = clipPlanes[i];
-
-			dx9ClipPlane.a = plane.normal.x;
-			dx9ClipPlane.b = plane.normal.y;
-			dx9ClipPlane.c = plane.normal.z;
-			dx9ClipPlane.d = plane.d;
-
-			// TODO Low priority - Transform planes to clip space?
-
-			hr = getActiveD3D9Device()->SetClipPlane(static_cast<DWORD>(i), dx9ClipPlane);
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Unable to set clip plane");
-			}
-
-			mask |= (1 << i);
-		}
-
-		hr = setRenderState(D3DRS_CLIPPLANEENABLE, mask);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Unable to set render state for clip planes");
-		}
-	}
-
-	HRESULT D3D9RenderAPI::setRenderState(D3DRENDERSTATETYPE state, DWORD value)
-	{
-		return getActiveD3D9Device()->SetRenderState(state, value);
-	}
-
-	HRESULT D3D9RenderAPI::setSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value)
-	{
-		return getActiveD3D9Device()->SetSamplerState(sampler, type, value);
-	}
-
-	HRESULT D3D9RenderAPI::setTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
-	{
-		if (stage < 8)
-			return getActiveD3D9Device()->SetTextureStageState(stage, type, value);
-		else
-			return D3D_OK;
-	}
-
-	DWORD D3D9RenderAPI::getCurrentAnisotropy(UINT32 unit)
-	{
-		DWORD oldVal;
-		getActiveD3D9Device()->GetSamplerState(static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, &oldVal);
-		return oldVal;
-	}
-
-	void D3D9RenderAPI::applyViewport()
-	{
-		if (mActiveRenderTarget == nullptr)
-			return;
-
-		const RenderTargetProperties& rtProps = mActiveRenderTarget->getProperties();
-		D3DVIEWPORT9 d3dvp;
-		HRESULT hr;
-
-		setCullingMode(mCullingMode);
-
-		// Set viewport dimensions
-		mViewportLeft = (UINT32)(rtProps.getWidth() * mViewportNorm.x);
-		mViewportTop = (UINT32)(rtProps.getHeight() * mViewportNorm.y);
-		mViewportWidth = (UINT32)(rtProps.getWidth() * mViewportNorm.width);
-		mViewportHeight = (UINT32)(rtProps.getHeight() * mViewportNorm.height);
-
-		d3dvp.X = mViewportLeft;
-		d3dvp.Y = mViewportTop;
-		d3dvp.Width = mViewportWidth;
-		d3dvp.Height = mViewportHeight;
-		if (rtProps.requiresTextureFlipping())
-		{
-			// Convert "top-left" to "bottom-left"
-			d3dvp.Y = rtProps.getHeight() - d3dvp.Height - d3dvp.Y;
-		}
-
-		// Z-values from 0.0 to 1.0 (TODO: standardise with OpenGL)
-		d3dvp.MinZ = 0.0f;
-		d3dvp.MaxZ = 1.0f;
-
-		if (FAILED(hr = getActiveD3D9Device()->SetViewport(&d3dvp)))
-			BS_EXCEPT(RenderingAPIException, "Failed to set viewport.");
-	}
-}

+ 0 - 22
Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderAPIFactory.cpp

@@ -1,22 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9RenderAPIFactory.h"
-#include "BsRenderAPI.h"
-
-namespace BansheeEngine
-{
-	const char* SystemName = "BansheeD3D9RenderSystem";
-
-	void D3D9RenderAPIFactory::create()
-	{
-	#ifdef BS_STATIC_LIB
-		HINSTANCE hInst = GetModuleHandle(NULL);
-	#else
-		HINSTANCE hInst = GetModuleHandle("BansheeD3D9RenderAPI.dll");
-	#endif
-
-		RenderAPICore::startUp<D3D9RenderAPI>(hInst);
-	}
-
-	D3D9RenderAPIFactory::InitOnStart D3D9RenderAPIFactory::initOnStart;
-}

+ 0 - 90
Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderTexture.cpp

@@ -1,90 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9RenderTexture.h"
-#include "BsD3D9Texture.h"
-#include "BsD3D9PixelBuffer.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsTextureView.h"
-
-namespace BansheeEngine
-{
-	D3D9RenderTextureCore::D3D9RenderTextureCore(const RENDER_TEXTURE_CORE_DESC& desc)
-		:RenderTextureCore(desc), mProperties(desc, false), mDX9ColorSurface(nullptr),
-		mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
-	{ }
-
-	D3D9RenderTextureCore::~D3D9RenderTextureCore()
-	{ }
-
-	void D3D9RenderTextureCore::initialize()
-	{
-		RenderTextureCore::initialize();
-
-		initializeSurfaces();
-	}
-
-	void D3D9RenderTextureCore::initializeSurfaces()
-	{
-		D3D9TextureCore* d3d9texture = static_cast<D3D9TextureCore*>(mColorSurface->getTexture().get());
-		D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
-			d3d9texture->getBuffer(mColorSurface->getFirstArraySlice(), mColorSurface->getMostDetailedMip()).get());
-		mDX9ColorSurface = pixelBuffer->getSurface(D3D9RenderAPI::getActiveD3D9Device());
-
-		D3D9TextureCore* d3d9DepthStencil = static_cast<D3D9TextureCore*>(mDepthStencilSurface->getTexture().get());
-		D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(
-			d3d9DepthStencil->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()).get());
-		mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderAPI::getActiveD3D9Device());
-	}
-
-	void D3D9RenderTextureCore::releaseSurfaces()
-	{
-		// All actual releasing happens in the color and depth textures.
-		mDX9ColorSurface = nullptr;
-		mDX9DepthStencilSurface = nullptr;
-	}
-
-	void D3D9RenderTextureCore::getCustomAttribute(const String& name, void* data) const
-	{
-		if(name == "DDBACKBUFFER")
-		{
-			IDirect3DSurface9** surf = (IDirect3DSurface9**)data;
-			*surf = mDX9ColorSurface;
-		}
-		else if(name == "D3DZBUFFER")
-		{
-			IDirect3DSurface9** surf = (IDirect3DSurface9**)data;
-			*surf = mDX9DepthStencilSurface;
-		}
-		else if(name == "HWND")
-		{
-			HWND* hWnd = (HWND*)data;
-			*hWnd = nullptr;
-		}
-	}
-
-	void D3D9RenderTextureCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{
-		initializeSurfaces();
-	}
-
-	void D3D9RenderTextureCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		releaseSurfaces();
-	}
-
-	void D3D9RenderTextureCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
-	{
-		releaseSurfaces();
-	}
-
-	void D3D9RenderTextureCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
-	{
-		initializeSurfaces();
-	}
-
-	D3D9RenderTexture::D3D9RenderTexture(const RENDER_TEXTURE_DESC& desc)
-		:RenderTexture(desc), mProperties(desc, false)
-	{
-
-	}
-}

+ 0 - 591
Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderWindow.cpp

@@ -1,591 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9RenderWindow.h"
-#include "BsInput.h"
-#include "BsCoreThread.h"
-#include "BsViewport.h"
-#include "BsException.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsRenderAPI.h"
-#include "Win32/BsWin32Platform.h"
-#include "BsD3D9VideoModeInfo.h"
-#include "BsMath.h"
-#include "BsRenderWindowManager.h"
-#include "Win32/BsWin32Window.h"
-
-namespace BansheeEngine
-{
-	D3D9RenderWindowProperties::D3D9RenderWindowProperties(const RENDER_WINDOW_DESC& desc)
-		:RenderWindowProperties(desc)
-	{
-
-	}
-
-	D3D9RenderWindowCore::D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance)
-		: RenderWindowCore(desc, windowId), mInstance(instance), mProperties(desc), mSyncedProperties(desc), 
-		mIsDepthBuffered(true), mIsChild(false), mWindow(nullptr),mDevice(nullptr), mDisplayFrequency(0), 
-		mDeviceValid(false), mShowOnSwap(false)
-	{ }
-
-	D3D9RenderWindowCore::~D3D9RenderWindowCore()
-	{ 
-		if (mDevice != nullptr)
-		{
-			mDevice->detachRenderWindow(this);
-			mDevice = nullptr;
-		}
-
-		if (mWindow != nullptr)
-		{
-			bs_delete(mWindow);
-			mWindow = nullptr;
-		}
-
-		mProperties.mActive = false;
-	}
-
-	void D3D9RenderWindowCore::initialize()
-	{
-		D3D9RenderWindowProperties& props = mProperties;
-
-		mMultisampleType = D3DMULTISAMPLE_NONE;
-		mMultisampleQuality = 0;
-		mDisplayFrequency = Math::roundToInt(mDesc.videoMode.getRefreshRate());
-
-		WINDOW_DESC windowDesc;
-		windowDesc.border = mDesc.border;
-		windowDesc.enableDoubleClick = mDesc.enableDoubleClick;
-		windowDesc.fullscreen = mDesc.fullscreen;
-		windowDesc.width = mDesc.videoMode.getWidth();
-		windowDesc.height = mDesc.videoMode.getHeight();
-		windowDesc.hidden = mDesc.hidden || mDesc.hideUntilSwap;
-		windowDesc.left = mDesc.left;
-		windowDesc.top = mDesc.top;
-		windowDesc.outerDimensions = mDesc.outerDimensions;
-		windowDesc.title = mDesc.title;
-		windowDesc.toolWindow = mDesc.toolWindow;
-		windowDesc.creationParams = this;
-		windowDesc.module = mInstance;
-		windowDesc.modal = mDesc.modal;
-		windowDesc.wndProc = &Win32Platform::_win32WndProc;
-
-		NameValuePairList::const_iterator opt;
-		opt = mDesc.platformSpecific.find("parentWindowHandle");
-		if (opt != mDesc.platformSpecific.end())
-			windowDesc.parent = (HWND)parseUINT64(opt->second);
-
-		opt = mDesc.platformSpecific.find("externalWindowHandle");
-		if (opt != mDesc.platformSpecific.end())
-			windowDesc.external = (HWND)parseUINT64(opt->second);
-
-		mIsChild = windowDesc.parent != nullptr;
-		props.mIsFullScreen = mDesc.fullscreen && !mIsChild;
-		props.mColorDepth = 32;
-		props.mActive = true;
-
-		const D3D9VideoModeInfo& videoModeInfo = static_cast<const D3D9VideoModeInfo&>(RenderAPICore::instance().getVideoModeInfo());
-		UINT32 numOutputs = videoModeInfo.getNumOutputs();
-		if (numOutputs > 0)
-		{
-			UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
-			const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
-			windowDesc.monitor = outputInfo.getMonitorHandle();
-		}
-
-		if (!windowDesc.external)
-		{
-			mShowOnSwap = mDesc.hideUntilSwap;
-			props.mHidden = mDesc.hideUntilSwap;
-		}
-
-		mWindow = bs_new<Win32Window>(windowDesc);
-
-		props.mWidth = mWindow->getWidth();
-		props.mHeight = mWindow->getHeight();
-		props.mTop = mWindow->getTop();
-		props.mLeft = mWindow->getLeft();
-
-		mIsDepthBuffered = mDesc.depthBuffer;
-
-		D3D9RenderAPI* rs = static_cast<D3D9RenderAPI*>(RenderAPICore::instancePtr());
-		rs->registerWindow(*this);
-
-		{
-			ScopedSpinLock lock(mLock);
-			mSyncedProperties = props;
-		}
-
-		RenderWindowManager::instance().notifySyncDataDirty(this);
-		RenderWindowCore::initialize();
-	}
-
-	void D3D9RenderWindowCore::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if (mIsChild)
-			return;
-
-		const D3D9VideoModeInfo& videoModeInfo = static_cast<const D3D9VideoModeInfo&>(RenderAPICore::instance().getVideoModeInfo());
-		UINT32 numOutputs = videoModeInfo.getNumOutputs();
-		if (numOutputs == 0)
-			return;
-
-		UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
-		const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
-
-		D3D9RenderWindowProperties& props = mProperties;
-
-		props.mWidth = width;
-		props.mHeight = height;
-		mDisplayFrequency = Math::roundToInt(refreshRate);
-
-		props.mIsFullScreen = true;
-
-		HMONITOR hMonitor = outputInfo.getMonitorHandle();
-		MONITORINFO monitorInfo;
-
-		memset(&monitorInfo, 0, sizeof(MONITORINFO));
-		monitorInfo.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hMonitor, &monitorInfo);
-
-		props.mTop = monitorInfo.rcMonitor.top;
-		props.mLeft = monitorInfo.rcMonitor.left;
-
-		// Invalidate device, which resets it
-		mDevice->invalidate(this);
-		mDevice->acquire();
-
-		_windowMovedOrResized();
-	}
-
-	void D3D9RenderWindowCore::setFullscreen(const VideoMode& mode)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		setFullscreen(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getOutputIdx());
-	}
-
-	void D3D9RenderWindowCore::setWindowed(UINT32 width, UINT32 height)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		D3D9RenderWindowProperties& props = mProperties;
-
-		if (!props.mIsFullScreen)
-			return;
-
-		props.mIsFullScreen = false;
-		props.mWidth = width;
-		props.mHeight = height;
-
-		UINT32 winWidth = 0;
-		UINT32 winHeight = 0;
-
-		RECT rect;
-		SetRect(&rect, 0, 0, winWidth, winHeight);
-
-		AdjustWindowRect(&rect, mWindow->getStyle(), false);
-		winWidth = rect.right - rect.left;
-		winHeight = rect.bottom - rect.top;
-
-		// Deal with centering when switching down to smaller resolution
-		HMONITOR hMonitor = MonitorFromWindow(mWindow->getHWnd(), MONITOR_DEFAULTTONEAREST);
-		MONITORINFO monitorInfo;
-		memset(&monitorInfo, 0, sizeof(MONITORINFO));
-		monitorInfo.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hMonitor, &monitorInfo);
-
-		LONG screenw = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
-		LONG screenh = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
-
-		int left = screenw > int(winWidth) ? ((screenw - int(winWidth)) / 2) : 0;
-		int top = screenh > int(winHeight) ? ((screenh - int(winHeight)) / 2) : 0;
-
-		SetWindowLong(mWindow->getHWnd(), GWL_STYLE, mWindow->getStyle());
-		SetWindowLong(mWindow->getHWnd(), GWL_EXSTYLE, mWindow->getStyleEx());
-		SetWindowPos(mWindow->getHWnd(), HWND_NOTOPMOST, left, top, winWidth, winHeight,
-			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
-
-		mDevice->invalidate(this);
-		mDevice->acquire();
-
-		_windowMovedOrResized();
-	}
-
-	void D3D9RenderWindowCore::setActive(bool state)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mWindow->setActive(state);
-
-		RenderWindowCore::setActive(state);
-	}
-
-	void D3D9RenderWindowCore::setHidden(bool hidden)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mShowOnSwap = false;
-		mWindow->setHidden(hidden);
-
-		RenderWindowCore::setHidden(hidden);
-	}
-
-	void D3D9RenderWindowCore::minimize()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mWindow->minimize();
-	}
-
-	void D3D9RenderWindowCore::maximize()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mWindow->maximize();
-	}
-
-	void D3D9RenderWindowCore::restore()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mWindow->restore();
-	}
-
-	void D3D9RenderWindowCore::move(INT32 left, INT32 top)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		D3D9RenderWindowProperties& props = mProperties;
-
-		if (!props.mIsFullScreen)
-		{
-			mWindow->move(left, top);
-
-			props.mTop = mWindow->getTop();
-			props.mLeft = mWindow->getLeft();
-
-			{
-				ScopedSpinLock lock(mLock);
-				mSyncedProperties.mLeft = props.mLeft;
-				mSyncedProperties.mTop = props.mTop;
-			}
-
-			RenderWindowManager::instance().notifySyncDataDirty(this);
-		}
-	}
-
-	void D3D9RenderWindowCore::resize(UINT32 width, UINT32 height)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		D3D9RenderWindowProperties& props = mProperties;
-
-		if (!props.mIsFullScreen)
-		{
-			mWindow->resize(width, height);
-
-			props.mWidth = mWindow->getWidth();
-			props.mHeight = mWindow->getHeight();
-
-			{
-				ScopedSpinLock lock(mLock);
-				mSyncedProperties.mWidth = props.mWidth;
-				mSyncedProperties.mHeight = props.mHeight;
-			}
-
-			RenderWindowManager::instance().notifySyncDataDirty(this);
-		}
-	}
-
-	void D3D9RenderWindowCore::getCustomAttribute(const String& name, void* pData) const
-	{
-		// Valid attributes and their equivalent native functions:
-		// D3DDEVICE			: getD3DDevice
-		// WINDOW				: getWindowHandle
-
-		if( name == "D3DDEVICE" )
-		{
-			IDirect3DDevice9* *pDev = (IDirect3DDevice9**)pData;
-			*pDev = _getD3D9Device();
-			return;
-		}		
-		else if( name == "WINDOW" )
-		{
-			UINT64 *pHwnd = (UINT64*)pData;
-			*pHwnd = (UINT64)_getWindowHandle();
-			return;
-		}
-		else if( name == "isTexture" )
-		{
-			bool *b = reinterpret_cast< bool * >( pData );
-			*b = false;
-
-			return;
-		}
-		else if( name == "D3DZBUFFER" )
-		{
-			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
-			*pSurf = mDevice->getDepthBuffer(this);
-			return;
-		}
-		else if( name == "DDBACKBUFFER" )
-		{
-			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
-			*pSurf = mDevice->getBackBuffer(this);
-			return;
-		}
-		else if( name == "DDFRONTBUFFER" )
-		{
-			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
-			*pSurf = mDevice->getBackBuffer(this);
-			return;
-		}
-	}
-
-	void D3D9RenderWindowCore::swapBuffers()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if (mShowOnSwap)
-			setHidden(false);
-
-		if (mDeviceValid)
-			mDevice->present(this);		
-	}
-
-	void D3D9RenderWindowCore::copyToMemory(PixelData &dst, FrameBuffer buffer)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		mDevice->copyContentsToMemory(this, dst, buffer);
-	}
-
-	void D3D9RenderWindowCore::_windowMovedOrResized()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if (!mWindow)
-			return;
-
-		mWindow->_windowMovedOrResized();
-
-		D3D9RenderWindowProperties& props = mProperties;
-		if (!props.isFullScreen()) // Fullscreen is handled directly by this object
-		{
-			props.mTop = mWindow->getTop();
-			props.mLeft = mWindow->getLeft();
-			props.mWidth = mWindow->getWidth();
-			props.mHeight = mWindow->getHeight();
-		}
-
-		RenderWindowCore::_windowMovedOrResized();
-	}
-
-	/************************************************************************/
-	/* 						D3D9 IMPLEMENTATION SPECIFIC                    */
-	/************************************************************************/
-	
-	void D3D9RenderWindowCore::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
-	{	
-		const D3D9RenderWindowProperties& props = mProperties;
-		IDirect3D9* pD3D = D3D9RenderAPI::getDirect3D9();
-		D3DDEVTYPE devType = D3DDEVTYPE_HAL;
-
-		if (mDevice != NULL)		
-			devType = mDevice->getDeviceType();		
-	
-		ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );
-		presentParams->Windowed = !props.mIsFullScreen;
-		presentParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
-		presentParams->BackBufferCount = 1;
-		presentParams->EnableAutoDepthStencil = mIsDepthBuffered;
-		presentParams->hDeviceWindow = mWindow->getHWnd();
-		presentParams->BackBufferWidth = props.mWidth;
-		presentParams->BackBufferHeight = props.mHeight;
-		presentParams->FullScreen_RefreshRateInHz = props.mIsFullScreen ? mDisplayFrequency : 0;
-		
-		if (presentParams->BackBufferWidth == 0)		
-			presentParams->BackBufferWidth = 1;					
-
-		if (presentParams->BackBufferHeight == 0)	
-			presentParams->BackBufferHeight = 1;					
-
-		if (props.getVSync())
-		{
-			if (props.isFullScreen())
-			{
-				switch(mVSyncInterval)
-				{
-				case 1:
-				default:
-					presentParams->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
-					break;
-				case 2:
-					presentParams->PresentationInterval = D3DPRESENT_INTERVAL_TWO;
-					break;
-				case 3:
-					presentParams->PresentationInterval = D3DPRESENT_INTERVAL_THREE;
-					break;
-				case 4:
-					presentParams->PresentationInterval = D3DPRESENT_INTERVAL_FOUR;
-					break;
-				};
-
-				D3DCAPS9 caps;
-				pD3D->GetDeviceCaps(mDevice->getAdapterNumber(), devType, &caps);
-				if (!(caps.PresentationIntervals & presentParams->PresentationInterval))
-				{
-					presentParams->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
-				}
-
-			}
-			else
-			{
-				presentParams->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
-			}
-		}
-		else
-		{
-			presentParams->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
-		}
-
-		presentParams->BackBufferFormat = D3DFMT_X8R8G8B8;
-
-		if (FAILED(pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
-			devType, presentParams->BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
-			D3DRTYPE_SURFACE, D3DFMT_D24S8)))
-		{
-			if (FAILED(pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
-				devType, presentParams->BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
-				D3DRTYPE_SURFACE, D3DFMT_D32)))
-			{
-				presentParams->AutoDepthStencilFormat = D3DFMT_D16;
-			}
-			else
-			{
-				presentParams->AutoDepthStencilFormat = D3DFMT_D32;
-			}
-		}
-		else
-		{
-			if (SUCCEEDED(pD3D->CheckDepthStencilMatch(mDevice->getAdapterNumber(), devType,
-				presentParams->BackBufferFormat, presentParams->BackBufferFormat, D3DFMT_D24S8)))
-			{
-				presentParams->AutoDepthStencilFormat = D3DFMT_D24S8;
-			}
-			else
-			{
-				presentParams->AutoDepthStencilFormat = D3DFMT_D24X8;
-			}
-		}
-
-		D3D9RenderAPI* rs = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-
-		D3DMULTISAMPLE_TYPE multisampleType;
-		DWORD multisampleQuality;
-
-		rs->determineMultisampleSettings(mDevice->getD3D9Device(), props.getMultisampleCount(),
-			presentParams->BackBufferFormat, props.isFullScreen(), &multisampleType, &multisampleQuality);
-
-		presentParams->MultiSampleType = multisampleType;
-		presentParams->MultiSampleQuality = (multisampleQuality == 0) ? 0 : multisampleQuality;
-	}
-
-	HWND D3D9RenderWindowCore::_getWindowHandle() const
-	{
-		return mWindow->getHWnd();
-	}
-
-	IDirect3DDevice9* D3D9RenderWindowCore::_getD3D9Device() const
-	{
-		return mDevice->getD3D9Device();
-	}
-
-	IDirect3DSurface9* D3D9RenderWindowCore::_getRenderSurface() const
-	{
-		return mDevice->getBackBuffer(this);
-	}
-
-	D3D9Device* D3D9RenderWindowCore::_getDevice() const
-	{
-		return mDevice;
-	}
-
-	void D3D9RenderWindowCore::_setDevice(D3D9Device* device)
-	{
-		mDevice = device;
-		mDeviceValid = false;
-	}
-
-	bool D3D9RenderWindowCore::_isDepthBuffered() const
-	{
-		return mIsDepthBuffered;
-	}
-
-	bool D3D9RenderWindowCore::_validateDevice()
-	{
-		mDeviceValid = mDevice->validate(this);
-		return mDeviceValid;
-	}
-
-	void D3D9RenderWindowCore::syncProperties()
-	{
-		ScopedSpinLock lock(mLock);
-		mProperties = mSyncedProperties;
-	}
-
-	D3D9RenderWindow::D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance)
-		:RenderWindow(desc, windowId), mInstance(instance), mProperties(desc)
-	{
-
-	}
-
-	void D3D9RenderWindow::getCustomAttribute(const String& name, void* pData) const
-	{
-		if (name == "WINDOW")
-		{
-			UINT64 *pHwnd = (UINT64*)pData;
-			*pHwnd = (UINT64)getHWnd();
-			return;
-		}
-	}
-
-	Vector2I D3D9RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
-	{
-		POINT pos;
-		pos.x = screenPos.x;
-		pos.y = screenPos.y;
-
-		ScreenToClient(getHWnd(), &pos);
-		return Vector2I(pos.x, pos.y);
-	}
-
-	Vector2I D3D9RenderWindow::windowToScreenPos(const Vector2I& windowPos) const
-	{
-		POINT pos;
-		pos.x = windowPos.x;
-		pos.y = windowPos.y;
-
-		ClientToScreen(getHWnd(), &pos);
-		return Vector2I(pos.x, pos.y);
-	}
-
-	HWND D3D9RenderWindow::getHWnd() const
-	{
-		blockUntilCoreInitialized();
-		return getCore()->_getWindowHandle();
-	}
-
-	SPtr<D3D9RenderWindowCore> D3D9RenderWindow::getCore() const
-	{
-		return std::static_pointer_cast<D3D9RenderWindowCore>(mCoreSpecific);
-	}
-
-	void D3D9RenderWindow::syncProperties()
-	{
-		ScopedSpinLock lock(getCore()->mLock);
-		mProperties = getCore()->mSyncedProperties;
-	}
-}

+ 0 - 47
Source/BansheeD3D9RenderAPI/Source/BsD3D9RenderWindowManager.cpp

@@ -1,47 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9RenderWindowManager.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9RenderWindow.h"
-#include "BsAsyncOp.h"
-
-namespace BansheeEngine
-{
-	D3D9RenderWindowManager::D3D9RenderWindowManager(D3D9RenderAPI* renderSystem)
-		:mRenderSystem(renderSystem)
-	{
-		assert(mRenderSystem != nullptr);
-	}
-
-	SPtr<RenderWindow> D3D9RenderWindowManager::createImpl(RENDER_WINDOW_DESC& desc, UINT32 windowId, const SPtr<RenderWindow>& parentWindow)
-	{
-		if(parentWindow != nullptr)
-		{
-			UINT64 hWnd;
-			parentWindow->getCustomAttribute("WINDOW", &hWnd);
-			desc.platformSpecific["parentWindowHandle"] = toString(hWnd);
-		}
-
-		D3D9RenderWindow* window = new (bs_alloc<D3D9RenderWindow>()) D3D9RenderWindow(desc, windowId, mRenderSystem->getInstanceHandle());
-
-		return SPtr<RenderWindow>(window, &CoreObject::_delete<D3D9RenderWindow, GenAlloc>);
-	}
-
-	D3D9RenderWindowCoreManager::D3D9RenderWindowCoreManager(D3D9RenderAPI* renderSystem)
-		:mRenderSystem(renderSystem)
-	{
-		assert(mRenderSystem != nullptr);
-	}
-
-	SPtr<RenderWindowCore> D3D9RenderWindowCoreManager::createInternal(RENDER_WINDOW_DESC& desc, UINT32 windowId)
-	{
-		D3D9RenderWindowCore* window = new (bs_alloc<D3D9RenderWindowCore>()) D3D9RenderWindowCore(desc, windowId, mRenderSystem->getInstanceHandle());
-
-		SPtr<D3D9RenderWindowCore> renderWindowPtr = bs_shared_ptr<D3D9RenderWindowCore>(window);
-		renderWindowPtr->_setThisPtr(renderWindowPtr);
-
-		windowCreated(window);
-
-		return renderWindowPtr;
-	}
-}

+ 0 - 30
Source/BansheeD3D9RenderAPI/Source/BsD3D9Resource.cpp

@@ -1,30 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9Resource.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsD3D9RenderAPI.h"
-
-namespace BansheeEngine
-{
-	Mutex D3D9Resource::msDeviceAccessMutex;
-
-	D3D9Resource::D3D9Resource()
-	{				
-		D3D9RenderAPI::getResourceManager()->_notifyResourceCreated(static_cast<D3D9Resource*>(this));		
-	}
-
-	D3D9Resource::~D3D9Resource()
-	{		
-		D3D9RenderAPI::getResourceManager()->_notifyResourceDestroyed(static_cast<D3D9Resource*>(this));	
-	}
-	
-	void D3D9Resource::lockDeviceAccess()
-	{		
-		D3D9_DEVICE_ACCESS_LOCK;								
-	}
-	
-	void D3D9Resource::unlockDeviceAccess()
-	{		
-		D3D9_DEVICE_ACCESS_UNLOCK;				
-	}
-}

+ 0 - 105
Source/BansheeD3D9RenderAPI/Source/BsD3D9ResourceManager.cpp

@@ -1,105 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9Resource.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsD3D9PixelBuffer.h"
-
-namespace BansheeEngine
-{
-	D3D9ResourceManager::D3D9ResourceManager()
-	{
-		mResourceCreationPolicy = RCP_CREATE_ON_ALL_DEVICES;
-		mDeviceAccessLockCount = 0;
-	}
-
-	D3D9ResourceManager::~D3D9ResourceManager()
-	{
-	
-	}
- 
-	void D3D9ResourceManager::setCreationPolicy(D3D9ResourceCreationPolicy creationPolicy)
-	{
-		mResourceCreationPolicy = creationPolicy;
-	}
-
-	D3D9ResourceCreationPolicy D3D9ResourceManager::getCreationPolicy() const
-	{
-		return mResourceCreationPolicy;
-	}
-
-	void D3D9ResourceManager::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{				
-		Lock lock(mResourcesMutex);
-
-		for (auto& resource : mResources)
-			resource->notifyOnDeviceCreate(d3d9Device);			
-	}
-
-	void D3D9ResourceManager::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		Lock lock(mResourcesMutex);
-
-		for (auto& resource : mResources)
-			resource->notifyOnDeviceDestroy(d3d9Device);
-	}
-
-	void D3D9ResourceManager::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
-	{
-		Lock lock(mResourcesMutex);
-
-		for (auto& resource : mResources)
-			resource->notifyOnDeviceLost(d3d9Device);
-	}
-
-	void D3D9ResourceManager::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
-	{		
-		Lock lock(mResourcesMutex);
-
-		for (auto& resource : mResources)
-			resource->notifyOnDeviceReset(d3d9Device);	
-	}
-
-	void D3D9ResourceManager::_notifyResourceCreated(D3D9Resource* pResource)
-	{		
-		Lock lock(mResourcesMutex);
-		mResources.push_back(pResource);
-	}
-	
-	void D3D9ResourceManager::_notifyResourceDestroyed(D3D9Resource* pResource)
-	{		
-		Lock lock(mResourcesMutex);
-
-		auto iter = mResources.begin();
-		while (iter != mResources.end())
-		{
-			if ((*iter) == pResource)
-			{
-				mResources.erase(iter);
-				break;
-			}			
-			++iter;
-		}	
-	}
-	
-	void D3D9ResourceManager::lockDeviceAccess()
-	{	
-		assert(mDeviceAccessLockCount >= 0);
-		mDeviceAccessLockCount++;
-		if (mDeviceAccessLockCount == 1)
-		{						
-			D3D9Resource::lockDeviceAccess();
-			D3D9PixelBuffer::lockDeviceAccess();
-		}
-	}
-
-	void D3D9ResourceManager::unlockDeviceAccess()
-	{
-		assert(mDeviceAccessLockCount > 0);		
-		mDeviceAccessLockCount--;				
-		if (mDeviceAccessLockCount == 0)
-		{						
-			D3D9PixelBuffer::unlockDeviceAccess();
-			D3D9Resource::unlockDeviceAccess();				
-		}
-	}
-}

+ 0 - 1145
Source/BansheeD3D9RenderAPI/Source/BsD3D9Texture.cpp

@@ -1,1145 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsCoreThread.h"
-#include "BsD3D9Texture.h"
-#include "BsD3D9PixelBuffer.h"
-#include "BsException.h"
-#include "BsBitwise.h"
-#include "BsD3D9Mappings.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9TextureManager.h"
-#include "BsD3D9Device.h"
-#include "BsD3D9DeviceManager.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsRenderStats.h"
-#include "BsPixelData.h"
-
-namespace BansheeEngine 
-{
-	D3D9TextureCore::D3D9TextureCore(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
-		PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount, UINT32 numArraySlices, const SPtr<PixelData>& initialData)
-		:TextureCore(textureType, width, height, depth, numMipmaps, format, usage, hwGamma, multisampleCount, numArraySlices, initialData),
-		mD3DPool(D3DPOOL_MANAGED), mDynamicTextures(false), mHwGammaReadSupported(false), mHwGammaWriteSupported(false), 
-		mMultisampleType(D3DMULTISAMPLE_NONE), mMultisampleQuality(0), mIsBindableAsShaderResource(true)
-	{
-
-	}
-	
-	D3D9TextureCore::~D3D9TextureCore()
-	{	
-		THROW_IF_NOT_CORE_THREAD;
-
-		for (auto& resPair : mMapDeviceToTextureResources)
-		{
-			TextureResources* textureResource = resPair.second;
-
-			freeTextureResources(resPair.first, textureResource);
-		}
-
-		for (auto& resPair : mMapDeviceToTextureResources)
-		{
-			TextureResources* textureResource = resPair.second;
-
-			if (textureResource != nullptr)
-				bs_delete(textureResource);
-		}
-
-		mMapDeviceToTextureResources.clear();
-		mSurfaceList.clear();
-
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_Texture);
-	}
-
-	void D3D9TextureCore::initialize()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		for (UINT32 i = 0; i < D3D9RenderAPI::getResourceCreationDeviceCount(); ++i)
-		{
-			IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getResourceCreationDevice(i);
-
-			createInternalResources(d3d9Device);
-		}
-
-		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Texture);
-		TextureCore::initialize();
-	}
-
-	PixelData D3D9TextureCore::lockImpl(GpuLockOptions options, UINT32 mipLevel, UINT32 face)
-	{
-		if (mProperties.getMultisampleCount() > 1)
-			BS_EXCEPT(InvalidStateException, "Multisampled textures cannot be accessed from the CPU directly.");
-
-		if(mLockedBuffer != nullptr)
-			BS_EXCEPT(InternalErrorException, "Trying to lock a buffer that's already locked.");
-
-		if (mProperties.getUsage() == TU_DEPTHSTENCIL)
-			BS_EXCEPT(InternalErrorException, "Cannot lock a depth stencil texture.");
-
-		UINT32 mipWidth = std::max(1u, mProperties.getWidth() >> mipLevel);
-		UINT32 mipHeight = std::max(1u, mProperties.getHeight() >> mipLevel);
-		UINT32 mipDepth = std::max(1u, mProperties.getDepth() >> mipLevel);
-
-		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mProperties.getFormat());
-
-		mLockedBuffer = getBuffer(face, mipLevel);
-		lockedArea.setExternalBuffer((UINT8*)mLockedBuffer->lock(options));
-
-		return lockedArea;
-	}
-	
-	void D3D9TextureCore::unlockImpl()
-	{
-		if(mLockedBuffer == nullptr)
-			BS_EXCEPT(InternalErrorException, "Trying to unlock a buffer that's not locked.");
-
-		mLockedBuffer->unlock();
-		mLockedBuffer = nullptr;
-	}
-
-	void D3D9TextureCore::readData(PixelData& dest, UINT32 mipLevel, UINT32 face)
-	{
-		if (mProperties.getMultisampleCount() > 1)
-			BS_EXCEPT(InvalidStateException, "Multisampled textures cannot be accessed from the CPU directly.");
-
-		if (mProperties.getUsage() == TU_DEPTHSTENCIL || mProperties.getUsage() == TU_RENDERTARGET) // Render targets cannot be locked normally
-		{
-			IDirect3DDevice9* device = D3D9RenderAPI::getActiveD3D9Device();
-
-			D3D9PixelBuffer* sourceBuffer = static_cast<D3D9PixelBuffer*>(getBuffer(face, mipLevel).get());
-			
-			UINT32 mipWidth = std::max(1u, mProperties.getWidth() >> mipLevel);
-			UINT32 mipHeight = std::max(1u, mProperties.getHeight() >> mipLevel);
-			D3DFORMAT format = chooseD3DFormat(device);
-
-			// Note: I'm allocating and releasing a texture every time we read.
-			// I might consider adding a flag to keep this texture permanent which would make reading
-			// faster but at the cost of double the memory.
-
-			IDirect3DTexture9* stagingTexture = nullptr; 
-			HRESULT hr = D3DXCreateTexture(device, (UINT)mipWidth, (UINT)mipHeight, 1,
-				0, format, D3DPOOL_SYSTEMMEM, &stagingTexture);
-
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Failed to create a texture: " + msg);
-			}
-
-			IDirect3DSurface9* stagingSurface = nullptr;
-			hr = stagingTexture->GetSurfaceLevel(0, &stagingSurface);
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Failed to retrieve a texture surface: " + msg);
-			}
-
-			hr = device->GetRenderTargetData(sourceBuffer->getSurface(device), stagingSurface);
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Failed to retrieve render target data: " + msg);
-			}
-
-			PixelData myData(mipWidth, mipHeight, 1, mProperties.getFormat());
-
-			D3DLOCKED_RECT lrect;
-			hr = stagingSurface->LockRect(&lrect, nullptr, D3DLOCK_READONLY);
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Failed to lock surface: " + msg);
-			}
-
-			D3D9PixelBuffer::initPixelDataFromD3DLock(myData, lrect);
-
-#if BS_DEBUG_MODE
-			if (dest.getConsecutiveSize() != myData.getConsecutiveSize())
-				BS_EXCEPT(InternalErrorException, "Buffer sizes don't match.");
-#endif
-
-			PixelUtil::bulkPixelConversion(myData, dest);
-
-			hr = stagingSurface->UnlockRect();
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Failed to unlock surface: " + msg);
-			}
-
-			SAFE_RELEASE(stagingSurface);
-			SAFE_RELEASE(stagingTexture);
-		}
-		else
-		{
-			PixelData myData = lock(GBL_READ_ONLY, mipLevel, face);
-
-#if BS_DEBUG_MODE
-			if (dest.getConsecutiveSize() != myData.getConsecutiveSize())
-			{
-				unlock();
-				BS_EXCEPT(InternalErrorException, "Buffer sizes don't match.");
-			}
-#endif
-
-			PixelUtil::bulkPixelConversion(myData, dest);
-
-			unlock();
-		}
-	}
-
-	void D3D9TextureCore::writeData(const PixelData& src, UINT32 mipLevel, UINT32 face, bool discardWholeBuffer)
-	{
-		if (mProperties.getMultisampleCount() > 1)
-			BS_EXCEPT(InvalidStateException, "Multisampled textures cannot be accessed from the CPU directly.");
-
-		if (mProperties.getUsage() == TU_DYNAMIC || mProperties.getUsage() == TU_STATIC)
-		{
-			PixelData myData = lock(discardWholeBuffer ? GBL_WRITE_ONLY_DISCARD : GBL_WRITE_ONLY, mipLevel, face);
-			PixelUtil::bulkPixelConversion(src, myData);
-			unlock();
-		}
-		else
-		{
-			BS_EXCEPT(RenderingAPIException, "Trying to write into a buffer with unsupported usage: " + toString(mProperties.getUsage()));
-		}
-	}
-	
-	void D3D9TextureCore::copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		TextureType texType = mProperties.getTextureType();
-
-		if (texType == TEX_TYPE_1D || texType == TEX_TYPE_3D)
-			BS_EXCEPT(NotImplementedException, "Copy not implemented for 1D and 3D textures yet.");
-
-        HRESULT hr;
-		D3D9TextureCore* other = static_cast<D3D9TextureCore*>(target.get());
-
-		for (auto& resPair : mMapDeviceToTextureResources)
-		{
-			TextureResources* srcTextureResource = resPair.second;
-			TextureResources* dstTextureResource = other->getTextureResources(resPair.first);
-
-			IDirect3DSurface9 *sourceSurface = nullptr;
-			IDirect3DSurface9 *destSurface = nullptr;
-
-			if (texType == TEX_TYPE_2D && srcTextureResource->pNormTex != nullptr && dstTextureResource->pNormTex != nullptr)
-			{			
-				if(FAILED(hr = srcTextureResource->pNormTex->GetSurfaceLevel(srcMipLevel, &sourceSurface)))
-				{
-					String msg = DXGetErrorDescription(hr);
-					BS_EXCEPT(RenderingAPIException, "Cannot retrieve source surface for copy: " + msg);
-				}
-
-				if(FAILED(hr = dstTextureResource->pNormTex->GetSurfaceLevel(destMipLevel, &destSurface)))
-				{
-					String msg = DXGetErrorDescription(hr);
-					BS_EXCEPT(RenderingAPIException, "Cannot retrieve destination surface for copy: " + msg);
-				}
-			}
-			else if (texType == TEX_TYPE_CUBE_MAP && srcTextureResource->pCubeTex != nullptr && dstTextureResource->pCubeTex != nullptr)
-			{				
-				IDirect3DSurface9 *sourceSurface = nullptr;
-				if (FAILED(hr = srcTextureResource->pCubeTex->GetCubeMapSurface((D3DCUBEMAP_FACES)srcFace, srcMipLevel, &sourceSurface)))
-				{
-					String msg = DXGetErrorDescription(hr);
-					BS_EXCEPT(RenderingAPIException, "Cannot retrieve source surface for copy: " + msg);
-				}
-
-				IDirect3DSurface9 *destSurface = nullptr;
-				if (FAILED(hr = dstTextureResource->pCubeTex->GetCubeMapSurface((D3DCUBEMAP_FACES)destFace, destMipLevel, &destSurface)))
-				{
-					String msg = DXGetErrorDescription(hr);
-					BS_EXCEPT(RenderingAPIException, "Cannot retrieve destination surface for copy: " + msg);
-				}
-			}
-
-			if (sourceSurface != nullptr && destSurface != nullptr)
-			{
-				D3DSURFACE_DESC desc;
-
-				sourceSurface->GetDesc(&desc);
-				if (desc.Pool != D3DPOOL_DEFAULT)
-					BS_EXCEPT(InvalidStateException, "Source surface must be in the default pool.");
-
-				destSurface->GetDesc(&desc);
-				if (desc.Pool != D3DPOOL_DEFAULT)
-					BS_EXCEPT(InvalidStateException, "Destination surface must be in the default pool.");
-
-				if (FAILED(hr = resPair.first->StretchRect(sourceSurface, NULL, destSurface, NULL, D3DTEXF_NONE)))
-				{
-					String msg = DXGetErrorDescription(hr);
-					BS_EXCEPT(RenderingAPIException, "StretchRect failed during copy: " + msg);
-				}
-			}
-
-			SAFE_RELEASE(sourceSurface);
-			SAFE_RELEASE(destSurface);
-		}		
-	}
-	
-	D3D9TextureCore::TextureResources* D3D9TextureCore::getTextureResources(IDirect3DDevice9* d3d9Device)
-	{		
-		auto iterFind = mMapDeviceToTextureResources.find(d3d9Device);
-
-		if (iterFind == mMapDeviceToTextureResources.end())		
-			return nullptr;		
-		
-		return iterFind->second;
-	}
-
-	D3D9TextureCore::TextureResources* D3D9TextureCore::allocateTextureResources(IDirect3DDevice9* d3d9Device)
-	{
-		assert(mMapDeviceToTextureResources.find(d3d9Device) == mMapDeviceToTextureResources.end());
-
-		TextureResources* textureResources = bs_new<TextureResources>();
-
-		textureResources->pNormTex = nullptr;
-		textureResources->pCubeTex = nullptr;
-		textureResources->pVolumeTex = nullptr;
-		textureResources->pBaseTex = nullptr;
-		textureResources->pMultisampleSurface = nullptr;
-		textureResources->pDepthStencilSurface = nullptr;
-
-		mMapDeviceToTextureResources[d3d9Device] = textureResources;
-
-		return textureResources;
-	}
-	
-	void D3D9TextureCore::freeTextureResources(IDirect3DDevice9* d3d9Device, D3D9TextureCore::TextureResources* textureResources)
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		// Release surfaces from each mip level.
-		for(unsigned int i = 0; i < mSurfaceList.size(); ++i)
-		{
-			D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[i].get());
-
-			pixelBuffer->releaseSurfaces(d3d9Device);			
-		}
-		
-		// Release the rest of the resources.
-		SAFE_RELEASE(textureResources->pBaseTex);
-		SAFE_RELEASE(textureResources->pNormTex);
-		SAFE_RELEASE(textureResources->pCubeTex);
-		SAFE_RELEASE(textureResources->pVolumeTex);
-		SAFE_RELEASE(textureResources->pMultisampleSurface);
-		SAFE_RELEASE(textureResources->pDepthStencilSurface);
-	}
-	
-	UINT32 D3D9TextureCore::calculateSize() const
-	{
-		UINT32 instanceSize = mProperties.getNumFaces() * 
-			PixelUtil::getMemorySize(mProperties.getWidth(), mProperties.getHeight(), 
-			mProperties.getDepth(), mProperties.getFormat());
-
-		return instanceSize * (UINT32)mMapDeviceToTextureResources.size();
-	}
-	
-	void D3D9TextureCore::determinePool()
-	{
-		if (useDefaultPool())
-			mD3DPool = D3DPOOL_DEFAULT;
-		else
-			mD3DPool = D3DPOOL_MANAGED;
-	}
-	
-	void D3D9TextureCore::createInternalResources(IDirect3DDevice9* d3d9Device)
-	{		
-		switch (mProperties.getTextureType())
-		{
-		case TEX_TYPE_1D:
-		case TEX_TYPE_2D:
-			createNormTex(d3d9Device);
-			break;
-		case TEX_TYPE_CUBE_MAP:
-			createCubeTex(d3d9Device);
-			break;
-		case TEX_TYPE_3D:
-			createVolumeTex(d3d9Device);
-			break;
-		default:
-			BS_EXCEPT(InternalErrorException, "Unknown texture type.");
-		}
-	}
-
-	void D3D9TextureCore::createNormTex(IDirect3DDevice9* d3d9Device)
-	{
-		UINT32 width = mProperties.getWidth();
-		UINT32 height = mProperties.getHeight();
-		int texUsage = mProperties.getUsage();
-		UINT32 origNumMips = mProperties.getNumMipmaps();
-		PixelFormat format = mProperties.getFormat();
-		bool hwGamma = mProperties.isHardwareGammaEnabled();
-		UINT32 sampleCount = mProperties.getMultisampleCount();
-
-		assert(width > 0 || height > 0);
-
-		D3DFORMAT d3dPF = chooseD3DFormat(d3d9Device);
-		if (format != D3D9Mappings::_getPF(d3dPF))
-		{
-			BS_EXCEPT(RenderingAPIException, "Provided pixel format is not supported by the driver: " + toString(format));
-		}
-
-		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
-		UINT numMips = (origNumMips == MIP_UNLIMITED) ? D3DX_DEFAULT : origNumMips + 1;
-
-		DWORD usage = 0;
-		if ((texUsage & TU_RENDERTARGET) != 0)
-			usage = D3DUSAGE_RENDERTARGET;
-		else if ((texUsage & TU_DEPTHSTENCIL) != 0)
-			usage = D3DUSAGE_DEPTHSTENCIL;
-
-		// Check dynamic textures
-		if (texUsage & TU_DYNAMIC)
-		{
-			if (canUseDynamicTextures(d3d9Device, usage, D3DRTYPE_TEXTURE, d3dPF))
-			{
-				usage |= D3DUSAGE_DYNAMIC;
-				mDynamicTextures = true;
-			}
-			else
-			{
-				mDynamicTextures = false;
-			}
-		}
-
-		// Check sRGB support
-		if (hwGamma)
-		{
-			mHwGammaReadSupported = canUseHardwareGammaCorrection(d3d9Device, usage, D3DRTYPE_TEXTURE, d3dPF, false);
-			if (texUsage & TU_RENDERTARGET)
-				mHwGammaWriteSupported = canUseHardwareGammaCorrection(d3d9Device, usage, D3DRTYPE_TEXTURE, d3dPF, true);
-		}
-
-		// Check multisample level
-		if ((texUsage & TU_RENDERTARGET) != 0 || (texUsage & TU_DEPTHSTENCIL) != 0)
-		{
-			D3D9RenderAPI* rsys = static_cast<D3D9RenderAPI*>(BansheeEngine::RenderAPICore::instancePtr());
-			rsys->determineMultisampleSettings(d3d9Device, sampleCount, d3dPF, false, &mMultisampleType, &mMultisampleQuality);
-		}
-		else
-		{
-			mMultisampleType = D3DMULTISAMPLE_NONE;
-			mMultisampleQuality = 0;
-		}
-
-		D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
-
-		// Check if mip maps are supported on hardware
-		if (numMips > 1 && (!(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPMAP) || (texUsage & TU_RENDERTARGET) != 0 || (texUsage & TU_DEPTHSTENCIL) != 0))
-		{
-			BS_EXCEPT(InvalidParametersException, "Invalid number of mipmaps. Maximum allowed is: 0");
-		}
-
-		determinePool();
-		TextureResources* textureResources;			
-	
-		// Get or create new texture resources structure.
-		textureResources = getTextureResources(d3d9Device);
-		if (textureResources != NULL)
-			freeTextureResources(d3d9Device, textureResources);
-		else
-			textureResources = allocateTextureResources(d3d9Device);
-
-		if ((texUsage & TU_RENDERTARGET) != 0 && (mMultisampleType != D3DMULTISAMPLE_NONE))
-		{
-			// Create AA surface
-			HRESULT hr = d3d9Device->CreateRenderTarget(width, height, d3dPF, 
-				mMultisampleType, mMultisampleQuality,
-				FALSE,
-				&textureResources->pMultisampleSurface, NULL);
-
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Unable to create AA render target: " + String(DXGetErrorDescription(hr)));
-
-			D3DSURFACE_DESC desc;
-			hr = textureResources->pMultisampleSurface->GetDesc(&desc);
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't get texture description: " + String(DXGetErrorDescription(hr)));
-			}
-
-			setFinalAttributes(d3d9Device, textureResources, desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));
-
-			mIsBindableAsShaderResource = false; // Cannot bind AA surfaces
-		}
-		else if ((texUsage & TU_DEPTHSTENCIL) != 0 && (mMultisampleType != D3DMULTISAMPLE_NONE))
-		{
-			// Create AA depth stencil surface
-			HRESULT hr = d3d9Device->CreateDepthStencilSurface(width, height, d3dPF, 
-				mMultisampleType, mMultisampleQuality,
-				FALSE, 
-				&textureResources->pDepthStencilSurface, NULL);
-
-			if (FAILED(hr))
-				BS_EXCEPT(RenderingAPIException, "Unable to create AA depth stencil render target: " + String(DXGetErrorDescription(hr)));
-
-			// Update final parameters as they may differ from requested ones
-			D3DSURFACE_DESC desc;
-			hr = textureResources->pDepthStencilSurface->GetDesc(&desc);
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't get texture description: " + String(DXGetErrorDescription(hr)));
-			}
-
-			setFinalAttributes(d3d9Device, textureResources, desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));
-
-			mIsBindableAsShaderResource = false; // Cannot bind AA depth buffer
-		}
-		else
-		{
-			// Create normal texture
-			HRESULT hr = D3DXCreateTexture(d3d9Device, (UINT)width, (UINT)height, numMips,
-				usage, d3dPF, mD3DPool, &textureResources->pNormTex);
-
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Error creating texture: " + String(DXGetErrorDescription(hr)));
-			}
-
-			hr = textureResources->pNormTex->QueryInterface(IID_IDirect3DBaseTexture9, (void **)&textureResources->pBaseTex);
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't get base texture: " + String(DXGetErrorDescription(hr)));
-			}
-
-			// Update final parameters as they may differ from requested ones
-			D3DSURFACE_DESC desc;
-			hr = textureResources->pNormTex->GetLevelDesc(0, &desc);
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(RenderingAPIException, "Can't get texture description: " + String(DXGetErrorDescription(hr)));
-			}
-
-			setFinalAttributes(d3d9Device, textureResources, desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));
-		}
-	}
-	
-	void D3D9TextureCore::createCubeTex(IDirect3DDevice9* d3d9Device)
-	{
-		UINT32 width = mProperties.getWidth();
-		UINT32 height = mProperties.getHeight();
-		int texUsage = mProperties.getUsage();
-		UINT32 origNumMips = mProperties.getNumMipmaps();
-		PixelFormat format = mProperties.getFormat();
-		bool hwGamma = mProperties.isHardwareGammaEnabled();
-
-		assert(width > 0 || height > 0);
-
-		D3DFORMAT d3dPF = chooseD3DFormat(d3d9Device);
-		if (format != D3D9Mappings::_getPF(d3dPF))
-		{
-			BS_EXCEPT(RenderingAPIException, "Provided pixel format is not supported by the driver: " + toString(format));
-		}
-
-		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
-		DWORD usage = (texUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
-		usage |= (texUsage & TU_DEPTHSTENCIL) ? D3DUSAGE_DEPTHSTENCIL : 0;
-
-		UINT numMips = (origNumMips == MIP_UNLIMITED) ? D3DX_DEFAULT : origNumMips + 1;
-
-		// Check dynamic textures
-		if (texUsage & TU_DYNAMIC)
-		{
-			if (canUseDynamicTextures(d3d9Device, usage, D3DRTYPE_CUBETEXTURE, d3dPF))
-			{
-				usage |= D3DUSAGE_DYNAMIC;
-				mDynamicTextures = true;
-			}
-			else
-			{
-				mDynamicTextures = false;
-			}
-		}
-
-		// Check sRGB support
-		if (hwGamma)
-		{
-			mHwGammaReadSupported = canUseHardwareGammaCorrection(d3d9Device, usage, D3DRTYPE_CUBETEXTURE, d3dPF, false);
-			if (texUsage & TU_RENDERTARGET)
-				mHwGammaWriteSupported = canUseHardwareGammaCorrection(d3d9Device, usage, D3DRTYPE_CUBETEXTURE, d3dPF, true);
-		}
-
-		// No multisampling on cube textures
-		mMultisampleType = D3DMULTISAMPLE_NONE;
-		mMultisampleQuality = 0;
-
-		D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		const D3DCAPS9& deviceCaps = device->getD3D9DeviceCaps();			
-		
-		// Check if mip map cube textures are supported
-		if (numMips > 1 && !(deviceCaps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP))
-		{
-			BS_EXCEPT(InvalidParametersException, "Invalid number of mipmaps. Maximum allowed is: 0");
-		}
-
-		determinePool();
-		TextureResources* textureResources;			
-
-		// Get or create new texture resources structure.
-		textureResources = getTextureResources(d3d9Device);
-		if (textureResources != NULL)
-			freeTextureResources(d3d9Device, textureResources);
-		else
-			textureResources = allocateTextureResources(d3d9Device);
-
-		// Create the texture
-		HRESULT hr = D3DXCreateCubeTexture(d3d9Device, (UINT)width, numMips,
-				usage, d3dPF, mD3DPool, &textureResources->pCubeTex);
-
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Error creating texture: " + String(DXGetErrorDescription(hr)));
-		}
-
-		hr = textureResources->pCubeTex->QueryInterface(IID_IDirect3DBaseTexture9, (void **)&textureResources->pBaseTex);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Can't get base texture: " + String(DXGetErrorDescription(hr)));
-		}
-		
-		// Update final parameters as they may differ from requested ones
-		D3DSURFACE_DESC desc;
-		hr = textureResources->pCubeTex->GetLevelDesc(0, &desc);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Can't get texture description: " + String(DXGetErrorDescription(hr)));
-		}
-
-		setFinalAttributes(d3d9Device, textureResources, desc.Width, desc.Height, 1, D3D9Mappings::_getPF(desc.Format));		
-	}
-	
-	void D3D9TextureCore::createVolumeTex(IDirect3DDevice9* d3d9Device)
-	{
-		UINT32 width = mProperties.getWidth();
-		UINT32 height = mProperties.getHeight();
-		UINT32 depth = mProperties.getDepth();
-		int texUsage = mProperties.getUsage();
-		UINT32 origNumMips = mProperties.getNumMipmaps();
-		PixelFormat format = mProperties.getFormat();
-		bool hwGamma = mProperties.isHardwareGammaEnabled();
-
-		assert(width > 0 && height > 0 && depth > 0);
-
-		if (texUsage & TU_RENDERTARGET)
-			BS_EXCEPT(RenderingAPIException, "D3D9 Volume texture can not be created as render target !!");
-
-		if (texUsage & TU_DEPTHSTENCIL)
-			BS_EXCEPT(RenderingAPIException, "D3D9 Volume texture can not be created as a depth stencil target !!");
-
-		D3DFORMAT d3dPF = chooseD3DFormat(d3d9Device);
-		if(format != D3D9Mappings::_getPF(d3dPF))
-		{
-			BS_EXCEPT(RenderingAPIException, "Provided pixel format is not supported by the driver: " + toString(format));
-		}
-
-		// Use D3DX to help us create the texture, this way it can adjust any relevant sizes
-		DWORD usage = (texUsage & TU_RENDERTARGET) ? D3DUSAGE_RENDERTARGET : 0;
-		UINT numMips = (origNumMips == MIP_UNLIMITED) ? D3DX_DEFAULT : origNumMips + 1;
-
-		// Check dynamic textures
-		if (texUsage & TU_DYNAMIC)
-		{
-			if (canUseDynamicTextures(d3d9Device, usage, D3DRTYPE_VOLUMETEXTURE, d3dPF))
-			{
-				usage |= D3DUSAGE_DYNAMIC;
-				mDynamicTextures = true;
-			}
-			else
-			{
-				mDynamicTextures = false;
-			}
-		}
-
-		// Check sRGB support
-		if (hwGamma)
-		{
-			mHwGammaReadSupported = canUseHardwareGammaCorrection(d3d9Device, usage, D3DRTYPE_VOLUMETEXTURE, d3dPF, false);
-			if (texUsage & TU_RENDERTARGET)
-				mHwGammaWriteSupported = canUseHardwareGammaCorrection(d3d9Device, usage, D3DRTYPE_VOLUMETEXTURE, d3dPF, true);
-		}
-
-		D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		const D3DCAPS9& rkCurCaps = device->getD3D9DeviceCaps();			
-
-		// Check if mip map volume textures are supported
-		if (numMips > 1 && !(rkCurCaps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
-		{
-			BS_EXCEPT(InvalidParametersException, "Invalid number of mipmaps. Maximum allowed is: 0");
-		}
-
-		determinePool();
-		TextureResources* textureResources;			
-
-		// Get or create new texture resources structure.
-		textureResources = getTextureResources(d3d9Device);
-		if (textureResources != NULL)
-			freeTextureResources(d3d9Device, textureResources);
-		else
-			textureResources = allocateTextureResources(d3d9Device);
-
-		// Create the texture
-		HRESULT hr = D3DXCreateVolumeTexture(d3d9Device, (UINT)width, (UINT)height, (UINT)depth,
-				numMips, usage, d3dPF, mD3DPool, &textureResources->pVolumeTex);
-
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Error creating texture: " + String(DXGetErrorDescription(hr)));
-		}
-
-		hr = textureResources->pVolumeTex->QueryInterface(IID_IDirect3DBaseTexture9, (void**)&textureResources->pBaseTex);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Can't get base texture: " + String(DXGetErrorDescription(hr)));
-		}
-		
-		// Update final parameters as they may differ from requested ones
-		D3DVOLUME_DESC desc;
-		hr = textureResources->pVolumeTex->GetLevelDesc(0, &desc);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(RenderingAPIException, "Can't get texture description: " + String(DXGetErrorDescription(hr)));
-		}
-
-		setFinalAttributes(d3d9Device, textureResources, desc.Width, desc.Height, desc.Depth, D3D9Mappings::_getPF(desc.Format));
-	}
-
-	void D3D9TextureCore::setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources,
-		UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
-	{ 
-		if(width != mProperties.getWidth() || height != mProperties.getHeight() || depth != mProperties.getDepth())
-		{
-			BS_EXCEPT(InternalErrorException, "Wanted and created textures sizes don't match!" \
-				"Width: " + toString(width) + "/" + toString(mProperties.getWidth()) +
-				"Height: " + toString(height) + "/" + toString(mProperties.getHeight()) +
-				"Depth: " + toString(depth) + "/" + toString(mProperties.getDepth()));
-		}
-
-		if(format != mProperties.getFormat())
-		{
-			BS_EXCEPT(InternalErrorException, "Wanted and created texture formats don't match! " + 
-				toString(format) + "/" + toString(mProperties.getFormat()));
-		}
-		
-		createSurfaceList(d3d9Device, textureResources);
-	}
-	
-	D3DTEXTUREFILTERTYPE D3D9TextureCore::getBestFilterMethod(IDirect3DDevice9* d3d9Device)
-	{
-		D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		const D3DCAPS9& deviceCaps = device->getD3D9DeviceCaps();			
-		
-		DWORD filterCaps = 0;
-
-		switch (mProperties.getTextureType())
-		{
-		case TEX_TYPE_1D:		
-			// Same as 2D
-		case TEX_TYPE_2D:		
-			filterCaps = deviceCaps.TextureFilterCaps;	
-			break;
-		case TEX_TYPE_3D:		
-			filterCaps = deviceCaps.VolumeTextureFilterCaps;	
-			break;
-		case TEX_TYPE_CUBE_MAP:	
-			filterCaps = deviceCaps.CubeTextureFilterCaps;	
-			break;
-		}
-
-		if(filterCaps & D3DPTFILTERCAPS_MINFGAUSSIANQUAD)
-			return D3DTEXF_GAUSSIANQUAD;
-		
-		if(filterCaps & D3DPTFILTERCAPS_MINFPYRAMIDALQUAD)
-			return D3DTEXF_PYRAMIDALQUAD;
-		
-		if(filterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
-			return D3DTEXF_ANISOTROPIC;
-		
-		if(filterCaps & D3DPTFILTERCAPS_MINFLINEAR)
-			return D3DTEXF_LINEAR;
-		
-		if(filterCaps & D3DPTFILTERCAPS_MINFPOINT)
-			return D3DTEXF_POINT;
-		
-		return D3DTEXF_POINT;
-	}
-	
-	bool D3D9TextureCore::canUseDynamicTextures(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, 
-		D3DFORMAT srcFormat)
-	{		
-		IDirect3D9* pD3D = nullptr;
-
-		HRESULT hr = d3d9Device->GetDirect3D(&pD3D);
-		if (FAILED(hr))
-			BS_EXCEPT(InvalidParametersException, "GetDirect3D failed !!!");
-
-		if (pD3D != nullptr)
-			pD3D->Release();
-	
-		D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		const D3DCAPS9& deviceCaps = device->getD3D9DeviceCaps();						
-		D3DFORMAT backBufferFormat = device->getBackBufferFormat();
-
-		hr = pD3D->CheckDeviceFormat(deviceCaps.AdapterOrdinal, deviceCaps.DeviceType, 
-			backBufferFormat, srcUsage | D3DUSAGE_DYNAMIC, srcType, srcFormat);
-
-		return hr == D3D_OK;
-	}
-	
-	bool D3D9TextureCore::canUseHardwareGammaCorrection(IDirect3DDevice9* d3d9Device, DWORD srcUsage, 
-		D3DRESOURCETYPE srcType, D3DFORMAT srcFormat, bool forwriting)
-	{
-		IDirect3D9* pD3D = nullptr;
-
-		HRESULT hr = d3d9Device->GetDirect3D(&pD3D);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(InvalidParametersException, "GetDirect3D failed !!!" );
-		}
-
-		if (pD3D != nullptr)
-			pD3D->Release();
-
-		D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		const D3DCAPS9& deviceCaps = device->getD3D9DeviceCaps();						
-		D3DFORMAT backBufferFormat = device->getBackBufferFormat();
-
-		if (forwriting)
-			srcUsage |= D3DUSAGE_QUERY_SRGBWRITE;
-		else
-			srcUsage |= D3DUSAGE_QUERY_SRGBREAD;
-
-		hr = pD3D->CheckDeviceFormat(deviceCaps.AdapterOrdinal, deviceCaps.DeviceType, 
-			backBufferFormat, srcUsage, srcType, srcFormat);
-
-		return hr == D3D_OK;
-	}
-	
-	bool D3D9TextureCore::canAutoGenMipmaps(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat)
-	{
-		IDirect3D9* pD3D = nullptr;
-
-		HRESULT hr = d3d9Device->GetDirect3D(&pD3D);
-		if (FAILED(hr))
-		{
-			BS_EXCEPT(InvalidParametersException, "GetDirect3D failed.");
-		}
-
-		if (pD3D != nullptr)
-			pD3D->Release();
-
-		D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-		const D3DCAPS9& deviceCaps = device->getD3D9DeviceCaps();						
-		D3DFORMAT backBufferFormat = device->getBackBufferFormat();
-
-		if (deviceCaps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP)
-		{
-			hr = pD3D->CheckDeviceFormat(deviceCaps.AdapterOrdinal, deviceCaps.DeviceType, 
-					backBufferFormat, srcUsage | D3DUSAGE_AUTOGENMIPMAP, srcType, srcFormat);
-			
-			return hr == D3D_OK;
-		}
-		else
-			return false;
-	}
-	
-	D3DFORMAT D3D9TextureCore::chooseD3DFormat(IDirect3DDevice9* d3d9Device)
-	{		
-		// Choose frame buffer pixel format in case PF_UNKNOWN was requested
-		if(mProperties.getFormat() == PF_UNKNOWN)
-		{	
-			D3D9Device* device = D3D9RenderAPI::getDeviceManager()->getDeviceFromD3D9Device(d3d9Device);
-			
-			if((mProperties.getUsage() & TU_DEPTHSTENCIL) != 0)
-				return device->getDepthStencilFormat();
-			else
-				return device->getBackBufferFormat();		
-		}
-
-		// Choose closest supported D3D format as a D3D format
-		return D3D9Mappings::_getPF(D3D9Mappings::_getClosestSupportedPF(mProperties.getFormat()));
-	}
-	
-	void D3D9TextureCore::createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources)
-	{
-		int texUsage = mProperties.getUsage();
-		TextureType texType = mProperties.getTextureType();
-		UINT32 numMips = mProperties.getNumMipmaps();
-
-		assert(textureResources != nullptr);
-
-		// Need to know static / dynamic
-		UINT32 usage;
-		if ((texUsage & TU_DYNAMIC) && mDynamicTextures)
-		{
-			usage = GBU_DYNAMIC;
-		}
-		else
-		{
-			usage = GBU_STATIC;
-		}
-
-		if (texUsage & TU_RENDERTARGET)
-		{
-			usage |= TU_RENDERTARGET;
-		}
-		else if (texUsage & TU_DEPTHSTENCIL)
-		{
-			usage |= TU_RENDERTARGET;
-		}
-		
-		UINT32 surfaceCount = static_cast<UINT32>((mProperties.getNumFaces() * (numMips + 1)));
-		bool updateOldList = mSurfaceList.size() == surfaceCount;
-		if(!updateOldList)
-		{			
-			mSurfaceList.clear();
-			for (UINT32 face = 0; face < mProperties.getNumFaces(); face++)
-			{
-				for (UINT32 mip = 0; mip <= numMips; mip++)
-				{
-					mSurfaceList.push_back(bs_shared_ptr_new<D3D9PixelBuffer>((GpuBufferUsage)usage, this));
-				}
-			}
-		}
-
-		IDirect3DSurface9* surface = nullptr;
-		IDirect3DVolume9* volume = nullptr;
-
-		if ((texUsage & TU_RENDERTARGET) != 0 && (mMultisampleType != D3DMULTISAMPLE_NONE))
-		{
-			assert(textureResources->pMultisampleSurface);
-			assert(texType == TEX_TYPE_2D);
-
-			D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[0].get());
-
-			currPixelBuffer->bind(d3d9Device, textureResources->pMultisampleSurface, textureResources->pBaseTex);
-		}
-		else if ((texUsage & TU_DEPTHSTENCIL) != 0 && (mMultisampleType != D3DMULTISAMPLE_NONE))
-		{
-			assert(textureResources->pDepthStencilSurface);
-			assert(texType == TEX_TYPE_2D);
-
-			D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[0].get());
-
-			currPixelBuffer->bind(d3d9Device, textureResources->pDepthStencilSurface, textureResources->pBaseTex);
-		}
-		else
-		{
-			assert(textureResources->pBaseTex);
-
-			UINT32 numCreatedMips = textureResources->pBaseTex->GetLevelCount() - 1;
-			if (numCreatedMips != numMips)
-			{
-				BS_EXCEPT(InternalErrorException, "Number of created and wanted mip map levels doesn't match: " + 
-					toString(numCreatedMips) + "/" + toString(numMips));
-			}
-
-			switch(texType) 
-			{
-			case TEX_TYPE_2D:
-			case TEX_TYPE_1D:
-				assert(textureResources->pNormTex);
-
-				for (UINT32 mip = 0; mip <= numMips; mip++)
-				{
-					if(textureResources->pNormTex->GetSurfaceLevel(static_cast<UINT>(mip), &surface) != D3D_OK)
-						BS_EXCEPT(RenderingAPIException, "Get surface level failed");
-
-					D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[mip].get());
-
-					currPixelBuffer->bind(d3d9Device, surface, textureResources->pBaseTex);
-
-					surface->Release();			
-				}
-
-				break;
-			case TEX_TYPE_CUBE_MAP:
-				assert(textureResources->pCubeTex);
-
-				for(UINT32 face = 0; face < 6; face++)
-				{
-					for (UINT32 mip = 0; mip <= numMips; mip++)
-					{
-						if(textureResources->pCubeTex->GetCubeMapSurface((D3DCUBEMAP_FACES)face, static_cast<UINT>(mip), &surface) != D3D_OK)
-							BS_EXCEPT(RenderingAPIException, "Get cubemap surface failed");
-
-						UINT32 idx = face*(numMips + 1) + mip;
-						D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[idx].get());
-
-						currPixelBuffer->bind(d3d9Device, surface, textureResources->pBaseTex);
-
-						surface->Release();				
-					}				
-				}
-				break;
-			case TEX_TYPE_3D:
-				assert(textureResources->pVolumeTex);
-
-				for (UINT32 mip = 0; mip <= numMips; mip++)
-				{
-					if(textureResources->pVolumeTex->GetVolumeLevel(static_cast<UINT>(mip), &volume) != D3D_OK)
-						BS_EXCEPT(RenderingAPIException, "Get volume level failed");	
-
-					D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[mip].get());
-					currPixelBuffer->bind(d3d9Device, volume, textureResources->pBaseTex);
-
-					volume->Release();
-				}
-				break;
-			};		
-		}		
-	}
-
-	SPtr<PixelBuffer> D3D9TextureCore::getBuffer(UINT32 face, UINT32 mipmap) 
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		if(face >= mProperties.getNumFaces())
-			BS_EXCEPT(InvalidParametersException, "A three dimensional cube has six faces");
-		if (mipmap > mProperties.getNumMipmaps())
-			BS_EXCEPT(InvalidParametersException, "Mipmap index out of range");
-
-		UINT32 idx = face*(mProperties.getNumMipmaps() + 1) + mipmap;
-
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-		TextureResources* textureResources = getTextureResources(d3d9Device);
-		if (textureResources == nullptr || textureResources->pBaseTex == nullptr)
-		{				
-			createInternalResources(d3d9Device);
-			textureResources = getTextureResources(d3d9Device);			
-		}
-	
-		assert(textureResources != nullptr);
-		assert(idx < mSurfaceList.size());
-		return mSurfaceList[idx];
-	}
-
-	bool D3D9TextureCore::useDefaultPool()
-	{
-		int usage = mProperties.getUsage();
-		return (usage & TU_RENDERTARGET) || (usage & TU_DEPTHSTENCIL) || ((usage & TU_DYNAMIC) && mDynamicTextures);
-	}
-	
-	void D3D9TextureCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) 
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (D3D9RenderAPI::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-			createInternalResources(d3d9Device);
-	}
-
-	void D3D9TextureCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) 
-	{				
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		auto iterFind = mMapDeviceToTextureResources.find(d3d9Device);
-
-		if (iterFind != mMapDeviceToTextureResources.end())
-		{			
-			TextureResources* textureResource = iterFind->second;
-
-			for(unsigned int i = 0; i < mSurfaceList.size(); ++i)
-			{
-				D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[i].get());
-
-				pixelBuffer->destroyBufferResources(d3d9Device);			
-			}
-
-			freeTextureResources(d3d9Device, textureResource);
-
-			if(textureResource != nullptr)
-				bs_delete(textureResource);
-
-			mMapDeviceToTextureResources.erase(iterFind);
-		}	
-	}
-
-	void D3D9TextureCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) 
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if(mD3DPool == D3DPOOL_DEFAULT)
-		{
-			auto iterFind = mMapDeviceToTextureResources.find(d3d9Device);
-
-			if (iterFind != mMapDeviceToTextureResources.end())
-			{
-				TextureResources* textureResource = iterFind->second;				
-				freeTextureResources(d3d9Device, textureResource);
-			}					
-		}		
-	}
-
-	void D3D9TextureCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) 
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if(mD3DPool == D3DPOOL_DEFAULT)
-		{			
-			createInternalResources(d3d9Device);
-		}
-	}
-
-	IDirect3DBaseTexture9* D3D9TextureCore::getTexture_internal()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		TextureResources* textureResources;			
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-			
-		textureResources = getTextureResources(d3d9Device);		
-		if (textureResources == nullptr || textureResources->pBaseTex == nullptr)
-		{			
-			createInternalResources(d3d9Device);
-			textureResources = getTextureResources(d3d9Device);			
-		}
-
-		assert(textureResources); 
-		assert(textureResources->pBaseTex); 
-
-		return textureResources->pBaseTex;
-	}
-
-	IDirect3DTexture9* D3D9TextureCore::getNormTexture_internal()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		TextureResources* textureResources;
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-		
-		textureResources = getTextureResources(d3d9Device);		
-		if (textureResources == nullptr || textureResources->pNormTex == nullptr)
-		{
-			createInternalResources(d3d9Device);
-			textureResources = getTextureResources(d3d9Device);			
-		}
-		assert(textureResources); 
-		assert(textureResources->pNormTex); 
-
-		return textureResources->pNormTex;
-	}
-
-	IDirect3DCubeTexture9* D3D9TextureCore::getCubeTexture_internal()
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		TextureResources* textureResources;
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-		
-		textureResources = getTextureResources(d3d9Device);		
-		if (textureResources == nullptr || textureResources->pCubeTex)
-		{
-			createInternalResources(d3d9Device);
-			textureResources = getTextureResources(d3d9Device);			
-		}
-
-		assert(textureResources); 
-		assert(textureResources->pCubeTex); 
-
-		return textureResources->pCubeTex;
-	}	
-}

+ 0 - 79
Source/BansheeD3D9RenderAPI/Source/BsD3D9TextureManager.cpp

@@ -1,79 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9TextureManager.h"
-#include "BsD3D9Texture.h"
-#include "BsD3D9RenderTexture.h"
-#include "BsException.h"
-#include "BsD3D9Mappings.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9MultiRenderTexture.h"
-
-namespace BansheeEngine 
-{
-	D3D9TextureManager::D3D9TextureManager()
-		:TextureManager()
-	{ }
-	
-	D3D9TextureManager::~D3D9TextureManager()
-	{ }
-
-	SPtr<RenderTexture> D3D9TextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc)
-	{
-		D3D9RenderTexture* tex = new (bs_alloc<D3D9RenderTexture>()) D3D9RenderTexture(desc);
-
-		return bs_core_ptr<D3D9RenderTexture>(tex);
-	}
-
-	SPtr<MultiRenderTexture> D3D9TextureManager::createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc)
-	{
-		D3D9MultiRenderTexture* tex = new (bs_alloc<D3D9MultiRenderTexture>()) D3D9MultiRenderTexture(desc);
-
-		return bs_core_ptr<D3D9MultiRenderTexture>(tex);
-	}
-
-	PixelFormat D3D9TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
-	{
-		if((usage & TU_RENDERTARGET) != 0)
-		{
-			return D3D9Mappings::_getClosestSupportedRenderTargetPF(format);
-		}
-		else if((usage & TU_DEPTHSTENCIL) != 0)
-		{
-			return D3D9Mappings::_getClosestSupportedDepthStencilPF(format);
-		}
-		else
-		{
-			// Basic filtering
-			return D3D9Mappings::_getClosestSupportedPF(format);
-		}
-	}
-
-	SPtr<TextureCore> D3D9TextureCoreManager::createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
-		int numMips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 multisampleCount, UINT32 numArraySlices,
-		const SPtr<PixelData>& initialData)
-	{
-		D3D9TextureCore* tex = new (bs_alloc<D3D9TextureCore>()) D3D9TextureCore(texType,
-			width, height, depth, numMips, format, usage, hwGammaCorrection, multisampleCount, numArraySlices, initialData);
-
-		SPtr<D3D9TextureCore> texPtr = bs_shared_ptr<D3D9TextureCore>(tex);
-		texPtr->_setThisPtr(texPtr);
-
-		return texPtr;
-	}
-
-	SPtr<RenderTextureCore> D3D9TextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_CORE_DESC& desc)
-	{
-		SPtr<D3D9RenderTextureCore> texPtr = bs_shared_ptr_new<D3D9RenderTextureCore>(desc);
-		texPtr->_setThisPtr(texPtr);
-
-		return texPtr;
-	}
-
-	SPtr<MultiRenderTextureCore> D3D9TextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
-	{
-		SPtr<D3D9MultiRenderTextureCore> texPtr = bs_shared_ptr_new<D3D9MultiRenderTextureCore>(desc);
-		texPtr->_setThisPtr(texPtr);
-
-		return texPtr;
-	}
-}

+ 0 - 171
Source/BansheeD3D9RenderAPI/Source/BsD3D9TimerQuery.cpp

@@ -1,171 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9TimerQuery.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsRenderStats.h"
-#include "BsDebug.h"
-
-namespace BansheeEngine
-{
-	D3D9TimerQuery::D3D9TimerQuery()
-		:mFinalized(false), mBeginQuery(nullptr), mFreqQuery(nullptr), mQueryIssued(false),
-		mEndQuery(nullptr), mDisjointQuery(nullptr), mTimeDelta(0.0f), mDevice(nullptr)
-	{
-		createQuery();
-
-		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Query);
-	}
-
-	D3D9TimerQuery::~D3D9TimerQuery()
-	{
-		releaseQuery();
-
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_Query);
-	}
-
-	void D3D9TimerQuery::createQuery()
-	{
-		mDevice = D3D9RenderAPI::getActiveD3D9Device();
-
-		HRESULT hr = mDevice->CreateQuery(D3DQUERYTYPE_TIMESTAMPDISJOINT, &mDisjointQuery);
-		if (hr != S_OK)
-		{
-			BS_EXCEPT(RenderingAPIException, "Failed to create a timer query.");
-		}
-
-		hr = mDevice->CreateQuery(D3DQUERYTYPE_TIMESTAMPFREQ, &mFreqQuery);
-		if (hr != S_OK)
-		{
-			BS_EXCEPT(RenderingAPIException, "Failed to create a timer query.");
-		}
-
-		hr = mDevice->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &mBeginQuery);
-		if (hr != S_OK)
-		{
-			BS_EXCEPT(RenderingAPIException, "Failed to create a timer query.");
-		}
-
-		hr = mDevice->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &mEndQuery);
-		if (hr != S_OK)
-		{
-			BS_EXCEPT(RenderingAPIException, "Failed to create a timer query.");
-		}
-	}
-
-	void D3D9TimerQuery::releaseQuery()
-	{
-		SAFE_RELEASE(mBeginQuery);
-		SAFE_RELEASE(mEndQuery);
-		SAFE_RELEASE(mDisjointQuery);
-		SAFE_RELEASE(mFreqQuery);
-	}
-
-	bool D3D9TimerQuery::isQueryValid() const
-	{
-		return mDisjointQuery != nullptr && mBeginQuery != nullptr && 
-			mEndQuery != nullptr && mFreqQuery != nullptr;
-	}
-
-	void D3D9TimerQuery::begin()
-	{
-		mQueryIssued = false;
-
-		if (isQueryValid())
-		{
-			mDisjointQuery->Issue(D3DISSUE_BEGIN);
-			mFreqQuery->Issue(D3DISSUE_END);
-			mBeginQuery->Issue(D3DISSUE_END);
-		}
-
-		setActive(true);
-	}
-
-	void D3D9TimerQuery::end()
-	{
-		if (isQueryValid())
-		{
-			mEndQuery->Issue(D3DISSUE_END);
-			mDisjointQuery->Issue(D3DISSUE_END);
-		}
-
-		mQueryIssued = true;
-		mFinalized = false;
-	}
-
-	bool D3D9TimerQuery::isReady() const
-	{
-		if (!isQueryValid()) // Possibly device reset, in which case query is considered done if issued
-			return mQueryIssued;
-
-		if (!mQueryIssued)
-			return false;
-
-		BOOL queryData;
-		return mDisjointQuery->GetData(&queryData, sizeof(BOOL), 0) == S_OK;
-	}
-
-	float D3D9TimerQuery::getTimeMs()
-	{
-		if(!mFinalized && isReady())
-		{
-			finalize();
-		}
-
-		return mTimeDelta;
-	}
-
-	void D3D9TimerQuery::finalize()
-	{
-		mFinalized = true;
-
-		if (!isQueryValid())
-		{
-			mTimeDelta = 0.0f;
-			return;
-		}
-
-		BOOL disjoint;
-		mDisjointQuery->GetData(&disjoint, sizeof(BOOL), 0);
-
-		if(!disjoint)
-		{
-			UINT64 frequency;
-			mFreqQuery->GetData(&frequency, sizeof(UINT64), 0);
-
-			UINT64 timeStart, timeEnd;
-			mBeginQuery->GetData(&timeStart, sizeof(UINT64), 0);
-			mEndQuery->GetData(&timeEnd, sizeof(UINT64), 0);
-
-			UINT64 delta = timeEnd - timeStart;
-			mTimeDelta = (delta/(float)frequency) * 1000.0f;
-		}
-		else
-		{
-			LOGWRN_VERBOSE("Unrealiable GPU timer query detected.");
-		}
-	}
-
-	void D3D9TimerQuery::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			createQuery();
-	}
-
-	void D3D9TimerQuery::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			releaseQuery();
-	}
-
-	void D3D9TimerQuery::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			releaseQuery();
-	}
-
-	void D3D9TimerQuery::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
-	{
-		if (d3d9Device == mDevice)
-			createQuery();
-	}
-}

+ 0 - 303
Source/BansheeD3D9RenderAPI/Source/BsD3D9VertexBuffer.cpp

@@ -1,303 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9VertexBuffer.h"
-#include "BsD3D9Mappings.h"
-#include "BsException.h"
-#include "BsD3D9HardwareBufferManager.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9Device.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsRenderStats.h"
-
-namespace BansheeEngine 
-{
-	D3D9VertexBufferCore::D3D9VertexBufferCore(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool streamOut)
-		: VertexBufferCore(vertexSize, numVertices, usage, streamOut), mSystemMemoryBuffer(nullptr)
-    { }
-
-	D3D9VertexBufferCore::~D3D9VertexBufferCore()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
-
-		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
-		{
-			BufferResources* bufferResources = bufferResourcesPair.second;
-
-			SAFE_RELEASE(bufferResources->mBuffer);
-
-			if (bufferResources != nullptr)
-				bs_delete(bufferResources);
-		}
-
-		mMapDeviceToBufferResources.clear();
-
-		if (mSystemMemoryBuffer != nullptr)
-			bs_free(mSystemMemoryBuffer);
-
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexBuffer);
-	}
-
-	void D3D9VertexBufferCore::initialize()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION;
-
-		// Set the desired memory pool
-		mBufferDesc.Pool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
-
-		// Allocate the system memory buffer.
-		mSystemMemoryBuffer = (UINT8*)bs_alloc(getSizeInBytes());
-		memset(mSystemMemoryBuffer, 0, getSizeInBytes());
-
-		// Case we have to create this buffer resource on loading.
-		if (D3D9RenderAPI::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-		{
-			for (UINT32 i = 0; i < D3D9RenderAPI::getResourceCreationDeviceCount(); ++i)
-			{
-				IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getResourceCreationDevice(i);
-
-				createBuffer(d3d9Device, mBufferDesc.Pool);
-			}
-		}
-
-		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexBuffer);
-		VertexBufferCore::initialize();
-	}
-
-	void* D3D9VertexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
-    {		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-#if BS_PROFILING_ENABLED
-		if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
-		{
-			BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_VertexBuffer);
-		}
-
-		if (options == GBL_READ_WRITE || options == GBL_WRITE_ONLY || options == GBL_WRITE_ONLY_DISCARD || options == GBL_WRITE_ONLY_NO_OVERWRITE)
-		{
-			BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_VertexBuffer);
-		}
-#endif
-
-		if (options != GBL_READ_ONLY)
-		{
-			for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
-			{
-				BufferResources* bufferResources = bufferResourcesPair.second;
-				bufferResources->mOutOfDate = true;
-
-				if(bufferResources->mLockLength > 0)
-				{
-					UINT32 highPoint = std::max( offset + length, 
-						bufferResources->mLockOffset + bufferResources->mLockLength );
-					bufferResources->mLockOffset = std::min( bufferResources->mLockOffset, offset );
-					bufferResources->mLockLength = highPoint - bufferResources->mLockOffset;
-				}
-				else
-				{
-					if (offset < bufferResources->mLockOffset)
-						bufferResources->mLockOffset = offset;
-					if (length > bufferResources->mLockLength)
-						bufferResources->mLockLength = length;
-				}
-				
-				if (bufferResources->mLockOptions != GBL_WRITE_ONLY_DISCARD)
-					bufferResources->mLockOptions = options;					
-			}
-		}
-
-		return mSystemMemoryBuffer + offset;		
-    }
-
-	void D3D9VertexBufferCore::unlockImpl()
-    {
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		for (auto& bufferResourcesPair : mMapDeviceToBufferResources)
-		{
-			BufferResources* bufferResources = bufferResourcesPair.second;
-
-			if (bufferResources->mOutOfDate && bufferResources->mBuffer != nullptr)
-				updateBufferResources(mSystemMemoryBuffer, bufferResources);
-		}
-    }
-
-	void D3D9VertexBufferCore::readData(UINT32 offset, UINT32 length, void* dest)
-    {
-        void* pSrc = this->lock(offset, length, GBL_READ_ONLY);
-        memcpy(dest, pSrc, length);
-        this->unlock();
-    }
-
-	void D3D9VertexBufferCore::writeData(UINT32 offset, UINT32 length, const void* source,
-		BufferWriteType writeFlags)
-	{
-		GpuLockOptions lockOption = GBL_WRITE_ONLY;
-		if(writeFlags == BufferWriteType::Discard)
-			lockOption = GBL_WRITE_ONLY_DISCARD;
-		else if(writeFlags == BufferWriteType::NoOverwrite)
-			lockOption = GBL_WRITE_ONLY_NO_OVERWRITE;
-
-		void* pDst = this->lock(offset, length, lockOption);
-		memcpy(pDst, source, length);
-		this->unlock();
-	}
-
-	void D3D9VertexBufferCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{			
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (D3D9RenderAPI::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-			createBuffer(d3d9Device, mBufferDesc.Pool);
-	}
-
-	void D3D9VertexBufferCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{	
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-
-		if (iterFind != mMapDeviceToBufferResources.end())	
-		{								
-			SAFE_RELEASE(iterFind->second->mBuffer);
-
-			if(iterFind->second != nullptr)
-				bs_delete(iterFind->second);
-
-			mMapDeviceToBufferResources.erase(iterFind);
-		}	
-	}
-
-	void D3D9VertexBufferCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
-	{	
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (mBufferDesc.Pool == D3DPOOL_DEFAULT)
-		{
-			auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-
-			if (iterFind != mMapDeviceToBufferResources.end())
-			{				
-				SAFE_RELEASE(iterFind->second->mBuffer);	
-			}					
-		}
-	}
-
-	void D3D9VertexBufferCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
-	{		
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		if (D3D9RenderAPI::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-			createBuffer(d3d9Device, mBufferDesc.Pool);
-	}
-
-	void D3D9VertexBufferCore::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool)
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		BufferResources* bufferResources;		
-		HRESULT hr;
-
-		// Find the vertex buffer of this device.
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-		if (iterFind != mMapDeviceToBufferResources.end())
-		{
-			bufferResources = iterFind->second;
-			SAFE_RELEASE(bufferResources->mBuffer);
-		}
-		else
-		{
-			bufferResources = bs_new<BufferResources>();			
-			mMapDeviceToBufferResources[d3d9Device] = bufferResources;
-		}
-
-		bufferResources->mBuffer = NULL;
-		bufferResources->mOutOfDate = true;
-		bufferResources->mLockOffset = 0;
-		bufferResources->mLockLength = getSizeInBytes();
-		bufferResources->mLockOptions = GBL_READ_WRITE;
-		
-		// Create the vertex buffer
-		hr = d3d9Device->CreateVertexBuffer(
-			static_cast<UINT>(mSizeInBytes), 
-			D3D9Mappings::get(mUsage), 
-			0,
-			ePool,
-			&bufferResources->mBuffer,
-			NULL);
-
-		if (FAILED(hr))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Cannot restore D3D9 vertex buffer: " + msg);
-		}
-
-		hr = bufferResources->mBuffer->GetDesc(&mBufferDesc);
-		if (FAILED(hr))
-		{
-			String msg = DXGetErrorDescription(hr);
-			BS_EXCEPT(RenderingAPIException, "Cannot get D3D9 Vertex buffer desc: " + msg);
-		}		
-	}
-
-	IDirect3DVertexBuffer9* D3D9VertexBufferCore::getD3D9VertexBuffer()
-	{
-		IDirect3DDevice9* d3d9Device = D3D9RenderAPI::getActiveD3D9Device();
-		auto iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-
-		// Case vertex buffer was not found for the current device -> create it.		
-		if (iterFind == mMapDeviceToBufferResources.end() || iterFind->second->mBuffer == nullptr)
-		{						
-			createBuffer(d3d9Device, mBufferDesc.Pool);
-			iterFind = mMapDeviceToBufferResources.find(d3d9Device);
-		}
-
-		if (iterFind->second->mOutOfDate)
-			updateBufferResources(mSystemMemoryBuffer, iterFind->second);
-		
-		return iterFind->second->mBuffer;
-	}	
-
-	bool D3D9VertexBufferCore::updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources)
-	{		
-		assert(bufferResources != nullptr);
-		assert(bufferResources->mBuffer != nullptr);
-		assert(bufferResources->mOutOfDate);
-				
-		if (bufferResources->mLockLength != 0)
-		{
-			void* dstBytes;
-			HRESULT hr;
-
-			// Lock the buffer.
-			hr = bufferResources->mBuffer->Lock(
-				static_cast<UINT>(bufferResources->mLockOffset),
-				static_cast<UINT>(bufferResources->mLockLength),
-				&dstBytes,
-				D3D9Mappings::get(bufferResources->mLockOptions, mUsage));
-
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Cannot lock D3D9 vertex buffer: " + msg);
-			}
-
-			memcpy(dstBytes, systemMemoryBuffer + bufferResources->mLockOffset, bufferResources->mLockLength);
-
-			// Unlock the buffer.
-			hr = bufferResources->mBuffer->Unlock();
-			if (FAILED(hr))
-			{
-				String msg = DXGetErrorDescription(hr);
-				BS_EXCEPT(RenderingAPIException, "Cannot unlock D3D9 vertex buffer: " + msg);
-			}
-		}
-
-		bufferResources->mOutOfDate = false;
-		bufferResources->mLockOffset = mSizeInBytes;
-		bufferResources->mLockLength = 0;
-		bufferResources->mLockOptions = GBL_READ_WRITE;
-
-		return true;		
-	}
-}

+ 0 - 113
Source/BansheeD3D9RenderAPI/Source/BsD3D9VertexDeclaration.cpp

@@ -1,113 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9VertexDeclaration.h"
-#include "BsD3D9Mappings.h"
-#include "BsException.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsD3D9ResourceManager.h"
-#include "BsRenderStats.h"
-
-namespace BansheeEngine 
-{
-	D3D9VertexDeclarationCore::D3D9VertexDeclarationCore(const List<VertexElement>& elements)
-		:VertexDeclarationCore(elements)
-    { }
-
-	D3D9VertexDeclarationCore::~D3D9VertexDeclarationCore()
-    {    
-		releaseDeclaration();
-
-		BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexDeclaration);
-	}
-
-	void D3D9VertexDeclarationCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
-	{
-		
-	}
-
-	void D3D9VertexDeclarationCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		auto it = mMapDeviceToDeclaration.find(d3d9Device);
-
-		if (it != mMapDeviceToDeclaration.end())	
-		{
-			SAFE_RELEASE(it->second);	
-			mMapDeviceToDeclaration.erase(it);
-		}
-	}
-
-	IDirect3DVertexDeclaration9* D3D9VertexDeclarationCore::getD3DVertexDeclaration()
-    {
-		IDirect3DDevice9* pCurDevice   = D3D9RenderAPI::getActiveD3D9Device();
-		auto it = mMapDeviceToDeclaration.find(pCurDevice);
-		IDirect3DVertexDeclaration9* lpVertDecl = NULL;
-
-		const List<VertexElement>& elementList = getProperties().getElements();
-
-		// Case we have to create the declaration for this device.
-		if (it == mMapDeviceToDeclaration.end() || it->second == NULL)
-		{
-			D3DVERTEXELEMENT9* d3delems = bs_newN<D3DVERTEXELEMENT9>((UINT32)( getProperties().getElements().size() + 1));
-
-			unsigned int idx;
-			auto iend = elementList.end();
-			auto i = elementList.begin();
-			for (idx = 0, i = elementList.begin(); i != iend; ++i, ++idx)
-			{
-				d3delems[idx].Method = D3DDECLMETHOD_DEFAULT;
-				d3delems[idx].Offset = static_cast<WORD>(i->getOffset());
-				d3delems[idx].Stream = i->getStreamIdx();
-				d3delems[idx].Type = D3D9Mappings::get(i->getType());
-				d3delems[idx].Usage = D3D9Mappings::get(i->getSemantic());
-				d3delems[idx].UsageIndex = static_cast<BYTE>(i->getSemanticIdx());
-			}
-
-			// Add terminator
-			d3delems[idx].Stream = 0xff;
-			d3delems[idx].Offset = 0;
-			d3delems[idx].Type = D3DDECLTYPE_UNUSED;
-			d3delems[idx].Method = 0;
-			d3delems[idx].Usage = 0;
-			d3delems[idx].UsageIndex = 0;
-
-			
-			HRESULT hr = pCurDevice->CreateVertexDeclaration(d3delems, &lpVertDecl);
-
-			if (FAILED(hr))
-			{
-				BS_EXCEPT(InternalErrorException, "Cannot create D3D9 vertex declaration: ");
-			}
-
-			bs_deleteN(d3delems, (UINT32)(elementList.size() + 1));
-
-			mMapDeviceToDeclaration[pCurDevice] = lpVertDecl;
-
-			BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexDeclaration);
-		}
-
-		// Declaration already exits.
-		else
-		{
-			lpVertDecl = mMapDeviceToDeclaration[pCurDevice];
-		}
-		
-        return lpVertDecl;
-    }
-
-	void D3D9VertexDeclarationCore::releaseDeclaration()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		auto it = mMapDeviceToDeclaration.begin();
-
-		while (it != mMapDeviceToDeclaration.end())
-		{
-			SAFE_RELEASE(it->second);
-			++it;
-		}	
-		mMapDeviceToDeclaration.clear();
-	}
-}
-

+ 0 - 78
Source/BansheeD3D9RenderAPI/Source/BsD3D9VideoModeInfo.cpp

@@ -1,78 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsD3D9VideoModeInfo.h"
-#include "BsD3D9RenderAPI.h"
-#include "BsMath.h"
-
-namespace BansheeEngine
-{
-	D3D9VideoModeInfo::D3D9VideoModeInfo(IDirect3D9* d3d9device)
-	{
-		for (UINT32 i = 0; i < d3d9device->GetAdapterCount(); i++)
-		{
-			D3DADAPTER_IDENTIFIER9 adapterIdentifier;
-			D3DCAPS9 d3dcaps9;
-
-			d3d9device->GetAdapterIdentifier(i, 0, &adapterIdentifier);
-			d3d9device->GetDeviceCaps(i, D3DDEVTYPE_HAL, &d3dcaps9);
-
-			mOutputs.push_back(bs_new<D3D9VideoOutputInfo>(d3d9device, i));
-		}
-	}
-
-	D3D9VideoOutputInfo::D3D9VideoOutputInfo(IDirect3D9* d3d9device, UINT32 adapterIdx)
-		:mMonitorHandle(0)
-	{
-		IDirect3D9* pD3D = D3D9RenderAPI::getDirect3D9();
-
-		D3DADAPTER_IDENTIFIER9 adapterIdentifier;
-		pD3D->GetAdapterIdentifier(adapterIdx, 0, &adapterIdentifier);
-
-		mName = adapterIdentifier.DeviceName;
-
-		for (UINT32 i = 0; i < pD3D->GetAdapterModeCount(adapterIdx, D3DFMT_X8R8G8B8); i++)
-		{
-			D3DDISPLAYMODE displayMode;
-			pD3D->EnumAdapterModes(adapterIdx, D3DFMT_X8R8G8B8, i, &displayMode);
-
-			bool foundVideoMode = false;
-			for (auto videoMode : mVideoModes)
-			{
-				D3D9VideoMode* d3d9videoMode = static_cast<D3D9VideoMode*>(videoMode);
-
-				UINT32 intRefresh = Math::roundToInt(d3d9videoMode->mRefreshRate);
-				if (d3d9videoMode->mWidth == displayMode.Width && d3d9videoMode->mHeight == displayMode.Height && intRefresh == displayMode.RefreshRate)
-				{
-					foundVideoMode = true;
-					break;
-				}
-			}
-
-			if (!foundVideoMode)
-			{
-				D3D9VideoMode* videoMode = bs_new<D3D9VideoMode>(displayMode.Width, displayMode.Height, (float)displayMode.RefreshRate, adapterIdx);
-
-				mVideoModes.push_back(videoMode);
-			}
-		}
-
-		// Get desktop display mode
-		HMONITOR hMonitor = pD3D->GetAdapterMonitor(adapterIdx);
-		MONITORINFOEX monitorInfo;
-		monitorInfo.cbSize = sizeof(MONITORINFOEX);
-		GetMonitorInfo(hMonitor, &monitorInfo);
-
-		DEVMODE devMode;
-		devMode.dmSize = sizeof(DEVMODE);
-		devMode.dmDriverExtra = 0;
-		EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
-
-		D3D9VideoMode* desktopVideoMode = bs_new<D3D9VideoMode>(devMode.dmPelsWidth, devMode.dmPelsHeight, (float)devMode.dmDisplayFrequency, adapterIdx);
-
-		mDesktopVideoMode = desktopVideoMode;
-	}
-
-	D3D9VideoMode::D3D9VideoMode(UINT32 width, UINT32 height, float refreshRate, UINT32 outputIdx)
-		:VideoMode(width, height, refreshRate, outputIdx)
-	{ }
-}

+ 4 - 10
Source/CMakeLists.txt

@@ -3,7 +3,7 @@ project (Banshee)
 
 
 # Version
 # Version
 set (BS_VERSION_MAJOR 0)
 set (BS_VERSION_MAJOR 0)
-set (BS_VERSION_MINOR 3)
+set (BS_VERSION_MINOR 4)
 
 
 # Configuration types
 # Configuration types
 if(CMAKE_CONFIGURATION_TYPES) # Multiconfig generator?
 if(CMAKE_CONFIGURATION_TYPES) # Multiconfig generator?
@@ -34,7 +34,7 @@ set_property(CACHE INPUT_MODULE PROPERTY STRINGS OIS)
 
 
 if(WIN32)
 if(WIN32)
 set(RENDER_API_MODULE "DirectX 11" CACHE STRING "Render API to use.")
 set(RENDER_API_MODULE "DirectX 11" CACHE STRING "Render API to use.")
-set_property(CACHE RENDER_API_MODULE PROPERTY STRINGS "DirectX 11" "DirectX 9" "OpenGL")
+set_property(CACHE RENDER_API_MODULE PROPERTY STRINGS "DirectX 11" "OpenGL")
 else()
 else()
 set(RENDER_API_MODULE "OpenGL" CACHE STRING "Render API to use.")
 set(RENDER_API_MODULE "OpenGL" CACHE STRING "Render API to use.")
 set_property(CACHE RENDER_API_MODULE PROPERTY STRINGS "OpenGL")
 set_property(CACHE RENDER_API_MODULE PROPERTY STRINGS "OpenGL")
@@ -44,6 +44,7 @@ set(RENDERER_MODULE "RenderBeast" CACHE STRING "Renderer backend to use.")
 set_property(CACHE RENDERER_MODULE PROPERTY STRINGS RenderBeast)
 set_property(CACHE RENDERER_MODULE PROPERTY STRINGS RenderBeast)
 
 
 set(BUILD_EDITOR ON CACHE BOOL "If true both the engine and the editor will be built.")
 set(BUILD_EDITOR ON CACHE BOOL "If true both the engine and the editor will be built.")
+set(INCLUDE_ALL_IN_WORKFLOW OFF CACHE BOOL "If true, all libraries (even those not selected) will be included in the generated workflow. Only relevant for workflow generators like Visual Studio.")
 
 
 mark_as_advanced(CMAKE_INSTALL_PREFIX)
 mark_as_advanced(CMAKE_INSTALL_PREFIX)
 
 
@@ -167,8 +168,6 @@ endfunction()
 function(add_engine_dependencies target_name)
 function(add_engine_dependencies target_name)
 	if(RENDER_API_MODULE MATCHES "DirectX 11")
 	if(RENDER_API_MODULE MATCHES "DirectX 11")
 		add_dependencies(${target_name} BansheeD3D11RenderAPI)
 		add_dependencies(${target_name} BansheeD3D11RenderAPI)
-	elseif(RENDER_API_MODULE MATCHES "DirectX 9")
-		add_dependencies(${target_name} BansheeD3D9RenderAPI)
 	else()
 	else()
 		add_dependencies(${target_name} BansheeGLRenderAPI)
 		add_dependencies(${target_name} BansheeGLRenderAPI)
 	endif()
 	endif()
@@ -196,17 +195,14 @@ endif()
 
 
 ## Plugins
 ## Plugins
 ### If using MSVC include all plugins in the solution (which ones actually build is controlled by dependencies)
 ### If using MSVC include all plugins in the solution (which ones actually build is controlled by dependencies)
-if(MSVC)
+if(INCLUDE_ALL_IN_WORKFLOW AND MSVC)
 	add_subdirectory(BansheeD3D11RenderAPI)
 	add_subdirectory(BansheeD3D11RenderAPI)
-	add_subdirectory(BansheeD3D9RenderAPI)
 	add_subdirectory(BansheeGLRenderAPI)
 	add_subdirectory(BansheeGLRenderAPI)
 	add_subdirectory(BansheeFMOD)
 	add_subdirectory(BansheeFMOD)
 	add_subdirectory(BansheeOpenAudio)
 	add_subdirectory(BansheeOpenAudio)
 else() # Otherwise include only chosen ones
 else() # Otherwise include only chosen ones
 	if(RENDER_API_MODULE MATCHES "DirectX 11")
 	if(RENDER_API_MODULE MATCHES "DirectX 11")
 		add_subdirectory(BansheeD3D11RenderAPI)
 		add_subdirectory(BansheeD3D11RenderAPI)
-	elseif(RENDER_API_MODULE MATCHES "DirectX 9")
-		add_subdirectory(BansheeD3D9RenderAPI)
 	else()
 	else()
 		add_subdirectory(BansheeGLRenderAPI)
 		add_subdirectory(BansheeGLRenderAPI)
 	endif()
 	endif()
@@ -263,8 +259,6 @@ endif()
 ## Set names of libraries used in the config file
 ## Set names of libraries used in the config file
 if(RENDER_API_MODULE MATCHES "DirectX 11")
 if(RENDER_API_MODULE MATCHES "DirectX 11")
 	set(RENDER_API_MODULE_LIB BansheeD3D11RenderAPI)
 	set(RENDER_API_MODULE_LIB BansheeD3D11RenderAPI)
-elseif(RENDER_API_MODULE MATCHES "DirectX 9")
-	set(RENDER_API_MODULE_LIB BansheeD3D9RenderAPI)
 else()
 else()
 	set(RENDER_API_MODULE_LIB BansheeGLRenderAPI)
 	set(RENDER_API_MODULE_LIB BansheeGLRenderAPI)
 endif()
 endif()