1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | CFClient::Texture - tetxure class for CFClient |
3 | CFPlus::Texture - tetxure class for CFPlus |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use CFClient::Texture; |
7 | use CFPlus::Texture; |
8 | |
8 | |
9 | =head1 DESCRIPTION |
9 | =head1 DESCRIPTION |
10 | |
10 | |
11 | =over 4 |
11 | =over 4 |
12 | |
12 | |
13 | =cut |
13 | =cut |
14 | |
14 | |
15 | package CFClient::Texture; |
15 | package CFPlus::Texture; |
16 | |
16 | |
17 | use strict; |
17 | use strict; |
18 | |
18 | |
19 | use Scalar::Util; |
19 | use Scalar::Util; |
20 | |
20 | |
21 | use CFClient::OpenGL; |
21 | use CFPlus::OpenGL; |
22 | |
22 | |
23 | my %TEXTURES; |
23 | my %TEXTURES; |
24 | |
24 | |
25 | sub new { |
25 | sub new { |
26 | my ($class, %data) = @_; |
26 | my ($class, %data) = @_; |
… | |
… | |
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, my $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 | = CFPlus::load_image_inline $self->{image}; |
114 | |
114 | |
115 | $self->{internalformat} ||= $internalformat; |
115 | $self->{internalformat} ||= $internalformat; |
116 | } |
116 | } |
117 | |
117 | |
118 | my ($tw, $th) = @$self{qw(w h)}; |
118 | my ($tw, $th) = @$self{qw(w h)}; |
119 | |
119 | |
120 | $self->{minified} ||= [CFClient::average $tw, $th, $data] |
120 | $self->{minified} ||= [CFPlus::average $tw, $th, $data] |
121 | if $self->{minify}; |
121 | if $self->{minify}; |
122 | |
122 | |
123 | pad2pot $data, $tw, $th unless $GL_NPOT; |
123 | pad2pot $data, $tw, $th unless $GL_NPOT; |
124 | |
124 | |
125 | $self->{s} = $self->{w} / $tw; |
125 | $self->{s} = $self->{w} / $tw; |
… | |
… | |
187 | delete $TEXTURES{$self+0}; |
187 | delete $TEXTURES{$self+0}; |
188 | |
188 | |
189 | $self->shutdown; |
189 | $self->shutdown; |
190 | } |
190 | } |
191 | |
191 | |
192 | $CFClient::OpenGL::INIT_HOOK{"CFClient::Texture"} = sub { |
192 | $CFPlus::OpenGL::INIT_HOOK{"CFPlus::Texture"} = sub { |
193 | # first mark all existing texture names as in-use, in case the context lost textures |
193 | # first mark all existing texture names as in-use, in case the context lost textures |
194 | glBindTexture GL_TEXTURE_2D, $_->{name} |
194 | glBindTexture GL_TEXTURE_2D, $_->{name} |
195 | for values %TEXTURES; |
195 | for values %TEXTURES; |
196 | $_->upload |
196 | $_->upload |
197 | for values %TEXTURES; |
197 | for values %TEXTURES; |
198 | }; |
198 | }; |
199 | |
199 | |
200 | $CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Texture"} = sub { |
200 | $CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Texture"} = sub { |
201 | $_->shutdown |
201 | $_->shutdown |
202 | for values %TEXTURES; |
202 | for values %TEXTURES; |
203 | }; |
203 | }; |
204 | |
204 | |
205 | 1; |
205 | 1; |