From cfeff1fe3271aa801d3dc7b577e7a29f20ad1181 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 2 Mar 2005 00:35:10 +0000 Subject: [PATCH] fix flattenMultitex() twice in one frame --- panda/src/display/graphicsEngine.cxx | 10 ++++++- panda/src/display/graphicsEngine.h | 1 + panda/src/display/graphicsOutput.I | 2 +- panda/src/display/graphicsOutput.cxx | 35 +++++++++++++++++------ panda/src/display/graphicsOutput.h | 1 + panda/src/display/graphicsWindow.cxx | 11 ++++++++ panda/src/grutil/multitexReducer.cxx | 7 ++++- panda/src/putil/Sources.pp | 6 ++-- panda/src/putil/indirectCompareSort.I | 29 +++++++++++++++++++ panda/src/putil/indirectCompareSort.h | 40 +++++++++++++++++++++++++++ 10 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 panda/src/putil/indirectCompareSort.I create mode 100644 panda/src/putil/indirectCompareSort.h diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index a272ae44ba..dedfaf254f 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -71,6 +71,7 @@ GraphicsEngine(Pipeline *pipeline) : } _windows_sorted = true; + _window_sort_index = 0; // Default frame buffer properties. _frame_buffer_properties = FrameBufferProperties::get_default(); @@ -1174,6 +1175,13 @@ void GraphicsEngine:: do_add_window(GraphicsOutput *window, GraphicsStateGuardian *gsg, const GraphicsThreadingModel &threading_model) { 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.push_back(window); @@ -1464,7 +1472,7 @@ resort_windows() { for (wi = _window.begin(); wi != _window.end(); ++wi) { GraphicsOutput *win = (*wi); display_cat.debug(false) - << " " << (void *)win; + << " " << win->get_name() << "(" << win->get_sort() << ")"; } display_cat.debug(false) << "\n"; diff --git a/panda/src/display/graphicsEngine.h b/panda/src/display/graphicsEngine.h index 77ab0a9a96..db9dce3810 100644 --- a/panda/src/display/graphicsEngine.h +++ b/panda/src/display/graphicsEngine.h @@ -226,6 +226,7 @@ private: Pipeline *_pipeline; Windows _windows; bool _windows_sorted; + unsigned int _window_sort_index; WindowRenderer _app; typedef pmap Threads; diff --git a/panda/src/display/graphicsOutput.I b/panda/src/display/graphicsOutput.I index 7c082d5c4f..4cb09607f7 100644 --- a/panda/src/display/graphicsOutput.I +++ b/panda/src/display/graphicsOutput.I @@ -340,7 +340,7 @@ operator < (const GraphicsOutput &other) const { if (_sort != other._sort) { return _sort < other._sort; } - return this < &other; + return _internal_sort_index < other._internal_sort_index; } diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index e02a7c14bc..2b4b3202d0 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -57,6 +57,7 @@ GraphicsOutput(GraphicsPipe *pipe, GraphicsStateGuardian *gsg, _flip_ready = false; _needs_context = true; _sort = 0; + _internal_sort_index = 0; _active = true; _one_shot = false; _inverted = window_inverted; @@ -204,12 +205,12 @@ setup_render_texture() { _texture->set_wrapu(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; _render_texture = false; @@ -585,6 +586,12 @@ reset_window(bool swapchain) { //////////////////////////////////////////////////////////////////// bool GraphicsOutput:: begin_frame() { + if (display_cat.is_spam()) { + display_cat.spam() + << "begin_frame(): " << get_type() << " " + << get_name() << " " << (void *)this << "\n"; + } + if (_gsg == (GraphicsStateGuardian *)NULL) { return false; } @@ -619,6 +626,12 @@ begin_frame() { void GraphicsOutput:: clear() { 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); DisplayRegionStack old_dr = _gsg->push_display_region(_default_display_region); @@ -636,6 +649,12 @@ clear() { //////////////////////////////////////////////////////////////////// void GraphicsOutput:: end_frame() { + if (display_cat.is_spam()) { + display_cat.spam() + << "end_frame(): " << get_type() << " " + << get_name() << " " << (void *)this << "\n"; + } + nassertv(_gsg != (GraphicsStateGuardian *)NULL); _gsg->end_frame(); @@ -652,7 +671,7 @@ end_frame() { if (_render_texture) { if (display_cat.is_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())) { display_cat.warning() @@ -664,7 +683,7 @@ end_frame() { if (!_render_texture) { if (display_cat.is_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()); _gsg->copy_texture(get_texture(), _default_display_region, buffer); diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index 4b68d67327..51ea28e5f6 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -170,6 +170,7 @@ private: void do_determine_display_regions(); int _sort; + unsigned int _internal_sort_index; protected: bool _active; diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index 463533b2ad..1d94997747 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -147,6 +147,17 @@ void GraphicsWindow:: request_properties(const WindowProperties &requested_properties) { MutexHolder holder(_properties_lock); _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. + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/grutil/multitexReducer.cxx b/panda/src/grutil/multitexReducer.cxx index 4bf9c5fd3e..c6a8f2b5dc 100644 --- a/panda/src/grutil/multitexReducer.cxx +++ b/panda/src/grutil/multitexReducer.cxx @@ -258,8 +258,13 @@ flatten(GraphicsOutput *window) { choose_texture_size(x_size, y_size, model_stage, uv_scale, window); + static int multitex_id = 1; + ostringstream multitex_name_strm; + multitex_name_strm << "multitex" << multitex_id; + multitex_id++; + 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); Texture *tex = buffer->get_texture(); tex->set_anisotropic_degree(aniso_degree); diff --git a/panda/src/putil/Sources.pp b/panda/src/putil/Sources.pp index 82ee7cfd2c..7ee19ce04d 100644 --- a/panda/src/putil/Sources.pp +++ b/panda/src/putil/Sources.pp @@ -31,6 +31,7 @@ firstOfPairLess.I firstOfPairLess.h \ globalPointerRegistry.I globalPointerRegistry.h \ indirectCompareNames.I indirectCompareNames.h \ + indirectCompareSort.I indirectCompareSort.h \ indirectCompareTo.I indirectCompareTo.h \ ioPtaDatagramFloat.h ioPtaDatagramInt.h \ ioPtaDatagramShort.h keyboardButton.h lineStream.I \ @@ -103,8 +104,9 @@ firstOfPairCompare.I firstOfPairCompare.h \ firstOfPairLess.I firstOfPairLess.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 \ ioPtaDatagramShort.h iterator_types.h keyboardButton.h lineStream.I \ lineStream.h lineStreamBuf.I lineStreamBuf.h \ diff --git a/panda/src/putil/indirectCompareSort.I b/panda/src/putil/indirectCompareSort.I new file mode 100644 index 0000000000..f5252338cf --- /dev/null +++ b/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 +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: IndirectCompareSort::operator () +// Access: Public +// Description: Returns true if a sorts before b, false otherwise. +//////////////////////////////////////////////////////////////////// +template +INLINE bool IndirectCompareSort:: +operator () (const ObjectType *a, const ObjectType *b) const { + return (a->get_sort() < b->get_sort()); +} diff --git a/panda/src/putil/indirectCompareSort.h b/panda/src/putil/indirectCompareSort.h new file mode 100644 index 0000000000..7616d4a1dc --- /dev/null +++ b/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 +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#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 IndirectCompareSort { +public: + INLINE bool operator () (const ObjectType *a, const ObjectType *b) const; +}; + +#include "indirectCompareSort.I" + +#endif +