[nostalgia/core/userland] Make shader compile failures oxError and return error instead of panicing
This commit is contained in:
parent
be0de98fc2
commit
4956534af4
@ -139,7 +139,7 @@ static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *buf
|
|||||||
ox::Error init(Context *ctx) {
|
ox::Error init(Context *ctx) {
|
||||||
const auto id = new GlImplData;
|
const auto id = new GlImplData;
|
||||||
ctx->setRendererData(id);
|
ctx->setRendererData(id);
|
||||||
id->bgShader = buildShaderProgram(bgvshad, bgfshad);
|
oxReturnError(buildShaderProgram(bgvshad, bgfshad).get(&id->bgShader));
|
||||||
for (auto &bg : id->backgrounds) {
|
for (auto &bg : id->backgrounds) {
|
||||||
initBackgroundBufferset(ctx, id->bgShader, &bg);
|
initBackgroundBufferset(ctx, id->bgShader, &bg);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
|
|
||||||
namespace nostalgia::core::renderer {
|
namespace nostalgia::core::renderer {
|
||||||
|
|
||||||
[[nodiscard]] GLuint buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) {
|
[[nodiscard]]
|
||||||
|
ox::Result<GLuint> buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) {
|
||||||
auto shader = glCreateShader(shaderType);
|
auto shader = glCreateShader(shaderType);
|
||||||
glShaderSource(shader, 1, &src, nullptr);
|
glShaderSource(shader, 1, &src, nullptr);
|
||||||
glCompileShader(shader);
|
glCompileShader(shader);
|
||||||
@ -23,29 +24,31 @@ namespace nostalgia::core::renderer {
|
|||||||
static const auto errMsgSize = 1000;
|
static const auto errMsgSize = 1000;
|
||||||
char errMsg[errMsgSize];
|
char errMsg[errMsgSize];
|
||||||
glGetShaderInfoLog(shader, errMsgSize, nullptr, errMsg);
|
glGetShaderInfoLog(shader, errMsgSize, nullptr, errMsg);
|
||||||
oxTracef("nostalgia::core::gfx::gl", "shader compile error in {}: {}", shaderName, errMsg);
|
oxErrorf("shader compile error in {}: {}", shaderName, errMsg);
|
||||||
oxPanic(OxError(1), "shader compile error");
|
|
||||||
glDeleteShader(shader);
|
glDeleteShader(shader);
|
||||||
shader = 0;
|
return OxError(1, "shader compile error");
|
||||||
}
|
}
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] GLuint buildVertShader(const GLchar *src, const char *shaderName) {
|
[[nodiscard]]
|
||||||
|
ox::Result<GLuint> buildVertShader(const GLchar *src, const char *shaderName) {
|
||||||
return buildShader(GL_VERTEX_SHADER, src, shaderName);
|
return buildShader(GL_VERTEX_SHADER, src, shaderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] GLuint buildFragShader(const GLchar *src, const char *shaderName) {
|
[[nodiscard]]
|
||||||
|
ox::Result<GLuint> buildFragShader(const GLchar *src, const char *shaderName) {
|
||||||
return buildShader(GL_FRAGMENT_SHADER, src, shaderName);
|
return buildShader(GL_FRAGMENT_SHADER, src, shaderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] GLuint buildShaderProgram(const GLchar *vert, const GLchar *frag) {
|
[[nodiscard]]
|
||||||
|
ox::Result<GLuint> buildShaderProgram(const GLchar *vert, const GLchar *frag) {
|
||||||
GLuint prgm = 0;
|
GLuint prgm = 0;
|
||||||
const auto vs = buildVertShader(vert, "vshad");
|
oxRequire(vs, buildVertShader(vert, "vshad"));
|
||||||
if (!vs) {
|
if (!vs) {
|
||||||
glDeleteShader(vs);
|
glDeleteShader(vs);
|
||||||
} else {
|
} else {
|
||||||
const auto fs = buildFragShader(frag, "fshad");
|
oxRequire(fs, buildFragShader(frag, "fshad"));
|
||||||
if (!fs) {
|
if (!fs) {
|
||||||
// cleanup shaders that were created
|
// cleanup shaders that were created
|
||||||
glDeleteShader(fs);
|
glDeleteShader(fs);
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <ox/std/error.hpp>
|
||||||
|
|
||||||
namespace nostalgia::core::renderer {
|
namespace nostalgia::core::renderer {
|
||||||
|
|
||||||
struct Texture {
|
struct Texture {
|
||||||
@ -39,7 +41,8 @@ struct Bufferset {
|
|||||||
GLsizei eboElements = 0;
|
GLsizei eboElements = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] GLuint buildShaderProgram(const GLchar *vert, const GLchar *frag);
|
[[nodiscard]]
|
||||||
|
ox::Result<GLuint> buildShaderProgram(const GLchar *vert, const GLchar *frag);
|
||||||
|
|
||||||
void destroy(const Bufferset &bufferset);
|
void destroy(const Bufferset &bufferset);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user