Skip to content

Commit

Permalink
Added constants XS. Because the number values of these enums may chan…
Browse files Browse the repository at this point in the history
…ge later. Also haven't testhaven't tested this but it may be faster. WIP #2
  • Loading branch information
f0rodo committed Aug 11, 2013
1 parent 895c5cc commit 8d8b1b6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ my %mods = (
xs => [ 'src/SDL2pp.xs' => 'lib/SDL2pp.xs'],
libs => [qw( SDL2 )],
},
'SDL2::Constants' => {
xs => [ 'src/Core/Constants.xs' => 'lib/SDL2/Constants.xs'],
libs => [qw( SDL2 )],
},
'SDL2::Log' => {
xs => [ 'src/Core/Log.xs' => 'lib/SDL2/Log.xs'],
libs => [qw( SDL2 )],
Expand All @@ -20,7 +24,6 @@ my %mods = (
xs => [ 'src/Core/Video.xs' => 'lib/SDL2/Video.xs'],
libs => [qw( SDL2 )],
},

'SDL2::Window' => {
xs => [ 'src/Core/objects/Window.xs' => 'lib/SDL2/Window.xs' ],
libs => [qw( SDL2 )],
Expand Down
21 changes: 21 additions & 0 deletions lib/SDL2/Constants.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package SDL2::Constants;
use warnings;
use vars qw(@ISA @EXPORT @EXPORT_OK);
require Exporter;
require DynaLoader;
our @ISA = qw(Exporter DynaLoader);

use SDL2::Internal::Loader;
if (check_and_load(__PACKAGE__)) {
bootstrap SDL2::Constants;
}
else {
warn "WARNING: " . __PACKAGE__ . " is not available\n";
}


use base 'Exporter';
use Config;

Expand Down Expand Up @@ -75,8 +89,15 @@ our %EXPORT_TAGS = (
SDL_LOG_PRIORITY_CRITICAL
SDL_NUM_LOG_PRIORITIES
)
],
'SDL2::Texture/access' => [
qw(
SDL_TEXTUREACCESS_STATIC
SDL_TEXTUREACCESS_STREAMING
)
]

);

#From https://github.com/PerlGameDev/SDL/blob/master/lib/SDL/Constants.pm#L609
Expand Down
10 changes: 10 additions & 0 deletions lib/SDL2/Texture.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ use vars qw(@ISA @EXPORT @EXPORT_OK);
require Exporter;
require DynaLoader;
our @ISA = qw(Exporter DynaLoader);
use SDL2::Constants ':SDL2::Texture';

use base 'Exporter';
our @EXPORT = @{ $SDL2::Constants::EXPORT_TAGS{'SDL2::Texture'} };
push @EXPORT, 'NULL';
our %EXPORT_TAGS = (
all => \@EXPORT,
access => $SDL2::Constants::EXPORT_TAGS{'SDL2::Texture/access'}
);


use SDL2::Internal::Loader;
if (check_and_load(__PACKAGE__)) {
Expand Down
30 changes: 30 additions & 0 deletions src/Core/Constants.xs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "helper.h"

#ifndef aTHX_
#define aTHX_
#endif

#include <SDL2/SDL.h>

MODULE = SDL2::Constants PACKAGE = SDL2::Constants PREFIX = constant_


int
constant_SDL_TEXTUREACCESS_STATIC ( )
CODE:
RETVAL = SDL_TEXTUREACCESS_STATIC;
OUTPUT:
RETVAL

int
constant_SDL_TEXTUREACCESS_STREAMING ( )
CODE:
RETVAL = SDL_TEXTUREACCESS_STREAMING;
OUTPUT:
RETVAL


5 changes: 4 additions & 1 deletion t/106_sdl2_texture.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use SDL2::Renderer;
use SDL2::Rect;
use SDL2::Texture;
use SDL2::ConfigData;
use SDL2::Constants;

BEGIN {

Expand All @@ -21,8 +22,10 @@ my $renderer = SDL2::Renderer->new($win, -1, SDL_RENDERER_SOFTWARE); #Hardware a

can_ok('SDL2::Texture', qw/new/);

my $texture = SDL2::Texture->new($renderer, 0, 0, 100, 100);
my $texture = SDL2::Texture->new($renderer, 0, SDL_TEXTUREACCESS_STATIC, 100, 100);
fail( SDL2pp::get_error() ) unless $texture;
my $texture2 = SDL2::Texture->new($renderer, 0, SDL_TEXTUREACCESS_STREAMING, 100, 100);
fail( SDL2pp::get_error() ) unless $texture2;

isa_ok($texture, 'SDL2::Texture');

0 comments on commit 8d8b1b6

Please sign in to comment.