Revision 24ab1cf8
Added by Leszek Koltunski almost 7 years ago
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
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.