Skip to content

Commit

Permalink
[engine] Remove unused class IndexedAttribArrayDisplayable
Browse files Browse the repository at this point in the history
  • Loading branch information
nmellado committed Jul 19, 2021
1 parent 3a290fb commit fa260e4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 155 deletions.
26 changes: 0 additions & 26 deletions src/Engine/Data/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,6 @@ class RA_ENGINE_API VaoIndices
size_t m_numElements { 0 };
};

/// This class handles an attrib array displayable on gpu only, without core
/// geometry. Use only when you don't need to access the cpu geometry again, or
/// when you need to specify special indices.
template <typename I>
class IndexedAttribArrayDisplayable : public AttribArrayDisplayable, public VaoIndices
{
using IndexType = I;
using IndexContainerType = Ra::Core::AlignedStdVector<IndexType>;

template <typename T>
inline void addAttrib( const std::string& name,
const typename Ra::Core::Utils::Attrib<T>::Container& data );
template <typename T>
inline void addAttrib( const std::string& name,
const typename Ra::Core ::Utils::Attrib<T>::Container&& data );
inline void updateGL() override;

inline void render( const ShaderProgram* prog ) override;

protected:
/// assume m_vao is bound.
inline void autoVertexAttribPointer( const ShaderProgram* prog );
IndexContainerType m_cpu_indices;
AttribManager m_attribManager;
};

/// Template class to manage the Displayable aspect of a Core Geomertry, such as TriangleMesh.
template <typename T>
class CoreGeometryDisplayable : public AttribArrayDisplayable
Expand Down
129 changes: 0 additions & 129 deletions src/Engine/Data/Mesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -40,135 +40,6 @@ void VaoIndices::setIndicesDirty() {
m_indicesDirty = true;
}

///////////////// IndexedAttribArrayDisplayable ///////////////////////

template <typename I>
template <typename T>
void IndexedAttribArrayDisplayable<I>::addAttrib(
const std::string& name,
const typename Ra::Core::Utils::Attrib<T>::Container& data ) {
auto handle = m_attribManager.addAttrib<T>( name );
m_attribManager.getAttrib( handle ).setData( data );
m_handleToBuffer[name] = m_dataDirty.size();
m_dataDirty.push_back( true );
m_vbos.emplace_back( nullptr );
m_isDirty = true;
}

template <typename I>
template <typename T>
void IndexedAttribArrayDisplayable<I>::addAttrib(
const std::string& name,
const typename Ra::Core ::Utils::Attrib<T>::Container&& data ) {
auto handle = m_attribManager.addAttrib<T>( name );
m_attribManager.getAttrib( handle ).setData( std::move( data ) );
m_handleToBuffer[name] = m_dataDirty.size();
m_dataDirty.push_back( true );
m_vbos.emplace_back( nullptr );
m_isDirty = true;
}

template <typename I>
void IndexedAttribArrayDisplayable<I>::updateGL() {
if ( m_isDirty )
{
// Check that our dirty bits are consistent.
ON_ASSERT( bool dirtyTest = false; for ( const auto& d
: m_dataDirty ) { dirtyTest = dirtyTest || d; } );
CORE_ASSERT( dirtyTest == m_isDirty, "Dirty flags inconsistency" );

if ( !m_indices )
{
m_indices = globjects::Buffer::create();
m_indicesDirty = true;
}
if ( m_indicesDirty )
{
m_indices->setData(
static_cast<gl::GLsizeiptr>( m_cpu_indices.size() * sizeof( IndexType ) ),
m_cpu_indices.data(),
GL_STATIC_DRAW );
m_indicesDirty = false;
}

m_numElements = m_cpu_indices.size();

if ( !m_vao ) { m_vao = globjects::VertexArray::create(); }
m_vao->bind();
m_vao->bindElementBuffer( m_indices.get() );
m_vao->unbind();

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_attribManager.for_each_attrib( func );
GL_CHECK_ERROR;
m_isDirty = false;
}
}

template <typename I>
void IndexedAttribArrayDisplayable<I>::autoVertexAttribPointer( const ShaderProgram* prog ) {

auto glprog = prog->getProgramObject();
gl::GLint attribCount = glprog->get( GL_ACTIVE_ATTRIBUTES );

for ( GLint idx = 0; idx < attribCount; ++idx )
{
const gl::GLsizei bufSize = 256;
gl::GLchar name[bufSize];
gl::GLsizei length;
gl::GLint size;
gl::GLenum type;
glprog->getActiveAttrib( idx, bufSize, &length, &size, &type, name );
auto loc = glprog->getAttributeLocation( name );

auto attribName = name; // m_translationTableShaderToMesh[name];
auto attrib = m_attribManager.getAttribBase( attribName );

if ( attrib && attrib->getSize() > 0 )
{
m_vao->enable( loc );
auto binding = m_vao->binding( idx );
binding->setAttribute( loc );
CORE_ASSERT( m_vbos[m_handleToBuffer[attribName]].get(), "vbo is nullptr" );
#ifdef CORE_USE_DOUBLE
binding->setBuffer( m_vbos[m_handleToBuffer[attribName]].get(),
0,
attrib->getElementSize() * sizeof( float ) );
#else

binding->setBuffer(
m_vbos[m_handleToBuffer[attribName]].get(), 0, attrib->getStride() );
#endif
binding->setFormat( attrib->getElementSize(), GL_SCALAR );
}
else
{ m_vao->disable( loc ); }
}
}

template <typename I>
void IndexedAttribArrayDisplayable<I>::render( const ShaderProgram* prog ) {
if ( m_vao )
{
autoVertexAttribPointer( prog );
m_vao->bind();
m_vao->drawElements( static_cast<GLenum>( m_renderMode ),
GLsizei( m_numElements ),
GL_UNSIGNED_INT,
nullptr );
m_vao->unbind();
}
}

//////////////// CoreGeometryDisplayable ///////////////////////////////

template <typename CoreGeometry>
Expand Down

0 comments on commit fa260e4

Please sign in to comment.