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

Comparing deliantra/Deliantra-Client/DC/Texture.pm (file contents):
Revision 1.31 by root, Wed Dec 26 21:03:21 2007 UTC vs.
Revision 1.35 by root, Wed Sep 3 06:07:39 2008 UTC

1=head1 NAME 1=head1 NAME
2 2
3DC::Texture - tetxure class for CFPlus 3DC::Texture - tetxure class for Deliantra-Client
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use DC::Texture; 7 use DC::Texture;
8 8
47 unless defined $image; 47 unless defined $image;
48 48
49 $class->new (image => $image, internalformat => undef, %arg) 49 $class->new (image => $image, internalformat => undef, %arg)
50} 50}
51 51
52
53sub new_from_file { 52sub new_from_resource {
54 my ($class, $path, %arg) = @_; 53 my ($class, $path, %arg) = @_;
55 54
56 open my $fh, "<:raw", $path 55 $class->new (resource_path => $path, internalformat => undef, %arg)
57 or die "$path: $!";
58
59 local $/;
60 $class->new_from_image (<$fh>, %arg)
61} 56}
62 57
63#sub new_from_surface { 58#sub new_from_surface {
64# my ($class, $surface) = @_; 59# my ($class, $surface) = @_;
65# 60#
121 # $rw,$rh rendered/used size 116 # $rw,$rh rendered/used size
122 # $dw,$dh $data 117 # $dw,$dh $data
123 118
124 my ($data, $dw, $dh); 119 my ($data, $dw, $dh);
125 120
121 if (exists $self->{resource_path}) {
122 open my $fh, "<:raw", DC::find_rcfile $self->{resource_path};
123 local $/;
124 $self->{image} = <$fh>;
125 $self->{delete_image} = 1;
126 }
127
126 if (defined $self->{data}) { 128 if (defined $self->{data}) {
127 $data = $self->{data}; 129 $data = $self->{data};
128 ($dw, $dh) = @$self{qw(w h)}; 130 ($dw, $dh) = @$self{qw(w h)};
129 131
130 } elsif ($self->{render_cb}) { 132 } elsif ($self->{render_cb}) {
131 ($dw, $dh) = @$self{qw(w h)}; 133 ($dw, $dh) = @$self{qw(w h)};
132 134
133 } elsif (defined $self->{image}) { 135 } elsif (defined $self->{image}) {
134 ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) 136 ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type})
135 = DC::load_image_inline $self->{image}; 137 = DC::load_image_inline $self->{image};
136 138
137 $self->{internalformat} ||= $internalformat; 139 $self->{internalformat} ||= $internalformat;
138 ($dw, $dh) = @$self{qw(w h)}; 140 ($dw, $dh) = @$self{qw(w h)};
139 141
140 delete $self->{image} if delete $self->{delete_image}; 142 delete $self->{image} if delete $self->{delete_image};
141 143
324 326
325 $self->unload; 327 $self->unload;
326} 328}
327 329
328$DC::OpenGL::INIT_HOOK{"DC::Texture"} = sub { 330$DC::OpenGL::INIT_HOOK{"DC::Texture"} = sub {
329 for (values %TEXTURES) { 331 for my $tex (values %TEXTURES) {
330 $_->upload if $_->{want_upload}; 332 if (my $name = $tex->{want_upload}) {
333 $tex->upload;
334
335 if ($tex->{loading} && $name > 0) {
336 # if loading is delayed we still have to allocate the texture name
337 glBindTexture GL_TEXTURE_2D, $name;
338 glTexImage2D GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, 0, GL_ALPHA, GL_UNSIGNED_BYTE;
339 }
340 }
331 } 341 }
332}; 342};
333 343
334$DC::OpenGL::SHUTDOWN_HOOK{"DC::Texture"} = sub { 344$DC::OpenGL::SHUTDOWN_HOOK{"DC::Texture"} = sub {
335 for (values %TEXTURES) { 345 for (values %TEXTURES) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines