From cee838c08ed01f698c75e4c0ba2e1b6f121bdd51 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Wed, 8 Feb 2006 17:52:29 +0000 Subject: [PATCH] begin_frame refactor --- panda/src/display/displayRegion.cxx | 12 +- panda/src/display/graphicsEngine.cxx | 12 +- panda/src/display/graphicsOutput.I | 11 -- panda/src/display/graphicsOutput.cxx | 74 +--------- panda/src/display/graphicsOutput.h | 28 ++-- panda/src/display/parasiteBuffer.cxx | 69 ++++------ panda/src/display/parasiteBuffer.h | 6 +- panda/src/dxgsg8/wdxGraphicsBuffer8.cxx | 61 ++++---- panda/src/dxgsg8/wdxGraphicsBuffer8.h | 12 +- panda/src/dxgsg8/wdxGraphicsWindow8.cxx | 130 +++++++++--------- panda/src/dxgsg8/wdxGraphicsWindow8.h | 6 +- panda/src/dxgsg9/wdxGraphicsBuffer9.cxx | 63 ++++----- panda/src/dxgsg9/wdxGraphicsBuffer9.h | 12 +- panda/src/dxgsg9/wdxGraphicsWindow9.cxx | 41 +++--- panda/src/dxgsg9/wdxGraphicsWindow9.h | 7 +- panda/src/glstuff/glGraphicsBuffer_src.h | 10 +- panda/src/glxdisplay/glxGraphicsBuffer.cxx | 39 +++--- panda/src/glxdisplay/glxGraphicsBuffer.h | 5 +- panda/src/glxdisplay/glxGraphicsWindow.cxx | 4 +- panda/src/glxdisplay/glxGraphicsWindow.h | 7 +- .../src/mesadisplay/osMesaGraphicsBuffer.cxx | 36 ++--- panda/src/mesadisplay/osMesaGraphicsBuffer.h | 5 +- panda/src/wgldisplay/wglGraphicsBuffer.cxx | 58 ++++---- panda/src/wgldisplay/wglGraphicsBuffer.h | 7 +- panda/src/wgldisplay/wglGraphicsWindow.cxx | 99 +++++-------- panda/src/wgldisplay/wglGraphicsWindow.h | 7 +- 26 files changed, 320 insertions(+), 501 deletions(-) diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index a50d1dea2f..92d2315466 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -549,20 +549,24 @@ get_screenshot(PNMImage &image) { GraphicsStateGuardian *gsg = window->get_gsg(); nassertr(gsg != (GraphicsStateGuardian *)NULL, false); - window->make_current(); + if (!window->begin_frame(GraphicsOutput::FM_refresh)) { + return false; + } // Create a temporary texture to receive the framebuffer image. PT(Texture) tex = new Texture; - + RenderBuffer buffer = gsg->get_render_buffer(get_screenshot_buffer_type()); if (!gsg->framebuffer_copy_to_ram(tex, -1, this, buffer)) { return false; } - + + window->end_frame(GraphicsOutput::FM_refresh); + if (!tex->store(image)) { return false; } - + return true; } diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index dd3039c1e6..42a9241b67 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -790,7 +790,7 @@ cull_and_draw_together(const GraphicsEngine::Windows &wlist) { for (wi = wlist.begin(); wi != wlist.end(); ++wi) { GraphicsOutput *win = (*wi); if (win->is_active() && win->get_gsg()->is_active()) { - if (win->begin_frame()) { + if (win->begin_frame(GraphicsOutput::FM_render)) { win->clear(); int num_display_regions = win->get_num_active_display_regions(); @@ -800,7 +800,7 @@ cull_and_draw_together(const GraphicsEngine::Windows &wlist) { cull_and_draw_together(win, dr); } } - win->end_frame(); + win->end_frame(GraphicsOutput::FM_render); if (_auto_flip) { if (win->flip_ready()) { @@ -864,7 +864,7 @@ cull_bin_draw(const GraphicsEngine::Windows &wlist) { GraphicsOutput *win = (*wi); if (win->is_active() && win->get_gsg()->is_active()) { // This should be done in the draw thread, not here. - if (win->begin_frame()) { + if (win->begin_frame(GraphicsOutput::FM_render)) { win->clear(); int num_display_regions = win->get_num_active_display_regions(); @@ -874,7 +874,7 @@ cull_bin_draw(const GraphicsEngine::Windows &wlist) { cull_bin_draw(win, dr); } } - win->end_frame(); + win->end_frame(GraphicsOutput::FM_render); if (_auto_flip) { if (win->flip_ready()) { @@ -940,8 +940,8 @@ make_contexts(const GraphicsEngine::Windows &wlist) { Windows::const_iterator wi; for (wi = wlist.begin(); wi != wlist.end(); ++wi) { GraphicsOutput *win = (*wi); - if (win->needs_context()) { - win->make_context(); + if (win->begin_frame(GraphicsOutput::FM_refresh)) { + win->end_frame(GraphicsOutput::FM_refresh); } } } diff --git a/panda/src/display/graphicsOutput.I b/panda/src/display/graphicsOutput.I index 4750e3ccfe..ced190ecb9 100644 --- a/panda/src/display/graphicsOutput.I +++ b/panda/src/display/graphicsOutput.I @@ -372,17 +372,6 @@ flip_ready() const { return _flip_ready; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsOutput::needs_context -// Access: Public -// Description: Returns true if make_context() still needs to be -// called, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool GraphicsOutput:: -needs_context() const { - return _needs_context; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsOutput::operator < // Access: Public diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 86f1329e5b..3bde0861f9 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -81,7 +81,6 @@ GraphicsOutput(GraphicsPipe *pipe, GraphicsStateGuardian *gsg, _has_size = false; _is_valid = false; _flip_ready = false; - _needs_context = true; _cube_map_index = -1; _cube_map_dr = NULL; _sort = 0; @@ -961,7 +960,7 @@ reset_window(bool swapchain) { // should be skipped. //////////////////////////////////////////////////////////////////// bool GraphicsOutput:: -begin_frame() { +begin_frame(FrameMode mode) { return false; } @@ -973,7 +972,7 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void GraphicsOutput:: -end_frame() { +end_frame(FrameMode mode) { } //////////////////////////////////////////////////////////////////// @@ -1090,37 +1089,6 @@ copy_to_textures() { _trigger_copy = false; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsOutput::begin_render_texture -// Access: Public, Virtual -// Description: If the GraphicsOutput supports direct render-to-texture, -// and if any setup needs to be done during begin_frame, -// then the setup code should go here. Any textures that -// can not be rendered to directly should be reflagged -// as RTM_copy_texture. -//////////////////////////////////////////////////////////////////// -void GraphicsOutput:: -begin_render_texture() { - for (int i=0; i _textures; bool _flip_ready; - bool _needs_context; int _cube_map_index; DisplayRegion *_cube_map_dr; PT(Geom) _texture_card; diff --git a/panda/src/display/parasiteBuffer.cxx b/panda/src/display/parasiteBuffer.cxx index b24d4535a8..0cf20e7ad1 100644 --- a/panda/src/display/parasiteBuffer.cxx +++ b/panda/src/display/parasiteBuffer.cxx @@ -106,21 +106,23 @@ get_host() { // should be skipped. //////////////////////////////////////////////////////////////////// bool ParasiteBuffer:: -begin_frame() { +begin_frame(FrameMode mode) { begin_frame_spam(); - if (_gsg == (GraphicsStateGuardian *)NULL) { + + if (!_host->begin_frame(FM_parasite)) { return false; } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; + + if (_track_host_size) { + if ((_host->get_x_size() != _x_size)|| + (_host->get_y_size() != _y_size)) { + set_size_and_recalc(_host->get_x_size(), + _host->get_y_size()); } } - make_current(); - begin_render_texture(); + clear_cube_map_selection(); - return _gsg->begin_frame(); + return true; } //////////////////////////////////////////////////////////////////// @@ -131,46 +133,23 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void ParasiteBuffer:: -end_frame() { +end_frame(FrameMode mode) { end_frame_spam(); + nassertv(_gsg != (GraphicsStateGuardian *)NULL); - _gsg->end_frame(); - end_render_texture(); - copy_to_textures(); - trigger_flip(); - if (_one_shot) { - prepare_for_deletion(); + + if (mode == FM_refresh) { + return; } - clear_cube_map_selection(); -} -//////////////////////////////////////////////////////////////////// -// Function: ParasiteBuffer::make_current -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// during begin_frame() to ensure the graphics context -// is ready for drawing. -//////////////////////////////////////////////////////////////////// -void ParasiteBuffer:: -make_current() { - _host->make_current(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ParasiteBuffer::auto_resize -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// to make sure this buffer is the right size. If not, -// it will be resized. -//////////////////////////////////////////////////////////////////// -void ParasiteBuffer:: -auto_resize() { - if (_track_host_size) { - _host->auto_resize(); - if ((_host->get_x_size() != _x_size)|| - (_host->get_y_size() != _y_size)) { - set_size_and_recalc(_host->get_x_size(), - _host->get_y_size()); + _host->end_frame(FM_parasite); + + if (mode == FM_render) { + copy_to_textures(); + if (_one_shot) { + prepare_for_deletion(); } + clear_cube_map_selection(); } } + diff --git a/panda/src/display/parasiteBuffer.h b/panda/src/display/parasiteBuffer.h index 427e7d6603..72bd2e18b8 100644 --- a/panda/src/display/parasiteBuffer.h +++ b/panda/src/display/parasiteBuffer.h @@ -63,11 +63,9 @@ PUBLISHED: virtual bool is_active() const; public: - virtual bool begin_frame(); - virtual void end_frame(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); virtual GraphicsOutput *get_host(); - virtual void make_current(); - virtual void auto_resize(); private: PT(GraphicsOutput) _host; diff --git a/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx b/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx index 5af7ba4434..ef9e75c961 100644 --- a/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx +++ b/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx @@ -80,20 +80,18 @@ wdxGraphicsBuffer8:: // should be skipped. //////////////////////////////////////////////////////////////////// bool wdxGraphicsBuffer8:: -begin_frame() { +begin_frame(FrameMode mode) { + begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { return false; } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } + + if (mode == FM_render) { + begin_render_texture(); + clear_cube_map_selection(); } - make_current(); - begin_render_texture(); - clear_cube_map_selection(); + return _gsg->begin_frame(); } @@ -105,22 +103,30 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void wdxGraphicsBuffer8:: -end_frame() { +end_frame(FrameMode mode) { + end_frame_spam(); nassertv(_gsg != (GraphicsStateGuardian *)NULL); - _gsg->end_frame(); - end_render_texture(); - copy_to_textures(); - trigger_flip(); - if (_one_shot) { - prepare_for_deletion(); + + if (mode == FM_render) { + end_render_texture(); + copy_to_textures(); + } + + _gsg->end_frame(); + + if (mode == FM_render) { + trigger_flip(); + if (_one_shot) { + prepare_for_deletion(); + } + clear_cube_map_selection(); } - clear_cube_map_selection(); } //////////////////////////////////////////////////////////////////// // Function: wglGraphicsStateGuardian::begin_render_texture -// Access: Public, Virtual +// Access: Public // Description: If the GraphicsOutput supports direct render-to-texture, // and if any setup needs to be done during begin_frame, // then the setup code should go here. Any textures that @@ -208,7 +214,7 @@ begin_render_texture() { //////////////////////////////////////////////////////////////////// // Function: GraphicsOutput::end_render_texture -// Access: Public, Virtual +// Access: Public // Description: If the GraphicsOutput supports direct render-to-texture, // and if any setup needs to be done during end_frame, // then the setup code should go here. Any textures that @@ -319,23 +325,6 @@ select_cube_map(int cube_map_index) { } } -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsBuffer8::make_current -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// during begin_frame() to ensure the graphics context -// is ready for drawing. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsBuffer8:: -make_current() { - PStatTimer timer(_make_current_pcollector); - - DXGraphicsStateGuardian8 *dxgsg; - DCAST_INTO_V(dxgsg, _gsg); - - // do nothing here -} - //////////////////////////////////////////////////////////////////// // Function: wdxGraphicsBuffer8::release_gsg // Access: Public, Virtual diff --git a/panda/src/dxgsg8/wdxGraphicsBuffer8.h b/panda/src/dxgsg8/wdxGraphicsBuffer8.h index e63b4b0b61..b1e47e9625 100644 --- a/panda/src/dxgsg8/wdxGraphicsBuffer8.h +++ b/panda/src/dxgsg8/wdxGraphicsBuffer8.h @@ -41,16 +41,12 @@ public: int x_size, int y_size); virtual ~wdxGraphicsBuffer8(); - virtual bool begin_frame(); - virtual void end_frame(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); + virtual void select_cube_map(int cube_map_index); - - virtual void make_current(); virtual void release_gsg(); - virtual void begin_render_texture(); - virtual void end_render_texture(); - virtual void process_events(); protected: @@ -58,6 +54,8 @@ protected: virtual bool open_buffer(); private: + void begin_render_texture(); + void end_render_texture(); static void process_1_event(); int _cube_map_index; diff --git a/panda/src/dxgsg8/wdxGraphicsWindow8.cxx b/panda/src/dxgsg8/wdxGraphicsWindow8.cxx index 9539c93beb..f28ffc4177 100644 --- a/panda/src/dxgsg8/wdxGraphicsWindow8.cxx +++ b/panda/src/dxgsg8/wdxGraphicsWindow8.cxx @@ -64,9 +64,74 @@ wdxGraphicsWindow8:: } //////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow8::make_current +// Function: wdxGraphicsWindow8::begin_frame // Access: Public, Virtual -// Description: +// Description: This function will be called within the draw thread +// before beginning rendering for a given frame. It +// should do whatever setup is required, and return true +// if the frame should be rendered, or false if it +// should be skipped. +//////////////////////////////////////////////////////////////////// +bool wdxGraphicsWindow8:: +begin_frame(FrameMode mode) { + begin_frame_spam(); + if (_gsg == (GraphicsStateGuardian *)NULL) { + return false; + } + + if (_awaiting_restore) { + // The fullscreen window was recently restored; we can't continue + // until the GSG says we can. + if (!_dxgsg->check_cooperative_level()) { + // Keep waiting. + return false; + } + _awaiting_restore = false; + init_resized_window(); + } + + make_current(); + + if (mode == FM_render) { + clear_cube_map_selection(); + } + + bool return_val = _gsg->begin_frame(); + _dxgsg->set_render_target(); + return return_val; +} + +//////////////////////////////////////////////////////////////////// +// Function: wdxGraphicsWindow8::end_frame +// Access: Public, Virtual +// Description: This function will be called within the draw thread +// after rendering is completed for a given frame. It +// should do whatever finalization is required. +//////////////////////////////////////////////////////////////////// +void wdxGraphicsWindow8:: +end_frame(FrameMode mode) { + + end_frame_spam(); + nassertv(_gsg != (GraphicsStateGuardian *)NULL); + + if (mode == FM_render) { + copy_to_textures(); + } + + _gsg->end_frame(); + + if (mode == FM_render) { + trigger_flip(); + if (_one_shot) { + prepare_for_deletion(); + } + clear_cube_map_selection(); + } +} +//////////////////////////////////////////////////////////////////// +// Function: wdxGraphicsWindow8::make_current +// Access: Private +// Description: //////////////////////////////////////////////////////////////////// void wdxGraphicsWindow8:: make_current() { @@ -89,67 +154,6 @@ make_current() { } } -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow8::begin_frame -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// before beginning rendering for a given frame. It -// should do whatever setup is required, and return true -// if the frame should be rendered, or false if it -// should be skipped. -//////////////////////////////////////////////////////////////////// -bool wdxGraphicsWindow8:: -begin_frame() { - begin_frame_spam(); - if (_gsg == (GraphicsStateGuardian *)NULL) { - return false; - } - if (_awaiting_restore) { - // The fullscreen window was recently restored; we can't continue - // until the GSG says we can. - if (!_dxgsg->check_cooperative_level()) { - // Keep waiting. - return false; - } - _awaiting_restore = false; - - init_resized_window(); - } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } - } - make_current(); - begin_render_texture(); - clear_cube_map_selection(); - bool return_val = _gsg->begin_frame(); - _dxgsg->set_render_target(); - return return_val; -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow8::end_frame -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// after rendering is completed for a given frame. It -// should do whatever finalization is required. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow8:: -end_frame() { - end_frame_spam(); - nassertv(_gsg != (GraphicsStateGuardian *)NULL); - _gsg->end_frame(); - end_render_texture(); - copy_to_textures(); - trigger_flip(); - if (_one_shot) { - prepare_for_deletion(); - } - clear_cube_map_selection(); -} - //////////////////////////////////////////////////////////////////// // Function: wdxGraphicsWindow8::end_flip // Access: Public, Virtual diff --git a/panda/src/dxgsg8/wdxGraphicsWindow8.h b/panda/src/dxgsg8/wdxGraphicsWindow8.h index c6a9d35209..957e1453fd 100644 --- a/panda/src/dxgsg8/wdxGraphicsWindow8.h +++ b/panda/src/dxgsg8/wdxGraphicsWindow8.h @@ -38,9 +38,8 @@ public: const string &name); virtual ~wdxGraphicsWindow8(); - virtual bool begin_frame(); - virtual void end_frame(); - virtual void make_current(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); virtual void end_flip(); virtual int verify_window_sizes(int numsizes, int *dimen); @@ -73,6 +72,7 @@ private: bool reset_device_resize_window(UINT new_xsize, UINT new_ysize); void init_resized_window(); + void make_current(); static int D3DFMT_to_DepthBits(D3DFORMAT fmt); static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID); diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx index 537ec354b8..b14dbb1998 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx @@ -77,21 +77,19 @@ wdxGraphicsBuffer9:: // should be skipped. //////////////////////////////////////////////////////////////////// bool wdxGraphicsBuffer9:: -begin_frame() { +begin_frame(FrameMode mode) { DBG_S dxgsg9_cat.debug ( ) << "wdxGraphicsBuffer9::begin_frame\n"; DBG_E + begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { return false; } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } + + if (mode == FM_render) { + begin_render_texture(); + clear_cube_map_selection(); } - make_current(); - begin_render_texture(); - clear_cube_map_selection(); + return _gsg->begin_frame(); } @@ -103,22 +101,30 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void wdxGraphicsBuffer9:: -end_frame() { +end_frame(FrameMode mode) { + end_frame_spam(); nassertv(_gsg != (GraphicsStateGuardian *)NULL); - _gsg->end_frame(); - end_render_texture(); - copy_to_textures(); - trigger_flip(); - if (_one_shot) { - prepare_for_deletion(); + + if (mode == FM_render) { + end_render_texture(); + copy_to_textures(); + } + + _gsg->end_frame(); + + if (mode == FM_render) { + trigger_flip(); + if (_one_shot) { + prepare_for_deletion(); + } + clear_cube_map_selection(); } - clear_cube_map_selection(); } //////////////////////////////////////////////////////////////////// // Function: wglGraphicsStateGuardian::begin_render_texture -// Access: Public, Virtual +// Access: Public // Description: If the GraphicsOutput supports direct render-to-texture, // and if any setup needs to be done during begin_frame, // then the setup code should go here. Any textures that @@ -221,7 +227,7 @@ begin_render_texture() { //////////////////////////////////////////////////////////////////// // Function: GraphicsOutput::end_render_texture -// Access: Public, Virtual +// Access: Public // Description: If the GraphicsOutput supports direct render-to-texture, // and if any setup needs to be done during end_frame, // then the setup code should go here. Any textures that @@ -355,25 +361,6 @@ select_cube_map(int cube_map_index) { } } -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsBuffer9::make_current -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// during begin_frame() to ensure the graphics context -// is ready for drawing. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsBuffer9:: -make_current() { - PStatTimer timer(_make_current_pcollector); - - DXGraphicsStateGuardian9 *dxgsg; - DCAST_INTO_V(dxgsg, _gsg); - - // do nothing here - DBG_S dxgsg9_cat.debug ( ) << "wdxGraphicsBuffer9::make_current\n"; DBG_E - -} - //////////////////////////////////////////////////////////////////// // Function: wdxGraphicsBuffer9::release_gsg // Access: Public, Virtual diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.h b/panda/src/dxgsg9/wdxGraphicsBuffer9.h index a4e01b3154..a94607471a 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.h +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.h @@ -41,16 +41,12 @@ public: int x_size, int y_size); virtual ~wdxGraphicsBuffer9(); - virtual bool begin_frame(); - virtual void end_frame(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); + virtual void select_cube_map(int cube_map_index); - - virtual void make_current(); virtual void release_gsg(); - virtual void begin_render_texture(); - virtual void end_render_texture(); - virtual void process_events(); protected: @@ -58,6 +54,8 @@ protected: virtual bool open_buffer(); private: + void begin_render_texture(); + void end_render_texture(); static void process_1_event(); int _cube_map_index; diff --git a/panda/src/dxgsg9/wdxGraphicsWindow9.cxx b/panda/src/dxgsg9/wdxGraphicsWindow9.cxx index 8740634c70..a2dc6189d4 100755 --- a/panda/src/dxgsg9/wdxGraphicsWindow9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsWindow9.cxx @@ -99,11 +99,12 @@ make_current() { // should be skipped. //////////////////////////////////////////////////////////////////// bool wdxGraphicsWindow9:: -begin_frame() { +begin_frame(FrameMode mode) { begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { return false; } + if (_awaiting_restore) { // The fullscreen window was recently restored; we can't continue // until the GSG says we can. @@ -112,18 +113,15 @@ begin_frame() { return false; } _awaiting_restore = false; - init_resized_window(); } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } - } + make_current(); - begin_render_texture(); - clear_cube_map_selection(); + + if (mode == FM_render) { + clear_cube_map_selection(); + } + bool return_val = _gsg->begin_frame(); _dxgsg->set_render_target(); return return_val; @@ -137,17 +135,24 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void wdxGraphicsWindow9:: -end_frame() { +end_frame(FrameMode mode) { + end_frame_spam(); nassertv(_gsg != (GraphicsStateGuardian *)NULL); - _gsg->end_frame(); - end_render_texture(); - copy_to_textures(); - trigger_flip(); - if (_one_shot) { - prepare_for_deletion(); + + if (mode == FM_render) { + copy_to_textures(); + } + + _gsg->end_frame(); + + if (mode == FM_render) { + trigger_flip(); + if (_one_shot) { + prepare_for_deletion(); + } + clear_cube_map_selection(); } - clear_cube_map_selection(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/dxgsg9/wdxGraphicsWindow9.h b/panda/src/dxgsg9/wdxGraphicsWindow9.h index 666244c485..dccf79a448 100755 --- a/panda/src/dxgsg9/wdxGraphicsWindow9.h +++ b/panda/src/dxgsg9/wdxGraphicsWindow9.h @@ -38,10 +38,8 @@ public: const string &name); virtual ~wdxGraphicsWindow9(); - virtual void make_current(); - - virtual bool begin_frame(); - virtual void end_frame(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); virtual void end_flip(); virtual int verify_window_sizes(int numsizes, int *dimen); @@ -74,6 +72,7 @@ private: bool reset_device_resize_window(UINT new_xsize, UINT new_ysize); void init_resized_window(); + void make_current(); static int D3DFMT_to_DepthBits(D3DFORMAT fmt); static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER9 *pDevID); diff --git a/panda/src/glstuff/glGraphicsBuffer_src.h b/panda/src/glstuff/glGraphicsBuffer_src.h index 5343fd6292..b0a941481d 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.h +++ b/panda/src/glstuff/glGraphicsBuffer_src.h @@ -60,12 +60,12 @@ public: virtual ~CLP(GraphicsBuffer)(); virtual void select_cube_map(int cube_map_index); - virtual void auto_resize(); - virtual void make_current(); - virtual void begin_render_texture(); - virtual void end_render_texture(); - + private: + void make_current(); + void begin_render_texture(); + void end_render_texture(); + // HPBUFFERARB _pbuffer; // HDC _pbuffer_dc; diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.cxx b/panda/src/glxdisplay/glxGraphicsBuffer.cxx index fed57fab78..0fa00a5f05 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.cxx +++ b/panda/src/glxdisplay/glxGraphicsBuffer.cxx @@ -72,19 +72,25 @@ glxGraphicsBuffer:: // should be skipped. //////////////////////////////////////////////////////////////////// bool glxGraphicsBuffer:: -begin_frame() { +begin_frame(FrameMode mode) { + PStatTimer timer(_make_current_pcollector); + begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { return false; } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } - } - make_current(); - begin_render_texture(); + + glxGraphicsStateGuardian *glxgsg; + DCAST_INTO_V(glxgsg, _gsg); + glXMakeCurrent(_display, _pbuffer, glxgsg->_context); + + // Now that we have made the context current to a window, we can + // reset the GSG state if this is the first time it has been used. + // (We can't just call reset() when we construct the GSG, because + // reset() requires having a current context.) + glxgsg->reset_if_new(); + + // begin_render_texture(); clear_cube_map_selection(); return _gsg->begin_frame(); } @@ -97,11 +103,11 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void glxGraphicsBuffer:: -end_frame() { +end_frame(FrameMode mode) { end_frame_spam(); nassertv(_gsg != (GraphicsStateGuardian *)NULL); _gsg->end_frame(); - end_render_texture(); + // end_render_texture(); copy_to_textures(); trigger_flip(); if (_one_shot) { @@ -119,17 +125,6 @@ end_frame() { //////////////////////////////////////////////////////////////////// void glxGraphicsBuffer:: make_current() { - PStatTimer timer(_make_current_pcollector); - - glxGraphicsStateGuardian *glxgsg; - DCAST_INTO_V(glxgsg, _gsg); - glXMakeCurrent(_display, _pbuffer, glxgsg->_context); - - // Now that we have made the context current to a window, we can - // reset the GSG state if this is the first time it has been used. - // (We can't just call reset() when we construct the GSG, because - // reset() requires having a current context.) - glxgsg->reset_if_new(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.h b/panda/src/glxdisplay/glxGraphicsBuffer.h index 9750faaab6..f5e3091803 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.h +++ b/panda/src/glxdisplay/glxGraphicsBuffer.h @@ -41,9 +41,8 @@ public: virtual ~glxGraphicsBuffer(); - virtual bool begin_frame(); - virtual void end_frame(); - virtual void make_current(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); virtual void release_gsg(); protected: diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index b01ab812e7..766b3e4ec6 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -170,7 +170,7 @@ release_gsg() { // should be skipped. //////////////////////////////////////////////////////////////////// bool glxGraphicsWindow:: -begin_frame() { +begin_frame(FrameMode mode) { begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { return false; @@ -200,7 +200,7 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void glxGraphicsWindow:: -end_frame() { +end_frame(FrameMode mode) { end_frame_spam(); nassertv(_gsg != (GraphicsStateGuardian *)NULL); _gsg->end_frame(); diff --git a/panda/src/glxdisplay/glxGraphicsWindow.h b/panda/src/glxdisplay/glxGraphicsWindow.h index f48e60cea2..286ddbe611 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.h +++ b/panda/src/glxdisplay/glxGraphicsWindow.h @@ -37,13 +37,10 @@ public: virtual ~glxGraphicsWindow(); virtual bool move_pointer(int device, int x, int y); - - virtual bool make_context(); - virtual void make_current(); virtual void release_gsg(); - virtual bool begin_frame(); - virtual void end_frame(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); virtual void begin_flip(); virtual void process_events(); diff --git a/panda/src/mesadisplay/osMesaGraphicsBuffer.cxx b/panda/src/mesadisplay/osMesaGraphicsBuffer.cxx index b52233e823..7f74bca7d7 100644 --- a/panda/src/mesadisplay/osMesaGraphicsBuffer.cxx +++ b/panda/src/mesadisplay/osMesaGraphicsBuffer.cxx @@ -61,14 +61,15 @@ begin_frame() { if (_gsg == (GraphicsStateGuardian *)NULL) { return false; } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } - } - make_current(); - begin_render_texture(); + + OSMesaGraphicsStateGuardian *mesagsg; + DCAST_INTO_V(mesagsg, _gsg); + OSMesaMakeCurrent(mesagsg->_context, _image.p(), _type, + _x_size, _y_size); + + mesagsg->reset_if_new(); + + // begin_render_texture(); clear_cube_map_selection(); return _gsg->begin_frame(); } @@ -85,7 +86,7 @@ end_frame() { end_frame_spam(); nassertv(_gsg != (GraphicsStateGuardian *)NULL); _gsg->end_frame(); - end_render_texture(); + // end_render_texture(); copy_to_textures(); trigger_flip(); if (_one_shot) { @@ -94,23 +95,6 @@ end_frame() { clear_cube_map_selection(); } -//////////////////////////////////////////////////////////////////// -// Function: OsMesaGraphicsBuffer::make_current -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// during begin_frame() to ensure the graphics context -// is ready for drawing. -//////////////////////////////////////////////////////////////////// -void OsMesaGraphicsBuffer:: -make_current() { - OSMesaGraphicsStateGuardian *mesagsg; - DCAST_INTO_V(mesagsg, _gsg); - OSMesaMakeCurrent(mesagsg->_context, _image.p(), _type, - _x_size, _y_size); - - mesagsg->reset_if_new(); -} - //////////////////////////////////////////////////////////////////// // Function: OsMesaGraphicsBuffer::close_buffer // Access: Protected, Virtual diff --git a/panda/src/mesadisplay/osMesaGraphicsBuffer.h b/panda/src/mesadisplay/osMesaGraphicsBuffer.h index 0449bddcd6..c8b9f3509c 100644 --- a/panda/src/mesadisplay/osMesaGraphicsBuffer.h +++ b/panda/src/mesadisplay/osMesaGraphicsBuffer.h @@ -38,9 +38,8 @@ public: virtual ~OsMesaGraphicsBuffer(); - virtual bool begin_frame(); - virtual void end_frame(); - virtual void make_current(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); protected: virtual void close_buffer(); diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.cxx b/panda/src/wgldisplay/wglGraphicsBuffer.cxx index 028179315c..f76da0df74 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.cxx +++ b/panda/src/wgldisplay/wglGraphicsBuffer.cxx @@ -65,7 +65,9 @@ wglGraphicsBuffer:: // should be skipped. //////////////////////////////////////////////////////////////////// bool wglGraphicsBuffer:: -begin_frame() { +begin_frame(FrameMode mode) { + PStatTimer timer(_make_current_pcollector); + begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { return false; @@ -87,15 +89,12 @@ begin_frame() { } } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } + wglMakeCurrent(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc)); + + if (mode == FM_render) { + begin_render_texture(); + clear_cube_map_selection(); } - make_current(); - begin_render_texture(); - clear_cube_map_selection(); return _gsg->begin_frame(); } @@ -107,17 +106,24 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void wglGraphicsBuffer:: -end_frame() { +end_frame(FrameMode mode) { end_frame_spam(); nassertv(_gsg != (GraphicsStateGuardian *)NULL); - _gsg->end_frame(); - end_render_texture(); - copy_to_textures(); - trigger_flip(); - if (_one_shot) { - prepare_for_deletion(); + + if (mode == FM_render) { + end_render_texture(); + copy_to_textures(); + } + + _gsg->end_frame(); + + if (mode == FM_render) { + trigger_flip(); + if (_one_shot) { + prepare_for_deletion(); + } + clear_cube_map_selection(); } - clear_cube_map_selection(); } //////////////////////////////////////////////////////////////////// @@ -219,23 +225,6 @@ select_cube_map(int cube_map_index) { wglgsg->_wglSetPbufferAttribARB(_pbuffer, iattrib_list); } -//////////////////////////////////////////////////////////////////// -// Function: wglGraphicsBuffer::make_current -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// during begin_frame() to ensure the graphics context -// is ready for drawing. -//////////////////////////////////////////////////////////////////// -void wglGraphicsBuffer:: -make_current() { - PStatTimer timer(_make_current_pcollector); - - wglGraphicsStateGuardian *wglgsg; - DCAST_INTO_V(wglgsg, _gsg); - - wglMakeCurrent(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc)); -} - //////////////////////////////////////////////////////////////////// // Function: wglGraphicsBuffer::release_gsg // Access: Public, Virtual @@ -319,7 +308,6 @@ open_buffer() { wglMakeCurrent(twindow_dc, wglgsg->get_context(twindow_dc)); wglgsg->reset_if_new(); - _needs_context = false; // Now that we have fully made a window and used that window to // create a rendering context, we can attempt to create a pbuffer. diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.h b/panda/src/wgldisplay/wglGraphicsBuffer.h index d57ec0d8b8..cc3c5fcdf3 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.h +++ b/panda/src/wgldisplay/wglGraphicsBuffer.h @@ -46,11 +46,10 @@ public: int x_size, int y_size); virtual ~wglGraphicsBuffer(); - virtual bool begin_frame(); - virtual void end_frame(); - virtual void select_cube_map(int cube_map_index); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); - virtual void make_current(); + virtual void select_cube_map(int cube_map_index); virtual void release_gsg(); virtual void begin_render_texture(); diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index 7c30bb4d78..348b4bc7a2 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -157,20 +157,26 @@ wglGraphicsWindow:: // should be skipped. //////////////////////////////////////////////////////////////////// bool wglGraphicsWindow:: -begin_frame() { +begin_frame(FrameMode mode) { + PStatTimer timer(_make_current_pcollector); + begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { return false; } - auto_resize(); - if (needs_context()) { - if (!make_context()) { - return false; - } + + wglGraphicsStateGuardian *wglgsg; + DCAST_INTO_R(wglgsg, _gsg, false); + + HGLRC context = wglgsg->get_context(_hdc); + nassertr(context, false); + wglMakeCurrent(_hdc, context); + wglgsg->reset_if_new(); + + if (mode == FM_render) { + clear_cube_map_selection(); } - make_current(); - begin_render_texture(); - clear_cube_map_selection(); + return _gsg->begin_frame(); } @@ -182,62 +188,25 @@ begin_frame() { // should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void wglGraphicsWindow:: -end_frame() { +end_frame(FrameMode mode) { + end_frame_spam(); + nassertv(_gsg != (GraphicsStateGuardian *)NULL); + + if (mode == FM_render) { + copy_to_textures(); + } + _gsg->end_frame(); - end_render_texture(); - copy_to_textures(); - trigger_flip(); - if (_one_shot) { - prepare_for_deletion(); + + if (mode == FM_render) { + trigger_flip(); + if (_one_shot) { + prepare_for_deletion(); + } + clear_cube_map_selection(); } - clear_cube_map_selection(); -} - -//////////////////////////////////////////////////////////////////// -// Function: wglGraphicsWindow::make_context -// Access: Public, Virtual -// Description: If _needs_context is true, this will be called -// in the draw thread prior to rendering into the -// window. It should attempt to create a graphics -// context, and return true if successful, false -// otherwise. If it returns false the window will be -// considered failed. -//////////////////////////////////////////////////////////////////// -bool wglGraphicsWindow:: -make_context() { - PStatTimer timer(_make_current_pcollector); - - wglGraphicsStateGuardian *wglgsg; - DCAST_INTO_R(wglgsg, _gsg, false); - - HGLRC context = wglgsg->get_context(_hdc); - if (context) { - wglMakeCurrent(_hdc, context); - wglgsg->reset_if_new(); - _needs_context = false; - return true; - } - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: wglGraphicsWindow::make_current -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// during begin_frame() to ensure the graphics context -// is ready for drawing. -//////////////////////////////////////////////////////////////////// -void wglGraphicsWindow:: -make_current() { - PStatTimer timer(_make_current_pcollector); - - wglGraphicsStateGuardian *wglgsg; - DCAST_INTO_V(wglgsg, _gsg); - HGLRC context = wglgsg->get_context(_hdc); - nassertv(context); - wglMakeCurrent(_hdc, context); } //////////////////////////////////////////////////////////////////// @@ -277,8 +246,12 @@ begin_flip() { // called. Empirically, it appears that it is not necessary in // many cases, but it definitely is necessary at least in the case // of Mesa on Windows. - make_current(); - + wglGraphicsStateGuardian *wglgsg; + DCAST_INTO_V(wglgsg, _gsg); + HGLRC context = wglgsg->get_context(_hdc); + nassertv(context); + wglMakeCurrent(_hdc, context); + SwapBuffers(_hdc); } } diff --git a/panda/src/wgldisplay/wglGraphicsWindow.h b/panda/src/wgldisplay/wglGraphicsWindow.h index 18028abbc0..5141c49af5 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.h +++ b/panda/src/wgldisplay/wglGraphicsWindow.h @@ -33,10 +33,9 @@ public: const string &name); virtual ~wglGraphicsWindow(); - virtual bool begin_frame(); - virtual void end_frame(); - virtual bool make_context(); - virtual void make_current(); + virtual bool begin_frame(FrameMode mode); + virtual void end_frame(FrameMode mode); + virtual void release_gsg(); virtual void begin_flip();