blob: 88d5cb41b95bf7b56505093a1b6958bbadc20e03 [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"
Corentin Wallez134e0802017-07-17 17:13:57 -040018#include "utils/SystemUtils.h"
Corentin Wallez04863c42019-10-25 11:36:47 +000019#include "utils/WGPUHelpers.h"
Corentin Wallez5ee7afd2017-06-19 13:09:41 -040020
Corentin Wallez4d7d1692018-08-13 08:23:27 +020021#include <glm/glm.hpp>
22#include <glm/gtc/matrix_transform.hpp>
23#include <glm/gtc/type_ptr.hpp>
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000024#include <vector>
Austin Eng376f1c62017-05-30 20:03:44 -040025
Corentin Wallez04863c42019-10-25 11:36:47 +000026wgpu::Device device;
Austin Eng376f1c62017-05-30 20:03:44 -040027
Corentin Wallez04863c42019-10-25 11:36:47 +000028wgpu::Buffer indexBuffer;
29wgpu::Buffer vertexBuffer;
30wgpu::Buffer planeBuffer;
31wgpu::Buffer cameraBuffer;
32wgpu::Buffer transformBuffer[2];
Austin Eng376f1c62017-05-30 20:03:44 -040033
Corentin Wallez04863c42019-10-25 11:36:47 +000034wgpu::BindGroup cameraBindGroup;
35wgpu::BindGroup bindGroup[2];
36wgpu::BindGroup cubeTransformBindGroup[2];
Austin Eng376f1c62017-05-30 20:03:44 -040037
Corentin Wallez04863c42019-10-25 11:36:47 +000038wgpu::Queue queue;
39wgpu::SwapChain swapchain;
40wgpu::TextureView depthStencilView;
41wgpu::RenderPipeline pipeline;
42wgpu::RenderPipeline planePipeline;
43wgpu::RenderPipeline reflectionPipeline;
Austin Eng376f1c62017-05-30 20:03:44 -040044
45void initBuffers() {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000046 static const uint32_t indexData[6 * 6] = {0, 1, 2, 0, 2, 3,
Austin Eng376f1c62017-05-30 20:03:44 -040047
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000048 4, 5, 6, 4, 6, 7,
Austin Eng376f1c62017-05-30 20:03:44 -040049
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000050 8, 9, 10, 8, 10, 11,
Austin Eng376f1c62017-05-30 20:03:44 -040051
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000052 12, 13, 14, 12, 14, 15,
Austin Eng376f1c62017-05-30 20:03:44 -040053
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000054 16, 17, 18, 16, 18, 19,
Austin Eng376f1c62017-05-30 20:03:44 -040055
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000056 20, 21, 22, 20, 22, 23};
Corentin Wallez9e9e29f2019-08-27 08:21:39 +000057 indexBuffer =
Corentin Wallez04863c42019-10-25 11:36:47 +000058 utils::CreateBufferFromData(device, indexData, sizeof(indexData), wgpu::BufferUsage::Index);
Austin Eng376f1c62017-05-30 20:03:44 -040059
60 static const float vertexData[6 * 4 * 6] = {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000061 -1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
62 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 -040063
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000064 -1.0, -1.0, -1.0, 1.0, 1.0, 0.0, -1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
65 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 -040066
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000067 -1.0, 1.0, -1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
68 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 -040069
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000070 -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
71 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 -040072
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000073 1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
74 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 -040075
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000076 -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
77 -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 +000078 vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData),
Corentin Wallez04863c42019-10-25 11:36:47 +000079 wgpu::BufferUsage::Vertex);
Austin Eng376f1c62017-05-30 20:03:44 -040080
81 static const float planeData[6 * 4] = {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000082 -2.0, -1.0, -2.0, 0.5, 0.5, 0.5, 2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
83 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 -040084 };
Corentin Wallez9e9e29f2019-08-27 08:21:39 +000085 planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData),
Corentin Wallez04863c42019-10-25 11:36:47 +000086 wgpu::BufferUsage::Vertex);
Austin Eng376f1c62017-05-30 20:03:44 -040087}
88
Austin Eng58c76b32017-06-02 14:31:53 -040089struct CameraData {
Austin Eng376f1c62017-05-30 20:03:44 -040090 glm::mat4 view;
91 glm::mat4 proj;
92} cameraData;
93
94void init() {
Corentin Wallez39039fa2018-07-18 14:06:10 +020095 device = CreateCppDawnDevice();
Austin Eng376f1c62017-05-30 20:03:44 -040096
Corentin Wallez6d315da2021-02-04 15:33:42 +000097 queue = device.GetQueue();
Kai Ninomiyac16a67a2017-07-27 18:30:57 -070098 swapchain = GetSwapChain(device);
Corentin Wallez6b087812020-10-27 15:35:56 +000099 swapchain.Configure(GetPreferredSwapChainTextureFormat(), wgpu::TextureUsage::RenderAttachment,
Corentin Wallez9e9e29f2019-08-27 08:21:39 +0000100 640, 480);
Austin Eng376f1c62017-05-30 20:03:44 -0400101
102 initBuffers();
103
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000104 wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
105 [[block]] struct Camera {
Ben Claytonc5686842021-03-17 09:48:19 +0000106 view : mat4x4<f32>;
107 proj : mat4x4<f32>;
Austin Eng376f1c62017-05-30 20:03:44 -0400108 };
dan sinclair0f9c2d72021-01-19 14:18:51 +0000109 [[group(0), binding(0)]] var<uniform> camera : Camera;
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000110
111 [[block]] struct Model {
Ben Claytonc5686842021-03-17 09:48:19 +0000112 matrix : mat4x4<f32>;
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000113 };
dan sinclair0f9c2d72021-01-19 14:18:51 +0000114 [[group(0), binding(1)]] var<uniform> model : Model;
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000115
116 [[location(0)]] var<in> pos : vec3<f32>;
117 [[location(1)]] var<in> col : vec3<f32>;
118
119 [[location(2)]] var<out> f_col : vec3<f32>;
120 [[builtin(position)]] var<out> Position : vec4<f32>;
121
122 [[stage(vertex)]] fn main() -> void {
Austin Eng376f1c62017-05-30 20:03:44 -0400123 f_col = col;
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000124 Position = camera.proj * camera.view * model.matrix * vec4<f32>(pos, 1.0);
125 return;
Corentin Wallez2a1d8c22019-07-12 17:52:22 +0000126 })");
Austin Eng376f1c62017-05-30 20:03:44 -0400127
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000128 wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
129 [[location(0)]] var<out> FragColor : vec4<f32>;
130 [[location(2)]] var<in> f_col : vec3<f32>;
131
132 [[stage(fragment)]] fn main() -> void {
133 FragColor = vec4<f32>(f_col, 1.0);
134 return;
Corentin Wallezb6fb5f32017-08-29 13:37:45 -0400135 })");
Austin Eng376f1c62017-05-30 20:03:44 -0400136
Corentin Wallez4814bdb2020-11-26 16:39:46 +0000137 wgpu::ShaderModule fsReflectionModule = utils::CreateShaderModuleFromWGSL(device, R"(
138 [[location(0)]] var<out> FragColor : vec4<f32>;
139 [[location(2)]] var<in> f_col : vec3<f32>;
140
141 [[stage(fragment)]] fn main() -> void {
142 FragColor = vec4<f32>(mix(f_col, vec3<f32>(0.5, 0.5, 0.5), vec3<f32>(0.5, 0.5, 0.5)), 1.0);
143 return;
Corentin Wallezb6fb5f32017-08-29 13:37:45 -0400144 })");
Austin Eng376f1c62017-05-30 20:03:44 -0400145
Kai Ninomiyaae1f25f2019-11-07 22:23:29 +0000146 utils::ComboVertexStateDescriptor vertexState;
147 vertexState.cVertexBuffers[0].attributeCount = 2;
148 vertexState.cAttributes[0].format = wgpu::VertexFormat::Float3;
149 vertexState.cAttributes[1].shaderLocation = 1;
150 vertexState.cAttributes[1].offset = 3 * sizeof(float);
151 vertexState.cAttributes[1].format = wgpu::VertexFormat::Float3;
Yunchao He1ba2cb82019-03-28 05:09:01 +0000152
Kai Ninomiyaae1f25f2019-11-07 22:23:29 +0000153 vertexState.vertexBufferCount = 1;
154 vertexState.cVertexBuffers[0].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 Wallez04863c42019-10-25 11:36:47 +0000158 {0, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer},
159 {1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer},
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
Yan, Shaoboa4924272018-12-10 19:47:22 +0000187 utils::ComboRenderPipelineDescriptor descriptor(device);
188 descriptor.layout = pl;
Corentin Wallezc6c7a422019-09-05 09:35:07 +0000189 descriptor.vertexStage.module = vsModule;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000190 descriptor.cFragmentStage.module = fsModule;
Kai Ninomiyaae1f25f2019-11-07 22:23:29 +0000191 descriptor.vertexState = &vertexState;
Yunchao He108bcbd2019-02-15 02:20:57 +0000192 descriptor.depthStencilState = &descriptor.cDepthStencilState;
Corentin Wallez04863c42019-10-25 11:36:47 +0000193 descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
Corentin Wallezc81a7172019-09-20 23:22:27 +0000194 descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
Yunchao Heea563332019-01-04 04:28:37 +0000195 descriptor.cDepthStencilState.depthWriteEnabled = true;
Corentin Wallez04863c42019-10-25 11:36:47 +0000196 descriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000197
198 pipeline = device.CreateRenderPipeline(&descriptor);
Austin Eng376f1c62017-05-30 20:03:44 -0400199
Yan, Shaoboa4924272018-12-10 19:47:22 +0000200 utils::ComboRenderPipelineDescriptor pDescriptor(device);
201 pDescriptor.layout = pl;
Corentin Wallezc6c7a422019-09-05 09:35:07 +0000202 pDescriptor.vertexStage.module = vsModule;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000203 pDescriptor.cFragmentStage.module = fsModule;
Kai Ninomiyaae1f25f2019-11-07 22:23:29 +0000204 pDescriptor.vertexState = &vertexState;
Yunchao He108bcbd2019-02-15 02:20:57 +0000205 pDescriptor.depthStencilState = &pDescriptor.cDepthStencilState;
Corentin Wallez04863c42019-10-25 11:36:47 +0000206 pDescriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
Corentin Wallezc81a7172019-09-20 23:22:27 +0000207 pDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
Corentin Wallez04863c42019-10-25 11:36:47 +0000208 pDescriptor.cDepthStencilState.stencilFront.passOp = wgpu::StencilOperation::Replace;
209 pDescriptor.cDepthStencilState.stencilBack.passOp = wgpu::StencilOperation::Replace;
210 pDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000211
212 planePipeline = device.CreateRenderPipeline(&pDescriptor);
Austin Eng376f1c62017-05-30 20:03:44 -0400213
Yan, Shaoboa4924272018-12-10 19:47:22 +0000214 utils::ComboRenderPipelineDescriptor rfDescriptor(device);
215 rfDescriptor.layout = pl;
Corentin Wallezc6c7a422019-09-05 09:35:07 +0000216 rfDescriptor.vertexStage.module = vsModule;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000217 rfDescriptor.cFragmentStage.module = fsReflectionModule;
Kai Ninomiyaae1f25f2019-11-07 22:23:29 +0000218 rfDescriptor.vertexState = &vertexState;
Yunchao He108bcbd2019-02-15 02:20:57 +0000219 rfDescriptor.depthStencilState = &rfDescriptor.cDepthStencilState;
Corentin Wallez04863c42019-10-25 11:36:47 +0000220 rfDescriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
Corentin Wallezc81a7172019-09-20 23:22:27 +0000221 rfDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
Corentin Wallez04863c42019-10-25 11:36:47 +0000222 rfDescriptor.cDepthStencilState.stencilFront.compare = wgpu::CompareFunction::Equal;
223 rfDescriptor.cDepthStencilState.stencilBack.compare = wgpu::CompareFunction::Equal;
224 rfDescriptor.cDepthStencilState.stencilFront.passOp = wgpu::StencilOperation::Replace;
225 rfDescriptor.cDepthStencilState.stencilBack.passOp = wgpu::StencilOperation::Replace;
Yunchao Heea563332019-01-04 04:28:37 +0000226 rfDescriptor.cDepthStencilState.depthWriteEnabled = true;
Corentin Wallez04863c42019-10-25 11:36:47 +0000227 rfDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
Yan, Shaoboa4924272018-12-10 19:47:22 +0000228
229 reflectionPipeline = device.CreateRenderPipeline(&rfDescriptor);
Austin Eng376f1c62017-05-30 20:03:44 -0400230
231 cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
232}
233
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000234struct {
235 uint32_t a;
236 float b;
237} s;
Austin Eng376f1c62017-05-30 20:03:44 -0400238void frame() {
239 s.a = (s.a + 1) % 256;
Corentin Wallez83e779d2017-07-10 21:44:06 -0400240 s.b += 0.01f;
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000241 if (s.b >= 1.0f) {
242 s.b = 0.0f;
243 }
Austin Eng376f1c62017-05-30 20:03:44 -0400244
Kai Ninomiya2afea0c2020-07-10 20:33:08 +0000245 cameraData.view = glm::lookAt(glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f,
246 8.f * std::cos(glm::radians(s.b * 360.f))),
247 glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
Austin Eng376f1c62017-05-30 20:03:44 -0400248
Corentin Wallez47a33412020-06-02 09:24:39 +0000249 queue.WriteBuffer(cameraBuffer, 0, &cameraData, sizeof(CameraData));
Austin Eng376f1c62017-05-30 20:03:44 -0400250
Corentin Wallez604072b2019-11-12 18:30:11 +0000251 wgpu::TextureView backbufferView = swapchain.GetCurrentTextureView();
252 utils::ComboRenderPassDescriptor renderPass({backbufferView}, depthStencilView);
Kai Ninomiyac16a67a2017-07-27 18:30:57 -0700253
Corentin Wallez04863c42019-10-25 11:36:47 +0000254 wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
Corentin Wallez82fbccb2018-09-21 00:24:37 +0000255 {
Corentin Wallez04863c42019-10-25 11:36:47 +0000256 wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
Yan, Shaobo300eec02018-12-21 10:40:26 +0000257 pass.SetPipeline(pipeline);
Corentin Wallez70c8c102019-10-09 16:08:42 +0000258 pass.SetBindGroup(0, bindGroup[0]);
François Beaufort91b21422019-10-10 07:29:58 +0000259 pass.SetVertexBuffer(0, vertexBuffer);
Corentin Wallez5fad85b2020-11-25 08:54:14 +0000260 pass.SetIndexBuffer(indexBuffer, wgpu::IndexFormat::Uint32);
Corentin Wallez67b1ad72020-03-31 16:21:35 +0000261 pass.DrawIndexed(36);
Austin Eng376f1c62017-05-30 20:03:44 -0400262
Corentin Wallez82fbccb2018-09-21 00:24:37 +0000263 pass.SetStencilReference(0x1);
Yan, Shaobo300eec02018-12-21 10:40:26 +0000264 pass.SetPipeline(planePipeline);
Corentin Wallez70c8c102019-10-09 16:08:42 +0000265 pass.SetBindGroup(0, bindGroup[0]);
François Beaufort91b21422019-10-10 07:29:58 +0000266 pass.SetVertexBuffer(0, planeBuffer);
Corentin Wallez67b1ad72020-03-31 16:21:35 +0000267 pass.DrawIndexed(6);
Austin Eng376f1c62017-05-30 20:03:44 -0400268
Yan, Shaobo300eec02018-12-21 10:40:26 +0000269 pass.SetPipeline(reflectionPipeline);
François Beaufort91b21422019-10-10 07:29:58 +0000270 pass.SetVertexBuffer(0, vertexBuffer);
Corentin Wallez70c8c102019-10-09 16:08:42 +0000271 pass.SetBindGroup(0, bindGroup[1]);
Corentin Wallez67b1ad72020-03-31 16:21:35 +0000272 pass.DrawIndexed(36);
Austin Eng376f1c62017-05-30 20:03:44 -0400273
Corentin Wallez82fbccb2018-09-21 00:24:37 +0000274 pass.EndPass();
275 }
276
Corentin Wallez04863c42019-10-25 11:36:47 +0000277 wgpu::CommandBuffer commands = encoder.Finish();
Austin Eng376f1c62017-05-30 20:03:44 -0400278 queue.Submit(1, &commands);
Corentin Wallez604072b2019-11-12 18:30:11 +0000279 swapchain.Present();
Kai Ninomiyac16a67a2017-07-27 18:30:57 -0700280 DoFlush();
Austin Eng376f1c62017-05-30 20:03:44 -0400281}
282
283int main(int argc, const char* argv[]) {
Corentin Wallez9347e8f2017-06-19 13:15:13 -0400284 if (!InitSample(argc, argv)) {
Austin Eng376f1c62017-05-30 20:03:44 -0400285 return 1;
286 }
287 init();
288
289 while (!ShouldQuit()) {
290 frame();
Corentin Wallez134e0802017-07-17 17:13:57 -0400291 utils::USleep(16000);
Austin Eng376f1c62017-05-30 20:03:44 -0400292 }
293
294 // TODO release stuff
295}