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.45 by root, Mon Apr 24 08:38:35 2006 UTC vs.
Revision 1.50 by root, Thu May 11 23:41:45 2006 UTC

28 28
29our %GL_EXT; 29our %GL_EXT;
30our $GL_VERSION; 30our $GL_VERSION;
31 31
32our $GL_NPOT; 32our $GL_NPOT;
33our $GL_DEBUG = 1;
33 34
34sub gl_init { 35sub 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
50sub 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
51sub find_rcfile($) { 58sub find_rcfile($) {
52 my $path; 59 my $path;
53 60
54 for (@INC) { 61 for (grep !ref, @INC) {
55 $path = "$_/CFClient/resources/$_[0]"; 62 $path = "$_/CFClient/resources/$_[0]";
56 return $path if -r $path; 63 return $path if -r $path;
57 } 64 }
58 65
59 die "FATAL: can't find required file $_[0]\n"; 66 die "FATAL: can't find required file $_[0]\n";
194#} 201#}
195 202
196sub new_from_layout { 203sub new_from_layout {
197 my ($class, $layout, %arg) = @_; 204 my ($class, $layout, %arg) = @_;
198 205
199 my ($w, $h, $data) = $layout->render; 206 my ($w, $h, $data, $format, $internalformat) = $layout->render;
200 207
201 $class->new ( 208 $class->new (
202 w => $w, 209 w => $w,
203 h => $h, 210 h => $h,
204 data => $data, 211 data => $data,
205 format => GL_ALPHA, 212 format => $format,
206 internalformat => GL_ALPHA, 213 internalformat => $format,
207 type => GL_UNSIGNED_BYTE, 214 type => GL_UNSIGNED_BYTE,
208 %arg, 215 %arg,
209 ) 216 )
210} 217}
211 218
212sub new_from_opengl { 219sub new_from_opengl {
213 my ($class, $w, $h, $cb) = @_; 220 my ($class, $w, $h, $cb) = @_;
214 221
215 $class->new (w => $w, h => $h, render_cb => $cb) 222 $class->new (w => $w || 1, h => $h || 1, render_cb => $cb)
216} 223}
217 224
218sub topot { 225sub topot {
219 (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0] 226 (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0]
220} 227}
243 = CFClient::load_image_inline $self->{image}; 250 = CFClient::load_image_inline $self->{image};
244 } 251 }
245 252
246 my ($tw, $th) = @$self{qw(w h)}; 253 my ($tw, $th) = @$self{qw(w h)};
247 254
248 unless ($tw && $th) { 255 unless ($tw > 0 && $th > 0) {
249 $tw = $th = 1; 256 $tw = $th = 1;
250 $data = "\x00" x 64; 257 $data = "\x00" x 64;
251 } 258 }
252 259
253 $self->{minified} = [CFClient::average $tw, $th, $data] 260 $self->{minified} = [CFClient::average $tw, $th, $data]
298 $tw, $th, # need to pad texture first 305 $tw, $th, # need to pad texture first
299 0, 306 0,
300 $self->{format}, 307 $self->{format},
301 $self->{type}, 308 $self->{type},
302 $data; 309 $data;
303 if (my $error = glGetError) { 310 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}; 311 $tw, $th, $self->{internalformat}, $self->{format}, $self->{type};
306 }
307 } else { 312 } else {
308 glCopyTexImage2D GL_TEXTURE_2D, 0, 313 glCopyTexImage2D GL_TEXTURE_2D, 0,
309 $self->{internalformat}, 314 $self->{internalformat},
310 0, 0, 315 0, 0,
311 $tw, $th, 316 $tw, $th,
312 0; 317 0;
313 if (my $error = glGetError) { 318 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}; 319 $tw, $th, $self->{internalformat};
316 }
317 } 320 }
318} 321}
319 322
320sub DESTROY { 323sub DESTROY {
321 my ($self) = @_; 324 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines