Skip to content

Commit 421862e

Browse files
committed
to_gl{,setup} to take/pass on args, _setup to handle $material, togl uses
1 parent ef53c9f commit 421862e

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

  • lib/PDL/Graphics/TriD

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,30 @@ sub togl {
2727
{ package # hide from PAUSE
2828
PDL::Graphics::TriD::Object;
2929
sub togl_setup {
30-
print "togl_setup $_[0]\n" if $PDL::Graphics::TriD::verbose;
31-
$_->togl_setup for $_[0]->contained_objects;
30+
my ($this, @args) = @_;
31+
print "togl_setup $this\n" if $PDL::Graphics::TriD::verbose;
32+
$_->togl_setup(@args) for $this->contained_objects;
3233
}
33-
sub togl { $_->togl for $_[0]->contained_objects }
34+
sub togl { $_->togl(@_[1..$#_]) for $_[0]->contained_objects }
3435
}
3536

3637
{ package # hide from PAUSE
3738
PDL::Graphics::TriD::Graph;
3839
sub togl_setup {
39-
my ($this) = @_;
40-
$this->{Axis}{$_}->togl_setup for grep $_ ne "Default", keys %{$this->{Axis}};
40+
my ($this, $points_arg, @args) = @_;
41+
$this->{Axis}{$_}->togl_setup($points_arg, @args) for grep $_ ne "Default", keys %{$this->{Axis}};
4142
while (my ($series,$h) = each %{ $this->{Data} }) {
4243
for my $data (values %$h) {
43-
$data->togl_setup($this->get_points($series, $data));
44+
$data->togl_setup($this->get_points($series, $data), @args);
4445
}
4546
}
4647
}
4748
sub togl {
48-
my ($this) = @_;
49-
$this->{Axis}{$_}->togl for grep $_ ne "Default", keys %{$this->{Axis}};
49+
my ($this, @args) = @_;
50+
$this->{Axis}{$_}->togl(@args) for grep $_ ne "Default", keys %{$this->{Axis}};
5051
while (my ($series,$h) = each %{ $this->{Data} }) {
5152
for my $data (values %$h) {
52-
$data->togl($this->get_points($series, $data));
53+
$data->togl($this->get_points($series, $data), @args);
5354
}
5455
}
5556
}
@@ -368,6 +369,7 @@ sub lighting {
368369
glEnable(GL_LIGHT0);
369370
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
370371
glLightfv_p(GL_LIGHT0,GL_POSITION,1.0,1.0,1.0,0.0);
372+
$this->{Impl}{material}->togl if $this->{Impl}{material};
371373
} else {
372374
glDisable(GL_LIGHTING);
373375
}
@@ -537,7 +539,7 @@ my $fragment_shader = join '', @SHADERBITS{qw(version
537539
my %SPHERE;
538540
my @KEYS = qw(vertices normals idx);
539541
sub togl_setup {
540-
my ($this,$points) = @_;
542+
my ($this, $points, $material) = @_;
541543
print "togl_setup $this\n" if $PDL::Graphics::TriD::verbose;
542544
@SPHERE{@KEYS} = gl_sphere(0.025, 15, 15) if !keys %SPHERE;
543545
@{ $this->{Impl} }{@KEYS} = @SPHERE{@KEYS};
@@ -553,6 +555,7 @@ sub togl_setup {
553555
}
554556
$this->{Impl}{offset_loc} = $this->load_attrib(offset => $points);
555557
$this->{Impl}{noffset} = $points->dim(1);
558+
$this->{Impl}{material} = $material;
556559
$this->togl_unbind;
557560
}
558561
sub gdraw {
@@ -598,7 +601,7 @@ my %frag = (
598601
tex_flat => join('', $frag_header, $frag_tex, $frag_flat),
599602
);
600603
sub togl_setup {
601-
my ($this,$points) = @_;
604+
my ($this, $points, $material) = @_;
602605
print "togl_setup $this\n" if $PDL::Graphics::TriD::verbose;
603606
my $shading = $this->{Options}{Shading};
604607
my $lightflat = $shading > 2 ? 'light' : 'flat';
@@ -621,6 +624,7 @@ sub togl_setup {
621624
if ($shading > 2) {
622625
$this->load_attrib(normal => $this->{Normals});
623626
$this->set_uniform(lightind => '1i' => [0]);
627+
$this->{Impl}{material} = $material;
624628
}
625629
$this->togl_unbind;
626630
}
@@ -877,11 +881,10 @@ sub display {
877881
print "VALID $this=$this->{IsValid}\n" if $PDL::Graphics::TriD::verbose;
878882
if (!$vp->{IsValid}) {
879883
glpSetAutoCheckErrors(1);
880-
$vp->togl_setup;
884+
$vp->togl_setup(undef, $vp->{DefMaterial});
881885
print "VALID1 $vp\n" if $PDL::Graphics::TriD::verbose;
882886
$vp->{IsValid} = 1;
883887
}
884-
$vp->{DefMaterial}->togl;
885888
$vp->togl;
886889
glMatrixMode(GL_MODELVIEW);
887890
glPopMatrix();

0 commit comments

Comments
 (0)