Workspace 6.21.5
Public Member Functions | Protected Member Functions | List of all members
Shader Class Referenceabstract

Interface for shaders, which are used to control the appearance of objects drawn by a renderer. Generally, developers will not want to derive from this directly, rather they will want to derive from TypedShader, and create one or more specific derivations of the ShaderImplementation class. More...

#include <Rendering/SceneComponents/Shaders/shader.h>

Inheritance diagram for Shader:
[legend]

Public Member Functions

 ~Shader () override
 
bool activate (SceneRenderer &renderer)
 Activates the shader on the target WSGLRenderer in preparation for drawing an object.
 
virtual bool appliesScreenSpaceAmbientOcclusion ()
 
virtual bool appliesSpecular ()
 
virtual bool appliesTransparency () const =0
 
Shaderclone () const override=0
 
bool deactivate (SceneRenderer &renderer)
 Deactivates the shader on the target WSGLRenderer, setting it back to the state it was in before the shader was bound.
 
int getId () const
 
Mesh::MeshModelSource::MeshModelInterfaceLockedPtr getMeshModelInterface (const QString &modelId, Mesh::MeshModelLibrary &modelLib)
 
bool getModelSourceUpdateRequested () const
 
bool getOptimizeOutInternalVolumeElements () const
 
double getSegmentLineWidth () const
 
virtual TexturizergetTexturizer ()
 
virtual const TexturizergetTexturizer () const
 
bool renderCurrentModel (SceneRenderer &renderer)
 Renders the model currently being processed by the specified renderer.s.
 
bool renderCurrentModelGlyphs (SceneRenderer &renderer)
 
void setOptimizeOutInternalVolumeElements (bool val)
 
void setSegmentLineWidth (double width)
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 

Protected Member Functions

 Shader ()
 
 Shader (const Shader &shader)
 
void addImplementation (const SceneRendererContext &context, ShaderImplementation &impl)
 
void setId (int id)
 

Detailed Description

See also
TypedShader
ShaderImplementation

Constructor & Destructor Documentation

◆ Shader() [1/2]

Shader ( )
protected

◆ Shader() [2/2]

Shader ( const Shader shader)
protected

◆ ~Shader()

~Shader ( )
override

Member Function Documentation

◆ activate()

bool activate ( SceneRenderer renderer)

Activating the shader sets up the target renderer so that when it draws the next object, it will be rendered using the technique the shader provides. If the shader's implementation makes use of hardware shader programs, the shader program will be bound to the device, causing the geometry of any models drawn while the shader is enabled to be rendered using the hardware shader.

For example, the usual order of events is as follows:

   - Activate shader
   - Bind geometry to the device
   - Enable transform
   - Draw primitives

NOTE: Most users will want to derive from TypedShader, which has already implemented this function. In this case, create an implementation class for the WSGLRenderer and include it as a template parameter to TypedShader when creating the shader subclass.

Parameters
rendererThe renderer on which we are activating this shader.

◆ addImplementation()

void addImplementation ( const SceneRendererContext context,
ShaderImplementation impl 
)
protected
Parameters
contextThe rendering context to which this shader implementation belongs. This makes sure that each shader implementation (and therefore any state that it stores) is bound to a single context, and therefore renderers that share a context will share shader state.
implThe implementation object to be used to activate / deactivate on the target renderer.

◆ appliesScreenSpaceAmbientOcclusion()

virtual bool appliesScreenSpaceAmbientOcclusion ( )
inlinevirtual

Sub-classes only need to overide this if they can apply Screen Space Ambient Occlusion

Reimplemented in BillboardImageShader, BlinnPhongShader, ColorStateShader, ElementColoringShader, LambertShader, and NodeColoringShader.

◆ appliesSpecular()

virtual bool appliesSpecular ( )
inlinevirtual

Sub-classes only need to overide this if they apply specular high-lights (eg. Blinn-Phong).

Reimplemented in BlinnPhongShader, ColorStateShader, and NullShader.

◆ appliesTransparency()

virtual bool appliesTransparency ( ) const
pure virtual

◆ clone()

Shader * clone ( ) const
overridepure virtual

◆ deactivate()

bool deactivate ( SceneRenderer renderer)
Parameters
rendererThe renderer on which we are activating this shader.
See also
activate

◆ getId()

int getId ( ) const
Returns
the identifier of this shader.

Every shader instance is required to have a unique identifier. Currently, the assignment of the shader's ID is managed at construction time through a static function.

Note
A Shader's ID is not guaranteed to be identical between sessions. Each time the workspace is loaded, shader Ids are re-generated.

◆ getMeshModelInterface()

Mesh::MeshModelSource::MeshModelInterfaceLockedPtr getMeshModelInterface ( const QString &  modelId,
Mesh::MeshModelLibrary modelLib 
)

Convenience function for returning a MeshModelInterface with a particular id from the specified model library. The modelSourceUpdateRequested flag will be set if the function was unable to retrieve data from its source this time round.

Returns
the model associated with the specified ID in the provided model library.

◆ getModelSourceUpdateRequested()

bool getModelSourceUpdateRequested ( ) const
Returns
true if during the last 'activate' request, a model source update request was made.
See also
getMeshModelInterface

◆ getOptimizeOutInternalVolumeElements()

bool getOptimizeOutInternalVolumeElements ( ) const
Returns
True if the geometry will optimize away (i.e. not use) volume (tetrahedral) elements that are fully internal.

◆ getSegmentLineWidth()

double getSegmentLineWidth ( ) const
Returns
The desired width of segments when rendered with this shader.

◆ getTexturizer() [1/2]

CSIRO::Rendering::Texturizer & getTexturizer ( )
virtual
Returns
Texturizer used by this shader. NoTexture Texturizer will be returned if shader doesn't use any.

Reimplemented in BillboardImageShader, BlinnPhongShader, LambertShader, and TextureCoordShader.

◆ getTexturizer() [2/2]

const CSIRO::Rendering::Texturizer & getTexturizer ( ) const
virtual
Returns
Texturizer used by this shader. NoTexture Texturizer will be returned if shader doesn't use any.

Reimplemented in BillboardImageShader, BlinnPhongShader, LambertShader, and TextureCoordShader.

◆ renderCurrentModel()

bool renderCurrentModel ( SceneRenderer renderer)

◆ renderCurrentModelGlyphs()

bool renderCurrentModelGlyphs ( SceneRenderer renderer)

◆ setId()

void setId ( int  id)
protected
Parameters
idThe identifier to assign to this shader.

A shader's ID is assumed by other parts of the code to be unique, so it is recommended that this function never be used - by either subclasses or external classes.

◆ setOptimizeOutInternalVolumeElements()

void setOptimizeOutInternalVolumeElements ( bool  val)
Parameters
valIf true, then the geometry render will optimize out internal volume (tetrahedral) elements.

◆ setSegmentLineWidth()

void setSegmentLineWidth ( double  width)
Parameters
widthThe desired width of segments when rendered with this shader.