Package WildMagic.LibGraphics.Effects
Class ShaderEffect
- java.lang.Object
-
- WildMagic.LibGraphics.ObjectSystem.GraphicsObject
-
- WildMagic.LibGraphics.Effects.Effect
-
- WildMagic.LibGraphics.Effects.ShaderEffect
-
- All Implemented Interfaces:
java.io.Serializable
,NameIdInterface
,StreamInterface
- Direct Known Subclasses:
DefaultShaderEffect
,GoochEffect
,IridescenceEffect
,LatticeEffect
,LightingEffect
,MaterialEffect
,MaterialTextureEffect
,RipplingOceanEffect
,SimpleBumpMapEffect
,TextureEffect
,VertexColor3Effect
,WireframeBehindEffect
public class ShaderEffect extends Effect implements NameIdInterface, StreamInterface, java.io.Serializable
The shader effect is a manager of the vertex and pixel shaders. It reimplements the user-relevant interfaces for the managed objects as a convenience to avoid long expressions involving pointer dereferencing.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_iPassQuantity
The number of passesprotected java.util.Vector<AlphaState>
m_kAlphaState
The AlphaState blending modesprotected java.util.Vector<Program>
m_kCompiledPrograms
The Compiled Programsprotected java.util.Vector<PixelShader>
m_kPShader
The PixelShadersprotected java.util.Vector<VertexShader>
m_kVShader
The VertexShadersprivate static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description ShaderEffect()
streaming constructorShaderEffect(int iPassQuantity)
Creates a ShaderEffect with the specified number of rendering passes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Delete data members:void
GetAllObjectsByName(java.lang.String rkName, java.util.Vector<GraphicsObject> rkObjects)
Writes all GraphicsObjects with the name that matches the input parameter, rkName into the Vector parameter rkObjects.AlphaState
GetBlending(int iPass)
Blending modes for multipass effects.Program
GetCProgram(int iPass)
Returns the Vertex program for the ith Passint
GetDiskUsed(StreamVersion rkVersion)
Returns the size of this object and it's children on disk for the current StreamVersion parameter.GraphicsObject
GetObjectByID(int uiID)
Returns the GraphicsObject with the ID that matches the input parameter, uiID.GraphicsObject
GetObjectByName(java.lang.String rkName)
Returns the GraphicsObject with the name that matches the input parameter, rkName.int
GetPassQuantity()
Program
GetPProgram(int iPass)
Returns the PixelProgram for the ith PassSamplerInformation
GetSamplerInformation(int iPass, int i)
Returns the SamplerInformation for the iPass & ith PixelShaderTexture
GetTexture(int iPass, int i)
Returns the Texture with the specified name for the ith PixelShaderTexture
GetTexture(int iPass, java.lang.String kSamplerImageName)
Returns the Texture with the specified name for the ith PixelShaderint
GetTextureQuantity(int iPass)
Returns the number of Textures for the ith PixelShaderProgram
GetVProgram(int iPass)
Returns the Vertex program for the ith Passvoid
Link(Stream rkStream, Stream.Link pkLink)
Copies this objects children objects from the input Stream's HashTable, based on the LinkID of the child stored in the pkLink parameter.void
Load(Stream rkStream, Stream.Link pkLink)
Loads this object from the input parameter rkStream, using the input Stream.Link to store the IDs of children objects of this object for linking after all objects are loaded from the Stream.void
LoadPrograms(Renderer kRenderer, Geometry pkGeometry, int iPass, int iMaxColors, int iMaxTCoords, int iMaxVShaderImages, int iMaxPShaderImages)
The renderers call this to load the shader programs from disk.void
LoadResources(Renderer pkRenderer, Geometry pkGeometry)
The functions are called by Renderer::LoadResources and Renderer::ReleaseResources for Geometry and Effect objects.void
OnLoadPrograms(int iPass, Program pkVProgram, Program pkPProgram, Program pkCProgram)
This function is called in LoadPrograms once the shader programs are created.void
OnReleasePrograms(int iPass, Program pkVProgram, Program pkPProgram)
This function is called in ReleasePrograms once the shader programs are ready to be released.boolean
Register(Stream rkStream)
Registers this object with the input Stream parameter.void
ReleasePrograms(int iPass)
Releases the Vertex and Pixel programsvoid
ReleaseResources(Renderer pkRenderer, Geometry pkGeometry)
The functions are called by Renderer::LoadResources and Renderer::ReleaseResources for Geometry and Effect objects.void
RestoreGlobalState(int iPass, Renderer pkRenderer, boolean bPrimaryEffect)
Set any global state needed by the pass and restore it later.void
Save(Stream rkStream)
Write this object and all it's children to the Stream.StringTree
SaveStrings(java.lang.String acTitle)
Write this object into a StringTree for the scene-graph visualization.void
SetCProgram(int iPass, Program kCProgram)
protected void
SetDefaultAlphaState()
Create default alpha states.void
SetGlobalState(int iPass, Renderer pkRenderer, boolean bPrimaryEffect)
Set any global state needed by the pass and restore it later.void
SetPassQuantity(int iPassQuantity)
The number of vertex/pixel shader pairs.void
SetPShader(int iPass, PixelShader pkPShader)
Sets the Pixel shader for the ith Passvoid
SetVShader(int iPass, VertexShader pkVShader)
Sets the Vertex shader for the ith Pass-
Methods inherited from class WildMagic.LibGraphics.ObjectSystem.GraphicsObject
GetID, GetName, GetNextID, GetObjectByIDBase, GetObjectByNameBase, SetName
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
m_iPassQuantity
protected int m_iPassQuantity
The number of passes
-
m_kVShader
protected java.util.Vector<VertexShader> m_kVShader
The VertexShaders
-
m_kPShader
protected java.util.Vector<PixelShader> m_kPShader
The PixelShaders
-
m_kCompiledPrograms
protected java.util.Vector<Program> m_kCompiledPrograms
The Compiled Programs
-
m_kAlphaState
protected java.util.Vector<AlphaState> m_kAlphaState
The AlphaState blending modes
-
-
Method Detail
-
dispose
public void dispose()
Delete data members:- Overrides:
dispose
in classGraphicsObject
-
GetVProgram
public Program GetVProgram(int iPass)
Returns the Vertex program for the ith Pass- Parameters:
iPass
- the ith rendering pass- Returns:
- the ith VertexProgram
-
GetAllObjectsByName
public void GetAllObjectsByName(java.lang.String rkName, java.util.Vector<GraphicsObject> rkObjects)
Writes all GraphicsObjects with the name that matches the input parameter, rkName into the Vector parameter rkObjects.- Specified by:
GetAllObjectsByName
in interfaceNameIdInterface
- Overrides:
GetAllObjectsByName
in classGraphicsObject
- Parameters:
rkName
- the name of the objects to return.rkObjects
- a Vector of all objects with the matching name.
-
GetBlending
public AlphaState GetBlending(int iPass)
Blending modes for multipass effects. Mode i specifies how the pixel colors from pass i-1 and pass i are blended. For a single effect attached to a Geometry object, blending mode 0 is irrelevant in that the source mode is equivalent to SBF_ONE and the destination mode is equivalent to SDF_ZERO; that is, the frame buffer values are replaced with the pixel values from the shader. If multiple effects are attached to a Geometry object, blending mode 0 specifies how the current effect is blended with the frame buffer.- Parameters:
iPass
- the ith rendering pass- Returns:
- the Alpha state associated with the rendering pass
-
GetCProgram
public Program GetCProgram(int iPass)
Returns the Vertex program for the ith Pass- Parameters:
iPass
- the ith rendering pass- Returns:
- the ith VertexProgram
-
GetPProgram
public Program GetPProgram(int iPass)
Returns the PixelProgram for the ith Pass- Parameters:
iPass
- the ith rendering pass- Returns:
- the ith PixelProgram
-
GetDiskUsed
public int GetDiskUsed(StreamVersion rkVersion)
Returns the size of this object and it's children on disk for the current StreamVersion parameter.- Specified by:
GetDiskUsed
in interfaceStreamInterface
- Overrides:
GetDiskUsed
in classEffect
- Parameters:
rkVersion
- the current version of the Stream file being created.- Returns:
- the size of this object on disk.
-
GetObjectByID
public GraphicsObject GetObjectByID(int uiID)
Returns the GraphicsObject with the ID that matches the input parameter, uiID.- Specified by:
GetObjectByID
in interfaceNameIdInterface
- Overrides:
GetObjectByID
in classGraphicsObject
- Parameters:
uiID
- the ID of the object to return.- Returns:
- the GraphicsObject that matches the input name.
-
GetObjectByName
public GraphicsObject GetObjectByName(java.lang.String rkName)
Returns the GraphicsObject with the name that matches the input parameter, rkName.- Specified by:
GetObjectByName
in interfaceNameIdInterface
- Overrides:
GetObjectByName
in classGraphicsObject
- Parameters:
rkName
- the name of the object to return.- Returns:
- the GraphicsObject that matches the input name.
-
GetPassQuantity
public int GetPassQuantity()
- Returns:
- The number of vertex/pixel shader pairs.
-
GetSamplerInformation
public SamplerInformation GetSamplerInformation(int iPass, int i)
Returns the SamplerInformation for the iPass & ith PixelShader- Parameters:
iPass
- the ith rendering passith
- SamplerInformation- Returns:
- the Texture with the specified name for the ith PixelShader
-
GetTexture
public Texture GetTexture(int iPass, int i)
Returns the Texture with the specified name for the ith PixelShader- Parameters:
iPass
- the ith rendering passrkName
- the name of the texture- Returns:
- the Texture with the specified name for the ith PixelShader
-
GetTexture
public Texture GetTexture(int iPass, java.lang.String kSamplerImageName)
Returns the Texture with the specified name for the ith PixelShader- Parameters:
iPass
- the ith rendering passrkName
- the name of the texture- Returns:
- the Texture with the specified name for the ith PixelShader
-
GetTextureQuantity
public int GetTextureQuantity(int iPass)
Returns the number of Textures for the ith PixelShader- Parameters:
iPass
- the ith rendering pass- Returns:
- the number of Textures for the ith PixelShader
-
Link
public void Link(Stream rkStream, Stream.Link pkLink)
Copies this objects children objects from the input Stream's HashTable, based on the LinkID of the child stored in the pkLink parameter.- Specified by:
Link
in interfaceStreamInterface
- Overrides:
Link
in classEffect
- Parameters:
rkStream
- the Stream where the child objects are stored.pkLink
- the Link class from which the child object IDs are read.
-
Load
public void Load(Stream rkStream, Stream.Link pkLink)
Loads this object from the input parameter rkStream, using the input Stream.Link to store the IDs of children objects of this object for linking after all objects are loaded from the Stream.- Specified by:
Load
in interfaceStreamInterface
- Overrides:
Load
in classEffect
- Parameters:
rkStream
- the Stream from which this object is being read.pkLink
- the Link class for storing the IDs of this object's children objects.
-
LoadPrograms
public void LoadPrograms(Renderer kRenderer, Geometry pkGeometry, int iPass, int iMaxColors, int iMaxTCoords, int iMaxVShaderImages, int iMaxPShaderImages)
The renderers call this to load the shader programs from disk. If a program load fails, the shader object is replaced by the default shader object. Conditions for failure: (1) The shader program file is not found. (2) The output of the vertex program and the input of the pixel program are not compatible. (3) The shader program requires more color parameters than supported by the renderer. (4) The pixel program requires more texture iamge units than supported by the renderer. (5) The shader program requires more texture coordinate sets than supported by the renderer.- Parameters:
kRenderer
- the Renderer objectiPass
- the ith rendering passiMaxColors
- the maximum colors supported by the rendereriMaxTCoords
- the maximum texture coordinaets sets supported by the rendereriMaxVShaderImages
- the maximum vertex-shader texture images sets supported by the rendereriMaxPShaderImages
- the maximum pixel-shader texture images sets supported by the renderer
-
LoadResources
public void LoadResources(Renderer pkRenderer, Geometry pkGeometry)
The functions are called by Renderer::LoadResources and Renderer::ReleaseResources for Geometry and Effect objects. Loads the programs into the shader objects and video memory- Overrides:
LoadResources
in classEffect
- Parameters:
pkRenderer
- the Rederer objectpkGeometry
- the Geometry the ShaderEffect is applied to
-
OnLoadPrograms
public void OnLoadPrograms(int iPass, Program pkVProgram, Program pkPProgram, Program pkCProgram)
This function is called in LoadPrograms once the shader programs are created. It gives the ShaderEffect-derived classes a chance to do any additional work to hook up the effect with the low-level objects.- Parameters:
iPass
- the ith rendering pass
-
OnReleasePrograms
public void OnReleasePrograms(int iPass, Program pkVProgram, Program pkPProgram)
This function is called in ReleasePrograms once the shader programs are ready to be released. It gives the ShaderEffect-derived classes a chance to do any additional work to unhook the low-level objects from the effect.- Parameters:
iPass
- the ith rendering pass
-
Register
public boolean Register(Stream rkStream)
Registers this object with the input Stream parameter. All objects streamed to disk are registered with the Stream so that a unique list of objects is maintained.- Specified by:
Register
in interfaceStreamInterface
- Overrides:
Register
in classEffect
- Parameters:
rkStream
- the Stream where the child objects are stored.- Returns:
- true if this object is registered, false if the object has already been registered.
-
ReleasePrograms
public void ReleasePrograms(int iPass)
Releases the Vertex and Pixel programs- Parameters:
iPass
- the ith rendering pass
-
ReleaseResources
public void ReleaseResources(Renderer pkRenderer, Geometry pkGeometry)
The functions are called by Renderer::LoadResources and Renderer::ReleaseResources for Geometry and Effect objects. Releases the programs from the shader objects and video memory- Overrides:
ReleaseResources
in classEffect
- Parameters:
pkRenderer
- the Rederer objectpkGeometry
- the Geometry the ShaderEffect is applied to
-
RestoreGlobalState
public void RestoreGlobalState(int iPass, Renderer pkRenderer, boolean bPrimaryEffect)
Set any global state needed by the pass and restore it later. The base class enables and disables blending as needed for multipass and multieffect drawing.- Parameters:
iPass
- the ith rendering passpkRenderer
- the Rendering objectbPrimaryEffect
- primary or secondary
-
Save
public void Save(Stream rkStream)
Write this object and all it's children to the Stream.- Specified by:
Save
in interfaceStreamInterface
- Overrides:
Save
in classEffect
- Parameters:
rkStream
- the Stream where the child objects are stored.
-
SaveStrings
public StringTree SaveStrings(java.lang.String acTitle)
Write this object into a StringTree for the scene-graph visualization.- Specified by:
SaveStrings
in interfaceStreamInterface
- Overrides:
SaveStrings
in classEffect
- Parameters:
acTitle
- the header for this object in the StringTree.- Returns:
- StringTree containing a String-based representation of this object and it's children.
-
SetCProgram
public void SetCProgram(int iPass, Program kCProgram)
-
SetGlobalState
public void SetGlobalState(int iPass, Renderer pkRenderer, boolean bPrimaryEffect)
Set any global state needed by the pass and restore it later. The base class enables and disables blending as needed for multipass and multieffect drawing.- Parameters:
iPass
- the ith rendering passpkRenderer
- the Rendering objectbPrimaryEffect
- primary or secondary
-
SetPassQuantity
public void SetPassQuantity(int iPassQuantity)
The number of vertex/pixel shader pairs. The Set* call reallocates the vertex shader, pixel shader, and alpha state arrays.- Parameters:
iPassQuantity
- The number of vertex/pixel shader pairs.
-
SetPShader
public void SetPShader(int iPass, PixelShader pkPShader)
Sets the Pixel shader for the ith Pass- Parameters:
iPass
- the ith rendering passpkPShader
- PixelShader
-
SetVShader
public void SetVShader(int iPass, VertexShader pkVShader)
Sets the Vertex shader for the ith Pass- Parameters:
iPass
- the ith rendering passpkVShader
- VertexShader
-
SetDefaultAlphaState
protected void SetDefaultAlphaState()
Create default alpha states. The Renderer enables this on a multieffect drawing operation. The first pass uses the default alpha state (SBF_SRC_ALPHA, DBF_ONE_MINUS_SRC_ALPHA). All other passes use modulation and all are enabled. These may be overridden by your application code by accessing the state via effect->GetBlending(pass).
-
-