From ba38195f196eb42c4ddd64f34d76aa0db47e5ce1 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 8 Aug 2008 20:54:45 +0000 Subject: [PATCH] auto-downscale parasite buffers --- panda/src/display/graphicsEngine.cxx | 9 --------- panda/src/display/graphicsOutput.cxx | 11 +++++++++-- panda/src/display/graphicsPipe.h | 1 + panda/src/display/parasiteBuffer.cxx | 26 +++++++++++++++++++++++++- panda/src/display/parasiteBuffer.h | 1 + 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index ac282f5dad..a4f0fd0274 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -408,15 +408,6 @@ make_output(GraphicsPipe *pipe, // last hope. if (can_use_parasite) { - if (x_size > host->get_x_size()) { - x_size = Texture::down_to_power_2(host->get_x_size()); - } - if (y_size > host->get_y_size()) { - y_size = Texture::down_to_power_2(host->get_y_size()); - } - if (flags & GraphicsPipe::BF_size_square) { - x_size = y_size = min(x_size, y_size); - } ParasiteBuffer *buffer = new ParasiteBuffer(host, name, x_size, y_size, flags); buffer->_sort = sort; do_add_window(buffer, threading_model); diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 6667457b5d..a468aa0c03 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -732,13 +732,20 @@ make_texture_buffer(const string &name, int x_size, int y_size, FrameBufferProperties props; props.set_rgb_color(1); props.set_depth_bits(1); + + int flags = GraphicsPipe::BF_refuse_window; + if (textures_power_2 != ATS_none) { + flags |= GraphicsPipe::BF_size_power_2; + } + if (tex->get_texture_type() == Texture::TT_cube_map) { + flags |= GraphicsPipe::BF_size_square; + } GraphicsOutput *buffer = get_gsg()->get_engine()-> make_output(get_gsg()->get_pipe(), name, get_child_sort(), props, WindowProperties::size(x_size, y_size), - GraphicsPipe::BF_refuse_window, - get_gsg(), get_host()); + flags, get_gsg(), get_host()); if (buffer != (GraphicsOutput *)NULL) { buffer->add_render_texture(tex, to_ram ? RTM_copy_ram : RTM_bind_or_copy); diff --git a/panda/src/display/graphicsPipe.h b/panda/src/display/graphicsPipe.h index 9354b1d214..5242c20d6b 100644 --- a/panda/src/display/graphicsPipe.h +++ b/panda/src/display/graphicsPipe.h @@ -85,6 +85,7 @@ PUBLISHED: BF_rtt_cumulative = 0x0400, // Buffer supports cumulative render-to-texture. BF_fb_props_optional = 0x0800, // FrameBufferProperties can be ignored. BF_size_square = 0x1000, // x_size must equal y_size (e.g. for cube maps) + BF_size_power_2 = 0x2000, // x_size and y_size must each be a power of two }; INLINE bool is_valid() const; diff --git a/panda/src/display/parasiteBuffer.cxx b/panda/src/display/parasiteBuffer.cxx index dc5d4df3ed..1a9886e63d 100644 --- a/panda/src/display/parasiteBuffer.cxx +++ b/panda/src/display/parasiteBuffer.cxx @@ -12,8 +12,8 @@ // //////////////////////////////////////////////////////////////////// - #include "parasiteBuffer.h" +#include "texture.h" TypeHandle ParasiteBuffer::_type_handle; @@ -87,6 +87,24 @@ set_size(int x, int y) { set_size_and_recalc(x, y); } +//////////////////////////////////////////////////////////////////// +// Function: ParasiteBuffer::set_size_and_recalc +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void ParasiteBuffer:: +set_size_and_recalc(int x, int y) { + if (_creation_flags & GraphicsPipe::BF_size_power_2) { + x = Texture::down_to_power_2(x); + y = Texture::down_to_power_2(y); + } + if (_creation_flags & GraphicsPipe::BF_size_square) { + x = y = min(x, y); + } + + GraphicsOutput::set_size_and_recalc(x, y); +} + //////////////////////////////////////////////////////////////////// // Function: ParasiteBuffer::is_active // Access: Published, Virtual @@ -135,6 +153,12 @@ begin_frame(FrameMode mode, Thread *current_thread) { set_size_and_recalc(_host->get_x_size(), _host->get_y_size()); } + } else { + if (_host->get_x_size() < _x_size || + _host->get_y_size() < _y_size) { + set_size_and_recalc(min(_x_size, _host->get_x_size()), + min(_y_size, _host->get_y_size())); + } } clear_cube_map_selection(); diff --git a/panda/src/display/parasiteBuffer.h b/panda/src/display/parasiteBuffer.h index e58065aceb..4575140670 100644 --- a/panda/src/display/parasiteBuffer.h +++ b/panda/src/display/parasiteBuffer.h @@ -60,6 +60,7 @@ PUBLISHED: void set_size(int x, int y); public: + void set_size_and_recalc(int x, int y); virtual bool begin_frame(FrameMode mode, Thread *current_thread); virtual void end_frame(FrameMode mode, Thread *current_thread); virtual GraphicsOutput *get_host();