From 4956534af4f95ac67b830837f0ced38b5a6ef71a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 18 Mar 2021 01:34:07 -0500 Subject: [PATCH] [nostalgia/core/userland] Make shader compile failures oxError and return error instead of panicing --- src/nostalgia/core/userland/gfx_opengl.cpp | 2 +- src/nostalgia/core/userland/glutils.cpp | 21 ++++++++++++--------- src/nostalgia/core/userland/glutils.hpp | 5 ++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/nostalgia/core/userland/gfx_opengl.cpp b/src/nostalgia/core/userland/gfx_opengl.cpp index 61e86ab1..cf006ae4 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 3dfe0490..4442d4fc 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 0adae2f9..a556dc4e 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);