… | |
… | |
121 | # $rw,$rh rendered/used size |
121 | # $rw,$rh rendered/used size |
122 | # $dw,$dh $data |
122 | # $dw,$dh $data |
123 | |
123 | |
124 | my ($data, $dw, $dh); |
124 | my ($data, $dw, $dh); |
125 | |
125 | |
126 | if (exists $self->{data}) { |
126 | if (defined $self->{data}) { |
127 | $data = $self->{data}; |
127 | $data = $self->{data}; |
128 | ($dw, $dh) = @$self{qw(w h)}; |
128 | ($dw, $dh) = @$self{qw(w h)}; |
129 | |
129 | |
130 | } elsif (exists $self->{render_cb}) { |
130 | } elsif ($self->{render_cb}) { |
131 | ($dw, $dh) = @$self{qw(w h)}; |
131 | ($dw, $dh) = @$self{qw(w h)}; |
132 | |
132 | |
133 | } elsif (exists $self->{image}) { |
133 | } elsif (defined $self->{image}) { |
134 | ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) |
134 | ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) |
135 | = CFPlus::load_image_inline $self->{image}; |
135 | = CFPlus::load_image_inline $self->{image}; |
136 | |
136 | |
137 | $self->{internalformat} ||= $internalformat; |
137 | $self->{internalformat} ||= $internalformat; |
138 | ($dw, $dh) = @$self{qw(w h)}; |
138 | ($dw, $dh) = @$self{qw(w h)}; |
139 | |
139 | |
140 | delete $self->{image} if delete $self->{delete_image}; |
140 | delete $self->{image} if delete $self->{delete_image}; |
141 | |
141 | |
142 | } elsif (exists $self->{tile}) { |
142 | } elsif (defined $self->{tile}) { |
143 | ++$self->{loading}; |
143 | ++$self->{loading}; |
144 | return CFPlus::DB::get tilecache => $self->{tile}, sub { |
144 | return CFPlus::DB::get tilecache => $self->{tile}, sub { |
145 | $self->loading_done ($_[0]); |
145 | $self->loading_done ($_[0]); |
146 | |
|
|
147 | $::MAP->set_texture ($self->{tile}, @$self{qw(name w h s t)}, @{$self->{minified}}) |
|
|
148 | if $::MAP; |
|
|
149 | $::MAPWIDGET->update |
|
|
150 | if $::MAPWIDGET; |
|
|
151 | }; |
146 | }; |
152 | |
147 | |
153 | } elsif (exists $self->{path}) { |
148 | } elsif (defined $self->{path}) { |
154 | ++$self->{loading}; |
149 | ++$self->{loading}; |
155 | return CFPlus::DB::read_file $self->{path}, sub { |
150 | return CFPlus::DB::read_file $self->{path}, sub { |
156 | $self->loading_done ($_[0]); |
151 | $self->loading_done ($_[0]); |
157 | }; |
152 | }; |
158 | |
153 | |
… | |
… | |
166 | |
161 | |
167 | $self->{minified} ||= [CFPlus::average $dw, $dh, $data] |
162 | $self->{minified} ||= [CFPlus::average $dw, $dh, $data] |
168 | if $self->{minify}; |
163 | if $self->{minify}; |
169 | |
164 | |
170 | # against rather broken cards we enforce a maximum texture size |
165 | # against rather broken cards we enforce a maximum texture size |
171 | $tw = min $MAX_W, minpot $tw; |
166 | $tw = min $MAX_W, $tw; |
172 | $th = min $MAX_H, minpot $th; |
167 | $th = min $MAX_H, $th; |
173 | |
168 | |
174 | # if only pot-textures are allowed, pot'ify tw/th |
169 | # if only pot-textures are allowed, pot'ify tw/th |
175 | unless ($GL_NPOT && 0) {#d# |
170 | unless ($GL_NPOT) { |
176 | $tw = minpot $tw; |
171 | $tw = CFPlus::minpot $tw; |
177 | $th = minpot $th; |
172 | $th = CFPlus::minpot $th; |
178 | } |
173 | } |
179 | |
174 | |
180 | # now further decrease texture size until the |
175 | # now further decrease texture size until the |
181 | # card does accept it |
176 | # card does accept it |
182 | while (!texture_valid_2d $self->{internalformat}, $tw, $th, $self->{format}, $self->{type}) { |
177 | while (!texture_valid_2d $self->{internalformat}, $tw, $th, $self->{format}, $self->{type}) { |
… | |
… | |
296 | $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; |
291 | $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; |
297 | } |
292 | } |
298 | |
293 | |
299 | $self->{s} = $rw / $tw; |
294 | $self->{s} = $rw / $tw; |
300 | $self->{t} = $rh / $th; |
295 | $self->{t} = $rh / $th; |
|
|
296 | |
|
|
297 | if ($self->{tile}) { |
|
|
298 | $::MAP->set_texture ($self->{tile}, @$self{qw(name w h s t)}, @{$self->{minified}}) |
|
|
299 | if $::MAP; |
|
|
300 | $::MAPWIDGET->update |
|
|
301 | if $::MAPWIDGET; |
|
|
302 | } |
301 | } |
303 | } |
302 | |
304 | |
303 | $_->($self) |
305 | $_->($self) |
304 | for @{ (delete $self->{upload_done}) || [] }; |
306 | for @{ (delete $self->{upload_done}) || [] }; |
305 | } |
307 | } |