add webgl support

This commit is contained in:
2019-10-05 21:08:40 +02:00
parent a1c0dcb007
commit f2a73a905d
19 changed files with 370 additions and 11 deletions

136
webgl/CMakeLists.txt Normal file
View File

@@ -0,0 +1,136 @@
cmake_minimum_required(VERSION 3.4.1)
project(panopainter)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-std=c++14 -O2 \
-s USE_GLFW=3 \
-s USE_WEBGL2=1 \
-s FULL_ES3=1 \
-s USE_PTHREADS=1 \
-s ASSERTIONS=2 \
-s TOTAL_MEMORY=64Mb \
-s ALLOW_MEMORY_GROWTH=1 \
-s WASM_MEM_MAX=512MB \
")
add_executable(panopainter
src/main.cpp
../libs/yoga/yoga/log.cpp
../libs/yoga/yoga/Utils.cpp
../libs/yoga/yoga/YGConfig.cpp
../libs/yoga/yoga/YGEnums.cpp
../libs/yoga/yoga/YGLayout.cpp
../libs/yoga/yoga/YGMarker.cpp
../libs/yoga/yoga/YGNode.cpp
../libs/yoga/yoga/YGNodePrint.cpp
../libs/yoga/yoga/YGStyle.cpp
../libs/yoga/yoga/YGValue.cpp
../libs/yoga/yoga/Yoga.cpp
../libs/tinyxml2/tinyxml2.cpp
../libs/jpeg/jpgd.cpp
../libs/jpeg/jpge.cpp
../libs/poly2tri/poly2tri/common/shapes.cc
../libs/poly2tri/poly2tri/sweep/advancing_front.cc
../libs/poly2tri/poly2tri/sweep/cdt.cc
../libs/poly2tri/poly2tri/sweep/sweep_context.cc
../libs/poly2tri/poly2tri/sweep/sweep.cc
../libs/fmt/src/format.cc
../src/pch.cpp
../src/util.cpp
../src/rtt.cpp
../src/bezier.cpp
../src/asset.cpp
../src/image.cpp
../src/texture.cpp
../src/font.cpp
../src/shader.cpp
../src/shape.cpp
../src/app.cpp
../src/app_cloud.cpp
../src/app_dialogs.cpp
../src/app_events.cpp
../src/app_layout.cpp
../src/app_shaders.cpp
../src/app_vr.cpp
../src/brush.cpp
../src/canvas.cpp
../src/canvas_layer.cpp
../src/canvas_actions.cpp
../src/canvas_modes.cpp
../src/log.cpp
../src/action.cpp
../src/layout.cpp
../src/version.cpp
../src/node.cpp
../src/node_about.cpp
../src/node_border.cpp
../src/node_button.cpp
../src/node_button_custom.cpp
../src/node_canvas.cpp
../src/node_checkbox.cpp
../src/node_color_quad.cpp
../src/node_colorwheel.cpp
../src/node_combobox.cpp
../src/node_changelog.cpp
../src/node_dialog_browse.cpp
../src/node_dialog_cloud.cpp
../src/node_dialog_open.cpp
../src/node_dialog_picker.cpp
../src/node_dialog_layer_rename.cpp
../src/node_dialog_resize.cpp
../src/node_icon.cpp
../src/node_image.cpp
../src/node_image_texture.cpp
../src/node_message_box.cpp
../src/node_panel_brush.cpp
../src/node_panel_color.cpp
../src/node_panel_grid.cpp
../src/node_panel_floating.cpp
../src/node_panel_layer.cpp
../src/node_panel_stroke.cpp
../src/node_panel_quick.cpp
../src/node_popup_menu.cpp
../src/node_progress_bar.cpp
../src/node_settings.cpp
../src/node_slider.cpp
../src/node_stroke_preview.cpp
../src/node_text.cpp
../src/node_text_input.cpp
../src/node_tool_bucket.cpp
../src/node_usermanual.cpp
../src/node_viewport.cpp
../src/node_scroll.cpp
../src/abr.cpp
../src/binary_stream.cpp
../src/serializer.cpp
../src/settings.cpp
../src/node_input_box.cpp
../src/node_dialog_export_ppbr.cpp
)
set_target_properties(panopainter PROPERTIES SUFFIX ".html")
set_target_properties(panopainter PROPERTIES LINK_FLAGS "\
--embed-file data \
-s USE_GLFW=3 \
-s USE_WEBGL2=1 \
-s FULL_ES3=1 \
-s USE_PTHREADS=1 \
-s ASSERTIONS=2 \
-s TOTAL_MEMORY=64Mb \
-s ALLOW_MEMORY_GROWTH=1 \
-s WASM_MEM_MAX=512MB \
")
target_include_directories(panopainter PRIVATE
src
../src
../libs/glm
../libs/tinyxml2
../libs/yoga
../libs/stb
../libs/jpeg
../libs/poly2tri/poly2tri
../libs/base64
../libs/sqlite3
../libs/nanort
../libs/hash-library
../libs/fmt/include
../libs/glad/include
../libs/tinyfiledialogs
)

