From 256cb8a82c07bd795b66435d89cdd62c3e570ea1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 4 Apr 2020 00:11:00 +1000 Subject: [PATCH] GL/Program: Make moveable --- src/common/gl/program.cpp | 26 ++++++++++++++++++++++++++ src/common/gl/program.h | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/src/common/gl/program.cpp b/src/common/gl/program.cpp index 99455bcad..787653fe6 100644 --- a/src/common/gl/program.cpp +++ b/src/common/gl/program.cpp @@ -13,6 +13,17 @@ static GLuint s_next_bad_shader_id = 1; Program::Program() = default; +Program::Program(Program&& prog) +{ + m_program_id = prog.m_program_id; + prog.m_program_id = 0; + m_vertex_shader_id = prog.m_vertex_shader_id; + prog.m_vertex_shader_id = 0; + m_fragment_shader_id = prog.m_fragment_shader_id; + prog.m_fragment_shader_id = 0; + m_uniform_locations = std::move(prog.m_uniform_locations); +} + Program::~Program() { Destroy(); @@ -174,6 +185,8 @@ void Program::Destroy() glDeleteProgram(m_program_id); m_program_id = 0; } + + m_uniform_locations.clear(); } int Program::RegisterUniform(const char* name) @@ -505,4 +518,17 @@ void Program::BindUniformBlock(const char* name, u32 index) glUniformBlockBinding(m_program_id, location, index); } +Program& Program::operator=(Program&& prog) +{ + Destroy(); + m_program_id = prog.m_program_id; + prog.m_program_id = 0; + m_vertex_shader_id = prog.m_vertex_shader_id; + prog.m_vertex_shader_id = 0; + m_fragment_shader_id = prog.m_fragment_shader_id; + prog.m_fragment_shader_id = 0; + m_uniform_locations = std::move(prog.m_uniform_locations); + return *this; +} + } // namespace GL \ No newline at end of file diff --git a/src/common/gl/program.h b/src/common/gl/program.h index ece24daaa..8144b88f8 100644 --- a/src/common/gl/program.h +++ b/src/common/gl/program.h @@ -9,6 +9,8 @@ class Program { public: Program(); + Program(const Program&) = delete; + Program(Program&& prog); ~Program(); static GLuint CompileShader(GLenum type, const std::string_view source); @@ -78,6 +80,9 @@ public: void BindUniformBlock(const char* name, u32 index); + Program& operator=(const Program&) = delete; + Program& operator=(Program&& prog); + private: static u32 s_last_program_id;