summaryrefslogtreecommitdiff
path: root/gfx/gl/shader.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-24 00:46:57 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-24 00:46:57 +0000
commit17aa6053e641d006649f94bb60a834ce945f351e (patch)
treeb76f6fc642b749ee69d4be4b2e3f60e80c0ed7bc /gfx/gl/shader.cpp
parentAdd traits wrapper for setting uniforms (diff)
parentFix network population of position in gBuffer (diff)
downloadilt-17aa6053e641d006649f94bb60a834ce945f351e.tar.bz2
ilt-17aa6053e641d006649f94bb60a834ce945f351e.tar.xz
ilt-17aa6053e641d006649f94bb60a834ce945f351e.zip
Merge remote-tracking branch 'origin/instanced-networks'
Diffstat (limited to 'gfx/gl/shader.cpp')
-rw-r--r--gfx/gl/shader.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index 5f83b83..0f75817 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -1,13 +1,48 @@
#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
{
ShaderRef shader {type};
- glShaderSource(shader, 1, &text, &len);
+ auto source = [&shader](auto text, GLint len) {
+ glShaderSource(shader, 1, &text, &len);
+ };
+ if (lookups) {
+ std::basic_string<GLchar> textMod {text};
+ for (const auto & match : ctre::range<R"(\bGL_[A-Z_]+\b)">(textMod)) {
+ 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()));
+ }
+ else {
+ source(text.data(), static_cast<GLint>(text.length()));
+ }
glCompileShader(shader);
CheckShaderError(shader, GL_COMPILE_STATUS, false, "Error compiling shader!");