fix glsl float interpolation, fix layers on ui reload, add vr thread for Quest

This commit is contained in:
2019-07-30 22:10:48 +02:00
parent f2d2ef1067
commit 945028f171
12 changed files with 95 additions and 40 deletions

View File

@@ -365,6 +365,29 @@ bool android_set_clipboard(const std::string& s)
return success;
}
bool vr_running = false;
static void engine_vr_loop()
{
LOG("start hmd render thread");
vr_running = true;
App::I->ui_sync();
while (vr_running)
{
#ifdef __QUEST__
App::I->render_task([] {
App::I->vr_draw_ui();
oculus_draw(0);
});
#endif
}
LOG("hmd renderer terminated");
}
static void engine_start_vr()
{
std::thread(engine_vr_loop).detach();
}
/**
* Initialize an EGL context for the current display.
*/
@@ -547,6 +570,8 @@ static int engine_init_display(struct engine* engine) {
g_context = context;
#ifdef __QUEST__
App::I->render_thread_id = std::this_thread::get_id();
LOG("QUEST init VR");
oculus_init_vr(display, context, engine->app->window);
#elif __FOCUS__
wave_init_vr(display, context, engine->app->window);
@@ -667,11 +692,22 @@ static int engine_init_display(struct engine* engine) {
App::I->width = 1024;
App::I->height = 1024;
App::I->redraw = true;
App::I->init();
App::I->resize(1024, 1024);
App::I->vr_active = true;
App::I->has_vr = true;
App::I->vr_only = true;
// give control to the render thread
LOG("release egl context");
eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
LOG("start render threads");
App::I->render_thread_start();
LOG("start ui thread");
App::I->ui_thread_start();
App::I->ui_sync();
LOG("start vr thread");
engine_start_vr();
#else
float density = get_display_density();
LOG("density %f", density);

View File

@@ -1666,7 +1666,7 @@ Here's a list of what's available in this release.
<border id="ext-fbf" height="20" width="30" color="0 0 0 1" align="center" justify="center" margin="0 5 0 0">
<text id="txt-rec" text="FbF" color="0 0 0 1"/>
</border>
<border id="ext-flt" height="20" width="30" color="0 0 0 1" align="center" justify="center" margin="0 5 0 0">
<border id="ext-flt" height="20" width="40" color="0 0 0 1" align="center" justify="center" margin="0 5 0 0">
<text id="ext-flt-text" text="B8" color="0 0 0 1"/>
</border>
<border id="ext-dpi" height="20" width="60" color=".2" align="center" justify="center" margin="0 5 0 0">

View File

@@ -826,6 +826,7 @@ void App::ui_thread_main()
android_attach_jni();
#endif
LOG("ui thread init()");
init();
auto t_start = std::chrono::high_resolution_clock::now();
@@ -921,6 +922,7 @@ void App::ui_thread_main()
void App::render_thread_start()
{
render_thread = std::thread(&App::render_thread_main, this);
render_running = true;
}
void App::render_thread_stop()
@@ -934,6 +936,7 @@ void App::render_thread_stop()
void App::ui_thread_start()
{
ui_thread = std::thread(&App::ui_thread_main, this);
ui_running = true;
}
void App::ui_thread_stop()

View File

@@ -1202,12 +1202,14 @@ void App::initLayout()
NodeIcon::static_init();
NodeStrokePreview::static_init();
static std::vector<std::shared_ptr<Layer>> saved_layers;
layout.on_reloading = [&] {
saved_layers = std::move(Canvas::I->m_layers);
ui_save();
NodeStrokePreview::empty_queue();
};
layout.on_loaded = [&] {
layout.on_loaded = [&] (bool reloaded) {
LOG("initializing layout updating after load");
layout[main_id]->update(width, height, zoom);
@@ -1215,8 +1217,16 @@ void App::initLayout()
init_sidebar();
layers->add_layer("Default", false, true);
Canvas::I->m_unsaved = false;
if (reloaded)
{
for (const auto& l : saved_layers)
layers->add_layer(l->m_name.c_str(), false, true, l);
}
else
{
layers->add_layer("Default", false, true);
Canvas::I->m_unsaved = false;
}
init_toolbar_draw();
init_toolbar_main();
@@ -1239,12 +1249,16 @@ void App::initLayout()
if (auto x = layout[main_id]->find<NodeBorder>("ext-flt"))
{
if (ShaderManager::ext_texture_float || ShaderManager::ext_half_float_pixel)
if (ShaderManager::ext_float32 || ShaderManager::ext_float16)
{
if (auto t = x->find<NodeText>("ext-flt-text"))
{
int bits = ShaderManager::ext_texture_float ? 32 : 16;
t->set_text_format("F%d", bits);
if (ShaderManager::ext_float32_linear)
t->set_text("F32L");
else if (ShaderManager::ext_float32)
t->set_text("F32");
else if (ShaderManager::ext_float16)
t->set_text("F16");
}
x->m_color = glm::vec4(0, 1, 0, 1);
}

View File

@@ -19,13 +19,15 @@ void App::initShaders()
ShaderManager::ext_framebuffer_fetch = true;
#if __GLES__
if (ext.find("texture_float") != std::string::npos)
ShaderManager::ext_texture_float = true;
ShaderManager::ext_float32 = true;
if (ext.find("texture_float_linear") != std::string::npos)
ShaderManager::ext_float32_linear = true;
if (ext.find("color_buffer_float") != std::string::npos)
ShaderManager::ext_texture_float = true;
if (ext.find("texture__half_float") != std::string::npos)
ShaderManager::ext_half_float_pixel = true;
ShaderManager::ext_float32 = true;
if (ext.find("texture_half_float") != std::string::npos)
ShaderManager::ext_float16 = true;
if (ext.find("color_buffer_half_float") != std::string::npos)
ShaderManager::ext_half_float_pixel = true;
ShaderManager::ext_float16 = true;
#endif
LOG("EXT: %s", ext.c_str());
}
@@ -33,8 +35,9 @@ void App::initShaders()
#if __GL__
// In OpenGL 3.3 these should be already available
ShaderManager::ext_texture_float = true;
ShaderManager::ext_half_float_pixel = true;
ShaderManager::ext_float32_linear = true;
ShaderManager::ext_float32 = true;
ShaderManager::ext_float16 = true;
#endif
LOG("Shader Extension shader_framebuffer_fetch: %s", ShaderManager::ext_framebuffer_fetch ? "enabled" : "disabled");

View File

@@ -834,12 +834,14 @@ void Canvas::stroke_commit()
ShaderManager::u_vec2(kShaderUniform::Resolution, m_size);
ShaderManager::u_float(kShaderUniform::Alpha, 1);
ShaderManager::u_int(kShaderUniform::Mask, m_smask_active);
ShaderManager::u_int(kShaderUniform::Lock, false);
ShaderManager::u_int(kShaderUniform::UseFragcoord, false);
ShaderManager::u_int(kShaderUniform::BlendMode, b->m_blend_mode);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
ShaderManager::u_int(kShaderUniform::UseDual, b->m_dual_enabled);
ShaderManager::u_int(kShaderUniform::UsePattern, b->m_pattern_enabled && !b->m_pattern_eachsample);
ShaderManager::u_int(kShaderUniform::DualBlendMode, b->m_dual_blend_mode);
ShaderManager::u_float(kShaderUniform::DualAlpha, b->m_dual_opacity);
ShaderManager::u_int(kShaderUniform::UsePattern, b->m_pattern_enabled && !b->m_pattern_eachsample);
ShaderManager::u_vec2(kShaderUniform::PatternScale, patt_scale);
ShaderManager::u_float(kShaderUniform::PatternInvert, b->m_pattern_invert);
ShaderManager::u_float(kShaderUniform::PatternBright, b->m_pattern_brightness);
@@ -847,7 +849,6 @@ void Canvas::stroke_commit()
ShaderManager::u_float(kShaderUniform::PatternDepth, b->m_pattern_depth);
ShaderManager::u_int(kShaderUniform::PatternBlendMode, b->m_pattern_blend_mode);
ShaderManager::u_vec2(kShaderUniform::PatternOffset, m_pattern_offset);
ShaderManager::u_float(kShaderUniform::DualAlpha, b->m_dual_opacity);
glActiveTexture(GL_TEXTURE0);
m_tex2[i].bind();
@@ -1494,24 +1495,22 @@ void Canvas::resize(int width, int height)
m_size = { width, height };
for (int i = 0; i < 6; i++)
{
if (ShaderManager::ext_texture_float)
if (ShaderManager::ext_float32_linear)
{
m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, GL_RGBA32F);
}
else if (ShaderManager::ext_half_float_pixel)
else if (ShaderManager::ext_float16)
{
m_tmp[i].create(width, height, -1, GL_RGBA16F);
m_tmp_dual[i].create(width, height, -1, GL_RGBA16F);
m_tex[i].create(width, height, GL_RGBA16F);
}
else
{
m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA8);
}
m_tex[i].create(width, height, GL_RGBA8);
m_tex2[i].create(width, height, GL_RGBA8);
}
for (auto& l : m_layers)
@@ -1548,24 +1547,22 @@ bool Canvas::create(int width, int height)
m_size = { width, height };
for (int i = 0; i < 6; i++)
{
if (ShaderManager::ext_texture_float)
if (ShaderManager::ext_float32_linear)
{
m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, GL_RGBA32F);
}
else if (ShaderManager::ext_half_float_pixel)
else if (ShaderManager::ext_float16)
{
m_tmp[i].create(width, height, -1, GL_RGBA16F);
m_tmp_dual[i].create(width, height, -1, GL_RGBA16F);
m_tex[i].create(width, height, GL_RGBA16F);
}
else
{
m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA8);
}
m_tex[i].create(width, height, GL_RGBA8);
m_tex2[i].create(width, height, GL_RGBA8);
}
#if defined(__IOS__) || defined(__ANDROID__)

