17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 01:39:20 +02:00

Fix/sonar maintainability rebased (#209)

* refactor(sonar): use override instead of redundant virtual (cpp:S3471)

* refactor(sonar): remove empty statements, one declaration per statement (cpp:S1116, cpp:S1659)

* refactor(sonar): drop redundant lambda return types (cpp:S3574)

* refactor(sonar): prefer using over typedef (cpp:S5416)

* refactor(sonar): use =default for trivial special members (cpp:S3490)

* refactor(sonar): use nullptr literal (cpp:S4962)

* refactor(sonar): remove redundant access specifiers (cpp:S3539)

* refactor(sonar): remove redundant casts (cpp:S1905)

* refactor(sonar): use std::scoped_lock instead of std::lock_guard (cpp:S5997)

* refactor(sonar): construct elements in place with emplace_back (cpp:S6003)

* refactor(sonar): make narrowing conversions explicit (cpp:S5276)

* refactor(sonar): mark unused parameters (cpp:S1172)

Unused names are commented out; parameters used only on some platforms
are marked [[maybe_unused]].

* refactor(sonar): declare non-mutating member functions const (cpp:S5817)

Virtual functions are left untouched so overrides keep matching.

* refactor(sonar): merge collapsible nested if statements (cpp:S1066)

Comments that preceded the inner if are kept above the merged statement.

* refactor(sonar): scope single-use variables in if init-statements (cpp:S6004)

* fix(sonar): give polymorphic base classes virtual destructors (cpp:S1235)

* refactor(sonar): use try_emplace for map insertion (cpp:S6030)

* refactor(sonar): use auto where the type is spelled out on the right (cpp:S5827)

* refactor(sonar): remove redundant parentheses (cpp:S1110)

* refactor(sonar): document intentionally empty functions (cpp:S1186)

* refactor(sonar): remove dead stores (cpp:S1854)

Side effects (e.g. LISTLINE++) are kept.

* refactor(sonar): remove unused variables, captures and private fields (cpp:S1481, cpp:S1068)

* refactor(sonar): use structured bindings for pair access (cpp:S6005)

* refactor(sonar): use range-based loops and ranges algorithms (cpp:S5566)

* refactor(sonar): split chained assignments (cpp:S1121)

* refactor(sonar): add default cases to switch statements (cpp:S3562)

* refactor(sonar): use std::size for array lengths (cpp:S7127)

* refactor(sonar): use std::ranges algorithms and std::erase(_if) (cpp:S6197)

* refactor(sonar): access static members through the class (cpp:S2209)

* refactor(sonar): add braces around nested if-else (cpp:S5261)

* refactor(sonar): avoid side effects inside typeid operands (cpp:S5279)

* refactor(sonar): drop top-level const from by-value return types (cpp:S5951)

* refactor(sonar): declare variables separately from their type definitions (cpp:S3646)

* refactor(sonar): declare loop counters in the for statement (cpp:S5955)

* refactor(sonar): rely on class template argument deduction (cpp:S6012)

* refactor(sonar): inherit base constructors instead of forwarding them (cpp:S5952)

* refactor(sonar): rename locals that shadow outer declarations (cpp:S1117)

Only local variables and definition parameters are renamed; shadowing
struct fields and enumerators in headers are left for a separate change.

* refactor(sonar): reduce enum qualification with using enum (cpp:S6177)

Applied only where no unqualified name in the block could be captured by
the introduced enumerators.

* refactor(sonar): mark converting constructors explicit (cpp:S1709)

sound_source and the gl::object conversion operators stay implicit; they
are relied upon by copy-list-initialisation and GL calls.

* refactor(sonar): initialise members in initialiser lists or declarations (cpp:S3230)

* refactor(sonar): make read-only local references and pointers const (cpp:S5350)

* refactor(sonar): take read-only pointer and reference parameters as const (cpp:S995)

TTrain command handlers keep their signature, it is fixed by the handler table.

* refactor(sonar): pass expensive-to-copy parameters by const reference (cpp:S1238)

Signatures declared in files touched by PR 206 (Driver.h, EU07.cpp) and
virtual overrides are left unchanged.

* refactor(sonar): use transparent comparators for string-keyed maps (cpp:S6045)

std::unordered_map instances and map types exposed in headers used by
other modules are left as they are.

* fix(sonar): do not use UI text as a printf format string (cpp:S5281)

Text lines containing '%' would otherwise be interpreted as format
specifiers by ImGui::TextColored.

* refactor(sonar): use std::bind_front for callbacks (cpp:S5995)

* refactor(sonar): drop const_cast on string literals passed to the Python C API (cpp:S859)

* refactor(sonar): take read-only string parameters as std::string_view (cpp:S6009)

The Windows messaging helpers keep std::string, they need c_str().

* refactor(sonar): make read-only global tables const (cpp:S5421)

Mutable global state (flags, timers, singletons) is left as is.

* refactor(sonar): replace single-case switch statements with if (cpp:S1301)

* refactor(sonar): format UUIDs and log timestamps with std::format (cpp:S6494, cpp:S5945)

* refactor(sonar): use std::array for local fixed-size arrays (cpp:S5945)

Arrays that are class members or part of headers are left unchanged.

* fix(sonar): test the bearing damage bit, not bit 0 (cpp:S872)

'DamageFlag & dtrain_bearing > 0' parsed as 'DamageFlag & (dtrain_bearing > 0)',
i.e. DamageFlag & 1, so bearing friction reacted to the wrong damage flag.

* refactor(sonar): assorted small fixes

- empty() instead of size() comparisons (cpp:S1155)
- member initialisers in declaration order (cpp:S3229)
- no redundant c_str() when a std::string is accepted (cpp:S7121)
- contains() on associative containers (cpp:S6171)
- const reference instead of a copying range-for (cpp:S6032)
- starts_with() for prefix checks (cpp:S6178)
- no std::move on temporaries (cpp:S5274)
- has_value() on std::optional (cpp:S7172)
- bool literals for bool members (cpp:S5820)
- inline only on the definition (cpp:S3548)
- explicit base access specifier (cpp:S5965)
- explicit element access instead of dereferencing an array (cpp:S7116)
- rely on the C++20 rewritten operator!= (cpp:S6186)

* refactor(sonar): more small fixes

- std::format instead of iostream manipulators in to_string/to_hex_str (cpp:S6495);
  output verified identical, negative hex values keep the unsigned form
- remove an empty compound statement (cpp:S108)
- drop an always-false unsigned < 0 branch (cpp:S1768)
- explicit lambda capture (cpp:S3608)
- std::make_unique (cpp:S5950)

* chore: strip stray carriage returns left in TTrain constructor comments

* fix: keep quantize() in its own value type

The S5276 change cast the result of the generic quantize<Type_>() to
unsigned int, which truncated float/double callers (shadow angle slider,
editor rotation snapping, AI speed control steps) and broke negative values.

* fix(sonar): use integer loop counters in segment sampling (cpp:S2193)

* refactor(sonar): clean up issues reported on PR 209

- remove locals left unused after the dead-store cleanup (cpp:S1481, cpp:S1854)
- unnamed unused parameter (cpp:S1172)
- single-use declarations moved into if init-statements (cpp:S6004)
- auto for casted initialisers (cpp:S5827)
- const references and pointers where nothing is modified (cpp:S5350)
- rename structured bindings shadowed by inner declarations (cpp:S1117)
This commit is contained in:
jerrrrycho
2026-10-11 13:22:33 +02:00
committed by GitHub
parent c26041f2e7
commit 6263fe539b
162 changed files with 4220 additions and 4598 deletions

View File

@@ -3,7 +3,7 @@
GLenum gl::buffer::glenum_target(gl::buffer::targets target)
{
static GLenum mapping[13] =
static std::array<GLenum, 13> const mapping =
{
GL_ARRAY_BUFFER,
GL_ATOMIC_COUNTER_BUFFER,
@@ -22,7 +22,7 @@ GLenum gl::buffer::glenum_target(gl::buffer::targets target)
return mapping[target];
}
void gl::buffer::bind(targets target)
void gl::buffer::bind(targets target) const
{
if (binding_points[target] == *this)
return;
@@ -31,7 +31,7 @@ void gl::buffer::bind(targets target)
binding_points[target] = *this;
}
void gl::buffer::bind_base(targets target, GLuint index)
void gl::buffer::bind_base(targets target, GLuint index) const
{
glBindBufferBase(glenum_target(target), index, *this);
binding_points[target] = *this;
@@ -47,7 +47,7 @@ void gl::buffer::unbind(targets target)
void gl::buffer::unbind()
{
for (size_t i = 0; i < sizeof(binding_points) / sizeof(GLuint); i++)
for (size_t i = 0; i < std::size(binding_points); i++)
unbind((targets)i);
}
@@ -87,7 +87,7 @@ void gl::buffer::download(targets target, void *data, int offset, GLsizeiptr siz
}
else
{
void *glbuf = glMapBufferRange(glenum_target(target), offset, size, GL_MAP_READ_BIT);
void const *glbuf = glMapBufferRange(glenum_target(target), offset, size, GL_MAP_READ_BIT);
memcpy(data, glbuf, size);
glUnmapBuffer(glenum_target(target));
}

View File

@@ -34,8 +34,8 @@ namespace gl
buffer();
~buffer();
void bind(targets target);
void bind_base(targets target, GLuint index);
void bind(targets target) const;
void bind_base(targets target, GLuint index) const;
static void unbind(targets target);
static void unbind();

View File

@@ -15,7 +15,7 @@ gl::cubemap::~cubemap()
glDeleteTextures(1, *this);
}
void gl::cubemap::alloc(GLint format, int width, int height, GLenum components, GLenum type)
void gl::cubemap::alloc(GLint format, int width, int height, GLenum components, GLenum type) const
{
glBindTexture(GL_TEXTURE_CUBE_MAP, *this);
for (GLuint tgt = GL_TEXTURE_CUBE_MAP_POSITIVE_X; tgt <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; tgt++)
@@ -29,13 +29,13 @@ void gl::cubemap::alloc(GLint format, int width, int height, GLenum components,
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}
void gl::cubemap::bind(int unit)
void gl::cubemap::bind(int unit) const
{
glActiveTexture(unit);
glBindTexture(GL_TEXTURE_CUBE_MAP, *this);
}
void gl::cubemap::generate_mipmaps()
void gl::cubemap::generate_mipmaps() const
{
glBindTexture(GL_TEXTURE_CUBE_MAP, *this);
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);

View File

@@ -12,8 +12,8 @@ namespace gl
cubemap();
~cubemap();
void alloc(GLint format, int width, int height, GLenum components, GLenum type);
void bind(int unit);
void generate_mipmaps();
void alloc(GLint format, int width, int height, GLenum components, GLenum type) const;
void bind(int unit) const;
void generate_mipmaps() const;
};
}

View File

@@ -80,7 +80,7 @@ void gl::framebuffer::blit_from(framebuffer *other, int w, int h, GLbitfield mas
blit(other, this, 0, 0, w, h, mask, attachment);
}
void gl::framebuffer::blit(framebuffer *src, framebuffer *dst, int sx, int sy, int w, int h, GLbitfield mask, GLenum attachment)
void gl::framebuffer::blit(framebuffer const *src, framebuffer const *dst, int sx, int sy, int w, int h, GLbitfield mask, GLenum attachment)
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, src ? *src : 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst ? *dst : 0);
@@ -90,17 +90,17 @@ void gl::framebuffer::blit(framebuffer *src, framebuffer *dst, int sx, int sy, i
int attachment_n = attachment - GL_COLOR_ATTACHMENT0;
{
GLenum outputs[8] = { GL_NONE };
outputs[attachment_n] = src != 0 ? attachment : GL_BACK_LEFT;
std::array<GLenum, 8> outputs{ GL_NONE };
outputs[attachment_n] = src != nullptr ? attachment : GL_BACK_LEFT;
glReadBuffer(attachment);
}
{
GLenum outputs[8] = { GL_NONE };
outputs[attachment_n] = dst != 0 ? attachment : GL_BACK_LEFT;
std::array<GLenum, 8> outputs{ GL_NONE };
outputs[attachment_n] = dst != nullptr ? attachment : GL_BACK_LEFT;
glDrawBuffers(attachment_n + 1, outputs);
glDrawBuffers(attachment_n + 1, outputs.data());
}
}

