/* * * 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 . */ #ifndef BLT_WITH_GRAPHICS_STATE_H #define BLT_WITH_GRAPHICS_STATE_H #include #include #include 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 void setView(U&& mat) { view = std::forward(mat); } template void setPerspective(U&& mat) { perspective = std::forward(mat); } void update(); }; } #endif //BLT_WITH_GRAPHICS_STATE_H