Skip to content

Commit 9fa1421

Browse files
committed
[engine] GeometryDisplayable updateGL (not tested).
1 parent ae71308 commit 9fa1421

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/Engine/Data/Mesh.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ bool GeometryDisplayable::addRenderLayer( LayerKeyType key, base::MeshRenderMode
287287

288288
return false;
289289
}
290+
290291
bool 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+
306344
void GeometryDisplayable::updateGL_specific_impl() {
307345
CORE_ASSERT( false, "not implemented yet" );
308346
// if ( !m_indices )

src/Engine/Data/Mesh.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class RA_ENGINE_API GeometryDisplayable : public AttribArrayDisplayable
401401
// RenderMode getRenderMode( LayerKeyType key );
402402

403403
/// Update (i.e. send to GPU) the buffers marked as dirty
404-
void updateGL() override {}
404+
void updateGL() override;
405405

406406
protected:
407407
void updateGL_specific_impl();

0 commit comments

Comments
 (0)