2
0
Эх сурвалжийг харах

shift-W in pview opens new window on same gsg

David Rose 22 жил өмнө
parent
commit
e51dfb192f

+ 5 - 0
panda/src/display/graphicsWindow.cxx

@@ -44,6 +44,11 @@ GraphicsWindow(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
   _pipe = pipe;
   _pipe = pipe;
   _gsg = gsg;
   _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.
   // Some default properties for windows unless specified otherwise.
   // Other properties (size, title, etc.) must be explicitly
   // Other properties (size, title, etc.) must be explicitly
   // specified.
   // specified.

+ 5 - 4
panda/src/framework/pandaFramework.cxx

@@ -166,13 +166,13 @@ get_default_window_props(WindowProperties &props) {
 //               NULL if not.
 //               NULL if not.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 WindowFramework *PandaFramework::
 WindowFramework *PandaFramework::
-open_window(GraphicsPipe *pipe) {
+open_window(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
   nassertr(_is_open, NULL);
   nassertr(_is_open, NULL);
 
 
   WindowProperties props;
   WindowProperties props;
   get_default_window_props(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.
 //               NULL if not.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 WindowFramework *PandaFramework::
 WindowFramework *PandaFramework::
-open_window(const WindowProperties &props, GraphicsPipe *pipe) {
+open_window(const WindowProperties &props, 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) {
@@ -203,7 +204,7 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe) {
   wf->set_lighting(get_lighting());
   wf->set_lighting(get_lighting());
   wf->set_background_type(get_background_type());
   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) {
   if (win == (GraphicsWindow *)NULL) {
     // Oops, couldn't make an actual window.
     // Oops, couldn't make an actual window.
     delete wf;
     delete wf;

+ 4 - 2
panda/src/framework/pandaFramework.h

@@ -54,9 +54,11 @@ public:
   INLINE void set_window_title(const string &title);
   INLINE void set_window_title(const string &title);
   virtual void get_default_window_props(WindowProperties &props);
   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,
   WindowFramework *open_window(const WindowProperties &props,
-			       GraphicsPipe *pipe = NULL);
+			       GraphicsPipe *pipe = 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;

+ 13 - 7
panda/src/framework/windowFramework.cxx

@@ -94,17 +94,23 @@ WindowFramework::
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 GraphicsWindow *WindowFramework::
 GraphicsWindow *WindowFramework::
 open_window(const WindowProperties &props, GraphicsEngine *engine,
 open_window(const WindowProperties &props, GraphicsEngine *engine,
-            GraphicsPipe *pipe) {
+            GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
   nassertr(_window == (GraphicsWindow *)NULL, _window);
   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) {
   if (_window != (GraphicsWindow *)NULL) {
     _window->request_properties(props);
     _window->request_properties(props);
     set_background_type(_background_type);
     set_background_type(_background_type);

+ 2 - 1
panda/src/framework/windowFramework.h

@@ -49,7 +49,8 @@ public:
 
 
 protected:
 protected:
   GraphicsWindow *open_window(const WindowProperties &props,
   GraphicsWindow *open_window(const WindowProperties &props,
-                              GraphicsEngine *engine, GraphicsPipe *pipe);
+                              GraphicsEngine *engine, GraphicsPipe *pipe,
+                              GraphicsStateGuardian *gsg = NULL);
   void close_window();
   void close_window();
 
 
 public:
 public:

+ 7 - 0
panda/src/pgraph/pandaNode.cxx

@@ -1066,6 +1066,13 @@ stash_child(int child_index) {
 void PandaNode::
 void PandaNode::
 unstash_child(int stashed_index) {
 unstash_child(int stashed_index) {
   nassertv(stashed_index >= 0 && stashed_index < get_num_stashed());
   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);
   PT(PandaNode) child_node = get_stashed(stashed_index);
   int sort = get_stashed_sort(stashed_index);
   int sort = get_stashed_sort(stashed_index);
   
   

+ 13 - 1
panda/src/testbed/pview.cxx

@@ -23,7 +23,19 @@ PandaFramework framework;
 void
 void
 event_W(CPT_Event, void *) {
 event_W(CPT_Event, void *) {
   // shift-W: open a new window on the same scene.
   // 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) {
   if (window != (WindowFramework *)NULL) {
     window->enable_keyboard();
     window->enable_keyboard();
     window->setup_trackball();
     window->setup_trackball();