diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f89d2ed..ac5e744e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,9 +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 ".bc") - set(CMAKE_EXECUTABLE_SUFFIX ".bc") - set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -o ") if (U_CMAKE_BUILD_TYPE MATCHES REL) add_compile_options(-O3 -DNDEBUG) endif() diff --git a/include/nanogui/opengl.h b/include/nanogui/opengl.h index 453ec401..0b0db727 100644 --- a/include/nanogui/opengl.h +++ b/include/nanogui/opengl.h @@ -42,10 +42,10 @@ #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 +# include # endif #endif 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/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]; diff --git a/src/screen.cpp b/src/screen.cpp index 4b04e75c..75aa4d39 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) @@ -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; @@ -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) @@ -426,7 +439,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 */ @@ -473,7 +486,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; 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)); }