separate shaders, RGBA16F doesn’t work with picking in iOS

This commit is contained in:
2018-08-08 11:09:35 +02:00
parent f941fc4254
commit 9cccecd381
7 changed files with 45 additions and 17 deletions

View File

@@ -234,6 +234,9 @@
ADD7D2AF1EBFA35F00D5A897 /* libcurl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2AE1EBFA35F00D5A897 /* libcurl.a */; }; ADD7D2AF1EBFA35F00D5A897 /* libcurl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2AE1EBFA35F00D5A897 /* libcurl.a */; };
ADD7D2B11EBFA42600D5A897 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2B01EBFA42600D5A897 /* libz.tbd */; }; ADD7D2B11EBFA42600D5A897 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2B01EBFA42600D5A897 /* libz.tbd */; };
ADD7D2B31EBFA42C00D5A897 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2B21EBFA42C00D5A897 /* Security.framework */; }; 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 */; }; ADE491161F86E65D00FB8E92 /* advancing_front.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491121F86D09100FB8E92 /* advancing_front.cc */; };
ADE491171F86E65D00FB8E92 /* cdt.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491151F86D09100FB8E92 /* cdt.cc */; }; ADE491171F86E65D00FB8E92 /* cdt.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491151F86D09100FB8E92 /* cdt.cc */; };
ADE491181F86E65D00FB8E92 /* shapes.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491111F86D09100FB8E92 /* shapes.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 = "<group>"; }; 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 = "<group>"; };
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; }; 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; }; 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 = "<group>"; };
ADE22BE4211904AA00D5F44B /* node_panel_grid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = node_panel_grid.h; sourceTree = "<group>"; };
ADE491111F86D09100FB8E92 /* shapes.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = shapes.cc; path = libs/poly2tri/poly2tri/common/shapes.cc; sourceTree = "<group>"; }; ADE491111F86D09100FB8E92 /* shapes.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = shapes.cc; path = libs/poly2tri/poly2tri/common/shapes.cc; sourceTree = "<group>"; };
ADE491121F86D09100FB8E92 /* advancing_front.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = advancing_front.cc; path = libs/poly2tri/poly2tri/sweep/advancing_front.cc; sourceTree = "<group>"; }; ADE491121F86D09100FB8E92 /* advancing_front.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = advancing_front.cc; path = libs/poly2tri/poly2tri/sweep/advancing_front.cc; sourceTree = "<group>"; };
ADE491131F86D09100FB8E92 /* sweep.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = sweep.cc; path = libs/poly2tri/poly2tri/sweep/sweep.cc; sourceTree = "<group>"; }; ADE491131F86D09100FB8E92 /* sweep.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = sweep.cc; path = libs/poly2tri/poly2tri/sweep/sweep.cc; sourceTree = "<group>"; };
@@ -634,6 +639,8 @@
AD1063681EC7ADFA002A525F /* node_panel_brush.h */, AD1063681EC7ADFA002A525F /* node_panel_brush.h */,
AD1063691EC7ADFA002A525F /* node_panel_color.cpp */, AD1063691EC7ADFA002A525F /* node_panel_color.cpp */,
AD10636A1EC7ADFA002A525F /* node_panel_color.h */, AD10636A1EC7ADFA002A525F /* node_panel_color.h */,
ADE22BE3211904AA00D5F44B /* node_panel_grid.cpp */,
ADE22BE4211904AA00D5F44B /* node_panel_grid.h */,
AD10636B1EC7ADFA002A525F /* node_panel_layer.cpp */, AD10636B1EC7ADFA002A525F /* node_panel_layer.cpp */,
AD10636C1EC7ADFA002A525F /* node_panel_layer.h */, AD10636C1EC7ADFA002A525F /* node_panel_layer.h */,
AD10636D1EC7ADFA002A525F /* node_panel_stroke.cpp */, AD10636D1EC7ADFA002A525F /* node_panel_stroke.cpp */,
@@ -1045,6 +1052,7 @@
AD0E5CA31ECC6F2B00C35669 /* main.cpp in Sources */, AD0E5CA31ECC6F2B00C35669 /* main.cpp in Sources */,
AD0E5CB21ECC72AD00C35669 /* jpge.cpp in Sources */, AD0E5CB21ECC72AD00C35669 /* jpge.cpp in Sources */,
ADC6F4681F3E66FB004177FA /* app_dialogs.cpp in Sources */, ADC6F4681F3E66FB004177FA /* app_dialogs.cpp in Sources */,
ADE22BE7211904AB00D5F44B /* node_panel_grid.cpp in Sources */,
AD0E5CD21ECC72AD00C35669 /* app_events.cpp in Sources */, AD0E5CD21ECC72AD00C35669 /* app_events.cpp in Sources */,
AD0E5CD11ECC72AD00C35669 /* app.cpp in Sources */, AD0E5CD11ECC72AD00C35669 /* app.cpp in Sources */,
AD0E5CC21ECC72AD00C35669 /* node_image.cpp in Sources */, AD0E5CC21ECC72AD00C35669 /* node_image.cpp in Sources */,
@@ -1165,6 +1173,7 @@
ADBC8C4A1FAE7CC40094B339 /* node_dialog_browse.cpp in Sources */, ADBC8C4A1FAE7CC40094B339 /* node_dialog_browse.cpp in Sources */,
AD1063871EC7ADFA002A525F /* node_image_texture.cpp in Sources */, AD1063871EC7ADFA002A525F /* node_image_texture.cpp in Sources */,
AD1063941EC7ADFA002A525F /* node_viewport.cpp in Sources */, AD1063941EC7ADFA002A525F /* node_viewport.cpp in Sources */,
ADE22BE5211904AB00D5F44B /* node_panel_grid.cpp in Sources */,
AD8CF7211E913F0500083FFD /* log.cpp in Sources */, AD8CF7211E913F0500083FFD /* log.cpp in Sources */,
AD95AEC71E41EDEC002DD03A /* pch.cpp in Sources */, AD95AEC71E41EDEC002DD03A /* pch.cpp in Sources */,
AD1063861EC7ADFA002A525F /* node_icon.cpp in Sources */, AD1063861EC7ADFA002A525F /* node_icon.cpp in Sources */,
@@ -1227,6 +1236,7 @@
AD0E119D1ECA215600CDA6BB /* app_layout.cpp in Sources */, AD0E119D1ECA215600CDA6BB /* app_layout.cpp in Sources */,
AD1063991EC7AE92002A525F /* node_button.cpp in Sources */, AD1063991EC7AE92002A525F /* node_button.cpp in Sources */,
ADD7D2931EBF9E1C00D5A897 /* log.cpp in Sources */, ADD7D2931EBF9E1C00D5A897 /* log.cpp in Sources */,
ADE22BE6211904AB00D5F44B /* node_panel_grid.cpp in Sources */,
ADD7D2971EBF9E1C00D5A897 /* canvas.cpp in Sources */, ADD7D2971EBF9E1C00D5A897 /* canvas.cpp in Sources */,
AD1063AC1EC7AE92002A525F /* node_viewport.cpp in Sources */, AD1063AC1EC7AE92002A525F /* node_viewport.cpp in Sources */,
ADD7D2991EBF9E1C00D5A897 /* font.cpp in Sources */, ADD7D2991EBF9E1C00D5A897 /* font.cpp in Sources */,

