From 7a2e20caac9db6f789a7b3fab344b9758af45335 Mon Sep 17 00:00:00 2001 From: Harvey Harrison Date: Sun, 19 Apr 2015 21:02:06 -0700 Subject: j3dcore: flatten the directory structure a bit Signed-off-by: Harvey Harrison --- src/javax/media/j3d/GLSLShaderProgram.java | 179 +++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 src/javax/media/j3d/GLSLShaderProgram.java (limited to 'src/javax/media/j3d/GLSLShaderProgram.java') diff --git a/src/javax/media/j3d/GLSLShaderProgram.java b/src/javax/media/j3d/GLSLShaderProgram.java new file mode 100644 index 0000000..6e5ef02 --- /dev/null +++ b/src/javax/media/j3d/GLSLShaderProgram.java @@ -0,0 +1,179 @@ +/* + * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ + +package javax.media.j3d; + +/** + * The GLSLShaderProgram object is a concrete implementation of a + * ShaderProgram node component for the OpenGL GLSL shading language. + * + * @see SourceCodeShader + * + * @since Java 3D 1.4 + */ + +public class GLSLShaderProgram extends ShaderProgram { + + /** + * Constructs a GLSL shader program node component. + * + *
+ * TODO: ADD MORE DOCUMENTATION HERE. + */ + public GLSLShaderProgram() { + } + + // Implement abstract setVertexAttrNames method (inherit javadoc from parent class) + @Override + public void setVertexAttrNames(String[] vertexAttrNames) { + checkForLiveOrCompiled(); + + if (vertexAttrNames != null) { + for (int i = 0; i < vertexAttrNames.length; i++) { + if (vertexAttrNames[i] == null) { + throw new NullPointerException(); + } + } + } + + ((GLSLShaderProgramRetained)this.retained).setVertexAttrNames(vertexAttrNames); + } + + // Implement abstract getVertexAttrNames method (inherit javadoc from parent class) + @Override + public String[] getVertexAttrNames() { + + if (isLiveOrCompiled()) { + if(!this.getCapability(ALLOW_NAMES_READ)) { + throw new CapabilityNotSetException(J3dI18N.getString("GLSLShaderProgram0")); + } + } + + return ((GLSLShaderProgramRetained)this.retained).getVertexAttrNames(); + + } + + // Implement abstract setShaderAttrNames method (inherit javadoc from parent class) + @Override + public void setShaderAttrNames(String[] shaderAttrNames) { + checkForLiveOrCompiled(); + + if (shaderAttrNames != null) { + for (int i = 0; i < shaderAttrNames.length; i++) { + if (shaderAttrNames[i] == null) { + throw new NullPointerException(); + } + } + } + + ((GLSLShaderProgramRetained)this.retained).setShaderAttrNames(shaderAttrNames); + } + + // Implement abstract getShaderAttrNames method (inherit javadoc from parent class) + @Override + public String[] getShaderAttrNames() { + + if (isLiveOrCompiled()) { + if(!this.getCapability(ALLOW_NAMES_READ)) { + throw new CapabilityNotSetException(J3dI18N.getString("GLSLShaderProgram0")); + } + } + + return ((GLSLShaderProgramRetained)this.retained).getShaderAttrNames(); + + } + + /** + * Copies the specified array of shaders into this shader + * program. This method makes a shallow copy of the array. The + * array of shaders may be null or empty (0 length), but the + * elements of the array must be non-null. The shading language of + * each shader in the array must be + * SHADING_LANGUAGE_GLSL. Each shader in the array must + * be a SourceCodeShader. + * + * @param shaders array of Shader objects to be copied into this + * ShaderProgram + * + * @exception CapabilityNotSetException if appropriate capability is + * not set and this object is part of live or compiled scene graph + * + * @exception IllegalArgumentException if the shading language of + * any shader in the shaders array is not + * SHADING_LANGUAGE_GLSL. + * + * @exception ClassCastException if any shader in the shaders + * array is not a SourceCodeShader. + * + * @exception NullPointerException if any element in the + * shaders array is null. + */ + @Override + public void setShaders(Shader[] shaders) { + checkForLiveOrCompiled(); + + if(shaders != null) { + // Check shaders for valid shading language and class type + for (int i = 0; i < shaders.length; i++) { + if (shaders[i].getShadingLanguage() != Shader.SHADING_LANGUAGE_GLSL) { + throw new IllegalArgumentException(J3dI18N.getString("GLSLShaderProgram2")); + } + + // Try to cast shader to SourceCodeShader; it will throw + // ClassCastException if it isn't. + SourceCodeShader shad = (SourceCodeShader)shaders[i]; + } + + } + + ((GLSLShaderProgramRetained)this.retained).setShaders(shaders); + } + + // Implement abstract getShaders method (inherit javadoc from parent class) + @Override + public Shader[] getShaders() { + + if (isLiveOrCompiled()) { + if(!this.getCapability(ALLOW_SHADERS_READ)) { + throw new CapabilityNotSetException(J3dI18N.getString("GLSLShaderProgram1")); + } + } + + return ((GLSLShaderProgramRetained)this.retained).getShaders(); + } + + /** + * Creates a retained mode GLSLShaderProgramRetained object that this + * GLSLShaderProgram component object will point to. + */ + @Override + void createRetained() { + this.retained = new GLSLShaderProgramRetained(); + this.retained.setSource(this); + } + + +} -- cgit v1.2.3