From 9cccecd381243922996fa3bef74d64f0d34f5b54 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 8 Aug 2018 11:09:35 +0200 Subject: [PATCH] =?UTF-8?q?separate=20shaders,=20RGBA16F=20doesn=E2=80=99t?= =?UTF-8?q?=20work=20with=20picking=20in=20iOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine.xcodeproj/project.pbxproj | 10 ++++++++++ engine/app_shaders.cpp | 16 ++++++++++++++++ engine/canvas.cpp | 10 +++++----- engine/image.cpp | 5 ++--- engine/node_canvas.cpp | 2 +- engine/node_panel_grid.cpp | 18 ++++++++++-------- engine/shader.h | 1 + 7 files changed, 45 insertions(+), 17 deletions(-) diff --git a/engine.xcodeproj/project.pbxproj b/engine.xcodeproj/project.pbxproj index f28edfb..993b3cd 100644 --- a/engine.xcodeproj/project.pbxproj +++ b/engine.xcodeproj/project.pbxproj @@ -234,6 +234,9 @@ ADD7D2AF1EBFA35F00D5A897 /* libcurl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2AE1EBFA35F00D5A897 /* libcurl.a */; }; ADD7D2B11EBFA42600D5A897 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2B01EBFA42600D5A897 /* libz.tbd */; }; ADD7D2B31EBFA42C00D5A897 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2B21EBFA42C00D5A897 /* Security.framework */; }; + ADE22BE5211904AB00D5F44B /* node_panel_grid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADE22BE3211904AA00D5F44B /* node_panel_grid.cpp */; }; + ADE22BE6211904AB00D5F44B /* node_panel_grid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADE22BE3211904AA00D5F44B /* node_panel_grid.cpp */; }; + ADE22BE7211904AB00D5F44B /* node_panel_grid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADE22BE3211904AA00D5F44B /* node_panel_grid.cpp */; }; ADE491161F86E65D00FB8E92 /* advancing_front.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491121F86D09100FB8E92 /* advancing_front.cc */; }; ADE491171F86E65D00FB8E92 /* cdt.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491151F86D09100FB8E92 /* cdt.cc */; }; ADE491181F86E65D00FB8E92 /* shapes.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491111F86D09100FB8E92 /* shapes.cc */; }; @@ -474,6 +477,8 @@ ADD7D2AE1EBFA35F00D5A897 /* libcurl.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcurl.a; path = "../../Downloads/curl-android-ios-master/prebuilt-with-ssl/iOS/arm64/libcurl.a"; sourceTree = ""; }; ADD7D2B01EBFA42600D5A897 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; }; ADD7D2B21EBFA42C00D5A897 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; }; + ADE22BE3211904AA00D5F44B /* node_panel_grid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = node_panel_grid.cpp; sourceTree = ""; }; + ADE22BE4211904AA00D5F44B /* node_panel_grid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = node_panel_grid.h; sourceTree = ""; }; ADE491111F86D09100FB8E92 /* shapes.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = shapes.cc; path = libs/poly2tri/poly2tri/common/shapes.cc; sourceTree = ""; }; ADE491121F86D09100FB8E92 /* advancing_front.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = advancing_front.cc; path = libs/poly2tri/poly2tri/sweep/advancing_front.cc; sourceTree = ""; }; ADE491131F86D09100FB8E92 /* sweep.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = sweep.cc; path = libs/poly2tri/poly2tri/sweep/sweep.cc; sourceTree = ""; }; @@ -634,6 +639,8 @@ AD1063681EC7ADFA002A525F /* node_panel_brush.h */, AD1063691EC7ADFA002A525F /* node_panel_color.cpp */, AD10636A1EC7ADFA002A525F /* node_panel_color.h */, + ADE22BE3211904AA00D5F44B /* node_panel_grid.cpp */, + ADE22BE4211904AA00D5F44B /* node_panel_grid.h */, AD10636B1EC7ADFA002A525F /* node_panel_layer.cpp */, AD10636C1EC7ADFA002A525F /* node_panel_layer.h */, AD10636D1EC7ADFA002A525F /* node_panel_stroke.cpp */, @@ -1045,6 +1052,7 @@ AD0E5CA31ECC6F2B00C35669 /* main.cpp in Sources */, AD0E5CB21ECC72AD00C35669 /* jpge.cpp in Sources */, ADC6F4681F3E66FB004177FA /* app_dialogs.cpp in Sources */, + ADE22BE7211904AB00D5F44B /* node_panel_grid.cpp in Sources */, AD0E5CD21ECC72AD00C35669 /* app_events.cpp in Sources */, AD0E5CD11ECC72AD00C35669 /* app.cpp in Sources */, AD0E5CC21ECC72AD00C35669 /* node_image.cpp in Sources */, @@ -1165,6 +1173,7 @@ ADBC8C4A1FAE7CC40094B339 /* node_dialog_browse.cpp in Sources */, AD1063871EC7ADFA002A525F /* node_image_texture.cpp in Sources */, AD1063941EC7ADFA002A525F /* node_viewport.cpp in Sources */, + ADE22BE5211904AB00D5F44B /* node_panel_grid.cpp in Sources */, AD8CF7211E913F0500083FFD /* log.cpp in Sources */, AD95AEC71E41EDEC002DD03A /* pch.cpp in Sources */, AD1063861EC7ADFA002A525F /* node_icon.cpp in Sources */, @@ -1227,6 +1236,7 @@ AD0E119D1ECA215600CDA6BB /* app_layout.cpp in Sources */, AD1063991EC7AE92002A525F /* node_button.cpp in Sources */, ADD7D2931EBF9E1C00D5A897 /* log.cpp in Sources */, + ADE22BE6211904AB00D5F44B /* node_panel_grid.cpp in Sources */, ADD7D2971EBF9E1C00D5A897 /* canvas.cpp in Sources */, AD1063AC1EC7AE92002A525F /* node_viewport.cpp in Sources */, ADD7D2991EBF9E1C00D5A897 /* font.cpp in Sources */, diff --git a/engine/app_shaders.cpp b/engine/app_shaders.cpp index bd6be42..9fd3f1f 100644 --- a/engine/app_shaders.cpp +++ b/engine/app_shaders.cpp @@ -35,6 +35,20 @@ void App::initShaders() "}"; // TEXTURE ALPHA static const char* shader_alpha_f = + SHADER_VERSION + "uniform sampler2D tex;\n" + "uniform mediump float alpha;\n" + "uniform bool highlight;\n" + "in mediump vec3 uv;\n" + "out mediump vec4 frag;\n" + "void main(){\n" + " mediump vec4 c = texture(tex, uv.xy);\n" + " frag = highlight ? \n" + " vec4(clamp(vec3(.3)+c.rgb, vec3(0), vec3(1)), c.a) : \n" + " texture(tex, uv.xy) * vec4(1,1,1,alpha);\n" + "}\n"; + // TEXTURE ALPHA SEPARATED + static const char* shader_alpha_sep_f = SHADER_VERSION "uniform sampler2D tex;\n" "uniform sampler2D tex_alpha;\n" @@ -479,6 +493,8 @@ void App::initShaders() LOG("Failed to create shader Texture"); if (!ShaderManager::create(kShader::TextureAlpha, shader_v, shader_alpha_f)) LOG("Failed to create shader TextureAlpha"); + if (!ShaderManager::create(kShader::TextureAlphaSep, shader_v, shader_alpha_sep_f)) + LOG("Failed to create shader TextureAlphaSep"); if (!ShaderManager::create(kShader::StrokePreview, shader_v, shader_stroke_preview_f)) LOG("Failed to create shader StrokePreview"); if (!ShaderManager::create(kShader::CompErase, shader_v, shader_comp_erase_f)) diff --git a/engine/canvas.cpp b/engine/canvas.cpp index 7441c22..2266998 100644 --- a/engine/canvas.cpp +++ b/engine/canvas.cpp @@ -246,7 +246,7 @@ void ui::Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz m_plane_transform[plane_index] * glm::translate(glm::vec3(0, 0, -1)); - ui::ShaderManager::use(kShader::TextureAlpha); + ui::ShaderManager::use(kShader::TextureAlphaSep); ui::ShaderManager::u_int(kShaderUniform::Tex, 0); ui::ShaderManager::u_int(kShaderUniform::TexA, 1); ui::ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index].m_opacity); @@ -899,8 +899,8 @@ void ui::Canvas::resize(int width, int height) for (int i = 0; i < 6; i++) { #if __IOS__ - m_tmp[i].create(width, height, -1, GL_RGBA16F); - m_tex[i].create(width, height, GL_RGBA16F); + m_tmp[i].create(width, height, -1, GL_RGBA8); + m_tex[i].create(width, height, GL_RGBA8); #else m_tmp[i].create(width, height, -1, GL_RGBA32F); m_tex[i].create(width, height, GL_RGBA32F); @@ -919,8 +919,8 @@ bool ui::Canvas::create(int width, int height) for (int i = 0; i < 6; i++) { #if __IOS__ - m_tmp[i].create(width, height, -1, GL_RGBA16F); - m_tex[i].create(width, height, GL_RGBA16F); + m_tmp[i].create(width, height, -1, GL_RGBA8); + m_tex[i].create(width, height, GL_RGBA8); #else m_tmp[i].create(width, height, -1, GL_RGBA32F); m_tex[i].create(width, height, GL_RGBA32F); diff --git a/engine/image.cpp b/engine/image.cpp index 416b074..b62531c 100644 --- a/engine/image.cpp +++ b/engine/image.cpp @@ -55,14 +55,13 @@ ui::Image ui::Image::resize(int w, int h) auto pixels = (glm::u8vec4*)data(); float x_ratio = ((float)(width - 1)) / w; float y_ratio = ((float)(height - 1)) / h; - float x_diff, y_diff, ya, yb; int offset = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int x = (int)(x_ratio * j); int y = (int)(y_ratio * i); - x_diff = (x_ratio * j) - x; - y_diff = (y_ratio * i) - y; + float x_diff = (x_ratio * j) - x; + float y_diff = (y_ratio * i) - y; int index = y * width + x; // range is 0 to 255 thus bitwise AND with 0xff diff --git a/engine/node_canvas.cpp b/engine/node_canvas.cpp index 2a8d085..873bd6a 100644 --- a/engine/node_canvas.cpp +++ b/engine/node_canvas.cpp @@ -201,7 +201,7 @@ void NodeCanvas::draw() { m_sampler.bind(0); m_sampler_linear.bind(1); - ui::ShaderManager::use(kShader::TextureAlpha); + ui::ShaderManager::use(kShader::TextureAlphaSep); ui::ShaderManager::u_int(kShaderUniform::Tex, 0); ui::ShaderManager::u_int(kShaderUniform::TexA, 1); ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index].m_opacity); diff --git a/engine/node_panel_grid.cpp b/engine/node_panel_grid.cpp index ba4bfeb..be0d3e9 100644 --- a/engine/node_panel_grid.cpp +++ b/engine/node_panel_grid.cpp @@ -50,14 +50,16 @@ void NodePanelGrid::init_controls() m_hm_load->on_click = [this](Node*) { App::I.pick_image([this](std::string path) { ui::Image img; - img.load(path); - m_hm_image = img.resize(128, 128); - m_hm_preview->tex.create(m_hm_image); - m_hm_preview->tex.create_mipmaps(); - auto sz = m_hm_preview->tex.size(); - m_hm_preview->SetAspectRatio(sz.x / sz.y); - m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value()); - m_hm_preview->SetHeight(100); + if (img.load_file(path)) + { + m_hm_image = img.resize(128, 128); + m_hm_preview->tex.create(m_hm_image); + m_hm_preview->tex.create_mipmaps(); + auto sz = m_hm_preview->tex.size(); + m_hm_preview->SetAspectRatio(sz.x / sz.y); + m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value()); + m_hm_preview->SetHeight(100); + } }); }; } diff --git a/engine/shader.h b/engine/shader.h index 7bbc91d..9097959 100644 --- a/engine/shader.h +++ b/engine/shader.h @@ -40,6 +40,7 @@ enum class kShader : uint16_t ColorHue = const_hash("color-hue"), Texture = const_hash("texture"), TextureAlpha= const_hash("texture-alpha"), + TextureAlphaSep= const_hash("texture-alpha-sep"), CompErase = const_hash("comp-erase"), CompDraw = const_hash("comp-draw"), UVs = const_hash("uvs"),