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
RenderContext.hpp
Go to the documentation of this file.
1 #ifndef RADIX_RENDER_CONTEXT_HPP
2 #define RADIX_RENDER_CONTEXT_HPP
3 
4 #include <vector>
5 
7 #include <radix/Camera.hpp>
8 
9 namespace radix {
10 
11 class Renderer;
12 class Mesh;
13 class Transform;
14 
15 struct RenderContext {
17  RenderContext(Renderer &r) : renderer(r) {}
18 
19  std::vector<Matrix4f> projStack;
20  bool projDirty;
21  inline Matrix4f& getProj() {
22  return projStack.back();
23  }
24  inline const Matrix4f& getProj() const {
25  return projStack.back();
26  }
27  inline void pushProj(const Matrix4f &m) {
28  projStack.push_back(m);
29  projDirty = true;
30  }
31  inline void popProj() {
32  projStack.pop_back();
33  projDirty = true;
34  }
35 
36  std::vector<Matrix4f> viewStack, invViewStack;
37  bool viewDirty;
39  inline Matrix4f& getView() {
40  return viewStack.back();
41  }
42  inline const Matrix4f& getView() const {
43  return viewStack.back();
44  }
45  inline Matrix4f& getInvView() {
46  return invViewStack.back();
47  }
48  inline const Matrix4f& getInvView() const {
49  return invViewStack.back();
50  }
51  inline void pushView(const Matrix4f &m) {
52  viewStack.push_back(m);
53  invViewStack.push_back(inverse(m));
54  viewDirty = true;
55  }
56  inline void popView() {
57  viewStack.pop_back();
58  invViewStack.pop_back();
59  viewDirty = true;
60  }
61 
62  inline void pushCamera(const Camera &c) {
63  projStack.push_back(Matrix4f::Identity);
64  c.getProjMatrix(projStack.back());
65  viewStack.push_back(Matrix4f::Identity);
66  c.getViewMatrix(viewStack.back());
67  invViewStack.push_back(Matrix4f::Identity);
68  c.getInvViewMatrix(invViewStack.back());
69  projDirty = viewDirty = true;
70  }
71  inline void popCamera() {
72  projStack.pop_back();
73  viewStack.pop_back();
74  invViewStack.pop_back();
75  projDirty = viewDirty = true;
76  }
77 
78  using ViewFrameInfo = std::pair<const Mesh&, const Transform&>;
79  std::vector<ViewFrameInfo> viewFramesStack;
80  inline const ViewFrameInfo getViewFrame() const {
81  return viewFramesStack.back();
82  }
83  inline void pushViewFrame(const ViewFrameInfo &frame) {
84  viewFramesStack.push_back(frame);
85  }
86  inline void popViewFrame() {
87  viewFramesStack.pop_back();
88  }
89 };
90 
91 } /* namespace radix */
92 
93 #endif /* RADIX_RENDER_CONTEXT_HPP */
void popView()
Definition: RenderContext.hpp:56
size_t viewStackMaxDepth
Definition: RenderContext.hpp:38
Definition: GameController.hpp:7
void pushCamera(const Camera &c)
Definition: RenderContext.hpp:62
std::vector< ViewFrameInfo > viewFramesStack
Definition: RenderContext.hpp:79
std::vector< Matrix4f > projStack
Definition: RenderContext.hpp:19
const Matrix4f & getView() const
Definition: RenderContext.hpp:42
const Matrix4f & getInvView() const
Definition: RenderContext.hpp:48
bool viewDirty
Definition: RenderContext.hpp:37
std::pair< const Mesh &, const Transform & > ViewFrameInfo
Definition: RenderContext.hpp:78
Matrix4f & getInvView()
Definition: RenderContext.hpp:45
std::vector< Matrix4f > viewStack
Definition: RenderContext.hpp:36
void pushView(const Matrix4f &m)
Definition: RenderContext.hpp:51
void getInvViewMatrix(Matrix4f &m) const
Definition: Camera.cpp:60
Matrix3f inverse(const Matrix3f &m)
Definition: Matrix3f.cpp:150
const ViewFrameInfo getViewFrame() const
Definition: RenderContext.hpp:80
void popViewFrame()
Definition: RenderContext.hpp:86
void getProjMatrix(Matrix4f &m) const
Definition: Camera.cpp:43
Definition: Camera.hpp:11
Matrix4f & getProj()
Definition: RenderContext.hpp:21
bool projDirty
Definition: RenderContext.hpp:20
void pushViewFrame(const ViewFrameInfo &frame)
Definition: RenderContext.hpp:83
static const Matrix4f Identity
Definition: Matrix4f.hpp:27
Definition: RenderContext.hpp:15
void getViewMatrix(Matrix4f &m) const
Definition: Camera.cpp:51
Matrix4f & getView()
Definition: RenderContext.hpp:39
Definition: Matrix4f.hpp:25
void popCamera()
Definition: RenderContext.hpp:71
Renderer & renderer
Definition: RenderContext.hpp:16
void popProj()
Definition: RenderContext.hpp:31
void pushProj(const Matrix4f &m)
Definition: RenderContext.hpp:27
Main renderer - handles sub-renderers and provides low level render functions.
Definition: Renderer.hpp:35
RenderContext(Renderer &r)
Definition: RenderContext.hpp:17
const Matrix4f & getProj() const
Definition: RenderContext.hpp:24
std::vector< Matrix4f > invViewStack
Definition: RenderContext.hpp:36