Search in sources :

Example 21 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class VertexBufferObjectSubData method unbind.

@Override
public void unbind(final ShaderProgram shader, final int[] locations) {
    final GL20 gl = Gdx.gl20;
    final int numAttributes = attributes.size();
    if (locations == null) {
        for (int i = 0; i < numAttributes; i++) {
            shader.disableVertexAttribute(attributes.get(i).alias);
        }
    } else {
        for (int i = 0; i < numAttributes; i++) {
            final int location = locations[i];
            if (location >= 0)
                shader.disableVertexAttribute(location);
        }
    }
    gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
    isBound = false;
}
Also used : GL20(com.badlogic.gdx.graphics.GL20)

Example 22 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class VertexBufferObjectSubData method bind.

@Override
public void bind(final ShaderProgram shader, final int[] locations) {
    final GL20 gl = Gdx.gl20;
    gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);
    if (isDirty) {
        byteBuffer.limit(buffer.limit() * 4);
        gl.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage);
        isDirty = false;
    }
    final int numAttributes = attributes.size();
    if (locations == null) {
        for (int i = 0; i < numAttributes; i++) {
            final VertexAttribute attribute = attributes.get(i);
            final int location = shader.getAttributeLocation(attribute.alias);
            if (location < 0)
                continue;
            shader.enableVertexAttribute(location);
            shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset);
        }
    } else {
        for (int i = 0; i < numAttributes; i++) {
            final VertexAttribute attribute = attributes.get(i);
            final int location = locations[i];
            if (location < 0)
                continue;
            shader.enableVertexAttribute(location);
            shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset);
        }
    }
    isBound = true;
}
Also used : GL20(com.badlogic.gdx.graphics.GL20) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute)

Example 23 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class ShaderProgram method setUniform1fv.

public void setUniform1fv(String name, float[] values, int offset, int length) {
    GL20 gl = Gdx.gl20;
    checkManaged();
    int location = fetchUniformLocation(name);
    gl.glUniform1fv(location, length, values, offset);
}
Also used : GL20(com.badlogic.gdx.graphics.GL20)

Example 24 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class ShaderProgram method setUniform3fv.

public void setUniform3fv(int location, float[] values, int offset, int length) {
    GL20 gl = Gdx.gl20;
    checkManaged();
    gl.glUniform3fv(location, length / 3, values, offset);
}
Also used : GL20(com.badlogic.gdx.graphics.GL20)

Example 25 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class CullTest method render.

@Override
public void render() {
    GL20 gl = Gdx.gl20;
    gl.glClearColor(0, 0, 0, 0);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL20.GL_DEPTH_TEST);
    cam.update();
    modelBatch.begin(cam);
    int visible = 0;
    for (int i = 0; i < instances.length; i++) {
        instances[i].transform.getTranslation(pos);
        if (cam.frustum.sphereInFrustum(pos, 1)) {
            ((ColorAttribute) instances[i].materials.get(0).get(ColorAttribute.Diffuse)).color.set(Color.WHITE);
            visible++;
        } else {
            ((ColorAttribute) instances[i].materials.get(0).get(ColorAttribute.Diffuse)).color.set(Color.RED);
        }
        modelBatch.render(instances[i]);
    }
    modelBatch.end();
    if (Gdx.input.isKeyPressed(Keys.A))
        cam.rotate(20 * Gdx.graphics.getDeltaTime(), 0, 1, 0);
    if (Gdx.input.isKeyPressed(Keys.D))
        cam.rotate(-20 * Gdx.graphics.getDeltaTime(), 0, 1, 0);
    gl.glDisable(GL20.GL_DEPTH_TEST);
    batch.begin();
    font.draw(batch, "visible: " + visible + "/100" + ", fps: " + Gdx.graphics.getFramesPerSecond(), 0, 20);
    batch.end();
}
Also used : GL20(com.badlogic.gdx.graphics.GL20)

Aggregations

GL20 (com.badlogic.gdx.graphics.GL20)52 IntBuffer (java.nio.IntBuffer)3 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)2 Cubemap (com.badlogic.gdx.graphics.Cubemap)1 ByteBuffer (java.nio.ByteBuffer)1