# Conflicts: # Content/Editor/Camera/M_Camera.flax # Content/Editor/CubeTexturePreviewMaterial.flax # Content/Editor/DebugMaterials/DDGIDebugProbes.flax # Content/Editor/DebugMaterials/SingleColor/Decal.flax # Content/Editor/DebugMaterials/SingleColor/Particle.flax # Content/Editor/DebugMaterials/SingleColor/Surface.flax # Content/Editor/DebugMaterials/SingleColor/SurfaceAdditive.flax # Content/Editor/DebugMaterials/SingleColor/Terrain.flax # Content/Editor/DefaultFontMaterial.flax # Content/Editor/Gizmo/FoliageBrushMaterial.flax # Content/Editor/Gizmo/Material.flax # Content/Editor/Gizmo/MaterialWire.flax # Content/Editor/Gizmo/SelectionOutlineMaterial.flax # Content/Editor/Gizmo/VertexColorsPreviewMaterial.flax # Content/Editor/Highlight Material.flax # Content/Editor/Icons/IconsMaterial.flax # Content/Editor/IesProfilePreviewMaterial.flax # Content/Editor/Particles/Particle Material Color.flax # Content/Editor/Particles/Smoke Material.flax # Content/Editor/SpriteMaterial.flax # Content/Editor/Terrain/Circle Brush Material.flax # Content/Editor/Terrain/Highlight Terrain Material.flax # Content/Editor/TexturePreviewMaterial.flax # Content/Editor/Wires Debug Material.flax # Content/Engine/DefaultDeformableMaterial.flax # Content/Engine/DefaultMaterial.flax # Content/Engine/DefaultTerrainMaterial.flax # Content/Engine/SingleColorMaterial.flax # Content/Engine/SkyboxMaterial.flax # Source/Engine/Graphics/Materials/MaterialShader.h
111 lines
3.1 KiB
C++
111 lines
3.1 KiB
C++
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "IMaterial.h"
|
|
#include "Engine/Core/Collections/Array.h"
|
|
#include "Engine/Graphics/GPUPipelineState.h"
|
|
#include "Engine/Renderer/Config.h"
|
|
|
|
/// <summary>
|
|
/// Current materials shader version.
|
|
/// </summary>
|
|
#define MATERIAL_GRAPH_VERSION 165
|
|
|
|
class Material;
|
|
class GPUShader;
|
|
class GPUConstantBuffer;
|
|
class MemoryReadStream;
|
|
|
|
/// <summary>
|
|
/// Represents material shader that can be used to render objects, visuals or effects. Contains a dedicated shader.
|
|
/// </summary>
|
|
class MaterialShader : public IMaterial
|
|
{
|
|
protected:
|
|
struct PipelineStateCache
|
|
{
|
|
GPUPipelineState* PS[6];
|
|
GPUPipelineState::Description Desc;
|
|
|
|
PipelineStateCache()
|
|
{
|
|
Platform::MemoryClear(PS, sizeof(PS));
|
|
}
|
|
|
|
void Init(GPUPipelineState::Description& desc)
|
|
{
|
|
Desc = desc;
|
|
}
|
|
|
|
GPUPipelineState* GetPS(CullMode mode, bool wireframe)
|
|
{
|
|
const int32 index = static_cast<int32>(mode) + (wireframe ? 3 : 0);
|
|
auto ps = PS[index];
|
|
if (!ps)
|
|
PS[index] = ps = InitPS(mode, wireframe);
|
|
return ps;
|
|
}
|
|
|
|
GPUPipelineState* InitPS(CullMode mode, bool wireframe);
|
|
|
|
void Release()
|
|
{
|
|
SAFE_DELETE_GPU_RESOURCES(PS);
|
|
}
|
|
};
|
|
|
|
protected:
|
|
bool _isLoaded;
|
|
GPUShader* _shader;
|
|
GPUConstantBuffer* _cb;
|
|
Array<byte> _cbData;
|
|
MaterialInfo _info;
|
|
|
|
protected:
|
|
/// <summary>
|
|
/// Init
|
|
/// </summary>
|
|
/// <param name="name">Material resource name</param>
|
|
MaterialShader(const StringView& name);
|
|
|
|
public:
|
|
/// <summary>
|
|
/// Finalizes an instance of the <see cref="MaterialShader"/> class.
|
|
/// </summary>
|
|
virtual ~MaterialShader();
|
|
|
|
public:
|
|
/// <summary>
|
|
/// Creates and loads the material from the data.
|
|
/// </summary>
|
|
/// <param name="name">Material resource name</param>
|
|
/// <param name="shaderCacheStream">Stream with compiled shader data</param>
|
|
/// <param name="info">Loaded material info structure</param>
|
|
/// <returns>The created and loaded material or null if failed.</returns>
|
|
static MaterialShader* Create(const StringView& name, MemoryReadStream& shaderCacheStream, const MaterialInfo& info);
|
|
|
|
/// <summary>
|
|
/// Creates the dummy material used by the Null rendering backend to mock object but not perform any rendering.
|
|
/// </summary>
|
|
/// <param name="shaderCacheStream">The shader cache stream.</param>
|
|
/// <param name="info">The material information.</param>
|
|
/// <returns>The created and loaded material or null if failed.</returns>
|
|
static MaterialShader* CreateDummy(MemoryReadStream& shaderCacheStream, const MaterialInfo& info);
|
|
|
|
/// <summary>
|
|
/// Clears the loaded data.
|
|
/// </summary>
|
|
virtual void Unload();
|
|
|
|
protected:
|
|
bool Load(MemoryReadStream& shaderCacheStream, const MaterialInfo& info);
|
|
virtual bool Load() = 0;
|
|
|
|
public:
|
|
// [IMaterial]
|
|
const MaterialInfo& GetInfo() const override;
|
|
GPUShader* GetShader() const override;
|
|
bool IsReady() const override;
|
|
};
|