fix emscript logging settings

main
Brett 2025-04-11 16:13:29 -04:00
parent ebcdbeb172
commit 1808af68b5
3 changed files with 419 additions and 381 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
include(FetchContent) include(FetchContent)
set(BLT_GRAPHICS_VERSION 2.0.9) set(BLT_GRAPHICS_VERSION 2.0.10)
set(BLT_GRAPHICS_TEST_VERSION 0.0.1) set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})

@ -1 +1 @@
Subproject commit 9a05c86b02c9c45c2b384c531007416148ec4b56 Subproject commit e2dc35fea98cc62897169cfc50dbf59fd820cd0e

View File

@ -17,422 +17,460 @@
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#include <emscripten/html5.h> #include <emscripten/html5.h>
#include <blt/std/types.h> #include <blt/std/types.h>
#endif #endif
void error_callback(int error, const char* description) void error_callback(int error, const char* description)
{ {
BLT_ERROR("GLFW Error (%d): %s", error, description); BLT_ERROR("GLFW Error (%d): %s", error, description);
std::abort(); std::abort();
} }
void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei, const GLchar* message, const void*) void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei, const GLchar* message, const void*)
{ {
// do not log performance concerns // do not log performance concerns
if (type == GL_DEBUG_TYPE_OTHER) if (type == GL_DEBUG_TYPE_OTHER)
return; return;
if (type == GL_DEBUG_TYPE_ERROR) if (type == GL_DEBUG_TYPE_ERROR)
{ {
BLT_ERROR("[OpenGL Error] message = '{}', type = 0x{:x}, severity = 0x{:x}, source = 0x{:x}, id = {}", BLT_ERROR("[OpenGL Error] message = '{}', type = 0x{:x}, severity = 0x{:x}, source = 0x{:x}, id = {}", message, type, severity, source, id);
message, type, severity, source, id); } else
} else {
{ BLT_WARN("[OpenGL Error] message = '{}', type = 0x{:x}, severity = 0x{:x}, source = 0x{:x}, id = {}", message, type, severity, source, id);
BLT_WARN("[OpenGL Error] message = '{}', type = 0x{:x}, severity = 0x{:x}, source = 0x{:x}, id = {}", }
message, type, severity, source, id);
}
} }
namespace blt::gfx namespace blt::gfx
{ {
struct struct
{ {
/* GLFW Window Object */ /* GLFW Window Object */
GLFWwindow* window = nullptr; GLFWwindow* window = nullptr;
/* BLT internal input state manager, handles keyboard/mouse allocations + states */ /* BLT internal input state manager, handles keyboard/mouse allocations + states */
input_manager inputManager; input_manager inputManager;
/* stores any drag and dropped paths for processing */ /* stores any drag and dropped paths for processing */
std::queue<std::string> pendingPaths; std::queue<std::string> pendingPaths;
/* current width and height of the window */ /* current width and height of the window */
std::int32_t width = 0; std::int32_t width = 0;
std::int32_t height = 0; std::int32_t height = 0;
/* Frame time information (last frame) */ /* Frame time information (last frame) */
std::int64_t lastTime = blt::system::nanoTime(); std::int64_t lastTime = blt::system::nanoTime();
std::int64_t deltaTime = 0; std::int64_t deltaTime = 0;
double nanoDelta = 0; double nanoDelta = 0;
double millisDelta = 0; double millisDelta = 0;
window_data* data = nullptr; window_data* data = nullptr;
} window_state; } window_state;
void create_callbacks() void create_callbacks()
{ {
/* Setup keyboard callback */ /* Setup keyboard callback */
glfwSetKeyCallback(window_state.window, [](GLFWwindow*, int key, int, int action, int) { glfwSetKeyCallback(window_state.window, [](GLFWwindow*, int key, int, int action, int) {
if (key < 0 || key == GLFW_KEY_UNKNOWN) if (key < 0 || key == GLFW_KEY_UNKNOWN)
return; return;
KEY_STATE state; KEY_STATE state;
switch (action) switch (action)
{ {
case GLFW_PRESS: case GLFW_PRESS:
state = KEY_STATE::PRESS; state = KEY_STATE::PRESS;
window_state.inputManager.key_pressed = true; window_state.inputManager.key_pressed = true;
break; break;
case GLFW_REPEAT: case GLFW_REPEAT:
state = KEY_STATE::REPEAT; state = KEY_STATE::REPEAT;
break; break;
default: default:
state = KEY_STATE::RELEASE; state = KEY_STATE::RELEASE;
window_state.inputManager.key_released = true; window_state.inputManager.key_released = true;
break; break;
} }
window_state.inputManager.key(key) = state; window_state.inputManager.key(key) = state;
}); });
/* Setup mouse button callback */ /* Setup mouse button callback */
glfwSetMouseButtonCallback(window_state.window, [](GLFWwindow*, int button, int action, int) { glfwSetMouseButtonCallback(window_state.window, [](GLFWwindow*, int button, int action, int) {
if (button < 0) if (button < 0)
return; return;
MOUSE_STATE state; MOUSE_STATE state;
switch (action) switch (action)
{ {
case GLFW_PRESS: case GLFW_PRESS:
state = MOUSE_STATE::PRESS; state = MOUSE_STATE::PRESS;
window_state.inputManager.mouse_pressed = true; window_state.inputManager.mouse_pressed = true;
break; break;
default: default:
state = MOUSE_STATE::RELEASE; state = MOUSE_STATE::RELEASE;
window_state.inputManager.mouse_released = true; window_state.inputManager.mouse_released = true;
break; break;
} }
window_state.inputManager.mouse(button) = state; window_state.inputManager.mouse(button) = state;
}); });
/* Setup mouse cursor callback */ /* Setup mouse cursor callback */
glfwSetCursorPosCallback(window_state.window, [](GLFWwindow*, double x, double y) { glfwSetCursorPosCallback(window_state.window, [](GLFWwindow*, double x, double y) {
window_state.inputManager.updateMousePos(x, y); window_state.inputManager.updateMousePos(x, y);
window_state.inputManager.mouse_moved = true; window_state.inputManager.mouse_moved = true;
}); });
/* Setup mouse scroll callback */ /* Setup mouse scroll callback */
glfwSetScrollCallback(window_state.window, [](GLFWwindow*, double, double s) { window_state.inputManager.updateScroll(s); }); glfwSetScrollCallback(window_state.window, [](GLFWwindow*, double, double s) {
window_state.inputManager.updateScroll(s);
});
/* Setup drop input callback */ /* Setup drop input callback */
glfwSetDropCallback(window_state.window, [](GLFWwindow*, int count, const char** paths) { glfwSetDropCallback(window_state.window, [](GLFWwindow*, int count, const char** paths) {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
window_state.pendingPaths.emplace(paths[i]); window_state.pendingPaths.emplace(paths[i]);
}); });
} }
void setup_ImGUI() void setup_ImGUI()
{ {
const char* glsl_version = "#version 100"; const char* glsl_version = "#version 100";
// Setup Dear ImGui context // Setup Dear ImGui context
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style // Setup Dear ImGui style
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
// ImGui::Spectrum::StyleColorsSpectrum(); // ImGui::Spectrum::StyleColorsSpectrum();
ImGui::Spectrum::LoadFont(); ImGui::Spectrum::LoadFont();
ImGui::SetupImGuiStyle(true, 1.0); ImGui::SetupImGuiStyle(true, 1.0);
// Setup FA // Setup FA
ImFontConfig config; ImFontConfig config;
config.MergeMode = true; config.MergeMode = true;
config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
static constexpr ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0}; static constexpr ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
io.Fonts->AddFontFromMemoryCompressedBase85TTF(fontAwesomeRegular_compressed_data_base85, 13.0f, &config, icon_ranges); io.Fonts->AddFontFromMemoryCompressedBase85TTF(fontAwesomeRegular_compressed_data_base85, 13.0f, &config, icon_ranges);
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeSolid_compressed_data, static_cast<int>(fontAwesomeSolid_compressed_size), 13.0, &config, io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeSolid_compressed_data, static_cast<int>(fontAwesomeSolid_compressed_size), 13.0, &config,
icon_ranges); icon_ranges);
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeBrands_compressed_data, static_cast<int>(fontAwesomeBrands_compressed_size), 13.0, io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeBrands_compressed_data, static_cast<int>(fontAwesomeBrands_compressed_size), 13.0,
&config, &config, icon_ranges);
icon_ranges);
//ImGui::StyleColorsLight(); //ImGui::StyleColorsLight();
// Setup Platform/Renderer backends // Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window_state.window, true); ImGui_ImplGlfw_InitForOpenGL(window_state.window, true);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
// ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas"); // ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
#endif #endif
ImGui_ImplOpenGL3_Init(glsl_version); ImGui_ImplOpenGL3_Init(glsl_version);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
io.IniFilename = nullptr; io.IniFilename = nullptr;
#endif #endif
} }
void loop(void* arg) void loop(void* arg)
{ {
auto& data = *((window_data*) arg); auto& data = *((window_data*) arg);
/* -- Get the current framebuffer size, update the global width/height state, along with OpenGL viewport -- */ /* -- Get the current framebuffer size, update the global width/height state, along with OpenGL viewport -- */
glfwGetFramebufferSize(window_state.window, &window_state.width, &window_state.height); glfwGetFramebufferSize(window_state.window, &window_state.width, &window_state.height);
glViewport(0, 0, window_state.width, window_state.height); glViewport(0, 0, window_state.width, window_state.height);
data.width = window_state.width; data.width = window_state.width;
data.height = window_state.height; data.height = window_state.height;
// TODO: user option for this // TODO: user option for this
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
/* -- Begin the next ImGUI frame -- */ /* -- Begin the next ImGUI frame -- */
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
/* -- Call user update function -- */ /* -- Call user update function -- */
data.call_update(); data.call_update();
/* -- Render the ImGUI frame -- */ /* -- Render the ImGUI frame -- */
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
/* -- Update GLFW state -- */ /* -- Update GLFW state -- */
window_state.inputManager.clear(); window_state.inputManager.clear();
glfwSwapBuffers(window_state.window); glfwSwapBuffers(window_state.window);
glfwPollEvents(); glfwPollEvents();
/* -- Update Frame Timing Information -- */ /* -- Update Frame Timing Information -- */
const auto current_time = system::nanoTime(); const auto current_time = system::nanoTime();
window_state.deltaTime = current_time - window_state.lastTime; window_state.deltaTime = current_time - window_state.lastTime;
window_state.lastTime = current_time; window_state.lastTime = current_time;
window_state.nanoDelta = static_cast<double>(window_state.deltaTime) / 1e9f; window_state.nanoDelta = static_cast<double>(window_state.deltaTime) / 1e9f;
window_state.millisDelta = static_cast<double>(window_state.deltaTime) / 1e6f; window_state.millisDelta = static_cast<double>(window_state.deltaTime) / 1e6f;
} }
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
EM_BOOL emscripten_resize_callback(int, const EmscriptenUiEvent* event, void* data) EM_BOOL emscripten_resize_callback(int, const EmscriptenUiEvent* event, void* data)
{ {
int width = event->documentBodyClientWidth; int width = event->documentBodyClientWidth;
int height = event->documentBodyClientHeight; int height = event->documentBodyClientHeight;
glfwSetWindowSize(window_state.window, width, height); glfwSetWindowSize(window_state.window, width, height);
return false; return false;
} }
EM_JS(int, get_screen_width, (), { EM_JS(int, get_screen_width, (), { return document.body.clientWidth; });
return document.body.clientWidth;
});
EM_JS(int, get_screen_height, (), { EM_JS(int, get_screen_height, (), { return document.body.clientHeight; });
return document.body.clientHeight;
});
#endif #endif
void init(window_data data) void init(window_data data)
{ {
window_state.data = &data; // NOLINT window_state.data = &data; // NOLINT
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n"); logging::get_global_config().set_log_format(
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false, std::string("[") + logging::tags::FULL_TIME + "] [" + logging::tags::LOG_LEVEL + "] (" + logging::tags::FILE + ":" + logging::tags::LINE +
emscripten_resize_callback); ") " + logging::tags::STR + "\n");
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false, emscripten_resize_callback);
data.width = get_screen_width(); data.width = get_screen_width();
data.height = get_screen_height(); data.height = get_screen_height();
#endif #endif
/* -- Set up Error Callback -- */ /* -- Set up Error Callback -- */
glfwSetErrorCallback(error_callback); glfwSetErrorCallback(error_callback);
BLT_ASSERT(glfwInit() && "Unable to init GLFW. Aborting."); BLT_ASSERT(glfwInit() && "Unable to init GLFW. Aborting.");
/* -- Set up Window Context -- */ /* -- Set up Window Context -- */
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, data.context.GL_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, data.context.GL_MAJOR);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, data.context.GL_MINOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, data.context.GL_MINOR);
glfwWindowHint(GLFW_DOUBLEBUFFER, data.context.DOUBLE_BUFFER); glfwWindowHint(GLFW_DOUBLEBUFFER, data.context.DOUBLE_BUFFER);
glfwWindowHint(GLFW_OPENGL_PROFILE, data.context.GL_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, data.context.GL_PROFILE);
glfwWindowHint(GLFW_SAMPLES, data.context.SAMPLES); glfwWindowHint(GLFW_SAMPLES, data.context.SAMPLES);
glfwWindowHint(GLFW_MAXIMIZED, data.maximized); glfwWindowHint(GLFW_MAXIMIZED, data.maximized);
/* -- Create the Window -- */ /* -- Create the Window -- */
window_state.window = glfwCreateWindow(data.width, data.height, data.title.c_str(), data.monitor, data.share); window_state.window = glfwCreateWindow(data.width, data.height, data.title.c_str(), data.monitor, data.share);
data.window = window_state.window; data.window = window_state.window;
BLT_ASSERT(window_state.window && "Unable to create GLFW window."); BLT_ASSERT(window_state.window && "Unable to create GLFW window.");
/* -- Set Window Specifics + OpenGL -- */ /* -- Set Window Specifics + OpenGL -- */
glfwMakeContextCurrent(window_state.window); glfwMakeContextCurrent(window_state.window);
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
glfwSwapInterval(data.sync_interval); glfwSwapInterval(data.sync_interval);
gladLoadGL(glfwGetProcAddress); gladLoadGL(glfwGetProcAddress);
#endif #endif
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(gl_error_callback, nullptr); glDebugMessageCallback(gl_error_callback, nullptr);
#endif #endif
/* -- Set up our local callbacks, ImGUI will then call these -- */ /* -- Set up our local callbacks, ImGUI will then call these -- */
create_callbacks(); create_callbacks();
/* -- Set up ImGUI -- */ /* -- Set up ImGUI -- */
setup_ImGUI(); setup_ImGUI();
#ifdef GL_MULTISAMPLE #ifdef GL_MULTISAMPLE
if (data.context.SAMPLES > 0) if (data.context.SAMPLES > 0)
glEnable(GL_MULTISAMPLE); glEnable(GL_MULTISAMPLE);
#endif #endif
window_state.width = data.width; window_state.width = data.width;
window_state.height = data.height; window_state.height = data.height;
/* -- Call User Provided post-window-init function -- */ /* -- Call User Provided post-window-init function -- */
data.call_init(); data.call_init();
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
/* /*
* "setting 0 or a negative value as the fps will use the browsers requestAnimationFrame mechanism to call the main loop function. * "setting 0 or a negative value as the fps will use the browsers requestAnimationFrame mechanism to call the main loop function.
* This is HIGHLY recommended if you are doing rendering, as the browsers requestAnimationFrame will * This is HIGHLY recommended if you are doing rendering, as the browsers requestAnimationFrame will
* make sure you render at a proper smooth rate that lines up properly with the browser and monitor." * make sure you render at a proper smooth rate that lines up properly with the browser and monitor."
* https://emscripten.org/docs/api_reference/emscripten.h.html * https://emscripten.org/docs/api_reference/emscripten.h.html
*/ */
emscripten_set_main_loop_arg(loop, (void*) &data, 0, true); emscripten_set_main_loop_arg(loop, (void*) &data, 0, true);
#else #else
/* -- General Loop -- */ /* -- General Loop -- */
while (!glfwWindowShouldClose(window_state.window)) while (!glfwWindowShouldClose(window_state.window))
loop((void*) &data); loop((void*) &data);
#endif #endif
/* -- Call User provided post-loop destroy function. Added for consistency -- */ /* -- Call User provided post-loop destroy function. Added for consistency -- */
data.call_destroy(); data.call_destroy();
} }
void cleanup() void cleanup()
{ {
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
glfwDestroyWindow(window_state.window); glfwDestroyWindow(window_state.window);
glfwTerminate(); glfwTerminate();
} }
double getMouseX() double getMouseX()
{ return window_state.inputManager.mouseX; } {
return window_state.inputManager.mouseX;
}
double getMouseY() double getMouseY()
{ return window_state.inputManager.mouseY; } {
return window_state.inputManager.mouseY;
}
double getMouseDX() double getMouseDX()
{ return window_state.inputManager.deltaX; } {
return window_state.inputManager.deltaX;
}
double getMouseDY() double getMouseDY()
{ return window_state.inputManager.deltaY; } {
return window_state.inputManager.deltaY;
}
void lockCursor() void lockCursor()
{ glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); } {
glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}
void unlockCursor() void unlockCursor()
{ glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } {
glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
bool isCursorLocked() bool isCursorLocked()
{ return glfwGetInputMode(window_state.window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED; } {
return glfwGetInputMode(window_state.window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
}
bool isCursorInWindow() bool isCursorInWindow()
{ {
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
// TODO: // TODO:
return true; return true;
#else #else
return glfwGetWindowAttrib(window_state.window, GLFW_HOVERED); return glfwGetWindowAttrib(window_state.window, GLFW_HOVERED);
#endif #endif
} }
void setRawInput(bool state) void setRawInput(bool state)
{ {
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
// TODO? // TODO?
#else #else
if (glfwRawMouseMotionSupported()) if (glfwRawMouseMotionSupported())
glfwSetInputMode(window_state.window, GLFW_RAW_MOUSE_MOTION, state ? GLFW_TRUE : GLFW_FALSE); glfwSetInputMode(window_state.window, GLFW_RAW_MOUSE_MOTION, state ? GLFW_TRUE : GLFW_FALSE);
#endif #endif
} }
bool isRawInput() bool isRawInput()
{ {
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
return false; return false;
#else #else
return glfwGetInputMode(window_state.window, GLFW_RAW_MOUSE_MOTION); return glfwGetInputMode(window_state.window, GLFW_RAW_MOUSE_MOTION);
#endif #endif
} }
void setClipboard(const std::string& str) void setClipboard(const std::string& str)
{ glfwSetClipboardString(window_state.window, str.c_str()); } {
glfwSetClipboardString(window_state.window, str.c_str());
}
std::string getClipboard() std::string getClipboard()
{ return glfwGetClipboardString(window_state.window); } {
return glfwGetClipboardString(window_state.window);
}
bool isMousePressed(int button) bool isMousePressed(int button)
{ return window_state.inputManager.isMousePressed(button); } {
return window_state.inputManager.isMousePressed(button);
}
bool isKeyPressed(int key) bool isKeyPressed(int key)
{ return window_state.inputManager.isKeyPressed(key); } {
return window_state.inputManager.isKeyPressed(key);
}
double getFrameDeltaSeconds() double getFrameDeltaSeconds()
{ return window_state.nanoDelta; } {
return window_state.nanoDelta;
}
double getFrameDeltaMilliseconds() double getFrameDeltaMilliseconds()
{ return window_state.millisDelta; } {
return window_state.millisDelta;
}
i64 getFrameDelta() i64 getFrameDelta()
{ return window_state.deltaTime; } {
return window_state.deltaTime;
}
bool mouseMovedLastFrame() bool mouseMovedLastFrame()
{ return window_state.inputManager.mouse_moved; } {
return window_state.inputManager.mouse_moved;
}
bool mousePressedLastFrame() bool mousePressedLastFrame()
{ return window_state.inputManager.mouse_pressed; } {
return window_state.inputManager.mouse_pressed;
}
bool keyPressedLastFrame() bool keyPressedLastFrame()
{ return window_state.inputManager.key_pressed; } {
return window_state.inputManager.key_pressed;
}
i32 getWindowHeight() i32 getWindowHeight()
{ return window_state.height; } {
return window_state.height;
}
i32 getWindowWidth() i32 getWindowWidth()
{ return window_state.width; } {
return window_state.width;
}
bool keyReleasedLastFrame() bool keyReleasedLastFrame()
{ return window_state.inputManager.key_released; } {
return window_state.inputManager.key_released;
}
bool mouseReleaseLastFrame() bool mouseReleaseLastFrame()
{ return window_state.inputManager.mouse_released; } {
return window_state.inputManager.mouse_released;
}
void setWindowSize(const i32 width, const i32 height) void setWindowSize(const i32 width, const i32 height)
{ {
window_state.data->setWindowSize(width, height); window_state.data->setWindowSize(width, height);
} }
window_data& window_data::setWindowSize(int32_t new_width, int32_t new_height) window_data& window_data::setWindowSize(int32_t new_width, int32_t new_height)
{ {
width = new_width; width = new_width;
height = new_height; height = new_height;
glfwSetWindowSize(window_state.window, width, height); glfwSetWindowSize(window_state.window, width, height);
return *this; return *this;
} }
window_data& window_data::setMonitor(GLFWmonitor* m) window_data& window_data::setMonitor(GLFWmonitor* m)
{ {
window_data::monitor = m; window_data::monitor = m;
return *this; return *this;
} }
window_data& window_data::setShare(GLFWwindow* s) window_data& window_data::setShare(GLFWwindow* s)
{ {
window_data::share = s; window_data::share = s;
return *this; return *this;
} }
window_data& window_data::setMaximized(bool b) window_data& window_data::setMaximized(bool b)
{ {
if (b) if (b)
window_data::maximized = GLFW_TRUE; window_data::maximized = GLFW_TRUE;
else else
window_data::maximized = GLFW_FALSE; window_data::maximized = GLFW_FALSE;
return *this; return *this;
} }
} }