Skip to content

Commit

Permalink
Made sure texture warmup also works on Adreno GPUs (at least on the A…
Browse files Browse the repository at this point in the history
…dreno 205 in the XPeria Play on Android 2.3.6).
  • Loading branch information
Nicolas Gramlich committed May 16, 2012
1 parent 4594755 commit beca7b4
Showing 1 changed file with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +24,11 @@ public class TextureWarmUpVertexBufferObject extends VertexBufferObject {
// 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;
Expand All @@ -34,12 +42,31 @@ public class TextureWarmUpVertexBufferObject extends VertexBufferObject {
// 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);
}

// ===========================================================
Expand All @@ -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());
}

Expand Down

0 comments on commit beca7b4

Please sign in to comment.