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