View File

@@ -35,6 +35,20 @@ void App::initShaders()
"}"; "}";
// TEXTURE ALPHA // TEXTURE ALPHA
static const char* shader_alpha_f = 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 SHADER_VERSION
"uniform sampler2D tex;\n" "uniform sampler2D tex;\n"
"uniform sampler2D tex_alpha;\n" "uniform sampler2D tex_alpha;\n"
@@ -479,6 +493,8 @@ void App::initShaders()
LOG("Failed to create shader Texture"); LOG("Failed to create shader Texture");
if (!ShaderManager::create(kShader::TextureAlpha, shader_v, shader_alpha_f)) if (!ShaderManager::create(kShader::TextureAlpha, shader_v, shader_alpha_f))
LOG("Failed to create shader TextureAlpha"); 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)) if (!ShaderManager::create(kShader::StrokePreview, shader_v, shader_stroke_preview_f))
LOG("Failed to create shader StrokePreview"); LOG("Failed to create shader StrokePreview");
if (!ShaderManager::create(kShader::CompErase, shader_v, shader_comp_erase_f)) if (!ShaderManager::create(kShader::CompErase, shader_v, shader_comp_erase_f))

View File

@@ -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] * m_plane_transform[plane_index] *
glm::translate(glm::vec3(0, 0, -1)); 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::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexA, 1); ui::ShaderManager::u_int(kShaderUniform::TexA, 1);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index].m_opacity); 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++) for (int i = 0; i < 6; i++)
{ {
#if __IOS__ #if __IOS__
m_tmp[i].create(width, height, -1, GL_RGBA16F); m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA16F); m_tex[i].create(width, height, GL_RGBA8);
#else #else
m_tmp[i].create(width, height, -1, GL_RGBA32F); m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, 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++) for (int i = 0; i < 6; i++)
{ {
#if __IOS__ #if __IOS__
m_tmp[i].create(width, height, -1, GL_RGBA16F); m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA16F); m_tex[i].create(width, height, GL_RGBA8);
#else #else
m_tmp[i].create(width, height, -1, GL_RGBA32F); m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, GL_RGBA32F); m_tex[i].create(width, height, GL_RGBA32F);

