| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- //
- // renderer.hpp
- // graphics
- //
- // Created by Sam Jaffe on 5/19/19.
- // Copyright © 2019 Sam Jaffe. All rights reserved.
- //
- #pragma once
- #include <unordered_map>
- #include "game/graphics/graphics_fwd.h"
- #include "game/math/math_fwd.hpp"
- #include "game/util/hash.hpp"
- #include "vector/vector.hpp"
- namespace graphics {
- struct renderer {
- virtual ~renderer() {}
- virtual std::shared_ptr<manager const> manager() const = 0;
- virtual void draw(object const & obj) = 0;
- virtual void draw(identity<material>, math::matr4 const &,
- std::vector<vertex> const &) = 0;
- virtual void clear() = 0;
- virtual void flush() = 0;
- };
- enum class driver { openGL };
- class direct_renderer : public renderer {
- public:
- direct_renderer(driver d);
- std::shared_ptr<class manager const> manager() const override;
- void draw(object const & obj) override;
- void draw(identity<material>, math::matr4 const &,
- std::vector<vertex> const &) override;
- void clear() override;
- void flush() override;
- private:
- struct renderer_impl * pimpl;
- };
- class batch_renderer : public renderer {
- public:
- batch_renderer(renderer * impl, std::size_t batch_size = 0);
- ~batch_renderer();
- std::shared_ptr<class manager const> manager() const override {
- return impl_->manager();
- }
- void draw(object const & obj) override;
- void draw(identity<material>, math::matr4 const &,
- std::vector<vertex> const &) override;
- void clear() override { impl_->clear(); }
- void flush() override;
- private:
- void check();
- void write();
- private:
- renderer * impl_;
- std::unordered_map<identity<material>, std::vector<vertex>> batches_;
- std::size_t batch_size_;
- std::size_t elements_;
- };
- }
|