Project

General

Profile

« Previous | Next » 

Revision 86e99907

Added by Leszek Koltunski almost 7 years ago

Correct the FPS work (now works even after a Pause() ! )

View differences:

src/main/java/org/distorted/library/DistortedScreen.java
24 24
import android.app.ActivityManager;
25 25
import android.content.Context;
26 26
import android.content.pm.ConfigurationInfo;
27
import android.graphics.Bitmap;
28
import android.graphics.Canvas;
29
import android.graphics.Paint;
27 30
import android.opengl.GLSurfaceView;
28 31

  
32
import org.distorted.library.type.Static3D;
33

  
29 34
/**
30 35
 * Class which represents the Screen.
31 36
 * <p>
......
33 38
 */
34 39
public class DistortedScreen extends DistortedOutputSurface
35 40
  {
41
  ///// DEBUGGING ONLY /////////////////////////
42
  private static final int NUM_FRAMES  = 100;
43

  
44
  private MeshObject fpsMesh;
45
  private DistortedTexture fpsTexture;
46
  private DistortedEffects fpsEffects;
47
  private Canvas fpsCanvas;
48
  private Bitmap fpsBitmap;
49
  private Paint mPaint;
50
  private int fpsH, fpsW;
51
  private String fpsString = "";
52
  private long lastTime=0;
53
  private long[] durations;
54
  private int currDuration;
55

  
36 56
///////////////////////////////////////////////////////////////////////////////////////////////////
37 57
// here we don't manage underlying OpenGL assets ourselves
38 58

  
......
40 60
  void delete()   {}
41 61
  void recreate() {}
42 62

  
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

  
65
  void prepareDebug(long time)
66
    {
67
    if( lastTime==0 ) lastTime = time;
68

  
69
    currDuration++;
70
    if (currDuration >= NUM_FRAMES) currDuration = 0;
71
    durations[NUM_FRAMES] += ((time - lastTime) - durations[currDuration]);
72
    durations[currDuration] = time - lastTime;
73

  
74
    fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
75

  
76
    mPaint.setColor(0xffffffff);
77
    fpsCanvas.drawRect(0, 0, fpsW, fpsH, mPaint);
78
    mPaint.setColor(0xff000000);
79
    fpsCanvas.drawText(fpsString, fpsW/2, 0.75f*fpsH, mPaint);
80
    fpsTexture.setTexture(fpsBitmap);
81

  
82
    lastTime = time;
83
    }
84

  
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

  
87
  void renderDebug(long time)
88
    {
89
    if (fpsTexture.setAsInput())
90
      {
91
      setAsOutput(time);
92
      fpsEffects.drawPriv(fpsW/2.0f, fpsH/2.0f, fpsMesh, this, time, 0);
93
      }
94
    }
95

  
43 96
///////////////////////////////////////////////////////////////////////////////////////////////////
44 97
// PUBLIC API
45 98
///////////////////////////////////////////////////////////////////////////////////////////////////
......
61 114
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
62 115
      view.setEGLContextClientVersion((configurationInfo.reqGlEsVersion >> 16) >= 3 ? 3 : 2);
63 116
      }
117

  
118
    /////// DEBUGGING ONLY //////////////
119
    fpsW = 120;
120
    fpsH =  70;
121

  
122
    fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888);
123
    fpsMesh = new MeshFlat(1,1);
124
    fpsTexture = new DistortedTexture(fpsW,fpsH);
125
    fpsTexture.setTexture(fpsBitmap);
126
    fpsCanvas = new Canvas(fpsBitmap);
127
    fpsEffects = new DistortedEffects();
128
    fpsEffects.move( new Static3D(5,5,0) );
129

  
130
    mPaint = new Paint();
131
    mPaint.setAntiAlias(true);
132
    mPaint.setTextAlign(Paint.Align.CENTER);
133
    mPaint.setTextSize(0.7f*fpsH);
134

  
135
    durations = new long[NUM_FRAMES+1];
136
    currDuration = 0;
137

  
138
    for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=0;
64 139
    }
65 140
  }

Also available in: Unified diff