Android Open Source - TinyVoxel Fullscreen Quad






From Project

Back to project page TinyVoxel.

License

The source code is released under:

GNU General Public License

If you think the Android project TinyVoxel listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor./*w  ww.jav a 2  s. com*/
 */

package com.toet.TinyVoxel.Util;

import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.toet.TinyVoxel.Debug.LogHandler;
import com.badlogic.gdx.Gdx;

import static com.badlogic.gdx.graphics.GL20.*;

import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.toet.TinyVoxel.Shaders.ShaderManager;

/**
 *
 * @author Kajos
 */
public class FullscreenQuad {
    
    private final Mesh mesh;
    private final ShaderProgram shader;
    
    public FullscreenQuad(ShaderProgram shaderOverride, boolean flipVertical, boolean flipHorizontal) {
        if (shaderOverride == null) {
            //blitShader
            shader = ShaderManager.get().getShader("shaders/PlainFragment.glsl", "shaders/PlainVertex.glsl");
        } else
            shader = shaderOverride;
            
        //Vertices
        float[] vertices = new float[] {
                                    flipHorizontal ? 1.0f: -1f, flipVertical ? 1f : -1.0f, 0, 0, 1,    
                                    flipHorizontal ? -1.0f: 1f, flipVertical ? 1f : -1.0f, 0, 1, 1,     
                                    flipHorizontal ? -1.0f: 1f, flipVertical ? -1.0f: 1f, 0, 1, 0,    
                                    flipHorizontal ? 1.0f: -1f, flipVertical ? -1.0f: 1f, 0, 0, 0};
        
        //Mesh
        VertexAttribute attr = new VertexAttribute(VertexAttributes.Usage.Position, 3, "position");
        VertexAttribute attr2 = new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "texCoords");
        mesh = new Mesh(true, 4, 0, attr, attr2);
        mesh.setVertices(vertices);
    }

    private String[] textureStrings = new String[]{"texture0", "texture1", "texture2", "texture3", "texture4"};

    public void render(Texture... textures) {
        setStates();

        shader.begin();

        // active texture 0 at last
        for(int i = textures.length - 1; i >= 0; i--){
            textures[i].bind(i);
            shader.setUniformi(textureStrings[i], i);
        }

        mesh.render(shader, GL_TRIANGLE_FAN);

        shader.end();
    }

    public void render(Texture texture) {
        setStates();

        shader.begin();

        // active texture 0 at last
        texture.bind(0);
        shader.setUniformi(textureStrings[0], 0);

        mesh.render(shader, GL_TRIANGLE_FAN);

        shader.end();
    }

    public static void setStates() {
        Gdx.graphics.getGL20().glDisable(GL20.GL_DEPTH_TEST);
        Gdx.graphics.getGL20().glDisable(GL20.GL_BLEND);
        Gdx.graphics.getGL20().glDisable(GL_CULL_FACE);
        Gdx.graphics.getGL20().glDepthMask(false);
        Gdx.graphics.getGL20().glColorMask(true, true, true, true);
    }

    public void render(float value, Texture[] textures) {
        setStates();

        shader.begin();

        // active texture 0 at last
        for(int i = textures.length - 1; i >= 0; i--){
            textures[i].bind(i);
            shader.setUniformi(textureStrings[i], i);
        }
        shader.setUniformf("value", value);

        mesh.render(shader, GL_TRIANGLE_FAN);

        shader.end();
    }

    public void render(int value1, int value2, int value3, Matrix4 matrix, Texture[] textures) {
        setStates();

        shader.begin();

        // active texture 0 at last
        for(int i = textures.length - 1; i >= 0; i--){
            textures[i].bind(i);
            shader.setUniformi(textureStrings[i], i);
        }
        shader.setUniformf("value1", value1);
        shader.setUniformf("value2", value2);
        shader.setUniformf("value3", value3);
        shader.setUniformMatrix("matrix", matrix);

        mesh.render(shader, GL_TRIANGLE_FAN);

        shader.end();
    }

    public void render(Matrix4 mat1, Matrix4 mat2, Cubemap cubemap, Texture[] textures) {
        setStates();

        shader.begin();

        cubemap.bind(textures.length);
        shader.setUniformi("cubemap", textures.length);
        // active texture 0 at last
        for(int i = textures.length - 1; i >= 0; i--){
            textures[i].bind(i);
            shader.setUniformi(textureStrings[i], i);
        }
        shader.setUniformMatrix("mat1", mat1);
        shader.setUniformMatrix("mat2", mat2);

        mesh.render(shader, GL_TRIANGLE_FAN);

        shader.end();
    }

    public void render(Vector3 position, Texture[] textures) {
        setStates();

        shader.begin();

        // active texture 0 at last
        for(int i = textures.length - 1; i >= 0; i--){
            textures[i].bind(i);
            shader.setUniformi(textureStrings[i], i);
        }
        shader.setUniformf("position", position);

        mesh.render(shader, GL_TRIANGLE_FAN);

        shader.end();
    }
    
    public void dispose() {
        mesh.dispose();
    }
}




