# Class ShaderProgram

java.lang.Object
javax.media.j3d.SceneGraphObject
javax.media.j3d.NodeComponent
javax.media.j3d.ShaderProgram

Direct Known Subclasses:
  `CgShaderProgram, GLSLShaderProgram`

public abstract class ShaderProgram extends NodeComponent
The ShaderProgram node component object is the abstract base class for programmable shader programs. Each concrete instance of a ShaderProgram is a container for a set of Shader objects. The set of Shaders contained in the ShaderProgram is a complete program for the Graphics Pipeline Unit (GPU) of the graphics accelerator. It is specified using the shader language defined by the ShaderProgram. The currently defined shader languages are: Cg and GLSL.

NOTE: Applications should not extend this class.

Since:
  Java 3D 1.4
See Also:
  - `Shader`
  - `ShaderAppearance.setShaderProgram(ShaderProgram)`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ALLOW_NAMES_READ`
Specifies that this ShaderProgram object allows reading its shader or vertex attribute names.
`static final int`
`ALLOW_SHADERS_READ`
Specifies that this ShaderProgram object allows reading its shaders.

## Method Summary

Modifier and Type
Method
Description
`abstract String[]`
`getShaderAttrNames()`
Retrieves the shader attribute names array from this ShaderProgram object.
`abstract Shader[]`
`getShaders()`
Retrieves the array of shaders from this shader program.
`abstract String[]`
`getVertexAttrNames()`
Retrieves the vertex attribute names array from this ShaderProgram object.
`abstract void`
`setShaderAttrNames(String[] shaderAttrNames)`
Sets the shader attribute names array for this ShaderProgram object.
`abstract void`
`setShaders(Shader[] shaders)`
Copies the specified array of shaders into this shader program.
`abstract void`
`setVertexAttrNames(String[] vertexAttrNames)`
Sets the vertex attribute names array for this ShaderProgram object.

### Methods inherited from class NodeComponent

`cloneNodeComponent, cloneNodeComponent, duplicateNodeComponent, duplicateNodeComponent, getDuplicateOnCloneTree, setDuplicateOnCloneTree`

### Methods inherited from class SceneGraphObject

`clearCapability, clearCapabilityIsFrequent, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getName, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setName, setUserData, toString, updateNodeReferences`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### ALLOW_SHADERS_READ

public static final int ALLOW_SHADERS_READ
Specifies that this ShaderProgram object allows reading its shaders.

See Also:
  - Constant Field Values

### ALLOW_NAMES_READ

public static final int ALLOW_NAMES_READ
Specifies that this ShaderProgram object allows reading its shader or vertex attribute names.

See Also:
  - Constant Field Values

## Method Details

### setVertexAttrNames

public abstract void setVertexAttrNames(String[] vertexAttrNames)
Sets the vertex attribute names array for this ShaderProgram object. Each element in the array specifies the shader attribute name that is bound to the corresponding numbered vertex attribute within a GeometryArray object that uses this shader program. Array element 0 specifies the name of GeometryArray vertex attribute 0, array element 1 specifies the name of GeometryArray vertex attribute 1, and so forth. The array of names may be null or empty (0 length), but the elements of the array must be non-null.

Parameters:
  `vertexAttrNames` - array of vertex attribute names for this shader program. A copy of this array is made.
Throws:
  `RestrictedAccessException` - if the method is called when this object is part of live or compiled scene graph.
  `NullPointerException` - if any element in the vertexAttrNames array is null.

### getVertexAttrNames

public abstract String[] getVertexAttrNames()
Retrieves the vertex attribute names array from this ShaderProgram object.

Returns:
  a copy of this ShaderProgram's array of vertex attribute names.
Throws:
  `CapabilityNotSetException` - if appropriate capability is not set and this object is part of live or compiled scene graph

### setShaderAttrNames

public abstract void setShaderAttrNames(String[] shaderAttrNames)
Sets the shader attribute names array for this ShaderProgram object. Each element in the array specifies a shader attribute name that may be set via a ShaderAttribute object. Only those attributes whose names that appear in the shader attribute names array can be set for a given shader program. The array of names may be null or empty (0 length), but the elements of the array must be non-null.

TODO: finish this.

Parameters:
  `shaderAttrNames` - array of shader attribute names for this shader program. A copy of this array is made.
Throws:
  `RestrictedAccessException` - if the method is called when this object is part of live or compiled scene graph.
  `NullPointerException` - if any element in the shaderAttrNames array is null.

### getShaderAttrNames

public abstract String[] getShaderAttrNames()
Retrieves the shader attribute names array from this ShaderProgram object.

Returns:
  a copy of this ShaderProgram's array of shader attribute names.
Throws:
  `CapabilityNotSetException` - if appropriate capability is not set and this object is part of live or compiled scene graph

### setShaders

public abstract void setShaders(Shader[] shaders)
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 match the subclass. Subclasses may impose additional restrictions.

Parameters:
  `shaders` - array of Shader objects to be copied into this ShaderProgram
Throws:
  `RestrictedAccessException` - if the method is called when this object is part of live or compiled scene graph.
  `IllegalArgumentException` - if the shading language of any shader in the shaders array doesn't match the type of the subclass.
  `NullPointerException` - if any element in the shaders array is null.

### getShaders

public abstract Shader[] getShaders()
Retrieves the array of shaders from this shader program. A shallow copy of the array is returned. The return value may be null.

Returns:
  a copy of this ShaderProgram's array of Shader objects
Throws:
  `CapabilityNotSetException` - if appropriate capability is not set and this object is part of live or compiled scene graph