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.16 by root, Thu Jul 19 13:45:18 2007 UTC vs.
Revision 1.23 by root, Tue Jul 24 01:24:27 2007 UTC

114 $self->{internalformat} ||= $internalformat; 114 $self->{internalformat} ||= $internalformat;
115 ($dw, $dh) = @$self{qw(w h)}; 115 ($dw, $dh) = @$self{qw(w h)};
116 } 116 }
117 117
118 my ($tw, $th) = ($dw, $dh); 118 my ($tw, $th) = ($dw, $dh);
119 my ($rw, $rh) = ($dw, $dh);
120 119
121 defined $data or $self->{render_cb} or die; # some sanity check 120 defined $data or $self->{render_cb} or die; # some sanity check
122 121
123 $self->{minified} ||= [CFPlus::average $dw, $dh, $data] 122 $self->{minified} ||= [CFPlus::average $dw, $dh, $data]
124 if $self->{minify}; 123 if $self->{minify};
139 # quarter the texture size 138 # quarter the texture size
140 $tw >>= 1; 139 $tw >>= 1;
141 $th >>= 1; 140 $th >>= 1;
142 } 141 }
143 142
143 # decide the amount of space used in the texture
144 my ($rw, $rh);
145 my ($ox, $oy); # area shift to lessen effetc of buggy opengl implementations (nvida, ati)
146 my $render;
147
144 if ($self->{render_cb}) { 148 if ($self->{render_cb}) {
145 # use only part of the texture 149 # use only part of the texture
146 #$rw >>= 1 while $rw > $tw; 150 #$rw >>= 1 while $rw > $tw;
147 #$rh >>= 1 while $rh > $th; 151 #$rh >>= 1 while $rh > $th;
148 $rw = min $rw, $tw; 152 $rw = min $dw, $tw;
149 $rh = min $rh, $th; 153 $rh = min $dh, $th;
154 ++$render;
150 } else { 155 } else {
151 if ($self->{wrap} || $tw < $dw || $th < $dh) { 156 if ($self->{wrap} || $tw < $dw || $th < $dh) {
152 # scale to the full texture size 157 # scale to the full texture size
153 ($rw, $rh) = ($tw, $th); 158 ($rw, $rh) = ($tw, $th);
159 ++$render;
154 } else { 160 } else {
155 # pad 161 # pad
156 pad $data, $dw, $dh, $tw, $th; 162 pad $data, $dw, $dh, $tw, $th;
157 ($rw, $rh) = ($dw, $dh); 163 ($rw, $rh) = ($dw, $dh);
158 ($dw, $dh) = ($tw, $th); 164 ($dw, $dh) = ($tw, $th);
159 } 165 }
160 } 166 }
161 167
162 # rendering means we need to scale in some way
163 my $render = $self->{render_cb} || $rw != $dw || $th != $dh;
164
165 if ($render) { 168 if ($render) {
166 #d#glClear 0,0,0,0; 169 $ox = int .5 * ($::WIDTH - $rw);
170 $oy = int .5 * ($::HEIGHT - $rh);
171
167 glViewport 0, 0, $tw, $th; 172 glViewport $ox, $oy, $tw, $th;
173 #glScissor 0, 0, $tw, $th;
174 #glEnable GL_SCISSOR_TEST;
168 glMatrixMode GL_PROJECTION; 175 glMatrixMode GL_PROJECTION;
169 glLoadIdentity; 176 glLoadIdentity;
170 glOrtho 0, $tw, 0, $th, -10000, 10000; 177 glOrtho 0, $tw, 0, $th, -10000, 10000;
171 glMatrixMode GL_MODELVIEW; 178 glMatrixMode GL_MODELVIEW;
172 glLoadIdentity; 179 glLoadIdentity;
173 180
174 if ($self->{render_cb}) { 181 if ($self->{render_cb}) {
175 glScale $rw / $dw, $rh / $dh; 182 glScale $rw / $dw, $rh / $dh;
176 $self->{render_cb}->($self, $rw, $rh); 183 $self->{render_cb}->($self, $rw, $rh);
177 } else { 184 } else {
185 glClearColor 0, 0, 0, 0;
186 glClear GL_COLOR_BUFFER_BIT;
178 glPixelZoom $tw / $dw, $th / $dh; 187 glPixelZoom $tw / $dw, $th / $dh;
188 glRasterPos 0, 0;
179 glDrawPixels $dw, $dh, 189 glDrawPixels $dw, $dh,
180 $self->{format}, 190 $self->{format},
181 $self->{type}, 191 $self->{type},
182 $data; 192 $data;
183 glPixelZoom 1, 1; 193 glPixelZoom 1, 1;
210 glGetError; 220 glGetError;
211 221
212 if ($render) { 222 if ($render) {
213 glCopyTexImage2D GL_TEXTURE_2D, 0, 223 glCopyTexImage2D GL_TEXTURE_2D, 0,
214 $self->{internalformat}, 224 $self->{internalformat},
215 0, 0, 225 $ox, $oy,
216 $tw, $th, 226 $tw, $th,
217 0; 227 0;
218 gl_check "copying to texture %dx%d if=%x", 228 gl_check "copying to texture %dx%d if=%x",
219 $tw, $th, $self->{internalformat}; 229 $tw, $th, $self->{internalformat};
230
231 #glDisable GL_SCISSOR_TEST;
220 } else { 232 } else {
221 glTexImage2D GL_TEXTURE_2D, 0, 233 glTexImage2D GL_TEXTURE_2D, 0,
222 $self->{internalformat}, 234 $self->{internalformat},
223 $dw, $dh, 235 $dw, $dh,
224 0, 236 0,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines