Skip to content

Commit

Permalink
Add gles version of the viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
progschj authored and jeffamstutz committed Jan 12, 2023
1 parent 2351bd8 commit 6991cbf
Show file tree
Hide file tree
Showing 12 changed files with 8,658 additions and 7,700 deletions.
30 changes: 29 additions & 1 deletion examples/viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,39 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
anari
anari_test_scenes
stb_image
glad
glad_gl
)

install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

option(BUILD_GLES_VIEWER "Build GLES version of the viewer" OFF)
if (BUILD_GLES_VIEWER)

add_executable(${PROJECT_NAME}_gles2
MainWindow.cpp
main.cpp
OrbitManipulator.cpp
)

target_compile_definitions(${PROJECT_NAME}_gles2 PRIVATE GLM_ENABLE_EXPERIMENTAL)
target_compile_definitions(${PROJECT_NAME}_gles2 PRIVATE USE_GLES2)

target_link_libraries(${PROJECT_NAME}_gles2 PRIVATE
imgui_glfw_gles2
anari
anari_test_scenes
stb_image
glad_gles2
)

install(TARGETS ${PROJECT_NAME}_gles2
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

endif()
15 changes: 14 additions & 1 deletion examples/viewer/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ MainWindow::MainWindow(const glm::uvec2 &windowSize)
// Request a window that is IEC standard RGB color space capable
glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE);

#ifdef USE_GLES2
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
#endif

// create GLFW window
g_window = glfwCreateWindow(windowSize.x,
windowSize.y,
Expand All @@ -176,10 +182,17 @@ MainWindow::MainWindow(const glm::uvec2 &windowSize)
glfwMakeContextCurrent(g_window);

// Setup for OpenGL graphics library rendering
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
#ifdef USE_GLES2
if (!gladLoadGLES2((GLADloadfunc)glfwGetProcAddress)) {
glfwTerminate();
throw std::runtime_error("Failed to load GLES!");
}
#else
if (!gladLoadGL((GLADloadfunc)glfwGetProcAddress)) {
glfwTerminate();
throw std::runtime_error("Failed to load GL!");
}
#endif

// Create a texture
glGenTextures(1, &framebufferTexture);
Expand Down
7 changes: 6 additions & 1 deletion examples/viewer/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
#include "OrbitManipulator.h"
#include "glm_box3.h"
// glad header
#include "glad/glad.h"
#ifdef USE_GLES2
#include "glad/gles2.h"
#else
#include "glad/gl.h"
#endif
// glfw header
#define GLFW_INCLUDE_NONE
#include "GLFW/glfw3.h"
// ANARI headers
#include "anari/anari_cpp.hpp"
Expand Down
24 changes: 21 additions & 3 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ set(OpenGL_GL_PREFERENCE "LEGACY")
find_package(OpenGL 4 REQUIRED)
find_package(glfw3 REQUIRED)

add_library(imgui_glfw OBJECT
set(IMGUI_SOURCES
${imgui_src_LOCATION}/imgui.cpp
${imgui_src_LOCATION}/imgui_draw.cpp
${imgui_src_LOCATION}/imgui_demo.cpp
Expand All @@ -51,12 +51,30 @@ add_library(imgui_glfw OBJECT
${imgui_src_LOCATION}/misc/cpp/imgui_stdlib.cpp
)

target_link_libraries(imgui_glfw PUBLIC glfw OpenGL::GL glad)
target_compile_definitions(imgui_glfw PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD)
add_library(imgui_glfw OBJECT
${IMGUI_SOURCES}
)

target_link_libraries(imgui_glfw PUBLIC glfw OpenGL::GL glad_gl)
target_compile_definitions(imgui_glfw PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD2)

target_include_directories(imgui_glfw
PUBLIC
${imgui_src_LOCATION}
${imgui_src_LOCATION}/backends
${imgui_src_LOCATION}/misc/cpp
)

add_library(imgui_glfw_gles2 OBJECT
${IMGUI_SOURCES}
)

target_link_libraries(imgui_glfw_gles2 PUBLIC glfw OpenGL::GL glad_gles2)
target_compile_definitions(imgui_glfw_gles2 PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD2 IMGUI_IMPL_OPENGL_ES3)

target_include_directories(imgui_glfw_gles2
PUBLIC
${imgui_src_LOCATION}
${imgui_src_LOCATION}/backends
${imgui_src_LOCATION}/misc/cpp
)
6 changes: 4 additions & 2 deletions external/glad/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Copyright 2021 The Khronos Group
## SPDX-License-Identifier: Apache-2.0

add_library(glad STATIC glad.c)
target_include_directories(glad PUBLIC ${CMAKE_CURRENT_LIST_DIR})
add_library(glad_gl STATIC src/gl.c)
add_library(glad_gles2 STATIC src/gles2.c)
target_include_directories(glad_gl PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
target_include_directories(glad_gles2 PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)

0 comments on commit 6991cbf

Please sign in to comment.