Permalink
Browse files

Made sure texture warmup also works on Adreno GPUs (at least on the A…

…dreno 205 in the XPeria Play on Android 2.3.6).
  • Loading branch information...
1 parent 4594755 commit beca7b4871ea1c4e2b4f4e3df354233402a4e3a0 Nicolas Gramlich committed May 16, 2012
Showing with 40 additions and 2 deletions.
  1. +40 −2 src/org/andengine/opengl/texture/TextureWarmUpVertexBufferObject.java
View
42 src/org/andengine/opengl/texture/TextureWarmUpVertexBufferObject.java
@@ -1,5 +1,8 @@
package org.andengine.opengl.texture;
+import java.nio.FloatBuffer;
+
+import org.andengine.entity.sprite.UncoloredSprite;
import org.andengine.opengl.shader.PositionTextureCoordinatesShaderProgram;
import org.andengine.opengl.shader.constants.ShaderProgramConstants;
import org.andengine.opengl.util.GLState;
@@ -21,6 +24,11 @@
// Constants
// ===========================================================
+ public static final int VERTEX_INDEX_X = 0;
+ public static final int VERTEX_INDEX_Y = UncoloredSprite.VERTEX_INDEX_X + 1;
+ public static final int TEXTURECOORDINATES_INDEX_U = UncoloredSprite.VERTEX_INDEX_Y + 1;
+ public static final int TEXTURECOORDINATES_INDEX_V = UncoloredSprite.TEXTURECOORDINATES_INDEX_U + 1;
+
public static final int VERTEX_SIZE = 2 + 2;
public static final int VERTICES_PER_VERTEXBUFFEROBJECT_SIZE = 3;
public static final int VERTEXBUFFEROBJECT_SIZE = TextureWarmUpVertexBufferObject.VERTEX_SIZE * TextureWarmUpVertexBufferObject.VERTICES_PER_VERTEXBUFFEROBJECT_SIZE;
@@ -34,12 +42,31 @@
// Fields
// ===========================================================
+ protected final FloatBuffer mFloatBuffer;
+
// ===========================================================
// Constructors
// ===========================================================
public TextureWarmUpVertexBufferObject() {
super(null, VERTEXBUFFEROBJECT_SIZE, DrawType.STATIC, true, TextureWarmUpVertexBufferObject.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT);
+
+ this.mFloatBuffer = this.mByteBuffer.asFloatBuffer();
+
+ this.mFloatBuffer.put(0 * VERTEX_SIZE + VERTEX_INDEX_X, 0);
+ this.mFloatBuffer.put(0 * VERTEX_SIZE + VERTEX_INDEX_Y, 0);
+ this.mFloatBuffer.put(0 * VERTEX_SIZE + TEXTURECOORDINATES_INDEX_U, 0);
+ this.mFloatBuffer.put(0 * VERTEX_SIZE + TEXTURECOORDINATES_INDEX_V, 0);
+
+ this.mFloatBuffer.put(1 * VERTEX_SIZE + VERTEX_INDEX_X, 1);
+ this.mFloatBuffer.put(1 * VERTEX_SIZE + VERTEX_INDEX_Y, 0);
+ this.mFloatBuffer.put(1 * VERTEX_SIZE + TEXTURECOORDINATES_INDEX_U, 1);
+ this.mFloatBuffer.put(1 * VERTEX_SIZE + TEXTURECOORDINATES_INDEX_V, 0);
+
+ this.mFloatBuffer.put(2 * VERTEX_SIZE + VERTEX_INDEX_X, 0);
+ this.mFloatBuffer.put(2 * VERTEX_SIZE + VERTEX_INDEX_Y, 1);
+ this.mFloatBuffer.put(2 * VERTEX_SIZE + TEXTURECOORDINATES_INDEX_U, 0);
+ this.mFloatBuffer.put(2 * VERTEX_SIZE + TEXTURECOORDINATES_INDEX_V, 1);
}
// ===========================================================
@@ -62,13 +89,24 @@ public int getNativeHeapMemoryByteSize() {
@Override
protected void onBufferData() {
- /* Nothing. */
+ GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, this.mByteBuffer.limit(), this.mByteBuffer, this.mUsage);
}
public void warmup(final GLState pGLState, final ITexture pTexture) {
pTexture.bind(pGLState);
this.bind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());
- this.draw(GLES20.GL_TRIANGLES, VERTICES_PER_VERTEXBUFFEROBJECT_SIZE);
+
+ pGLState.pushModelViewGLMatrix();
+ {
+ /* Far far away and really small. */
+ pGLState.resetModelViewGLMatrixStack();
+ pGLState.translateModelViewGLMatrixf(1000000, 1000000, 0);
+ pGLState.scaleModelViewGLMatrixf(0.0001f, 0.0001f, 0);
+
+ this.draw(GLES20.GL_TRIANGLES, VERTICES_PER_VERTEXBUFFEROBJECT_SIZE);
+ }
+ pGLState.popModelViewGLMatrix();
+
this.unbind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());
}

1 comment on commit beca7b4

@nicolasgramlich

Apparently the Adreno GPUs have some optimization when sending it data consisting of all zeros, which caused the warmup not to work. =P

Please sign in to comment.