From cb8e25f859b1ae008b1fc13721d649c396ce8ea8 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 8 Jun 2006 21:19:37 +0000 Subject: [PATCH] A few more fixes --- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 53 +++++++++++++++++ panda/src/dxgsg8/dxGraphicsStateGuardian8.h | 3 + panda/src/dxgsg8/wdxGraphicsBuffer8.cxx | 33 ++++++----- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 58 +++++++++++++++++++ panda/src/dxgsg9/dxGraphicsStateGuardian9.h | 4 ++ panda/src/dxgsg9/wdxGraphicsBuffer9.cxx | 29 ++++++---- 6 files changed, 157 insertions(+), 23 deletions(-) diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index bc47db1be2..8ee36b8b68 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -4053,3 +4053,56 @@ LPDIRECT3DDEVICE8 DXGraphicsStateGuardian8:: get_d3d_device() { return _d3d_device; } + +//////////////////////////////////////////////////////////////////// +// Function: dxGraphicsStateGuardian8::calc_fb_properties +// Access: Public +// Description: Convert DirectX framebuffer format ids into a +// FrameBufferProperties structure. +//////////////////////////////////////////////////////////////////// +FrameBufferProperties DXGraphicsStateGuardian8:: +calc_fb_properties(DWORD cformat, DWORD dformat, DWORD multisampletype) { + FrameBufferProperties props; + int index=0; + int alpha=0; + int color=0; + switch (cformat) { + case D3DFMT_R8G8B8: index=0; color=24; alpha=0; break; + case D3DFMT_A8R8G8B8: index=0; color=24; alpha=8; break; + case D3DFMT_X8R8G8B8: index=0; color=24; alpha=0; break; + case D3DFMT_R5G6B5: index=0; color=16; alpha=0; break; + case D3DFMT_X1R5G5B5: index=0; color=15; alpha=0; break; + case D3DFMT_A1R5G5B5: index=0; color=15; alpha=1; break; + case D3DFMT_A4R4G4B4: index=0; color=12; alpha=4; break; + case D3DFMT_R3G3B2: index=0; color= 8; alpha=0; break; + case D3DFMT_A8R3G3B2: index=0; color= 8; alpha=8; break; + case D3DFMT_X4R4G4B4: index=0; color=12; alpha=0; break; + case D3DFMT_A2B10G10R10: index=0; color=30; alpha=2; break; + case D3DFMT_A8P8: index=1; color= 8; alpha=8; break; + case D3DFMT_P8: index=1; color= 8; alpha=0; break; + } + props.set_color_bits(color); + props.set_alpha_bits(alpha); + if (index) { + props.set_rgb_color(0); + props.set_indexed_color(1); + } else if (color) { + props.set_rgb_color(1); + props.set_indexed_color(0); + } + int depth=0; + int stencil=0; + switch (dformat) { + case D3DFMT_D32: depth=32; stencil=0; break; + case D3DFMT_D15S1: depth=15; stencil=1; break; + case D3DFMT_D24S8: depth=24; stencil=8; break; + case D3DFMT_D16: depth=16; stencil=0; break; + case D3DFMT_D24X8: depth=24; stencil=0; break; + case D3DFMT_D24X4S4: depth=24; stencil=4; break; + } + props.set_depth_bits(depth); + props.set_stencil_bits(stencil); + props.set_multisamples(multisampletype); + return props; +} + diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index e1989fe6d2..a0828f4996 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -48,6 +48,9 @@ public: DXGraphicsStateGuardian8(GraphicsPipe *pipe); ~DXGraphicsStateGuardian8(); + FrameBufferProperties + calc_fb_properties(DWORD cformat, DWORD dformat, DWORD multisampletype); + virtual TextureContext *prepare_texture(Texture *tex); void apply_texture(int i, TextureContext *tc); virtual void release_texture(TextureContext *tc); diff --git a/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx b/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx index 4a5d6ca377..2f78faff58 100644 --- a/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx +++ b/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx @@ -137,7 +137,7 @@ end_frame(FrameMode mode, Thread *current_thread) { } //////////////////////////////////////////////////////////////////// -// Function: wglGraphicsStateGuardian::save_bitplanes +// Function: wdxGraphicsBuffer8::save_bitplanes // Access: Public // Description: After rendering, d3d_device will need to be restored // to its initial state. This function saves the state. @@ -151,26 +151,16 @@ save_bitplanes() { dxgsg8_cat.error ( ) << "GetRenderTarget " << D3DERRORSTRING(hr) FL; return false; } - hr = _saved_color_buffer -> GetDesc (&_saved_color_desc); - if (!SUCCEEDED (hr)) { - dxgsg8_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; - return false; - } hr = _dxgsg -> _d3d_device -> GetDepthStencilSurface (&_saved_depth_buffer); if (!SUCCEEDED (hr)) { dxgsg8_cat.error ( ) << "GetDepthStencilSurface " << D3DERRORSTRING(hr) FL; return false; } - hr = _saved_depth_buffer -> GetDesc (&_saved_depth_desc); - if (!SUCCEEDED (hr)) { - dxgsg8_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; - return false; - } return true; } //////////////////////////////////////////////////////////////////// -// Function: wglGraphicsStateGuardian::restore_bitplanes +// Function: wdxGraphicsBuffer8::restore_bitplanes // Access: Public // Description: After rendering, d3d_device will need to be restored // to its initial state. This function restores the state. @@ -197,7 +187,7 @@ restore_bitplanes() { //////////////////////////////////////////////////////////////////// -// Function: wglGraphicsStateGuardian::rebuild_bitplanes +// Function: wdxGraphicsBuffer8::rebuild_bitplanes // Access: Public // Description: If necessary, reallocates (or allocates) the // bitplanes for the buffer. @@ -447,6 +437,23 @@ open_buffer() { return false; } + HRESULT hr; + hr = _saved_color_buffer -> GetDesc (&_saved_color_desc); + if (!SUCCEEDED (hr)) { + dxgsg8_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; + return false; + } + hr = _saved_depth_buffer -> GetDesc (&_saved_depth_desc); + if (!SUCCEEDED (hr)) { + dxgsg8_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; + return false; + } + _fb_properties = _dxgsg-> + calc_fb_properties(_saved_color_desc.Format, + _saved_depth_desc.Format, + _saved_depth_desc.MultiSampleType); + _fb_properties.set_force_hardware(1); // Wild guess. + if (!rebuild_bitplanes()) { restore_bitplanes(); return false; diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index e7d8910124..b11feadff3 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -5199,3 +5199,61 @@ do_issue_stencil() { stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_enable, 0); } } + +//////////////////////////////////////////////////////////////////// +// Function: dxGraphicsStateGuardian9::calc_fb_properties +// Access: Public +// Description: Convert DirectX framebuffer format ids into a +// FrameBufferProperties structure. +//////////////////////////////////////////////////////////////////// +FrameBufferProperties DXGraphicsStateGuardian9:: +calc_fb_properties(DWORD cformat, DWORD dformat, + DWORD multisampletype, DWORD multisamplequality) { + FrameBufferProperties props; + int index=0; + int alpha=0; + int color=0; + switch (cformat) { + case D3DFMT_R8G8B8: index=0; color=24; alpha=0; break; + case D3DFMT_A8R8G8B8: index=0; color=24; alpha=8; break; + case D3DFMT_X8R8G8B8: index=0; color=24; alpha=0; break; + case D3DFMT_R5G6B5: index=0; color=16; alpha=0; break; + case D3DFMT_X1R5G5B5: index=0; color=15; alpha=0; break; + case D3DFMT_A1R5G5B5: index=0; color=15; alpha=1; break; + case D3DFMT_A4R4G4B4: index=0; color=12; alpha=4; break; + case D3DFMT_R3G3B2: index=0; color= 8; alpha=0; break; + case D3DFMT_A8R3G3B2: index=0; color= 8; alpha=8; break; + case D3DFMT_X4R4G4B4: index=0; color=12; alpha=0; break; + case D3DFMT_A2B10G10R10: index=0; color=30; alpha=2; break; + case D3DFMT_A8P8: index=1; color= 8; alpha=8; break; + case D3DFMT_P8: index=1; color= 8; alpha=0; break; + } + props.set_color_bits(color); + props.set_alpha_bits(alpha); + if (index) { + props.set_rgb_color(0); + props.set_indexed_color(1); + } else if (color) { + props.set_rgb_color(1); + props.set_indexed_color(0); + } + int depth=0; + int stencil=0; + switch (dformat) { + case D3DFMT_D32: depth=32; stencil=0; break; + case D3DFMT_D15S1: depth=15; stencil=1; break; + case D3DFMT_D24S8: depth=24; stencil=8; break; + case D3DFMT_D16: depth=16; stencil=0; break; + case D3DFMT_D24X8: depth=24; stencil=0; break; + case D3DFMT_D24X4S4: depth=24; stencil=4; break; + } + props.set_depth_bits(depth); + props.set_stencil_bits(stencil); + if (multisampletype == D3DMULTISAMPLE_NONMASKABLE) { + props.set_multisamples(2); + } else { + props.set_multisamples(multisampletype); + } + return props; +} + diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h index 2d3c1380ea..d08149863a 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h @@ -81,6 +81,10 @@ public: DXGraphicsStateGuardian9(GraphicsPipe *pipe); ~DXGraphicsStateGuardian9(); + FrameBufferProperties + calc_fb_properties(DWORD cformat, DWORD dformat, + DWORD multisampletype, DWORD multisamplequality); + virtual TextureContext *prepare_texture(Texture *tex); void apply_texture(int i, TextureContext *tc); virtual void release_texture(TextureContext *tc); diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx index fe5eb0b081..d51f5667a8 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx @@ -151,21 +151,11 @@ save_bitplanes() { dxgsg9_cat.error ( ) << "GetRenderTarget " << D3DERRORSTRING(hr) FL; return false; } - hr = _saved_color_buffer -> GetDesc (&_saved_color_desc); - if (!SUCCEEDED (hr)) { - dxgsg9_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; - return false; - } hr = _dxgsg -> _d3d_device -> GetDepthStencilSurface (&_saved_depth_buffer); if (!SUCCEEDED (hr)) { dxgsg9_cat.error ( ) << "GetDepthStencilSurface " << D3DERRORSTRING(hr) FL; return false; } - hr = _saved_depth_buffer -> GetDesc (&_saved_depth_desc); - if (!SUCCEEDED (hr)) { - dxgsg9_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; - return false; - } return true; } @@ -457,6 +447,25 @@ open_buffer() { return false; } + HRESULT hr; + hr = _saved_color_buffer -> GetDesc (&_saved_color_desc); + if (!SUCCEEDED (hr)) { + dxgsg9_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; + return false; + } + hr = _saved_depth_buffer -> GetDesc (&_saved_depth_desc); + if (!SUCCEEDED (hr)) { + dxgsg9_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL; + return false; + } + _fb_properties = _dxgsg-> + calc_fb_properties(_saved_color_desc.Format, + _saved_depth_desc.Format, + _saved_depth_desc.MultiSampleType, + _saved_depth_desc.MultiSampleQuality); + _fb_properties.set_force_hardware(1); // Wild guess. + + if (!rebuild_bitplanes()) { restore_bitplanes(); return false;