Skip to content

Commit

Permalink
Move changes in master to topic branch
Browse files Browse the repository at this point in the history
  • Loading branch information
devel-chm committed Aug 5, 2017
1 parent 06ddcee commit adccfea
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions lib/OpenGL/Modern/Helpers.pm
Expand Up @@ -57,7 +57,7 @@ use from perl.
OpenGL::Modern is an XS module providings bindings to the
C OpenGL library for graphics. As such, it needs to handle
conversion of input arguements from perl into the required
datatypes for the C OpenGL API, it then calls the OpenGL\
datatypes for the C OpenGL API, it then calls the OpenGL
routine, and then converts the return value (if any) from
the C API datatype into an appropriate Perl type.
Expand Down Expand Up @@ -153,6 +153,7 @@ $VERSION = '0.01_02';
pack_GLint
pack_GLstrings
pack_ptr
iv_ptr
xs_buffer
glGetShaderInfoLog_p
Expand Down Expand Up @@ -223,6 +224,11 @@ sub pack_ptr {
return pack 'P', $_[0];
}

sub iv_ptr {
$_[0] = "\0" x $_[1] if $_[1];
return unpack( $PACK_TYPE, pack( 'P', $_[0] ) );
}

# No parameter declaration because we don't want copies
# This makes a packed string buffer of desired length.
# As above, be careful of the variable scopes.
Expand All @@ -245,11 +251,13 @@ sub get_info_log_p {
return substr $buffer, 0, $len;
}

sub glGetShaderInfoLog_p { get_info_log_p \&glGetShaderInfoLog, @_ }
sub glGetProgramInfoLog_p { get_info_log_p \&glGetProgramInfoLog, @_ }
sub glGetShaderInfoLog_p { get_info_log_p \&glGetShaderInfoLog_c, @_ }
sub glGetProgramInfoLog_p { get_info_log_p \&glGetProgramInfoLog_c, @_ }

# This should probably be named glpGetVersion since there is actually
# no glGetVersion() in the OpenGL API.
#
sub glGetVersion_p {

# const GLubyte * GLAPIENTRY glGetString (GLenum name);
my $glVersion = glGetString( GL_VERSION );
( $glVersion ) = ( $glVersion =~ m!^(\d+\.\d+)!g );
Expand Down Expand Up @@ -290,9 +298,9 @@ sub get_iv_p {
return wantarray ? @params : $params[0];
}

sub glGetProgramiv_p { get_iv_p \&glGetProgramiv_c, @_ }
sub glGetProgramiv_p { get_iv_p \&glGetProgramiv_c, @_ } # TODO: get rid of $count

sub glGetShaderiv_p { get_iv_p \&glGetShaderiv_c, @_ }
sub glGetShaderiv_p { get_iv_p \&glGetShaderiv_c, @_ } # TODO: get rid of $count

sub glShaderSource_p {
my ( $shader, @sources ) = @_;
Expand All @@ -303,25 +311,33 @@ sub glShaderSource_p {
}

sub glGetIntegerv_p {
my ( $pname, $count ) = @_;
my ( $pname, $count ) = @_; # TODO: get rid of $count
$count ||= 1;
xs_buffer my $data, 4 * $count;
glGetIntegerv_c $pname, unpack( $PACK_TYPE, pack( 'p', $data ) );
my @data = unpack 'I*', $data;
return wantarray ? @data : $data[0];
}

sub glBufferData_p {
sub glBufferData_p { # NOTE: this might be better named glpBufferDataf_p
my $usage = pop;
my ($target, $size, @data) = @_;
my $pdata = pack "f*", @data;

glBufferData_c $target, $size, unpack( $PACK_TYPE, pack( 'p', $pdata ) ), $usage;
}

sub glBufferData_o { # NOTE: this was glBufferData_p in OpenGL
my ( $target, $oga, $usage ) = @_;
glBufferData_c $target, $oga->length, $oga->ptr, $usage;
}

sub glUniform2f_p {
sub glUniform2fv_p { # NOTE: this name is more consistent with OpenGL API
my ( $uniform, $v0, $v1 ) = @_;
glUniform2f $uniform, $v0, $v1;
}

sub glUniform4f_p {
sub glUniform4fv_p { # NOTE: this name is more consistent with OpenGL API
my ( $uniform, $v0, $v1, $v2, $v3 ) = @_;
glUniform4f $uniform, $v0, $v1, $v2, $v3;
}
Expand Down

0 comments on commit adccfea

Please sign in to comment.