Derm.Render.ShaderObject Class Reference

Shader object. More...

Inheritance diagram for Derm.Render.ShaderObject:
Derm.Render.RenderObject Derm.Render.IShaderState Derm.Render.IRenderObject Derm.Render.IReferenced Derm.Render.Shaders.MeshFragmentShader Derm.Render.Shaders.MeshVertexShader Derm.Render.Shaders.ProjectRigidVertex Derm.Render.Shaders.StdDirLightShader Derm.Render.Shaders.StdLightModelShader Derm.Render.Shaders.StdPosLightShader Derm.Render.Shaders.StdSpotLightShader Derm.Render.Shaders.TransformState

List of all members.

Public Member Functions

 ShaderObject (int sType, string sSourcePath)
 Construct a ShaderObject defining its main class and the source strings.
 ShaderObject (int sType, IEnumerable< string > sSource, IEnumerable< string > sInterface)
 Construct a ShaderObject defining its main class and the source strings.
 ShaderObject (int sType, IEnumerable< string > sSource)
 Construct a ShaderObject defining its main class and the source strings.
override void Create (RenderContext ctx)
 Create this ShaderObject.
override void Delete (RenderContext ctx)
 Delete this ShaderObject.
void SetState (RenderContext ctx, ShaderProgram sProgram)
 Set shader program state.

Static Public Member Functions

static ShaderObject GetShaderObject (string sName)
 Obtain precompiled shader object instance.
static void RegisterShaderObject (string sName, ShaderObject sText)
 Register a ShaderObject by name for future creations.

Protected Member Functions

 ShaderObject (int sType)
 Construct a ShaderObject defining its main class.

Static Protected Member Functions

static void AppendHeader (List< string > mSource, int sVersion)
 Append default source header.
static void AppendSourceStrings (List< string > sLines, string sPath)
 Append every line stored in a file.
static void AppendSourceStrings (List< string > sLines, IEnumerable< string > source)
 Append a constant array of strings.

Properties

IEnumerable< ShaderObjectAttachments [get]
 Shader objects required for correct linkage.
virtual IEnumerable< string > Defines [get]
 Shader source preprocessor definitions.
virtual string[] Interface [get]
 Shader object source interface.
virtual string[] Source [get]
 Shader object source strings.

Events

CompilerEventHandler CompilerEvent
 Compiler event.
LinkerEventHandler LinkerEvent
 Linker event.

Detailed Description

Shader object.

A ShaderObject is a function library allowing to compose a ShaderProgram. The ShaderObject is characterized by its source code; the source code has to be compiled, before being linked with a ShaderProgram instance. A single ShaderObject could be linked with one or more ShaderProgram instances. Once linked, it doesn't have the reason to be allocated anymore (except for reuse in another program linkage).

A ShaderObject instance has a main class, which determine the execution stage of the code, when the formed ShaderProgram is executed. The possible shader classes are:

A ShaderObject can be correctly linked only with ShaderObject of the same class. Implementing a ShaderObject on external definition of a ShaderObject with different class will result in a link error.

This class automatically builds the source code of each ShaderObject. The generated source code has the following strings:

The standard header is composed from standard pragmas (current shader version, debug or optimization pragmas). This source in invariant.

Shader program preprocessor definitions are supplied by the ShaderProgram holding the ShaderObject. Indeed preprocessor definitions are shared between every ShaderObject linked with the same ShaderProgram. This source changes depending on shader program linkage.

A ShaderObject source is determined completly by derived implementation. The source could be hardcoded, defined at runtime or loaded from external storage. This source changes depending on ShaderObject concrete implementation.


Constructor & Destructor Documentation

Derm.Render.ShaderObject.ShaderObject ( int  sType,
IEnumerable< string >  sSource 
)

Construct a ShaderObject defining its main class and the source strings.

Parameters:
sType A System.Int32 indicating the shader class. Simply an integer which can assume the values Gl.VERTEX_SHADER, Gl.FRAGMENT_SHADER or Gl.GEOMETRY_SHADER.
sSource A IEnumerable<string> specifying the shader object source strings.
Derm.Render.ShaderObject.ShaderObject ( int  sType,
IEnumerable< string >  sSource,
IEnumerable< string >  sInterface 
)

Construct a ShaderObject defining its main class and the source strings.

Parameters:
sType A System.Int32 indicating the shader class. Simply an integer which can assume the values Gl.VERTEX_SHADER, Gl.FRAGMENT_SHADER or Gl.GEOMETRY_SHADER.
sSource A IEnumerable<string> specifying the shader object source strings.

/

Parameters:
sSource A IEnumerable<string> specifying the shader object interface strings.
Derm.Render.ShaderObject.ShaderObject ( int  sType,
string  sSourcePath 
)

