From 07c2787a39911cddf2e6e75929efdb8efa4ae5e4 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 13 Aug 2008 18:27:33 +0000 Subject: [PATCH] fix for inverted screenshot --- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 26 ++++++++++++++---- panda/src/dxgsg8/dxGraphicsStateGuardian8.h | 2 ++ panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 27 ++++++++++++++----- panda/src/dxgsg9/dxGraphicsStateGuardian9.h | 2 ++ 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index a564420fca..8d591b3c3f 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -1420,7 +1420,7 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, if (tex->get_texture_type() != Texture::TT_2d_texture) { // For a specialty texture like a cube map, go the slow route // through RAM for now. - return framebuffer_copy_to_ram(tex, z, dr, rb); + return do_framebuffer_copy_to_ram(tex, z, dr, rb, true); } nassertr(dtc->get_d3d_2d_texture() != NULL, false); @@ -1501,7 +1501,7 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, if (!okflag) { // The copy failed. Fall back to copying it to RAM and back. // Terribly slow, but what are you going to do? - return framebuffer_copy_to_ram(tex, z, dr, rb); + return do_framebuffer_copy_to_ram(tex, z, dr, rb, true); } return true; @@ -1520,6 +1520,21 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, //////////////////////////////////////////////////////////////////// bool DXGraphicsStateGuardian8:: framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb) { + return do_framebuffer_copy_to_ram(tex, z, dr, rb, false); +} + +//////////////////////////////////////////////////////////////////// +// Function: DXGraphicsStateGuardian8::do_framebuffer_copy_to_ram +// Access: Public +// Description: This is the implementation of +// framebuffer_copy_to_ram(); it adds one additional +// parameter, which should be true if the framebuffer is +// to be inverted during the copy (as in the same way it +// copies to texture memory). +//////////////////////////////////////////////////////////////////// +bool DXGraphicsStateGuardian8:: +do_framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, + const RenderBuffer &rb, bool inverted) { set_read_buffer(rb); RECT rect; @@ -1603,7 +1618,7 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend return false; } - // copy_inverted = true; + copy_inverted = true; RELEASE(backbuffer, dxgsg8, "backbuffer", RELEASE_ONCE); @@ -1647,8 +1662,6 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend return false; } - // For some reason the front buffer comes out inverted, but the - // back buffer does not. copy_inverted = true; } else { @@ -1658,6 +1671,9 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend return false; } + if (inverted) { + copy_inverted = !copy_inverted; + } DXTextureContext8::d3d_surface_to_texture(rect, temp_surface, copy_inverted, tex, z); diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index e61407f835..0b5421e0e8 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -98,6 +98,8 @@ public: const RenderBuffer &rb); virtual bool framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb); + bool do_framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, + const RenderBuffer &rb, bool inverted); virtual void reset(); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 0c2b393a4e..bbc707ce73 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -2074,7 +2074,7 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, if (tex->get_texture_type() != Texture::TT_2d_texture) { // For a specialty texture like a cube map, go the slow route // through RAM for now. - return framebuffer_copy_to_ram(tex, z, dr, rb); + return do_framebuffer_copy_to_ram(tex, z, dr, rb, true); } nassertr(dtc->get_d3d_2d_texture() != NULL, false); @@ -2172,7 +2172,7 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, if (!okflag) { // The copy failed. Fall back to copying it to RAM and back. // Terribly slow, but what are you going to do? - return framebuffer_copy_to_ram(tex, z, dr, rb); + return do_framebuffer_copy_to_ram(tex, z, dr, rb, true); } return true; @@ -2192,6 +2192,21 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, bool DXGraphicsStateGuardian9:: framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb) { + return do_framebuffer_copy_to_ram(tex, z, dr, rb, false); +} + +//////////////////////////////////////////////////////////////////// +// Function: DXGraphicsStateGuardian9::do_framebuffer_copy_to_ram +// Access: Public +// Description: This is the implementation of +// framebuffer_copy_to_ram(); it adds one additional +// parameter, which should be true if the framebuffer is +// to be inverted during the copy (as in the same way it +// copies to texture memory). +//////////////////////////////////////////////////////////////////// +bool DXGraphicsStateGuardian9:: +do_framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, + const RenderBuffer &rb, bool inverted) { set_read_buffer(rb); RECT rect; @@ -2291,7 +2306,7 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, return false; } - // copy_inverted = true; + copy_inverted = true; RELEASE(backbuffer, dxgsg9, "backbuffer", RELEASE_ONCE); @@ -2339,8 +2354,6 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, return false; } - // For some reason the front buffer comes out inverted, but the - // back buffer does not. copy_inverted = true; } else { @@ -2350,7 +2363,9 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, return false; } - copy_inverted = false; + if (inverted) { + copy_inverted = !copy_inverted; + } DXTextureContext9::d3d_surface_to_texture(rect, temp_surface, copy_inverted, tex, z); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h index 81f3a36bee..9c2a8ae9ac 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h @@ -138,6 +138,8 @@ public: const RenderBuffer &rb); virtual bool framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb); + bool do_framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, + const RenderBuffer &rb, bool inverted); void reset_render_states (void); virtual void reset();