… | |
… | |
20 | use XSLoader; |
20 | use XSLoader; |
21 | XSLoader::load "CFClient", $VERSION; |
21 | XSLoader::load "CFClient", $VERSION; |
22 | } |
22 | } |
23 | |
23 | |
24 | use Carp (); |
24 | use Carp (); |
25 | use AnyEvent; |
25 | use AnyEvent (); |
26 | use BerkeleyDB; |
26 | use BerkeleyDB; |
|
|
27 | |
27 | use CFClient::OpenGL; |
28 | use CFClient::OpenGL; |
28 | |
29 | |
29 | our %GL_EXT; |
30 | our %GL_EXT; |
30 | our $GL_VERSION; |
31 | our $GL_VERSION; |
31 | |
32 | |
… | |
… | |
40 | |
41 | |
41 | glDisable GL_COLOR_MATERIAL; |
42 | glDisable GL_COLOR_MATERIAL; |
42 | glShadeModel GL_FLAT; |
43 | glShadeModel GL_FLAT; |
43 | glDisable GL_DITHER; |
44 | glDisable GL_DITHER; |
44 | glDisable GL_DEPTH_TEST; |
45 | glDisable GL_DEPTH_TEST; |
|
|
46 | glDepthMask 0; |
45 | glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST; |
47 | glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST; |
46 | |
48 | |
47 | CFClient::Texture::restore_state (); |
49 | CFClient::Texture::restore_state (); |
48 | } |
50 | } |
49 | |
51 | |
50 | sub gl_check { |
52 | sub gl_check { |
51 | return unless $GL_DEBUG; |
53 | return unless $GL_DEBUG; |
52 | |
54 | |
53 | if (my $error = glGetError) { |
55 | if (my $error = glGetError) { |
54 | Carp::cluck sprintf "opengl error %x while %s", $error, sprintf @_; |
56 | Carp::cluck sprintf "opengl error %x while %s", $error, &sprintf(@_); |
55 | } |
57 | } |
56 | } |
58 | } |
57 | |
59 | |
58 | sub find_rcfile($) { |
60 | sub find_rcfile($) { |
59 | my $path; |
61 | my $path; |
… | |
… | |
117 | new CFClient::Database |
119 | new CFClient::Database |
118 | -Env => $DB_ENV, |
120 | -Env => $DB_ENV, |
119 | -Filename => $table, |
121 | -Filename => $table, |
120 | # -Filename => "database", |
122 | # -Filename => "database", |
121 | # -Subname => $table, |
123 | # -Subname => $table, |
|
|
124 | -Property => DB_CHKSUM, |
122 | -Flags => DB_CREATE | DB_UPGRADE, |
125 | -Flags => DB_CREATE | DB_UPGRADE, |
123 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; |
126 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; |
|
|
127 | } |
|
|
128 | |
|
|
129 | sub pod_to_pango($) { |
|
|
130 | my ($pom) = @_; |
|
|
131 | |
|
|
132 | $pom->present ("CFClient::PodToPango") |
|
|
133 | } |
|
|
134 | |
|
|
135 | package CFClient::PodToPango; |
|
|
136 | |
|
|
137 | use base Pod::POM::View::Text; |
|
|
138 | |
|
|
139 | our $indent = 0; |
|
|
140 | |
|
|
141 | *view_seq_code = |
|
|
142 | *view_seq_bold = sub { "<b>$_[1]</b>" }; |
|
|
143 | *view_seq_italic = sub { "<i>$_[1]</i>" }; |
|
|
144 | *view_seq_space = |
|
|
145 | *view_seq_link = |
|
|
146 | *view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) }; |
|
|
147 | |
|
|
148 | sub view_seq_text { |
|
|
149 | my $text = $_[1]; |
|
|
150 | $text =~ s/\s+/ /g; |
|
|
151 | CFClient::UI::Label::escape ($text) |
|
|
152 | } |
|
|
153 | |
|
|
154 | sub view_item { |
|
|
155 | ("\t" x ($indent / 4)) |
|
|
156 | . $_[1]->title->present ($_[0]) |
|
|
157 | . "\n" |
|
|
158 | . $_[1]->content->present ($_[0]) |
|
|
159 | } |
|
|
160 | |
|
|
161 | sub view_verbatim { |
|
|
162 | (join "", |
|
|
163 | map +("\t" x ($indent / 2)) . "$_\n", |
|
|
164 | split /\n/, CFClient::UI::Label::escape ($_[1])) |
|
|
165 | . "\n" |
|
|
166 | } |
|
|
167 | |
|
|
168 | sub view_textblock { |
|
|
169 | ("\t" x ($indent / 2)) . "$_[1]\n\n" |
|
|
170 | } |
|
|
171 | |
|
|
172 | sub view_head2 { |
|
|
173 | "<big>" . $_[1]->title->present ($_[0]) . "</big>\n\n" |
|
|
174 | . $_[1]->content->present ($_[0]) |
|
|
175 | }; |
|
|
176 | |
|
|
177 | sub view_over { |
|
|
178 | local $indent = $indent + $_[1]->indent; |
|
|
179 | $_[1]->content->present ($_[0]) |
124 | } |
180 | } |
125 | |
181 | |
126 | package CFClient::Database; |
182 | package CFClient::Database; |
127 | |
183 | |
128 | our @ISA = BerkeleyDB::Btree::; |
184 | our @ISA = BerkeleyDB::Btree::; |
… | |
… | |
201 | #} |
257 | #} |
202 | |
258 | |
203 | sub new_from_layout { |
259 | sub new_from_layout { |
204 | my ($class, $layout, %arg) = @_; |
260 | my ($class, $layout, %arg) = @_; |
205 | |
261 | |
206 | my ($w, $h, $data) = $layout->render; |
262 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
207 | |
263 | |
208 | $class->new ( |
264 | $class->new ( |
209 | w => $w, |
265 | w => $w, |
210 | h => $h, |
266 | h => $h, |
211 | data => $data, |
267 | data => $data, |
212 | format => GL_ALPHA, |
268 | format => $format, |
213 | internalformat => GL_ALPHA, |
269 | internalformat => $format, |
214 | type => GL_UNSIGNED_BYTE, |
270 | type => GL_UNSIGNED_BYTE, |
215 | %arg, |
271 | %arg, |
216 | ) |
272 | ) |
217 | } |
273 | } |
218 | |
274 | |
… | |
… | |
300 | glGetError; |
356 | glGetError; |
301 | |
357 | |
302 | if (defined $data) { |
358 | if (defined $data) { |
303 | glTexImage2D GL_TEXTURE_2D, 0, |
359 | glTexImage2D GL_TEXTURE_2D, 0, |
304 | $self->{internalformat}, |
360 | $self->{internalformat}, |
305 | $tw, $th, # need to pad texture first |
361 | $tw, $th, |
306 | 0, |
362 | 0, |
307 | $self->{format}, |
363 | $self->{format}, |
308 | $self->{type}, |
364 | $self->{type}, |
309 | $data; |
365 | $data; |
310 | CFClient::gl_check "uploading texture %dx%d if=%x f=%x t=%x", |
366 | CFClient::gl_check "uploading texture %dx%d if=%x f=%x t=%x", |
… | |
… | |
316 | $tw, $th, |
372 | $tw, $th, |
317 | 0; |
373 | 0; |
318 | CFClient::gl_check "copying to texture %dx%d if=%x", |
374 | CFClient::gl_check "copying to texture %dx%d if=%x", |
319 | $tw, $th, $self->{internalformat}; |
375 | $tw, $th, $self->{internalformat}; |
320 | } |
376 | } |
|
|
377 | |
|
|
378 | glBindTexture GL_TEXTURE_2D, 0; # just to be on the safe side |
321 | } |
379 | } |
322 | |
380 | |
323 | sub DESTROY { |
381 | sub DESTROY { |
324 | my ($self) = @_; |
382 | my ($self) = @_; |
325 | |
383 | |
… | |
… | |
327 | |
385 | |
328 | glDeleteTexture delete $self->{name} |
386 | glDeleteTexture delete $self->{name} |
329 | if $self->{name}; |
387 | if $self->{name}; |
330 | } |
388 | } |
331 | |
389 | |
332 | sub restore_state{ |
390 | sub restore_state { |
333 | $_->upload |
391 | $_->upload |
334 | for values %TEXTURES; |
392 | for values %TEXTURES; |
335 | }; |
393 | } |
336 | |
394 | |
337 | 1; |
395 | 1; |
338 | |
396 | |
339 | =back |
397 | =back |
340 | |
398 | |