001: /*
002: * $RCSfile: SourceCodeShader.java,v $
003: *
004: * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.6 $
028: * $Date: 2008/02/28 20:17:30 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * The SourceCodeShader object is a shader that is defined using
036: * text-based source code. It is used to define the source code for
037: * both vertex and fragment shaders. The currently supported shading
038: * languages are Cg and GLSL.
039: *
040: * @see ShaderProgram
041: *
042: * @since Java 3D 1.4
043: */
044:
045: public class SourceCodeShader extends Shader {
046:
047: /**
048: * Not a public constructor, for internal use
049: */
050: SourceCodeShader() {
051: }
052:
053: /**
054: * Constructs a new shader object of the specified shading
055: * language and shader type from the specified source string.
056: *
057: * @param shadingLanguage the specified shading language, one of:
058: * <code>SHADING_LANGUAGE_GLSL</code> or
059: * <code>SHADING_LANGUAGE_CG</code>.
060: *
061: * @param shaderType the shader type, one of:
062: * <code>SHADER_TYPE_VERTEX</code> or
063: * <code>SHADER_TYPE_FRAGMENT</code>.
064: *
065: * @param shaderSource the shader source code
066: *
067: * @exception NullPointerException if shaderSource is null.
068: */
069:
070: public SourceCodeShader(int shadingLanguage, int shaderType,
071: String shaderSource) {
072: super (shadingLanguage, shaderType);
073: if (shaderSource == null) {
074: throw new NullPointerException();
075: }
076: ((SourceCodeShaderRetained) this .retained)
077: .initShaderSource(shaderSource);
078: }
079:
080: /**
081: * Retrieves the shader source string from this shader object.
082: *
083: * @return the shader source string.
084: */
085: public String getShaderSource() {
086: return ((SourceCodeShaderRetained) this .retained)
087: .getShaderSource();
088: }
089:
090: /**
091: * Creates a retained mode SourceCodeShaderRetained object that this
092: * SourceCodeShader component object will point to.
093: */
094: void createRetained() {
095: this .retained = new SourceCodeShaderRetained();
096: this .retained.setSource(this );
097: // System.err.println("SourceCodeShader.createRetained()");
098: }
099:
100: /**
101: * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
102: */
103: public NodeComponent cloneNodeComponent() {
104: SourceCodeShaderRetained scsRetained = (SourceCodeShaderRetained) retained;
105:
106: SourceCodeShader scs = new SourceCodeShader(scsRetained
107: .getShadingLanguage(), scsRetained.getShaderType(),
108: scsRetained.getShaderSource());
109: scs.duplicateNodeComponent(this );
110: return scs;
111: }
112:
113: /**
114: * Copies all node information from <code>originalNodeComponent</code>
115: * into the current node. This method is called from the
116: * <code>duplicateNode</code> method. This routine does
117: * the actual duplication of all "local data" (any data defined in
118: * this object).
119: *
120: * @param originalNodeComponent the original node to duplicate
121: * @param forceDuplicate when set to <code>true</code>, causes the
122: * <code>duplicateOnCloneTree</code> flag to be ignored. When
123: * <code>false</code>, the value of each node's
124: * <code>duplicateOnCloneTree</code> variable determines whether
125: * NodeComponent data is duplicated or copied.
126: *
127: * @see Node#cloneTree
128: * @see NodeComponent#setDuplicateOnCloneTree
129: */
130: void duplicateAttributes(NodeComponent originalNodeComponent,
131: boolean forceDuplicate) {
132: super
133: .duplicateAttributes(originalNodeComponent,
134: forceDuplicate);
135:
136: String sc = ((SourceCodeShaderRetained) originalNodeComponent.retained)
137: .getShaderSource();
138:
139: if (sc != null) {
140: ((SourceCodeShaderRetained) retained).setShaderSource(sc);
141: }
142: }
143:
144: }
|