GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Renderer.hpp
Go to the documentation of this file.
1 #ifndef RADIX_RENDERER_HPP
2 #define RADIX_RENDERER_HPP
3 
4 #include <string>
5 
6 #include <radix/World.hpp>
15 
16 namespace radix {
17 
18 class Entity;
19 struct Viewport;
20 
35 class Renderer {
36 public:
41 
42  // TODO: possibly remove to make rendering viewport-stateless
43  void setViewport(Viewport *vp) {
44  viewport = vp;
45  }
46  Viewport* getViewport() const {
47  return viewport;
48  }
49 
50  void init();
51 
55  void updateLights(Shader& shader);
56 
60  void render();
61 
66  void renderText(RenderContext &rc, Text text);
67 
68 
78  void renderMesh(RenderContext &rc, Shader &shader, Matrix4f &mdlMtx, const Mesh &mesh,
79  const Material *mat = nullptr);
80 
81  void renderMesh(RenderContext &rc, Shader &shader, Matrix4f &mdlMtx, const Mesh &mesh,
82  const Material &mat) {
83  return renderMesh(rc, shader, mdlMtx, mesh, &mat);
84  }
85 
89  void addRenderer(SubRenderer& subRenderer);
90 
94  void removeRenderer(SubRenderer& subRenderer);
95 
96  static Matrix4f getFrameView(const Matrix4f &src, const Matrix4f &in, const Matrix4f &out);
97  static Matrix4f getFrameView(const Matrix4f &src, const Transform &in, const Transform &out) {
98  Matrix4f inMat;
99  inMat.translate(in.getPosition());
100  inMat.rotate(in.getOrientation());
101  Matrix4f outMat;
102  outMat.translate(out.getPosition());
103  outMat.rotate(out.getOrientation());
104  return getFrameView(src, inMat, outMat);
105  }
106  static bool clipViewFrame(const RenderContext &rc, const Mesh &frame,
107  const Transform &frameTform, RectangleI &scissor);
108 
109  static Matrix4f clipProjMat(const Entity &ent, const Matrix4f &view, const Matrix4f &proj);
110 
111 private:
112  struct Support {
114  } support;
115 
116  uint lightsUBO;
117 
122 
123  std::vector<SubRenderer*> subRenderers;
125 };
126 
127 } /* namespace radix */
128 
129 #endif /* RADIX_RENDERER_HPP */
Definition: Viewport.hpp:6
Definition: GameController.hpp:7
uint lightsUBO
Definition: Renderer.hpp:116
void translate(const Vector3f &v)
Definition: Matrix4f.cpp:49
void renderText(RenderContext &rc, Text text)
Renders a string to the screen using signed-distance field text rendering.
Definition: Renderer.cpp:69
RenderContext rc
Definition: Renderer.hpp:120
const Vector3f & getPosition() const
Definition: Transform.hpp:40
ECS entity, Component container It is created like this:
Definition: Entity.hpp:23
int vpWidth
Definition: Renderer.hpp:124
Definition: SubRenderer.hpp:14
void renderMesh(RenderContext &rc, Shader &shader, Matrix4f &mdlMtx, const Mesh &mesh, const Material *mat=nullptr)
Renders a mesh with the specified material and transform determined by the given modelMatrix.
Definition: Renderer.cpp:73
Definition: Rectangle.hpp:10
std::vector< SubRenderer * > subRenderers
Definition: Renderer.hpp:123
World & world
Definition: Renderer.hpp:118
Renderer(World &world)
Definition: Renderer.cpp:13
Definition: Renderer.hpp:112
Viewport * getViewport() const
Definition: Renderer.hpp:46
int vpHeight
Definition: Renderer.hpp:124
const Quaternion & getOrientation() const
Definition: Transform.hpp:50
Definition: Text.hpp:11
TextRenderer textRenderer
Definition: Renderer.hpp:121
void render()
Cycles through all the sub-renderers and calls their render function.
Definition: Renderer.cpp:30
void updateLights(Shader &shader)
Initializes the lights in the world on the given shader.
Definition: Renderer.cpp:36
Definition: TextRenderer.hpp:14
static Matrix4f clipProjMat(const Entity &ent, const Matrix4f &view, const Matrix4f &proj)
static Matrix4f getFrameView(const Matrix4f &src, const Matrix4f &in, const Matrix4f &out)
Definition: Renderer.cpp:120
void removeRenderer(SubRenderer &subRenderer)
Remove a renderer from the render queue.
Definition: Renderer.cpp:194
void init()
Definition: Renderer.cpp:23
Definition: RenderContext.hpp:15
void setViewport(Viewport *vp)
Definition: Renderer.hpp:43
void rotate(float angle, float x, float y, float z)
Definition: Matrix4f.cpp:56
bool uniformBuffers
Definition: Renderer.hpp:113
struct radix::Renderer::Support support
Definition: Matrix4f.hpp:25
Definition: Shader.hpp:9
static Matrix4f getFrameView(const Matrix4f &src, const Transform &in, const Transform &out)
Definition: Renderer.hpp:97
Definition: World.hpp:32
Main renderer - handles sub-renderers and provides low level render functions.
Definition: Renderer.hpp:35
Viewport * viewport
Definition: Renderer.hpp:119
void renderMesh(RenderContext &rc, Shader &shader, Matrix4f &mdlMtx, const Mesh &mesh, const Material &mat)
Definition: Renderer.hpp:81
Definition: Mesh.hpp:10
Definition: Transform.hpp:11
static bool clipViewFrame(const RenderContext &rc, const Mesh &frame, const Transform &frameTform, RectangleI &scissor)
Definition: Renderer.cpp:125
void addRenderer(SubRenderer &subRenderer)
Add a renderer to the render queue.
Definition: Renderer.cpp:190
Definition: Material.hpp:11