Skip to content

Commit 97ff517

Browse files
bfree-githubmohawk2
authored andcommitted
incorporate from unreleased OpenGL::Shader 1.02
1 parent 8e50de6 commit 97ff517

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
- OpenGL::Shader improved error reporting for shader compiles - thanks Ivan Baidakou
2+
- from unreleased OpenGL::Shader 1.02: add SetArray for setting integer uniforms
3+
- from unreleased OpenGL::Shader 1.02: update SetMatrix to handle both 3x3 and 4x4 matrices
24

35
0.7004 2025-03-19
46
- re-release with higher version number for OpenGL::Array

lib/OpenGL/Shader.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ sub new {
8787
my $this = shift;
8888
my @types = @_ ? @_ : ('GLSL','CG','ARB');
8989
foreach my $type (@types) {
90+
next if !$type;
9091
my $module = GetTypeModule($type);
9192
(my $file = $module) =~ s{::}{/}g;
9293
require "$file.pm";

lib/OpenGL/Shader/ARB.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ sub new {
7878
my $ver = TypeVersion();
7979
return undef if (!$ver);
8080

81-
my $self = OpenGL::Shader::Objects->new(@_);
81+
my $self = OpenGL::Shader::Objects->new('ARB');
8282
return undef if (!$self);
8383
bless($self,$class);
8484

85-
$self->{type} = 'ARB';
8685
$self->{version} = $ver;
8786
$self->{description} = TypeDescription();
8887

lib/OpenGL/Shader/CG.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use Carp;
1414

1515
use strict;
1616
use warnings;
17-
our $VERSION = '1.01';
17+
our $VERSION = '1.02';
1818

19-
our $SHADER_VER;
19+
our $SHADER_VER = '1.0';
2020
our $DESCRIPTION = qq
2121
{nVidia's Cg Shader Language};
2222
@@ -90,11 +90,10 @@ sub new
9090
my $ver = TypeVersion();
9191
return undef if (!$ver);
9292
93-
my $self = OpenGL::Shader::Objects->new(@_);
93+
my $self = OpenGL::Shader::Objects->new('CG');
9494
return undef if (!$self);
9595
bless($self,$class);
9696
97-
$self->{type} = 'CG';
9897
$self->{version} = $ver;
9998
$self->{description} = $DESCRIPTION;
10099

lib/OpenGL/Shader/Common.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use strict;
1414
use warnings;
1515
use Carp;
1616

17-
our $VERSION = '1.01';
17+
our $VERSION = '1.02';
1818

1919
=head1 NAME
2020

lib/OpenGL/Shader/GLSL.pm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use strict;
1414
use warnings;
1515
use Carp;
1616

17-
our $VERSION = '1.01';
17+
our $VERSION = '1.02';
1818

1919
our $SHADER_VER;
2020
our $DESCRIPTION = qq
@@ -79,18 +79,14 @@ sub new {
7979
# Check for additional required OpenGL extensions
8080
my $ver = TypeVersion();
8181
return undef if (!$ver);
82-
my $self = OpenGL::Shader::Objects->new(@_);
82+
my $self = OpenGL::Shader::Objects->new('GLSL');
8383
return undef if (!$self);
8484
bless($self,$class);
85-
$self->{type} = 'GLSL';
8685
$self->{version} = $ver;
8786
$self->{description} = $DESCRIPTION;
8887
$self->{fragment_const} = GL_FRAGMENT_SHADER;
8988
$self->{vertex_const} = GL_VERTEX_SHADER;
9089
return $self;
9190
}
9291

93-
9492
1;
95-
__END__
96-

lib/OpenGL/Shader/Objects.pm

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use strict;
1616
use warnings;
1717
use Carp;
1818

19-
our $VERSION = '1.01';
19+
our $VERSION = '1.02';
2020

2121
use OpenGL::Shader::Common;
2222
our @ISA = qw(OpenGL::Shader::Common);
@@ -51,14 +51,14 @@ modify it under the same terms as Perl itself.
5151
sub new {
5252
my $this = shift;
5353
my $class = ref($this) || $this;
54-
my $self = OpenGL::Shader::Common->new(@_);
54+
my($type) = @_;
55+
my $self = OpenGL::Shader::Common->new($type);
5556
return undef if (!$self);
5657
bless($self,$class);
5758
# Check for required OpenGL extensions
5859
return undef if (OpenGL::glpCheckExtension('GL_ARB_shader_objects'));
5960
return undef if (OpenGL::glpCheckExtension('GL_ARB_fragment_shader'));
6061
return undef if (OpenGL::glpCheckExtension('GL_ARB_vertex_shader'));
61-
$self->{type} = '';
6262
$self->{version} = '';
6363
$self->{description} = '';
6464
$self->{fragment_const} = '';
@@ -154,7 +154,17 @@ sub Map {
154154
return $id;
155155
}
156156

157-
# Set shader vector
157+
# Set shader Uniform integer array
158+
sub SetArray {
159+
my($self,$var,@values) = @_;
160+
my $id = $self->Map($var);
161+
return 'Unable to map $var' if (!defined($id));
162+
my $count = scalar(@values);
163+
eval('glUniform'.$count.'iARB($id,@values)');
164+
return '';
165+
}
166+
167+
# Set shader Uniform float array
158168
sub SetVector {
159169
my($self,$var,@values) = @_;
160170
my $id = $self->Map($var);
@@ -164,13 +174,18 @@ sub SetVector {
164174
return '';
165175
}
166176

167-
168-
# Set shader 4x4 matrix
177+
# Set shader matrix
169178
sub SetMatrix {
170179
my($self,$var,$oga) = @_;
171180
my $id = $self->Map($var);
172181
return 'Unable to map $var' if (!defined($id));
173-
glUniformMatrix4fvARB_c($id,1,0,$oga->ptr());
182+
if ($oga->elements == 16) {
183+
glUniformMatrix4fvARB_c($id,1,0,$oga->ptr());
184+
} elsif ($oga->elements == 9) {
185+
glUniformMatrix3fvARB_c($id,1,0,$oga->ptr());
186+
} else {
187+
return 'Only supports 3x3 and 4x4 matrices';
188+
}
174189
return '';
175190
}
176191

t/shader.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ die "No known shader types available" if !$good;
4444

4545
pass "at least one test";
4646
test_shader('ARB');
47-
test_shader('CG');
47+
test_shader('CG') if !OpenGL::glpCheckExtension('GL_EXT_Cg_shader');
4848
test_shader('GLSL');
4949

5050
sub test_shader {

0 commit comments

Comments
 (0)