From 78a08bafcdb9f2ff861a545d158544844fa73160 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 19 Oct 2007 15:35:43 +0000 Subject: [PATCH] gl-min-buffer-usage-hint, gl-debug-buffers --- .../glstuff/glGraphicsStateGuardian_src.cxx | 32 +++++++++---------- panda/src/glstuff/glmisc_src.cxx | 21 ++++++++++++ panda/src/glstuff/glmisc_src.h | 5 +++ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 143a230520..a7b4366648 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -57,8 +57,6 @@ #include -#define DEBUG_BUFFERS false - TypeHandle CLP(GraphicsStateGuardian)::_type_handle; PStatCollector CLP(GraphicsStateGuardian)::_load_display_list_pcollector("Draw:Transfer data:Display lists"); @@ -1644,8 +1642,8 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, // Before we compile or call a display list, make sure the current // buffers are unbound, or the nVidia drivers may crash. if (_current_vbuffer_index != 0) { - if (GLCAT.is_spam()) { - GLCAT.spam() + if (GLCAT.is_debug() && CLP(debug_buffers)) { + GLCAT.debug() << "unbinding vertex buffer\n"; } _glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -2770,7 +2768,7 @@ prepare_vertex_buffer(GeomVertexArrayData *data) { CLP(VertexBufferContext) *gvbc = new CLP(VertexBufferContext)(_prepared_objects, data); _glGenBuffers(1, &gvbc->_index); - if (DEBUG_BUFFERS && GLCAT.is_debug()) { + if (GLCAT.is_debug() && CLP(debug_buffers)) { GLCAT.debug() << "creating vertex buffer " << gvbc->_index << ": " << data->get_num_rows() << " vertices " @@ -2799,8 +2797,8 @@ apply_vertex_buffer(VertexBufferContext *vbc, CLP(VertexBufferContext) *gvbc = DCAST(CLP(VertexBufferContext), vbc); if (_current_vbuffer_index != gvbc->_index) { - if (GLCAT.is_spam()) { - GLCAT.spam() + if (GLCAT.is_debug() && CLP(debug_buffers)) { + GLCAT.debug() << "binding vertex buffer " << gvbc->_index << "\n"; } _glBindBuffer(GL_ARRAY_BUFFER, gvbc->_index); @@ -2810,8 +2808,8 @@ apply_vertex_buffer(VertexBufferContext *vbc, if (gvbc->was_modified(reader)) { int num_bytes = reader->get_data_size_bytes(); - if (GLCAT.is_spam()) { - GLCAT.spam() + if (GLCAT.is_debug() && CLP(debug_buffers)) { + GLCAT.debug() << "copying " << num_bytes << " bytes into vertex buffer " << gvbc->_index << "\n"; } @@ -2853,7 +2851,7 @@ release_vertex_buffer(VertexBufferContext *vbc) { CLP(VertexBufferContext) *gvbc = DCAST(CLP(VertexBufferContext), vbc); - if (DEBUG_BUFFERS && GLCAT.is_debug()) { + if (GLCAT.is_debug() && CLP(debug_buffers)) { GLCAT.debug() << "deleting vertex buffer " << gvbc->_index << "\n"; } @@ -2863,8 +2861,8 @@ release_vertex_buffer(VertexBufferContext *vbc) { // help out a flaky driver, and we need to keep our internal state // consistent anyway. if (_current_vbuffer_index == gvbc->_index) { - if (GLCAT.is_spam()) { - GLCAT.spam() + if (GLCAT.is_debug() && CLP(debug_buffers)) { + GLCAT.debug() << "unbinding vertex buffer\n"; } _glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -2907,12 +2905,12 @@ setup_array_data(const unsigned char *&client_pointer, return (client_pointer != NULL); } if (!vertex_buffers || _geom_display_list != 0 || - array_reader->get_usage_hint() == Geom::UH_client) { + array_reader->get_usage_hint() < CLP(min_buffer_usage_hint)) { // The array specifies client rendering only, or buffer objects // are configured off. if (_current_vbuffer_index != 0) { - if (GLCAT.is_spam()) { - GLCAT.spam() + if (GLCAT.is_debug() && CLP(debug_buffers)) { + GLCAT.debug() << "unbinding vertex buffer\n"; } _glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -2953,7 +2951,7 @@ prepare_index_buffer(GeomPrimitive *data) { CLP(IndexBufferContext) *gibc = new CLP(IndexBufferContext)(_prepared_objects, data); _glGenBuffers(1, &gibc->_index); - if (DEBUG_BUFFERS && GLCAT.is_debug()) { + if (GLCAT.is_debug() && CLP(debug_buffers)) { GLCAT.debug() << "creating index buffer " << gibc->_index << ": " << data->get_num_vertices() << " indices (" @@ -3038,7 +3036,7 @@ release_index_buffer(IndexBufferContext *ibc) { CLP(IndexBufferContext) *gibc = DCAST(CLP(IndexBufferContext), ibc); - if (DEBUG_BUFFERS && GLCAT.is_debug()) { + if (GLCAT.is_debug() && CLP(debug_buffers)) { GLCAT.debug() << "deleting index buffer " << gibc->_index << "\n"; } diff --git a/panda/src/glstuff/glmisc_src.cxx b/panda/src/glstuff/glmisc_src.cxx index 02ac9654ce..4f4422240c 100644 --- a/panda/src/glstuff/glmisc_src.cxx +++ b/panda/src/glstuff/glmisc_src.cxx @@ -100,6 +100,27 @@ ConfigVariableInt CLP(max_errors) "detect and report before it shuts down rendering. Set it to " "-1 for no limit.")); +ConfigVariableEnum CLP(min_buffer_usage_hint) + ("gl-min-buffer-usage-hint", GeomEnums::UH_stream, + PRC_DESC("This specifies the first usage hint value that will be " + "loaded as a vertex buffer, instead of directly from the " + "client. Normally, this should be \"stream\", which means " + "to load the vertex buffer using GL_STREAM_DRAW. If this " + "is set to \"dynamic\", or \"static\", then only usage hints " + "at that level or higher will be loaded as a vertex buffer, " + "and stream or lower will be rendered directly from the " + "client array. If changing this results in a remarkable " + "performance improvement, you may have code that is " + "creating and destroying vertex buffers every frame, instead " + "of reusing the same buffers. Consider increasing " + "released-vbuffer-cache-size instead.")); + +ConfigVariableBool CLP(debug_buffers) + ("gl-debug-buffers", false, + PRC_DESC("Set this true, in addition to enabling debug notify for " + "glgsg, to enable debug messages about the creation and " + "destruction of OpenGL vertex buffers.")); + 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 a152b152b1..0c95323a3d 100644 --- a/panda/src/glstuff/glmisc_src.h +++ b/panda/src/glstuff/glmisc_src.h @@ -18,6 +18,9 @@ #include "pandabase.h" #include "configVariableBool.h" +#include "configVariableInt.h" +#include "configVariableEnum.h" +#include "geomEnums.h" //#define GSG_VERBOSE 1 @@ -33,6 +36,8 @@ extern ConfigVariableBool CLP(compile_and_execute); extern ConfigVariableBool CLP(interleaved_arrays); extern ConfigVariableBool CLP(parallel_arrays); extern ConfigVariableInt CLP(max_errors); +extern ConfigVariableEnum CLP(min_buffer_usage_hint); +extern ConfigVariableBool CLP(debug_buffers); extern EXPCL_GL void CLP(init_classes)();