Construct a ShaderObject defining its main class and the source strings.

Parameters:
sType A System.Int32 indicating the shader class. Simply an integer which can assume the values Gl.VERTEX_SHADER, Gl.FRAGMENT_SHADER or Gl.GEOMETRY_SHADER.
sSourcePath A System.String specifying the file containing the shader object source strings.
Derm.Render.ShaderObject.ShaderObject ( int  sType  )  [protected]

Construct a ShaderObject defining its main class.

Parameters:
sType A System.Int32 indicating the shader class. Simply an integer which can assume the values Gl.VERTEX_SHADER, Gl.FRAGMENT_SHADER or Gl.GEOMETRY_SHADER.

Member Function Documentation

static void Derm.Render.ShaderObject.AppendHeader ( List< string >  mSource,
int  sVersion 
) [static, protected]

Append default source header.

Parameters:
sLines A List<System.String> which represent the current shader object source lines.
sVersion A System.Int32 representing the shader language version to use in generated shader.
static void Derm.Render.ShaderObject.AppendSourceStrings ( List< string >  sLines,
string  sPath 
) [static, protected]

Append every line stored in a file.

Parameters:
sLines A List<string> representing the current shader source.
sPath A System.String which specify the path for accessing to the file containing the source to append.
static void Derm.Render.ShaderObject.AppendSourceStrings ( List< string >  sLines,
IEnumerable< string >  source 
) [static, protected]

Append a constant array of strings.

Parameters:
sLines A List<string> representing the current shader source.
source A System.String[] which represents the source for be appended at the end of the source sLines .

This is a simple utility routine will appends an array of strings to a source line list. Note that this routine automatically add the end-of-line character for each string present in source .

override void Derm.Render.ShaderObject.Create ( RenderContext  ctx  )  [virtual]

Create this ShaderObject.

Parameters:
ctx 

Implements Derm.Render.RenderObject.

override void Derm.Render.ShaderObject.Delete ( RenderContext  ctx  )  [virtual]

Delete this ShaderObject.

Parameters:
ctx 

Implements Derm.Render.RenderObject.

static ShaderObject Derm.Render.ShaderObject.GetShaderObject ( string  sName  )  [static]

Obtain precompiled shader object instance.

Parameters:
sName 
Returns:
It returns a ShaderObject instance already compiled.

These ShaderObject instances can be used for linking programs, without the need to generate and compile a specific ShaderObject instance.

This approach allow to minimize shader objects allocation, avoid compilation of generated source and hopefully speedup the linkage process.

static void Derm.Render.ShaderObject.RegisterShaderObject ( string  sName,
ShaderObject  sText 
) [static]

Register a ShaderObject by name for future creations.

Parameters:
sName 
sText 

Every shader object which doesn't depends on conditional symbols can be compiled once and then linked with others shader objects for bein attached to a ShaderProgram.

void Derm.Render.ShaderObject.SetState ( RenderContext  ctx,
ShaderProgram  sProgram 
)

Set shader program state.

Parameters:
ctx A RenderContext used to set the shader program state.
sProgram A ShaderProgram

This routine does nothing. There isn't any reason to allow shader object to modify shader program state.

Implements Derm.Render.IShaderState.


Property Documentation

IEnumerable<ShaderObject> Derm.Render.ShaderObject.Attachments [get]

Shader objects required for correct linkage.

This method returns always null. ShaderObject doesn't define additional attachments.

Implements Derm.Render.IShaderState.

virtual IEnumerable<string> Derm.Render.ShaderObject.Defines [get]

Shader source preprocessor definitions.

Automatic preprocessor defines introduced by the presence of this ShaderObject in linkage operations. Default implementation returns always null.

This automatic mechanism allow to adapt shader sources depending on the linkage status of external shader objects. This method is qualified as virtual in the way to allow override in derived classes.

Implements Derm.Render.IShaderState.

virtual string [] Derm.Render.ShaderObject.Interface [get, protected]

Shader object source interface.

virtual string [] Derm.Render.ShaderObject.Source [get, protected]

Shader object source strings.

This property is fundamental for shader object source code. It is meant as the text lines composing the shader source, without the the following elements:

  • version directive
  • pragma {optimization|debug} directives The elements listed above are appended automatically when the shader source is generated.

Event Documentation

CompilerEventHandler Derm.Render.ShaderObject.CompilerEvent

Compiler event.

Implements Derm.Render.IShaderState.

LinkerEventHandler Derm.Render.ShaderObject.LinkerEvent

Linker event.

Implements Derm.Render.IShaderState.



Services powered by Get Deus Ex Render Machina at SourceForge.net. Fast, secure and Free Open Source software downloads