From d0cf3615bcb21a7eb9d24717938771aea7e24ff9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 20 Jul 2006 19:46:24 +0000 Subject: [PATCH] more fixes to fullscreen/windowed switch --- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 28 +++++++++++++++++++ panda/src/dxgsg8/dxGraphicsStateGuardian8.h | 1 + panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 28 +++++++++++++++++++ panda/src/dxgsg9/dxGraphicsStateGuardian9.h | 1 + 4 files changed, 58 insertions(+) diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 95229929dd..47b3ec2bf3 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -2896,6 +2896,34 @@ do_issue_blending() { _d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); } +//////////////////////////////////////////////////////////////////// +// Function: DXGraphicsStateGuardian8::close_gsg +// Access: Protected, Virtual +// Description: This is called by the associated GraphicsWindow when +// close_window() is called. It should null out the +// _win pointer and possibly free any open resources +// associated with the GSG. +//////////////////////////////////////////////////////////////////// +void DXGraphicsStateGuardian8:: +close_gsg() { + GraphicsStateGuardian::close_gsg(); + + // Unlike in OpenGL, in DX8 it is safe to try to explicitly release + // any textures here. And it may even be a good idea. + if (_prepared_objects->get_ref_count() == 1) { + release_all_textures(); + release_all_geoms(); + release_all_vertex_buffers(); + release_all_index_buffers(); + + // Now we need to actually delete all of the objects we just + // released. + Thread *current_thread = Thread::get_current_thread(); + _prepared_objects->begin_frame(this, current_thread); + _prepared_objects->end_frame(current_thread); + } +} + //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian8::free_nondx_resources // Access: Public diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index 6342b3e52a..c32a9be73f 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -141,6 +141,7 @@ protected: virtual void enable_clip_plane(int plane_id, bool enable); virtual void bind_clip_plane(const NodePath &plane, int plane_id); + virtual void close_gsg(); void free_nondx_resources(); void free_d3d_device(); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index d2b709ad7c..9a170489ad 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -3996,6 +3996,34 @@ bind_clip_plane(const NodePath &plane, int plane_id) { } } +//////////////////////////////////////////////////////////////////// +// Function: DXGraphicsStateGuardian9::close_gsg +// Access: Protected, Virtual +// Description: This is called by the associated GraphicsWindow when +// close_window() is called. It should null out the +// _win pointer and possibly free any open resources +// associated with the GSG. +//////////////////////////////////////////////////////////////////// +void DXGraphicsStateGuardian9:: +close_gsg() { + GraphicsStateGuardian::close_gsg(); + + // Unlike in OpenGL, in DX9 it is safe to try to explicitly release + // any textures here. And it may even be a good idea. + if (_prepared_objects->get_ref_count() == 1) { + release_all_textures(); + release_all_geoms(); + release_all_vertex_buffers(); + release_all_index_buffers(); + + // Now we need to actually delete all of the objects we just + // released. + Thread *current_thread = Thread::get_current_thread(); + _prepared_objects->begin_frame(this, current_thread); + _prepared_objects->end_frame(current_thread); + } +} + //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian9::free_nondx_resources // Access: Public diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h index 56b6e63484..2aa179056f 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h @@ -187,6 +187,7 @@ protected: virtual void enable_clip_plane(int plane_id, bool enable); virtual void bind_clip_plane(const NodePath &plane, int plane_id); + virtual void close_gsg(); void free_nondx_resources(); void free_d3d_device();