Browse Source

fix flattenMultitex() twice in one frame

David Rose 21 years ago
parent
commit
cfeff1fe32

+ 9 - 1
panda/src/display/graphicsEngine.cxx

@@ -71,6 +71,7 @@ GraphicsEngine(Pipeline *pipeline) :
   }
   }
 
 
   _windows_sorted = true;
   _windows_sorted = true;
+  _window_sort_index = 0;
 
 
   // Default frame buffer properties.
   // Default frame buffer properties.
   _frame_buffer_properties = FrameBufferProperties::get_default();
   _frame_buffer_properties = FrameBufferProperties::get_default();
@@ -1174,6 +1175,13 @@ void GraphicsEngine::
 do_add_window(GraphicsOutput *window, GraphicsStateGuardian *gsg,
 do_add_window(GraphicsOutput *window, GraphicsStateGuardian *gsg,
               const GraphicsThreadingModel &threading_model) {
               const GraphicsThreadingModel &threading_model) {
   MutexHolder holder(_lock);
   MutexHolder holder(_lock);
+
+  // We have a special counter that is unique per window that allows
+  // us to assure that recently-added windows end up on the end of the
+  // list.
+  window->_internal_sort_index = _window_sort_index;
+  _window_sort_index++;
+
   _windows_sorted = false;
   _windows_sorted = false;
   _windows.push_back(window);
   _windows.push_back(window);
   
   
@@ -1464,7 +1472,7 @@ resort_windows() {
     for (wi = _window.begin(); wi != _window.end(); ++wi) {
     for (wi = _window.begin(); wi != _window.end(); ++wi) {
       GraphicsOutput *win = (*wi);
       GraphicsOutput *win = (*wi);
       display_cat.debug(false)
       display_cat.debug(false)
-        << " " << (void *)win;
+        << " " << win->get_name() << "(" << win->get_sort() << ")";
     }
     }
     display_cat.debug(false)
     display_cat.debug(false)
       << "\n";
       << "\n";

+ 1 - 0
panda/src/display/graphicsEngine.h

@@ -226,6 +226,7 @@ private:
   Pipeline *_pipeline;
   Pipeline *_pipeline;
   Windows _windows;
   Windows _windows;
   bool _windows_sorted;
   bool _windows_sorted;
+  unsigned int _window_sort_index;
 
 
   WindowRenderer _app;
   WindowRenderer _app;
   typedef pmap<string, PT(RenderThread) > Threads;
   typedef pmap<string, PT(RenderThread) > Threads;

+ 1 - 1
panda/src/display/graphicsOutput.I

@@ -340,7 +340,7 @@ operator < (const GraphicsOutput &other) const {
   if (_sort != other._sort) {
   if (_sort != other._sort) {
     return _sort < other._sort;
     return _sort < other._sort;
   }
   }
-  return this < &other;
+  return _internal_sort_index < other._internal_sort_index;
 }
 }
 
 
 
 

+ 27 - 8
panda/src/display/graphicsOutput.cxx

@@ -57,6 +57,7 @@ GraphicsOutput(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
   _flip_ready = false;
   _flip_ready = false;
   _needs_context = true;
   _needs_context = true;
   _sort = 0;
   _sort = 0;
+  _internal_sort_index = 0;
   _active = true;
   _active = true;
   _one_shot = false;
   _one_shot = false;
   _inverted = window_inverted;
   _inverted = window_inverted;
@@ -204,12 +205,12 @@ setup_render_texture() {
   _texture->set_wrapu(Texture::WM_clamp);
   _texture->set_wrapu(Texture::WM_clamp);
   _texture->set_wrapv(Texture::WM_clamp);
   _texture->set_wrapv(Texture::WM_clamp);
 
 
-  if (has_size()) {
-    // If we know our size now, go ahead and tell the texture.
-    PixelBuffer *pb = _texture->_pbuffer;
-    pb->set_xsize(get_x_size());
-    pb->set_ysize(get_y_size());
-  }
+  // Go ahead and tell the texture our anticipated size, even if it
+  // might be inaccurate (particularly if this is a GraphicsWindow,
+  // which has system-imposed restrictions on size).
+  PixelBuffer *pb = _texture->_pbuffer;
+  pb->set_xsize(get_x_size());
+  pb->set_ysize(get_y_size());
 
 
   _copy_texture = true;
   _copy_texture = true;
   _render_texture = false;
   _render_texture = false;
@@ -585,6 +586,12 @@ reset_window(bool swapchain) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool GraphicsOutput::
 bool GraphicsOutput::
 begin_frame() {
 begin_frame() {
+  if (display_cat.is_spam()) {
+    display_cat.spam()
+      << "begin_frame(): " << get_type() << " " 
+      << get_name() << " " << (void *)this << "\n";
+  }
+
   if (_gsg == (GraphicsStateGuardian *)NULL) {
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
     return false;
   }
   }
@@ -619,6 +626,12 @@ begin_frame() {
 void GraphicsOutput::
 void GraphicsOutput::
 clear() {
 clear() {
   if (is_any_clear_active()) {
   if (is_any_clear_active()) {
+    if (display_cat.is_spam()) {
+      display_cat.spam()
+        << "clear(): " << get_type() << " " 
+        << get_name() << " " << (void *)this << "\n";
+    }
+
     nassertv(_gsg != (GraphicsStateGuardian *)NULL);
     nassertv(_gsg != (GraphicsStateGuardian *)NULL);
 
 
     DisplayRegionStack old_dr = _gsg->push_display_region(_default_display_region);
     DisplayRegionStack old_dr = _gsg->push_display_region(_default_display_region);
@@ -636,6 +649,12 @@ clear() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void GraphicsOutput::
 void GraphicsOutput::
 end_frame() {
 end_frame() {
+  if (display_cat.is_spam()) {
+    display_cat.spam()
+      << "end_frame(): " << get_type() << " " 
+      << get_name() << " " << (void *)this << "\n";
+  }
+
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
   _gsg->end_frame();
   _gsg->end_frame();
 
 
@@ -652,7 +671,7 @@ end_frame() {
     if (_render_texture) {
     if (_render_texture) {
       if (display_cat.is_debug()) {
       if (display_cat.is_debug()) {
         display_cat.debug()
         display_cat.debug()
-          << "Locking texture for " << (void *)this << " at frame end.\n";
+          << "Locking texture for " << get_name() << " at frame end.\n";
       }
       }
       if (!_gsg->framebuffer_bind_to_texture(this, get_texture())) {
       if (!_gsg->framebuffer_bind_to_texture(this, get_texture())) {
         display_cat.warning()
         display_cat.warning()
@@ -664,7 +683,7 @@ end_frame() {
     if (!_render_texture) {
     if (!_render_texture) {
       if (display_cat.is_debug()) {
       if (display_cat.is_debug()) {
         display_cat.debug()
         display_cat.debug()
-          << "Copying texture for " << (void *)this << " at frame end.\n";
+          << "Copying texture for " << get_name() << " at frame end.\n";
       }
       }
       RenderBuffer buffer = _gsg->get_render_buffer(get_draw_buffer_type());
       RenderBuffer buffer = _gsg->get_render_buffer(get_draw_buffer_type());
       _gsg->copy_texture(get_texture(), _default_display_region, buffer);
       _gsg->copy_texture(get_texture(), _default_display_region, buffer);

+ 1 - 0
panda/src/display/graphicsOutput.h

@@ -170,6 +170,7 @@ private:
   void do_determine_display_regions();
   void do_determine_display_regions();
 
 
   int _sort;
   int _sort;
+  unsigned int _internal_sort_index;
 
 
 protected:
 protected:
   bool _active;
   bool _active;

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

@@ -147,6 +147,17 @@ void GraphicsWindow::
 request_properties(const WindowProperties &requested_properties) {
 request_properties(const WindowProperties &requested_properties) {
   MutexHolder holder(_properties_lock);
   MutexHolder holder(_properties_lock);
   _requested_properties.add_properties(requested_properties);
   _requested_properties.add_properties(requested_properties);
+
+  if (!_has_size && _requested_properties.has_size()) {
+    // If we just requested a particular size, anticipate that it will
+    // stick.  This is helpful for the MultitexReducer, which needs to
+    // know the size of the textures that it will be working with,
+    // even if the texture hasn't been fully generated yet.
+    _x_size = _requested_properties.get_x_size();
+    _y_size = _requested_properties.get_y_size();
+
+    // Don't set _has_size yet, because we don't really know yet.
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 6 - 1
panda/src/grutil/multitexReducer.cxx

@@ -258,8 +258,13 @@ flatten(GraphicsOutput *window) {
     choose_texture_size(x_size, y_size, model_stage, uv_scale,
     choose_texture_size(x_size, y_size, model_stage, uv_scale,
                         window);
                         window);
 
 
+    static int multitex_id = 1;
+    ostringstream multitex_name_strm;
+    multitex_name_strm << "multitex" << multitex_id;
+    multitex_id++;
+
     GraphicsOutput *buffer = 
     GraphicsOutput *buffer = 
-      window->make_texture_buffer("multitex", x_size, y_size);
+      window->make_texture_buffer(multitex_name_strm.str(), x_size, y_size);
     buffer->set_one_shot(true);
     buffer->set_one_shot(true);
     Texture *tex = buffer->get_texture();
     Texture *tex = buffer->get_texture();
     tex->set_anisotropic_degree(aniso_degree);
     tex->set_anisotropic_degree(aniso_degree);

+ 4 - 2
panda/src/putil/Sources.pp

@@ -31,6 +31,7 @@
     firstOfPairLess.I firstOfPairLess.h \
     firstOfPairLess.I firstOfPairLess.h \
     globalPointerRegistry.I globalPointerRegistry.h \
     globalPointerRegistry.I globalPointerRegistry.h \
     indirectCompareNames.I indirectCompareNames.h \
     indirectCompareNames.I indirectCompareNames.h \
+    indirectCompareSort.I indirectCompareSort.h \
     indirectCompareTo.I indirectCompareTo.h \
     indirectCompareTo.I indirectCompareTo.h \
     ioPtaDatagramFloat.h ioPtaDatagramInt.h \
     ioPtaDatagramFloat.h ioPtaDatagramInt.h \
     ioPtaDatagramShort.h keyboardButton.h lineStream.I \
     ioPtaDatagramShort.h keyboardButton.h lineStream.I \
@@ -103,8 +104,9 @@
     firstOfPairCompare.I firstOfPairCompare.h \
     firstOfPairCompare.I firstOfPairCompare.h \
     firstOfPairLess.I firstOfPairLess.h \
     firstOfPairLess.I firstOfPairLess.h \
     globalPointerRegistry.I globalPointerRegistry.h \
     globalPointerRegistry.I globalPointerRegistry.h \
-    indirectCompareNames.I indirectCompareNames.h indirectCompareTo.I \
-    indirectCompareTo.h \
+    indirectCompareNames.I indirectCompareNames.h \
+    indirectCompareSort.I indirectCompareSort.h \
+    indirectCompareTo.I indirectCompareTo.h \
     ioPtaDatagramFloat.h ioPtaDatagramInt.h \
     ioPtaDatagramFloat.h ioPtaDatagramInt.h \
     ioPtaDatagramShort.h iterator_types.h keyboardButton.h lineStream.I \
     ioPtaDatagramShort.h iterator_types.h keyboardButton.h lineStream.I \
     lineStream.h lineStreamBuf.I lineStreamBuf.h \
     lineStream.h lineStreamBuf.I lineStreamBuf.h \

+ 29 - 0
panda/src/putil/indirectCompareSort.I

@@ -0,0 +1,29 @@
+// Filename: indirectCompareSort.I
+// Created by:  drose (01Mar05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: IndirectCompareSort::operator ()
+//       Access: Public
+//  Description: Returns true if a sorts before b, false otherwise.
+////////////////////////////////////////////////////////////////////
+template<class ObjectType>
+INLINE bool IndirectCompareSort<ObjectType>::
+operator () (const ObjectType *a, const ObjectType *b) const {
+  return (a->get_sort() < b->get_sort());
+}

+ 40 - 0
panda/src/putil/indirectCompareSort.h

@@ -0,0 +1,40 @@
+// Filename: indirectCompareSort.h
+// Created by:  drose (01Mar05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef INDIRECTCOMPARESORT_H
+#define INDIRECTCOMPARESORT_H
+
+#include "pandabase.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : IndirectCompareSort
+// Description : An STL function object class, this is intended to be
+//               used on any ordered collection of pointers to classes
+//               that define a get_sort() method.  It defines the
+//               order of the pointers by sort comparison.
+////////////////////////////////////////////////////////////////////
+template<class ObjectType>
+class IndirectCompareSort {
+public:
+  INLINE bool operator () (const ObjectType *a, const ObjectType *b) const;
+};
+
+#include "indirectCompareSort.I"
+
+#endif
+