… | |
… | |
140 | $th >>= 1; |
140 | $th >>= 1; |
141 | } |
141 | } |
142 | |
142 | |
143 | # decide the amount of space used in the texture |
143 | # decide the amount of space used in the texture |
144 | my ($rw, $rh); |
144 | my ($rw, $rh); |
|
|
145 | my $render; |
145 | |
146 | |
146 | if ($self->{render_cb}) { |
147 | if ($self->{render_cb}) { |
147 | # use only part of the texture |
148 | # use only part of the texture |
148 | #$rw >>= 1 while $rw > $tw; |
149 | #$rw >>= 1 while $rw > $tw; |
149 | #$rh >>= 1 while $rh > $th; |
150 | #$rh >>= 1 while $rh > $th; |
150 | $rw = min $dw, $tw; |
151 | $rw = min $dw, $tw; |
151 | $rh = min $dh, $th; |
152 | $rh = min $dh, $th; |
|
|
153 | ++$render; |
152 | } else { |
154 | } else { |
153 | if ($self->{wrap} || $tw < $dw || $th < $dh) { |
155 | if ($self->{wrap} || $tw < $dw || $th < $dh) { |
154 | # scale to the full texture size |
156 | # scale to the full texture size |
155 | ($rw, $rh) = ($tw, $th); |
157 | ($rw, $rh) = ($tw, $th); |
|
|
158 | ++$render; |
156 | } else { |
159 | } else { |
157 | # pad |
160 | # pad |
158 | pad $data, $dw, $dh, $tw, $th; |
161 | pad $data, $dw, $dh, $tw, $th; |
159 | ($rw, $rh) = ($dw, $dh); |
162 | ($rw, $rh) = ($dw, $dh); |
160 | ($dw, $dh) = ($tw, $th); |
163 | ($dw, $dh) = ($tw, $th); |
161 | } |
164 | } |
162 | } |
165 | } |
163 | |
166 | |
164 | # rendering means we need to scale in some way |
|
|
165 | my $render = $self->{render_cb} || $rw != $dw || $th != $dh; |
|
|
166 | |
|
|
167 | if ($render) { |
167 | if ($render) { |
168 | glViewport 0, 0, $tw, $th; |
168 | glViewport 0, 0, $tw, $th; |
169 | glClear 0, 0, 0, 0; |
|
|
170 | glMatrixMode GL_PROJECTION; |
169 | glMatrixMode GL_PROJECTION; |
171 | glLoadIdentity; |
170 | glLoadIdentity; |
172 | glOrtho 0, $tw, 0, $th, -10000, 10000; |
171 | glOrtho 0, $tw, 0, $th, -10000, 10000; |
173 | glMatrixMode GL_MODELVIEW; |
172 | glMatrixMode GL_MODELVIEW; |
174 | glLoadIdentity; |
173 | glLoadIdentity; |
175 | |
174 | |
176 | if ($self->{render_cb}) { |
175 | if ($self->{render_cb}) { |
177 | glScale $rw / $dw, $rh / $dh; |
176 | glScale $rw / $dw, $rh / $dh; |
178 | $self->{render_cb}->($self, $rw, $rh); |
177 | $self->{render_cb}->($self, $rw, $rh); |
179 | } else { |
178 | } else { |
|
|
179 | glClearColor 0, 0, 0, 0; |
|
|
180 | glClear GL_COLOR_BUFFER_BIT; |
180 | glPixelZoom $tw / $dw, $th / $dh; |
181 | glPixelZoom $tw / $dw, $th / $dh; |
181 | glDrawPixels $dw, $dh, |
182 | glDrawPixels $dw, $dh, |
182 | $self->{format}, |
183 | $self->{format}, |
183 | $self->{type}, |
184 | $self->{type}, |
184 | $data; |
185 | $data; |