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

Base class for all capabilities that can be added to a shader program. More...

#include <Rendering/OpenGL/Shaders/Capabilities/wsglshaderprogramcapability.h>

Inheritance diagram for WSGLShaderProgramCapability:
[legend]

Public Types

enum  UsageFlags { UpdateOnActivate = 0x01 , UpdateOnRender = 0x02 , UpdatePerGlyph = 0x04 }
 

Public Member Functions

virtual ~WSGLShaderProgramCapability ()
 
virtual const WSGLShaderProgramCapabilityIdcapabilityId () const =0
 
virtual const CapabilityIdListdependencies () const =0
 
virtual QString getSource (QOpenGLShader::ShaderType type) const =0
 
virtual UsageFlags getUsageFlags () const =0
 
virtual bool onProgramActivate (WSGLShaderProgram &program, WSGLRenderer &renderer)=0
 
virtual bool onProgramDeactivate (WSGLShaderProgram &program, WSGLRenderer &renderer)=0
 
WSGLShaderProgramCapabilityoperator= (const WSGLShaderProgramCapability &)
 
virtual bool postProgramLink (WSGLShaderProgram &program)=0
 
virtual bool postRenderModel (WSGLShaderProgram &program, WSGLRenderer &renderer, WSGLRenderItem &item)=0
 
virtual bool preRenderGlyph (WSGLShaderProgram &program, WSGLRenderer &renderer, WSGLInstancedItem &item, int instanceNumber)=0
 
virtual bool preRenderModel (WSGLShaderProgram &program, WSGLRenderer &renderer, WSGLRenderItem &item)=0
 

Protected Member Functions

 WSGLShaderProgramCapability ()
 
 WSGLShaderProgramCapability (const WSGLShaderProgramCapability &)
 
QString readSourceFromFile (const QString &filename) const
 

Detailed Description

The WSGLRenderer uses a 'uber' shader model; that is, shaders share a common set of code and are built 'dynamically' when they are compiled in order to minimize the amount of code that a shader developer needs to write.

WSGLShaderImplementation objects are bound to a particular context, and each may instantiate multiple WSGLShaderPrograms. Each one of these programs corresponds to an OpenGL program object, with attached Vertex, Fragment and (potentially) Geometry shaders. In order to make use of commonly used WSGL capabilities such as lighting and transforms, the developer must add WSGLShaderProgramCapability objects to their WSGLShaderProgram. The program will then use these capabilities by invoking the relevant virtual functions at the correct times:

This allows the capability to differentiate between when a model is being rendered with glyphs on and the normal case, when it is rendered without glyphs.

Note
When writing the GLSL for the shaders associated with the program, the developer should refer to the relevant capability documentation in order to make use of the correct variables and functions.

Member Enumeration Documentation

◆ UsageFlags

enum UsageFlags
Enumerator
UpdateOnActivate 
UpdateOnRender 
UpdatePerGlyph 

Constructor & Destructor Documentation

◆ WSGLShaderProgramCapability() [1/2]

◆ WSGLShaderProgramCapability() [2/2]

◆ ~WSGLShaderProgramCapability()

Member Function Documentation

◆ capabilityId()

virtual const WSGLShaderProgramCapabilityId & capabilityId ( ) const
pure virtual

◆ dependencies()

virtual const CapabilityIdList & dependencies ( ) const
pure virtual
Returns
A list of the capabilities that this capability depends on. An error will occur if these capabilities are not also added to a shader program which has this capability added to it.

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ getSource()

virtual QString getSource ( QOpenGLShader::ShaderType  type) const
pure virtual
Returns
The GLSL source code associated with this capability. WSGLShaderPrograms will invoke this function in order to compile a unified shader with all the relevant capabilities.

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ getUsageFlags()

virtual UsageFlags getUsageFlags ( ) const
pure virtual
Returns
The usage flags representing how this capability should be used at render time.

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ onProgramActivate()

