From 212ed03c2b3922c7f6a6abe0d0ede8af4c32b13c Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Wed, 30 Jan 2002 02:27:14 +0000 Subject: [PATCH] non-working progress save --- panda/src/dxgsg8/Sources.pp | 21 +- panda/src/dxgsg8/config_dxgsg8.cxx | 16 +- panda/src/dxgsg8/config_dxgsg8.h | 7 +- panda/src/dxgsg8/dxGeomNodeContext8.h | 10 +- panda/src/dxgsg8/dxGraphicsStateGuardian8.I | 40 +- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 955 ++++++----- panda/src/dxgsg8/dxGraphicsStateGuardian8.h | 103 +- panda/src/dxgsg8/dxTextureContext8.cxx | 139 +- panda/src/dxgsg8/dxTextureContext8.h | 25 +- panda/src/wdxdisplay8/Sources.pp | 19 +- panda/src/wdxdisplay8/config_wdxdisplay8.cxx | 2 + panda/src/wdxdisplay8/config_wdxdisplay8.h | 2 + panda/src/wdxdisplay8/wdxGraphicsPipe8.cxx | 1495 +---------------- panda/src/wdxdisplay8/wdxGraphicsPipe8.h | 1 - panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx | 1422 +++++++++++----- panda/src/wdxdisplay8/wdxGraphicsWindow8.h | 105 +- 16 files changed, 1858 insertions(+), 2504 deletions(-) diff --git a/panda/src/dxgsg8/Sources.pp b/panda/src/dxgsg8/Sources.pp index 15c07c39f5..ec929e9676 100644 --- a/panda/src/dxgsg8/Sources.pp +++ b/panda/src/dxgsg8/Sources.pp @@ -6,26 +6,25 @@ #if $[BUILD_DX8] #begin lib_target - - #define TARGET dxgsg8 + #define TARGET dxgsg #define LOCAL_LIBS \ cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display light \ putil linmath sgraph mathutil pnmimage event - #define COMBINED_SOURCES $[TARGET]_composite1.cxx + #define COMBINED_SOURCES $[TARGET]_composite1.cxx - #define SOURCES \ - config_dxgsg8.h dxGraphicsStateGuardian8.I \ - dxGraphicsStateGuardian8.cxx dxGraphicsStateGuardian8.h \ - dxSavedFrameBuffer8.I dxSavedFrameBuffer8.h \ + // need to install these due to external projects that link directly with libpandadx (bartop) + #define INSTALL_HEADERS \ + config_dxgsg8.h dxGraphicsStateGuardian8.I dxGraphicsStateGuardian8.h \ dxTextureContext8.h dxGeomNodeContext8.h dxGeomNodeContext8.I + + // build dxGraphicsStateGuardian separately since its so big + + #define SOURCES \ + dxGraphicsStateGuardian8.cxx dxSavedFrameBuffer8.I dxSavedFrameBuffer8.h $[INSTALL_HEADERS] #define INCLUDED_SOURCES \ config_dxgsg8.cxx dxSavedFrameBuffer8.cxx dxTextureContext8.cxx dxGeomNodeContext8.cxx - - #define INSTALL_HEADERS \ - dxGraphicsStateGuardian8.I dxGraphicsStateGuardian8.h \ - dxSavedFrameBuffer8.I dxSavedFrameBuffer8.h dxTextureContext8.h #end lib_target #endif diff --git a/panda/src/dxgsg8/config_dxgsg8.cxx b/panda/src/dxgsg8/config_dxgsg8.cxx index 1305921f5a..0592bbf1a1 100644 --- a/panda/src/dxgsg8/config_dxgsg8.cxx +++ b/panda/src/dxgsg8/config_dxgsg8.cxx @@ -16,10 +16,10 @@ // //////////////////////////////////////////////////////////////////// -#include "config_dxgsg8.h" -#include "dxGraphicsStateGuardian8.h" -#include "dxSavedFrameBuffer8.h" -#include "dxTextureContext8.h" +#include "config_dxgsg.h" +#include "dxGraphicsStateGuardian.h" +#include "dxSavedFrameBuffer.h" +#include "dxTextureContext.h" #include @@ -74,11 +74,12 @@ bool dx_ignore_mipmaps = config_dxgsg.GetBool("dx-ignore-mipmaps", false); // if this is set, more accurate but more expensive fog computations are performed bool dx_use_rangebased_fog = config_dxgsg.GetBool("dx-use-rangebased-fog", false); +bool dx_force_16bpptextures = config_dxgsg.GetBool("dx-force-16bpptextures", false); +bool dx_no_dithering = config_dxgsg.GetBool("dx-no-dithering", false); #ifdef _DEBUG float dx_global_miplevel_bias = config_dxgsg.GetFloat("dx-global-miplevel-bias", 0.0); bool dx_debug_view_mipmaps = config_dxgsg.GetBool("dx-debug-view-mipmaps", false); -bool dx_force_16bpptextures = config_dxgsg.GetBool("dx-force-16bpptextures", false); bool dx_force_anisotropic_filtering = config_dxgsg.GetBool("dx-force-anisotropic-filtering", false); //int dx_print_texstats = config_dxgsg.GetBool("dx-print-texstats", 0); #endif @@ -104,7 +105,7 @@ parse_decal_type(const string &type) { } ConfigureFn(config_dxgsg) { - init_libdxgsg8(); + init_libdxgsg(); } //////////////////////////////////////////////////////////////////// @@ -115,7 +116,8 @@ ConfigureFn(config_dxgsg) { // called by the static initializers and need not be // called explicitly, but special cases exist. //////////////////////////////////////////////////////////////////// -void init_libdxgsg8() { +void +init_libdxgsg() { static bool initialized = false; if (initialized) { return; diff --git a/panda/src/dxgsg8/config_dxgsg8.h b/panda/src/dxgsg8/config_dxgsg8.h index 39d2442421..3b64ca9c02 100644 --- a/panda/src/dxgsg8/config_dxgsg8.h +++ b/panda/src/dxgsg8/config_dxgsg8.h @@ -35,10 +35,12 @@ extern bool dx_auto_normalize_lighting; extern bool dx_use_rangebased_fog; extern const bool link_tristrips; -// debug flags +// debug flags we might want to use in full optimized build extern bool dx_ignore_mipmaps; extern bool dx_mipmap_everything; extern bool dx_show_transforms; +extern bool dx_force_16bpptextures; +extern bool dx_no_dithering; #ifndef NDEBUG extern int dx_force_backface_culling; @@ -47,7 +49,6 @@ extern int dx_force_backface_culling; #ifdef _DEBUG extern float dx_global_miplevel_bias; extern bool dx_debug_view_mipmaps; -extern bool dx_force_16bpptextures; extern bool dx_force_anisotropic_filtering; #endif @@ -59,6 +60,6 @@ enum DXDecalType { }; extern DXDecalType dx_decal_type; -extern EXPCL_PANDADX void init_libdxgsg8(); +extern EXPCL_PANDADX void init_libdxgsg(); #endif diff --git a/panda/src/dxgsg8/dxGeomNodeContext8.h b/panda/src/dxgsg8/dxGeomNodeContext8.h index 4680e7d497..35ded17e6f 100644 --- a/panda/src/dxgsg8/dxGeomNodeContext8.h +++ b/panda/src/dxgsg8/dxGeomNodeContext8.h @@ -33,7 +33,15 @@ #include "pvector.h" #define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h -#include +#include + +#if DIRECT3D_VERSION != 0x0800 +#error DX8.1 headers not available, you need to install newer MS Platform SDK! +#endif + +#if D3D_SDK_VERSION != 220 +#error you have DX 8.0 headers, not DX 8.1, you need to install newer MS Platform SDK! +#endif typedef struct { DWORD nVerts; diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.I b/panda/src/dxgsg8/dxGraphicsStateGuardian8.I index 7ccbddc6fc..2a04aac13c 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.I +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.I @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////// -#include "config_dxgsg8.h" +#include "config_dxgsg.h" #include //////////////////////////////////////////////////////////////////// @@ -30,12 +30,12 @@ enable_line_smooth(bool val) { _line_smooth_enabled = val; #ifdef NDEBUG { - if(val && (_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)) + if(val && (scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)) dxgsg_cat.error() << "no HW support for line smoothing!!\n"; } #endif - _d3dDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, (DWORD)val); } } @@ -47,7 +47,7 @@ enable_line_smooth(bool val) { INLINE void DXGraphicsStateGuardian:: enable_lighting(bool val) { if (_lighting_enabled != val) { - _d3dDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, (DWORD)val); if(_lighting_enabled = val) _lighting_enabled_this_frame = true; } @@ -64,14 +64,14 @@ enable_dither(bool val) { #ifdef _DEBUG { - if(val && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER)) + if(val && !(scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER)) dxgsg_cat.error() << "no HW support for color dithering!!\n"; return; } #endif _dither_enabled = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, (DWORD)val); } } @@ -84,7 +84,7 @@ INLINE void DXGraphicsStateGuardian:: enable_stencil_test(bool val) { if (_stencil_test_enabled != val) { _stencil_test_enabled = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILENABLE, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILENABLE, (DWORD)val); } } @@ -112,12 +112,12 @@ enable_clip_plane(int clip_plane, bool val) { _clip_plane_enabled[clip_plane] = val; DWORD ClipPlaneBits; - _d3dDevice->GetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , &ClipPlaneBits); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , &ClipPlaneBits); if (val) ClipPlaneBits |= 1 << clip_plane; else ClipPlaneBits &= ~(1 << clip_plane); - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , ClipPlaneBits); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , ClipPlaneBits); } } @@ -130,7 +130,7 @@ INLINE void DXGraphicsStateGuardian:: enable_blend(bool val) { if (_blend_enabled != val) { _blend_enabled = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, (DWORD)val); } } @@ -143,7 +143,7 @@ INLINE void DXGraphicsStateGuardian:: set_shademode(D3DSHADEMODE val) { if (_CurShadeMode != val) { _CurShadeMode = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, (DWORD)val); } } @@ -151,7 +151,7 @@ INLINE void DXGraphicsStateGuardian:: enable_primitive_clipping(bool val) { if (_clipping_enabled != val) { _clipping_enabled = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, (DWORD)val); } } @@ -164,7 +164,7 @@ INLINE void DXGraphicsStateGuardian:: enable_fog(bool val) { if ((_fog_enabled != val) && (_doFogType!=None)) { _fog_enabled = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, (DWORD)val); } } @@ -178,7 +178,7 @@ enable_alpha_test(bool val ) { if (_alpha_test_enabled != val) { _alpha_test_enabled = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, (DWORD)val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, (DWORD)val); } } @@ -195,7 +195,7 @@ call_dxLightModelAmbient( const Colorf& color) #ifdef GSG_VERBOSE dxgsg_cat.debug() << "dxLightModel(LIGHT_MODEL_AMBIENT, " << color << ")" << endl; #endif - _d3dDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, + scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, D3DRGBA(color[0], color[1], color[2], color[3])); } } @@ -242,8 +242,8 @@ call_dxAlphaFunc(D3DCMPFUNC func, DWORD ref) } dxgsg_cat.debug() << ref << ")" << endl; #endif - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, func); - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF, ref); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, func); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF, ref); } } @@ -254,7 +254,7 @@ call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc ) if (_blend_source_func != sfunc) { _blend_source_func = sfunc; - _d3dDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, sfunc); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, sfunc); #ifdef GSG_VERBOSE dxgsg_cat.debug() << "dxSrcBlendFunc("; switch (sfunc) @@ -296,7 +296,7 @@ call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc ) if ( _blend_dest_func != dfunc) { _blend_dest_func = dfunc; - _d3dDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, dfunc); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, dfunc); #ifdef GSG_VERBOSE dxgsg_cat.debug() << "dxDstBlendFunc("; switch (dfunc) @@ -338,7 +338,7 @@ INLINE void DXGraphicsStateGuardian:: enable_zwritemask(bool val) { if (_depth_write_enabled != val) { _depth_write_enabled = val; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, val); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, val); } } diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index bb37745014..19dc79ae05 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -28,14 +28,13 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include #include -#include #include #include #include @@ -61,8 +60,8 @@ #include #endif -#include "config_dxgsg8.h" -#include "dxGraphicsStateGuardian8.h" +#include "config_dxgsg.h" +#include "dxGraphicsStateGuardian.h" // disable nameless struct 'warning' #pragma warning (disable : 4201) @@ -284,7 +283,7 @@ void DXGraphicsStateGuardian::FillFPSMeterTexture(void) { // init it to transparent black if(FAILED( hr = _fpsmeter_font_surf->Lock( NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL ))) { dxgsg_cat.error() << "fps meter creation failed, Lock() failed on texture! hr = " << ConvD3DErrorToString(hr) << "\n"; - dx_show_fps_meter = false; + _bShowFPSMeter = false; return; } ZeroMemory(ddsd.lpSurface,ddsd.dwWidth*ddsd.dwHeight*2); @@ -294,7 +293,7 @@ void DXGraphicsStateGuardian::FillFPSMeterTexture(void) { HDC hDC; if(FAILED( hr = _fpsmeter_font_surf->GetDC(&hDC))) { dxgsg_cat.error() << "fps meter creation failed, GetDC failed on fps font surface! hr = " << ConvD3DErrorToString(hr) << "\n"; - dx_show_fps_meter = false; + _bShowFPSMeter = false; return; } @@ -327,7 +326,7 @@ void DXGraphicsStateGuardian::FillFPSMeterTexture(void) { // GDI writes 0x00 for alpha, have to make letter pixels opaque again if(FAILED( hr = _fpsmeter_font_surf->Lock( NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL ))) { dxgsg_cat.error() << "fps meter creation failed, Lock() failed on texture! hr = " << ConvD3DErrorToString(hr) << "\n"; - dx_show_fps_meter = false; + _bShowFPSMeter = false; return; } @@ -359,6 +358,8 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) { GraphicsStateGuardian::reset(); + ZeroMemory(&scrn,sizeof(DXScreenData)); + _bShowFPSMeter = false; _pCurFvfBufPtr = NULL; _pFvfBufBasePtr = new char[VERT_BUFFER_SIZE]; // allocate storage for vertex info. _index_buf = new WORD[D3DMAXNUMVERTICES]; // allocate storage for vertex index info. @@ -366,9 +367,9 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) { _fpsmeter_font_surf=NULL; _dx_ready = false; - _pri = _zbuf = _back = NULL; - _pDD = NULL; - _d3dDevice = NULL; +// scrn.pddsPrimary = scrn.pddsZBuf = scrn.pddsBack = NULL; +// _pDD = NULL; +// scrn.pD3DDevice = NULL; // non-dx obj values inited here should not change if resize is // called and dx objects need to be recreated (otherwise they @@ -408,8 +409,8 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) { //////////////////////////////////////////////////////////////////// DXGraphicsStateGuardian:: ~DXGraphicsStateGuardian() { - if (_d3dDevice != NULL) - _d3dDevice->SetTexture(0, NULL); // this frees reference to the old texture + if (scrn.pD3DDevice != NULL) + scrn.pD3DDevice->SetTexture(0, NULL); // this frees reference to the old texture _pCurTexContext = NULL; free_pointers(); @@ -443,25 +444,30 @@ free_dxgsg_objects(void) { _dx_ready = false; - if (_d3dDevice!=NULL) { - _d3dDevice->SetTexture(0,NULL); // should release this stuff internally anyway - RELEASE(_d3dDevice,dxgsg,"d3dDevice",RELEASE_DOWN_TO_ZERO); + if (scrn.pD3DDevice!=NULL) { + scrn.pD3DDevice->SetTexture(0,NULL); // should release this stuff internally anyway + RELEASE(scrn.pD3DDevice,dxgsg,"d3dDevice",RELEASE_DOWN_TO_ZERO); } DeleteAllVideoSurfaces(); // Release the DDraw and D3D objects used by the app - RELEASE(_zbuf,dxgsg,"zbuffer",false); - RELEASE(_back,dxgsg,"backbuffer",false); - RELEASE(_pri,dxgsg,"primary surface",false); + RELEASE(scrn.pddsZBuf,dxgsg,"zbuffer",false); + RELEASE(scrn.pddsBack,dxgsg,"backbuffer",false); + RELEASE(scrn.pddsPrimary,dxgsg,"primary surface",false); } HRESULT CALLBACK EnumTexFmtsCallback( LPDDPIXELFORMAT pddpf, VOID* param ) { // wont build if its a member fn, so had to do this stuff +#ifdef USE_TEXFMTVEC + DDPixelFormatVec *pPixFmtVec = (DDPixelFormatVec *) param; + pPixFmtVec->push_back(*pddpf); +#else DXGraphicsStateGuardian *mystate = (DXGraphicsStateGuardian *) param; assert(mystate->_cNumTexPixFmts < MAX_DX_TEXPIXFMTS); memcpy( &(mystate->_pTexPixFmts[mystate->_cNumTexPixFmts]), pddpf, sizeof(DDPIXELFORMAT) ); mystate->_cNumTexPixFmts++; +#endif return DDENUMRET_OK; } @@ -472,42 +478,56 @@ HRESULT CALLBACK EnumTexFmtsCallback( LPDDPIXELFORMAT pddpf, VOID* param ) { // set up. //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: -dx_init( LPDIRECTDRAW7 context, +dx_init( void) { +/* + LPDIRECTDRAW7 context, LPDIRECTDRAWSURFACE7 pri, LPDIRECTDRAWSURFACE7 back, LPDIRECTDRAWSURFACE7 zbuf, LPDIRECT3D7 pD3D, LPDIRECT3DDEVICE7 pDevice, - RECT viewrect) { - _pDD = context; - _pri = pri; - _back = back; - _zbuf = zbuf; - _d3d = pD3D; - _d3dDevice = pDevice; + RECT viewrect) */ + assert(scrn.pDD!=NULL); + assert(scrn.pD3D!=NULL); + assert(scrn.pD3DDevice!=NULL); + assert(scrn.pddsPrimary!=NULL); + assert(scrn.pddsBack!=NULL); + + _pDD=scrn.pDD; // save for speed of access + _pCurD3DDevice = scrn.pD3DDevice; + +/* _pDD = context; + scrn.pddsPrimary = pri; + scrn.pddsBack = back; + scrn.pddsZBuf = zbuf; + scrn.pD3D = pD3D; + scrn.pD3DDevice = pDevice; _view_rect = viewrect; +*/ ZeroMemory(&_lmodel_ambient,sizeof(Colorf)); - _d3dDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0x0); + scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0x0); _light_enabled = (bool *)NULL; _cur_light_enabled = (bool *)NULL; _clip_plane_enabled = (bool *)NULL; _cur_clip_plane_enabled = (bool *)NULL; - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , 0x0); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , 0x0); - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, true); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, true); _clipping_enabled = true; _CurShadeMode = D3DSHADE_FLAT; - _d3dDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, _CurShadeMode); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, _CurShadeMode); _depth_test_enabled = true; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, _depth_test_enabled); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, _depth_test_enabled); // need to free these properly +#ifndef USE_TEXFMTVEC _cNumTexPixFmts = 0; _pTexPixFmts = NULL; +#endif _pCurTexContext = NULL; //Color and alpha transform variables @@ -524,22 +544,22 @@ dx_init( LPDIRECTDRAW7 context, //_point_smooth_enabled = false; _line_smooth_enabled = false; - _d3dDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, false); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, false); _color_material_enabled = false; _normals_enabled = false; _depth_test_enabled = D3DZB_FALSE; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); _blend_enabled = false; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, (DWORD)_blend_enabled); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, (DWORD)_blend_enabled); - _d3dDevice->GetRenderState(D3DRENDERSTATE_SRCBLEND, (DWORD*)&_blend_source_func); - _d3dDevice->GetRenderState(D3DRENDERSTATE_DESTBLEND, (DWORD*)&_blend_dest_func); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_SRCBLEND, (DWORD*)&_blend_source_func); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_DESTBLEND, (DWORD*)&_blend_dest_func); _fog_enabled = false; - _d3dDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, _fog_enabled); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, _fog_enabled); _decal_level = 0; _current_projection_mat = LMatrix4f::ident_mat(); @@ -554,7 +574,7 @@ dx_init( LPDIRECTDRAW7 context, // _line_width = 1.0f; // _point_size = 1.0f; - assert(_back!=NULL); // dxgsg is always double-buffered right now + assert(scrn.pddsBack!=NULL); // dxgsg is always double-buffered right now #ifdef COUNT_DRAWPRIMS global_pD3DDevice = pDevice; @@ -569,29 +589,48 @@ dx_init( LPDIRECTDRAW7 context, HRESULT hr; +#ifdef USE_TEXFMTVEC + assert(scrn.TexPixFmts.size()==0); + + if(FAILED(hr=_pCurD3DDevice->EnumTextureFormats(EnumTexFmtsCallback, &scrn.TexPixFmts))) { +#else _pTexPixFmts = new DDPIXELFORMAT[MAX_DX_TEXPIXFMTS]; _cNumTexPixFmts = 0; - assert(_pTexPixFmts!=NULL); - if (pDevice->EnumTextureFormats(EnumTexFmtsCallback, this) != S_OK) { - dxgsg_cat.error() << "EnumTextureFormats failed!!\n"; + if(FAILED(hr=_pCurD3DDevice->EnumTextureFormats(EnumTexFmtsCallback, this))) { +#endif + if(hr==D3DERR_TEXTURE_NO_SUPPORT) { + dxgsg_cat.error() << "EnumTextureFormats indicates No Texturing Support on this HW!, exiting...\n"; + exit(1); + } else { + dxgsg_cat.error() << "EnumTextureFormats failed! hr = " << ConvD3DErrorToString(hr) << endl; + } } - if (FAILED(hr = pDevice->GetCaps(&_D3DDevDesc))) { - dxgsg_cat.fatal() << "GetCaps failed on D3D Device\n"; +/* + if(FAILED(hr = pDevice->GetCaps(&scrn.D3DDevDesc))) { + dxgsg_cat.fatal() << "GetCaps failed on D3D Device! hr = " << ConvD3DErrorToString(hr) << endl; exit(1); } - +*/ DX_DECLARE_CLEAN(DDCAPS,ddCaps); - if (FAILED(hr = _pDD->GetCaps(&ddCaps,NULL))) { - dxgsg_cat.fatal() << "GetCaps failed on DDraw\n"; + if (FAILED(hr = scrn.pDD->GetCaps(&ddCaps,NULL))) { + dxgsg_cat.fatal() << "GetCaps failed on DDraw! hr = " << ConvD3DErrorToString(hr) << "\n"; exit(1); } - _bIsTNLDevice = (IsEqualGUID(_D3DDevDesc.deviceGUID,IID_IDirect3DTnLHalDevice)!=0); + // s3 virge drivers sometimes give crap values for these + if(scrn.D3DDevDesc.dwMaxTextureWidth==0) + scrn.D3DDevDesc.dwMaxTextureWidth=256; - if ((dx_decal_type==GDT_offset) && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) { + if(scrn.D3DDevDesc.dwMaxTextureHeight==0) + scrn.D3DDevDesc.dwMaxTextureHeight=256; + +// shouldve already been set +// sc_bIsTNLDevice = (IsEqualGUID(scrn.D3DDevDesc.deviceGUID,IID_IDirect3DTnLHalDevice)!=0); + + if ((dx_decal_type==GDT_offset) && !(scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) { #ifdef _DEBUG // dx7 doesnt support PLANEMASK renderstate #if(DIRECT3D_VERSION < 0x700) @@ -619,14 +658,14 @@ dx_init( LPDIRECTDRAW7 context, #endif #endif - if ((dx_decal_type==GDT_mask) && !(_D3DDevDesc.dpcTriCaps.dwMiscCaps & D3DPMISCCAPS_MASKPLANES)) { + if ((dx_decal_type==GDT_mask) && !(scrn.D3DDevDesc.dpcTriCaps.dwMiscCaps & D3DPMISCCAPS_MASKPLANES)) { #ifdef _DEBUG dxgsg_cat.debug() << "No hardware support for colorwrite disabling, switching to dx-decal-type 'mask' to 'blend'\n"; #endif dx_decal_type = GDT_blend; } - if (((dx_decal_type==GDT_blend)||(dx_decal_type==GDT_mask)) && !(_D3DDevDesc.dpcTriCaps.dwMiscCaps & D3DPMISCCAPS_MASKZ)) { + if (((dx_decal_type==GDT_blend)||(dx_decal_type==GDT_mask)) && !(scrn.D3DDevDesc.dpcTriCaps.dwMiscCaps & D3DPMISCCAPS_MASKZ)) { dxgsg_cat.error() << "dx-decal-type mask impossible to implement, no hardware support for Z-masking, decals will not appear correctly!\n"; } @@ -637,41 +676,41 @@ dx_init( LPDIRECTDRAW7 context, #define REQUIRED_BLENDCAPS (D3DPBLENDCAPS_ZERO|D3DPBLENDCAPS_ONE| /*D3DPBLENDCAPS_SRCCOLOR|D3DPBLENDCAPS_INVSRCCOLOR| */ \ D3DPBLENDCAPS_SRCALPHA|D3DPBLENDCAPS_INVSRCALPHA /* | D3DPBLENDCAPS_DESTALPHA|D3DPBLENDCAPS_INVDESTALPHA|D3DPBLENDCAPS_DESTCOLOR|D3DPBLENDCAPS_INVDESTCOLOR*/) - if (((_D3DDevDesc.dpcTriCaps.dwSrcBlendCaps & REQUIRED_BLENDCAPS)!=REQUIRED_BLENDCAPS) || - ((_D3DDevDesc.dpcTriCaps.dwDestBlendCaps & REQUIRED_BLENDCAPS)!=REQUIRED_BLENDCAPS)) { - dxgsg_cat.error() << "device is missing alpha blending capabilities, blending may not work correctly: SrcBlendCaps: 0x"<< (void*) _D3DDevDesc.dpcTriCaps.dwSrcBlendCaps << " DestBlendCaps: "<< (void*) _D3DDevDesc.dpcTriCaps.dwDestBlendCaps << endl; + if (((scrn.D3DDevDesc.dpcTriCaps.dwSrcBlendCaps & REQUIRED_BLENDCAPS)!=REQUIRED_BLENDCAPS) || + ((scrn.D3DDevDesc.dpcTriCaps.dwDestBlendCaps & REQUIRED_BLENDCAPS)!=REQUIRED_BLENDCAPS)) { + dxgsg_cat.error() << "device is missing alpha blending capabilities, blending may not work correctly: SrcBlendCaps: 0x"<< (void*) scrn.D3DDevDesc.dpcTriCaps.dwSrcBlendCaps << " DestBlendCaps: "<< (void*) scrn.D3DDevDesc.dpcTriCaps.dwDestBlendCaps << endl; } - if (!(_D3DDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_TRANSPARENCY)) { - dxgsg_cat.error() << "device is missing texture transparency capability, transparency may not work correctly! TextureCaps: 0x"<< (void*) _D3DDevDesc.dpcTriCaps.dwTextureCaps << endl; + if (!(scrn.D3DDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_TRANSPARENCY)) { + dxgsg_cat.error() << "device is missing texture transparency capability, transparency may not work correctly! TextureCaps: 0x"<< (void*) scrn.D3DDevDesc.dpcTriCaps.dwTextureCaps << endl; } // just require trilinear. if it can do that, it can probably do all the lesser point-sampling variations too #define REQUIRED_TEXFILTERCAPS (D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_LINEAR) - if ((_D3DDevDesc.dpcTriCaps.dwTextureFilterCaps & REQUIRED_TEXFILTERCAPS)!=REQUIRED_TEXFILTERCAPS) { - dxgsg_cat.error() << "device is missing texture bilinear filtering capability, textures may appear blocky! TextureFilterCaps: 0x"<< (void*) _D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; + if ((scrn.D3DDevDesc.dpcTriCaps.dwTextureFilterCaps & REQUIRED_TEXFILTERCAPS)!=REQUIRED_TEXFILTERCAPS) { + dxgsg_cat.error() << "device is missing texture bilinear filtering capability, textures may appear blocky! TextureFilterCaps: 0x"<< (void*) scrn.D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; } #define REQUIRED_MIPMAP_TEXFILTERCAPS (D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_LINEARMIPLINEAR) if (!(ddCaps.ddsCaps.dwCaps & DDSCAPS_MIPMAP)) { - dxgsg_cat.debug() << "device does not have mipmap texturing filtering capability! TextureFilterCaps: 0x"<< (void*) _D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; + dxgsg_cat.debug() << "device does not have mipmap texturing filtering capability! TextureFilterCaps: 0x"<< (void*) scrn.D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; dx_ignore_mipmaps = TRUE; - } else if ((_D3DDevDesc.dpcTriCaps.dwTextureFilterCaps & REQUIRED_MIPMAP_TEXFILTERCAPS)!=REQUIRED_MIPMAP_TEXFILTERCAPS) { - dxgsg_cat.debug() << "device is missing tri-linear mipmap filtering capability, texture mipmaps may not supported! TextureFilterCaps: 0x"<< (void*) _D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; + } else if ((scrn.D3DDevDesc.dpcTriCaps.dwTextureFilterCaps & REQUIRED_MIPMAP_TEXFILTERCAPS)!=REQUIRED_MIPMAP_TEXFILTERCAPS) { + dxgsg_cat.debug() << "device is missing tri-linear mipmap filtering capability, texture mipmaps may not supported! TextureFilterCaps: 0x"<< (void*) scrn.D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; } #define REQUIRED_TEXBLENDCAPS (D3DTEXOPCAPS_MODULATE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_SELECTARG2) - if ((_D3DDevDesc.dwTextureOpCaps & REQUIRED_TEXBLENDCAPS)!=REQUIRED_TEXBLENDCAPS) { - dxgsg_cat.error() << "device is missing some required texture blending capabilities, texture blending may not work properly! TextureOpCaps: 0x"<< (void*) _D3DDevDesc.dwTextureOpCaps << endl; + if ((scrn.D3DDevDesc.dwTextureOpCaps & REQUIRED_TEXBLENDCAPS)!=REQUIRED_TEXBLENDCAPS) { + dxgsg_cat.error() << "device is missing some required texture blending capabilities, texture blending may not work properly! TextureOpCaps: 0x"<< (void*) scrn.D3DDevDesc.dwTextureOpCaps << endl; } - if(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) { + if(scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) { // watch out for drivers that emulate per-pixel fog with per-vertex fog (Riva128, Matrox Millen G200) // some of these require gouraud-shading to be set to work, as if you were using vertex fog _doFogType=PerPixelFog; } else { // every card is going to have vertex fog, since it's implemented in d3d runtime - assert((_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX )!=0); + assert((scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX )!=0); // vtx fog may look crappy if you have large polygons in the foreground and they get clipped, // so you may want to disable it @@ -682,44 +721,44 @@ dx_init( LPDIRECTDRAW7 context, _doFogType = PerVertexFog; // range-based fog only works with vertex fog in dx7/8 - if(dx_use_rangebased_fog && (_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGRANGE)) - _d3dDevice->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE, true); + if(dx_use_rangebased_fog && (scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGRANGE)) + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE, true); } } - SetRect(&clip_rect, 0,0,0,0); // no clip rect set + SetRect(&scrn.clip_rect, 0,0,0,0); // no clip rect set // Lighting, let's turn it off by default _lighting_enabled = false; - _d3dDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, _lighting_enabled); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, _lighting_enabled); // turn on dithering if the rendertarget is < 8bits/color channel DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd_back); - _back->GetSurfaceDesc(&ddsd_back); - _dither_enabled = ((ddsd_back.ddpfPixelFormat.dwRGBBitCount < 24) && - (_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER)); - _d3dDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, _dither_enabled); + scrn.pddsBack->GetSurfaceDesc(&ddsd_back); + _dither_enabled = (!dx_no_dithering) && ((ddsd_back.ddpfPixelFormat.dwRGBBitCount < 24) && + (scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER)); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, _dither_enabled); - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING,true); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING,true); // Stencil test is off by default _stencil_test_enabled = false; - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILENABLE, _stencil_test_enabled); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILENABLE, _stencil_test_enabled); // Antialiasing. enable_line_smooth(false); // enable_multisample(true); _current_fill_mode = RenderModeProperty::M_filled; - _d3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); - _d3dDevice->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); // technically DX7's front-end has no limit on the number of lights, but it's simpler for // this implementation to set a small GL-like limit to make the light array traversals short // and so I dont have to write code that reallocs light arrays - assert((_D3DDevDesc.dwMaxActiveLights==0) || // 0 means infinite lights - (DXGSG_MAX_LIGHTS <= _D3DDevDesc.dwMaxActiveLights)); + assert((scrn.D3DDevDesc.dwMaxActiveLights==0) || // 0 means infinite lights + (DXGSG_MAX_LIGHTS <= scrn.D3DDevDesc.dwMaxActiveLights)); _max_lights = DXGSG_MAX_LIGHTS; @@ -734,7 +773,7 @@ dx_init( LPDIRECTDRAW7 context, } if(dx_auto_normalize_lighting) - _d3dDevice->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, true); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, true); // Set up the clip plane id map _max_clip_planes = D3DMAXUSERCLIPPLANES; @@ -747,7 +786,7 @@ dx_init( LPDIRECTDRAW7 context, } // initial clip rect - SetRect(&clip_rect, 0,0,0,0); // no clip rect set + SetRect(&scrn.clip_rect, 0,0,0,0); // no clip rect set // must do SetTSS here because redundant states are filtered out by our code based on current values above, so // initial conditions must be correct @@ -755,7 +794,7 @@ dx_init( LPDIRECTDRAW7 context, _CurTexBlendMode = TextureApplyProperty::M_modulate; SetTextureBlendMode(_CurTexBlendMode,FALSE); _texturing_enabled = false; - _d3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); // disables texturing + scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); // disables texturing // Init more Texture State _CurTexMagFilter=_CurTexMinFilter=Texture::FT_nearest; @@ -765,23 +804,23 @@ dx_init( LPDIRECTDRAW7 context, // this code must match apply_texture() code for states above // so DX TSS renderstate matches dxgsg state - _d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT); - _d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFP_POINT); - _d3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTFP_NONE); - _d3dDevice->SetTextureStageState(0, D3DTSS_MAXANISOTROPY,_CurTexAnisoDegree); - _d3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU,get_texture_wrap_mode(_CurTexWrapModeU)); - _d3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV,get_texture_wrap_mode(_CurTexWrapModeV)); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFP_POINT); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTFP_NONE); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAXANISOTROPY,_CurTexAnisoDegree); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_ADDRESSU,get_texture_wrap_mode(_CurTexWrapModeU)); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_ADDRESSV,get_texture_wrap_mode(_CurTexWrapModeV)); #ifdef _DEBUG - if ((_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_MIPMAPLODBIAS) && + if ((scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_MIPMAPLODBIAS) && (dx_global_miplevel_bias!=0.0f)) { - _d3dDevice->SetTextureStageState(0, D3DTSS_MIPMAPLODBIAS, *((LPDWORD) (&dx_global_miplevel_bias)) ); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MIPMAPLODBIAS, *((LPDWORD) (&dx_global_miplevel_bias)) ); } #endif if(dx_full_screen_antialiasing) { - if(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT) { - _d3dDevice->SetRenderState(D3DRENDERSTATE_ANTIALIAS,D3DANTIALIAS_SORTINDEPENDENT); + if(scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT) { + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ANTIALIAS,D3DANTIALIAS_SORTINDEPENDENT); if(dxgsg_cat.is_debug()) dxgsg_cat.debug() << "enabling full-screen anti-aliasing\n"; } else { @@ -794,28 +833,120 @@ dx_init( LPDIRECTDRAW7 context, if(dx_force_backface_culling!=0) { if((dx_force_backface_culling > 0) && (dx_force_backface_culling < D3DCULL_FORCE_DWORD)) { - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, dx_force_backface_culling); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, dx_force_backface_culling); } else { dx_force_backface_culling=0; if(dxgsg_cat.is_debug()) dxgsg_cat.debug() << "error, invalid value for dx-force-backface-culling\n"; } } - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, dx_force_backface_culling); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, dx_force_backface_culling); #else - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); #endif _alpha_func = D3DCMP_ALWAYS; _alpha_func_ref = 0; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, _alpha_func); - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF, _alpha_func_ref); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, _alpha_func); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF, _alpha_func_ref); _alpha_test_enabled = false; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, _alpha_test_enabled); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, _alpha_test_enabled); + + + + + // all this must be moved to dx_init, since we need to create DX surface + string windows_icon_filename = get_icon_filename().to_os_specific(); + string windows_mono_cursor_filename = get_mono_cursor_filename().to_os_specific(); + string windows_color_cursor_filename = get_color_cursor_filename().to_os_specific(); + + if(!windows_icon_filename.empty()) { + // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) + // if icon is more than 8bpp + + // loads a .ico fmt file + wc.hIcon = (HICON) LoadImage(NULL, windows_icon_filename.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE ); + + if(wc.hIcon==NULL) { + wdxdisplay_cat.warning() << "windows icon filename '" << windows_icon_filename << "' not found!!\n"; + } + } else { + wc.hIcon = NULL; // use default app icon + } + + + if(!windows_color_cursor_filename.empty()) { + // card support for full color non-black/white GDI cursors varies greatly. if the cursor is not supported, + // it is rendered in software by GDI, which causes a flickering effect (because it's not synced + // with flip?). GDI transparently masks the lack of HW support so there is no easy way for app to detect + // if HW cursor support exists. alternatives are to tie cursor motion to frame rate using DDraw blts + // or overlays (this is done automatically by DX8 runtime mouse cursor support), or to have separate thread draw cursor + // (sync issues?). instead we do mono cursor unless card is known to support 256 color cursors + bool bSupportsColorCursor=true; + + /* if any card doesnt support color, dont load it*/ + for(int w=0;w<_windows.size();w++) + bSupportsColorCursor &= supports_color_cursors(_windows[w]->_dxgsg->scrn.DXDeviceID); + + if(bSupportsColorCursor) { + DWORD load_flags = LR_LOADFROMFILE; + + if(dx_full_screen) { + // I think cursors should use LR_CREATEDIBSECTION since they should not be mapped to the device palette (in the case of 256-color cursors) + // since they are not going to be used on the desktop + load_flags |= LR_CREATEDIBSECTION; + } + + // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) + // if icon is more than 8bpp + + // loads a .cur fmt file. + _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_color_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, load_flags ); + + if(_hMouseCursor==NULL) { + wdxdisplay_cat.warning() << "windows color cursor filename '" << windows_color_cursor_filename << "' not found!!\n"; + goto try_mono_cursor; + + } + +/* dont need these anymore since we are do mousestuff before window creation + SetClassLongPtr(_mwindow, GCLP_HCURSOR, (LONG_PTR) hNewMouseCursor); + SetCursor(hNewMouseCursor); + + if(_bLoadedCustomCursor) + DestroyCursor(_hMouseCursor); +*/ + _bLoadedCustomCursor=true; + } + } + + try_mono_cursor: + + if((!_bLoadedCustomCursor) && (!windows_mono_cursor_filename.empty())) { + // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) + // if icon is more than 8bpp + + DWORD load_flags = LR_LOADFROMFILE; + + if(dx_full_screen) { + // I think cursors should use LR_CREATEDIBSECTION since they should not be mapped to the device palette (in the case of 256-color cursors) + // since they are not going to be used on the desktop + load_flags |= LR_CREATEDIBSECTION; + } + // loads a .cur fmt file. + _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_mono_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, load_flags); + + if(_hMouseCursor==NULL) { + wdxdisplay_cat.warning() << "windows mono cursor filename '" << windows_mono_cursor_filename << "' not found!!\n"; + } else _bLoadedCustomCursor=true; + } + + if(!_bLoadedCustomCursor) + _hMouseCursor = LoadCursor(NULL, DEFAULT_CURSOR); + // need to release this better, so dx_init can be called multiple times - - if(dx_show_fps_meter) { + if(_bShowFPSMeter) { _start_time = timeGetTime(); _current_fps = 0.0f; _start_frame_count = _cur_frame_count = 0; @@ -833,7 +964,12 @@ dx_init( LPDIRECTDRAW7 context, // note GDI cant draw to 4-4-4-4 fmt DDSURF on win9x (GetDC will fail) DDPIXELFORMAT *pCurPixFmt; + +#ifdef USE_TEXFMTVEC + for(i=0,pCurPixFmt=&scrn.TexPixFmts[scrn.TexPixFmts.size()-1];idwRGBBitCount==16) && #ifdef MAKE_FPSMETER_TRANSPARENT (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) && @@ -846,10 +982,14 @@ dx_init( LPDIRECTDRAW7 context, break; } +#ifdef USE_TEXFMTVEC + if(i>=scrn.TexPixFmts.size()) { +#else if(i>=_cNumTexPixFmts) { +#endif // if this fails, no 4-4-4-4 fmt, need code to use 5-5-5-1 dxgsg_cat.error() << "couldnt find 4-4-4-4 tex fmt for fpsmeter font!\n"; - dx_show_fps_meter = false; + _bShowFPSMeter = false; return; } @@ -876,7 +1016,7 @@ dx_init( LPDIRECTDRAW7 context, // could handle this case less wastefully by creating font texture w/multiple rows, // so its naturally square - if(_D3DDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ) { + if(scrn.D3DDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ) { if(texdim_y> texdim_x) texdim_x = texdim_y; texdim_y = texdim_x; @@ -890,16 +1030,16 @@ dx_init( LPDIRECTDRAW7 context, RELEASE(_fpsmeter_font_surf,dxgsg,"fpsmeter fontsurf",false); } - PRINTREFCNT(_pDD,"pre-fpsmeter-font-create IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"pre-fpsmeter-font-create IDirectDraw7"); // Create a new surface for the texture - if(FAILED( hr = _pDD->CreateSurface( &ddsd, &_fpsmeter_font_surf, NULL ) )) { + if(FAILED( hr = scrn.pDD->CreateSurface( &ddsd, &_fpsmeter_font_surf, NULL ) )) { dxgsg_cat.error() << "CreateSurface() failed for fpsmeter font! hr = " << ConvD3DErrorToString(hr) << "\n"; - dx_show_fps_meter = false; + _bShowFPSMeter = false; return; } - PRINTREFCNT(_pDD,"post-fpsmeter-font-create IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"post-fpsmeter-font-create IDirectDraw7"); FillFPSMeterTexture(); @@ -916,7 +1056,7 @@ dx_init( LPDIRECTDRAW7 context, _fps_u_usedwidth = letterfontareaWidth/(float)texdim_x; _fps_v_usedheight = fontareaHeight/(float)texdim_y; - SetFPSMeterPosition(_view_rect); + SetFPSMeterPosition(scrn.view_rect); } // Make sure the DX state matches all of our initial attribute states. @@ -948,14 +1088,16 @@ clear(const RenderBuffer &buffer) { int flags = 0; - if (buffer_type & RenderBuffer::T_depth) + if (buffer_type & RenderBuffer::T_depth) { flags |= D3DCLEAR_ZBUFFER; + assert(scrn.pddsZBuf!=NULL); + } if (buffer_type & RenderBuffer::T_back) //set appropriate flags flags |= D3DCLEAR_TARGET; if (buffer_type & RenderBuffer::T_stencil) flags |= D3DCLEAR_STENCIL; - HRESULT hr = _d3dDevice->Clear(0, NULL, flags, _d3dcolor_clear_value, + HRESULT hr = scrn.pD3DDevice->Clear(0, NULL, flags, _d3dcolor_clear_value, (D3DVALUE) _depth_clear_value, (DWORD)_stencil_clear_value); if (hr != DD_OK) dxgsg_cat.error() << "clear_buffer failed: Clear returned " << ConvD3DErrorToString(hr) << endl; @@ -990,7 +1132,7 @@ bool DXGraphicsStateGuardian:: enable_light(int light, bool val) { if (_light_enabled[light] != val) { _light_enabled[light] = val; - HRESULT res = _d3dDevice->LightEnable( light, val ); + HRESULT res = scrn.pD3DDevice->LightEnable( light, val ); #ifdef GSG_VERBOSE dxgsg_cat.debug() @@ -1071,17 +1213,17 @@ void DXGraphicsStateGuardian::set_clipper(RECT cliprect) { HRGN hrgn = CreateRectRgn(cliprect.left, cliprect.top, cliprect.right, cliprect.bottom); GetRegionData(hrgn, sizeof(RGNDATAHEADER) + sizeof(RECT), rgn_data); - if (_pri->GetClipper(&Clipper) != DD_OK) { - result = _pDD->CreateClipper(0, &Clipper, NULL); + if (scrn.pddsPrimary->GetClipper(&Clipper) != DD_OK) { + result = scrn.pDD->CreateClipper(0, &Clipper, NULL); result = Clipper->SetClipList(rgn_data, 0); - result = _pri->SetClipper(Clipper); + result = scrn.pddsPrimary->SetClipper(Clipper); } else { result = Clipper->SetClipList(rgn_data, 0 ); if (result == DDERR_CLIPPERISUSINGHWND) { - result = _pri->SetClipper(NULL); - result = _pDD->CreateClipper(0, &Clipper, NULL); + result = scrn.pddsPrimary->SetClipper(NULL); + result = scrn.pDD->CreateClipper(0, &Clipper, NULL); result = Clipper->SetClipList(rgn_data, 0 ) ; - result = _pri->SetClipper(Clipper); + result = scrn.pddsPrimary->SetClipper(Clipper); } } free(rgn_data); @@ -1138,7 +1280,7 @@ render_frame() { modify_state(state); #endif - HRESULT hr = _d3dDevice->BeginScene(); + HRESULT hr = scrn.pD3DDevice->BeginScene(); if(FAILED(hr)) { if((hr==DDERR_SURFACELOST)||(hr==DDERR_SURFACEBUSY)) { @@ -1153,7 +1295,7 @@ render_frame() { return; } -/* _d3dDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &matIdentity); */ +/* scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &matIdentity); */ #ifdef GSG_VERBOSE dxgsg_cat.debug() @@ -1213,7 +1355,7 @@ render_frame() { // draw new tri-based FPS meter - if(dx_show_fps_meter) { + if(_bShowFPSMeter) { DO_PSTATS_STUFF(PStatTimer timer(_win->_show_fps_pcollector)); // compute and write new texture indices here @@ -1258,33 +1400,33 @@ render_frame() { #ifdef MAKE_FPSMETER_TRANSPARENT call_dxBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); if(!_blend_enabled) - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true); #else if(_blend_enabled) - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false); #endif if (_CurShadeMode != D3DSHADE_FLAT) { - _d3dDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT); } DWORD saved_zfunc; - _d3dDevice->GetRenderState(D3DRENDERSTATE_ZFUNC,&saved_zfunc); - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZFUNC,D3DCMP_ALWAYS); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_ZFUNC,&saved_zfunc); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC,D3DCMP_ALWAYS); DWORD saved_fill_state; if(_current_fill_mode != RenderModeProperty::M_filled) { - _d3dDevice->GetRenderState(D3DRENDERSTATE_FILLMODE, &saved_fill_state); - _d3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_FILLMODE, &saved_fill_state); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); } DWORD saved_clipping_state,saved_cull_state; - _d3dDevice->GetRenderState(D3DRENDERSTATE_CULLMODE, &saved_cull_state); - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_CULLMODE, &saved_cull_state); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); - _d3dDevice->GetRenderState(D3DRENDERSTATE_CLIPPING, &saved_clipping_state); - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, false); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_CLIPPING, &saved_clipping_state); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, false); // ignore lighting state since verts are post-xform @@ -1292,76 +1434,76 @@ render_frame() { DWORD saved_colorop,saved_alphaop,saved_colorarg1,saved_alphaarg1; LPDIRECTDRAWSURFACE7 saved_tex_surf=NULL; - _d3dDevice->GetTextureStageState(0, D3DTSS_MAGFILTER, &saved_magfilter); - _d3dDevice->GetTextureStageState(0, D3DTSS_MINFILTER, &saved_minfilter); - _d3dDevice->GetTextureStageState(0, D3DTSS_MIPFILTER, &saved_mipfilter); - _d3dDevice->GetTextureStageState( 0, D3DTSS_COLOROP, &saved_colorop); - _d3dDevice->GetTextureStageState( 0, D3DTSS_COLORARG1, &saved_colorarg1); - _d3dDevice->GetTextureStageState( 0, D3DTSS_ALPHAOP, &saved_alphaop); - _d3dDevice->GetTextureStageState( 0, D3DTSS_ALPHAARG1, &saved_alphaarg1); + scrn.pD3DDevice->GetTextureStageState(0, D3DTSS_MAGFILTER, &saved_magfilter); + scrn.pD3DDevice->GetTextureStageState(0, D3DTSS_MINFILTER, &saved_minfilter); + scrn.pD3DDevice->GetTextureStageState(0, D3DTSS_MIPFILTER, &saved_mipfilter); + scrn.pD3DDevice->GetTextureStageState( 0, D3DTSS_COLOROP, &saved_colorop); + scrn.pD3DDevice->GetTextureStageState( 0, D3DTSS_COLORARG1, &saved_colorarg1); + scrn.pD3DDevice->GetTextureStageState( 0, D3DTSS_ALPHAOP, &saved_alphaop); + scrn.pD3DDevice->GetTextureStageState( 0, D3DTSS_ALPHAARG1, &saved_alphaarg1); if(saved_mipfilter!= D3DTFP_NONE) - _d3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTFP_NONE); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTFP_NONE); #define FPS_TEXFILTER(X) D3D##X##_POINT if(saved_minfilter!=FPS_TEXFILTER(TFN)) - _d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, FPS_TEXFILTER(TFN)); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, FPS_TEXFILTER(TFN)); if(saved_magfilter!= FPS_TEXFILTER(TFG)) - _d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, FPS_TEXFILTER(TFG)); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, FPS_TEXFILTER(TFG)); if(saved_colorop!=D3DTOP_SELECTARG1) - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); if(saved_colorarg1!=D3DTA_TEXTURE) - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); if(saved_alphaop!=D3DTOP_SELECTARG1) - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); if(saved_alphaarg1!=D3DTA_TEXTURE) - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - hr = _d3dDevice->SetTexture(0, _fpsmeter_font_surf); + hr = scrn.pD3DDevice->SetTexture(0, _fpsmeter_font_surf); if(FAILED(hr)) { dxgsg_cat.error() << "SetTexture failed in draw fps meter, result = " << ConvD3DErrorToString(hr) << endl; exit(1); } DWORD nVerts = (NUM_FPSMETER_LETTERS+1)*2*3; // +1 for suffix square - HRESULT hr = _d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, _fpsmeter_fvfflags, _fpsmeter_verts, nVerts, NULL); - TestDrawPrimFailure(DrawPrim,hr,_pDD,NUM_FPSMETER_LETTERS*2,0); + HRESULT hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, _fpsmeter_fvfflags, _fpsmeter_verts, nVerts, NULL); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,NUM_FPSMETER_LETTERS*2,0); #ifdef MAKE_FPSMETER_TRANSPARENT if(!_blend_enabled) - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false); #else if(_blend_enabled) - _d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true); #endif - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, saved_zfunc); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, saved_zfunc); - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, saved_clipping_state); - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, saved_cull_state); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, saved_clipping_state); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, saved_cull_state); - _d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, saved_magfilter); - _d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, saved_minfilter); - _d3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, saved_mipfilter); - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, saved_colorop); - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, saved_colorarg1); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, saved_alphaop); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, saved_alphaarg1); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, saved_magfilter); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, saved_minfilter); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, saved_mipfilter); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, saved_colorop); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, saved_colorarg1); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, saved_alphaop); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, saved_alphaarg1); if (_CurShadeMode != D3DSHADE_FLAT) { - _d3dDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, _CurShadeMode); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, _CurShadeMode); } if(_current_fill_mode != RenderModeProperty::M_filled) { - _d3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, saved_fill_state); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, saved_fill_state); } - _d3dDevice->SetTexture(0, ((_pCurTexContext != NULL) ? _pCurTexContext->_surface : NULL)); + scrn.pD3DDevice->SetTexture(0, ((_pCurTexContext != NULL) ? _pCurTexContext->_surface : NULL)); } - hr = _d3dDevice->EndScene(); + hr = scrn.pD3DDevice->EndScene(); // any GDI operations MUST occur after EndScene @@ -1402,7 +1544,7 @@ render_frame() { return; } - if(dx_show_fps_meter) { + if(_bShowFPSMeter) { DO_PSTATS_STUFF(PStatTimer timer(_win->_show_fps_pcollector)); DWORD now = timeGetTime(); // this is win32 fn @@ -1512,13 +1654,13 @@ report_texmgr_stats() { ZeroMemory(&ddsCaps,sizeof(ddsCaps)); ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; - if(FAILED( hr = _pDD->GetAvailableVidMem(&ddsCaps,&dwVidTotal,&dwVidFree))) { + if(FAILED( hr = scrn.pDD->GetAvailableVidMem(&ddsCaps,&dwVidTotal,&dwVidFree))) { dxgsg_cat.debug() << "report_texmgr GetAvailableVidMem for VIDMEM failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } ddsCaps.dwCaps = DDSCAPS_TEXTURE; - if(FAILED( hr = _pDD->GetAvailableVidMem(&ddsCaps,&dwTexTotal,&dwTexFree))) { + if(FAILED( hr = scrn.pDD->GetAvailableVidMem(&ddsCaps,&dwTexTotal,&dwTexFree))) { dxgsg_cat.debug() << "report_texmgr GetAvailableVidMem for TEXTURE failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } @@ -1528,7 +1670,7 @@ report_texmgr_stats() { ZeroMemory(&tminfo,sizeof(D3DDEVINFO_TEXTUREMANAGER)); if(!bTexStatsRetrievalImpossible) { - hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTUREMANAGER,&tminfo,sizeof(D3DDEVINFO_TEXTUREMANAGER)); + hr = scrn.pD3DDevice->GetInfo(D3DDEVINFOID_TEXTUREMANAGER,&tminfo,sizeof(D3DDEVINFO_TEXTUREMANAGER)); if (hr!=D3D_OK) { if (hr==S_FALSE) { static int PrintedMsg=2; @@ -1569,7 +1711,7 @@ report_texmgr_stats() { D3DDEVINFO_TEXTURING texappinfo; ZeroMemory(&texappinfo,sizeof(D3DDEVINFO_TEXTURING)); - hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTURING,&texappinfo,sizeof(D3DDEVINFO_TEXTURING)); + hr = scrn.pD3DDevice->GetInfo(D3DDEVINFOID_TEXTURING,&texappinfo,sizeof(D3DDEVINFO_TEXTURING)); if (hr!=D3D_OK) { dxgsg_cat.error() << "GetInfo(TEXTURING) failed : result = " << ConvD3DErrorToString(hr) << endl; return; @@ -1611,12 +1753,12 @@ report_texmgr_stats() { // Function: DXGraphicsStateGuardian::render_scene // Access: Public, Virtual // Description: Renders an entire scene, from the root node of the -// scene graph, as seen from a particular ProjectionNode +// scene graph, as seen from a particular LensNode // and with a given initial state. This initial state // may be modified during rendering. //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: -render_scene(Node *root, ProjectionNode *projnode) { +render_scene(Node *root, LensNode *projnode) { #ifdef GSG_VERBOSE _pass_number = 0; dxgsg_cat.debug() @@ -1639,28 +1781,31 @@ render_scene(Node *root, ProjectionNode *projnode) { // Function: DXGraphicsStateGuardian::render_subgraph // Access: Public, Virtual // Description: Renders a subgraph of the scene graph as seen from a -// given projection node, and with a particular initial +// given lens node, and with a particular initial // state. This state may be modified by the render // process. //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: render_subgraph(RenderTraverser *traverser, - Node *subgraph, ProjectionNode *projnode, + Node *subgraph, LensNode *projnode, const AllTransitionsWrapper &net_trans) { - ProjectionNode *old_projection_node = _current_projection_node; - _current_projection_node = projnode; + LensNode *old_camera = _current_camera; + _current_camera = projnode; LMatrix4f old_projection_mat = _current_projection_mat; + Lens *lens = projnode->get_lens(); + const LMatrix4f &projection_mat = lens->get_projection_mat(); + // d3d is left-handed coord system - LMatrix4f projection_mat = projnode->get_projection()->get_projection_mat(CS_yup_left); + _current_projection_mat = + LMatrix4f::convert_mat(CS_yup_left, lens->get_coordinate_system()) * + projection_mat; + _projection_mat_stack_count++; #if 0 - dxgsg_cat.spam() << "cur projection matrix: " << projection_mat <<"\n"; + dxgsg_cat.spam() << "cur projection matrix: " << _current_projection_mat <<"\n"; #endif - _current_projection_mat = projection_mat; - _projection_mat_stack_count++; - #ifdef _DEBUG { static bool bPrintedMsg=false; @@ -1679,15 +1824,16 @@ render_subgraph(RenderTraverser *traverser, HRESULT hr; + // BUGBUG: could we avoid doing this every frame if projmat doesnt change? // We load the projection matrix directly. - hr = _d3dDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, + hr = scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, (LPD3DMATRIX) _current_projection_mat.get_data()); // We infer the modelview matrix by doing a wrt on the projection // node. LMatrix4f modelview_mat; - get_rel_mat(subgraph, _current_projection_node, modelview_mat); //needs reversal from glgsg, probably due D3D LH coordsys -// get_rel_mat(_current_projection_node, subgraph, modelview_mat); + get_rel_mat(subgraph, _current_camera, modelview_mat); //needs reversal from glgsg, probably due D3D LH coordsys +// get_rel_mat(_current_camera, subgraph, modelview_mat); if (_coordinate_system != CS_yup_left) { // Now we build the coordinate system conversion into the @@ -1704,7 +1850,7 @@ render_subgraph(RenderTraverser *traverser, render_subgraph(traverser, subgraph, sub_trans); - _current_projection_node = old_projection_node; + _current_camera = old_camera; _current_projection_mat = old_projection_mat; _projection_mat_stack_count--; @@ -1712,7 +1858,7 @@ render_subgraph(RenderTraverser *traverser, // We must now restore the projection matrix from before. We could // do a push/pop matrix if we were using D3DX if (_projection_mat_stack_count > 0) - hr =_d3dDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, + hr =scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, (LPD3DMATRIX) _current_projection_mat.get_data()); } @@ -1720,7 +1866,7 @@ render_subgraph(RenderTraverser *traverser, // Function: DXGraphicsStateGuardian::render_subgraph // Access: Public, Virtual // Description: Renders a subgraph of the scene graph as seen from the -// current projection node, and with a particular +// current lens node, and with a particular // initial state. This state may be modified during the // render process. //////////////////////////////////////////////////////////////////// @@ -2114,8 +2260,8 @@ draw_point(GeomPoint *geom, GeomContext *gc) { draw_prim_inner_loop(nPrims, geom, _perVertex | _perPrim); if(!_bDrawPrimDoSetupVertexBuffer) { - HRESULT hr = _d3dDevice->DrawPrimitive(D3DPT_POINTLIST, _curFVFflags, _pFvfBufBasePtr, nPrims, NULL); - TestDrawPrimFailure(DrawPrim,hr,_pDD,nPrims,0); + HRESULT hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_POINTLIST, _curFVFflags, _pFvfBufBasePtr, nPrims, NULL); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,nPrims,0); } else { COPYVERTDATA_2_VERTEXBUFFER(D3DPT_POINTLIST,nPrims); } @@ -2165,8 +2311,8 @@ draw_point(GeomPoint *geom, GeomContext *gc) { dps_data.textureCoords[0].dwStride = sizeof(TexCoordf); } - HRESULT hr = _d3dDevice->DrawPrimitiveStrided(D3DPT_POINTLIST, _curFVFflags, &dps_data, nPrims, NULL); - TestDrawPrimFailure(DrawPrimStrided,hr,_pDD,nPrims,0); + HRESULT hr = scrn.pD3DDevice->DrawPrimitiveStrided(D3DPT_POINTLIST, _curFVFflags, &dps_data, nPrims, NULL); + TestDrawPrimFailure(DrawPrimStrided,hr,scrn.pDD,nPrims,0); } _pCurFvfBufPtr = NULL; @@ -2256,12 +2402,12 @@ draw_line(GeomLine* geom, GeomContext *gc) { if(!_bDrawPrimDoSetupVertexBuffer) { if (_tmp_fvf == NULL) - hr = _d3dDevice->DrawPrimitive(D3DPT_LINELIST, _curFVFflags, _pFvfBufBasePtr, vertCount, NULL); + hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_LINELIST, _curFVFflags, _pFvfBufBasePtr, vertCount, NULL); else { - hr = _d3dDevice->DrawPrimitive(D3DPT_LINELIST, _curFVFflags, _tmp_fvf, vertCount, NULL); + hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_LINELIST, _curFVFflags, _tmp_fvf, vertCount, NULL); delete [] _tmp_fvf; } - TestDrawPrimFailure(DrawPrim,hr,_pDD,vertCount,0); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,vertCount,0); } else { COPYVERTDATA_2_VERTEXBUFFER(D3DPT_LINELIST,vertCount); } @@ -2364,8 +2510,8 @@ draw_linestrip_base(Geom* geom, GeomContext *gc, bool bConnectEnds) { } if(!_bDrawPrimDoSetupVertexBuffer) { - HRESULT hr = _d3dDevice->DrawPrimitive(D3DPT_LINESTRIP, _curFVFflags, _pFvfBufBasePtr, nVerts, NULL); - TestDrawPrimFailure(DrawPrim,hr,_pDD,nVerts,0); + HRESULT hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_LINESTRIP, _curFVFflags, _pFvfBufBasePtr, nVerts, NULL); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,nVerts,0); } else { COPYVERTDATA_2_VERTEXBUFFER(D3DPT_LINESTRIP,nVerts); } @@ -2439,11 +2585,11 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { DO_PSTATS_STUFF(_vertices_other_pcollector.add_level(nprims)); D3DMATRIX OldD3DWorldMatrix; - _d3dDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); + scrn.pD3DDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); bool bReEnableDither=false; - _d3dDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); + scrn.pD3DDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); Geom::VertexIterator vi = geom->make_vertex_iterator(); Geom::ColorIterator ci = geom->make_color_iterator(); @@ -2484,11 +2630,11 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { modelview_mat = ctatt->get_matrix(); // get the camera information - float aspect_ratio; - aspect_ratio = _actual_display_region->get_camera()->get_aspect(); + float aspect_ratio = + get_current_camera()->get_lens()->get_aspect_ratio(); // null the world xform, so sprites are orthog to scrn (but not necessarily camera pnt unless they lie along z-axis) - _d3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matIdentity); + scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matIdentity); // only need to change _WORLD xform, _VIEW xform is Identity // precomputation stuff @@ -2784,14 +2930,14 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { // cant do tristrip/fan since it would require 1 call want to make 1 call for multiple quads which arent connected // best we can do is indexed primitive, which sends 2 redundant indices instead of sending 2 redundant full verts - HRESULT hr = _d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, _pFvfBufBasePtr, 4*nprims, _index_buf,QUADVERTLISTLEN*nprims,NULL); - TestDrawPrimFailure(DrawIndexedPrim,hr,_pDD,QUADVERTLISTLEN*nprims,nprims); + HRESULT hr = scrn.pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, _pFvfBufBasePtr, 4*nprims, _index_buf,QUADVERTLISTLEN*nprims,NULL); + TestDrawPrimFailure(DrawIndexedPrim,hr,scrn.pDD,QUADVERTLISTLEN*nprims,nprims); _pCurFvfBufPtr = NULL; delete [] SpriteArray; // restore the matrices - _d3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); + scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); if(bReEnableDither) enable_dither(true); @@ -2813,7 +2959,7 @@ draw_polygon(GeomPolygon *geom, GeomContext *gc) { // wireframe polygon will be drawn as linestrip, otherwise draw as multi-tri trifan DWORD rstate; - _d3dDevice->GetRenderState(D3DRENDERSTATE_FILLMODE, &rstate); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_FILLMODE, &rstate); if(rstate==D3DFILL_WIREFRAME) { draw_linestrip_base(geom,gc,true); } else { @@ -2837,7 +2983,7 @@ draw_quad(GeomQuad *geom, GeomContext *gc) { // wireframe quad will be drawn as linestrip, otherwise draw as multi-tri trifan DWORD rstate; - _d3dDevice->GetRenderState(D3DRENDERSTATE_FILLMODE, &rstate); + scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_FILLMODE, &rstate); if(rstate==D3DFILL_WIREFRAME) { draw_linestrip_base(geom,gc,true); } else { @@ -2952,8 +3098,8 @@ draw_tri(GeomTri *geom, GeomContext *gc) { DWORD nVerts=nPrims*3; if(!_bDrawPrimDoSetupVertexBuffer) { - hr = _d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, _pFvfBufBasePtr, nVerts, NULL); - TestDrawPrimFailure(DrawPrim,hr,_pDD,nVerts,nPrims); + hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, _pFvfBufBasePtr, nVerts, NULL); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,nVerts,nPrims); } else { COPYVERTDATA_2_VERTEXBUFFER(D3DPT_TRIANGLELIST,nVerts); } @@ -3145,8 +3291,8 @@ draw_tri(GeomTri *geom, GeomContext *gc) { DWORD nVerts = nPrims*dwVertsperPrim; - hr = _d3dDevice->DrawPrimitiveStrided(primtype, fvf_flags, &dps_data, nVerts, NULL); - TestDrawPrimFailure(DrawPrimStrided,hr,_pDD,nVerts,nPrims); + hr = scrn.pD3DDevice->DrawPrimitiveStrided(primtype, fvf_flags, &dps_data, nVerts, NULL); + TestDrawPrimFailure(DrawPrimStrided,hr,scrn.pDD,nVerts,nPrims); _pCurFvfBufPtr = NULL; } @@ -3160,13 +3306,13 @@ draw_tri(GeomTri *geom, GeomContext *gc) { 0.0f, 0.0f, 33.0, 2.0, 0.0f }; - _d3dDevice->SetTextureStageState(0,D3DTSS_ADDRESSU,D3DTADDRESS_BORDER); - _d3dDevice->SetTextureStageState(0,D3DTSS_ADDRESSV,D3DTADDRESS_BORDER); - _d3dDevice->SetTextureStageState(0,D3DTSS_BORDERCOLOR,MY_D3DRGBA(0,0,0,0)); + scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_ADDRESSU,D3DTADDRESS_BORDER); + scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_ADDRESSV,D3DTADDRESS_BORDER); + scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_BORDERCOLOR,MY_D3DRGBA(0,0,0,0)); _curFVFflags = D3DFVF_XYZ | (D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0)) ; - HRESULT hr = _d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, vert_buf, nPrims*3, NULL); - TestDrawPrimFailure(DrawPrim,hr,_pDD,nPrims*3,nPrims); + HRESULT hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, vert_buf, nPrims*3, NULL); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,nPrims*3,nPrims); #endif } @@ -3360,8 +3506,8 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { } if(!_bDrawPrimDoSetupVertexBuffer) { - hr = _d3dDevice->DrawPrimitive(trilisttype, _curFVFflags, _pFvfBufBasePtr, nVerts, NULL); - TestDrawPrimFailure(DrawPrim,hr,_pDD,nVerts,nVerts-2); + hr = scrn.pD3DDevice->DrawPrimitive(trilisttype, _curFVFflags, _pFvfBufBasePtr, nVerts, NULL); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,nVerts,nVerts-2); } else { COPYVERTDATA_2_VERTEXBUFFER(trilisttype,nVerts); } @@ -3602,8 +3748,8 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { for (uint j=0;jDrawPrimitiveStrided(trilisttype, fvf_flags, &dps_data, cCurNumStripVerts, NULL); - TestDrawPrimFailure(DrawPrimStrided,hr,_pDD,cCurNumStripVerts,cCurNumStripVerts-2); + hr = scrn.pD3DDevice->DrawPrimitiveStrided(trilisttype, fvf_flags, &dps_data, cCurNumStripVerts, NULL); + TestDrawPrimFailure(DrawPrimStrided,hr,scrn.pDD,cCurNumStripVerts,cCurNumStripVerts-2); dps_data.position.lpvData = (VOID*)(((char*) dps_data.position.lpvData) + cCurNumStripVerts*dps_data.position.dwStride); dps_data.diffuse.lpvData = (VOID*)(((char*) dps_data.diffuse.lpvData) + cCurNumStripVerts*dps_data.diffuse.dwStride); @@ -3910,8 +4056,8 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) { // possible optimization: make DP 1 for all spheres call here, since trilist is independent tris. // indexes couldnt start w/0 tho, need to pass offset to gensph - HRESULT hr = _d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, _pFvfBufBasePtr, nVerts, _index_buf,nIndices,NULL); - TestDrawPrimFailure(DrawIndexedPrim,hr,_pDD,nVerts,(nIndices>>2)); + HRESULT hr = scrn.pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, _curFVFflags, _pFvfBufBasePtr, nVerts, _index_buf,nIndices,NULL); + TestDrawPrimFailure(DrawIndexedPrim,hr,scrn.pDD,nVerts,(nIndices>>2)); } _pCurFvfBufPtr = NULL; @@ -3930,7 +4076,7 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) { TextureContext *DXGraphicsStateGuardian:: prepare_texture(Texture *tex) { - DXTextureContext *gtc = new DXTextureContext(tex); + DXTextureContext *dtc = new DXTextureContext(tex); #ifdef WBD_GL_MODE glGenTextures(1, >c->_index); @@ -3939,20 +4085,25 @@ prepare_texture(Texture *tex) { specify_texture(tex); apply_texture_immediate(tex); #else - if (gtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts) == NULL) { - delete gtc; + +#ifdef USE_TEXFMTVEC + if (dtc->CreateTexture(scrn.pD3DDevice,scrn.TexPixFmts,&scrn.D3DDevDesc) == NULL) { +#else + if (dtc->CreateTexture(scrn.pD3DDevice,_cNumTexPixFmts,_pTexPixFmts,&scrn.D3DDevDesc) == NULL) { +#endif + delete dtc; return NULL; } #endif // WBD_GL_MODE - bool inserted = mark_prepared_texture(gtc); + bool inserted = mark_prepared_texture(dtc); // If this assertion fails, the same texture was prepared twice, // which shouldn't be possible, since the texture itself should // detect this. nassertr(inserted, NULL); - return gtc; + return dtc; } //////////////////////////////////////////////////////////////////// @@ -3995,10 +4146,13 @@ apply_texture(TextureContext *tc) { } dtc->DeleteTexture(); - if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts) == NULL) { +#ifdef USE_TEXFMTVEC + if (dtc->CreateTexture(scrn.pD3DDevice,scrn.TexPixFmts,&scrn.D3DDevDesc) == NULL) { +#else + if (dtc->CreateTexture(scrn.pD3DDevice,_cNumTexPixFmts,_pTexPixFmts,&scrn.D3DDevDesc) == NULL) { +#endif // Oops, we can't re-create the texture for some reason. - dxgsg_cat.error() - << "Unable to re-create texture " << *dtc->_texture << endl; + dxgsg_cat.error() << "Unable to re-create texture " << *dtc->_texture << endl; release_texture(dtc); enable_texturing(false); @@ -4018,24 +4172,14 @@ apply_texture(TextureContext *tc) { wrapV=tex->get_wrapv(); if (wrapU!=_CurTexWrapModeU) { - _d3dDevice->SetTextureStageState(0,D3DTSS_ADDRESSU,get_texture_wrap_mode(wrapU)); + scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_ADDRESSU,get_texture_wrap_mode(wrapU)); _CurTexWrapModeU = wrapU; } if (wrapV!=_CurTexWrapModeV) { - _d3dDevice->SetTextureStageState(0,D3DTSS_ADDRESSV,get_texture_wrap_mode(wrapV)); + scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_ADDRESSV,get_texture_wrap_mode(wrapV)); _CurTexWrapModeV = wrapV; } -/* -#ifdef _DEBUG - Texture::WrapMode wrapval; - _d3dDevice->GetTextureStageState(0,D3DTSS_ADDRESSU,(DWORD*)&wrapval); - assert(get_texture_wrap_mode(wrapU) == wrapval); - _d3dDevice->GetTextureStageState(0,D3DTSS_ADDRESSV,(DWORD*)&wrapval); - assert(get_texture_wrap_mode(wrapV) == wrapval); -#endif -*/ - uint aniso_degree=tex->get_anisotropic_degree(); Texture::FilterType ft=tex->get_magfilter(); @@ -4043,7 +4187,7 @@ apply_texture(TextureContext *tc) { if (_CurTexMagFilter!=ft) { _CurTexMagFilter = ft; - _d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER,(ft==Texture::FT_nearest)? D3DTFG_POINT : D3DTFG_LINEAR); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER,(ft==Texture::FT_nearest)? D3DTFG_POINT : D3DTFG_LINEAR); #ifdef _DEBUG if((ft!=Texture::FT_linear)&&(ft!=Texture::FT_nearest)) { dxgsg_cat.error() << "MipMap filter type setting for texture magfilter makes no sense, texture: " << tex->get_name() << "\n"; @@ -4053,8 +4197,8 @@ apply_texture(TextureContext *tc) { } else { if (aniso_degree!=_CurTexAnisoDegree) { _CurTexAnisoDegree = aniso_degree; - _d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_ANISOTROPIC ); - _d3dDevice->SetTextureStageState(0, D3DTSS_MAXANISOTROPY,aniso_degree); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_ANISOTROPIC ); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAXANISOTROPY,aniso_degree); } } @@ -4097,8 +4241,8 @@ apply_texture(TextureContext *tc) { minfilter=D3DTFN_ANISOTROPIC; } - _d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, minfilter); - _d3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, mipfilter); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, minfilter); + scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, mipfilter); _CurTexMinFilter = ft; _CurTexAnisoDegree = aniso_degree; @@ -4106,8 +4250,7 @@ apply_texture(TextureContext *tc) { // bugbug: does this handle the case of untextured geometry? // we dont see this bug cause we never mix textured/untextured - - _d3dDevice->SetTexture(0,dtc->_surface); + scrn.pD3DDevice->SetTexture(0,dtc->_surface); #if 0 if (dtc!=NULL) { @@ -4388,7 +4531,7 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) { */ - (void) ConvertDDSurftoPixBuf(pb,((_cur_read_pixel_buffer & RenderBuffer::T_back) ? _back : _pri)); + (void) ConvertDDSurftoPixBuf(pb,((_cur_read_pixel_buffer & RenderBuffer::T_back) ? scrn.pddsBack : scrn.pddsPrimary)); nassertv(!pb->_image.empty()); } @@ -4548,7 +4691,7 @@ void DXGraphicsStateGuardian::apply_material( const Material* material ) { cur_material.dcvSpecular = *(D3DCOLORVALUE *)(material->get_specular().get_data()); cur_material.dcvEmissive = *(D3DCOLORVALUE *)(material->get_emission().get_data()); cur_material.dvPower = material->get_shininess(); - _d3dDevice->SetMaterial(&cur_material); + scrn.pD3DDevice->SetMaterial(&cur_material); } //////////////////////////////////////////////////////////////////// @@ -4567,10 +4710,10 @@ apply_fog(Fog *fog) { // should probably avoid doing redundant SetRenderStates, but whatever - _d3dDevice->SetRenderState((D3DRENDERSTATETYPE)_doFogType, d3dfogmode); + scrn.pD3DDevice->SetRenderState((D3DRENDERSTATETYPE)_doFogType, d3dfogmode); const Colorf &fog_colr = fog->get_color(); - _d3dDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, MY_D3DRGBA(fog_colr[0], fog_colr[1], fog_colr[2], 0.0f)); // Alpha bits are not used // do we need to adjust fog start/end values based on D3DPRASTERCAPS_WFOG/D3DPRASTERCAPS_ZFOG ? @@ -4585,12 +4728,12 @@ apply_fog(Fog *fog) { // properties. float fog_start, fog_end; fog->compute_linear_range(fog_start, fog_end, - _current_projection_node, + _current_camera, _coordinate_system); - _d3dDevice->SetRenderState( D3DRENDERSTATE_FOGSTART, + scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_FOGSTART, *((LPDWORD) (&fog_start)) ); - _d3dDevice->SetRenderState( D3DRENDERSTATE_FOGEND, + scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_FOGEND, *((LPDWORD) (&fog_end)) ); } break; @@ -4599,7 +4742,7 @@ apply_fog(Fog *fog) { { // Exponential fog is always camera-relative. float fog_density = fog->get_exp_density(); - _d3dDevice->SetRenderState( D3DRENDERSTATE_FOGDENSITY, + scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_FOGDENSITY, *((LPDWORD) (&fog_density)) ); } break; @@ -4634,7 +4777,7 @@ void DXGraphicsStateGuardian::apply_light( PointLight* light ) { alight.dvAttenuation1 = (D3DVALUE)light->get_linear_attenuation(); alight.dvAttenuation2 = (D3DVALUE)light->get_quadratic_attenuation(); - HRESULT res = _d3dDevice->SetLight(_cur_light_id, &alight); + HRESULT res = scrn.pD3DDevice->SetLight(_cur_light_id, &alight); } //////////////////////////////////////////////////////////////////// @@ -4658,7 +4801,7 @@ void DXGraphicsStateGuardian::apply_light( DirectionalLight* light ) { alight.dcvSpecular = *(D3DCOLORVALUE *)(light->get_specular().get_data()); alight.dvDirection = *(D3DVECTOR *) - (get_rel_forward( light, _current_projection_node, CS_yup_left).get_data()); + (get_rel_forward( light, _current_camera, CS_yup_left).get_data()); alight.dvRange = D3DLIGHT_RANGE_MAX; alight.dvFalloff = 1.0f; @@ -4667,9 +4810,9 @@ void DXGraphicsStateGuardian::apply_light( DirectionalLight* light ) { alight.dvAttenuation1 = 0.0f; // linear alight.dvAttenuation2 = 0.0f; // quadratic - HRESULT res = _d3dDevice->SetLight(_cur_light_id, &alight); -// _d3dDevice->LightEnable( _cur_light_id, TRUE ); -// _d3dDevice->SetRenderState( D3DRENDERSTATE_LIGHTING, TRUE ); + HRESULT res = scrn.pD3DDevice->SetLight(_cur_light_id, &alight); +// scrn.pD3DDevice->LightEnable( _cur_light_id, TRUE ); +// scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_LIGHTING, TRUE ); } //////////////////////////////////////////////////////////////////// @@ -4703,12 +4846,12 @@ void DXGraphicsStateGuardian::apply_light( Spotlight* light ) { // Position needs to specify x, y, z, and w // w == 1 implies non-infinite position - LPoint3f pos = get_rel_pos( light, _current_projection_node ); + LPoint3f pos = get_rel_pos( light, _current_camera ); LPoint4f fpos( pos[0], pos[1], pos[2], 1 ); glLightfv( id, GL_POSITION, fpos.get_data() ); glLightfv( id, GL_SPOT_DIRECTION, - get_rel_forward( light, _current_projection_node, + get_rel_forward( light, _current_camera, _coordinate_system ).get_data() ); glLightf( id, GL_SPOT_EXPONENT, light->get_exponent() ); glLightf( id, GL_SPOT_CUTOFF, @@ -4752,7 +4895,7 @@ void DXGraphicsStateGuardian::apply_light( Spotlight* light ) { alight.dvAttenuation1 = (D3DVALUE)light->get_linear_attenuation(); // linear alight.dvAttenuation2 = (D3DVALUE)light->get_quadratic_attenuation();// quadratic - HRESULT res = _d3dDevice->SetLight(_cur_light_id, &alight); + HRESULT res = scrn.pD3DDevice->SetLight(_cur_light_id, &alight); #endif // WBD_GL_MODE } @@ -4796,16 +4939,16 @@ issue_transform(const TransformTransition *attrib) { {0.0f, 0.0f, 3.0, 0.0f, -1.0f, 0.0f, MY_D3DRGBA(0.0f, 0.0f, 1.0f, 1.0f)}, // blu }; - HRESULT hr = _d3dDevice->DrawPrimitive(D3DPT_LINELIST, D3DFVF_DIFFUSE | D3DFVF_XYZ | D3DFVF_NORMAL, + HRESULT hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_LINELIST, D3DFVF_DIFFUSE | D3DFVF_XYZ | D3DFVF_NORMAL, vert_buf, 6, NULL); - TestDrawPrimFailure(DrawPrim,hr,_pDD,6,0); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,6,0); enable_lighting(lighting_was_enabled); enable_texturing(texturing_was_enabled); } #endif - _d3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD/*VIEW*/, + scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD/*VIEW*/, (LPD3DMATRIX) attrib->get_matrix().get_data()); _bTransformIssued = true; } @@ -4828,7 +4971,7 @@ issue_tex_matrix(const TexMatrixTransition *attrib) { glMatrixMode(GL_TEXTURE); glLoadMatrixf(attrib->get_matrix().get_data()); #else - _d3dDevice->SetTransform( D3DTRANSFORMSTATE_TEXTURE0, + scrn.pD3DDevice->SetTransform( D3DTRANSFORMSTATE_TEXTURE0, (LPD3DMATRIX)attrib->get_matrix().get_data()); #endif // WBD_GL_MODE } @@ -5028,11 +5171,11 @@ issue_render_mode(const RenderModeTransition *attrib) { switch (mode) { case RenderModeProperty::M_filled: - _d3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); break; case RenderModeProperty::M_wireframe: - _d3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME); break; default: @@ -5203,47 +5346,47 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex //if bCanJustEnable, then we only need to make sure ColorOp is turned on and set properly if (bCanJustEnable && (TexBlendMode==_CurTexBlendMode)) { // just reset COLOROP 0 to enable pipeline, rest is already set properly - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, TexBlendColorOp1[TexBlendMode] ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, TexBlendColorOp1[TexBlendMode] ); return; } - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, TexBlendColorOp1[TexBlendMode] ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, TexBlendColorOp1[TexBlendMode] ); switch (TexBlendMode) { case TextureApplyProperty::M_modulate: // emulates GL_MODULATE glTexEnv mode // want to multiply tex-color*pixel color to emulate GL modulate blend (see glTexEnv) - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); break; case TextureApplyProperty::M_decal: // emulates GL_DECAL glTexEnv mode - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); break; case TextureApplyProperty::M_replace: - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); break; case TextureApplyProperty::M_add: - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); // since I'm making up 'add' mode, use modulate. "adding" alpha never makes sense right? - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); break; case TextureApplyProperty::M_blend: @@ -5255,21 +5398,21 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex GL requires 2 independent operations on 3 input vars for this mode DX texture pipeline requires re-using input of last stage on each new op, so I dont think exact emulation is possible - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); need to SetTexture(1,tex) also - _d3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE ); wrong - _d3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - _d3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TFACTOR ); + scrn.pD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE ); wrong + scrn.pD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); + scrn.pD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TFACTOR ); - _d3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - _d3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT ); + scrn.pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); + scrn.pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT ); */ @@ -5298,7 +5441,7 @@ enable_texturing(bool val) { // I'm going to allow enabling texturing even if no tex has been set yet, seems to cause no probs if (val == FALSE) { - _d3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); + scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); } else { SetTextureBlendMode(_CurTexBlendMode,TRUE); } @@ -5347,11 +5490,11 @@ issue_depth_test(const DepthTestTransition *attrib) { if (mode == DepthTestProperty::M_none) { _depth_test_enabled = false; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); } else { _depth_test_enabled = true; - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE); - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, get_depth_func_type(mode)); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, get_depth_func_type(mode)); } } @@ -5374,24 +5517,24 @@ issue_stencil(const StencilTransition *attrib) { D3DSTENCILOP zfail_op = get_stencil_action_type(attrib->get_zfail_action()); #ifdef _DEBUG - if(!(_D3DDevDesc.dwStencilCaps & (1<<(pass_op-1)))) { + if(!(scrn.D3DDevDesc.dwStencilCaps & (1<<(pass_op-1)))) { dxgsg_cat.warning() << "driver doesnt support pass stencil operation: " << pass_op << endl; } - if(!(_D3DDevDesc.dwStencilCaps & (1<<(fail_op-1)))) { + if(!(scrn.D3DDevDesc.dwStencilCaps & (1<<(fail_op-1)))) { dxgsg_cat.warning() << "driver doesnt support fail stencil operation: " << fail_op << endl; } - if(!(_D3DDevDesc.dwStencilCaps & (1<<(zfail_op-1)))) { + if(!(scrn.D3DDevDesc.dwStencilCaps & (1<<(zfail_op-1)))) { dxgsg_cat.warning() << "driver doesnt support zfail stencil operation: " << zfail_op << endl; } #endif // TODO: need to cache all these - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILFUNC, get_stencil_func_type(mode)); - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILPASS, pass_op); - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILFAIL, fail_op); - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILZFAIL, zfail_op); - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILREF, attrib->get_reference_value()); - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILMASK, attrib->get_func_mask()); - _d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILWRITEMASK, attrib->get_write_mask()); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILFUNC, get_stencil_func_type(mode)); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILPASS, pass_op); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILFAIL, fail_op); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILZFAIL, zfail_op); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILREF, attrib->get_reference_value()); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILMASK, attrib->get_func_mask()); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILWRITEMASK, attrib->get_write_mask()); } } @@ -5413,17 +5556,17 @@ issue_cull_face(const CullFaceTransition *attrib) { switch (mode) { case CullFaceProperty::M_cull_none: - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); break; case CullFaceProperty::M_cull_clockwise: - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW); break; case CullFaceProperty::M_cull_counter_clockwise: - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); break; case CullFaceProperty::M_cull_all: dxgsg_cat.warning() << "M_cull_all is invalid for DX GSG renderer, using CULL_CCW \n"; - _d3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); break; default: dxgsg_cat.error() @@ -5503,7 +5646,7 @@ issue_clip_plane(const ClipPlaneTransition *attrib) { equation[1] = clip_plane._b; equation[2] = clip_plane._c; equation[3] = clip_plane._d; - _d3dDevice->SetClipPlane(_cur_clip_plane_id, equation); + scrn.pD3DDevice->SetClipPlane(_cur_clip_plane_id, equation); } else if (_cur_clip_plane_id == -1) { dxgsg_cat.error() @@ -5655,7 +5798,7 @@ begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib) { // Just draw the base geometry normally. base_geom->draw(this); - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! } else #endif @@ -5665,7 +5808,7 @@ begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib) { } else { // need to save current xform matrix in case it is changed during subrendering, so subsequent decal draws use same xform _bTransformIssued = false; - _d3dDevice->GetTransform( D3DTRANSFORMSTATE_WORLD, &_SavedTransform); + scrn.pD3DDevice->GetTransform( D3DTRANSFORMSTATE_WORLD, &_SavedTransform); // First turn off writing the depth buffer to render the base geometry. enable_zwritemask(false); @@ -5711,7 +5854,7 @@ end_decal(GeomNode *base_geom) { #ifndef DISABLE_POLYGON_OFFSET_DECALING if (dx_decal_type == GDT_offset) { // Restore the Zbias offset. - _d3dDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! } else #endif { // for GDT_mask @@ -5738,7 +5881,7 @@ end_decal(GeomNode *base_geom) { #if(DIRECT3D_VERSION < 0x700) else { // dx7 doesn't support planemask rstate // note: not saving current planemask val, assumes this is always all 1's. should be ok - _d3dDevice->SetRenderState(D3DRENDERSTATE_PLANEMASK,0x0); // note PLANEMASK is supposedly obsolete for DX7 + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_PLANEMASK,0x0); // note PLANEMASK is supposedly obsolete for DX7 } #endif // Note: For DX8, use D3DRS_COLORWRITEENABLE (check D3DPMISCCAPS_COLORWRITEENABLE first) @@ -5748,7 +5891,7 @@ end_decal(GeomNode *base_geom) { // if current xform has changed, reset to saved xform if(_bTransformIssued) - _d3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &_SavedTransform); + scrn.pD3DDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &_SavedTransform); base_geom->draw(this); @@ -5762,7 +5905,7 @@ end_decal(GeomNode *base_geom) { } #if(DIRECT3D_VERSION < 0x700) else { - _d3dDevice->SetRenderState(D3DRENDERSTATE_PLANEMASK,0xFFFFFFFF); // this is unlikely to work due to poor driver support + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_PLANEMASK,0xFFFFFFFF); // this is unlikely to work due to poor driver support } #endif enable_texturing(was_textured); @@ -5992,11 +6135,14 @@ free_pointers() { delete[] _cur_clip_plane_enabled; _cur_clip_plane_enabled = (bool *)NULL; } - +#ifdef USE_TEXFMTVEC + scrn.TexPixFmts.clear(); +#else if (_pTexPixFmts != NULL) { delete [] _pTexPixFmts; _pTexPixFmts = NULL; } +#endif if(_fpsmeter_verts!=NULL) { delete [] _fpsmeter_verts; @@ -6126,49 +6272,50 @@ dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled) { // msg already delivered to d3d.dll and it's unloaded itself if(!bAtExitFnEverCalled) { - PRINTREFCNT(_pDD,"exit start IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"exit start IDirectDraw7"); // these 2 calls release ddraw surfaces and vbuffers. unsafe unless not on exit release_all_textures(); release_all_geoms(); - PRINTREFCNT(_pDD,"after release_all_textures IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"after release_all_textures IDirectDraw7"); // Do a safe check for releasing the D3DDEVICE. RefCount should be zero. - // if we're called from exit(), _d3dDevice may already have been released - if (_d3dDevice!=NULL) { - _d3dDevice->SetTexture(0,NULL); // should release this stuff internally anyway - RELEASE(_d3dDevice,dxgsg,"d3dDevice",RELEASE_DOWN_TO_ZERO); + // if we're called from exit(), scrn.pD3DDevice may already have been released + if (scrn.pD3DDevice!=NULL) { + scrn.pD3DDevice->SetTexture(0,NULL); // should release this stuff internally anyway + RELEASE(scrn.pD3DDevice,dxgsg,"d3dDevice",RELEASE_DOWN_TO_ZERO); } - PRINTREFCNT(_pDD,"after d3ddevice release IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"after d3ddevice release IDirectDraw7"); RELEASE(_fpsmeter_font_surf,dxgsg,"fpsmeter fontsurf",false); - PRINTREFCNT(_pDD,"after fpsfont release IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"after fpsfont release IDirectDraw7"); - if((_back!=NULL)&&(_zbuf!=NULL)) - _back->DeleteAttachedSurface(0x0,_zbuf); + if((scrn.pddsBack!=NULL)&&(scrn.pddsZBuf!=NULL)) + scrn.pddsBack->DeleteAttachedSurface(0x0,scrn.pddsZBuf); // Release the DDraw and D3D objects used by the app - RELEASE(_zbuf,dxgsg,"zbuffer",false); + RELEASE(scrn.pddsZBuf,dxgsg,"zbuffer",false); - PRINTREFCNT(_pDD,"before releasing d3d obj, IDirectDraw7"); - RELEASE(_d3d,dxgsg,"IDirect3D7 _d3d",false); //RELEASE_DOWN_TO_ZERO); - PRINTREFCNT(_pDD,"after releasing d3d obj, IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"before releasing d3d obj, IDirectDraw7"); + RELEASE(scrn.pD3D,dxgsg,"IDirect3D7 scrn.pD3D",false); //RELEASE_DOWN_TO_ZERO); + PRINTREFCNT(scrn.pDD,"after releasing d3d obj, IDirectDraw7"); - RELEASE(_back,dxgsg,"backbuffer",false); - RELEASE(_pri,dxgsg,"primary surface",false); + // is it wrong to explictly release scrn.pddsBack if it is part of complex surface chain (as in fullscrn mode)? + RELEASE(scrn.pddsBack,dxgsg,"backbuffer",false); + RELEASE(scrn.pddsPrimary,dxgsg,"primary surface",false); - PRINTREFCNT(_pDD,"after releasing all surfs, IDirectDraw7"); + PRINTREFCNT(scrn.pDD,"after releasing all surfs, IDirectDraw7"); } // for some reason, DLL_PROCESS_DETACH has not yet been sent to ddraw, so we can still call its fns // Do a safe check for releasing DDRAW. RefCount should be zero. - if (_pDD!=NULL) { + if (scrn.pDD!=NULL) { if(bRestoreDisplayMode) { - HRESULT hr = _pDD->RestoreDisplayMode(); + HRESULT hr = scrn.pDD->RestoreDisplayMode(); if(dxgsg_cat.is_spam()) dxgsg_cat.spam() << "dx_cleanup - Restoring original desktop DisplayMode\n"; if(FAILED(hr)) { @@ -6180,11 +6327,11 @@ dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled) { // if exit() called, there is definitely no more need for the IDDraw object, // so we can make sure it's fully released // note currently this is never called - RELEASE(_pDD,dxgsg,"IDirectDraw7 _pDD", RELEASE_DOWN_TO_ZERO); + RELEASE(scrn.pDD,dxgsg,"IDirectDraw7 scrn.pDD", RELEASE_DOWN_TO_ZERO); } else { // seems wrong to release to zero, since it might be being used somewhere else? - RELEASE(_pDD,dxgsg,"IDirectDraw7 _pDD", false); + RELEASE(scrn.pDD,dxgsg,"IDirectDraw7 scrn.pDD", false); if(refcnt>0) { if(dxgsg_cat.is_spam()) dxgsg_cat.debug() << "dx_cleanup - warning IDDraw7 refcnt = " << refcnt << ", should be zero!\n"; @@ -6199,32 +6346,32 @@ dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled) { //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: dx_setup_after_resize(RECT viewrect, HWND mwindow) { - if (_back == NULL) // nothing created yet + if (scrn.pddsBack == NULL) // nothing created yet return; // for safety, need some better error-cleanup here - assert((_pri!=NULL) && (_back!=NULL) && (_zbuf!=NULL)); + assert((scrn.pddsPrimary!=NULL) && (scrn.pddsBack!=NULL) && (scrn.pddsZBuf!=NULL)); DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd_back); DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd_zbuf); - _back->GetSurfaceDesc(&ddsd_back); - _zbuf->GetSurfaceDesc(&ddsd_zbuf); + scrn.pddsBack->GetSurfaceDesc(&ddsd_back); + scrn.pddsZBuf->GetSurfaceDesc(&ddsd_zbuf); ULONG refcnt; - if((_back!=NULL)&&(_zbuf!=NULL)) - _back->DeleteAttachedSurface(0x0,_zbuf); + if((scrn.pddsBack!=NULL)&&(scrn.pddsZBuf!=NULL)) + scrn.pddsBack->DeleteAttachedSurface(0x0,scrn.pddsZBuf); - RELEASE(_zbuf,dxgsg,"zbuffer",false); - RELEASE(_back,dxgsg,"backbuffer",false); - RELEASE(_pri,dxgsg,"primary surface",false); + RELEASE(scrn.pddsZBuf,dxgsg,"zbuffer",false); + RELEASE(scrn.pddsBack,dxgsg,"backbuffer",false); + RELEASE(scrn.pddsPrimary,dxgsg,"primary surface",false); - assert((_pri == NULL) && (_back == NULL) && (_zbuf == NULL)); - _view_rect = viewrect; + assert((scrn.pddsPrimary == NULL) && (scrn.pddsBack == NULL) && (scrn.pddsZBuf == NULL)); + scrn.view_rect = viewrect; - DWORD renderWid = _view_rect.right - _view_rect.left; - DWORD renderHt = _view_rect.bottom - _view_rect.top; + DWORD renderWid = scrn.view_rect.right - scrn.view_rect.left; + DWORD renderHt = scrn.view_rect.bottom - scrn.view_rect.top; ddsd_back.dwWidth = ddsd_zbuf.dwWidth = renderWid; ddsd_back.dwHeight = ddsd_zbuf.dwHeight = renderHt; @@ -6234,10 +6381,10 @@ dx_setup_after_resize(RECT viewrect, HWND mwindow) { ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; ddsd.dwFlags = DDSD_CAPS; - PRINTVIDMEM(_pDD,&ddsd.ddsCaps,"resize primary surf"); + PRINTVIDMEM(scrn.pDD,&ddsd.ddsCaps,"resize primary surf"); HRESULT hr; - if (FAILED(hr = _pDD->CreateSurface( &ddsd, &_pri, NULL ))) { + if (FAILED(hr = scrn.pDD->CreateSurface( &ddsd, &scrn.pddsPrimary, NULL ))) { dxgsg_cat.fatal() << "resize() - CreateSurface failed for primary : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } @@ -6247,7 +6394,7 @@ dx_setup_after_resize(RECT viewrect, HWND mwindow) { // our window is partially obscured by other windows. LPDIRECTDRAWCLIPPER Clipper; - if (FAILED(hr = _pDD->CreateClipper( 0, &Clipper, NULL ))) { + if (FAILED(hr = scrn.pDD->CreateClipper( 0, &Clipper, NULL ))) { dxgsg_cat.fatal() << "CreateClipper after resize failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); @@ -6256,7 +6403,7 @@ dx_setup_after_resize(RECT viewrect, HWND mwindow) { // clipper is internally referenced by the primary surface, so it is safe // to release our local reference to it. Clipper->SetHWnd( 0, mwindow ); - _pri->SetClipper( Clipper ); + scrn.pddsPrimary->SetClipper( Clipper ); Clipper->Release(); } @@ -6265,43 +6412,43 @@ dx_setup_after_resize(RECT viewrect, HWND mwindow) { ddsd_back.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; // just to make sure ddsd_back.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; - PRINTVIDMEM(_pDD,&ddsd_back.ddsCaps,"resize backbuffer surf"); + PRINTVIDMEM(scrn.pDD,&ddsd_back.ddsCaps,"resize backbuffer surf"); - if (FAILED(hr = _pDD->CreateSurface( &ddsd_back, &_back, NULL ))) { + if (FAILED(hr = scrn.pDD->CreateSurface( &ddsd_back, &scrn.pddsBack, NULL ))) { dxgsg_cat.fatal() << "resize() - CreateSurface failed for backbuffer : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } - PRINTVIDMEM(_pDD,&ddsd_back.ddsCaps,"resize zbuffer surf"); + PRINTVIDMEM(scrn.pDD,&ddsd_back.ddsCaps,"resize zbuffer surf"); // Recreate and attach a z-buffer. - if (FAILED(hr = _pDD->CreateSurface( &ddsd_zbuf, &_zbuf, NULL ))) { + if (FAILED(hr = scrn.pDD->CreateSurface( &ddsd_zbuf, &scrn.pddsZBuf, NULL ))) { dxgsg_cat.fatal() << "resize() - CreateSurface failed for Z buffer: result = " << ConvD3DErrorToString(hr) << endl; exit(1); } // Attach the z-buffer to the back buffer. - if ((hr = _back->AddAttachedSurface( _zbuf ) ) != DD_OK) { + if ((hr = scrn.pddsBack->AddAttachedSurface( scrn.pddsZBuf ) ) != DD_OK) { dxgsg_cat.fatal() << "resize() - AddAttachedSurface failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } - if ((hr = _d3dDevice->SetRenderTarget(_back,0x0) ) != DD_OK) { + if ((hr = scrn.pD3DDevice->SetRenderTarget(scrn.pddsBack,0x0) ) != DD_OK) { dxgsg_cat.fatal() << "resize() - SetRenderTarget failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } // Create the viewport D3DVIEWPORT7 vp = { 0, 0, renderWid, renderHt, 0.0f, 1.0f}; - hr = _d3dDevice->SetViewport( &vp ); + hr = scrn.pD3DDevice->SetViewport( &vp ); if (hr != DD_OK) { dxgsg_cat.fatal() << "SetViewport failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } - if(dx_show_fps_meter) - SetFPSMeterPosition(_view_rect); + if(_bShowFPSMeter) + SetFPSMeterPosition(scrn.view_rect); } bool refill_tex_callback(TextureContext *tc,void *void_dxgsg_ptr) { @@ -6329,8 +6476,12 @@ bool recreate_tex_callback(TextureContext *tc,void *void_dxgsg_ptr) { // Re-fill the contents of textures and vertex buffers // which just got restored now. - LPDIRECTDRAWSURFACE7 ddtex = dtc->CreateTexture(dxgsg->_d3dDevice, - dxgsg->_cNumTexPixFmts,dxgsg->_pTexPixFmts); + LPDIRECTDRAWSURFACE7 ddtex = +#ifdef USE_TEXFMTVEC + dtc->CreateTexture(dxgsg->scrn.pD3DDevice,scrn.TexPixFmts,&dxgsg->scrn.D3DDevDesc); +#else + dtc->CreateTexture(dxgsg->scrn.pD3DDevice,dxgsg->_cNumTexPixFmts,dxgsg->_pTexPixFmts,&dxgsg->scrn.D3DDevDesc); +#endif return ddtex!=NULL; } @@ -6343,7 +6494,7 @@ HRESULT DXGraphicsStateGuardian::DeleteAllVideoSurfaces(void) { ULONG refcnt; - if(dx_show_fps_meter) + if(_bShowFPSMeter) RELEASE(_fpsmeter_font_surf,dxgsg,"fpsmeter fontsurf",false); if(dxgsg_cat.is_debug()) @@ -6372,7 +6523,7 @@ HRESULT DXGraphicsStateGuardian::RestoreAllVideoSurfaces(void) { // note: could go through and just restore surfs that return IsLost() true // apparently that isnt as reliable w/some drivers tho - if (FAILED(hr = _pDD->RestoreAllSurfaces() )) { + if (FAILED(hr = scrn.pDD->RestoreAllSurfaces() )) { dxgsg_cat.fatal() << "RestoreAllSurfs failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } @@ -6380,7 +6531,7 @@ HRESULT DXGraphicsStateGuardian::RestoreAllVideoSurfaces(void) { // cant access template in libpanda.dll directly due to vc++ limitations, use traverser to get around it traverse_prepared_textures(refill_tex_callback,this); - if(dx_show_fps_meter) + if(_bShowFPSMeter) FillFPSMeterTexture(); if(dxgsg_cat.is_debug()) @@ -6395,7 +6546,7 @@ HRESULT DXGraphicsStateGuardian::RestoreAllVideoSurfaces(void) { // Description: Repaint primary buffer from back buffer //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian::show_frame(void) { - if(_pri==NULL) + if(scrn.pddsPrimary==NULL) return; DO_PSTATS_STUFF(PStatTimer timer(_win->_swap_pcollector)); // this times just the flip, so it must go here in dxgsg, instead of wdxdisplay, which would time the whole frame @@ -6432,7 +6583,7 @@ void DXGraphicsStateGuardian::show_full_screen_frame(void) { // bugbug: dont we want triple buffering instead of wasting time // waiting for vsync? - hr = _pri->Flip( NULL, dwFlipFlags); + hr = scrn.pddsPrimary->Flip( NULL, dwFlipFlags); if(FAILED(hr)) { if((hr == DDERR_SURFACELOST) || (hr == DDERR_SURFACEBUSY)) { @@ -6475,10 +6626,10 @@ void DXGraphicsStateGuardian::show_windowed_frame(void) { bltfx.dwDDFX |= DDBLTFX_NOTEARING; // hmm, does any driver actually recognize this flag? } - hr = _pri->Blt( &_view_rect, _back, NULL, DDBLT_DDFX | DDBLT_WAIT, &bltfx ); + hr = scrn.pddsPrimary->Blt( &scrn.view_rect, scrn.pddsBack, NULL, DDBLT_DDFX | DDBLT_WAIT, &bltfx ); if (dx_sync_video) { - HRESULT hr = _pDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); + HRESULT hr = scrn.pDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); if(hr != DD_OK) { dxgsg_cat.error() << "WaitForVerticalBlank() failed : " << ConvD3DErrorToString(hr) << endl; exit(1); @@ -6498,7 +6649,7 @@ void DXGraphicsStateGuardian::show_windowed_frame(void) { bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { - HRESULT hr = _pDD->TestCooperativeLevel(); + HRESULT hr = scrn.pDD->TestCooperativeLevel(); if(SUCCEEDED(_last_testcooplevel_result)) { if(SUCCEEDED(hr)) // this means this was just a safety check, dont need to restore surfs @@ -6512,7 +6663,7 @@ bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { // The following error is returned only for exclusivemode apps. // DDERR_NOEXCLUSIVEMODE: Some other app took exclusive mode. - hr = _pDD->TestCooperativeLevel(); + hr = scrn.pDD->TestCooperativeLevel(); HRESULT expected_error = (dx_full_screen ? DDERR_NOEXCLUSIVEMODE : DDERR_EXCLUSIVEMODEALREADYSET); @@ -6583,11 +6734,11 @@ bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { // Description: we receive the new x and y position of the client //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian::adjust_view_rect(int x, int y) { - if (_view_rect.left != x || _view_rect.top != y) { - _view_rect.right = x + _view_rect.right - _view_rect.left; - _view_rect.left = x; - _view_rect.bottom = y + _view_rect.bottom - _view_rect.top; - _view_rect.top = y; + if (scrn.view_rect.left != x || scrn.view_rect.top != y) { + scrn.view_rect.right = x + scrn.view_rect.right - scrn.view_rect.left; + scrn.view_rect.left = x; + scrn.view_rect.bottom = y + scrn.view_rect.bottom - scrn.view_rect.top; + scrn.view_rect.top = y; // set_clipper(clip_rect); } @@ -7062,14 +7213,14 @@ prepare_geom_node(GeomNode *node) { HRESULT hr; LPDIRECT3D7 pD3D; - assert(_d3dDevice!=NULL); - hr=_d3dDevice->GetDirect3D(&pD3D); + assert(scrn.pD3DDevice!=NULL); + hr=scrn.pD3DDevice->GetDirect3D(&pD3D); assert(!FAILED(hr)); LPDIRECT3DVERTEXBUFFER7 pD3DVertexBuffer; DX_DECLARE_CLEAN(D3DVERTEXBUFFERDESC, VBdesc); VBdesc.dwCaps = D3DVBCAPS_WRITEONLY; - VBdesc.dwCaps |= _bIsTNLDevice ? 0x0 : D3DVBCAPS_SYSTEMMEMORY; + VBdesc.dwCaps |= scrn.bIsTNLDevice ? 0x0 : D3DVBCAPS_SYSTEMMEMORY; VBdesc.dwFVF=fvfFlags; VBdesc.dwNumVertices=cNumVerts; @@ -7082,7 +7233,7 @@ prepare_geom_node(GeomNode *node) { dx_gnc->_pVB = pD3DVertexBuffer; - if(!_bIsTNLDevice) { + if(!scrn.bIsTNLDevice) { // create VB for ProcessVerts to xform to fvfFlags&=~D3DFVF_XYZ; // switch to xformed vert type @@ -7151,7 +7302,7 @@ prepare_geom_node(GeomNode *node) { assert(cNumVerts==dx_gnc->_num_verts); - hr=dx_gnc->_pVB->Optimize(_d3dDevice,0x0); + hr=dx_gnc->_pVB->Optimize(scrn.pD3DDevice,0x0); if(FAILED(hr)) { dxgsg_cat.error() << "error optimizing vertex buffer: " << ConvD3DErrorToString(hr) << endl; delete dx_gnc; @@ -7208,10 +7359,10 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { #ifdef _DEBUG assert(dx_gnc->_pVB!=NULL); - assert((!_bIsTNLDevice)==(dx_gnc->_pXformed_VB!=NULL)); + assert((!scrn.bIsTNLDevice)==(dx_gnc->_pXformed_VB!=NULL)); #endif - if(!_bIsTNLDevice) { + if(!scrn.bIsTNLDevice) { HRESULT hr; DWORD PVOp=D3DVOP_CLIP | D3DVOP_TRANSFORM | D3DVOP_EXTENTS; @@ -7228,7 +7379,7 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { PVOp|=D3DVOP_LIGHT; } - hr=dx_gnc->_pXformed_VB->ProcessVertices(PVOp,0,dx_gnc->_num_verts,dx_gnc->_pVB,0,_d3dDevice,0x0); + hr=dx_gnc->_pXformed_VB->ProcessVertices(PVOp,0,dx_gnc->_num_verts,dx_gnc->_pVB,0,scrn.pD3DDevice,0x0); if(FAILED(hr)) { dxgsg_cat.error() << "error in ProcessVertices: " << ConvD3DErrorToString(hr) << endl; exit(1); @@ -7236,7 +7387,7 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { // disable clipping, since VB is already xformed and clipped if(_clipping_enabled) - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, false); + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, false); } // assume we need gouraud for now. we can make this more complex to select flat conditionally later @@ -7251,20 +7402,20 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { DPInfo *dpi=&dx_gnc->_PrimInfo[i]; LPDIRECT3DVERTEXBUFFER7 pVB; - if(_bIsTNLDevice) { + if(scrn.bIsTNLDevice) { pVB=dx_gnc->_pVB; } else { pVB=dx_gnc->_pXformed_VB; } - HRESULT hr = _d3dDevice->DrawPrimitiveVB(dpi->primtype,pVB,cur_startvert,dpi->nVerts,0x0); - TestDrawPrimFailure(DrawPrim,hr,_pDD,dpi->nVerts,0); + HRESULT hr = scrn.pD3DDevice->DrawPrimitiveVB(dpi->primtype,pVB,cur_startvert,dpi->nVerts,0x0); + TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,dpi->nVerts,0); cur_startvert+=dpi->nVerts; } - if((!_bIsTNLDevice) && _clipping_enabled) - _d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, true); + if((!scrn.bIsTNLDevice) && _clipping_enabled) + scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, true); // Also draw all the dynamic Geoms. for (i = 0; i < dx_gnc->_other_geoms.size(); i++) { diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index bba968b4f4..ea1c6d4082 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -16,8 +16,8 @@ // //////////////////////////////////////////////////////////////////// -#ifndef DXGRAPHICSSTATEGUARDIAN8_H -#define DXGRAPHICSSTATEGUARDIAN8_H +#ifndef DXGRAPHICSSTATEGUARDIAN_H +#define DXGRAPHICSSTATEGUARDIAN_H //#define GSG_VERBOSE @@ -38,11 +38,41 @@ #include #include -#include "dxGeomNodeContext8.h" -#include "dxTextureContext8.h" +#include "dxGeomNodeContext.h" +#include "dxTextureContext.h" +#include extern char * ConvD3DErrorToString(const HRESULT &error); // defined in wdxGraphicsPipe.cxx +// for dwSupportedScreenDepthsMask +#define X1R5G5B5_FLAG 0x1 +#define R5G6B5_FLAG 0x2 +#define X8R8G8B8_FLAG 0x4 +#define R8G8B8_FLAG 0x8 + +typedef struct { + LPDIRECT3DDEVICE8 pD3DDevice; + LPDIRECT3D8 pD3D8; + LPDIRECTDRAWSURFACE7 pddsPrimary,pddsBack,pddsZBuf; + HWND hWnd; + HMONITOR hMon; + RECT view_rect,clip_rect; + DWORD MaxAvailVidMem; + bool bIsLowVidMemCard; + bool bIsTNLDevice; + ushort depth_buffer_bitdepth; //GetSurfaceDesc is not reliable so must store this explicitly + ushort CardIDNum; // its posn in DisplayArray, for dbgprint purposes + DDDEVICEIDENTIFIER2 DXDeviceID; +// D3DDEVICEDESC8 D3DDevDesc; + DWORD dwSupportedScreenDepthsMask; + D3DCAPS8 d3dcaps; + D3DDISPLAYMODE DisplayMode; +#ifdef USE_TEXFMTVEC + DDPixelFormatVec TexPixFmts; +#endif +} DXScreenData; +// typedef vector ScreenDataVector; + class PlaneNode; class Light; @@ -61,7 +91,7 @@ INLINE ostream &operator << (ostream &out, GLenum v) { #define DX_DECLARE_CLEAN(type, var) \ type var; \ - ZeroMemory(&var, sizeof(type)); \ + ZeroMemory(&var, sizeof(type)); \ var.dwSize = sizeof(type); // #define DEBUG_RELEASES @@ -115,6 +145,10 @@ extern void dbgPrintVidMem(LPDIRECTDRAW7 pDD, LPDDSCAPS2 lpddsCaps,const char *p #define PRINTVIDMEM(pDD,pCaps,pMsg) #endif +#ifndef D3DERRORSTRING +#define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__"), hr=" << DXGetErrorString8(HRESULT) << ": " << DXGetErrorDescription8(HRESULT) << endl +#endif + //////////////////////////////////////////////////////////////////// // Class : DXGraphicsStateGuardian // Description : A GraphicsStateGuardian specialized for rendering @@ -123,6 +157,8 @@ extern void dbgPrintVidMem(LPDIRECTDRAW7 pDD, LPDDSCAPS2 lpddsCaps,const char *p //////////////////////////////////////////////////////////////////// class EXPCL_PANDADX DXGraphicsStateGuardian : public GraphicsStateGuardian { friend class wdxGraphicsWindow; + friend class wdxGraphicsPipe; + friend class wdxGraphicsWindowGroup; friend class DXTextureContext; public: @@ -137,9 +173,9 @@ public: virtual void prepare_display_region(); virtual void render_frame(); - virtual void render_scene(Node *root, ProjectionNode *projnode); + virtual void render_scene(Node *root, LensNode *projnode); virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, ProjectionNode *projnode, + Node *subgraph, LensNode *projnode, const AllTransitionsWrapper &net_trans); virtual void render_subgraph(RenderTraverser *traverser, Node *subgraph, @@ -227,9 +263,15 @@ public: public: // recreate_tex_callback needs these to be public - LPDIRECT3DDEVICE7 _d3dDevice; + LPDIRECT3DDEVICE7 _pCurD3DDevice; //this needs to be set every device iteration + LPDIRECTDRAW7 _pDD; + DXScreenData scrn; + +#ifndef USE_TEXFMTVEC LPDDPIXELFORMAT _pTexPixFmts; int _cNumTexPixFmts; +#endif +// D3DDEVICEDESC7 _D3DDevDesc; protected: void free_pointers(); // free local internal buffers @@ -241,8 +283,6 @@ protected: void set_draw_buffer(const RenderBuffer &rb); void set_read_buffer(const RenderBuffer &rb); - void bind_texture(TextureContext *tc); - // for storage of the flexible vertex format char *_pCurFvfBufPtr,*_pFvfBufBasePtr; INLINE void add_to_FVFBuf(void *data, size_t bytes) ; @@ -250,15 +290,23 @@ protected: bool _dx_ready; HRESULT _last_testcooplevel_result; + +/* + moved to per display data bool _bIsTNLDevice; LPDIRECTDRAWSURFACE7 _back; LPDIRECTDRAWSURFACE7 _zbuf; - LPDIRECT3D7 _d3d; LPDIRECTDRAWSURFACE7 _pri; - LPDIRECTDRAW7 _pDD; - RECT _view_rect; - RECT clip_rect; + LPDIRECT3D7 _d3d; + LPDIRECTDRAW7 _pDD; + RECT _view_rect; + RECT clip_rect; +*/ + LPDIRECT3D7 _pCurD3D7; + LPDIRECTDRAW7 _pCurDD; + bool _bShowFPSMeter; + HDC _front_hdc; DXTextureContext *_pCurTexContext; @@ -267,8 +315,6 @@ protected: RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation - D3DDEVICEDESC7 _D3DDevDesc; - void GenerateSphere(void *pVertexSpace,DWORD dwVertSpaceByteSize, void *pIndexSpace,DWORD dwIndexSpaceByteSize, D3DVECTOR *pCenter, float fRadius, @@ -329,7 +375,6 @@ protected: Colorf _issued_color; // WBD ADDED D3DCOLOR _issued_color_D3DCOLOR; // WBD ADDED D3DCOLOR _d3dcolor_clear_value; - D3DSHADEMODE _CurShadeMode; bool _bDrawPrimDoSetupVertexBuffer; // if true, draw methods just copy vertex data into pCurrentGeomContext @@ -370,10 +415,7 @@ protected: bool _fog_enabled; /* TODO: cache fog state - float _fog_start; - float _fog_end; - float _fog_density; - float _fog_color; + float _fog_start,_fog_end,_fog_density,float _fog_color; */ float _alpha_func_ref; D3DCMPFUNC _alpha_func; @@ -398,7 +440,6 @@ protected: int _decal_level; RenderModeProperty::Mode _current_fill_mode; //poinr/wireframe/solid - GraphicsChannel *_panda_gfx_channel; // cache the 1 channel dx supports // Cur Texture State @@ -452,12 +493,13 @@ public: static void init_type(void); virtual TypeHandle get_type(void) const; virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - - LPDIRECT3DDEVICE7 GetD3DDevice() { return _d3dDevice; } - LPDIRECTDRAW7 GetDDInterface() { return _pDD; } - LPDIRECTDRAWSURFACE7 GetBackBuffer() { return _back; } +/* + LPDIRECT3DDEVICE7 GetD3DDevice() { return scrn.pD3DDevice; } + LPDIRECTDRAW7 GetDDInterface() { return scrn.pDD; } + LPDIRECTDRAWSURFACE7 GetBackBuffer() { return scrn.pddsBackBuffer; } LPDIRECTDRAWSURFACE7 GetZBuffer() { return _zbuf; } - INLINE void Set_HDC(HDC hdc) { _front_hdc = hdc; } +*/ +// INLINE void Set_HDC(HDC hdc) { _front_hdc = hdc; } void adjust_view_rect(int x, int y); INLINE void SetDXReady(bool stat) { _dx_ready = stat; } INLINE bool GetDXReady(void) { return _dx_ready;} @@ -472,13 +514,14 @@ public: void show_frame(); void show_full_screen_frame(); void show_windowed_frame(); - void dx_init( LPDIRECTDRAW7 context, +/* void dx_init( LPDIRECTDRAW7 context, LPDIRECTDRAWSURFACE7 pri, LPDIRECTDRAWSURFACE7 back, LPDIRECTDRAWSURFACE7 zbuf, LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 d3dDevice, - RECT viewrect); + RECT viewrect); */ + void dx_init(void); friend HRESULT CALLBACK EnumTexFmtsCallback( LPDDPIXELFORMAT pddpf, VOID* param ); @@ -488,7 +531,7 @@ private: #define ISPOW2(X) (((X) & ((X)-1))==0) -#include "dxGraphicsStateGuardian8.I" +#include "dxGraphicsStateGuardian.I" #endif diff --git a/panda/src/dxgsg8/dxTextureContext8.cxx b/panda/src/dxgsg8/dxTextureContext8.cxx index 8598bf86b7..6e845c148b 100644 --- a/panda/src/dxgsg8/dxTextureContext8.cxx +++ b/panda/src/dxgsg8/dxTextureContext8.cxx @@ -18,9 +18,9 @@ #include #include -#include "dxTextureContext8.h" -#include "config_dxgsg8.h" -#include "dxGraphicsStateGuardian8.h" +#include "dxTextureContext.h" +#include "config_dxgsg.h" +#include "dxGraphicsStateGuardian.h" #include "pnmImage.h" //#define FORCE_16bpp_1555 @@ -971,24 +971,38 @@ HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf) // gets the attributes of the texture from the bitmap, creates the // texture, and then copies the bitmap into the texture. //----------------------------------------------------------------------------- -LPDIRECTDRAWSURFACE7 DXTextureContext:: -CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts) { +LPDIRECTDRAWSURFACE7 DXTextureContext::CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, +#ifdef USE_TEXFMTVEC + DDPixelFormatVec &TexFmts,LPD3DDEVICEDESC7 pD3DDevDesc) +#else + int cNumTexPixFmts, DDPIXELFORMAT *pTexFmts,LPD3DDEVICEDESC7 pD3DDevDesc) +#endif + { HRESULT hr; - int i; - PixelBuffer *pbuf = _texture->_pbuffer; - int cNumAlphaBits; // number of alpha bits in texture pixfmt - + int i,cNumAlphaBits; // number of alpha bits in texture pixfmt DDPIXELFORMAT *pDesiredPixFmt; LPDIRECTDRAWSURFACE7 pddsRender; LPDIRECTDRAW7 pDD = NULL; - - DDPIXELFORMAT TexFmtsArr[MAX_DX_TEXPIXFMTS]; - ConversionType ConvNeeded; + assert(_texture!=NULL); + + PixelBuffer *pbuf = _texture->_pbuffer; + +#ifdef USE_TEXFMTVEC + int cNumTexPixFmts=TexturePixelFormats.size(); +#endif + DDPIXELFORMAT *pTexPixFmts = new DDPIXELFORMAT[cNumTexPixFmts]; + // make local copy of array so I can muck with it during searches for this texture fmt - memcpy(TexFmtsArr,pTexPixFmts,cNumTexPixFmts*sizeof(DDPIXELFORMAT)); - pTexPixFmts=TexFmtsArr; + // (such as marking pixfmts that no search will be interested in) + // probably should do this faster way + +#ifdef USE_TEXFMTVEC + memcpy(pTexPixFmts,&TexturePixelFormats[0],cNumTexPixFmts*sizeof(DDPIXELFORMAT)); +#else + memcpy(pTexPixFmts,pTexFmts,cNumTexPixFmts*sizeof(DDPIXELFORMAT)); +#endif // bpp indicates requested fmt, not pixbuf fmt DWORD bpp = get_bits_per_pixel(pbuf->get_format(), &cNumAlphaBits); @@ -1006,12 +1020,10 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT DWORD dwOrigWidth = (DWORD)pbuf->get_xsize(); DWORD dwOrigHeight = (DWORD)pbuf->get_ysize(); - // Get the device caps so we can check if the device has any constraints - // when using textures - D3DDEVICEDESC7 devDesc; - if(FAILED( pd3dDevice->GetCaps( &devDesc ) )) { - goto error_exit; - } + // Use the device caps so we can check if the device has any constraints + // when using textures. + + assert((pD3DDevDesc->dwMaxTextureWidth>0) && (pD3DDevDesc->dwMaxTextureHeight>0)); // Setup the new surface desc for the texture. Note how we are using the // texture manage attribute, so Direct3D does alot of dirty work for us @@ -1056,31 +1068,31 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT if(!ISPOW2(ddsd.dwWidth) || !ISPOW2(ddsd.dwHeight)) { dxgsg_cat.error() << "ERROR: texture dimensions are not a power of 2 for " << _tex->get_name() << "!!!!! \n"; -#ifdef _DEBUG - exit(1); // want to catch badtexsize errors -#else - goto error_exit; -#endif + #ifdef _DEBUG + exit(1); // want to catch badtexsize errors + #else + goto error_exit; + #endif } bool bShrinkOriginal; - bShrinkOriginal=false; - if((dwOrigWidth>devDesc.dwMaxTextureWidth)||(dwOrigHeight>devDesc.dwMaxTextureHeight)) { -#ifdef _DEBUG - dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !!\n" - << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," < ("<< devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !\n"; -#endif - if(dwOrigWidth>devDesc.dwMaxTextureWidth) - ddsd.dwWidth=devDesc.dwMaxTextureWidth; - if(dwOrigHeight>devDesc.dwMaxTextureHeight) - ddsd.dwHeight=devDesc.dwMaxTextureHeight; + if((dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth)||(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight)) { + #ifdef _DEBUG + dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !!\n" + << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," < ("<< pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !\n"; + #endif + + if(dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth) + ddsd.dwWidth=pD3DDevDesc->dwMaxTextureWidth; + if(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight) + ddsd.dwHeight=pD3DDevDesc->dwMaxTextureHeight; bShrinkOriginal=true; } // checks for SQUARE reqmt (nvidia riva128 needs this) - if((ddsd.dwWidth != ddsd.dwHeight) && (devDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) { + if((ddsd.dwWidth != ddsd.dwHeight) && (pD3DDevDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) { // assume pow2 textures. sum exponents, divide by 2 rounding down to get sq size int i,width_exp,height_exp; @@ -1130,7 +1142,8 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT szErrorMsg = "CreateTexture failed: couldn't find compatible Tex DDPIXELFORMAT!\n"; - dxgsg_cat.spam() << "CreateTexture handling bitdepth: " << bpp << " alphabits: " << cNumAlphaBits << "\n"; + if(dxgsg_cat.is_spam()) + dxgsg_cat.spam() << "CreateTexture handling bitdepth: " << bpp << " alphabits: " << cNumAlphaBits << "\n"; // Mark formats I dont want to deal with for(i=0,pCurPixFmt=pTexPixFmts;idwFlags & DDPF_RGB)&&(pCurPixFmt->dwRGBBitCount==24)) { ConvNeeded=((cNumColorChannels==3) ? Conv24to24 : Conv32to24); @@ -1230,13 +1241,10 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT } } -#ifdef _DEBUG - if(!dx_force_16bpptextures) -#endif - - // no 24-bit fmt. look for 32 bit fmt (note: this is memory-hogging choice - // instead I could look for memory-conserving 16-bit fmt). - // check mask to ensure ARGB, not RGBA (which I am not handling here) + if(!dx_force_16bpptextures) { + // no 24-bit fmt. look for 32 bit fmt (note: this is memory-hogging choice + // instead I could look for memory-conserving 16-bit fmt). + // check mask to ensure ARGB, not RGBA (which I am not handling here) for(i=0,pCurPixFmt=pTexPixFmts;idwRGBBitCount==32) && (pCurPixFmt->dwFlags & DDPF_RGB) && ((pCurPixFmt->dwRBitMask|pCurPixFmt->dwGBitMask|pCurPixFmt->dwBBitMask)==0xFFFFFF) @@ -1246,6 +1254,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT goto found_matching_format; } } + } // no 24-bit or 32 fmt. look for 16 bit fmt for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) && (pCurPixFmt->dwFlags & DDPF_LUMINANCE)) { @@ -1375,9 +1380,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT // look for native lum fmt assert(cNumAlphaBits==0); // dont handle those other 8bit lum fmts like 4-4, since 16 8-8 is usually supported too -#ifdef _DEBUG if(!dx_force_16bpptextures) -#endif { for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==8) && (pCurPixFmt->dwFlags & DDPF_LUMINANCE) && @@ -1404,15 +1407,16 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT } } - // find compatible 16bpp fmt, just look for any 565, then 0555 + // find compatible 16bpp fmt, just look for any 565, then 0555 DWORD dwMasks[2] = {0xF800, 0x7C00}; + ConversionType ConvType[2] = {ConvLum8to16_0565,ConvLum8to16_0555}; for(DWORD modenum=0;modenum<2;modenum++) for(i=0,pCurPixFmt=&pTexPixFmts[0];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_RGB) && (!(pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)) && (pCurPixFmt->dwRBitMask==dwMasks[modenum])) { - ConvNeeded=ConvLum8to16_0565; + ConvNeeded=ConvType[modenum]; goto found_matching_format; } } @@ -1481,7 +1485,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT else ft=Texture::FT_linear; } - if((ft==Texture::FT_linear) && !(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR)) + if((ft==Texture::FT_linear) && !(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR)) ft=Texture::FT_nearest; _tex->set_magfilter(ft); @@ -1514,26 +1518,26 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT ft=Texture::FT_linear; } - assert((devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST)!=0); + assert((pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST)!=0); switch(ft) { case Texture::FT_nearest_mipmap_linear: - if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST)) + if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST)) ft=Texture::FT_nearest_mipmap_nearest; break; case Texture::FT_linear_mipmap_nearest: - if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR)) + if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR)) ft=Texture::FT_nearest_mipmap_nearest; break; case Texture::FT_linear_mipmap_linear: - if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR)) { - if(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR) + if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR)) { + if(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR) ft=Texture::FT_linear_mipmap_nearest; else ft=Texture::FT_nearest_mipmap_nearest; // if you cant do linear in a level, you probably cant do linear b/w levels, so just do nearest-all } break; case Texture::FT_linear: - if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR)) + if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR)) ft=Texture::FT_nearest; break; } @@ -1543,14 +1547,14 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT uint aniso_degree; aniso_degree=1; - if(devDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANISOTROPY) { + if(pD3DDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANISOTROPY) { aniso_degree=_tex->get_anisotropic_degree(); - if((aniso_degree>devDesc.dwMaxAnisotropy) + if((aniso_degree>pD3DDevDesc->dwMaxAnisotropy) #ifdef _DEBUG || dx_force_anisotropic_filtering #endif ) - aniso_degree=devDesc.dwMaxAnisotropy; + aniso_degree=pD3DDevDesc->dwMaxAnisotropy; } _tex->set_anisotropic_degree(aniso_degree); #ifdef _DEBUG @@ -1564,7 +1568,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT dxgsg_cat.debug() << "CreateTexture: generating mipmaps for "<< _tex->get_name() << endl; } - if(devDesc.dwDevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) { + if(pD3DDevDesc->dwDevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) { // must assign a texture to a specific stage // for now I'm just going to use stage 0 for all ddsd.dwTextureStage=0; @@ -1594,6 +1598,8 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT // Done with DDraw pDD->Release(); + delete [] pTexPixFmts; + // Return the newly created texture return _surface; @@ -1606,6 +1612,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT _surface = NULL; } + delete [] pTexPixFmts; return NULL; } diff --git a/panda/src/dxgsg8/dxTextureContext8.h b/panda/src/dxgsg8/dxTextureContext8.h index e160686e5f..dc670ce1d1 100644 --- a/panda/src/dxgsg8/dxTextureContext8.h +++ b/panda/src/dxgsg8/dxTextureContext8.h @@ -16,8 +16,8 @@ // //////////////////////////////////////////////////////////////////// -#ifndef DXTEXTURECONTEXT8_H -#define DXTEXTURECONTEXT8_H +#ifndef DXTEXTURECONTEXT_H +#define DXTEXTURECONTEXT_H #include @@ -32,13 +32,23 @@ #include #define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h -#include +#include #undef WIN32_LEAN_AND_MEAN +#ifndef D3DERRORSTRING +#define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__"), hr=" << DXGetErrorString8(HRESULT) << ": " << DXGetErrorDescription8(HRESULT) << endl +#endif + #include #include +//#define USE_TEXFMTVEC // doesnt work now, crashes in destructor + +#ifdef USE_TEXFMTVEC +typedef pvector DDPixelFormatVec; +#else #define MAX_DX_TEXPIXFMTS 20 // should be enough for any card +#endif //////////////////////////////////////////////////////////////////// // Class : DXTextureContext @@ -55,7 +65,13 @@ public: LPDIRECTDRAWSURFACE7 _surface; Texture *_tex; // ptr to parent, primarily for access to namestr - LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts); +// static is_unused_texpixelformat(DDPIXELFORMAT *) + +#ifdef USE_TEXFMTVEC + LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, DDPixelFormatVec &TexFmts,LPD3DDEVICEDESC7 pD3DDevDesc); +#else + LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, DDPIXELFORMAT *pTexFmts,LPD3DDEVICEDESC7 pD3DDevDesc); +#endif bool _bHasMipMaps; DWORD _PixBufConversionType; // enum ConversionType @@ -85,5 +101,6 @@ private: static TypeHandle _type_handle; }; + #endif diff --git a/panda/src/wdxdisplay8/Sources.pp b/panda/src/wdxdisplay8/Sources.pp index 3c846e580b..33162da8c5 100644 --- a/panda/src/wdxdisplay8/Sources.pp +++ b/panda/src/wdxdisplay8/Sources.pp @@ -6,15 +6,24 @@ #if $[BUILD_DX8] #begin lib_target - #define TARGET wdxdisplay8 - #define LOCAL_LIBS dxgsg8 + #define TARGET wdxdisplay + #define LOCAL_LIBS \ + dxgsg #define COMBINED_SOURCES $[TARGET]_composite1.cxx + + // need to install these due to external projects that link directly with libpandadx (bartop) + #define INSTALL_HEADERS \ + config_wdxdisplay8.h wdxGraphicsPipe8.h wdxGraphicsWindow8.h - #define SOURCES \ - config_wdxdisplay8.h wdxGraphicsPipe8.h wdxGraphicsWindow8.cxx wdxGraphicsWindow8.h + #define INCLUDED_SOURCES \ + config_wdxdisplay8.cxx wdxGraphicsPipe8.cxx - #define INCLUDED_SOURCES config_wdxdisplay8.cxx wdxGraphicsPipe8.cxx + // note SOURCES shoult NOT include INCLUDED_SOURCES, that would cause a double build + // SOURCES should be headers and separately-built cxx files + // build wdxGraphicsWindow.cxx separately since its big + + #define SOURCES wdxGraphicsWindow8.cxx $[INSTALL_HEADERS] #end lib_target #endif diff --git a/panda/src/wdxdisplay8/config_wdxdisplay8.cxx b/panda/src/wdxdisplay8/config_wdxdisplay8.cxx index 97c36b56bb..f66d6157e5 100644 --- a/panda/src/wdxdisplay8/config_wdxdisplay8.cxx +++ b/panda/src/wdxdisplay8/config_wdxdisplay8.cxx @@ -31,6 +31,8 @@ ConfigureFn(config_wdxdisplay) { bool dx_force_16bpp_zbuffer = config_wdxdisplay.GetBool("dx-force-16bpp-zbuffer", false); bool bResponsive_minimized_fullscreen_window = config_wdxdisplay.GetBool("responsive-minimized-fullscreen-window",false); +bool dx_preserve_fpu_state = config_wdxdisplay.GetBool("dx-preserve-fpu-state", false); +int dx_preferred_deviceID = config_wdxdisplay.GetInt("dx-preferred-deviceID", -1); extern void AtExitFn(void); diff --git a/panda/src/wdxdisplay8/config_wdxdisplay8.h b/panda/src/wdxdisplay8/config_wdxdisplay8.h index 2393dede1f..3bc3759240 100644 --- a/panda/src/wdxdisplay8/config_wdxdisplay8.h +++ b/panda/src/wdxdisplay8/config_wdxdisplay8.h @@ -27,6 +27,8 @@ NotifyCategoryDecl(wdxdisplay, EXPCL_PANDADX, EXPTP_PANDADX); extern bool bResponsive_minimized_fullscreen_window; extern bool dx_force_16bpp_zbuffer; +extern bool dx_preserve_fpu_state; +extern int dx_preferred_deviceID; extern Filename get_icon_filename(); extern Filename get_mono_cursor_filename(); extern Filename get_color_cursor_filename(); diff --git a/panda/src/wdxdisplay8/wdxGraphicsPipe8.cxx b/panda/src/wdxdisplay8/wdxGraphicsPipe8.cxx index 499b4f9d79..2425f3d720 100644 --- a/panda/src/wdxdisplay8/wdxGraphicsPipe8.cxx +++ b/panda/src/wdxdisplay8/wdxGraphicsPipe8.cxx @@ -20,7 +20,7 @@ #include "config_wdxdisplay8.h" #include #include -#include +#include //////////////////////////////////////////////////////////////////// // Static variables @@ -107,1497 +107,4 @@ find_window(HWND win) { return NULL; } -extern char * ConvD3DErrorToString(const HRESULT &error) { - switch(error) { - case E_FAIL: - return "Unspecified error E_FAIL"; - - case DD_OK: - return "No error.\0"; - case D3DERR_BADMAJORVERSION : // (700) - return "D3DERR_BADMAJORVERSION";//: // (700) - case D3DERR_BADMINORVERSION : // (701) - return "D3DERR_BADMINORVERSION";//: // (701) - case D3DERR_INVALID_DEVICE : // (705) - return "D3DERR_INVALID_DEVICE";//: // (705) - case D3DERR_INITFAILED : // (706) - return "D3DERR_INITFAILED";//: // (706) - case D3DERR_DEVICEAGGREGATED : // (707) - return "D3DERR_DEVICEAGGREGATED";//: // (707) - case D3DERR_EXECUTE_CREATE_FAILED : // (710) - return "D3DERR_EXECUTE_CREATE_FAILED";//: // (710) - case D3DERR_EXECUTE_DESTROY_FAILED : // (711) - return "D3DERR_EXECUTE_DESTROY_FAILED";//: // (711) - case D3DERR_EXECUTE_LOCK_FAILED : // (712) - return "D3DERR_EXECUTE_LOCK_FAILED";//: // (712) - case D3DERR_EXECUTE_UNLOCK_FAILED : // (713) - return "D3DERR_EXECUTE_UNLOCK_FAILED";//: // (713) - case D3DERR_EXECUTE_LOCKED : // (714) - return "D3DERR_EXECUTE_LOCKED";//: // (714) - case D3DERR_EXECUTE_NOT_LOCKED : // (715) - return "D3DERR_EXECUTE_NOT_LOCKED";//: // (715) - case D3DERR_EXECUTE_FAILED : // (716) - return "D3DERR_EXECUTE_FAILED";//: // (716) - case D3DERR_EXECUTE_CLIPPED_FAILED : // (717) - return "D3DERR_EXECUTE_CLIPPED_FAILED";//: // (717) - case D3DERR_TEXTURE_NO_SUPPORT : // (720) - return "D3DERR_TEXTURE_NO_SUPPORT";//: // (720) - case D3DERR_TEXTURE_CREATE_FAILED : // (721) - return "D3DERR_TEXTURE_CREATE_FAILED";//: // (721) - case D3DERR_TEXTURE_DESTROY_FAILED : // (722) - return "D3DERR_TEXTURE_DESTROY_FAILED";//: // (722) - case D3DERR_TEXTURE_LOCK_FAILED : // (723) - return "D3DERR_TEXTURE_LOCK_FAILED";//: // (723) - case D3DERR_TEXTURE_UNLOCK_FAILED : // (724) - return "D3DERR_TEXTURE_UNLOCK_FAILED";//: // (724) - case D3DERR_TEXTURE_LOAD_FAILED : // (725) - return "D3DERR_TEXTURE_LOAD_FAILED";//: // (725) - case D3DERR_TEXTURE_SWAP_FAILED : // (726) - return "D3DERR_TEXTURE_SWAP_FAILED";//: // (726) - case D3DERR_TEXTURE_LOCKED : // (727) - return "D3DERR_TEXTURE_LOCKED";//: // (727) - case D3DERR_TEXTURE_NOT_LOCKED : // (728) - return "D3DERR_TEXTURE_NOT_LOCKED";//: // (728) - case D3DERR_TEXTURE_GETSURF_FAILED : // (729) - return "D3DERR_TEXTURE_GETSURF_FAILED";//: // (729) - case D3DERR_MATRIX_CREATE_FAILED : // (730) - return "D3DERR_MATRIX_CREATE_FAILED";//: // (730) - case D3DERR_MATRIX_DESTROY_FAILED : // (731) - return "D3DERR_MATRIX_DESTROY_FAILED";//: // (731) - case D3DERR_MATRIX_SETDATA_FAILED : // (732) - return "D3DERR_MATRIX_SETDATA_FAILED";//: // (732) - case D3DERR_MATRIX_GETDATA_FAILED : // (733) - return "D3DERR_MATRIX_GETDATA_FAILED";//: // (733) - case D3DERR_SETVIEWPORTDATA_FAILED : // (734) - return "D3DERR_SETVIEWPORTDATA_FAILED";//: // (734) - case D3DERR_INVALIDCURRENTVIEWPORT : // (735) - return "D3DERR_INVALIDCURRENTVIEWPORT";//: // (735) - case D3DERR_INVALIDPRIMITIVETYPE : // (736) - return "D3DERR_INVALIDPRIMITIVETYPE";//: // (736) - case D3DERR_INVALIDVERTEXTYPE : // (737) - return "D3DERR_INVALIDVERTEXTYPE";//: // (737) - case D3DERR_TEXTURE_BADSIZE : // (738) - return "D3DERR_TEXTURE_BADSIZE";//: // (738) - case D3DERR_INVALIDRAMPTEXTURE : // (739) - return "D3DERR_INVALIDRAMPTEXTURE";//: // (739) - case D3DERR_MATERIAL_CREATE_FAILED : // (740) - return "D3DERR_MATERIAL_CREATE_FAILED";//: // (740) - case D3DERR_MATERIAL_DESTROY_FAILED : // (741) - return "D3DERR_MATERIAL_DESTROY_FAILED";//: // (741) - case D3DERR_MATERIAL_SETDATA_FAILED : // (742) - return "D3DERR_MATERIAL_SETDATA_FAILED";//: // (742) - case D3DERR_MATERIAL_GETDATA_FAILED : // (743) - return "D3DERR_MATERIAL_GETDATA_FAILED";//: // (743) - case D3DERR_INVALIDPALETTE : // (744) - return "D3DERR_INVALIDPALETTE";//: // (744) - case D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY : // (745) - return "D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY";//: // (745) - case D3DERR_ZBUFF_NEEDS_VIDEOMEMORY : // (746) - return "D3DERR_ZBUFF_NEEDS_VIDEOMEMORY";//: // (746) - case D3DERR_SURFACENOTINVIDMEM : // (747) - return "D3DERR_SURFACENOTINVIDMEM";//: // (747) - case D3DERR_LIGHT_SET_FAILED : // (750) - return "D3DERR_LIGHT_SET_FAILED";//: // (750) - case D3DERR_LIGHTHASVIEWPORT : // (751) - return "D3DERR_LIGHTHASVIEWPORT";//: // (751) - case D3DERR_LIGHTNOTINTHISVIEWPORT : // (752) - return "D3DERR_LIGHTNOTINTHISVIEWPORT";//: // (752) - case D3DERR_SCENE_IN_SCENE : // (760) - return "D3DERR_SCENE_IN_SCENE";//: // (760) - case D3DERR_SCENE_NOT_IN_SCENE : // (761) - return "D3DERR_SCENE_NOT_IN_SCENE";//: // (761) - case D3DERR_SCENE_BEGIN_FAILED : // (762) - return "D3DERR_SCENE_BEGIN_FAILED";//: // (762) - case D3DERR_SCENE_END_FAILED : // (763) - return "D3DERR_SCENE_END_FAILED";//: // (763) - case D3DERR_INBEGIN : // (770) - return "D3DERR_INBEGIN";//: // (770) - case D3DERR_NOTINBEGIN : // (771) - return "D3DERR_NOTINBEGIN";//: // (771) - case D3DERR_NOVIEWPORTS : // (772) - return "D3DERR_NOVIEWPORTS";//: // (772) - case D3DERR_VIEWPORTDATANOTSET : // (773) - return "D3DERR_VIEWPORTDATANOTSET";//: // (773) - case D3DERR_VIEWPORTHASNODEVICE : // (774) - return "D3DERR_VIEWPORTHASNODEVICE";//: // (774) - case D3DERR_NOCURRENTVIEWPORT : // (775) - return "D3DERR_NOCURRENTVIEWPORT";//: // (775) - case D3DERR_INVALIDVERTEXFORMAT : // (2048) - return "D3DERR_INVALIDVERTEXFORMAT";//: // (2048) - case D3DERR_COLORKEYATTACHED : // (2050) - return "D3DERR_COLORKEYATTACHED";//: // (2050) - case D3DERR_VERTEXBUFFEROPTIMIZED : // (2060) - return "D3DERR_VERTEXBUFFEROPTIMIZED";//: // (2060) - case D3DERR_VBUF_CREATE_FAILED : // (2061) - return "D3DERR_VBUF_CREATE_FAILED";//: // (2061) - case D3DERR_VERTEXBUFFERLOCKED : // (2062) - return "D3DERR_VERTEXBUFFERLOCKED";//: // (2062) - case D3DERR_ZBUFFER_NOTPRESENT : // (2070) - return "D3DERR_ZBUFFER_NOTPRESENT";//: // (2070) - case D3DERR_STENCILBUFFER_NOTPRESENT : // (2071) - return "D3DERR_STENCILBUFFER_NOTPRESENT";//: // (2071) - case D3DERR_WRONGTEXTUREFORMAT : // (2072) - return "D3DERR_WRONGTEXTUREFORMAT";//: // (2072) - case D3DERR_UNSUPPORTEDCOLOROPERATION : // (2073) - return "D3DERR_UNSUPPORTEDCOLOROPERATION";//: // (2073) - case D3DERR_UNSUPPORTEDCOLORARG : // (2074) - return "D3DERR_UNSUPPORTEDCOLORARG";//: // (2074) - case D3DERR_UNSUPPORTEDALPHAOPERATION : // (2075) - return "D3DERR_UNSUPPORTEDALPHAOPERATION";//: // (2075) - case D3DERR_UNSUPPORTEDALPHAARG : // (2076) - return "D3DERR_UNSUPPORTEDALPHAARG";//: // (2076) - case D3DERR_TOOMANYOPERATIONS : // (2077) - return "D3DERR_TOOMANYOPERATIONS";//: // (2077) - case D3DERR_CONFLICTINGTEXTUREFILTER : // (2078) - return "D3DERR_CONFLICTINGTEXTUREFILTER";//: // (2078) - case D3DERR_UNSUPPORTEDFACTORVALUE : // (2079) - return "D3DERR_UNSUPPORTEDFACTORVALUE";//: // (2079) - case D3DERR_CONFLICTINGRENDERSTATE : // (2081) - return "D3DERR_CONFLICTINGRENDERSTATE";//: // (2081) - case D3DERR_UNSUPPORTEDTEXTUREFILTER : // (2082) - return "D3DERR_UNSUPPORTEDTEXTUREFILTER";//: // (2082) - case D3DERR_TOOMANYPRIMITIVES : // (2083) - return "D3DERR_TOOMANYPRIMITIVES";//: // (2083) - case D3DERR_INVALIDMATRIX : // (2084) - return "D3DERR_INVALIDMATRIX";//: // (2084) - case D3DERR_TOOMANYVERTICES : // (2085) - return "D3DERR_TOOMANYVERTICES";//: // (2085) - case D3DERR_CONFLICTINGTEXTUREPALETTE : // (2086) - return "D3DERR_CONFLICTINGTEXTUREPALETTE";//: // (2086) -//#if DX7 - case D3DERR_VERTEXBUFFERUNLOCKFAILED : // (2063) - return "D3DERR_VERTEXBUFFERUNLOCKFAILED";//: // (2063) - case D3DERR_INVALIDSTATEBLOCK : // (2100) - return "D3DERR_INVALIDSTATEBLOCK";//: // (2100) - case D3DERR_INBEGINSTATEBLOCK : // (2101) - return "D3DERR_INBEGINSTATEBLOCK";//: // (2101) - case D3DERR_NOTINBEGINSTATEBLOCK : // (2102) - return "D3DERR_NOTINBEGINSTATEBLOCK";//: // (2102) - //case D3DERR_INOVERLAYSTATEBLOCK : // (2103) - // return "D3DERR_INOVERLAYSTATEBLOCK";//: // (2103) - case DDERR_NOSTEREOHARDWARE : // ( 181 ) - return "DDERR_NOSTEREOHARDWARE ";//: // ( 181 ) - case DDERR_NOSURFACELEFT : // ( 182 ) - return "DDERR_NOSURFACELEFT ";//: // ( 182 ) - case DDERR_DDSCAPSCOMPLEXREQUIRED : // ( 542 ) - return "DDERR_DDSCAPSCOMPLEXREQUIRED";//: // ( 542 ) - case DDERR_NOTONMIPMAPSUBLEVEL : // ( 603 ) - return "DDERR_NOTONMIPMAPSUBLEVEL";//: // ( 603 ) - case DDERR_TESTFINISHED : // ( 692 ) - return "DDERR_TESTFINISHED";//: // ( 692 ) - case DDERR_NEWMODE : // ( 693 ) - return "DDERR_NEWMODE";//: // ( 693 ) -//#endif - //case D3DERR_COMMAND_UNPARSED : // (3000) - /// return "case";//D3DERR_COMMAND_UNPARSED : // (3000) - - case DDERR_ALREADYINITIALIZED : // ( 5 ) - return "DDERR_ALREADYINITIALIZED ";//: // ( 5 ) - case DDERR_CANNOTATTACHSURFACE : // ( 10 ) - return "DDERR_CANNOTATTACHSURFACE ";//: // ( 10 ) - case DDERR_CANNOTDETACHSURFACE : // ( 20 ) - return "DDERR_CANNOTDETACHSURFACE ";//: // ( 20 ) - case DDERR_CURRENTLYNOTAVAIL : // ( 40 ) - return "DDERR_CURRENTLYNOTAVAIL ";//: // ( 40 ) - case DDERR_EXCEPTION : // ( 55 ) - return "DDERR_EXCEPTION ";//: // ( 55 ) - case DDERR_HEIGHTALIGN : // ( 90 ) - return "DDERR_HEIGHTALIGN ";//: // ( 90 ) - case DDERR_INCOMPATIBLEPRIMARY : // ( 95 ) - return "DDERR_INCOMPATIBLEPRIMARY ";//: // ( 95 ) - case DDERR_INVALIDCAPS : // ( 100 ) - return "DDERR_INVALIDCAPS ";//: // ( 100 ) - case DDERR_INVALIDCLIPLIST : // ( 110 ) - return "DDERR_INVALIDCLIPLIST ";//: // ( 110 ) - case DDERR_INVALIDMODE : // ( 120 ) - return "DDERR_INVALIDMODE ";//: // ( 120 ) - case DDERR_INVALIDOBJECT : // ( 130 ) - return "DDERR_INVALIDOBJECT ";//: // ( 130 ) - case DDERR_INVALIDPIXELFORMAT : // ( 145 ) - return "DDERR_INVALIDPIXELFORMAT ";//: // ( 145 ) - case DDERR_INVALIDRECT : // ( 150 ) - return "DDERR_INVALIDRECT ";//: // ( 150 ) - case DDERR_LOCKEDSURFACES : // ( 160 ) - return "DDERR_LOCKEDSURFACES ";//: // ( 160 ) - case DDERR_NO3D : // ( 170 ) - return "DDERR_NO3D ";//: // ( 170 ) - case DDERR_NOALPHAHW : // ( 180 ) - return "DDERR_NOALPHAHW ";//: // ( 180 ) - case DDERR_NOCLIPLIST : // ( 205 ) - return "DDERR_NOCLIPLIST ";//: // ( 205 ) - case DDERR_NOCOLORCONVHW : // ( 210 ) - return "DDERR_NOCOLORCONVHW ";//: // ( 210 ) - case DDERR_NOCOOPERATIVELEVELSET : // ( 212 ) - return "DDERR_NOCOOPERATIVELEVELSET ";//: // ( 212 ) - case DDERR_NOCOLORKEY : // ( 215 ) - return "DDERR_NOCOLORKEY ";//: // ( 215 ) - case DDERR_NOCOLORKEYHW : // ( 220 ) - return "DDERR_NOCOLORKEYHW ";//: // ( 220 ) - case DDERR_NODIRECTDRAWSUPPORT : // ( 222 ) - return "DDERR_NODIRECTDRAWSUPPORT ";//: // ( 222 ) - case DDERR_NOEXCLUSIVEMODE : // ( 225 ) - return "DDERR_NOEXCLUSIVEMODE ";//: // ( 225 ) - case DDERR_NOFLIPHW : // ( 230 ) - return "DDERR_NOFLIPHW ";//: // ( 230 ) - case DDERR_NOGDI : // ( 240 ) - return "DDERR_NOGDI ";//: // ( 240 ) - case DDERR_NOMIRRORHW : // ( 250 ) - return "DDERR_NOMIRRORHW ";//: // ( 250 ) - case DDERR_NOTFOUND : // ( 255 ) - return "DDERR_NOTFOUND ";//: // ( 255 ) - case DDERR_NOOVERLAYHW : // ( 260 ) - return "DDERR_NOOVERLAYHW ";//: // ( 260 ) - case DDERR_OVERLAPPINGRECTS : // ( 270 ) - return "DDERR_OVERLAPPINGRECTS ";//: // ( 270 ) - case DDERR_NORASTEROPHW : // ( 280 ) - return "DDERR_NORASTEROPHW ";//: // ( 280 ) - case DDERR_NOROTATIONHW : // ( 290 ) - return "DDERR_NOROTATIONHW ";//: // ( 290 ) - case DDERR_NOSTRETCHHW : // ( 310 ) - return "DDERR_NOSTRETCHHW ";//: // ( 310 ) - case DDERR_NOT4BITCOLOR : // ( 316 ) - return "DDERR_NOT4BITCOLOR ";//: // ( 316 ) - case DDERR_NOT4BITCOLORINDEX : // ( 317 ) - return "DDERR_NOT4BITCOLORINDEX ";//: // ( 317 ) - case DDERR_NOT8BITCOLOR : // ( 320 ) - return "DDERR_NOT8BITCOLOR ";//: // ( 320 ) - case DDERR_NOTEXTUREHW : // ( 330 ) - return "DDERR_NOTEXTUREHW ";//: // ( 330 ) - case DDERR_NOVSYNCHW : // ( 335 ) - return "DDERR_NOVSYNCHW ";//: // ( 335 ) - case DDERR_NOZBUFFERHW : // ( 340 ) - return "DDERR_NOZBUFFERHW ";//: // ( 340 ) - case DDERR_NOZOVERLAYHW : // ( 350 ) - return "DDERR_NOZOVERLAYHW ";//: // ( 350 ) - case DDERR_OUTOFCAPS : // ( 360 ) - return "DDERR_OUTOFCAPS ";//: // ( 360 ) - case DDERR_OUTOFVIDEOMEMORY : // ( 380 ) - return "DDERR_OUTOFVIDEOMEMORY ";//: // ( 380 ) - case DDERR_OVERLAYCANTCLIP : // ( 382 ) - return "DDERR_OVERLAYCANTCLIP ";//: // ( 382 ) - case DDERR_OVERLAYCOLORKEYONLYONEACTIVE : // ( 384 ) - return "DDERR_OVERLAYCOLORKEYONLYONEACTIVE ";//: // ( 384 ) - case DDERR_PALETTEBUSY : // ( 387 ) - return "DDERR_PALETTEBUSY ";//: // ( 387 ) - case DDERR_COLORKEYNOTSET : // ( 400 ) - return "DDERR_COLORKEYNOTSET ";//: // ( 400 ) - case DDERR_SURFACEALREADYATTACHED : // ( 410 ) - return "DDERR_SURFACEALREADYATTACHED ";//: // ( 410 ) - case DDERR_SURFACEALREADYDEPENDENT : // ( 420 ) - return "DDERR_SURFACEALREADYDEPENDENT ";//: // ( 420 ) - case DDERR_SURFACEBUSY : // ( 430 ) - return "DDERR_SURFACEBUSY ";//: // ( 430 ) - case DDERR_CANTLOCKSURFACE : // ( 435 ) - return "DDERR_CANTLOCKSURFACE";//: // ( 435 ) - case DDERR_SURFACEISOBSCURED : // ( 440 ) - return "DDERR_SURFACEISOBSCURED ";//: // ( 440 ) - case DDERR_SURFACELOST : // ( 450 ) - return "DDERR_SURFACELOST ";//: // ( 450 ) - case DDERR_SURFACENOTATTACHED : // ( 460 ) - return "DDERR_SURFACENOTATTACHED ";//: // ( 460 ) - case DDERR_TOOBIGHEIGHT : // ( 470 ) - return "DDERR_TOOBIGHEIGHT ";//: // ( 470 ) - case DDERR_TOOBIGSIZE : // ( 480 ) - return "DDERR_TOOBIGSIZE ";//: // ( 480 ) - case DDERR_TOOBIGWIDTH : // ( 490 ) - return "DDERR_TOOBIGWIDTH ";//: // ( 490 ) - case DDERR_UNSUPPORTEDFORMAT : // ( 510 ) - return "DDERR_UNSUPPORTEDFORMAT ";//: // ( 510 ) - case DDERR_UNSUPPORTEDMASK : // ( 520 ) - return "DDERR_UNSUPPORTEDMASK ";//: // ( 520 ) - case DDERR_INVALIDSTREAM : // ( 521 ) - return "DDERR_INVALIDSTREAM";//: // ( 521 ) - case DDERR_VERTICALBLANKINPROGRESS : // ( 537 ) - return "DDERR_VERTICALBLANKINPROGRESS ";//: // ( 537 ) - case DDERR_WASSTILLDRAWING : // ( 540 ) - return "DDERR_WASSTILLDRAWING ";//: // ( 540 ) - case DDERR_XALIGN : // ( 560 ) - return "DDERR_XALIGN ";//: // ( 560 ) - case DDERR_INVALIDDIRECTDRAWGUID : // ( 561 ) - return "DDERR_INVALIDDIRECTDRAWGUID ";//: // ( 561 ) - case DDERR_DIRECTDRAWALREADYCREATED : // ( 562 ) - return "DDERR_DIRECTDRAWALREADYCREATED ";//: // ( 562 ) - case DDERR_NODIRECTDRAWHW : // ( 563 ) - return "DDERR_NODIRECTDRAWHW ";//: // ( 563 ) - case DDERR_PRIMARYSURFACEALREADYEXISTS : // ( 564 ) - return "DDERR_PRIMARYSURFACEALREADYEXISTS ";//: // ( 564 ) - case DDERR_NOEMULATION : // ( 565 ) - return "DDERR_NOEMULATION ";//: // ( 565 ) - case DDERR_REGIONTOOSMALL : // ( 566 ) - return "DDERR_REGIONTOOSMALL ";//: // ( 566 ) - case DDERR_CLIPPERISUSINGHWND : // ( 567 ) - return "DDERR_CLIPPERISUSINGHWND ";//: // ( 567 ) - case DDERR_NOCLIPPERATTACHED : // ( 568 ) - return "DDERR_NOCLIPPERATTACHED ";//: // ( 568 ) - case DDERR_NOHWND : // ( 569 ) - return "DDERR_NOHWND ";//: // ( 569 ) - case DDERR_HWNDSUBCLASSED : // ( 570 ) - return "DDERR_HWNDSUBCLASSED ";//: // ( 570 ) - case DDERR_HWNDALREADYSET : // ( 571 ) - return "DDERR_HWNDALREADYSET ";//: // ( 571 ) - case DDERR_NOPALETTEATTACHED : // ( 572 ) - return "DDERR_NOPALETTEATTACHED ";//: // ( 572 ) - case DDERR_NOPALETTEHW : // ( 573 ) - return "DDERR_NOPALETTEHW ";//: // ( 573 ) - case DDERR_BLTFASTCANTCLIP : // ( 574 ) - return "DDERR_BLTFASTCANTCLIP ";//: // ( 574 ) - case DDERR_NOBLTHW : // ( 575 ) - return "DDERR_NOBLTHW ";//: // ( 575 ) - case DDERR_NODDROPSHW : // ( 576 ) - return "DDERR_NODDROPSHW ";//: // ( 576 ) - case DDERR_OVERLAYNOTVISIBLE : // ( 577 ) - return "DDERR_OVERLAYNOTVISIBLE ";//: // ( 577 ) - case DDERR_NOOVERLAYDEST : // ( 578 ) - return "DDERR_NOOVERLAYDEST ";//: // ( 578 ) - case DDERR_INVALIDPOSITION : // ( 579 ) - return "DDERR_INVALIDPOSITION ";//: // ( 579 ) - case DDERR_NOTAOVERLAYSURFACE : // ( 580 ) - return "DDERR_NOTAOVERLAYSURFACE ";//: // ( 580 ) - case DDERR_EXCLUSIVEMODEALREADYSET : // ( 581 ) - return "DDERR_EXCLUSIVEMODEALREADYSET ";//: // ( 581 ) - case DDERR_NOTFLIPPABLE : // ( 582 ) - return "DDERR_NOTFLIPPABLE ";//: // ( 582 ) - case DDERR_CANTDUPLICATE : // ( 583 ) - return "DDERR_CANTDUPLICATE ";//: // ( 583 ) - case DDERR_NOTLOCKED : // ( 584 ) - return "DDERR_NOTLOCKED ";//: // ( 584 ) - case DDERR_CANTCREATEDC : // ( 585 ) - return "DDERR_CANTCREATEDC ";//: // ( 585 ) - case DDERR_NODC : // ( 586 ) - return "DDERR_NODC ";//: // ( 586 ) - case DDERR_WRONGMODE : // ( 587 ) - return "DDERR_WRONGMODE ";//: // ( 587 ) - case DDERR_IMPLICITLYCREATED : // ( 588 ) - return "DDERR_IMPLICITLYCREATED ";//: // ( 588 ) - case DDERR_NOTPALETTIZED : // ( 589 ) - return "DDERR_NOTPALETTIZED ";//: // ( 589 ) - case DDERR_UNSUPPORTEDMODE : // ( 590 ) - return "DDERR_UNSUPPORTEDMODE ";//: // ( 590 ) - case DDERR_NOMIPMAPHW : // ( 591 ) - return "DDERR_NOMIPMAPHW ";//: // ( 591 ) - case DDERR_INVALIDSURFACETYPE : // ( 592 ) - return "DDERR_INVALIDSURFACETYPE";//: // ( 592 ) - case DDERR_NOOPTIMIZEHW : // ( 600 ) - return "DDERR_NOOPTIMIZEHW";//: // ( 600 ) - case DDERR_NOTLOADED : // ( 601 ) - return "DDERR_NOTLOADED";//: // ( 601 ) - case DDERR_NOFOCUSWINDOW : // ( 602 ) - return "DDERR_NOFOCUSWINDOW";//: // ( 602 ) - case DDERR_DCALREADYCREATED : // ( 620 ) - return "DDERR_DCALREADYCREATED ";//: // ( 620 ) - case DDERR_NONONLOCALVIDMEM : // ( 630 ) - return "DDERR_NONONLOCALVIDMEM";//: // ( 630 ) - case DDERR_CANTPAGELOCK : // ( 640 ) - return "DDERR_CANTPAGELOCK ";//: // ( 640 ) - case DDERR_CANTPAGEUNLOCK : // ( 660 ) - return "DDERR_CANTPAGEUNLOCK ";//: // ( 660 ) - case DDERR_NOTPAGELOCKED : // ( 680 ) - return "DDERR_NOTPAGELOCKED ";//: // ( 680 ) - case DDERR_MOREDATA : // ( 690 ) - return "DDERR_MOREDATA ";//: // ( 690 ) - case DDERR_EXPIRED : // ( 691 ) - return "DDERR_EXPIRED";//: // ( 691 ) - case DDERR_VIDEONOTACTIVE : // ( 695 ) - return "DDERR_VIDEONOTACTIVE ";//: // ( 695 ) - case DDERR_DEVICEDOESNTOWNSURFACE : // ( 699 ) - return "DDERR_DEVICEDOESNTOWNSURFACE ";//: // ( 699 ) - case DXFILEERR_BADOBJECT : // (850) - return "DXFILEERR_BADOBJECT";//: // (850) - case DXFILEERR_BADVALUE : // (851) - return "DXFILEERR_BADVALUE";//: // (851) - case DXFILEERR_BADTYPE : // (852) - return "DXFILEERR_BADTYPE";//: // (852) - case DXFILEERR_BADSTREAMHANDLE : // (853) - return "DXFILEERR_BADSTREAMHANDLE";//: // (853) - case DXFILEERR_BADALLOC : // (854) - return "DXFILEERR_BADALLOC";//: // (854) - case DXFILEERR_NOTFOUND : // (855) - return "DXFILEERR_NOTFOUND";//: // (855) - case DXFILEERR_NOTDONEYET : // (856) - return "DXFILEERR_NOTDONEYET";//: // (856) - case DXFILEERR_FILENOTFOUND : // (857) - return "DXFILEERR_FILENOTFOUND";//: // (857) - case DXFILEERR_RESOURCENOTFOUND : // (858) - return "DXFILEERR_RESOURCENOTFOUND";//: // (858) - case DXFILEERR_URLNOTFOUND : // (859) - return "DXFILEERR_URLNOTFOUND";//: // (859) - case DXFILEERR_BADRESOURCE : // (860) - return "DXFILEERR_BADRESOURCE";//: // (860) - case DXFILEERR_BADFILETYPE : // (861) - return "DXFILEERR_BADFILETYPE";//: // (861) - case DXFILEERR_BADFILEVERSION : // (862) - return "DXFILEERR_BADFILEVERSION";//: // (862) - case DXFILEERR_BADFILEFLOATSIZE : // (863) - return "DXFILEERR_BADFILEFLOATSIZE";//: // (863) - case DXFILEERR_BADFILECOMPRESSIONTYPE : // (864) - return "DXFILEERR_BADFILECOMPRESSIONTYPE";//: // (864) - case DXFILEERR_BADFILE : // (865) - return "DXFILEERR_BADFILE";//: // (865) - case DXFILEERR_PARSEERROR : // (866) - return "DXFILEERR_PARSEERROR";//: // (866) - case DXFILEERR_NOTEMPLATE : // (867) - return "DXFILEERR_NOTEMPLATE";//: // (867) - case DXFILEERR_BADARRAYSIZE : // (868) - return "DXFILEERR_BADARRAYSIZE";//: // (868) - case DXFILEERR_BADDATAREFERENCE : // (869) - return "DXFILEERR_BADDATAREFERENCE";//: // (869) - case DXFILEERR_INTERNALERROR : // (870) - return "DXFILEERR_INTERNALERROR";//: // (870) - case DXFILEERR_NOMOREOBJECTS : // (871) - return "DXFILEERR_NOMOREOBJECTS";//: // (871) - case DXFILEERR_BADINTRINSICS : // (872) - return "DXFILEERR_BADINTRINSICS";//: // (872) - case DXFILEERR_NOMORESTREAMHANDLES : // (873) - return "DXFILEERR_NOMORESTREAMHANDLES";//: // (873) - case DXFILEERR_NOMOREDATA : // (874) - return "DXFILEERR_NOMOREDATA";//: // (874) - case DXFILEERR_BADCACHEFILE : // (875) - return "DXFILEERR_BADCACHEFILE";//: // (875) - case DXFILEERR_NOINTERNET : // (876) - return "DXFILEERR_NOINTERNET";//: // (876) - - case E_UNEXPECTED : - return "E_UNEXPECTED "; - case E_NOTIMPL : - return "E_NOTIMPL "; - case E_OUTOFMEMORY : - return "E_OUTOFMEMORY "; - case E_INVALIDARG : - return "E_INVALIDARG or DDERR_INVALIDPARAMS"; - case E_NOINTERFACE : - return "E_NOINTERFACE "; - case E_POINTER : - return "E_POINTER "; - case E_HANDLE : - return "E_HANDLE "; - case E_ABORT : - return "E_ABORT "; -// case E_FAIL : -// return "E_FAIL "; - case E_ACCESSDENIED : - return "E_ACCESSDENIED "; - case E_PENDING : - return "E_PENDING "; - case CO_E_INIT_TLS : - return "CO_E_INIT_TLS "; - case CO_E_INIT_SHARED_ALLOCATOR : - return "CO_E_INIT_SHARED_ALLOCATOR "; - case CO_E_INIT_MEMORY_ALLOCATOR : - return "CO_E_INIT_MEMORY_ALLOCATOR "; - case CO_E_INIT_CLASS_CACHE : - return "CO_E_INIT_CLASS_CACHE "; - case CO_E_INIT_RPC_CHANNEL : - return "CO_E_INIT_RPC_CHANNEL "; - case CO_E_INIT_TLS_SET_CHANNEL_CONTROL : - return "CO_E_INIT_TLS_SET_CHANNEL_CONTROL "; - case CO_E_INIT_TLS_CHANNEL_CONTROL : - return "CO_E_INIT_TLS_CHANNEL_CONTROL "; - case CO_E_INIT_UNACCEPTED_USER_ALLOCATOR : - return "CO_E_INIT_UNACCEPTED_USER_ALLOCATOR "; - case CO_E_INIT_SCM_MUTEX_EXISTS : - return "CO_E_INIT_SCM_MUTEX_EXISTS "; - case CO_E_INIT_SCM_FILE_MAPPING_EXISTS : - return "CO_E_INIT_SCM_FILE_MAPPING_EXISTS "; - case CO_E_INIT_SCM_MAP_VIEW_OF_FILE : - return "CO_E_INIT_SCM_MAP_VIEW_OF_FILE "; - case CO_E_INIT_SCM_EXEC_FAILURE : - return "CO_E_INIT_SCM_EXEC_FAILURE "; - case CO_E_INIT_ONLY_SINGLE_THREADED : - return "CO_E_INIT_ONLY_SINGLE_THREADED "; - case CO_E_CANT_REMOTE : - return "CO_E_CANT_REMOTE "; - case CO_E_BAD_SERVER_NAME : - return "CO_E_BAD_SERVER_NAME "; - case CO_E_WRONG_SERVER_IDENTITY : - return "CO_E_WRONG_SERVER_IDENTITY "; - case CO_E_OLE1DDE_DISABLED : - return "CO_E_OLE1DDE_DISABLED "; - case CO_E_RUNAS_SYNTAX : - return "CO_E_RUNAS_SYNTAX "; - case CO_E_CREATEPROCESS_FAILURE : - return "CO_E_CREATEPROCESS_FAILURE "; - case CO_E_RUNAS_CREATEPROCESS_FAILURE : - return "CO_E_RUNAS_CREATEPROCESS_FAILURE "; - case CO_E_RUNAS_LOGON_FAILURE : - return "CO_E_RUNAS_LOGON_FAILURE "; - case CO_E_LAUNCH_PERMSSION_DENIED : - return "CO_E_LAUNCH_PERMSSION_DENIED "; - case CO_E_START_SERVICE_FAILURE : - return "CO_E_START_SERVICE_FAILURE "; - case CO_E_REMOTE_COMMUNICATION_FAILURE : - return "CO_E_REMOTE_COMMUNICATION_FAILURE "; - case CO_E_SERVER_START_TIMEOUT : - return "CO_E_SERVER_START_TIMEOUT "; - case CO_E_CLSREG_INCONSISTENT : - return "CO_E_CLSREG_INCONSISTENT "; - case CO_E_IIDREG_INCONSISTENT : - return "CO_E_IIDREG_INCONSISTENT "; - case CO_E_NOT_SUPPORTED : - return "CO_E_NOT_SUPPORTED "; - case CO_E_RELOAD_DLL : - return "CO_E_RELOAD_DLL "; - case CO_E_MSI_ERROR : - return "CO_E_MSI_ERROR "; - case OLE_E_OLEVERB : - return "OLE_E_OLEVERB "; - case OLE_E_ADVF : - return "OLE_E_ADVF "; - case OLE_E_ENUM_NOMORE : - return "OLE_E_ENUM_NOMORE "; - case OLE_E_ADVISENOTSUPPORTED : - return "OLE_E_ADVISENOTSUPPORTED "; - case OLE_E_NOCONNECTION : - return "OLE_E_NOCONNECTION "; - case OLE_E_NOTRUNNING : - return "OLE_E_NOTRUNNING "; - case OLE_E_NOCACHE : - return "OLE_E_NOCACHE "; - case OLE_E_BLANK : - return "OLE_E_BLANK "; - case OLE_E_CLASSDIFF : - return "OLE_E_CLASSDIFF "; - case OLE_E_CANT_GETMONIKER : - return "OLE_E_CANT_GETMONIKER "; - case OLE_E_CANT_BINDTOSOURCE : - return "OLE_E_CANT_BINDTOSOURCE "; - case OLE_E_STATIC : - return "OLE_E_STATIC "; - case OLE_E_PROMPTSAVECANCELLED : - return "OLE_E_PROMPTSAVECANCELLED "; - case OLE_E_INVALIDRECT : - return "OLE_E_INVALIDRECT "; - case OLE_E_WRONGCOMPOBJ : - return "OLE_E_WRONGCOMPOBJ "; - case OLE_E_INVALIDHWND : - return "OLE_E_INVALIDHWND "; - case OLE_E_NOT_INPLACEACTIVE : - return "OLE_E_NOT_INPLACEACTIVE "; - case OLE_E_CANTCONVERT : - return "OLE_E_CANTCONVERT "; - case OLE_E_NOSTORAGE : - return "OLE_E_NOSTORAGE "; - case DV_E_FORMATETC : - return "DV_E_FORMATETC "; - case DV_E_DVTARGETDEVICE : - return "DV_E_DVTARGETDEVICE "; - case DV_E_STGMEDIUM : - return "DV_E_STGMEDIUM "; - case DV_E_STATDATA : - return "DV_E_STATDATA "; - case DV_E_LINDEX : - return "DV_E_LINDEX "; - case DV_E_TYMED : - return "DV_E_TYMED "; - case DV_E_CLIPFORMAT : - return "DV_E_CLIPFORMAT "; - case DV_E_DVASPECT : - return "DV_E_DVASPECT "; - case DV_E_DVTARGETDEVICE_SIZE : - return "DV_E_DVTARGETDEVICE_SIZE "; - case DV_E_NOIVIEWOBJECT : - return "DV_E_NOIVIEWOBJECT "; - case DRAGDROP_E_NOTREGISTERED : - return "DRAGDROP_E_NOTREGISTERED "; - case DRAGDROP_E_ALREADYREGISTERED : - return "DRAGDROP_E_ALREADYREGISTERED "; - case DRAGDROP_E_INVALIDHWND : - return "DRAGDROP_E_INVALIDHWND "; - case CLASS_E_NOAGGREGATION : - return "CLASS_E_NOAGGREGATION "; - case CLASS_E_CLASSNOTAVAILABLE : - return "CLASS_E_CLASSNOTAVAILABLE "; - case CLASS_E_NOTLICENSED : - return "CLASS_E_NOTLICENSED "; - case VIEW_E_DRAW : - return "VIEW_E_DRAW "; - case REGDB_E_READREGDB : - return "REGDB_E_READREGDB "; - case REGDB_E_WRITEREGDB : - return "REGDB_E_WRITEREGDB "; - case REGDB_E_KEYMISSING : - return "REGDB_E_KEYMISSING "; - case REGDB_E_INVALIDVALUE : - return "REGDB_E_INVALIDVALUE "; - case REGDB_E_CLASSNOTREG : - return "REGDB_E_CLASSNOTREG "; - case REGDB_E_IIDNOTREG : - return "REGDB_E_IIDNOTREG "; - case CAT_E_CATIDNOEXIST : - return "CAT_E_CATIDNOEXIST "; - case CAT_E_NODESCRIPTION : - return "CAT_E_NODESCRIPTION "; - case CS_E_PACKAGE_NOTFOUND : - return "CS_E_PACKAGE_NOTFOUND "; - case CS_E_NOT_DELETABLE : - return "CS_E_NOT_DELETABLE "; - case CS_E_CLASS_NOTFOUND : - return "CS_E_CLASS_NOTFOUND "; - case CS_E_INVALID_VERSION : - return "CS_E_INVALID_VERSION "; - case CS_E_NO_CLASSSTORE : - return "CS_E_NO_CLASSSTORE "; - case CACHE_E_NOCACHE_UPDATED : - return "CACHE_E_NOCACHE_UPDATED "; - case OLEOBJ_E_NOVERBS : - return "OLEOBJ_E_NOVERBS "; - case OLEOBJ_E_INVALIDVERB : - return "OLEOBJ_E_INVALIDVERB "; - case INPLACE_E_NOTUNDOABLE : - return "INPLACE_E_NOTUNDOABLE "; - case INPLACE_E_NOTOOLSPACE : - return "INPLACE_E_NOTOOLSPACE "; - case CONVERT10_E_OLESTREAM_GET : - return "CONVERT10_E_OLESTREAM_GET "; - case CONVERT10_E_OLESTREAM_PUT : - return "CONVERT10_E_OLESTREAM_PUT "; - case CONVERT10_E_OLESTREAM_FMT : - return "CONVERT10_E_OLESTREAM_FMT "; - case CONVERT10_E_OLESTREAM_BITMAP_TO_DIB : - return "CONVERT10_E_OLESTREAM_BITMAP_TO_DIB "; - case CONVERT10_E_STG_FMT : - return "CONVERT10_E_STG_FMT "; - case CONVERT10_E_STG_NO_STD_STREAM : - return "CONVERT10_E_STG_NO_STD_STREAM "; - case CONVERT10_E_STG_DIB_TO_BITMAP : - return "CONVERT10_E_STG_DIB_TO_BITMAP "; - case CLIPBRD_E_CANT_OPEN : - return "CLIPBRD_E_CANT_OPEN "; - case CLIPBRD_E_CANT_EMPTY : - return "CLIPBRD_E_CANT_EMPTY "; - case CLIPBRD_E_CANT_SET : - return "CLIPBRD_E_CANT_SET "; - case CLIPBRD_E_BAD_DATA : - return "CLIPBRD_E_BAD_DATA "; - case CLIPBRD_E_CANT_CLOSE : - return "CLIPBRD_E_CANT_CLOSE "; - case MK_E_CONNECTMANUALLY : - return "MK_E_CONNECTMANUALLY "; - case MK_E_EXCEEDEDDEADLINE : - return "MK_E_EXCEEDEDDEADLINE "; - case MK_E_NEEDGENERIC : - return "MK_E_NEEDGENERIC "; - case MK_E_UNAVAILABLE : - return "MK_E_UNAVAILABLE "; - case MK_E_SYNTAX : - return "MK_E_SYNTAX "; - case MK_E_NOOBJECT : - return "MK_E_NOOBJECT "; - case MK_E_INVALIDEXTENSION : - return "MK_E_INVALIDEXTENSION "; - case MK_E_INTERMEDIATEINTERFACENOTSUPPORTED : - return "MK_E_INTERMEDIATEINTERFACENOTSUPPORTED "; - case MK_E_NOTBINDABLE : - return "MK_E_NOTBINDABLE "; - case MK_E_NOTBOUND : - return "MK_E_NOTBOUND "; - case MK_E_CANTOPENFILE : - return "MK_E_CANTOPENFILE "; - case MK_E_MUSTBOTHERUSER : - return "MK_E_MUSTBOTHERUSER "; - case MK_E_NOINVERSE : - return "MK_E_NOINVERSE "; - case MK_E_NOSTORAGE : - return "MK_E_NOSTORAGE "; - case MK_E_NOPREFIX : - return "MK_E_NOPREFIX "; - case MK_E_ENUMERATION_FAILED : - return "MK_E_ENUMERATION_FAILED "; - case CO_E_NOTINITIALIZED : - return "CO_E_NOTINITIALIZED "; - case CO_E_ALREADYINITIALIZED : - return "CO_E_ALREADYINITIALIZED "; - case CO_E_CANTDETERMINECLASS : - return "CO_E_CANTDETERMINECLASS "; - case CO_E_CLASSSTRING : - return "CO_E_CLASSSTRING "; - case CO_E_IIDSTRING : - return "CO_E_IIDSTRING "; - case CO_E_APPNOTFOUND : - return "CO_E_APPNOTFOUND "; - case CO_E_APPSINGLEUSE : - return "CO_E_APPSINGLEUSE "; - case CO_E_ERRORINAPP : - return "CO_E_ERRORINAPP "; - case CO_E_DLLNOTFOUND : - return "CO_E_DLLNOTFOUND "; - case CO_E_ERRORINDLL : - return "CO_E_ERRORINDLL "; - case CO_E_WRONGOSFORAPP : - return "CO_E_WRONGOSFORAPP "; - case CO_E_OBJNOTREG : - return "CO_E_OBJNOTREG "; - case CO_E_OBJISREG : - return "CO_E_OBJISREG "; - case CO_E_OBJNOTCONNECTED : - return "CO_E_OBJNOTCONNECTED "; - case CO_E_APPDIDNTREG : - return "CO_E_APPDIDNTREG "; - case CO_E_RELEASED : - return "CO_E_RELEASED "; - case CO_E_FAILEDTOIMPERSONATE : - return "CO_E_FAILEDTOIMPERSONATE "; - case CO_E_FAILEDTOGETSECCTX : - return "CO_E_FAILEDTOGETSECCTX "; - case CO_E_FAILEDTOOPENTHREADTOKEN : - return "CO_E_FAILEDTOOPENTHREADTOKEN "; - case CO_E_FAILEDTOGETTOKENINFO : - return "CO_E_FAILEDTOGETTOKENINFO "; - case CO_E_TRUSTEEDOESNTMATCHCLIENT : - return "CO_E_TRUSTEEDOESNTMATCHCLIENT "; - case CO_E_FAILEDTOQUERYCLIENTBLANKET : - return "CO_E_FAILEDTOQUERYCLIENTBLANKET "; - case CO_E_FAILEDTOSETDACL : - return "CO_E_FAILEDTOSETDACL "; - case CO_E_ACCESSCHECKFAILED : - return "CO_E_ACCESSCHECKFAILED "; - case CO_E_NETACCESSAPIFAILED : - return "CO_E_NETACCESSAPIFAILED "; - case CO_E_WRONGTRUSTEENAMESYNTAX : - return "CO_E_WRONGTRUSTEENAMESYNTAX "; - case CO_E_INVALIDSID : - return "CO_E_INVALIDSID "; - case CO_E_CONVERSIONFAILED : - return "CO_E_CONVERSIONFAILED "; - case CO_E_NOMATCHINGSIDFOUND : - return "CO_E_NOMATCHINGSIDFOUND "; - case CO_E_LOOKUPACCSIDFAILED : - return "CO_E_LOOKUPACCSIDFAILED "; - case CO_E_NOMATCHINGNAMEFOUND : - return "CO_E_NOMATCHINGNAMEFOUND "; - case CO_E_LOOKUPACCNAMEFAILED : - return "CO_E_LOOKUPACCNAMEFAILED "; - case CO_E_SETSERLHNDLFAILED : - return "CO_E_SETSERLHNDLFAILED "; - case CO_E_FAILEDTOGETWINDIR : - return "CO_E_FAILEDTOGETWINDIR "; - case CO_E_PATHTOOLONG : - return "CO_E_PATHTOOLONG "; - case CO_E_FAILEDTOGENUUID : - return "CO_E_FAILEDTOGENUUID "; - case CO_E_FAILEDTOCREATEFILE : - return "CO_E_FAILEDTOCREATEFILE "; - case CO_E_FAILEDTOCLOSEHANDLE : - return "CO_E_FAILEDTOCLOSEHANDLE "; - case CO_E_EXCEEDSYSACLLIMIT : - return "CO_E_EXCEEDSYSACLLIMIT "; - case CO_E_ACESINWRONGORDER : - return "CO_E_ACESINWRONGORDER "; - case CO_E_INCOMPATIBLESTREAMVERSION : - return "CO_E_INCOMPATIBLESTREAMVERSION "; - case CO_E_FAILEDTOOPENPROCESSTOKEN : - return "CO_E_FAILEDTOOPENPROCESSTOKEN "; - case CO_E_DECODEFAILED : - return "CO_E_DECODEFAILED "; - case CO_E_ACNOTINITIALIZED : - return "CO_E_ACNOTINITIALIZED "; - case OLE_S_USEREG : - return "OLE_S_USEREG "; - case OLE_S_STATIC : - return "OLE_S_STATIC "; - case OLE_S_MAC_CLIPFORMAT : - return "OLE_S_MAC_CLIPFORMAT "; - case DRAGDROP_S_DROP : - return "DRAGDROP_S_DROP "; - case DRAGDROP_S_CANCEL : - return "DRAGDROP_S_CANCEL "; - case DRAGDROP_S_USEDEFAULTCURSORS : - return "DRAGDROP_S_USEDEFAULTCURSORS "; - case DATA_S_SAMEFORMATETC : - return "DATA_S_SAMEFORMATETC "; - case VIEW_S_ALREADY_FROZEN : - return "VIEW_S_ALREADY_FROZEN "; - case CACHE_S_FORMATETC_NOTSUPPORTED : - return "CACHE_S_FORMATETC_NOTSUPPORTED "; - case CACHE_S_SAMECACHE : - return "CACHE_S_SAMECACHE "; - case CACHE_S_SOMECACHES_NOTUPDATED : - return "CACHE_S_SOMECACHES_NOTUPDATED "; - case OLEOBJ_S_INVALIDVERB : - return "OLEOBJ_S_INVALIDVERB "; - case OLEOBJ_S_CANNOT_DOVERB_NOW : - return "OLEOBJ_S_CANNOT_DOVERB_NOW "; - case OLEOBJ_S_INVALIDHWND : - return "OLEOBJ_S_INVALIDHWND "; - case INPLACE_S_TRUNCATED : - return "INPLACE_S_TRUNCATED "; - case CONVERT10_S_NO_PRESENTATION : - return "CONVERT10_S_NO_PRESENTATION "; - case MK_S_REDUCED_TO_SELF : - return "MK_S_REDUCED_TO_SELF "; - case MK_S_ME : - return "MK_S_ME "; - case MK_S_HIM : - return "MK_S_HIM "; - case MK_S_US : - return "MK_S_US "; - case MK_S_MONIKERALREADYREGISTERED : - return "MK_S_MONIKERALREADYREGISTERED "; - case CO_E_CLASS_CREATE_FAILED : - return "CO_E_CLASS_CREATE_FAILED "; - case CO_E_SCM_ERROR : - return "CO_E_SCM_ERROR "; - case CO_E_SCM_RPC_FAILURE : - return "CO_E_SCM_RPC_FAILURE "; - case CO_E_BAD_PATH : - return "CO_E_BAD_PATH "; - case CO_E_SERVER_EXEC_FAILURE : - return "CO_E_SERVER_EXEC_FAILURE "; - case CO_E_OBJSRV_RPC_FAILURE : - return "CO_E_OBJSRV_RPC_FAILURE "; - case MK_E_NO_NORMALIZED : - return "MK_E_NO_NORMALIZED "; - case CO_E_SERVER_STOPPING : - return "CO_E_SERVER_STOPPING "; - case MEM_E_INVALID_ROOT : - return "MEM_E_INVALID_ROOT "; - case MEM_E_INVALID_LINK : - return "MEM_E_INVALID_LINK "; - case MEM_E_INVALID_SIZE : - return "MEM_E_INVALID_SIZE "; - case CO_S_NOTALLINTERFACES : - return "CO_S_NOTALLINTERFACES "; - case DISP_E_UNKNOWNINTERFACE : - return "DISP_E_UNKNOWNINTERFACE "; - case DISP_E_MEMBERNOTFOUND : - return "DISP_E_MEMBERNOTFOUND "; - case DISP_E_PARAMNOTFOUND : - return "DISP_E_PARAMNOTFOUND "; - case DISP_E_TYPEMISMATCH : - return "DISP_E_TYPEMISMATCH "; - case DISP_E_UNKNOWNNAME : - return "DISP_E_UNKNOWNNAME "; - case DISP_E_NONAMEDARGS : - return "DISP_E_NONAMEDARGS "; - case DISP_E_BADVARTYPE : - return "DISP_E_BADVARTYPE "; - case DISP_E_EXCEPTION : - return "DISP_E_EXCEPTION "; - case DISP_E_OVERFLOW : - return "DISP_E_OVERFLOW "; - case DISP_E_BADINDEX : - return "DISP_E_BADINDEX "; - case DISP_E_UNKNOWNLCID : - return "DISP_E_UNKNOWNLCID "; - case DISP_E_ARRAYISLOCKED : - return "DISP_E_ARRAYISLOCKED "; - case DISP_E_BADPARAMCOUNT : - return "DISP_E_BADPARAMCOUNT "; - case DISP_E_PARAMNOTOPTIONAL : - return "DISP_E_PARAMNOTOPTIONAL "; - case DISP_E_BADCALLEE : - return "DISP_E_BADCALLEE "; - case DISP_E_NOTACOLLECTION : - return "DISP_E_NOTACOLLECTION "; - case DISP_E_DIVBYZERO : - return "DISP_E_DIVBYZERO "; - case TYPE_E_BUFFERTOOSMALL : - return "TYPE_E_BUFFERTOOSMALL "; - case TYPE_E_FIELDNOTFOUND : - return "TYPE_E_FIELDNOTFOUND "; - case TYPE_E_INVDATAREAD : - return "TYPE_E_INVDATAREAD "; - case TYPE_E_UNSUPFORMAT : - return "TYPE_E_UNSUPFORMAT "; - case TYPE_E_REGISTRYACCESS : - return "TYPE_E_REGISTRYACCESS "; - case TYPE_E_LIBNOTREGISTERED : - return "TYPE_E_LIBNOTREGISTERED "; - case TYPE_E_UNDEFINEDTYPE : - return "TYPE_E_UNDEFINEDTYPE "; - case TYPE_E_QUALIFIEDNAMEDISALLOWED : - return "TYPE_E_QUALIFIEDNAMEDISALLOWED "; - case TYPE_E_INVALIDSTATE : - return "TYPE_E_INVALIDSTATE "; - case TYPE_E_WRONGTYPEKIND : - return "TYPE_E_WRONGTYPEKIND "; - case TYPE_E_ELEMENTNOTFOUND : - return "TYPE_E_ELEMENTNOTFOUND "; - case TYPE_E_AMBIGUOUSNAME : - return "TYPE_E_AMBIGUOUSNAME "; - case TYPE_E_NAMECONFLICT : - return "TYPE_E_NAMECONFLICT "; - case TYPE_E_UNKNOWNLCID : - return "TYPE_E_UNKNOWNLCID "; - case TYPE_E_DLLFUNCTIONNOTFOUND : - return "TYPE_E_DLLFUNCTIONNOTFOUND "; - case TYPE_E_BADMODULEKIND : - return "TYPE_E_BADMODULEKIND "; - case TYPE_E_SIZETOOBIG : - return "TYPE_E_SIZETOOBIG "; - case TYPE_E_DUPLICATEID : - return "TYPE_E_DUPLICATEID "; - case TYPE_E_INVALIDID : - return "TYPE_E_INVALIDID "; - case TYPE_E_TYPEMISMATCH : - return "TYPE_E_TYPEMISMATCH "; - case TYPE_E_OUTOFBOUNDS : - return "TYPE_E_OUTOFBOUNDS "; - case TYPE_E_IOERROR : - return "TYPE_E_IOERROR "; - case TYPE_E_CANTCREATETMPFILE : - return "TYPE_E_CANTCREATETMPFILE "; - case TYPE_E_CANTLOADLIBRARY : - return "TYPE_E_CANTLOADLIBRARY "; - case TYPE_E_INCONSISTENTPROPFUNCS : - return "TYPE_E_INCONSISTENTPROPFUNCS "; - case TYPE_E_CIRCULARTYPE : - return "TYPE_E_CIRCULARTYPE "; - case STG_E_INVALIDFUNCTION : - return "STG_E_INVALIDFUNCTION "; - case STG_E_FILENOTFOUND : - return "STG_E_FILENOTFOUND "; - case STG_E_PATHNOTFOUND : - return "STG_E_PATHNOTFOUND "; - case STG_E_TOOMANYOPENFILES : - return "STG_E_TOOMANYOPENFILES "; - case STG_E_ACCESSDENIED : - return "STG_E_ACCESSDENIED "; - case STG_E_INVALIDHANDLE : - return "STG_E_INVALIDHANDLE "; - case STG_E_INSUFFICIENTMEMORY : - return "STG_E_INSUFFICIENTMEMORY "; - case STG_E_INVALIDPOINTER : - return "STG_E_INVALIDPOINTER "; - case STG_E_NOMOREFILES : - return "STG_E_NOMOREFILES "; - case STG_E_DISKISWRITEPROTECTED : - return "STG_E_DISKISWRITEPROTECTED "; - case STG_E_SEEKERROR : - return "STG_E_SEEKERROR "; - case STG_E_WRITEFAULT : - return "STG_E_WRITEFAULT "; - case STG_E_READFAULT : - return "STG_E_READFAULT "; - case STG_E_SHAREVIOLATION : - return "STG_E_SHAREVIOLATION "; - case STG_E_LOCKVIOLATION : - return "STG_E_LOCKVIOLATION "; - case STG_E_FILEALREADYEXISTS : - return "STG_E_FILEALREADYEXISTS "; - case STG_E_INVALIDPARAMETER : - return "STG_E_INVALIDPARAMETER "; - case STG_E_MEDIUMFULL : - return "STG_E_MEDIUMFULL "; - case STG_E_PROPSETMISMATCHED : - return "STG_E_PROPSETMISMATCHED "; - case STG_E_ABNORMALAPIEXIT : - return "STG_E_ABNORMALAPIEXIT "; - case STG_E_INVALIDHEADER : - return "STG_E_INVALIDHEADER "; - case STG_E_INVALIDNAME : - return "STG_E_INVALIDNAME "; - case STG_E_UNKNOWN : - return "STG_E_UNKNOWN "; - case STG_E_UNIMPLEMENTEDFUNCTION : - return "STG_E_UNIMPLEMENTEDFUNCTION "; - case STG_E_INVALIDFLAG : - return "STG_E_INVALIDFLAG "; - case STG_E_INUSE : - return "STG_E_INUSE "; - case STG_E_NOTCURRENT : - return "STG_E_NOTCURRENT "; - case STG_E_REVERTED : - return "STG_E_REVERTED "; - case STG_E_CANTSAVE : - return "STG_E_CANTSAVE "; - case STG_E_OLDFORMAT : - return "STG_E_OLDFORMAT "; - case STG_E_OLDDLL : - return "STG_E_OLDDLL "; - case STG_E_SHAREREQUIRED : - return "STG_E_SHAREREQUIRED "; - case STG_E_NOTFILEBASEDSTORAGE : - return "STG_E_NOTFILEBASEDSTORAGE "; - case STG_E_EXTANTMARSHALLINGS : - return "STG_E_EXTANTMARSHALLINGS "; - case STG_E_DOCFILECORRUPT : - return "STG_E_DOCFILECORRUPT "; - case STG_E_BADBASEADDRESS : - return "STG_E_BADBASEADDRESS "; - case STG_E_INCOMPLETE : - return "STG_E_INCOMPLETE "; - case STG_E_TERMINATED : - return "STG_E_TERMINATED "; - case STG_S_CONVERTED : - return "STG_S_CONVERTED "; - case STG_S_BLOCK : - return "STG_S_BLOCK "; - case STG_S_RETRYNOW : - return "STG_S_RETRYNOW "; - case STG_S_MONITORING : - return "STG_S_MONITORING "; - case STG_S_MULTIPLEOPENS : - return "STG_S_MULTIPLEOPENS "; - case STG_S_CONSOLIDATIONFAILED : - return "STG_S_CONSOLIDATIONFAILED "; - case STG_S_CANNOTCONSOLIDATE : - return "STG_S_CANNOTCONSOLIDATE "; - case RPC_E_CALL_REJECTED : - return "RPC_E_CALL_REJECTED "; - case RPC_E_CALL_CANCELED : - return "RPC_E_CALL_CANCELED "; - case RPC_E_CANTPOST_INSENDCALL : - return "RPC_E_CANTPOST_INSENDCALL "; - case RPC_E_CANTCALLOUT_INASYNCCALL : - return "RPC_E_CANTCALLOUT_INASYNCCALL "; - case RPC_E_CANTCALLOUT_INEXTERNALCALL : - return "RPC_E_CANTCALLOUT_INEXTERNALCALL "; - case RPC_E_CONNECTION_TERMINATED : - return "RPC_E_CONNECTION_TERMINATED "; - case RPC_E_SERVER_DIED : - return "RPC_E_SERVER_DIED "; - case RPC_E_CLIENT_DIED : - return "RPC_E_CLIENT_DIED "; - case RPC_E_INVALID_DATAPACKET : - return "RPC_E_INVALID_DATAPACKET "; - case RPC_E_CANTTRANSMIT_CALL : - return "RPC_E_CANTTRANSMIT_CALL "; - case RPC_E_CLIENT_CANTMARSHAL_DATA : - return "RPC_E_CLIENT_CANTMARSHAL_DATA "; - case RPC_E_CLIENT_CANTUNMARSHAL_DATA : - return "RPC_E_CLIENT_CANTUNMARSHAL_DATA "; - case RPC_E_SERVER_CANTMARSHAL_DATA : - return "RPC_E_SERVER_CANTMARSHAL_DATA "; - case RPC_E_SERVER_CANTUNMARSHAL_DATA : - return "RPC_E_SERVER_CANTUNMARSHAL_DATA "; - case RPC_E_INVALID_DATA : - return "RPC_E_INVALID_DATA "; - case RPC_E_INVALID_PARAMETER : - return "RPC_E_INVALID_PARAMETER "; - case RPC_E_CANTCALLOUT_AGAIN : - return "RPC_E_CANTCALLOUT_AGAIN "; - case RPC_E_SERVER_DIED_DNE : - return "RPC_E_SERVER_DIED_DNE "; - case RPC_E_SYS_CALL_FAILED : - return "RPC_E_SYS_CALL_FAILED "; - case RPC_E_OUT_OF_RESOURCES : - return "RPC_E_OUT_OF_RESOURCES "; - case RPC_E_ATTEMPTED_MULTITHREAD : - return "RPC_E_ATTEMPTED_MULTITHREAD "; - case RPC_E_NOT_REGISTERED : - return "RPC_E_NOT_REGISTERED "; - case RPC_E_FAULT : - return "RPC_E_FAULT "; - case RPC_E_SERVERFAULT : - return "RPC_E_SERVERFAULT "; - case RPC_E_CHANGED_MODE : - return "RPC_E_CHANGED_MODE "; - case RPC_E_INVALIDMETHOD : - return "RPC_E_INVALIDMETHOD "; - case RPC_E_DISCONNECTED : - return "RPC_E_DISCONNECTED "; - case RPC_E_RETRY : - return "RPC_E_RETRY "; - case RPC_E_SERVERCALL_RETRYLATER : - return "RPC_E_SERVERCALL_RETRYLATER "; - case RPC_E_SERVERCALL_REJECTED : - return "RPC_E_SERVERCALL_REJECTED "; - case RPC_E_INVALID_CALLDATA : - return "RPC_E_INVALID_CALLDATA "; - case RPC_E_CANTCALLOUT_ININPUTSYNCCALL : - return "RPC_E_CANTCALLOUT_ININPUTSYNCCALL "; - case RPC_E_WRONG_THREAD : - return "RPC_E_WRONG_THREAD "; - case RPC_E_THREAD_NOT_INIT : - return "RPC_E_THREAD_NOT_INIT "; - case RPC_E_VERSION_MISMATCH : - return "RPC_E_VERSION_MISMATCH "; - case RPC_E_INVALID_HEADER : - return "RPC_E_INVALID_HEADER "; - case RPC_E_INVALID_EXTENSION : - return "RPC_E_INVALID_EXTENSION "; - case RPC_E_INVALID_IPID : - return "RPC_E_INVALID_IPID "; - case RPC_E_INVALID_OBJECT : - return "RPC_E_INVALID_OBJECT "; - case RPC_S_CALLPENDING : - return "RPC_S_CALLPENDING "; - case RPC_S_WAITONTIMER : - return "RPC_S_WAITONTIMER "; - case RPC_E_CALL_COMPLETE : - return "RPC_E_CALL_COMPLETE "; - case RPC_E_UNSECURE_CALL : - return "RPC_E_UNSECURE_CALL "; - case RPC_E_TOO_LATE : - return "RPC_E_TOO_LATE "; - case RPC_E_NO_GOOD_SECURITY_PACKAGES : - return "RPC_E_NO_GOOD_SECURITY_PACKAGES "; - case RPC_E_ACCESS_DENIED : - return "RPC_E_ACCESS_DENIED "; - case RPC_E_REMOTE_DISABLED : - return "RPC_E_REMOTE_DISABLED "; - case RPC_E_INVALID_OBJREF : - return "RPC_E_INVALID_OBJREF "; - case RPC_E_NO_CONTEXT : - return "RPC_E_NO_CONTEXT "; - case RPC_E_TIMEOUT : - return "RPC_E_TIMEOUT "; - case RPC_E_NO_SYNC : - return "RPC_E_NO_SYNC "; - case RPC_E_UNEXPECTED : - return "RPC_E_UNEXPECTED "; - case NTE_BAD_UID : - return "NTE_BAD_UID "; - case NTE_BAD_HASH : - return "NTE_BAD_HASH "; - //case NTE_BAD_HASH : - //return "NTE_BAD_HASH "; - case NTE_BAD_KEY : - return "NTE_BAD_KEY "; - case NTE_BAD_LEN : - return "NTE_BAD_LEN "; - case NTE_BAD_DATA : - return "NTE_BAD_DATA "; - case NTE_BAD_SIGNATURE : - return "NTE_BAD_SIGNATURE "; - case NTE_BAD_VER : - return "NTE_BAD_VER "; - case NTE_BAD_ALGID : - return "NTE_BAD_ALGID "; - case NTE_BAD_FLAGS : - return "NTE_BAD_FLAGS "; - case NTE_BAD_TYPE : - return "NTE_BAD_TYPE "; - case NTE_BAD_KEY_STATE : - return "NTE_BAD_KEY_STATE "; - case NTE_BAD_HASH_STATE : - return "NTE_BAD_HASH_STATE "; - case NTE_NO_KEY : - return "NTE_NO_KEY "; - case NTE_NO_MEMORY : - return "NTE_NO_MEMORY "; - case NTE_EXISTS : - return "NTE_EXISTS "; - case NTE_PERM : - return "NTE_PERM "; - case NTE_NOT_FOUND : - return "NTE_NOT_FOUND "; - case NTE_DOUBLE_ENCRYPT : - return "NTE_DOUBLE_ENCRYPT "; - case NTE_BAD_PROVIDER : - return "NTE_BAD_PROVIDER "; - case NTE_BAD_PROV_TYPE : - return "NTE_BAD_PROV_TYPE "; - case NTE_BAD_PUBLIC_KEY : - return "NTE_BAD_PUBLIC_KEY "; - case NTE_BAD_KEYSET : - return "NTE_BAD_KEYSET "; - case NTE_PROV_TYPE_NOT_DEF : - return "NTE_PROV_TYPE_NOT_DEF "; - case NTE_PROV_TYPE_ENTRY_BAD : - return "NTE_PROV_TYPE_ENTRY_BAD "; - case NTE_KEYSET_NOT_DEF : - return "NTE_KEYSET_NOT_DEF "; - case NTE_KEYSET_ENTRY_BAD : - return "NTE_KEYSET_ENTRY_BAD "; - case NTE_PROV_TYPE_NO_MATCH : - return "NTE_PROV_TYPE_NO_MATCH "; - case NTE_SIGNATURE_FILE_BAD : - return "NTE_SIGNATURE_FILE_BAD "; - case NTE_PROVIDER_DLL_FAIL : - return "NTE_PROVIDER_DLL_FAIL "; - case NTE_PROV_DLL_NOT_FOUND : - return "NTE_PROV_DLL_NOT_FOUND "; - case NTE_BAD_KEYSET_PARAM : - return "NTE_BAD_KEYSET_PARAM "; - case NTE_FAIL : - return "NTE_FAIL "; - case NTE_SYS_ERR : - return "NTE_SYS_ERR "; - case CRYPT_E_MSG_ERROR : - return "CRYPT_E_MSG_ERROR "; - case CRYPT_E_UNKNOWN_ALGO : - return "CRYPT_E_UNKNOWN_ALGO "; - case CRYPT_E_OID_FORMAT : - return "CRYPT_E_OID_FORMAT "; - case CRYPT_E_INVALID_MSG_TYPE : - return "CRYPT_E_INVALID_MSG_TYPE "; - case CRYPT_E_UNEXPECTED_ENCODING : - return "CRYPT_E_UNEXPECTED_ENCODING "; - case CRYPT_E_AUTH_ATTR_MISSING : - return "CRYPT_E_AUTH_ATTR_MISSING "; - case CRYPT_E_HASH_VALUE : - return "CRYPT_E_HASH_VALUE "; - case CRYPT_E_INVALID_INDEX : - return "CRYPT_E_INVALID_INDEX "; - case CRYPT_E_ALREADY_DECRYPTED : - return "CRYPT_E_ALREADY_DECRYPTED "; - case CRYPT_E_NOT_DECRYPTED : - return "CRYPT_E_NOT_DECRYPTED "; - case CRYPT_E_RECIPIENT_NOT_FOUND : - return "CRYPT_E_RECIPIENT_NOT_FOUND "; - case CRYPT_E_CONTROL_TYPE : - return "CRYPT_E_CONTROL_TYPE "; - case CRYPT_E_ISSUER_SERIALNUMBER : - return "CRYPT_E_ISSUER_SERIALNUMBER "; - case CRYPT_E_SIGNER_NOT_FOUND : - return "CRYPT_E_SIGNER_NOT_FOUND "; - case CRYPT_E_ATTRIBUTES_MISSING : - return "CRYPT_E_ATTRIBUTES_MISSING "; - case CRYPT_E_STREAM_MSG_NOT_READY : - return "CRYPT_E_STREAM_MSG_NOT_READY "; - case CRYPT_E_STREAM_INSUFFICIENT_DATA : - return "CRYPT_E_STREAM_INSUFFICIENT_DATA "; - case CRYPT_E_BAD_LEN : - return "CRYPT_E_BAD_LEN "; - case CRYPT_E_BAD_ENCODE : - return "CRYPT_E_BAD_ENCODE "; - case CRYPT_E_FILE_ERROR : - return "CRYPT_E_FILE_ERROR "; - case CRYPT_E_NOT_FOUND : - return "CRYPT_E_NOT_FOUND "; - case CRYPT_E_EXISTS : - return "CRYPT_E_EXISTS "; - case CRYPT_E_NO_PROVIDER : - return "CRYPT_E_NO_PROVIDER "; - case CRYPT_E_SELF_SIGNED : - return "CRYPT_E_SELF_SIGNED "; - case CRYPT_E_DELETED_PREV : - return "CRYPT_E_DELETED_PREV "; - case CRYPT_E_NO_MATCH : - return "CRYPT_E_NO_MATCH "; - case CRYPT_E_UNEXPECTED_MSG_TYPE : - return "CRYPT_E_UNEXPECTED_MSG_TYPE "; - case CRYPT_E_NO_KEY_PROPERTY : - return "CRYPT_E_NO_KEY_PROPERTY "; - case CRYPT_E_NO_DECRYPT_CERT : - return "CRYPT_E_NO_DECRYPT_CERT "; - case CRYPT_E_BAD_MSG : - return "CRYPT_E_BAD_MSG "; - case CRYPT_E_NO_SIGNER : - return "CRYPT_E_NO_SIGNER "; - case CRYPT_E_PENDING_CLOSE : - return "CRYPT_E_PENDING_CLOSE "; - case CRYPT_E_REVOKED : - return "CRYPT_E_REVOKED "; - case CRYPT_E_NO_REVOCATION_DLL : - return "CRYPT_E_NO_REVOCATION_DLL "; - case CRYPT_E_NO_REVOCATION_CHECK : - return "CRYPT_E_NO_REVOCATION_CHECK "; - case CRYPT_E_REVOCATION_OFFLINE : - return "CRYPT_E_REVOCATION_OFFLINE "; - case CRYPT_E_NOT_IN_REVOCATION_DATABASE : - return "CRYPT_E_NOT_IN_REVOCATION_DATABASE "; - case CRYPT_E_INVALID_NUMERIC_STRING : - return "CRYPT_E_INVALID_NUMERIC_STRING "; - case CRYPT_E_INVALID_PRINTABLE_STRING : - return "CRYPT_E_INVALID_PRINTABLE_STRING "; - case CRYPT_E_INVALID_IA5_STRING : - return "CRYPT_E_INVALID_IA5_STRING "; - case CRYPT_E_INVALID_X500_STRING : - return "CRYPT_E_INVALID_X500_STRING "; - case CRYPT_E_NOT_CHAR_STRING : - return "CRYPT_E_NOT_CHAR_STRING "; - case CRYPT_E_FILERESIZED : - return "CRYPT_E_FILERESIZED "; - case CRYPT_E_SECURITY_SETTINGS : - return "CRYPT_E_SECURITY_SETTINGS "; - case CRYPT_E_NO_VERIFY_USAGE_DLL : - return "CRYPT_E_NO_VERIFY_USAGE_DLL "; - case CRYPT_E_NO_VERIFY_USAGE_CHECK : - return "CRYPT_E_NO_VERIFY_USAGE_CHECK "; - case CRYPT_E_VERIFY_USAGE_OFFLINE : - return "CRYPT_E_VERIFY_USAGE_OFFLINE "; - case CRYPT_E_NOT_IN_CTL : - return "CRYPT_E_NOT_IN_CTL "; - case CRYPT_E_NO_TRUSTED_SIGNER : - return "CRYPT_E_NO_TRUSTED_SIGNER "; - case CRYPT_E_OSS_ERROR : - return "CRYPT_E_OSS_ERROR "; - case CERTSRV_E_BAD_REQUESTSUBJECT : - return "CERTSRV_E_BAD_REQUESTSUBJECT "; - case CERTSRV_E_NO_REQUEST : - return "CERTSRV_E_NO_REQUEST "; - case CERTSRV_E_BAD_REQUESTSTATUS : - return "CERTSRV_E_BAD_REQUESTSTATUS "; - case CERTSRV_E_PROPERTY_EMPTY : - return "CERTSRV_E_PROPERTY_EMPTY "; - //case CERTDB_E_JET_ERROR : - //return "CERTDB_E_JET_ERROR "; - case TRUST_E_SYSTEM_ERROR : - return "TRUST_E_SYSTEM_ERROR "; - case TRUST_E_NO_SIGNER_CERT : - return "TRUST_E_NO_SIGNER_CERT "; - case TRUST_E_COUNTER_SIGNER : - return "TRUST_E_COUNTER_SIGNER "; - case TRUST_E_CERT_SIGNATURE : - return "TRUST_E_CERT_SIGNATURE "; - case TRUST_E_TIME_STAMP : - return "TRUST_E_TIME_STAMP "; - case TRUST_E_BAD_DIGEST : - return "TRUST_E_BAD_DIGEST "; - case TRUST_E_BASIC_CONSTRAINTS : - return "TRUST_E_BASIC_CONSTRAINTS "; - case TRUST_E_FINANCIAL_CRITERIA : - return "TRUST_E_FINANCIAL_CRITERIA "; - case TRUST_E_PROVIDER_UNKNOWN : - return "TRUST_E_PROVIDER_UNKNOWN "; - case TRUST_E_ACTION_UNKNOWN : - return "TRUST_E_ACTION_UNKNOWN "; - case TRUST_E_SUBJECT_FORM_UNKNOWN : - return "TRUST_E_SUBJECT_FORM_UNKNOWN "; - case TRUST_E_SUBJECT_NOT_TRUSTED : - return "TRUST_E_SUBJECT_NOT_TRUSTED "; - case DIGSIG_E_ENCODE : - return "DIGSIG_E_ENCODE "; - case DIGSIG_E_DECODE : - return "DIGSIG_E_DECODE "; - case DIGSIG_E_EXTENSIBILITY : - return "DIGSIG_E_EXTENSIBILITY "; - case DIGSIG_E_CRYPTO : - return "DIGSIG_E_CRYPTO "; - case PERSIST_E_SIZEDEFINITE : - return "PERSIST_E_SIZEDEFINITE "; - case PERSIST_E_SIZEINDEFINITE : - return "PERSIST_E_SIZEINDEFINITE "; - case PERSIST_E_NOTSELFSIZING : - return "PERSIST_E_NOTSELFSIZING "; - case TRUST_E_NOSIGNATURE : - return "TRUST_E_NOSIGNATURE "; - case CERT_E_EXPIRED : - return "CERT_E_EXPIRED "; - case CERT_E_VALIDITYPERIODNESTING : - return "CERT_E_VALIDITYPERIODNESTING "; - case CERT_E_ROLE : - return "CERT_E_ROLE "; - case CERT_E_PATHLENCONST : - return "CERT_E_PATHLENCONST "; - case CERT_E_CRITICAL : - return "CERT_E_CRITICAL "; - case CERT_E_PURPOSE : - return "CERT_E_PURPOSE "; - case CERT_E_ISSUERCHAINING : - return "CERT_E_ISSUERCHAINING "; - case CERT_E_MALFORMED : - return "CERT_E_MALFORMED "; - case CERT_E_UNTRUSTEDROOT : - return "CERT_E_UNTRUSTEDROOT "; - case CERT_E_CHAINING : - return "CERT_E_CHAINING "; - case TRUST_E_FAIL : - return "TRUST_E_FAIL "; - case CERT_E_REVOKED : - return "CERT_E_REVOKED "; - case CERT_E_UNTRUSTEDTESTROOT : - return "CERT_E_UNTRUSTEDTESTROOT "; - case CERT_E_REVOCATION_FAILURE : - return "CERT_E_REVOCATION_FAILURE "; - case CERT_E_CN_NO_MATCH : - return "CERT_E_CN_NO_MATCH "; - case CERT_E_WRONG_USAGE : - return "CERT_E_WRONG_USAGE "; - case SPAPI_E_EXPECTED_SECTION_NAME : - return "SPAPI_E_EXPECTED_SECTION_NAME "; - case SPAPI_E_BAD_SECTION_NAME_LINE : - return "SPAPI_E_BAD_SECTION_NAME_LINE "; - case SPAPI_E_SECTION_NAME_TOO_LONG : - return "SPAPI_E_SECTION_NAME_TOO_LONG "; - case SPAPI_E_GENERAL_SYNTAX : - return "SPAPI_E_GENERAL_SYNTAX "; - case SPAPI_E_WRONG_INF_STYLE : - return "SPAPI_E_WRONG_INF_STYLE "; - case SPAPI_E_SECTION_NOT_FOUND : - return "SPAPI_E_SECTION_NOT_FOUND "; - case SPAPI_E_LINE_NOT_FOUND : - return "SPAPI_E_LINE_NOT_FOUND "; - case SPAPI_E_NO_ASSOCIATED_CLASS : - return "SPAPI_E_NO_ASSOCIATED_CLASS "; - case SPAPI_E_CLASS_MISMATCH : - return "SPAPI_E_CLASS_MISMATCH "; - case SPAPI_E_DUPLICATE_FOUND : - return "SPAPI_E_DUPLICATE_FOUND "; - case SPAPI_E_NO_DRIVER_SELECTED : - return "SPAPI_E_NO_DRIVER_SELECTED "; - case SPAPI_E_KEY_DOES_NOT_EXIST : - return "SPAPI_E_KEY_DOES_NOT_EXIST "; - case SPAPI_E_INVALID_DEVINST_NAME : - return "SPAPI_E_INVALID_DEVINST_NAME "; - case SPAPI_E_INVALID_CLASS : - return "SPAPI_E_INVALID_CLASS "; - case SPAPI_E_DEVINST_ALREADY_EXISTS : - return "SPAPI_E_DEVINST_ALREADY_EXISTS "; - case SPAPI_E_DEVINFO_NOT_REGISTERED : - return "SPAPI_E_DEVINFO_NOT_REGISTERED "; - case SPAPI_E_INVALID_REG_PROPERTY : - return "SPAPI_E_INVALID_REG_PROPERTY "; - case SPAPI_E_NO_INF : - return "SPAPI_E_NO_INF "; - case SPAPI_E_NO_SUCH_DEVINST : - return "SPAPI_E_NO_SUCH_DEVINST "; - case SPAPI_E_CANT_LOAD_CLASS_ICON : - return "SPAPI_E_CANT_LOAD_CLASS_ICON "; - case SPAPI_E_INVALID_CLASS_INSTALLER : - return "SPAPI_E_INVALID_CLASS_INSTALLER "; - case SPAPI_E_DI_DO_DEFAULT : - return "SPAPI_E_DI_DO_DEFAULT "; - case SPAPI_E_DI_NOFILECOPY : - return "SPAPI_E_DI_NOFILECOPY "; - case SPAPI_E_INVALID_HWPROFILE : - return "SPAPI_E_INVALID_HWPROFILE "; - case SPAPI_E_NO_DEVICE_SELECTED : - return "SPAPI_E_NO_DEVICE_SELECTED "; - case SPAPI_E_DEVINFO_LIST_LOCKED : - return "SPAPI_E_DEVINFO_LIST_LOCKED "; - case SPAPI_E_DEVINFO_DATA_LOCKED : - return "SPAPI_E_DEVINFO_DATA_LOCKED "; - case SPAPI_E_DI_BAD_PATH : - return "SPAPI_E_DI_BAD_PATH "; - case SPAPI_E_NO_CLASSINSTALL_PARAMS : - return "SPAPI_E_NO_CLASSINSTALL_PARAMS "; - case SPAPI_E_FILEQUEUE_LOCKED : - return "SPAPI_E_FILEQUEUE_LOCKED "; - case SPAPI_E_BAD_SERVICE_INSTALLSECT : - return "SPAPI_E_BAD_SERVICE_INSTALLSECT "; - case SPAPI_E_NO_CLASS_DRIVER_LIST : - return "SPAPI_E_NO_CLASS_DRIVER_LIST "; - case SPAPI_E_NO_ASSOCIATED_SERVICE : - return "SPAPI_E_NO_ASSOCIATED_SERVICE "; - case SPAPI_E_NO_DEFAULT_DEVICE_INTERFACE : - return "SPAPI_E_NO_DEFAULT_DEVICE_INTERFACE "; - case SPAPI_E_DEVICE_INTERFACE_ACTIVE : - return "SPAPI_E_DEVICE_INTERFACE_ACTIVE "; - case SPAPI_E_DEVICE_INTERFACE_REMOVED : - return "SPAPI_E_DEVICE_INTERFACE_REMOVED "; - case SPAPI_E_BAD_INTERFACE_INSTALLSECT : - return "SPAPI_E_BAD_INTERFACE_INSTALLSECT "; - case SPAPI_E_NO_SUCH_INTERFACE_CLASS : - return "SPAPI_E_NO_SUCH_INTERFACE_CLASS "; - case SPAPI_E_INVALID_REFERENCE_STRING : - return "SPAPI_E_INVALID_REFERENCE_STRING "; - case SPAPI_E_INVALID_MACHINENAME : - return "SPAPI_E_INVALID_MACHINENAME "; - case SPAPI_E_REMOTE_COMM_FAILURE : - return "SPAPI_E_REMOTE_COMM_FAILURE "; - case SPAPI_E_MACHINE_UNAVAILABLE : - return "SPAPI_E_MACHINE_UNAVAILABLE "; - case SPAPI_E_NO_CONFIGMGR_SERVICES : - return "SPAPI_E_NO_CONFIGMGR_SERVICES "; - case SPAPI_E_INVALID_PROPPAGE_PROVIDER : - return "SPAPI_E_INVALID_PROPPAGE_PROVIDER "; - case SPAPI_E_NO_SUCH_DEVICE_INTERFACE : - return "SPAPI_E_NO_SUCH_DEVICE_INTERFACE "; - case SPAPI_E_DI_POSTPROCESSING_REQUIRED : - return "SPAPI_E_DI_POSTPROCESSING_REQUIRED "; - case SPAPI_E_INVALID_COINSTALLER : - return "SPAPI_E_INVALID_COINSTALLER "; - case SPAPI_E_NO_COMPAT_DRIVERS : - return "SPAPI_E_NO_COMPAT_DRIVERS "; - case SPAPI_E_NO_DEVICE_ICON : - return "SPAPI_E_NO_DEVICE_ICON "; - case SPAPI_E_INVALID_INF_LOGCONFIG : - return "SPAPI_E_INVALID_INF_LOGCONFIG "; - case SPAPI_E_DI_DONT_INSTALL : - return "SPAPI_E_DI_DONT_INSTALL "; - case SPAPI_E_INVALID_FILTER_DRIVER : - return "SPAPI_E_INVALID_FILTER_DRIVER "; - case SPAPI_E_ERROR_NOT_INSTALLED : - return "SPAPI_E_ERROR_NOT_INSTALLED "; - - default: - static char buff[1000]; - sprintf(buff, "Unrecognized error value: %08X\0", error); - - return buff; - } -} diff --git a/panda/src/wdxdisplay8/wdxGraphicsPipe8.h b/panda/src/wdxdisplay8/wdxGraphicsPipe8.h index a5b5f5542a..4c71c60429 100644 --- a/panda/src/wdxdisplay8/wdxGraphicsPipe8.h +++ b/panda/src/wdxdisplay8/wdxGraphicsPipe8.h @@ -37,7 +37,6 @@ //////////////////////////////////////////////////////////////////// // Defines //////////////////////////////////////////////////////////////////// -class Xclass; extern char * ConvD3DErrorToString(const HRESULT &error); diff --git a/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx b/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx index 6d0593f1f6..bf247e5829 100644 --- a/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx +++ b/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx @@ -20,10 +20,9 @@ #include #include #include -#include "wdxGraphicsWindow8.h" -#include "wdxGraphicsPipe8.h" -#include "dxGraphicsStateGuardian8.h" -#include "config_wdxdisplay8.h" +#include "wdxGraphicsWindow.h" +#include "wdxGraphicsPipe.h" +#include "config_wdxdisplay.h" #include #include @@ -36,7 +35,8 @@ #define D3D_OVERLOADS //#define INITGUID dont want this if linking w/dxguid.lib -#include +#include +#include #include @@ -48,12 +48,15 @@ TypeHandle wdxGraphicsWindow::_type_handle; #define LAST_ERROR 0 #define ERRORBOX_TITLE "Panda3D Error" #define WDX_WINDOWCLASSNAME "wdxDisplay" +#define DEFAULT_CURSOR IDC_ARROW typedef map HWND_PANDAWIN_MAP; HWND_PANDAWIN_MAP hwnd_pandawin_map; wdxGraphicsWindow* global_wdxwinptr = NULL; // need this for temporary windproc +#define MAX_DISPLAYS 20 + extern bool dx_full_screen_antialiasing; // defined in dxgsg_config.cxx #define MOUSE_ENTERED 0 @@ -63,6 +66,11 @@ extern bool dx_full_screen_antialiasing; // defined in dxgsg_config.cxx LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam,LPARAM lparam); +// imperfect method to ID NVid? could also scan desc str, but that isnt fullproof either +#define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.dwVendorId==0x10DE) || (DDDEVICEID.dwVendorId==0x12D2)) +#define IS_ATI(DDDEVICEID) (DDDEVICEID.dwVendorId==0x1002) +#define IS_MATROX(DDDEVICEID) (DDDEVICEID.dwVendorId==0x102B) + // because we dont have access to ModifierButtons, as a hack just synchronize state of these // keys on get/lose keybd focus #define NUM_MODIFIER_KEYS 16 @@ -186,28 +194,32 @@ void wdxGraphicsWindow::DestroyMe(bool bAtExitFnCalled) { wdxdisplay_cat.spam() << "DestroyMe called, AtExitFnCalled=" << bAtExitFnCalled << endl; _exiting_window = true; // may be needed for DestroyWindow call + DXScreenData scrn; + memcpy(&scrn,&_dxgsg->scrn,sizeof(DXScreenData)); if(_dxgsg!=NULL) { _dxgsg->dx_cleanup(_props._fullscreen, bAtExitFnCalled); _dxgsg=NULL; } - if(_hdc!=NULL) { - ReleaseDC(_mwindow,_hdc); - _hdc = NULL; +/* + if(scrn._hdc!=NULL) { + ReleaseDC(scrn.hWnd,scrn._hdc); +// _hdc = NULL; } - - if((_hOldForegroundWindow!=NULL) && (_mwindow==GetForegroundWindow())) { - SetForegroundWindow(_hOldForegroundWindow); +*/ +/* + if((scrn._hOldForegroundWindow!=NULL) && (scrn.hWnd==GetForegroundWindow())) { + SetForegroundWindow(scrn._hOldForegroundWindow); } - - if(_mwindow!=NULL) { - if(_bLoadedCustomCursor && _hMouseCursor!=NULL) - DestroyCursor(_hMouseCursor); - - DestroyWindow(_mwindow); - hwnd_pandawin_map.erase(_mwindow); - _mwindow = NULL; +"*/ + if(scrn.hWnd!=NULL) { +/* + if(_bLoadedCustomCursor && (_hMouseCursor!=NULL)) + DestroyCursor(_hMouseCursor); +*/ + DestroyWindow(scrn.hWnd); + hwnd_pandawin_map.erase(scrn.hWnd); } } @@ -405,6 +417,13 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { handle_keyrelease(MouseButton::button(button)); return 0; + case WM_SETCURSOR: + // Turn off any GDI window cursor + SetCursor( NULL ); + _dxgsg->scrn.pD3DDevice->ShowCursor(true); + return TRUE; // prevent Windows from setting cursor to window class cursor (see docs on WM_SETCURSOR) + break; + case WM_MOVE: if(!DXREADY) break; @@ -465,7 +484,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { } #endif // old comment -- added SIZE_RESTORED to handle 3dfx case - if((_mwindow==NULL) || dx_full_screen || ((wparam != SIZE_RESTORED) && (wparam != SIZE_MAXIMIZED))) + if(dx_full_screen || ((_dxgsg==NULL) || (_dxgsg->scrn.hWnd==NULL)) || ((wparam != SIZE_RESTORED) && (wparam != SIZE_MAXIMIZED))) break; width = LOWORD(lparam); height = HIWORD(lparam); @@ -494,7 +513,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { } if(_mouse_entry_enabled) - handle_mouse_entry(MOUSE_ENTERED,_hMouseCursor); + handle_mouse_entry(MOUSE_ENTERED,_pParentWindowGroup->_hMouseCursor); POINT point; GetCursorPos(&point); @@ -520,7 +539,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { } if(_mouse_entry_enabled) - handle_mouse_entry(MOUSE_EXITED,_hMouseCursor); + handle_mouse_entry(MOUSE_EXITED,_pParentWindowGroup->_hMouseCursor); int i; for(i=0;iGetBackBuffer()==NULL) { + if(_dxgsg->scrn.pddsBack==NULL) { //assume this is initial creation reshape and ignore this call return; } @@ -637,13 +657,13 @@ void wdxGraphicsWindow::handle_reshape(bool bDoDxReset) { // Clear the back/primary surface to black DX_DECLARE_CLEAN(DDBLTFX, bltfx) bltfx.dwDDFX |= DDBLTFX_NOTEARING; - hr = _dxgsg->_pri->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&bltfx); + hr = _dxgsg->scrn.pddsPrimary->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&bltfx); if(FAILED( hr )) { wdxdisplay_cat.fatal() << "Blt to Black of Primary Surf failed! : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } - if(FAILED(hr = _dxgsg->_pDD->TestCooperativeLevel())) { + if(FAILED(hr = _dxgsg->scrn.pDD->TestCooperativeLevel())) { wdxdisplay_cat.error() << "TestCooperativeLevel failed : result = " << ConvD3DErrorToString(hr) << endl; return; } @@ -664,8 +684,8 @@ void wdxGraphicsWindow::handle_reshape(bool bDoDxReset) { DX_DECLARE_CLEAN( DDSURFACEDESC2, ddsd ); - _dxgsg->GetBackBuffer()->GetSurfaceDesc(&ddsd); - LPDIRECTDRAW7 pDD = _dxgsg->GetDDInterface(); + _dxgsg->scrn.pddsBack->GetSurfaceDesc(&ddsd); + LPDIRECTDRAW7 pDD = _dxgsg->scrn.pDD; ddsd.dwFlags &= ~DDSD_PITCH; ddsd.dwWidth = 1; ddsd.dwHeight = 1; @@ -678,24 +698,26 @@ void wdxGraphicsWindow::handle_reshape(bool bDoDxReset) { exit(1); } - DX_DECLARE_CLEAN( DDSURFACEDESC2, ddsdZ ); - _dxgsg->GetZBuffer()->GetSurfaceDesc(&ddsdZ); - ddsdZ.dwFlags &= ~DDSD_PITCH; - ddsdZ.dwWidth = 1; ddsdZ.dwHeight = 1; - - PRINTVIDMEM(pDD,&ddsdZ.ddsCaps,"dummy zbuf"); - - if(FAILED( hr = pDD->CreateSurface( &ddsdZ, &pddsDummyZ, NULL ) )) { - wdxdisplay_cat.fatal() << "Resize CreateSurface for temp zbuf failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + if(_dxgsg->scrn.pddsZBuf!=NULL) { + DX_DECLARE_CLEAN( DDSURFACEDESC2, ddsdZ ); + _dxgsg->scrn.pddsZBuf->GetSurfaceDesc(&ddsdZ); + ddsdZ.dwFlags &= ~DDSD_PITCH; + ddsdZ.dwWidth = 1; ddsdZ.dwHeight = 1; + + PRINTVIDMEM(pDD,&ddsdZ.ddsCaps,"dummy zbuf"); + + if(FAILED( hr = pDD->CreateSurface( &ddsdZ, &pddsDummyZ, NULL ) )) { + wdxdisplay_cat.fatal() << "Resize CreateSurface for temp zbuf failed : result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } + + if(FAILED( hr = pddsDummy->AddAttachedSurface( pddsDummyZ ) )) { + wdxdisplay_cat.fatal() << "Resize AddAttachedSurf for temp zbuf failed : result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } } - if(FAILED( hr = pddsDummy->AddAttachedSurface( pddsDummyZ ) )) { - wdxdisplay_cat.fatal() << "Resize AddAttachedSurf for temp zbuf failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - if(FAILED( hr = _dxgsg->GetD3DDevice()->SetRenderTarget( pddsDummy, 0x0 ))) { + if(FAILED( hr = _dxgsg->scrn.pD3DDevice->SetRenderTarget( pddsDummy, 0x0 ))) { wdxdisplay_cat.fatal() << "Resize failed to set render target to temporary surface, result = " << ConvD3DErrorToString(hr) << endl; exit(1); @@ -705,9 +727,13 @@ void wdxGraphicsWindow::handle_reshape(bool bDoDxReset) { } RECT view_rect; - GetClientRect( _mwindow, &view_rect ); - ClientToScreen( _mwindow, (POINT*)&view_rect.left ); // translates top,left pnt - ClientToScreen( _mwindow, (POINT*)&view_rect.right ); // translates right,bottom pnt + + assert(!dx_full_screen); + + HWND hWnd=_dxgsg->scrn.hWnd; + GetClientRect( hWnd, &view_rect ); + ClientToScreen( hWnd, (POINT*)&view_rect.left ); // translates top,left pnt + ClientToScreen( hWnd, (POINT*)&view_rect.right ); // translates right,bottom pnt // change _props xsize,ysize resized((view_rect.right - view_rect.left),(view_rect.bottom - view_rect.top)); @@ -721,7 +747,7 @@ void wdxGraphicsWindow::handle_reshape(bool bDoDxReset) { if(_dxgsg!=NULL) { if(bDoDxReset) - _dxgsg->dx_setup_after_resize(view_rect,_mwindow); // create the new resized rendertargets + _dxgsg->dx_setup_after_resize(view_rect,hWnd); // create the new resized rendertargets _dxgsg->SetDXReady(true); } } @@ -752,16 +778,16 @@ void wdxGraphicsWindow::deactivate_window(void) { if(_props._fullscreen) { // make sure window is minimized - + WINDOWPLACEMENT wndpl; wndpl.length=sizeof(WINDOWPLACEMENT); - - if(!GetWindowPlacement(_mwindow,&wndpl)) { - wdxdisplay_cat.error() << "GetWindowPlacement failed!\n"; - return; + if(!GetWindowPlacement(_dxgsg->scrn.hWnd,&wndpl)) { + wdxdisplay_cat.error() << "GetWindowPlacement failed!\n"; + return; } + if((wndpl.showCmd!=SW_MINIMIZE)&&(wndpl.showCmd!=SW_SHOWMINIMIZED)) { - ShowWindow(_mwindow, SW_MINIMIZE); + ShowWindow(_dxgsg->scrn.hWnd, SW_MINIMIZE); } throw_event("PandaPaused"); // right now this is used to signal python event handler to disable audio @@ -769,7 +795,8 @@ void wdxGraphicsWindow::deactivate_window(void) { // if(!bResponsive_minimized_fullscreen_window) { // need this even in responsive-mode to trigger the dxgsg check of cooplvl, i think? - _PandaPausedTimer = SetTimer(_mwindow,PAUSED_TIMER_ID,500,NULL); + + _PandaPausedTimer = SetTimer(_dxgsg->scrn.hWnd,PAUSED_TIMER_ID,500,NULL); if(_PandaPausedTimer!=PAUSED_TIMER_ID) { wdxdisplay_cat.error() << "Error in SetTimer!\n"; } @@ -789,13 +816,13 @@ void wdxGraphicsWindow::reactivate_window(void) { _window_inactive = false; if(_PandaPausedTimer!=NULL) { - KillTimer(_mwindow,_PandaPausedTimer); + KillTimer(_dxgsg->scrn.hWnd,_PandaPausedTimer); _PandaPausedTimer = NULL; } // move window to top of zorder // if(_props._fullscreen) - // SetWindowPos(_mwindow, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOOWNERZORDER); + // SetWindowPos(_DisplayDataArray[0].hWnd, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOOWNERZORDER); GdiFlush(); } else if(_active_minimized_fullscreen) { @@ -803,7 +830,7 @@ void wdxGraphicsWindow::reactivate_window(void) { wdxdisplay_cat.spam() << "WDX window unminimized from active-minimized state...\n"; if(_PandaPausedTimer!=NULL) { - KillTimer(_mwindow,_PandaPausedTimer); + KillTimer(_dxgsg->scrn.hWnd,_PandaPausedTimer); _PandaPausedTimer = NULL; } @@ -811,7 +838,7 @@ void wdxGraphicsWindow::reactivate_window(void) { // move window to top of zorder // if(_props._fullscreen) - // SetWindowPos(_mwindow, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOOWNERZORDER); + // SetWindowPos(_DisplayDataArray[0].hWnd, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOOWNERZORDER); GdiFlush(); } @@ -825,9 +852,9 @@ void wdxGraphicsWindow::reactivate_window(void) { // Access: // Description: //////////////////////////////////////////////////////////////////// -wdxGraphicsWindow:: -wdxGraphicsWindow(GraphicsPipe* pipe) : GraphicsWindow(pipe) { - config(); +wdxGraphicsWindow::wdxGraphicsWindow(GraphicsPipe* pipe) : GraphicsWindow(pipe) { + _pParentWindowGroup=NULL; + _pParentWindowGroup=new wdxGraphicsWindowGroup(this); } //////////////////////////////////////////////////////////////////// @@ -835,61 +862,50 @@ wdxGraphicsWindow(GraphicsPipe* pipe) : GraphicsWindow(pipe) { // Access: // Description: //////////////////////////////////////////////////////////////////// -wdxGraphicsWindow:: -wdxGraphicsWindow(GraphicsPipe* pipe, const - GraphicsWindow::Properties& props) : GraphicsWindow(pipe, props) { - config(); +wdxGraphicsWindow::wdxGraphicsWindow(GraphicsPipe* pipe, const GraphicsWindow::Properties& props) + : GraphicsWindow(pipe, props) { + _pParentWindowGroup=NULL; + _pParentWindowGroup=new wdxGraphicsWindowGroup(this); } -//////////////////////////////////////////////////////////////////// -// Function: config -// Access: -// Description: Set up win32 window -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow::config(void) { - GraphicsWindow::config(); - - global_wdxwinptr = this; // for use during createwin() - - _hdc = NULL; - _mwindow = NULL; - _gsg = _dxgsg = NULL; - _exiting_window = false; - _window_inactive = false; - _return_control_to_app = false; - _active_minimized_fullscreen = false; - _bIsLowVidMemCard = false; - - _hOldForegroundWindow=GetForegroundWindow(); - - if(dx_full_screen || _props._fullscreen) { - _props._fullscreen = dx_full_screen = true; +bool supports_color_cursors(DDDEVICEIDENTIFIER2 &DevID) { + // TODO: add more cards as more testing is done + if(IS_NVIDIA(DevID)) { + // all nvidia seem to support 256 color + return true; + } else if(IS_ATI(DevID)) { + // radeons seem to be in the 5100 range and support color, assume anything in 6000 or above + // is newer than radeon and supports 256 color + if(((DevID.dwDeviceId>=0x5100) && (DevID.dwDeviceId<=0x5200)) || + (DevID.dwDeviceId>=0x6000)) + return true; + } else if IS_MATROX(DevID) { + if(DevID.dwDeviceId==0x0525) // G400 seems to support color cursors, havent tested other matrox + return true; } - _WindowAdjustingType = NotAdjusting; - _hMouseCursor = NULL; - _bSizeIsMaximized=FALSE; - - // Create a GSG to manage the graphics - make_gsg(); - if(_gsg==NULL) { - wdxdisplay_cat.error() << "DXGSG creation failed!\n"; - exit(1); - } - _dxgsg = DCAST(DXGraphicsStateGuardian, _gsg); - - HINSTANCE hinstance = GetModuleHandle(NULL); + return false; +} +void wdxGraphicsWindowGroup::CreateWindows(void) { + HINSTANCE hProgramInstance = GetModuleHandle(NULL); WNDCLASS wc; + static bool wc_registered = false; + _hParentWindow = NULL; + _bLoadedCustomCursor=false; // Clear before filling in window structure! ZeroMemory(&wc, sizeof(WNDCLASS)); wc.style = CS_HREDRAW | CS_VREDRAW; //CS_OWNDC; wc.lpfnWndProc = (WNDPROC) static_window_proc; - wc.hInstance = hinstance; + wc.hInstance = hProgramInstance; + wc.hCursor = NULL; // for DX8 we handle the cursor messages ourself +#if 0 + // all this must be moved to dx_init, since we need to create DX surface string windows_icon_filename = get_icon_filename().to_os_specific(); string windows_mono_cursor_filename = get_mono_cursor_filename().to_os_specific(); + string windows_color_cursor_filename = get_color_cursor_filename().to_os_specific(); if(!windows_icon_filename.empty()) { // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) @@ -905,9 +921,55 @@ void wdxGraphicsWindow::config(void) { wc.hIcon = NULL; // use default app icon } - _bLoadedCustomCursor=false; - if(!windows_mono_cursor_filename.empty()) { + if(!windows_color_cursor_filename.empty()) { + // card support for full color non-black/white GDI cursors varies greatly. if the cursor is not supported, + // it is rendered in software by GDI, which causes a flickering effect (because it's not synced + // with flip?). GDI transparently masks the lack of HW support so there is no easy way for app to detect + // if HW cursor support exists. alternatives are to tie cursor motion to frame rate using DDraw blts + // or overlays (this is done automatically by DX8 runtime mouse cursor support), or to have separate thread draw cursor + // (sync issues?). instead we do mono cursor unless card is known to support 256 color cursors + bool bSupportsColorCursor=true; + + /* if any card doesnt support color, dont load it*/ + for(int w=0;w<_windows.size();w++) + bSupportsColorCursor &= supports_color_cursors(_windows[w]->_dxgsg->scrn.DXDeviceID); + + if(bSupportsColorCursor) { + DWORD load_flags = LR_LOADFROMFILE; + + if(dx_full_screen) { + // I think cursors should use LR_CREATEDIBSECTION since they should not be mapped to the device palette (in the case of 256-color cursors) + // since they are not going to be used on the desktop + load_flags |= LR_CREATEDIBSECTION; + } + + // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) + // if icon is more than 8bpp + + // loads a .cur fmt file. + _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_color_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, load_flags ); + + if(_hMouseCursor==NULL) { + wdxdisplay_cat.warning() << "windows color cursor filename '" << windows_color_cursor_filename << "' not found!!\n"; + goto try_mono_cursor; + + } + +/* dont need these anymore since we are do mousestuff before window creation + SetClassLongPtr(_mwindow, GCLP_HCURSOR, (LONG_PTR) hNewMouseCursor); + SetCursor(hNewMouseCursor); + + if(_bLoadedCustomCursor) + DestroyCursor(_hMouseCursor); +*/ + _bLoadedCustomCursor=true; + } + } + + try_mono_cursor: + + if((!_bLoadedCustomCursor) && (!windows_mono_cursor_filename.empty())) { // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) // if icon is more than 8bpp @@ -922,38 +984,86 @@ void wdxGraphicsWindow::config(void) { _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_mono_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, load_flags); if(_hMouseCursor==NULL) { - wdxdisplay_cat.warning() << "windows cursor filename '" << windows_mono_cursor_filename << "' not found!!\n"; - _hMouseCursor = LoadCursor(NULL, IDC_ARROW); - } - _bLoadedCustomCursor=true; - } else { - _hMouseCursor = LoadCursor(NULL, IDC_ARROW); + wdxdisplay_cat.warning() << "windows mono cursor filename '" << windows_mono_cursor_filename << "' not found!!\n"; + } else _bLoadedCustomCursor=true; } - wc.hCursor = _hMouseCursor; - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszMenuName = NULL; - wc.lpszClassName = WDX_WINDOWCLASSNAME; + if(!_bLoadedCustomCursor) + _hMouseCursor = LoadCursor(NULL, DEFAULT_CURSOR); - if(!RegisterClass(&wc)) { - wdxdisplay_cat.fatal() << "could not register window class!" << endl; - exit(1); + + #endif + + if (!wc_registered) { + // We only need to register the window class once per session. + wc.hCursor = _hMouseCursor; + wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = WDX_WINDOWCLASSNAME; + + if(!RegisterClass(&wc)) { + wdxdisplay_cat.error() << "could not register window class!" << endl; + } + wc_registered = true; } DWORD window_style = WS_POPUP | WS_SYSMENU; // for CreateWindow + global_wdxwinptr = _windows[0]; // for use during createwin() bugbug look at this again + // rect now contains the coords for the entire window, not the client if(dx_full_screen) { + // get upper-left corner coords using GetMonitorInfo - _mwindow = CreateWindow(WDX_WINDOWCLASSNAME, _props._title.c_str(), - window_style, 0, 0, _props._xsize,_props._ysize, - NULL, NULL, hinstance, 0); + // GetMonInfo doesnt exist on w95, so dont statically link to it + HINSTANCE hUser32 = (HINSTANCE) LoadLibrary("user32.dll"); + assert(hUser32); + typedef BOOL (WINAPI* LPGETMONITORINFO)(HMONITOR, LPMONITORINFO); + LPGETMONITORINFO pfnGetMonitorInfo = (LPGETMONITORINFO) GetProcAddress(hUser32, "GetMonitorInfoA"); + + // extra windows must be parented to the first so app doesnt minimize when user selects them + + for(int devnum=0;devnum<_windows.size();devnum++) { + MONITORINFO minfo; + ZeroMemory(&minfo, sizeof(MONITORINFO)); + minfo.cbSize = sizeof(MONITORINFO); + if(pfnGetMonitorInfo) + (*pfnGetMonitorInfo)(_windows[devnum]->_dxgsg->scrn.hMon, &minfo); + else { + minfo.rcMonitor.left = minfo.rcMonitor.top = 0; + } + + GraphicsWindow::Properties *props = &_windows[devnum]->_props; + + HWND hWin = CreateWindow(WDX_WINDOWCLASSNAME, props->_title.c_str(), + window_style, minfo.rcMonitor.left, minfo.rcMonitor.top, + props->_xsize,props->_ysize, + _hParentWindow, NULL, hProgramInstance, 0); + + if(!hWin) { + wdxdisplay_cat.fatal() << "CreateWindow failed for monitor " << devnum << "!, LastError=" << GetLastError() << endl; + #ifdef _DEBUG + PrintErrorMessage(LAST_ERROR); + #endif + exit(1); + } + + _windows[devnum]->_dxgsg->scrn.hWnd = hWin; + if(devnum==0) { + _hParentWindow=hWin; + } + } + FreeLibrary(hUser32); } else { - RECT win_rect; - SetRect(&win_rect, _props._xorg, _props._yorg, _props._xorg + _props._xsize, - _props._yorg + _props._ysize); + assert(_windows.size()==1); - if(_props._border) + GraphicsWindow::Properties *props = &_windows[0]->_props; + + RECT win_rect; + SetRect(&win_rect, props->_xorg, props->_yorg, props->_xorg + props->_xsize, + props->_yorg + props->_ysize); + + if(props->_border) window_style |= WS_OVERLAPPEDWINDOW; // should we just use WS_THICKFRAME instead? AdjustWindowRect(&win_rect, window_style, FALSE); //compute window size based on desired client area size @@ -966,27 +1076,75 @@ void wdxGraphicsWindow::config(void) { win_rect.bottom -= win_rect.top; win_rect.top = 0; } - _mwindow = CreateWindow(WDX_WINDOWCLASSNAME, _props._title.c_str(), - window_style, win_rect.left, win_rect.top, win_rect.right-win_rect.left, - win_rect.bottom-win_rect.top, - NULL, NULL, hinstance, 0); + _hParentWindow = + CreateWindow(WDX_WINDOWCLASSNAME, props->_title.c_str(), + window_style, win_rect.left, win_rect.top, win_rect.right-win_rect.left, + win_rect.bottom-win_rect.top, + NULL, NULL, hProgramInstance, 0); + _windows[0]->_dxgsg->scrn.hWnd = _hParentWindow; } - if(!_mwindow) { - wdxdisplay_cat.fatal() << "config() - failed to create window" << endl; + if(_hParentWindow==NULL) { + wdxdisplay_cat.fatal() << "CreateWindow failed!\n"; exit(1); } - hwnd_pandawin_map[_mwindow] = this; + for(int devnum=0;devnum<_windows.size();devnum++) { + wdxGraphicsWindow *pWDXWin = _windows[devnum]; + // for use by the window_proc + hwnd_pandawin_map[pWDXWin->_dxgsg->scrn.hWnd] = pWDXWin; + +/* + // DC is mostly used for writing fps meter (but also old palette code, which needs updating) + // probably only need to do this for devnum 0 + HDC hdc = GetDC(pWDXWin->_dxgsg_>scrn.hWnd); + pWDXWin->_dxgsg->Set_HDC(hdc); +*/ + } + + // now we can stop using the global_wdxwinptr crutch since windows are created global_wdxwinptr = NULL; // get rid of any reference to this obj +} - // move window to top of zorder - SetWindowPos(_mwindow, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE); +//////////////////////////////////////////////////////////////////// +// Function: config +// Access: +// Description: Set up win32 window. +//////////////////////////////////////////////////////////////////// +void wdxGraphicsWindow::config_window(wdxGraphicsWindowGroup *pParentGroup) { +// assert(_pParentWindowGroup==NULL); + _pParentWindowGroup=pParentGroup; - _hdc = GetDC(_mwindow); + GraphicsWindow::config(); - dx_setup(); + _hdc = NULL; + _gsg = _dxgsg = NULL; + _exiting_window = false; + _window_inactive = false; + _return_control_to_app = false; + _active_minimized_fullscreen = false; + if(dx_full_screen || _props._fullscreen) { + _props._fullscreen = dx_full_screen = true; + } + + _WindowAdjustingType = NotAdjusting; + _bSizeIsMaximized=FALSE; + + _gsg = _dxgsg = NULL; + // Create a GSG to manage the graphics + if(_gsg==NULL) { + make_gsg(); + if(_gsg==NULL) { + wdxdisplay_cat.error() << "make_gsg() failed!\n"; + exit(1); + } + } + _dxgsg = DCAST(DXGraphicsStateGuardian, _gsg); +} + +void wdxGraphicsWindow::finish_window_setup(void) { + // init panda input handling _mouse_input_enabled = false; _mouse_motion_enabled = false; _mouse_passive_motion_enabled = false; @@ -1002,11 +1160,18 @@ void wdxGraphicsWindow::config(void) { GraphicsWindowInputDevice device = GraphicsWindowInputDevice::pointer_and_keyboard("keyboard/mouse"); _input_devices.push_back(device); - ShowWindow(_mwindow, SW_SHOWNORMAL); - ShowWindow(_mwindow, SW_SHOWNORMAL); // call twice to override STARTUPINFO value, which may be set to hidden initially by emacs -// UpdateWindow( _mwindow ); + // move windows to top of zorder + HWND hWin = _dxgsg->scrn.hWnd; + + SetWindowPos(hWin, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE); + // call twice to override STARTUPINFO value, which may be set to hidden initially (by emacs for instance) + ShowWindow(hWin, SW_SHOWNORMAL); + ShowWindow(hWin, SW_SHOWNORMAL); + // UpdateWindow( _mwindow ); } + + HRESULT CALLBACK EnumDevicesCallback(LPSTR pDeviceDescription, LPSTR pDeviceName, LPD3DDEVICEDESC7 pD3DDeviceDesc,LPVOID pContext) { D3DDEVICEDESC7 *pd3ddevs = (D3DDEVICEDESC7 *)pContext; @@ -1053,46 +1218,90 @@ HRESULT WINAPI EnumDisplayModesCallBack(LPDDSURFACEDESC2 lpDDSurfaceDesc,LPVOID return DDENUMRET_OK; } -BOOL WINAPI DriverEnumCallback( GUID* pGUID, TCHAR* strDesc,TCHAR* strName, +/* +BOOL WINAPI DriverEnumCallback_Voodoo1( GUID* pGUID, TCHAR* strDesc,TCHAR* strName, VOID *argptr, HMONITOR hm) { - if(hm!=NULL) // skip over non-primary display devices + + if(hm!=NULL) // skip over non-primary and non-voodoo-type display devices return DDENUMRET_OK; + GUID null_guid; + ZeroMemory(&null_guid,sizeof(GUID)); + // primary display driver will have NULL guid - // ignore that and save any non-null value, whic + // ignore that and save any non-null value, which // indicates a secondary driver, which is usually voodoo1/2 - if(pGUID!=NULL) { + if((pGUID!=NULL) && !IsEqualGUID(null_guid,*pGUID)) { memcpy(argptr,pGUID,sizeof(GUID)); } return DDENUMRET_OK; } + +BOOL WINAPI save_devinfo( GUID* pGUID, TCHAR* strDesc,TCHAR* strName,VOID *argptr, HMONITOR hm) { + + DXDeviceInfoVec *pDevInfoArr = (DXDeviceInfoVec *) argptr; + + DXDeviceInfo devinfo; + ZeroMemory(&devinfo,sizeof(devinfo)); + + // primary display driver will have NULL guid + if(pGUID!=NULL) { + memcpy(&devinfo.guidDeviceIdentifier,pGUID,sizeof(GUID)); + } + if(strDesc!=NULL) { + _tcsncpy(devinfo.szDescription, + strDesc, + MAX_DDDEVICEID_STRING); + } + if(strName!=NULL) { + _tcsncpy(devinfo.szDriver,strName,MAX_DDDEVICEID_STRING); + } + devinfo.hMon=hm; + + pDevInfoArr->push_back(devinfo); + return DDENUMRET_OK; +} + +BOOL WINAPI DriverEnumCallback_MultiMon( GUID* pGUID, TCHAR* strDesc,TCHAR* strName,VOID *argptr, HMONITOR hm) { + if(hm==NULL) { + // skip over the 'primary' since it will duplicated later as an explicit device + return DDENUMRET_OK; + } + + return save_devinfo(pGUID,strDesc,strName,argptr,hm); +} +*/ void wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { - if(wdxdisplay_cat.is_debug()) - wdxdisplay_cat.debug() << "resize("<scrn.hWnd, NULL, 0,0, xsize, ysize, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSENDCHANGING); // WM_ERASEBKGND will be ignored, because _WindowAdjustingType!=NotAdjusting because // we dont want to redraw as user is manually resizing window, so need to force explicit // background clear for the programmatic resize fn call - _WindowAdjustingType=NotAdjusting; - + _WindowAdjustingType=NotAdjusting; + // this doesnt seem to be working in toontown resize, so I put ddraw blackblt in handle_reshape instead //window_proc(_mwindow, WM_ERASEBKGND,(WPARAM)_hdc,0x0); handle_reshape(true); return; } + if(wdxdisplay_cat.is_info()) + wdxdisplay_cat.info() << "resize("<SetDXReady(false); HRESULT hr; DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_curmode); - if(FAILED(hr = _dxgsg->_pDD->GetDisplayMode(&ddsd_curmode))) { + if(FAILED(hr = _dxgsg->scrn.pDD->GetDisplayMode(&ddsd_curmode))) { wdxdisplay_cat.fatal() << "resize() - GetDisplayMode failed, result = " << ConvD3DErrorToString(hr) << endl; exit(1); } @@ -1111,12 +1320,12 @@ void wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { DMI.maxWidth=xsize; DMI.maxHeight=ysize; DMI.pDDSD_Arr=DDSD_Arr; - if(FAILED(hr = _dxgsg->_pDD->EnumDisplayModes(DDEDM_REFRESHRATES,&ddsd_search,&DMI,EnumDisplayModesCallBack))) { + if(FAILED(hr = _dxgsg->scrn.pDD->EnumDisplayModes(DDEDM_REFRESHRATES,&ddsd_search,&DMI,EnumDisplayModesCallBack))) { wdxdisplay_cat.fatal() << "resize() - EnumDisplayModes failed, result = " << ConvD3DErrorToString(hr) << endl; return; } - DMI.supportedBitDepths &= _dxgsg->_D3DDevDesc.dwDeviceRenderBitDepth; + DMI.supportedBitDepths &= _dxgsg->scrn.D3DDevDesc.dwDeviceRenderBitDepth; DWORD dwFullScreenBitDepth; DWORD requested_bpp=ddsd_curmode.ddpfPixelFormat.dwRGBBitCount; @@ -1136,7 +1345,7 @@ void wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { return; } - if(FAILED(hr = _dxgsg->_pDD->TestCooperativeLevel())) { + if(FAILED(hr = _dxgsg->scrn.pDD->TestCooperativeLevel())) { wdxdisplay_cat.error() << "TestCooperativeLevel failed : result = " << ConvD3DErrorToString(hr) << endl; wdxdisplay_cat.error() << "Full screen app failed to get exclusive mode on resize, exiting..\n"; return; @@ -1145,17 +1354,20 @@ void wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { _dxgsg->free_dxgsg_objects(); // let driver choose default refresh rate (hopefully its >=60Hz) - if(FAILED( hr = _dxgsg->_pDD->SetDisplayMode( xsize,ysize,dwFullScreenBitDepth, 0L, 0L ))) { + if(FAILED( hr = _dxgsg->scrn.pDD->SetDisplayMode( xsize,ysize,dwFullScreenBitDepth, 0L, 0L ))) { wdxdisplay_cat.error() << "resize failed to reset display mode to (" << xsize <<"x"<_pDD,_dxgsg->_d3d,NULL); + _dxgsg->scrn.dwRenderWidth=xsize; + _dxgsg->scrn.dwRenderHeight=ysize; + + CreateScreenBuffersAndDevice(_dxgsg->scrn); _dxgsg->RecreateAllVideoSurfaces(); _dxgsg->SetDXReady(true); } @@ -1171,33 +1383,48 @@ verify_window_sizes(unsigned int numsizes,unsigned int *dimen) { DisplayModeInfo DMI; DWORD i,*pCurDim=(DWORD *)dimen; - for(i=0;i_pDD->EnumDisplayModes(DDEDM_REFRESHRATES,&ddsd_search,&DMI,EnumDisplayModesCallBack))) { + if(FAILED(hr = _dxgsg->scrn.pDD->EnumDisplayModes(DDEDM_REFRESHRATES,&ddsd_search,&DMI,EnumDisplayModesCallBack))) { wdxdisplay_cat.fatal() << "resize() - EnumDisplayModes failed, result = " << ConvD3DErrorToString(hr) << endl; return 0; } // get rid of bpp's we cant render at - DMI.supportedBitDepths &= _dxgsg->_D3DDevDesc.dwDeviceRenderBitDepth; + DMI.supportedBitDepths &= _dxgsg->scrn.D3DDevDesc.dwDeviceRenderBitDepth; bool bIsGoodMode=false; - if(_bIsLowVidMemCard) + if(_dxgsg->scrn.bIsLowVidMemCard) bIsGoodMode=(((float)xsize*(float)ysize)<=(float)(640*480)); - else bIsGoodMode=((DMI.supportedBitDepths & (DDBD_16 | DDBD_24 | DDBD_32))!=0); + else if(DMI.supportedBitDepths & (DDBD_16 | DDBD_24 | DDBD_32)) { + // assume user is testing fullscreen, not windowed, so use the dwTotal value + // see if 3 scrnbufs (front/back/z)at 16bpp at xsize*ysize will fit with a few + // extra megs for texmem + + // 8MB Rage Pro says it has 6.8 megs Total free and will run at 1024x768, so + // formula makes it so that is OK + + #define REQD_TEXMEM 1800000.0f + + if(_dxgsg->scrn.MaxAvailVidMem==0) { + //assume buggy drivers return bad val of 0 and everything will be OK + bIsGoodMode=true; + } else { + bIsGoodMode = ((((float)xsize*(float)ysize)*6+REQD_TEXMEM) < (float)_dxgsg->scrn.MaxAvailVidMem); + } + } if(bIsGoodMode) num_valid_modes++; @@ -1210,11 +1437,7 @@ verify_window_sizes(unsigned int numsizes,unsigned int *dimen) { return num_valid_modes; } -// imperfect method to ID NVid? could also scan desc str, but that isnt fullproof either -#define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.dwVendorId==0x10DE) || (DDDEVICEID.dwVendorId==0x12D2)) -#define IS_ATI(DDDEVICEID) (DDDEVICEID.dwVendorId==0x1002) -#define IS_MATROX(DDDEVICEID) (DDDEVICEID.dwVendorId==0x102B) - +/* void wdxGraphicsWindow:: check_for_color_cursor_support(void) { // card support for non-black/white GDI cursors varies greatly. if the cursor is not supported, @@ -1274,281 +1497,306 @@ check_for_color_cursor_support(void) { _hMouseCursor = hNewMouseCursor; } } +*/ -//////////////////////////////////////////////////////////////////// -// Function: dx_setup -// Description: Set up the DirectX environment. The size of the -// rendered area will be computed from the Client area -// of the window (if in windowed mode) and the _props -// structure will be set accordingly. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow:: -dx_setup() { - LPDIRECT3D7 pD3DI; - LPDIRECTDRAW7 pDD; +// returns true if successful +bool wdxGraphicsWindow::search_for_device(LPDIRECT3D8 pD3D8,DXDeviceInfo *pDevinfo) { + DWORD dwRenderWidth = _props._xsize; + DWORD dwRenderHeight = _props._ysize; HRESULT hr; - DX_DECLARE_CLEAN( DDSURFACEDESC2, SurfaceDesc ); - // Check for DirectX 7 by looking for DirectDrawCreateEx + assert(_dxgsg!=NULL); + _dxgsg->scrn.pD3D8 = pD3D8; - HINSTANCE DDHinst = LoadLibrary( "ddraw.dll" ); - if(DDHinst == 0) { - wdxdisplay_cat.fatal() << "can't locate DDRAW.DLL!" << endl; - exit(1); - } - - if(NULL == GetProcAddress( DDHinst, "DirectDrawCreateEx" )) { - wdxdisplay_cat.fatal() << "Panda currently requires at least DirectX 7.0!" << endl; - exit(1); - } - - GUID DriverGUID; - ZeroMemory(&DriverGUID,sizeof(GUID)); - - // search for early voodoo-type non-primary display drivers - // if they exist, use them for 3D (could examine 3D devices on all - // drivers and pick the best one, but I'll assume the computer setuper knows what he's doing) - if(hr = DirectDrawEnumerateEx( DriverEnumCallback, &DriverGUID, DDENUM_NONDISPLAYDEVICES )) { - wdxdisplay_cat.fatal() << "config() - DirectDrawEnumerateEx failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - GUID *pOurDriverGUID=NULL; - if(DriverGUID.Data1 != 0x0) { // assumes no driver guid ever starts with 0, so 0 means Enum found no voodoo-type device - pOurDriverGUID=&DriverGUID; - } - - // Create the Direct Draw Object - hr = DirectDrawCreateEx(pOurDriverGUID, (void **)&pDD, IID_IDirectDraw7, NULL); - if(hr != DD_OK) { - wdxdisplay_cat.fatal() - << "config() - DirectDrawCreateEx failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - FreeLibrary(DDHinst); //undo LoadLib above, decrement ddrawl.dll refcnt (after DDrawCreate, since dont want to unload/reload) - - pDD->GetDeviceIdentifier(&_DXDeviceID,0x0); - -#ifdef _DEBUG - wdxdisplay_cat.debug() << " GfxCard: " << _DXDeviceID.szDescription << "; DriverFile: '" << _DXDeviceID.szDriver << "'; VendorID: " <<_DXDeviceID.dwVendorId <<"; DriverVer: " << HIWORD(_DXDeviceID.liDriverVersion.HighPart) << "." << LOWORD(_DXDeviceID.liDriverVersion.HighPart) << "." << HIWORD(_DXDeviceID.liDriverVersion.LowPart) << "." << LOWORD(_DXDeviceID.liDriverVersion.LowPart) << endl; -#endif - - check_for_color_cursor_support(); - - // Query DirectDraw for access to Direct3D - - hr = pDD->QueryInterface( IID_IDirect3D7, (VOID**)&pD3DI ); - if(hr != DD_OK) { - wdxdisplay_cat.fatal() << "QI for D3D failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + D3DCAPS8 d3dcaps; + hr = pD3D8->GetDeviceCaps(pDevInfo->cardID,D3DDEVTYPE_HAL,&d3dcaps); + if(FAILED(hr)) { + if(hr==D3DERR_INVALIDDEVICE) { + wdxdisplay_cat.fatal() << "No D3D-capable 3D hardware detected! Exiting...\n"; + } else { + wdxdisplay_cat.fatal() << "GetDeviceCaps failed, hr = " << D3DERRORSTRING(hr); + } + exit(1); } +/* + LPDIRECTDRAW7 pDD; D3DDEVICEDESC7 d3ddevs[2]; // put HAL in 0, TnLHAL in 1 - // just look for HAL and TnL devices right now. I dont think // we have any interest in the sw rasts at this point ZeroMemory(d3ddevs,2*sizeof(D3DDEVICEDESC7)); - hr = pD3DI->EnumDevices(EnumDevicesCallback,d3ddevs); + hr = _dxgsg->scrn.pD3D->EnumDevices(EnumDevicesCallback,d3ddevs); if(hr != DD_OK) { - wdxdisplay_cat.fatal() << "EnumDevices failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + wdxdisplay_cat.fatal() << "EnumDevices failed : result = " << ConvD3DErrorToString(hr) << endl; + goto error_exit; + } + + WORD DeviceIdx; + DeviceIdx=REGHALIDX; + + if(!(d3ddevs[REGHALIDX].dwDevCaps & D3DDEVCAPS_HWRASTERIZATION )) { + // should never get here because enum devices should filter out non-HAL devices + wdxdisplay_cat.error() << "No 3D HW present on device #"<scrn.DXDeviceID.szDescription<<")\n"; + goto error_exit; } - WORD DeviceIdx=REGHALIDX; + memcpy(&_dxgsg->scrn.D3DDevDesc,&d3ddevs[DeviceIdx],sizeof(D3DDEVICEDESC7)); +*/ - if(!(d3ddevs[DeviceIdx].dwDevCaps & D3DDEVCAPS_HWRASTERIZATION )) { - wdxdisplay_cat.fatal() << "No 3D HW present, exiting..." << endl; - exit(1); + _dxgsg->scrn.bIsTNLDevice=((d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)!=0); + + // only way to get vidmem estimate prior to device creation and displaymode changing on DX8 is to use DX7 ddraw + + // Create the Direct Draw Objects + hr = (*_pParentWindowGroup->_pDDCreateEx)(&pDevInfo->guidDeviceIdentifier,(void **)&pDD, IID_IDirectDraw7, NULL); + if(hr != DD_OK) { + wdxdisplay_cat.fatal() << "DirectDrawCreateEx failed for monitor("<cardID<<": result = " << D3DERRORSTRING(hr); + exit(1); + } - DDSURFACEDESC2 DDSD_Arr[MAX_DISPLAY_MODES]; - DisplayModeInfo DMI; - ZeroMemory(&DDSD_Arr,sizeof(DDSD_Arr)); - ZeroMemory(&DMI,sizeof(DMI)); - DMI.maxWidth=dwRenderWidth; DMI.maxHeight=dwRenderHeight; - DMI.pDDSD_Arr=DDSD_Arr; + if((dispmode.Width==dwRenderWidth) && (dispmode.Height==dwRenderHeight)) { + if(FAILED(hr = pD3D8->CheckDeviceFormat(pDevInfo->cardID,D3DDEVTYPE_HAL,dispmode.Format, + D3DUSAGE_RENDERTARGET,dispmode.Format)) { + if(hr==D3DERR_NOTAVAILABLE) + continue; + else { + wdxdisplay_cat.error() << "CheckDeviceFormat failed for device #"<cardID<<": result = " << D3DERRORSTRING(hr); + exit(1); + } + } - if(FAILED(hr= pDD->EnumDisplayModes(DDEDM_REFRESHRATES,&ddsd_search,&DMI,EnumDisplayModesCallBack))) { - wdxdisplay_cat.fatal() << "EnumDisplayModes failed, result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } + switch(dispmode.Format) { + case D3DFMT_X1R5G5B5: + _dxgsg->scrn.dwSupportedScreenDepths |= X1R5G5B5_FLAG; + break; + case D3DFMT_X8R8G8B8: + _dxgsg->scrn.dwSupportedScreenDepths |= X8R8G8B8_FLAG; + break; + case D3DFMT_R8G8B8: + _dxgsg->scrn.dwSupportedScreenDepths |= R8G8B8_FLAG; + break; + case D3DFMT_R5G6B5: + _dxgsg->scrn.dwSupportedScreenDepths |= R5G6B5_FLAG; + break; + default: + //Render target formats should be only D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_X8R8G8B8 (or R8G8B8?) + wdxdisplay_cat.debug() << "unrecognized supported screen D3DFMT returned by EnumAdapterDisplayModes!\n"; + } + } + } +/* + if(wdxdisplay_cat.is_info()) + wdxdisplay_cat.info() << "Before fullscreen switch: GetAvailableVidMem for device #"<scrn.D3DDevDesc.dwDeviceRenderBitDepth; +*/ + // note I'm not saving refresh rate, will just use adapter default at given res for now - DWORD dwFullScreenBitDepth; + // note: this chooses 32bpp, which may not be preferred over 16 for memory & speed reasons on some older cards in particular - // Now we try to figure out if we can use requested screen resolution and best - // rendertarget bpp and still have at least 2 meg of texture vidmem + D3DFORMAT pixFmt; - // Get Current VidMem avail. Note this is only an estimate, when we switch to fullscreen - // mode from desktop, more vidmem will be available (typically 1.2 meg). I dont want - // to switch to fullscreen more than once due to the annoying monitor flicker, so try - // to figure out optimal mode using this estimate - DDSCAPS2 ddsCaps; - DWORD dwTotal,dwFree; - ZeroMemory(&ddsCaps,sizeof(DDSCAPS2)); - ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; //set internally by DX anyway, dont think this any different than 0x0 - - if(FAILED( hr = pDD->GetAvailableVidMem(&ddsCaps,&dwTotal,&dwFree))) { - wdxdisplay_cat.error() << "GetAvailableVidMem failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - #ifdef _DEBUG - wdxdisplay_cat.debug() << "before FullScreen switch: GetAvailableVidMem returns Total: " << dwTotal/1000000.0 << " Free: " << dwFree/1000000.0 << endl; - #endif - - DMI.supportedBitDepths &= pD3DDevDesc->dwDeviceRenderBitDepth; - - // note: this chooses 32bpp, which may not be preferred over 16 for memory & speed reasons - if(DMI.supportedBitDepths & DDBD_32) { - dwFullScreenBitDepth=32; // go for 32bpp if its avail - } else if(DMI.supportedBitDepths & DDBD_24) { - dwFullScreenBitDepth=24; // go for 24bpp if its avail - } else if(DMI.supportedBitDepths & DDBD_16) { - dwFullScreenBitDepth=16; // do 16bpp - } else { - wdxdisplay_cat.fatal() - << "No Supported FullScreen resolutions at " << dwRenderWidth << "x" << dwRenderHeight << endl; - exit(1); - } - - if(dwFree>0) { // assume buggy drivers (this means you, FireGL2) may return zero for dwTotal, so ignore value if its 0 + if(_dxgsg->scrn.dwSupportedScreenDepths & X8R8G8B8_FLAG) + pixFmt = D3DFORMAT_X8R8G8B8; + else if(_dxgsg->scrn.dwSupportedScreenDepths & R8G8B8_FLAG) + pixFmt = D3DFORMAT_R8G8B8; + else if(_dxgsg->scrn.dwSupportedScreenDepths & R5G6B5_FLAG) + pixFmt = D3DFORMAT_R5G6B5; + else if(_dxgsg->scrn.dwSupportedScreenDepths & X1R5G5B5_FLAG) + pixFmt = D3DFORMAT_X1R5G5B5; + else { + wdxdisplay_cat.fatal() << "No supported FullScreen resolutions at " << dwRenderWidth << "x" << dwRenderHeight + << " for device #" << pDevInfo->cardID << " (" << _dxgsg->scrn.DXDeviceID.szDescription<<"), skipping device...\n"; + return false; + } + + if(_dxgsg->scrn.bIsLowVidMemCard) { // hack: figuring out exactly what res to use is tricky, instead I will // just use 640x480 if we have < 3 meg avail - - #define LOWVIDMEMTHRESHOLD 3500000 - if(dwFree< LOWVIDMEMTHRESHOLD) { - // we're going to need 800x600 or 640x480 at 16 bit to save enough tex vidmem - dwFullScreenBitDepth=16; // do 16bpp - dwRenderWidth=640; - dwRenderHeight=480; - _bIsLowVidMemCard = true; - wdxdisplay_cat.debug() << " "<scrn.dwSupportedScreenDepths & R5G6B5_FLAG) + pixFmt = D3DFORMAT_R5G6B5; + else if(_dxgsg->scrn.dwSupportedScreenDepths & X1R5G5B5_FLAG) + pixFmt = D3DFORMAT_X1R5G5B5; + else { + wdxdisplay_cat.fatal() << "Low Memory VidCard has no supported FullScreen 16bpp resolutions at "<< dwRenderWidth << "x" << dwRenderHeight + << " for device #" << pDevInfo->cardID << " (" << _dxgsg->scrn.DXDeviceID.szDescription<<"), skipping device...\n"; + return false; } - - #if 0 - // cant do this without more accurate way to estimate mem used before actually switching - // to that fullscrn mode. simply computing memsize based on GetDisplayMode doesnt seem - // to be accurate within more than 1 meg - - // we think we need to reserve at least 2 megs of vidmem for textures. - // to do this, reduce buffer bitdepth if possible - #define RESERVEDTEXVIDMEM 2000000 - - int rendertargetmem=dwRenderWidth*dwRenderHeight*(dwFullScreenBitDepth>>3); - int memleft = dwFree-rendertargetmem*2; //*2 to handle backbuf/zbuf - - if(memleft < RESERVEDTEXVIDMEM) { - dwFullScreenBitDepth=16; - wdxdisplay_cat.debug() << "using 16bpp rendertargets to save tex vidmem\n"; - assert((DMI.supportedBitDepths & DDBD_16) && (pD3DDevDesc->dwDeviceRenderBitDepth & DDBD_16)); // probably a safe assumption - rendertargetmem=dwRenderWidth*dwRenderHeight*(dwFullScreenBitDepth>>3); - memleft = dwFree-rendertargetmem*2; - - // BUGBUG: if we still cant reserve 2 megs of vidmem, need to auto-reduce the scrn res - if(memleft < RESERVEDTEXVIDMEM) - wdxdisplay_cat.debug() << " XXXXXX WARNING: cant reserve 2MB of tex vidmem. only " << memleft << " bytes available. Need to rewrite wdxdisplay to try lower resolutions XXXXXXXXXXXXXXXXXXXX\n"; - } - #endif - } - - // extern bool dx_preserve_fpu_state; - DWORD SCL_FPUFlag = DDSCL_FPUSETUP; - - // if(dx_preserve_fpu_state) - // SCL_FPUFlag = DDSCL_FPUPRESERVE; // tell d3d to preserve the fpu state across calls. this hurts perf, but is good for dbgging - - DWORD SCL_FLAGS = SCL_FPUFlag | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; - - if(FAILED(hr = pDD->SetCooperativeLevel(_mwindow, SCL_FLAGS))) { - wdxdisplay_cat.fatal() << "SetCooperativeLevel failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - // s3 savage2000 on w95 seems to set EXCLUSIVE_MODE only if you call SetCoopLevel twice. - // so we do it, it really shouldnt be necessary if drivers werent buggy - if(FAILED(hr = pDD->SetCooperativeLevel(_mwindow, SCL_FLAGS))) { - wdxdisplay_cat.fatal() - << "SetCooperativeLevel failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - if(FAILED(hr = pDD->TestCooperativeLevel())) { - wdxdisplay_cat.fatal() << "TestCooperativeLevel failed : result = " << ConvD3DErrorToString(hr) << endl; - wdxdisplay_cat.fatal() << "Full screen app failed to get exclusive mode on init, exiting..\n"; - exit(1); - } - - // let driver choose default refresh rate (hopefully its >=60Hz) - if(FAILED( hr = pDD->SetDisplayMode( dwRenderWidth, dwRenderHeight, - dwFullScreenBitDepth, 0L, 0L ))) { - wdxdisplay_cat.fatal() << "failed to reset display mode to ("<GetAvailableVidMem(&ddsCaps,&dwTotal,&dwFree))) { - wdxdisplay_cat.debug() << "GetAvailableVidMem failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - wdxdisplay_cat.debug() << "after FullScreen switch: GetAvailableVidMem returns Total: " << dwTotal/1000000.0 << " Free: " << dwFree/1000000.0 << endl; - #endif - } + dwRenderWidth=640; + dwRenderHeight=480; + dx_force_16bpptextures = true; + + if(wdxdisplay_cat.is_info()) + wdxdisplay_cat.info() << "Available VidMem (" << dwVidMemFree<<") is under " << LOWVIDMEMTHRESHOLD <<", using 640x480 16bpp rendertargets to save tex vidmem.\n"; + } } - - CreateScreenBuffersAndDevice(dwRenderWidth,dwRenderHeight,pDD,pD3DI,pD3DDevDesc); - - _dxgsg->SetDXReady(true); + + _dxgsg->scrn.DisplayMode.Width=dwRenderWidth; + _dxgsg->scrn.DisplayMode.Height=dwRenderHeight; + _dxgsg->scrn.DisplayMode.Format = pixFmt; + _dxgsg->scrn.DisplayMode.RefreshRate = D3DPRESENT_RATE_DEFAULT; + _dxgsg->scrn.hMon=pDevinfo->hMon; + _dxgsg->scrn.CardIDNum=pDevInfo->cardID; + return true; } +void wdxGraphicsWindowGroup:: +SetCoopLevelsAndDisplayModes(void) { + HRESULT hr; + DWORD SCL_FPUFlag; + if(dx_preserve_fpu_state) + SCL_FPUFlag = DDSCL_FPUPRESERVE; // tell d3d to preserve the fpu state across calls. this hurts perf, but is good for dbgging + else SCL_FPUFlag = DDSCL_FPUSETUP; + + DXScreenData *pScrn=&_windows[0]->_dxgsg->scrn; + // All SetCoopLevels must use the parent window + + if(!dx_full_screen) { + if(FAILED(hr = pScrn->pDD->SetCooperativeLevel(_hParentWindow, SCL_FPUFlag | DDSCL_NORMAL))) { + wdxdisplay_cat.fatal() << "SetCooperativeLevel failed : result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } + return; + } + + DWORD SCL_FLAGS = SCL_FPUFlag | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; + + if(_windows.size()>1) { + SCL_FLAGS |= DDSCL_SETDEVICEWINDOW; + } + + for(int devnum=0;devnum<_windows.size();devnum++) { + DXScreenData *pScrn=&_windows[devnum]->_dxgsg->scrn; + + // need to set focus/device windows for multimon + // focus window is primary monitor that will receive keybd input + // all ddraw objs need to have same focus window + if(_windows.size()>1) { + if(FAILED(hr = pScrn->pDD->SetCooperativeLevel(_hParentWindow, DDSCL_SETFOCUSWINDOW))) { + wdxdisplay_cat.fatal() << "SetCooperativeLevel SetFocusWindow failed on device 0: result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } + } + + // s3 savage2000 on w95 seems to set EXCLUSIVE_MODE only if you call SetCoopLevel twice. + // so we do it, it really shouldnt be necessary if drivers werent buggy + for(int jj=0;jj<2;jj++) { + if(FAILED(hr = pScrn->pDD->SetCooperativeLevel(pScrn->hWnd, SCL_FLAGS))) { + wdxdisplay_cat.fatal() << "SetCooperativeLevel failed for device #"<< devnum<<": result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } + } + + if(FAILED(hr = pScrn->pDD->TestCooperativeLevel())) { + wdxdisplay_cat.fatal() << "TestCooperativeLevel failed for device #"<< devnum<<": result = " << ConvD3DErrorToString(hr) << endl; + wdxdisplay_cat.fatal() << "Full screen app failed to get exclusive mode on init, exiting..\n"; + exit(1); + } + + // note: its important we call SetDisplayMode on all cards before creating surfaces on any of them + // let driver choose default refresh rate (hopefully its >=60Hz) + if(FAILED( hr = pScrn->pDD->SetDisplayMode( pScrn->dwRenderWidth, pScrn->dwRenderHeight, + pScrn->dwFullScreenBitDepth, 0, 0 ))) { + wdxdisplay_cat.fatal() << "SetDisplayMode failed to set ("<dwRenderWidth<<"x"<dwRenderHeight<<"x"<dwFullScreenBitDepth<<") on device #"<< pScrn->CardIDNum<<": result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } + + if(wdxdisplay_cat.is_debug()) { + DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd34); + pScrn->pDD->GetDisplayMode(&ddsd34); + wdxdisplay_cat.debug() << "set displaymode to " << ddsd34.dwWidth << "x" << ddsd34.dwHeight << " at "<< ddsd34.ddpfPixelFormat.dwRGBBitCount << "bpp, " << ddsd34.dwRefreshRate<< "Hz\n"; + + /* + #ifdef _DEBUG + if(FAILED(hr = (*Disply).pDD->GetAvailableVidMem(&ddsGAVMCaps,&dwVidMemTotal,&dwVidMemFree))) { + wdxdisplay_cat.debug() << "GetAvailableVidMem failed : result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } + wdxdisplay_cat.debug() << "after fullscreen switch: GetAvailableVidMem returns Total: " << dwVidMemTotal/1000000.0 << " Free: " << dwVidMemFree/1000000.0 << endl; + #endif + */ + } + } +} + +//return true if successful void wdxGraphicsWindow:: -CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTDRAW7 pDD, - LPDIRECT3D7 pD3DI,D3DDEVICEDESC7 *pD3DDevDesc) { - LPDIRECTDRAWSURFACE7 pPrimaryDDSurf,pBackDDSurf,pZDDSurf; - LPDIRECT3DDEVICE7 pD3DDevice; +CreateScreenBuffersAndDevice(DXScreenData &Display) { + + DWORD dwRenderWidth=Display.dwRenderWidth; + DWORD dwRenderHeight=Display.dwRenderHeight; + LPDIRECT3D7 pD3DI=Display.pD3D; + LPDIRECTDRAW7 pDD=Display.pDD; + D3DDEVICEDESC7 *pD3DDevDesc=&Display.D3DDevDesc; + + LPDIRECTDRAWSURFACE7 pPrimaryDDSurf,pBackDDSurf,pZDDSurf; + LPDIRECT3DDEVICE7 pD3DDevice; RECT view_rect; int i; HRESULT hr; DX_DECLARE_CLEAN( DDSURFACEDESC2, SurfaceDesc ); - D3DDEVICEDESC7 d3ddevs[2]; // put HAL in 0, TnLHAL in 1 assert(pDD!=NULL); assert(pD3DI!=NULL); + assert(pD3DDevDesc->dwDevCaps & D3DDEVCAPS_HWRASTERIZATION ); + ResourceManagerDiscardBytes(0); + +/* // select the best device if the caller does not provide one + D3DDEVICEDESC7 d3ddevs[2]; // put HAL in 0, TnLHAL in 1 + if(pD3DDevDesc==NULL) { - // just look for HAL and TnL devices right now. I dont think // we have any interest in the sw rasts at this point @@ -1574,9 +1822,12 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD pD3DDevDesc=&d3ddevs[DeviceIdx]; } +*/ - DX_DECLARE_CLEAN(DDCAPS,DDCaps); - pDD->GetCaps(&DDCaps,NULL); + + + DX_DECLARE_CLEAN(DDCAPS,DDCaps); + pDD->GetCaps(&DDCaps,NULL); if(dx_full_screen) { // Setup to create the primary surface w/backbuffer @@ -1597,7 +1848,26 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD // Create the primary surface if(FAILED( hr = pDD->CreateSurface( &ddsd, &pPrimaryDDSurf, NULL ) )) { wdxdisplay_cat.fatal() << "CreateSurface failed for primary surface: result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + + if(((hr==DDERR_OUTOFVIDEOMEMORY)||(hr==DDERR_OUTOFMEMORY)) && + (Display.dwFullScreenBitDepth>16)) { + // emergency fallback to 16bpp (shouldnt have to do this unless GetAvailVidMem lied) + // will this work for multimon? what if surfs are already created on 1st mon? + Display.dwFullScreenBitDepth=16; + + if(wdxdisplay_cat.info()) + wdxdisplay_cat.info() << "GetAvailVidMem lied, not enough VidMem for 32bpp, so trying 16bpp on device #"<< Display.CardIDNum<< endl; + + if(FAILED( hr = pDD->SetDisplayMode( Display.dwRenderWidth, Display.dwRenderHeight,Display.dwFullScreenBitDepth, 0, 0 ))) { + wdxdisplay_cat.fatal() << "SetDisplayMode failed to set ("<GetDisplayMode( &SurfaceDesc ))) { - wdxdisplay_cat.fatal() - << "GetDisplayMode failed result = " << ConvD3DErrorToString(hr) << endl; + wdxdisplay_cat.fatal() << "GetDisplayMode failed result = " << ConvD3DErrorToString(hr) << endl; exit(1); } if(SurfaceDesc.ddpfPixelFormat.dwRGBBitCount <= 8) { @@ -1649,24 +1917,15 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD exit(1); } -// extern bool dx_preserve_fpu_state; - DWORD SCL_FPUFlag = DDSCL_FPUSETUP; - -// if(dx_preserve_fpu_state) -// SCL_FPUFlag = DDSCL_FPUPRESERVE; // tell d3d to preserve the fpu state across calls. this hurts perf, but is good for dbgging - - if(FAILED(hr = pDD->SetCooperativeLevel(_mwindow, SCL_FPUFlag | DDSCL_NORMAL))) { - wdxdisplay_cat.fatal() << "SetCooperativeLevel failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } + // Get the dimensions of the viewport and screen bounds - GetClientRect( _mwindow, &view_rect ); + GetClientRect( Display.hWnd, &view_rect ); POINT ul,lr; ul.x=view_rect.left; ul.y=view_rect.top; lr.x=view_rect.right; lr.y=view_rect.bottom; - ClientToScreen( _mwindow, &ul ); - ClientToScreen( _mwindow, &lr ); + ClientToScreen(Display.hWnd, &ul ); + ClientToScreen(Display.hWnd, &lr ); view_rect.left=ul.x; view_rect.top=ul.y; view_rect.right=lr.x; view_rect.bottom=lr.y; @@ -1697,15 +1956,14 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD // our window is partially obscured by other windows. LPDIRECTDRAWCLIPPER Clipper; if(FAILED(hr = pDD->CreateClipper( 0, &Clipper, NULL ))) { - wdxdisplay_cat.fatal() - << "CreateClipper failed : result = " << ConvD3DErrorToString(hr) << endl; + wdxdisplay_cat.fatal() << "CreateClipper failed : result = " << ConvD3DErrorToString(hr) << endl; exit(1); } // Associate the clipper with our window. Note that, afterwards, the // clipper is internally referenced by the primary surface, so it is safe // to release our local reference to it. - Clipper->SetHWnd( 0, _mwindow ); + Clipper->SetHWnd( 0, Display.hWnd ); pPrimaryDDSurf->SetClipper( Clipper ); Clipper->Release(); @@ -1732,7 +1990,7 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD PRINTVIDMEM(pDD,&SurfaceDesc.ddsCaps,"initial backbuf"); - // Create the backbuffer. (might want to handle failure due to running out of video memory. + // Create the backbuffer. (might want to handle failure due to running out of video memory) if(FAILED(hr = pDD->CreateSurface( &SurfaceDesc, &pBackDDSurf, NULL ))) { wdxdisplay_cat.fatal() << "CreateSurface failed for backbuffer : result = " << ConvD3DErrorToString(hr) << endl; @@ -1776,9 +2034,10 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD // Get an appropiate pixel format from enumeration of the formats. On the // first pass, we look for a zbuffer dpeth which is equal to the frame // buffer depth (as some cards unfornately require this). - if(FAILED(pD3DI->EnumZBufferFormats( IID_IDirect3DHALDevice, EnumZBufFmtsCallback, - (VOID*)&ZBufPixFmts ))) { - wdxdisplay_cat.fatal() << "EnumZBufferFormats failed " << endl; + if(FAILED(pD3DI->EnumZBufferFormats((Display.bIsTNLDevice ? IID_IDirect3DHALDevice : IID_IDirect3DTnLHalDevice), + EnumZBufFmtsCallback, + (VOID*)&ZBufPixFmts ))) { + wdxdisplay_cat.fatal() << "EnumZBufferFormats failed" << endl; exit(1); } @@ -1821,9 +2080,9 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD exit(1); } - #define SET_ZBUF_DEPTH(DEPTH) { assert(pz##DEPTH != NULL); _depth_buffer_bpp=DEPTH; ddsd.ddpfPixelFormat = *pz##DEPTH;} + #define SET_ZBUF_DEPTH(DEPTH) { assert(pz##DEPTH != NULL); Display.depth_buffer_bitdepth=DEPTH; ddsd.ddpfPixelFormat = *pz##DEPTH;} - if(IS_NVIDIA(_DXDeviceID)) { + if(IS_NVIDIA(Display.DXDeviceID)) { DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_pri) pPrimaryDDSurf->GetSurfaceDesc(&ddsd_pri); @@ -1881,7 +2140,34 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD // Create and attach a z-buffer if(FAILED( hr = pDD->CreateSurface( &ddsd, &pZDDSurf, NULL ) )) { wdxdisplay_cat.fatal() << "CreateSurface failed for Z buffer: result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + + if(((hr==DDERR_OUTOFVIDEOMEMORY)||(hr==DDERR_OUTOFMEMORY)) && + ((Display.dwFullScreenBitDepth>16)||(ddsd.ddpfPixelFormat.dwRGBBitCount>16))) { + Display.dwFullScreenBitDepth=16; + // emergency fallback to 16bpp (shouldnt have to do this unless GetAvailVidMem lied) + // will this work for multimon? what if surfs are already created on 1st mon? + + if(wdxdisplay_cat.info()) + wdxdisplay_cat.info() << "GetAvailVidMem lied, not enough VidMem for 32bpp, so trying 16bpp on device #"<< Display.CardIDNum<< endl; + + ULONG refcnt; + + // free pri and back (maybe should just free pri since created as complex chain?) + RELEASE(pBackDDSurf,wdxdisplay,"backbuffer",false); + RELEASE(pPrimaryDDSurf,wdxdisplay,"primary surface",false); + + if(FAILED( hr = pDD->SetDisplayMode( Display.dwRenderWidth, Display.dwRenderHeight,Display.dwFullScreenBitDepth, 0, 0 ))) { + wdxdisplay_cat.fatal() << "SetDisplayMode failed to set ("<GetAdapterCount(); + if(_numAdapters < num_windows) { + wdxdisplay_cat.fatal() << "couldn't find enough devices attached to meet multi window reqmt of " << num_windows << endl; + exit(1); + } + + for(int i=0;i<_numAdapters;i++) { + D3DADAPTER_IDENTIFIER8 adapter_info; + hr = pD3D8->GetAdapterIdentifier(i,D3DENUM_NO_WHQL_LEVEL,&adapter_info); + if(FAILED(hr)) { + wdxdisplay_cat.fatal() << "D3D GetAdapterID failed" << D3DERRORSTRING(hr); + } + + LARGE_INTEGER *DrvVer=&adapter_info.DriverVersion; + + wdxdisplay_cat.info() << "D3D8 Adapter[" << i << "]: " << adapter_info.Description << + ", Driver: " << adapter_info.Driver << ", DriverVersion: (" + << HIWORD(DrvVer->HighPart) << "." << LOWORD(DrvVer->HighPart) << "." + << HIWORD(DrvVer->LowPart) << "." << LOWORD(DrvVer->LowPart) << ")\nVendorID: 0x" + << (void*) adapter_info.VendorId << " DeviceID: 0x" << (void*) adapter_info.DeviceId + << " SubsysID: 0x" << (void*) adapter_info.SubsysId << " Revision: 0x" + << (void*) adapter_info.Revision << endl; + + DXDeviceInfo devinfo; + ZeroMemory(&devinfo,sizeof(devinfo)); + memcpy(&devinfo.guidDeviceIdentifier,&adapter_info.DeviceIdentifier,sizeof(GUID)); + strncpy(devinfo.szDescription,&adapter_info.Description,MAX_DDDEVICEID_STRING); + strncpy(devinfo.szDriver,&adapter_info.Driver,MAX_DDDEVICEID_STRING); + devinfo.hMon=pD3D8->GetAdapterMonitor(i); + devinfo.cardID=i; + _DeviceInfoVec.push_back(devinfo); + } + + for(i=0;iconfig_window(this); + } + + int good_device_count=0; + + if(num_windows==1) { + UINT D3DAdapterNum = D3DADAPTER_DEFAULT; + + if(dx_preferred_deviceID!=-1) { + if(dx_preferred_deviceID>=_numAdapters) { + wdxdisplay_cat.fatal() << "invalid dx-preferred-deviceID, valid values are 0-" << _numAdapters << ", using default adapter instead\n"; + } else D3DAdapterNum=dx_preferred_deviceID; + } + if(_windows[0]->search_for_device(D3DAdapterNum,&(_DeviceInfoVec[devnum]))) + good_device_count=1; + } else { + for(int devnum=0;devnum<_DeviceInfoVec.size() && (good_device_count < num_windows);devnum++) { + if(_windows[devnum]->search_for_device(devnum,&(_DeviceInfoVec[devnum]))) + good_device_count++; + } + } + + if(good_device_count < num_windows) { + if(good_device_count==0) + wdxdisplay_cat.fatal() << "no usable display devices, exiting...\n"; + else wdxdisplay_cat.fatal() << "multi-device request for " << num_windows << "devices, found only "<< good_device_count << " usable ones, exiting!"; + exit(1); + } + + _DeviceInfoVec.clear(); // dont need this anymore + + CreateWindows(); // creates win32 windows (need to do this before Setting coopLvls and display modes, + // but after we have all the monitor handles needed by CreateWindow() + + SetCoopLevelsAndDisplayModes(); + + if(dx_show_fps_meter) + _windows[0]->_dxgsg->_bShowFPSMeter = true; // just show fps on 1st mon + + for(i=0;iCreateScreenBuffersAndDevice(_windows[i]->_dxgsg->scrn); + } + + for(i=0;ifinish_window_setup(); + } + + for(i=0;i_dxgsg->SetDXReady(true); + } +} + +wdxGraphicsWindowGroup::wdxGraphicsWindowGroup(GraphicsPipe *pipe,int num_windows,GraphicsWindow::Properties *WinPropArray) { + make_windows(pipe,num_windows,WinPropArray); +} + +void wdxGraphicsWindowGroup:: +make_windows(GraphicsPipe *pipe,int num_windows,GraphicsWindow::Properties *WinPropArray) { + _hParentWindow=NULL; + _windows.reserve(num_windows); + int i; + + // first make all the objs without running the dx config() stuff + for(i=0;iclose_window(); + } + + if((_hOldForegroundWindow!=NULL) /*&& (scrn.hWnd==GetForegroundWindow())*/) { + SetForegroundWindow(_hOldForegroundWindow); + } + + if(_bLoadedCustomCursor && (_hMouseCursor!=NULL)) + DestroyCursor(_hMouseCursor); + + + if(_hDDrawDLL != NULL) { + FreeLibrary(_hDDrawDLL); + _hDDrawDLL = NULL; + } + + if(_hD3D8_DLL != NULL) { + FreeLibrary(_hD3D8_DLL); + _hD3D8_DLL = NULL; + } +} + diff --git a/panda/src/wdxdisplay8/wdxGraphicsWindow8.h b/panda/src/wdxdisplay8/wdxGraphicsWindow8.h index 05c4e0680a..67f1923255 100644 --- a/panda/src/wdxdisplay8/wdxGraphicsWindow8.h +++ b/panda/src/wdxdisplay8/wdxGraphicsWindow8.h @@ -15,9 +15,9 @@ // panda3d@yahoogroups.com . // //////////////////////////////////////////////////////////////////// -#ifndef WDXGRAPHICSWINDOW8_H -#define WDXGRAPHICSWINDOW8_H -//#define WBD_GL_MODE 1 // if setting this, do it in dxGraphicsStateGuardian.h too +#ifndef WDXGRAPHICSWINDOW_H +#define WDXGRAPHICSWINDOW_H +//#define WBD_GL_MODE 1 // if setting this, do it in wdxGraphicsStateGuardian.h too // //////////////////////////////////////////////////////////////////// // Includes @@ -28,15 +28,30 @@ #define WINDOWS_LEAN_AND_MEAN #include #undef WINDOWS_LEAN_AND_MEAN -#include +#include +#include + +#include "dxGraphicsStateGuardian8.h" //////////////////////////////////////////////////////////////////// // Defines //////////////////////////////////////////////////////////////////// class wdxGraphicsPipe; +class wdxGraphicsWindowGroup; -const int WDXWIN_CONFIGURE = 4; -const int WDXWIN_EVENT = 8; +const int WDXWIN_CONFIGURE = 4; +const int WDXWIN_EVENT = 8; + +typedef HRESULT (WINAPI * LPDIRECTDRAWCREATEEX)(GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid,IUnknown FAR *pUnkOuter); + +typedef struct { + UINT cardID; + char szDriver[MAX_DDDEVICEID_STRING]; + char szDescription[MAX_DDDEVICEID_STRING]; + GUID guidDeviceIdentifier; + HMONITOR hMon; +} DXDeviceInfo; +typedef vector DXDeviceInfoVec; //////////////////////////////////////////////////////////////////// // Class : wdxGraphicsWindow @@ -45,31 +60,29 @@ const int WDXWIN_EVENT = 8; class EXPCL_PANDADX wdxGraphicsWindow : public GraphicsWindow { friend class DXGraphicsStateGuardian; friend class DXTextureContext; + friend class wdxGraphicsWindowGroup; public: wdxGraphicsWindow(GraphicsPipe* pipe); - wdxGraphicsWindow(GraphicsPipe* pipe, - const GraphicsWindow::Properties& props); - virtual ~wdxGraphicsWindow(void); + wdxGraphicsWindow(GraphicsPipe* pipe,const GraphicsWindow::Properties& props); + // this constructor will not initialize the wdx stuff, only the panda graphicswindow stuff + wdxGraphicsWindow(GraphicsPipe* pipe,const GraphicsWindow::Properties& props,wdxGraphicsWindowGroup *pParentGroup); + + virtual ~wdxGraphicsWindow(void); virtual bool supports_update() const; virtual void update(void); virtual void end_frame( void ); virtual TypeHandle get_gsg_type() const; static GraphicsWindow* make_wdxGraphicsWindow(const FactoryParams ¶ms); - void CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight, - LPDIRECTDRAW7 pDD,LPDIRECT3D7 pD3DI, - D3DDEVICEDESC7 *pD3DDevDesc); LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); void process_events(void); INLINE bool mouse_entry_enabled(void) { return _mouse_entry_enabled; } INLINE bool mouse_motion_enabled(void) { return _mouse_motion_enabled; } - INLINE bool mouse_passive_motion_enabled(void) { - return _mouse_passive_motion_enabled; - } + INLINE bool mouse_passive_motion_enabled(void) { return _mouse_passive_motion_enabled; } void handle_window_move( int x, int y ); void handle_mouse_motion( int x, int y ); void handle_mouse_entry( int state, HCURSOR hMouseCursor ); @@ -78,8 +91,6 @@ public: void dx_setup(); virtual void begin_frame( void ); void show_frame(); - DXGraphicsStateGuardian *_dxgsg; - virtual void resize(unsigned int xsize,unsigned int ysize); virtual unsigned int verify_window_sizes(unsigned int numsizes,unsigned int *dimen); virtual int get_depth_bitwidth(void); @@ -87,30 +98,30 @@ public: protected: void CreateScreenBuffersAndDevice(LPDIRECTDRAW7 pDD,LPDIRECT3D7 pD3DI); ButtonHandle lookup_key(WPARAM wparam) const; - virtual void config( void ); +// virtual void config(void); + void config_single_window(void); + void config_window(wdxGraphicsWindowGroup *pParentGroup); + void finish_window_setup(void); + bool search_for_device(LPDIRECT3D8 pD3D8,DXDeviceInfo *pDevinfo); void setup_colormap(void); void enable_mouse_input(bool val); void enable_mouse_motion(bool val); void enable_mouse_passive_motion(bool val); void enable_mouse_entry(bool val); - void check_for_color_cursor_support(void); - DDDEVICEIDENTIFIER2 _DXDeviceID; public: - HWND _mwindow; - HWND _hOldForegroundWindow; - UINT_PTR _PandaPausedTimer; - + UINT_PTR _PandaPausedTimer; + DXGraphicsStateGuardian *_dxgsg; + void CreateScreenBuffersAndDevice(DXScreenData &Display); + private: + wdxGraphicsWindowGroup *_pParentWindowGroup; HDC _hdc; HPALETTE _colormap; typedef enum { NotAdjusting,MovingOrResizing,Resizing } WindowAdjustType; - WindowAdjustType _WindowAdjustingType; - bool _bIsLowVidMemCard; - bool _bLoadedCustomCursor; - HCURSOR _hMouseCursor; - bool _bSizeIsMaximized; + WindowAdjustType _WindowAdjustingType; + bool _bSizeIsMaximized; bool _mouse_input_enabled; bool _mouse_motion_enabled; bool _mouse_passive_motion_enabled; @@ -137,6 +148,42 @@ private: static TypeHandle _type_handle; }; +// this class really belongs in panda, not here +class EXPCL_PANDADX wdxGraphicsWindowGroup { +// group of windows are all created at the same time + friend class wdxGraphicsWindow; + +PUBLISHED: + wdxGraphicsWindowGroup(GraphicsPipe *,const GraphicsWindow::Properties&); + wdxGraphicsWindowGroup(GraphicsPipe *,const GraphicsWindow::Properties&,const GraphicsWindow::Properties&); + wdxGraphicsWindowGroup(GraphicsPipe *,const GraphicsWindow::Properties&,const GraphicsWindow::Properties&, + const GraphicsWindow::Properties&); +public: + wdxGraphicsWindowGroup(wdxGraphicsWindow *OneWindow); + // dont publish variable length one, since FFI wont support it + wdxGraphicsWindowGroup(GraphicsPipe *pipe,int num_windows,GraphicsWindow::Properties *WinPropArray); + ~wdxGraphicsWindowGroup(); + void SetCoopLevelsAndDisplayModes(void); +public: + void CreateWindows(void); + void make_windows(GraphicsPipe *,int num_windows,GraphicsWindow::Properties *pWinPropArray); + void initWindowGroup(void); + + pvector _windows; + DXDeviceInfoVec *_pDeviceInfoVec; // only used during init to store valid devices + HWND _hParentWindow; + HWND _hOldForegroundWindow; + HCURSOR _hMouseCursor; + bool _bLoadedCustomCursor; + bool _bClosingAllWindows; + bool _bIsDX81; + UINT _numMonitors,_numAdapters; + LPDIRECT3D8 _pD3D8; + HINSTANCE _hDDrawDLL,_hD3D8_DLL; + LPDIRECTDRAWCREATEEX _pDDCreateEx; + DXDeviceInfoVec _DeviceInfoVec; +}; + extern void set_global_parameters(void); extern void restore_global_parameters(void);