diff --git a/src/nostalgia/glutils/glutils.cpp b/src/nostalgia/glutils/glutils.cpp index 22d52e53..69cd7513 100644 --- a/src/nostalgia/glutils/glutils.cpp +++ b/src/nostalgia/glutils/glutils.cpp @@ -49,26 +49,30 @@ static ox::Result buildShader(GLuint shaderType, const GLchar *src, co GLint status; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (status != GL_TRUE) { - ox::BString<1000> errMsg; - glGetShaderInfoLog(shader, errMsg.cap(), nullptr, errMsg.data()); - oxErrorf("shader compile error in {}: {}", shaderName, errMsg); + ox::Vector errMsg(1000); + glGetShaderInfoLog(shader, static_cast(errMsg.size()), nullptr, errMsg.data()); + oxErrorf("shader compile error in {}: {}", shaderName, errMsg.data()); return OxError(1, "shader compile error"); } return shader; } -ox::Result buildShaderProgram(const GLchar *vert, const GLchar *frag) noexcept { - oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert, "vshad")); - oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag, "fshad")); +ox::Result buildShaderProgram(const GLchar *vert, const GLchar *frag, [[maybe_unused]] const GLchar *geo) noexcept { GLProgram prgm(glCreateProgram()); + oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert, "vshad")); glAttachShader(prgm, vs); + oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag, "fshad")); glAttachShader(prgm, fs); + if (geo && ox_strlen(geo) != 0) { + oxRequire(gs, buildShader(GL_GEOMETRY_SHADER, geo, "gshad")); + glAttachShader(prgm, gs); + } glLinkProgram(prgm); return prgm; } -ox::Result buildShaderProgram(const ox::String &vert, const ox::String &frag) noexcept { - return buildShaderProgram(vert.c_str(), frag.c_str()); +ox::Result buildShaderProgram(const ox::String &vert, const ox::String &frag, const ox::String &geo) noexcept { + return buildShaderProgram(vert.c_str(), frag.c_str(), geo.c_str()); } GLVertexArray generateVertexArrayObject() noexcept { @@ -105,7 +109,6 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept { oxAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Frame Buffer is incomplete"); // restore primary FB glBindFramebuffer(GL_FRAMEBUFFER, 0); - oxAssert(glGetError() == 0, "Framebuffer creation failed"); return fb; } diff --git a/src/nostalgia/glutils/glutils.hpp b/src/nostalgia/glutils/glutils.hpp index 5028cca8..188d3a7f 100644 --- a/src/nostalgia/glutils/glutils.hpp +++ b/src/nostalgia/glutils/glutils.hpp @@ -18,7 +18,7 @@ #endif #include #else -#include +#include #endif #include @@ -66,7 +66,7 @@ struct GLObject: public Base { this->id = id; } - constexpr GLObject(GLObject &&o) noexcept: Base(ox::move(o)) { + constexpr GLObject(GLObject &&o) noexcept: Base(std::move(o)) { id = o.id; o.id = 0; } @@ -78,7 +78,7 @@ struct GLObject: public Base { GLObject &operator=(GLObject &&o) noexcept { if (this != &o) { del(id); - Base::operator=(ox::move(o)); + Base::operator=(std::move(o)); id = o.id; o.id = 0; } @@ -145,9 +145,9 @@ struct FrameBuffer { }; -ox::Result buildShaderProgram(const GLchar *vert, const GLchar *frag) noexcept; +ox::Result buildShaderProgram(const GLchar *vert, const GLchar *frag, const GLchar *geo = nullptr) noexcept; -ox::Result buildShaderProgram(const ox::String &vert, const ox::String &frag) noexcept; +ox::Result buildShaderProgram(const ox::String &vert, const ox::String &frag, const ox::String &geo = "") noexcept; glutils::GLVertexArray generateVertexArrayObject() noexcept;