Rev Author Line No. Line
1 ovan 1 #ifndef __CONTEXT_HEADER__
2 #define __CONTEXT_HEADER__
3  
4 #include "../compile.h"
5 #include "../device/device_stub.h"
6 #include "../math/aabbox.h"
7 #include "identifier.h"
8 #include "shader.h"
9 #include "mesh.h"
10  
11 #include "texture.h"
12 #include "texture_array.h"
13 #include "texture3d.h"
14  
15 namespace sleek
16 {
17     namespace driver
18     {
19         enum RENDER_CONTEXT
20         {
21             RCTX_OGL3,
22             RCTX_D3D
23         };
24  
25         enum AntiailiasingMode
26         {
27             DAM_OFF,
28             DAM_FAST,
29             DAM_NICE,
30             DAM_COUNT
31         };
32  
33         class driver;
34         class MeshBuffer;
35  
36         class context : public std::enable_shared_from_this<context>
37         {
38             public:
39                 context(std::shared_ptr<device::Device>&, std::shared_ptr<context> shared = nullptr) noexcept;
40                 ~context() noexcept;
41  
42                 virtual RENDER_CONTEXT getType() const noexcept = 0;
43  
44                 virtual std::shared_ptr<driver>     createDriver() noexcept = 0;
45                 virtual std::shared_ptr<texture>    createScreenshot(const math::aabbox2du&) const noexcept = 0;
46  
47                 virtual std::shared_ptr<identifier> createTexture(texture*, bool dsa = true) const noexcept = 0;
48                 virtual std::shared_ptr<identifier> createTextureArray(texture_array*, bool dsa = true) const noexcept = 0;
49                 virtual std::shared_ptr<identifier> createTexture3d(texture3d*, bool dsa = true) const noexcept = 0;
50  
51                 virtual std::shared_ptr<identifier> createVBO(MeshBuffer *o, VBO_BUFFER_TYPE t, VBO_BUFFER_ALIGNMENT a = VBO_STATIC, bool dsa = true) const noexcept = 0;
52                 virtual std::shared_ptr<shader>     createShader(bool dsa = true) const noexcept = 0;
53  
54                 virtual void setViewport(const math::vector2di& i) noexcept = 0;
55                 virtual void setAntialiasing(const AntiailiasingMode &i) noexcept = 0;
56  
57                 virtual AntiailiasingMode getAntiailiasing() const noexcept = 0;
58                 virtual math::vector2di getViewport() const noexcept = 0;
59  
60                 inline std::shared_ptr<context> getptr()
61                 {
62                     return shared_from_this();
63                 }
64  
65                 virtual bool testError(int line, const std::string &file) const noexcept = 0;
66  
67                 virtual bool bind() noexcept = 0;
68                 virtual void begin(const math::pixel &clearcolor = math::pixel(0xFFAAFFFF)) noexcept = 0;
69                 virtual void end() noexcept = 0;
70             protected:
71                 std::shared_ptr<device::Device> win;
72                 std::shared_ptr<context> shared;
73         };
74  
75         // build platform dependent render context
76  
77         std::shared_ptr<context> createContextRenderer(
78             RENDER_CONTEXT,
79             std::shared_ptr<device::Device>&,
80             std::shared_ptr<context> shared = nullptr
81         ) noexcept;
82     }
83 }
84  
85 #endif