use of com.badlogic.gdx.graphics.glutils.IndexBufferObjectSubData in project libgdx by libgdx.
the class VBOWithVAOPerformanceTest method create.
@Override
public void create() {
if (Gdx.gl30 == null) {
throw new GdxRuntimeException("GLES 3.0 profile required for this test");
}
String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n" + "{ \n" + " v_color = a_color; \n" + " v_texCoords = a_texCoord0; \n" + " gl_Position = u_worldView * a_position; \n" + "} \n";
String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false) {
Gdx.app.log("ShaderTest", shader.getLog());
Gdx.app.exit();
}
int numSprites = 1000;
int maxIndices = numSprites * 6;
int maxVertices = numSprites * 6;
VertexAttribute[] vertexAttributes = new VertexAttribute[] { VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0) };
VertexBufferObjectWithVAO newVBOWithVAO = new VertexBufferObjectWithVAO(false, maxVertices, vertexAttributes);
OldVertexBufferObjectWithVAO oldVBOWithVAO = new OldVertexBufferObjectWithVAO(false, maxVertices, vertexAttributes);
IndexBufferObjectSubData newIndices = new IndexBufferObjectSubData(false, maxIndices);
IndexBufferObjectSubData oldIndices = new IndexBufferObjectSubData(false, maxIndices);
newVBOWithVAOMesh = new Mesh(newVBOWithVAO, newIndices, false) {
};
oldVBOWithVAOMesh = new Mesh(oldVBOWithVAO, oldIndices, false) {
};
float[] vertexArray = new float[maxVertices * 9];
int index = 0;
int stride = 9 * 6;
for (int i = 0; i < numSprites; i++) {
addRandomSprite(vertexArray, index);
index += stride;
}
short[] indexArray = new short[maxIndices];
for (short i = 0; i < maxIndices; i++) {
indexArray[i] = i;
}
newVBOWithVAOMesh.setVertices(vertexArray);
newVBOWithVAOMesh.setIndices(indexArray);
oldVBOWithVAOMesh.setVertices(vertexArray);
oldVBOWithVAOMesh.setIndices(indexArray);
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
batch = new SpriteBatch();
bitmapFont = new BitmapFont();
stringBuilder = new StringBuilder();
}
Aggregations