Project

General

Profile

« Previous | Next » 

Revision 24ab1cf8

Added by Leszek Koltunski almost 7 years ago

Move showing FPS in the uppoer-left corner of the Screen to the Library.
App can enable/disable this at any time with a single API call.

View differences:

src/main/java/org/distorted/examples/deform/DeformRenderer.java
46 46
   {
47 47
   private static final int NUM_VECTORS =  8;
48 48
   private static final int NUM_LINES   = 10;
49
   private static final int NUM_FRAMES  = 100;
50 49

  
51 50
   private GLSurfaceView mView;
52 51
   private DistortedTexture stretchTexture;
......
72 71
   private EffectNames mMode = EffectNames.DISTORT;
73 72
   private long mLastEffect = -1;
74 73

  
75
   // FPS
76
   private MeshObject fpsMesh;
77
   private DistortedTexture fpsTexture;
78
   private DistortedEffects fpsEffects;
79
   private Canvas fpsCanvas;
80
   private Bitmap fpsBitmap;
81
   private Paint mPaint;
82
   private int fpsH, fpsW;
83
   private String fpsString = "";
84
   private long lastTime=0;
85
   private long[] durations;
86
   private int currDuration;
87

  
88 74
///////////////////////////////////////////////////////////////////////////////////////////////////
89 75

  
90 76
   DeformRenderer(GLSurfaceView view)
91 77
      { 
92 78
      mView = view;
93 79

  
94
      fpsW = 120;
95
      fpsH =  70;
96

  
97
      fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888);
98
      fpsMesh = new MeshFlat(1,1);
99
      fpsTexture = new DistortedTexture(fpsW,fpsH);
100
      fpsTexture.setTexture(fpsBitmap);
101
      fpsCanvas = new Canvas(fpsBitmap);
102
      fpsEffects = new DistortedEffects();
103
      fpsEffects.move( new Static3D(5,5,0) );
104

  
105
      mPaint = new Paint();
106
      mPaint.setAntiAlias(true);
107
      mPaint.setTextAlign(Paint.Align.CENTER);
108
      mPaint.setTextSize(0.7f*fpsH);
109

  
110 80
      stretchEffects = new DistortedEffects();
111

  
112 81
      mRegion = new Static4D(0,0,0,0);
113 82

  
114
      durations = new long[NUM_FRAMES+1];
115
      currDuration = 0;
116

  
117
      for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=0;
118

  
119 83
      // DISTORT
120 84
      mReleasedDistortDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
121 85
      mReleasedDistortDynamic.setMode(Dynamic3D.MODE_PATH);
......
165 129
      mMovingShearDynamic.add(vShear[0]);
166 130

  
167 131
      mScreen = new DistortedScreen(mView);
132
      Distorted.setDebug(Distorted.DEBUG_FPS);
168 133
      }
169 134

  
170 135
///////////////////////////////////////////////////////////////////////////////////////////////////
......
186 151
   
187 152
   public void onDrawFrame(GL10 glUnused)
188 153
     {
189
     mPaint.setColor(0xffffffff);
190
     fpsCanvas.drawRect(0, 0, fpsW, fpsH, mPaint);
191
     mPaint.setColor(0xff000000);
192
     fpsCanvas.drawText(fpsString, fpsW/2, 0.75f*fpsH, mPaint);
193
     fpsTexture.setTexture(fpsBitmap);
194

  
195
     long time = System.currentTimeMillis();
196

  
197
     mScreen.render(time);
198
     computeFPS(time);
154
     mScreen.render(System.currentTimeMillis());
199 155
     }
200 156

  
201 157
///////////////////////////////////////////////////////////////////////////////////////////////////
......
217 173
     Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
218 174
     stretchCanvas = new Canvas(stretchBitmap);
219 175

  
220
     mPaint.setColor(0xff008800);
221
     mPaint.setStyle(Style.FILL);
222
     stretchCanvas.drawRect(0, 0, w, h, mPaint);
223
     mPaint.setColor(0xffffffff);
176
     Paint paint = new Paint();
177
     paint.setColor(0xff008800);
178
     paint.setStyle(Style.FILL);
179
     stretchCanvas.drawRect(0, 0, w, h, paint);
180
     paint.setColor(0xffffffff);
224 181

  
225 182
     for(int i=0; i<=NUM_LINES ; i++ )
226 183
       {
227
       stretchCanvas.drawRect(w*i/NUM_LINES - 1,                 0,  w*i/NUM_LINES + 1,  h                , mPaint);
228
       stretchCanvas.drawRect(                0, h *i/NUM_LINES -1,  w                ,  h*i/NUM_LINES + 1, mPaint);
184
       stretchCanvas.drawRect(w*i/NUM_LINES - 1,                 0,  w*i/NUM_LINES + 1,  h                , paint);
185
       stretchCanvas.drawRect(                0, h *i/NUM_LINES -1,  w                ,  h*i/NUM_LINES + 1, paint);
229 186
       }
230 187

  
231 188
     touchPoint= new Static3D(0,0,0);
......
238 195

  
239 196
     mScreen.detachAll();
240 197
     mScreen.attach(stretchTexture,stretchEffects,stretchMesh);
241
     mScreen.attach(fpsTexture,fpsEffects,fpsMesh);
242 198

  
243 199
     mScreen.resize(width, height);
244 200
     }
