]> git.localhorst.tv Git - blank.git/blob - src/graphics/Viewport.hpp
reorganize basic rendering functionality
[blank.git] / src / graphics / Viewport.hpp
1 #ifndef BLANK_GRAPHICS_VIEWPORT_HPP_
2 #define BLANK_GRAPHICS_VIEWPORT_HPP_
3
4 #include "BlendedSprite.hpp"
5 #include "BlockLighting.hpp"
6 #include "Camera.hpp"
7 #include "Canvas.hpp"
8 #include "DirectionalLighting.hpp"
9
10 #include <glm/glm.hpp>
11 #include <SDL.h>
12
13
14 namespace blank {
15
16 class Viewport {
17
18 public:
19         Viewport();
20
21         Viewport(const Viewport &) = delete;
22         Viewport &operator =(const Viewport &) = delete;
23
24         void VSync(bool b) noexcept;
25
26         void EnableDepthTest() noexcept;
27         void DisableDepthTest() noexcept;
28
29         void EnableBackfaceCulling() noexcept;
30         void DisableBackfaceCulling() noexcept;
31
32         void EnableAlphaBlending() noexcept;
33         void EnableInvertBlending() noexcept;
34         void DisableBlending() noexcept;
35
36         void Resize(int w, int h) noexcept;
37
38         float Width() const noexcept { return canv.Size().x; }
39         float Height() const noexcept { return canv.Size().y; }
40
41         void Clear() noexcept;
42         void ClearDepth() noexcept;
43
44         BlockLighting &ChunkProgram() noexcept;
45         DirectionalLighting &EntityProgram() noexcept;
46         DirectionalLighting &HUDProgram() noexcept;
47         BlendedSprite &SpriteProgram() noexcept;
48
49         void WorldPosition(const glm::mat4 &) noexcept;
50
51         const glm::mat4 &Perspective() const noexcept { return cam.Projection(); }
52         const glm::mat4 &Ortho() const noexcept { return canv.Projection(); }
53         const glm::mat4 &CenterTransform() const noexcept { return center; }
54
55 private:
56         SDL_GLContext ctx;
57         Camera cam;
58         Canvas canv;
59
60         glm::mat4 center;
61
62         BlockLighting chunk_prog;
63         DirectionalLighting entity_prog;
64         BlendedSprite sprite_prog;
65
66         enum {
67                 NONE,
68                 CHUNK,
69                 ENTITY,
70                 HUD,
71                 SPRITE,
72         } active_prog;
73
74 };
75
76 }
77
78 #endif