/* * Copyright 2016 - 2021 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include "glutils.hpp" namespace nostalgia::core::renderer { template struct GLobject; template struct GLobject; [[nodiscard]] static ox::Result buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) { const auto shader = glCreateShader(shaderType); glShaderSource(shader, 1, &src, nullptr); glCompileShader(shader); GLint status; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (status != GL_TRUE) { std::array errMsg; glGetShaderInfoLog(shader, errMsg.size(), nullptr, errMsg.data()); oxErrorf("shader compile error in {}: {}", shaderName, errMsg.data()); glDeleteShader(shader); return OxError(1, "shader compile error"); } return Shader(shader); } [[nodiscard]] ox::Result buildShaderProgram(const GLchar *vert, const GLchar *frag) { oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert, "vshad")); oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag, "fshad")); Program prgm(glCreateProgram()); glAttachShader(prgm, vs); glAttachShader(prgm, fs); glLinkProgram(prgm); return ox::move(prgm); } void destroy(const Bufferset &bufferset) { glDeleteVertexArrays(1, &bufferset.vao); glDeleteBuffers(1, &bufferset.ebo); glDeleteBuffers(1, &bufferset.vbo); } }