diff --git a/panda/src/dxgsg/Sources.pp b/panda/src/dxgsg/Sources.pp index 446158e38a..92cc59b837 100644 --- a/panda/src/dxgsg/Sources.pp +++ b/panda/src/dxgsg/Sources.pp @@ -12,18 +12,15 @@ putil linmath sgraph mathutil pnmimage event #define COMBINED_SOURCES $[TARGET]_composite1.cxx + + #define INSTALL_HEADERS \ + config_dxgsg.h dxGraphicsStateGuardian.I dxGraphicsStateGuardian.h \ + dxTextureContext.h dxGeomNodeContext.h dxGeomNodeContext.I #define SOURCES \ - config_dxgsg.h dxGraphicsStateGuardian.I \ - dxGraphicsStateGuardian.cxx dxGraphicsStateGuardian.h \ - dxSavedFrameBuffer.I dxSavedFrameBuffer.h \ - dxTextureContext.h dxGeomNodeContext.h dxGeomNodeContext.I + dxGraphicsStateGuardian.cxx dxSavedFrameBuffer.I dxSavedFrameBuffer.h $[INSTALL_HEADERS] #define INCLUDED_SOURCES \ config_dxgsg.cxx dxSavedFrameBuffer.cxx dxTextureContext.cxx dxGeomNodeContext.cxx - - #define INSTALL_HEADERS \ - config_dxgsg.h dxGraphicsStateGuardian.I dxGraphicsStateGuardian.h \ - dxSavedFrameBuffer.I dxSavedFrameBuffer.h dxTextureContext.h #end lib_target diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.I b/panda/src/dxgsg/dxGraphicsStateGuardian.I index ce80dd68ae..2a04aac13c 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.I +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.I @@ -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/dxgsg/dxGraphicsStateGuardian.cxx b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx index 8308c87610..680549afe2 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx @@ -283,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); @@ -293,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; } @@ -326,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; } @@ -358,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. @@ -365,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 @@ -407,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(); @@ -442,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; } @@ -471,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 @@ -523,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(); @@ -553,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; @@ -568,41 +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(FAILED(hr=pDevice->EnumTextureFormats(EnumTexFmtsCallback, this))) { + 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"; + 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))) { +/* + 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))) { + if (FAILED(hr = scrn.pDD->GetCaps(&ddCaps,NULL))) { dxgsg_cat.fatal() << "GetCaps failed on DDraw! hr = " << ConvD3DErrorToString(hr) << "\n"; exit(1); } // s3 virge drivers sometimes give crap values for these - if(_D3DDevDesc.dwMaxTextureWidth==0) - _D3DDevDesc.dwMaxTextureWidth=256; + if(scrn.D3DDevDesc.dwMaxTextureWidth==0) + scrn.D3DDevDesc.dwMaxTextureWidth=256; - if(_D3DDevDesc.dwMaxTextureHeight==0) - _D3DDevDesc.dwMaxTextureHeight=256; + if(scrn.D3DDevDesc.dwMaxTextureHeight==0) + scrn.D3DDevDesc.dwMaxTextureHeight=256; - _bIsTNLDevice = (IsEqualGUID(_D3DDevDesc.deviceGUID,IID_IDirect3DTnLHalDevice)!=0); +// shouldve already been set +// sc_bIsTNLDevice = (IsEqualGUID(scrn.D3DDevDesc.deviceGUID,IID_IDirect3DTnLHalDevice)!=0); - if ((dx_decal_type==GDT_offset) && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) { + if ((dx_decal_type==GDT_offset) && !(scrn.D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) { #ifdef _DEBUG // dx7 doesnt support PLANEMASK renderstate #if(DIRECT3D_VERSION < 0x700) @@ -630,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"; } @@ -648,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 @@ -693,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); + scrn.pddsBack->GetSurfaceDesc(&ddsd_back); _dither_enabled = (!dx_no_dithering) && ((ddsd_back.ddpfPixelFormat.dwRGBBitCount < 24) && - (_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER)); - _d3dDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, _dither_enabled); + (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; @@ -745,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; @@ -758,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 @@ -766,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; @@ -776,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 { @@ -805,28 +833,28 @@ 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); // 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; @@ -844,7 +872,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) && @@ -857,10 +890,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; } @@ -887,7 +924,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; @@ -901,16 +938,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(); @@ -927,7 +964,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. @@ -959,14 +996,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; @@ -1001,7 +1040,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() @@ -1082,17 +1121,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); @@ -1149,7 +1188,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)) { @@ -1164,7 +1203,7 @@ render_frame() { return; } -/* _d3dDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &matIdentity); */ +/* scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &matIdentity); */ #ifdef GSG_VERBOSE dxgsg_cat.debug() @@ -1224,7 +1263,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 @@ -1269,33 +1308,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 @@ -1303,76 +1342,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 @@ -1413,7 +1452,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 @@ -1523,13 +1562,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); } @@ -1539,7 +1578,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; @@ -1580,7 +1619,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; @@ -1693,8 +1732,9 @@ 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 @@ -1726,7 +1766,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()); } @@ -2128,8 +2168,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); } @@ -2179,8 +2219,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; @@ -2270,12 +2310,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); } @@ -2378,8 +2418,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); } @@ -2453,11 +2493,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(); @@ -2502,7 +2542,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { 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 @@ -2798,14 +2838,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); @@ -2827,7 +2867,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 { @@ -2851,7 +2891,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 { @@ -2966,8 +3006,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); } @@ -3159,8 +3199,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; } @@ -3174,13 +3214,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 } @@ -3374,8 +3414,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); } @@ -3616,8 +3656,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); @@ -3924,8 +3964,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; @@ -3953,7 +3993,12 @@ prepare_texture(Texture *tex) { specify_texture(tex); apply_texture_immediate(tex); #else - if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts,&_D3DDevDesc) == 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 delete dtc; return NULL; } @@ -4009,7 +4054,11 @@ apply_texture(TextureContext *tc) { } dtc->DeleteTexture(); - if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts,&_D3DDevDesc)==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; @@ -4031,11 +4080,11 @@ 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; } @@ -4046,7 +4095,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"; @@ -4056,8 +4105,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); } } @@ -4100,8 +4149,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; @@ -4109,7 +4158,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) { @@ -4390,7 +4439,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()); } @@ -4550,7 +4599,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); } //////////////////////////////////////////////////////////////////// @@ -4569,10 +4618,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 ? @@ -4590,9 +4639,9 @@ apply_fog(Fog *fog) { _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; @@ -4601,7 +4650,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; @@ -4636,7 +4685,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); } //////////////////////////////////////////////////////////////////// @@ -4669,9 +4718,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 ); } //////////////////////////////////////////////////////////////////// @@ -4754,7 +4803,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 } @@ -4798,16 +4847,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; } @@ -4830,7 +4879,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 } @@ -5030,11 +5079,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: @@ -5205,47 +5254,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: @@ -5257,21 +5306,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 ); */ @@ -5300,7 +5349,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); } @@ -5349,11 +5398,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)); } } @@ -5376,24 +5425,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()); } } @@ -5415,17 +5464,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() @@ -5505,7 +5554,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() @@ -5657,7 +5706,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 @@ -5667,7 +5716,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); @@ -5713,7 +5762,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 @@ -5740,7 +5789,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) @@ -5750,7 +5799,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); @@ -5764,7 +5813,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); @@ -5994,11 +6043,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; @@ -6128,49 +6180,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)) { @@ -6182,11 +6235,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"; @@ -6201,32 +6254,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; @@ -6236,10 +6289,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); } @@ -6249,7 +6302,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); @@ -6258,7 +6311,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(); } @@ -6267,43 +6320,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) { @@ -6331,8 +6384,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,&dxgsg->_D3DDevDesc); + 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; } @@ -6345,7 +6402,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()) @@ -6374,7 +6431,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); } @@ -6382,7 +6439,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()) @@ -6397,7 +6454,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 @@ -6434,7 +6491,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)) { @@ -6477,10 +6534,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); @@ -6500,7 +6557,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 @@ -6514,7 +6571,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); @@ -6585,11 +6642,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); } @@ -7064,14 +7121,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; @@ -7084,7 +7141,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 @@ -7153,7 +7210,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; @@ -7210,10 +7267,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; @@ -7230,7 +7287,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); @@ -7238,7 +7295,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 @@ -7253,20 +7310,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/dxgsg/dxGraphicsStateGuardian.h b/panda/src/dxgsg/dxGraphicsStateGuardian.h index 11aa4d5add..9e639509ef 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.h +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.h @@ -40,9 +40,32 @@ #include "dxGeomNodeContext.h" #include "dxTextureContext.h" +#include extern char * ConvD3DErrorToString(const HRESULT &error); // defined in wdxGraphicsPipe.cxx +typedef struct { + LPDIRECT3DDEVICE7 pD3DDevice; + LPDIRECTDRAW7 pDD; + LPDIRECT3D7 pD3D; + LPDIRECTDRAWSURFACE7 pddsPrimary,pddsBack,pddsZBuf; + HWND hWnd; + HMONITOR hMon; + DWORD dwRenderWidth,dwRenderHeight,dwFullScreenBitDepth; + 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; + D3DDEVICEDESC7 D3DDevDesc; +#ifdef USE_TEXFMTVEC + DDPixelFormatVec TexPixFmts; +#endif +} DXScreenData; +// typedef vector ScreenDataVector; + class PlaneNode; class Light; @@ -61,7 +84,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 @@ -123,6 +146,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: @@ -227,10 +252,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; - D3DDEVICEDESC7 _D3DDevDesc; +#endif +// D3DDEVICEDESC7 _D3DDevDesc; protected: void free_pointers(); // free local internal buffers @@ -249,15 +279,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; @@ -326,7 +364,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 @@ -367,10 +404,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; @@ -395,7 +429,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 @@ -449,12 +482,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;} @@ -469,13 +503,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 ); diff --git a/panda/src/dxgsg/dxTextureContext.cxx b/panda/src/dxgsg/dxTextureContext.cxx index cd3659fcb7..6e845c148b 100644 --- a/panda/src/dxgsg/dxTextureContext.cxx +++ b/panda/src/dxgsg/dxTextureContext.cxx @@ -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, LPD3DDEVICEDESC7 pD3DDevDesc) { +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); @@ -1128,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;iRelease(); + delete [] pTexPixFmts; + // Return the newly created texture return _surface; @@ -1595,6 +1612,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT _surface = NULL; } + delete [] pTexPixFmts; return NULL; } diff --git a/panda/src/dxgsg/dxTextureContext.h b/panda/src/dxgsg/dxTextureContext.h index c60a72ec1e..f2fc1e8011 100644 --- a/panda/src/dxgsg/dxTextureContext.h +++ b/panda/src/dxgsg/dxTextureContext.h @@ -38,7 +38,13 @@ #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,8 +61,14 @@ public: LPDIRECTDRAWSURFACE7 _surface; Texture *_tex; // ptr to parent, primarily for access to namestr - LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, - LPDDPIXELFORMAT pTexPixFmts,LPD3DDEVICEDESC7 pD3DDevDesc); +// 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 diff --git a/panda/src/wdxdisplay/config_wdxdisplay.cxx b/panda/src/wdxdisplay/config_wdxdisplay.cxx index df0a115d1a..2be0d26284 100644 --- a/panda/src/wdxdisplay/config_wdxdisplay.cxx +++ b/panda/src/wdxdisplay/config_wdxdisplay.cxx @@ -29,7 +29,6 @@ ConfigureFn(config_wdxdisplay) { init_libwdxdisplay(); } -int dx_use_multimon = config_wdxdisplay.GetInt("dx-multimon", 1); 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); diff --git a/panda/src/wdxdisplay/config_wdxdisplay.h b/panda/src/wdxdisplay/config_wdxdisplay.h index 5f845d4d92..20cc42c98a 100644 --- a/panda/src/wdxdisplay/config_wdxdisplay.h +++ b/panda/src/wdxdisplay/config_wdxdisplay.h @@ -28,7 +28,6 @@ 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_use_multimon; extern Filename get_icon_filename(); extern Filename get_mono_cursor_filename(); extern Filename get_color_cursor_filename(); diff --git a/panda/src/wdxdisplay/wdxGraphicsPipe.cxx b/panda/src/wdxdisplay/wdxGraphicsPipe.cxx index 3f4e0b4c39..824314621b 100644 --- a/panda/src/wdxdisplay/wdxGraphicsPipe.cxx +++ b/panda/src/wdxdisplay/wdxGraphicsPipe.cxx @@ -101,7 +101,7 @@ find_window(HWND win) { int num_windows = get_num_windows(); for(int w = 0; w < num_windows; w++) { wdxGraphicsWindow *window = DCAST(wdxGraphicsWindow, get_window(w)); - if(window->_mwindow == win) + if(window->_dxgsg->scrn.hWnd == win) return window; } return NULL; diff --git a/panda/src/wdxdisplay/wdxGraphicsWindow.cxx b/panda/src/wdxdisplay/wdxGraphicsWindow.cxx index d1be7cd6cf..2602400530 100644 --- a/panda/src/wdxdisplay/wdxGraphicsWindow.cxx +++ b/panda/src/wdxdisplay/wdxGraphicsWindow.cxx @@ -22,7 +22,6 @@ #include #include "wdxGraphicsWindow.h" #include "wdxGraphicsPipe.h" -#include "dxGraphicsStateGuardian.h" #include "config_wdxdisplay.h" #include @@ -45,18 +44,17 @@ //////////////////////////////////////////////////////////////////// TypeHandle wdxGraphicsWindow::_type_handle; -static bool wc_registered = false; - #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_DEVICES 20 +#define MAX_DISPLAYS 20 extern bool dx_full_screen_antialiasing; // defined in dxgsg_config.cxx @@ -67,6 +65,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 @@ -190,28 +193,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); } } @@ -469,7 +476,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); @@ -498,7 +505,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); @@ -524,7 +531,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; } @@ -641,13 +649,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; } @@ -668,8 +676,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; @@ -682,24 +690,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); @@ -709,9 +719,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)); @@ -725,7 +739,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); } } @@ -756,16 +770,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 @@ -773,7 +787,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"; } @@ -793,13 +808,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) { @@ -807,7 +822,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; } @@ -815,7 +830,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(); } @@ -829,9 +844,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); } //////////////////////////////////////////////////////////////////// @@ -839,63 +854,46 @@ 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() - - _hDDraw_DLL = NULL; - _hdc = NULL; - _mwindow = NULL; - _gsg = _dxgsg = NULL; - _exiting_window = false; - _window_inactive = false; - _return_control_to_app = false; - _active_minimized_fullscreen = false; - _bIsLowVidMemCard = false; - _MaxAvailVidMem = 0; - - _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; // 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; 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) @@ -913,7 +911,54 @@ void wdxGraphicsWindow::config(void) { _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 @@ -928,14 +973,13 @@ 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; } + if(!_bLoadedCustomCursor) + _hMouseCursor = LoadCursor(NULL, DEFAULT_CURSOR); + if (!wc_registered) { // We only need to register the window class once per session. wc.hCursor = _hMouseCursor; @@ -951,18 +995,61 @@ void wdxGraphicsWindow::config(void) { 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 @@ -975,27 +1062,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; @@ -1011,11 +1146,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; @@ -1062,28 +1204,69 @@ 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 (!_props._fullscreen) { 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 @@ -1104,7 +1287,7 @@ void wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { 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); } @@ -1123,12 +1306,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; @@ -1148,7 +1331,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; @@ -1157,17 +1340,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); } @@ -1189,24 +1375,24 @@ verify_window_sizes(unsigned int numsizes,unsigned int *dimen) { DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_search); ddsd_search.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; //| DDSD_PIXELFORMAT; - ddsd_search.dwWidth=xsize; ddsd_search.dwHeight=ysize; + ddsd_search.dwWidth=xsize; ddsd_search.dwHeight=ysize; ZeroMemory(&DDSD_Arr,sizeof(DDSD_Arr)); ZeroMemory(&DMI,sizeof(DMI)); 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 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 if(DMI.supportedBitDepths & (DDBD_16 | DDBD_24 | DDBD_32)) { // assume user is testing fullscreen, not windowed, so use the dwTotal value @@ -1218,11 +1404,11 @@ verify_window_sizes(unsigned int numsizes,unsigned int *dimen) { #define REQD_TEXMEM 1800000.0f - if(_MaxAvailVidMem==0) { + 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)_MaxAvailVidMem); + bIsGoodMode = ((((float)xsize*(float)ysize)*6+REQD_TEXMEM) < (float)_dxgsg->scrn.MaxAvailVidMem); } } @@ -1237,11 +1423,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, @@ -1301,292 +1483,326 @@ 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; +// returns true if successful +bool wdxGraphicsWindow::search_for_device(int devnum,DXDeviceInfo *pDevinfo) { + DWORD dwRenderWidth = _props._xsize; + DWORD dwRenderHeight = _props._ysize; LPDIRECTDRAW7 pDD; HRESULT hr; - DX_DECLARE_CLEAN( DDSURFACEDESC2, SurfaceDesc ); - // Check for DirectX 7 by looking for DirectDrawCreateEx + assert(_dxgsg!=NULL); - _hDDraw_DLL = LoadLibrary("ddraw.dll"); - if(_hDDraw_DLL == 0) { - wdxdisplay_cat.fatal() << "can't locate DDRAW.DLL!\n"; - exit(1); - } + GUID *pDDDeviceGUID; + if(pDevinfo==NULL) + pDDDeviceGUID=NULL; + else pDDDeviceGUID=&pDevinfo->guidDeviceIdentifier; - // Note: I dont want to mess with manually doing FreeLibrary(ddraw.dll) for now. The OS will clean - // this up when the app exits, if we need to I'll add this later. + assert(_pParentWindowGroup->_pDDCreateEx!=NULL); - typedef HRESULT (WINAPI * LPDIRECTDRAWCREATEEX)(GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid,IUnknown FAR *pUnkOuter); - - // load all ddraw exports dynamically to avoid static link to ddraw.dll, in case system doesnt have it - - LPDIRECTDRAWCREATEEX pDDCreateEx = (LPDIRECTDRAWCREATEEX) GetProcAddress(_hDDraw_DLL,"DirectDrawCreateEx"); - if(pDDCreateEx == NULL) { - wdxdisplay_cat.fatal() << "Panda currently requires at least DirectX 7.0!\n"; - exit(1); - } - - LPDIRECTDRAWENUMERATEEX pDDEnumEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(_hDDraw_DLL,"DirectDrawEnumerateExA"); - if(pDDEnumEx == NULL) { - wdxdisplay_cat.fatal() << "GetProcAddr failed for DirectDrawEnumerateEx!\n"; - 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 = (*pDDEnumEx)( 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 = (*pDDCreateEx)(pOurDriverGUID, (void **)&pDD, IID_IDirectDraw7, NULL); + // Create the Direct Draw Objects + hr = (*_pParentWindowGroup->_pDDCreateEx)(pDDDeviceGUID,(void **)&pDD, IID_IDirectDraw7, NULL); if(hr != DD_OK) { - wdxdisplay_cat.fatal() - << "config() - DirectDrawCreateEx failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + wdxdisplay_cat.fatal() << "DirectDrawCreateEx failed for monitor("<szDescription << "; DriverFile: '" << pDevID->szDriver + << "'; VendorID: " << pDevID->dwVendorId << "; DriverVer: " + << HIWORD(pDevID->liDriverVersion.HighPart) << "." + << LOWORD(pDevID->liDriverVersion.HighPart) << "." + << HIWORD(pDevID->liDriverVersion.LowPart) << "." + << LOWORD(pDevID->liDriverVersion.LowPart) << endl; + } -#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 ); + hr = pDD->QueryInterface( IID_IDirect3D7, (VOID**)&_dxgsg->scrn.pD3D); if(hr != DD_OK) { wdxdisplay_cat.fatal() << "QI for D3D failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + goto error_exit; } - D3DDEVICEDESC7 d3ddevs[MAX_DEVICES]; // put HAL in 0, TnLHAL in 1 + 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=REGHALIDX; - - if(!(d3ddevs[DeviceIdx].dwDevCaps & D3DDEVCAPS_HWRASTERIZATION )) { - wdxdisplay_cat.fatal() << "No 3D HW present, exiting..." << endl; - exit(1); + + 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; } - + // select TNL if present if(d3ddevs[TNLHALIDX].dwDevCaps & D3DDEVCAPS_HWRASTERIZATION) { - DeviceIdx=TNLHALIDX; - } - - D3DDEVICEDESC7 *pD3DDevDesc=&d3ddevs[DeviceIdx]; - - DWORD dwRenderWidth=0, dwRenderHeight=0; + DeviceIdx=TNLHALIDX; + } + + memcpy(&_dxgsg->scrn.D3DDevDesc,&d3ddevs[DeviceIdx],sizeof(D3DDEVICEDESC7)); + _dxgsg->scrn.bIsTNLDevice=(DeviceIdx==TNLHALIDX); + // 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 ddsGAVMCaps; - DWORD dwVidMemTotal=0,dwVidMemFree=0; + DWORD dwVidMemTotal,dwVidMemFree; + dwVidMemTotal=dwVidMemFree=0; ZeroMemory(&ddsGAVMCaps,sizeof(DDSCAPS2)); ddsGAVMCaps.dwCaps = DDSCAPS_VIDEOMEMORY; //set internally by DX anyway, dont think this any different than 0x0 if(FAILED(hr = pDD->GetAvailableVidMem(&ddsGAVMCaps,&dwVidMemTotal,&dwVidMemFree))) { - wdxdisplay_cat.error() << "GetAvailableVidMem failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + wdxdisplay_cat.error() << "GetAvailableVidMem failed for device #"<scrn.bIsLowVidMemCard = ((dwVidMemFree>0) && (dwVidMemFree< LOWVIDMEMTHRESHOLD)); if(dx_full_screen) { - dwRenderWidth = _props._xsize; - dwRenderHeight = _props._ysize; - _props._xorg = _props._yorg = 0; + _props._xorg = _props._yorg = 0; + + DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_search); + ddsd_search.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; + ddsd_search.dwWidth=dwRenderWidth; ddsd_search.dwHeight=dwRenderHeight; + + 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(FAILED(hr= pDD->EnumDisplayModes(DDEDM_REFRESHRATES,&ddsd_search,&DMI,EnumDisplayModesCallBack))) { + wdxdisplay_cat.fatal() << "EnumDisplayModes failed for device #" << devnum << " (" << _dxgsg->scrn.DXDeviceID.szDescription<<"), result = " << ConvD3DErrorToString(hr) << endl; + // goto skip_device; + exit(1); // probably want to exit, since it may be my fault + } + + if(wdxdisplay_cat.is_info()) + wdxdisplay_cat.info() << "Before fullscreen switch: GetAvailableVidMem for device #"<scrn.D3DDevDesc.dwDeviceRenderBitDepth; - // CREATE FULL SCREEN BUFFERS - // Store the rectangle which contains the renderer + DWORD dwFullScreenBitDepth; - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_search); - ddsd_search.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; - ddsd_search.dwWidth=dwRenderWidth; ddsd_search.dwHeight=dwRenderHeight; - - 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(FAILED(hr= pDD->EnumDisplayModes(DDEDM_REFRESHRATES,&ddsd_search,&DMI,EnumDisplayModesCallBack))) { - wdxdisplay_cat.fatal() << "EnumDisplayModes failed, result = " << ConvD3DErrorToString(hr) << endl; - exit(1); + // 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 + << " for device #" << devnum << " (" << _dxgsg->scrn.DXDeviceID.szDescription<<"), skipping device..."; + goto error_exit; + } + + 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 + + dwFullScreenBitDepth=16; + 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"; } - - #ifdef _DEBUG - wdxdisplay_cat.debug() << "before fullscreen switch: GetAvailableVidMem returns Total: " << dwVidMemTotal/1000000.0 << " Free: " << dwVidMemFree/1000000.0 << endl; - #endif - - DWORD dwFullScreenBitDepth; - - // 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 - - 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(_bIsLowVidMemCard) { - // we're going to need 800x600 or 640x480 at 16 bit to save enough tex vidmem - dwFullScreenBitDepth=16; // do 16bpp - dwRenderWidth=640; - dwRenderHeight=480; - // force 16bpp textures too? - - #if 0 - // cant do this without more accurate way to estimate mem used before actually switching + + #if 0 + /* + // cant use this method 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 - } + + 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() << "XXXX WARNING: cant reserve 2MB of tex vidmem. only " << memleft << " bytes available. Need to rewrite wdxdisplay to try lower resolutions XXXXXXXX\n"; + } + */ + #endif + } - 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; - - DWORD SCL_FLAGS = SCL_FPUFlag | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; - - // 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 = 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(&ddsGAVMCaps,&dwVidMemTotal,&dwVidMemFree))) { - wdxdisplay_cat.debug() << "GetAvailableVidMem failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - wdxdisplay_cat.debug() << "before fullscreen switch: GetAvailableVidMem returns Total: " << dwVidMemTotal/1000000.0 << " Free: " << dwVidMemFree/1000000.0 << endl; - #endif - } + _dxgsg->scrn.dwFullScreenBitDepth=dwFullScreenBitDepth; } + + _dxgsg->scrn.dwRenderWidth=dwRenderWidth; + _dxgsg->scrn.dwRenderHeight=dwRenderHeight; + if(pDevinfo) + _dxgsg->scrn.hMon=pDevinfo->hMon; + _dxgsg->scrn.CardIDNum=devnum; // add ID tag for dbgprint purposes - CreateScreenBuffersAndDevice(dwRenderWidth,dwRenderHeight,pDD,pD3DI,pD3DDevDesc); + return true; + + // handle errors within this for device loop + + error_exit: + if(_dxgsg->scrn.pD3D!=NULL) + _dxgsg->scrn.pD3D->Release(); + if(_dxgsg->scrn.pDD!=NULL) + _dxgsg->scrn.pDD->Release(); - _dxgsg->SetDXReady(true); + _dxgsg->scrn.pDD=NULL; + _dxgsg->scrn.pD3D=NULL; + return false; } +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 ); +/* // 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 @@ -1612,9 +1828,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 @@ -1635,7 +1854,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) { @@ -1687,23 +1923,15 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD exit(1); } - 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; - - 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; @@ -1734,15 +1962,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(); @@ -1769,7 +1996,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; @@ -1813,9 +2040,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); } @@ -1858,9 +2086,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); @@ -1918,7 +2146,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 ("<1) { + // just do Enumeration for multimon case. + // enumeration was reqd to select voodoo1-class devices, but I'm no longer + // going to support them on DX7 due to lack of mouse cursor + + LPDIRECTDRAWENUMERATEEX pDDEnumEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(_hDDrawDLL,"DirectDrawEnumerateExA"); + if(pDDEnumEx == NULL) { + wdxdisplay_cat.fatal() << "GetProcAddr failed for DirectDrawEnumerateEx!\n"; + exit(1); + } + + hr = (*pDDEnumEx)(DriverEnumCallback_MultiMon, &_DeviceInfoVec, DDENUM_ATTACHEDSECONDARYDEVICES | DDENUM_NONDISPLAYDEVICES); + if(FAILED(hr)) { + wdxdisplay_cat.fatal() << "DirectDrawEnumerateEx failed : result = " << ConvD3DErrorToString(hr) << endl; + exit(1); + } + + if(_DeviceInfoVec.size() < num_windows) { + wdxdisplay_cat.fatal() << "couldn't find enough devices attached to meet multi window reqmt of " << num_windows << endl; + exit(1); + } + } else { + DXDeviceInfo devinfo; + ZeroMemory(&devinfo,sizeof(devinfo)); + } + + for(i=0;iconfig_window(this); + } + + int good_device_count=0; + + if(num_windows==1) { + if(_windows[0]->search_for_device(0,NULL)) + 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 << endl; + 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; + } +} + diff --git a/panda/src/wdxdisplay/wdxGraphicsWindow.h b/panda/src/wdxdisplay/wdxGraphicsWindow.h index a8275ff2ae..121ea8f232 100644 --- a/panda/src/wdxdisplay/wdxGraphicsWindow.h +++ b/panda/src/wdxdisplay/wdxGraphicsWindow.h @@ -30,14 +30,26 @@ #undef WINDOWS_LEAN_AND_MEAN #include +#include "dxGraphicsStateGuardian.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 { + char szDriver[MAX_DDDEVICEID_STRING]; + char szDescription[MAX_DDDEVICEID_STRING]; + GUID guidDeviceIdentifier; + HMONITOR hMon; +} DXDeviceInfo; +typedef vector DXDeviceInfoVec; //////////////////////////////////////////////////////////////////// // Class : wdxGraphicsWindow @@ -46,31 +58,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 ); @@ -79,8 +89,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); @@ -88,31 +96,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(int devnum,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; - DWORD _MaxAvailVidMem; - bool _bLoadedCustomCursor; - HCURSOR _hMouseCursor; - bool _bSizeIsMaximized; + WindowAdjustType _WindowAdjustingType; + bool _bSizeIsMaximized; bool _mouse_input_enabled; bool _mouse_motion_enabled; bool _mouse_passive_motion_enabled; @@ -122,7 +129,6 @@ private: bool _active_minimized_fullscreen; bool _return_control_to_app; int _depth_buffer_bpp; - HINSTANCE _hDDraw_DLL; public: static TypeHandle get_class_type(void); @@ -140,6 +146,40 @@ 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; + HINSTANCE _hDDrawDLL; + HWND _hOldForegroundWindow; + HCURSOR _hMouseCursor; + bool _bLoadedCustomCursor; + bool _bClosingAllWindows; + int _numMonitors; + LPDIRECTDRAWCREATEEX _pDDCreateEx; + DXDeviceInfoVec _DeviceInfoVec; +}; + extern void set_global_parameters(void); extern void restore_global_parameters(void);