diff --git a/src/Engine/Data/Mesh.hpp b/src/Engine/Data/Mesh.hpp index e193909861c..781d5c2f8db 100644 --- a/src/Engine/Data/Mesh.hpp +++ b/src/Engine/Data/Mesh.hpp @@ -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() {} @@ -373,9 +375,9 @@ class MultiIndexedGeometry : public CoreGeometryDisplayable using LayerKeyType = std::pair; using EntryType = std::pair; - 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( stream, "" ) ); @@ -386,9 +388,9 @@ class MultiIndexedGeometry : public CoreGeometryDisplayable return std::hash {}( result ) ^ ( std::hash {}( k.second ) << 1 ); } - }; // namespace Data + }; std::unordered_map m_indices; -}; // namespace Engine +}; /// LineMesh, own a Core::Geometry::LineMesh class RA_ENGINE_API LineMesh : public IndexedGeometry @@ -787,6 +789,37 @@ void CoreGeometryDisplayable::autoVertexAttribPointer( const Shade } } +template +void CoreGeometryDisplayable::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 void CoreGeometryDisplayable::loadGeometry_common( T&& mesh ) { m_mesh = std::move( mesh ); diff --git a/src/Engine/Data/Texture.cpp b/src/Engine/Data/Texture.cpp index 8c5b1fcbc4d..6de203e1a87 100644 --- a/src/Engine/Data/Texture.cpp +++ b/src/Engine/Data/Texture.cpp @@ -16,6 +16,8 @@ #include #include +#include + namespace Ra { namespace Engine { namespace Data { @@ -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 diff --git a/src/Engine/Data/Texture.hpp b/src/Engine/Data/Texture.hpp index 3f7c0448d87..ba84861b736 100644 --- a/src/Engine/Data/Texture.hpp +++ b/src/Engine/Data/Texture.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -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 borderColor { std::nullopt }; }; /// ImageParameters stores the infomation needed to upload a image to the GPU as a texture. diff --git a/tests/unittest/Engine/texture.cpp b/tests/unittest/Engine/texture.cpp index e984c7abda8..cbf80f530a6 100644 --- a/tests/unittest/Engine/texture.cpp +++ b/tests/unittest/Engine/texture.cpp @@ -157,8 +157,8 @@ TEST_CASE( "Engine/Data/Texture", "[unittests][Engine][Engine/Data][Textures]" ) std::array, 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; @@ -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 ); @@ -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