| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- //
- // 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<materials::uniform, unsigned int> uniform_id;
- };
- class opengl_manager : public manager {
- public:
- shader compile(shaders::type type, std::string const & path) const override;
- shader_program compile(identity<shader> fragment,
- identity<shader> vertex) const override;
- texture compile(textures::format color, math::vec2i size,
- void const * buffer) const override;
- opengl_uniform_data & data(identity<shader_program> id);
- private:
- std::unordered_map<identity<shader_program>, opengl_uniform_data> data_;
- };
- class opengl_renderer : public renderer_impl {
- public:
- opengl_renderer();
- ~opengl_renderer();
- void draw(identity<material>, math::matr4 const &,
- std::vector<vertex> const &) override;
- void clear() override;
- void flush() override;
- std::shared_ptr<class manager const> manager() const override {
- return manager_;
- }
- private:
- void activate(material const & mat);
- private:
- const math::matr4 identity{math::matrix::identity<float, 4>()};
- std::shared_ptr<opengl_manager> 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};
- };
- }
|