… | |
… | |
139 | |
139 | |
140 | use Scalar::Util; |
140 | use Scalar::Util; |
141 | |
141 | |
142 | use SDL::OpenGL; |
142 | use SDL::OpenGL; |
143 | |
143 | |
144 | my @textures; |
144 | my %TEXTURES; |
145 | |
145 | |
146 | sub new { |
146 | sub new { |
147 | my ($class, %data) = @_; |
147 | my ($class, %data) = @_; |
148 | |
148 | |
149 | my $self = bless { |
149 | my $self = bless { |
… | |
… | |
151 | format => GL_RGBA, |
151 | format => GL_RGBA, |
152 | type => GL_UNSIGNED_BYTE, |
152 | type => GL_UNSIGNED_BYTE, |
153 | %data, |
153 | %data, |
154 | }, $class; |
154 | }, $class; |
155 | |
155 | |
156 | push @textures, $self; |
156 | Scalar::Util::weaken ($TEXTURES{$self+0} = $self); |
157 | Scalar::Util::weaken $textures[-1]; |
|
|
158 | |
157 | |
159 | $self->upload; |
158 | $self->upload; |
160 | |
159 | |
161 | $self |
160 | $self |
162 | } |
161 | } |
… | |
… | |
293 | } |
292 | } |
294 | |
293 | |
295 | sub DESTROY { |
294 | sub DESTROY { |
296 | my ($self) = @_; |
295 | my ($self) = @_; |
297 | |
296 | |
298 | return unless exists $self->{name}; |
297 | delete $TEXTURES{$self+0}; |
299 | |
298 | |
300 | glDeleteTextures delete $self->{name}; |
299 | glDeleteTextures delete $self->{name} |
|
|
300 | if $self->{name}; |
301 | } |
301 | } |
302 | |
302 | |
303 | sub restore_state{ |
303 | sub restore_state{ |
304 | $_->upload |
304 | $_->upload |
305 | for grep $_, @textures; |
305 | for values %TEXTURES; |
306 | }; |
306 | }; |
307 | |
307 | |
308 | 1; |
308 | 1; |
309 | |
309 | |
310 | =back |
310 | =back |