Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 2 | // |
| 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 Wallez | 9347e8f | 2017-06-19 13:15:13 -0400 | [diff] [blame] | 15 | #include "SampleUtils.h" |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 16 | |
Corentin Wallez | f684040 | 2018-07-18 14:00:56 +0200 | [diff] [blame] | 17 | #include "utils/DawnHelpers.h" |
Corentin Wallez | 134e080 | 2017-07-17 17:13:57 -0400 | [diff] [blame] | 18 | #include "utils/SystemUtils.h" |
Corentin Wallez | 5ee7afd | 2017-06-19 13:09:41 -0400 | [diff] [blame] | 19 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 20 | #include <array> |
| 21 | #include <cstring> |
| 22 | #include <random> |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 23 | |
| 24 | #include <glm/glm.hpp> |
| 25 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 26 | dawn::Device device; |
| 27 | dawn::Queue queue; |
| 28 | dawn::SwapChain swapchain; |
| 29 | dawn::TextureView depthStencilView; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 30 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 31 | dawn::Buffer modelBuffer; |
| 32 | std::array<dawn::Buffer, 2> particleBuffers; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 33 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 34 | dawn::RenderPipeline renderPipeline; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 35 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 36 | dawn::Buffer updateParams; |
| 37 | dawn::ComputePipeline updatePipeline; |
| 38 | std::array<dawn::BindGroup, 2> updateBGs; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 39 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 40 | size_t pingpong = 0; |
| 41 | |
| 42 | static const uint32_t kNumParticles = 1000; |
| 43 | |
| 44 | struct Particle { |
| 45 | glm::vec2 pos; |
| 46 | glm::vec2 vel; |
| 47 | }; |
| 48 | |
| 49 | struct SimParams { |
| 50 | float deltaT; |
| 51 | float rule1Distance; |
| 52 | float rule2Distance; |
| 53 | float rule3Distance; |
| 54 | float rule1Scale; |
| 55 | float rule2Scale; |
| 56 | float rule3Scale; |
| 57 | int particleCount; |
| 58 | }; |
| 59 | |
| 60 | void initBuffers() { |
| 61 | glm::vec2 model[3] = { |
| 62 | {-0.01, -0.02}, |
| 63 | {0.01, -0.02}, |
| 64 | {0.00, 0.02}, |
| 65 | }; |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 66 | modelBuffer = utils::CreateBufferFromData(device, model, sizeof(model), dawn::BufferUsageBit::Vertex); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 67 | |
Corentin Wallez | 83e779d | 2017-07-10 21:44:06 -0400 | [diff] [blame] | 68 | SimParams params = { 0.04f, 0.1f, 0.025f, 0.025f, 0.02f, 0.05f, 0.005f, kNumParticles }; |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 69 | updateParams = utils::CreateBufferFromData(device, ¶ms, sizeof(params), dawn::BufferUsageBit::Uniform); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 70 | |
| 71 | std::vector<Particle> initialParticles(kNumParticles); |
| 72 | { |
| 73 | std::mt19937 generator; |
| 74 | std::uniform_real_distribution<float> dist(-1.0f, 1.0f); |
| 75 | for (auto& p : initialParticles) |
| 76 | { |
| 77 | p.pos = glm::vec2(dist(generator), dist(generator)); |
| 78 | p.vel = glm::vec2(dist(generator), dist(generator)) * 0.1f; |
| 79 | } |
| 80 | } |
| 81 | |
Kai Ninomiya | 78c8b83 | 2017-07-21 17:00:22 -0700 | [diff] [blame] | 82 | for (size_t i = 0; i < 2; i++) { |
Corentin Wallez | 82b6573 | 2018-08-22 15:37:29 +0200 | [diff] [blame] | 83 | dawn::BufferDescriptor descriptor; |
| 84 | descriptor.size = sizeof(Particle) * kNumParticles; |
| 85 | descriptor.usage = dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Storage; |
| 86 | particleBuffers[i] = device.CreateBuffer(&descriptor); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 87 | |
| 88 | particleBuffers[i].SetSubData(0, |
Stephen White | e5ae327 | 2018-02-04 11:07:02 -0500 | [diff] [blame] | 89 | sizeof(Particle) * kNumParticles, |
| 90 | reinterpret_cast<uint8_t*>(initialParticles.data())); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | void initRender() { |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 95 | dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"( |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 96 | #version 450 |
| 97 | layout(location = 0) in vec2 a_particlePos; |
| 98 | layout(location = 1) in vec2 a_particleVel; |
| 99 | layout(location = 2) in vec2 a_pos; |
| 100 | void main() { |
| 101 | float angle = -atan(a_particleVel.x, a_particleVel.y); |
| 102 | vec2 pos = vec2(a_pos.x * cos(angle) - a_pos.y * sin(angle), |
| 103 | a_pos.x * sin(angle) + a_pos.y * cos(angle)); |
| 104 | gl_Position = vec4(pos + a_particlePos, 0, 1); |
| 105 | } |
| 106 | )"); |
| 107 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 108 | dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"( |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 109 | #version 450 |
Corentin Wallez | b6fb5f3 | 2017-08-29 13:37:45 -0400 | [diff] [blame] | 110 | layout(location = 0) out vec4 fragColor; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 111 | void main() { |
| 112 | fragColor = vec4(1.0); |
| 113 | } |
| 114 | )"); |
| 115 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 116 | dawn::InputState inputState = device.CreateInputStateBuilder() |
| 117 | .SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, pos)) |
| 118 | .SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, vel)) |
| 119 | .SetInput(0, sizeof(Particle), dawn::InputStepMode::Instance) |
| 120 | .SetAttribute(2, 1, dawn::VertexFormat::FloatR32G32, 0) |
| 121 | .SetInput(1, sizeof(glm::vec2), dawn::InputStepMode::Vertex) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 122 | .GetResult(); |
| 123 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 124 | depthStencilView = CreateDefaultDepthStencilView(device); |
| 125 | |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 126 | renderPipeline = device.CreateRenderPipelineBuilder() |
Corentin Wallez | 6f7749c | 2018-05-02 18:10:13 -0400 | [diff] [blame] | 127 | .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 128 | .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint) |
| 129 | .SetStage(dawn::ShaderStage::Vertex, vsModule, "main") |
| 130 | .SetStage(dawn::ShaderStage::Fragment, fsModule, "main") |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 131 | .SetInputState(inputState) |
| 132 | .GetResult(); |
| 133 | } |
| 134 | |
| 135 | void initSim() { |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 136 | dawn::ShaderModule module = utils::CreateShaderModule(device, dawn::ShaderStage::Compute, R"( |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 137 | #version 450 |
| 138 | |
| 139 | struct Particle { |
| 140 | vec2 pos; |
| 141 | vec2 vel; |
| 142 | }; |
| 143 | |
| 144 | layout(std140, set = 0, binding = 0) uniform SimParams { |
| 145 | float deltaT; |
| 146 | float rule1Distance; |
| 147 | float rule2Distance; |
| 148 | float rule3Distance; |
| 149 | float rule1Scale; |
| 150 | float rule2Scale; |
| 151 | float rule3Scale; |
| 152 | int particleCount; |
| 153 | } params; |
| 154 | |
| 155 | layout(std140, set = 0, binding = 1) buffer ParticlesA { |
Kai Ninomiya | 7883e7e | 2018-07-10 11:01:28 -0700 | [diff] [blame] | 156 | Particle particles[1000]; |
| 157 | } particlesA; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 158 | |
| 159 | layout(std140, set = 0, binding = 2) buffer ParticlesB { |
Kai Ninomiya | 7883e7e | 2018-07-10 11:01:28 -0700 | [diff] [blame] | 160 | Particle particles[1000]; |
| 161 | } particlesB; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 162 | |
| 163 | void main() { |
| 164 | // https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp |
| 165 | |
| 166 | uint index = gl_GlobalInvocationID.x; |
| 167 | if (index >= params.particleCount) { return; } |
| 168 | |
Kai Ninomiya | 7883e7e | 2018-07-10 11:01:28 -0700 | [diff] [blame] | 169 | vec2 vPos = particlesA.particles[index].pos; |
| 170 | vec2 vVel = particlesA.particles[index].vel; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 171 | |
| 172 | vec2 cMass = vec2(0.0, 0.0); |
| 173 | vec2 cVel = vec2(0.0, 0.0); |
| 174 | vec2 colVel = vec2(0.0, 0.0); |
| 175 | int cMassCount = 0; |
| 176 | int cVelCount = 0; |
| 177 | |
| 178 | vec2 pos; |
| 179 | vec2 vel; |
| 180 | for (int i = 0; i < params.particleCount; ++i) { |
| 181 | if (i == index) { continue; } |
Kai Ninomiya | 7883e7e | 2018-07-10 11:01:28 -0700 | [diff] [blame] | 182 | pos = particlesA.particles[i].pos.xy; |
| 183 | vel = particlesA.particles[i].vel.xy; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 184 | |
| 185 | if (distance(pos, vPos) < params.rule1Distance) { |
| 186 | cMass += pos; |
| 187 | cMassCount++; |
| 188 | } |
| 189 | if (distance(pos, vPos) < params.rule2Distance) { |
| 190 | colVel -= (pos - vPos); |
| 191 | } |
| 192 | if (distance(pos, vPos) < params.rule3Distance) { |
| 193 | cVel += vel; |
| 194 | cVelCount++; |
| 195 | } |
| 196 | } |
| 197 | if (cMassCount > 0) { |
| 198 | cMass = cMass / cMassCount - vPos; |
| 199 | } |
| 200 | if (cVelCount > 0) { |
| 201 | cVel = cVel / cVelCount; |
| 202 | } |
| 203 | |
| 204 | vVel += cMass * params.rule1Scale + colVel * params.rule2Scale + cVel * params.rule3Scale; |
| 205 | |
| 206 | // clamp velocity for a more pleasing simulation. |
| 207 | vVel = normalize(vVel) * clamp(length(vVel), 0.0, 0.1); |
| 208 | |
| 209 | // kinematic update |
| 210 | vPos += vVel * params.deltaT; |
| 211 | |
| 212 | // Wrap around boundary |
| 213 | if (vPos.x < -1.0) vPos.x = 1.0; |
| 214 | if (vPos.x > 1.0) vPos.x = -1.0; |
| 215 | if (vPos.y < -1.0) vPos.y = 1.0; |
| 216 | if (vPos.y > 1.0) vPos.y = -1.0; |
| 217 | |
Kai Ninomiya | 7883e7e | 2018-07-10 11:01:28 -0700 | [diff] [blame] | 218 | particlesB.particles[index].pos = vPos; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 219 | |
| 220 | // Write back |
Kai Ninomiya | 7883e7e | 2018-07-10 11:01:28 -0700 | [diff] [blame] | 221 | particlesB.particles[index].vel = vVel; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 222 | } |
| 223 | )"); |
| 224 | |
Kai Ninomiya | 234becf | 2018-07-10 12:23:50 -0700 | [diff] [blame] | 225 | auto bgl = utils::MakeBindGroupLayout( |
| 226 | device, { |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 227 | {0, dawn::ShaderStageBit::Compute, dawn::BindingType::UniformBuffer}, |
| 228 | {1, dawn::ShaderStageBit::Compute, dawn::BindingType::StorageBuffer}, |
| 229 | {2, dawn::ShaderStageBit::Compute, dawn::BindingType::StorageBuffer}, |
Kai Ninomiya | 234becf | 2018-07-10 12:23:50 -0700 | [diff] [blame] | 230 | }); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 231 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 232 | dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 233 | |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame^] | 234 | dawn::ComputePipelineDescriptor csDesc; |
| 235 | csDesc.module = module.Clone(); |
| 236 | csDesc.entryPoint = "main"; |
| 237 | csDesc.layout = pl.Clone(); |
| 238 | updatePipeline = device.CreateComputePipeline(&csDesc); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 239 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 240 | dawn::BufferView updateParamsView = updateParams.CreateBufferViewBuilder() |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 241 | .SetExtent(0, sizeof(SimParams)) |
| 242 | .GetResult(); |
| 243 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 244 | std::array<dawn::BufferView, 2> views; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 245 | for (uint32_t i = 0; i < 2; ++i) { |
| 246 | views[i] = particleBuffers[i].CreateBufferViewBuilder() |
| 247 | .SetExtent(0, kNumParticles * sizeof(Particle)) |
| 248 | .GetResult(); |
| 249 | } |
| 250 | |
| 251 | for (uint32_t i = 0; i < 2; ++i) { |
| 252 | updateBGs[i] = device.CreateBindGroupBuilder() |
| 253 | .SetLayout(bgl) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 254 | .SetBufferViews(0, 1, &updateParamsView) |
| 255 | .SetBufferViews(1, 1, &views[i]) |
| 256 | .SetBufferViews(2, 1, &views[(i + 1) % 2]) |
| 257 | .GetResult(); |
| 258 | } |
| 259 | } |
| 260 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 261 | dawn::CommandBuffer createCommandBuffer(const dawn::RenderPassDescriptor& renderPass, size_t i) { |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 262 | static const uint32_t zeroOffsets[1] = {0}; |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 263 | auto& bufferDst = particleBuffers[(i + 1) % 2]; |
| 264 | return device.CreateCommandBufferBuilder() |
| 265 | .BeginComputePass() |
| 266 | .SetComputePipeline(updatePipeline) |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 267 | .SetBindGroup(0, updateBGs[i]) |
| 268 | .Dispatch(kNumParticles, 1, 1) |
| 269 | .EndComputePass() |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 270 | |
Corentin Wallez | 6f7749c | 2018-05-02 18:10:13 -0400 | [diff] [blame] | 271 | .BeginRenderPass(renderPass) |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 272 | .SetRenderPipeline(renderPipeline) |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 273 | .SetVertexBuffers(0, 1, &bufferDst, zeroOffsets) |
| 274 | .SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets) |
| 275 | .DrawArrays(3, kNumParticles, 0, 0) |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 276 | .EndRenderPass() |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 277 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 278 | .GetResult(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void init() { |
Corentin Wallez | 39039fa | 2018-07-18 14:06:10 +0200 | [diff] [blame] | 282 | device = CreateCppDawnDevice(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 283 | |
Corentin Wallez | b703def | 2018-06-14 20:26:27 -0400 | [diff] [blame] | 284 | queue = device.CreateQueue(); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 285 | swapchain = GetSwapChain(device); |
Corentin Wallez | 2e31e8f | 2017-09-21 12:54:53 -0400 | [diff] [blame] | 286 | swapchain.Configure(GetPreferredSwapChainTextureFormat(), |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 287 | dawn::TextureUsageBit::OutputAttachment, 640, 480); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 288 | |
| 289 | initBuffers(); |
| 290 | initRender(); |
| 291 | initSim(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void frame() { |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 295 | dawn::Texture backbuffer; |
| 296 | dawn::RenderPassDescriptor renderPass; |
Corentin Wallez | 8d6b5d2 | 2018-05-11 13:04:44 -0400 | [diff] [blame] | 297 | GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 298 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 299 | dawn::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 300 | queue.Submit(1, &commandBuffer); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 301 | swapchain.Present(backbuffer); |
| 302 | DoFlush(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 303 | |
| 304 | pingpong = (pingpong + 1) % 2; |
| 305 | } |
| 306 | |
| 307 | int main(int argc, const char* argv[]) { |
Corentin Wallez | 9347e8f | 2017-06-19 13:15:13 -0400 | [diff] [blame] | 308 | if (!InitSample(argc, argv)) { |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 309 | return 1; |
| 310 | } |
| 311 | init(); |
| 312 | |
| 313 | while (!ShouldQuit()) { |
| 314 | frame(); |
Corentin Wallez | 134e080 | 2017-07-17 17:13:57 -0400 | [diff] [blame] | 315 | utils::USleep(16000); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | // TODO release stuff |
| 319 | } |