mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 23:26:24 +00:00
Swap chains, part 2 (#94)
This commit is contained in:
@@ -19,9 +19,10 @@
|
||||
|
||||
nxt::Device device;
|
||||
nxt::Queue queue;
|
||||
nxt::SwapChain swapchain;
|
||||
nxt::TextureView depthStencilView;
|
||||
nxt::RenderPipeline pipeline;
|
||||
nxt::RenderPass renderpass;
|
||||
nxt::Framebuffer framebuffer;
|
||||
nxt::Buffer buffer;
|
||||
nxt::BindGroup bindGroup;
|
||||
|
||||
@@ -31,6 +32,8 @@ void init() {
|
||||
device = CreateCppNXTDevice();
|
||||
|
||||
queue = device.CreateQueueBuilder().GetResult();
|
||||
swapchain = GetSwapChain(device);
|
||||
swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, 640, 480);
|
||||
|
||||
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
||||
#version 450
|
||||
@@ -60,7 +63,9 @@ void init() {
|
||||
.SetBindGroupLayout(0, bgl)
|
||||
.GetResult();
|
||||
|
||||
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
|
||||
renderpass = CreateDefaultRenderPass(device);
|
||||
depthStencilView = CreateDefaultDepthStencilView(device);
|
||||
|
||||
pipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pl)
|
||||
@@ -93,6 +98,10 @@ void frame() {
|
||||
buffer.TransitionUsage(nxt::BufferUsageBit::TransferDst);
|
||||
buffer.SetSubData(0, sizeof(s) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&s));
|
||||
|
||||
nxt::Texture backbuffer;
|
||||
nxt::Framebuffer framebuffer;
|
||||
GetNextFramebuffer(device, renderpass, swapchain, depthStencilView, &backbuffer, &framebuffer);
|
||||
|
||||
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||
.BeginRenderPass(renderpass, framebuffer)
|
||||
.BeginRenderSubpass()
|
||||
@@ -105,7 +114,9 @@ void frame() {
|
||||
.GetResult();
|
||||
|
||||
queue.Submit(1, &commands);
|
||||
DoSwapBuffers();
|
||||
backbuffer.TransitionUsage(nxt::TextureUsageBit::Present);
|
||||
swapchain.Present(backbuffer);
|
||||
DoFlush();
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
Reference in New Issue
Block a user