Skip to content

Commit

Permalink
Visibility update wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Dec 12, 2024
1 parent 0b6d4eb commit 5de2edd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
17 changes: 11 additions & 6 deletions lib/renderer/include/renderer/context/gl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ namespace VTX::Renderer::Context::GL

template<typename T>
inline void setSub(
const T & p_data,
const GLintptr p_offset = GLintptr( 0 ),
const GLsizei p_size = GLsizei( sizeof( T ) )
const T & p_data,
const GLint p_offset = GLint( 0 ),
const GLsizei p_size = GLsizei( sizeof( T ) )
) const
{
assert( glIsBuffer( _id ) );
Expand All @@ -164,16 +164,21 @@ namespace VTX::Renderer::Context::GL
}

template<typename T>
inline void setSub( const std::vector<T> & p_vector, const GLintptr p_offset = GLintptr( 0 ) ) const
inline void setSub(
const std::vector<T> & p_vector,
const GLint p_offset = GLint( 0 ),
const bool p_offsetSource = false,
const GLsizei p_size = 0
) const
{
assert( glIsBuffer( _id ) );
assert( _size > 0 );

GLsizei size = GLsizei( sizeof( T ) * p_vector.size() );
GLsizei size = not p_size ? GLsizei( sizeof( T ) * p_vector.size() ) : p_size;

assert( p_offset + size <= _size );

glNamedBufferSubData( _id, p_offset, size, p_vector.data() );
glNamedBufferSubData( _id, p_offset, size, p_vector.data() + ( p_offsetSource ? p_offset : 0 ) );
}

template<typename T>
Expand Down
17 changes: 14 additions & 3 deletions lib/renderer/include/renderer/context/opengl_45.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ namespace VTX::Renderer::Context
assert( _bufferValueEntries.contains( p_key ) );

std::unique_ptr<_StructBufferDataValueEntry> & entry = _bufferValueEntries[ p_key ];
entry->buffer->setSub( p_value, entry->offset + p_index * entry->totalSize, GLsizei( entry->size ) );
entry->buffer->setSub(
p_value, GLint( entry->offset + p_index * entry->totalSize ), GLsizei( entry->size )
);
}

/**
Expand Down Expand Up @@ -125,11 +127,20 @@ namespace VTX::Renderer::Context
* @brief Send data to an existing GPU buffer.
*/
template<typename T>
inline void setSub( const std::vector<T> & p_data, const Key & p_key, const size_t p_offset = 0 )
inline void setSub(
const std::vector<T> & p_data,
const Key & p_key,
const size_t p_offset = 0,
const bool p_offsetSource = false,
const size_t p_size = 0
)
{
VTX_DEBUG( "Set sub buffer {} : {} -> {}", p_key, p_offset, p_size );
assert( _buffers.contains( p_key ) );

_buffers[ p_key ]->setSub( p_data, GLintptr( p_offset * sizeof( T ) ) );
_buffers[ p_key ]->setSub(
p_data, GLint( p_offset * sizeof( T ) ), p_offsetSource, GLsizei( p_size * sizeof( T ) )
);
}

/**
Expand Down
16 changes: 13 additions & 3 deletions lib/renderer/src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ namespace VTX::Renderer
}

return;
///////////////////// COMPUTE
///////////////////// COMPUTE TEST ///////////////////////
uint size = 10000;

std::vector<Vec4f> readData( size, Vec4f( 1.f, 2.f, 3.f, 4.f ) );
Expand Down Expand Up @@ -486,6 +486,7 @@ namespace VTX::Renderer
{
Cache::SphereCylinder & cacheSC = _cacheSpheresCylinders[ &p_proxy ];
uchar mask = 1 << E_ELEMENT_FLAGS::VISIBILITY;

for ( auto it = p_atomIds.rangeBegin(); it != p_atomIds.rangeEnd(); ++it )
{
for ( uint i = it->getFirst(); i <= it->getLast(); ++i )
Expand All @@ -494,12 +495,21 @@ namespace VTX::Renderer
cacheSC.flags[ i ] |= p_visible << E_ELEMENT_FLAGS::VISIBILITY;
}
}
_context->setSub( cacheSC.flags, "SpheresCylindersFlags", cacheSC.rangeSpheres.getFirst() );

const size_t offset = cacheSC.rangeSpheres.getFirst();

_context->setSub(
cacheSC.flags,
"SpheresCylindersFlags",
offset + p_atomIds.getFirst(),
false,
p_atomIds.getLast() - p_atomIds.getFirst() + 1
);

// TODO: ribbons.
};

// TODO:
// TODO:<
// onAtomVisibilities
// onAtomSelections
// onAtomRepresentations
Expand Down
1 change: 1 addition & 0 deletions lib/util/include/util/generic/base_nameable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace VTX::Util::Generic
{
// TODO: remove or use concept.
class BaseNameable
{
public:
Expand Down

0 comments on commit 5de2edd

Please sign in to comment.