@@ -287,6 +287,7 @@ bool GeometryDisplayable::addRenderLayer( LayerKeyType key, base::MeshRenderMode
287287
288288 return false ;
289289}
290+
290291bool GeometryDisplayable::removeRenderLayer ( LayerKeyType key ) {
291292 auto it = m_geomLayers.find ( key );
292293 if ( it == m_geomLayers.end () ) return false ;
@@ -303,6 +304,43 @@ bool GeometryDisplayable::removeRenderLayer( LayerKeyType key ) {
303304 return true ;
304305}
305306
307+ void GeometryDisplayable::updateGL () {
308+ if ( m_isDirty ) {
309+ // Check that our dirty bits are consistent.
310+ ON_ASSERT ( bool dirtyTest = false ; for ( auto d
311+ : m_dataDirty ) { dirtyTest = dirtyTest || d; } );
312+ CORE_ASSERT ( dirtyTest == m_isDirty, " Dirty flags inconsistency" );
313+ CORE_ASSERT ( !( m_geom.vertices ().empty () ), " No vertex." );
314+
315+ updateGL_specific_impl ();
316+
317+ auto func = [this ]( Ra::Core::Utils::AttribBase* b ) {
318+ auto idx = m_handleToBuffer[b->getName ()];
319+
320+ if ( m_dataDirty[idx] ) {
321+ if ( !m_vbos[idx] ) { m_vbos[idx] = globjects::Buffer::create (); }
322+ m_vbos[idx]->setData ( b->getBufferSize (), b->dataPtr (), GL_DYNAMIC_DRAW );
323+ m_dataDirty[idx] = false ;
324+ }
325+ };
326+
327+ m_geom.vertexAttribs ().for_each_attrib ( func );
328+
329+ // cleanup removed attrib
330+ for ( auto buffer : m_handleToBuffer ) {
331+ // do not remove name from handleToBuffer to keep index ...
332+ // we could also update handleToBuffer, m_vbos, m_dataDirty
333+ if ( !m_geom.hasAttrib ( buffer.first ) && m_vbos[buffer.second ] ) {
334+ m_vbos[buffer.second ].reset ( nullptr );
335+ m_dataDirty[buffer.second ] = false ;
336+ }
337+ }
338+
339+ GL_CHECK_ERROR ;
340+ m_isDirty = false ;
341+ }
342+ }
343+
306344void GeometryDisplayable::updateGL_specific_impl () {
307345 CORE_ASSERT ( false , " not implemented yet" );
308346 // if ( !m_indices )
0 commit comments