Skip to content

Commit

Permalink
Castor3D: Created PassComponentPlugin class, and implemented componen…
Browse files Browse the repository at this point in the history
…ts plugins.

Also added documentation for PassComponent.
  • Loading branch information
DragonJoker committed Oct 10, 2022
1 parent dd57dd1 commit 06ab9f9
Show file tree
Hide file tree
Showing 76 changed files with 1,949 additions and 1,361 deletions.
2 changes: 1 addition & 1 deletion external/ShaderWriter
29 changes: 3 additions & 26 deletions include/Core/Castor3D/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,7 @@ namespace castor3d
*\param[in] data Les fonctions spécifiques du composant.
*/
C3D_API uint32_t registerPassComponent( castor::String const & type
, ParsersFiller createParsers
, SectionsFiller createSections
, CreateMaterialShader createMaterialShader
, ComponentData data );
, PassComponentPluginUPtr componentPlugin );
/**
*\~english
*\brief Unregisters a pass component.
Expand Down Expand Up @@ -856,30 +853,10 @@ namespace castor3d
}

template< typename ComponentT >
uint32_t registerPassComponent( ParsersFiller pcreateParsers = &ComponentT::createParsers
, SectionsFiller pcreateSections = &ComponentT::createSections
, CreateMaterialShader pcreateMaterialShader = &ComponentT::createMaterialShader
, ZeroBuffer pzeroBuffer = &ComponentT::zeroBuffer
, FillRemapMask pfillRemapMask = &ComponentT::fillRemapMask
, WriteTextureConfig pwriteTextureConfig = &ComponentT::writeTextureConfig
, NeedsMapComponent pneedsMapComponent = &ComponentT::needsMapComponent
, CreateMapComponent pcreateMapComponent = &ComponentT::createMapComponent
, IsComponentNeeded pisComponentNeeded = &ComponentT::isComponentNeeded
, CreateComponentsShader pcreateComponentsShader = &ComponentT::createComponentsShader
, std::function< UpdateComponent() > getUpdateComponent = &ComponentT::getUpdateComponent )
uint32_t registerPassComponent( CreatePassComponentPlugin createPlugin = &ComponentT::createPlugin )
{
return registerPassComponent( ComponentT::TypeName
, pcreateParsers
, pcreateSections
, pcreateMaterialShader
, ComponentData{ pzeroBuffer
, pfillRemapMask
, pwriteTextureConfig
, pneedsMapComponent
, pcreateMapComponent
, pisComponentNeeded
, pcreateComponentsShader
, getUpdateComponent() } );
, createPlugin() );
}
/**@}*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ namespace castor3d
struct BlendComponent
: public BaseDataPassComponentT< BlendData >
{
C3D_API explicit BlendComponent( Pass & pass );

C3D_API static void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers );

C3D_API static bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )
class Plugin
: public PassComponentPlugin
{
// Component is never need in shader.
return false;
public:
void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers )const override;

bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )const override
{
// Component is never need in shader.
return false;
}
};

static PassComponentPluginUPtr createPlugin()
{
return castor::makeUniqueDerived< PassComponentPlugin, Plugin >();
}

C3D_API explicit BlendComponent( Pass & pass );

C3D_API void accept( PassVisitorBase & vis )override;

C3D_API PassFlags getPassFlags()const override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ namespace castor3d
{
C3D_API void fillComponents( sdw::type::BaseStruct & components
, shader::Materials const & materials
, shader::Material const * material
, sdw::StructInstance const * surface )const override;
C3D_API void fillComponentsInits( sdw::type::BaseStruct & components
C3D_API void fillComponentsInits( sdw::type::BaseStruct const & components
, shader::Materials const & materials
, shader::Material const * material
, sdw::StructInstance const * surface
Expand All @@ -31,16 +30,32 @@ namespace castor3d
, shader::BlendComponents const & src )const override;
};

C3D_API explicit NormalComponent( Pass & pass );
class Plugin
: public PassComponentPlugin
{
public:
bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )const override
{
return checkFlag( filter, ComponentModeFlag::eGeometry )
|| checkFlag( filter, ComponentModeFlag::eDiffuseLighting )
|| checkFlag( filter, ComponentModeFlag::eSpecularLighting )
|| checkFlag( filter, ComponentModeFlag::eOcclusion );
}

C3D_API static bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter );
shader::PassComponentsShaderPtr createComponentsShader()const override
{
return std::make_unique< ComponentsShader >();
}
};

C3D_API static shader::PassComponentsShaderPtr createComponentsShader()
C3D_API static PassComponentPluginUPtr createPlugin()
{
return std::make_unique< ComponentsShader >();
return castor::makeUniqueDerived< PassComponentPlugin, Plugin >();
}

C3D_API explicit NormalComponent( Pass & pass );

C3D_API static castor::String const TypeName;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,36 @@ namespace castor3d
, sdw::expr::ExprList & inits )const override;
};

C3D_API explicit PassHeaderComponent( Pass & pass );
class Plugin
: public PassComponentPlugin
{
public:
void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers )const override;
void zeroBuffer( Pass const & pass
, shader::PassMaterialShader const & materialShader
, PassBuffer & buffer )const override;

C3D_API static void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers );
C3D_API static void zeroBuffer( Pass const & pass
, shader::PassMaterialShader const & materialShader
, PassBuffer & buffer );
bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )const override
{
// Component is never needed in lighting shader.
return false;
}

C3D_API static bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )
{
// Component is never needed in shader.
return false;
}
shader::PassMaterialShaderPtr createMaterialShader()const override
{
return std::make_unique< MaterialShader >();
}
};

C3D_API static shader::PassMaterialShaderPtr createMaterialShader()
static PassComponentPluginUPtr createPlugin()
{
return std::make_unique< MaterialShader >();
return castor::makeUniqueDerived< PassComponentPlugin, Plugin >();
}

C3D_API explicit PassHeaderComponent( Pass & pass );

C3D_API void accept( PassVisitorBase & vis )override;

C3D_API PassFlags getPassFlags()const override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,32 @@ namespace castor3d
, sdw::expr::ExprList & inits )const override;
};

C3D_API explicit TextureCountComponent( Pass & pass );
class Plugin
: public PassComponentPlugin
{
public:
void zeroBuffer( Pass const & pass
, shader::PassMaterialShader const & materialShader
, PassBuffer & buffer )const override;
bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )const override
{
// Component is always needed in lighting shaders.
return false;
}

C3D_API static void zeroBuffer( Pass const & pass
, shader::PassMaterialShader const & materialShader
, PassBuffer & buffer );
shader::PassMaterialShaderPtr createMaterialShader()const override
{
return std::make_unique< MaterialShader >();
}
};

C3D_API static bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )
static PassComponentPluginUPtr createPlugin()
{
// Component is always needed in shader.
return false;
return castor::makeUniqueDerived< PassComponentPlugin, Plugin >();
}

C3D_API static shader::PassMaterialShaderPtr createMaterialShader()
{
return std::make_unique< MaterialShader >();
}
C3D_API explicit TextureCountComponent( Pass & pass );

C3D_API void accept( PassVisitorBase & vis )override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ namespace castor3d
{
C3D_API void fillComponents( sdw::type::BaseStruct & components
, shader::Materials const & materials
, shader::Material const * material
, sdw::StructInstance const * surface )const override;
C3D_API void fillComponentsInits( sdw::type::BaseStruct & components
C3D_API void fillComponentsInits( sdw::type::BaseStruct const & components
, shader::Materials const & materials
, shader::Material const * material
, sdw::StructInstance const * surface
Expand All @@ -43,24 +42,34 @@ namespace castor3d
, shader::BlendComponents const & src )const override;
};

C3D_API explicit TexturesComponent( Pass & pass );
class Plugin
: public PassComponentPlugin
{
public:
void zeroBuffer( Pass const & pass
, shader::PassMaterialShader const & materialShader
, PassBuffer & buffer )const override;
bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )const override;

C3D_API static void zeroBuffer( Pass const & pass
, shader::PassMaterialShader const & materialShader
, PassBuffer & buffer );
C3D_API static bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter );
shader::PassComponentsShaderPtr createComponentsShader()const override
{
return std::make_unique< ComponentsShader >();
}

C3D_API static shader::PassComponentsShaderPtr createComponentsShader()
{
return std::make_unique< ComponentsShader >();
}
shader::PassMaterialShaderPtr createMaterialShader()const override
{
return std::make_unique< MaterialShader >();
}
};

C3D_API static shader::PassMaterialShaderPtr createMaterialShader()
static PassComponentPluginUPtr createPlugin()
{
return std::make_unique< MaterialShader >();
return castor::makeUniqueDerived< PassComponentPlugin, Plugin >();
}

C3D_API explicit TexturesComponent( Pass & pass );

C3D_API void accept( PassVisitorBase & vis )override;

C3D_API PassFlags getPassFlags()const override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@ namespace castor3d
struct TwoSidedComponent
: public BaseDataPassComponentT< castor::AtomicGroupChangeTracked< bool > >
{
C3D_API explicit TwoSidedComponent( Pass & pass );

C3D_API static void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers );

C3D_API static bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )
class Plugin
: public PassComponentPlugin
{
// Component is never need in shader.
return false;
public:
void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers )const override;

bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )const override
{
// Component is never need in shader.
return false;
}
};

static PassComponentPluginUPtr createPlugin()
{
return castor::makeUniqueDerived< PassComponentPlugin, Plugin >();
}

C3D_API explicit TwoSidedComponent( Pass & pass );

C3D_API void accept( PassVisitorBase & vis )override;

bool isTwoSided()const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@ namespace castor3d
struct UntileComponent
: public BaseDataPassComponentT< castor::AtomicGroupChangeTracked< bool > >
{
C3D_API explicit UntileComponent( Pass & pass );
class Plugin
: public PassComponentPlugin
{
public:
void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers )const override;

C3D_API static void createParsers( castor::AttributeParsers & parsers
, ChannelFillers & channelFillers );
bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )const override
{
// Component is never need in shader.
return false;
}
};

C3D_API static bool isComponentNeeded( TextureFlags const & textures
, ComponentModeFlags const & filter )
static PassComponentPluginUPtr createPlugin()
{
// Component is never need in shader.
return false;
return castor::makeUniqueDerived< PassComponentPlugin, Plugin >();
}

C3D_API explicit UntileComponent( Pass & pass );

C3D_API void accept( PassVisitorBase & vis )override;

C3D_API PassFlags getPassFlags()const override
Expand Down
Loading

0 comments on commit 06ab9f9

Please sign in to comment.