Revision b0ebdf5e
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/examples/projection/ProjectionRenderer.java | ||
---|---|---|
35 | 35 |
import android.graphics.Canvas; |
36 | 36 |
import android.graphics.Paint; |
37 | 37 |
import android.graphics.Paint.Style; |
38 |
import android.opengl.GLES30; |
|
39 | 38 |
import android.opengl.GLSurfaceView; |
40 | 39 |
|
41 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
45 | 44 |
private GLSurfaceView mView; |
46 | 45 |
private DistortedEffects mEffects; |
47 | 46 |
private DistortedScreen mScreen; |
48 |
|
|
47 |
private DistortedTexture mTexture; |
|
49 | 48 |
private float mF, mNear; |
50 | 49 |
|
51 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
90 | 89 |
mEffects.abortAllEffects(); |
91 | 90 |
|
92 | 91 |
Paint paint = new Paint(); |
93 |
DistortedTexture texture= new DistortedTexture(width,height); |
|
94 |
MeshFlat mesh = new MeshFlat(50,50*height/width); |
|
95 | 92 |
Bitmap bmp = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888); |
96 | 93 |
Canvas bmpCanvas = new Canvas(bmp); |
97 | 94 |
|
... | ... | |
108 | 105 |
bmpCanvas.drawRect( 0, height*i/NUMLINES -1, width , height*i/NUMLINES + 1, paint); |
109 | 106 |
} |
110 | 107 |
|
111 |
texture.setTexture(bmp); |
|
112 |
|
|
113 | 108 |
int min = width<height ? width:height; |
114 | 109 |
|
115 | 110 |
Static3D vector = new Static3D(0,0,min/5); |
... | ... | |
120 | 115 |
mEffects.distort(vector, new Static3D( width/4, 3*height/4, 0), region); |
121 | 116 |
mEffects.distort(vector, new Static3D(3*width/4, 3*height/4, 0), region); |
122 | 117 |
|
118 |
// Avoid memory leaks: delete old texture if it exists (it might if we |
|
119 |
// got here after a brief amount of time spent in the background) |
|
120 |
if( mTexture!=null ) mTexture.markForDeletion(); |
|
121 |
|
|
122 |
mTexture= new DistortedTexture(width,height); |
|
123 |
mTexture.setTexture(bmp); |
|
124 |
|
|
123 | 125 |
mScreen.detachAll(); |
124 |
mScreen.attach(texture,mEffects,mesh);
|
|
126 |
mScreen.attach(mTexture,mEffects,new MeshFlat(50,50*height/width));
|
|
125 | 127 |
mScreen.resize(width, height); |
126 | 128 |
} |
127 | 129 |
|
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.