View File

@@ -26,7 +26,7 @@ namespace gl
void blit_to(framebuffer *other, int w, int h, GLbitfield mask, GLenum attachment);
void blit_from(framebuffer *other, int w, int h, GLbitfield mask, GLenum attachment);
static void blit(framebuffer *src, framebuffer *dst, int sx, int sy, int w, int h, GLbitfield mask, GLenum attachment);
static void blit(framebuffer const *src, framebuffer const *dst, int sx, int sy, int w, int h, GLbitfield mask, GLenum attachment);
using bindable::bind;
static void bind(GLuint id);

View File

@@ -15,12 +15,12 @@ namespace gl
return id;
}
inline operator GLuint* const()
inline operator GLuint*()
{
return &id;
}
inline operator const GLuint* const() const
inline operator const GLuint*() const
{
return &id;
}

View File

@@ -12,7 +12,7 @@ void gl::pbo::request_read(int x, int y, int lx, int ly, int pixsize, GLenum for
sync.reset();
bind(PIXEL_PACK_BUFFER);
glReadPixels(x, y, lx, ly, format, type, 0);
glReadPixels(x, y, lx, ly, format, type, nullptr);
unbind(PIXEL_PACK_BUFFER);
sync.emplace();

View File

@@ -15,8 +15,8 @@ namespace gl
static std::shared_ptr<gl::vao> vao;
public:
postfx(const std::string &s);
postfx(const shader &s);
explicit postfx(const std::string &s);
explicit postfx(const shader &s);
void attach();
void apply(opengl_texture &src, framebuffer *dst);

View File

@@ -49,9 +49,9 @@ std::optional<int64_t> gl::query::result()
return std::nullopt;
}
GLenum gl::query::glenum_target(targets target)
GLenum gl::query::glenum_target(targets Target) const
{
static GLenum mapping[6] =
static std::array<GLenum, 6> const mapping =
{
GL_SAMPLES_PASSED,
GL_ANY_SAMPLES_PASSED,
@@ -60,7 +60,7 @@ GLenum gl::query::glenum_target(targets target)
GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
GL_TIME_ELAPSED
};
return mapping[target];
return mapping[Target];
}
thread_local gl::query* gl::query::active_queries[6];

