Search in sources :

Example 81 with GdxRuntimeException

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();
}
Also used : IndexBufferObjectSubData(com.badlogic.gdx.graphics.glutils.IndexBufferObjectSubData) StringBuilder(com.badlogic.gdx.utils.StringBuilder) Mesh(com.badlogic.gdx.graphics.Mesh) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexBufferObjectWithVAO(com.badlogic.gdx.graphics.glutils.VertexBufferObjectWithVAO) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 82 with GdxRuntimeException

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);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 83 with GdxRuntimeException

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;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 84 with GdxRuntimeException

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();
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 85 with GdxRuntimeException

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;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) RenderableProvider(com.badlogic.gdx.graphics.g3d.RenderableProvider)

Aggregations

GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)202 IOException (java.io.IOException)40 FileHandle (com.badlogic.gdx.files.FileHandle)14 Array (com.badlogic.gdx.utils.Array)13 Texture (com.badlogic.gdx.graphics.Texture)12 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)9 InputStream (java.io.InputStream)9 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)7 BufferedInputStream (java.io.BufferedInputStream)7 File (java.io.File)7 OutputStream (java.io.OutputStream)7 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)6 LifecycleListener (com.badlogic.gdx.LifecycleListener)5 ByteBuffer (java.nio.ByteBuffer)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4