//  // // # # ### # # -= Nuclex Project =-  // // ## # # # ## ## NCXDirect3D9.cpp - Nuclex Direct3D9 extension  // // ### # # ###  // // # ### # ### Registers the extension module  // // # ## # # ## ##  // // # # ### # # R8 (C)2002 Markus Ewald -> License.txt  // //  // #ifndef NUCLEX_DIRECT3D9_H #define NUCLEX_DIRECT3D9_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 "DirectX/D3D9.h" #include "DirectX/D3DX9.h" #include "DirectX/DXErr9.h" // #include "MemoryTracker/MemoryTracker.h" // Der folgende ifdef-Block zeigt die Standardlösung zur Erstellung von // Makros, die das Exportieren aus einer DLL vereinfachen. Alle Dateien // in dieser DLL wurden mit dem in der Befehlszeile definierten Symbol // NUCLEX_EXPORTS kompiliert. Dieses Symbol sollte für kein Projekt definiert // werden, das diese DLL verwendet. Auf diese Weise betrachtet jedes andere // Projekt, dessen Quellcodedateien diese Datei einbeziehen, // NUCLEX_API-Funktionen als aus einer DLL importiert, während diese DLL mit // diesem Makro definierte Symbole als exportiert betrachtet. #ifdef DIRECT3D9PLUGIN_EXPORTS #define NUCLEXDIRECT3D9_API __declspec(dllexport) #else #define NUCLEXDIRECT3D9_API __declspec(dllimport) #endif _COM_SMARTPTR_TYPEDEF(ID3DXBuffer, IID_ID3DXBuffer); _COM_SMARTPTR_TYPEDEF(ID3DXMesh, IID_ID3DXMesh); namespace Nuclex { namespace Video { NUCLEXDIRECT3D9_API IDirect3D9 *getDirect3D9(); // ####################################################################### // // # Nuclex::Video::D3DFORMATFromPixelFormat() # // // ####################################################################### // /** Converts a nuclex pixel format into a direct3d pixel format @param eFormat Format to convert @return 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; } } // ####################################################################### // // # Nuclex::Video::PixelFormatFromD3DFORMAT() # // // ####################################################################### // /** Converts a direct3d pixel format into a nuclex pixel format @param eFormat Format to convert @return 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; } } // ####################################################################### // // # Nuclex::Video::D3DCheck() # // // ####################################################################### // /** Direct3D method call check. Converts errors to exceptions @param pszSource Source of the call @param pszMethod Method being called @param hResult 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 + ": " + DXGetErrorString9(hResult) ); } }} // namespace Nuclex::Video; #endif // NUCLEX_DIRECT3D9_H