Revision b0ebdf5e
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
---|---|---|
79 | 79 |
private float mRadius; |
80 | 80 |
|
81 | 81 |
private EffectNames mMode = EffectNames.DISTORT; |
82 |
private boolean bitmapCreated = false; |
|
83 | 82 |
private long mLastEffect = -1; |
84 | 83 |
|
85 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
168 | 167 |
mRegion.set3(mRadius*scrWidth); |
169 | 168 |
} |
170 | 169 |
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
|
|
173 |
public void onPause() |
|
174 |
{ |
|
175 |
bitmapCreated = false; |
|
176 |
} |
|
177 |
|
|
178 | 170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
179 | 171 |
|
180 | 172 |
public void onDrawFrame(GL10 glUnused) |
... | ... | |
200 | 192 |
|
201 | 193 |
mRegion.set3(mRadius*scrWidth); |
202 | 194 |
|
203 |
if( !bitmapCreated ) |
|
204 |
{ |
|
205 |
createBitmap(scrWidth/2,scrHeight/2); |
|
206 |
stretchEffects.abortAllEffects(); |
|
207 |
fpsEffects.abortAllEffects(); |
|
208 |
stretchEffects.move( new Static3D(scrWidth/4,scrHeight/4,0) ); |
|
209 |
fpsEffects.move( new Static3D(5,5,0) ); |
|
210 |
bitmapCreated=true; |
|
211 |
|
|
212 |
mScreen.detachAll(); |
|
213 |
mScreen.attach(stretchTexture,stretchEffects,stretchMesh); |
|
214 |
mScreen.attach(fpsTexture,fpsEffects,fpsMesh); |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
stretchEffects.abortEffects(EffectTypes.VERTEX); |
|
219 |
stretchEffects.abortEffects(EffectTypes.FRAGMENT); |
|
220 |
stretchEffects.abortEffects(EffectNames.SHEAR); |
|
221 |
} |
|
222 |
|
|
223 |
mScreen.resize(width, height); |
|
224 |
} |
|
225 |
|
|
226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
227 |
|
|
228 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
229 |
{ |
|
230 |
DistortedEffects.enableEffect(EffectNames.DISTORT); |
|
231 |
DistortedEffects.enableEffect(EffectNames.DEFORM); |
|
232 |
|
|
233 |
try |
|
234 |
{ |
|
235 |
Distorted.onCreate(mView.getContext()); |
|
236 |
} |
|
237 |
catch(Exception ex) |
|
238 |
{ |
|
239 |
android.util.Log.e("DeformRenderer", ex.toString() ); |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
244 |
|
|
245 |
private void createBitmap(int w, int h) |
|
246 |
{ |
|
247 | 195 |
Canvas stretchCanvas; |
248 |
|
|
249 |
stretchTexture = new DistortedTexture(w,h); |
|
196 |
int w=width/2; |
|
197 |
int h=height/2; |
|
198 |
|
|
250 | 199 |
stretchMesh = new MeshFlat(50,50*h/w); |
251 | 200 |
Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888); |
252 | 201 |
stretchCanvas = new Canvas(stretchBitmap); |
253 |
|
|
202 |
|
|
254 | 203 |
fpsW = scrWidth/5; |
255 | 204 |
fpsH = fpsW/2; |
256 | 205 |
|
... | ... | |
259 | 208 |
mPaint.setStyle(Style.FILL); |
260 | 209 |
stretchCanvas.drawRect(0, 0, w, h, mPaint); |
261 | 210 |
mPaint.setColor(0xffffffff); |
262 |
|
|
211 |
|
|
263 | 212 |
for(int i=0; i<=NUM_LINES ; i++ ) |
264 | 213 |
{ |
265 | 214 |
stretchCanvas.drawRect(w*i/NUM_LINES - 1, 0, w*i/NUM_LINES + 1, h , mPaint); |
266 | 215 |
stretchCanvas.drawRect( 0, h *i/NUM_LINES -1, w , h*i/NUM_LINES + 1, mPaint); |
267 | 216 |
} |
268 |
|
|
217 |
|
|
269 | 218 |
touchPoint= new Static3D(0,0,0); |
270 |
|
|
271 |
fpsTexture = new DistortedTexture(fpsW,fpsH); |
|
272 | 219 |
fpsMesh = new MeshFlat(1,1); |
273 | 220 |
|
274 | 221 |
fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888); |
275 | 222 |
fpsCanvas = new Canvas(fpsBitmap); |
276 |
|
|
223 |
|
|
224 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h); |
|
277 | 225 |
stretchTexture.setTexture(stretchBitmap); |
226 |
|
|
227 |
if( fpsTexture==null ) fpsTexture = new DistortedTexture(fpsW,fpsH); |
|
278 | 228 |
fpsTexture.setTexture(fpsBitmap); |
229 |
|
|
230 |
stretchEffects.abortAllEffects(); |
|
231 |
fpsEffects.abortAllEffects(); |
|
232 |
stretchEffects.move( new Static3D(scrWidth/4,scrHeight/4,0) ); |
|
233 |
fpsEffects.move( new Static3D(5,5,0) ); |
|
234 |
|
|
235 |
mScreen.detachAll(); |
|
236 |
mScreen.attach(stretchTexture,stretchEffects,stretchMesh); |
|
237 |
mScreen.attach(fpsTexture,fpsEffects,fpsMesh); |
|
238 |
|
|
239 |
mScreen.resize(width, height); |
|
240 |
} |
|
241 |
|
|
242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
243 |
|
|
244 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
245 |
{ |
|
246 |
DistortedEffects.enableEffect(EffectNames.DISTORT); |
|
247 |
DistortedEffects.enableEffect(EffectNames.DEFORM); |
|
248 |
|
|
249 |
try |
|
250 |
{ |
|
251 |
Distorted.onCreate(mView.getContext()); |
|
252 |
} |
|
253 |
catch(Exception ex) |
|
254 |
{ |
|
255 |
android.util.Log.e("DeformRenderer", ex.toString() ); |
|
256 |
} |
|
279 | 257 |
} |
280 | 258 |
|
281 | 259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Major:
1) in the Library, fix the fact that some applications (those that were creating their DistortedSurface objects outside of onSurfaceCreated or onSurfaceChanged) would not render after the activity went to background (press POWER to see that).
2) in the Apps, call the new 'Distorted.onPause()' API to fix the above problem
The above fixes the problem, but it still leaks memory if an App creates its Surface in onSurfaceCreated/Changed (precisely: it leaves the old Surface in the DistortedSurface Map). Thus
3) Fix the first 15 Apps to avoid the memory leak. Next Apps coming.