Removed references to `Misaki.HighPerformance.Unsafe` and replaced them with `Misaki.HighPerformance.LowLevel` in multiple files. Removed calls to `AllocationManager.Initialize()` and `AllocationManager.Dispose()` in `EngineCore.cs`. Added new methods to the `ICommandBuffer` interface for enhanced rendering capabilities. Updated the `D3D12CommandBuffer` class to implement new graphics command handling methods. Added the `Material` class to manage shader properties and caching for improved performance. Encapsulated shader compilation and reflection processes within the `Shader` class for better organization. Added the `CBufferCache` struct to optimize GPU resource management for constant buffer data. Updated the `MeshRenderPass` class to utilize the new `Material` class for dynamic mesh rendering. Updated various project files to reflect the restructuring of dependencies. Modified XAML files and code-behind for improved readability and maintainability.
72 lines
1.4 KiB
C#
72 lines
1.4 KiB
C#
using Ghost.Graphics.Contracts;
|
|
using Ghost.Graphics.Data;
|
|
using Ghost.Graphics.Shading;
|
|
using Ghost.Graphics.Utilities;
|
|
using System.Drawing;
|
|
using System.Numerics;
|
|
|
|
namespace Ghost.Graphics.RenderPasses;
|
|
|
|
internal unsafe class MeshRenderPass : IRenderPass
|
|
{
|
|
private const string _HLSL_SOURCE = @"
|
|
cbuffer ConstantBuffer : register(b0)
|
|
{
|
|
float4 _Color;
|
|
};
|
|
|
|
struct VertexInput
|
|
{
|
|
float3 position : POSITION;
|
|
float4 color : COLOR;
|
|
};
|
|
|
|
struct PixelInput
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float4 color : COLOR;
|
|
};
|
|
|
|
PixelInput VSMain(VertexInput input)
|
|
{
|
|
PixelInput output;
|
|
output.position = float4(input.position, 1.0f);
|
|
output.color = input.color;
|
|
return output;
|
|
}
|
|
|
|
float4 PSMain(PixelInput input) : SV_TARGET
|
|
{
|
|
return float4(_Color.xyz, 1.0);
|
|
}
|
|
";
|
|
|
|
private Mesh? _mesh;
|
|
private Shader? _shader;
|
|
private Material? _material;
|
|
|
|
public void Initialize(ICommandBuffer cmb)
|
|
{
|
|
_mesh = MeshBuilder.CreateCube(0.25f);
|
|
_mesh.UploadMeshData(cmb);
|
|
|
|
_shader = new(_HLSL_SOURCE);
|
|
_material = new(_shader);
|
|
|
|
var color = new Vector4(Color.Brown.R / 255f, Color.Brown.G / 255f, Color.Brown.B / 255f, 1.0f);
|
|
_material.SetVector("_Color", ref color);
|
|
}
|
|
|
|
public void Execute(ICommandBuffer cmb)
|
|
{
|
|
cmb.DrawMesh(_mesh!, _material!);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_mesh?.Dispose();
|
|
_shader?.Dispose();
|
|
_material?.Dispose();
|
|
}
|
|
}
|