summaryrefslogtreecommitdiff
path: root/gfx/gl/glSource.cpp
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 /gfx/gl/glSource.cpp
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
Diffstat (limited to 'gfx/gl/glSource.cpp')
-rw-r--r--gfx/gl/glSource.cpp38
1 files changed, 38 insertions, 0 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()} + "'"};
+ }
+}