Add Material class, modify TestGame.
This commit is contained in:
9
Voile/Source/Rendering/Material.cs
Normal file
9
Voile/Source/Rendering/Material.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Voile.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// An abstract class representing a render pipeline for the renderer, with entry points to fragment and vertex programs.
|
||||
/// </summary>
|
||||
public abstract class Material
|
||||
{
|
||||
public static UnlitMaterial Unlit => new UnlitMaterial();
|
||||
}
|
||||
@@ -123,7 +123,11 @@ namespace Voile.Rendering
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void EndFrame() => WgpuEndFrame();
|
||||
public override void EndFrame()
|
||||
{
|
||||
WgpuEndFrame();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Shutdown()
|
||||
@@ -292,31 +296,31 @@ namespace Voile.Rendering
|
||||
_wgpu.SurfaceGetCurrentTexture(_surface, ref _surfaceTexture);
|
||||
_surfaceTextureView = _wgpu.TextureCreateView(_surfaceTexture.Texture, null);
|
||||
|
||||
RenderPassColorAttachment* colorAttachments = stackalloc RenderPassColorAttachment[1];
|
||||
colorAttachments[0].View = _surfaceTextureView;
|
||||
colorAttachments[0].LoadOp = LoadOp.Clear;
|
||||
colorAttachments[0].ClearValue = VoileColorToWebGPUColor(_clearColor);
|
||||
colorAttachments[0].StoreOp = StoreOp.Store;
|
||||
RenderPassColorAttachment colorAttachments = CreateClearColorAttachment(_surfaceTextureView, _clearColor);
|
||||
|
||||
_renderPassDescriptor.ColorAttachments = colorAttachments;
|
||||
_renderPassDescriptor.ColorAttachmentCount = 1;
|
||||
RenderPassDescriptor renderPassDescriptor = new()
|
||||
{
|
||||
ColorAttachments = &colorAttachments,
|
||||
ColorAttachmentCount = 1
|
||||
};
|
||||
|
||||
_renderPassEncoder = _wgpu.CommandEncoderBeginRenderPass(_commandEncoder, _renderPassDescriptor);
|
||||
_renderPassEncoder = _wgpu.CommandEncoderBeginRenderPass(_commandEncoder, renderPassDescriptor);
|
||||
}
|
||||
|
||||
private unsafe void WgpuEndFrame()
|
||||
{
|
||||
_wgpu.RenderPassEncoderEnd(_renderPassEncoder);
|
||||
var commandBuffer = _wgpu.CommandEncoderFinish(_commandEncoder, null);
|
||||
_wgpu.CommandEncoderRelease(_commandEncoder);
|
||||
|
||||
_wgpu.QueueSubmit(_queue, 1, &commandBuffer);
|
||||
_wgpu.SurfacePresent(_surface);
|
||||
_wgpu.CommandBufferRelease(commandBuffer);
|
||||
|
||||
_wgpu.SurfacePresent(_surface);
|
||||
_wgpu.TextureViewRelease(_surfaceTextureView);
|
||||
|
||||
_wgpu.TextureRelease(_surfaceTexture.Texture);
|
||||
_wgpu.RenderPassEncoderRelease(_renderPassEncoder);
|
||||
_wgpu.CommandBufferRelease(commandBuffer);
|
||||
_wgpu.CommandEncoderRelease(_commandEncoder);
|
||||
}
|
||||
|
||||
private unsafe void ShutdownUnsafe()
|
||||
@@ -332,6 +336,23 @@ namespace Voile.Rendering
|
||||
return new Silk.NET.WebGPU.Color(color.R, color.G, color.B, color.A);
|
||||
}
|
||||
|
||||
private unsafe RenderPassColorAttachment CreateClearColorAttachment(TextureView* view, Color clearColor)
|
||||
{
|
||||
var colorAttachment = new RenderPassColorAttachment
|
||||
{
|
||||
View = view,
|
||||
LoadOp = LoadOp.Clear,
|
||||
ClearValue = VoileColorToWebGPUColor(clearColor),
|
||||
StoreOp = StoreOp.Store
|
||||
};
|
||||
|
||||
return colorAttachment;
|
||||
}
|
||||
|
||||
private unsafe RenderPipeline* CreatePipeline(Material fromMaterial)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
private Vector2 _windowSize;
|
||||
private IWindow? _window;
|
||||
|
||||
@@ -346,7 +367,6 @@ namespace Voile.Rendering
|
||||
private SurfaceTexture _surfaceTexture;
|
||||
private unsafe TextureView* _surfaceTextureView;
|
||||
private unsafe CommandEncoder* _commandEncoder;
|
||||
private RenderPassDescriptor _renderPassDescriptor;
|
||||
private unsafe RenderPassEncoder* _renderPassEncoder;
|
||||
|
||||
private Logger _logger = new(nameof(StandardRenderer));
|
||||
|
||||
9
Voile/Source/Rendering/UnlitMaterial.cs
Normal file
9
Voile/Source/Rendering/UnlitMaterial.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Voile.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// A default material for unlit objects.
|
||||
/// </summary>
|
||||
public class UnlitMaterial : Material
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user