Java tutorial
/* * 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.GL20; public class GLFrameBufferMaterial extends GLMaterial { private GLShader forwardShader; private GLTexture forwardTexture = new GLTexture("", 0); private GLShader postShader; private GLTexture postColor0Texture = new GLTexture("", 0); private GLTexture postDepthTexture = new GLTexture("", 0); private GLShader post2Shader; private GLTexture post2Color0Texture = new GLTexture("", 0); private float sizeX, sizeY; public GLFrameBufferMaterial(String name, float sizeX, float sizeY) { super(name); this.sizeX = sizeX; this.sizeY = sizeY; } @Override public boolean isCompatible(boolean hasNormals, boolean hasTexCoords) { return !hasNormals & hasTexCoords; } @Override public GLShader preparePass(GLScene.PassType passType, GLScene.DrawModifier drawModifier) { switch (passType) { case Forward: if (forwardShader != null) { forwardShader.use(); forwardTexture.use(forwardShader.getTextureImageUnitColor0()); } return forwardShader; case PostProcess: if (postShader != null) { postShader.use(); GL20.glUniform1f(postShader.getUniformValuePixelSizeH(), sizeX); GL20.glUniform1f(postShader.getUniformValuePixelSizeV(), sizeY); postColor0Texture.use(postShader.getTextureImageUnitColor0()); postDepthTexture.use(postShader.getTextureImageUnitDepth()); } return postShader; case PostProcess2: if (post2Shader != null) { post2Shader.use(); GL20.glUniform1f(post2Shader.getUniformValuePixelSizeH(), sizeX); GL20.glUniform1f(post2Shader.getUniformValuePixelSizeV(), sizeY); post2Color0Texture.use(post2Shader.getTextureImageUnitColor0()); } return post2Shader; } return null; } public void setForwardShader(GLShader forwardShader) { this.forwardShader = forwardShader; } public void setPostShader(GLShader postShader) { this.postShader = postShader; } public void setForwardTexture(GLTexture forwardTexture) { this.forwardTexture = forwardTexture; } public void setPostColor0Texture(GLTexture postColor0Texture) { this.postColor0Texture = postColor0Texture; } public void setPostDepthTexture(GLTexture postDepthTexture) { this.postDepthTexture = postDepthTexture; } public void setPost2Shader(GLShader post2Shader) { this.post2Shader = post2Shader; } public void setPost2Color0Texture(GLTexture post2Color0Texture) { this.post2Color0Texture = post2Color0Texture; } }