Skip to content

Commit

Permalink
More small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-tomas committed Oct 30, 2023
1 parent 5331bf7 commit 237d548
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 84 deletions.
135 changes: 68 additions & 67 deletions bloss1/src/ecs/scene_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,19 @@ namespace bls
vec3 fog_color = read_vec3(&iline, ',');
vec2 min_max = read_vec2(&iline, ',');

for (auto &pass : AppConfig::render_passes)
auto it = std::find_if(AppConfig::render_passes.begin(),
AppConfig::render_passes.end(),
[](const auto &pass) { return typeid(*pass.pass) == typeid(FogPass); });

if (it != AppConfig::render_passes.end())
{
if (typeid(*pass.pass) == typeid(FogPass))
{
auto *fog_pass = static_cast<FogPass *>(pass.pass);
fog_pass->fog_color = fog_color;
fog_pass->min_max = min_max;

pass.enabled = std::stoul(enabled);
pass.position = std::stoul(position);
post_processing->set_pass(pass.id, pass.enabled, pass.position);
break;
}
auto *fog_pass = static_cast<FogPass *>(it->pass);
fog_pass->fog_color = fog_color;
fog_pass->min_max = min_max;

it->enabled = std::stoul(enabled);
it->position = std::stoul(position);
post_processing->set_pass(it->id, it->enabled, it->position);
}
}

Expand All @@ -617,21 +617,21 @@ namespace bls
std::getline(iline, threshold, ',');
std::getline(iline, amount, ';');

for (auto &pass : AppConfig::render_passes)
auto it = std::find_if(AppConfig::render_passes.begin(),
AppConfig::render_passes.end(),
[](const auto &pass) { return typeid(*pass.pass) == typeid(BloomPass); });

if (it != AppConfig::render_passes.end())
{
if (typeid(*pass.pass) == typeid(BloomPass))
{
auto *bloom_pass = static_cast<BloomPass *>(pass.pass);
bloom_pass->samples = std::stoul(samples);
bloom_pass->spread = std::stof(spread);
bloom_pass->threshold = std::stof(threshold);
bloom_pass->amount = std::stof(amount);

pass.enabled = std::stoul(enabled);
pass.position = std::stoul(position);
post_processing->set_pass(pass.id, pass.enabled, pass.position);
break;
}
auto *bloom_pass = static_cast<BloomPass *>(it->pass);
bloom_pass->samples = std::stoul(samples);
bloom_pass->spread = std::stof(spread);
bloom_pass->threshold = std::stof(threshold);
bloom_pass->amount = std::stof(amount);

it->enabled = std::stoul(enabled);
it->position = std::stoul(position);
post_processing->set_pass(it->id, it->enabled, it->position);
}
}

Expand All @@ -644,18 +644,18 @@ namespace bls
str amount;
std::getline(iline, amount, ';');

for (auto &pass : AppConfig::render_passes)
auto it = std::find_if(AppConfig::render_passes.begin(),
AppConfig::render_passes.end(),
[](const auto &pass) { return typeid(*pass.pass) == typeid(SharpenPass); });

if (it != AppConfig::render_passes.end())
{
if (typeid(*pass.pass) == typeid(SharpenPass))
{
auto *sharpen_pass = static_cast<SharpenPass *>(pass.pass);
sharpen_pass->amount = std::stof(amount);

pass.enabled = std::stoul(enabled);
pass.position = std::stoul(position);
post_processing->set_pass(pass.id, pass.enabled, pass.position);
break;
}
auto *sharpen_pass = static_cast<SharpenPass *>(it->pass);
sharpen_pass->amount = std::stof(amount);

it->enabled = std::stoul(enabled);
it->position = std::stoul(position);
post_processing->set_pass(it->id, it->enabled, it->position);
}
}

Expand All @@ -670,18 +670,19 @@ namespace bls
str levels;
std::getline(iline, levels, ';');

for (auto &pass : AppConfig::render_passes)
auto it =
std::find_if(AppConfig::render_passes.begin(),
AppConfig::render_passes.end(),
[](const auto &pass) { return typeid(*pass.pass) == typeid(PosterizationPass); });

