update color at picking and cleanup code from some warnings

This commit is contained in:
2019-03-11 15:35:59 +01:00
parent 373e7ad0e9
commit fda399f7dd
16 changed files with 56 additions and 63 deletions

View File

@@ -92,7 +92,7 @@ bool ABR::section_patt()
int nc = std::min((int)vm->channels.size(), 3); int nc = std::min((int)vm->channels.size(), 3);
if (nc != image_mode) if (nc != image_mode)
{ {
LOG("PATT: image_mode (%d) and number of channels (%d) not matching\n", LOG("PATT: image_mode (%d) and number of channels (%ld) not matching\n",
image_mode, vm->channels.size()); image_mode, vm->channels.size());
} }
if (auto img = vm->image(true, false)) if (auto img = vm->image(true, false))
@@ -271,7 +271,7 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
std::string blend_mode = p->value<Enum>("textureBlendMode"); std::string blend_mode = p->value<Enum>("textureBlendMode");
auto bm_it = std::find(modes.begin(), modes.end(), blend_mode); auto bm_it = std::find(modes.begin(), modes.end(), blend_mode);
if (bm_it != modes.end()) if (bm_it != modes.end())
b->m_pattern_blend_mode = std::distance(modes.begin(), bm_it); b->m_pattern_blend_mode = (int)std::distance(modes.begin(), bm_it);
b->m_pattern_enabled = p->value<Boolean>("useTexture"); b->m_pattern_enabled = p->value<Boolean>("useTexture");
} }
@@ -342,7 +342,7 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
std::string blend_mode = db->value<Enum>("BlnM"); std::string blend_mode = db->value<Enum>("BlnM");
auto bm_it = std::find(modes.begin(), modes.end(), blend_mode); auto bm_it = std::find(modes.begin(), modes.end(), blend_mode);
if (bm_it != modes.end()) if (bm_it != modes.end())
b->m_dual_blend_mode = std::distance(modes.begin(), bm_it); b->m_dual_blend_mode = (int)std::distance(modes.begin(), bm_it);
b->m_dual_enabled = db->value<Boolean>("useDualBrush"); b->m_dual_enabled = db->value<Boolean>("useDualBrush");
} }

View File

@@ -726,7 +726,7 @@ int App::res_from_index(int i)
int App::res_to_index(int res) int App::res_to_index(int res)
{ {
return std::distance(res_map.begin(), std::find(res_map.begin(), res_map.end(), res)); return (int)std::distance(res_map.begin(), std::find(res_map.begin(), res_map.end(), res));
} }
std::string App::res_to_string(int res) std::string App::res_to_string(int res)

View File

@@ -871,7 +871,7 @@ void App::init_menu_layer()
popup->find<NodeButtonCustom>("layer-merge")->on_click = [this, popup](Node*) { popup->find<NodeButtonCustom>("layer-merge")->on_click = [this, popup](Node*) {
const auto& order = canvas->m_canvas->m_order; const auto& order = canvas->m_canvas->m_order;
//layers->get_child_index(layers->) //layers->get_child_index(layers->)
int current_idx_order = std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx)); int current_idx_order = (int)std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx));
if (current_idx_order > 0) if (current_idx_order > 0)
{ {
int dest_layer_idx = order[current_idx_order - 1]; int dest_layer_idx = order[current_idx_order - 1];
@@ -891,7 +891,7 @@ void App::init_menu_layer()
if (layers->m_current_layer) if (layers->m_current_layer)
{ {
const auto& order = canvas->m_canvas->m_order; const auto& order = canvas->m_canvas->m_order;
int current_idx_order = std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx)); int current_idx_order = (int)std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx));
if (current_idx_order > 0) if (current_idx_order > 0)
{ {
int down_layer_idx = order[current_idx_order - 1]; int down_layer_idx = order[current_idx_order - 1];

View File

@@ -230,7 +230,7 @@ void Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz)
!m_layers[layer_index]->m_dirty_face[plane_index]) !m_layers[layer_index]->m_dirty_face[plane_index])
continue; continue;
glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)m_mixer.getWidth() / m_mixer.getHeight(), 0.1f, 1000.f); //glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)m_mixer.getWidth() / m_mixer.getHeight(), 0.1f, 1000.f);
auto plane_mvp_z = auto plane_mvp_z =
glm::scale(glm::vec3(1, -1, 1)) * glm::scale(glm::vec3(1, -1, 1)) *
m_proj * m_mv * m_proj * m_mv *
@@ -379,12 +379,12 @@ glm::vec4 Canvas::stroke_draw_samples(int i, std::vector<vertex_t>& P)
} }
else if (P.size() == 3) else if (P.size() == 3)
{ {
m_brush_shape.update_vertices(P.data(), P.size()); m_brush_shape.update_vertices(P.data(), (int)P.size());
} }
else else
{ {
P = triangulate_simple(P); P = triangulate_simple(P);
m_brush_shape.update_vertices(P.data(), P.size()); m_brush_shape.update_vertices(P.data(), (int)P.size());
} }
m_brush_shape.draw_fill(); m_brush_shape.draw_fill();
@@ -643,18 +643,8 @@ bool Canvas::point_trace_plane(glm::vec2 loc, glm::vec3& hit_pos, glm::vec2& hit
bool Canvas::point_trace_plane(glm::vec2 loc, glm::vec3& ray_origin, glm::vec3& ray_dir, bool Canvas::point_trace_plane(glm::vec2 loc, glm::vec3& ray_origin, glm::vec3& ray_dir,
glm::vec3& hit_pos, glm::vec3& hit_normal, glm::vec2& hit_fb_pos, int plane_id) glm::vec3& hit_pos, glm::vec3& hit_normal, glm::vec2& hit_fb_pos, int plane_id)
{ {
/*
auto ln = (loc / zw(m_box)) * 2.f - 1.f;
auto p = m_plane_unproject[plane_id] * glm::vec4(ln, 1, 1);
if (p.w <= 0)
{
return true;
}
*/
point_unproject(loc, { 0, 0, zw(m_box) }, m_mv, m_proj, ray_origin, ray_dir); point_unproject(loc, { 0, 0, zw(m_box) }, m_mv, m_proj, ray_origin, ray_dir);
glm::vec3 hit; glm::vec3 hit;
glm::vec2 fb_pos;
float hit_t; float hit_t;
if (ray_intersect(ray_origin, ray_dir, m_plane_origin[plane_id], if (ray_intersect(ray_origin, ray_dir, m_plane_origin[plane_id],
m_plane_normal[plane_id], m_plane_tangent[plane_id], hit, hit_t)) m_plane_normal[plane_id], m_plane_tangent[plane_id], hit, hit_t))
@@ -1590,7 +1580,7 @@ void Canvas::export_layers_thread(std::string file_name)
App::I.async_update(); App::I.async_update();
} }
int progress = 0; int progress = 0;
int total = (m_order.size() + 1) * 6; int total = (int)(m_order.size() + 1) * 6;
// prepare common states // prepare common states
glViewport(0, 0, m_width, m_height); glViewport(0, 0, m_width, m_height);

View File

@@ -70,7 +70,7 @@ public:
} }
} }
} }
glm::vec2 bbsz = bbmax - bbmin; //glm::vec2 bbsz = bbmax - bbmin;
} }
} }
}; };

View File

@@ -84,12 +84,16 @@ void CanvasModeBasicCamera::on_GestureEvent(GestureEvent* ge)
m_camera_fov = Canvas::I->m_cam_fov; m_camera_fov = Canvas::I->m_cam_fov;
break; break;
case kEventType::GestureMove: case kEventType::GestureMove:
{
Canvas::I->m_pan = m_pan_start + ge->m_pos_delta * glm::vec2(-1, -1) * 0.3f * (Canvas::I->m_cam_fov / 85.f); Canvas::I->m_pan = m_pan_start + ge->m_pos_delta * glm::vec2(-1, -1) * 0.3f * (Canvas::I->m_cam_fov / 85.f);
Canvas::I->m_cam_fov = m_camera_fov - ge->m_distance_delta * .05f; Canvas::I->m_cam_fov = m_camera_fov - ge->m_distance_delta * .05f;
auto angle = Canvas::I->m_pan * 0.003f; auto angle = Canvas::I->m_pan * 0.003f;
Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x); Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
App::I.brush_update(); App::I.brush_update();
break; break;
}
default:
break;
} }
} }
@@ -127,7 +131,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
Canvas::I->pick_start(); Canvas::I->pick_start();
glm::vec4 pix = Canvas::I->pick_get(loc); glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix; Canvas::I->m_current_brush->m_tip_color = pix;
App::I.color->set_color(pix); App::I.brush_update();
} }
else else
{ {
@@ -147,7 +151,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
node->mouse_release(); node->mouse_release();
glm::vec4 pix = Canvas::I->pick_get(loc); glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix; Canvas::I->m_current_brush->m_tip_color = pix;
App::I.color->set_color(pix); App::I.brush_update();
Canvas::I->pick_end(); Canvas::I->pick_end();
} }
m_dragging = false; m_dragging = false;
@@ -179,7 +183,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{ {
glm::vec4 pix = Canvas::I->pick_get(loc); glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix; Canvas::I->m_current_brush->m_tip_color = pix;
App::I.color->set_color(pix); App::I.brush_update();
} }
if (m_dragging && m_resizing) if (m_dragging && m_resizing)
{ {
@@ -1017,7 +1021,7 @@ void CanvasModeTransform::enter(kCanvasMode prev)
vertex_t(corners[3], { 0, 1 }), vertex_t(corners[3], { 0, 1 }),
}); });
auto shape3d = triangulate(m_points_face[0]); auto shape3d = triangulate(m_points_face[0]);
m_shape[0].update_vertices(shape3d.data(), shape3d.size()); m_shape[0].update_vertices(shape3d.data(), (int)shape3d.size());
m_commit_on_leave = true; m_commit_on_leave = true;
@@ -1123,7 +1127,7 @@ void CanvasModeTransform::enter(kCanvasMode prev)
} }
auto shape3d = triangulate(m_points_face[plane]); auto shape3d = triangulate(m_points_face[plane]);
m_shape[plane].update_vertices(shape3d.data(), shape3d.size()); m_shape[plane].update_vertices(shape3d.data(), (int)shape3d.size());
Canvas::I->m_layers[Canvas::I->m_current_layer_idx]->m_rtt[plane].bindFramebuffer(); Canvas::I->m_layers[Canvas::I->m_current_layer_idx]->m_rtt[plane].bindFramebuffer();
m_tex[plane].create(bb_sz.x, bb_sz.y); m_tex[plane].create(bb_sz.x, bb_sz.y);

View File

