Project

General

Profile

« Previous | Next » 

Revision 5f2a53b6

Added by Leszek Koltunski about 7 years ago

Progress with VBOs - this time abstract out a new class, DistortedObject - i.e. everything that uploads something to GPU and thus needs to be auto re-created upon loss of the context.

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.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;
......
48 47
   private DistortedEffects mEffects;
49 48
   private DistortedTexture mTexture;
50 49
   private DistortedScreen mScreen;
50
   private MeshFlat mMesh;
51 51
   private AroundTheWorldEffectsManager mManager;
52 52
   private int mObjWidth, mObjHeight;
53 53

  
......
130 130
      if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
131 131
      mTexture.setTexture(bitmap);
132 132

  
133
      if( mMesh==null ) mMesh = new MeshFlat(30,30*mObjHeight/mObjWidth);
134

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

  
136 138
      DistortedEffects.enableEffect(EffectNames.DISTORT);
137 139
      DistortedEffects.enableEffect(EffectNames.SINK);
src/main/java/org/distorted/examples/bean/BeanRenderer.java
50 50
   private DistortedEffects mEffects;
51 51
   private DistortedScreen mScreen;
52 52
   private DistortedTexture mTexture;
53
   private MeshFlat mMesh;
53 54
   private int bmpHeight, bmpWidth;
54 55
    
55 56
///////////////////////////////////////////////////////////////////////////////////////////////////
......
149 150
      
150 151
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
151 152
      mTexture.setTexture(bitmap);
152

  
153
      if( mMesh==null ) mMesh = new MeshFlat(25,25*bmpHeight/bmpWidth);
153 154
      mScreen.detachAll();
154
      mScreen.attach(mTexture,mEffects,new MeshFlat(25,25*bmpHeight/bmpWidth));
155
      mScreen.attach(mTexture,mEffects,mMesh);
155 156

  
156 157
      DistortedEffects.enableEffect(EffectNames.DISTORT);
157 158

  
src/main/java/org/distorted/examples/check/CheckRenderer.java
59 59
    private GLSurfaceView mView;
60 60
    private DistortedEffects mEffects;
61 61
    private DistortedTexture mTexture;
62
    private MeshFlat mMesh;
62 63
    private DistortedScreen mScreen;
63 64
    private int bmpHeight, bmpWidth;
64 65

  
......
136 137
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
137 138
      mTexture.setTexture(bitmap);
138 139

  
140
      if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
141

  
139 142
      mScreen.detachAll();
140
      mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
143
      mScreen.attach(mTexture,mEffects,mMesh);
141 144

  
142 145
      mEffects.abortEffects(EffectTypes.VERTEX);
143 146
      mEffects.abortEffects(EffectTypes.FRAGMENT);
src/main/java/org/distorted/examples/deform/DeformRenderer.java
211 211
     int w=width/2;
212 212
     int h=height/2;
213 213

  
214
     if( stretchMesh!=null ) stretchMesh.markForDeletion();
215

  
214 216
     stretchMesh = new MeshFlat(50,50*h/w);
215 217
     Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
216 218
     stretchCanvas = new Canvas(stretchBitmap);
src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
52 52
   private GLSurfaceView mView;
53 53
   private DistortedEffects[] mEffects;
54 54
   private DistortedTexture[] mTexture;
55
   private MeshFlat mMesh;
55 56
   private DistortedScreen mScreen;
56 57
   private int bmpHeight, bmpWidth;
57 58
    
......
169 170
      mTexture[1].setTexture(bitmap1);
170 171
      mTexture[2].setTexture(bitmap2);
171 172

  
172
      MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
173
      if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
173 174

  
174 175
      mScreen.detachAll();
175
      for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mesh);
176
      for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mMesh);
176 177

  
177 178
      DistortedEffects.enableEffect(EffectNames.SINK);
178 179
      DistortedEffects.enableEffect(EffectNames.DISTORT);
src/main/java/org/distorted/examples/differenteffects/DifferentEffectsRenderer.java
53 53
   private GLSurfaceView mView;
54 54
   private DistortedEffects[] mEffects;
55 55
   private DistortedTexture mTexture;
56
   private MeshFlat mMesh;
56 57
   private DistortedScreen mScreen;
57 58
   private int bmpHeight, bmpWidth;
58 59
    
......
162 163
     bmpHeight = bitmap.getHeight();
163 164
     bmpWidth  = bitmap.getWidth();
