diff --git a/src/nostalgia/core/userland/gfx_opengl.cpp b/src/nostalgia/core/userland/gfx_opengl.cpp index 61e86ab1d..cf006ae4b 100644 --- a/src/nostalgia/core/userland/gfx_opengl.cpp +++ b/src/nostalgia/core/userland/gfx_opengl.cpp @@ -139,7 +139,7 @@ static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *buf ox::Error init(Context *ctx) { const auto id = new GlImplData; ctx->setRendererData(id); - id->bgShader = buildShaderProgram(bgvshad, bgfshad); + oxReturnError(buildShaderProgram(bgvshad, bgfshad).get(&id->bgShader)); for (auto &bg : id->backgrounds) { initBackgroundBufferset(ctx, id->bgShader, &bg); } diff --git a/src/nostalgia/core/userland/glutils.cpp b/src/nostalgia/core/userland/glutils.cpp index 3dfe0490b..4442d4fc4 100644 --- a/src/nostalgia/core/userland/glutils.cpp +++ b/src/nostalgia/core/userland/glutils.cpp @@ -13,7 +13,8 @@ namespace nostalgia::core::renderer { -[[nodiscard]] GLuint buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) { +[[nodiscard]] +ox::Result buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) { auto shader = glCreateShader(shaderType); glShaderSource(shader, 1, &src, nullptr); glCompileShader(shader); @@ -23,29 +24,31 @@ namespace nostalgia::core::renderer { static const auto errMsgSize = 1000; char errMsg[errMsgSize]; glGetShaderInfoLog(shader, errMsgSize, nullptr, errMsg); - oxTracef("nostalgia::core::gfx::gl", "shader compile error in {}: {}", shaderName, errMsg); - oxPanic(OxError(1), "shader compile error"); + oxErrorf("shader compile error in {}: {}", shaderName, errMsg); glDeleteShader(shader); - shader = 0; + return OxError(1, "shader compile error"); } return shader; } -[[nodiscard]] GLuint buildVertShader(const GLchar *src, const char *shaderName) { +[[nodiscard]] +ox::Result buildVertShader(const GLchar *src, const char *shaderName) { return buildShader(GL_VERTEX_SHADER, src, shaderName); } -[[nodiscard]] GLuint buildFragShader(const GLchar *src, const char *shaderName) { +[[nodiscard]] +ox::Result buildFragShader(const GLchar *src, const char *shaderName) { return buildShader(GL_FRAGMENT_SHADER, src, shaderName); } -[[nodiscard]] GLuint buildShaderProgram(const GLchar *vert, const GLchar *frag) { +[[nodiscard]] +ox::Result buildShaderProgram(const GLchar *vert, const GLchar *frag) { GLuint prgm = 0; - const auto vs = buildVertShader(vert, "vshad"); + oxRequire(vs, buildVertShader(vert, "vshad")); if (!vs) { glDeleteShader(vs); } else { - const auto fs = buildFragShader(frag, "fshad"); + oxRequire(fs, buildFragShader(frag, "fshad")); if (!fs) { // cleanup shaders that were created glDeleteShader(fs); diff --git a/src/nostalgia/core/userland/glutils.hpp b/src/nostalgia/core/userland/glutils.hpp index 0adae2f9b..a556dc4ec 100644 --- a/src/nostalgia/core/userland/glutils.hpp +++ b/src/nostalgia/core/userland/glutils.hpp @@ -14,6 +14,8 @@ #include #endif +#include + namespace nostalgia::core::renderer { struct Texture { @@ -39,7 +41,8 @@ struct Bufferset { GLsizei eboElements = 0; }; -[[nodiscard]] GLuint buildShaderProgram(const GLchar *vert, const GLchar *frag); +[[nodiscard]] +ox::Result buildShaderProgram(const GLchar *vert, const GLchar *frag); void destroy(const Bufferset &bufferset);