class SpriteMaterial

Interfaced implemented by materials used for rendering sprites.

This is expected to be used as a singleton.

Public

Constructors

SpriteMaterial

SpriteMaterial(u32 id, const HMaterial &material, ShaderVariationParameters variation = ShaderVariationParameters::kEmpty, bool allowBatching = true)

Methods

~SpriteMaterial

virtual ~SpriteMaterial() noexcept

GetId

u32 GetId() const

Returns the unique ID of the sprite material.

AllowBatching

bool AllowBatching() const

Determines is this material allowed to be batched with other materials with the same merge hash.

GetMergeHash

virtual u64 GetMergeHash(const SpriteMaterialInfo &info) const

Generates a hash value that describes the contents of the sprite material info structure.

Returned hash doesn't guarantee that the two objects with the same hash are identical, but rather that the objects are mergeable via Merge().

Merge

virtual void Merge(SpriteMaterialInfo &mergeInto, const SpriteMaterialInfo &mergeFrom) const

Merges two SpriteMaterialInfos into one structure.

User must guarantee that the two objects are mergeable by ensuring their merge hashes match (by calling GetMergeHash()).

mergeInto
Object that contains the first part of the data, and will contain the result of the merge.
mergeFrom
Object that contains the second part of the data to merge, which will be merged into the first object.

CreateParameterAdapter

virtual SPtr<render::MaterialParameterAdapter> CreateParameterAdapter(bool supportClipping)

Creates parameter adapter for use with this material

supportClipping
If true, parameter adapter will be created for use with the clip region buffer variant of the material.

Prepare

virtual void Prepare(const SPtr<render::MaterialParameterAdapter> &parameterAdapter, const SPtr<render::MeshBase> &mesh, const SPtr<render::Texture> &texture, const SPtr<SamplerState> &sampler, const render::GpuBufferSuballocation &uniformBuffer, const SPtr<render::GpuBuffer> &clipRegionBuffer) const

Prepares the provided parameters for use with the current material.

parameterAdapter
Pararmeter adapter to use for populating the parameters.
mesh
Mesh to render, containing vertices in screen space.
texture
Optional texture to render the mesh with.
sampler
Optional sampler to render the texture with.
uniformBuffer
Buffer containing data GPU parameters, created from GUISpriteUniformBufferDefinition.
clipRegionBuffer
Buffer containing regions against all rendered sprite quads will be culled/clipped against.

Render

virtual void Render(render::GpuCommandBuffer &commandBuffer, const SPtr<render::GpuParameterSet> &parameters, const SPtr<render::MeshBase> &mesh, const SubMesh &subMesh, const SPtr<render::GpuBuffer> &clipRegionBuffer, u32 clipRegionCount, const SPtr<SpriteMaterialExtraInfo> &additionalData) const

Renders the provided mesh using the current material.

commandBuffer
Command buffer to encode the render commands on.
parameters
Parameters to use for rendering, prepared via the call to Prepare().
mesh
Mesh to render, containing vertices in screen space.
subMesh
Portion of to render.
clipRegionBuffer
Buffer containing regions against all rendered sprite quads will be culled/clipped against.
clipRegionCount
Number of regions in .
additionalData
Optional additional data that might be required by the renderer.

staticPopulateUniformBuffer

static void PopulateUniformBuffer(const render::GpuBufferMappedScope &uniforms, const Vector2I &viewportOffset, float inverseViewportWidth, float inverseViewportHeight, bool flipY, float animationTime, u32 clipRegionCount, const Matrix4 &transform, const render::SpriteMaterialInfo &materialInformation)

Writes the provided parameters into a uniform buffer created from GUISpriteUniformBufferDefinition.

Protected

Methods

Initialize

virtual void Initialize()

Perform initialization of render-thread specific objects.

staticDestroy

static void Destroy(const SPtr<render::Material> &material)

Destroys the render thread material.

Fields

mId

u32 mId

mAllowBatching

bool mAllowBatching

mMaterial

SPtr<render::Material> mMaterial

mWithoutClippingVariationIndex

u32 mWithoutClippingVariationIndex

mWithClippingVariationIndex

u32 mWithClippingVariationIndex

mMaterialStored

std::atomic<bool> mMaterialStored

mTextureParameter

render::MaterialParameterSampledTexture mTextureParameter

mSamplerParameter

render::MaterialParameterSampler mSamplerParameter