diff --git a/Build.PL b/Build.PL index d0596cd..233c471 100644 --- a/Build.PL +++ b/Build.PL @@ -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 )], @@ -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 )], diff --git a/lib/SDL2/Constants.pm b/lib/SDL2/Constants.pm index 81d1daf..6fc1d47 100644 --- a/lib/SDL2/Constants.pm +++ b/lib/SDL2/Constants.pm @@ -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; @@ -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 diff --git a/lib/SDL2/Texture.pm b/lib/SDL2/Texture.pm index cd07b69..c765cff 100644 --- a/lib/SDL2/Texture.pm +++ b/lib/SDL2/Texture.pm @@ -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__)) { diff --git a/src/Core/Constants.xs b/src/Core/Constants.xs new file mode 100644 index 0000000..7d3f958 --- /dev/null +++ b/src/Core/Constants.xs @@ -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 + +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 + + diff --git a/t/106_sdl2_texture.t b/t/106_sdl2_texture.t index ccce45a..6707e6e 100644 --- a/t/106_sdl2_texture.t +++ b/t/106_sdl2_texture.t @@ -5,6 +5,7 @@ use SDL2::Renderer; use SDL2::Rect; use SDL2::Texture; use SDL2::ConfigData; +use SDL2::Constants; BEGIN { @@ -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');