@@ -30,7 +30,6 @@ void NodeComboBox::loaded()
popup->loaded(); popup->loaded();
root()->add_child(popup); root()->add_child(popup);
m_items.clear(); m_items.clear();
int real_index = 0;
for (int i = 0; i < m_data.size(); i++) for (int i = 0; i < m_data.size(); i++)
{ {
if (m_data[i] == "-") if (m_data[i] == "-")

View File

@@ -128,7 +128,7 @@ void NodeDialogCloud::load_thumbs_thread()
break; break;
res.clear(); res.clear();
char* url_escaped = curl_easy_escape(curl, n.c_str(), n.size()); char* url_escaped = curl_easy_escape(curl, n.c_str(), (int)n.size());
std::string url = std::string("https://panopainter.com/cloud/cloud-info.php?file=") + url_escaped; std::string url = std::string("https://panopainter.com/cloud/cloud-info.php?file=") + url_escaped;
delete url_escaped; delete url_escaped;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

View File

@@ -298,7 +298,7 @@ bool NodePanelBrush::save()
sw.wstring_raw("PPVR"); // magic code sw.wstring_raw("PPVR"); // magic code
sw.wu16(0); // version major sw.wu16(0); // version major
sw.wu16(1); // minor sw.wu16(1); // minor
sw.wu32(m_container->m_children.size()); // number of items sw.wu32((int)m_container->m_children.size()); // number of items
for (const auto& child : m_container->m_children) for (const auto& child : m_container->m_children)
{ {
auto b = std::static_pointer_cast<NodeButtonBrush>(child); auto b = std::static_pointer_cast<NodeButtonBrush>(child);
@@ -331,7 +331,7 @@ bool NodePanelBrush::restore()
auto vmin = sr.ru16(); auto vmin = sr.ru16();
if (vmaj != 0 && vmin != 1) if (vmaj != 0 && vmin != 1)
{ {
LOG("unrecognised version %d.$d", vmaj, vmin); LOG("unrecognised version %d.%d", vmaj, vmin);
return false; return false;
} }
@@ -448,7 +448,7 @@ void NodePanelBrushPreset::init()
} }
else else
{ {
int next = std::min<int>(m_container->m_children.size() - 1, index); int next = std::min<int>((int)m_container->m_children.size() - 1, index);
m_current = (NodeBrushPresetItem*)m_container->m_children[next].get(); m_current = (NodeBrushPresetItem*)m_container->m_children[next].get();
m_current->m_selected = true; m_current->m_selected = true;
} }
@@ -515,7 +515,7 @@ bool NodePanelBrushPreset::save()
sw.wstring_raw("PPVR"); sw.wstring_raw("PPVR");
sw.wu16(0); sw.wu16(0);
sw.wu16(1); sw.wu16(1);
sw.wu32(m_container->m_children.size()); sw.wu32((int)m_container->m_children.size());
for (int ci = 0; ci < m_container->m_children.size(); ci++) for (int ci = 0; ci < m_container->m_children.size(); ci++)
{ {
auto bpi = static_cast<NodeBrushPresetItem*>(m_container->get_child_at(ci)); auto bpi = static_cast<NodeBrushPresetItem*>(m_container->get_child_at(ci));

View File

@@ -414,7 +414,7 @@ void NodePanelGrid::bake_uvs()
{ {
for (int x = 0; x < fb.getWidth(); x++) for (int x = 0; x < fb.getWidth(); x++)
{ {
int i = y * fb.getHeight() + x; int i = (int)y * fb.getHeight() + x;
auto nor = glm::make_vec3(&d_nor[i * 4]); auto nor = glm::make_vec3(&d_nor[i * 4]);
auto pos = glm::make_vec3(&d_pos[i * 4]); auto pos = glm::make_vec3(&d_pos[i * 4]);
auto& out = d_out[i]; auto& out = d_out[i];

View File

@@ -126,7 +126,7 @@ void NodePanelLayer::init()
auto num = m[2].str(); auto num = m[2].str();
int count = atoi(num.c_str()) + 1; int count = atoi(num.c_str()) + 1;
char tmp[128]; char tmp[128];
sprintf(tmp, "%s%0*d", m[1].str().c_str(), num.length(), count); sprintf(tmp, "%s%0*d", m[1].str().c_str(), (int)num.length(), count);
next = tmp; next = tmp;
} }
int source_index = m_layers_container->get_child_index(m_current_layer); int source_index = m_layers_container->get_child_index(m_current_layer);

View File

@@ -48,7 +48,7 @@ bool NodePanelStroke::import_abr(const std::string& path)
abr.open(path); abr.open(path);
int tot = abr.m_samples.size() + abr.m_patterns.size() + abr.m_presets.size(); int tot = (int)(abr.m_samples.size() + abr.m_patterns.size() + abr.m_presets.size());
std::atomic_int count(0); std::atomic_int count(0);
parallel_for(abr.m_samples.size(), [&](size_t i) parallel_for(abr.m_samples.size(), [&](size_t i)

View File

@@ -364,7 +364,7 @@ void NodeStrokePreview::draw_stroke_immediate()
ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 }); ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 });
ShaderManager::u_float(kShaderUniform::Alpha, f.flow); ShaderManager::u_float(kShaderUniform::Alpha, f.flow);
ShaderManager::u_float(kShaderUniform::Opacity, f.opacity); ShaderManager::u_float(kShaderUniform::Opacity, f.opacity);
auto rect = stroke_draw_samples(f.shapes, m_tex_dual); /*auto rect =*/ stroke_draw_samples(f.shapes, m_tex_dual);
} }
// copy raw stroke to tex // copy raw stroke to tex
@@ -404,7 +404,7 @@ void NodeStrokePreview::draw_stroke_immediate()
ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 } /*f.col*/); ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 } /*f.col*/);
ShaderManager::u_float(kShaderUniform::Alpha, glm::max(f.flow, m_min_flow)); ShaderManager::u_float(kShaderUniform::Alpha, glm::max(f.flow, m_min_flow));
ShaderManager::u_float(kShaderUniform::Opacity, f.opacity); ShaderManager::u_float(kShaderUniform::Opacity, f.opacity);
auto rect = stroke_draw_samples(f.shapes, m_tex); /*auto rect =*/ stroke_draw_samples(f.shapes, m_tex);
} }
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE3);
m_rtt_mixer.unbindTexture(); m_rtt_mixer.unbindTexture();
@@ -529,7 +529,7 @@ void NodeStrokePreview::draw()
void NodeStrokePreview::handle_resize(glm::vec2 old_size, glm::vec2 new_size) void NodeStrokePreview::handle_resize(glm::vec2 old_size, glm::vec2 new_size)
{ {
if (m_rtt.getWidth() == new_size.x && m_rtt.getHeight() == new_size.y || !m_brush) if ((m_rtt.getWidth() == new_size.x && m_rtt.getHeight() == new_size.y) || !m_brush)
return; return;
new_size *= root()->m_zoom; new_size *= root()->m_zoom;

View File

@@ -68,7 +68,7 @@ public:
} }
virtual void write(BinaryStreamWriter& w) const override virtual void write(BinaryStreamWriter& w) const override
{ {
w.wi32(items.size()); w.wi32((int)items.size());
for (auto& i : items) for (auto& i : items)
i->write(w); i->write(w);
} }
@@ -412,7 +412,7 @@ public:
{ {
w.wwstring(name); w.wwstring(name);
w.wkey_or_string(class_id); w.wkey_or_string(class_id);
w.wu32(props.size()); w.wu32((int)props.size());
for (auto& p : props) for (auto& p : props)
{ {
w.wkey_or_string(p.first); w.wkey_or_string(p.first);
@@ -518,7 +518,7 @@ public:
auto decoded = r.rrle(sl); auto decoded = r.rrle(sl);
data.insert(data.end(), decoded.begin(), decoded.end()); data.insert(data.end(), decoded.begin(), decoded.end());
} }
auto len = r.pos() - start; //auto len = r.pos() - start;
} }
else else
{ {
@@ -541,7 +541,7 @@ public:
VMArray(uint32_t version, const Rectangle& rect) : version(version), rect(rect) { } VMArray(uint32_t version, const Rectangle& rect) : version(version), rect(rect) { }
std::shared_ptr<Image> image(bool grayscale, bool invert) const std::shared_ptr<Image> image(bool grayscale, bool invert) const
{ {
int nc = channels.size(); int nc = (int)channels.size();
auto pixels = (channels[0].depth >> 3) * rect.area(); auto pixels = (channels[0].depth >> 3) * rect.area();
if (nc == 1 || nc >= 3) if (nc == 1 || nc >= 3)
{ {
@@ -589,7 +589,7 @@ public:
} }
else else
{ {
LOG("Error image with %d channels\n", channels.size()); LOG("Error image with %ld channels\n", channels.size());
} }
return nullptr; return nullptr;
} }

View File

@@ -369,8 +369,8 @@ std::vector<vertex_t> triangulate(const std::vector<vertex_t>& points)
while (node) while (node)
{ {
if (outline.empty() || // if empty insert right away if (outline.empty() || // if empty insert right away
outline.back() != node->a && // insert only if different than the last post (outline.back() != node->a && // insert only if different than the last post
(outline.front() != node->a || !node->end)) // if is the end check against the first one (outline.front() != node->a || !node->end))) // if is the end check against the first one
{ {
outline.push_back(node->a); outline.push_back(node->a);
} }
@@ -438,8 +438,8 @@ glm::vec3 convert_rgb2hsv(const glm::vec3 c)
std::vector<std::string> split(const std::string& subject, char d, int max_split/* = 0*/) std::vector<std::string> split(const std::string& subject, char d, int max_split/* = 0*/)
{ {
std::vector<std::string> ret; std::vector<std::string> ret;
int start = 0; size_t start = 0;
int n = subject.find_first_of(d); size_t n = subject.find_first_of(d);
while (n != std::string::npos) while (n != std::string::npos)
{ {
ret.push_back(subject.substr(start, n - start)); ret.push_back(subject.substr(start, n - start));
@@ -499,10 +499,10 @@ std::string wstr2str(const std::wstring & wstr)
bool str_iequals(const std::string& a, const std::string& b) bool str_iequals(const std::string& a, const std::string& b)
{ {
unsigned int sz = a.size(); size_t sz = a.size();
if (b.size() != sz) if (b.size() != sz)
return false; return false;
for (unsigned int i = 0; i < sz; ++i) for (size_t i = 0; i < sz; ++i)
if (std::tolower(a[i]) != std::tolower(b[i])) if (std::tolower(a[i]) != std::tolower(b[i]))
return false; return false;
return true; return true;
@@ -586,25 +586,25 @@ size_t curl_data_write(void *ptr, size_t size, size_t nmemb, FILE *stream)
/// @param use_threads : enable / disable threads. /// @param use_threads : enable / disable threads.
/// ///
/// ///
void parallel_for(unsigned nb_elements, std::function<void(int i)> functor, bool use_threads) void parallel_for(size_t nb_elements, std::function<void(size_t i)> functor, bool use_threads)
{ {
// ------- // -------
unsigned nb_threads_hint = std::thread::hardware_concurrency(); size_t nb_threads_hint = std::thread::hardware_concurrency();
unsigned nb_threads = nb_threads_hint == 0 ? 8 : (nb_threads_hint); size_t nb_threads = nb_threads_hint == 0 ? 8 : (nb_threads_hint);
unsigned batch_size = nb_elements / nb_threads; size_t batch_size = nb_elements / nb_threads;
unsigned batch_remainder = nb_elements % nb_threads; size_t batch_remainder = nb_elements % nb_threads;
std::vector< std::thread > my_threads(nb_threads); std::vector< std::thread > my_threads(nb_threads);
if (use_threads) if (use_threads)
{ {
// Multithread execution // Multithread execution
for (unsigned i = 0; i < nb_threads; ++i) for (size_t i = 0; i < nb_threads; ++i)
{ {
int start = i * batch_size; size_t start = i * batch_size;
my_threads[i] = std::thread([functor, start, batch_size]() { my_threads[i] = std::thread([functor, start, batch_size]() {
for (int j = start; j < start + batch_size; j++) for (size_t j = start; j < start + batch_size; j++)
functor(j); functor(j);
}); });
} }
@@ -612,16 +612,16 @@ void parallel_for(unsigned nb_elements, std::function<void(int i)> functor, bool
else else
{ {
// Single thread execution (for easy debugging) // Single thread execution (for easy debugging)
for (unsigned i = 0; i < nb_threads; ++i) { for (size_t i = 0; i < nb_threads; ++i) {
int start = i * batch_size; size_t start = i * batch_size;
for (int j = start; j < start + batch_size; j++) for (size_t j = start; j < start + batch_size; j++)
functor(j); functor(j);
} }
} }
// Deform the elements left // Deform the elements left
int start = nb_threads * batch_size; size_t start = nb_threads * batch_size;
for (int j = start; j < start + batch_remainder; j++) for (size_t j = start; j < start + batch_remainder; j++)
functor(j); functor(j);
// Wait for the other thread to finish their task // Wait for the other thread to finish their task

View File

@@ -87,7 +87,7 @@ 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); void parallel_for(size_t nb_elements, std::function<void(size_t i)> functor, bool use_threads = true);
template<typename T> struct cbuffer template<typename T> struct cbuffer
{ {