From e51dfb192f08cfe7fa12f3e7c832595d0a52400f Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 17 Jul 2003 18:17:24 +0000 Subject: [PATCH] shift-W in pview opens new window on same gsg --- panda/src/display/graphicsWindow.cxx | 5 +++++ panda/src/framework/pandaFramework.cxx | 9 +++++---- panda/src/framework/pandaFramework.h | 6 ++++-- panda/src/framework/windowFramework.cxx | 20 +++++++++++++------- panda/src/framework/windowFramework.h | 3 ++- panda/src/pgraph/pandaNode.cxx | 7 +++++++ panda/src/testbed/pview.cxx | 14 +++++++++++++- 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index 656f274f20..bc8fe6b192 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -44,6 +44,11 @@ GraphicsWindow(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) { _pipe = pipe; _gsg = gsg; + if (display_cat.is_debug()) { + display_cat.debug() + << "Creating new window using GSG " << (void *)gsg << "\n"; + } + // Some default properties for windows unless specified otherwise. // Other properties (size, title, etc.) must be explicitly // specified. diff --git a/panda/src/framework/pandaFramework.cxx b/panda/src/framework/pandaFramework.cxx index 71c4a7558f..413064a9c5 100644 --- a/panda/src/framework/pandaFramework.cxx +++ b/panda/src/framework/pandaFramework.cxx @@ -166,13 +166,13 @@ get_default_window_props(WindowProperties &props) { // NULL if not. //////////////////////////////////////////////////////////////////// WindowFramework *PandaFramework:: -open_window(GraphicsPipe *pipe) { +open_window(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) { nassertr(_is_open, NULL); WindowProperties props; get_default_window_props(props); - return open_window(props, pipe); + return open_window(props, pipe, gsg); } //////////////////////////////////////////////////////////////////// @@ -186,7 +186,8 @@ open_window(GraphicsPipe *pipe) { // NULL if not. //////////////////////////////////////////////////////////////////// WindowFramework *PandaFramework:: -open_window(const WindowProperties &props, GraphicsPipe *pipe) { +open_window(const WindowProperties &props, GraphicsPipe *pipe, + GraphicsStateGuardian *gsg) { if (pipe == (GraphicsPipe *)NULL) { pipe = get_default_pipe(); if (pipe == (GraphicsPipe *)NULL) { @@ -203,7 +204,7 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe) { wf->set_lighting(get_lighting()); wf->set_background_type(get_background_type()); - GraphicsWindow *win = wf->open_window(props, &_engine, pipe); + GraphicsWindow *win = wf->open_window(props, &_engine, pipe, gsg); if (win == (GraphicsWindow *)NULL) { // Oops, couldn't make an actual window. delete wf; diff --git a/panda/src/framework/pandaFramework.h b/panda/src/framework/pandaFramework.h index c5a6df2b1d..47383b4aa7 100644 --- a/panda/src/framework/pandaFramework.h +++ b/panda/src/framework/pandaFramework.h @@ -54,9 +54,11 @@ public: INLINE void set_window_title(const string &title); virtual void get_default_window_props(WindowProperties &props); - WindowFramework *open_window(GraphicsPipe *pipe = NULL); + WindowFramework *open_window(GraphicsPipe *pipe = NULL, + GraphicsStateGuardian *gsg = NULL); WindowFramework *open_window(const WindowProperties &props, - GraphicsPipe *pipe = NULL); + GraphicsPipe *pipe = NULL, + GraphicsStateGuardian *gsg = NULL); INLINE int get_num_windows() const; INLINE WindowFramework *get_window(int n) const; diff --git a/panda/src/framework/windowFramework.cxx b/panda/src/framework/windowFramework.cxx index 5256a089e3..d1530f98cd 100644 --- a/panda/src/framework/windowFramework.cxx +++ b/panda/src/framework/windowFramework.cxx @@ -94,17 +94,23 @@ WindowFramework:: //////////////////////////////////////////////////////////////////// GraphicsWindow *WindowFramework:: open_window(const WindowProperties &props, GraphicsEngine *engine, - GraphicsPipe *pipe) { + GraphicsPipe *pipe, GraphicsStateGuardian *gsg) { nassertr(_window == (GraphicsWindow *)NULL, _window); - PT(GraphicsStateGuardian) gsg = engine->make_gsg(pipe); - if (gsg == (GraphicsStateGuardian *)NULL) { - // No GSG, no window. - framework_cat.fatal() << "open_window: failed to create gsg object!\n"; - return NULL; + PT(GraphicsStateGuardian) ptgsg = gsg; + + // If we were not given a gsg in the arguments, create a new one + // just for this window. + if (ptgsg == (GraphicsStateGuardian *)NULL) { + ptgsg = engine->make_gsg(pipe); + if (ptgsg == (GraphicsStateGuardian *)NULL) { + // No GSG, no window. + framework_cat.fatal() << "open_window: failed to create gsg object!\n"; + return NULL; + } } - _window = engine->make_window(pipe, gsg); + _window = engine->make_window(pipe, ptgsg); if (_window != (GraphicsWindow *)NULL) { _window->request_properties(props); set_background_type(_background_type); diff --git a/panda/src/framework/windowFramework.h b/panda/src/framework/windowFramework.h index a16edccbf4..98fb7b479f 100644 --- a/panda/src/framework/windowFramework.h +++ b/panda/src/framework/windowFramework.h @@ -49,7 +49,8 @@ public: protected: GraphicsWindow *open_window(const WindowProperties &props, - GraphicsEngine *engine, GraphicsPipe *pipe); + GraphicsEngine *engine, GraphicsPipe *pipe, + GraphicsStateGuardian *gsg = NULL); void close_window(); public: diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index ece30980a4..0a486612be 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -1066,6 +1066,13 @@ stash_child(int child_index) { void PandaNode:: unstash_child(int stashed_index) { nassertv(stashed_index >= 0 && stashed_index < get_num_stashed()); + + // Save a reference count for ourselves. I don't think this should + // be necessary, but there are occasional crashes in stash() during + // furniture moving mode. Perhaps this will eliminate those + // crashes. + PT(PandaNode) self = this; + PT(PandaNode) child_node = get_stashed(stashed_index); int sort = get_stashed_sort(stashed_index); diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index 5f833a9ff9..76071a34c4 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -23,7 +23,19 @@ PandaFramework framework; void event_W(CPT_Event, void *) { // shift-W: open a new window on the same scene. - WindowFramework *window = framework.open_window(); + + // If we already have a window, use the same GSG. + GraphicsPipe *pipe = (GraphicsPipe *)NULL; + GraphicsStateGuardian *gsg = (GraphicsStateGuardian *)NULL; + + if (framework.get_num_windows() > 0) { + WindowFramework *old_window = framework.get_window(0); + GraphicsWindow *win = old_window->get_graphics_window(); + pipe = win->get_pipe(); + gsg = win->get_gsg(); + } + + WindowFramework *window = framework.open_window(pipe, gsg); if (window != (WindowFramework *)NULL) { window->enable_keyboard(); window->setup_trackball();