ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.43 by root, Fri Apr 21 07:19:56 2006 UTC vs.
Revision 1.57 by root, Sun May 21 00:02:00 2006 UTC

20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "CFClient", $VERSION; 21 XSLoader::load "CFClient", $VERSION;
22} 22}
23 23
24use Carp (); 24use Carp ();
25use AnyEvent; 25use AnyEvent ();
26use BerkeleyDB; 26use BerkeleyDB;
27
27use CFClient::OpenGL; 28use CFClient::OpenGL;
28 29
29our %GL_EXT; 30our %GL_EXT;
30our $GL_VERSION; 31our $GL_VERSION;
31 32
32our $GL_NPOT; 33our $GL_NPOT;
34our $GL_DEBUG = 1;
33 35
34sub gl_init { 36sub gl_init {
35 $GL_VERSION = gl_version * 1; 37 $GL_VERSION = gl_version * 1;
36 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; 38 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions;
37 39
38 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; 40 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2;
39 41
40 glEnable GL_TEXTURE_2D;
41 glEnable GL_COLOR_MATERIAL; 42 glDisable GL_COLOR_MATERIAL;
42 glShadeModel GL_FLAT; 43 glShadeModel GL_FLAT;
44 glDisable GL_DITHER;
43 glDisable GL_DEPTH_TEST; 45 glDisable GL_DEPTH_TEST;
44 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 46 glDepthMask 0;
45
46 glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST; 47 glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST;
47 48
48 CFClient::Texture::restore_state (); 49 CFClient::Texture::restore_state ();
50}
51
52sub gl_check {
53 return unless $GL_DEBUG;
54
55 if (my $error = glGetError) {
56 Carp::cluck sprintf "opengl error %x while %s", $error, &sprintf(@_);
57 }
49} 58}
50 59
51sub find_rcfile($) { 60sub find_rcfile($) {
52 my $path; 61 my $path;
53 62
54 for (@INC) { 63 for (grep !ref, @INC) {
55 $path = "$_/CFClient/resources/$_[0]"; 64 $path = "$_/CFClient/resources/$_[0]";
56 return $path if -r $path; 65 return $path if -r $path;
57 } 66 }
58 67
59 die "FATAL: can't find required file $_[0]\n"; 68 die "FATAL: can't find required file $_[0]\n";
110 new CFClient::Database 119 new CFClient::Database
111 -Env => $DB_ENV, 120 -Env => $DB_ENV,
112 -Filename => $table, 121 -Filename => $table,
113# -Filename => "database", 122# -Filename => "database",
114# -Subname => $table, 123# -Subname => $table,
124 -Property => DB_CHKSUM,
115 -Flags => DB_CREATE | DB_UPGRADE, 125 -Flags => DB_CREATE | DB_UPGRADE,
116 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
129sub pod_to_pango($) {
130 my ($pom) = @_;
131
132 $pom->present ("CFClient::PodToPango")
133}
134
135package CFClient::PodToPango;
136
137use base Pod::POM::View::Text;
138
139our $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
148sub view_seq_text {
149 my $text = $_[1];
150 $text =~ s/\s+/ /g;
151 CFClient::UI::Label::escape ($text)
152}
153
154sub view_item {
155 ("\t" x ($indent / 4))
156 . $_[1]->title->present ($_[0])
157 . "\n"
158 . $_[1]->content->present ($_[0])
159}
160
161sub view_verbatim {
162 (join "",
163 map +("\t" x ($indent / 2)) . "$_\n",
164 split /\n/, CFClient::UI::Label::escape ($_[1]))
165 . "\n"
166}
167
168sub view_textblock {
169 ("\t" x ($indent / 2)) . "$_[1]\n\n"
170}
171
172sub view_head2 {
173 "<big>" . $_[1]->title->present ($_[0]) . "</big>\n\n"
174 . $_[1]->content->present ($_[0])
175};
176
177sub view_over {
178 local $indent = $indent + $_[1]->indent;
179 $_[1]->content->present ($_[0])
117} 180}
118 181
119package CFClient::Database; 182package CFClient::Database;
120 183
121our @ISA = BerkeleyDB::Btree::; 184our @ISA = BerkeleyDB::Btree::;
194#} 257#}
195 258
196sub new_from_layout { 259sub new_from_layout {
197 my ($class, $layout, %arg) = @_; 260 my ($class, $layout, %arg) = @_;
198 261
199 my ($w, $h, $data) = $layout->render; 262 my ($w, $h, $data, $format, $internalformat) = $layout->render;
200 263
201 $class->new ( 264 $class->new (
202 w => $w, 265 w => $w,
203 h => $h, 266 h => $h,
204 data => $data, 267 data => $data,
205 internalformat => GL_ALPHA4,
206 format => GL_ALPHA, 268 format => $format,
269 internalformat => $format,
207 type => GL_UNSIGNED_BYTE, 270 type => GL_UNSIGNED_BYTE,
208 %arg, 271 %arg,
209 ) 272 )
210} 273}
211 274
212sub new_from_opengl { 275sub new_from_opengl {
213 my ($class, $w, $h, $cb) = @_; 276 my ($class, $w, $h, $cb) = @_;
214 277
215 $class->new (w => $w, h => $h, render_cb => $cb) 278 $class->new (w => $w || 1, h => $h || 1, render_cb => $cb)
216} 279}
217 280
218sub topot { 281sub topot {
219 (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0] 282 (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0]
220} 283}
243 = CFClient::load_image_inline $self->{image}; 306 = CFClient::load_image_inline $self->{image};
244 } 307 }
245 308
246 my ($tw, $th) = @$self{qw(w h)}; 309 my ($tw, $th) = @$self{qw(w h)};
247 310
248 unless ($tw && $th) { 311 unless ($tw > 0 && $th > 0) {
249 $tw = $th = 1; 312 $tw = $th = 1;
250 $data = "\x00" x 64; 313 $data = "\x00" x 64;
251 } 314 }
252 315
253 $self->{minified} = [CFClient::average $tw, $th, $data] 316 $self->{minified} = [CFClient::average $tw, $th, $data]
267 } 330 }
268 331
269 $self->{s} = $self->{w} / $tw; 332 $self->{s} = $self->{w} / $tw;
270 $self->{t} = $self->{h} / $th; 333 $self->{t} = $self->{h} / $th;
271 334
272 glGetError;
273
274 $self->{name} ||= glGenTexture; 335 $self->{name} ||= glGenTexture;
275 336
276 glBindTexture GL_TEXTURE_2D, $self->{name}; 337 glBindTexture GL_TEXTURE_2D, $self->{name};
277 338
278 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 339 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
279 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 340 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
280 341
281 if ($::FAST) { 342 if ($::FAST) {
282 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; 343 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
283 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST; 344 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;
345 } elsif ($self->{mipmap} && $GL_VERSION >= 1.4) {
346 # alternatively check for 0x8191
347 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1;
348 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
349 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR;
284 } else { 350 } else {
285 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap}; 351 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap};
286 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 352 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
287 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $self->{mipmap} ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; 353 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;
288 } 354 }
289 355
356 glGetError;
357
290 if (defined $data) { 358 if (defined $data) {
291 glTexImage2D GL_TEXTURE_2D, 0, 359 glTexImage2D GL_TEXTURE_2D, 0,
292 $self->{internalformat}, 360 $self->{internalformat},
293 $tw, $th, # need to pad texture first 361 $tw, $th,
294 0, 362 0,
295 $self->{format}, 363 $self->{format},
296 $self->{type}, 364 $self->{type},
297 $data; 365 $data;
298 if (my $error = glGetError) { 366 CFClient::gl_check "uploading texture %dx%d if=%x f=%x t=%x",
299 Carp::cluck sprintf "texture upload error: %x %dx%d i=%x f=%x t=%x",
300 $error, $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; 367 $tw, $th, $self->{internalformat}, $self->{format}, $self->{type};
301 }
302 } else { 368 } else {
303 glCopyTexImage2D GL_TEXTURE_2D, 0, 369 glCopyTexImage2D GL_TEXTURE_2D, 0,
304 $self->{internalformat}, 370 $self->{internalformat},
305 0, 0, 371 0, 0,
306 $tw, $th, 372 $tw, $th,
307 0; 373 0;
308 if (my $error = glGetError) { 374 CFClient::gl_check "copying to texture %dx%d if=%x",
309 Carp::cluck sprintf "texture upload error: %x %dx%d i=%x",
310 $error, $tw, $th, $self->{internalformat}; 375 $tw, $th, $self->{internalformat};
311 }
312 } 376 }
377
378 glBindTexture GL_TEXTURE_2D, 0; # just to be on the safe side
313} 379}
314 380
315sub DESTROY { 381sub DESTROY {
316 my ($self) = @_; 382 my ($self) = @_;
317 383
319 385
320 glDeleteTexture delete $self->{name} 386 glDeleteTexture delete $self->{name}
321 if $self->{name}; 387 if $self->{name};
322} 388}
323 389
324sub restore_state{ 390sub restore_state {
325 $_->upload 391 $_->upload
326 for values %TEXTURES; 392 for values %TEXTURES;
327}; 393}
328 394
3291; 3951;
330 396
331=back 397=back
332 398

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines