BLT-With-Graphics-Template/include/blt/gfx/renderer/postprocess.h

151 lines
3.9 KiB
C
Raw Normal View History

#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef BLT_GRAPHICS_POST_PROCESS_H
#define BLT_GRAPHICS_POST_PROCESS_H
#include <blt/std/types.h>
#include <blt/gfx/framebuffer.h>
#include <blt/gfx/shader.h>
#include <blt/gfx/model.h>
#include <vector>
#include <memory>
namespace blt::gfx
{
2024-05-03 22:14:48 -04:00
class pp_engine_t;
2024-05-03 22:14:48 -04:00
class pp_step_t;
class pp_step_t
{
public:
virtual void create()
{}
// only called on render()
virtual void draw(pp_step_t&)
{}
// only called on bind()
virtual void draw()
{}
auto& getBuffer()
{
return draw_buffer;
}
2024-05-03 22:14:48 -04:00
auto& getShader()
2024-05-03 22:14:48 -04:00
{
return *shader;
}
bool hasShader()
{
return shader != nullptr;
}
2024-05-03 22:14:48 -04:00
virtual ~pp_step_t() = default;
protected:
2024-05-03 20:03:31 -04:00
frame_buffer_t draw_buffer;
2024-05-03 22:14:48 -04:00
std::unique_ptr<shader_t> shader;
};
class pp_render_target_t : public pp_step_t
{
public:
void create() override;
void draw() override;
};
class pp_to_screen_step_t : public pp_step_t
{
public:
void create() override;
void draw(pp_step_t& previous) override;
};
class pp_outline_target : public pp_step_t
{
public:
void create() override;
2024-05-03 22:14:48 -04:00
void draw() override;
};
class pp_outline_step_t : public pp_step_t
{
public:
void create() override;
void draw(pp_step_t& previous) override;
};
2024-05-03 22:14:48 -04:00
class pp_engine_t
{
public:
void create();
2024-05-03 22:14:48 -04:00
void bind();
void render();
void cleanup();
void addStep(std::unique_ptr<pp_step_t> step)
{
steps.emplace_back(std::move(step));
}
static std::unique_ptr<shader_t> createShader(std::string_view fragment);
static std::unique_ptr<pp_engine_t> make_basic_pp()
{
return make_single_pp(std::make_unique<pp_render_target_t>());
}
static std::unique_ptr<pp_engine_t> make_single_pp(std::unique_ptr<pp_step_t> step)
{
auto engine = new pp_engine_t();
engine->addStep(std::move(step));
return std::unique_ptr<pp_engine_t>(engine);
}
template<typename... Args>
static std::unique_ptr<pp_engine_t> make_multi_pp(Args... steps)
{
auto engine = new pp_engine_t();
(engine->addStep(std::move(steps)), ...);
return std::unique_ptr<pp_engine_t>(engine);
}
private:
pp_engine_t() = default;
2024-05-03 22:14:48 -04:00
std::vector<std::unique_ptr<pp_step_t>> steps;
std::unique_ptr<vertex_array_t> screen_vao;
};
}
#endif //BLT_GRAPHICS_POST_PROCESS_H