our_dick/include/gfx/ogl/shader.hpp
2022-02-10 16:56:01 -08:00

78 lines
2.2 KiB
C++

/**
This file is a part of our_dick
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_GRAPHICS_OGL_SHADER_HPP
#define OUR_DICK_GRAPHICS_OGL_SHADER_HPP
#include "gl_include.hpp"
#include <string>
namespace gfx::ogl{
//class representing an opengl shader (NOT an opengl program)
class shader
{
public:
//Strongly typed enum of possible shader types
enum class type : GLuint{
FRAGMENT = GL_FRAGMENT_SHADER,
VERTEX = GL_VERTEX_SHADER,
GEOMETRY = GL_GEOMETRY_SHADER,
COMPUTE = GL_COMPUTE_SHADER,
TESS_CONTROL = GL_TESS_CONTROL_SHADER,
TESS_EVALUATION = GL_TESS_EVALUATION_SHADER,
};
private:
GLuint m_shader_id = 0; //handle to shader object
public:
//initialize this shader with the type 't' and add no source text
explicit shader(type t);
//initialize this shader with the type 't't and load in 'data' as source text
shader(const char* data, type t);
shader(const shader&);
shader(shader&&);
~shader();
shader& operator=(const shader&);
shader& operator=(shader&&);
//change the shader source to 'data' and recompile
bool load(const char* data);
//change the shader source and shader type then recompile
bool reload(const char* data, type t);
//release ownership of the shader handle. unsafe
GLuint release();
type get_type()const;
//raw access to shader handle
GLuint raw()const;
//get most recently generated error from this shader's infolog
std::string get_error()const;
//check if an error exists after a compilation attempt
bool has_compile_error()const;
};
}
#endif