… | |
… | |
169 | |
169 | |
170 | $class->new (image => $image, %arg) |
170 | $class->new (image => $image, %arg) |
171 | } |
171 | } |
172 | |
172 | |
173 | sub new_from_file { |
173 | sub new_from_file { |
174 | my ($class, $path) = @_; |
174 | my ($class, $path, %arg) = @_; |
175 | |
175 | |
176 | open my $fh, "<:raw", $path |
176 | open my $fh, "<:raw", $path |
177 | or die "$path: $!"; |
177 | or die "$path: $!"; |
178 | |
178 | |
179 | local $/; |
179 | local $/; |
180 | $class->new_from_image (<$fh>) |
180 | $class->new_from_image (<$fh>, %arg) |
181 | } |
181 | } |
182 | |
182 | |
183 | #sub new_from_surface { |
183 | #sub new_from_surface { |
184 | # my ($class, $surface) = @_; |
184 | # my ($class, $surface) = @_; |
185 | # |
185 | # |
… | |
… | |
191 | # h => $surface->height, |
191 | # h => $surface->height, |
192 | # ) |
192 | # ) |
193 | #} |
193 | #} |
194 | |
194 | |
195 | sub new_from_layout { |
195 | sub new_from_layout { |
196 | my ($class, $layout) = @_; |
196 | my ($class, $layout, %arg) = @_; |
197 | |
197 | |
198 | my ($w, $h, $data) = $layout->render; |
198 | my ($w, $h, $data) = $layout->render; |
199 | |
199 | |
200 | $class->new ( |
200 | $class->new ( |
201 | w => $w, |
201 | w => $w, |
202 | h => $h, |
202 | h => $h, |
203 | data => $data, |
203 | data => $data, |
204 | internalformat => GL_ALPHA4, |
204 | internalformat => GL_ALPHA4, |
205 | format => GL_ALPHA, |
205 | format => GL_ALPHA, |
206 | type => GL_UNSIGNED_BYTE, |
206 | type => GL_UNSIGNED_BYTE, |
|
|
207 | %arg, |
207 | ) |
208 | ) |
208 | } |
209 | } |
209 | |
210 | |
210 | sub new_from_opengl { |
211 | sub new_from_opengl { |
211 | my ($class, $w, $h, $cb) = @_; |
212 | my ($class, $w, $h, $cb) = @_; |
… | |
… | |
271 | |
272 | |
272 | $self->{name} ||= glGenTexture; |
273 | $self->{name} ||= glGenTexture; |
273 | |
274 | |
274 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
275 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
275 | |
276 | |
276 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; |
|
|
277 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR; |
|
|
278 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
277 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
279 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
278 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
|
|
279 | |
|
|
280 | if ($::FAST) { |
|
|
281 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; |
|
|
282 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST; |
|
|
283 | } else { |
|
|
284 | glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap}; |
|
|
285 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
286 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $self->{mipmap} ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; |
|
|
287 | } |
280 | |
288 | |
281 | if (defined $data) { |
289 | if (defined $data) { |
282 | glTexImage2D GL_TEXTURE_2D, 0, |
290 | glTexImage2D GL_TEXTURE_2D, 0, |
283 | $self->{internalformat}, |
291 | $self->{internalformat}, |
284 | $tw, $th, # need to pad texture first |
292 | $tw, $th, # need to pad texture first |