/** * PANDA 3D SOFTWARE * Copyright (c) Carnegie Mellon University. All rights reserved. * * All use of this software is subject to the terms of the revised BSD * license. You should have received a copy of this license along * with this source code in a file named "LICENSE." * * @file dxgsg9base.h * @author georges * @date 2001-10-07 */ #ifndef DXGSG9BASE_H #define DXGSG9BASE_H #include "pandabase.h" #include "graphicsWindow.h" #include "pmap.h" #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 // get rid of mfc win32 hdr stuff #endif #ifndef STRICT // enable strict type checking in windows.h, see msdn #define STRICT #endif #include #define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h // #define D3D_DEBUG_INFO #undef Configure #include #include // This symbol is defined (or not defined) in Config.pp. #define // USE_GENERIC_DXERR_LIBRARY 1 #ifdef USE_GENERIC_DXERR_LIBRARY #include #define DX_GET_ERROR_STRING_FUNC DXGetErrorString #define DX_GET_ERROR_DESCRIPTION_FUNC DXGetErrorDescription #else #include #define DX_GET_ERROR_STRING_FUNC DXGetErrorString9 #define DX_GET_ERROR_DESCRIPTION_FUNC DXGetErrorDescription9 #endif #undef WIN32_LEAN_AND_MEAN #if (D3D_SDK_VERSION & 0xffff) < 32 #error You need to install the latest DirectX9 SDK. #endif #ifndef D3DERRORSTRING #ifdef NDEBUG #define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" << DX_GET_ERROR_STRING_FUNC(HRESULT) << std::endl // leave out descriptions to shrink release build #else #define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" << DX_GET_ERROR_STRING_FUNC(HRESULT) << ": " << DX_GET_ERROR_DESCRIPTION_FUNC(HRESULT) << std::endl #endif #endif // imperfect method to ID NVid? could also scan desc str, but that isnt // fullproof either #define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.VendorId==0x10DE) || (DDDEVICEID.VendorId==0x12D2)) #define IS_ATI(DDDEVICEID) (DDDEVICEID.VendorId==0x1002) #define IS_MATROX(DDDEVICEID) (DDDEVICEID.VendorId==0x102B) #define D3D_MAXTEXTURESTAGES 8 typedef enum {VertexShader,PixelShader} ShaderType; typedef DWORD DXShaderHandle; #define ISPOW2(X) (((X) & ((X)-1))==0) #define IS_VALID_PTR(PTR) (!IsBadWritePtr(PTR,sizeof(void*))) #define DX_DECLARE_CLEAN(type, var) \ type var; \ ZeroMemory(&var, sizeof(type)); \ var.dwSize = sizeof(type); #define SAFE_DELSHADER(TYPE,HANDLE,PDEVICE) \ if((HANDLE!=nullptr)&&IS_VALID_PTR(PDEVICE)) { PDEVICE->Delete##TYPE##Shader(HANDLE); HANDLE=nullptr; } #define SAFE_DELETE(p) { if(p) { assert(IS_VALID_PTR(p)); delete (p); (p)=nullptr; } } #define SAFE_DELETE_ARRAY(p) { if(p) { assert(IS_VALID_PTR(p)); delete [] (p); (p)=nullptr; } } // for stuff outside a panda class #define SAFE_RELEASE(p) { if(p) { assert(IS_VALID_PTR(p)); (p)->Release(); (p)=nullptr; } } #define SAFE_FREELIB(hDLL) { if(hDLL!=nullptr) { FreeLibrary(hDLL);hDLL = nullptr; } } // this is bDoDownToZero argument to RELEASE() #define RELEASE_DOWN_TO_ZERO true #define RELEASE_ONCE false // uncomment to add refcnt debug output #define DEBUG_RELEASES #ifdef DEBUG_RELEASES #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) { \ ULONG refcnt; \ if(IS_VALID_PTR(OBJECT)) { \ refcnt = (OBJECT)->Release(); \ MODULE##_cat.debug() << DBGSTR << " released, refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << std::endl; \ if((bDoDownToZero) && (refcnt>0)) { \ MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \ do { \ refcnt = (OBJECT)->Release(); \ } while(refcnt>0); \ } \ (OBJECT) = nullptr; \ } else { \ MODULE##_cat.debug() << DBGSTR << " not released, ptr == NULL" << std::endl; \ }} #define PRINT_REFCNT(MODULE,p) { ULONG refcnt; (p)->AddRef(); refcnt=(p)->Release(); \ MODULE##_cat.debug() << #p << " has refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << std::endl; } #else #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) { \ ULONG refcnt; \ if(IS_VALID_PTR(OBJECT)) { \ refcnt=(OBJECT)->Release(); \ if((bDoDownToZero) && (refcnt>0)) { \ MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \ do { \ refcnt = (OBJECT)->Release(); \ } while(refcnt>0); \ } \ (OBJECT) = nullptr; \ }} #define PRINT_REFCNT(MODULE,p) #endif #ifdef DO_PSTATS #define DO_PSTATS_STUFF(XX) XX; #else #define DO_PSTATS_STUFF(XX) #endif #define PANDA_MAXNUMVERTS 0xFFFF // Note Device may support more than this if it supports D3DFMT_INDEX32 indexbufs. #define FLG(NN) (1< g_D3DFORMATmap; extern void Init_D3DFORMAT_map(); extern const char *D3DFormatStr(D3DFORMAT fmt); #endif