Wasabi
Public Member Functions | Static Public Member Functions | Friends | List of all members
WEffect Class Reference

#include <WEffect.hpp>

Inheritance diagram for WEffect:
WFileAsset WBase

Public Member Functions

virtual std::string GetTypeName () const override
 
virtual void SetID (uint32_t newID) override
 
virtual void SetName (std::string newName) override
 
 WEffect (class Wasabi *const app, uint32_t ID=0)
 
WError BindShader (WShader *shader)
 
WError UnbindShader (W_SHADER_TYPE type)
 
void SetPrimitiveTopology (VkPrimitiveTopology topology)
 
void SetBlendingState (VkPipelineColorBlendAttachmentState state)
 
void SetBlendingStates (vector< VkPipelineColorBlendAttachmentState > states)
 
void SetDepthStencilState (VkPipelineDepthStencilStateCreateInfo state)
 
void SetRasterizationState (VkPipelineRasterizationStateCreateInfo state)
 
WError BuildPipeline (class WRenderTarget *rt)
 
WError Bind (class WRenderTarget *rt)
 
void SetRenderFlags (W_EFFECT_RENDER_FLAGS flags)
 
W_EFFECT_RENDER_FLAGS GetRenderFlags () const
 
class WMaterialCreateMaterial (uint32_t bindingSet=0, bool isPerFrame=false)
 
VkPipelineLayout GetPipelineLayout () const
 
VkDescriptorSetLayout GetDescriptorSetLayout (uint32_t setIndex=0) const
 
W_INPUT_LAYOUT GetInputLayout (uint32_t layout_index=0) const
 
size_t GetInputLayoutSize (uint32_t layout_index=0) const
 
virtual bool Valid () const override
 
virtual WError SaveToStream (WFile *file, std::ostream &outputStream) override
 
virtual WError LoadFromStream (WFile *file, std::istream &inputStream, std::vector< void * > &args, std::string nameSuffix) override
 
- Public Member Functions inherited from WFileAsset
 WFileAsset (class Wasabi *const app, uint32_t ID=0)
 
virtual WError LoadFromStream (class WFile *file, std::istream &inputStream, vector< void * > &args, std::string nameSuffix)=0
 
- Public Member Functions inherited from WBase
 WBase (class Wasabi *const app, uint32_t ID=0)
 
uint32_t GetID () const
 
std::string GetName () const
 
class WasabiGetAppPtr () const
 
void AddReference ()
 
void RemoveReference ()
 

Static Public Member Functions

static std::string _GetTypeName ()
 
static std::vector< void * > LoadArgs (class WRenderTarget *rt, bool bSaveData=false)
 

Friends

class WMaterial
 

Additional Inherited Members

- Protected Attributes inherited from WBase
class Wasabim_app
 
uint32_t m_ID
 
std::string m_name
 

Detailed Description

A WEffect is a container for shaders, rendering states, and the Vulkan graphics (or compute) pipeline. An effect specifies how rendering of geometry is to be done. More generally, an effect controls all stages of a Vulkan pipeline.

Example:

WShader* vs = new MyVertexShader(m_app);
vs->Load();
WShader* ps = new MyPixelShader(m_app);
ps->Load();
WEffect* myFX = new WEffect(m_app);
myFX->BindShader(vs);
myFX->BindShader(ps);
myFX->BuildPipeline(m_app->Renderer->GetDefaultRenderTarget());

Member Function Documentation

◆ _GetTypeName()

static std::string WEffect::_GetTypeName ( )
static

Returns "Effect" string.

Returns
Returns "Effect" string

◆ Bind()

WError WEffect::Bind ( class WRenderTarget rt)

Binds the effect (pipeline) to render command buffer of the specified render target. The render target must have its Begin() function called before this function is called. Binding an effect means binding all descriptor sets of all specified materials and binding the effect's pipeline.

Parameters
rtRender target to bind to its command buffer
Returns
Error code, see WError.h

◆ BindShader()

WError WEffect::BindShader ( WShader shader)

Binds a shader to this effect.

Parameters
shaderNew shader to bind
Returns
Error code, see WError.h

◆ BuildPipeline()

WError WEffect::BuildPipeline ( class WRenderTarget rt)

Builds Vulkan pipelines corresponding to the currently bound shaders and Vulkan states. This function will build several pipelines for different numbers of input layout supplied by the shaders. For instance, a shader with two input layouts will have two pipelines, one that only uses one input layout and another that uses both. This is done to provide convenience when one wishes to use the same effect without supplying all required vertex shaders.

Parameters
rtRender target that the effect plans on rendering to
Returns
Error code, see WError.h

◆ CreateMaterial()

class WMaterial* WEffect::CreateMaterial ( uint32_t  bindingSet = 0,
bool  isPerFrame = false 
)

Allocates a new material for this effect.

Parameters
bindingSetThe binding set to use from this effect
isPerFrameIf set to true, this material will be bound to the pipeline automatically every time this effect is bound
Returns
Newly allocated and initialized material

