summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-21 03:01:44 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-21 03:01:44 +0000
commit2368cde54675f39e9b5a99880124503b3ae391e1 (patch)
tree31ffa54a9ea46061f0138d244dd6081c58779e66 /gfx
parentLook for and replace GL_XXX with fixed string (diff)
downloadilt-2368cde54675f39e9b5a99880124503b3ae391e1.tar.bz2
ilt-2368cde54675f39e9b5a99880124503b3ae391e1.tar.xz
ilt-2368cde54675f39e9b5a99880124503b3ae391e1.zip
Replace tokens found with values from getIntegerv
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shader.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index b57dcd4..0f75817 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -1,8 +1,24 @@
#include "shader.h"
+#include <algorithm>
#include <array>
#include <stdexcept>
#include <string>
+namespace {
+ auto
+ getInt(GLenum e)
+ {
+ GLint i {};
+ glGetIntegerv(e, &i);
+ return std::to_string(i);
+ }
+
+ using LookUpFunction = std::string (*)(GLenum);
+ constexpr std::array<std::tuple<std::string_view, GLenum, LookUpFunction>, 1> LOOKUPS {{
+ {"GL_MAX_GEOMETRY_OUTPUT_VERTICES", GL_MAX_GEOMETRY_OUTPUT_VERTICES, getInt},
+ }};
+}
+
Shader::ShaderRef
Shader::compile() const
{
@@ -13,7 +29,14 @@ Shader::compile() const
if (lookups) {
std::basic_string<GLchar> textMod {text};
for (const auto & match : ctre::range<R"(\bGL_[A-Z_]+\b)">(textMod)) {
- textMod.replace(match.begin(), match.end(), "255");
+ if (const auto lookup = std::find_if(LOOKUPS.begin(), LOOKUPS.end(),
+ [&match](const auto & lookup) {
+ return std::get<std::string_view>(lookup) == match;
+ });
+ lookup != LOOKUPS.end()) {
+ const auto & [name, pname, getFunction] = *lookup;
+ textMod.replace(match.begin(), match.end(), getFunction(pname));
+ }
}
source(textMod.c_str(), static_cast<GLint>(textMod.length()));
}