… | |
… | |
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 $render; |
|
|
146 | |
144 | if ($self->{render_cb}) { |
147 | if ($self->{render_cb}) { |
145 | # use only part of the texture |
148 | # use only part of the texture |
146 | #$rw >>= 1 while $rw > $tw; |
149 | #$rw >>= 1 while $rw > $tw; |
147 | #$rh >>= 1 while $rh > $th; |
150 | #$rh >>= 1 while $rh > $th; |
148 | $rw = min $rw, $tw; |
151 | $rw = min $dw, $tw; |
149 | $rh = min $rh, $th; |
152 | $rh = min $dh, $th; |
|
|
153 | ++$render; |
150 | } else { |
154 | } else { |
151 | if ($self->{wrap} || $tw < $dw || $th < $dh) { |
155 | if ($self->{wrap} || $tw < $dw || $th < $dh) { |
152 | # scale to the full texture size |
156 | # scale to the full texture size |
153 | ($rw, $rh) = ($tw, $th); |
157 | ($rw, $rh) = ($tw, $th); |
|
|
158 | ++$render; |
154 | } else { |
159 | } else { |
155 | # pad |
160 | # pad |
156 | pad $data, $dw, $dh, $tw, $th; |
161 | pad $data, $dw, $dh, $tw, $th; |
157 | ($rw, $rh) = ($dw, $dh); |
162 | ($rw, $rh) = ($dw, $dh); |
158 | ($dw, $dh) = ($tw, $th); |
163 | ($dw, $dh) = ($tw, $th); |
159 | } |
164 | } |
160 | } |
165 | } |
161 | |
166 | |
162 | # rendering means we need to scale in some way |
|
|
163 | my $render = $self->{render_cb} || $rw != $dw || $th != $dh; |
|
|
164 | |
|
|
165 | if ($render) { |
167 | if ($render) { |
166 | #d#glClear 0,0,0,0; |
|
|
167 | glViewport 0, 0, $tw, $th; |
168 | glViewport 0, 0, $tw, $th; |
|
|
169 | #glScissor 0, 0, $tw, $th; |
|
|
170 | #glEnable GL_SCISSOR_TEST; |
168 | glMatrixMode GL_PROJECTION; |
171 | glMatrixMode GL_PROJECTION; |
169 | glLoadIdentity; |
172 | glLoadIdentity; |
170 | glOrtho 0, $tw, 0, $th, -10000, 10000; |
173 | glOrtho 0, $tw, 0, $th, -10000, 10000; |
171 | glMatrixMode GL_MODELVIEW; |
174 | glMatrixMode GL_MODELVIEW; |
172 | glLoadIdentity; |
175 | glLoadIdentity; |
173 | |
176 | |
174 | if ($self->{render_cb}) { |
177 | if ($self->{render_cb}) { |
175 | glScale $rw / $dw, $rh / $dh; |
178 | glScale $rw / $dw, $rh / $dh; |
176 | $self->{render_cb}->($self, $rw, $rh); |
179 | $self->{render_cb}->($self, $rw, $rh); |
177 | } else { |
180 | } else { |
|
|
181 | glClearColor 0, 0, 0, 0; |
|
|
182 | glClear GL_COLOR_BUFFER_BIT; |
178 | glPixelZoom $tw / $dw, $th / $dh; |
183 | glPixelZoom $tw / $dw, $th / $dh; |
179 | glDrawPixels $dw, $dh, |
184 | glDrawPixels $dw, $dh, |
180 | $self->{format}, |
185 | $self->{format}, |
181 | $self->{type}, |
186 | $self->{type}, |
182 | $data; |
187 | $data; |
… | |
… | |
215 | 0, 0, |
220 | 0, 0, |
216 | $tw, $th, |
221 | $tw, $th, |
217 | 0; |
222 | 0; |
218 | gl_check "copying to texture %dx%d if=%x", |
223 | gl_check "copying to texture %dx%d if=%x", |
219 | $tw, $th, $self->{internalformat}; |
224 | $tw, $th, $self->{internalformat}; |
|
|
225 | |
|
|
226 | #glDisable GL_SCISSOR_TEST; |
220 | } else { |
227 | } else { |
221 | glTexImage2D GL_TEXTURE_2D, 0, |
228 | glTexImage2D GL_TEXTURE_2D, 0, |
222 | $self->{internalformat}, |
229 | $self->{internalformat}, |
223 | $dw, $dh, |
230 | $dw, $dh, |
224 | 0, |
231 | 0, |