◆ GetDescriptorSetLayout()

VkDescriptorSetLayout WEffect::GetDescriptorSetLayout ( uint32_t  setIndex = 0) const

Retrieves the Vulkan descriptor set layout.

Parameters
Indexof the specified set
Returns
The Vulkan descriptor set layout

◆ GetInputLayout()

W_INPUT_LAYOUT WEffect::GetInputLayout ( uint32_t  layout_index = 0) const

Retrieves an input layout supplied by one of the bound shaders.

Parameters
layout_indexIndex of the layout requested
Returns
The input layout at layout_index supplied by bound shaders

◆ GetInputLayoutSize()

size_t WEffect::GetInputLayoutSize ( uint32_t  layout_index = 0) const

Retrieves the size of the input layout at the given index.

Parameters
layout_indexIndex of the layout requested
Returns
The size of the input layout at the given index

◆ GetPipelineLayout()

VkPipelineLayout WEffect::GetPipelineLayout ( ) const

Retrieves the layout of the pipelines created by this effect.

Returns
The Vulkan pipeline layout for the effect's pipelines

◆ GetRenderFlags()

W_EFFECT_RENDER_FLAGS WEffect::GetRenderFlags ( ) const

Retrieves the render flags of this effect. See WEffect::SetRenderFlags.

Returns
Render flags of this effect

◆ GetTypeName()

virtual std::string WEffect::GetTypeName ( ) const
overridevirtual

This function must be implemented by a child class. This is used for debugging, in which a class should return its name.

Returns
The name of the class

Implements WBase.

◆ SetBlendingState()

void WEffect::SetBlendingState ( VkPipelineColorBlendAttachmentState  state)

Sets the blending state in the Vulkan pipeline. This needs to be called before BuildPipeline() for changes to be effective.

Parameters
stateThe new Vulkan Blend state

◆ SetBlendingStates()

void WEffect::SetBlendingStates ( vector< VkPipelineColorBlendAttachmentState >  states)

Sets multiple blending states in the Vulkan pipeline. Multiple blend states are used when the render target has multiple output attachments. This needs to be called before BuildPipeline() for changes to be effective.

Parameters
stateThe new Vulkan Blend state

◆ SetDepthStencilState()

void WEffect::SetDepthStencilState ( VkPipelineDepthStencilStateCreateInfo  state)

Sets the depth stencil state in the Vulkan pipeline. This needs to be called before BuildPipeline() for changes to be effective.

Parameters
stateThe new Vulkan depth stencil state

◆ SetID()

virtual void WEffect::SetID ( uint32_t  newID)
overridevirtual

Sets the ID of this object and notifies its manager.

Parameters
newIDNew ID

Implements WBase.

◆ SetName()

virtual void WEffect::SetName ( std::string  newName)
overridevirtual

Sets the name of this object.

Parameters
nameNew name for the object

Implements WBase.

◆ SetPrimitiveTopology()

void WEffect::SetPrimitiveTopology ( VkPrimitiveTopology  topology)

Sets the primitive topology in the Vulkan pipeline. This needs to be called before BuildPipeline() for changes to be effective.

Parameters
topologyThe new Vulkan primitive topology

◆ SetRasterizationState()

void WEffect::SetRasterizationState ( VkPipelineRasterizationStateCreateInfo  state)

Sets the rasterization state in the Vulkan pipeline. This needs to be called before BuildPipeline() for changes to be effective.

Parameters
stateThe new Vulkan rasterization state

◆ SetRenderFlags()

void WEffect::SetRenderFlags ( W_EFFECT_RENDER_FLAGS  flags)

Sets the render flags of this effect. Render flags is a bitfield of type W_EFFECT_RENDER_FLAGS that specifies various preperties about the rendering of the effect, such as which stage it should render in.

Parameters
flagsFlags to set

◆ UnbindShader()

WError WEffect::UnbindShader ( W_SHADER_TYPE  type)

Unbinds a shader from this effect.

Parameters
typeThe type of the shader to unbind
Returns
Error code, see WError.h

◆ Valid()

virtual bool WEffect::Valid ( ) const
overridevirtual

Checks the validity of the effect. An effect is valid if it has at least one pipeline created and has a bound vertex shader that supplies a valid input layout.

Returns
true if the effect is valid, false otherwise

Implements WBase.


The documentation for this class was generated from the following file:
WEffect::BindShader
WError BindShader(WShader *shader)
Wasabi::Renderer
class WRenderer * Renderer
Definition: WCore.hpp:70
WEffect
Definition: WEffect.hpp:539
WShader::Load
virtual void Load(bool bSaveData=false)
Definition: WEffect.hpp:485
WBase::RemoveReference
void RemoveReference()
WBase::m_app
class Wasabi * m_app
Definition: WBase.hpp:92
WEffect::BuildPipeline
WError BuildPipeline(class WRenderTarget *rt)
WShader
Definition: WEffect.hpp:421