virtual bool onProgramActivate ( WSGLShaderProgram program,
WSGLRenderer renderer 
)
pure virtual

Invoked when the program is activated. The WSGLShaderProgram is assumed to be bound. Subclasses can override this function to set up any program or other GL state (such as uniform values) that do not change on a per-render-item basis.

Parameters
programThe program which is being activated.
rendererThe renderer on which the program is being activated.
Returns
true if the activation process was successful, false if errors occurred.
See also
onProgramDeactivate
preRenderModel
postRenderModel

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ onProgramDeactivate()

virtual bool onProgramDeactivate ( WSGLShaderProgram program,
WSGLRenderer renderer 
)
pure virtual

Invoked when the program is deactivated. The WSGLShaderProgram is assumed to be bound. Use this function to clean up any GL state that is common to all items rendered.

Parameters
programThe program which is being deactivated.
rendererThe renderer that the program is being deactivated on.
Returns
true if the deactivation was successful, false if errors occurred.
See also
onProgramActivate
preRenderModel
postRenderModel

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ operator=()

Parameters
rhs

◆ postProgramLink()

virtual bool postProgramLink ( WSGLShaderProgram program)
pure virtual

Invoked immediately after the program is linked. Use this function to stored uniform locations or other variables which will remain constant for the life of the capability.

Parameters
programThe program which has just been linked.

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ postRenderModel()

virtual bool postRenderModel ( WSGLShaderProgram program,
WSGLRenderer renderer,
WSGLRenderItem item 
)
pure virtual

Invoked immediately following the rendering of a WSGLRenderItem (i.e. immediately after a call to glDrawElements or glDrawRangeElements). Use this function to clean up any GL state that changes on a per-item basis. The program is assumed to be bound.

Parameters
programThe program which is rendering the item.
rendererThe renderer which the program has just used to render the item.
itemThe render item just drawn.
Returns
true if the postRenderModel process was successful, false if errors occurred.
See also
preRenderModel
onProgramActivate
onProgramDeactivate

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ preRenderGlyph()

virtual bool preRenderGlyph ( WSGLShaderProgram program,
WSGLRenderer renderer,
WSGLInstancedItem item,
int  instanceNumber 
)
pure virtual

Invoked immediately prior to the rendering of an individual glyph instance (i.e. immediately before a call to glDrawElements or glDrawRangeElements). Use this function to set up any GL state that changes on a per-glyph basis. The program is assumed to be bound.

Note
This function will only be called if the render item is glyphed. For normal rendering, see preRenderModel
Parameters
programThe program which is rendering the item.
rendererThe renderer which the program has just used to render the item.
itemThe instanced item we're going to use to render an instance.
instanceNumberThe instance number of the glyph.
Returns
true if the preRenderModel process was successful, false if errors occurred.
See also
preRenderModel
postRenderGlyph

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ preRenderModel()

virtual bool preRenderModel ( WSGLShaderProgram program,
WSGLRenderer renderer,
WSGLRenderItem item 
)
pure virtual

Invoked immediately prior to the rendering of a WSGLRenderItem (i.e. immediately before a call to glDrawElements or glDrawRangeElements). Use this function to set up any GL state that changes on a per-item basis. The program is assumed to be bound.

Parameters
programThe program which is rendering the item.
rendererThe renderer which the program is about to use to render the item.
itemThe render item about to be drawn.
Returns
true if the preRenderModel process was successful, false if errors occurred.
See also
postRenderModel
onProgramActivate
onProgramDeactivate

Implemented in WSGLBlinnPhongLightingCapability, WSGLClippingCapability, WSGLDepthPeelingCapability, WSGLLambertLightingCapability, WSGLScreenSpaceAmbientOcclusionCapability, and WSGLTransformCapability.

◆ readSourceFromFile()

QString readSourceFromFile ( const QString &  filename) const
protected
Parameters
filenameThe name of the file from which the source is to be read.