93
webgl/src/main.cpp Normal file
View File

@@ -0,0 +1,93 @@
#include <pch.h>
#include <stdio.h>
#include <emscripten.h>
#include <thread>
#include <chrono>
#include <app.h>
#include <fstream>
App app;
GLFWwindow* wnd;
float theta = 0;
glm::vec2 g_cursor_pos;
void main_loop()
{
app.render_thread_tick();
app.ui_thread_tick();
// theta += 0.1f;
// float r = sinf(theta);
// glClearColor(r, 0.9f, 0.9f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT);
// app.tick(0);
// app.update(0);
// app.draw(0);
// SDL_GL_SwapWindow(wnd);
}
int main()
{
if (glfwInit() != GL_TRUE)
printf("Failed to init GLFW");
wnd = glfwCreateWindow(800, 600, "hello", nullptr, nullptr);
glfwMakeContextCurrent(wnd);
glfwSetCursorPosCallback(wnd, [](GLFWwindow* wnd, double x, double y){
g_cursor_pos = glm::vec2(x, y);
app.ui_task_async([=]{
app.mouse_move(x, y, 1.f, kEventSource::Mouse, false);
});
});
glfwSetMouseButtonCallback(wnd, [](GLFWwindow* wnd, int button, int action, int mods){
app.ui_task_async([=]{
if (action == GLFW_PRESS)
app.mouse_down(button, g_cursor_pos.x, g_cursor_pos.y, 1.f, kEventSource::Mouse, false);
else if (action == GLFW_RELEASE)
app.mouse_up(button, g_cursor_pos.x, g_cursor_pos.y, kEventSource::Mouse, false);
});
});
glfwSetWindowSizeCallback(wnd, [](GLFWwindow* wnd, int width, int height){
app.ui_task_async([=]{
app.resize(width, height);
});
});
glfwSetWindowCloseCallback(wnd, [](GLFWwindow* wnd){
app.ui_task([] {
if (!app.request_close())
glfwSetWindowShouldClose(app.glfw_window, GLFW_FALSE);
});
});
glfwSetWindowRefreshCallback(wnd, [](GLFWwindow* wnd){
app.ui_task_async([=]{
app.redraw = true;
}, true);
});
printf("GL version: %s\n", glGetString(GL_VERSION));
printf("GL vendor: %s\n", glGetString(GL_VENDOR));
printf("GL renderer: %s\n", glGetString(GL_RENDERER));
printf("GLSL version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
App::I = &app;
app.initLog();
app.create();
app.width = 800;
app.height = 600;
app.glfw_window = wnd;
// app.render_thread_tick();
// app.ui_thread_tick();
app.ui_task_async([]{
app.init();
});
LOG("start threads");
//app.render_thread_start();
// app.ui_thread_start();
emscripten_set_main_loop(main_loop, 0, true);
printf("hello world 003\n");
return 0;
}