use of com.badlogic.gdx.utils.GdxRuntimeException 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();
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class ShaderLoader method load.
protected void load(final StringBuilder out, final String name) {
final int idx = name.lastIndexOf(':');
final String fileName = idx < 0 ? name : name.substring(0, idx);
final String snipName = idx < 0 || (idx >= name.length() - 1) ? "" : name.substring(idx + 1);
ObjectMap<String, String> snips = snippets.get(fileName, null);
if (snips == null) {
snips = parse(root.child(fileName));
snippets.put(fileName, snips);
}
String result = snips.get(snipName, null);
if (result == null)
throw new GdxRuntimeException("No snippet [" + snipName + "] in file " + root.child(fileName).path());
parse(out, fileName, result);
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class ShaderLoader method parse.
protected ObjectMap<String, String> parse(final FileHandle file) {
ObjectMap<String, String> result = new ObjectMap<String, String>();
BufferedReader reader = file.reader(1024);
String line;
String snipName = "";
stringBuilder.setLength(0);
int idx;
try {
while ((line = reader.readLine()) != null) {
if (line.length() > 3 && line.charAt(0) == '[' && (idx = line.indexOf(']')) > 1) {
if (snipName.length() > 0 || stringBuilder.length() > 0)
result.put(snipName, stringBuilder.toString());
stringBuilder.setLength(0);
snipName = line.substring(1, idx);
} else
stringBuilder.append(line.trim()).append("\r\n");
}
} catch (IOException e) {
throw new GdxRuntimeException(e);
}
if (snipName.length() > 0 || stringBuilder.length() > 0)
result.put(snipName, stringBuilder.toString());
return result;
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class HeightField method set.
public void set(float[] data, int offset) {
if (this.data.length > (data.length - offset))
throw new GdxRuntimeException("Incorrect data size");
System.arraycopy(data, offset, this.data, 0, this.data.length);
update();
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class BaseShadowSystem method begin.
@Override
public <T extends RenderableProvider> void begin(Camera camera, final Iterable<T> renderableProviders) {
if (this.renderableProviders != null || this.camera != null)
throw new GdxRuntimeException("Call end() first.");
this.camera = camera;
this.renderableProviders = (Iterable<RenderableProvider>) renderableProviders;
}
Aggregations