diff --git a/android/build.gradle b/android/build.gradle index 86fbb16..3550bca 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -10,7 +10,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.3.0' classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5" } } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index cb2d279..bc4fc72 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 01 13:12:48 BST 2017 +#Mon Jan 28 10:43:43 CET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip diff --git a/src/node_panel_brush.cpp b/src/node_panel_brush.cpp index 966f38b..8599ba6 100644 --- a/src/node_panel_brush.cpp +++ b/src/node_panel_brush.cpp @@ -196,6 +196,7 @@ void NodePanelBrushPreset::init() //brush->m_brush->m_tip_size = .05f; brush->m_preview->m_brush = brush->m_brush; brush->m_preview->draw_stroke(); + brush->m_thumb->m_use_mipmaps = true; brush->m_thumb->set_image(brush->m_brush->m_brush_thumb_path); brush->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1); save(); diff --git a/src/node_panel_grid.cpp b/src/node_panel_grid.cpp index ad2e98a..cfda8df 100644 --- a/src/node_panel_grid.cpp +++ b/src/node_panel_grid.cpp @@ -4,6 +4,7 @@ #include "canvas.h" #include "app.h" #include "image.h" +#include "util.h" Node* NodePanelGrid::clone_instantiate() const { @@ -388,7 +389,7 @@ void NodePanelGrid::bake_uvs() dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_apply((size_t)fb.getHeight(), queue, ^ (size_t y) #else - for (int y = 0; y < fb.getHeight(); y++) + parallel_for(fb.getHeight(), [&](int y) #endif { for (int x = 0; x < fb.getWidth(); x++) @@ -428,10 +429,7 @@ void NodePanelGrid::bake_uvs() out = glm::lerp(glm::vec4(255, 255, 255, 255), glm::vec4(50, 50, 50, 255), hit / (float)samples); } pb_value++; - } -#if _WIN32 || __IOS__ || __OSX__ - ); -#endif + }); } ); while (pb_value < fb.getHeight()) diff --git a/src/node_panel_stroke.cpp b/src/node_panel_stroke.cpp index 9f57886..dbf62b5 100644 --- a/src/node_panel_stroke.cpp +++ b/src/node_panel_stroke.cpp @@ -82,6 +82,7 @@ void NodePanelStroke::init_controls() Canvas::I->m_current_brush = b; m_preset_thumb = find("preset-thumb"); + m_preset_thumb->m_use_mipmaps = true; m_preset_preview = find("preset-preview"); m_preset_preview->m_brush = b; m_preset_preview->draw_stroke(); @@ -118,12 +119,17 @@ void NodePanelStroke::init_controls() m_brush_button = find("tip-change"); m_brush_button->on_click = [this](Node*) { + auto screen = root()->m_size; glm::vec2 pos = m_brush_button->m_pos + glm::vec2(m_brush_button->m_size.x, 0); root()->add_child(m_brush_popup); + root()->update(); + if ((pos.y + m_brush_popup->m_size.y) > screen.y) pos.y = screen.y - m_brush_popup->m_size.y; + if (pos.y < 0) pos.y = 0; m_brush_popup->SetPosition(pos.x, pos.y); m_brush_popup->mouse_capture(); root()->update(); + m_brush_popup->on_brush_changed = [this](Node*, int index) { if (on_brush_changed) on_brush_changed(this, m_brush_popup->get_texture_path(index), m_brush_popup->get_thumb_path(index)); diff --git a/src/texture.cpp b/src/texture.cpp index a91c329..503f0eb 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -9,13 +9,14 @@ std::map TextureManager::m_textures; bool TextureManager::load(const char* path, bool generate_mipmaps) { uint16_t id = const_hash(path); - if (m_textures.count(id) == 0 || !m_textures[id].ready()) + auto t = m_textures.find(id); + if (t == m_textures.end() || !m_textures[id].ready()) { if (!m_textures[id].load(path)) return false; - if (generate_mipmaps) - m_textures[id].create_mipmaps(); } + if (generate_mipmaps && !m_textures[id].has_mips) + m_textures[id].create_mipmaps(); return true; } diff --git a/src/util.cpp b/src/util.cpp index 5a8988b..4c63df4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -362,3 +362,58 @@ size_t curl_data_write(void *ptr, size_t size, size_t nmemb, FILE *stream) size_t written = fwrite(ptr, size, nmemb, stream); return written; } + +/// @param[in] nb_elements : size of your for loop +/// @param[in] functor(start, end) : +/// your function processing a sub chunk of the for loop. +/// "start" is the first index to process (included) until the index "end" +/// (excluded) +/// @code +/// for(int i = start; i < end; ++i) +/// computation(i); +/// @endcode +/// @param use_threads : enable / disable threads. +/// +/// +void parallel_for(unsigned nb_elements, std::function functor, bool use_threads) +{ + // ------- + unsigned nb_threads_hint = std::thread::hardware_concurrency(); + unsigned nb_threads = nb_threads_hint == 0 ? 8 : (nb_threads_hint); + + unsigned batch_size = nb_elements / nb_threads; + unsigned batch_remainder = nb_elements % nb_threads; + + std::vector< std::thread > my_threads(nb_threads); + + if (use_threads) + { + // Multithread execution + for (unsigned i = 0; i < nb_threads; ++i) + { + int start = i * batch_size; + my_threads[i] = std::thread([functor, start, batch_size]() { + for (int j = start; j < start + batch_size; j++) + functor(j); + }); + } + } + else + { + // Single thread execution (for easy debugging) + for (unsigned i = 0; i < nb_threads; ++i) { + int start = i * batch_size; + for (int j = start; j < start + batch_size; j++) + functor(j); + } + } + + // Deform the elements left + int start = nb_threads * batch_size; + for (int j = start; j < start + batch_remainder; j++) + functor(j); + + // Wait for the other thread to finish their task + if (use_threads) + std::for_each(my_threads.begin(), my_threads.end(), std::mem_fn(&std::thread::join)); +} \ No newline at end of file diff --git a/src/util.h b/src/util.h index 7228899..5d67608 100644 --- a/src/util.h +++ b/src/util.h @@ -75,6 +75,8 @@ inline glm::ivec3 xyz(const glm::ivec4& v) { return glm::ivec3(v.x, v.y, v.z); } inline glm::ivec2 zw(const glm::ivec4& v) { return glm::ivec2(v.z, v.w); } inline glm::vec2 xy(const glm::vec3& v) { return glm::vec2(v.x, v.y); } +void parallel_for(unsigned nb_elements, std::function functor, bool use_threads = true); + template struct cbuffer { T m_vec[N];