From aaa4e1222350bf9dd03ba68012f0e9e38a85f30e Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 10 Apr 2008 20:18:20 +0000 Subject: [PATCH] gl-finish --- panda/src/glstuff/glGraphicsStateGuardian_src.I | 15 +++++++++++++++ panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 15 +++++++++++++++ panda/src/glstuff/glGraphicsStateGuardian_src.h | 1 + panda/src/glstuff/glmisc_src.cxx | 8 ++++++++ panda/src/glstuff/glmisc_src.h | 1 + 5 files changed, 40 insertions(+) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.I b/panda/src/glstuff/glGraphicsStateGuardian_src.I index 7708415325..bd6b1cf7af 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.I +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.I @@ -145,6 +145,21 @@ get_gl_version_release() const { return _gl_version_release; } +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::maybe_gl_finish +// Access: Protected +// Description: Calls glFinish() if the config variable gl-finish is +// set True. +//////////////////////////////////////////////////////////////////// +INLINE void CLP(GraphicsStateGuardian):: +maybe_gl_finish() const { +#ifdef DO_PSTATS + if (CLP(finish)) { + GLP(Finish)(); + } +#endif +} + //////////////////////////////////////////////////////////////////// // Function: CLP(GraphicsStateGuardian)::enable_multisample_antialias // Access: Protected diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index fa61316b58..5ca29f2031 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -253,6 +253,13 @@ CLP(GraphicsStateGuardian)(GraphicsPipe *pipe) : // since we know this works properly in OpenGL, and we want the // performance benefit it gives us. _prepared_objects->_support_released_buffer_cache = true; + +#ifdef DO_PSTATS + if (CLP(finish)) { + GLCAT.warning() + << "The config variable gl-finish is set True. This may have a substantial negative impact your render performance.\n"; + } +#endif // DO_PSTATS } //////////////////////////////////////////////////////////////////// @@ -1686,6 +1693,7 @@ end_frame(Thread *current_thread) { // will be finished drawing before we return to the application. // It's not clear what effect this has on our total frame time. gl_flush(); + maybe_gl_finish(); report_my_gl_errors(); } @@ -2567,6 +2575,7 @@ end_draw_primitives() { } GraphicsStateGuardian::end_draw_primitives(); + maybe_gl_finish(); report_my_gl_errors(); } @@ -3032,6 +3041,7 @@ apply_vertex_buffer(VertexBufferContext *vbc, gvbc->mark_loaded(reader); } + maybe_gl_finish(); report_my_gl_errors(); return true; } @@ -3217,6 +3227,7 @@ apply_index_buffer(IndexBufferContext *ibc, gibc->mark_loaded(reader); } + maybe_gl_finish(); report_my_gl_errors(); return true; } @@ -6206,6 +6217,8 @@ set_state_and_transform(const RenderState *target, } _state_rs = _target_rs; + maybe_gl_finish(); + report_my_gl_errors(); } //////////////////////////////////////////////////////////////////// @@ -7079,6 +7092,8 @@ upload_texture(CLP(TextureContext) *gtc) { false, 0, image_compression); } + maybe_gl_finish(); + if (success) { gtc->_already_applied = true; gtc->_uses_mipmaps = uses_mipmaps; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 31acde2617..c857d9f048 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -245,6 +245,7 @@ protected: void do_issue_stencil(); virtual void gl_flush() const; + INLINE void maybe_gl_finish() const; virtual GLenum gl_get_error() const; static bool report_errors_loop(int line, const char *source_file, diff --git a/panda/src/glstuff/glmisc_src.cxx b/panda/src/glstuff/glmisc_src.cxx index 4f4422240c..fe292360e5 100644 --- a/panda/src/glstuff/glmisc_src.cxx +++ b/panda/src/glstuff/glmisc_src.cxx @@ -121,6 +121,14 @@ ConfigVariableBool CLP(debug_buffers) "glgsg, to enable debug messages about the creation and " "destruction of OpenGL vertex buffers.")); +ConfigVariableBool CLP(finish) + ("gl-finish", false, + PRC_DESC("Set this true to force a call to glFinish() after every major " + "graphics operation. This is likely to slow down rendering " + "performance substantially, but it will make PStats graphs " + "more accurately reflect where the graphics bottlenecks are. " + "This variable is enabled only if PStats is compiled in.")); + extern ConfigVariableBool CLP(parallel_arrays); void CLP(init_classes)() { diff --git a/panda/src/glstuff/glmisc_src.h b/panda/src/glstuff/glmisc_src.h index 0c95323a3d..36293751df 100644 --- a/panda/src/glstuff/glmisc_src.h +++ b/panda/src/glstuff/glmisc_src.h @@ -38,6 +38,7 @@ extern ConfigVariableBool CLP(parallel_arrays); extern ConfigVariableInt CLP(max_errors); extern ConfigVariableEnum CLP(min_buffer_usage_hint); extern ConfigVariableBool CLP(debug_buffers); +extern ConfigVariableBool CLP(finish); extern EXPCL_GL void CLP(init_classes)();