| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.gameperformance; |
| 17 |
|
| 18 |
import java.util.ArrayList; |
| 19 |
import java.util.List; |
| 20 |
|
| 21 |
import javax.microedition.khronos.opengles.GL; |
| 22 |
|
| 23 |
import android.annotation.NonNull; |
| 24 |
import android.opengl.GLES20; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class FillRateOpenGLTest extends RenderPatchOpenGLTest { |
| 32 |
private final float[] BLEND_COLOR = new float[] { 1.0f, 1.0f, 1.0f, 0.2f }; |
| 33 |
|
| 34 |
private final boolean mTestBlend; |
| 35 |
|
| 36 |
public FillRateOpenGLTest(@NonNull GamePerformanceActivity activity, boolean testBlend) { |
| 37 |
super(activity); |
| 38 |
mTestBlend = testBlend; |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public String getName() { |
| 43 |
return mTestBlend ? "blend_rate" : "fill_rate"; |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public String getUnitName() { |
| 48 |
return "screens"; |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public double getUnitScale() { |
| 53 |
return 0.2; |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public void initUnits(double screens) { |
| 58 |
final CustomOpenGLView view = getView(); |
| 59 |
final int pixelRate = (int)Math.round(screens * view.getHeight() * view.getWidth()); |
| 60 |
final int maxPerPath = view.getHeight() * view.getHeight(); |
| 61 |
|
| 62 |
final int patchCount = (int)(pixelRate + maxPerPath -1) / maxPerPath; |
| 63 |
final float patchDimension = |
| 64 |
(float)((Math.sqrt(2.0f) * pixelRate / patchCount) / maxPerPath); |
| 65 |
|
| 66 |
final List<RenderPatchAnimation> renderPatches = new ArrayList<>(); |
| 67 |
final RenderPatch renderPatch = new RenderPatch(2 , |
| 68 |
patchDimension, |
| 69 |
RenderPatch.TESSELLATION_BASE); |
| 70 |
for (int i = 0; i < patchCount; ++i) { |
| 71 |
renderPatches.add(new RenderPatchAnimation(renderPatch, getView().getRenderRatio())); |
| 72 |
} |
| 73 |
setRenderPatches(renderPatches); |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public float[] getColor() { |
| 78 |
return BLEND_COLOR; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public void onBeforeDraw(GL gl) { |
| 83 |
if (!mTestBlend) { |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
GLES20.glEnable(GLES20.GL_BLEND); |
| 89 |
OpenGLUtils.checkGlError("disableBlend"); |
| 90 |
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); |
| 91 |
OpenGLUtils.checkGlError("blendFunction"); |
| 92 |
} |
| 93 |
} |