Skip to content

Commit fa57877

Browse files
committed
Fix error in TesselatedSvgNode::join - offset indices correctly
1 parent d8dc2c8 commit fa57877

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

azul-core/src/gl.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,9 @@ uniform vec2 vBboxSize;
672672
attribute vec2 vAttrXY;
673673
674674
void main() {
675-
gl_Position = vec4(vAttrXY / vBboxSize - vec2(1.0), 1.0, 1.0);
676-
gl_PointSize = 1.0;
675+
vec2 vCalc = vAttrXY / vBboxSize;
676+
vec2 vCalc1 = vCalc - vec2(1.0, 1.0);
677+
gl_Position = vec4(vCalc1, 0.0, 1.0);
677678
}";
678679

679680
static SVG_FRAGMENT_SHADER: &[u8] = b"#version 150

azulc/src/svg.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,21 @@ pub fn join_tessellated_nodes(nodes: &[TessellatedSvgNode]) -> TessellatedSvgNod
454454

455455
use rayon::iter::IntoParallelRefIterator;
456456
use rayon::iter::ParallelIterator;
457+
use rayon::iter::IndexedParallelIterator;
458+
use rayon::iter::IntoParallelRefMutIterator;
459+
460+
let mut index_offset = 0;
461+
462+
// note: can not be parallelized!
463+
let all_index_offsets = nodes
464+
.as_ref()
465+
.iter()
466+
.map(|t| {
467+
let i = index_offset;
468+
index_offset += t.vertices.len();
469+
i
470+
})
471+
.collect::<Vec<_>>();
457472

458473
let all_vertices = nodes
459474
.as_ref()
@@ -464,9 +479,27 @@ pub fn join_tessellated_nodes(nodes: &[TessellatedSvgNode]) -> TessellatedSvgNod
464479
let all_indices = nodes
465480
.as_ref()
466481
.par_iter()
467-
.flat_map(|t| {
482+
.enumerate()
483+
.flat_map(|(buffer_index, t)| {
484+
485+
// since the vertex buffers are now joined,
486+
// offset the indices by the vertex buffers lengths
487+
// encountered so far
488+
let vertex_buffer_offset: u32 = all_index_offsets
489+
.get(buffer_index)
490+
.copied()
491+
.unwrap_or(0)
492+
.min(core::u32::MAX as usize) as u32;
493+
468494
let mut indices = t.indices.clone().into_library_owned_vec();
495+
if vertex_buffer_offset != 0 {
496+
indices
497+
.par_iter_mut()
498+
.for_each(|i| { *i += vertex_buffer_offset; });
499+
}
500+
469501
indices.push(GL_RESTART_INDEX);
502+
470503
indices
471504
})
472505
.collect::<Vec<_>>();

examples/rust/opengl.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,17 @@ fn parse_multipolygons(data: &str) -> Vec<SvgMultiPolygon> {
163163

164164
let mut current = SvgPoint { x: i[0], y: i[1] };
165165
current.x -= 13.804493;
166-
current.x *= 10000.0;
167166
current.y -= 51.05264;
168-
current.y *= 10000.0;
167+
current.x *= 50000.0;
168+
current.y *= 50000.0;
169+
current.x += 500.0;
170+
current.y += 500.0;
171+
current.x *= 2.0;
172+
current.y *= 2.0;
169173

170174
last = Some(current);
171175
let last_point = last_point?;
176+
172177
Some(SvgPathElement::Line(SvgLine { start: last_point, end: current }))
173178
}).collect::<Vec<_>>().into(),
174179
}

0 commit comments

Comments
 (0)