Swap chains, part 2 (#94)

This commit is contained in:
Kai Ninomiya
2017-07-27 18:30:57 -07:00
committed by GitHub
parent 3818e18c5c
commit c16a67ae52
49 changed files with 771 additions and 435 deletions

View File

@@ -25,9 +25,10 @@ nxt::Buffer vertexBuffer;
nxt::Buffer instanceBuffer;
nxt::Queue queue;
nxt::SwapChain swapchain;
nxt::TextureView depthStencilView;
nxt::RenderPipeline pipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
void initBuffers() {
static const float vertexData[12] = {
@@ -50,6 +51,8 @@ void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
swapchain = GetSwapChain(device);
swapchain.Configure(nxt::TextureFormat::R8G8B8A8Unorm, 640, 480);
initBuffers();
@@ -77,7 +80,9 @@ void init() {
.SetInput(1, 2 * sizeof(float), nxt::InputStepMode::Instance)
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
renderpass = CreateDefaultRenderPass(device);
depthStencilView = CreateDefaultDepthStencilView(device);
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@@ -87,6 +92,10 @@ void init() {
}
void frame() {
nxt::Texture backbuffer;
nxt::Framebuffer framebuffer;
GetNextFramebuffer(device, renderpass, swapchain, depthStencilView, &backbuffer, &framebuffer);
static const uint32_t vertexBufferOffsets[1] = {0};
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
@@ -100,7 +109,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[]) {