From a52a3be557dd12741eddffc3ca30dcb81b3f3786 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 11 Jul 2002 21:03:56 +0000 Subject: [PATCH] move clear() to DisplayRegion and GraphicsWindow objects instead of on GSG --- panda/src/display/Sources.pp | 9 +- panda/src/display/clearableRegion.I | 198 ++++++++++++++++++ panda/src/display/clearableRegion.cxx | 19 ++ panda/src/display/clearableRegion.h | 68 ++++++ panda/src/display/displayRegion.h | 3 +- panda/src/display/display_composite1.cxx | 2 +- panda/src/display/display_composite2.cxx | 1 - panda/src/display/graphicsEngine.cxx | 6 + panda/src/display/graphicsStateGuardian.I | 18 ++ panda/src/display/graphicsStateGuardian.cxx | 122 ++++------- panda/src/display/graphicsStateGuardian.h | 29 +-- panda/src/display/graphicsWindow.cxx | 36 +++- panda/src/display/graphicsWindow.h | 29 ++- panda/src/distort/nonlinearImager.cxx | 4 - panda/src/dxgsg/dxGraphicsStateGuardian.cxx | 18 +- panda/src/dxgsg/dxGraphicsStateGuardian.h | 3 +- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 18 +- panda/src/dxgsg8/dxGraphicsStateGuardian8.h | 3 +- panda/src/glgsg/glGraphicsStateGuardian.cxx | 16 +- panda/src/glgsg/glGraphicsStateGuardian.h | 3 +- 20 files changed, 416 insertions(+), 189 deletions(-) create mode 100644 panda/src/display/clearableRegion.I create mode 100644 panda/src/display/clearableRegion.cxx create mode 100644 panda/src/display/clearableRegion.h diff --git a/panda/src/display/Sources.pp b/panda/src/display/Sources.pp index 54dd8a630a..3185f2a7bd 100644 --- a/panda/src/display/Sources.pp +++ b/panda/src/display/Sources.pp @@ -10,7 +10,9 @@ #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - config_display.h displayRegion.I displayRegion.h \ + config_display.h \ + clearableRegion.I clearableRegion.h \ + displayRegion.I displayRegion.h \ displayRegionStack.I \ displayRegionStack.h \ frameBufferStack.I frameBufferStack.h \ @@ -31,7 +33,9 @@ savedFrameBuffer.I savedFrameBuffer.h #define INCLUDED_SOURCES \ - config_display.cxx displayRegion.cxx \ + config_display.cxx \ + clearableRegion.cxx \ + displayRegion.cxx \ geomContext.cxx geomNodeContext.cxx graphicsChannel.cxx \ graphicsEngine.cxx \ graphicsLayer.cxx graphicsPipe.cxx graphicsStateGuardian.cxx \ @@ -42,6 +46,7 @@ #define INSTALL_HEADERS \ config_display.h \ + clearableRegion.I clearableRegion.h \ displayRegion.I displayRegion.h displayRegionStack.I \ displayRegionStack.h \ frameBufferStack.I frameBufferStack.h \ diff --git a/panda/src/display/clearableRegion.I b/panda/src/display/clearableRegion.I new file mode 100644 index 0000000000..7510b35916 --- /dev/null +++ b/panda/src/display/clearableRegion.I @@ -0,0 +1,198 @@ +// Filename: clearableRegion.I +// Created by: drose (11Jul02) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, 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://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ClearableRegion:: +ClearableRegion() : + _flags(0), + _clear_color(0.0f, 0.0f, 0.0f, 0.0f), + _clear_depth(1.0f) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ClearableRegion:: +ClearableRegion(const ClearableRegion ©) : + _flags(copy._flags), + _clear_color(copy._clear_color), + _clear_depth(copy._clear_depth) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::Copy Assignment Operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void ClearableRegion:: +operator = (const ClearableRegion ©) { + _flags = copy._flags; + _clear_color = copy._clear_color; + _clear_depth = copy._clear_depth; +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::copy_clear_settings +// Access: Public +// Description: A convenience function that does the same thing as +// the assignment operator; this is just syntactically a +// little nicer (and a little clearer) to call from a +// derived class. +//////////////////////////////////////////////////////////////////// +INLINE void ClearableRegion:: +copy_clear_settings(const ClearableRegion ©) { + operator = (copy); +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::set_clear_color_active +// Access: Published +// Description: Toggles the flag that indicates whether the color +// buffer should be cleared every frame. If this is +// true, the color buffer will be cleared to the color +// indicated by set_clear_color(); otherwise, it will be +// left alone. +//////////////////////////////////////////////////////////////////// +INLINE void ClearableRegion:: +set_clear_color_active(bool clear_color_active) { + if (clear_color_active) { + _flags |= F_clear_color_active; + } else { + _flags &= ~F_clear_color_active; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::get_clear_color_active +// Access: Published +// Description: Returns the current setting of the flag that +// indicates whether the color buffer should be cleared +// every frame. See set_clear_color_active(). +//////////////////////////////////////////////////////////////////// +INLINE bool ClearableRegion:: +get_clear_color_active() const { + return ((_flags & F_clear_color_active) != 0); +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::set_clear_depth_active +// Access: Published +// Description: Toggles the flag that indicates whether the depth +// buffer should be cleared every frame. If this is +// true, the depth buffer will be cleared to the depth +// value indicated by set_clear_depth(); otherwise, it +// will be left alone. +//////////////////////////////////////////////////////////////////// +INLINE void ClearableRegion:: +set_clear_depth_active(bool clear_depth_active) { + if (clear_depth_active) { + _flags |= F_clear_depth_active; + } else { + _flags &= ~F_clear_depth_active; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::get_clear_depth_active +// Access: Published +// Description: Returns the current setting of the flag that +// indicates whether the depth buffer should be cleared +// every frame. See set_clear_depth_active(). +//////////////////////////////////////////////////////////////////// +INLINE bool ClearableRegion:: +get_clear_depth_active() const { + return ((_flags & F_clear_depth_active) != 0); +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::set_clear_color +// Access: Published +// Description: Sets the clear color to the indicated value. This is +// the value that will be used to clear the color buffer +// every frame, but only if get_clear_color_active() +// returns true. If get_clear_color_active() returns +// false, this is meaningless. +//////////////////////////////////////////////////////////////////// +INLINE void ClearableRegion:: +set_clear_color(const Colorf &color) { + _clear_color = color; +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::get_clear_color +// Access: Published +// Description: Returns the current clear color value. This is +// the value that will be used to clear the color buffer +// every frame, but only if get_clear_color_active() +// returns true. If get_clear_color_active() returns +// false, this is meaningless. +//////////////////////////////////////////////////////////////////// +INLINE const Colorf &ClearableRegion:: +get_clear_color() const { + return _clear_color; +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::set_clear_depth +// Access: Published +// Description: Sets the clear depth to the indicated value. This is +// the value that will be used to clear the depth buffer +// every frame, but only if get_clear_depth_active() +// returns true. If get_clear_depth_active() returns +// false, this is meaningless. +//////////////////////////////////////////////////////////////////// +INLINE void ClearableRegion:: +set_clear_depth(float depth) { + _clear_depth = depth; +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::get_clear_depth +// Access: Published +// Description: Returns the current clear depth value. This is +// the value that will be used to clear the depth buffer +// every frame, but only if get_clear_depth_active() +// returns true. If get_clear_depth_active() returns +// false, this is meaningless. +//////////////////////////////////////////////////////////////////// +INLINE float ClearableRegion:: +get_clear_depth() const { + return _clear_depth; +} + +//////////////////////////////////////////////////////////////////// +// Function: ClearableRegion::is_any_clear_active +// Access: Published +// Description: Returns true if any of the clear types (so far there +// are just color or depth) have been set active, or +// false if none of them are active and there is no need +// to clear. +//////////////////////////////////////////////////////////////////// +INLINE bool ClearableRegion:: +is_any_clear_active() const { + return (_flags != 0); +} diff --git a/panda/src/display/clearableRegion.cxx b/panda/src/display/clearableRegion.cxx new file mode 100644 index 0000000000..b39c66e110 --- /dev/null +++ b/panda/src/display/clearableRegion.cxx @@ -0,0 +1,19 @@ +// Filename: clearableRegion.cxx +// Created by: drose (11Jul02) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, 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://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "clearableRegion.h" diff --git a/panda/src/display/clearableRegion.h b/panda/src/display/clearableRegion.h new file mode 100644 index 0000000000..f2204a7e3b --- /dev/null +++ b/panda/src/display/clearableRegion.h @@ -0,0 +1,68 @@ +// Filename: clearableRegion.h +// Created by: drose (11Jul02) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, 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://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef CLEARABLEREGION_H +#define CLEARABLEREGION_H + +#include "pandabase.h" +#include "luse.h" + +//////////////////////////////////////////////////////////////////// +// Class : ClearableRegion +// Description : This is just an interface definition for a +// rectangular region of the screen that might or might +// not need to be cleared every frame before rendering. +// This includes DisplayRegions and GraphicsWindows. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA ClearableRegion { +public: + INLINE ClearableRegion(); + INLINE ClearableRegion(const ClearableRegion ©); + INLINE void operator = (const ClearableRegion ©); + + INLINE void copy_clear_settings(const ClearableRegion ©); + +PUBLISHED: + INLINE void set_clear_color_active(bool clear_color_active); + INLINE bool get_clear_color_active() const; + + INLINE void set_clear_depth_active(bool clear_depth_active); + INLINE bool get_clear_depth_active() const; + + INLINE void set_clear_color(const Colorf &color); + INLINE const Colorf &get_clear_color() const; + + INLINE void set_clear_depth(float depth); + INLINE float get_clear_depth() const; + + INLINE bool is_any_clear_active() const; + +private: + enum Flags { + F_clear_color_active = 0x0001, + F_clear_depth_active = 0x0002, + }; + int _flags; + + Colorf _clear_color; + float _clear_depth; +}; + +#include "clearableRegion.I" + +#endif diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index 7a24d06196..56b5f455dd 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -20,6 +20,7 @@ #include "pandabase.h" +#include "clearableRegion.h" #include "referenceCount.h" #include "nodePath.h" #include "cullResult.h" @@ -38,7 +39,7 @@ class Camera; // Class : DisplayRegion // Description : //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DisplayRegion : public ReferenceCount { +class EXPCL_PANDA DisplayRegion : public ReferenceCount, public ClearableRegion { public: DisplayRegion(GraphicsLayer *); DisplayRegion(GraphicsLayer *, diff --git a/panda/src/display/display_composite1.cxx b/panda/src/display/display_composite1.cxx index 3cad8174c9..e02e1bc597 100644 --- a/panda/src/display/display_composite1.cxx +++ b/panda/src/display/display_composite1.cxx @@ -1,4 +1,4 @@ - +#include "clearableRegion.cxx" #include "displayRegion.cxx" #include "geomContext.cxx" #include "geomNodeContext.cxx" diff --git a/panda/src/display/display_composite2.cxx b/panda/src/display/display_composite2.cxx index 4da48d0236..c7699fd783 100644 --- a/panda/src/display/display_composite2.cxx +++ b/panda/src/display/display_composite2.cxx @@ -1,4 +1,3 @@ - #include "config_display.cxx" #include "hardwareChannel.cxx" #include "interactiveGraphicsPipe.cxx" diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index b8fe9a0d9b..c922a6ada0 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -159,6 +159,9 @@ cull_and_draw_together(GraphicsStateGuardian *gsg, DisplayRegion *dr) { if (setup_gsg(gsg, scene_setup)) { DisplayRegionStack old_dr = gsg->push_display_region(dr); gsg->prepare_display_region(); + if (dr->is_any_clear_active()) { + gsg->clear(dr); + } DrawCullHandler cull_handler(gsg); do_cull(&cull_handler, scene_setup, gsg); @@ -346,6 +349,9 @@ do_draw(CullResult *cull_result, SceneSetup *scene_setup, if (setup_gsg(gsg, scene_setup)) { DisplayRegionStack old_dr = gsg->push_display_region(dr); gsg->prepare_display_region(); + if (dr->is_any_clear_active()) { + gsg->clear(dr); + } cull_result->draw(); gsg->pop_display_region(old_dr); } diff --git a/panda/src/display/graphicsStateGuardian.I b/panda/src/display/graphicsStateGuardian.I index bed3f686bb..0348c969bd 100644 --- a/panda/src/display/graphicsStateGuardian.I +++ b/panda/src/display/graphicsStateGuardian.I @@ -63,6 +63,24 @@ get_scene() const { return _scene_setup; } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::clear +// Access: Public +// Description: Clears the framebuffer within the indicated +// DisplayRegion, according to the flags indicated by +// the DisplayRegion object (inheriting from +// ClearableRegion). Note that by default, a +// DisplayRegion does not have any clear flags set, in +// which case this function will do nothing. +//////////////////////////////////////////////////////////////////// +INLINE void GraphicsStateGuardian:: +clear(DisplayRegion *dr) { + DisplayRegionStack old_dr = push_display_region(dr); + prepare_display_region(); + clear((ClearableRegion *)dr); + pop_display_region(old_dr); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::modify_state // Access: Public diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 9b99bd127d..bb6c70961c 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -173,72 +173,6 @@ get_render_buffer(int buffer_type) { return RenderBuffer(this, buffer_type & _buffer_mask); } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::set_color_clear_value -// Access: Public -// Description: Sets the color that the next clear() command will set -// the color buffer to -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -set_color_clear_value(const Colorf& value) { - _color_clear_value = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::set_depth_clear_value -// Access: Public -// Description: Sets the depth that the next clear() command will set -// the depth buffer to -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -set_depth_clear_value(const float value) { - _depth_clear_value = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::set_stencil_clear_value -// Access: Public -// Description: Sets the value that the next clear() command will set -// the stencil buffer to -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -set_stencil_clear_value(const bool value) { - _stencil_clear_value = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::set_accum_clear_value -// Access: Public -// Description: Sets the color that the next clear() command will set -// the accumulation buffer to -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -set_accum_clear_value(const Colorf& value) { - _accum_clear_value = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::enable_frame_clear -// Access: Public -// Description: Activates or deactivates the automatic clearing of -// the frame buffer and/or depth buffer at the beginning -// of each frame. -// -// If clear_color is true, the color buffer will be -// cleared; if clear_depth is true, the depth buffer -// will be cleared. -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -enable_frame_clear(bool clear_color, bool clear_depth) { - _clear_buffer_type = 0; - if (clear_color) { - _clear_buffer_type |= RenderBuffer::T_back; - } - if (clear_depth) { - _clear_buffer_type |= RenderBuffer::T_depth; - } -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::release_all_textures // Access: Public @@ -410,25 +344,49 @@ set_state_and_transform(const RenderState *state, } //////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::clear_framebuffer -// Access: Public, Virtual -// Description: Erases the contents of the framebuffer, according to -// _clear_buffer_type, which is set by -// enable_frame_clear(). -// -// This is used to prepare the framebuffer for drawing -// a new frame. +// Function: GraphicsStateGuardian::set_color_clear_value +// Access: Public +// Description: Sets the color that the next do_clear() command will set +// the color buffer to //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: -clear_framebuffer() { - if (_clear_buffer_type != 0) { - PT(DisplayRegion) win_dr = - _win->make_scratch_display_region(_win->get_width(), _win->get_height()); - nassertv(win_dr != (DisplayRegion*)NULL); - DisplayRegionStack old_dr = push_display_region(win_dr); +set_color_clear_value(const Colorf& value) { + _color_clear_value = value; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::set_depth_clear_value +// Access: Public +// Description: Sets the depth that the next do_clear() command will set +// the depth buffer to +//////////////////////////////////////////////////////////////////// +void GraphicsStateGuardian:: +set_depth_clear_value(const float value) { + _depth_clear_value = value; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::clear +// Access: Public +// Description: Clears the framebuffer within the current +// DisplayRegion, according to the flags indicated by +// the given ClearableRegion object. +//////////////////////////////////////////////////////////////////// +void GraphicsStateGuardian:: +clear(ClearableRegion *clearable) { + int clear_buffer_type = 0; + if (clearable->get_clear_color_active()) { + clear_buffer_type |= RenderBuffer::T_back; + set_color_clear_value(clearable->get_clear_color()); + } + if (clearable->get_clear_depth_active()) { + clear_buffer_type |= RenderBuffer::T_depth; + set_depth_clear_value(clearable->get_clear_depth()); + } + + if (clear_buffer_type != 0) { prepare_display_region(); - clear(get_render_buffer(_clear_buffer_type)); - pop_display_region(old_dr); + do_clear(get_render_buffer(clear_buffer_type)); } } diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 76c15bf83f..e4f785b0bd 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -43,6 +43,8 @@ #include "notify.h" #include "pvector.h" +class ClearableRegion; + //////////////////////////////////////////////////////////////////// // Class : GraphicsStateGuardian // Description : Encapsulates all the communication with a particular @@ -62,24 +64,6 @@ public: virtual ~GraphicsStateGuardian(); PUBLISHED: - virtual void set_color_clear_value(const Colorf& value); - virtual void set_depth_clear_value(const float value); - virtual void set_stencil_clear_value(const bool value); - virtual void set_accum_clear_value(const Colorf& value); - INLINE Colorf get_color_clear_value(void) const { - return _color_clear_value; - } - INLINE float get_depth_clear_value(void) const { - return _depth_clear_value; - } - INLINE bool get_stencil_clear_value(void) const { - return _stencil_clear_value; - } - INLINE Colorf get_accum_clear_value(void) const { - return _accum_clear_value; - } - - void enable_frame_clear(bool clear_color, bool clear_depth); void release_all_textures(); void release_all_geoms(); @@ -104,9 +88,12 @@ public: virtual void set_state_and_transform(const RenderState *state, const TransformState *transform); - virtual void clear(const RenderBuffer &buffer)=0; - virtual void clear(const RenderBuffer &buffer, const DisplayRegion* region)=0; - virtual void clear_framebuffer(); + virtual void set_color_clear_value(const Colorf &value); + virtual void set_depth_clear_value(const float value); + virtual void do_clear(const RenderBuffer &buffer)=0; + + void clear(ClearableRegion *clearable); + INLINE void clear(DisplayRegion *dr); virtual void prepare_display_region()=0; virtual bool prepare_lens(); diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index 461cf2b110..aa610a8eba 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -150,6 +150,10 @@ GraphicsWindow(GraphicsPipe *pipe) : Configurable() { _is_synced = false; _window_active = true; _display_regions_stale = false; + + // By default, windows are set up to clear color and depth. + set_clear_color_active(true); + set_clear_depth_active(true); } //////////////////////////////////////////////////////////////////// @@ -159,7 +163,7 @@ GraphicsWindow(GraphicsPipe *pipe) : Configurable() { //////////////////////////////////////////////////////////////////// GraphicsWindow:: GraphicsWindow(GraphicsPipe *pipe, - const GraphicsWindow::Properties& props) : Configurable() { + const GraphicsWindow::Properties &props) : Configurable() { #ifdef DO_MEMORY_USAGE MemoryUsage::update_type(this, this); #endif @@ -168,8 +172,14 @@ GraphicsWindow(GraphicsPipe *pipe, _draw_callback = NULL; _idle_callback = NULL; + _frame_number = 0; _is_synced = false; _window_active = true; + _display_regions_stale = false; + + // By default, windows are set up to clear color and depth. + set_clear_color_active(true); + set_clear_depth_active(true); } //////////////////////////////////////////////////////////////////// @@ -408,7 +418,7 @@ resized(const unsigned int x, const unsigned int y) { // DisplayRegion is not associated with any layer. // // To allocate a normal DisplayRegion for rendering, use -// the interface provded in GraphicsLayer. +// the interface provided in GraphicsLayer. //////////////////////////////////////////////////////////////////// PT(DisplayRegion) GraphicsWindow:: make_scratch_display_region(int xsize, int ysize) const { @@ -425,7 +435,9 @@ make_scratch_display_region(int xsize, int ysize) const { ysize = _props._ysize; } - return new DisplayRegion(xsize, ysize); + PT(DisplayRegion) region = new DisplayRegion(xsize, ysize); + region->copy_clear_settings(*this); + return region; } //////////////////////////////////////////////////////////////////// @@ -493,14 +505,22 @@ begin_frame() { //////////////////////////////////////////////////////////////////// // Function: GraphicsWindow::clear // Access: Public -// Description: Invokes the GSG to clear the entire contents of the -// window prior to drawing into it. This is normally -// called only by the draw process at the beginning of -// the frame. +// Description: Clears the entire framebuffer before rendering, +// according to the settings of get_color_clear_active() +// and get_depth_clear_active() (inherited from +// ClearableRegion). //////////////////////////////////////////////////////////////////// void GraphicsWindow:: clear() { - _gsg->clear_framebuffer(); + if (is_any_clear_active()) { + nassertv(_gsg != (GraphicsStateGuardian *)NULL); + + PT(DisplayRegion) win_dr = + make_scratch_display_region(get_width(), get_height()); + DisplayRegionStack old_dr = _gsg->push_display_region(win_dr); + _gsg->clear(this); + _gsg->pop_display_region(old_dr); + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index d3901c58e2..356a14d962 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -17,28 +17,25 @@ //////////////////////////////////////////////////////////////////// #ifndef GRAPHICSWINDOW_H #define GRAPHICSWINDOW_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include + +#include "pandabase.h" #include "graphicsWindowInputDevice.h" #include "graphicsChannel.h" #include "displayRegion.h" #include "graphicsStateGuardian.h" +#include "clearableRegion.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "typedef.h" +#include "configurable.h" +#include "referenceCount.h" +#include "mouseData.h" +#include "modifierButtons.h" +#include "buttonEvent.h" +#include "iterator_types.h" +#include "factory.h" +#include "pStatCollector.h" -#include #include "pvector.h" #include "pdeque.h" @@ -69,7 +66,7 @@ class CullHandler; // Class : GraphicsWindow // Description : //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GraphicsWindow : public Configurable, public ReferenceCount { +class EXPCL_PANDA GraphicsWindow : public Configurable, public ReferenceCount, public ClearableRegion { PUBLISHED: class EXPCL_PANDA Properties { PUBLISHED: diff --git a/panda/src/distort/nonlinearImager.cxx b/panda/src/distort/nonlinearImager.cxx index b4f50d31e3..2f875febcb 100644 --- a/panda/src/distort/nonlinearImager.cxx +++ b/panda/src/distort/nonlinearImager.cxx @@ -601,10 +601,6 @@ render_screen(GraphicsEngine *engine, NonlinearImager::Screen &screen) { PT(DisplayRegion) scratch_region = _gsg->get_window()->make_scratch_display_region(screen._tex_width, screen._tex_height); scratch_region->set_camera(screen._source_camera); - - _gsg->clear(_gsg->get_render_buffer(RenderBuffer::T_back | - RenderBuffer::T_depth), - scratch_region); engine->render_subframe(_gsg, scratch_region); // Copy the results of the render from the frame buffer into the diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx index 79e839f85f..309249951d 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx @@ -928,13 +928,13 @@ dx_init( void) { } //////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::clear +// Function: DXGraphicsStateGuardian::do_clear // Access: Public, Virtual // Description: Clears all of the indicated buffers to their assigned // colors. //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: -clear(const RenderBuffer &buffer) { +do_clear(const RenderBuffer &buffer) { DO_PSTATS_STUFF(PStatTimer timer(_win->_clear_pcollector)); nassertv(buffer._gsg == this); @@ -963,20 +963,6 @@ clear(const RenderBuffer &buffer) { */ } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::clear -// Access: Public, Virtual -// Description: Clears all of the indicated buffers to their assigned -// colors. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -clear(const RenderBuffer &buffer, const DisplayRegion *region) { - DisplayRegionStack old_dr = push_display_region(region); - prepare_display_region(); - clear(buffer); - pop_display_region(old_dr); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::prepare_display_region // Access: Public, Virtual diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.h b/panda/src/dxgsg/dxGraphicsStateGuardian.h index 88f84761d9..6068b576be 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.h +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.h @@ -68,8 +68,7 @@ public: virtual void reset(); - virtual void clear(const RenderBuffer &buffer); - virtual void clear(const RenderBuffer &buffer, const DisplayRegion* region); + virtual void do_clear(const RenderBuffer &buffer); virtual void prepare_display_region(); virtual bool prepare_lens(); diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index c2b73c8ac3..fd72baa488 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -1028,13 +1028,13 @@ support_overlay_window(bool flag) { } //////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::clear +// Function: DXGraphicsStateGuardian::do_clear // Access: Public, Virtual // Description: Clears all of the indicated buffers to their assigned // colors. //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: -clear(const RenderBuffer &buffer) { +do_clear(const RenderBuffer &buffer) { DO_PSTATS_STUFF(PStatTimer timer(_win->_clear_pcollector)); nassertv(buffer._gsg == this); @@ -1067,20 +1067,6 @@ clear(const RenderBuffer &buffer) { */ } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::clear -// Access: Public, Virtual -// Description: Clears all of the indicated buffers to their assigned -// colors. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -clear(const RenderBuffer &buffer, const DisplayRegion *region) { - DisplayRegionStack old_dr = push_display_region(region); - prepare_display_region(); - clear(buffer); - pop_display_region(old_dr); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::prepare_display_region // Access: Public, Virtual diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index 88cd4a8884..e9f27d5b7a 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -75,8 +75,7 @@ public: virtual void reset(); - virtual void clear(const RenderBuffer &buffer); - virtual void clear(const RenderBuffer &buffer, const DisplayRegion* region); + virtual void do_clear(const RenderBuffer &buffer); virtual void prepare_display_region(); virtual bool prepare_lens(); diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index ae216ca647..660e55c6a2 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -316,7 +316,7 @@ reset() { // colors. //////////////////////////////////////////////////////////////////// void GLGraphicsStateGuardian:: -clear(const RenderBuffer &buffer) { +do_clear(const RenderBuffer &buffer) { DO_PSTATS_STUFF(PStatTimer timer(_win->_clear_pcollector);) // activate(); @@ -381,20 +381,6 @@ clear(const RenderBuffer &buffer) { glClear(mask); } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::clear -// Access: Public, Virtual -// Description: Clears all of the indicated buffers to their assigned -// colors. -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -clear(const RenderBuffer &buffer, const DisplayRegion *region) { - DisplayRegionStack old_dr = push_display_region(region); - prepare_display_region(); - clear(buffer); - pop_display_region(old_dr); -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::prepare_display_region // Access: Public, Virtual diff --git a/panda/src/glgsg/glGraphicsStateGuardian.h b/panda/src/glgsg/glGraphicsStateGuardian.h index eb363b0a64..e6533f88aa 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.h +++ b/panda/src/glgsg/glGraphicsStateGuardian.h @@ -68,8 +68,7 @@ public: virtual void reset(); - virtual void clear(const RenderBuffer &buffer); - virtual void clear(const RenderBuffer &buffer, const DisplayRegion* region); + virtual void do_clear(const RenderBuffer &buffer); virtual void prepare_display_region(); virtual bool prepare_lens();