From 7b8d304aecf8e0db6b6eff2eaceb29a150cca016 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 18 Apr 2005 22:42:03 +0000 Subject: [PATCH] unify vbuffer, ibuffer --- .../glstuff/glGraphicsStateGuardian_src.cxx | 26 ++++++++++++++----- .../src/glstuff/glGraphicsStateGuardian_src.h | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 0a94edcf28..ace0bace34 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -821,6 +821,8 @@ reset() { _needs_tex_gen = false; _tex_gen_modifies_mat = false; _last_max_stage_index = 0; + _current_vbuffer_index = 0; + _current_ibuffer_index = 0; _auto_antialias_mode = false; _render_mode = RenderModeAttrib::M_filled; _point_size = 1.0f; @@ -2919,9 +2921,12 @@ apply_vertex_buffer(VertexBufferContext *vbc) { CLP(VertexBufferContext) *gvbc = DCAST(CLP(VertexBufferContext), vbc); - _glBindBuffer(GL_ARRAY_BUFFER, gvbc->_index); + if (_current_vbuffer_index != gvbc->_index) { + _glBindBuffer(GL_ARRAY_BUFFER, gvbc->_index); + _current_vbuffer_index = gvbc->_index; + add_to_vertex_buffer_record(gvbc); + } - add_to_vertex_buffer_record(gvbc); if (gvbc->was_modified()) { PStatTimer timer(_load_vertex_buffer_pcollector); int num_bytes = gvbc->get_data()->get_data_size_bytes(); @@ -2997,7 +3002,10 @@ setup_array_data(const qpGeomVertexArrayData *data) { data->get_usage_hint() == qpGeom::UH_client) { // The array specifies client rendering only, or buffer objects // are configured off. - _glBindBuffer(GL_ARRAY_BUFFER, 0); + if (_current_vbuffer_index != 0) { + _glBindBuffer(GL_ARRAY_BUFFER, 0); + _current_vbuffer_index = 0; + } return data->get_data(); } @@ -3056,9 +3064,12 @@ apply_index_buffer(IndexBufferContext *ibc) { CLP(IndexBufferContext) *gibc = DCAST(CLP(IndexBufferContext), ibc); - _glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gibc->_index); + if (_current_ibuffer_index != gibc->_index) { + _glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gibc->_index); + _current_ibuffer_index = gibc->_index; + add_to_index_buffer_record(gibc); + } - add_to_index_buffer_record(gibc); if (gibc->was_modified()) { PStatTimer timer(_load_index_buffer_pcollector); int num_bytes = gibc->get_data()->get_data_size_bytes(); @@ -3134,7 +3145,10 @@ setup_primitive(const qpGeomPrimitive *data) { data->get_usage_hint() == qpGeom::UH_client) { // The array specifies client rendering only, or buffer objects // are configured off. - _glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + if (_current_ibuffer_index != 0) { + _glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + _current_ibuffer_index = 0; + } return data->get_data(); } diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index bfc3141bbb..43fbfe0573 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -337,6 +337,8 @@ protected: bool _auto_rescale_normal; GLuint _geom_display_list; int _last_max_stage_index; + GLuint _current_vbuffer_index; + GLuint _current_ibuffer_index; int _error_count;