View File

@@ -106,7 +106,7 @@ bool LayoutManager::load(const char* path)
}
if (on_loaded)
on_loaded();
on_loaded(m_loaded);
m_loaded = true;
return true;

View File

@@ -18,7 +18,7 @@ class LayoutManager
struct stat m_file_info { 0 };
public:
bool m_loaded = false;
std::function<void()> on_loaded;
std::function<void(bool reloaded)> on_loaded;
std::function<void()> on_reloading;
void unload();
void create();

View File

@@ -267,16 +267,17 @@ void NodeCanvas::draw()
ShaderManager::u_int(kShaderUniform::TexStroke, 1);
ShaderManager::u_int(kShaderUniform::TexMask, 2);
ShaderManager::u_int(kShaderUniform::TexDual, 3);
ShaderManager::u_vec2(kShaderUniform::Resolution, Canvas::I->m_size);
ShaderManager::u_int(kShaderUniform::TexPattern, 4);
ShaderManager::u_vec2(kShaderUniform::Resolution, Canvas::I->m_size);
ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index]->m_opacity);
ShaderManager::u_int(kShaderUniform::Lock, m_canvas->m_layers[layer_index]->m_alpha_locked);
ShaderManager::u_int(kShaderUniform::Mask, m_canvas->m_smask_active);
ShaderManager::u_int(kShaderUniform::Lock, m_canvas->m_layers[layer_index]->m_alpha_locked);
ShaderManager::u_int(kShaderUniform::UseFragcoord, false);
ShaderManager::u_int(kShaderUniform::BlendMode, b->m_blend_mode);
ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
ShaderManager::u_int(kShaderUniform::UseDual, b->m_dual_enabled);
ShaderManager::u_int(kShaderUniform::DualBlendMode, b->m_dual_blend_mode);
ShaderManager::u_float(kShaderUniform::DualAlpha, b->m_dual_opacity);
ShaderManager::u_int(kShaderUniform::UsePattern, b->m_pattern_enabled && !b->m_pattern_eachsample);
ShaderManager::u_vec2(kShaderUniform::PatternScale, patt_scale);
ShaderManager::u_float(kShaderUniform::PatternInvert, b->m_pattern_invert);
@@ -285,7 +286,6 @@ void NodeCanvas::draw()
ShaderManager::u_float(kShaderUniform::PatternDepth, b->m_pattern_depth);
ShaderManager::u_int(kShaderUniform::PatternBlendMode, b->m_pattern_blend_mode);
ShaderManager::u_vec2(kShaderUniform::PatternOffset, Canvas::I->m_pattern_offset);
ShaderManager::u_float(kShaderUniform::DualAlpha, b->m_dual_opacity);
glActiveTexture(GL_TEXTURE0);
m_canvas->m_layers[layer_index]->m_rtt[plane_index].bindTexture();

