21 #ifndef WIN32_LEAN_AND_MEAN 22 #define WIN32_LEAN_AND_MEAN 1 // get rid of mfc win32 hdr stuff 31 #define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h 41 #ifdef USE_GENERIC_DXERR_LIBRARY 43 #define DX_GET_ERROR_STRING_FUNC DXGetErrorString 44 #define DX_GET_ERROR_DESCRIPTION_FUNC DXGetErrorDescription 47 #define DX_GET_ERROR_STRING_FUNC DXGetErrorString9 48 #define DX_GET_ERROR_DESCRIPTION_FUNC DXGetErrorDescription9 51 #undef WIN32_LEAN_AND_MEAN 53 #if (D3D_SDK_VERSION & 0xffff) < 32 54 #error You need to install the latest DirectX9 SDK. 57 #ifndef D3DERRORSTRING 59 #define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" << DX_GET_ERROR_STRING_FUNC(HRESULT) << std::endl // leave out descriptions to shrink release build 61 #define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" << DX_GET_ERROR_STRING_FUNC(HRESULT) << ": " << DX_GET_ERROR_DESCRIPTION_FUNC(HRESULT) << std::endl 67 #define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.VendorId==0x10DE) || (DDDEVICEID.VendorId==0x12D2)) 68 #define IS_ATI(DDDEVICEID) (DDDEVICEID.VendorId==0x1002) 69 #define IS_MATROX(DDDEVICEID) (DDDEVICEID.VendorId==0x102B) 71 #define D3D_MAXTEXTURESTAGES 8 73 typedef enum {VertexShader,PixelShader} ShaderType;
74 typedef DWORD DXShaderHandle;
76 #define ISPOW2(X) (((X) & ((X)-1))==0) 77 #define IS_VALID_PTR(PTR) (!IsBadWritePtr(PTR,sizeof(void*))) 79 #define DX_DECLARE_CLEAN(type, var) \ 81 ZeroMemory(&var, sizeof(type)); \ 82 var.dwSize = sizeof(type); 84 #define SAFE_DELSHADER(TYPE,HANDLE,PDEVICE) \ 85 if((HANDLE!=nullptr)&&IS_VALID_PTR(PDEVICE)) { PDEVICE->Delete##TYPE##Shader(HANDLE); HANDLE=nullptr; } 87 #define SAFE_DELETE(p) { if(p) { assert(IS_VALID_PTR(p)); delete (p); (p)=nullptr; } } 88 #define SAFE_DELETE_ARRAY(p) { if(p) { assert(IS_VALID_PTR(p)); delete [] (p); (p)=nullptr; } } 91 #define SAFE_RELEASE(p) { if(p) { assert(IS_VALID_PTR(p)); (p)->Release(); (p)=nullptr; } } 92 #define SAFE_FREELIB(hDLL) { if(hDLL!=nullptr) { FreeLibrary(hDLL);hDLL = nullptr; } } 95 #define RELEASE_DOWN_TO_ZERO true 96 #define RELEASE_ONCE false 101 #ifdef DEBUG_RELEASES 102 #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) { \ 104 if(IS_VALID_PTR(OBJECT)) { \ 105 refcnt = (OBJECT)->Release(); \ 106 MODULE##_cat.debug() << DBGSTR << " released, refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << std::endl; \ 107 if((bDoDownToZero) && (refcnt>0)) { \ 108 MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \ 110 refcnt = (OBJECT)->Release(); \ 113 (OBJECT) = nullptr; \ 115 MODULE##_cat.debug() << DBGSTR << " not released, ptr == NULL" << std::endl; \ 118 #define PRINT_REFCNT(MODULE,p) { ULONG refcnt; (p)->AddRef(); refcnt=(p)->Release(); \ 119 MODULE##_cat.debug() << #p << " has refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << std::endl; } 122 #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) { \ 124 if(IS_VALID_PTR(OBJECT)) { \ 125 refcnt=(OBJECT)->Release(); \ 126 if((bDoDownToZero) && (refcnt>0)) { \ 127 MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \ 129 refcnt = (OBJECT)->Release(); \ 132 (OBJECT) = nullptr; \ 135 #define PRINT_REFCNT(MODULE,p) 139 #define DO_PSTATS_STUFF(XX) XX; 141 #define DO_PSTATS_STUFF(XX) 144 #define PANDA_MAXNUMVERTS 0xFFFF // Note Device may support more than this if it supports D3DFMT_INDEX32 indexbufs. 146 #define FLG(NN) (1<<NN) 147 #define MAX_POSSIBLE_TEXFMTS 32 149 R8G8B8_FLAG = FLG(0),
150 A8R8G8B8_FLAG = FLG(1),
151 X8R8G8B8_FLAG = FLG(2),
152 R5G6B5_FLAG = FLG(3),
153 X1R5G5B5_FLAG = FLG(4),
154 A1R5G5B5_FLAG = FLG(5),
155 A4R4G4B4_FLAG = FLG(6),
156 R3G3B2_FLAG = FLG(7),
158 A8R3G3B2_FLAG = FLG(9),
159 X4R4G4B4_FLAG = FLG(10),
160 A2B10G10R10_FLAG = FLG(11),
161 G16R16_FLAG = FLG(12),
168 D24X8_FLAG = FLG(19),
169 D24S8_FLAG = FLG(20),
172 W11V11U10_FLAG = FLG(23),
173 A2W10V10U10_FLAG = FLG(24),
183 #define D3DFMT_INTZ ((D3DFORMAT)MAKEFOURCC('I', 'N', 'T', 'Z')) 184 #define D3DFMT_ATI1 ((D3DFORMAT)MAKEFOURCC('A', 'T', 'I', '1')) 185 #define D3DFMT_ATI2 ((D3DFORMAT)MAKEFOURCC('A', 'T', 'I', '2')) 189 #define DISPLAY_32BPP_REQUIRES_16BPP_ZBUFFER_FLAG DXT1_FLAG 190 #define DISPLAY_16BPP_REQUIRES_16BPP_ZBUFFER_FLAG DXT2_FLAG 192 #define IS_16BPP_DISPLAY_FORMAT(FMT) (((FMT)==D3DFMT_R5G6B5)||((FMT)==D3DFMT_X1R5G5B5)||((FMT)==D3DFMT_A1R5G5B5)) 193 #define IS_16BPP_ZBUFFER(FMT) ((FMT==D3DFMT_D16)||(FMT==D3DFMT_D15S1)) 194 #define IS_STENCIL_FORMAT(FMT) (((FMT)==D3DFMT_D24S8) || ((FMT)==D3DFMT_D15S1) || ((FMT)==D3DFMT_D24X4S4)) 195 #define RECT_XSIZE(REC) (REC.right-REC.left) 196 #define RECT_YSIZE(REC) (REC.bottom-REC.top) 201 LPDIRECT3DDEVICE9 _d3d_device;
202 IDirect3DSwapChain9 *_swap_chain;
206 DWORD _max_available_video_memory;
208 ushort _depth_buffer_bitdepth;
209 bool _can_direct_disable_color_writes;
210 bool _is_low_memory_card;
212 bool _can_use_hw_vertex_shaders;
213 bool _can_use_pixel_shaders;
214 UINT _supported_screen_depths_mask;
215 UINT _supported_tex_formats_mask;
216 bool _supports_rgba16f_texture_format;
217 bool _supports_rgba32_texture_format;
219 D3DDISPLAYMODE _display_mode;
220 D3DPRESENT_PARAMETERS _presentation_params;
221 D3DADAPTER_IDENTIFIER9 _dx_device_id;
222 D3DFORMAT _render_to_texture_d3d_format;
223 D3DFORMAT _framebuffer_d3d_format;
227 int _managed_textures;
228 int _managed_vertex_buffers;
229 int _managed_index_buffers;
231 bool _supports_dynamic_textures;
232 bool _supports_automatic_mipmap_generation;
233 bool _intel_compressed_texture_bug;
239 extern void Init_D3DFORMAT_map();
240 extern const char *D3DFormatStr(D3DFORMAT fmt);
A GraphicsStateGuardian for rendering into DirectX9 contexts.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.