add webgl support
This commit is contained in:
83
src/app.cpp
83
src/app.cpp
@@ -250,6 +250,7 @@ void App::initLog()
|
||||
LOG("load preferences failed");
|
||||
}
|
||||
|
||||
#if WITH_CURL
|
||||
int progress_callback_download(void *clientp, curl_off_t dltotal,
|
||||
curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
@@ -265,9 +266,11 @@ int progress_callback_upload(void *clientp, curl_off_t dltotal,
|
||||
progress((float)ulnow / (float)ultotal);
|
||||
return 0;
|
||||
}
|
||||
#endif //CURL
|
||||
|
||||
void App::download(std::string url, std::string dest_filepath, std::function<void(float)> progress)
|
||||
{
|
||||
#if WITH_CURL
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
@@ -289,12 +292,14 @@ void App::download(std::string url, std::string dest_filepath, std::function<voi
|
||||
curl_easy_cleanup(curl);
|
||||
fclose(fp);
|
||||
}
|
||||
#endif //CURL
|
||||
}
|
||||
|
||||
bool App::check_license()
|
||||
{
|
||||
return true; // TODO: for distribuiton only
|
||||
|
||||
#if WITH_CURL
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
@@ -321,11 +326,13 @@ bool App::check_license()
|
||||
if (err == CURLcode::CURLE_OK && ret == "success")
|
||||
return true;
|
||||
}
|
||||
#endif //CURL
|
||||
return false;
|
||||
}
|
||||
|
||||
void App::upload(std::string filename, std::string name, std::function<void(float)> progress)
|
||||
{
|
||||
#if WITH_CURL
|
||||
CURL *curl;
|
||||
|
||||
struct curl_httppost *formpost = NULL;
|
||||
@@ -362,6 +369,7 @@ void App::upload(std::string filename, std::string name, std::function<void(floa
|
||||
std::cout << "\n\nUPLOAD RESULT\n" << res << "\n\n\n";
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
#endif //CURL
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -413,6 +421,7 @@ void App::init()
|
||||
LOG("GL version: %s", glGetString(GL_VERSION));
|
||||
LOG("GL vendor: %s", glGetString(GL_VENDOR));
|
||||
LOG("GL renderer: %s", glGetString(GL_RENDERER));
|
||||
LOG("GLSL version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
||||
//GLint n_exts;
|
||||
//glGetIntegerv(GL_NUM_EXTENSIONS, &n_exts);
|
||||
@@ -465,7 +474,7 @@ void App::async_start()
|
||||
#elif _WIN32
|
||||
async_lock();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#elif __LINUX__
|
||||
#elif __LINUX__ || __WEB__
|
||||
glfwMakeContextCurrent(glfw_window);
|
||||
#endif
|
||||
}
|
||||
@@ -499,7 +508,7 @@ void App::async_swap()
|
||||
android_async_swap();
|
||||
#elif _WIN32
|
||||
win32_async_swap();
|
||||
#elif __LINUX__
|
||||
#elif __LINUX__ || __WEB__
|
||||
glfwSwapBuffers(glfw_window);
|
||||
#endif
|
||||
}
|
||||
@@ -833,6 +842,37 @@ void App::rec_loop()
|
||||
}
|
||||
}
|
||||
|
||||
void App::render_thread_tick()
|
||||
{
|
||||
static uint32_t count = 0;
|
||||
render_thread_id = std::this_thread::get_id();
|
||||
render_running = true;
|
||||
std::deque<AppTask> working_list;
|
||||
|
||||
// move the task list locally to free the queue for other threads
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(render_task_mutex);
|
||||
if (render_tasklist.empty())
|
||||
return;
|
||||
working_list = std::move(render_tasklist);
|
||||
}
|
||||
|
||||
// execute the tasks
|
||||
if (!working_list.empty())
|
||||
{
|
||||
async_start();
|
||||
while (!working_list.empty())
|
||||
{
|
||||
//LOG("render task %d", count);
|
||||
//LOG("task %s", working_list.front().name.c_str());
|
||||
count++;
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
async_end();
|
||||
}
|
||||
}
|
||||
|
||||
void App::render_thread_main()
|
||||
{
|
||||
BT_SetTerminate();
|
||||
@@ -868,6 +908,45 @@ void App::render_thread_main()
|
||||
}
|
||||
}
|
||||
|
||||
void App::ui_thread_tick()
|
||||
{
|
||||
ui_thread_id = std::this_thread::get_id();
|
||||
ui_running = true;
|
||||
|
||||
std::deque<AppTask> working_list;
|
||||
|
||||
// move the task list locally to free the queue for other threads
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(ui_task_mutex);
|
||||
working_list = std::move(ui_tasklist);
|
||||
}
|
||||
|
||||
// execute the tasks
|
||||
if (!working_list.empty())
|
||||
{
|
||||
while (!working_list.empty())
|
||||
{
|
||||
//LOG("ui task %d", count);
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
tick(0);
|
||||
|
||||
if (redraw)
|
||||
{
|
||||
update(0);
|
||||
render_task([this]
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
clear();
|
||||
draw(0);
|
||||
async_swap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::ui_thread_main()
|
||||
{
|
||||
BT_SetTerminate();
|
||||
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
#elif defined(__OSX__) && defined(__OBJC__)
|
||||
View* osx_view;
|
||||
AppOSX* osx_app;
|
||||
#elif __LINUX__
|
||||
#elif __LINUX__ || __WEB__
|
||||
GLFWwindow* glfw_window;
|
||||
#endif
|
||||
|
||||
@@ -294,6 +294,7 @@ public:
|
||||
static std::thread render_thread;
|
||||
static std::thread::id render_thread_id;
|
||||
static bool render_running;
|
||||
void render_thread_tick();
|
||||
void render_thread_main();
|
||||
void render_thread_start();
|
||||
void render_thread_stop();
|
||||
@@ -365,6 +366,7 @@ public:
|
||||
static std::thread ui_thread;
|
||||
static std::thread::id ui_thread_id;
|
||||
static bool ui_running;
|
||||
void ui_thread_tick();
|
||||
void ui_thread_main();
|
||||
void ui_thread_start();
|
||||
void ui_thread_stop();
|
||||
|
||||
@@ -193,7 +193,7 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
|
||||
std::string path = win32_open_file(filter.c_str());
|
||||
if (!path.empty())
|
||||
callback(path);
|
||||
#else
|
||||
#elif __LINUX__
|
||||
if (auto p = tinyfd_openFileDialog("Open File", "", 0, nullptr, nullptr, false))
|
||||
callback(p);
|
||||
#endif
|
||||
|
||||
@@ -17,7 +17,7 @@ void App::initShaders()
|
||||
std::string ext = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||
if (ext.find("shader_framebuffer_fetch") != std::string::npos)
|
||||
ShaderManager::ext_framebuffer_fetch = true;
|
||||
#if __GLES__
|
||||
#if __GLES__ && !__WEB__
|
||||
if (ext.find("texture_float") != std::string::npos)
|
||||
ShaderManager::ext_float32 = true;
|
||||
if (ext.find("texture_float_linear") != std::string::npos)
|
||||
|
||||
@@ -145,6 +145,8 @@ bool Asset::create_dir(const std::string& path)
|
||||
return android_create_dir(path);
|
||||
#elif __IOS__ || __OSX__
|
||||
return apple_create_dir(path);
|
||||
else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -155,6 +157,7 @@ static size_t curl_data_handler_asset(void* contents, size_t size, size_t nmemb,
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
#if WITH_CURL
|
||||
static int progress_callback_asset_download(void* clientp, curl_off_t dltotal,
|
||||
curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
@@ -168,9 +171,11 @@ static int progress_callback_asset_download(void* clientp, curl_off_t dltotal,
|
||||
bool cont = ass->on_progress(p);
|
||||
return cont ? 0 : 1;
|
||||
}
|
||||
#endif //CURL
|
||||
|
||||
bool Asset::open_url(const std::string& url, std::function<bool(float)> progress /*= nullptr*/)
|
||||
{
|
||||
#if WITH_CURL
|
||||
CURL* curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
@@ -204,6 +209,7 @@ bool Asset::open_url(const std::string& url, std::function<bool(float)> progress
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif // CURL
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1577,7 +1577,7 @@ bool Canvas::create(int width, int height)
|
||||
m_tex[i].create(width, height, GL_RGBA8);
|
||||
m_tex2[i].create(width, height, GL_RGBA8);
|
||||
}
|
||||
#if defined(__IOS__) || defined(__ANDROID__)
|
||||
#if defined(__GLES__)
|
||||
m_sampler_brush.create();
|
||||
#else
|
||||
m_sampler_brush.create(GL_LINEAR, GL_CLAMP_TO_BORDER);
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
#include "canvas_modes.h"
|
||||
#include <stack>
|
||||
|
||||
#if __WEB__
|
||||
#define CANVAS_RES 512
|
||||
#else
|
||||
#define CANVAS_RES 1536
|
||||
#endif
|
||||
|
||||
struct PPIThumb
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ LogRemote LogRemote::I;
|
||||
|
||||
void LogRemote::start()
|
||||
{
|
||||
#if WITH_CURL
|
||||
if (m_running || m_error)
|
||||
return; // already running
|
||||
|
||||
@@ -27,6 +28,7 @@ void LogRemote::start()
|
||||
net_close();
|
||||
LOG("NET thread loop exit");
|
||||
});
|
||||
#endif //CURL
|
||||
}
|
||||
|
||||
void LogRemote::stop()
|
||||
@@ -39,6 +41,7 @@ void LogRemote::stop()
|
||||
|
||||
void LogRemote::net_init()
|
||||
{
|
||||
#if WITH_CURL
|
||||
if (!(curl = curl_easy_init()))
|
||||
return;
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &this->readBuffer);
|
||||
@@ -48,10 +51,12 @@ void LogRemote::net_init()
|
||||
#ifdef __ANDROID__
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
#endif
|
||||
#endif //CURL
|
||||
}
|
||||
std::string LogRemote::net_request(std::string cmd, std::string data /*= ""*/)
|
||||
{
|
||||
readBuffer.clear();
|
||||
#if WITH_CURL
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
|
||||
auto url = m_url + cmd;
|
||||
@@ -63,13 +68,16 @@ std::string LogRemote::net_request(std::string cmd, std::string data /*= ""*/)
|
||||
m_running = false;
|
||||
m_error = true;
|
||||
}
|
||||
#endif //CURL
|
||||
return readBuffer;
|
||||
}
|
||||
void LogRemote::net_close()
|
||||
{
|
||||
#if WITH_CURL
|
||||
if (curl)
|
||||
curl_easy_cleanup(curl);
|
||||
curl = nullptr;
|
||||
#endif //CURL
|
||||
m_running = false;
|
||||
}
|
||||
void LogRemote::file_init()
|
||||
|
||||
@@ -23,8 +23,10 @@ public:
|
||||
BlockingQueue<std::string> m_mq;
|
||||
// Store messages until the file is open
|
||||
std::vector<std::string> m_tmp;
|
||||
#if WITH_CURL
|
||||
CURL *curl = nullptr;
|
||||
CURLcode res;
|
||||
#endif
|
||||
std::string readBuffer;
|
||||
std::string m_url = "http://omigamedev.ddns.net:8083";
|
||||
int m_session;
|
||||
|
||||
@@ -1322,7 +1322,7 @@ void Node::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
|
||||
void Node::load_internal(const tinyxml2::XMLElement* x_node)
|
||||
{
|
||||
m_name = x_node->Name();
|
||||
//LOG("node %s", m_name.c_str());
|
||||
//LOG("load_internal node %s", m_name.c_str());
|
||||
|
||||
init();
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ void NodeDialogCloud::removed(Node* parent)
|
||||
|
||||
void NodeDialogCloud::load_thumbs_thread()
|
||||
{
|
||||
#if WITH_CURL
|
||||
BT_SetTerminate();
|
||||
CURL *curl = curl_easy_init();
|
||||
std::string res;
|
||||
@@ -144,6 +145,7 @@ void NodeDialogCloud::load_thumbs_thread()
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
#endif //CURL
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -147,7 +147,7 @@ void NodePanelGrid::init_controls()
|
||||
if (texres == m_texture.size().x)
|
||||
return;
|
||||
|
||||
#if defined(__IOS__) || defined(__ANDROID__)
|
||||
#if defined(__GLES__)
|
||||
m_texture.create(texres, texres);
|
||||
m_texture.create_mipmaps();
|
||||
#else
|
||||
|
||||
@@ -177,8 +177,12 @@ void NodePanelQuick::init_controls()
|
||||
|
||||
NodeButtonCustom* NodePanelQuick::init_button_brush(const std::string& name, bool szp, bool flp)
|
||||
{
|
||||
LOG("init_button_brush %s", name.c_str());
|
||||
auto button = find<NodeButtonCustom>(name.c_str());
|
||||
if (!button)
|
||||
LOG("couldn't find button %s", name.c_str());
|
||||
button->on_click = std::bind(&this_class::handle_button_brush_click, this, std::placeholders::_1);
|
||||
LOG("button has %d children", button->m_children.size());
|
||||
auto pr = static_cast<NodeStrokePreview*>(button->m_children[0].get());
|
||||
pr->m_brush = std::make_shared<Brush>();
|
||||
pr->m_brush->m_tip_size_pressure = szp;
|
||||
|
||||
23
src/pch.h
23
src/pch.h
@@ -103,6 +103,24 @@
|
||||
#define __block
|
||||
#define BT_SetTerminate void
|
||||
|
||||
#elif defined(EMSCRIPTEN)
|
||||
|
||||
#define GLFW_INCLUDE_ES3
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#define __WEB__ 1
|
||||
#define SHADER_VERSION "#version 300 es\n"
|
||||
#define PP_OS "web"
|
||||
#define __GLES__ 1
|
||||
#define __WEBGL__ 1
|
||||
#define __block
|
||||
#define BT_SetTerminate void
|
||||
|
||||
//#define GL_RGBA8 GL_RGBA
|
||||
|
||||
#endif
|
||||
|
||||
#define SIXPLETTE(I) {I, I, I, I, I, I}
|
||||
@@ -155,5 +173,8 @@
|
||||
#include <stb/stb_truetype.h>
|
||||
#include <stb/stb_image.h>
|
||||
#include <stb/stb_image_write.h>
|
||||
#include <curl/curl.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
#include <curl/curl.h>
|
||||
#endif
|
||||
@@ -299,7 +299,7 @@ void Sampler::set_border(glm::vec4 rgba)
|
||||
{
|
||||
App::I->render_task([this, rgba]
|
||||
{
|
||||
#if USE_SAMPLER && !defined(__IOS__) && !defined(__ANDROID__)
|
||||
#if USE_SAMPLER && !defined(__GLES__)
|
||||
glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(rgba));
|
||||
#endif // USE_SAMPLER
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user