summaryrefslogtreecommitdiff
path: root/chisel/backends/opengl/program.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chisel/backends/opengl/program.cpp')
-rw-r--r--chisel/backends/opengl/program.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/chisel/backends/opengl/program.cpp b/chisel/backends/opengl/program.cpp
new file mode 100644
index 0000000..c155320
--- /dev/null
+++ b/chisel/backends/opengl/program.cpp
@@ -0,0 +1,34 @@
+#include "gfx.h"
+#include "program.h"
+
+namespace gfx {
+ Program::Program() {
+ _program_id = glCreateProgram();
+ }
+ Program::Program(Program&& other) : _program_id(other._program_id) {
+ other._program_id = 0;
+ }
+ Program::~Program() {
+ if (!_program_id)
+ return;
+
+ // Delete the program
+ glDeleteProgram(_program_id);
+ }
+ void Program::attach(Shader& shader) {
+ glAttachShader(_program_id, shader.shader_id());
+ }
+ void Program::link() {
+ glLinkProgram(_program_id);
+ }
+ void Program::use() {
+ if (state::current_program_id == _program_id)
+ return;
+
+ glUseProgram(_program_id);
+ state::current_program_id = _program_id;
+ }
+ GLuint Program::program_id() {
+ return _program_id;
+ }
+} \ No newline at end of file