update gradle project, parallel for-loop based on std::thread on android, fix mipmaps on TextureManager
This commit is contained in:
@@ -10,7 +10,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
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"
|
classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#Mon May 01 13:12:48 BST 2017
|
#Mon Jan 28 10:43:43 CET 2019
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ void NodePanelBrushPreset::init()
|
|||||||
//brush->m_brush->m_tip_size = .05f;
|
//brush->m_brush->m_tip_size = .05f;
|
||||||
brush->m_preview->m_brush = brush->m_brush;
|
brush->m_preview->m_brush = brush->m_brush;
|
||||||
brush->m_preview->draw_stroke();
|
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->m_thumb->set_image(brush->m_brush->m_brush_thumb_path);
|
||||||
brush->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
|
brush->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
|
||||||
save();
|
save();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "canvas.h"
|
#include "canvas.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
Node* NodePanelGrid::clone_instantiate() const
|
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_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||||
dispatch_apply((size_t)fb.getHeight(), queue, ^ (size_t y)
|
dispatch_apply((size_t)fb.getHeight(), queue, ^ (size_t y)
|
||||||
#else
|
#else
|
||||||
for (int y = 0; y < fb.getHeight(); y++)
|
parallel_for(fb.getHeight(), [&](int y)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
for (int x = 0; x < fb.getWidth(); x++)
|
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);
|
out = glm::lerp(glm::vec4(255, 255, 255, 255), glm::vec4(50, 50, 50, 255), hit / (float)samples);
|
||||||
}
|
}
|
||||||
pb_value++;
|
pb_value++;
|
||||||
}
|
});
|
||||||
#if _WIN32 || __IOS__ || __OSX__
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
while (pb_value < fb.getHeight())
|
while (pb_value < fb.getHeight())
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ void NodePanelStroke::init_controls()
|
|||||||
Canvas::I->m_current_brush = b;
|
Canvas::I->m_current_brush = b;
|
||||||
|
|
||||||
m_preset_thumb = find<NodeImage>("preset-thumb");
|
m_preset_thumb = find<NodeImage>("preset-thumb");
|
||||||
|
m_preset_thumb->m_use_mipmaps = true;
|
||||||
m_preset_preview = find<NodeStrokePreview>("preset-preview");
|
m_preset_preview = find<NodeStrokePreview>("preset-preview");
|
||||||
m_preset_preview->m_brush = b;
|
m_preset_preview->m_brush = b;
|
||||||
m_preset_preview->draw_stroke();
|
m_preset_preview->draw_stroke();
|
||||||
@@ -118,12 +119,17 @@ void NodePanelStroke::init_controls()
|
|||||||
|
|
||||||
m_brush_button = find<NodeButtonCustom>("tip-change");
|
m_brush_button = find<NodeButtonCustom>("tip-change");
|
||||||
m_brush_button->on_click = [this](Node*) {
|
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);
|
glm::vec2 pos = m_brush_button->m_pos + glm::vec2(m_brush_button->m_size.x, 0);
|
||||||
root()->add_child(m_brush_popup);
|
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->SetPosition(pos.x, pos.y);
|
||||||
m_brush_popup->mouse_capture();
|
m_brush_popup->mouse_capture();
|
||||||
root()->update();
|
root()->update();
|
||||||
|
|
||||||
|
|
||||||
m_brush_popup->on_brush_changed = [this](Node*, int index) {
|
m_brush_popup->on_brush_changed = [this](Node*, int index) {
|
||||||
if (on_brush_changed)
|
if (on_brush_changed)
|
||||||
on_brush_changed(this, m_brush_popup->get_texture_path(index), m_brush_popup->get_thumb_path(index));
|
on_brush_changed(this, m_brush_popup->get_texture_path(index), m_brush_popup->get_thumb_path(index));
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ std::map<uint16_t, Texture2D> TextureManager::m_textures;
|
|||||||
bool TextureManager::load(const char* path, bool generate_mipmaps)
|
bool TextureManager::load(const char* path, bool generate_mipmaps)
|
||||||
{
|
{
|
||||||
uint16_t id = const_hash(path);
|
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))
|
if (!m_textures[id].load(path))
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
55
src/util.cpp
55
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);
|
size_t written = fwrite(ptr, size, nmemb, stream);
|
||||||
return written;
|
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<void(int i)> 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));
|
||||||
|
}
|
||||||
@@ -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::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); }
|
inline glm::vec2 xy(const glm::vec3& v) { return glm::vec2(v.x, v.y); }
|
||||||
|
|
||||||
|
void parallel_for(unsigned nb_elements, std::function<void(int i)> functor, bool use_threads = true);
|
||||||
|
|
||||||
template<typename T, int N> struct cbuffer
|
template<typename T, int N> struct cbuffer
|
||||||
{
|
{
|
||||||
T m_vec[N];
|
T m_vec[N];
|
||||||
|
|||||||
Reference in New Issue
Block a user