jGL
Loading...
Searching...
No Matches
shapeRenderer.h
Go to the documentation of this file.
1#ifndef SHAPERENDERER_H
2#define SHAPERENDERER_H
3
4#include <jGL/shape.h>
5#include <jGL/shader.h>
6#include <jGL/priorityStore.h>
7
8#include <unordered_map>
9#include <map>
10#include <string>
11#include <iterator>
12#include <vector>
13#include <algorithm>
14
15#include <chrono>
16
17namespace jGL
18{
19
24 typedef std::string ShapeId;
25
30 class ShapeRenderer : public PriorityStore<Shape>
31 {
32
33 public:
34
40 {
42 : xytheta(true), scale(true), colour(true)
43 {}
44
46 };
47
53 ShapeRenderer(size_t sizeHint = 8)
54 : PriorityStore(sizeHint), shader(nullptr)
55 {}
56
63 ShapeRenderer(std::shared_ptr<Shader> shader, size_t sizeHint = 8)
64 : PriorityStore(sizeHint), shader(shader)
65 {}
66
67 Shape & getShape(ShapeId id) { return this->operator[](id); }
68
69 const Transform * getTransform(ShapeId id) { return getShape(id).transform; }
70 const glm::vec4 * getColour(ShapeId id) { return getShape(id).colour; }
71
82 virtual void draw
83 (
84 std::shared_ptr<Shader> shader,
85 std::multimap<RenderPriority,ShapeId> & ids,
86 UpdateInfo info = UpdateInfo()
87 )
88 {
89 std::vector<std::pair<Info, Shape>> shapes = vectorise(ids);
90 draw(shader, shapes, info);
91 }
92
102 virtual void draw
103 (
104 std::multimap<RenderPriority, ShapeId> & ids,
105 UpdateInfo info = UpdateInfo()
106 )
107 {
108 std::vector<std::pair<Info, Shape>> shapes = vectorise(ids);
109 draw(shader, shapes, info);
110 }
111
117 virtual void draw
118 (
119 std::shared_ptr<Shader> shader,
120 UpdateInfo info = UpdateInfo()
121 )
122 {
123 draw(shader, cache, info);
124 }
125
130 virtual void draw
131 (
132 UpdateInfo info = UpdateInfo()
133 )
134 {
135 draw(shader, cache, info);
136 }
137
138 bool hasId(const ShapeId id) const { return idToElement.find(id) != idToElement.end(); }
139
140 virtual void setProjection(glm::mat4 p) {projection = p;}
141
142 protected:
143
144 virtual void draw
145 (
146 std::shared_ptr<Shader> shader,
147 std::vector<std::pair<Info, Shape>> & shapes,
148 UpdateInfo info = UpdateInfo()
149 ) = 0;
150
151 std::shared_ptr<Shader> shader;
152
153 glm::mat4 projection = glm::mat4(0.0f);
154
155 };
156}
157
158#endif /* SHAPERENDERER_H */
Store elements in a priority ordering, with identities.
Definition priorityStore.h:32
std::vector< std::pair< Info, Shape > > vectorise(std::multimap< Priority, ElementId > &oids)
Return a vector from overriding priorities.
Definition priorityStore.h:142
Shape & operator[](ElementId id)
Definition priorityStore.h:155
std::vector< std::pair< Info, Shape > > cache
Definition priorityStore.h:169
std::unordered_map< ElementId, std::pair< Shape, Priority > > idToElement
Definition priorityStore.h:167
Renders shapes with optional rendering priority.
Definition shapeRenderer.h:31
glm::mat4 projection
Definition shapeRenderer.h:153
virtual void draw(std::shared_ptr< Shader > shader, UpdateInfo info=UpdateInfo())
Draw with overriding shader and cached priorities.
Definition shapeRenderer.h:118
virtual void draw(std::shared_ptr< Shader > shader, std::multimap< RenderPriority, ShapeId > &ids, UpdateInfo info=UpdateInfo())
Draw with overriding render priority and shader.
Definition shapeRenderer.h:83
std::shared_ptr< Shader > shader
Definition shapeRenderer.h:151
virtual void draw(UpdateInfo info=UpdateInfo())
Draw with default shader and cached priorities.
Definition shapeRenderer.h:131
const glm::vec4 * getColour(ShapeId id)
Definition shapeRenderer.h:70
virtual void draw(std::shared_ptr< Shader > shader, std::vector< std::pair< Info, Shape > > &shapes, UpdateInfo info=UpdateInfo())=0
ShapeRenderer(std::shared_ptr< Shader > shader, size_t sizeHint=8)
Construct a new ShapeRenderer.
Definition shapeRenderer.h:63
virtual void setProjection(glm::mat4 p)
Definition shapeRenderer.h:140
bool hasId(const ShapeId id) const
Definition shapeRenderer.h:138
const Transform * getTransform(ShapeId id)
Definition shapeRenderer.h:69
virtual void draw(std::multimap< RenderPriority, ShapeId > &ids, UpdateInfo info=UpdateInfo())
Draw with overriding render priority.
Definition shapeRenderer.h:103
ShapeRenderer(size_t sizeHint=8)
Construct a new ShapeRenderer.
Definition shapeRenderer.h:53
Shape & getShape(ShapeId id)
Definition shapeRenderer.h:67
A drawable shape.
Definition shape.h:14
const Transform * transform
Definition shape.h:26
const glm::vec4 * colour
Definition shape.h:27
A drawable graphic.
Definition id.h:10
std::string ShapeId
Definition shapeRenderer.h:24
Control updated data for drawing.
Definition shapeRenderer.h:40
bool xytheta
Definition shapeRenderer.h:45
bool colour
Definition shapeRenderer.h:45
UpdateInfo()
Definition shapeRenderer.h:41
bool scale
Definition shapeRenderer.h:45
Position, rotation, and scale.
Definition primitive.h:44