more easily extendable DisplayRegion

This commit is contained in:
rdb 2012-01-07 18:52:20 +00:00
parent c06eafece4
commit 2d78a0503b
6 changed files with 50 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
};

View File

@ -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);
}

View File

@ -1103,6 +1103,7 @@ texture_uploaded(Texture *tex) {
LoadedTexture &lt = _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);

View File

@ -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::