View File

@@ -22,10 +22,10 @@ private:
thread_local static query* active_queries[6];
protected:
GLenum glenum_target(targets target);
GLenum glenum_target(targets target) const;
public:
query(targets target);
explicit query(targets target);
~query();
void begin();

View File

@@ -7,7 +7,7 @@
#include "glsl_common.h"
#include "utilities/Logs.h"
inline bool strcend(std::string const &value, std::string const &ending)
inline bool strcend(std::string_view value, std::string_view ending)
{
if (ending.size() > value.size())
return false;
@@ -41,7 +41,7 @@ bool has_gl_extension(char const *name) {
GLint count = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
for (GLint i = 0; i < count; ++i) {
char const *ext = reinterpret_cast<char const *>(glGetStringi(GL_EXTENSIONS, i));
auto ext = reinterpret_cast<char const *>(glGetStringi(GL_EXTENSIONS, i));
if (ext != nullptr && std::strcmp(ext, name) == 0) {
return true;
}
@@ -52,7 +52,7 @@ bool has_gl_extension(char const *name) {
} // anonymous namespace
std::string gl::shader::read_file(const std::string &filename)
std::string gl::shader::read_file(const std::string &filename) const
{
std::stringstream stream;
std::ifstream f;
@@ -73,11 +73,11 @@ void gl::shader::expand_includes(std::string &str, const std::string &basedir)
size_t start_pos = 0;
std::string magic = "#include";
while ((start_pos = str.find(magic, start_pos)) != str.npos)
while ((start_pos = str.find(magic, start_pos)) != std::string::npos)
{
size_t fp = str.find('<', start_pos);
size_t fe = str.find('>', start_pos);
if (fp == str.npos || fe == str.npos)
if (fp == std::string::npos || fe == std::string::npos)
return;
std::string filename = str.substr(fp + 1, fe - fp - 1);
@@ -154,8 +154,7 @@ std::pair<GLuint, std::string> gl::shader::process_source(const std::string &fil
// the driver advertises support (see desktop comment above).
// (Glad config doesn't generate GLAD_GL_EXT_gpu_shader5 -- query
// the live extension string the same way.)
static bool const have_gpu_shader5 = has_gl_extension("GL_EXT_gpu_shader5");
if (have_gpu_shader5)
if (static bool const have_gpu_shader5 = has_gl_extension("GL_EXT_gpu_shader5"); have_gpu_shader5)
str += "#extension GL_EXT_gpu_shader5 : enable\n";
if (type == GL_GEOMETRY_SHADER)
str += "#extension GL_EXT_geometry_shader : require\n";
@@ -189,17 +188,17 @@ void gl::shader::parse_texture_entries(std::string &str)
size_t start_pos = 0;
std::string magic = "#texture";
while ((start_pos = str.find(magic, start_pos)) != str.npos)
while ((start_pos = str.find(magic, start_pos)) != std::string::npos)
{
size_t fp = str.find('(', start_pos);
size_t fe = str.find(')', start_pos);
if (fp == str.npos || fe == str.npos)
if (fp == std::string::npos || fe == std::string::npos)
return;
std::istringstream ss(str.substr(fp + 1, fe - fp - 1));
std::string token;
std::string name;
std::string uniformname;
texture_entry conf;
size_t arg = 0;
@@ -207,14 +206,14 @@ void gl::shader::parse_texture_entries(std::string &str)
{
std::istringstream token_ss(token);
if (arg == 0)
token_ss >> name;
token_ss >> uniformname;
else if (arg == 1)
token_ss >> conf.id;
else if (arg == 2)
{
std::string comp;
token_ss >> comp;
if (components_mapping.find(comp) == components_mapping.end())
if (!components_mapping.contains(comp))
log_error("unknown components: " + comp);
else
conf.components = components_mapping[comp];
@@ -224,12 +223,12 @@ void gl::shader::parse_texture_entries(std::string &str)
if (arg == 3)
{
if (name.empty())
if (uniformname.empty())
log_error("empty name");
else if (conf.id >= gl::MAX_TEXTURES)
log_error("invalid texture binding: " + std::to_string(conf.id));
else
texture_conf.emplace(std::make_pair(name, conf));
texture_conf.try_emplace(uniformname, conf);
}
else
log_error("invalid argument count to #texture");
@@ -243,17 +242,17 @@ void gl::shader::parse_param_entries(std::string &str)
size_t start_pos = 0;
std::string magic = "#param";
while ((start_pos = str.find(magic, start_pos)) != str.npos)
while ((start_pos = str.find(magic, start_pos)) != std::string::npos)
{
size_t fp = str.find('(', start_pos);
size_t fe = str.find(')', start_pos);
if (fp == str.npos || fe == str.npos)
if (fp == std::string::npos || fe == std::string::npos)
return;
std::istringstream ss(str.substr(fp + 1, fe - fp - 1));
std::string token;
std::string name;
std::string uniformname;
param_entry conf;
size_t arg = 0;
@@ -261,7 +260,7 @@ void gl::shader::parse_param_entries(std::string &str)
{
std::istringstream token_ss(token);
if (arg == 0)
token_ss >> name;
token_ss >> uniformname;
else if (arg == 1)
token_ss >> conf.location;
else if (arg == 2)
@@ -272,7 +271,7 @@ void gl::shader::parse_param_entries(std::string &str)
{
std::string tok;
token_ss >> tok;
if (defaultparams_mapping.find(tok) == defaultparams_mapping.end())
if (!defaultparams_mapping.contains(tok))
log_error("unknown param default: " + tok);
conf.defaultparam = defaultparams_mapping[tok];
}
@@ -281,7 +280,7 @@ void gl::shader::parse_param_entries(std::string &str)
if (arg == 5)
{
if (name.empty())
if (uniformname.empty())
log_error("empty name");
else if (conf.location >= gl::MAX_PARAMS)
log_error("invalid param binding: " + std::to_string(conf.location));
@@ -290,7 +289,7 @@ void gl::shader::parse_param_entries(std::string &str)
else if (conf.offset + conf.size > 4)
log_error("invalid size: " + std::to_string(conf.size));
else
param_conf.emplace(std::make_pair(name, conf));
param_conf.try_emplace(uniformname, conf);
}
else
log_error("invalid argument count to #param");
@@ -299,32 +298,31 @@ void gl::shader::parse_param_entries(std::string &str)
}
}
void gl::shader::log_error(const std::string &str)
void gl::shader::log_error(const std::string &str) const
{
ErrorLog("bad shader: " + name + ": " + str, logtype::shader);
}
gl::shader::shader(const std::string &filename)
gl::shader::shader(const std::string &filename) : name(filename)
{
name = filename;
std::pair<GLuint, std::string> source = process_source(filename, "shaders/");
auto [shadertype, shadersource] = process_source(filename, "shaders/");
const GLchar *cstr = source.second.c_str();
const GLchar *cstr = shadersource.c_str();
**this = glCreateShader(source.first);
glShaderSource(*this, 1, &cstr, 0);
**this = glCreateShader(shadertype);
glShaderSource(*this, 1, &cstr, nullptr);
glCompileShader(*this);
GLint status;
glGetShaderiv(*this, GL_COMPILE_STATUS, &status);
if (!status)
{
GLchar info[512];
glGetShaderInfoLog(*this, 512, 0, info);
log_error(std::string(info));
std::array<GLchar, 512> info{};
glGetShaderInfoLog(*this, static_cast<GLsizei>(info.size()), nullptr, info.data());
log_error(std::string(info.data()));
throw shader_exception("failed to compile " + filename + ": " + std::string(info));
throw shader_exception("failed to compile " + filename + ": " + std::string(info.data()));
}
}
@@ -339,11 +337,11 @@ void gl::program::init()
{
bind();
for (auto it : texture_conf)
for (auto const &[texturename, textureentry] : texture_conf)
{
shader::texture_entry &e = it.second;
GLuint loc = glGetUniformLocation(*this, it.first.c_str());
glUniform1i(loc, e.id);
shader::texture_entry const &e = textureentry;
GLuint loc = glGetUniformLocation(*this, texturename.c_str());
glUniform1i(loc, static_cast<GLint>(e.id));
}
glUniform1i(glGetUniformLocation(*this, "shadowmap"), gl::SHADOW_TEX);
@@ -370,7 +368,7 @@ gl::program::program()
**this = glCreateProgram();
}
gl::program::program(std::vector<std::reference_wrapper<const gl::shader>> shaders) : program()
gl::program::program(std::vector<std::reference_wrapper<const gl::shader>> const &shaders) : program()
{
for (const gl::shader &s : shaders)
attach(s);
@@ -379,10 +377,10 @@ gl::program::program(std::vector<std::reference_wrapper<const gl::shader>> shade
void gl::program::attach(const gl::shader &s)
{
for (auto it : s.texture_conf)
texture_conf.emplace(std::make_pair(it.first, std::move(it.second)));
for (auto it : s.param_conf)
param_conf.emplace(std::make_pair(it.first, std::move(it.second)));
for (auto [texturename, textureentry] : s.texture_conf)
texture_conf.try_emplace(texturename, std::move(textureentry));
for (auto [paramname, paramentry] : s.param_conf)
param_conf.try_emplace(paramname, std::move(paramentry));
glAttachShader(*this, *s);
}
@@ -394,9 +392,9 @@ void gl::program::link()
glGetProgramiv(*this, GL_LINK_STATUS, &status);
if (!status)
{
GLchar info[512];
glGetProgramInfoLog(*this, 512, 0, info);
throw shader_exception("failed to link program: " + std::string(info));
std::array<GLchar, 512> info{};
glGetProgramInfoLog(*this, static_cast<GLsizei>(info.size()), nullptr, info.data());
throw shader_exception("failed to link program: " + std::string(info.data()));
}
init();

View File

@@ -21,7 +21,7 @@ namespace gl
#ifdef SHADERVALIDATOR_STANDALONE
shader() = default;
#endif
shader(const std::string &filename);
explicit shader(const std::string &filename);
~shader();
enum class components_e
@@ -73,19 +73,19 @@ namespace gl
void parse_texture_entries(std::string &str);
void parse_param_entries(std::string &str);
std::string read_file(const std::string &filename);
std::string read_file(const std::string &filename) const;
static std::unordered_map<std::string, components_e> components_mapping;
static std::unordered_map<std::string, defaultparam_e> defaultparams_mapping;
void log_error(const std::string &str);
void log_error(const std::string &str) const;
};
class program : public object, public bindable<program>
{
public:
program();
program(std::vector<std::reference_wrapper<const gl::shader>>);
explicit program(std::vector<std::reference_wrapper<const gl::shader>> const &);
~program();
using bindable::bind;

View File

@@ -1,10 +1,9 @@
#include "stdafx.h"
#include "ubo.h"
gl::ubo::ubo(size_t size, int idx, GLenum hint)
gl::ubo::ubo(size_t size, int idx, GLenum hint) : index(idx)
{
allocate(buffer::UNIFORM_BUFFER, size, hint);
index = idx;
bind_uniform();
}

View File

@@ -29,7 +29,7 @@ namespace gl
void update(const uint8_t *data, int offset, GLsizeiptr size);
template <typename T> void update(const T &data, size_t offset = 0)
{
update(reinterpret_cast<const uint8_t*>(&data), offset, sizeof(data));
update(reinterpret_cast<const uint8_t*>(&data), static_cast<int>(offset), sizeof(data));
}
};

View File

@@ -31,7 +31,7 @@ void gl::vao::setup_attrib(gl::buffer &buffer, int attrib, int size, int type, i
else {
if (attrib == 0)
params.clear();
params.push_back({buffer, attrib, size, type, stride, offset});
params.emplace_back(buffer, attrib, size, type, stride, offset);
active = nullptr;
}
}
@@ -60,14 +60,14 @@ void gl::vao::bind()
glBindVertexArray(*this);
}
else {
for (attrib_params &param : params) {
for (attrib_params const &param : params) {
param.buffer.bind(gl::buffer::ARRAY_BUFFER);
glVertexAttribPointer(param.attrib, param.size, param.type, GL_FALSE, param.stride, reinterpret_cast<void*>(param.offset));
glEnableVertexAttribArray(param.attrib);
}
for (size_t i = params.size(); i < 5; i++)
glDisableVertexAttribArray(i);
glDisableVertexAttribArray(static_cast<GLuint>(i));
if (ebo)
ebo->bind(gl::buffer::ELEMENT_ARRAY_BUFFER);
@@ -84,6 +84,6 @@ void gl::vao::unbind()
}
else {
for (size_t i = 0; i < 4; i++)
glDisableVertexAttribArray(i);
glDisableVertexAttribArray(static_cast<GLuint>(i));
}
}

View File

@@ -6,7 +6,7 @@
namespace gl
{
class vao : object, public bindable<vao>
class vao : private object, public bindable<vao>
{
struct attrib_params {
// TBD: should be shared_ptr? (when buffer is destroyed by owner VAO could still potentially exist)