diff --git a/include/ngl/Shader.h b/include/ngl/Shader.h index c3363f8e..13bff265 100644 --- a/include/ngl/Shader.h +++ b/include/ngl/Shader.h @@ -146,10 +146,6 @@ class NGL_DLLEXPORT Shader //---------------------------------------------------------------------------------------------------------------------- bool m_compiled = false; //---------------------------------------------------------------------------------------------------------------------- - /// @brief what type of shader we are - //---------------------------------------------------------------------------------------------------------------------- - ShaderType m_shaderType; - //---------------------------------------------------------------------------------------------------------------------- /// @brief the GL handle for this shader object used in linking etc //---------------------------------------------------------------------------------------------------------------------- GLuint m_shaderHandle; diff --git a/sonar-project.properties b/sonar-project.properties index cb15cec7..cf3c2b8b 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -8,5 +8,5 @@ sonar.cfamily.cache.enabled=false sonar.coverage.exclusions = ./tests/files/* ./src/ngl/* ./src/shaders/* sonar.c.file.suffixes=- -sonar.cpp.file.suffixes=.cc,.cpp,.cxx,.c++,.hh,.hpp,.hxx,.h++,.ipp,.c,.h +sonar.cpp.file.suffixes=.cc,.cpp,.cxx,.c++,.hh,.hpp,.hxx,.h++,.ipp,.c,.h,.inl sonar.cfamily.reportingCppStandardOverride=c++17 diff --git a/src/Image.cpp b/src/Image.cpp index cbef2712..0bb08bed 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -103,7 +103,7 @@ Vec4 Image::getColour(const GLuint _x, const GLuint _y) const noexcept NGL_ASSERT(_x <= m_width && _y <= m_height) if(m_data != nullptr) { - auto offset = _x * m_channels + ((_y)*m_width * m_channels); + auto offset = _x * m_channels + (_y*m_width * m_channels); if(m_channels == 3) { return Vec4(m_data[offset], m_data[offset + 1], m_data[offset + 2]); @@ -122,12 +122,12 @@ Vec4 Image::getColour(const GLuint _x, const GLuint _y) const noexcept Vec4 Image::getColour(const Real _uvX, const Real _uvY) const noexcept { - GLuint xx = static_cast< GLuint >(_uvX * (m_width - 1)); - GLuint yy = static_cast< GLuint >(_uvY * (m_height - 1)); + auto xx = static_cast< GLuint >(_uvX * (m_width - 1)); + auto yy = static_cast< GLuint >(_uvY * (m_height - 1)); NGL_ASSERT(xx < m_width && yy < m_height) - if(m_data != 0) + if(m_data != nullptr) { auto offset = xx * m_channels + (yy * m_width * m_channels); if(m_channels == 4) @@ -377,12 +377,12 @@ bool Image::load(std::string_view _fname,bool _flipY) noexcept #ifdef USEBUILTINIMAGE -// #define STB_IMAGE_IMPLEMENTATION -// #include "../3rdparty/stb_image.h" bool Image::load(std::string_view _fname,bool _flipY) noexcept { const char *fname = _fname.data(); - int w, h, ch; + int w; + int h; + int ch; stbi_set_flip_vertically_on_load(_flipY); unsigned char *img = stbi_load(fname, &w, &h, &ch, 0); diff --git a/src/NGLMessage.cpp b/src/NGLMessage.cpp index 3280e99e..0829c0df 100644 --- a/src/NGLMessage.cpp +++ b/src/NGLMessage.cpp @@ -53,7 +53,7 @@ NGLMessage::~NGLMessage() NGLMessage &NGLMessage::init() { - static NGLMessage s_instance = NGLMessage(); + static auto s_instance = NGLMessage(); return s_instance; } diff --git a/src/Quaternion.cpp b/src/Quaternion.cpp index 18ba2176..5ab464d9 100644 --- a/src/Quaternion.cpp +++ b/src/Quaternion.cpp @@ -39,7 +39,7 @@ Quaternion::Quaternion(const Mat4 &_m) noexcept else if ( _m.m_openGL[0] > _m.m_openGL[5] && _m.m_openGL[0] > _m.m_openGL[10] ) { // Column 0: - auto S = static_cast(sqrtf( 1.0f + _m.m_openGL[0] - _m.m_openGL[5] - _m.m_openGL[10] ) * 2.0f); + auto S = sqrtf( 1.0f + _m.m_openGL[0] - _m.m_openGL[5] - _m.m_openGL[10] ) * 2.0f; m_x = 0.25f * S; m_y = (_m.m_openGL[1] + _m.m_openGL[4] ) / S; m_z = (_m.m_openGL[8] + _m.m_openGL[2] ) / S; diff --git a/src/Shader.cpp b/src/Shader.cpp index 288b184d..7de9c7b0 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -45,11 +45,9 @@ void printInfoLog(const GLuint &_obj) } } -Shader::Shader(std::string_view _name, ShaderType _type, ErrorExit _exitOnError) noexcept +Shader::Shader(std::string_view _name, ShaderType _type, ErrorExit _exitOnError) noexcept : +m_name{_name},m_errorExit(_exitOnError) { - m_name = _name; - m_shaderType = _type; - m_errorExit = _exitOnError; switch(_type) { case ShaderType::VERTEX: @@ -86,10 +84,7 @@ Shader::Shader(std::string_view _name, ShaderType _type, ErrorExit _exitOnError) } #endif break; - case ShaderType::NONE: - { - ; - } + case ShaderType::NONE:{} } m_compiled = false; m_refCount = 0; @@ -97,7 +92,7 @@ Shader::Shader(std::string_view _name, ShaderType _type, ErrorExit _exitOnError) Shader::~Shader() { // Note this needs to be with cerr as NGLMessage crashes here - std::cerr << fmt::format("removing shader {0} \n", m_name); //,Colours::WHITE,TimeFormat::NONE); + std::cerr << fmt::format("removing shader {0} \n", m_name); glDeleteShader(m_shaderHandle); } @@ -144,7 +139,6 @@ bool Shader::editShader(std::string_view _toFind, std::string_view _edit) { m_source = pystring::replace(m_source, _toFind.data(), _edit.data()); } - //NGLMessage::addMessage(m_source,Colours::YELLOW,TimeFormat::NONE); const char *data = m_source.c_str(); glShaderSource(m_shaderHandle, 1, &data, nullptr); m_compiled = false; diff --git a/src/ShaderLib.cpp b/src/ShaderLib.cpp index fb39ee50..91fb1930 100644 --- a/src/ShaderLib.cpp +++ b/src/ShaderLib.cpp @@ -131,10 +131,9 @@ GLint ShaderLib::getAttribLocation(std::string_view _shaderName, std::string_vie GLint attrib = 0; - // get an iterator to the shaders - auto shader = m_shaderPrograms.find(_shaderName.data()); + // make sure we have a valid shader - if(shader != m_shaderPrograms.end()) + if(auto shader = m_shaderPrograms.find(_shaderName.data()); shader != m_shaderPrograms.end()) { // grab the pointer to the shader and call compile attrib = glGetAttribLocation(shader->second->getID(), _paramName.data()); @@ -152,9 +151,8 @@ GLint ShaderLib::getAttribLocation(std::string_view _shaderName, std::string_vie GLuint ShaderLib::getShaderID(std::string_view _shaderName) noexcept { GLuint value = 0; - auto shader = m_shaders.find(_shaderName.data()); // make sure we have a valid shader and program - if(shader != m_shaders.end()) + if(auto shader = m_shaders.find(_shaderName.data()); shader != m_shaders.end()) { value = shader->second->getShaderHandle(); } @@ -169,16 +167,16 @@ void ShaderLib::attachShader(std::string_view _name, ShaderType _type, ErrorExit { m_shaders[_name.data()] = std::make_unique< Shader >(_name, _type, _exitOnError); if(m_debugState == true) + { NGLMessage::addMessage(fmt::format("just attached {0} to ngl::ShaderLib", _name.data())); + } } //---------------------------------------------------------------------------------------------------------------------- bool ShaderLib::compileShader(std::string_view _name) noexcept -{ - // get an iterator to the shaders - auto shader = m_shaders.find(_name.data()); +{ // make sure we have a valid shader - if(shader != m_shaders.end()) + if(auto shader = m_shaders.find(_name.data()); shader != m_shaders.end()) { // grab the pointer to the shader and call compile return shader->second->compile(); @@ -371,7 +369,7 @@ bool ShaderLib::loadFromJson(std::string_view _fname) noexcept file.close(); // NGLMessage::addMessage(fmt::format("loaded json\n {}",source)); // we need a mutable string for parsing so copy to a char * buffer - std::unique_ptr< char[] > buffer(new char[jsonsource.size()]); + auto buffer=std::make_unique(jsonsource.size()); memcpy(buffer.get(), jsonsource.data(), jsonsource.size()); // null terminate the string! buffer[jsonsource.size()] = '\0'; @@ -483,8 +481,6 @@ bool ShaderLib::loadFromJson(std::string_view _fname) noexcept for(rj::SizeType i = 0; i < uniforms.Size(); i++) { - // std::cerr<<"i "<second->link(); } else @@ -537,9 +534,9 @@ bool ShaderLib::linkProgramObject(std::string_view _name) noexcept //---------------------------------------------------------------------------------------------------------------------- void ShaderLib::use(std::string_view _name) noexcept { - auto program = m_shaderPrograms.find(_name.data()); + // make sure we have a valid program - if(program != m_shaderPrograms.end()) + if(auto program = m_shaderPrograms.find(_name.data()); program != m_shaderPrograms.end()) { m_currentShader = _name.data(); program->second->use(); @@ -555,9 +552,8 @@ void ShaderLib::use(std::string_view _name) noexcept //---------------------------------------------------------------------------------------------------------------------- GLuint ShaderLib::getProgramID(std::string_view _name) noexcept { - auto program = m_shaderPrograms.find(_name.data()); // make sure we have a valid program - if(program != m_shaderPrograms.end()) + if(auto program = m_shaderPrograms.find(_name.data()); program != m_shaderPrograms.end()) { return program->second->getID(); } @@ -571,9 +567,9 @@ GLuint ShaderLib::getProgramID(std::string_view _name) noexcept //---------------------------------------------------------------------------------------------------------------------- void ShaderLib::autoRegisterUniforms(std::string_view _shaderName) noexcept { - auto program = m_shaderPrograms.find(_shaderName.data()); + // make sure we have a valid program - if(program != m_shaderPrograms.end()) + if(auto program = m_shaderPrograms.find(_shaderName.data()); program != m_shaderPrograms.end()) { program->second->autoRegisterUniforms(); program->second->autoRegisterUniformBlocks(); @@ -587,9 +583,9 @@ void ShaderLib::autoRegisterUniforms(std::string_view _shaderName) noexcept //---------------------------------------------------------------------------------------------------------------------- void ShaderLib::bindAttribute(std::string_view _programName, GLuint _index, std::string_view _attribName) noexcept { - auto program = m_shaderPrograms.find(_programName.data()); + // make sure we have a valid program - if(program != m_shaderPrograms.end()) + if(auto program = m_shaderPrograms.find(_programName.data()); program != m_shaderPrograms.end()) { program->second->bindAttribute(_index, _attribName); } @@ -602,9 +598,9 @@ void ShaderLib::bindAttribute(std::string_view _programName, GLuint _index, std: //---------------------------------------------------------------------------------------------------------------------- void ShaderLib::bindFragDataLocation(std::string_view _programName, GLuint _index, std::string_view _attribName) noexcept { - auto program = m_shaderPrograms.find(_programName.data()); + // make sure we have a valid program - if(program != m_shaderPrograms.end()) + if(auto program = m_shaderPrograms.find(_programName.data()); program != m_shaderPrograms.end()) { program->second->bindFragDataLocation(_index, _attribName); } @@ -624,12 +620,9 @@ void ShaderLib::useNullProgram() noexcept GLuint ShaderLib::getUniformBlockIndex(std::string_view _uniformBlockName) noexcept { - GLuint id = 0; - - // get an iterator to the shaders - auto shader = m_shaderPrograms.find(m_currentShader.data()); + GLuint id = 0; // make sure we have a valid shader - if(shader != m_shaderPrograms.end()) + if(auto shader = m_shaderPrograms.find(m_currentShader.data()); shader != m_shaderPrograms.end()) { // grab the pointer to the shader and call compile id = shader->second->getUniformBlockIndex(_uniformBlockName.data()); @@ -753,9 +746,8 @@ void ShaderLib::loadCheckerShaders() noexcept void ShaderLib::printRegisteredUniforms(std::string_view _shader) noexcept { - auto program = m_shaderPrograms.find(_shader.data()); // make sure we have a valid program - if(program != m_shaderPrograms.end()) + if( auto program = m_shaderPrograms.find(_shader.data()); program != m_shaderPrograms.end()) { program->second->printRegisteredUniforms(); } @@ -764,9 +756,8 @@ void ShaderLib::printRegisteredUniforms(std::string_view _shader) noexcept void ShaderLib::printProperties() noexcept { - auto program = m_shaderPrograms.find(m_currentShader); // make sure we have a valid program - if(program != m_shaderPrograms.end()) + if( auto program = m_shaderPrograms.find(m_currentShader); program != m_shaderPrograms.end()) { NGLMessage::addMessage("_______________________________________________________________________________________________________________________", Colours::WHITE, TimeFormat::NONE); NGLMessage::addMessage(fmt::format("Printing Properties for ShaderProgram {0} ", m_currentShader), Colours::WHITE, TimeFormat::NONE); @@ -783,4 +774,3 @@ void ShaderLib::printProperties() noexcept } // namespace ngl -//---------------------------------------------------------------------------------------------------------------------- diff --git a/src/ShaderProgram.cpp b/src/ShaderProgram.cpp index 69a83a51..30e38bdb 100644 --- a/src/ShaderProgram.cpp +++ b/src/ShaderProgram.cpp @@ -123,7 +123,7 @@ bool ShaderProgram::link() noexcept if(infologLength > 0) { - std::unique_ptr< char[] > infoLog(new char[static_cast< size_t >(infologLength)]); + auto infoLog=std::make_unique(static_cast< size_t >(infologLength)); GLint charsWritten = 0; glGetProgramInfoLog(m_programID, infologLength, &charsWritten, infoLog.get()); @@ -133,7 +133,9 @@ bool ShaderProgram::link() noexcept { NGLMessage::addError("Program link failed (will exit if errorExit enabled else return false)"); if(m_errorExit == ErrorExit::ON) + { exit(EXIT_FAILURE); + } } } glUseProgram(m_programID); @@ -146,10 +148,8 @@ bool ShaderProgram::link() noexcept //---------------------------------------------------------------------------------------------------------------------- GLint ShaderProgram::getUniformLocation(const char *_name) const noexcept { - - auto uniform = m_registeredUniforms.find(_name); // make sure we have a valid shader - if(uniform != m_registeredUniforms.end()) + if( auto uniform = m_registeredUniforms.find(_name); uniform != m_registeredUniforms.end()) { return uniform->second.loc; } @@ -179,11 +179,11 @@ void ShaderProgram::printActiveUniforms() const noexcept } GLint nUniforms; glGetProgramiv(m_programID, GL_ACTIVE_UNIFORMS, &nUniforms); - char name[256]; + std::array name; GLsizei l; for(GLint i = 0; i < nUniforms; ++i) { - glGetActiveUniformName(m_programID, static_cast< GLuint >(i), 256, &l, name); + glGetActiveUniformName(m_programID, static_cast< GLuint >(i), name.size(), &l, &name[0]); NGLMessage::addMessage(fmt::format("Uniform: {0}", name), Colours::WHITE, TimeFormat::NONE); } } @@ -537,11 +537,11 @@ void ShaderProgram::printRegisteredUniforms() const noexcept NGLMessage::drawLine(); NGLMessage::addMessage(fmt::format("Registered Uniforms for shader {0}", m_programName), Colours::WHITE, TimeFormat::NONE); NGLMessage::drawLine(); - for(auto d : m_registeredUniforms) + for(auto [name,uniformdata] : m_registeredUniforms) { std::string type; std::string shaderValue; - auto value = types.find(d.second.type); + auto value = types.find(uniformdata.type); if(value != types.end()) { type = value->second; @@ -550,8 +550,8 @@ void ShaderProgram::printRegisteredUniforms() const noexcept { type = "unknown type"; } - shaderValue = getValueFromShader(d.second); - NGLMessage::addMessage(fmt::format("Uniform {0} Location -> {1} glsl type : {2} value {3}", d.first, d.second.loc, type, shaderValue), Colours::WHITE, TimeFormat::NONE); + shaderValue = getValueFromShader(uniformdata); + NGLMessage::addMessage(fmt::format("Uniform {0} Location -> {1} glsl type : {2} value {3}", name, uniformdata.loc, type, shaderValue), Colours::WHITE, TimeFormat::NONE); } NGLMessage::drawLine(); } diff --git a/src/SimpleVAO.cpp b/src/SimpleVAO.cpp index 6034df47..7b48b11c 100644 --- a/src/SimpleVAO.cpp +++ b/src/SimpleVAO.cpp @@ -93,7 +93,7 @@ void SimpleVAO::setData(const VertexData &_data) Real *SimpleVAO::mapBuffer(unsigned int _index, GLenum _accessMode) { - NGL_UNUSED(_index); + NGL_UNUSED(_index) Real *ptr = nullptr; bind(); glBindBuffer(GL_ARRAY_BUFFER, m_id);