]> git.localhorst.tv Git - blank.git/blob - src/graphics/Viewport.hpp
glm backwards compatibility
[blank.git] / src / graphics / Viewport.hpp
1 #ifndef BLANK_GRAPHICS_VIEWPORT_HPP_
2 #define BLANK_GRAPHICS_VIEWPORT_HPP_
3
4 #include "align.hpp"
5 #include "BlendedSprite.hpp"
6 #include "BlockLighting.hpp"
7 #include "Camera.hpp"
8 #include "Canvas.hpp"
9 #include "DirectionalLighting.hpp"
10 #include "glm.hpp"
11 #include "PlainColor.hpp"
12 #include "SkyBoxShader.hpp"
13
14
15 namespace blank {
16
17 class Viewport {
18
19 public:
20         Viewport();
21
22         Viewport(const Viewport &) = delete;
23         Viewport &operator =(const Viewport &) = delete;
24
25         void VSync(bool b);
26
27         void EnableDepthTest() noexcept;
28         void EqualDepthTest() noexcept;
29         void DisableDepthTest() noexcept;
30
31         void EnableBackfaceCulling() noexcept;
32         void DisableBackfaceCulling() noexcept;
33
34         void EnableAlphaBlending() noexcept;
35         void EnableInvertBlending() noexcept;
36         void DisableBlending() noexcept;
37
38         void Resize(int w, int h) noexcept;
39
40         float Width() const noexcept { return canv.Size().x; }
41         float Height() const noexcept { return canv.Size().y; }
42
43         void Clear() noexcept;
44         void ClearDepth() noexcept;
45
46         glm::vec2 GetPosition(const glm::vec2 &off, Gravity grav) const noexcept;
47
48         void SetCursor(const glm::vec3 &) noexcept;
49         void SetCursor(const glm::vec3 &, Gravity) noexcept;
50         void MoveCursor(const glm::vec3 &) noexcept;
51         const glm::mat4 &Cursor() const noexcept { return cursor; }
52
53         void OffsetCamera(const glm::vec3 &o) noexcept { cam_offset = o; }
54         const glm::vec3 &CameraOffset() const noexcept { return cam_offset; }
55
56         BlockLighting &ChunkProgram() noexcept;
57         DirectionalLighting &EntityProgram() noexcept;
58         DirectionalLighting &HUDProgram() noexcept;
59         PlainColor &WorldColorProgram() noexcept;
60         PlainColor &HUDColorProgram() noexcept;
61         SkyBoxShader &SkyBoxProgram() noexcept;
62         BlendedSprite &SpriteProgram() noexcept;
63
64         void WorldPosition(const glm::mat4 &) noexcept;
65
66         const glm::mat4 &Perspective() const noexcept { return cam.Projection(); }
67         const glm::mat4 &Ortho() const noexcept { return canv.Projection(); }
68
69 private:
70         Camera cam;
71         Canvas canv;
72
73         glm::mat4 cursor;
74
75         glm::vec3 cam_offset;
76
77         BlockLighting chunk_prog;
78         DirectionalLighting entity_prog;
79         PlainColor color_prog;
80         SkyBoxShader sky_prog;
81         BlendedSprite sprite_prog;
82
83         enum {
84                 NONE,
85                 CHUNK,
86                 ENTITY,
87                 HUD,
88                 COLOR_WORLD,
89                 COLOR_HUD,
90                 SKY_BOX,
91                 SPRITE,
92         } active_prog;
93
94 };
95
96 }
97
98 #endif