Search in sources :

Example 1 with Renderable

use of com.badlogic.gdx.graphics.g3d.Renderable in project libgdx by libgdx.

the class BillboardParticleBatch method allocRenderable.

protected Renderable allocRenderable() {
    Renderable renderable = new Renderable();
    renderable.meshPart.primitiveType = GL20.GL_TRIANGLES;
    renderable.meshPart.offset = 0;
    renderable.material = new Material(this.blendingAttribute, this.depthTestAttribute, TextureAttribute.createDiffuse(texture));
    renderable.meshPart.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH * 6, currentAttributes);
    renderable.meshPart.mesh.setIndices(indices);
    renderable.shader = shader;
    return renderable;
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable) Mesh(com.badlogic.gdx.graphics.Mesh) Material(com.badlogic.gdx.graphics.g3d.Material)

Example 2 with Renderable

use of com.badlogic.gdx.graphics.g3d.Renderable in project libgdx by libgdx.

the class BillboardParticleBatch method setTexture.

public void setTexture(Texture texture) {
    renderablePool.freeAll(renderables);
    renderables.clear();
    for (int i = 0, free = renderablePool.getFree(); i < free; ++i) {
        Renderable renderable = renderablePool.obtain();
        TextureAttribute attribute = (TextureAttribute) renderable.material.get(TextureAttribute.Diffuse);
        attribute.textureDescription.texture = texture;
    }
    this.texture = texture;
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 3 with Renderable

use of com.badlogic.gdx.graphics.g3d.Renderable in project libgdx by libgdx.

the class BillboardParticleBatch method allocShader.

private void allocShader() {
    Renderable newRenderable = allocRenderable();
    shader = newRenderable.shader = getShader(newRenderable);
    renderablePool.free(newRenderable);
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable)

Example 4 with Renderable

use of com.badlogic.gdx.graphics.g3d.Renderable in project libgdx by libgdx.

the class BillboardParticleBatch method clearRenderablesPool.

private void clearRenderablesPool() {
    renderablePool.freeAll(renderables);
    for (int i = 0, free = renderablePool.getFree(); i < free; ++i) {
        Renderable renderable = renderablePool.obtain();
        renderable.meshPart.mesh.dispose();
    }
    renderables.clear();
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable)

Example 5 with Renderable

use of com.badlogic.gdx.graphics.g3d.Renderable in project libgdx by libgdx.

the class MultipleRenderTargetTest method render.

@Override
public void render() {
    track += Gdx.graphics.getDeltaTime();
    Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    cameraController.update(Gdx.graphics.getDeltaTime());
    renderContext.begin();
    frameBuffer.begin();
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    renerablePool.flush();
    renderables.clear();
    modelCache.begin(camera);
    modelCache.add(cannon);
    modelCache.add(floorInstance);
    for (Light light : lights) {
        light.update(Gdx.graphics.getDeltaTime());
        modelCache.add(light.lightInstance);
    }
    modelCache.end();
    modelCache.getRenderables(renderables, renerablePool);
    for (Renderable renderable : renderables) {
        renderable.shader = shaderProvider.getShader(renderable);
    }
    renderableSorter.sort(camera, renderables);
    Shader currentShader = null;
    for (int i = 0; i < renderables.size; i++) {
        final Renderable renderable = renderables.get(i);
        if (currentShader != renderable.shader) {
            if (currentShader != null)
                currentShader.end();
            currentShader = renderable.shader;
            currentShader.begin(camera, renderContext);
        }
        currentShader.render(renderable);
    }
    if (currentShader != null)
        currentShader.end();
    frameBuffer.end();
    mrtSceneShader.begin();
    mrtSceneShader.setUniformi("u_diffuseTexture", renderContext.textureBinder.bind(frameBuffer.getColorBufferTexture(DIFFUSE_ATTACHMENT)));
    mrtSceneShader.setUniformi("u_normalTexture", renderContext.textureBinder.bind(frameBuffer.getColorBufferTexture(NORMAL_ATTACHMENT)));
    mrtSceneShader.setUniformi("u_positionTexture", renderContext.textureBinder.bind(frameBuffer.getColorBufferTexture(POSITION_ATTACHMENT)));
    mrtSceneShader.setUniformi("u_depthTexture", renderContext.textureBinder.bind(frameBuffer.getColorBufferTexture(DEPTH_ATTACHMENT)));
    for (int i = 0; i < lights.size; i++) {
        Light light = lights.get(i);
        mrtSceneShader.setUniformf("lights[" + i + "].lightPosition", light.position);
        mrtSceneShader.setUniformf("lights[" + i + "].lightColor", light.color);
    }
    mrtSceneShader.setUniformf("u_viewPos", camera.position);
    mrtSceneShader.setUniformMatrix("u_inverseProjectionMatrix", camera.invProjectionView);
    quad.render(mrtSceneShader, GL30.GL_TRIANGLE_FAN);
    mrtSceneShader.end();
    renderContext.end();
    batch.disableBlending();
    batch.begin();
    batch.draw(frameBuffer.getColorBufferTexture(DIFFUSE_ATTACHMENT), 0, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
    batch.draw(frameBuffer.getColorBufferTexture(NORMAL_ATTACHMENT), Gdx.graphics.getWidth() / 4f, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
    batch.draw(frameBuffer.getColorBufferTexture(POSITION_ATTACHMENT), 2 * Gdx.graphics.getWidth() / 4f, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
    batch.draw(frameBuffer.getColorBufferTexture(DEPTH_ATTACHMENT), 3 * Gdx.graphics.getWidth() / 4f, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
    batch.end();
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable) Shader(com.badlogic.gdx.graphics.g3d.Shader)

Aggregations

Renderable (com.badlogic.gdx.graphics.g3d.Renderable)16 Material (com.badlogic.gdx.graphics.g3d.Material)8 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)5 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 Model (com.badlogic.gdx.graphics.g3d.Model)3 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)3 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)3 AssetManager (com.badlogic.gdx.assets.AssetManager)2 Mesh (com.badlogic.gdx.graphics.Mesh)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 Texture (com.badlogic.gdx.graphics.Texture)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Environment (com.badlogic.gdx.graphics.g3d.Environment)2 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)2 Shader (com.badlogic.gdx.graphics.g3d.Shader)2 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)2 PointLight (com.badlogic.gdx.graphics.g3d.environment.PointLight)2 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)2 DefaultTextureBinder (com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder)2 RenderContext (com.badlogic.gdx.graphics.g3d.utils.RenderContext)2