Project

General

Profile

« Previous | Next » 

Revision 59540ba2

Added by Leszek Koltunski about 7 years ago

Convert (almost) all remaining Apps to the new API which avoids memory leaks with Surfaces.

Remaining problematic Apps: 15. FBO 16. Star Wars (both leak Tree FBOs) 22. SurfaceView (does not work at all after going to background)

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java
46 46
{
47 47
   private GLSurfaceView mView;
48 48
   private DistortedEffects mEffects;
49
   private DistortedTexture mTexture;
49 50
   private DistortedScreen mScreen;
50 51
   private AroundTheWorldEffectsManager mManager;
51 52
   private int mObjWidth, mObjHeight;
......
126 127
      mObjWidth = bitmap.getWidth();
127 128
      mObjHeight= bitmap.getHeight();
128 129

  
129
      DistortedTexture texture = new DistortedTexture(mObjWidth,mObjHeight);
130
      texture.setTexture(bitmap);
131

  
132
      MeshFlat mesh = new MeshFlat(30,30*mObjHeight/mObjWidth);
130
      if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
131
      mTexture.setTexture(bitmap);
133 132

  
134 133
      mScreen.detachAll();
135
      mScreen.attach(texture, mEffects, mesh );
134
      mScreen.attach(mTexture, mEffects, new MeshFlat(30,30*mObjHeight/mObjWidth));
136 135

  
137 136
      DistortedEffects.enableEffect(EffectNames.DISTORT);
138 137
      DistortedEffects.enableEffect(EffectNames.SINK);
src/main/java/org/distorted/examples/blur/BlurRenderer.java
48 48
class BlurRenderer implements GLSurfaceView.Renderer
49 49
{
50 50
    private GLSurfaceView mView;
51
    private DistortedTexture mTexture;
51 52
    private DistortedEffects mEffects;
52 53
    private DistortedEffectsPostprocess mPostEffects;
53 54
    private DistortedScreen mScreen;
......
137 138
      bmpHeight = bitmap.getHeight();
138 139
      bmpWidth  = bitmap.getWidth();
139 140

  
140
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
141
      texture.setTexture(bitmap);
141
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
142
      mTexture.setTexture(bitmap);
142 143

  
143 144
      mScreen.detachAll();
144
      DistortedNode node = new DistortedNode(texture,mEffects,mMesh);
145
      DistortedNode node = new DistortedNode(mTexture,mEffects,mMesh);
145 146
      node.setPostprocessEffects(mPostEffects);
146 147
      mScreen.attach(node);
147 148

  
src/main/java/org/distorted/examples/fbo/FBORenderer.java
53 53
{
54 54
   private GLSurfaceView mView;
55 55
   private DistortedEffects mEffects;
56
   private DistortedTexture mLisaTexture, mGridTexture;
56 57
   private DistortedScreen mScreen;
57 58
   private DistortedNode mRoot;
58 59
   private int lisaHeight, lisaWidth;
......
157 158
      int gridWidth = bitmap2.getWidth();
158 159
      int gridHeight= bitmap2.getHeight();
159 160

  
160
      DistortedTexture lisa = new DistortedTexture(lisaWidth,lisaHeight);
161
      DistortedTexture grid = new DistortedTexture(gridWidth,gridHeight);
162
      lisa.setTexture(bitmap1);
163
      grid.setTexture(bitmap2);
161
      if( mLisaTexture==null ) mLisaTexture = new DistortedTexture(lisaWidth,lisaHeight);
162
      if( mGridTexture==null ) mGridTexture = new DistortedTexture(gridWidth,gridHeight);
163
      mLisaTexture.setTexture(bitmap1);
164
      mGridTexture.setTexture(bitmap2);
164 165
      DistortedEffects gridEffects = new DistortedEffects();
165 166

  
166 167
      mEffects.abortAllEffects();
167 168

  
168
      mRoot = new DistortedNode(lisa, mEffects,new MeshFlat(1,1));
169
      mRoot.attach(grid,gridEffects,new MeshCubes(10,10,false));
169
      mRoot = new DistortedNode(mLisaTexture, mEffects,new MeshFlat(1,1));
170
      mRoot.attach(mGridTexture,gridEffects,new MeshCubes(10,10,false));
170 171

  
171 172
      setDepthPriv();
172 173

  
src/main/java/org/distorted/examples/mirror/MirrorRenderer.java
21 21

  
22 22
import android.graphics.Bitmap;
23 23
import android.graphics.BitmapFactory;
24
import android.opengl.GLES30;
25 24
import android.opengl.GLSurfaceView;
26 25

  
27 26
import org.distorted.examples.R;
......
127 126
        mScreenW = width;
128 127
        mScreenH = height;
129 128

  
129
        if( mOffScreen1!=null ) mOffScreen1.markForDeletion();
130
        if( mOffScreen2!=null ) mOffScreen2.markForDeletion();
131

  
130 132
        mOffScreen1 = new DistortedFramebuffer(mScreenW,mScreenH);
131 133
        mOffScreen2 = new DistortedFramebuffer( (int)(MIRROR_SCALE*mScreenW), (int)(MIRROR_SCALE*mScreenH) );
132 134

  
......
186 188
      mHeadW   = bitmapH.getWidth();
187 189
      mHeadH   = bitmapH.getHeight();
188 190

  
189
      mTextureMirror = new DistortedTexture(mMirrorW,mMirrorH);
190
      mTextureHead   = new DistortedTexture(mHeadW, mHeadH);
191
      if( mTextureMirror==null ) mTextureMirror = new DistortedTexture(mMirrorW,mMirrorH);
192
      if( mTextureHead  ==null ) mTextureHead   = new DistortedTexture(mHeadW, mHeadH);
191 193

  
192 194
      mTextureMirror.setTexture(bitmapM);
193 195
      mTextureHead.setTexture(bitmapH);
src/main/java/org/distorted/examples/save/SaveRenderer.java
57 57
  private GLSurfaceView mView;
58 58
  private DistortedEffects mEffects;
59 59
  private DistortedFramebuffer mOffscreen;
60
  private DistortedTexture mTexture;
60 61
  private DistortedScreen mScreen;
61 62
  private Static1D s0;
62 63
  private Dynamic3D mScaleDyn;
......
242 243
    bmpWidth  = bitmap.getWidth();
243 244

  
244 245
    MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
245
    DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
246
    texture.setTexture(bitmap);
246
    if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
247
    mTexture.setTexture(bitmap);
247 248

  
248
    mOffscreen = new DistortedFramebuffer( (int)(mScale*bmpWidth) , (int)(mScale*bmpHeight) );
249
    if( mOffscreen==null ) mOffscreen = new DistortedFramebuffer( (int)(mScale*bmpWidth) , (int)(mScale*bmpHeight) );
249 250

  
250 251
    mOffscreen.detachAll();
251
    mOffscreen.attach(texture,mEffects,mesh);
252
    mOffscreen.attach(mTexture,mEffects,mesh);
252 253
    mScreen.detachAll();
253
    mScreen.attach(texture,mEffects,mesh);
254
    mScreen.attach(mTexture,mEffects,mesh);
254 255

  
255 256
    DistortedEffects.enableEffect(EffectNames.SINK);
256 257

  
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java
204 204
    double angleA = (90.0f - FOV_ANGLE/2)*Math.PI/180;
205 205
    double angleB = (90.0f - FOV_ANGLE/2 +CRAWL_ANGLE)*Math.PI/180;
206 206

  
207
    if( mCrawlBackgroundTexture!=null ) mCrawlBackgroundTexture.markForDeletion();
207 208
    mCrawlBackgroundTexture = new DistortedTexture(w,(int)(h*Math.sin(angleA)/Math.sin(angleB)));
208 209
       
209 210
    int randomA, randomX, randomY, randomTime;
......
286 287
    paint.setTypeface(tf);     
287 288
 
288 289
    ///// create GFFA ///////////////////
289
    mGFFATexture  = new DistortedTexture(GFFA_WIDTH,GFFA_HEIGHT);
290
    if( mGFFATexture==null ) mGFFATexture  = new DistortedTexture(GFFA_WIDTH,GFFA_HEIGHT);
290 291
    bitmapGFFA = Bitmap.createBitmap(GFFA_WIDTH,GFFA_HEIGHT,Bitmap.Config.ARGB_8888);
291 292
    bitmapGFFA.eraseColor(0x00000000);
292 293
    Canvas gffaCanvas = new Canvas(bitmapGFFA);
......
299 300
    mGFFATexture.setTexture(bitmapGFFA);
300 301
      
301 302
    ///// create Logo ///////////////////
302
    mLogoTexture  = new DistortedTexture(bitmapLogo.getWidth(),bitmapLogo.getHeight());
303
    if( mLogoTexture==null ) mLogoTexture  = new DistortedTexture(bitmapLogo.getWidth(),bitmapLogo.getHeight());
303 304
    mLogoTexture.setTexture(bitmapLogo);
304 305

  
305 306
    ///// create CRAWL //////////////////
306
    mCrawlTexture = new DistortedTexture(CRAWL_WIDTH,CRAWL_HEIGHT);
307
    if( mCrawlTexture==null ) mCrawlTexture = new DistortedTexture(CRAWL_WIDTH,CRAWL_HEIGHT);
307 308
    bitmapText = Bitmap.createBitmap(CRAWL_WIDTH,CRAWL_HEIGHT,Bitmap.Config.ARGB_8888);
308 309
    bitmapText.eraseColor(0x00000000);
309 310
    Canvas textCanvas = new Canvas(bitmapText);
......
317 318
    mCrawlTexture.setTexture(bitmapText);
318 319
      
319 320
    ///// create Stars ///////////////////
320
    mStarTexture = new DistortedTexture(bitmapStar.getWidth(),bitmapStar.getHeight());
321
    if( mStarTexture==null ) mStarTexture = new DistortedTexture(bitmapStar.getWidth(),bitmapStar.getHeight());
321 322
    mStarTexture.setTexture(bitmapStar);
322 323

  
323 324
    gffaID = mGFFAEffects.getID();

Also available in: Unified diff