View File

@@ -121,7 +121,7 @@ void NodePanelGrid::init_controls()
m_render->on_click = [this](Node*)
{
if (ShaderManager::ext_texture_float || ShaderManager::ext_half_float_pixel)
if (ShaderManager::ext_float32 || ShaderManager::ext_float16)
{
std::thread([this] {
bake_uvs();
@@ -350,11 +350,11 @@ void NodePanelGrid::bake_uvs()
return;
RTT fb;
if (ShaderManager::ext_texture_float)
if (ShaderManager::ext_float32)
{
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
}
else if (ShaderManager::ext_half_float_pixel)
else if (ShaderManager::ext_float16)
{
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA16F);
}

View File

@@ -7,8 +7,9 @@
std::map<kShader, Shader> ShaderManager::m_shaders;
Shader* ShaderManager::m_current;
bool ShaderManager::ext_framebuffer_fetch = false;
bool ShaderManager::ext_texture_float = false;
bool ShaderManager::ext_half_float_pixel = false;
bool ShaderManager::ext_float32 = false;
bool ShaderManager::ext_float32_linear = false;
bool ShaderManager::ext_float16 = false;
std::string Shader::read(const std::string& path)
{

View File

@@ -110,8 +110,9 @@ class ShaderManager
static Shader* m_current;
public:
static bool ext_framebuffer_fetch;
static bool ext_texture_float;
static bool ext_half_float_pixel;
static bool ext_float32;
static bool ext_float32_linear;
static bool ext_float16;
static bool load(kShader id, const std::string& path);
static bool reload();
static bool create(kShader id, const std::string& vertex, const std::string& fragment);