CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Shader Class Referenceabstract

A resource that represents a shader that can be compiled and loaded into the runtime. More...

#include <CeresEngine/Material/Shader.hpp>

Inheritance diagram for CeresEngine::Shader:
CeresEngine::TResource< Shader > CeresEngine::Resource CeresEngine::IReflectable CeresEngine::TResource< CESLShader, Shader > CeresEngine::TResource< GLSLShader, Shader > CeresEngine::TResource< HLSLShader, Shader > CeresEngine::TResource< SPIRVShader, Shader > CeresEngine::CESLShader CeresEngine::GLSLShader CeresEngine::HLSLShader CeresEngine::SPIRVShader

Public Member Functions

 Shader ()=default
 
 Shader (const ShaderSource &source, const ShaderStages &stage)
 
 ~Shader () noexcept override=default
 
const ShaderSourcegetSource () const noexcept
 The shader source to compile the final shader to.
 
void setSource (const ShaderSource &source)
 The shader source to compile the final shader to.
 
virtual ShadingLanguage getShadingLanguage () const noexcept=0
 Specifies the shading language of the shader resource.
 
virtual Optional< ShaderBinarycompile (ShaderType type, const ShaderSpecializationConstants &specializationConstants={}) const =0
 Compiles the shader into a binary that can be loaded by the render API.
 
Async< Optional< ShaderBinary > > compileAsync (ShaderType type, ShaderSpecializationConstants specializationConstants={})
 Asynchronously compiles the shader into a binary that can be loaded by the render API.
 
String getSourceName () const
 Gets the shader source name.
 
- Public Member Functions inherited from CeresEngine::TResource< Shader >
ResourceHandle< ShadergetResourceHandle () const noexcept
 Generates a hash for the provided type.
 
SPtr< ShadergetShared () noexcept
 Gets a shared pointer to the resource.
 
SPtr< const ShadergetShared () const noexcept
 Gets a shared pointer to the resource.
 
const ResourceTypeInfogetResourceType () const noexcept override
 Returns the resource type information descriptor.
 
 TResource (ResourceData &data, InputStream &dataStream)
 
void serialize (OutputStream &dataStream) const override
 Serializes a resource by writing data to dataStream.
 
- Public Member Functions inherited from CeresEngine::Resource
 Resource ()
 Default constructor for the Resource class.
 
 Resource (ResourceData &data)
 Creates a new Resource instance by passing a ResourceData instance.
 
virtual ~Resource () noexcept=default
 Resource virtual destructor.
 
ResourceManagergetResourceManager () const noexcept
 
HResource getResourceHandle () const noexcept
 Generates a hash for the provided type.
 
UUID getResourceID () const noexcept
 
HResource getParentResource () const noexcept
 A parent resource to which this resource is attached to.
 
SPtr< ResourceMetadatagetResourceMetadata () const noexcept
 A pointer to the user-defined resource metadata.
 
const PackagePtrgetPackage () const noexcept
 The package from which the resource was loaded from.
 
template<typename T = Resource>
SPtr< TgetShared () noexcept
 Gets a shared pointer to the resource.
 
template<typename T = Resource>
SPtr< const TgetShared () const noexcept
 Gets a shared pointer to the resource.
 
 Resource (ResourceData &data, InputStream &dataStream)
 Creates a new resource by reading data from dataStream.
 
- Public Member Functions inherited from CeresEngine::IReflectable
virtual ~IReflectable () noexcept=default
 

Protected Member Functions

ShaderSource preProcessShader (const ShaderSource &sourceCode, const ShaderSpecializationConstants &specializationConstants, const URI &includeSearchPath) const
 Runs the shader pre-processor on the shader.
 
Optional< ShaderBinarycompileShaderInternal (const ShaderSource &sourceCode, ShadingLanguage language, const URI &includeSearchPath) const
 Internal method to compile the given shaderSource using the ShaderC compiler.
 
- Protected Member Functions inherited from CeresEngine::Resource
HResourceStream createStream (const ResourceStreamFlags &flags=ResourceStreamFlag::Default)
 Creates a new resource stream.
 
