2022-02-10 16:56:01 -08:00

96 lines
2.5 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_FBO_HPP
#define OUR_DICK_GRAPHICS_OGL_FBO_HPP
#include "gl_include.hpp"
#include "texture.hpp"
#include "rbo.hpp"
#include "math/vec.hpp"
#include "util/init_constants.hpp"
namespace gfx::ogl{
class fbo
{
private:
GLuint m_buffer;
math::vec4<GLfloat> m_vp_coords;
public:
fbo();
template<typename... Args>
explicit fbo(Args&&... args);
explicit fbo(util::no_initialize_t);
fbo(const fbo&) = delete;
fbo(fbo&& f);
~fbo();
fbo& operator=(const fbo&) = delete;
fbo& operator=(fbo&& f);
GLuint raw()const;
bool detach(GLenum point);
bool attach(const texture& tex, GLenum point);
bool attach(const rbo& r, GLenum point);
void clear_color_buffer(const math::vec4<GLfloat>& color = {0.0f, 0.0f, 0.0f, 1.0f});
void clear_depth_buffer(GLfloat value = 1.0f);
void clear_stencil_buffer(GLint value = 0);
void clear(GLbitfield mask);
void set_viewport(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
void apply_viewport()const;
const math::vec4<GLfloat>& get_viewport()const;
bool bind()const;
private:
template<typename... Args>
void i_attach(const rbo& r, GLenum point, Args&&... args);
template<typename... Args>
void i_attach(const texture& r, GLenum point, Args&&... args);
};
template<typename... Args>
fbo::fbo(Args&&... args):
fbo()
{
i_attach(std::forward<Args>(args)...);
}
template<typename... Args>
void fbo::i_attach(const rbo& r, GLenum point, Args&&... args){
attach(r, point);
if constexpr(sizeof...(args) > 0){
i_attach(std::forward<Args>(args)...);
}
}
template<typename... Args>
void fbo::i_attach(const texture& t, GLenum point, Args&&... args){
attach(t, point);
if constexpr(sizeof...(args) > 0){
i_attach(std::forward<Args>(args)...);
}
}
}
#endif