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.41 by root, Wed Apr 19 23:37:48 2006 UTC vs.
Revision 1.44 by root, Mon Apr 24 08:22:20 2006 UTC

19 19
20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "CFClient", $VERSION; 21 XSLoader::load "CFClient", $VERSION;
22} 22}
23 23
24use Carp ();
24use AnyEvent; 25use AnyEvent;
25use BerkeleyDB; 26use BerkeleyDB;
26use CFClient::OpenGL; 27use CFClient::OpenGL;
27 28
28our %GL_EXT; 29our %GL_EXT;
169 170
170 $class->new (image => $image, %arg) 171 $class->new (image => $image, %arg)
171} 172}
172 173
173sub new_from_file { 174sub new_from_file {
174 my ($class, $path) = @_; 175 my ($class, $path, %arg) = @_;
175 176
176 open my $fh, "<:raw", $path 177 open my $fh, "<:raw", $path
177 or die "$path: $!"; 178 or die "$path: $!";
178 179
179 local $/; 180 local $/;
180 $class->new_from_image (<$fh>) 181 $class->new_from_image (<$fh>, %arg)
181} 182}
182 183
183#sub new_from_surface { 184#sub new_from_surface {
184# my ($class, $surface) = @_; 185# my ($class, $surface) = @_;
185# 186#
191# h => $surface->height, 192# h => $surface->height,
192# ) 193# )
193#} 194#}
194 195
195sub new_from_layout { 196sub new_from_layout {
196 my ($class, $layout) = @_; 197 my ($class, $layout, %arg) = @_;
197 198
198 my ($w, $h, $data) = $layout->render; 199 my ($w, $h, $data) = $layout->render;
199 200
200 $class->new ( 201 $class->new (
201 w => $w, 202 w => $w,
202 h => $h, 203 h => $h,
203 data => $data, 204 data => $data,
204 internalformat => GL_ALPHA4,
205 format => GL_ALPHA, 205 format => GL_ALPHA,
206 internalformat => GL_ALPHA,
206 type => GL_UNSIGNED_BYTE, 207 type => GL_UNSIGNED_BYTE,
208 %arg,
207 ) 209 )
208} 210}
209 211
210sub new_from_opengl { 212sub new_from_opengl {
211 my ($class, $w, $h, $cb) = @_; 213 my ($class, $w, $h, $cb) = @_;
254 unless ($GL_NPOT) { 256 unless ($GL_NPOT) {
255 # TODO: does not work for zero-sized textures 257 # TODO: does not work for zero-sized textures
256 $tw = topot $tw; 258 $tw = topot $tw;
257 $th = topot $th; 259 $th = topot $th;
258 260
259 if ($tw != $self->{w} || $th != $self->{h} && defined $data) { 261 if (($tw != $self->{w} || $th != $self->{h}) && defined $data) {
260 my $bpp = (length $data) / ($self->{w} * $self->{h}); 262 my $bpp = (length $data) / ($self->{w} * $self->{h});
261 $data = pack "(a" . ($tw * $bpp) . ")*", 263 $data = pack "(a" . ($tw * $bpp) . ")*",
262 unpack "(a" . ($self->{w} * $bpp) . ")*", $data; 264 unpack "(a" . ($self->{w} * $bpp) . ")*", $data;
263 $data .= ("\x00" x ($tw * $bpp)) x ($th - $self->{h}); 265 $data .= ("\x00" x ($tw * $bpp)) x ($th - $self->{h});
264 } 266 }
271 273
272 $self->{name} ||= glGenTexture; 274 $self->{name} ||= glGenTexture;
273 275
274 glBindTexture GL_TEXTURE_2D, $self->{name}; 276 glBindTexture GL_TEXTURE_2D, $self->{name};
275 277
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; 278 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
279 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 279 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
280
281 if ($::FAST) {
282 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
283 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;
284 } else {
285 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap};
286 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;
288 }
280 289
281 if (defined $data) { 290 if (defined $data) {
282 glTexImage2D GL_TEXTURE_2D, 0, 291 glTexImage2D GL_TEXTURE_2D, 0,
283 $self->{internalformat}, 292 $self->{internalformat},
284 $tw, $th, # need to pad texture first 293 $tw, $th, # need to pad texture first
285 0, 294 0,
286 $self->{format}, 295 $self->{format},
287 $self->{type}, 296 $self->{type},
288 $data; 297 $data;
289 if (my $error = glGetError) { 298 if (my $error = glGetError) {
290 warn sprintf "texture upload error: %x %dx%d i=%x f=%x t=%x\n", 299 Carp::cluck sprintf "texture upload error: %x %dx%d i=%x f=%x t=%x",
291 $error, $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; 300 $error, $tw, $th, $self->{internalformat}, $self->{format}, $self->{type};
292 } 301 }
293 } else { 302 } else {
294 glCopyTexImage2D GL_TEXTURE_2D, 0, 303 glCopyTexImage2D GL_TEXTURE_2D, 0,
295 $self->{internalformat}, 304 $self->{internalformat},
296 0, 0, 305 0, 0,
297 $tw, $th, 306 $tw, $th,
298 0; 307 0;
299 glGetError and die "glCopyTexImage2D $tw,$th"; 308 if (my $error = glGetError) {
309 Carp::cluck sprintf "texture upload error: %x %dx%d i=%x",
310 $error, $tw, $th, $self->{internalformat};
311 }
300 } 312 }
301} 313}
302 314
303sub DESTROY { 315sub DESTROY {
304 my ($self) = @_; 316 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines