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();
|
||||
|
||||
Reference in New Issue
Block a user