Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions src/Engine/Data/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ class CoreGeometryDisplayable : public AttribArrayDisplayable
void setAttribNameCorrespondance( const std::string& meshAttribName,
const std::string& shaderAttribName );

void autoVertexAttribCheck( const ShaderProgram* prog );

protected:
virtual void updateGL_specific_impl() {}

Expand Down Expand Up @@ -373,9 +375,9 @@ class MultiIndexedGeometry : public CoreGeometryDisplayable<T>
using LayerKeyType = std::pair<LayerSemanticCollection, std::string>;

using EntryType = std::pair<bool, VaoIndices*>;
struct RA_CORE_API KeyHash {
std::size_t operator()( const LayerKeyType& k ) const {
// Mix semantic collection into a single identifier string
struct KeyHash {
std::size_t operator()( const LayerKeyType& k )
const { // Mix semantic collection into a single identifier string
std::ostringstream stream;
std::copy(
k.first.begin(), k.first.end(), std::ostream_iterator<std::string>( stream, "" ) );
Expand All @@ -386,9 +388,9 @@ class MultiIndexedGeometry : public CoreGeometryDisplayable<T>
return std::hash<std::string> {}( result ) ^
( std::hash<std::string> {}( k.second ) << 1 );
}
}; // namespace Data
};
std::unordered_map<LayerKeyType, EntryType, KeyHash> m_indices;
}; // namespace Engine
};

/// LineMesh, own a Core::Geometry::LineMesh
class RA_ENGINE_API LineMesh : public IndexedGeometry<Core::Geometry::LineMesh>
Expand Down Expand Up @@ -787,6 +789,37 @@ void CoreGeometryDisplayable<CoreGeometry>::autoVertexAttribPointer( const Shade
}
}

template <typename CoreGeometry>
void CoreGeometryDisplayable<CoreGeometry>::autoVertexAttribCheck( 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 attribNameOpt = m_translationTable.keyIfExists( name );
if ( attribNameOpt ) {
auto attribName = *attribNameOpt;
auto attrib = m_mesh.getAttribBase( attribName );
if ( attrib && attrib->getSize() > 0 ) {
LOG( logINFO ) << "enable " << attribName << " to " << name << " " << loc;
}
else {
LOG( logINFO ) << "attribName not vaild " << attribName << " disable " << name
<< " " << loc;
}
}
else { LOG( logINFO ) << "attrib not found in table, disable " << name << " " << loc; }
}
}

template <typename T>
void CoreGeometryDisplayable<T>::loadGeometry_common( T&& mesh ) {
m_mesh = std::move( mesh );
Expand Down
7 changes: 7 additions & 0 deletions src/Engine/Data/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <ostream>
#include <utility>

#include <glm/vec4.hpp>

namespace Ra {
namespace Engine {
namespace Data {
Expand Down Expand Up @@ -342,6 +344,11 @@ void Texture::sendSamplerParametersToGpu() {
GL_CHECK_ERROR;
m_texture->setParameter( GL_TEXTURE_MAG_FILTER, m_textureParameters.sampler.magFilter );
GL_CHECK_ERROR;
if ( m_textureParameters.sampler.borderColor ) {
auto bc = *( m_textureParameters.sampler.borderColor );
auto border = glm::vec4 { bc[0], bc[1], bc[2], bc[3] };
m_texture->setParameter( GL_TEXTURE_BORDER_COLOR, border );
}
}

/// \todo template by texels type
Expand Down
3 changes: 3 additions & 0 deletions src/Engine/Data/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <variant>

Expand All @@ -30,6 +31,8 @@ struct SamplerParameters {
GLenum minFilter { GL_LINEAR };
/// OpenGL magnification filter ( GL_LINEAR or GL_NEAREST )
GLenum magFilter { GL_LINEAR };
/// Border color, if used
std::optional<Core::Utils::Color> borderColor { std::nullopt };
};

/// ImageParameters stores the infomation needed to upload a image to the GPU as a texture.
Expand Down
22 changes: 20 additions & 2 deletions tests/unittest/Engine/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ TEST_CASE( "Engine/Data/Texture", "[unittests][Engine][Engine/Data][Textures]" )
std::array<std::shared_ptr<void>, 6> data2void {
{ data2[0], data2[1], data2[2], data2[3], data2[4], data2[5] } };

TextureParameters params1 = { {}, {} };
TextureParameters params2 = { {}, {} };
TextureParameters params1 = { { "tex1" }, {}, {} };
TextureParameters params2 = { {}, {}, {} };

params1.image.texels = data1;
params2.image.target = GL_TEXTURE_CUBE_MAP;
Expand All @@ -167,6 +167,19 @@ TEST_CASE( "Engine/Data/Texture", "[unittests][Engine][Engine/Data][Textures]" )
Texture texture1( params1 );
Texture texture2( params2 );

REQUIRE( texture1.getName() == params1.name );
REQUIRE( texture1.getWidth() == 1 );
REQUIRE( texture1.getHeight() == 1 );
REQUIRE( texture1.getDepth() == 1 );
REQUIRE( texture1.getFormat() == GL_RGB );

// no border color by default
REQUIRE( !texture1.getParameters().sampler.borderColor.has_value() );

// setting a border color makes the optional borderColor has value
texture1.getParameters().sampler.borderColor = Ra::Core::Utils::Color::White();
REQUIRE( texture1.getParameters().sampler.borderColor.has_value() );

texture1.initialize();
texture2.initialize();
viewer.bindOpenGLContext( true );
Expand Down Expand Up @@ -215,6 +228,11 @@ TEST_CASE( "Engine/Data/Texture", "[unittests][Engine][Engine/Data][Textures]" )
for ( uchar i = 0; i < 3 * 4; ++i )
data1Resized[i] = i;
texture1.resize( 2, 2, 1, data1Resized );

REQUIRE( texture1.getWidth() == 2 );
REQUIRE( texture1.getHeight() == 2 );
REQUIRE( texture1.getDepth() == 1 );

readData1 = gpuTexture1->getImage( 0, params1.image.format, params1.image.type );
// see GL_PACK_ROW_LENGTH
// https://registry.khronos.org/OpenGL-Refpages/gl4/html/glPixelStore.xhtml
Expand Down
Loading