14#include <lagrange/ui/api.h>
17#if defined(__EMSCRIPTEN__)
18#include <webgl/webgl2.h>
23#include <GLFW/glfw3.h>
31#include <unordered_map>
34#include <lagrange/utils/assert.h>
48bool checkGLError(
const char* label);
52 checkGLError(LA_ASSERT_FUNCTION); \
69 template <
class F,
class...
Args>
70 void operator()(F func,
Args... args)
72 void* func_void_ptr =
reinterpret_cast<void*
>(func);
73 void* enable_ptr =
reinterpret_cast<void*
>(glEnable);
74 void* disable_ptr =
reinterpret_cast<void*
>(glDisable);
76 if (func_void_ptr == enable_ptr) {
77 set_toggle(
true, args...);
78 }
else if (func_void_ptr == disable_ptr) {
79 set_toggle(
false, args...);
81 auto it = values.find(func_void_ptr);
82 if (it != values.end()) {
84 assert(values[func_void_ptr].size() > 0);
87 values[func_void_ptr].top() = [=]() { LA_GL(func(args...)); };
96 static int major_version;
97 static int minor_version;
98 static std::string get_glsl_version_string();
100 static bool on_opengl_thread();
102 static std::string_view get_enum_string(GLenum value);
106 template <
class T,
class...
Args>
107 void set_toggle(
bool val, T discard_val, [[maybe_unused]]
Args... args)
113 void set_toggle(
bool val) { (void)(val); }
116 template <
class...
Args>
117 void set_toggle(
bool val, GLenum name, [[maybe_unused]]
Args... args)
119 set_toggle(val, name);
121 template <
class...
Args>
122 void set_toggle(
bool val,
int name, [[maybe_unused]]
Args... args)
124 set_toggle(val, GLenum(name));
127 void set_toggle(
bool val, GLenum name)
129 auto& stack = toggles[name];
130 while (stack.size() < m_stack_level) stack.push(glIsEnabled(name));
135 std::stack<std::function<void(
void)>>& get_stack(F func)
137 const void* func_void_ptr =
reinterpret_cast<const void*
>(func);
138 return values[func_void_ptr];
142 std::unordered_map<
const void*, std::stack<std::function<void(
void)>>> values;
143 std::unordered_map<GLenum, std::stack<bool>> toggles;
146 static std::unique_ptr<GLState> m_instance;
147 size_t m_stack_level;
148 std::thread::id m_gl_thread_id;
159 template <
class F,
class...
Args>
160 void operator()(F func,
Args... args)
162 GLState::get()(func, args...);
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: project.cpp:27
Definition: GLContext.h:152
Definition: GLContext.h:63