ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.34 by root, Sat Apr 15 21:16:49 2006 UTC vs.
Revision 1.35 by root, Sat Apr 15 22:55:59 2006 UTC

139 139
140use Scalar::Util; 140use Scalar::Util;
141 141
142use SDL::OpenGL; 142use SDL::OpenGL;
143 143
144my @textures; 144my %TEXTURES;
145my @NAMES;
145 146
146sub new { 147sub new {
147 my ($class, %data) = @_; 148 my ($class, %data) = @_;
148 149
149 my $self = bless { 150 my $self = bless {
151 format => GL_RGBA, 152 format => GL_RGBA,
152 type => GL_UNSIGNED_BYTE, 153 type => GL_UNSIGNED_BYTE,
153 %data, 154 %data,
154 }, $class; 155 }, $class;
155 156
156 push @textures, $self; 157 Scalar::Util::weaken ($TEXTURES{$self+0} = $self);
157 Scalar::Util::weaken $textures[-1];
158 158
159 $self->upload; 159 $self->upload;
160 160
161 $self 161 $self
162} 162}
262 } 262 }
263 263
264 $self->{s} = $self->{w} / $tw; 264 $self->{s} = $self->{w} / $tw;
265 $self->{t} = $self->{h} / $th; 265 $self->{t} = $self->{h} / $th;
266 266
267 $self->{name} ||= (glGenTextures 1)->[0]; 267 $self->{name} ||= (pop @NAMES) || (glGenTextures 1)->[0];
268 268
269 glBindTexture GL_TEXTURE_2D, $self->{name}; 269 glBindTexture GL_TEXTURE_2D, $self->{name};
270 270
271 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; 271 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR;
272 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; 272 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR;
293} 293}
294 294
295sub DESTROY { 295sub DESTROY {
296 my ($self) = @_; 296 my ($self) = @_;
297 297
298 return unless exists $self->{name}; 298 delete $TEXTURES{$self+0};
299 299
300 glDeleteTextures delete $self->{name}; 300 if (my $name = delete $self->{name}) {
301 glDeleteTextures $name;
302 push @NAMES, $name;
303 }
304
301} 305}
302 306
303sub restore_state{ 307sub restore_state{
304 $_->upload 308 $_->upload
305 for grep $_, @textures; 309 for grep $_, values %TEXTURES;
306}; 310};
307 311
3081; 3121;
309 313
310=back 314=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines