Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opengl.h: fixed gl3ext header #146

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<CMAKE_CXX_COMPILER> -o <TARGET> <LINK_FLAGS> <OBJECTS>")
if (U_CMAKE_BUILD_TYPE MATCHES REL)
add_compile_options(-O3 -DNDEBUG)
endif()
Expand Down
4 changes: 2 additions & 2 deletions include/nanogui/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
#include <GLFW/glfw3.h>

#if defined(NANOGUI_USE_GLES)
# if NANOGUI_GLES_VERSION == 2
# if NANOGUI_GLES_VERSION == 2 || defined(__EMSCRIPTEN__)
# include <GLES2/gl2ext.h>
# elif NANOGUI_GLES_VERSION == 3
# include <GLES3/gl2ext.h>
# include <GLES3/gl3ext.h>
# endif
#endif

Expand Down
1 change: 1 addition & 0 deletions include/nanogui/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions include/nanogui/textbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ template <typename Scalar> 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);
Expand Down Expand Up @@ -280,6 +288,14 @@ template <typename Scalar> 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];
Expand Down
23 changes: 18 additions & 5 deletions src/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nanogui/screen.h>
#include <nanogui/theme.h>
#include <nanogui/opengl.h>
Expand All @@ -23,6 +22,7 @@
#if defined(EMSCRIPTEN)
# include <emscripten/emscripten.h>
# include <emscripten/html5.h>
# undef NANOGUI_GLAD
#endif

#if defined(_WIN32)
Expand Down Expand Up @@ -118,16 +118,29 @@ 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;
m_float_buffer = (bool) float_mode;
#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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions src/texture_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down