// // opengl_renderer.h // graphics // // Created by Sam Jaffe on 6/2/19. // Copyright © 2019 Sam Jaffe. All rights reserved. // #pragma once #include "../helper.hpp" #include "../renderer_impl.hpp" #include "game/graphics/manager.hpp" #include "game/util/identity.hpp" #include "matrix/matrix.hpp" #include "matrix/matrix_helpers.hpp" namespace graphics { struct opengl_uniform_data { unsigned int operator[](materials::uniform id) { return uniform_id[id]; } std::unordered_map uniform_id; }; class opengl_manager : public manager { public: shader compile(shaders::type type, std::string const & path) const override; shader_program compile(identity fragment, identity vertex) const override; texture compile(textures::format color, math::vec2i size, void const * buffer) const override; opengl_uniform_data & data(identity id); private: std::unordered_map, opengl_uniform_data> data_; }; class opengl_renderer : public renderer_impl { public: opengl_renderer(); ~opengl_renderer(); void draw(identity, math::matr4 const &, std::vector const &) override; void clear() override; void flush() override; std::shared_ptr manager() const override { return manager_; } private: void activate(material const & mat); private: const math::matr4 identity{math::matrix::identity()}; std::shared_ptr manager_; unsigned int active_material; math::matr4 world_to_clip{identity}; double current_time{0.0}; unsigned int vertex_array_object{0}, vertex_buffer_object{0}; }; }