From df1fd03cace63725e6650656413d15049301a219 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 29 Mar 2002 20:18:38 +0000 Subject: [PATCH] pgraph uses window's begin_frame() .. end_frame() --- panda/src/crgsg/crGraphicsStateGuardian.cxx | 11 ---- panda/src/display/graphicsEngine.cxx | 8 +-- panda/src/display/graphicsStateGuardian.cxx | 64 +++++++++++++++---- panda/src/display/graphicsStateGuardian.h | 7 +- panda/src/display/graphicsWindow.cxx | 38 ++++------- panda/src/display/graphicsWindow.h | 5 +- panda/src/glgsg/glGraphicsStateGuardian.cxx | 11 ---- panda/src/gsgbase/graphicsStateGuardianBase.h | 2 - 8 files changed, 76 insertions(+), 70 deletions(-) diff --git a/panda/src/crgsg/crGraphicsStateGuardian.cxx b/panda/src/crgsg/crGraphicsStateGuardian.cxx index 13d19a192d..9d26a58e92 100644 --- a/panda/src/crgsg/crGraphicsStateGuardian.cxx +++ b/panda/src/crgsg/crGraphicsStateGuardian.cxx @@ -528,19 +528,8 @@ render_frame() { report_errors(); _decal_level = 0; -#ifdef DO_PSTATS - // For Pstats to track our current texture memory usage, we have to - // reset the set of current textures each frame. - init_frame_pstats(); _vertices_display_list_pcollector.clear_level(); - // But since we don't get sent a new issue_texture() unless our - // texture state has changed, we have to be sure to clear the - // current texture state now. A bit unfortunate, but probably not - // measurably expensive. - clear_attribute(TextureTransition::get_class_type()); -#endif - // First, clear the entire window. clear_framebuffer(); diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 0c8e3e7e57..a87dba0bb5 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -111,7 +111,7 @@ cull_and_draw_together() { Windows::iterator wi; for (wi = _windows.begin(); wi != _windows.end(); ++wi) { GraphicsWindow *win = (*wi); - win->get_gsg()->reset_frame(); + win->begin_frame(); win->clear(); int num_display_regions = win->get_num_display_regions(); @@ -119,7 +119,7 @@ cull_and_draw_together() { DisplayRegion *dr = win->get_display_region(i); cull_and_draw_together(win, dr); } - win->flip(); + win->end_frame(); win->process_events(); } } @@ -160,7 +160,7 @@ cull_bin_draw() { Windows::iterator wi; for (wi = _windows.begin(); wi != _windows.end(); ++wi) { GraphicsWindow *win = (*wi); - win->get_gsg()->reset_frame(); + win->begin_frame(); win->clear(); int num_display_regions = win->get_num_display_regions(); @@ -168,7 +168,7 @@ cull_bin_draw() { DisplayRegion *dr = win->get_display_region(i); cull_bin_draw(win, dr); } - win->flip(); + win->end_frame(); win->process_events(); } } diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 165573124d..af2d470aeb 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -24,6 +24,7 @@ #include "colorAttrib.h" #include "colorScaleAttrib.h" #include "lightAttrib.h" +#include "textureAttrib.h" #include "renderState.h" #include "depthWriteAttrib.h" #include "colorWriteAttrib.h" @@ -852,24 +853,15 @@ prepare_lens() { return false; } -static CPT(RenderState) -get_unlit_state() { - static CPT(RenderState) state = NULL; - if (state == (const RenderState *)NULL) { - state = RenderState::make(LightAttrib::make_all_off()); - } - return state; -} - //////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::reset_frame +// Function: GraphicsStateGuardian::begin_frame // Access: Public, Virtual // Description: Called before each frame is rendered, to allow the // GSG a chance to do any internal cleanup before // beginning the frame. //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: -reset_frame() { +begin_frame() { // Undo any lighting we had enabled last frame, to force the lights // to be reissued, in case their parameters or positions have // changed between frames. @@ -886,6 +878,29 @@ reset_frame() { _lighting_enabled_this_frame = false; } + +#ifdef DO_PSTATS + // For Pstats to track our current texture memory usage, we have to + // reset the set of current textures each frame. + init_frame_pstats(); + + // But since we don't get sent a new issue_texture() unless our + // texture state has changed, we have to be sure to clear the + // current texture state now. A bit unfortunate, but probably not + // measurably expensive. + modify_state(get_untextured_state()); +#endif +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::end_frame +// Access: Public, Virtual +// Description: Called after each frame is rendered, to allow the +// GSG a chance to do any internal cleanup after +// rendering the frame, and before the window flips. +//////////////////////////////////////////////////////////////////// +void GraphicsStateGuardian:: +end_frame() { } //////////////////////////////////////////////////////////////////// @@ -1701,6 +1716,33 @@ record_state_change(TypeHandle type) { } #endif // DO_PSTATS +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::get_unlit_state +// Access: Protected, Static +// Description: +//////////////////////////////////////////////////////////////////// +CPT(RenderState) GraphicsStateGuardian:: +get_unlit_state() { + static CPT(RenderState) state = NULL; + if (state == (const RenderState *)NULL) { + state = RenderState::make(LightAttrib::make_all_off()); + } + return state; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::get_untextured_state +// Access: Protected, Static +// Description: +//////////////////////////////////////////////////////////////////// +CPT(RenderState) GraphicsStateGuardian:: +get_untextured_state() { + static CPT(RenderState) state = NULL; + if (state == (const RenderState *)NULL) { + state = RenderState::make(TextureAttrib::make_off()); + } + return state; +} void GraphicsStateGuardian:: traverse_prepared_textures(bool (*pertex_callbackfn)(TextureContext *,void *),void *callback_arg) { diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 6003e7eb1b..1cd5962819 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -132,7 +132,8 @@ public: INLINE void enable_normals(bool val) { _normals_enabled = val; } - virtual void reset_frame(); + virtual void begin_frame(); + virtual void end_frame(); // These functions will be queried by the GeomIssuer to determine if // it should issue normals, texcoords, and/or colors, based on the @@ -245,6 +246,9 @@ protected: INLINE void count_node(Node *) { } #endif + static CPT(RenderState) get_unlit_state(); + static CPT(RenderState) get_untextured_state(); + protected: PT(SceneSetup) _scene_setup; @@ -385,7 +389,6 @@ public: private: static void read_priorities(void); - static GsgFactory *_factory; public: diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index d9132c358d..2aa2faf035 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -454,6 +454,18 @@ void GraphicsWindow:: update() { } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindow::begin_frame +// Access: Public, Virtual +// Description: This function will be called by the GSG before +// beginning processing for a given frame. It should do +// whatever setup is required. +//////////////////////////////////////////////////////////////////// +void GraphicsWindow:: +begin_frame() { + _gsg->begin_frame(); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsWindow::clear // Access: Public @@ -467,31 +479,6 @@ clear() { _gsg->clear_framebuffer(); } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::flip -// Access: Public, Virtual -// Description: Flips the back buffer and front buffer, or does -// whatever other processing is appropriate, after the -// frame has been completely drawn. Normally this is -// only called by the draw process between frames, in -// sync with all the other windows. -//////////////////////////////////////////////////////////////////// -void GraphicsWindow:: -flip() { - end_frame(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::begin_frame -// Access: Public, Virtual -// Description: This function will be called by the GSG before -// beginning processing for a given frame. It should do -// whatever setup is required. -//////////////////////////////////////////////////////////////////// -void GraphicsWindow:: -begin_frame() { -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsWindow::end_frame // Access: Public, Virtual @@ -501,6 +488,7 @@ begin_frame() { //////////////////////////////////////////////////////////////////// void GraphicsWindow:: end_frame() { + _gsg->end_frame(); _frame_number++; } diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index 911b808214..27ecdaf6d5 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -200,11 +200,8 @@ PUBLISHED: INLINE void render_and_update(); public: - // New-style scene graph rendering (not yet complete). - void clear(); - virtual void flip(); - virtual void begin_frame(); + void clear(); virtual void end_frame(); virtual void deactivate_window(void); virtual void reactivate_window(void); diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index 32c1bb53c1..be82c4cf5d 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -527,19 +527,8 @@ render_frame() { report_errors(); _decal_level = 0; -#ifdef DO_PSTATS - // For Pstats to track our current texture memory usage, we have to - // reset the set of current textures each frame. - init_frame_pstats(); _vertices_display_list_pcollector.clear_level(); - // But since we don't get sent a new issue_texture() unless our - // texture state has changed, we have to be sure to clear the - // current texture state now. A bit unfortunate, but probably not - // measurably expensive. - clear_attribute(TextureTransition::get_class_type()); -#endif - // First, clear the entire window. clear_framebuffer(); diff --git a/panda/src/gsgbase/graphicsStateGuardianBase.h b/panda/src/gsgbase/graphicsStateGuardianBase.h index 472c61750b..9189a1c2dd 100644 --- a/panda/src/gsgbase/graphicsStateGuardianBase.h +++ b/panda/src/gsgbase/graphicsStateGuardianBase.h @@ -123,8 +123,6 @@ class LensNode; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA GraphicsStateGuardianBase : public TypedReferenceCount { public: - virtual void reset_frame()=0; - // These functions will be queried by the GeomIssuer to determine if // it should issue normals, texcoords, and/or colors, based on the // GSG's current state.