fix emscript logging settings
parent
ebcdbeb172
commit
1808af68b5
|
@ -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
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
|
|
||||||
#include <emscripten/html5.h>
|
#include <emscripten/html5.h>
|
||||||
#include <blt/std/types.h>
|
#include <blt/std/types.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -35,12 +35,10 @@ void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, G
|
||||||
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 = {}",
|
BLT_WARN("[OpenGL Error] message = '{}', type = 0x{:x}, severity = 0x{:x}, source = 0x{:x}, id = {}", message, type, severity, source, id);
|
||||||
message, type, severity, source, id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +113,9 @@ namespace blt::gfx
|
||||||
});
|
});
|
||||||
|
|
||||||
/* 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) {
|
||||||
|
@ -137,7 +137,7 @@ namespace blt::gfx
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
|
@ -150,21 +150,20 @@ namespace blt::gfx
|
||||||
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)
|
||||||
|
@ -203,7 +202,7 @@ namespace blt::gfx
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -215,27 +214,24 @@ namespace blt::gfx
|
||||||
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.");
|
||||||
|
@ -255,15 +251,15 @@ namespace blt::gfx
|
||||||
|
|
||||||
/* -- 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();
|
||||||
|
@ -271,10 +267,10 @@ namespace blt::gfx
|
||||||
/* -- 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;
|
||||||
|
@ -282,7 +278,7 @@ namespace blt::gfx
|
||||||
/* -- 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 browser’s requestAnimationFrame mechanism to call the main loop function.
|
* "setting 0 or a negative value as the fps will use the browser’s requestAnimationFrame mechanism to call the main loop function.
|
||||||
* This is HIGHLY recommended if you are doing rendering, as the browser’s requestAnimationFrame will
|
* This is HIGHLY recommended if you are doing rendering, as the browser’s requestAnimationFrame will
|
||||||
|
@ -290,11 +286,11 @@ namespace blt::gfx
|
||||||
* 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();
|
||||||
|
@ -311,96 +307,138 @@ namespace blt::gfx
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue