From f42935b8e9df1374572b5cc3809a2ea2e03b5551 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 3 Jun 2009 21:15:23 +0000 Subject: [PATCH] prevent GL error; fix indentation issues etc. --- panda/src/glstuff/glGraphicsBuffer_src.cxx | 26 ++++---- .../src/glstuff/glGraphicsStateGuardian_src.I | 10 +-- .../glstuff/glGraphicsStateGuardian_src.cxx | 65 ++++++++++--------- .../src/glstuff/glGraphicsStateGuardian_src.h | 4 ++ panda/src/glstuff/glmisc_src.cxx | 8 +++ panda/src/glstuff/glmisc_src.h | 2 + 6 files changed, 67 insertions(+), 48 deletions(-) diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index d0a699ff10..abbdbc6b65 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx @@ -41,8 +41,7 @@ CLP(GraphicsBuffer)(GraphicsEngine *engine, GraphicsPipe *pipe, if ( glgsg->get_supports_framebuffer_multisample() && glgsg->get_supports_framebuffer_blit() ) { _requested_multisamples = fb_prop.get_multisamples(); - } - else { + } else { _requested_multisamples = 0; } @@ -52,24 +51,22 @@ CLP(GraphicsBuffer)(GraphicsEngine *engine, GraphicsPipe *pipe, if ( (_requested_coverage_samples <= 8) && (_requested_coverage_samples > 0) ) { _requested_multisamples = 4; _requested_coverage_samples = 8; - } - else if (_requested_coverage_samples > 8) { - if (_requested_multisamples < 8) + } else if (_requested_coverage_samples > 8) { + if (_requested_multisamples < 8) { _requested_multisamples = 4; - else + } else { _requested_multisamples = 8; + } _requested_coverage_samples = 16; } - } - else { + + } else { _requested_coverage_samples = 0; } - float maxMultisamples = 0.0f; - glGetFloatv(GL_MAX_SAMPLES_EXT, &maxMultisamples); - - if (_requested_multisamples > maxMultisamples) - _requested_multisamples = maxMultisamples; + if (_requested_multisamples > glgsg->_max_fb_samples) { + _requested_multisamples = glgsg->_max_fb_samples; + } _rb_size_x = 0; _rb_size_y = 0; @@ -85,6 +82,7 @@ CLP(GraphicsBuffer)(GraphicsEngine *engine, GraphicsPipe *pipe, } _shared_depth_buffer = 0; + report_my_gl_errors(); } //////////////////////////////////////////////////////////////////// @@ -874,6 +872,7 @@ select_cube_map(int cube_map_index) { //////////////////////////////////////////////////////////////////// bool CLP(GraphicsBuffer):: open_buffer() { + report_my_gl_errors(); // Double check that we have a host nassertr(_host != 0, false); @@ -934,6 +933,7 @@ void CLP(GraphicsBuffer):: close_buffer() { check_host_valid(); + report_my_gl_errors(); _active = false; if (_gsg == 0) { diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.I b/panda/src/glstuff/glGraphicsStateGuardian_src.I index f9bf2bbd88..b20157fe8c 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.I +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.I @@ -45,10 +45,12 @@ report_errors(int line, const char *source_file) { INLINE void CLP(GraphicsStateGuardian):: report_my_errors(int line, const char *source_file) { #ifndef NDEBUG - GLenum error_code = gl_get_error(); - if (error_code != GL_NO_ERROR) { - if (!report_errors_loop(line, source_file, error_code, _error_count)) { - panic_deactivate(); + if (_track_errors) { + GLenum error_code = gl_get_error(); + if (error_code != GL_NO_ERROR) { + if (!report_errors_loop(line, source_file, error_code, _error_count)) { + panic_deactivate(); + } } } #endif diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index c65fb386ba..87dad6aa41 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -75,10 +75,6 @@ PStatCollector CLP(GraphicsStateGuardian)::_primitive_batches_display_list_pcoll PStatCollector CLP(GraphicsStateGuardian)::_vertices_display_list_pcollector("Vertices:Display lists"); PStatCollector CLP(GraphicsStateGuardian)::_vertices_immediate_pcollector("Vertices:Immediate mode"); -// KZL hack. These track PRC settings. -bool _track_errors = 1; -bool _allow_flush = 1; - // The following noop functions are assigned to the corresponding // glext function pointers in the class, in case the functions are not // defined by the GL, just so it will always be safe to call the @@ -273,6 +269,10 @@ CLP(GraphicsStateGuardian)(GraphicsEngine *engine, GraphicsPipe *pipe) : // the window tells us otherwise. _is_hardware = true; + // calling glGetError() forces a sync, this turns it off if you want to. + _track_errors = !CLP(force_no_error); + _allow_flush = !CLP(force_no_flush); + #ifdef DO_PSTATS if (CLP(finish)) { GLCAT.warning() @@ -824,22 +824,25 @@ reset() { get_extension_func(GLPREFIX_QUOTED, "GenerateMipmapEXT"); } + _supports_framebuffer_multisample = false; if ( has_extension("GL_EXT_framebuffer_multisample") ) { _supports_framebuffer_multisample = true; _glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) - get_extension_func(GLPREFIX_QUOTED, "RenderbufferStorageMultisampleEXT"); + get_extension_func(GLPREFIX_QUOTED, "RenderbufferStorageMultisampleEXT"); } + _supports_framebuffer_multisample_coverage_nv = false; if ( has_extension("GL_NV_framebuffer_multisample_coverage") ) { _supports_framebuffer_multisample_coverage_nv = true; _glRenderbufferStorageMultisampleCoverage = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) - get_extension_func(GLPREFIX_QUOTED, "RenderbufferStorageMultisampleCoverageNV"); + get_extension_func(GLPREFIX_QUOTED, "RenderbufferStorageMultisampleCoverageNV"); } + _supports_framebuffer_blit = false; if ( has_extension("GL_EXT_framebuffer_blit") ) { _supports_framebuffer_blit = true; _glBlitFramebuffer = (PFNGLBLITFRAMEBUFFEREXTPROC) - get_extension_func(GLPREFIX_QUOTED, "BlitFramebufferEXT"); + get_extension_func(GLPREFIX_QUOTED, "BlitFramebufferEXT"); } _glDrawBuffers = NULL; @@ -858,6 +861,13 @@ reset() { _maximum_simultaneous_render_targets = max_draw_buffers; } + _max_fb_samples = 0; + if (_supports_framebuffer_multisample) { + GLfloat max_samples; + GLP(GetFloatv)(GL_MAX_SAMPLES_EXT, &max_samples); + _max_fb_samples = max_samples; + } + _supports_occlusion_query = false; if (CLP(support_occlusion_query)) { if (is_at_least_gl_version(1, 5)) { @@ -1175,16 +1185,6 @@ reset() { #endif // OPENGLES_1 _dithering_enabled = false; - // calling glGetError() forces a sync, this turns it off if you want to. - if (ConfigVariableBool("gl-force-no-error", false, PRC_DESC("make the gl GSG not report errors, as doing so is a performance hit."))) - _track_errors = false; - else - _track_errors = true; - if (ConfigVariableBool("gl-force-no-flush", false, PRC_DESC("make the gl GSG not flush, as doing so is a performance hit. This is a dangerour setting."))) - _allow_flush = false; - else - _allow_flush = true; - _current_shader = (Shader *)NULL; _current_shader_context = (CLP(ShaderContext) *)NULL; _vertex_array_shader = (Shader *)NULL; @@ -1365,13 +1365,14 @@ reset() { void CLP(GraphicsStateGuardian):: clear(DrawableRegion *clearable) { PStatTimer timer(_clear_pcollector); + report_my_gl_errors(); if ((!clearable->get_clear_color_active())&& (!clearable->get_clear_depth_active())&& (!clearable->get_clear_stencil_active())) { return; } - + set_state_and_transform(RenderState::make_empty(), _internal_transform); int mask = 0; @@ -1603,6 +1604,7 @@ begin_frame(Thread *current_thread) { if (!GraphicsStateGuardian::begin_frame(current_thread)) { return false; } + report_my_gl_errors(); #ifdef DO_PSTATS _vertices_display_list_pcollector.clear_level(); @@ -1705,6 +1707,7 @@ end_scene() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: end_frame(Thread *current_thread) { + report_my_gl_errors(); #ifdef DO_PSTATS // Check for textures, etc., that are no longer resident. These // calls might be measurably expensive, and they don't have any @@ -4540,8 +4543,9 @@ draw_immediate_composite_primitives(const GeomPrimitivePipelineReader *reader, G void CLP(GraphicsStateGuardian):: gl_flush() const { PStatTimer timer(_flush_pcollector); - if (_allow_flush) - GLP(Flush)(); + if (_allow_flush) { + GLP(Flush)(); + } } //////////////////////////////////////////////////////////////////// @@ -4551,10 +4555,11 @@ gl_flush() const { //////////////////////////////////////////////////////////////////// GLenum CLP(GraphicsStateGuardian):: gl_get_error() const { - if (_track_errors) - return GLP(GetError)(); - else - return GL_NO_ERROR; + if (_track_errors) { + return GLP(GetError)(); + } else { + return GL_NO_ERROR; + } } //////////////////////////////////////////////////////////////////// @@ -4568,8 +4573,6 @@ gl_get_error() const { bool CLP(GraphicsStateGuardian):: report_errors_loop(int line, const char *source_file, GLenum error_code, int &error_count) { - if (!_track_errors) - return GL_NO_ERROR; #ifndef NDEBUG while ((CLP(max_errors) < 0 || error_count < CLP(max_errors)) && (error_code != GL_NO_ERROR)) { @@ -6252,6 +6255,7 @@ end_bind_clip_planes() { void CLP(GraphicsStateGuardian):: set_state_and_transform(const RenderState *target, const TransformState *transform) { + report_my_gl_errors(); #ifndef NDEBUG if (gsg_cat.is_spam()) { gsg_cat.spam() << "Setting GSG state to " << (void *)target << ":\n"; @@ -8652,16 +8656,15 @@ extract_texture_image(PTA_uchar &image, size_t &page_size, } // Now see if we were successful. - if (_track_errors) - { + if (_track_errors) { GLenum error_code = GLP(GetError)(); if (error_code != GL_NO_ERROR) { - GLCAT.error() + GLCAT.error() << "Unable to extract texture for " << *tex << ", mipmap level " << n << " : " << get_error_string(error_code) << "\n"; - nassertr(false, false); - return false; + nassertr(false, false); + return false; } } return true; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index ff09675c1c..d24100bd62 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -518,6 +518,7 @@ public: PFNGLBLITFRAMEBUFFEREXTPROC _glBlitFramebuffer; PFNGLDRAWBUFFERSPROC _glDrawBuffers; int _max_draw_buffers; + int _max_fb_samples; PFNGLGENQUERIESPROC _glGenQueries; PFNGLBEGINQUERYPROC _glBeginQuery; @@ -542,6 +543,9 @@ public: RenderState::SlotMask _inv_state_mask; + bool _track_errors; + bool _allow_flush; + #ifndef NDEBUG bool _show_texture_usage; int _show_texture_usage_max_size; diff --git a/panda/src/glstuff/glmisc_src.cxx b/panda/src/glstuff/glmisc_src.cxx index 0f8e4195de..ff7532b456 100644 --- a/panda/src/glstuff/glmisc_src.cxx +++ b/panda/src/glstuff/glmisc_src.cxx @@ -148,6 +148,14 @@ ConfigVariableBool CLP(matrix_palette) ("gl-matrix-palette", false, PRC_DESC("Temporary hack variable protecting untested code. See glGraphicsStateGuardian_src.cxx.")); +ConfigVariableBool CLP(force_no_error) + ("gl-force-no-error", false, + PRC_DESC("Avoid reporting OpenGL errors, for a small performance benefit.")); + +ConfigVariableBool CLP(force_no_flush) + ("gl-force-no-flush", false, + PRC_DESC("Avoid calling glFlush(), for a potential performance benefit. This may be a little dangerous.")); + 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 45c62a5329..053b1d4567 100644 --- a/panda/src/glstuff/glmisc_src.h +++ b/panda/src/glstuff/glmisc_src.h @@ -39,6 +39,8 @@ extern ConfigVariableBool CLP(debug_buffers); extern ConfigVariableBool CLP(finish); extern ConfigVariableBool CLP(force_depth_stencil); extern ConfigVariableBool CLP(matrix_palette); +extern ConfigVariableBool CLP(force_no_error); +extern ConfigVariableBool CLP(force_no_flush); extern EXPCL_GL void CLP(init_classes)();