--- deliantra/Deliantra-Client/DC/Texture.pm 2007/08/21 00:59:34 1.27 +++ deliantra/Deliantra-Client/DC/Texture.pm 2007/12/26 20:46:39 1.30 @@ -1,10 +1,10 @@ =head1 NAME -CFPlus::Texture - tetxure class for CFPlus +dc::Texture - tetxure class for CFPlus =head1 SYNOPSIS - use CFPlus::Texture; + use dc::Texture; =head1 DESCRIPTION @@ -12,12 +12,12 @@ =cut -package CFPlus::Texture; +package dc::Texture; use strict; use List::Util qw(max min); -use CFPlus::OpenGL; +use dc::OpenGL; my %TEXTURES; my ($MAX_W, $MAX_H) = (4096, 4096); # maximum texture size attempted by this module @@ -32,7 +32,7 @@ %data, }, $class; - CFPlus::weaken ($TEXTURES{$self+0} = $self); + dc::weaken ($TEXTURES{$self+0} = $self); $self->upload unless delete $self->{delay}; @@ -112,7 +112,7 @@ return if $self->{loading}; unless ($GL_VERSION) { - $self->{was_loaded} = 1; + $self->{want_upload} = -1; return; } @@ -132,7 +132,7 @@ } elsif (defined $self->{image}) { ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) - = CFPlus::load_image_inline $self->{image}; + = dc::load_image_inline $self->{image}; $self->{internalformat} ||= $internalformat; ($dw, $dh) = @$self{qw(w h)}; @@ -141,13 +141,13 @@ } elsif (defined $self->{tile}) { ++$self->{loading}; - return CFPlus::DB::get tilecache => $self->{tile}, sub { + return dc::DB::get tilecache => $self->{tile}, sub { $self->loading_done ($_[0]); }; } elsif (defined $self->{path}) { ++$self->{loading}; - return CFPlus::DB::read_file $self->{path}, sub { + return dc::DB::read_file $self->{path}, sub { $self->loading_done ($_[0]); }; @@ -159,17 +159,17 @@ defined $data or $self->{render_cb} or die; # some sanity check - $self->{minified} ||= [CFPlus::average $dw, $dh, $data] + $self->{minified} ||= [dc::average $dw, $dh, $data] if $self->{minify}; # against rather broken cards we enforce a maximum texture size - $tw = min $MAX_W, minpot $tw; - $th = min $MAX_H, minpot $th; + $tw = min $MAX_W, $tw; + $th = min $MAX_H, $th; # if only pot-textures are allowed, pot'ify tw/th - unless ($GL_NPOT && 0) {#d# - $tw = minpot $tw; - $th = minpot $th; + unless ($GL_NPOT) { + $tw = dc::minpot $tw; + $th = dc::minpot $th; } # now further decrease texture size until the @@ -234,6 +234,10 @@ } } + if ((my $name = delete $self->{want_upload}) > 0) { + $self->{name} = $name; + } + glBindTexture GL_TEXTURE_2D, $self->{name} ||= glGenTexture; if ($self->{wrap}) { @@ -321,17 +325,16 @@ $self->unload; } -$CFPlus::OpenGL::INIT_HOOK{"CFPlus::Texture"} = sub { +$dc::OpenGL::INIT_HOOK{"dc::Texture"} = sub { for (values %TEXTURES) { - next unless delete $_->{was_loaded}; - $_->upload; + $_->upload if $_->{want_upload}; } }; -$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Texture"} = sub { +$dc::OpenGL::SHUTDOWN_HOOK{"dc::Texture"} = sub { for (values %TEXTURES) { next unless $_->{name}; - $_->{was_loaded} = 1; + $_->{want_upload} = $_->{name}; $_->unload; } };