void destroyStream (HResourceStream &stream)
 Destroys a stream.
 
void markAsDirty ()
 Marks the resource as dirty.
 

Protected Attributes

ShaderStages mStages
 A set of stages supported by the shader.
 
ShaderSource mSource = ShaderSource(ShaderType::Undefined, "")
 The shader source to compile the final shader to.
 

Friends

class TUserTypeInfo< Shader >
 

Additional Inherited Members

- Static Public Member Functions inherited from CeresEngine::Resource
template<typename Processor >
static constexpr void reflect (Processor &&RTTI)
 Executes the given processor for every field of the struct.
 

Detailed Description

A resource that represents a shader that can be compiled and loaded into the runtime.

Constructor & Destructor Documentation

◆ Shader() [1/2]

CeresEngine::Shader::Shader ( )
explicitdefault

◆ Shader() [2/2]

CeresEngine::Shader::Shader ( const ShaderSource source,
const ShaderStages stage 
)
explicit

◆ ~Shader()

CeresEngine::Shader::~Shader ( )
overridedefaultnoexcept

Member Function Documentation

◆ compile()

virtual Optional< ShaderBinary > CeresEngine::Shader::compile ( ShaderType  type,
const ShaderSpecializationConstants specializationConstants = {} 
) const
pure virtual

Compiles the shader into a binary that can be loaded by the render API.

Parameters
typeThe type of shader to compile.

Implemented in CeresEngine::CESLShader, CeresEngine::HLSLShader, CeresEngine::GLSLShader, and CeresEngine::SPIRVShader.

◆ compileAsync()

Async< Optional< ShaderBinary > > CeresEngine::Shader::compileAsync ( ShaderType  type,
ShaderSpecializationConstants  specializationConstants = {} 
)

Asynchronously compiles the shader into a binary that can be loaded by the render API.

Parameters
typeThe type of shader to compile.

◆ compileShaderInternal()

Optional< ShaderBinary > CeresEngine::Shader::compileShaderInternal ( const ShaderSource sourceCode,
ShadingLanguage  language,
const URI includeSearchPath 
) const
protected

Internal method to compile the given shaderSource using the ShaderC compiler.

Parameters
sourceCodeThe shader source code to be compiled.
languageThe language to interpret the source as.
includeSearchPathThe URL of the include search path. Can be a relative URL, in that case the URL will be resolved in relation to the resource manager base URL.
Returns
A shader binary with the results of compiling the shader.

◆ getShadingLanguage()

virtual ShadingLanguage CeresEngine::Shader::getShadingLanguage ( ) const
pure virtualnoexcept

Specifies the shading language of the shader resource.

Implemented in CeresEngine::CESLShader, CeresEngine::HLSLShader, CeresEngine::GLSLShader, and CeresEngine::SPIRVShader.

◆ getSource()

const ShaderSource & CeresEngine::Shader::getSource ( ) const
inlinenoexcept

The shader source to compile the final shader to.

◆ getSourceName()

String CeresEngine::Shader::getSourceName ( ) const

Gets the shader source name.

◆ preProcessShader()

ShaderSource CeresEngine::Shader::preProcessShader ( const ShaderSource sourceCode,
const ShaderSpecializationConstants specializationConstants,
const URI includeSearchPath 
) const
protected

Runs the shader pre-processor on the shader.

Parameters
sourceCodeThe shader source code to be pre-processed.
specializationConstantsThe shader specialization constants to be used when pre-processing the shader.
includeSearchPathThe URL of the include search path. Can be a relative URL, in that case the URL will be resolved in relation to the resource manager base URL.
Returns
The pre-processed shader source.

◆ setSource()

void CeresEngine::Shader::setSource ( const ShaderSource source)

The shader source to compile the final shader to.

Friends And Related Symbol Documentation

◆ TUserTypeInfo< Shader >

Member Data Documentation

◆ mSource

ShaderSource CeresEngine::Shader::mSource = ShaderSource(ShaderType::Undefined, "")
protected

The shader source to compile the final shader to.

◆ mStages

ShaderStages CeresEngine::Shader::mStages
protected

A set of stages supported by the shader.


The documentation for this class was generated from the following file: