-
Notifications
You must be signed in to change notification settings - Fork 2
/
02-triangle.cpp
63 lines (56 loc) · 1.77 KB
/
02-triangle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "../framework/vulkanApp.h"
class TriangleApp : public VulkanApp
{
std::shared_ptr<magma::GraphicsPipeline> graphicsPipeline;
public:
TriangleApp(const AppEntry& entry):
VulkanApp(entry, TEXT("02 - Triangle"), 512, 512)
{
initialize();
setupPipeline();
recordCommandBuffer(Buffer::Front);
recordCommandBuffer(Buffer::Back);
}
void render(uint32_t bufferIndex) override
{
submitCommandBuffer(bufferIndex);
}
void createLogicalDevice() override
{
device = physicalDevice->createDefaultDevice();
}
void setupPipeline()
{
graphicsPipeline = std::make_shared<GraphicsPipeline>(device,
"position", "fill",
magma::renderstate::nullVertexInput,
magma::renderstate::triangleList,
magma::renderstate::fillCullBackCcw,
magma::renderstate::dontMultisample,
magma::renderstate::depthAlwaysDontWrite,
magma::renderstate::dontBlendRgb,
nullptr,
renderPass, 0,
pipelineCache);
}
void recordCommandBuffer(uint32_t index)
{
auto& cmdBuffer = commandBuffers[index];
cmdBuffer->begin();
{
cmdBuffer->beginRenderPass(renderPass, framebuffers[index], {magma::clear::gray});
{
cmdBuffer->setViewport(0, 0, width, height);
cmdBuffer->setScissor(0, 0, width, height);
cmdBuffer->bindPipeline(graphicsPipeline);
cmdBuffer->draw(3, 0);
}
cmdBuffer->endRenderPass();
}
cmdBuffer->end();
}
};
std::unique_ptr<IApplication> appFactory(const AppEntry& entry)
{
return std::unique_ptr<TriangleApp>(new TriangleApp(entry));
}