de.ikosa.mars.viewer.glviewer.engine.GLSSQScene.java Source code

Java tutorial

Introduction

Here is the source code for de.ikosa.mars.viewer.glviewer.engine.GLSSQScene.java

Source

/*
 * Copyright (C) 2013 Clemens-Alexander Brust IT-Dienstleistungen
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.ikosa.mars.viewer.glviewer.engine;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;

public class GLSSQScene {
    private GLMesh ssqMesh;

    public GLSSQScene(GLResources resourceManager, GLShader postShader, GLTexture postColor0Texture,
            GLTexture postDepthTexture, GLShader post2Shader, GLTexture post2Color0Texture) {
        // get screen space quad
        ssqMesh = resourceManager.getMesh("ScreenSpaceQuad");

        // configure material
        GLFrameBufferMaterial material = (GLFrameBufferMaterial) ssqMesh.getSubMesh(0).getMaterial();

        material.setPostShader(postShader);
        material.setPostColor0Texture(postColor0Texture);
        material.setPostDepthTexture(postDepthTexture);

        material.setPost2Shader(post2Shader);
        material.setPost2Color0Texture(post2Color0Texture);
    }

    public void Pass(GLScene.PassType passType) {
        ssqMesh.use();
        for (int m = 0; m < ssqMesh.getSubMeshCount(); m++) {
            GLSubMesh subMesh = ssqMesh.getSubMesh(m);
            GLMaterial ssqMaterial = subMesh.getMaterial();
            GLShader ssqShader = ssqMaterial.preparePass(passType, GLScene.DrawModifier.None);
            if (ssqShader != null) {
                GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, subMesh.getIndexVboId());
                GL11.glDrawElements(GL11.GL_TRIANGLES, subMesh.getIndexCount(), GL11.GL_UNSIGNED_INT, 0);
            }
        }
    }
}