summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-12 15:33:09 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-12 15:48:47 +0000
commitdcdff7828e1dc3b5cbfc10a30ee10c2ffec07987 (patch)
treef2d0e52661d38f389c8686b7b6fcd5afe4efafe8
parentMove generic constexpr_strlen to lib (diff)
downloadilt-dcdff7828e1dc3b5cbfc10a30ee10c2ffec07987.tar.bz2
ilt-dcdff7828e1dc3b5cbfc10a30ee10c2ffec07987.tar.xz
ilt-dcdff7828e1dc3b5cbfc10a30ee10c2ffec07987.zip
Move GL shared source into it's own class/file
-rw-r--r--gfx/gl/glSource.cpp38
-rw-r--r--gfx/gl/glSource.h (renamed from gfx/gl/shader-source.h)1
-rw-r--r--gfx/gl/shader.cpp41
-rw-r--r--gfx/gl/shader.h2
-rw-r--r--lib/embed-glsl.cpp.m42
-rw-r--r--lib/embed-glsl.h.m42
6 files changed, 44 insertions, 42 deletions
diff --git a/gfx/gl/glSource.cpp b/gfx/gl/glSource.cpp
new file mode 100644
index 0000000..13686ae
--- /dev/null
+++ b/gfx/gl/glSource.cpp
@@ -0,0 +1,38 @@
+#include "glSource.h"
+#include <array>
+
+GLsource::ShaderRef
+GLsource::compile() const
+{
+ ShaderRef id {type};
+ glShaderSource(id, 1, &text, &len);
+ glCompileShader(id);
+
+ CheckShaderError(id, GL_COMPILE_STATUS, false, "Error compiling shader!");
+ return id;
+}
+
+void
+GLsource::CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage)
+{
+ GLint success = 0;
+ std::array<GLchar, 1024> error {};
+
+ if (isProgram) {
+ glGetProgramiv(shader, flag, &success);
+ }
+ else {
+ glGetShaderiv(shader, flag, &success);
+ }
+
+ if (success == GL_FALSE) {
+ if (isProgram) {
+ glGetProgramInfoLog(shader, error.size(), nullptr, error.data());
+ }
+ else {
+ glGetShaderInfoLog(shader, error.size(), nullptr, error.data());
+ }
+
+ throw std::runtime_error {std::string {errorMessage} + ": '" + std::string {error.data(), error.size()} + "'"};
+ }
+}
diff --git a/gfx/gl/shader-source.h b/gfx/gl/glSource.h
index 524025c..53c221b 100644
--- a/gfx/gl/shader-source.h
+++ b/gfx/gl/glSource.h
@@ -12,6 +12,7 @@ struct GLsource {
GLuint type;
[[nodiscard]] ShaderRef compile() const;
+ static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);
};
#endif
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index 771db97..06edc5c 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -1,5 +1,5 @@
#include "shader.h"
-#include "gfx/gl/shader-source.h"
+#include "gfx/gl/glSource.h"
#include <array>
#include <cstddef>
#include <gfx/gl/shaders/fs-basicShader.h>
@@ -26,10 +26,10 @@ Shader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : viewProjection_unif
glBindAttribLocation(m_program, 2, "normal");
glLinkProgram(m_program);
- CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program");
+ GLsource::CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program");
glValidateProgram(m_program);
- CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program");
+ GLsource::CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program");
viewProjection_uniform = glGetUniformLocation(m_program, "viewProjection");
model_uniform = glGetUniformLocation(m_program, "model");
@@ -86,38 +86,3 @@ Shader::setModel(const Location & loc, Program pid) const
}
}
-void
-Shader::CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage)
-{
- GLint success = 0;
- std::array<GLchar, 1024> error {};
-
- if (isProgram) {
- glGetProgramiv(shader, flag, &success);
- }
- else {
- glGetShaderiv(shader, flag, &success);
- }
-
- if (success == GL_FALSE) {
- if (isProgram) {
- glGetProgramInfoLog(shader, error.size(), nullptr, error.data());
- }
- else {
- glGetShaderInfoLog(shader, error.size(), nullptr, error.data());
- }
-
- throw std::runtime_error {std::string {errorMessage} + ": '" + std::string {error.data(), error.size()} + "'"};
- }
-}
-
-GLsource::ShaderRef
-GLsource::compile() const
-{
- ShaderRef id {type};
- glShaderSource(id, 1, &text, &len);
- glCompileShader(id);
-
- Shader::CheckShaderError(id, GL_COMPILE_STATUS, false, "Error compiling shader!");
- return id;
-}
diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h
index 8b18e99..3ee9449 100644
--- a/gfx/gl/shader.h
+++ b/gfx/gl/shader.h
@@ -19,8 +19,6 @@ public:
void setModel(const Location &, Program = Program::Basic) const;
void setUniform(const GLchar *, glm::vec3 dir) const;
- static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);
-
private:
class ProgramHandle {
public:
diff --git a/lib/embed-glsl.cpp.m4 b/lib/embed-glsl.cpp.m4
index d820756..003db65 100644
--- a/lib/embed-glsl.cpp.m4
+++ b/lib/embed-glsl.cpp.m4
@@ -2,7 +2,7 @@ changecom()dnl
// NAME
#include "substr(TYPE,1)-NAME.h"
#include <GL/glew.h>
-#include "gfx/gl/shader-source.h"
+#include "gfx/gl/glSource.h"
#include "lib/strings.hpp"
constexpr const GLchar * src { R"GLSL-EMBED(dnl
diff --git a/lib/embed-glsl.h.m4 b/lib/embed-glsl.h.m4
index 918007b..f277c56 100644
--- a/lib/embed-glsl.h.m4
+++ b/lib/embed-glsl.h.m4
@@ -1,4 +1,4 @@
// NAME
-#include <gfx/gl/shader-source.h>
+#include <gfx/gl/glSource.h>
extern const GLsource NAME`_'substr(TYPE,1);