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.1 by root, Fri May 26 18:28:23 2006 UTC vs.
Revision 1.5 by root, Wed Jun 14 16:20:23 2006 UTC

122 unless ($tw > 0 && $th > 0) { 122 unless ($tw > 0 && $th > 0) {
123 $tw = $th = 1; 123 $tw = $th = 1;
124 $data = "\x00" x 64; 124 $data = "\x00" x 64;
125 } 125 }
126 126
127 $self->{minified} = [CFClient::average $tw, $th, $data] 127 $self->{minified} ||= [CFClient::average $tw, $th, $data]
128 if $self->{minify}; 128 if $self->{minify};
129 129
130 unless ($GL_NPOT) { 130 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 131
143 $self->{s} = $self->{w} / $tw; 132 $self->{s} = $self->{w} / $tw;
144 $self->{t} = $self->{h} / $th; 133 $self->{t} = $self->{h} / $th;
145 134
146 $self->{name} ||= glGenTexture; 135 $self->{name} ||= glGenTexture;
147 136
148 glBindTexture GL_TEXTURE_2D, $self->{name}; 137 glBindTexture GL_TEXTURE_2D, $self->{name};
149 138
139 if ($self->{wrap}) {
150 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 140 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
151 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 141 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
142 } else {
143 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, $GL_VERSION >= 1.2 ? GL_CLAMP_TO_EDGE : GL_CLAMP;
144 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, $GL_VERSION >= 1.2 ? GL_CLAMP_TO_EDGE : GL_CLAMP;
145 }
152 146
153 if ($::FAST) { 147 if ($::FAST) {
154 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; 148 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
155 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST; 149 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;
156 } elsif ($self->{mipmap} && $GL_VERSION >= 1.4) { 150 } elsif ($self->{mipmap} && $GL_VERSION >= 1.4) {
157 # alternatively check for 0x8191
158 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1; 151 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1;
159 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 152 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
160 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR; 153 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR;
161 } else { 154 } else {
162 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap}; 155 glTexParameter GL_TEXTURE_2D, GL_GENERATE_MIPMAP, $self->{mipmap};
183 $tw, $th, 176 $tw, $th,
184 0; 177 0;
185 gl_check "copying to texture %dx%d if=%x", 178 gl_check "copying to texture %dx%d if=%x",
186 $tw, $th, $self->{internalformat}; 179 $tw, $th, $self->{internalformat};
187 } 180 }
188
189 glBindTexture GL_TEXTURE_2D, 0; # just to be on the safe side
190} 181}
191 182
192sub DESTROY { 183sub DESTROY {
193 my ($self) = @_; 184 my ($self) = @_;
194 185

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines