--- deliantra/Deliantra-Client/DC/Texture.pm 2006/06/14 18:59:31 1.6 +++ deliantra/Deliantra-Client/DC/Texture.pm 2006/07/04 23:23:32 1.10 @@ -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 { @@ -67,21 +67,21 @@ # ) #} -sub new_from_layout { - my ($class, $layout, %arg) = @_; - - my ($w, $h, $data, $format, $internalformat) = $layout->render; - - $class->new ( - w => $w, - h => $h, - data => $data, - format => $format, - internalformat => $format, - type => GL_UNSIGNED_BYTE, - %arg, - ) -} +#sub new_from_layout { +# my ($class, $layout, %arg) = @_; +# +# my ($w, $h, $data, $format, $internalformat) = $layout->render; +# +# $class->new ( +# w => $w, +# h => $h, +# data => $data, +# format => $format, +# internalformat => $format, +# type => GL_UNSIGNED_BYTE, +# %arg, +# ) +#} sub new_from_opengl { my ($class, $w, $h, $cb) = @_; @@ -109,8 +109,10 @@ $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)}; @@ -161,6 +163,7 @@ gl_check "uploading texture %dx%d if=%x f=%x t=%x", $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; } else { + exists $self->{render_cb} or die; glCopyTexImage2D GL_TEXTURE_2D, 0, $self->{internalformat}, 0, 0, @@ -171,20 +174,34 @@ } } +sub shutdown { + my ($self) = @_; + + glDeleteTexture $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 { + # first mark all existing texture names as in-use, in case the context lost textures + glBindTexture GL_TEXTURE_2D, $_->{name} + for values %TEXTURES; $_->upload for values %TEXTURES; }; +$CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Texture"} = sub { + $_->shutdown + for values %TEXTURES; +}; + 1; =back