… | |
… | |
40 | } |
40 | } |
41 | |
41 | |
42 | sub new_from_image { |
42 | sub new_from_image { |
43 | my ($class, $image, %arg) = @_; |
43 | my ($class, $image, %arg) = @_; |
44 | |
44 | |
45 | $class->new (image => $image, %arg) |
45 | $class->new (image => $image, internalformat => undef, %arg) |
46 | } |
46 | } |
47 | |
47 | |
48 | sub new_from_file { |
48 | sub new_from_file { |
49 | my ($class, $path, %arg) = @_; |
49 | my ($class, $path, %arg) = @_; |
50 | |
50 | |
… | |
… | |
107 | glMatrixMode GL_MODELVIEW; |
107 | glMatrixMode GL_MODELVIEW; |
108 | glLoadIdentity; |
108 | glLoadIdentity; |
109 | $self->{render_cb}->($self, $self->{w}, $self->{h}); |
109 | $self->{render_cb}->($self, $self->{w}, $self->{h}); |
110 | |
110 | |
111 | } else { |
111 | } else { |
112 | ($self->{w}, $self->{h}, $data, $self->{internalformat}, $self->{format}, $self->{type}) |
112 | ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) |
113 | = CFClient::load_image_inline $self->{image}; |
113 | = CFClient::load_image_inline $self->{image}; |
|
|
114 | |
|
|
115 | $self->{internalformat} ||= $internalformat; |
114 | } |
116 | } |
115 | |
117 | |
116 | my ($tw, $th) = @$self{qw(w h)}; |
118 | my ($tw, $th) = @$self{qw(w h)}; |
117 | |
119 | |
118 | $self->{minified} ||= [CFClient::average $tw, $th, $data] |
120 | $self->{minified} ||= [CFClient::average $tw, $th, $data] |
… | |
… | |
169 | gl_check "copying to texture %dx%d if=%x", |
171 | gl_check "copying to texture %dx%d if=%x", |
170 | $tw, $th, $self->{internalformat}; |
172 | $tw, $th, $self->{internalformat}; |
171 | } |
173 | } |
172 | } |
174 | } |
173 | |
175 | |
|
|
176 | sub shutdown { |
|
|
177 | my ($self) = @_; |
|
|
178 | |
|
|
179 | glDeleteTexture delete $self->{name} |
|
|
180 | if $self->{name}; |
|
|
181 | } |
|
|
182 | |
174 | sub DESTROY { |
183 | sub DESTROY { |
175 | my ($self) = @_; |
184 | my ($self) = @_; |
176 | |
185 | |
177 | delete $TEXTURES{$self+0}; |
186 | delete $TEXTURES{$self+0}; |
178 | |
187 | |
179 | glDeleteTexture delete $self->{name} |
188 | $self->shutdown; |
180 | if $self->{name}; |
|
|
181 | } |
189 | } |
182 | |
190 | |
183 | $CFClient::OpenGL::INIT_HOOK{"CFClient::Texture"} = sub { |
191 | $CFClient::OpenGL::INIT_HOOK{"CFClient::Texture"} = sub { |
184 | $_->upload |
192 | $_->upload |
185 | for values %TEXTURES; |
193 | for values %TEXTURES; |
186 | }; |
194 | }; |
187 | |
195 | |
|
|
196 | $CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Texture"} = sub { |
|
|
197 | $_->shutdown |
|
|
198 | for values %TEXTURES; |
|
|
199 | }; |
|
|
200 | |
188 | 1; |
201 | 1; |
189 | |
202 | |
190 | =back |
203 | =back |
191 | |
204 | |
192 | =head1 AUTHOR |
205 | =head1 AUTHOR |