NAP
Public Types | Public Member Functions | Protected Member Functions | List of all members
Shader Class Reference

#include <shader.h>

Public Types

enum  EShaderType : uint { Vertex = 0x01, Fragment = 0x02 }
 
using ShaderTypeFlags = uint
 

Public Member Functions

 Shader (Core &core)
 
 ~Shader ()
 
const VertexAttributeDeclarationsgetAttributes () const
 
VkShaderModule getVertexModule () const
 
VkShaderModule getFragmentModule () const
 
- Public Member Functions inherited from BaseShader
 BaseShader (Core &core)
 
virtual ~BaseShader ()
 
const SamplerDeclarationsgetSamplerDeclarations () const
 
const std::vector< BufferObjectDeclaration > & getUBODeclarations () const
 
const std::vector< BufferObjectDeclaration > & getSSBODeclarations () const
 
const ShaderConstantDeclarationsgetConstantDeclarations () const
 
const std::string & getDisplayName () const
 
VkDescriptorSetLayout getDescriptorSetLayout () const
 
void clear ()
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual bool init (utility::ErrorState &errorState)
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Protected Member Functions

bool load (const std::string &displayName, const std::vector< std::string > &searchPaths, const char *vertShader, int vertSize, const char *fragShader, int fragSize, utility::ErrorState &errorState)
 
bool loadDefault (const std::string &displayName, utility::ErrorState &errorState)
 
- Protected Member Functions inherited from BaseShader
bool initLayout (VkDevice device, nap::utility::ErrorState &errorState)
 
bool verifyShaderVariableDeclarations (utility::ErrorState &errorState)
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 
- Protected Attributes inherited from BaseShader
RenderServicemRenderService = nullptr
 Handle to render engine. More...
 
std::string mDisplayName
 Filename of shader used as display name. More...
 
BufferObjectDeclarationList mUBODeclarations
 All uniform buffer object declarations. More...
 
BufferObjectDeclarationList mSSBODeclarations
 All storage buffer object declarations. More...
 
SamplerDeclarations mSamplerDeclarations
 All sampler declarations. More...
 
ShaderConstantDeclarations mConstantDeclarations
 All shader constant declarations. More...
 
VkDescriptorSetLayout mDescriptorSetLayout = VK_NULL_HANDLE
 Descriptor set layout. More...
 

Description

Cross-Compiles GLSL vertex and fragment shader code to SPIR-V and creates a Vulkan shader module. All uniforms, samplers and attributes are extracted. Make sure to call init() on initialization of a derived shader class. A nap::Material links to a BaseShader. The shader is compiled on initialization. Use a nap::Material or nap::MaterialInstance to set / override uniforms and samplers.

Inheritance diagram for Shader:
[legend]
Collaboration diagram for Shader:
[legend]

Member Typedef Documentation

◆ ShaderTypeFlags

Member Enumeration Documentation

◆ EShaderType

enum EShaderType : uint

Shader type flag bits

Enumerator
Vertex 
Fragment 

Constructor & Destructor Documentation

◆ Shader()

Shader ( Core core)

◆ ~Shader()

~Shader ( )

Member Function Documentation

◆ getAttributes()

const VertexAttributeDeclarations& getAttributes ( ) const
Returns
all vertex shader attribute declarations.

◆ getFragmentModule()

VkShaderModule getFragmentModule ( ) const
Returns
Vulkan fragment module.

◆ getVertexModule()

VkShaderModule getVertexModule ( ) const
Returns
Vulkan vertex module.

◆ load()

bool load ( const std::string &  displayName,
const std::vector< std::string > &  searchPaths,
const char *  vertShader,
int  vertSize,
const char *  fragShader,
int  fragSize,
utility::ErrorState errorState 
)
protected

Compiles the GLSL shader code, creates the shader module and parses all the uniforms and samplers. Call this in a derived class on initialization.

Parameters
displayNamethe name of the shader.
searchPathsthe search paths of the shader.
vertShaderthe vertex shader GLSL code.
vertSizetotal number of characters in vertShader.
fragShaderthe fragment shader GLSL code.
fragSizetotal number of characters in fragShader.
errorStatecontains the error if initialization fails.
Returns
if initialization succeeded.

◆ loadDefault()

bool loadDefault ( const std::string &  displayName,
utility::ErrorState errorState 
)
protected

Loads a NAP default shader from disk. Compiles the GLSL shader code, creates the shader module and parses all the uniforms and samplers. Call this in a derived class on initialization.

Parameters
displayNamethe name of the NAP default shader.
errorStatecontains the error if initialization fails.
Returns
if initialization succeeded.