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.2 by root, Mon May 29 02:01:56 2006 UTC vs.
Revision 1.6 by root, Wed Jun 14 18:59:31 2006 UTC

87 my ($class, $w, $h, $cb) = @_; 87 my ($class, $w, $h, $cb) = @_;
88 88
89 $class->new (w => $w || 1, h => $h || 1, render_cb => $cb) 89 $class->new (w => $w || 1, h => $h || 1, render_cb => $cb)
90} 90}
91 91
92sub topot {
93 (grep $_ >= $_[0], 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768)[0]
94}
95
96sub upload { 92sub upload {
97 my ($self) = @_; 93 my ($self) = @_;
98 94
99 return unless $GL_VERSION; 95 return unless $GL_VERSION;
100 96
117 = CFClient::load_image_inline $self->{image}; 113 = CFClient::load_image_inline $self->{image};
118 } 114 }
119 115
120 my ($tw, $th) = @$self{qw(w h)}; 116 my ($tw, $th) = @$self{qw(w h)};
121 117
122 unless ($tw > 0 && $th > 0) {
123 $tw = $th = 1;
124 $data = "\x00" x 64;
125 }
126
127 $self->{minified} = [CFClient::average $tw, $th, $data] 118 $self->{minified} ||= [CFClient::average $tw, $th, $data]
128 if $self->{minify}; 119 if $self->{minify};
129 120
130 unless ($GL_NPOT) { 121 pad2pot $data, $tw, $th unless $GL_NPOT;
131 # TODO: does not work for zero-sized textures
132 $tw = topot $tw;
133 $th = topot $th;
134
135 if (($tw != $self->{w} || $th != $self->{h}) && defined $data) {
136 my $bpp = (length $data) / ($self->{w} * $self->{h});
137 $data = pack "(a" . ($tw * $bpp) . ")*",
138 unpack "(a" . ($self->{w} * $bpp) . ")*", $data;
139 $data .= ("\x00" x ($tw * $bpp)) x ($th - $self->{h});
140 }
141 }
142 122
143 $self->{s} = $self->{w} / $tw; 123 $self->{s} = $self->{w} / $tw;
144 $self->{t} = $self->{h} / $th; 124 $self->{t} = $self->{h} / $th;
145 125
146 $self->{name} ||= glGenTexture; 126 $self->{name} ||= glGenTexture;
157 137
158 if ($::FAST) { 138 if ($::FAST) {
159 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; 139 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
160 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST; 140 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;
161 } elsif ($self->{mipmap} && $GL_VERSION >= 1.4) { 141 } elsif ($self->{mipmap} && $GL_VERSION >= 1.4) {
162 # alternatively check for 0x8191
163 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1; 142 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1;
164 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 143 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
165 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR; 144 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR;
166 } else { 145 } else {
167 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap}; 146 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap};
188 $tw, $th, 167 $tw, $th,
189 0; 168 0;
190 gl_check "copying to texture %dx%d if=%x", 169 gl_check "copying to texture %dx%d if=%x",
191 $tw, $th, $self->{internalformat}; 170 $tw, $th, $self->{internalformat};
192 } 171 }
193
194 glBindTexture GL_TEXTURE_2D, 0; # just to be on the safe side
195} 172}
196 173
197sub DESTROY { 174sub DESTROY {
198 my ($self) = @_; 175 my ($self) = @_;
199 176

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines