Add Material class, modify TestGame.
This commit is contained in:
@@ -98,8 +98,8 @@ public class TestGame : Game
|
|||||||
// _scene.BeginDraw();
|
// _scene.BeginDraw();
|
||||||
// _scene.EndDraw();
|
// _scene.EndDraw();
|
||||||
_renderer.BeginFrame();
|
_renderer.BeginFrame();
|
||||||
_renderer.ClearBackground(Color.Red);
|
// _renderer.ClearBackground(Color.Aqua);
|
||||||
_renderer.ClearBackground(Color.Blue);
|
// // _renderer.DrawRectangle(new Vector2(128, 128), Color.Black);
|
||||||
_renderer.EndFrame();
|
_renderer.EndFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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 />
|
/// <inheritdoc />
|
||||||
public override void EndFrame() => WgpuEndFrame();
|
public override void EndFrame()
|
||||||
|
{
|
||||||
|
WgpuEndFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
@@ -292,31 +296,31 @@ namespace Voile.Rendering
|
|||||||
_wgpu.SurfaceGetCurrentTexture(_surface, ref _surfaceTexture);
|
_wgpu.SurfaceGetCurrentTexture(_surface, ref _surfaceTexture);
|
||||||
_surfaceTextureView = _wgpu.TextureCreateView(_surfaceTexture.Texture, null);
|
_surfaceTextureView = _wgpu.TextureCreateView(_surfaceTexture.Texture, null);
|
||||||
|
|
||||||
RenderPassColorAttachment* colorAttachments = stackalloc RenderPassColorAttachment[1];
|
RenderPassColorAttachment colorAttachments = CreateClearColorAttachment(_surfaceTextureView, _clearColor);
|
||||||
colorAttachments[0].View = _surfaceTextureView;
|
|
||||||
colorAttachments[0].LoadOp = LoadOp.Clear;
|
|
||||||
colorAttachments[0].ClearValue = VoileColorToWebGPUColor(_clearColor);
|
|
||||||
colorAttachments[0].StoreOp = StoreOp.Store;
|
|
||||||
|
|
||||||
_renderPassDescriptor.ColorAttachments = colorAttachments;
|
RenderPassDescriptor renderPassDescriptor = new()
|
||||||
_renderPassDescriptor.ColorAttachmentCount = 1;
|
{
|
||||||
|
ColorAttachments = &colorAttachments,
|
||||||
|
ColorAttachmentCount = 1
|
||||||
|
};
|
||||||
|
|
||||||
_renderPassEncoder = _wgpu.CommandEncoderBeginRenderPass(_commandEncoder, _renderPassDescriptor);
|
_renderPassEncoder = _wgpu.CommandEncoderBeginRenderPass(_commandEncoder, renderPassDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void WgpuEndFrame()
|
private unsafe void WgpuEndFrame()
|
||||||
{
|
{
|
||||||
_wgpu.RenderPassEncoderEnd(_renderPassEncoder);
|
_wgpu.RenderPassEncoderEnd(_renderPassEncoder);
|
||||||
var commandBuffer = _wgpu.CommandEncoderFinish(_commandEncoder, null);
|
var commandBuffer = _wgpu.CommandEncoderFinish(_commandEncoder, null);
|
||||||
|
_wgpu.CommandEncoderRelease(_commandEncoder);
|
||||||
|
|
||||||
_wgpu.QueueSubmit(_queue, 1, &commandBuffer);
|
_wgpu.QueueSubmit(_queue, 1, &commandBuffer);
|
||||||
_wgpu.SurfacePresent(_surface);
|
_wgpu.CommandBufferRelease(commandBuffer);
|
||||||
|
|
||||||
|
_wgpu.SurfacePresent(_surface);
|
||||||
_wgpu.TextureViewRelease(_surfaceTextureView);
|
_wgpu.TextureViewRelease(_surfaceTextureView);
|
||||||
|
|
||||||
_wgpu.TextureRelease(_surfaceTexture.Texture);
|
_wgpu.TextureRelease(_surfaceTexture.Texture);
|
||||||
_wgpu.RenderPassEncoderRelease(_renderPassEncoder);
|
_wgpu.RenderPassEncoderRelease(_renderPassEncoder);
|
||||||
_wgpu.CommandBufferRelease(commandBuffer);
|
|
||||||
_wgpu.CommandEncoderRelease(_commandEncoder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void ShutdownUnsafe()
|
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);
|
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 Vector2 _windowSize;
|
||||||
private IWindow? _window;
|
private IWindow? _window;
|
||||||
|
|
||||||
@@ -346,7 +367,6 @@ namespace Voile.Rendering
|
|||||||
private SurfaceTexture _surfaceTexture;
|
private SurfaceTexture _surfaceTexture;
|
||||||
private unsafe TextureView* _surfaceTextureView;
|
private unsafe TextureView* _surfaceTextureView;
|
||||||
private unsafe CommandEncoder* _commandEncoder;
|
private unsafe CommandEncoder* _commandEncoder;
|
||||||
private RenderPassDescriptor _renderPassDescriptor;
|
|
||||||
private unsafe RenderPassEncoder* _renderPassEncoder;
|
private unsafe RenderPassEncoder* _renderPassEncoder;
|
||||||
|
|
||||||
private Logger _logger = new(nameof(StandardRenderer));
|
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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
## Engine
|
## Engine
|
||||||
|
|
||||||
### Core
|
### Core
|
||||||
|
|
||||||
- Virtual file system
|
- Virtual file system
|
||||||
- Hot reloading
|
- Hot reloading
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user