Revision 392e16fd
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/save/SaveRenderer.java | ||
---|---|---|
54 | 54 |
{ |
55 | 55 |
private GLSurfaceView mView; |
56 | 56 |
private DistortedTexture mGirl; |
57 |
private DistortedEffectQueues mQueues;
|
|
57 |
private DistortedEffectQueues mEffects;
|
|
58 | 58 |
private GridFlat mGrid; |
59 |
private DistortedFramebuffer mOffscreen; |
|
59 |
private DistortedFramebuffer mScreen, mOffscreen;
|
|
60 | 60 |
private Static1D s0; |
61 | 61 |
private Dynamic3D mScaleDyn; |
62 | 62 |
private Static3D mScaleFactor; |
... | ... | |
91 | 91 |
mScaleFactor = new Static3D(mScale,mScale,1.0f); |
92 | 92 |
mScaleDyn.add(mScaleFactor); |
93 | 93 |
|
94 |
mQueues = new DistortedEffectQueues(); |
|
95 |
mQueues.sink( diSink, pLeft , sinkRegion); |
|
96 |
mQueues.sink( diSink, pRight, sinkRegion); |
|
94 |
mEffects = new DistortedEffectQueues(); |
|
95 |
mEffects.sink( diSink, pLeft , sinkRegion); |
|
96 |
mEffects.sink( diSink, pRight, sinkRegion); |
|
97 |
|
|
98 |
mScreen = new DistortedFramebuffer(0); |
|
97 | 99 |
} |
98 | 100 |
|
99 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
152 | 154 |
|
153 | 155 |
if( isSaving ) // render to an offscreen buffer and read pixels |
154 | 156 |
{ |
155 |
mQueues.abortEffects(EffectTypes.MATRIX);
|
|
156 |
mQueues.scale(mScaleFactor);
|
|
157 |
mQueues.draw(time, mGirl, mGrid, mOffscreen);
|
|
157 |
mEffects.abortEffects(EffectTypes.MATRIX);
|
|
158 |
mEffects.scale(mScaleFactor);
|
|
159 |
mEffects.draw(time, mGirl, mGrid, mOffscreen);
|
|
158 | 160 |
applyMatrixEffects(scrWidth,scrHeight); |
159 | 161 |
|
160 | 162 |
int fW =(int)(mScale*bmpWidth); |
... | ... | |
178 | 180 |
isSaving = false; |
179 | 181 |
} |
180 | 182 |
|
181 |
mQueues.draw(time, mGirl, mGrid);
|
|
183 |
mEffects.draw(time, mGirl, mGrid, mScreen);
|
|
182 | 184 |
} |
183 | 185 |
|
184 | 186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
185 | 187 |
|
186 | 188 |
private void applyMatrixEffects(int width, int height) |
187 | 189 |
{ |
188 |
mQueues.abortEffects(EffectTypes.MATRIX);
|
|
190 |
mEffects.abortEffects(EffectTypes.MATRIX);
|
|
189 | 191 |
|
190 | 192 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
191 | 193 |
{ |
192 | 194 |
int w = (height*bmpWidth)/bmpHeight; |
193 | 195 |
float factor = (float)height/bmpHeight; |
194 | 196 |
|
195 |
mQueues.move( new Static3D((width-w)/2,0,0) );
|
|
196 |
mQueues.scale(factor);
|
|
197 |
mEffects.move( new Static3D((width-w)/2,0,0) );
|
|
198 |
mEffects.scale(factor);
|
|
197 | 199 |
} |
198 | 200 |
else |
199 | 201 |
{ |
200 | 202 |
int h = (width*bmpHeight)/bmpWidth; |
201 | 203 |
float factor = (float)width/bmpWidth; |
202 | 204 |
|
203 |
mQueues.move( new Static3D(0,(height-h)/2,0) );
|
|
204 |
mQueues.scale(factor);
|
|
205 |
mEffects.move( new Static3D(0,(height-h)/2,0) );
|
|
206 |
mEffects.scale(factor);
|
|
205 | 207 |
} |
206 | 208 |
|
207 |
mQueues.scale(mScaleDyn);
|
|
209 |
mEffects.scale(mScaleDyn);
|
|
208 | 210 |
} |
209 | 211 |
|
210 | 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
214 | 216 |
scrWidth = width; |
215 | 217 |
scrHeight= height; |
216 | 218 |
applyMatrixEffects(width, height); |
217 |
Distorted.onSurfaceChanged(width, height);
|
|
219 |
mScreen.resize(width, height);
|
|
218 | 220 |
} |
219 | 221 |
|
220 | 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Change in the API: we always have to create a DistortedFramebuffer to render to.