164 165

  
165
     MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
166
     if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
166 167
     if( mTexture==null ) mTexture  = new DistortedTexture(bmpWidth,bmpHeight);
167 168
     mTexture.setTexture(bitmap);
168 169

  
169 170
     mScreen.detachAll();
170
     for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture, mEffects[i], mesh);
171
     for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture, mEffects[i], mMesh);
171 172

  
172 173
     DistortedEffects.enableEffect(EffectNames.SINK);
173 174
     DistortedEffects.enableEffect(EffectNames.DISTORT);
src/main/java/org/distorted/examples/fbo/FBORenderer.java
56 56
   private DistortedTexture mLisaTexture, mGridTexture;
57 57
   private DistortedScreen mScreen;
58 58
   private DistortedNode mRoot;
59
   private MeshFlat mMeshFlat;
60
   private MeshCubes mMeshCubes;
59 61
   private int lisaHeight, lisaWidth;
60 62
   private boolean mDepth;
61 63

  
......
166 168

  
167 169
      mEffects.abortAllEffects();
168 170

  
169
      mRoot = new DistortedNode(mLisaTexture, mEffects,new MeshFlat(1,1));
170
      mRoot.attach(mGridTexture,gridEffects,new MeshCubes(10,10,false));
171
      if( mMeshFlat==null ) mMeshFlat = new MeshFlat(1,1);
172
      if( mMeshCubes==null) mMeshCubes= new MeshCubes(10,10,false);
173

  
174
      mRoot = new DistortedNode(mLisaTexture, mEffects, mMeshFlat);
175
      mRoot.attach(mGridTexture,gridEffects,mMeshCubes);
171 176

  
172 177
      setDepthPriv();
173 178

  
src/main/java/org/distorted/examples/girl/GirlRenderer.java
52 52
    private DistortedEffects mEffects;
53 53
    private DistortedScreen mScreen;
54 54
    private DistortedTexture mTexture;
55
    private MeshFlat mMesh;
55 56
    private Static3D v0,v1,v2,v3;
56 57
    private Static1D dBegin, dMiddle, dEnd, s0;
57 58
    private int bmpHeight, bmpWidth;
......
207 208
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
208 209
      mTexture.setTexture(bitmap);
209 210

  
211
      if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
212

  
210 213
      mScreen.detachAll();
211
      mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
214
      mScreen.attach(mTexture,mEffects,mMesh);
212 215

  
213 216
      DistortedEffects.enableEffect(EffectNames.DISTORT);
214 217
      DistortedEffects.enableEffect(EffectNames.SINK);
src/main/java/org/distorted/examples/listener/ListenerRenderer.java
55 55
   private DistortedEffects mEffects;
56 56
   private DistortedScreen mScreen;
57 57
   private DistortedTexture mTexture;
58
   private MeshFlat mMesh;
58 59
   private int bmpHeight, bmpWidth;
59 60
   private Random mRnd;
60 61

  
......
158 159
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
159 160
      mTexture.setTexture(bitmap);
160 161

  
162
      if( mMesh==null ) mMesh = new MeshFlat(50,50*bmpHeight/bmpWidth);
163

  
161 164
      mScreen.detachAll();
162
      mScreen.attach(mTexture,mEffects,new MeshFlat(50,50*bmpHeight/bmpWidth));
165
      mScreen.attach(mTexture,mEffects,mMesh);
163 166

  
164 167
      for(int i=0; i<NUM_BUBBLES; i++) randomizeNewBubble();
165 168

  
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
48 48
    private GLSurfaceView mView;
49 49
    private DistortedEffects mEffects;
50 50
    private DistortedTexture mTexture;
51
    private MeshFlat mMesh;
51 52
    private DistortedScreen mScreen;
52 53
    private int bmpHeight, bmpWidth;
53 54

  
......
135 136
      // Do not leak memory by creating it the second time around.
136 137
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
137 138

  
139
      // likewise the Mesh
140
      if( mMesh==null ) mMesh = new MeshFlat(9,9*bmpHeight/bmpWidth);
141

  
138 142
      // even if mTexture wasn't null, we still need to call setTexture() on it
139 143
      // because every time activity goes to background, its OpenGL resources
140 144
      // - including Textures - get deleted. We always need to call setTexture()
......
142 146
      mTexture.setTexture(bitmap);
143 147

  
144 148
      mScreen.detachAll();