if (it != AppConfig::render_passes.end())
{
if (typeid(*pass.pass) == typeid(PosterizationPass))
{
auto *post_pass = static_cast<PosterizationPass *>(pass.pass);
post_pass->levels = std::stof(levels);

pass.enabled = std::stoul(enabled);
pass.position = std::stoul(position);
post_processing->set_pass(pass.id, pass.enabled, pass.position);
break;
}
auto *post_pass = static_cast<PosterizationPass *>(it->pass);
post_pass->levels = std::stof(levels);

it->enabled = std::stoul(enabled);
it->position = std::stoul(position);
post_processing->set_pass(it->id, it->enabled, it->position);
}
}

Expand All @@ -696,18 +697,18 @@ namespace bls
str pixel_size;
std::getline(iline, pixel_size, ';');

for (auto &pass : AppConfig::render_passes)
auto it = std::find_if(AppConfig::render_passes.begin(),
AppConfig::render_passes.end(),
[](const auto &pass) { return typeid(*pass.pass) == typeid(PixelizationPass); });

if (it != AppConfig::render_passes.end())
{
if (typeid(*pass.pass) == typeid(PixelizationPass))
{
auto *pixel_pass = static_cast<PixelizationPass *>(pass.pass);
pixel_pass->pixel_size = std::stoul(pixel_size);

pass.enabled = std::stoul(enabled);
pass.position = std::stoul(position);
post_processing->set_pass(pass.id, pass.enabled, pass.position);
break;
}
auto *pixel_pass = static_cast<PixelizationPass *>(it->pass);
pixel_pass->pixel_size = std::stoul(pixel_size);

it->enabled = std::stoul(enabled);
it->position = std::stoul(position);
post_processing->set_pass(it->id, it->enabled, it->position);
}
}

Expand All @@ -717,15 +718,15 @@ namespace bls
std::getline(iline, position, ',');
std::getline(iline, enabled, ';');

for (auto &pass : AppConfig::render_passes)
auto it = std::find_if(AppConfig::render_passes.begin(),
AppConfig::render_passes.end(),
[](const auto &pass) { return typeid(*pass.pass) == typeid(PixelizationPass); });

if (it != AppConfig::render_passes.end())
{
if (typeid(*pass.pass) == typeid(FXAAPass))
{
pass.enabled = std::stoul(enabled);
pass.position = std::stoul(position);
post_processing->set_pass(pass.id, pass.enabled, pass.position);
break;
}
it->enabled = std::stoul(enabled);
it->position = std::stoul(position);
post_processing->set_pass(it->id, it->enabled, it->position);
}
}
}
Expand Down
14 changes: 2 additions & 12 deletions bloss1/src/renderer/opengl/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,9 @@ namespace bls
std::vector<char> error_message(log_length + 1);
glGetProgramInfoLog(id, log_length, NULL, &error_message[0]);

str error = "";
for (auto c : error_message)
{
error += c;
}
LOG_ERROR("linking program");
LOG_ERROR("error when linking shader: '%s'", vertex_path.c_str());
LOG_ERROR("error when linking program: '%s'", error.c_str());
LOG_ERROR("error when linking program: '%s'", error_message.data());

throw std::runtime_error(
"failed to link "
Expand Down Expand Up @@ -140,12 +135,7 @@ namespace bls
std::vector<char> error_message(log_length + 1);
glGetShaderInfoLog(ID, log_length, NULL, &error_message[0]);

str error = "";
for (auto c : error_message)
{
error += c;
}
LOG_ERROR("error when compiling '%s': %s", path.c_str(), error.c_str());
LOG_ERROR("error when compiling '%s': %s", path.c_str(), error_message.data());
}
}

Expand Down
10 changes: 5 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
set positional-arguments

@default: (build "profile") (run "profile")
@default: (lint) (format) (build "profile") (run "profile")

@debug: (build "debug") (run "debug")
@profile: (build "profile") (run "profile")
@release: (build "release") (run "release")
@debug: (lint) (format) (build "debug") (run "debug")
@profile: (lint) (format) (build "profile") (run "profile")
@release: (lint) (format) (build "release") (run "release")

@lint:
cppcheck --enable=warning,performance,portability,unusedFunction,style,information --disable=missingInclude --std=c++20 bloss1/src/**
cppcheck --enable=warning,performance,portability,style,information --disable=missingInclude --std=c++20 bloss1/src/**

@format:
find bloss1/src/ -iname *.hpp -o -iname *.cpp | xargs clang-format -i -style=file
Expand Down

0 comments on commit 237d548

Please sign in to comment.