org.xith3d.loaders.shaders.base
Class ShaderLoader<T extends Shader>

java.lang.Object
  extended by org.xith3d.loaders.shaders.base.ShaderLoader<T>
Direct Known Subclasses:
AssemblyShaderLoader, GLSLShaderLoader

public abstract class ShaderLoader<T extends Shader>
extends java.lang.Object

Loader base for Shader loaders.


Constructor Summary
protected ShaderLoader()
           
protected ShaderLoader(java.lang.String basePath)
           
protected ShaderLoader(java.net.URL baseURL)
           
 
Method Summary
protected  void cacheShader(java.lang.String cacheTag, T shader)
          Stores the Shader into the cache by the given tag.
 java.lang.String getBasePath()
           
 java.net.URL getBaseURL()
           
protected  T getFromCache(java.lang.String cacheTag)
          Retrieves the Shader from the cache, or null, if the Shader was not cached.
abstract  T loadShader(java.io.InputStream in, Shader.ShaderType type)
          Retrives the Shader from the given InputStream.
abstract  T loadShader(java.io.Reader reader, Shader.ShaderType type)
          Retrives the Shader from the given reader.
abstract  T loadShader(java.lang.String name, Shader.ShaderType type)
          Retrives the Shader with the given name.
abstract  T loadShader(java.net.URL url, Shader.ShaderType type)
          Retrives the Shader from the given URL.
abstract  T loadShaderFromString(java.lang.String source, Shader.ShaderType typ)
          Creates a Shader from the given String.
protected  void popBasePath()
           
protected  void popBaseURL()
           
 void setBasePath(java.lang.String pathName)
          This method sets the base path name for data files associated with the file.
protected  boolean setBasePathFromShaderFile(java.lang.String shaderFilename)
           
 void setBaseURL(java.net.URL url)
          This method sets the base URL name for data files associated with the file.
protected  boolean setBaseURLFromShaderURL(java.net.URL shaderURL)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShaderLoader

protected ShaderLoader()

ShaderLoader

protected ShaderLoader(java.net.URL baseURL)

ShaderLoader

protected ShaderLoader(java.lang.String basePath)
Method Detail

setBaseURL

public void setBaseURL(java.net.URL url)
This method sets the base URL name for data files associated with the file. The baseUrl should be null by default, which is an indicator to the loader that it should look for any associated files starting from the same place as the URL passed into the load(URL) method. Note: Users of setBaseUrl() would then use load(URL) as opposed to load(String).


popBaseURL

protected void popBaseURL()

getBaseURL

public java.net.URL getBaseURL()
Returns:
the current base URL setting.

setBasePath

public void setBasePath(java.lang.String pathName)
This method sets the base path name for data files associated with the file. The basePath should be null by default, which is an indicator to the loader that it should look for any associated files starting from the same directory as the file passed into the load(String) method. Note: Users of setBasePath() would then use load(String) as opposed to load(URL).


popBasePath

protected void popBasePath()

getBasePath

public java.lang.String getBasePath()
Returns:
the current base path setting.

setBaseURLFromShaderURL

protected boolean setBaseURLFromShaderURL(java.net.URL shaderURL)
                                   throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

setBasePathFromShaderFile

protected boolean setBasePathFromShaderFile(java.lang.String shaderFilename)

getFromCache

protected T getFromCache(java.lang.String cacheTag)
Retrieves the Shader from the cache, or null, if the Shader was not cached.

Parameters:
cacheTag - the tag to search the cache for

cacheShader

protected void cacheShader(java.lang.String cacheTag,
                           T shader)
Stores the Shader into the cache by the given tag.

Parameters:
cacheTag - the tag to assotiate the Shader within the cache

loadShader

public abstract T loadShader(java.io.Reader reader,
                             Shader.ShaderType type)
                                     throws java.io.IOException
Retrives the Shader from the given reader.

Parameters:
reader - the reader to load the Shader from
type - the desired Shader type
Returns:
the Shader object
Throws:
java.io.IOException

loadShader

public abstract T loadShader(java.io.InputStream in,
                             Shader.ShaderType type)
                                     throws java.io.IOException
Retrives the Shader from the given InputStream.

Parameters:
in - the InputStream to load the Shader from
type - the desired Shader type
Returns:
the Shader object
Throws:
java.io.IOException

loadShader

public abstract T loadShader(java.net.URL url,
                             Shader.ShaderType type)
                                     throws java.io.IOException
Retrives the Shader from the given URL.

Parameters:
url - the URL to load the Shader from
type - the desired Shader type
Returns:
the Shader object
Throws:
java.io.IOException

loadShader

public abstract T loadShader(java.lang.String name,
                             Shader.ShaderType type)
                                     throws java.io.IOException
Retrives the Shader with the given name. Loading works in the following order:
If the Shader was already loaded and is still in the cache then the existing Shader is returned. So don't modify Shaders returned by this method.
The Shader is loaded from the basePath or basURL.

Parameters:
name - The name of the Shader
type - The desired Shader type
Returns:
the Shader object
Throws:
java.io.IOException

loadShaderFromString

public abstract T loadShaderFromString(java.lang.String source,
                                       Shader.ShaderType typ)
Creates a Shader from the given String. The generated Shader is not cached.

Parameters:
source - The String that should get parsed
Returns:
Shader A Shader object that is based on the current content of the given String