BLT-With-Graphics-Template/include/blt/gfx/state.h

77 lines
2.0 KiB
C
Raw Normal View History

/*
* <Short Description>
* Copyright (C) 2023 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_WITH_GRAPHICS_STATE_H
#define BLT_WITH_GRAPHICS_STATE_H
#include <blt/gfx/shader.h>
#include <blt/math/vectors.h>
#include <blt/math/matrix.h>
namespace blt::gfx
{
/**
* layout (std140) uniform GlobalMatrices
* {
* mat4 projection;
* mat4 view;
* mat4 pvm;
* };
*/
class matrix_state_manager
{
private:
blt::mat4x4 perspective;
blt::mat4x4 view;
blt::mat4x4 pv;
uniform_buffer* global_matrix_ubo = nullptr;
public:
[[nodiscard]] inline const blt::mat4x4& computedPV() const
{
return pv;
}
void create_internals()
{
global_matrix_ubo = new uniform_buffer(sizeof(blt::mat4x4) * 3);
}
void delete_internals()
{
delete global_matrix_ubo;
}
template<typename U>
void setView(U&& mat)
{
view = std::forward(mat);
}
template<typename U>
void setPerspective(U&& mat)
{
perspective = std::forward(mat);
}
void update();
};
}
#endif //BLT_WITH_GRAPHICS_STATE_H