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.18 by root, Mon Apr 10 11:55:16 2006 UTC vs.
Revision 1.19 by root, Mon Apr 10 19:34:03 2006 UTC

17BEGIN { 17BEGIN {
18 $VERSION = '0.1'; 18 $VERSION = '0.1';
19 19
20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "Crossfire::Client", $VERSION; 21 XSLoader::load "Crossfire::Client", $VERSION;
22}
23
24our %GL_EXT;
25our $GL_VERSION;
26
27our $GL_NPOT;
28
29sub gl_init {
30 $GL_VERSION = gl_version * 1;
31 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions;
32
33 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2;
34
35 Crossfire::Client::Texture::restore_state ();
36
37# $GL_NPOT=0;#d#
22} 38}
23 39
24sub find_rcfile($) { 40sub find_rcfile($) {
25 my $path; 41 my $path;
26 42
135 my ($class, $w, $h, $cb) = @_; 151 my ($class, $w, $h, $cb) = @_;
136 152
137 $class->new (width => $w, height => $h, rendercb => $cb) 153 $class->new (width => $w, height => $h, rendercb => $cb)
138} 154}
139 155
156sub topot {
157 (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0]
158}
159
140sub upload { 160sub upload {
141 my ($self) = @_; 161 my ($self) = @_;
142 162
143 return unless $SDL::App::USING_OPENGL; 163 return unless $SDL::App::USING_OPENGL;
144 164
169 $self->{height} = $pb->get_height; 189 $self->{height} = $pb->get_height;
170 190
171 $data = $pb->get_pixels; 191 $data = $pb->get_pixels;
172 } 192 }
173 193
194 my ($tw, $th) = @$self{qw(width height)};
195
196 unless ($NPOT) {
197 $tw = topot $tw;
198 $th = topot $th;
199
200 if (defined $data) {
201 $data = pack "(a$tw)*", (unpack "(a$self->{width})*", $data);
202 $data .= ("\x00" x $tw) x ($th - $self->{height});
203 }
204 }
205
206 $self->{u} = $self->{width} / $tw;
207 $self->{v} = $self->{height} / $th;
208
174 ($self->{name}) = @{glGenTextures 1}; 209 $self->{name} ||= (glGenTextures 1)->[0];
175 210
176 glBindTexture GL_TEXTURE_2D, $self->{name}; 211 glBindTexture GL_TEXTURE_2D, $self->{name};
177 212
178 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; 213 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
179 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR; 214 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR;
182 217
183 glGetError; 218 glGetError;
184 if (defined $data) { 219 if (defined $data) {
185 glTexImage2D GL_TEXTURE_2D, 0, 220 glTexImage2D GL_TEXTURE_2D, 0,
186 $self->{internalformat}, 221 $self->{internalformat},
187 $self->{width}, $self->{height}, 222 $tw, $th, # need to pad texture first
188 0, 223 0,
189 $self->{format}, 224 $self->{format},
190 GL_UNSIGNED_BYTE, 225 GL_UNSIGNED_BYTE,
191 $data; 226 $data;
192 glGetError and die; 227 glGetError and die;
193 } else { 228 } else {
194 glCopyTexImage2D GL_TEXTURE_2D, 0, 229 glCopyTexImage2D GL_TEXTURE_2D, 0,
195 $self->{internalformat}, 230 $self->{internalformat},
196 0, 0, 231 0, 0,
197 $self->{width}, $self->{height}, 232 $tw, $th,
198 0; 233 0;
199 glPopmatrix; 234 glPopmatrix;
200 } 235 }
201} 236}
202 237
206 return unless exists $self->{name}; 241 return unless exists $self->{name};
207 242
208 glDeleteTextures delete $self->{name}; 243 glDeleteTextures delete $self->{name};
209} 244}
210 245
211push @::GL_INIT, sub { 246sub restore_state{
212 $_->upload 247 $_->upload
213 for grep $_, @textures; 248 for grep $_, @textures;
214}; 249};
215 250
2161; 2511;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines