Mercurial > games > semicongine
comparison tests/test_vulkan_wrapper.nim @ 574:bbeec60e25ca
did: first final implementation of scene-graph <-> pipeline connection, not working yet
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 02 Apr 2023 01:22:09 +0700 |
parents | f31a9821ae1c |
children | 056e08dfad10 |
comparison
equal
deleted
inserted
replaced
573:f31a9821ae1c | 574:bbeec60e25ca |
---|---|
56 @[], | 56 @[], |
57 @[], | 57 @[], |
58 selectedPhysicalDevice.filterForGraphicsPresentationQueues() | 58 selectedPhysicalDevice.filterForGraphicsPresentationQueues() |
59 ) | 59 ) |
60 | 60 |
61 const inputs = AttributeGroup(attributes: @[attr(name="pos", thetype=Float32, components=3)]) | 61 const inputs = AttributeGroup(attributes: @[attr(name="position", thetype=Float32, components=3)]) |
62 const uniforms = AttributeGroup() | 62 const uniforms = AttributeGroup() |
63 const outputs = AttributeGroup(attributes: @[attr(name="fragpos", thetype=Float32, components=3)]) | 63 const outputs = AttributeGroup(attributes: @[attr(name="fragpos", thetype=Float32, components=3)]) |
64 const fragOutput = AttributeGroup(attributes: @[attr(name="color", thetype=Float32, components=4)]) | 64 const fragOutput = AttributeGroup(attributes: @[attr(name="color", thetype=Float32, components=4)]) |
65 const vertexBinary = shaderCode(inputs=inputs, uniforms=uniforms, outputs=outputs, stage=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = pos;") | 65 const vertexBinary = shaderCode(inputs=inputs, uniforms=uniforms, outputs=outputs, stage=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = position;") |
66 const fragmentBinary = shaderCode(inputs=outputs, uniforms=uniforms, outputs=fragOutput, stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);") | 66 const fragmentBinary = shaderCode(inputs=outputs, uniforms=uniforms, outputs=fragOutput, stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 1);") |
67 var | 67 var |
68 vertexshader = device.createShader(inputs, uniforms, outputs, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary) | 68 vertexshader = device.createShader(inputs, uniforms, outputs, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary) |
69 fragmentshader = device.createShader(inputs, uniforms, outputs, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary) | 69 fragmentshader = device.createShader(inputs, uniforms, outputs, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary) |
70 surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat() | 70 surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat() |
71 renderPass = device.simpleForwardRenderPass(surfaceFormat.format, vertexshader, fragmentshader, 2) | 71 renderPass = device.simpleForwardRenderPass(surfaceFormat.format, vertexshader, fragmentshader, 2) |
72 var (swapchain, res) = device.createSwapchain(renderPass, surfaceFormat, device.firstGraphicsQueue().get().family, 2) | 72 var (swapchain, res) = device.createSwapchain(renderPass, surfaceFormat, device.firstGraphicsQueue().get().family, 2) |
73 if res != VK_SUCCESS: | 73 if res != VK_SUCCESS: |
74 raise newException(Exception, "Unable to create swapchain") | 74 raise newException(Exception, "Unable to create swapchain") |
75 | 75 |
76 var thescene = Scene(name: "main", root: newEntity("triangle", newMesh([newVec3(-1, -1), newVec3(0, 1), newVec3(1, -1)]))) | 76 var thescene = Scene( |
77 name: "main", | |
78 root: newEntity("root", | |
79 newEntity("triangle1", newMesh([newVec3f(-0.5, -0.5), newVec3f(0.5, 0.5), newVec3f(0.5, -0.5)])), | |
80 newEntity("triangle2", newMesh([newVec3f(-0.5, -0.5), newVec3f(0.5, -0.5), newVec3f(0.5, 0.5)])), | |
81 ) | |
82 ) | |
77 thescene.setupDrawables(renderPass) | 83 thescene.setupDrawables(renderPass) |
78 | 84 |
79 echo "Setup successfull, start rendering" | 85 echo "Setup successfull, start rendering" |
80 for i in 0 ..< 1: | 86 for i in 0 ..< 1: |
81 discard swapchain.drawScene(thescene) | 87 discard swapchain.drawScene(thescene) |
83 echo "Start cleanup" | 89 echo "Start cleanup" |
84 | 90 |
85 | 91 |
86 # cleanup | 92 # cleanup |
87 checkVkResult device.vk.vkDeviceWaitIdle() | 93 checkVkResult device.vk.vkDeviceWaitIdle() |
94 thescene.destroy() | |
88 vertexshader.destroy() | 95 vertexshader.destroy() |
89 fragmentshader.destroy() | 96 fragmentshader.destroy() |
90 renderPass.destroy() | 97 renderPass.destroy() |
91 swapchain.destroy() | 98 swapchain.destroy() |
92 device.destroy() | 99 device.destroy() |