Classes¶
GraphicsAssets/Materials
Brief descriptions¶
Structures |
|
Structure for creating a buffer (SRV or UAV). |
|
Structure for creating a read-write texture. |
|
Classes |
|
Interface and base class for material asset views, implementing shared logic for master and instance material classes. |
|
Encapsulates the master material view, extending the functionality of MaterialAssetView. |
|
Encapsulates material instance view. |
Detailed information¶
BufferDesc¶
engine/core/modules/graphics_assets/include/graphics_assets/material_asset.h
-
struct BufferDesc¶
Structure for creating a buffer (SRV or UAV).
This structure holds the information necessary to create a buffer, whether it is a Shader Resource View (SRV) or an Unordered Access View (UAV).
Public Members
-
const char8_t *name¶
Debug name of the buffer (currently not functional).
-
int elementSize¶
Size of a single element (or structure).
-
int elementCount¶
Number of elements in the buffer.
-
unsigned flags¶
Additional flags.
Warning
Under no circumstances should
TEXFMT
be included in the flags, as this implicitly makes all buffers structured!
-
unsigned format¶
The data format (
TEXFMT
) of the buffer.
-
const char8_t *name¶
TextureDesc¶
engine/core/modules/graphics_assets/include/graphics_assets/material_asset.h
-
struct TextureDesc¶
Structure for creating a read-write texture.
This structure holds the information necessary to create a read-write texture, including its dimensions, image data, and additional properties.
Public Members
-
const char8_t *name¶
Debug name of the texture.
-
TexImage32 *image¶
Pointer to the texture image data.
-
int width¶
Width of the texture.
-
int height¶
Height of the texture.
-
int depthOrArraySize¶
Depth of the texture or size of the texture array.
-
int flags¶
Additional flags for texture creation, including
TEXFMT
format.
-
int levels¶
Number of mipmap levels in the texture.
-
const char8_t *name¶
MaterialAssetView¶
engine/core/modules/graphics_assets/include/graphics_assets/material_asset.h
-
class MaterialAssetView : public nau::IAssetView¶
Interface and base class for material asset views, implementing shared logic for master and instance material classes.
This class serves as both an interface and a partial implementation, encapsulating common functionality used by both master material classes and material instance classes. It provides a unified approach to handling material assets and simplifies code reuse across various material types.
Subclassed by nau::MasterMaterialAssetView, nau::MaterialInstanceAssetView
Public Functions
-
virtual void bind() = 0¶
Binds the resource for use.
-
virtual void bindPipeline(eastl::string_view pipelineName) = 0¶
Binds the specified pipeline for use.
- Parameters:
pipelineName – [in] The name of the pipeline to bind.
-
virtual PROGRAM getPipelineProgram(eastl::string_view pipelineName) const = 0¶
Retrieves the program associated with the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
- Returns:
The program associated with the pipeline.
-
virtual eastl::unordered_set<eastl::string> getPipelineNames() const¶
Retrieves a set of all pipeline names.
- Returns:
A set containing the names of all pipelines.
-
virtual void setCullMode(eastl::string_view pipelineName, CullMode cullMode)¶
Sets the cull mode for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
cullMode – [in] The cull mode to set.
-
virtual CullMode getCullMode(eastl::string_view pipelineName) const¶
Gets the cull mode for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
- Returns:
The cull mode of the pipeline.
-
virtual void setDepthMode(eastl::string_view pipelineName, DepthMode depthMode)¶
Sets the depth mode for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
depthMode – [in] The depth mode to set.
-
virtual DepthMode getDepthMode(eastl::string_view pipelineName) const¶
Gets the depth mode for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
- Returns:
The depth mode of the pipeline.
-
virtual void setBlendMode(eastl::string_view pipelineName, BlendMode blendMode)¶
Sets the blend mode for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
blendMode – [in] The blend mode to set.
-
virtual BlendMode getBlendMode(eastl::string_view pipelineName) const¶
Gets the blend mode for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
- Returns:
The blend mode of the pipeline.
-
virtual void setScissorsEnabled(eastl::string_view pipelineName, bool isEnabled)¶
Enables or disables the scissor test for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
isEnabled – [in]
true
to enable the scissor test,false
to disable it.
-
virtual bool isScissorsEnabled(eastl::string_view pipelineName) const¶
Checks if the scissor test is enabled for the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
- Returns:
true
if the scissor test is enabled,false
otherwise.
-
inline eastl::string getName() const¶
Retrieves the name.
- Returns:
The name as a string.
-
inline size_t getNameHash() const¶
-
inline void enableAutoSetTextures(bool isEnabled)¶
Enables or disables automatic texture setting.
- Parameters:
isEnabled – [in]
true
to enable automatic texture setting,false
to disable it.
-
inline bool isAutoSetTexturesEnabled() const¶
Checks if automatic texture setting is enabled.
- Returns:
true
if automatic texture setting is enabled,false
otherwise.
-
template<typename T>
void setProperty(eastl::string_view pipelineName, eastl::string_view propertyName, const T &value)¶ Sets a property for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
propertyName – [in] The name of the property to be set.
value – [in] The new value to set for the property.
-
template<typename T>
T getProperty(eastl::string_view pipelineName, eastl::string_view propertyName)¶ Retrieves a property value for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
propertyName – [in] The name of the property to retrieve.
- Returns:
The value of the property, cast to the specified type
T
.
-
void setCBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, Sbuffer *cbuffer)¶
Sets a constant buffer for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the constant buffer.
cbuffer – [in] A pointer to the constant buffer to set.
-
Sbuffer *getCBuffer(eastl::string_view pipelineName, eastl::string_view bufferName)¶
Retrieves a constant buffer for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the constant buffer to retrieve.
- Returns:
A pointer to the constant buffer.
-
void setTexture(eastl::string_view pipelineName, eastl::string_view propertyName, BaseTexture *texture)¶
Sets a texture property for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
propertyName – [in] The name of the texture property to set.
texture – [in] A pointer to the texture to assign.
-
void setSolidColorTexture(eastl::string_view pipelineName, eastl::string_view propertyName, math::E3DCOLOR color)¶
Sets a solid color texture for a pipeline property.
- Parameters:
pipelineName – [in] The name of the pipeline.
propertyName – [in] The name of the texture property.
color – [in] The color to set for the texture (in RGBA format).
-
async::Task setTextureFromAsset(eastl::string_view pipelineName, eastl::string_view propertyName, eastl::string_view textureAsset)¶
Sets a texture for a pipeline property from an asset.
- Parameters:
pipelineName – [in] The name of the pipeline.
propertyName – [in] The name of the texture property.
textureAsset – [in] The asset reference for the texture.
-
void createRwBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, const BufferDesc &desc)¶
Creates a read-write buffer for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to create.
desc – [in] The buffer description.
-
void writeRwBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, const void *data, size_t size)¶
Writes data to a read-write buffer in a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to write to.
data – [in] The data to write to the buffer.
size – [in] The size of the data to write.
-
void readRwBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, void *data, size_t size)¶
Reads data from a read-write buffer in a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to read from.
data – [out] The memory where the data will be copied.
size – [in] The size of the data to read.
-
void setRwBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, Sbuffer *rwBuffer)¶
Sets a read-write buffer for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to set.
rwBuffer – [in] The buffer to assign to the pipeline.
-
Sbuffer *getRwBuffer(eastl::string_view pipelineName, eastl::string_view bufferName)¶
Retrieves a read-write buffer from a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to retrieve.
- Returns:
The read-write buffer if found.
-
void createRoBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, const BufferDesc &desc)¶
Creates a read-only buffer for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to create.
desc – [in] The buffer description.
-
void writeRoBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, const void *data, size_t size)¶
Writes data to a read-only buffer in a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to write to.
data – [in] The data to write to the buffer.
size – [in] The size of the data to write.
-
void setRoBuffer(eastl::string_view pipelineName, eastl::string_view bufferName, Sbuffer *roBuffer)¶
Sets a read-only buffer for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to set.
rwBuffer – [in] The buffer to assign to the pipeline.
-
Sbuffer *getRoBuffer(eastl::string_view pipelineName, eastl::string_view bufferName)¶
Retrieves a read-only buffer from a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the buffer to retrieve.
- Returns:
The read-only buffer if found.
-
void createRwTexture(eastl::string_view pipelineName, eastl::string_view bufferName, const TextureDesc &desc)¶
Creates a read-write texture for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to create.
desc – [in] The texture description.
-
void writeRwTexture(eastl::string_view pipelineName, eastl::string_view bufferName, const void *data, size_t size)¶
Writes data to a read-write texture in a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to write to.
data – [in] The data to write to the texture.
size – [in] The size of the data to write.
-
void readRwTexture(eastl::string_view pipelineName, eastl::string_view bufferName, void *data, size_t size)¶
Reads data from a read-write texture in a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to read from.
data – [out] The memory where the data will be copied.
size – [in] The size of the data to read.
-
void setRwTexture(eastl::string_view pipelineName, eastl::string_view bufferName, BaseTexture *rwTexture)¶
Sets a read-write texture for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to set.
rwTexture – [in] The texture to assign to the pipeline.
-
BaseTexture *getRwTexture(eastl::string_view pipelineName, eastl::string_view bufferName)¶
Retrieves a read-write texture from a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to retrieve.
- Returns:
The read-write texture if found.
-
void createRoTexture(eastl::string_view pipelineName, eastl::string_view bufferName, const TextureDesc &desc)¶
Creates a read-only texture for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to create.
desc – [in] The texture description.
-
void writeRoTexture(eastl::string_view pipelineName, eastl::string_view bufferName, const void *data, size_t size)¶
Writes data to a read-only texture in a specified pipeline.
Note: Writing to a read-only texture may not be allowed, depending on the pipeline configuration.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to write to.
data – [in] The data to write to the texture.
size – [in] The size of the data to write.
-
void setRoTexture(eastl::string_view pipelineName, eastl::string_view bufferName, BaseTexture *roTexture)¶
Sets a read-only texture for a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to set.
roTexture – [in] The texture to assign to the pipeline.
-
BaseTexture *getRoTexture(eastl::string_view pipelineName, eastl::string_view bufferName)¶
Retrieves a read-only texture from a specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
bufferName – [in] The name of the texture to retrieve.
- Returns:
The read-only texture if found.
-
void dispatch(uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ)¶
Dispatches a compute shader workload to a compute pipeline.
- Parameters:
threadGroupCountX – [in] The number of thread groups to dispatch in the X dimension.
threadGroupCountY – [in] The number of thread groups to dispatch in the Y dimension.
threadGroupCountZ – [in] The number of thread groups to dispatch in the Z dimension.
Public Static Functions
-
static async::Task<MaterialAssetView::Ptr> createFromAssetAccessor(nau::Ptr<> accessor)¶
Asynchronously creates a material asset view from the given accessor.
- Parameters:
accessor – [in] Provides data for constructing the view.
- Returns:
Task with operation status and access to the created view.
Protected Types
-
using Timestamp = std::chrono::time_point<std::chrono::steady_clock>¶
Protected Functions
-
void updateBuffers(eastl::string_view pipelineName)¶
Updates the constant buffers bound to the pipeline with the associated CPU values.
- Parameters:
pipelineName – [in] The name of the pipeline for which constant buffers are updated.
-
void updateRenderState(eastl::string_view pipelineName)¶
Updates the render state for the specified pipeline based on the pipeline’s settings.
- Parameters:
pipelineName – [in] The name of the pipeline for which the render state is updated.
-
bool hasComputeShader() const¶
Checks if any of the pipelines have a compute shader.
- Returns:
True if any pipeline contains a compute shader, false otherwise.
Protected Static Functions
-
static async::Task<Pipeline> makeMasterPipeline(eastl::string_view pipelineName, const MaterialPipeline &materialPipeline, eastl::span<ShaderAssetView::Ptr> shaders)¶
Constructs a master render pipeline based on the provided material pipeline and shader data.
- Parameters:
pipelineName – [in] The name to assign to the pipeline.
materialPipeline – [in] The compiled material pipeline, which includes material-specific properties.
shaders – [in] A span of shader asset views to bind to the pipeline.
- Returns:
A task that provides the constructed pipeline and its operation status once complete.
-
static async::Task<Pipeline> makeInstancePipeline(eastl::string_view pipelineName, const MaterialPipeline &materialPipeline, Pipeline &masterPipeline)¶
Constructs an instance of a render pipeline based on a master pipeline and material properties.
- Parameters:
pipelineName – [in] The name to assign to the pipeline.
materialPipeline – [in] The material-specific pipeline data that overrides values in the master pipeline.
masterPipeline – [in] The master pipeline containing the base properties, textures, buffers, and other resources.
- Returns:
A task that provides the constructed pipeline instance once complete.
-
static void makeCullMode(CullMode cullMode, shaders::RenderState &renderState)¶
Sets the culling mode for the given render state.
- Parameters:
cullMode – [in] The desired culling mode (None, Clockwise, CounterClockwise).
renderState – [inout] The render state object to which the culling mode will be applied.
-
static void makeDepthMode(DepthMode depthMode, shaders::RenderState &renderState)¶
Sets the depth mode for the given render state.
- Parameters:
depthMode – [in] The desired depth mode (Default, ReadOnly, WriteOnly, Disabled).
renderState – [inout] The render state object to which the depth mode will be applied.
-
static void makeBlendMode(BlendMode blendMode, shaders::RenderState &renderState)¶
Sets the blend mode for the given render state.
- Parameters:
blendMode – [in] The desired blend mode.
renderState – [inout] The render state object to which the blend mode will be applied.
-
static void makeStencilCmpFunc(ComparisonFunc cmpFunc, shaders::RenderState &renderState)¶
Sets the stencil comparison function for the given render state.
- Parameters:
cmpFunc – [in] The comparison function to use for the stencil test.
renderState – [inout] The render state object to which the stencil comparison function will be applied.
Private Types
-
using Ptr = nau::Ptr<MaterialAssetView>¶
-
struct BufferCache¶
Represents a cached buffer resource and manages its bindings across various pipeline stages.
-
struct ConstantBufferVariable¶
Represents a variable within a constant buffer, including its reflection data and current value.
Public Members
-
const ShaderVariableDescription *reflection¶
-
BufferCache *parentBuffer¶
-
RuntimeValue::Ptr currentValue¶
-
RuntimeValue::Ptr *masterValue¶
Only for MaterialInstanceView.
-
bool isMasterValue¶
Only for MaterialInstanceView.
-
const ShaderVariableDescription *reflection¶
-
struct Pipeline¶
Descriptor for a render pipeline pass.
This structure encapsulates the inputs for a render pipeline pass, including shaders, resources, and other state-related properties. It is similar to a pipeline state object, such as those used in Direct3D 12 (e.g.,
Pipeline State <>
). The pipeline stores various resources such as constant buffers, textures, and samplers, as well as configuration options like render state, culling mode, and depth/blend settings.Public Members
-
eastl::vector<ShaderAssetView::Ptr> shaders¶
-
eastl::unordered_map<eastl::string, ConstantBufferVariable> properties¶
-
eastl::unordered_map<eastl::string, SampledTextureProperty> texProperties¶
-
eastl::unordered_map<eastl::string, BufferCache> constantBuffers¶
-
eastl::unordered_map<eastl::string, BufferCache> systemCBuffers¶
-
eastl::unordered_map<eastl::string, BufferCache> rwBuffers¶
-
eastl::unordered_map<eastl::string, BufferCache> roBuffers¶
-
eastl::unordered_map<eastl::string, TextureCache> rwTextures¶
-
eastl::unordered_map<eastl::string, TextureCache> roTextures¶
-
eastl::unordered_map<eastl::string, TextureCache> samplerTextures¶
-
eastl::unordered_map<eastl::string, SamplerCache> samplers¶
-
PROGRAM programID¶
-
eastl::optional<CullMode> cullMode¶
-
eastl::optional<DepthMode> depthMode¶
-
eastl::optional<BlendMode> blendMode¶
-
eastl::optional<bool> isScissorsEnabled¶
-
eastl::optional<ComparisonFunc> stencilCmpFunc¶
-
bool isDirty¶
-
bool isRenderStateDirty¶
-
eastl::vector<ShaderAssetView::Ptr> shaders¶
-
struct SampledTextureProperty¶
Represents a property of a sampled texture, including its current and master values.
-
struct SamplerCache¶
Represents a cached sampler resource and manages its bindings across various pipeline stages.
-
virtual void bind() = 0¶
MasterMaterialAssetView¶
engine/core/modules/graphics_assets/include/graphics_assets/material_asset.h
-
class MasterMaterialAssetView : public nau::MaterialAssetView¶
Encapsulates the master material view, extending the functionality of MaterialAssetView.
This class represents a master material, providing additional functionality specific to master materials.
Public Functions
-
~MasterMaterialAssetView() override¶
-
virtual void bind() override¶
Binds the default pipeline for the material view.
-
virtual void bindPipeline(eastl::string_view pipelineName) override¶
Binds the specified pipeline for use in rendering.
- Parameters:
pipelineName – [in] The name of the pipeline to bind.
-
virtual PROGRAM getPipelineProgram(eastl::string_view pipelineName) const override¶
Retrieves the program associated with the specified pipeline.
- Parameters:
pipelineName – [in] The name of the pipeline.
- Returns:
The program associated with the pipeline.
Public Static Functions
-
static async::Task<MasterMaterialAssetView::Ptr> createFromMaterial(Material &&material)¶
Asynchronously creates a master material asset view from the given material object.
- Parameters:
material – [in] The material object to construct the view from.
- Returns:
Task with operation status and access to the created master material view.
Private Types
-
using Ptr = nau::Ptr<MasterMaterialAssetView>¶
Private Functions
-
void setGlobals(eastl::string_view pipelineName)¶
Private Members
-
eastl::string m_defaultProgram¶
Friends
- friend class MaterialInstanceAssetView
-
~MasterMaterialAssetView() override¶
MaterialInstanceAssetView¶
engine/core/modules/graphics_assets/include/graphics_assets/material_asset.h
-
class MaterialInstanceAssetView : public nau::MaterialAssetView¶
Encapsulates material instance view.
This class represents the view for a material instance, providing functionality specific to instances of materials rather than the master materials.
Public Functions
-
~MaterialInstanceAssetView() override¶
-
virtual void bind() override¶
Binds the default pipeline for the material view.
-
virtual void bindPipeline(eastl::string_view pipelineName) override¶
Binds the specified pipeline for use in rendering.
- Parameters:
pipelineName – [in] The name of the pipeline to bind.
-
virtual PROGRAM getPipelineProgram(eastl::string_view pipelineName) const override¶
Retrieves the program associated with the specified pipeline from the master material.
Note
The instance does not own the program; it references the program from the master material.
- Parameters:
pipelineName – [in] The name of the pipeline.
- Returns:
The program associated with the pipeline from the master material.
Public Static Functions
-
static async::Task<MaterialInstanceAssetView::Ptr> createFromMaterial(Material &&material)¶
Constructs the view from the material instance object.
Warning
material.master
must reference a master material handle.- Parameters:
material – [in] Material instance object to construct the view from.
- Returns:
Task object providing operation status as well as the constructed view.
Private Types
-
using Ptr = nau::Ptr<MaterialInstanceAssetView>¶
Private Functions
-
void syncBuffers(const Pipeline &masterPipeline, Pipeline &instancePipeline)¶
-
void syncTextures(const Pipeline &masterPipeline, Pipeline &instancePipeline)¶
Private Members
-
MasterMaterialAssetView::Ptr m_masterMaterial¶
-
~MaterialInstanceAssetView() override¶