diff options
-rw-r--r-- | gfx/gl/shader.cpp | 5 | ||||
-rw-r--r-- | gfx/gl/shader.h | 6 | ||||
-rw-r--r-- | lib/embed-glsl.cpp.m4 | 9 | ||||
-rw-r--r-- | lib/strlen.h | 14 |
4 files changed, 9 insertions, 25 deletions
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp index 5f83b83..285c2c3 100644 --- a/gfx/gl/shader.cpp +++ b/gfx/gl/shader.cpp @@ -7,7 +7,10 @@ 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); + }; + 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 cff2281..cc1bbc0 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -2,20 +2,18 @@ #include <glRef.h> #include <glad/gl.h> -#include <optional> #include <string_view> class Shader { public: using ShaderRef = glRef<GLuint, &glCreateShader, &glDeleteShader>; - constexpr Shader(const GLchar * text, GLint len, GLuint type) : text {text}, len {len}, type {type} { } + constexpr Shader(const GLchar * text, GLuint type) : text {text}, type {type} { } [[nodiscard]] ShaderRef compile() const; static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage); private: - const GLchar * text; - GLint len; + const std::basic_string_view<GLchar> text; GLuint type; }; diff --git a/lib/embed-glsl.cpp.m4 b/lib/embed-glsl.cpp.m4 index 60fb56b..9fe0b41 100644 --- a/lib/embed-glsl.cpp.m4 +++ b/lib/embed-glsl.cpp.m4 @@ -1,12 +1,9 @@ changecom() dnl // NAME #include "gfx/gl/shader.h" -#include "lib/strlen.h" #include "substr(TYPE,1)-NAME.h" #include <glad/gl.h> - constexpr const GLchar * src {R"GLSL-EMBED(dnl -include(SOURCE))GLSL-EMBED"}; -constexpr auto len {constexpr_strlen(src)}; - -const Shader NAME`_'substr(TYPE,1) { src, len, GLTYPE }; +constexpr Shader NAME`_'substr(TYPE,1) { + R"GLSL-EMBED(dnl + include(SOURCE))GLSL-EMBED", GLTYPE }; diff --git a/lib/strlen.h b/lib/strlen.h deleted file mode 100644 index 2090d25..0000000 --- a/lib/strlen.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include <cstddef> -#include <glad/gl.h> - -constexpr auto -constexpr_strlen(const GLchar * const s) -{ - std::size_t ch {}; - while (s[ch]) { - ch++; - } - return ch; -} |