Skip to content

Commit 04e5437

Browse files
committed
Working web assembly build - ImGUI not working
1 parent 817bae4 commit 04e5437

150 files changed

Lines changed: 17929 additions & 196 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎dependencies/CMakeLists.txt‎

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@ include(FetchContent)
22

33

44
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
5-
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
6-
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
7-
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
8-
95
FetchContent_Declare(
106
imgui
117
GIT_REPOSITORY https://github.com/ocornut/imgui
128
GIT_TAG docking
139
)
1410

15-
FetchContent_Declare(
16-
glfw
17-
GIT_REPOSITORY https://github.com/glfw/glfw
18-
GIT_TAG 3.3.8
19-
)
11+
if(NOT EMSCRIPTEN)
12+
FetchContent_Declare(
13+
glfw
14+
GIT_REPOSITORY https://github.com/glfw/glfw
15+
GIT_TAG 3.3.8
16+
)
17+
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
18+
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
19+
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
20+
FetchContent_MakeAvailable(glfw)
21+
endif()
2022

2123
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
2224
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
2325
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
2426

25-
FetchContent_MakeAvailable(glfw)
2627

2728
FetchContent_Declare(
2829
glm
@@ -32,8 +33,10 @@ FetchContent_Declare(
3233
FetchContent_MakeAvailable(glm)
3334

3435

35-
add_library(glad STATIC
36-
glad/src/glad.c)
36+
if(NOT EMSCRIPTEN)
37+
add_library(glad STATIC glad/src/glad.c)
38+
target_include_directories(glad PUBLIC glad/include)
39+
endif()
3740

3841

3942
add_library(learnopengl
@@ -42,13 +45,16 @@ add_library(learnopengl
4245
"learnopengl/include/stb_image/stb_image.h"
4346
"learnopengl/src/stb_image.cpp" "learnopengl/include/camera/camera.h" "learnopengl/src/camera.cpp" "learnopengl/include/VAO/VAO.h" "learnopengl/include/VBO/VBO.h" "learnopengl/src/VAO.cpp" "learnopengl/src/VBO.cpp" "learnopengl/include/texture/texture.h" "learnopengl/src/texture.cpp")
4447

45-
target_include_directories(glad PUBLIC glad/include)
4648
target_include_directories(learnopengl PUBLIC learnopengl/include)
47-
target_link_libraries(learnopengl PUBLIC
48-
glad
49-
glm::glm)
49+
if(EMSCRIPTEN)
50+
target_link_libraries(learnopengl PUBLIC glm::glm)
51+
else()
52+
target_link_libraries(learnopengl PUBLIC glad glm::glm OpenGL::GL)
53+
endif()
5054

51-
find_package(OpenGL REQUIRED)
55+
if(NOT EMSCRIPTEN)
56+
find_package(OpenGL REQUIRED)
57+
endif()
5258

5359
FetchContent_MakeAvailable(imgui)
5460

@@ -60,13 +66,16 @@ add_library(imgui STATIC
6066
${imgui_SOURCE_DIR}/imgui_widgets.cpp
6167
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
6268
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
63-
)
69+
)
6470

6571
target_include_directories(imgui PUBLIC
6672
${imgui_SOURCE_DIR}
6773
${imgui_SOURCE_DIR}/backends
6874
)
6975

70-
target_link_libraries(imgui PUBLIC glfw OpenGL::GL)
71-
72-
target_link_libraries(learnopengl PUBLIC OpenGL::GL)
76+
if(EMSCRIPTEN)
77+
target_compile_options(imgui PRIVATE "-s" "USE_GLFW=3")
78+
else()
79+
target_link_libraries(imgui PUBLIC glfw OpenGL::GL)
80+
target_link_libraries(learnopengl PUBLIC OpenGL::GL)
81+
endif()

‎dependencies/learnopengl/include/VAO/VAO.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*#pragma once
2-
#include <glad/glad.h>
2+
#include <glad_include_guard.h>
33
#include <VBO/VBO.h>
44
#include <vector>
55

‎dependencies/learnopengl/include/VBO/VBO.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#pragma once
22

3-
#include <glad/glad.h>
43
#include <vector>
54

5+
#ifdef __EMSCRIPTEN__
6+
#include <GLES3/gl3.h>
7+
#else
8+
#include <glad/glad.h>
9+
#endif
10+
611
class VBO {
712
public:
813
unsigned int ID;

‎dependencies/learnopengl/include/camera/camera.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#pragma once
22

3+
#ifdef __EMSCRIPTEN__
4+
#include <GLES3/gl3.h>
5+
#else
36
#include <glad/glad.h>
7+
#endif
48
#include <glm/glm.hpp>
59
#include <glm/gtc/matrix_transform.hpp>
610

‎dependencies/learnopengl/include/shader/shader.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#pragma once
22

3+
#ifdef __EMSCRIPTEN__
4+
#include <GLES3/gl3.h>
5+
#else
36
#include <glad/glad.h>
7+
#endif
48
#include <glm/glm.hpp>
59

610
#include <string>

‎dependencies/learnopengl/include/texture/texture.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
#include <iostream>
44
#include <stb_image/stb_image.h>
55
#include <shader/shader.h>
6+
#ifdef __EMSCRIPTEN__
7+
#include <GLES3/gl3.h>
8+
#else
69
#include <glad/glad.h>
7-
10+
#endif
811
using std::string;
912

1013
class Texture {

‎dependencies/learnopengl/src/shader.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <shader/shader.h>
2-
#include <glad/glad.h>
32
#include <glm/glm.hpp>
43

54
#include <string>
@@ -72,6 +71,8 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath, const char* geo
7271
checkCompileErrors(fragment, "FRAGMENT");
7372
// if geometry shader is given, compile geometry shader
7473
unsigned int geometry;
74+
#ifndef __EMSCRIPTEN__
75+
7576
if (geometryPath != nullptr)
7677
{
7778
const char* gShaderCode = geometryCode.c_str();
@@ -80,6 +81,8 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath, const char* geo
8081
glCompileShader(geometry);
8182
checkCompileErrors(geometry, "GEOMETRY");
8283
}
84+
85+
#endif
8386
// shader Program
8487
ID = glCreateProgram();
8588
glAttachShader(ID, vertex);

‎src/CMakeLists.txt‎

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(SOURCE_FILES
22
"graphics/graphics.cpp"
33
"graphics/graphics.h"
4-
"types/types.h" "parser/tokenizer.h" "parser/checker.h" "parser/rpn.h" "parser/parser.h" "parser/checker.cpp" "parser/parser.cpp" "parser/rpn.cpp" "parser/tokenizer.cpp" "parser/simplifier.h" "parser/simplifier.cpp" "transformer/constant.h" "transformer/constant.cpp" "preprocessor/preprocessor.h" "preprocessor/string_builder.h" "transformer/operator.h" "transformer/operator.cpp" "transformer/transformer.h" "transformer/transformer.cpp" "preprocessor/string_builder.cpp" "preprocessor/preprocessor.cpp" "interactions/interactions.h" "interactions/interactions.cpp" "parser/validator.cpp" "parser/validator.h" "graphics/ui_init.h" "graphics/ui_init.cpp" "graphics/ui.h" "graphics/ui.cpp" "types/type_mapper.h" "types/type_mapper.cpp" "compiler/compiler_shader.h" "compiler/compiler_shader.cpp" "transformer/tree.h" "transformer/tree.cpp" "higher_order/derivative.h" "higher_order/higher_order.h" "higher_order/derivative.cpp" "higher_order/higher_order.cpp" "graphics/3d/mesh.h" "graphics/3d/mesh.cpp" "graphics/3d/camera_state.h" "graphics/3d/camera_state.cpp" "graphics/picker.cpp")
4+
"types/types.h" "parser/tokenizer.h" "parser/checker.h" "parser/rpn.h" "parser/parser.h" "parser/checker.cpp" "parser/parser.cpp" "parser/rpn.cpp" "parser/tokenizer.cpp" "parser/simplifier.h" "parser/simplifier.cpp" "transformer/constant.h" "transformer/constant.cpp" "preprocessor/preprocessor.h" "preprocessor/string_builder.h" "transformer/operator.h" "transformer/operator.cpp" "transformer/transformer.h" "transformer/transformer.cpp" "preprocessor/string_builder.cpp" "preprocessor/preprocessor.cpp" "interactions/interactions.h" "interactions/interactions.cpp" "parser/validator.cpp" "parser/validator.h" "graphics/ui_init.h" "graphics/ui_init.cpp" "graphics/ui.h" "graphics/ui.cpp" "types/type_mapper.h" "types/type_mapper.cpp" "compiler/compiler_shader.h" "compiler/compiler_shader.cpp" "transformer/tree.h" "transformer/tree.cpp" "higher_order/derivative.h" "higher_order/higher_order.h" "higher_order/derivative.cpp" "higher_order/higher_order.cpp" "graphics/3d/mesh.h" "graphics/3d/mesh.cpp" "graphics/3d/camera_state.h" "graphics/3d/camera_state.cpp" "graphics/picker.cpp" "glad_include_guard.h")
55
set(SHADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/shaders")
66
set(HEADER_BUILD "${CMAKE_CURRENT_BINARY_DIR}/shaders/embedded_shaders.h")
77
set(HEADER_SRC "${CMAKE_CURRENT_SOURCE_DIR}/shaders/embedded_shaders.h")
@@ -32,18 +32,30 @@ add_custom_command(
3232

3333

3434
add_executable(complex-plotter WIN32 ${SOURCE_FILES} ${HEADER_SRC} "main.cpp")
35-
find_package(OpenGL REQUIRED)
3635

37-
target_link_libraries(complex-plotter PRIVATE
38-
glad
39-
glfw
40-
glm::glm
41-
OpenGL::GL
42-
learnopengl
43-
imgui
44-
)
36+
if(NOT EMSCRIPTEN)
37+
find_package(OpenGL REQUIRED)
38+
endif()
4539

46-
if(UNIX AND NOT APPLE)
40+
if(EMSCRIPTEN)
41+
target_link_libraries(complex-plotter PRIVATE
42+
#glfw
43+
glm::glm
44+
learnopengl
45+
imgui
46+
)
47+
else()
48+
target_link_libraries(complex-plotter PRIVATE
49+
glad
50+
glfw
51+
glm::glm
52+
OpenGL::GL
53+
learnopengl
54+
imgui
55+
)
56+
endif()
57+
58+
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
4759
target_link_libraries(complex-plotter PRIVATE
4860
pthread
4961
dl
@@ -63,4 +75,12 @@ target_include_directories(complex-plotter PRIVATE
6375
"${CMAKE_CURRENT_SOURCE_DIR}"
6476
"${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/learnopengl/include"
6577
"."
66-
)
78+
)
79+
80+
if(EMSCRIPTEN)
81+
set(EMSCRIPTEN_LINK_FLAGS "-s USE_GLFW=3 -s USE_WEBGL2=1 -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2 -s ALLOW_MEMORY_GROWTH=1")
82+
83+
set_target_properties(complex-plotter PROPERTIES LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS}")
84+
target_compile_options(complex-plotter PRIVATE "-s" "USE_GLFW=3")
85+
set_target_properties(complex-plotter PROPERTIES SUFFIX ".html")
86+
endif()

‎src/glad_include_guard.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#ifdef __EMSCRIPTEN__
4+
#include <GLES3/gl3.h>
5+
#else
6+
#include <glad/glad.h>
7+
#endif

‎src/graphics/3d/camera_state.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
#include <glad/glad.h>
2+
#include <glad_include_guard.h>
33
#include <GLFW/glfw3.h>
44
#include <glm/glm.hpp>
55
#include <glm/gtc/matrix_transform.hpp>

0 commit comments

Comments
 (0)