145
      mScreen.attach(mTexture,mEffects,new MeshFlat(9,9*bmpHeight/bmpWidth));
149
      mScreen.attach(mTexture,mEffects,mMesh);
146 150

  
147 151
      DistortedEffects.enableEffect(EffectNames.DISTORT);
148 152

  
src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java
48 48
   private DistortedEffects mEffects;
49 49
   private DistortedTexture mTexture;
50 50
   private DistortedScreen mScreen;
51
   private MeshFlat mMesh;
51 52
   private boolean mRefresh;
52 53

  
53 54
///////////////////////////////////////////////////////////////////////////////////////////////////
......
136 137
     mBitmap  = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
137 138
     mCanvas  = new Canvas(mBitmap);
138 139

  
140
     if( mMesh!=null ) mMesh.markForDeletion();
141
     mMesh = new MeshFlat(80,80*texH/texW);
142

  
139 143
     mScreen.detachAll();
140
     mScreen.attach(mTexture,mEffects,new MeshFlat(80,80*texH/texW));
144
     mScreen.attach(mTexture,mEffects,mMesh);
141 145
     mScreen.resize(texW, texH);
142 146
     mView.onSurfaceChanged(texW,texH);
143 147

  
src/main/java/org/distorted/examples/plainmonalisa/RenderThread.java
65 65

  
66 66
  private DistortedEffects mEffects;
67 67
  private DistortedTexture mTexture;
68
  private MeshFlat mMesh;
68 69
  private DistortedScreen mScreen;
69 70
  private int bmpHeight, bmpWidth;
70 71
  private SurfaceView mView;
......
259 260
    if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
260 261
    mTexture.setTexture(bmp);
261 262

  
263
    if( mMesh==null ) mMesh = new MeshFlat(9,9*bmpHeight/bmpWidth);
264

  
262 265
    mScreen.detachAll();
263
    mScreen.attach(mTexture,mEffects,new MeshFlat(9,9*bmpHeight/bmpWidth));
266
    mScreen.attach(mTexture,mEffects,mMesh);
264 267

  
265 268
    DistortedEffects.enableEffect(EffectNames.DISTORT);
266 269

  
src/main/java/org/distorted/examples/projection/ProjectionRenderer.java
44 44
   private GLSurfaceView mView;
45 45
   private DistortedEffects mEffects;
46 46
   private DistortedScreen mScreen;
47
   private MeshFlat mMesh;
47 48
   private DistortedTexture mTexture;
48 49
   private float mF, mNear;
49 50

  
......
122 123
      mTexture= new DistortedTexture(width,height);
123 124
      mTexture.setTexture(bmp);
124 125

  
126
      // likewise with the Mesh
127
      if( mMesh!=null ) mMesh.markForDeletion();
128

  
129
      mMesh = new MeshFlat(50,50*height/width);
130

  
125 131
      mScreen.detachAll();
126
      mScreen.attach(mTexture,mEffects,new MeshFlat(50,50*height/width));
132
      mScreen.attach(mTexture,mEffects,mMesh);
127 133
      mScreen.resize(width, height);
128 134
      }
129 135

  
src/main/java/org/distorted/examples/save/SaveRenderer.java
58 58
  private DistortedEffects mEffects;
59 59
  private DistortedFramebuffer mOffscreen;
60 60
  private DistortedTexture mTexture;
61
  private MeshFlat mMesh;
61 62
  private DistortedScreen mScreen;
62 63
  private Static1D s0;
63 64
  private Dynamic3D mScaleDyn;
......
242 243
    bmpHeight = bitmap.getHeight();
243 244
    bmpWidth  = bitmap.getWidth();
244 245

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

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

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

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

  
src/main/java/org/distorted/examples/sink/SinkRenderer.java
50 50
  private DistortedEffects mEffects;
51 51
  private DistortedScreen mScreen;
52 52
  private DistortedTexture mTexture;
53
  private MeshFlat mMesh;
53 54
  private int bmpHeight, bmpWidth;
54 55
    
55 56
///////////////////////////////////////////////////////////////////////////////////////////////////
......
126 127

  
127 128
    if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
128 129
    mTexture.setTexture(bitmap);
130
    if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
129 131

  
130 132
    mScreen.detachAll();
131
    mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
133
    mScreen.attach(mTexture,mEffects,mMesh);
132 134

  
133 135
    DistortedEffects.enableEffect(EffectNames.SINK);
134 136

  

Also available in: Unified diff