1 /* 2 * $RCSfile: ShaderAttributeObject.java,v $ 3 * 4 * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Sun designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Sun in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 24 * CA 95054 USA or visit www.sun.com if you need additional information or 25 * have any questions. 26 * 27 * $Revision: 1.5 $ 28 * $Date: 2008/02/28 20:17:29 $ 29 * $State: Exp $ 30 */ 31 32 package javax.media.j3d; 33 34 import javax.vecmath.*; 35 36 /** 37 * The ShaderAttributeObject class is an abstract class that 38 * encapsulates a uniform shader attribute whose value is specified 39 * explicitly. This class has concrete subclasses for single-value 40 * attributes (ShaderAttributeValue) and array attributes 41 * (ShaderAttributeArray). The shader variable <code>attrName</code> 42 * is explicitly set to the specified <code>value</code> during 43 * rendering. <code>attrName</code> must be the name of a valid 44 * uniform attribute in the shader in which it is used. Otherwise, the 45 * attribute name will be ignored and a runtime error may be 46 * generated. The <code>value</code> must be an instance of one of the 47 * allowed classes or an array of one the allowed classes. The allowed 48 * classes are: <code>Integer</code>, <code>Float</code>, 49 * <code>Tuple{2,3,4}{i,f}</code>, 50 * <code>Matrix{3,4}f</code>. A ClassCastException will be thrown 51 * if a specified <code>value</code> object is not one of the allowed 52 * types. Further, the type of the value is immutable once a 53 * ShaderAttributeObject is constructed. Subsequent setValue 54 * operations must be called with an object of the same type as the 55 * one that was used to construct the ShaderAttributeObject. Finally, 56 * the type of the <code>value</code> object must match the type of 57 * the corresponding <code>attrName</code> variable in the shader in 58 * which it is used. Otherwise, the shader will not be able to use the 59 * attribute and a runtime error may be generated. 60 * 61 * @see ShaderAttributeSet 62 * @see ShaderProgram 63 * 64 * @since Java 3D 1.4 65 */ 66 67 public abstract class ShaderAttributeObject extends ShaderAttribute { 68 69 /** 70 * Specifies that this ShaderAttributeObject allows reading its value. 71 */ 72 public static final int 73 ALLOW_VALUE_READ = 74 CapabilityBits.SHADER_ATTRIBUTE_OBJECT_ALLOW_VALUE_READ; 75 76 /** 77 * Specifies that this ShaderAttributeObject allows writing its value. 78 */ 79 public static final int 80 ALLOW_VALUE_WRITE = 81 CapabilityBits.SHADER_ATTRIBUTE_OBJECT_ALLOW_VALUE_WRITE; 82 83 84 // Array for setting default read capabilities 85 private static final int[] readCapabilities = { 86 ALLOW_VALUE_READ 87 }; 88 89 90 /** 91 * Package scope constructor 92 */ ShaderAttributeObject(String attrName, Object value)93 ShaderAttributeObject(String attrName, Object value) { 94 super(attrName); 95 96 // set default read capabilities 97 setDefaultReadCapabilities(readCapabilities); 98 99 ((ShaderAttributeObjectRetained)this.retained).createObjectData(value); 100 } 101 102 103 /** 104 * Retrieves the value of this shader attribute. 105 * A copy of the object is returned. 106 * 107 * @return a copy of the value of this shader attribute 108 * 109 * @exception CapabilityNotSetException if appropriate capability is 110 * not set and this object is part of live or compiled scene graph 111 */ getValue()112 public abstract Object getValue(); 113 114 /** 115 * Sets the value of this shader attribute to the specified value. 116 * A copy of the object is stored. 117 * 118 * @param value the new value of the shader attribute 119 * 120 * @exception NullPointerException if value is null 121 * 122 * @exception ClassCastException if value is not an instance of 123 * the same base class as the object used to construct this shader 124 * attribute object. 125 * 126 * @exception CapabilityNotSetException if appropriate capability is 127 * not set and this object is part of live or compiled scene graph 128 */ setValue(Object value)129 public abstract void setValue(Object value); 130 131 /** 132 * Retrieves the base class of the value of this shader attribute. 133 * This class will always be one of the allowable classes, even if 134 * a subclass was used to construct this shader attribute object. 135 * For example, if this shader attribute object was constructed 136 * with an instance of <code>javax.vecmath.Point3f</code>, the 137 * returned class would be <code>javax.vecmath.Tuple3f</code>. 138 * 139 * @return the base class of the value of this shader attribute 140 * 141 * @exception CapabilityNotSetException if appropriate capability is 142 * not set and this object is part of live or compiled scene graph 143 */ getValueClass()144 public Class getValueClass() { 145 146 return ((ShaderAttributeObjectRetained)this.retained).getValueClass(); 147 } 148 149 } 150