Skip to content

Commit

Permalink
[engine] GeometryDisplayable updateGL (not tested).
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyr committed Apr 1, 2022
1 parent ae71308 commit 9fa1421
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/Engine/Data/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ bool GeometryDisplayable::addRenderLayer( LayerKeyType key, base::MeshRenderMode

return false;
}

bool GeometryDisplayable::removeRenderLayer( LayerKeyType key ) {
auto it = m_geomLayers.find( key );
if ( it == m_geomLayers.end() ) return false;
Expand All @@ -303,6 +304,43 @@ bool GeometryDisplayable::removeRenderLayer( LayerKeyType key ) {
return true;
}

void GeometryDisplayable::updateGL() {
if ( m_isDirty ) {
// Check that our dirty bits are consistent.
ON_ASSERT( bool dirtyTest = false; for ( auto d
: m_dataDirty ) { dirtyTest = dirtyTest || d; } );
CORE_ASSERT( dirtyTest == m_isDirty, "Dirty flags inconsistency" );
CORE_ASSERT( !( m_geom.vertices().empty() ), "No vertex." );

updateGL_specific_impl();

auto func = [this]( Ra::Core::Utils::AttribBase* b ) {
auto idx = m_handleToBuffer[b->getName()];

if ( m_dataDirty[idx] ) {
if ( !m_vbos[idx] ) { m_vbos[idx] = globjects::Buffer::create(); }
m_vbos[idx]->setData( b->getBufferSize(), b->dataPtr(), GL_DYNAMIC_DRAW );
m_dataDirty[idx] = false;
}
};

m_geom.vertexAttribs().for_each_attrib( func );

// cleanup removed attrib
for ( auto buffer : m_handleToBuffer ) {
// do not remove name from handleToBuffer to keep index ...
// we could also update handleToBuffer, m_vbos, m_dataDirty
if ( !m_geom.hasAttrib( buffer.first ) && m_vbos[buffer.second] ) {
m_vbos[buffer.second].reset( nullptr );
m_dataDirty[buffer.second] = false;
}
}

GL_CHECK_ERROR;
m_isDirty = false;
}
}

void GeometryDisplayable::updateGL_specific_impl() {
CORE_ASSERT( false, "not implemented yet" );
// if ( !m_indices )
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Data/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class RA_ENGINE_API GeometryDisplayable : public AttribArrayDisplayable
// RenderMode getRenderMode( LayerKeyType key );

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

protected:
void updateGL_specific_impl();
Expand Down

0 comments on commit 9fa1421

Please sign in to comment.