From 2d78a0503b98649264c4caf8c8499259641dff57 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 7 Jan 2012 18:52:20 +0000 Subject: [PATCH] more easily extendable DisplayRegion --- panda/src/display/displayRegion.I | 13 +++++++++- panda/src/display/displayRegion.cxx | 25 +++++++++++++++++++ panda/src/display/displayRegion.h | 7 ++++++ .../display/displayRegionCullCallbackData.cxx | 4 +-- panda/src/display/graphicsEngine.cxx | 5 ++-- panda/src/display/graphicsOutput.cxx | 7 ++---- 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/panda/src/display/displayRegion.I b/panda/src/display/displayRegion.I index 7e6e554fd5..27d4cd2cc4 100644 --- a/panda/src/display/displayRegion.I +++ b/panda/src/display/displayRegion.I @@ -53,8 +53,8 @@ get_dimensions(PN_stdfloat &l, PN_stdfloat &r, PN_stdfloat &b, PN_stdfloat &t) c b = cdata->_dimensions[2]; t = cdata->_dimensions[3]; } -/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// // Function: DisplayRegion::get_dimensions // Access: Published // Description: Retrieves the coordinates of the DisplayRegion's @@ -512,6 +512,17 @@ get_draw_region_pcollector() { return _draw_region_pcollector; } +//////////////////////////////////////////////////////////////////// +// Function: DisplayRegion::pixel_size_changed +// Access: Private, Virtual +// Description: Called when the size in pixels of this region +// has changed. Also called the first time the +// pixel size is known. +//////////////////////////////////////////////////////////////////// +INLINE void DisplayRegion:: +pixel_size_changed(int x_size, int y_size) { +} + //////////////////////////////////////////////////////////////////// // Function: DisplayRegion::CDataCull::Constructor // Access: Public diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index 836d65aa29..00daef72bf 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -14,6 +14,7 @@ #include "displayRegion.h" #include "stereoDisplayRegion.h" +#include "graphicsEngine.h" #include "graphicsOutput.h" #include "config_display.h" #include "texture.h" @@ -43,6 +44,8 @@ DisplayRegion(GraphicsOutput *window, const LVecBase4 &dimensions) : _draw_buffer_type = window->get_draw_buffer_type(); set_dimensions(dimensions); compute_pixels_all_stages(); + + _window->add_display_region(this); } //////////////////////////////////////////////////////////////////// @@ -738,6 +741,9 @@ do_compute_pixels(int x_size, int y_size, CData *cdata) { << "DisplayRegion::do_compute_pixels(" << x_size << ", " << y_size << ")\n"; } + int old_w = cdata->_pr - cdata->_pl; + int old_h = cdata->_pt - cdata->_pb; + cdata->_pl = int((cdata->_dimensions[0] * x_size) + 0.5); cdata->_pr = int((cdata->_dimensions[1] * x_size) + 0.5); @@ -756,6 +762,12 @@ do_compute_pixels(int x_size, int y_size, CData *cdata) { cdata->_pbi = int(((1.0f - cdata->_dimensions[2]) * y_size) + 0.5); cdata->_pti = int(((1.0f - cdata->_dimensions[3]) * y_size) + 0.5); } + + int w = cdata->_pr - cdata->_pl; + int h = cdata->_pt - cdata->_pb; + if (old_w != w || old_h != h) { + pixel_size_changed(w, h); + } } //////////////////////////////////////////////////////////////////// @@ -782,6 +794,19 @@ set_active_index(int index) { #endif // DO_PSTATS } +//////////////////////////////////////////////////////////////////// +// Function: DisplayRegion::do_cull +// Access: Protected, Virtual +// Description: Performs a cull traversal. The default +// implementation simply calls GraphicsEngine::do_cull. +//////////////////////////////////////////////////////////////////// +void DisplayRegion:: +do_cull(CullHandler *cull_handler, SceneSetup *scene_setup, + GraphicsStateGuardian *gsg, Thread *current_thread) { + + GraphicsEngine::do_cull(cull_handler, scene_setup, gsg, current_thread); +} + //////////////////////////////////////////////////////////////////// // Function: DisplayRegion::CData::Constructor // Access: Public diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index c921118770..530176b8d5 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -162,6 +162,11 @@ private: void win_display_regions_changed(); void do_compute_pixels(int x_size, int y_size, CData *cdata); void set_active_index(int index); + INLINE virtual void pixel_size_changed(int x_size, int y_size); + +protected: + virtual void do_cull(CullHandler *cull_handler, SceneSetup *scene_setup, + GraphicsStateGuardian *gsg, Thread *current_thread); protected: // The associated window is a permanent property of the @@ -261,7 +266,9 @@ public: private: static TypeHandle _type_handle; + friend class GraphicsEngine; friend class GraphicsOutput; + friend class DisplayRegionCullCallbackData; friend class DisplayRegionPipelineReader; }; diff --git a/panda/src/display/displayRegionCullCallbackData.cxx b/panda/src/display/displayRegionCullCallbackData.cxx index 419221c700..daf85e3ad0 100644 --- a/panda/src/display/displayRegionCullCallbackData.cxx +++ b/panda/src/display/displayRegionCullCallbackData.cxx @@ -60,7 +60,5 @@ upcall() { DisplayRegion *dr = _scene_setup->get_display_region(); GraphicsStateGuardian *gsg = dr->get_window()->get_gsg(); - GraphicsEngine::do_cull(_cull_handler, _scene_setup, - gsg, current_thread); + dr->do_cull(_cull_handler, _scene_setup, gsg, current_thread); } - diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 43156a37af..f64287be48 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -1103,6 +1103,7 @@ texture_uploaded(Texture *tex) { LoadedTexture < = _loaded_textures.back(); lt._tex = tex; lt._image_modified = tex->get_image_modified(); +// Usually only called by DisplayRegion::do_cull. } //////////////////////////////////////////////////////////////////// @@ -1334,7 +1335,7 @@ cull_and_draw_together(GraphicsOutput *win, DisplayRegion *dr, } else { // Perform the cull normally. - do_cull(&cull_handler, scene_setup, gsg, current_thread); + dr->do_cull(&cull_handler, scene_setup, gsg, current_thread); } gsg->end_scene(); @@ -1452,7 +1453,7 @@ cull_to_bins(GraphicsOutput *win, DisplayRegion *dr, Thread *current_thread) { } else { // Perform the cull normally. - do_cull(&cull_handler, scene_setup, gsg, current_thread); + dr->do_cull(&cull_handler, scene_setup, gsg, current_thread); } PStatTimer timer(_cull_sort_pcollector, current_thread); diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index a57b96a527..f3d06c1585 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -671,7 +671,7 @@ make_mono_display_region(const LVecBase4 &dimensions) { return dr; } - return add_display_region(new DisplayRegion(this, dimensions)); + return new DisplayRegion(this, dimensions); } //////////////////////////////////////////////////////////////////// @@ -720,9 +720,6 @@ make_stereo_display_region(const LVecBase4 &dimensions) { PT(StereoDisplayRegion) stereo = new StereoDisplayRegion(this, dimensions, left, right); - add_display_region(stereo); - add_display_region(left); - add_display_region(right); return stereo; } @@ -1592,7 +1589,7 @@ create_texture_card_vdata(int x, int y) { //////////////////////////////////////////////////////////////////// // Function: GraphicsOutput::add_display_region // Access: Private -// Description: Called by one of the make_display_region() methods to +// Description: Called by the DisplayRegion constructor to // add the new DisplayRegion to the list. //////////////////////////////////////////////////////////////////// DisplayRegion *GraphicsOutput::