--- deliantra/Deliantra-Client/DC/Texture.pm 2006/06/14 16:20:23 1.5 +++ deliantra/Deliantra-Client/DC/Texture.pm 2006/06/17 15:07:53 1.8 @@ -42,7 +42,7 @@ sub new_from_image { my ($class, $image, %arg) = @_; - $class->new (image => $image, %arg) + $class->new (image => $image, internalformat => undef, %arg) } sub new_from_file { @@ -89,10 +89,6 @@ $class->new (w => $w || 1, h => $h || 1, render_cb => $cb) } -sub topot { - (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0] -} - sub upload { my ($self) = @_; @@ -113,17 +109,14 @@ $self->{render_cb}->($self, $self->{w}, $self->{h}); } else { - ($self->{w}, $self->{h}, $data, $self->{internalformat}, $self->{format}, $self->{type}) + ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) = CFClient::load_image_inline $self->{image}; + + $self->{internalformat} ||= $internalformat; } my ($tw, $th) = @$self{qw(w h)}; - unless ($tw > 0 && $th > 0) { - $tw = $th = 1; - $data = "\x00" x 64; - } - $self->{minified} ||= [CFClient::average $tw, $th, $data] if $self->{minify}; @@ -180,13 +173,19 @@ } } +sub shutdown { + my ($self) = @_; + + glDeleteTexture delete $self->{name} + if $self->{name}; +} + sub DESTROY { my ($self) = @_; delete $TEXTURES{$self+0}; - glDeleteTexture delete $self->{name} - if $self->{name}; + $self->shutdown; } $CFClient::OpenGL::INIT_HOOK{"CFClient::Texture"} = sub { @@ -194,6 +193,11 @@ for values %TEXTURES; }; +$CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Texture"} = sub { + $_->shutdown + for values %TEXTURES; +}; + 1; =back