Project

General

Profile

« Previous | Next » 

Revision b8f8ef5c

Added by Leszek Koltunski over 4 years ago

New option to display current frame number in the upper-left corner of a DistortedScreen.

View differences:

src/main/java/org/distorted/library/main/DistortedScreen.java
40 40
  {
41 41
  ///// DEBUGGING ONLY /////////////////////////
42 42
  private static final int NUM_FRAMES  = 100;
43
  private static final int FPS_W       = 120;
44
  private static final int FPS_H       =  70;
43
  private static final int DEBUG_W     = 150;
44
  private static final int DEBUG_H     =  70;
45 45

  
46
  private boolean mShowFPS;
46
  private static final int DEBUG_MODE_NONE = 0;
47
  private static final int DEBUG_MODE_FPS  = 1;
48
  private static final int DEBUG_MODE_FRAME= 2;
47 49

  
48
  private MeshQuad fpsMesh;
49
  private DistortedTexture fpsTexture;
50
  private DistortedEffects fpsEffects;
51
  private Canvas fpsCanvas;
52
  private Bitmap fpsBitmap;
50
  private int mDebugMode;
51
  private boolean mDebugAllocated;
52

  
53
  private MeshQuad debugMesh;
54
  private DistortedTexture debugTexture;
55
  private DistortedEffects debugEffects;
56
  private Canvas debugCanvas;
57
  private Bitmap debugBitmap;
53 58
  private Paint mPaint;
54
  private String fpsString;
59
  private String debugString;
55 60
  private long lastTime=0;
56 61
  private long[] durations;
57 62
  private int currDuration;
63
  private int frameNumber;
58 64
  private static Static3D mMoveVector = new Static3D(0,0,0);
59 65
  private static MatrixEffectMove mMoveEffect = new MatrixEffectMove(mMoveVector);
60 66
  ///// END DEBUGGING //////////////////////////
......
74 80
  public DistortedScreen()
75 81
    {
76 82
    super(DistortedLibrary.FBO_QUEUE_SIZE,1,BOTH_DEPTH_STENCIL, TYPE_SYST, 1,1);
77
    mShowFPS = false;
83
    mDebugMode = DEBUG_MODE_NONE;
78 84
    mCurRenderedFBO = 0;
79 85
    mToBeBlittedFBO = 0;
80 86
    mFirstCircle = true;
87
    mDebugAllocated = false;
81 88
    }
82 89

  
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

  
92
   private void allocateDebug()
93
     {
94
     if( !mDebugAllocated )
95
       {
96
       mDebugAllocated = true;
97

  
98
       debugString = "";
99
       debugBitmap = Bitmap.createBitmap(DEBUG_W, DEBUG_H, Bitmap.Config.ARGB_8888);
100
       debugMesh = new MeshQuad();
101
       debugTexture = new DistortedTexture();
102
       debugTexture.setTexture(debugBitmap);
103
       debugCanvas = new Canvas(debugBitmap);
104
       debugEffects = new DistortedEffects();
105
       debugEffects.apply( new MatrixEffectScale( new Static3D(DEBUG_W,DEBUG_H,1) ) );
106
       debugEffects.apply(mMoveEffect);
107

  
108
       mPaint = new Paint();
109
       mPaint.setAntiAlias(true);
110
       mPaint.setTextAlign(Paint.Align.CENTER);
111
       mPaint.setTextSize(0.7f * DEBUG_H);
112
       }
113
     }
114

  
83 115
///////////////////////////////////////////////////////////////////////////////////////////////////
84 116
/**
85 117
 * Draws all the attached children to this OutputSurface.
......
91 123
 */
92 124
  public int render(long time)
93 125
    {
94
    if( mShowFPS )
126
    if( mDebugMode!=DEBUG_MODE_NONE )
95 127
      {
96 128
      if( lastTime==0 ) lastTime = time;
97 129

  
98
      currDuration++;
99
      if (currDuration >= NUM_FRAMES) currDuration = 0;
100
      durations[NUM_FRAMES] += ((time - lastTime) - durations[currDuration]);
101
      durations[currDuration] = time - lastTime;
102

  
103
      fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
130
      if( mDebugMode==DEBUG_MODE_FPS )
131
        {
132
        currDuration++;
133
        if (currDuration >= NUM_FRAMES) currDuration = 0;
134
        durations[NUM_FRAMES] += ((time - lastTime) - durations[currDuration]);
135
        durations[currDuration] = time - lastTime;
136

  
137
        debugString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
138
        }
139
      else if( mDebugMode==DEBUG_MODE_FRAME )
140
        {
141
        debugString = "" + frameNumber;
142
        frameNumber++;
143
        }
104 144

  
105 145
      mPaint.setColor(0xffffffff);
106
      fpsCanvas.drawRect(0, 0, FPS_W, FPS_H, mPaint);
146
      debugCanvas.drawRect(0, 0, DEBUG_W, DEBUG_H, mPaint);
107 147
      mPaint.setColor(0xff000000);
108
      fpsCanvas.drawText(fpsString, 0.5f*FPS_W, 0.75f*FPS_H, mPaint);
109
      fpsTexture.setTexture(fpsBitmap);
148
      debugCanvas.drawText(debugString, 0.5f*DEBUG_W, 0.75f*DEBUG_H, mPaint);
149
      debugTexture.setTexture(debugBitmap);
110 150

  
111
      mMoveVector.set( (-mWidth+FPS_W)/2 +5, (mHeight-FPS_H)/2 -5, 0);
151
      mMoveVector.set( (-mWidth+DEBUG_W)/2 +5, (mHeight-DEBUG_H)/2 -5, 0);
112 152

  
113 153
      lastTime = time;
114 154
      }
......
132 172

  
133 173
    DistortedLibrary.blitPriv(this);
134 174

  
135
    if( mShowFPS && fpsTexture.setAsInput())
175
    if( mDebugMode!=DEBUG_MODE_NONE && debugTexture.setAsInput())
136 176
      {
137
      DistortedLibrary.drawPriv(fpsEffects, fpsMesh, this, time);
177
      DistortedLibrary.drawPriv(debugEffects, debugMesh, this, time);
138 178
      }
139 179

  
140 180
    if( ++mCurRenderedFBO>= DistortedLibrary.FBO_QUEUE_SIZE )
......
157 197
 */
158 198
  public void showFPS()
159 199
    {
160
    if( !mShowFPS )
200
    if( mDebugMode!=DEBUG_MODE_FPS )
161 201
      {
162
      mShowFPS = true;
163
      fpsString = "";
164
      fpsBitmap = Bitmap.createBitmap(FPS_W, FPS_H, Bitmap.Config.ARGB_8888);
165
      fpsMesh = new MeshQuad();
166
      fpsTexture = new DistortedTexture();
167
      fpsTexture.setTexture(fpsBitmap);
168
      fpsCanvas = new Canvas(fpsBitmap);
169
      fpsEffects = new DistortedEffects();
170
      fpsEffects.apply( new MatrixEffectScale( new Static3D(FPS_W,FPS_H,1) ) );
171
      fpsEffects.apply(mMoveEffect);
172

  
173
      mPaint = new Paint();
174
      mPaint.setAntiAlias(true);
175
      mPaint.setTextAlign(Paint.Align.CENTER);
176
      mPaint.setTextSize(0.7f * FPS_H);
202
      allocateDebug();
203
      mDebugMode = DEBUG_MODE_FPS;
177 204

  
178 205
      durations = new long[NUM_FRAMES + 1];
179 206
      currDuration = 0;
......
182 209
      durations[NUM_FRAMES] = NUM_FRAMES * 16;               // close to 1000/16 ~ 60
183 210
      }
184 211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
/**
215
 * Make the library show current frame number in the upper-left corner.
216
 * <p>
217
 */
218
  public void showFrameNumber()
219
    {
220
    if( mDebugMode!=DEBUG_MODE_FRAME )
221
      {
222
      allocateDebug();
223
      mDebugMode = DEBUG_MODE_FRAME;
224
      frameNumber = 0;
225
      }
226
    }
185 227
  }

Also available in: Unified diff