Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -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" |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 16 | |
Corentin Wallez | 5ee7afd | 2017-06-19 13:09:41 -0400 | [diff] [blame] | 17 | #include "utils/NXTHelpers.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 | |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 20 | #include <vector> |
| 21 | #include <glm/glm/glm.hpp> |
| 22 | #include <glm/glm/gtc/matrix_transform.hpp> |
| 23 | #include <glm/glm/gtc/type_ptr.hpp> |
| 24 | |
| 25 | nxt::Device device; |
| 26 | |
| 27 | nxt::Buffer indexBuffer; |
| 28 | nxt::Buffer vertexBuffer; |
| 29 | nxt::Buffer planeBuffer; |
| 30 | nxt::Buffer cameraBuffer; |
| 31 | nxt::Buffer transformBuffer[2]; |
| 32 | |
| 33 | nxt::BindGroup cameraBindGroup; |
| 34 | nxt::BindGroup bindGroup[2]; |
| 35 | nxt::BindGroup cubeTransformBindGroup[2]; |
| 36 | |
| 37 | nxt::Queue queue; |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 38 | nxt::SwapChain swapchain; |
| 39 | nxt::TextureView depthStencilView; |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 40 | nxt::RenderPipeline pipeline; |
| 41 | nxt::RenderPipeline planePipeline; |
| 42 | nxt::RenderPipeline reflectionPipeline; |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 43 | |
| 44 | void initBuffers() { |
| 45 | static const uint32_t indexData[6*6] = { |
| 46 | 0, 1, 2, |
| 47 | 0, 2, 3, |
| 48 | |
| 49 | 4, 5, 6, |
| 50 | 4, 6, 7, |
| 51 | |
| 52 | 8, 9, 10, |
| 53 | 8, 10, 11, |
| 54 | |
| 55 | 12, 13, 14, |
| 56 | 12, 14, 15, |
| 57 | |
| 58 | 16, 17, 18, |
| 59 | 16, 18, 19, |
| 60 | |
| 61 | 20, 21, 22, |
| 62 | 20, 22, 23 |
| 63 | }; |
Corentin Wallez | d8c068f | 2018-07-09 15:15:07 +0200 | [diff] [blame] | 64 | indexBuffer = utils::CreateBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 65 | |
| 66 | static const float vertexData[6 * 4 * 6] = { |
| 67 | -1.0, -1.0, 1.0, 1.0, 0.0, 0.0, |
| 68 | 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, |
| 69 | 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, |
| 70 | -1.0, 1.0, 1.0, 1.0, 0.0, 0.0, |
| 71 | |
| 72 | -1.0, -1.0, -1.0, 1.0, 1.0, 0.0, |
| 73 | -1.0, 1.0, -1.0, 1.0, 1.0, 0.0, |
| 74 | 1.0, 1.0, -1.0, 1.0, 1.0, 0.0, |
| 75 | 1.0, -1.0, -1.0, 1.0, 1.0, 0.0, |
| 76 | |
| 77 | -1.0, 1.0, -1.0, 1.0, 0.0, 1.0, |
| 78 | -1.0, 1.0, 1.0, 1.0, 0.0, 1.0, |
| 79 | 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, |
| 80 | 1.0, 1.0, -1.0, 1.0, 0.0, 1.0, |
| 81 | |
| 82 | -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, |
| 83 | 1.0, -1.0, -1.0, 0.0, 1.0, 0.0, |
| 84 | 1.0, -1.0, 1.0, 0.0, 1.0, 0.0, |
| 85 | -1.0, -1.0, 1.0, 0.0, 1.0, 0.0, |
| 86 | |
| 87 | 1.0, -1.0, -1.0, 0.0, 1.0, 1.0, |
| 88 | 1.0, 1.0, -1.0, 0.0, 1.0, 1.0, |
| 89 | 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, |
| 90 | 1.0, -1.0, 1.0, 0.0, 1.0, 1.0, |
| 91 | |
| 92 | -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, |
| 93 | -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, |
| 94 | -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, |
| 95 | -1.0, 1.0, -1.0, 1.0, 1.0, 1.0 |
| 96 | }; |
Corentin Wallez | d8c068f | 2018-07-09 15:15:07 +0200 | [diff] [blame] | 97 | vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 98 | |
| 99 | static const float planeData[6 * 4] = { |
| 100 | -2.0, -1.0, -2.0, 0.5, 0.5, 0.5, |
| 101 | 2.0, -1.0, -2.0, 0.5, 0.5, 0.5, |
| 102 | 2.0, -1.0, 2.0, 0.5, 0.5, 0.5, |
| 103 | -2.0, -1.0, 2.0, 0.5, 0.5, 0.5, |
| 104 | }; |
Corentin Wallez | d8c068f | 2018-07-09 15:15:07 +0200 | [diff] [blame] | 105 | planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Austin Eng | 58c76b3 | 2017-06-02 14:31:53 -0400 | [diff] [blame] | 108 | struct CameraData { |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 109 | glm::mat4 view; |
| 110 | glm::mat4 proj; |
| 111 | } cameraData; |
| 112 | |
| 113 | void init() { |
| 114 | device = CreateCppNXTDevice(); |
| 115 | |
Corentin Wallez | b703def | 2018-06-14 20:26:27 -0400 | [diff] [blame] | 116 | queue = device.CreateQueue(); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 117 | swapchain = GetSwapChain(device); |
Corentin Wallez | 2e31e8f | 2017-09-21 12:54:53 -0400 | [diff] [blame] | 118 | swapchain.Configure(GetPreferredSwapChainTextureFormat(), |
| 119 | nxt::TextureUsageBit::OutputAttachment, 640, 480); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 120 | |
| 121 | initBuffers(); |
| 122 | |
Corentin Wallez | 5ee7afd | 2017-06-19 13:09:41 -0400 | [diff] [blame] | 123 | nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 124 | #version 450 |
| 125 | layout(set = 0, binding = 0) uniform cameraData { |
| 126 | mat4 view; |
| 127 | mat4 proj; |
| 128 | } camera; |
| 129 | layout(set = 0, binding = 1) uniform modelData { |
| 130 | mat4 modelMatrix; |
| 131 | }; |
| 132 | layout(location = 0) in vec3 pos; |
| 133 | layout(location = 1) in vec3 col; |
| 134 | layout(location = 2) out vec3 f_col; |
| 135 | void main() { |
| 136 | f_col = col; |
| 137 | gl_Position = camera.proj * camera.view * modelMatrix * vec4(pos, 1.0); |
| 138 | })" |
| 139 | ); |
| 140 | |
Corentin Wallez | 5ee7afd | 2017-06-19 13:09:41 -0400 | [diff] [blame] | 141 | nxt::ShaderModule fsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 142 | #version 450 |
| 143 | layout(location = 2) in vec3 f_col; |
Corentin Wallez | b6fb5f3 | 2017-08-29 13:37:45 -0400 | [diff] [blame] | 144 | layout(location = 0) out vec4 fragColor; |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 145 | void main() { |
| 146 | fragColor = vec4(f_col, 1.0); |
Corentin Wallez | b6fb5f3 | 2017-08-29 13:37:45 -0400 | [diff] [blame] | 147 | })"); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 148 | |
Corentin Wallez | b6fb5f3 | 2017-08-29 13:37:45 -0400 | [diff] [blame] | 149 | nxt::ShaderModule fsReflectionModule = |
| 150 | utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 151 | #version 450 |
| 152 | layout(location = 2) in vec3 f_col; |
Corentin Wallez | b6fb5f3 | 2017-08-29 13:37:45 -0400 | [diff] [blame] | 153 | layout(location = 0) out vec4 fragColor; |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 154 | void main() { |
| 155 | fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0); |
Corentin Wallez | b6fb5f3 | 2017-08-29 13:37:45 -0400 | [diff] [blame] | 156 | })"); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 157 | |
| 158 | auto inputState = device.CreateInputStateBuilder() |
| 159 | .SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32, 0) |
| 160 | .SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32B32, 3 * sizeof(float)) |
| 161 | .SetInput(0, 6 * sizeof(float), nxt::InputStepMode::Vertex) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 162 | .GetResult(); |
| 163 | |
Kai Ninomiya | 234becf | 2018-07-10 12:23:50 -0700 | [diff] [blame] | 164 | auto bgl = utils::MakeBindGroupLayout( |
| 165 | device, { |
| 166 | {0, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer}, |
| 167 | {1, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer}, |
| 168 | }); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 169 | |
Kai Ninomiya | f53f98b | 2018-06-27 16:21:39 -0700 | [diff] [blame] | 170 | nxt::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 171 | |
| 172 | cameraBuffer = device.CreateBufferBuilder() |
Austin Eng | 39c901d | 2017-06-12 17:33:44 -0400 | [diff] [blame] | 173 | .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform) |
Austin Eng | 58c76b3 | 2017-06-02 14:31:53 -0400 | [diff] [blame] | 174 | .SetSize(sizeof(CameraData)) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 175 | .GetResult(); |
| 176 | |
| 177 | glm::mat4 transform(1.0); |
Corentin Wallez | d8c068f | 2018-07-09 15:15:07 +0200 | [diff] [blame] | 178 | transformBuffer[0] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 179 | |
| 180 | transform = glm::translate(transform, glm::vec3(0.f, -2.f, 0.f)); |
Corentin Wallez | d8c068f | 2018-07-09 15:15:07 +0200 | [diff] [blame] | 181 | transformBuffer[1] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 182 | |
| 183 | nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder() |
Austin Eng | 58c76b3 | 2017-06-02 14:31:53 -0400 | [diff] [blame] | 184 | .SetExtent(0, sizeof(CameraData)) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 185 | .GetResult(); |
| 186 | |
| 187 | nxt::BufferView transformBufferView[2] = { |
| 188 | transformBuffer[0].CreateBufferViewBuilder() |
| 189 | .SetExtent(0, sizeof(glm::mat4)) |
| 190 | .GetResult(), |
| 191 | transformBuffer[1].CreateBufferViewBuilder() |
| 192 | .SetExtent(0, sizeof(glm::mat4)) |
| 193 | .GetResult(), |
| 194 | }; |
| 195 | |
| 196 | bindGroup[0] = device.CreateBindGroupBuilder() |
| 197 | .SetLayout(bgl) |
| 198 | .SetUsage(nxt::BindGroupUsage::Frozen) |
| 199 | .SetBufferViews(0, 1, &cameraBufferView) |
| 200 | .SetBufferViews(1, 1, &transformBufferView[0]) |
| 201 | .GetResult(); |
| 202 | |
| 203 | bindGroup[1] = device.CreateBindGroupBuilder() |
| 204 | .SetLayout(bgl) |
| 205 | .SetUsage(nxt::BindGroupUsage::Frozen) |
| 206 | .SetBufferViews(0, 1, &cameraBufferView) |
| 207 | .SetBufferViews(1, 1, &transformBufferView[1]) |
| 208 | .GetResult(); |
| 209 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 210 | depthStencilView = CreateDefaultDepthStencilView(device); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 211 | |
| 212 | auto depthStencilState = device.CreateDepthStencilStateBuilder() |
Austin Eng | 1063439 | 2017-06-01 11:30:03 -0400 | [diff] [blame] | 213 | .SetDepthCompareFunction(nxt::CompareFunction::Less) |
| 214 | .SetDepthWriteEnabled(true) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 215 | .GetResult(); |
| 216 | |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 217 | pipeline = device.CreateRenderPipelineBuilder() |
Corentin Wallez | 6f7749c | 2018-05-02 18:10:13 -0400 | [diff] [blame] | 218 | .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) |
| 219 | .SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 220 | .SetLayout(pl) |
| 221 | .SetStage(nxt::ShaderStage::Vertex, vsModule, "main") |
| 222 | .SetStage(nxt::ShaderStage::Fragment, fsModule, "main") |
Corentin Wallez | 405dcd6 | 2017-09-19 13:38:05 -0400 | [diff] [blame] | 223 | .SetIndexFormat(nxt::IndexFormat::Uint32) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 224 | .SetInputState(inputState) |
| 225 | .SetDepthStencilState(depthStencilState) |
| 226 | .GetResult(); |
| 227 | |
| 228 | auto planeStencilState = device.CreateDepthStencilStateBuilder() |
Austin Eng | 1063439 | 2017-06-01 11:30:03 -0400 | [diff] [blame] | 229 | .SetDepthCompareFunction(nxt::CompareFunction::Less) |
| 230 | .SetDepthWriteEnabled(false) |
| 231 | .SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Always, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 232 | .GetResult(); |
| 233 | |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 234 | planePipeline = device.CreateRenderPipelineBuilder() |
Corentin Wallez | 6f7749c | 2018-05-02 18:10:13 -0400 | [diff] [blame] | 235 | .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) |
| 236 | .SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 237 | .SetLayout(pl) |
| 238 | .SetStage(nxt::ShaderStage::Vertex, vsModule, "main") |
| 239 | .SetStage(nxt::ShaderStage::Fragment, fsModule, "main") |
| 240 | .SetInputState(inputState) |
| 241 | .SetDepthStencilState(planeStencilState) |
| 242 | .GetResult(); |
| 243 | |
| 244 | auto reflectionStencilState = device.CreateDepthStencilStateBuilder() |
Austin Eng | 1063439 | 2017-06-01 11:30:03 -0400 | [diff] [blame] | 245 | .SetDepthCompareFunction(nxt::CompareFunction::Less) |
| 246 | .SetDepthWriteEnabled(true) |
| 247 | .SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Equal, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 248 | .GetResult(); |
| 249 | |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 250 | reflectionPipeline = device.CreateRenderPipelineBuilder() |
Corentin Wallez | 6f7749c | 2018-05-02 18:10:13 -0400 | [diff] [blame] | 251 | .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) |
| 252 | .SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 253 | .SetLayout(pl) |
| 254 | .SetStage(nxt::ShaderStage::Vertex, vsModule, "main") |
| 255 | .SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main") |
| 256 | .SetInputState(inputState) |
| 257 | .SetDepthStencilState(reflectionStencilState) |
| 258 | .GetResult(); |
| 259 | |
| 260 | cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f); |
| 261 | } |
| 262 | |
| 263 | struct {uint32_t a; float b;} s; |
| 264 | void frame() { |
| 265 | s.a = (s.a + 1) % 256; |
Corentin Wallez | 83e779d | 2017-07-10 21:44:06 -0400 | [diff] [blame] | 266 | s.b += 0.01f; |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 267 | if (s.b >= 1.0f) {s.b = 0.0f;} |
| 268 | static const uint32_t vertexBufferOffsets[1] = {0}; |
| 269 | |
| 270 | cameraData.view = glm::lookAt( |
| 271 | glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f, 8.f * std::cos(glm::radians(s.b * 360.f))), |
| 272 | glm::vec3(0.0f, 0.0f, 0.0f), |
Corentin Wallez | 804fc74 | 2018-07-03 14:43:46 +0200 | [diff] [blame] | 273 | glm::vec3(0.0f, -1.0f, 0.0f) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 274 | ); |
| 275 | |
Stephen White | e5ae327 | 2018-02-04 11:07:02 -0500 | [diff] [blame] | 276 | cameraBuffer.SetSubData(0, sizeof(CameraData), reinterpret_cast<uint8_t*>(&cameraData)); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 277 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 278 | nxt::Texture backbuffer; |
Corentin Wallez | 8d6b5d2 | 2018-05-11 13:04:44 -0400 | [diff] [blame] | 279 | nxt::RenderPassDescriptor renderPass; |
| 280 | GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 281 | |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 282 | nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() |
Corentin Wallez | 6f7749c | 2018-05-02 18:10:13 -0400 | [diff] [blame] | 283 | .BeginRenderPass(renderPass) |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 284 | .SetRenderPipeline(pipeline) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 285 | .SetBindGroup(0, bindGroup[0]) |
| 286 | .SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets) |
Corentin Wallez | 405dcd6 | 2017-09-19 13:38:05 -0400 | [diff] [blame] | 287 | .SetIndexBuffer(indexBuffer, 0) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 288 | .DrawElements(36, 1, 0, 0) |
| 289 | |
Austin Eng | 1063439 | 2017-06-01 11:30:03 -0400 | [diff] [blame] | 290 | .SetStencilReference(0x1) |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 291 | .SetRenderPipeline(planePipeline) |
Austin Eng | 0c50889 | 2017-07-21 18:36:13 -0400 | [diff] [blame] | 292 | .SetBindGroup(0, bindGroup[0]) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 293 | .SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets) |
| 294 | .DrawElements(6, 1, 0, 0) |
| 295 | |
Corentin Wallez | 66ff447 | 2017-07-14 11:32:57 -0400 | [diff] [blame] | 296 | .SetRenderPipeline(reflectionPipeline) |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 297 | .SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets) |
| 298 | .SetBindGroup(0, bindGroup[1]) |
| 299 | .DrawElements(36, 1, 0, 0) |
| 300 | .EndRenderPass() |
| 301 | .GetResult(); |
| 302 | |
| 303 | queue.Submit(1, &commands); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 304 | swapchain.Present(backbuffer); |
| 305 | DoFlush(); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | int main(int argc, const char* argv[]) { |
Corentin Wallez | 9347e8f | 2017-06-19 13:15:13 -0400 | [diff] [blame] | 309 | if (!InitSample(argc, argv)) { |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 310 | return 1; |
| 311 | } |
| 312 | init(); |
| 313 | |
| 314 | while (!ShouldQuit()) { |
| 315 | frame(); |
Corentin Wallez | 134e080 | 2017-07-17 17:13:57 -0400 | [diff] [blame] | 316 | utils::USleep(16000); |
Austin Eng | 376f1c6 | 2017-05-30 20:03:44 -0400 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // TODO release stuff |
| 320 | } |