Skip to content

Commit 3dc81d7

Browse files
committed
label split coord into position, toffset
1 parent 807dc89 commit 3dc81d7

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

  • lib/PDL/Graphics/TriD

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@ vec4 lightfuncgouraud(
144144
return ambient + diffuse + spec;
145145
}
146146
EOF
147-
(map _passthrough(@$_), [position=>3], [normal=>3], [colour=>3], [texcoord=>2]),
147+
(map _passthrough(@$_), [position=>3], [toffset=>2], [normal=>3], [colour=>3], [texcoord=>2]),
148148
fs_diffuse_colour => " vec4 in_diffuse = vec4(vColour, 1);\n",
149149
fs_diffuse_tex => " vec4 in_diffuse = $TEXFUNC(tex, vTexcoord);\n",
150150
fs_out_fragcolour_decl => "$FS_OUT vec4 $FRAG_OUT;\n",
151151
fs_out_flat => " $FRAG_OUT = in_diffuse;\n",
152152
vs_in => " vec3 the_position = position;\n",
153153
vs_in_offset_decl => "$VS_IN vec3 offset;\n",
154154
vs_do_offset => " the_position += offset;\n",
155+
vs_do_toffset => " the_position += vec3(toffset.x, 0, toffset.y);\n",
155156
vs_out => " gl_Position = uMVP * vec4(the_position, 1);\n",
156157
vs_out_light => <<'EOF',
157158
vNormal = normalize(uNormalMatrix * normal);
@@ -463,9 +464,9 @@ sub _font_setup {
463464
my ($fref) = @_;
464465
my ($texture, $rightbound, $orig) = gl_font_texture();
465466
$fref->{texture} = PDL::float(1,1,1,1) * $texture->dummy(0,1);
466-
my $widthpix = $rightbound->numdiff; $widthpix->slice('0') ++;
467+
my $widthpix = $rightbound->numdiff; $widthpix->slice('0')++;
467468
$fref->{widthflt} = $widthpix->float;
468-
$fref->{widthflt11} = $fref->{widthflt}->t->append([1,1])->dummy(1);
469+
$fref->{widthflt1} = $fref->{widthflt}->t->append([1])->dummy(1);
469470
$fref->{heightpix} = $texture->dim(1);
470471
$fref->{numchars} = my $numchars = $rightbound->nelem;
471472
my $texwidthm1 = $texture->dim(0) - 1;
@@ -483,8 +484,9 @@ sub _font_setup {
483484
$texcoords->slice('(1),0::2') .= 1; # v of top, v bot=already 0
484485
}
485486
my $vertex_shader = join '', @SHADERBITS{qw(version
486-
vs_in_position_decl vs_in_texcoord_decl vs_out_texcoord_decl u_matrix_decl
487-
main_start vs_in vs_out vs_out_texcoord main_end
487+
vs_in_position_decl vs_in_toffset_decl
488+
vs_in_texcoord_decl vs_out_texcoord_decl u_matrix_decl
489+
main_start vs_in vs_do_toffset vs_out vs_out_texcoord main_end
488490
)};
489491
my $fragment_shader = join '', @SHADERBITS{qw(version
490492
fs_in_texcoord_decl fs_out_fragcolour_decl u_tex_decl
@@ -499,10 +501,10 @@ sub togl_setup {
499501
});
500502
$points //= $this->{Points}; # as Labels is used in Graph
501503
my $numchars = $FONT{numchars};
502-
my $vert_template = PDL->new(PDL::float, [0,0,1], [0,0,0], [1,0,1], [1,0,0]);
504+
my $vert_template = PDL->new(PDL::float, [0,1], [0,0], [1,1], [1,0]);
503505
my $dwidth = $PDL::Graphics::TriD::Window::DEFAULT_WIDTH / 1.5;
504506
my $dheight = $PDL::Graphics::TriD::Window::DEFAULT_HEIGHT / 1.5;
505-
$vert_template *= PDL::float(1 / $dwidth, 1, $FONT{heightpix} / $dheight);
507+
$vert_template *= PDL::float(1 / $dwidth, $FONT{heightpix} / $dheight);
506508
my @codes = map [map ord, split //], @{ $this->{Strings} };
507509
my ($v2, @v1, @v3) = PDL->null;
508510
for (0..$#codes) {
@@ -512,13 +514,15 @@ sub togl_setup {
512514
push @v3, @$l;
513515
$v2 = PDL::glue(0,$v2,$FONT{widthflt}->dice_axis(0,$l)->cumusumover);
514516
}
515-
my $v = $points->dice_axis(1, \@v1)->dummy(1) +
516-
($v2->t->append([0,0])->dummy(1) / $dwidth) +
517-
$vert_template * $FONT{widthflt11}->dice_axis(2,\@v3);
517+
my $v = $points->dice_axis(1, \@v1)->dummy(1,4);
518+
my $toffset =
519+
($v2->t->append([0])->dummy(1) / $dwidth) +
520+
$vert_template * $FONT{widthflt1}->dice_axis(2,\@v3);
518521
$this->{Impl}{program_nodestroy} = $this->cache_do(prog => 'shader', sub {
519522
$this->compile_program($vertex_shader, $fragment_shader);
520523
});
521524
$this->load_attrib(position => $v->clump(1,2));
525+
$this->load_attrib(toffset => $toffset->clump(1,2));
522526
$this->load_attrib(texcoord => $FONT{texcoords}->dice_axis(2,\@v3)->clump(1,2));
523527
$this->load_idx_buffer(indx_buf => $this->{Impl}{idx} = $FONT{idx}->flat + 4 * PDL->sequence(PDL::ulong,1,0+@v1));
524528
$this->togl_unbind;

0 commit comments

Comments
 (0)