Revision b28c6c21
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/Distorted.java | ||
|---|---|---|
| 34 | 34 |
static int GLSL; |
| 35 | 35 |
static String GLSL_VERSION; |
| 36 | 36 |
|
| 37 |
//////////// DEBUG FLAGS ///////////////////////////////////////////// |
|
| 38 |
/** |
|
| 39 |
* When rendering a Screen, show FPS in the upper-left corner? |
|
| 40 |
*/ |
|
| 41 |
public static final int DEBUG_FPS = 1; |
|
| 42 |
|
|
| 43 |
//////////// END DEBUG FLAGS ///////////////////////////////////////// |
|
| 44 |
|
|
| 37 | 45 |
/** |
| 38 | 46 |
* When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's |
| 39 | 47 |
* backing up our DistortedTexture. |
| ... | ... | |
| 76 | 84 |
|
| 77 | 85 |
private static boolean mInitialized=false; |
| 78 | 86 |
|
| 87 |
static int mDebugLevel = 0; |
|
| 88 |
static DistortedDebug mDebug; |
|
| 89 |
|
|
| 79 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 80 | 91 |
// private: hide this from Javadoc |
| 81 | 92 |
|
| ... | ... | |
| 91 | 102 |
return mInitialized; |
| 92 | 103 |
} |
| 93 | 104 |
|
| 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 106 |
/** |
|
| 107 |
* Make the library show various debugging information. |
|
| 108 |
* <p> |
|
| 109 |
* Currently only DEBUG_FPS - show FPS in the upper-left corner of every Screen - is defined. |
|
| 110 |
* |
|
| 111 |
* @param bitmask 0, or a bitmask of DEBUG_** flags to enable (currently only DEBUG_FPS defined) |
|
| 112 |
*/ |
|
| 113 |
public static void setDebug(int bitmask) |
|
| 114 |
{
|
|
| 115 |
mDebugLevel = bitmask; |
|
| 116 |
|
|
| 117 |
if( mDebugLevel!=0 && mDebug==null ) mDebug = new DistortedDebug(); |
|
| 118 |
} |
|
| 119 |
|
|
| 94 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 95 | 121 |
/** |
| 96 | 122 |
* When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures. |
| src/main/java/org/distorted/library/DistortedDebug.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.library; |
|
| 21 |
|
|
| 22 |
import android.graphics.Bitmap; |
|
| 23 |
import android.graphics.Canvas; |
|
| 24 |
import android.graphics.Paint; |
|
| 25 |
|
|
| 26 |
import org.distorted.library.type.Static3D; |
|
| 27 |
|
|
| 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 29 |
/** |
|
| 30 |
* Show various debugs. |
|
| 31 |
* <p> |
|
| 32 |
* Currently only showing the FPS in the upper-left corner of every DistortedScreen is supported. |
|
| 33 |
*/ |
|
| 34 |
class DistortedDebug |
|
| 35 |
{
|
|
| 36 |
private static final int NUM_FRAMES = 100; |
|
| 37 |
|
|
| 38 |
private MeshObject fpsMesh; |
|
| 39 |
private DistortedTexture fpsTexture; |
|
| 40 |
private DistortedEffects fpsEffects; |
|
| 41 |
private Canvas fpsCanvas; |
|
| 42 |
private Bitmap fpsBitmap; |
|
| 43 |
private Paint mPaint; |
|
| 44 |
private int fpsH, fpsW; |
|
| 45 |
private String fpsString = ""; |
|
| 46 |
private long lastTime=0; |
|
| 47 |
private long[] durations; |
|
| 48 |
private int currDuration; |
|
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
DistortedDebug() |
|
| 53 |
{
|
|
| 54 |
fpsW = 120; |
|
| 55 |
fpsH = 70; |
|
| 56 |
|
|
| 57 |
fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888); |
|
| 58 |
fpsMesh = new MeshFlat(1,1); |
|
| 59 |
fpsTexture = new DistortedTexture(fpsW,fpsH); |
|
| 60 |
fpsTexture.setTexture(fpsBitmap); |
|
| 61 |
fpsCanvas = new Canvas(fpsBitmap); |
|
| 62 |
fpsEffects = new DistortedEffects(); |
|
| 63 |
fpsEffects.move( new Static3D(5,5,0) ); |
|
| 64 |
|
|
| 65 |
mPaint = new Paint(); |
|
| 66 |
mPaint.setAntiAlias(true); |
|
| 67 |
mPaint.setTextAlign(Paint.Align.CENTER); |
|
| 68 |
mPaint.setTextSize(0.7f*fpsH); |
|
| 69 |
|
|
| 70 |
durations = new long[NUM_FRAMES+1]; |
|
| 71 |
currDuration = 0; |
|
| 72 |
for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=0; |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
private void computeFPS(long currTime) |
|
| 78 |
{
|
|
| 79 |
if( lastTime!=0 ) |
|
| 80 |
{
|
|
| 81 |
currDuration++; |
|
| 82 |
if( currDuration>=NUM_FRAMES ) currDuration = 0; |
|
| 83 |
durations[NUM_FRAMES] += ((currTime-lastTime)-durations[currDuration]); |
|
| 84 |
durations[currDuration] = currTime-lastTime; |
|
| 85 |
|
|
| 86 |
fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f; |
|
| 87 |
|
|
| 88 |
mPaint.setColor(0xffffffff); |
|
| 89 |
fpsCanvas.drawRect(0, 0, fpsW, fpsH, mPaint); |
|
| 90 |
mPaint.setColor(0xff000000); |
|
| 91 |
fpsCanvas.drawText(fpsString, fpsW/2, 0.75f*fpsH, mPaint); |
|
| 92 |
fpsTexture.setTexture(fpsBitmap); |
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
lastTime = currTime; |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
void renderFPS(long currTime, DistortedOutputSurface surface) |
|
| 101 |
{
|
|
| 102 |
computeFPS(currTime); |
|
| 103 |
|
|
| 104 |
fpsTexture.setAsInput(); |
|
| 105 |
surface.setAsOutput(); |
|
| 106 |
fpsEffects.drawPriv( fpsW/2, fpsH/2, fpsMesh, surface, currTime, 0); |
|
| 107 |
} |
|
| 108 |
} |
|
| src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
|---|---|---|
| 363 | 363 |
setAsOutput(time); |
| 364 | 364 |
numRenders += renderChildren(time,mNumChildren,mChildren); |
| 365 | 365 |
|
| 366 |
if( Distorted.mDebugLevel!=0 && this instanceof DistortedScreen ) |
|
| 367 |
{
|
|
| 368 |
Distorted.mDebug.renderFPS(time,this); |
|
| 369 |
} |
|
| 370 |
|
|
| 366 | 371 |
return numRenders; |
| 367 | 372 |
} |
| 368 | 373 |
|
| src/main/java/org/distorted/library/DistortedScreen.java | ||
|---|---|---|
| 33 | 33 |
*/ |
| 34 | 34 |
public class DistortedScreen extends DistortedOutputSurface |
| 35 | 35 |
{
|
| 36 |
|
|
| 37 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | 37 |
// here we don't manage underlying OpenGL assets ourselves |
| 39 | 38 |
|
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.