… | |
… | |
28 | |
28 | |
29 | our %GL_EXT; |
29 | our %GL_EXT; |
30 | our $GL_VERSION; |
30 | our $GL_VERSION; |
31 | |
31 | |
32 | our $GL_NPOT; |
32 | our $GL_NPOT; |
|
|
33 | our $GL_DEBUG = 1; |
33 | |
34 | |
34 | sub gl_init { |
35 | sub gl_init { |
35 | $GL_VERSION = gl_version * 1; |
36 | $GL_VERSION = gl_version * 1; |
36 | %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; |
37 | %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; |
37 | |
38 | |
38 | $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; |
39 | $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; |
39 | |
40 | |
40 | glEnable GL_TEXTURE_2D; |
|
|
41 | glEnable GL_COLOR_MATERIAL; |
41 | glDisable GL_COLOR_MATERIAL; |
42 | glShadeModel GL_FLAT; |
42 | glShadeModel GL_FLAT; |
|
|
43 | glDisable GL_DITHER; |
43 | glDisable GL_DEPTH_TEST; |
44 | glDisable GL_DEPTH_TEST; |
44 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
45 | |
|
|
46 | glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST; |
45 | glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST; |
47 | |
46 | |
48 | CFClient::Texture::restore_state (); |
47 | CFClient::Texture::restore_state (); |
|
|
48 | } |
|
|
49 | |
|
|
50 | sub gl_check { |
|
|
51 | return unless $GL_DEBUG; |
|
|
52 | |
|
|
53 | if (my $error = glGetError) { |
|
|
54 | Carp::cluck sprintf "opengl error %x while %s", $error, sprintf @_; |
|
|
55 | } |
49 | } |
56 | } |
50 | |
57 | |
51 | sub find_rcfile($) { |
58 | sub find_rcfile($) { |
52 | my $path; |
59 | my $path; |
53 | |
60 | |
… | |
… | |
110 | new CFClient::Database |
117 | new CFClient::Database |
111 | -Env => $DB_ENV, |
118 | -Env => $DB_ENV, |
112 | -Filename => $table, |
119 | -Filename => $table, |
113 | # -Filename => "database", |
120 | # -Filename => "database", |
114 | # -Subname => $table, |
121 | # -Subname => $table, |
|
|
122 | -Property => DB_CHKSUM, |
115 | -Flags => DB_CREATE | DB_UPGRADE, |
123 | -Flags => DB_CREATE | DB_UPGRADE, |
116 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; |
124 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; |
117 | } |
125 | } |
118 | |
126 | |
119 | package CFClient::Database; |
127 | package CFClient::Database; |
… | |
… | |
194 | #} |
202 | #} |
195 | |
203 | |
196 | sub new_from_layout { |
204 | sub new_from_layout { |
197 | my ($class, $layout, %arg) = @_; |
205 | my ($class, $layout, %arg) = @_; |
198 | |
206 | |
199 | my ($w, $h, $data) = $layout->render; |
207 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
200 | |
208 | |
201 | $class->new ( |
209 | $class->new ( |
202 | w => $w, |
210 | w => $w, |
203 | h => $h, |
211 | h => $h, |
204 | data => $data, |
212 | data => $data, |
205 | format => GL_ALPHA, |
213 | format => $format, |
206 | internalformat => GL_ALPHA, |
214 | internalformat => $format, |
207 | type => GL_UNSIGNED_BYTE, |
215 | type => GL_UNSIGNED_BYTE, |
208 | %arg, |
216 | %arg, |
209 | ) |
217 | ) |
210 | } |
218 | } |
211 | |
219 | |
212 | sub new_from_opengl { |
220 | sub new_from_opengl { |
213 | my ($class, $w, $h, $cb) = @_; |
221 | my ($class, $w, $h, $cb) = @_; |
214 | |
222 | |
215 | $class->new (w => $w, h => $h, render_cb => $cb) |
223 | $class->new (w => $w || 1, h => $h || 1, render_cb => $cb) |
216 | } |
224 | } |
217 | |
225 | |
218 | sub topot { |
226 | sub topot { |
219 | (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0] |
227 | (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0] |
220 | } |
228 | } |
… | |
… | |
298 | $tw, $th, # need to pad texture first |
306 | $tw, $th, # need to pad texture first |
299 | 0, |
307 | 0, |
300 | $self->{format}, |
308 | $self->{format}, |
301 | $self->{type}, |
309 | $self->{type}, |
302 | $data; |
310 | $data; |
303 | if (my $error = glGetError) { |
311 | CFClient::gl_check "uploading texture %dx%d if=%x f=%x t=%x", |
304 | Carp::cluck sprintf "texture upload error: %x %dx%d i=%x f=%x t=%x", |
|
|
305 | $error, $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; |
312 | $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; |
306 | } |
|
|
307 | } else { |
313 | } else { |
308 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
314 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
309 | $self->{internalformat}, |
315 | $self->{internalformat}, |
310 | 0, 0, |
316 | 0, 0, |
311 | $tw, $th, |
317 | $tw, $th, |
312 | 0; |
318 | 0; |
313 | if (my $error = glGetError) { |
319 | CFClient::gl_check "copying to texture %dx%d if=%x", |
314 | Carp::cluck sprintf "texture upload error: %x %dx%d i=%x", |
|
|
315 | $error, $tw, $th, $self->{internalformat}; |
320 | $tw, $th, $self->{internalformat}; |
316 | } |
|
|
317 | } |
321 | } |
318 | } |
322 | } |
319 | |
323 | |
320 | sub DESTROY { |
324 | sub DESTROY { |
321 | my ($self) = @_; |
325 | my ($self) = @_; |