aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/render/window.h
blob: 1aabfa0f8f5a6886b6184f12103e76aa038f33b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef __JIN_RENDER_WINDOW
#define __JIN_RENDER_WINDOW
#include <SDL2/SDL.h>
#include "../utils/utils.h"
#include "../common/subsystem.h"

namespace jin
{
namespace render
{

    class Window : public common::Subsystem
    {
    public: 

        struct Setting : SettingBase
        {
        public:
            int width, height; // ڴС 
            bool vsync;        // ֱͬ
            const char* title; // 
        };

        SDL_Window* getWnd();
        
        SDL_GLContext getCtx(); 
        
        static inline Window* get()
        {
            return (g_wnd ? g_wnd : (g_wnd = new Window()));
        }

        inline int getW()
        {
            return width;
        }

        inline int getH()
        {
            return height;
        }

        inline void swapBuffers();

        bool init(const SettingBase* setting) override;
        void quit() override;

    private: 

        Window(); 
        ~Window(); 
        
        static Window* g_wnd; 
        
        SDL_Window* wnd; 
        
        SDL_GLContext ctx;
        
        int width, height;

        onlyonce bool _init(const SettingBase* setting) override;
        onlyonce void _quit() override;
    };

    typedef Window::Setting WindowSetting;

}
}
#endif