Skip to content

Commit

Permalink
added the inl files to the scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacey committed Sep 29, 2023
1 parent 07ef21f commit fe4b68b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 69 deletions.
4 changes: 0 additions & 4 deletions include/ngl/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/NGLMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ NGLMessage::~NGLMessage()

NGLMessage &NGLMessage::init()
{
static NGLMessage s_instance = NGLMessage();
static auto s_instance = NGLMessage();
return s_instance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Quaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Real>(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;
Expand Down
14 changes: 4 additions & 10 deletions src/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -86,18 +84,15 @@ Shader::Shader(std::string_view _name, ShaderType _type, ErrorExit _exitOnError)
}
#endif
break;
case ShaderType::NONE:
{
;
}
case ShaderType::NONE:{}
}
m_compiled = false;
m_refCount = 0;
}
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);
}

Expand Down Expand Up @@ -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;
Expand Down
58 changes: 24 additions & 34 deletions src/ShaderLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
}
Expand All @@ -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();
Expand Down Expand Up @@ -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<char []>(jsonsource.size());
memcpy(buffer.get(), jsonsource.data(), jsonsource.size());
// null terminate the string!
buffer[jsonsource.size()] = '\0';
Expand Down Expand Up @@ -483,8 +481,6 @@ bool ShaderLib::loadFromJson(std::string_view _fname) noexcept

for(rj::SizeType i = 0; i < uniforms.Size(); i++)
{
// std::cerr<<"i "<<i<<'\n';
// const rj::Value::Ch *name=uniforms["name"].GetString();
auto &currentUniform = uniforms[i];
const rj::Value::Ch *name = currentUniform["name"].GetString();
const rj::Value::Ch *type = currentUniform["type"].GetString();
Expand Down Expand Up @@ -519,12 +515,13 @@ void ShaderLib::loadShaderSourceFromString(std::string_view _shaderName, std::st
bool ShaderLib::linkProgramObject(std::string_view _name) noexcept
{
bool linked = false;
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())
{
if(m_debugState == true)
{
NGLMessage::addMessage(fmt::format("Linking {0}", _name.data()));
}
linked = program->second->link();
}
else
Expand All @@ -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();
Expand All @@ -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();
}
Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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());
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand All @@ -783,4 +774,3 @@ void ShaderLib::printProperties() noexcept

} // namespace ngl

//----------------------------------------------------------------------------------------------------------------------
20 changes: 10 additions & 10 deletions src/ShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char []>(static_cast< size_t >(infologLength));
GLint charsWritten = 0;

glGetProgramInfoLog(m_programID, infologLength, &charsWritten, infoLog.get());
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -179,11 +179,11 @@ void ShaderProgram::printActiveUniforms() const noexcept
}
GLint nUniforms;
glGetProgramiv(m_programID, GL_ACTIVE_UNIFORMS, &nUniforms);
char name[256];
std::array<char,256> 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);
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleVAO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fe4b68b

Please sign in to comment.