Java Source Code List

com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration.java
com.badlogic.gdx.backends.gwt.GwtApplication.java
com.badlogic.gdx.backends.gwt.GwtGL20.java
com.badlogic.gdx.backends.gwt.GwtInput.java
com.badlogic.gdx.backends.gwt.GwtNet.java
com.badlogic.gdx.graphics.Pixmap.java
com.toet.TinyVoxel.Config.java
com.toet.TinyVoxel.Game.java
com.toet.TinyVoxel.IOSConfig.java
com.toet.TinyVoxel.IOSLauncher.java
com.toet.TinyVoxel.OuyaController.java
com.toet.TinyVoxel.Time.java
com.toet.TinyVoxel.Character.Character.java
com.toet.TinyVoxel.Debug.LogHandler.java
com.toet.TinyVoxel.GameControllers.CharacterController.java
com.toet.TinyVoxel.GameControllers.CustomTouchPad.java
com.toet.TinyVoxel.GameControllers.KeyBoardController.java
com.toet.TinyVoxel.GameControllers.TouchPadController.java
com.toet.TinyVoxel.Importer.BinvoxImporter.java
com.toet.TinyVoxel.Importer.DataInputStream.java
com.toet.TinyVoxel.Importer.MeshImporter.java
com.toet.TinyVoxel.Renderer.BlockBuilder.java
com.toet.TinyVoxel.Renderer.Floor.java
com.toet.TinyVoxel.Renderer.Manager.java
com.toet.TinyVoxel.Renderer.Bundles.ArrayBundle.java
com.toet.TinyVoxel.Renderer.Bundles.Bundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridBundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridInterface.java
com.toet.TinyVoxel.Renderer.Bundles.Grid.java
com.toet.TinyVoxel.Renderer.Bundles.GroundBundle.java
com.toet.TinyVoxel.Renderer.Bundles.SingleBundle.java
com.toet.TinyVoxel.Renderer.Bundles.TinyGrid.java
com.toet.TinyVoxel.Renderer.Tools.BrushUtils.java
com.toet.TinyVoxel.Renderer.Tools.GridUtils.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedBoolean.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedInteger.java
com.toet.TinyVoxel.Screens.GUI.java
com.toet.TinyVoxel.Screens.Menu.java
com.toet.TinyVoxel.Shaders.ShaderManager.java
com.toet.TinyVoxel.Shadow.ShadowManager.java
com.toet.TinyVoxel.Util.Box.java
com.toet.TinyVoxel.Util.FullscreenQuad.java
com.toet.TinyVoxel.Util.JobManager.java
com.toet.TinyVoxel.Util.NonBackedTexture.java
com.toet.TinyVoxel.Util.Position.java
com.toet.TinyVoxel.Util.RLEInputStream.java
com.toet.TinyVoxel.Util.RLEOutputStream.java
com.toet.TinyVoxel.Util.SimpleMath.java
com.toet.TinyVoxel.Util.StreamUtil.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.client.GwtConfig.java
com.toet.TinyVoxel.client.HtmlLauncher.java
com.toet.TinyVoxel.desktop.DesktopConfig.java
com.toet.TinyVoxel.desktop.DesktopLauncher.java