Path Tracing
Loading...
Searching...
No Matches
program.hpp
Go to the documentation of this file.
1#pragma once
2#include <GL/glew.h>
3#include <common/shader.hpp>
4#include <initializer_list>
5#include <utility>
6
12class GLProgram {
13 GLuint id_ = 0;
14public:
15 GLProgram() = default;
17
18 GLProgram(const GLProgram&) = delete;
19 GLProgram& operator=(const GLProgram&) = delete;
20
21 GLProgram(GLProgram&& other) noexcept : id_(std::exchange(other.id_, 0)) {}
22 GLProgram& operator=(GLProgram&& other) noexcept {
23 if(this != &other) { reset(); id_ = std::exchange(other.id_, 0); }
24 return *this;
25 }
26
27 bool load(std::initializer_list<std::pair<GLenum, const char*>> shaders) {
28 GLuint new_id = LoadShaders(shaders);
29 if(new_id == 0) return false;
30 reset();
31 id_ = new_id;
32 return true;
33 }
34
35 void reset() {
36 if(id_) { glDeleteProgram(id_); id_ = 0; }
37 }
38
39 GLuint id() const { return id_; }
40 explicit operator bool() const { return id_ != 0; }
41 void use() const { glUseProgram(id_); }
42};
GLProgram()=default
GLProgram(const GLProgram &)=delete
GLProgram(GLProgram &&other) noexcept
Definition program.hpp:21
void reset()
Definition program.hpp:35
bool load(std::initializer_list< std::pair< GLenum, const char * > > shaders)
Definition program.hpp:27
GLuint id() const
Definition program.hpp:39
GLProgram & operator=(GLProgram &&other) noexcept
Definition program.hpp:22
GLProgram & operator=(const GLProgram &)=delete
void use() const
Definition program.hpp:41
~GLProgram()
Definition program.hpp:16
unsigned int GLuint
Definition imgui_impl_opengl3_loader.h:147
#define glDeleteProgram
Definition imgui_impl_opengl3_loader.h:581
#define glUseProgram
Definition imgui_impl_opengl3_loader.h:624
GLuint LoadShaders(std::initializer_list< std::pair< GLenum, const char * > > shaders)
Compile shaders Compiles and links on runtime any type of shader (VERTEX, FRAGMENT,...
Definition shader.cpp:107
OpenGL shader compilation header.