Class ShaderEffect

    • Constructor Summary

      Constructors 
      Constructor Description
      ShaderEffect()
      streaming constructor
      ShaderEffect​(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 Pass
      int 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 Pass
      SamplerInformation GetSamplerInformation​(int iPass, int i)
      Returns the SamplerInformation for the iPass & ith PixelShader
      Texture GetTexture​(int iPass, int i)
      Returns the Texture with the specified name for the ith PixelShader
      Texture GetTexture​(int iPass, java.lang.String kSamplerImageName)
      Returns the Texture with the specified name for the ith PixelShader
      int GetTextureQuantity​(int iPass)
      Returns the number of Textures for the ith PixelShader
      Program GetVProgram​(int iPass)
      Returns the Vertex program for the ith Pass
      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.
      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 programs
      void 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 Pass
      void SetVShader​(int iPass, VertexShader pkVShader)
      Sets the Vertex shader for the ith Pass
      • Methods inherited from class WildMagic.LibGraphics.Effects.Effect

        Draw
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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
    • Constructor Detail

      • ShaderEffect

        public ShaderEffect()
        streaming constructor
      • ShaderEffect

        public ShaderEffect​(int iPassQuantity)
        Creates a ShaderEffect with the specified number of rendering passes.
        Parameters:
        iPassQuantity - The number of vertex/pixel shader pairs.
    • Method Detail

      • 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 interface NameIdInterface
        Overrides:
        GetAllObjectsByName in class GraphicsObject
        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 interface StreamInterface
        Overrides:
        GetDiskUsed in class Effect
        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 interface NameIdInterface
        Overrides:
        GetObjectByID in class GraphicsObject
        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 interface NameIdInterface
        Overrides:
        GetObjectByName in class GraphicsObject
        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 pass
        ith - 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 pass
        rkName - 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 pass
        rkName - 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 interface StreamInterface
        Overrides:
        Link in class Effect
        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 interface StreamInterface
        Overrides:
        Load in class Effect
        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 object
        iPass - the ith rendering pass
        iMaxColors - the maximum colors supported by the renderer
        iMaxTCoords - the maximum texture coordinaets sets supported by the renderer
        iMaxVShaderImages - the maximum vertex-shader texture images sets supported by the renderer
        iMaxPShaderImages - 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 class Effect
        Parameters:
        pkRenderer - the Rederer object
        pkGeometry - 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 interface StreamInterface
        Overrides:
        Register in class Effect
        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 class Effect
        Parameters:
        pkRenderer - the Rederer object
        pkGeometry - 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 pass
        pkRenderer - the Rendering object
        bPrimaryEffect - primary or secondary
      • Save

        public void Save​(Stream rkStream)
        Write this object and all it's children to the Stream.
        Specified by:
        Save in interface StreamInterface
        Overrides:
        Save in class Effect
        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 interface StreamInterface
        Overrides:
        SaveStrings in class Effect
        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 pass
        pkRenderer - the Rendering object
        bPrimaryEffect - 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 pass
        pkPShader - PixelShader
      • SetVShader

        public void SetVShader​(int iPass,
                               VertexShader pkVShader)
        Sets the Vertex shader for the ith Pass
        Parameters:
        iPass - the ith rendering pass
        pkVShader - 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).