… | |
… | |
115 | |
115 | |
116 | $self |
116 | $self |
117 | } |
117 | } |
118 | |
118 | |
119 | sub new_from_image { |
119 | sub new_from_image { |
120 | my ($class, $image) = @_; |
120 | my ($class, $image, %arg) = @_; |
121 | |
121 | |
122 | $class->new (image => $image) |
122 | $class->new (image => $image, %arg) |
123 | } |
123 | } |
124 | |
124 | |
125 | sub new_from_file { |
125 | sub new_from_file { |
126 | my ($class, $path) = @_; |
126 | my ($class, $path) = @_; |
127 | |
127 | |
… | |
… | |
179 | if (exists $self->{data}) { |
179 | if (exists $self->{data}) { |
180 | $data = $self->{data}; |
180 | $data = $self->{data}; |
181 | |
181 | |
182 | } elsif (exists $self->{render_cb}) { |
182 | } elsif (exists $self->{render_cb}) { |
183 | glViewport 0, 0, $self->{w}, $self->{h}; |
183 | glViewport 0, 0, $self->{w}, $self->{h}; |
184 | glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000; |
|
|
185 | glMatrixMode GL_PROJECTION; |
184 | glMatrixMode GL_PROJECTION; |
186 | glLoadIdentity; |
185 | glLoadIdentity; |
|
|
186 | glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000; |
187 | glMatrixMode GL_MODELVIEW; |
187 | glMatrixMode GL_MODELVIEW; |
188 | glLoadIdentity; |
188 | glLoadIdentity; |
189 | glClear GL_COLOR_BUFFER_BIT; |
|
|
190 | $self->{render_cb}->($self, $self->{w}, $self->{h}); |
189 | $self->{render_cb}->($self, $self->{w}, $self->{h}); |
191 | |
190 | |
192 | } else { |
191 | } else { |
193 | ($self->{w}, $self->{h}, $data, $self->{internalformat}, $self->{format}, $self->{type}) |
192 | ($self->{w}, $self->{h}, $data, $self->{internalformat}, $self->{format}, $self->{type}) |
194 | = CFClient::load_image_inline $self->{image}; |
193 | = CFClient::load_image_inline $self->{image}; |
… | |
… | |
198 | |
197 | |
199 | unless ($tw && $th) { |
198 | unless ($tw && $th) { |
200 | $tw = $th = 1; |
199 | $tw = $th = 1; |
201 | $data = "\x00" x 64; |
200 | $data = "\x00" x 64; |
202 | } |
201 | } |
|
|
202 | |
|
|
203 | $self->{minified} = [CFClient::average $tw, $th, $data] |
|
|
204 | if $self->{minify}; |
203 | |
205 | |
204 | unless ($GL_NPOT) { |
206 | unless ($GL_NPOT) { |
205 | # TODO: does not work for zero-sized textures |
207 | # TODO: does not work for zero-sized textures |
206 | $tw = topot $tw; |
208 | $tw = topot $tw; |
207 | $th = topot $th; |
209 | $th = topot $th; |
… | |
… | |
239 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
241 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
240 | $self->{internalformat}, |
242 | $self->{internalformat}, |
241 | 0, 0, |
243 | 0, 0, |
242 | $tw, $th, |
244 | $tw, $th, |
243 | 0; |
245 | 0; |
244 | glGetError and die; |
246 | glGetError and die "glCopyTexImage2D $tw,$th"; |
245 | } |
247 | } |
246 | } |
248 | } |
247 | |
249 | |
248 | sub DESTROY { |
250 | sub DESTROY { |
249 | my ($self) = @_; |
251 | my ($self) = @_; |