Files
our_dick/src/graphics/rbo.cpp

82 lines
1.9 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/>.
*/
#include "graphics/rbo.hpp"
#include <utility> //swap, exchange
namespace gfx{
rbo::rbo(GLsizei width, GLsizei height, GLenum format, GLsizei samples):
m_format(format),
m_width(width),
m_height(height)
{
glGenRenderbuffers(1, &m_buffer);
bind();
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, m_format, m_width, m_height);
unbind();
}
rbo::rbo(rbo&& r):
m_buffer(std::exchange(r.m_buffer, 0)),
m_format(r.m_format),
m_width(r.m_width),
m_height(r.m_height){}
rbo::~rbo(){
if(m_buffer)
glDeleteRenderbuffers(1, &m_buffer);
}
rbo& rbo::operator=(rbo&& r){
std::swap(m_buffer, r.m_buffer);
m_format = r.m_format;
m_width = r.m_width;
m_height = r.m_height;
return *this;
}
GLuint rbo::raw()const{
return m_buffer;
}
void rbo::bind()const{
glBindRenderbuffer(GL_RENDERBUFFER, m_buffer);
}
void rbo::unbind()const{
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
void rbo::resize(GLsizei w, GLsizei h){
*this = rbo(w, h, m_format);
}
void rbo::reformat(GLenum format){
*this = rbo(m_width, m_height, format);
}
GLuint rbo::release(){
return std::exchange(m_buffer, 0);
}
GLsizei rbo::get_width()const{
return m_width;
}
GLsizei rbo::get_height()const{
return m_height;
}
}