@@ -111,89 +111,6 @@ fs_out_light => <<'EOF',
111111EOF
112112);
113113
114- { package # hide from PAUSE
115- PDL::Graphics::TriD::Labels;
116- use OpenGL::Modern qw(
117- glEnable glBlendFunc
118- glDrawElements_c
119- GL_BLEND GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
120- GL_TRIANGLES GL_UNSIGNED_INT
121- GL_RGBA32F GL_RGBA
122- ) ;
123- use PDL::Graphics::OpenGLQ;
124- my %FONT ;
125- sub _font_setup {
126- my ($fref ) = @_ ;
127- my ($texture , $rightbound , $orig ) = gl_font_texture();
128- $fref -> {texture } = PDL::float(1,1,1,1) * $texture -> dummy(0,1);
129- my $widthpix = $rightbound -> numdiff; $widthpix -> slice(' 0' ) += 1;
130- @{ $fref -> {widthpix } } = $widthpix -> list;
131- $fref -> {widthflt } = $widthpix -> float;
132- $fref -> {widthflt11 } = $fref -> {widthflt }-> t-> append([1,1])-> dummy(1);
133- $fref -> {heightpix } = $texture -> dim(1);
134- $fref -> {numchars } = my $numchars = $rightbound -> nelem;
135- $fref -> {texwidthm1 } = my $texwidthm1 = $texture -> dim(0) - 1;
136- $fref -> {leftbound } = my $leftbound = $rightbound -> rotate(1) + 1;
137- $leftbound -> slice(' 0' ) .= 0; $leftbound -> set_datatype(PDL::float-> enum);
138- $fref -> {rightbound } = $rightbound = $rightbound -> float;
139- $_ /= $texwidthm1 for $leftbound , $rightbound ;
140- @$fref {qw( xorig yorig) } = $orig -> list;
141- $fref -> {texture } = PDL::float(1,1,1,1) * $texture -> dummy(0,1);
142- # 4 = top-left, bot-left, top-right, bot-right, triangle idx=012,213
143- $fref -> {idx } = PDL-> new(PDL::ulong, [0,1,2], [2,1,3]);
144- $fref -> {texcoords } = my $texcoords = PDL-> zeroes(PDL::float,2,4,$numchars );
145- $texcoords -> slice(' (0),0:1' ) .= $leftbound -> dummy(0,1); # u of left
146- $texcoords -> slice(' (0),2:3' ) .= $rightbound -> dummy(0,1); # u of right
147- $texcoords -> slice(' (1),0::2' ) .= 1; # v of top, v bot=already 0
148- }
149- sub togl_setup {
150- my ($this ,$points ) = @_ ;
151- print " togl_setup $this \n " if $PDL::Graphics::TriD::verbose ;
152- if (!keys %FONT ) {
153- _font_setup(\%FONT );
154- $this -> load_texture(font_id => $FONT {texture }, GL_RGBA32F, ($FONT {texture }-> dims)[1,2], GL_RGBA);
155- $FONT {font_id } = $this -> {Impl }{font_id };
156- } else {
157- $this -> {Impl }{font_id } = $FONT {font_id };
158- }
159- $points //= $this -> {Points }; # as Labels is used in Graph
160- my $numchars = $FONT {numchars };
161- my $vert_template = PDL-> new(PDL::float, [0,0,1], [0,0,0], [1,0,1], [1,0,0]);
162- my $dwidth = $PDL::Graphics::TriD::Window::DEFAULT_WIDTH / 1.5;
163- my $dheight = $PDL::Graphics::TriD::Window::DEFAULT_HEIGHT / 1.5;
164- $vert_template *= PDL::float(1 / $dwidth , 1, $FONT {heightpix } / $dheight );
165- my @codes = map [map ord , split //], @{ $this -> {Strings } };
166- my ($v2 , @v1 , @v3 ) = PDL-> null;
167- for (0..$#codes ) {
168- my ($l , $xoffset ) = ($codes [$_ ], 0);
169- PDL::barf " Codepoint $_ >= $numchars " for grep $_ >= $numchars , @$l ;
170- push @v1 , ($_ ) x @$l ;
171- push @v3 , @$l ;
172- $v2 = PDL::glue(0,$v2 ,$FONT {widthflt }-> dice_axis(0,$l )-> cumusumover);
173- }
174- my $v = $points -> dice_axis(1, \@v1 )-> dummy(1) +
175- ($v2 -> t-> append([0,0])-> dummy(1) / $dwidth ) +
176- $vert_template * $FONT {widthflt11 }-> dice_axis(2,\@v3 );
177- $this -> load_buffer(vert_buf => $v -> clump(1,2));
178- $this -> load_buffer(texc_buf => $FONT {texcoords }-> dice_axis(2,\@v3 )-> clump(1,2));
179- $this -> load_idx_buffer(indx_buf => $this -> {Impl }{idx } = $FONT {idx }-> flat + 4 * PDL-> sequence(PDL::ulong,1,0+@v1 ));
180- $this -> togl_unbind;
181- }
182- sub gdraw {
183- my ($this ,$points ) = @_ ;
184- $this -> togl_bind;
185- glEnable(GL_BLEND);
186- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
187- glDrawElements_c(GL_TRIANGLES, $this -> {Impl }{idx }-> nelem, GL_UNSIGNED_INT, 0);
188- $this -> togl_unbind;
189- }
190- }
191-
192- my %mode2enum = (
193- linestrip => GL_LINE_STRIP,
194- lineloop => GL_LINE_LOOP,
195- );
196-
197114{ package # hide from PAUSE
198115 PDL::Graphics::TriD::GObject;
199116use OpenGL::Modern qw(
@@ -414,6 +331,84 @@ sub DESTROY {
414331}
415332}
416333
334+ { package # hide from PAUSE
335+ PDL::Graphics::TriD::Labels;
336+ use OpenGL::Modern qw(
337+ glEnable glBlendFunc
338+ glDrawElements_c
339+ GL_BLEND GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
340+ GL_TRIANGLES GL_UNSIGNED_INT
341+ GL_RGBA32F GL_RGBA
342+ ) ;
343+ use PDL::Graphics::OpenGLQ;
344+ my %FONT ;
345+ sub _font_setup {
346+ my ($fref ) = @_ ;
347+ my ($texture , $rightbound , $orig ) = gl_font_texture();
348+ $fref -> {texture } = PDL::float(1,1,1,1) * $texture -> dummy(0,1);
349+ my $widthpix = $rightbound -> numdiff; $widthpix -> slice(' 0' ) += 1;
350+ @{ $fref -> {widthpix } } = $widthpix -> list;
351+ $fref -> {widthflt } = $widthpix -> float;
352+ $fref -> {widthflt11 } = $fref -> {widthflt }-> t-> append([1,1])-> dummy(1);
353+ $fref -> {heightpix } = $texture -> dim(1);
354+ $fref -> {numchars } = my $numchars = $rightbound -> nelem;
355+ $fref -> {texwidthm1 } = my $texwidthm1 = $texture -> dim(0) - 1;
356+ $fref -> {leftbound } = my $leftbound = $rightbound -> rotate(1) + 1;
357+ $leftbound -> slice(' 0' ) .= 0; $leftbound -> set_datatype(PDL::float-> enum);
358+ $fref -> {rightbound } = $rightbound = $rightbound -> float;
359+ $_ /= $texwidthm1 for $leftbound , $rightbound ;
360+ @$fref {qw( xorig yorig) } = $orig -> list;
361+ $fref -> {texture } = PDL::float(1,1,1,1) * $texture -> dummy(0,1);
362+ # 4 = top-left, bot-left, top-right, bot-right, triangle idx=012,213
363+ $fref -> {idx } = PDL-> new(PDL::ulong, [0,1,2], [2,1,3]);
364+ $fref -> {texcoords } = my $texcoords = PDL-> zeroes(PDL::float,2,4,$numchars );
365+ $texcoords -> slice(' (0),0:1' ) .= $leftbound -> dummy(0,1); # u of left
366+ $texcoords -> slice(' (0),2:3' ) .= $rightbound -> dummy(0,1); # u of right
367+ $texcoords -> slice(' (1),0::2' ) .= 1; # v of top, v bot=already 0
368+ }
369+ sub togl_setup {
370+ my ($this ,$points ) = @_ ;
371+ print " togl_setup $this \n " if $PDL::Graphics::TriD::verbose ;
372+ if (!keys %FONT ) {
373+ _font_setup(\%FONT );
374+ $this -> load_texture(font_id => $FONT {texture }, GL_RGBA32F, ($FONT {texture }-> dims)[1,2], GL_RGBA);
375+ $FONT {font_id } = $this -> {Impl }{font_id };
376+ } else {
377+ $this -> {Impl }{font_id } = $FONT {font_id };
378+ }
379+ $points //= $this -> {Points }; # as Labels is used in Graph
380+ my $numchars = $FONT {numchars };
381+ my $vert_template = PDL-> new(PDL::float, [0,0,1], [0,0,0], [1,0,1], [1,0,0]);
382+ my $dwidth = $PDL::Graphics::TriD::Window::DEFAULT_WIDTH / 1.5;
383+ my $dheight = $PDL::Graphics::TriD::Window::DEFAULT_HEIGHT / 1.5;
384+ $vert_template *= PDL::float(1 / $dwidth , 1, $FONT {heightpix } / $dheight );
385+ my @codes = map [map ord , split //], @{ $this -> {Strings } };
386+ my ($v2 , @v1 , @v3 ) = PDL-> null;
387+ for (0..$#codes ) {
388+ my ($l , $xoffset ) = ($codes [$_ ], 0);
389+ PDL::barf " Codepoint $_ >= $numchars " for grep $_ >= $numchars , @$l ;
390+ push @v1 , ($_ ) x @$l ;
391+ push @v3 , @$l ;
392+ $v2 = PDL::glue(0,$v2 ,$FONT {widthflt }-> dice_axis(0,$l )-> cumusumover);
393+ }
394+ my $v = $points -> dice_axis(1, \@v1 )-> dummy(1) +
395+ ($v2 -> t-> append([0,0])-> dummy(1) / $dwidth ) +
396+ $vert_template * $FONT {widthflt11 }-> dice_axis(2,\@v3 );
397+ $this -> load_buffer(vert_buf => $v -> clump(1,2));
398+ $this -> load_buffer(texc_buf => $FONT {texcoords }-> dice_axis(2,\@v3 )-> clump(1,2));
399+ $this -> load_idx_buffer(indx_buf => $this -> {Impl }{idx } = $FONT {idx }-> flat + 4 * PDL-> sequence(PDL::ulong,1,0+@v1 ));
400+ $this -> togl_unbind;
401+ }
402+ sub gdraw {
403+ my ($this ,$points ) = @_ ;
404+ $this -> togl_bind;
405+ glEnable(GL_BLEND);
406+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
407+ glDrawElements_c(GL_TRIANGLES, $this -> {Impl }{idx }-> nelem, GL_UNSIGNED_INT, 0);
408+ $this -> togl_unbind;
409+ }
410+ }
411+
417412{ package # hide from PAUSE
418413 PDL::Graphics::TriD::GL::Primitive;
419414use OpenGL::Modern qw( glDrawArrays) ;
@@ -530,6 +525,11 @@ sub gdraw {
530525}
531526}
532527
528+ my %mode2enum = (
529+ linestrip => GL_LINE_STRIP,
530+ lineloop => GL_LINE_LOOP,
531+ );
532+
533533{ package # hide from PAUSE
534534 PDL::Graphics::TriD::DrawMulti;
535535use OpenGL::Modern qw( glMultiDrawElements_c GL_UNSIGNED_INT) ;
0 commit comments