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

Comparing deliantra/Deliantra-Client/DC/Texture.pm (file contents):
Revision 1.25 by root, Mon Aug 6 05:06:33 2007 UTC vs.
Revision 1.29 by root, Tue Dec 25 18:58:32 2007 UTC

110 if $cb; 110 if $cb;
111 111
112 return if $self->{loading}; 112 return if $self->{loading};
113 113
114 unless ($GL_VERSION) { 114 unless ($GL_VERSION) {
115 $self->{was_loaded} = 1; 115 $self->{want_upload} = -1;
116 return; 116 return;
117 } 117 }
118 118
119 unless ($self->{name}) { 119 unless ($self->{name}) {
120 # $tw,$th texture 120 # $tw,$th texture
121 # $rw,$rh rendered/used size 121 # $rw,$rh rendered/used size
122 # $dw,$dh $data 122 # $dw,$dh $data
123 123
124 my ($data, $dw, $dh); 124 my ($data, $dw, $dh);
125 125
126 if (exists $self->{data}) { 126 if (defined $self->{data}) {
127 $data = $self->{data}; 127 $data = $self->{data};
128 ($dw, $dh) = @$self{qw(w h)}; 128 ($dw, $dh) = @$self{qw(w h)};
129 129
130 } elsif (exists $self->{render_cb}) { 130 } elsif ($self->{render_cb}) {
131 ($dw, $dh) = @$self{qw(w h)}; 131 ($dw, $dh) = @$self{qw(w h)};
132 132
133 } elsif (exists $self->{image}) { 133 } elsif (defined $self->{image}) {
134 ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) 134 ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type})
135 = CFPlus::load_image_inline $self->{image}; 135 = CFPlus::load_image_inline $self->{image};
136 136
137 $self->{internalformat} ||= $internalformat; 137 $self->{internalformat} ||= $internalformat;
138 ($dw, $dh) = @$self{qw(w h)}; 138 ($dw, $dh) = @$self{qw(w h)};
139 139
140 delete $self->{image} if delete $self->{delete_image}; 140 delete $self->{image} if delete $self->{delete_image};
141 141
142 } elsif (exists $self->{tile}) { 142 } elsif (defined $self->{tile}) {
143 ++$self->{loading}; 143 ++$self->{loading};
144 return CFPlus::DB::get tilecache => $self->{tile}, sub { 144 return CFPlus::DB::get tilecache => $self->{tile}, sub {
145 $self->loading_done ($_[0]); 145 $self->loading_done ($_[0]);
146
147 $::MAP->set_texture ($self->{tile}, @$self{qw(name w h s t)}, @{$self->{minified}})
148 if $::MAP;
149 $::MAPWIDGET->update
150 if $::MAPWIDGET;
151 }; 146 };
152 147
153 } elsif (exists $self->{path}) { 148 } elsif (defined $self->{path}) {
154 ++$self->{loading}; 149 ++$self->{loading};
155 return CFPlus::DB::read_file $self->{path}, sub { 150 return CFPlus::DB::read_file $self->{path}, sub {
156 $self->loading_done ($_[0]); 151 $self->loading_done ($_[0]);
157 }; 152 };
158 153
166 161
167 $self->{minified} ||= [CFPlus::average $dw, $dh, $data] 162 $self->{minified} ||= [CFPlus::average $dw, $dh, $data]
168 if $self->{minify}; 163 if $self->{minify};
169 164
170 # against rather broken cards we enforce a maximum texture size 165 # against rather broken cards we enforce a maximum texture size
171 $tw = min $MAX_W, minpot $tw; 166 $tw = min $MAX_W, $tw;
172 $th = min $MAX_H, minpot $th; 167 $th = min $MAX_H, $th;
173 168
174 # if only pot-textures are allowed, pot'ify tw/th 169 # if only pot-textures are allowed, pot'ify tw/th
175 unless ($GL_NPOT && 0) {#d# 170 unless ($GL_NPOT) {
176 $tw = minpot $tw; 171 $tw = CFPlus::minpot $tw;
177 $th = minpot $th; 172 $th = CFPlus::minpot $th;
178 } 173 }
179 174
180 # now further decrease texture size until the 175 # now further decrease texture size until the
181 # card does accept it 176 # card does accept it
182 while (!texture_valid_2d $self->{internalformat}, $tw, $th, $self->{format}, $self->{type}) { 177 while (!texture_valid_2d $self->{internalformat}, $tw, $th, $self->{format}, $self->{type}) {
237 $data; 232 $data;
238 glPixelZoom 1, 1; 233 glPixelZoom 1, 1;
239 } 234 }
240 } 235 }
241 236
237 if ((my $name = delete $self->{want_upload}) > 0) {
238 $self->{name} = $name;
239 }
240
242 glBindTexture GL_TEXTURE_2D, $self->{name} ||= glGenTexture; 241 glBindTexture GL_TEXTURE_2D, $self->{name} ||= glGenTexture;
243 242
244 if ($self->{wrap}) { 243 if ($self->{wrap}) {
245 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 244 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
246 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 245 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
273 gl_check "copying to texture %dx%d if=%x", 272 gl_check "copying to texture %dx%d if=%x",
274 $tw, $th, $self->{internalformat}; 273 $tw, $th, $self->{internalformat};
275 274
276 #glDisable GL_SCISSOR_TEST; 275 #glDisable GL_SCISSOR_TEST;
277 } else { 276 } else {
277 my $if = $self->{internalformat};
278
279 if ($GL_COMPRESS && $::CFG->{texture_compression}) {
280 if ($if == GL_RGB) {
281 $if = GL_COMPRESSED_RGB_ARB;
282 } elsif ($if == GL_RGBA) {
283 $if = GL_COMPRESSED_RGBA_ARB;
284 }
285 }
286
278 glTexImage2D GL_TEXTURE_2D, 0, 287 glTexImage2D GL_TEXTURE_2D, 0,
279 $self->{internalformat}, 288 $if,
280 $dw, $dh, 289 $dw, $dh,
281 0, 290 0,
282 $self->{format}, 291 $self->{format},
283 $self->{type}, 292 $self->{type},
284 $data; 293 $data;
286 $tw, $th, $self->{internalformat}, $self->{format}, $self->{type}; 295 $tw, $th, $self->{internalformat}, $self->{format}, $self->{type};
287 } 296 }
288 297
289 $self->{s} = $rw / $tw; 298 $self->{s} = $rw / $tw;
290 $self->{t} = $rh / $th; 299 $self->{t} = $rh / $th;
300
301 if ($self->{tile}) {
302 $::MAP->set_texture ($self->{tile}, @$self{qw(name w h s t)}, @{$self->{minified}})
303 if $::MAP;
304 $::MAPWIDGET->update
305 if $::MAPWIDGET;
306 }
291 } 307 }
292 308
293 $_->($self) 309 $_->($self)
294 for @{ (delete $self->{upload_done}) || [] }; 310 for @{ (delete $self->{upload_done}) || [] };
295} 311}
309 $self->unload; 325 $self->unload;
310} 326}
311 327
312$CFPlus::OpenGL::INIT_HOOK{"CFPlus::Texture"} = sub { 328$CFPlus::OpenGL::INIT_HOOK{"CFPlus::Texture"} = sub {
313 for (values %TEXTURES) { 329 for (values %TEXTURES) {
314 next unless delete $_->{was_loaded}; 330 $_->upload if $_->{want_upload};
315 $_->upload;
316 } 331 }
317}; 332};
318 333
319$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Texture"} = sub { 334$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Texture"} = sub {
320 for (values %TEXTURES) { 335 for (values %TEXTURES) {
321 next unless $_->{name}; 336 next unless $_->{name};
322 $_->{was_loaded} = 1; 337 $_->{want_upload} = $_->{name};
323 $_->unload; 338 $_->unload;
324 } 339 }
325}; 340};
326 341
3271; 3421;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines