]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/device_backend.h
Refactor low-level state management
[libs/gl.git] / source / backends / opengl / device_backend.h
1 #ifndef MSP_GL_DEVICE_BACKEND_H_
2 #define MSP_GL_DEVICE_BACKEND_H_
3
4 #include <vector>
5 #include <msp/core/noncopyable.h>
6 #include <msp/graphics/glcontext.h>
7
8 namespace Msp {
9 namespace GL {
10
11 class OpenGLBuffer;
12 class OpenGLPipelineState;
13 class OpenGLTexture;
14
15 struct OpenGLDeviceState
16 {
17         const OpenGLPipelineState *last_pipeline = 0;
18         std::vector<int> bound_tex_targets;
19         std::vector<char> bound_uniform_blocks;
20         unsigned restart_index = 0;
21         unsigned n_clip_distances = 0;
22         const OpenGLBuffer *scratch_buffer = 0;
23         const OpenGLTexture *scratch_texture = 0;
24 };
25
26 class OpenGLDevice: public NonCopyable
27 {
28 protected:
29         Graphics::GLContext context;
30         OpenGLDeviceState state;
31
32         OpenGLDevice(Graphics::Window &, const Graphics::GLOptions &);
33
34         static Graphics::GLOptions create_default_options();
35
36         void fill_info();
37
38         Graphics::GLContext &get_context() { return context; }
39
40 public:
41         OpenGLDeviceState &get_state() { return state; }
42 };
43
44 using DeviceBackend = OpenGLDevice;
45 using DeviceOptions = Graphics::GLOptions;
46
47 } // namespace GL
48 } // namespace Msp
49
50 #endif