View File

@@ -55,14 +55,13 @@ ui::Image ui::Image::resize(int w, int h)
auto pixels = (glm::u8vec4*)data(); auto pixels = (glm::u8vec4*)data();
float x_ratio = ((float)(width - 1)) / w; float x_ratio = ((float)(width - 1)) / w;
float y_ratio = ((float)(height - 1)) / h; float y_ratio = ((float)(height - 1)) / h;
float x_diff, y_diff, ya, yb;
int offset = 0; int offset = 0;
for (int i = 0; i < h; i++) { for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) { for (int j = 0; j < w; j++) {
int x = (int)(x_ratio * j); int x = (int)(x_ratio * j);
int y = (int)(y_ratio * i); int y = (int)(y_ratio * i);
x_diff = (x_ratio * j) - x; float x_diff = (x_ratio * j) - x;
y_diff = (y_ratio * i) - y; float y_diff = (y_ratio * i) - y;
int index = y * width + x; int index = y * width + x;
// range is 0 to 255 thus bitwise AND with 0xff // range is 0 to 255 thus bitwise AND with 0xff

View File

@@ -201,7 +201,7 @@ void NodeCanvas::draw()
{ {
m_sampler.bind(0); m_sampler.bind(0);
m_sampler_linear.bind(1); 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::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexA, 1); ui::ShaderManager::u_int(kShaderUniform::TexA, 1);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index].m_opacity); ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index].m_opacity);

View File

@@ -50,14 +50,16 @@ void NodePanelGrid::init_controls()
m_hm_load->on_click = [this](Node*) { m_hm_load->on_click = [this](Node*) {
App::I.pick_image([this](std::string path) { App::I.pick_image([this](std::string path) {
ui::Image img; ui::Image img;
img.load(path); if (img.load_file(path))
m_hm_image = img.resize(128, 128); {
m_hm_preview->tex.create(m_hm_image); m_hm_image = img.resize(128, 128);
m_hm_preview->tex.create_mipmaps(); m_hm_preview->tex.create(m_hm_image);
auto sz = m_hm_preview->tex.size(); m_hm_preview->tex.create_mipmaps();
m_hm_preview->SetAspectRatio(sz.x / sz.y); auto sz = m_hm_preview->tex.size();
m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value()); m_hm_preview->SetAspectRatio(sz.x / sz.y);
m_hm_preview->SetHeight(100); m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value());
m_hm_preview->SetHeight(100);
}
}); });
}; };
} }

View File

@@ -40,6 +40,7 @@ enum class kShader : uint16_t
ColorHue = const_hash("color-hue"), ColorHue = const_hash("color-hue"),
Texture = const_hash("texture"), Texture = const_hash("texture"),
TextureAlpha= const_hash("texture-alpha"), TextureAlpha= const_hash("texture-alpha"),
TextureAlphaSep= const_hash("texture-alpha-sep"),
CompErase = const_hash("comp-erase"), CompErase = const_hash("comp-erase"),
CompDraw = const_hash("comp-draw"), CompDraw = const_hash("comp-draw"),
UVs = const_hash("uvs"), UVs = const_hash("uvs"),