summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/shader.cpp11
-rw-r--r--gfx/gl/shader.h7
2 files changed, 16 insertions, 2 deletions
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index 285c2c3..b57dcd4 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -10,7 +10,16 @@ Shader::compile() const
auto source = [&shader](auto text, GLint len) {
glShaderSource(shader, 1, &text, &len);
};
- source(text.data(), static_cast<GLint>(text.length()));
+ 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");
+ }
+ 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!");
diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h
index cc1bbc0..c6b45af 100644
--- a/gfx/gl/shader.h
+++ b/gfx/gl/shader.h
@@ -3,12 +3,16 @@
#include <glRef.h>
#include <glad/gl.h>
#include <string_view>
+#include <thirdparty/ctre/include/ctre.hpp>
class Shader {
public:
using ShaderRef = glRef<GLuint, &glCreateShader, &glDeleteShader>;
- constexpr Shader(const GLchar * text, GLuint type) : text {text}, type {type} { }
+ constexpr Shader(const GLchar * text, GLuint type) :
+ text {text}, type {type}, lookups {ctre::search<R"(\bGL_[A-Z_]+\b)">(this->text)}
+ {
+ }
[[nodiscard]] ShaderRef compile() const;
static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);
@@ -16,4 +20,5 @@ public:
private:
const std::basic_string_view<GLchar> text;
GLuint type;
+ bool lookups;
};