1
- // Copyright © Amer Koleci and Contributors.
1
+ // Copyright (c) Amer Koleci and Contributors.
2
2
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
3
3
4
4
using System . Numerics ;
5
- using Alimer . WebGPU . SampleFramework ;
6
5
using WebGPU ;
7
6
using static WebGPU . WebGPU ;
8
7
9
- namespace DrawTriangle ;
8
+ namespace Alimer . WebGPU . Samples ;
10
9
11
10
public static unsafe class Program
12
11
{
@@ -136,12 +135,12 @@ protected override void Initialize()
136
135
137
136
wgpuShaderModuleRelease ( shaderModule ) ;
138
137
139
- ReadOnlySpan < VertexPositionColor > vertexData = stackalloc VertexPositionColor [ ] {
138
+ ReadOnlySpan < VertexPositionColor > vertexData = [
140
139
new ( new Vector3 ( - 0.5f , 0.5f , 0.5f ) , new Vector4 ( 1.0f , 0.0f , 0.0f , 1.0f ) ) ,
141
140
new ( new Vector3 ( 0.5f , 0.5f , 0.5f ) , new Vector4 ( 0.0f , 1.0f , 0.0f , 1.0f ) ) ,
142
141
new ( new Vector3 ( 0.5f , - 0.5f , 0.5f ) , new Vector4 ( 0.0f , 0.0f , 1.0f , 1.0f ) ) ,
143
142
new ( new Vector3 ( - 0.5f , - 0.5f , 0.5f ) , new Vector4 ( 1.0f , 1.0f , 0.0f , 1.0f ) )
144
- } ;
143
+ ] ;
145
144
_vertexBuffer = wgpuDeviceCreateBuffer ( _graphicsDevice . Device , WGPUBufferUsage . Vertex | WGPUBufferUsage . CopyDst , vertexData . Length * VertexPositionColor . SizeInBytes ) ;
146
145
wgpuQueueWriteBuffer ( _graphicsDevice . Queue , _vertexBuffer , vertexData ) ;
147
146
@@ -177,12 +176,14 @@ protected override void OnTick()
177
176
_graphicsDevice ! . RenderFrame ( OnDraw ) ;
178
177
}
179
178
180
- private void OnDraw ( WGPUCommandEncoder encoder , WGPUTextureView swapChainTextureView )
179
+ private void OnDraw ( WGPUCommandEncoder encoder , WGPUTexture target )
181
180
{
181
+ WGPUTextureView targetView = wgpuTextureCreateView ( target , null ) ;
182
+
182
183
WGPURenderPassColorAttachment renderPassColorAttachment = new ( ) ;
183
184
// The attachment is tighed to the view returned by the swap chain, so that
184
185
// the render pass draws directly on screen.
185
- renderPassColorAttachment . view = swapChainTextureView ;
186
+ renderPassColorAttachment . view = targetView ;
186
187
// Not relevant here because we do not use multi-sampling
187
188
renderPassColorAttachment . resolveTarget = WGPUTextureView . Null ;
188
189
renderPassColorAttachment . loadOp = WGPULoadOp . Clear ;
@@ -199,7 +200,6 @@ private void OnDraw(WGPUCommandEncoder encoder, WGPUTextureView swapChainTexture
199
200
depthStencilAttachment = null ,
200
201
201
202
// We do not use timers for now neither
202
- timestampWriteCount = 0 ,
203
203
timestampWrites = null
204
204
} ;
205
205
@@ -214,6 +214,7 @@ private void OnDraw(WGPUCommandEncoder encoder, WGPUTextureView swapChainTexture
214
214
wgpuRenderPassEncoderDrawIndexed ( renderPass , 6 ) ;
215
215
216
216
wgpuRenderPassEncoderEnd ( renderPass ) ;
217
+ wgpuTextureViewReference ( targetView ) ;
217
218
}
218
219
}
219
220
}
0 commit comments