63struct LA_UI_API GLState
70 template <
class F,
class...
Args>
71 void operator()(F func,
Args... args)
73 void* func_void_ptr =
reinterpret_cast<void*
>(func);
74 void* enable_ptr =
reinterpret_cast<void*
>(glEnable);
75 void* disable_ptr =
reinterpret_cast<void*
>(glDisable);
77 if (func_void_ptr == enable_ptr) {
78 set_toggle(
true, args...);
79 }
else if (func_void_ptr == disable_ptr) {
80 set_toggle(
false, args...);
82 auto it = values.find(func_void_ptr);
83 if (it != values.end()) {
85 assert(values[func_void_ptr].size() > 0);
88 values[func_void_ptr].top() = [=]() { LA_GL(func(args...)); };
95 static GLState& get();
97 static int major_version;
98 static int minor_version;
99 static std::string get_glsl_version_string();
101 static bool on_opengl_thread();
103 static std::string_view get_enum_string(GLenum value);
107 template <
class T,
class...
Args>
108 void set_toggle(
bool val, T discard_val, [[maybe_unused]]
Args... args)
114 void set_toggle(
bool val) { (void)(val); }
117 template <
class...
Args>
118 void set_toggle(
bool val, GLenum name, [[maybe_unused]]
Args... args)
120 set_toggle(val, name);
122 template <
class...
Args>
123 void set_toggle(
bool val,
int name, [[maybe_unused]]
Args... args)
125 set_toggle(val, GLenum(name));
128 void set_toggle(
bool val, GLenum name)
130 auto& stack = toggles[name];
131 while (stack.size() < m_stack_level) stack.push(glIsEnabled(name));
136 std::stack<std::function<void(
void)>>& get_stack(F func)
138 const void* func_void_ptr =
reinterpret_cast<const void*
>(func);
139 return values[func_void_ptr];
143 std::unordered_map<
const void*, std::stack<std::function<void(
void)>>> values;
144 std::unordered_map<GLenum, std::stack<bool>> toggles;
147 static std::unique_ptr<GLState> m_instance;
148 size_t m_stack_level;
149 std::thread::id m_gl_thread_id;