From 632fedf08c0775c71e1e176f5a4d7c3f9a8c21ed Mon Sep 17 00:00:00 2001 From: kallaballa Date: Mon, 17 Apr 2023 09:22:46 +0200 Subject: [PATCH 1/9] opengl.h: fixed gl3ext header --- include/nanogui/opengl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nanogui/opengl.h b/include/nanogui/opengl.h index 453ec401..3dccd270 100644 --- a/include/nanogui/opengl.h +++ b/include/nanogui/opengl.h @@ -45,7 +45,7 @@ # if NANOGUI_GLES_VERSION == 2 # include # elif NANOGUI_GLES_VERSION == 3 -# include +# include # endif #endif From def22c7bfdd7eb14a69053374133b368de28535d Mon Sep 17 00:00:00 2001 From: kallaballa Date: Mon, 17 Apr 2023 09:50:05 +0200 Subject: [PATCH 2/9] GL_TEXTURE_2D_MULTISAMPLE is not available in ES --- src/texture_gl.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/texture_gl.cpp b/src/texture_gl.cpp index 0fb8f47c..ea65e2e0 100644 --- a/src/texture_gl.cpp +++ b/src/texture_gl.cpp @@ -100,9 +100,11 @@ void Texture::init() { internal_format_gl); (void) pixel_format_gl; (void) component_format_gl; - +#if defined(NANOGUI_USE_OPENGL) GLenum tex_mode = m_samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; - +#else + GLenum tex_mode = GL_TEXTURE_2D; +#endif if (m_flags & (uint8_t) TextureFlags::ShaderRead) { CHK(glGenTextures(1, &m_texture_handle)); CHK(glBindTexture(tex_mode, m_texture_handle)); @@ -153,7 +155,11 @@ void Texture::upload(const uint8_t *data) { internal_format_gl); if (m_texture_handle != 0) { +#if defined(NANOGUI_USE_OPENGL) GLenum tex_mode = m_samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; +#else + GLenum tex_mode = GL_TEXTURE_2D; +#endif CHK(glBindTexture(tex_mode, m_texture_handle)); if (data) @@ -216,7 +222,12 @@ void Texture::upload_sub_region(const uint8_t *data, const Vector2i& origin, con if (origin.x() + size.x() > m_size.x() || origin.y() + size.y() > m_size.y()) throw std::runtime_error("Texture::upload_sub_region(): out of bounds!"); +#if defined(NANOGUI_USE_OPENGL) GLenum tex_mode = m_samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; +#else + GLenum tex_mode = GL_TEXTURE_2D; +#endif + CHK(glBindTexture(tex_mode, m_texture_handle)); if (data) @@ -286,7 +297,11 @@ void Texture::resize(const Vector2i &size) { } void Texture::generate_mipmap() { +#if defined(NANOGUI_USE_OPENGL) GLenum tex_mode = m_samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; +#else + GLenum tex_mode = GL_TEXTURE_2D; +#endif CHK(glBindTexture(tex_mode, m_texture_handle)); CHK(glGenerateMipmap(tex_mode)); } From 7a48d811178bc0ad5c4373bb95e06bce3da56e5b Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 19 Apr 2023 06:16:25 +0200 Subject: [PATCH 3/9] use so suffix for shared objects even with wasm --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f89d2ed..97a791ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,8 +66,8 @@ if (CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$") set(NANOGUI_BUILD_GLAD_DEFAULT OFF) set(NANOGUI_BUILD_GLFW_DEFAULT OFF) - set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc") - set(CMAKE_EXECUTABLE_SUFFIX ".bc") + set(CMAKE_STATIC_LIBRARY_SUFFIX ".so") + set(CMAKE_EXECUTABLE_SUFFIX ".so") set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -o ") if (U_CMAKE_BUILD_TYPE MATCHES REL) add_compile_options(-O3 -DNDEBUG) From 63dc37b69d772f76b2314e43b8bac23cb2b904ce Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 19 Apr 2023 06:22:21 +0200 Subject: [PATCH 4/9] fixed nanogui shared object ending --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f89d2ed..642a040e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,9 +66,9 @@ if (CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$") set(NANOGUI_BUILD_GLAD_DEFAULT OFF) set(NANOGUI_BUILD_GLFW_DEFAULT OFF) - set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc") - set(CMAKE_EXECUTABLE_SUFFIX ".bc") - set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -o ") +# set(CMAKE_STATIC_LIBRARY_SUFFIX ".so") + # set(CMAKE_EXECUTABLE_SUFFIX ".so") +# set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -o ") if (U_CMAKE_BUILD_TYPE MATCHES REL) add_compile_options(-O3 -DNDEBUG) endif() From 976133ebf70fbf5ba611d616222730e210f05072 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 19 Apr 2023 17:24:35 +0200 Subject: [PATCH 5/9] emscripten/opengl fixes --- CMakeLists.txt | 6 ------ include/nanogui/opengl.h | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97a791ba..d8f42c59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,12 +66,6 @@ if (CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$") set(NANOGUI_BUILD_GLAD_DEFAULT OFF) set(NANOGUI_BUILD_GLFW_DEFAULT OFF) - set(CMAKE_STATIC_LIBRARY_SUFFIX ".so") - set(CMAKE_EXECUTABLE_SUFFIX ".so") - set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -o ") - if (U_CMAKE_BUILD_TYPE MATCHES REL) - add_compile_options(-O3 -DNDEBUG) - endif() endif() # Compile for a sufficiently recent processor. Assumes Nehalem+ (with SSE4.2) by diff --git a/include/nanogui/opengl.h b/include/nanogui/opengl.h index 3dccd270..0b0db727 100644 --- a/include/nanogui/opengl.h +++ b/include/nanogui/opengl.h @@ -42,7 +42,7 @@ #include #if defined(NANOGUI_USE_GLES) -# if NANOGUI_GLES_VERSION == 2 +# if NANOGUI_GLES_VERSION == 2 || defined(__EMSCRIPTEN__) # include # elif NANOGUI_GLES_VERSION == 3 # include From c2868fcb43e14e7f68bc0acdeb935efb7c95ea8f Mon Sep 17 00:00:00 2001 From: kallaballa Date: Fri, 28 Apr 2023 20:56:34 +0200 Subject: [PATCH 6/9] more wasm adaption --- src/screen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screen.cpp b/src/screen.cpp index 4b04e75c..7fc51aa8 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -10,7 +10,6 @@ All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE.txt file. */ - #include #include #include @@ -23,6 +22,7 @@ #if defined(EMSCRIPTEN) # include # include +# undef NANOGUI_GLAD #endif #if defined(_WIN32) @@ -426,7 +426,7 @@ void Screen::initialize(GLFWwindow *window, bool shutdown_glfw) { /* The canvas element is configured as width/height: auto, expand to the available space instead of using the specified window resolution */ nanogui_emscripten_resize_callback(0, nullptr, nullptr); - emscripten_set_resize_callback(nullptr, nullptr, false, + emscripten_set_resize_callback("#canvas", nullptr, false, nanogui_emscripten_resize_callback); } else if (w != w2 || h != h2) { /* Configure for rendering on a high-DPI display */ From 81f1336e050d6319e1788e6b1bb86e7d3f28975a Mon Sep 17 00:00:00 2001 From: kallaballa Date: Sun, 11 Jun 2023 03:05:06 +0200 Subject: [PATCH 7/9] further emscripten adaptions --- src/screen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/screen.cpp b/src/screen.cpp index 7fc51aa8..b9d640f6 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -118,9 +118,9 @@ Screen::Screen() GLint n_stencil_bits = 0, n_depth_bits = 0; GLboolean float_mode; CHK(glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, - GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE, &n_depth_bits)); + GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE, &n_depth_bits)); CHK(glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, - GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &n_stencil_bits)); + GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &n_stencil_bits)); CHK(glGetBooleanv(GL_RGBA_FLOAT_MODE, &float_mode)); m_depth_buffer = n_depth_bits > 0; m_stencil_buffer = n_stencil_bits > 0; @@ -473,7 +473,7 @@ void Screen::initialize(GLFWwindow *window, bool shutdown_glfw) { if (!m_nvg_context) throw std::runtime_error("Could not initialize NanoVG!"); - m_visible = glfwGetWindowAttrib(window, GLFW_VISIBLE) != 0; + m_visible = true;//glfwGetWindowAttrib(window, GLFW_VISIBLE) != 0; set_theme(new Theme(m_nvg_context)); m_mouse_pos = Vector2i(0); m_mouse_state = m_modifiers = 0; From 35c9689ec5b6c32d6b890cc6e21aba0daae98b69 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 14 Jun 2023 20:00:02 +0200 Subject: [PATCH 8/9] added a constructor to Screen that explicitly enables/disables OpenGL buffers. Useful if the current framebuffer is not the default framebuffer which might be configured differently. --- include/nanogui/screen.h | 1 + src/screen.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/nanogui/screen.h b/include/nanogui/screen.h index d2e044f4..f72c66bd 100644 --- a/include/nanogui/screen.h +++ b/include/nanogui/screen.h @@ -252,6 +252,7 @@ class NANOGUI_EXPORT Screen : public Widget { * to the appropriate callback event handlers below */ Screen(); + Screen(bool enableDepthBuffer, bool enableStencilBuffer, bool enableFloatMode); /// Initialize the \ref Screen void initialize(GLFWwindow *window, bool shutdown_glfw); diff --git a/src/screen.cpp b/src/screen.cpp index b9d640f6..75aa4d39 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -128,6 +128,19 @@ Screen::Screen() #endif } +Screen::Screen(bool enableDepthBuffer, bool enableStencilBuffer, bool enableFloatMode) + : Widget(nullptr), m_glfw_window(nullptr), m_nvg_context(nullptr), + m_cursor(Cursor::Arrow), m_background(0.3f, 0.3f, 0.32f, 1.f), + m_shutdown_glfw(false), m_fullscreen(false), m_depth_buffer(false), + m_stencil_buffer(false), m_float_buffer(false), m_redraw(false) { + memset(m_cursors, 0, sizeof(GLFWcursor *) * (size_t) Cursor::CursorCount); +#if defined(NANOGUI_USE_OPENGL) + m_depth_buffer = enableDepthBuffer; + m_stencil_buffer = enableStencilBuffer; + m_float_buffer = enableFloatMode; +#endif +} + Screen::Screen(const Vector2i &size, const std::string &caption, bool resizable, bool fullscreen, bool depth_buffer, bool stencil_buffer, bool float_buffer, unsigned int gl_major, unsigned int gl_minor) From 3ecdc8530076f9e3e0ee0d6e66428045e313b27a Mon Sep 17 00:00:00 2001 From: kallaballa Date: Sat, 17 Jun 2023 02:16:40 +0200 Subject: [PATCH 9/9] make max and min value available --- include/nanogui/textbox.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/nanogui/textbox.h b/include/nanogui/textbox.h index b480673b..9079993c 100644 --- a/include/nanogui/textbox.h +++ b/include/nanogui/textbox.h @@ -189,6 +189,14 @@ template class IntBox : public TextBox { m_max_value = max_value; } + Scalar get_max_value() { + return m_max_value; + } + + Scalar get_min_value() { + return m_min_value; + } + void set_min_max_values(Scalar min_value, Scalar max_value) { set_min_value(min_value); set_max_value(max_value); @@ -280,6 +288,14 @@ template class FloatBox : public TextBox { return (Scalar) std::stod(TextBox::value()); } + Scalar get_max_value() { + return m_max_value; + } + + Scalar get_min_value() { + return m_min_value; + } + void set_value(Scalar value) { Scalar clamped_value = std::min(std::max(value, m_min_value),m_max_value); char buffer[50];