#pragma region CPL License /* Nuclex Engine Copyright (C) 2002-2008 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion #ifndef NUCLEX_PLUGINS_DIRECT3D9_DIRECT3D9PLUGIN_H #define NUCLEX_PLUGINS_DIRECT3D9_DIRECT3D9PLUGIN_H #include "Nuclex/Nuclex.h" #ifndef NUCLEX_WIN32 #error This plugin only works on the win32 platform #endif #include "Nuclex/Video/Surface.h" #include "Nuclex/Support/Exception.h" #include "Nuclex/Support/String.h" // #include "MemoryTracker/DisableMemoryTracker.h" #include #include #include #include // #include "MemoryTracker/MemoryTracker.h" // The following block will decide whether symbols are imported from a // dll (client app) or exported to a dll (nuclex library). // The DIRECT3D9PLUGIN_EXPORTS symbol should only be used for compiling // the Nuclex.Plugins.Direct3D9 library and nowhere else. // #ifdef DIRECT3D9PLUGIN_EXPORTS #define DIRECT3D9PLUGIN_API __declspec(dllexport) #else #define DIRECT3D9PLUGIN_API __declspec(dllimport) #endif _COM_SMARTPTR_TYPEDEF(ID3DXBuffer, IID_ID3DXBuffer); _COM_SMARTPTR_TYPEDEF(ID3DXMesh, IID_ID3DXMesh); namespace Nuclex { namespace Video { // ------------------------------------------------------------------------------------------- // /// Obtains the global Direct3D9 instance /// The global Direct3D9 instance DIRECT3D9PLUGIN_API IDirect3D9 *getDirect3D9(); // ------------------------------------------------------------------------------------------- // /// Converts a nuclex pixel format into a direct3d pixel format /// Format to convert /// The Direct3D pixel format static inline D3DFORMAT D3DFORMATFromPixelFormat(Surface::PixelFormat eFormat) { switch(eFormat) { case Surface::PF_A_8: return D3DFMT_A8; case Surface::PF_RGB_3_3_2: return D3DFMT_R3G3B2; case Surface::PF_RGB_5_6_5: return D3DFMT_R5G6B5; case Surface::PF_RGB_8_8_8: return D3DFMT_R8G8B8; case Surface::PF_XRGB_1_5_5_5: return D3DFMT_X1R5G5B5; case Surface::PF_XRGB_8_8_8_8: return D3DFMT_X8R8G8B8; case Surface::PF_ARGB_1_5_5_5: return D3DFMT_A1R5G5B5; case Surface::PF_ARGB_4_4_4_4: return D3DFMT_A4R4G4B4; case Surface::PF_ARGB_8_8_8_8: return D3DFMT_A8R8G8B8; default: return D3DFMT_UNKNOWN; } } // ------------------------------------------------------------------------------------------- // /// Converts a direct3d pixel format into a nuclex pixel format /// Format to convert /// The nuclex pixel format static inline Surface::PixelFormat PixelFormatFromD3DFORMAT(D3DFORMAT eFormat) { switch(eFormat) { case D3DFMT_A8: return Surface::PF_A_8; case D3DFMT_R3G3B2: return Surface::PF_RGB_3_3_2; case D3DFMT_R5G6B5: return Surface::PF_RGB_5_6_5; case D3DFMT_R8G8B8: return Surface::PF_RGB_8_8_8; case D3DFMT_X1R5G5B5: return Surface::PF_XRGB_1_5_5_5; case D3DFMT_X8R8G8B8: return Surface::PF_XRGB_8_8_8_8; case D3DFMT_A1R5G5B5: return Surface::PF_ARGB_1_5_5_5; case D3DFMT_A4R4G4B4: return Surface::PF_ARGB_4_4_4_4; case D3DFMT_A8R8G8B8: return Surface::PF_ARGB_8_8_8_8; default: return Surface::PF_NONE; } } // ------------------------------------------------------------------------------------------- // /// Direct3D method call check. Converts errors to exceptions /// Source of the call /// Method being called /// Method result code static inline void D3DCheck( const char *pszSource, const char *pszMethod, const HRESULT hResult ) { if(FAILED(hResult)) { throw UnexpectedException( pszSource, string("Unexpected failure in ") + pszMethod + ": " + DXGetErrorString9A(hResult) ); } } // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Video #endif // NUCLEX_PLUGINS_DIRECT3D9_DIRECT3D9PLUGIN_H