fix emscript logging settings
parent
ebcdbeb172
commit
1808af68b5
|
@ -1,7 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
include(FetchContent)
|
||||
|
||||
set(BLT_GRAPHICS_VERSION 2.0.9)
|
||||
set(BLT_GRAPHICS_VERSION 2.0.10)
|
||||
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
|
||||
|
||||
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9a05c86b02c9c45c2b384c531007416148ec4b56
|
||||
Subproject commit e2dc35fea98cc62897169cfc50dbf59fd820cd0e
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
#include <emscripten/html5.h>
|
||||
#include <blt/std/types.h>
|
||||
|
||||
#endif
|
||||
|
@ -35,12 +35,10 @@ void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, G
|
|||
return;
|
||||
if (type == GL_DEBUG_TYPE_ERROR)
|
||||
{
|
||||
BLT_ERROR("[OpenGL Error] message = '{}', type = 0x{:x}, severity = 0x{:x}, source = 0x{:x}, id = {}",
|
||||
message, type, severity, source, id);
|
||||
BLT_ERROR("[OpenGL Error] message = '{}', type = 0x{:x}, severity = 0x{:x}, source = 0x{:x}, id = {}", message, type, severity, source, id);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +113,9 @@ namespace blt::gfx
|
|||
});
|
||||
|
||||
/* 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 */
|
||||
glfwSetDropCallback(window_state.window, [](GLFWwindow*, int count, const char** paths) {
|
||||
|
@ -137,7 +137,7 @@ namespace blt::gfx
|
|||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
// ImGui::Spectrum::StyleColorsSpectrum();
|
||||
// ImGui::Spectrum::StyleColorsSpectrum();
|
||||
ImGui::Spectrum::LoadFont();
|
||||
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,
|
||||
icon_ranges);
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeBrands_compressed_data, static_cast<int>(fontAwesomeBrands_compressed_size), 13.0,
|
||||
&config,
|
||||
icon_ranges);
|
||||
&config, icon_ranges);
|
||||
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(window_state.window, true);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
|
||||
#endif
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
|
||||
#endif
|
||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#ifdef __EMSCRIPTEN__
|
||||
io.IniFilename = nullptr;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop(void* arg)
|
||||
|
@ -203,7 +202,7 @@ namespace blt::gfx
|
|||
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)
|
||||
{
|
||||
|
@ -215,27 +214,24 @@ namespace blt::gfx
|
|||
return false;
|
||||
}
|
||||
|
||||
EM_JS(int, get_screen_width, (), {
|
||||
return document.body.clientWidth;
|
||||
});
|
||||
EM_JS(int, get_screen_width, (), { return document.body.clientWidth; });
|
||||
|
||||
EM_JS(int, get_screen_height, (), {
|
||||
return document.body.clientHeight;
|
||||
});
|
||||
EM_JS(int, get_screen_height, (), { return document.body.clientHeight; });
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void init(window_data data)
|
||||
{
|
||||
window_state.data = &data; // NOLINT
|
||||
#ifdef __EMSCRIPTEN__
|
||||
blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n");
|
||||
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false,
|
||||
emscripten_resize_callback);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
logging::get_global_config().set_log_format(
|
||||
std::string("[") + logging::tags::FULL_TIME + "] [" + logging::tags::LOG_LEVEL + "] (" + logging::tags::FILE + ":" + logging::tags::LINE +
|
||||
") " + logging::tags::STR + "\n");
|
||||
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false, emscripten_resize_callback);
|
||||
|
||||
data.width = get_screen_width();
|
||||
data.height = get_screen_height();
|
||||
#endif
|
||||
#endif
|
||||
/* -- Set up Error Callback -- */
|
||||
glfwSetErrorCallback(error_callback);
|
||||
BLT_ASSERT(glfwInit() && "Unable to init GLFW. Aborting.");
|
||||
|
@ -255,15 +251,15 @@ namespace blt::gfx
|
|||
|
||||
/* -- Set Window Specifics + OpenGL -- */
|
||||
glfwMakeContextCurrent(window_state.window);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glfwSwapInterval(data.sync_interval);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageCallback(gl_error_callback, nullptr);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* -- Set up our local callbacks, ImGUI will then call these -- */
|
||||
create_callbacks();
|
||||
|
@ -271,10 +267,10 @@ namespace blt::gfx
|
|||
/* -- Set up ImGUI -- */
|
||||
setup_ImGUI();
|
||||
|
||||
#ifdef GL_MULTISAMPLE
|
||||
#ifdef GL_MULTISAMPLE
|
||||
if (data.context.SAMPLES > 0)
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
window_state.width = data.width;
|
||||
window_state.height = data.height;
|
||||
|
@ -282,7 +278,7 @@ namespace blt::gfx
|
|||
/* -- Call User Provided post-window-init function -- */
|
||||
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.
|
||||
* 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
|
||||
*/
|
||||
emscripten_set_main_loop_arg(loop, (void*) &data, 0, true);
|
||||
#else
|
||||
#else
|
||||
/* -- General Loop -- */
|
||||
while (!glfwWindowShouldClose(window_state.window))
|
||||
loop((void*) &data);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* -- Call User provided post-loop destroy function. Added for consistency -- */
|
||||
data.call_destroy();
|
||||
|
@ -311,96 +307,138 @@ namespace blt::gfx
|
|||
}
|
||||
|
||||
double getMouseX()
|
||||
{ return window_state.inputManager.mouseX; }
|
||||
{
|
||||
return window_state.inputManager.mouseX;
|
||||
}
|
||||
|
||||
double getMouseY()
|
||||
{ return window_state.inputManager.mouseY; }
|
||||
{
|
||||
return window_state.inputManager.mouseY;
|
||||
}
|
||||
|
||||
double getMouseDX()
|
||||
{ return window_state.inputManager.deltaX; }
|
||||
{
|
||||
return window_state.inputManager.deltaX;
|
||||
}
|
||||
|
||||
double getMouseDY()
|
||||
{ return window_state.inputManager.deltaY; }
|
||||
{
|
||||
return window_state.inputManager.deltaY;
|
||||
}
|
||||
|
||||
void lockCursor()
|
||||
{ glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); }
|
||||
{
|
||||
glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
|
||||
void unlockCursor()
|
||||
{ glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); }
|
||||
{
|
||||
glfwSetInputMode(window_state.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
bool isCursorLocked()
|
||||
{ return glfwGetInputMode(window_state.window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED; }
|
||||
{
|
||||
return glfwGetInputMode(window_state.window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
|
||||
}
|
||||
|
||||
bool isCursorInWindow()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// TODO:
|
||||
return true;
|
||||
#else
|
||||
#else
|
||||
return glfwGetWindowAttrib(window_state.window, GLFW_HOVERED);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void setRawInput(bool state)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// TODO?
|
||||
#else
|
||||
#else
|
||||
if (glfwRawMouseMotionSupported())
|
||||
glfwSetInputMode(window_state.window, GLFW_RAW_MOUSE_MOTION, state ? GLFW_TRUE : GLFW_FALSE);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isRawInput()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#ifdef __EMSCRIPTEN__
|
||||
return false;
|
||||
#else
|
||||
#else
|
||||
return glfwGetInputMode(window_state.window, GLFW_RAW_MOUSE_MOTION);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void setClipboard(const std::string& str)
|
||||
{ glfwSetClipboardString(window_state.window, str.c_str()); }
|
||||
{
|
||||
glfwSetClipboardString(window_state.window, str.c_str());
|
||||
}
|
||||
|
||||
std::string getClipboard()
|
||||
{ return glfwGetClipboardString(window_state.window); }
|
||||
{
|
||||
return glfwGetClipboardString(window_state.window);
|
||||
}
|
||||
|
||||
bool isMousePressed(int button)
|
||||
{ return window_state.inputManager.isMousePressed(button); }
|
||||
{
|
||||
return window_state.inputManager.isMousePressed(button);
|
||||
}
|
||||
|
||||
bool isKeyPressed(int key)
|
||||
{ return window_state.inputManager.isKeyPressed(key); }
|
||||
{
|
||||
return window_state.inputManager.isKeyPressed(key);
|
||||
}
|
||||
|
||||
double getFrameDeltaSeconds()
|
||||
{ return window_state.nanoDelta; }
|
||||
{
|
||||
return window_state.nanoDelta;
|
||||
}
|
||||
|
||||
double getFrameDeltaMilliseconds()
|
||||
{ return window_state.millisDelta; }
|
||||
{
|
||||
return window_state.millisDelta;
|
||||
}
|
||||
|
||||
i64 getFrameDelta()
|
||||
{ return window_state.deltaTime; }
|
||||
{
|
||||
return window_state.deltaTime;
|
||||
}
|
||||
|
||||
bool mouseMovedLastFrame()
|
||||
{ return window_state.inputManager.mouse_moved; }
|
||||
{
|
||||
return window_state.inputManager.mouse_moved;
|
||||
}
|
||||
|
||||
bool mousePressedLastFrame()
|
||||
{ return window_state.inputManager.mouse_pressed; }
|
||||
{
|
||||
return window_state.inputManager.mouse_pressed;
|
||||
}
|
||||
|
||||
bool keyPressedLastFrame()
|
||||
{ return window_state.inputManager.key_pressed; }
|
||||
{
|
||||
return window_state.inputManager.key_pressed;
|
||||
}
|
||||
|
||||
i32 getWindowHeight()
|
||||
{ return window_state.height; }
|
||||
{
|
||||
return window_state.height;
|
||||
}
|
||||
|
||||
i32 getWindowWidth()
|
||||
{ return window_state.width; }
|
||||
{
|
||||
return window_state.width;
|
||||
}
|
||||
|
||||
bool keyReleasedLastFrame()
|
||||
{ return window_state.inputManager.key_released; }
|
||||
{
|
||||
return window_state.inputManager.key_released;
|
||||
}
|
||||
|
||||
bool mouseReleaseLastFrame()
|
||||
{ return window_state.inputManager.mouse_released; }
|
||||
{
|
||||
return window_state.inputManager.mouse_released;
|
||||
}
|
||||
|
||||
void setWindowSize(const i32 width, const i32 height)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue