support window-type offscreen in pview

This commit is contained in:
David Rose 2009-04-24 19:04:07 +00:00
parent e5e71cce6f
commit 0b4470af0d
7 changed files with 109 additions and 78 deletions

View File

@ -30,6 +30,8 @@ ConfigVariableDouble aspect_ratio
("aspect-ratio", 0.0); ("aspect-ratio", 0.0);
ConfigVariableBool show_frame_rate_meter ConfigVariableBool show_frame_rate_meter
("show-frame-rate-meter", false); ("show-frame-rate-meter", false);
ConfigVariableString window_type
("window-type", "onscreen");
ConfigVariableString record_session ConfigVariableString record_session
("record-session", ""); ("record-session", "");

View File

@ -233,7 +233,7 @@ get_default_pipe() {
// GraphicsWindow to share the same mouse. // GraphicsWindow to share the same mouse.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
NodePath PandaFramework:: NodePath PandaFramework::
get_mouse(GraphicsWindow *window) { get_mouse(GraphicsOutput *window) {
Mouses::iterator mi = _mouses.find(window); Mouses::iterator mi = _mouses.find(window);
if (mi != _mouses.end()) { if (mi != _mouses.end()) {
return (*mi).second; return (*mi).second;
@ -241,16 +241,19 @@ get_mouse(GraphicsWindow *window) {
NodePath mouse; NodePath mouse;
NodePath data_root = get_data_root(); if (window->is_of_type(GraphicsWindow::get_class_type())) {
MouseAndKeyboard *mouse_node = new MouseAndKeyboard(window, 0, "mouse"); NodePath data_root = get_data_root();
mouse = data_root.attach_new_node(mouse_node); GraphicsWindow *win = DCAST(GraphicsWindow, window);
MouseAndKeyboard *mouse_node = new MouseAndKeyboard(win, 0, "mouse");
mouse = data_root.attach_new_node(mouse_node);
RecorderController *recorder = get_recorder(); RecorderController *recorder = get_recorder();
if (recorder != (RecorderController *)NULL) { if (recorder != (RecorderController *)NULL) {
// If we're in recording or playback mode, associate a recorder. // If we're in recording or playback mode, associate a recorder.
MouseRecorder *mouse_recorder = new MouseRecorder("mouse"); MouseRecorder *mouse_recorder = new MouseRecorder("mouse");
mouse = mouse.attach_new_node(mouse_recorder); mouse = mouse.attach_new_node(mouse_recorder);
recorder->add_recorder("mouse", mouse_recorder); recorder->add_recorder("mouse", mouse_recorder);
}
} }
_mouses[window] = mouse; _mouses[window] = mouse;
@ -265,7 +268,7 @@ get_mouse(GraphicsWindow *window) {
// earlier call to get_mouse(). // earlier call to get_mouse().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PandaFramework:: void PandaFramework::
remove_mouse(const GraphicsWindow *window) { remove_mouse(const GraphicsOutput *window) {
Mouses::iterator mi = _mouses.find(window); Mouses::iterator mi = _mouses.find(window);
if (mi != _mouses.end()) { if (mi != _mouses.end()) {
(*mi).second.remove_node(); (*mi).second.remove_node();
@ -391,7 +394,12 @@ open_window(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
WindowProperties props; WindowProperties props;
get_default_window_props(props); get_default_window_props(props);
return open_window(props, pipe, gsg); int flags = GraphicsPipe::BF_require_window;
if (window_type == "offscreen") {
flags = GraphicsPipe::BF_refuse_window;
}
return open_window(props, flags, pipe, gsg);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -405,8 +413,8 @@ open_window(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
// NULL if not. // NULL if not.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
WindowFramework *PandaFramework:: WindowFramework *PandaFramework::
open_window(const WindowProperties &props, GraphicsPipe *pipe, open_window(const WindowProperties &props, int flags,
GraphicsStateGuardian *gsg) { GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
if (pipe == (GraphicsPipe *)NULL) { if (pipe == (GraphicsPipe *)NULL) {
pipe = get_default_pipe(); pipe = get_default_pipe();
if (pipe == (GraphicsPipe *)NULL) { if (pipe == (GraphicsPipe *)NULL) {
@ -424,18 +432,18 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe,
wf->set_perpixel(get_perpixel()); wf->set_perpixel(get_perpixel());
wf->set_background_type(get_background_type()); wf->set_background_type(get_background_type());
GraphicsWindow *win = wf->open_window(props, get_graphics_engine(), GraphicsOutput *win = wf->open_window(props, flags, get_graphics_engine(),
pipe, gsg); pipe, gsg);
_engine->open_windows(); _engine->open_windows();
if (win != (GraphicsWindow *)NULL && !win->is_valid()) { if (win != (GraphicsOutput *)NULL && !win->is_valid()) {
// The window won't open. // The window won't open.
_engine->remove_window(win); _engine->remove_window(win);
wf->close_window(); wf->close_window();
win = NULL; win = NULL;
} }
if (win == (GraphicsWindow *)NULL) { if (win == (GraphicsOutput *)NULL) {
// Oops, couldn't make an actual window. // Oops, couldn't make a window or buffer.
framework_cat.error() framework_cat.error()
<< "Unable to create window.\n"; << "Unable to create window.\n";
return NULL; return NULL;
@ -449,14 +457,14 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe,
// Function: PandaFramework::find_window // Function: PandaFramework::find_window
// Access: Public // Access: Public
// Description: Returns the index of the first WindowFramework object // Description: Returns the index of the first WindowFramework object
// found that references the indicated GraphicsWindow // found that references the indicated GraphicsOutput
// pointer, or -1 if none do. // pointer, or -1 if none do.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int PandaFramework:: int PandaFramework::
find_window(const GraphicsWindow *win) const { find_window(const GraphicsOutput *win) const {
int n; int n;
for (n = 0; n < (int)_windows.size(); n++) { for (n = 0; n < (int)_windows.size(); n++) {
if (_windows[n]->get_graphics_window() == win) { if (_windows[n]->get_graphics_output() == win) {
return n; return n;
} }
} }
@ -494,8 +502,8 @@ close_window(int n) {
nassertv(n >= 0 && n < (int)_windows.size()); nassertv(n >= 0 && n < (int)_windows.size());
WindowFramework *wf = _windows[n]; WindowFramework *wf = _windows[n];
GraphicsWindow *win = wf->get_graphics_window(); GraphicsOutput *win = wf->get_graphics_output();
if (win != (GraphicsWindow *)NULL) { if (win != (GraphicsOutput *)NULL) {
_engine->remove_window(win); _engine->remove_window(win);
} }
@ -515,8 +523,8 @@ close_all_windows() {
for (wi = _windows.begin(); wi != _windows.end(); ++wi) { for (wi = _windows.begin(); wi != _windows.end(); ++wi) {
WindowFramework *wf = (*wi); WindowFramework *wf = (*wi);
GraphicsWindow *win = wf->get_graphics_window(); GraphicsOutput *win = wf->get_graphics_output();
if (win != (GraphicsWindow *)NULL) { if (win != (GraphicsOutput *)NULL) {
_engine->remove_window(win); _engine->remove_window(win);
} }
@ -543,7 +551,7 @@ all_windows_closed() const {
Windows::const_iterator wi; Windows::const_iterator wi;
for (wi = _windows.begin(); wi != _windows.end(); ++wi) { for (wi = _windows.begin(); wi != _windows.end(); ++wi) {
WindowFramework *wf = (*wi); WindowFramework *wf = (*wi);
if (wf->get_graphics_window()->get_properties().get_open()) { if (wf->get_graphics_output()->is_valid()) {
return false; return false;
} }
} }
@ -938,7 +946,7 @@ event_esc(const Event *event, void *data) {
WindowFramework *wf; WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr()); DCAST_INTO_V(wf, param.get_ptr());
PT(GraphicsWindow) win = wf->get_graphics_window(); PT(GraphicsOutput) win = wf->get_graphics_output();
PandaFramework *self = (PandaFramework *)data; PandaFramework *self = (PandaFramework *)data;
self->close_window(wf); self->close_window(wf);
@ -1341,7 +1349,7 @@ event_f9(const Event *event, void *data) {
self->_engine->render_frame(); self->_engine->render_frame();
} }
Filename filename = wf->get_graphics_window()->save_screenshot_default(); Filename filename = wf->get_graphics_output()->save_screenshot_default();
string text; string text;
if (filename.empty()) { if (filename.empty()) {
text = "Screenshot failed"; text = "Screenshot failed";
@ -1467,7 +1475,7 @@ event_window_event(const Event *event, void *data) {
// than the window framework object (which is the parameter of all // than the window framework object (which is the parameter of all
// of the keyboard events). // of the keyboard events).
EventParameter param = event->get_parameter(0); EventParameter param = event->get_parameter(0);
const GraphicsWindow *win; const GraphicsOutput *win;
DCAST_INTO_V(win, param.get_ptr()); DCAST_INTO_V(win, param.get_ptr());
// Is this a window we've heard about? // Is this a window we've heard about?
@ -1477,7 +1485,7 @@ event_window_event(const Event *event, void *data) {
<< "Ignoring message from unknown window.\n"; << "Ignoring message from unknown window.\n";
} else { } else {
if (!win->get_properties().get_open()) { if (!win->is_valid()) {
int window_index = self->find_window(win); int window_index = self->find_window(win);
while (window_index != -1) { while (window_index != -1) {
self->close_window(window_index); self->close_window(window_index);

View File

@ -50,8 +50,8 @@ public:
INLINE const NodePath &get_data_root() const; INLINE const NodePath &get_data_root() const;
INLINE EventHandler &get_event_handler(); INLINE EventHandler &get_event_handler();
INLINE AsyncTaskManager &get_task_mgr(); INLINE AsyncTaskManager &get_task_mgr();
NodePath get_mouse(GraphicsWindow *window); NodePath get_mouse(GraphicsOutput *window);
void remove_mouse(const GraphicsWindow *window); void remove_mouse(const GraphicsOutput *window);
void define_key(const string &event_name, void define_key(const string &event_name,
const string &description, const string &description,
@ -64,13 +64,13 @@ public:
WindowFramework *open_window(); WindowFramework *open_window();
WindowFramework *open_window(GraphicsPipe *pipe, WindowFramework *open_window(GraphicsPipe *pipe,
GraphicsStateGuardian *gsg = NULL); GraphicsStateGuardian *gsg = NULL);
WindowFramework *open_window(const WindowProperties &props, WindowFramework *open_window(const WindowProperties &props, int flags,
GraphicsPipe *pipe = NULL, GraphicsPipe *pipe = NULL,
GraphicsStateGuardian *gsg = NULL); GraphicsStateGuardian *gsg = NULL);
INLINE int get_num_windows() const; INLINE int get_num_windows() const;
INLINE WindowFramework *get_window(int n) const; INLINE WindowFramework *get_window(int n) const;
int find_window(const GraphicsWindow *win) const; int find_window(const GraphicsOutput *win) const;
int find_window(const WindowFramework *wf) const; int find_window(const WindowFramework *wf) const;
void close_window(int n); void close_window(int n);
INLINE void close_window(WindowFramework *wf); INLINE void close_window(WindowFramework *wf);
@ -176,7 +176,7 @@ private:
typedef pvector< PT(WindowFramework) > Windows; typedef pvector< PT(WindowFramework) > Windows;
Windows _windows; Windows _windows;
typedef pmap< const GraphicsWindow *, NodePath > Mouses; typedef pmap< const GraphicsOutput *, NodePath > Mouses;
Mouses _mouses; Mouses _mouses;
NodePath _models; NodePath _models;

View File

@ -28,10 +28,26 @@ get_panda_framework() const {
// Function: WindowFramework::get_graphics_window // Function: WindowFramework::get_graphics_window
// Access: Public // Access: Public
// Description: Returns a pointer to the underlying GraphicsWindow // Description: Returns a pointer to the underlying GraphicsWindow
// object. // object, if it is in fact a window; or NULL if it is
// not.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE GraphicsWindow *WindowFramework:: INLINE GraphicsWindow *WindowFramework::
get_graphics_window() const { get_graphics_window() const {
if (_window != (GraphicsOutput *)NULL &&
_window->is_of_type(GraphicsWindow::get_class_type())) {
return DCAST(GraphicsWindow, _window);
}
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: WindowFramework::get_graphics_output
// Access: Public
// Description: Returns a pointer to the underlying GraphicsOutput
// object
////////////////////////////////////////////////////////////////////
INLINE GraphicsOutput *WindowFramework::
get_graphics_output() const {
return _window; return _window;
} }

View File

@ -142,13 +142,13 @@ WindowFramework::
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: WindowFramework::open_window // Function: WindowFramework::open_window
// Access: Protected // Access: Protected
// Description: Opens the actual window. This is normally called // Description: Opens the actual window or buffer. This is normally
// only from PandaFramework::open_window(). // called only from PandaFramework::open_window().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
GraphicsWindow *WindowFramework:: GraphicsOutput *WindowFramework::
open_window(const WindowProperties &props, GraphicsEngine *engine, open_window(const WindowProperties &props, int flags, GraphicsEngine *engine,
GraphicsPipe *pipe, GraphicsStateGuardian *gsg) { GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
nassertr(_window == (GraphicsWindow *)NULL, _window); nassertr(_window == (GraphicsOutput *)NULL, _window);
static int next_window_index = 1; static int next_window_index = 1;
ostringstream stream; ostringstream stream;
@ -160,11 +160,10 @@ open_window(const WindowProperties &props, GraphicsEngine *engine,
GraphicsOutput *winout = GraphicsOutput *winout =
engine->make_output(pipe, name, 0, engine->make_output(pipe, name, 0,
FrameBufferProperties::get_default(), FrameBufferProperties::get_default(),
props, GraphicsPipe::BF_require_window, props, flags, gsg, NULL);
gsg, NULL);
if (winout != (GraphicsOutput *)NULL) { if (winout != (GraphicsOutput *)NULL) {
_window = DCAST(GraphicsWindow, winout); _window = winout;
_window->request_properties(props); // _window->request_properties(props);
// Create a display region that covers the entire window. // Create a display region that covers the entire window.
_display_region_3d = _window->make_display_region(); _display_region_3d = _window->make_display_region();
@ -193,7 +192,7 @@ open_window(const WindowProperties &props, GraphicsEngine *engine,
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: WindowFramework::close_window // Function: WindowFramework::close_window
// Access: Protected // Access: Protected
// Description: Closes the window. This is normally called // Description: Closes the window or buffer. This is normally called
// from PandaFramework::close_window(). // from PandaFramework::close_window().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void WindowFramework:: void WindowFramework::
@ -328,13 +327,12 @@ get_aspect_2d() {
// An aspect ratio of 0.0 means to try to infer it. // An aspect ratio of 0.0 means to try to infer it.
this_aspect_ratio = 1.0f; this_aspect_ratio = 1.0f;
WindowProperties properties = _window->get_properties(); if (_window->has_size()) {
if (!properties.has_size()) { int x_size = _window->get_x_size();
properties = _window->get_requested_properties(); int y_size = _window->get_y_size();
} if (y_size != 0) {
if (properties.has_size() && properties.get_y_size() != 0.0f) { this_aspect_ratio = (float)x_size / (float)y_size;
this_aspect_ratio = }
(float)properties.get_x_size() / (float)properties.get_y_size();
} }
} }
@ -382,7 +380,8 @@ enable_keyboard() {
return; return;
} }
if (_window->get_num_input_devices() > 0) { if (_window->is_of_type(GraphicsWindow::get_class_type()) &&
DCAST(GraphicsWindow, _window)->get_num_input_devices() > 0) {
NodePath mouse = get_mouse(); NodePath mouse = get_mouse();
// Create a button thrower to listen for our keyboard events and // Create a button thrower to listen for our keyboard events and
@ -412,7 +411,8 @@ setup_trackball() {
return; return;
} }
if (_window->get_num_input_devices() > 0) { if (_window->is_of_type(GraphicsWindow::get_class_type()) &&
DCAST(GraphicsWindow, _window)->get_num_input_devices() > 0) {
NodePath mouse = get_mouse(); NodePath mouse = get_mouse();
NodePath camera = get_camera_group(); NodePath camera = get_camera_group();
@ -1088,12 +1088,12 @@ make_camera() {
} else { } else {
// Otherwise, infer the aspect ratio from the window size. This // Otherwise, infer the aspect ratio from the window size. This
// does assume we have square pixels on our output device. // does assume we have square pixels on our output device.
WindowProperties properties = _window->get_properties(); if (_window->has_size()) {
if (!properties.has_size()) { int x_size = _window->get_x_size();
properties = _window->get_requested_properties(); int y_size = _window->get_y_size();
} if (y_size != 0) {
if (properties.has_size()) { lens->set_film_size(x_size, y_size);
lens->set_film_size(properties.get_x_size(), properties.get_y_size()); }
} }
} }

View File

@ -18,6 +18,7 @@
#include "pandabase.h" #include "pandabase.h"
#include "nodePath.h" #include "nodePath.h"
#include "camera.h" #include "camera.h"
#include "graphicsOutput.h"
#include "graphicsWindow.h" #include "graphicsWindow.h"
#include "animControlCollection.h" #include "animControlCollection.h"
#include "trackball.h" #include "trackball.h"
@ -27,7 +28,6 @@
#include "partGroup.h" #include "partGroup.h"
#include "pvector.h" #include "pvector.h"
#include "typedWritableReferenceCount.h" #include "typedWritableReferenceCount.h"
#include "graphicsWindow.h"
#include "loaderOptions.h" #include "loaderOptions.h"
#include "pgSliderBar.h" #include "pgSliderBar.h"
#include "textNode.h" #include "textNode.h"
@ -48,7 +48,7 @@ class DisplayRegion;
// display region within a window. (In the case where a // display region within a window. (In the case where a
// window has been subdivided with split_window(), there // window has been subdivided with split_window(), there
// may be multiple WindowFrameworks objects that share // may be multiple WindowFrameworks objects that share
// the same GraphicsWindow pointer, but reference // the same GraphicsOutput pointer, but reference
// different display regions within that window). // different display regions within that window).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_FRAMEWORK WindowFramework : public TypedWritableReferenceCount { class EXPCL_FRAMEWORK WindowFramework : public TypedWritableReferenceCount {
@ -60,7 +60,7 @@ public:
virtual ~WindowFramework(); virtual ~WindowFramework();
protected: protected:
GraphicsWindow *open_window(const WindowProperties &props, GraphicsOutput *open_window(const WindowProperties &props, int flags,
GraphicsEngine *engine, GraphicsPipe *pipe, GraphicsEngine *engine, GraphicsPipe *pipe,
GraphicsStateGuardian *gsg = NULL); GraphicsStateGuardian *gsg = NULL);
void close_window(); void close_window();
@ -68,6 +68,7 @@ protected:
public: public:
INLINE PandaFramework *get_panda_framework() const; INLINE PandaFramework *get_panda_framework() const;
INLINE GraphicsWindow *get_graphics_window() const; INLINE GraphicsWindow *get_graphics_window() const;
INLINE GraphicsOutput *get_graphics_output() const;
NodePath get_camera_group(); NodePath get_camera_group();
INLINE int get_num_cameras() const; INLINE int get_num_cameras() const;
@ -156,7 +157,7 @@ private:
private: private:
PandaFramework *_panda_framework; PandaFramework *_panda_framework;
PT(GraphicsWindow) _window; PT(GraphicsOutput) _window;
PT(DisplayRegion) _display_region_2d; PT(DisplayRegion) _display_region_2d;
PT(DisplayRegion) _display_region_3d; PT(DisplayRegion) _display_region_3d;

View File

@ -54,7 +54,7 @@ output_screenshot(Filename &fn)
framework.do_frame(current_thread); framework.do_frame(current_thread);
WindowFramework *wf = framework.get_window(0); WindowFramework *wf = framework.get_window(0);
bool ok = wf->get_graphics_window()->save_screenshot(fn, "from pview"); bool ok = wf->get_graphics_output()->save_screenshot(fn, "from pview");
if (!ok) { if (!ok) {
cerr << "Could not generate screenshot " << fn << "\n"; cerr << "Could not generate screenshot " << fn << "\n";
} }
@ -71,7 +71,7 @@ event_W(const Event *, void *) {
if (framework.get_num_windows() > 0) { if (framework.get_num_windows() > 0) {
WindowFramework *old_window = framework.get_window(0); WindowFramework *old_window = framework.get_window(0);
GraphicsWindow *win = old_window->get_graphics_window(); GraphicsOutput *win = old_window->get_graphics_output();
pipe = win->get_pipe(); pipe = win->get_pipe();
// gsg = win->get_gsg(); // gsg = win->get_gsg();
} }
@ -100,19 +100,23 @@ event_Enter(const Event *, void *) {
WindowProperties props; WindowProperties props;
if (framework.get_num_windows() > 0) { for (int i = 0; i < framework.get_num_windows(); ++i) {
WindowFramework *old_window = framework.get_window(0); WindowFramework *old_window = framework.get_window(i);
GraphicsWindow *win = old_window->get_graphics_window(); GraphicsWindow *win = old_window->get_graphics_window();
pipe = win->get_pipe(); if (win != (GraphicsWindow *)NULL) {
gsg = win->get_gsg(); pipe = win->get_pipe();
props = win->get_properties(); gsg = win->get_gsg();
framework.close_window(old_window); props = win->get_properties();
framework.close_window(old_window);
break;
}
} }
// set the toggle // set the toggle
props.set_fullscreen(!props.get_fullscreen()); props.set_fullscreen(!props.get_fullscreen());
int flags = GraphicsPipe::BF_require_window;
WindowFramework *window = framework.open_window(props, pipe, gsg); WindowFramework *window = framework.open_window(props, flags, pipe, gsg);
if (window != (WindowFramework *)NULL) { if (window != (WindowFramework *)NULL) {
window->enable_keyboard(); window->enable_keyboard();
window->setup_trackball(); window->setup_trackball();
@ -144,7 +148,7 @@ event_0(const Event *event, void *) {
DCAST_INTO_V(wf, param.get_ptr()); DCAST_INTO_V(wf, param.get_ptr());
// Create a new offscreen buffer. // Create a new offscreen buffer.
GraphicsWindow *win = wf->get_graphics_window(); GraphicsOutput *win = wf->get_graphics_output();
PT(GraphicsOutput) buffer = win->make_texture_buffer("tex", 256, 256); PT(GraphicsOutput) buffer = win->make_texture_buffer("tex", 256, 256);
cerr << buffer->get_type() << "\n"; cerr << buffer->get_type() << "\n";
@ -339,7 +343,7 @@ main(int argc, char *argv[]) {
window->loop_animations(hierarchy_match_flags); window->loop_animations(hierarchy_match_flags);
// Make sure the textures are preloaded. // Make sure the textures are preloaded.
framework.get_models().prepare_scene(window->get_graphics_window()->get_gsg()); framework.get_models().prepare_scene(window->get_graphics_output()->get_gsg());
loading_np.remove_node(); loading_np.remove_node();