Class Shader

Synopsis

#include <Source/Falcor/Core/API/Shader.h>

class dlldecl Shader : public std::enable_shared_from_this<Shader>

Description

Low-level shader object This class abstracts the API's shader creation and management

Mentioned in

Inheritance

Ancestors: std::enable_shared_from_this< Shader >

Classes

DefineList

Methods

Shader
~Shader
createCreate a shader object
getApiHandleGet the API handle.
getEntryPointGet the name of the entry point.
getTypeGet the shader Type
init

Source

Lines 135-221 in Source/Falcor/Core/API/Shader.h.

class dlldecl Shader : public std::enable_shared_from_this<Shader>
{
public:
    using SharedPtr = std::shared_ptr<Shader>;
    using SharedConstPtr = std::shared_ptr<const Shader>;
    using ApiHandle = ShaderHandle;
    typedef ComPtr<ISlangBlob> Blob;
    enum class CompilerFlags
    {
        None                        = 0x0,
        TreatWarningsAsErrors       = 0x1,
        DumpIntermediates           = 0x2,
        FloatingPointModeFast       = 0x4,
        FloatingPointModePrecise    = 0x8,
        GenerateDebugInfo           = 0x10,
    };
    class DefineList : public std::map<std::string, std::string>
    {
    public:
        /** Adds a macro definition. If the macro already exists, it will be replaced.
            \param[in] name The name of macro.
            \param[in] value Optional. The value of the macro.
            \return The updated list of macro definitions.
        */
        DefineList& add(const std::string& name, const std::string& val = "") { (*this)[name] = val; return *this; }
        /** Removes a macro definition. If the macro doesn't exist, the call will be silently ignored.
            \param[in] name The name of macro.
            \return The updated list of macro definitions.
        */
        DefineList& remove(const std::string& name) { (*this).erase(name); return *this; }
        /** Add a define list to the current list
        */
        DefineList& add(const DefineList& dl) { for (const auto& p : dl) add(p.first, p.second); return *this; }
        /** Remove a define list from the current list
        */
        DefineList& remove(const DefineList& dl) { for (const auto& p : dl) remove(p.first); return *this; }
        DefineList() = default;
        DefineList(std::initializer_list<std::pair<const std::string, std::string>> il) : std::map<std::string, std::string>(il) {}
    };
    /** Create a shader object
        \param[in] shaderBlog A blob containing the shader code
        \param[in] Type The Type of the shader
        \param[out] log This string will contain the error log message in case shader compilation failed
        \return If success, a new shader object, otherwise nullptr
    */
    static SharedPtr create(const Blob& shaderBlob, ShaderType type, std::string const&  entryPointName, CompilerFlags flags, std::string& log)
    {
        SharedPtr pShader = SharedPtr(new Shader(type));
        pShader->mEntryPointName = entryPointName;
        return pShader->init(shaderBlob, entryPointName, flags, log) ? pShader : nullptr;
    }
    virtual ~Shader();
    /** Get the API handle.
    */
    const ApiHandle& getApiHandle() const { return mApiHandle; }
    /** Get the shader Type
    */
    ShaderType getType() const { return mType; }
    /** Get the name of the entry point.
    */
    const std::string& getEntryPoint() const { return mEntryPointName; }
ef FALCOR_D3D12
    ID3DBlobPtr getD3DBlob() const;
if
protected:
    // API handle depends on the shader Type, so it stored be stored as part of the private data
    bool init(const Blob& shaderBlob, const std::string&  entryPointName, CompilerFlags flags, std::string& log);
    Shader(ShaderType Type);
    ShaderType mType;
    std::string mEntryPointName;
    ApiHandle mApiHandle;
    void* mpPrivateData = nullptr;
};





Add Discussion as Guest

Log in to DocsForge