Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/dxgsg8/dxgsg8base.h

Go to the documentation of this file.
00001 // Filename: dxgsg8base.h
00002 // Created by:  georges (07Oct01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef DXGSG8BASE_H
00020 #define DXGSG8BASE_H
00021 
00022 // include win32 defns for everything up to WinServer2003, and assume I'm smart enough to
00023 // use GetProcAddress for backward compat on newer fns
00024 // Note DX8 cannot be installed on w95, so OK to assume base of win98
00025 #define _WIN32_WINNT 0x0502
00026 
00027 #define WIN32_LEAN_AND_MEAN   // get rid of mfc win32 hdr stuff
00028 #ifndef STRICT
00029 // enable strict type checking in windows.h, see msdn
00030 #define STRICT
00031 #endif
00032 
00033 #include <windows.h>
00034 
00035 #define D3D_OVERLOADS   //  get D3DVECTOR '+' operator, etc from d3dtypes.h
00036 #include <d3d8.h>
00037 #include <d3dx8.h>
00038 #include <dxerr8.h>
00039 #undef WIN32_LEAN_AND_MEAN
00040 
00041 #include "pandabase.h"
00042 #include "graphicsWindow.h"
00043 
00044 #if D3D_SDK_VERSION != 220
00045 #error you have DX 8.0 headers, not DX 8.1, you need to install DX 8.1 SDK!
00046 #endif
00047 
00048 #if DIRECT3D_VERSION != 0x0800
00049 #error DX8.1 headers not available, you need to install newer MS Platform SDK!
00050 #endif
00051 
00052 #ifndef D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD
00053 #error you have pre-release DX8.1 headers, you need to install final DX 8.1 SDK!
00054 #endif
00055 
00056 #ifndef D3DERRORSTRING
00057 #ifdef NDEBUG
00058 #define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" <<  DXGetErrorString8(HRESULT) << endl  // leave out descriptions to shrink release build
00059 #else
00060 #define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" <<  DXGetErrorString8(HRESULT) << ": " << DXGetErrorDescription8(HRESULT) << endl
00061 #endif
00062 #endif
00063 
00064 // imperfect method to ID NVid? could also scan desc str, but that isnt fullproof either
00065 #define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.VendorId==0x10DE) || (DDDEVICEID.VendorId==0x12D2))
00066 #define IS_ATI(DDDEVICEID) (DDDEVICEID.VendorId==0x1002)
00067 #define IS_MATROX(DDDEVICEID) (DDDEVICEID.VendorId==0x102B)
00068 
00069 #define D3D_MAXTEXTURESTAGES 8
00070 
00071 typedef enum {VertexShader,PixelShader} ShaderType;
00072 typedef DWORD DXShaderHandle;
00073 
00074 #define ISPOW2(X) (((X) & ((X)-1))==0)
00075 #define IS_VALID_PTR(PTR)  (!IsBadWritePtr(PTR,sizeof(void*)))
00076 
00077 #define DX_DECLARE_CLEAN(type, var) \
00078     type var;                       \
00079     ZeroMemory(&var, sizeof(type)); \
00080     var.dwSize = sizeof(type);
00081     
00082 #define SAFE_DELSHADER(TYPE,HANDLE,PDEVICE)  \
00083   if((HANDLE!=NULL)&&IS_VALID_PTR(PDEVICE)) { PDEVICE->Delete##TYPE##Shader(HANDLE);  HANDLE=NULL; }
00084 
00085 #define SAFE_DELETE(p)       { if(p) { assert(IS_VALID_PTR(p));   delete (p);     (p)=NULL; } }
00086 #define SAFE_DELETE_ARRAY(p) { if(p) { assert(IS_VALID_PTR(p));   delete [] (p);   (p)=NULL; } }
00087 
00088 // for stuff outside a panda class
00089 #define SAFE_RELEASE(p)      { if(p) { assert(IS_VALID_PTR(p)); (p)->Release(); (p)=NULL; } }
00090 #define SAFE_FREELIB(hDLL)   { if(hDLL!=NULL) {  FreeLibrary(hDLL);hDLL = NULL; } }
00091 
00092 // this is bDoDownToZero argument to RELEASE()
00093 #define RELEASE_DOWN_TO_ZERO true
00094 #define RELEASE_ONCE false
00095 
00096 
00097 // uncomment to add refcnt debug output 
00098 #define DEBUG_RELEASES
00099 
00100 #ifdef DEBUG_RELEASES
00101 #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero)             {  \
00102    ULONG refcnt;                                                \
00103    if(IS_VALID_PTR(OBJECT)) {                                   \
00104         refcnt = (OBJECT)->Release();                           \
00105         MODULE##_cat.debug() << DBGSTR << " released, refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << endl; \
00106         if((bDoDownToZero) && (refcnt>0)) {                     \
00107               MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
00108               do {                                \
00109                 refcnt = (OBJECT)->Release();     \
00110               } while(refcnt>0);                  \
00111         }                                         \
00112         (OBJECT) = NULL;                          \
00113       } else {                                    \
00114         MODULE##_cat.debug() << DBGSTR << " not released, ptr == NULL" << endl;  \
00115       }}
00116 
00117 #define PRINT_REFCNT(MODULE,p) { ULONG refcnt;  (p)->AddRef();  refcnt=(p)->Release(); \
00118                                  MODULE##_cat.debug() << #p << " has refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << endl; }
00119                                  
00120 #else
00121 #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero)   { \
00122    ULONG refcnt;                                        \
00123    if(IS_VALID_PTR(OBJECT))                           { \
00124         refcnt=(OBJECT)->Release();                     \
00125         if((bDoDownToZero) && (refcnt>0)) {             \
00126               MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
00127               do {                                \
00128                 refcnt = (OBJECT)->Release();     \
00129               } while(refcnt>0);                  \
00130         }                                         \
00131         (OBJECT) = NULL;                          \
00132    }}
00133 
00134 #define PRINT_REFCNT(MODULE,p)
00135 #endif    
00136 
00137 #ifdef DO_PSTATS
00138 #define DO_PSTATS_STUFF(XX) XX;
00139 #else
00140 #define DO_PSTATS_STUFF(XX)
00141 #endif
00142 
00143 #define PANDA_MAXNUMVERTS 0xFFFF  // Note Device may support more than this if it supports D3DFMT_INDEX32 indexbufs.
00144 
00145 #define FLG(NN) (1<<NN)
00146 #define MAX_POSSIBLE_TEXFMTS 32
00147 typedef enum {
00148     R8G8B8_FLAG =       FLG(0),
00149     A8R8G8B8_FLAG =     FLG(1),
00150     X8R8G8B8_FLAG =     FLG(2),
00151     R5G6B5_FLAG =       FLG(3),
00152     X1R5G5B5_FLAG =     FLG(4),
00153     A1R5G5B5_FLAG =     FLG(5),
00154     A4R4G4B4_FLAG =     FLG(6),
00155     R3G3B2_FLAG =       FLG(7),
00156     A8_FLAG =           FLG(8),
00157     A8R3G3B2_FLAG =     FLG(9),
00158     X4R4G4B4_FLAG =     FLG(10),
00159     A2B10G10R10_FLAG =  FLG(11),
00160     G16R16_FLAG =       FLG(12),
00161     A8P8_FLAG =         FLG(13),
00162     P8_FLAG =           FLG(14),
00163     L8_FLAG =           FLG(15),
00164     A8L8_FLAG =         FLG(16),
00165     A4L4_FLAG =         FLG(17),
00166     V8U8_FLAG =         FLG(18),
00167     L6V5U5_FLAG =       FLG(19),
00168     X8L8V8U8_FLAG =     FLG(20),
00169     Q8W8V8U8_FLAG =     FLG(21),
00170     V16U16_FLAG =       FLG(22),
00171     W11V11U10_FLAG =    FLG(23),
00172     A2W10V10U10_FLAG =  FLG(24),
00173     UYVY_FLAG =         FLG(25),
00174     YUY2_FLAG =         FLG(26),
00175     DXT1_FLAG =         FLG(27),
00176     DXT2_FLAG =         FLG(28),
00177     DXT3_FLAG =         FLG(29),
00178     DXT4_FLAG =         FLG(30),
00179     DXT5_FLAG =         FLG(31)
00180 } D3DFORMAT_FLAG;
00181 
00182 // this is only used in conjunction w/rendertgt fmts, so just make it something that can never be a rtgt
00183 #define DISPLAY_32BPP_REQUIRES_16BPP_ZBUFFER_FLAG DXT1_FLAG
00184 #define DISPLAY_16BPP_REQUIRES_16BPP_ZBUFFER_FLAG DXT2_FLAG
00185 
00186 #define IS_16BPP_DISPLAY_FORMAT(FMT) (((FMT)==D3DFMT_R5G6B5)||((FMT)==D3DFMT_X1R5G5B5)||((FMT)==D3DFMT_A1R5G5B5))
00187 #define IS_16BPP_ZBUFFER(FMT) ((FMT==D3DFMT_D16)||(FMT==D3DFMT_D15S1))
00188 #define IS_STENCIL_FORMAT(FMT) (((FMT)==D3DFMT_D24S8) || ((FMT)==D3DFMT_D15S1) || ((FMT)==D3DFMT_D24X4S4))
00189 #define RECT_XSIZE(REC) (REC.right-REC.left)
00190 #define RECT_YSIZE(REC) (REC.bottom-REC.top)
00191 
00192 typedef struct {
00193       LPDIRECT3DDEVICE8 pD3DDevice;
00194       LPDIRECT3D8       pD3D8;  // copied from DXGraphicsPipe8 for convenience
00195       HWND              hWnd;
00196       HMONITOR          hMon;
00197       DWORD             MaxAvailVidMem;
00198       ushort            CardIDNum;  // adapter ID
00199       ushort            depth_buffer_bitdepth;  //GetSurfaceDesc is not reliable so must store this explicitly
00200       bool              bCanDirectDisableColorWrites;  // if true, dont need blending for this
00201       bool              bIsLowVidMemCard;
00202       bool              bIsTNLDevice;
00203       bool              bCanUseHWVertexShaders;
00204       bool              bCanUsePixelShaders;
00205       bool              bIsDX81;
00206       UINT              SupportedScreenDepthsMask;
00207       UINT              SupportedTexFmtsMask;
00208       D3DCAPS8          d3dcaps;
00209       D3DDISPLAYMODE    DisplayMode;
00210       D3DPRESENT_PARAMETERS PresParams;  // not redundant with DisplayMode since width/height must be 0 for windowed mode
00211       D3DADAPTER_IDENTIFIER8 DXDeviceID;
00212 } DXScreenData;
00213 
00214 
00215 //utility stuff
00216 extern map<D3DFORMAT_FLAG,D3DFORMAT> g_D3DFORMATmap;
00217 extern void Init_D3DFORMAT_map(void);
00218 extern const char *D3DFormatStr(D3DFORMAT fmt);
00219 
00220 #endif
00221 

Generated on Fri May 2 00:37:16 2003 for Panda by doxygen1.3