......
336 292
                     break;
337 293
       }
338 294
     }
339

  
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341

  
342
   private void computeFPS(long currentTime)
343
     {
344
     if( lastTime!=0 )
345
       {
346
       currDuration++;
347
       if( currDuration>=NUM_FRAMES ) currDuration = 0;
348
       durations[NUM_FRAMES] += ((currentTime-lastTime)-durations[currDuration]);
349
       durations[currDuration] = currentTime-lastTime;
350

  
351
       fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
352
       }
353
      
354
     lastTime = currentTime;
355
     }
356 295
   }
src/main/java/org/distorted/examples/multiblur/MultiblurRenderer.java
21 21

  
22 22
import android.graphics.Bitmap;
23 23
import android.graphics.BitmapFactory;
24
import android.graphics.Canvas;
25
import android.graphics.Paint;
26 24
import android.opengl.GLSurfaceView;
27 25

  
28 26
import org.distorted.examples.R;
......
36 34
import org.distorted.library.EffectQuality;
37 35
import org.distorted.library.EffectTypes;
38 36
import org.distorted.library.MeshCubes;
39
import org.distorted.library.MeshFlat;
40 37
import org.distorted.library.type.Dynamic1D;
41 38
import org.distorted.library.type.Dynamic3D;
42 39
import org.distorted.library.type.DynamicQuat;
......
54 51

  
55 52
class MultiblurRenderer implements GLSurfaceView.Renderer
56 53
{
57
    private static final int NUM_FRAMES  = 100;
58

  
59 54
    private static final int[] MOVE_VEC =
60 55
        {
61 56
        +1,+1,+1,
......
88 83
    Static4D mQuat1, mQuat2;
89 84
    int mScreenMin;
90 85

  
91
    // FPS
92
    private DistortedTexture fpsTexture;
93
    private DistortedEffects fpsEffects;
94
    private Canvas fpsCanvas;
95
    private Bitmap fpsBitmap;
96
    private Paint mPaint;
97
    private int fpsH, fpsW;
98
    private String fpsString = "";
99
    private long lastTime=0;
100
    private long[] durations;
101
    private int currDuration;
102

  
103 86
///////////////////////////////////////////////////////////////////////////////////////////////////
104 87

  
105 88
    MultiblurRenderer(GLSurfaceView v)
......
107 90
      mView = v;
108 91
      mDistance = -1;
109 92

  
110
      fpsW = 120;
111
      fpsH =  70;
112

  
113
      fpsTexture = new DistortedTexture(fpsW,fpsH);
114
      fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888);
115
      fpsTexture.setTexture(fpsBitmap);
116
      fpsCanvas = new Canvas(fpsBitmap);
117
      fpsEffects = new DistortedEffects();
118
      fpsEffects.move( new Static3D(5,5,0) );
119
      durations = new long[NUM_FRAMES+1];
120
      currDuration = 0;
121

  
122
      mPaint = new Paint();
123
      mPaint.setAntiAlias(true);
124
      mPaint.setTextAlign(Paint.Align.CENTER);
125
      mPaint.setTextSize(0.7f*fpsH);
126

  
127
      for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=0;
128

  
129 93
      mBlurStatus = new boolean[NUM_OBJECTS];
130 94
      mMoveDynamic= new Dynamic3D[NUM_OBJECTS];
131 95
      mMoveVector = new Static3D[NUM_OBJECTS];
......
170 134
        mScreen.attach(mNode[i]);
171 135
        }
172 136

  
173
      mScreen.attach(fpsTexture,fpsEffects,new MeshFlat(1,1));
174

  
175 137
      mBlurStatus[0] = true;
176 138
      mNode[0].setPostprocessEffects(mPostEffects);
139

  
140
      Distorted.setDebug(Distorted.DEBUG_FPS);
177 141
      }
178 142

  
179 143
///////////////////////////////////////////////////////////////////////////////////////////////////
......
187 151

  
188 152
    public void onDrawFrame(GL10 glUnused) 
189 153
      {
190
      mPaint.setColor(0xffffffff);
191
      fpsCanvas.drawRect(0, 0, fpsW, fpsH, mPaint);
192
      mPaint.setColor(0xff000000);
193
      fpsCanvas.drawText(fpsString, fpsW/2, 0.75f*fpsH, mPaint);
194
      fpsTexture.setTexture(fpsBitmap);
195

  
196
      long time = System.currentTimeMillis();
197

  
198
      mScreen.render(time);
199
      computeFPS(time);
154
      mScreen.render(System.currentTimeMillis());
200 155
      }
201 156

  
202 157
///////////////////////////////////////////////////////////////////////////////////////////////////
......
262 217
        }
263 218
      }
264 219

  
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

  
267
   private void computeFPS(long currentTime)
268
     {
269
     if( lastTime!=0 )
270
       {
271
       currDuration++;
272
       if( currDuration>=NUM_FRAMES ) currDuration = 0;
273
       durations[NUM_FRAMES] += ((currentTime-lastTime)-durations[currDuration]);
274
       durations[currDuration] = currentTime-lastTime;
275

  
276
       fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
277
       }
278

  
279
     lastTime = currentTime;
280
     }
281

  
282 220
///////////////////////////////////////////////////////////////////////////////////////////////////
283 221

  
284 222
    private void computeMoveVectors()

Also available in: Unified diff