浏览代码

unify vbuffer, ibuffer

David Rose 20 年之前
父节点
当前提交
7b8d304aec
共有 2 个文件被更改,包括 22 次插入6 次删除
  1. 20 6
      panda/src/glstuff/glGraphicsStateGuardian_src.cxx
  2. 2 0
      panda/src/glstuff/glGraphicsStateGuardian_src.h

+ 20 - 6
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -821,6 +821,8 @@ reset() {
   _needs_tex_gen = false;
   _needs_tex_gen = false;
   _tex_gen_modifies_mat = false;
   _tex_gen_modifies_mat = false;
   _last_max_stage_index = 0;
   _last_max_stage_index = 0;
+  _current_vbuffer_index = 0;
+  _current_ibuffer_index = 0;
   _auto_antialias_mode = false;
   _auto_antialias_mode = false;
   _render_mode = RenderModeAttrib::M_filled;
   _render_mode = RenderModeAttrib::M_filled;
   _point_size = 1.0f;
   _point_size = 1.0f;
@@ -2919,9 +2921,12 @@ apply_vertex_buffer(VertexBufferContext *vbc) {
 
 
   CLP(VertexBufferContext) *gvbc = DCAST(CLP(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()) {
   if (gvbc->was_modified()) {
     PStatTimer timer(_load_vertex_buffer_pcollector);
     PStatTimer timer(_load_vertex_buffer_pcollector);
     int num_bytes = gvbc->get_data()->get_data_size_bytes();
     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) {
       data->get_usage_hint() == qpGeom::UH_client) {
     // The array specifies client rendering only, or buffer objects
     // The array specifies client rendering only, or buffer objects
     // are configured off.
     // 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();
     return data->get_data();
   }
   }
 
 
@@ -3056,9 +3064,12 @@ apply_index_buffer(IndexBufferContext *ibc) {
 
 
   CLP(IndexBufferContext) *gibc = DCAST(CLP(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()) {
   if (gibc->was_modified()) {
     PStatTimer timer(_load_index_buffer_pcollector);
     PStatTimer timer(_load_index_buffer_pcollector);
     int num_bytes = gibc->get_data()->get_data_size_bytes();
     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) {
       data->get_usage_hint() == qpGeom::UH_client) {
     // The array specifies client rendering only, or buffer objects
     // The array specifies client rendering only, or buffer objects
     // are configured off.
     // 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();
     return data->get_data();
   }
   }
 
 

+ 2 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -337,6 +337,8 @@ protected:
   bool _auto_rescale_normal;
   bool _auto_rescale_normal;
   GLuint _geom_display_list;
   GLuint _geom_display_list;
   int _last_max_stage_index;
   int _last_max_stage_index;
+  GLuint _current_vbuffer_index;
+  GLuint _current_ibuffer_index;
   
   
   int _error_count;
   int _error_count;