blob: f54766dc8b004a160c6f3c42961f85b1c51bb953 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Austin Eng376f1c62017-05-30 20:03:44 -04002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Corentin Wallez9347e8f2017-06-19 13:15:13 -040015#include "SampleUtils.h"
Austin Eng376f1c62017-05-30 20:03:44 -040016
Yan, Shaoboa4924272018-12-10 19:47:22 +000017#include "utils/ComboRenderPipelineDescriptor.h"
Austin Eng700a5fb2021-06-24 19:21:31 +000018#include "utils/ScopedAutoreleasePool.h"
Corentin Wallez134e0802017-07-17 17:13:57 -040019#include "utils/SystemUtils.h"
Corentin Wallez04863c42019-10-25 11:36:47 +000020#include "utils/WGPUHelpers.h"
Corentin Wallez5ee7afd2017-06-19 13:09:41 -040021
Corentin Wallez4d7d1692018-08-13 08:23:27 +020022#include <glm/glm.hpp>
23#include <glm/gtc/matrix_transform.hpp>
24#include <glm/gtc/type_ptr.hpp>
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000025#include <vector>
Austin Eng376f1c62017-05-30 20:03:44 -040026
Corentin Wallez04863c42019-10-25 11:36:47 +000027wgpu::Device device;
Austin Eng376f1c62017-05-30 20:03:44 -040028
Corentin Wallez04863c42019-10-25 11:36:47 +000029wgpu::Buffer indexBuffer;
30wgpu::Buffer vertexBuffer;
31wgpu::Buffer planeBuffer;
32wgpu::Buffer cameraBuffer;
33wgpu::Buffer transformBuffer[2];
Austin Eng376f1c62017-05-30 20:03:44 -040034
Corentin Wallez04863c42019-10-25 11:36:47 +000035wgpu::BindGroup cameraBindGroup;
36wgpu::BindGroup bindGroup[2];
37wgpu::BindGroup cubeTransformBindGroup[2];
Austin Eng376f1c62017-05-30 20:03:44 -040038
Corentin Wallez04863c42019-10-25 11:36:47 +000039wgpu::Queue queue;
40wgpu::SwapChain swapchain;
41wgpu::TextureView depthStencilView;
42wgpu::RenderPipeline pipeline;
43wgpu::RenderPipeline planePipeline;
44wgpu::RenderPipeline reflectionPipeline;
Austin Eng376f1c62017-05-30 20:03:44 -040045
46void initBuffers() {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000047 static const uint32_t indexData[6 * 6] = {0, 1, 2, 0, 2, 3,
Austin Eng376f1c62017-05-30 20:03:44 -040048
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000049 4, 5, 6, 4, 6, 7,
Austin Eng376f1c62017-05-30 20:03:44 -040050
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000051 8, 9, 10, 8, 10, 11,
Austin Eng376f1c62017-05-30 20:03:44 -040052
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000053 12, 13, 14, 12, 14, 15,
Austin Eng376f1c62017-05-30 20:03:44 -040054
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000055 16, 17, 18, 16, 18, 19,
Austin Eng376f1c62017-05-30 20:03:44 -040056
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000057 20, 21, 22, 20, 22, 23};
Corentin Wallez9e9e29f2019-08-27 08:21:39 +000058 indexBuffer =
Corentin Wallez04863c42019-10-25 11:36:47 +000059 utils::CreateBufferFromData(device, indexData, sizeof(indexData), wgpu::BufferUsage::Index);
Austin Eng376f1c62017-05-30 20:03:44 -040060
61 static const float vertexData[6 * 4 * 6] = {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000062 -1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
63 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
Austin Eng376f1c62017-05-30 20:03:44 -040064
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000065 -1.0, -1.0, -1.0, 1.0, 1.0, 0.0, -1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
66 1.0, 1.0, -1.0, 1.0, 1.0, 0.0, 1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
Austin Eng376f1c62017-05-30 20:03:44 -040067
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000068 -1.0, 1.0, -1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
69 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
Austin Eng376f1c62017-05-30 20:03:44 -040070
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000071 -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
72 1.0, -1.0, 1.0, 0.0, 1.0, 0.0, -1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
Austin Eng376f1c62017-05-30 20:03:44 -040073
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000074 1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
75 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 1.0, 1.0,
Austin Eng376f1c62017-05-30 20:03:44 -040076
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000077 -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
78 -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0};
Corentin Wallez9e9e29f2019-08-27 08:21:39 +000079 vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData),
Corentin Wallez04863c42019-10-25 11:36:47 +000080 wgpu::BufferUsage::Vertex);
Austin Eng376f1c62017-05-30 20:03:44 -040081
82 static const float planeData[6 * 4] = {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000083 -2.0, -1.0, -2.0, 0.5, 0.5, 0.5, 2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
84 2.0, -1.0, 2.0, 0.5, 0.5, 0.5, -2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
Austin Eng376f1c62017-05-30 20:03:44 -040085 };
Corentin Wallez9e9e29f2019-08-27 08:21:39 +000086 planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData),
Corentin Wallez04863c42019-10-25 11:36:47 +000087 wgpu::BufferUsage::Vertex);
Austin Eng376f1c62017-05-30 20:03:44 -040088}
89
Austin Eng58c76b32017-06-02 14:31:53 -040090struct CameraData {
Austin Eng376f1c62017-05-30 20:03:44 -040091 glm::mat4 view;
92 glm::mat4 proj;
93} cameraData;
94
95void init() {
Corentin Wallez39039fa2018-07-18 14:06:10 +020096 device = CreateCppDawnDevice();
Austin Eng376f1c62017-05-30 20:03:44 -040097
Corentin Wallez6d315da2021-02-04 15:33:42 +000098 queue = device.GetQueue();
Kai Ninomiyac16a67a2017-07-27 18:30:57 -070099 swapchain = GetSwapChain(device);
Corentin Wallez6b087812020-10-27 15:35:56 +0000100 swapchain.Configure(GetPreferredSwapChainTextureFormat(), wgpu::TextureUsage::RenderAttachment,
Corentin Wallez9e9e29f2019-08-27 08:21:39 +0000101 640, 480);
Austin Eng376f1c62017-05-30 20:03:44 -0400102
103 initBuffers();
104
Corentin Wallez7aec4ae2021-03-24 15:55:32 +0000105 wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"(
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000106 [[block]] struct Camera {
Ben Claytonc5686842021-03-17 09:48:19 +0000107 view : mat4x4<f32>;
108 proj : mat4x4<f32>;
Austin Eng376f1c62017-05-30 20:03:44 -0400109 };
dan sinclair0f9c2d72021-01-19 14:18:51 +0000110 [[group(0), binding(0)]] var<uniform> camera : Camera;
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000111
112 [[block]] struct Model {
Ben Claytonc5686842021-03-17 09:48:19 +0000113 matrix : mat4x4<f32>;
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000114 };
dan sinclair0f9c2d72021-01-19 14:18:51 +0000115 [[group(0), binding(1)]] var<uniform> model : Model;
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000116
James Price9e0debd2021-04-13 14:52:44 +0000117 struct VertexOut {
118 [[location(2)]] f_col : vec3<f32>;
119 [[builtin(position)]] Position : vec4<f32>;
120 };
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000121
James Price9e0debd2021-04-13 14:52:44 +0000122 [[stage(vertex)]] fn main(
123 [[location(0)]] pos : vec3<f32>,
124 [[location(1)]] col : vec3<f32>) -> VertexOut {
125 var output : VertexOut;
126 output.f_col = col;
127 output.Position = camera.proj * camera.view * model.matrix * vec4<f32>(pos, 1.0);
128 return output;
Corentin Wallez2a1d8c22019-07-12 17:52:22 +0000129 })");
Austin Eng376f1c62017-05-30 20:03:44 -0400130
Corentin Wallez7aec4ae2021-03-24 15:55:32 +0000131 wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
James Price9e0debd2021-04-13 14:52:44 +0000132 [[stage(fragment)]] fn main(
133 [[location(2)]] f_col : vec3<f32>) -> [[location(0)]] vec4<f32> {
134 return vec4<f32>(f_col, 1.0);
Corentin Wallezb6fb5f32017-08-29 13:37:45 -0400135 })");
Austin Eng376f1c62017-05-30 20:03:44 -0400136
Corentin Wallez7aec4ae2021-03-24 15:55:32 +0000137 wgpu::ShaderModule fsReflectionModule = utils::CreateShaderModule(device, R"(
James Price9e0debd2021-04-13 14:52:44 +0000138 [[stage(fragment)]] fn main(
139 [[location(2)]] f_col : vec3<f32>) -> [[location(0)]] vec4<f32> {
140 return vec4<f32>(mix(f_col, vec3<f32>(0.5, 0.5, 0.5), vec3<f32>(0.5, 0.5, 0.5)), 1.0);
Corentin Wallezb6fb5f32017-08-29 13:37:45 -0400141 })");
Austin Eng376f1c62017-05-30 20:03:44 -0400142
Corentin Wallez9895c272021-03-18 16:46:58 +0000143 wgpu::VertexAttribute attributes[2];
144 attributes[0].shaderLocation = 0;
145 attributes[0].offset = 0;
146 attributes[0].format = wgpu::VertexFormat::Float32x3;
147 attributes[1].shaderLocation = 1;
148 attributes[1].offset = 3 * sizeof(float);
149 attributes[1].format = wgpu::VertexFormat::Float32x3;
Yunchao He1ba2cb82019-03-28 05:09:01 +0000150
Corentin Wallez9895c272021-03-18 16:46:58 +0000151 wgpu::VertexBufferLayout vertexBufferLayout;
152 vertexBufferLayout.attributeCount = 2;
153 vertexBufferLayout.attributes = attributes;
154 vertexBufferLayout.arrayStride = 6 * sizeof(float);
Austin Eng376f1c62017-05-30 20:03:44 -0400155
Kai Ninomiya234becf2018-07-10 12:23:50 -0700156 auto bgl = utils::MakeBindGroupLayout(
157 device, {
Corentin Wallez9895c272021-03-18 16:46:58 +0000158 {0, wgpu::ShaderStage::Vertex, wgpu::BufferBindingType::Uniform},
159 {1, wgpu::ShaderStage::Vertex, wgpu::BufferBindingType::Uniform},
Kai Ninomiya234becf2018-07-10 12:23:50 -0700160 });
Austin Eng376f1c62017-05-30 20:03:44 -0400161
Corentin Wallez04863c42019-10-25 11:36:47 +0000162 wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
Austin Eng376f1c62017-05-30 20:03:44 -0400163
Corentin Wallez04863c42019-10-25 11:36:47 +0000164 wgpu::BufferDescriptor cameraBufDesc;
Corentin Wallez82b65732018-08-22 15:37:29 +0200165 cameraBufDesc.size = sizeof(CameraData);
Corentin Wallez04863c42019-10-25 11:36:47 +0000166 cameraBufDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Uniform;
Corentin Wallez82b65732018-08-22 15:37:29 +0200167 cameraBuffer = device.CreateBuffer(&cameraBufDesc);
Austin Eng376f1c62017-05-30 20:03:44 -0400168
169 glm::mat4 transform(1.0);
Corentin Wallez9e9e29f2019-08-27 08:21:39 +0000170 transformBuffer[0] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4),
Corentin Wallez04863c42019-10-25 11:36:47 +0000171 wgpu::BufferUsage::Uniform);
Austin Eng376f1c62017-05-30 20:03:44 -0400172
173 transform = glm::translate(transform, glm::vec3(0.f, -2.f, 0.f));
Corentin Wallez9e9e29f2019-08-27 08:21:39 +0000174 transformBuffer[1] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4),
Corentin Wallez04863c42019-10-25 11:36:47 +0000175 wgpu::BufferUsage::Uniform);
Austin Eng376f1c62017-05-30 20:03:44 -0400176
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000177 bindGroup[0] = utils::MakeBindGroup(
178 device, bgl,
179 {{0, cameraBuffer, 0, sizeof(CameraData)}, {1, transformBuffer[0], 0, sizeof(glm::mat4)}});
Austin Eng376f1c62017-05-30 20:03:44 -0400180
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000181 bindGroup[1] = utils::MakeBindGroup(
182 device, bgl,
183 {{0, cameraBuffer, 0, sizeof(CameraData)}, {1, transformBuffer[1], 0, sizeof(glm::mat4)}});
Austin Eng376f1c62017-05-30 20:03:44 -0400184
Kai Ninomiyac16a67a2017-07-27 18:30:57 -0700185 depthStencilView = CreateDefaultDepthStencilView(device);
Austin Eng376f1c62017-05-30 20:03:44 -0400186
Corentin Wallez9895c272021-03-18 16:46:58 +0000187 {
Brandon Jones41c87d92021-05-21 05:01:38 +0000188 utils::ComboRenderPipelineDescriptor descriptor;
Corentin Wallez9895c272021-03-18 16:46:58 +0000189 descriptor.vertex.module = vsModule;
190 descriptor.vertex.bufferCount = 1;
191 descriptor.vertex.buffers = &vertexBufferLayout;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000192
Corentin Wallez9895c272021-03-18 16:46:58 +0000193 descriptor.layout = pl;
194 descriptor.cFragment.module = fsModule;
195 descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
Austin Eng376f1c62017-05-30 20:03:44 -0400196
Corentin Wallez9895c272021-03-18 16:46:58 +0000197 wgpu::DepthStencilState* depthStencil =
198 descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8);
199 depthStencil->depthWriteEnabled = true;
200 depthStencil->depthCompare = wgpu::CompareFunction::Less;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000201
Brandon Jones41c87d92021-05-21 05:01:38 +0000202 pipeline = device.CreateRenderPipeline(&descriptor);
Corentin Wallez9895c272021-03-18 16:46:58 +0000203 }
Austin Eng376f1c62017-05-30 20:03:44 -0400204
Corentin Wallez9895c272021-03-18 16:46:58 +0000205 {
Brandon Jones41c87d92021-05-21 05:01:38 +0000206 utils::ComboRenderPipelineDescriptor descriptor;
Corentin Wallez9895c272021-03-18 16:46:58 +0000207 descriptor.vertex.module = vsModule;
208 descriptor.vertex.bufferCount = 1;
209 descriptor.vertex.buffers = &vertexBufferLayout;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000210
Corentin Wallez9895c272021-03-18 16:46:58 +0000211 descriptor.layout = pl;
212 descriptor.cFragment.module = fsModule;
213 descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
214
215 wgpu::DepthStencilState* depthStencil =
216 descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8);
217 depthStencil->stencilFront.passOp = wgpu::StencilOperation::Replace;
218 depthStencil->stencilBack.passOp = wgpu::StencilOperation::Replace;
219 depthStencil->depthCompare = wgpu::CompareFunction::Less;
220
Brandon Jones41c87d92021-05-21 05:01:38 +0000221 planePipeline = device.CreateRenderPipeline(&descriptor);
Corentin Wallez9895c272021-03-18 16:46:58 +0000222 }
223
224 {
Brandon Jones41c87d92021-05-21 05:01:38 +0000225 utils::ComboRenderPipelineDescriptor descriptor;
Corentin Wallez9895c272021-03-18 16:46:58 +0000226 descriptor.vertex.module = vsModule;
227 descriptor.vertex.bufferCount = 1;
228 descriptor.vertex.buffers = &vertexBufferLayout;
229
230 descriptor.layout = pl;
231 descriptor.cFragment.module = fsReflectionModule;
232 descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
233
234 wgpu::DepthStencilState* depthStencil =
235 descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8);
236 depthStencil->stencilFront.compare = wgpu::CompareFunction::Equal;
237 depthStencil->stencilBack.compare = wgpu::CompareFunction::Equal;
238 depthStencil->stencilFront.passOp = wgpu::StencilOperation::Replace;
239 depthStencil->stencilBack.passOp = wgpu::StencilOperation::Replace;
240 depthStencil->depthWriteEnabled = true;
241 depthStencil->depthCompare = wgpu::CompareFunction::Less;
242
Brandon Jones41c87d92021-05-21 05:01:38 +0000243 reflectionPipeline = device.CreateRenderPipeline(&descriptor);
Corentin Wallez9895c272021-03-18 16:46:58 +0000244 }
Austin Eng376f1c62017-05-30 20:03:44 -0400245
246 cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
247}
248
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000249struct {
250 uint32_t a;
251 float b;
252} s;
Austin Eng376f1c62017-05-30 20:03:44 -0400253void frame() {
254 s.a = (s.a + 1) % 256;
Corentin Wallez83e779d2017-07-10 21:44:06 -0400255 s.b += 0.01f;
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000256 if (s.b >= 1.0f) {
257 s.b = 0.0f;
258 }
Austin Eng376f1c62017-05-30 20:03:44 -0400259
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000260 cameraData.view = glm::lookAt(glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f,
261 8.f * std::cos(glm::radians(s.b * 360.f))),
262 glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
Austin Eng376f1c62017-05-30 20:03:44 -0400263
Corentin Wallez47a33412020-06-02 09:24:39 +0000264 queue.WriteBuffer(cameraBuffer, 0, &cameraData, sizeof(CameraData));
Austin Eng376f1c62017-05-30 20:03:44 -0400265
Corentin Wallez604072b2019-11-12 18:30:11 +0000266 wgpu::TextureView backbufferView = swapchain.GetCurrentTextureView();
267 utils::ComboRenderPassDescriptor renderPass({backbufferView}, depthStencilView);
Kai Ninomiyac16a67a2017-07-27 18:30:57 -0700268
Corentin Wallez04863c42019-10-25 11:36:47 +0000269 wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
Corentin Wallez82fbccb2018-09-21 00:24:37 +0000270 {
Corentin Wallez04863c42019-10-25 11:36:47 +0000271 wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
Yan, Shaobo300eec02018-12-21 10:40:26 +0000272 pass.SetPipeline(pipeline);
Corentin Wallez70c8c102019-10-09 16:08:42 +0000273 pass.SetBindGroup(0, bindGroup[0]);
François Beaufort91b21422019-10-10 07:29:58 +0000274 pass.SetVertexBuffer(0, vertexBuffer);
Corentin Wallez5fad85b2020-11-25 08:54:14 +0000275 pass.SetIndexBuffer(indexBuffer, wgpu::IndexFormat::Uint32);
Corentin Wallez67b1ad72020-03-31 16:21:35 +0000276 pass.DrawIndexed(36);
Austin Eng376f1c62017-05-30 20:03:44 -0400277
Corentin Wallez82fbccb2018-09-21 00:24:37 +0000278 pass.SetStencilReference(0x1);
Yan, Shaobo300eec02018-12-21 10:40:26 +0000279 pass.SetPipeline(planePipeline);
Corentin Wallez70c8c102019-10-09 16:08:42 +0000280 pass.SetBindGroup(0, bindGroup[0]);
François Beaufort91b21422019-10-10 07:29:58 +0000281 pass.SetVertexBuffer(0, planeBuffer);
Corentin Wallez67b1ad72020-03-31 16:21:35 +0000282 pass.DrawIndexed(6);
Austin Eng376f1c62017-05-30 20:03:44 -0400283
Yan, Shaobo300eec02018-12-21 10:40:26 +0000284 pass.SetPipeline(reflectionPipeline);
François Beaufort91b21422019-10-10 07:29:58 +0000285 pass.SetVertexBuffer(0, vertexBuffer);
Corentin Wallez70c8c102019-10-09 16:08:42 +0000286 pass.SetBindGroup(0, bindGroup[1]);
Corentin Wallez67b1ad72020-03-31 16:21:35 +0000287 pass.DrawIndexed(36);
Austin Eng376f1c62017-05-30 20:03:44 -0400288
Corentin Wallez82fbccb2018-09-21 00:24:37 +0000289 pass.EndPass();
290 }
291
Corentin Wallez04863c42019-10-25 11:36:47 +0000292 wgpu::CommandBuffer commands = encoder.Finish();
Austin Eng376f1c62017-05-30 20:03:44 -0400293 queue.Submit(1, &commands);
Corentin Wallez604072b2019-11-12 18:30:11 +0000294 swapchain.Present();
Kai Ninomiyac16a67a2017-07-27 18:30:57 -0700295 DoFlush();
Austin Eng376f1c62017-05-30 20:03:44 -0400296}
297
298int main(int argc, const char* argv[]) {
Corentin Wallez9347e8f2017-06-19 13:15:13 -0400299 if (!InitSample(argc, argv)) {
Austin Eng376f1c62017-05-30 20:03:44 -0400300 return 1;
301 }
302 init();
303
304 while (!ShouldQuit()) {
Austin Eng700a5fb2021-06-24 19:21:31 +0000305 utils::ScopedAutoreleasePool pool;
Austin Eng376f1c62017-05-30 20:03:44 -0400306 frame();
Corentin Wallez134e0802017-07-17 17:13:57 -0400307 utils::USleep(16000);
Austin Eng376f1c62017-05-30 20:03:44 -0400308 }
309
310 // TODO release stuff
311}