Revision 28fe91ae
Added by Leszek Koltunski about 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; |
|
24 | 26 |
import android.opengl.GLSurfaceView; |
25 | 27 |
|
26 | 28 |
import org.distorted.examples.R; |
... | ... | |
33 | 35 |
import org.distorted.library.EffectNames; |
34 | 36 |
import org.distorted.library.EffectTypes; |
35 | 37 |
import org.distorted.library.MeshCubes; |
38 |
import org.distorted.library.MeshFlat; |
|
36 | 39 |
import org.distorted.library.type.Dynamic1D; |
37 | 40 |
import org.distorted.library.type.Dynamic3D; |
38 | 41 |
import org.distorted.library.type.DynamicQuat; |
... | ... | |
50 | 53 |
|
51 | 54 |
class MultiblurRenderer implements GLSurfaceView.Renderer |
52 | 55 |
{ |
56 |
private static final int NUM_FRAMES = 100; |
|
57 |
|
|
53 | 58 |
private static final int[] MOVE_VEC = |
54 | 59 |
{ |
55 | 60 |
+1,+1,+1, |
... | ... | |
81 | 86 |
|
82 | 87 |
Static4D mQuat1, mQuat2; |
83 | 88 |
int mScreenMin; |
84 |
|
|
89 |
|
|
90 |
// FPS |
|
91 |
private DistortedTexture fpsTexture; |
|
92 |
private DistortedEffects fpsEffects; |
|
93 |
private MeshFlat fpsMesh; |
|
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 |
|
|
85 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
86 | 104 |
|
87 | 105 |
MultiblurRenderer(GLSurfaceView v) |
... | ... | |
89 | 107 |
mView = v; |
90 | 108 |
mDistance = -1; |
91 | 109 |
|
110 |
mPaint = new Paint(); |
|
111 |
mPaint.setAntiAlias(true); |
|
112 |
mPaint.setTextAlign(Paint.Align.CENTER); |
|
113 |
|
|
114 |
fpsTexture = new DistortedTexture(100,100); |
|
115 |
fpsEffects = new DistortedEffects(); |
|
116 |
fpsEffects.move( new Static3D(5,5,0) ); |
|
117 |
fpsMesh = new MeshFlat(1,1); |
|
118 |
durations = new long[NUM_FRAMES+1]; |
|
119 |
currDuration = 0; |
|
120 |
|
|
121 |
for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=0; |
|
122 |
|
|
92 | 123 |
mBlurStatus = new boolean[NUM_OBJECTS]; |
93 | 124 |
mMoveDynamic= new Dynamic3D[NUM_OBJECTS]; |
94 | 125 |
mMoveVector = new Static3D[NUM_OBJECTS]; |
... | ... | |
133 | 164 |
mScreen.attach(mNode[i]); |
134 | 165 |
} |
135 | 166 |
|
167 |
mScreen.attach(fpsTexture,fpsEffects,fpsMesh); |
|
168 |
|
|
136 | 169 |
mBlurStatus[0] = true; |
137 | 170 |
mNode[0].setPostprocessEffects(mPostEffects); |
138 | 171 |
} |
... | ... | |
141 | 174 |
|
142 | 175 |
public void onDrawFrame(GL10 glUnused) |
143 | 176 |
{ |
144 |
mScreen.render( System.currentTimeMillis() ); |
|
177 |
mPaint.setColor(0xffffffff); |
|
178 |
fpsCanvas.drawRect(0, 0, fpsW, fpsH, mPaint); |
|
179 |
mPaint.setColor(0xff000000); |
|
180 |
fpsCanvas.drawText(fpsString, fpsW/2, 5*fpsH/6, mPaint); |
|
181 |
fpsTexture.setTexture(fpsBitmap); |
|
182 |
|
|
183 |
long time = System.currentTimeMillis(); |
|
184 |
|
|
185 |
mScreen.render(time); |
|
186 |
computeFPS(time); |
|
145 | 187 |
} |
146 | 188 |
|
147 | 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
167 | 209 |
|
168 | 210 |
computeMoveVectors(); |
169 | 211 |
|
212 |
fpsW = width/5; |
|
213 |
fpsH = fpsW/2; |
|
214 |
mPaint.setTextSize(2*fpsH/3); |
|
215 |
fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888); |
|
216 |
fpsCanvas = new Canvas(fpsBitmap); |
|
217 |
fpsTexture.setTexture(fpsBitmap); |
|
218 |
|
|
170 | 219 |
mScreen.resize(width, height); |
171 | 220 |
} |
172 | 221 |
|
... | ... | |
208 | 257 |
} |
209 | 258 |
} |
210 | 259 |
|
260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
261 |
|
|
262 |
private void computeFPS(long currentTime) |
|
263 |
{ |
|
264 |
if( lastTime!=0 ) |
|
265 |
{ |
|
266 |
currDuration++; |
|
267 |
if( currDuration>=NUM_FRAMES ) currDuration = 0; |
|
268 |
durations[NUM_FRAMES] += ((currentTime-lastTime)-durations[currDuration]); |
|
269 |
durations[currDuration] = currentTime-lastTime; |
|
270 |
|
|
271 |
fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f; |
|
272 |
} |
|
273 |
|
|
274 |
lastTime = currentTime; |
|
275 |
} |
|
276 |
|
|
211 | 277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
212 | 278 |
|
213 | 279 |
private void computeMoveVectors() |
Also available in: Unified diff
Multiblur: add FPS