comparison tests/test_vulkan_wrapper.nim @ 129:15d37022625c

add: input handling, small refactoring for renderer
author Sam <sam@basx.dev>
date Tue, 18 Apr 2023 03:04:37 +0700
parents 9901ec3831d1
children 11666d28e04d
comparison
equal deleted inserted replaced
128:9901ec3831d1 129:15d37022625c
103 setInstanceData[Vec3f](r, "translate", @[newVec3f(0.5, -0.3)]) 103 setInstanceData[Vec3f](r, "translate", @[newVec3f(0.5, -0.3)])
104 setInstanceData[Vec3f](t, "translate", @[newVec3f(0.3, 0.3)]) 104 setInstanceData[Vec3f](t, "translate", @[newVec3f(0.3, 0.3)])
105 setInstanceData[Vec3f](c, "translate", @[newVec3f(-0.3, 0.1)]) 105 setInstanceData[Vec3f](c, "translate", @[newVec3f(-0.3, 0.1)])
106 result = newEntity("root", t, r, c) 106 result = newEntity("root", t, r, c)
107 107
108 when isMainModule: 108 proc main() =
109 var engine = initEngine("Test") 109 var engine = initEngine("Test")
110 110
111 # INIT RENDERER: 111 # INIT RENDERER:
112 const 112 const
113 vertexInput = @[ 113 vertexInput = @[
133 main="color = vec4(outcolor, 1);" 133 main="color = vec4(outcolor, 1);"
134 ) 134 )
135 var 135 var
136 surfaceFormat = engine.gpuDevice.physicalDevice.getSurfaceFormats().filterSurfaceFormat() 136 surfaceFormat = engine.gpuDevice.physicalDevice.getSurfaceFormats().filterSurfaceFormat()
137 renderPass = engine.gpuDevice.simpleForwardRenderPass(surfaceFormat.format, vertexCode, fragmentCode, 2) 137 renderPass = engine.gpuDevice.simpleForwardRenderPass(surfaceFormat.format, vertexCode, fragmentCode, 2)
138 renderer = engine.gpuDevice.initRenderer([renderPass]) 138 engine.setRenderer([renderPass])
139 139
140 # INIT SCENE 140 # INIT SCENES
141
142 var scenes = [scene_simple(), scene_different_mesh_types(), scene_primitives()] 141 var scenes = [scene_simple(), scene_different_mesh_types(), scene_primitives()]
143 var time = initShaderGlobal("time", 0.0'f32) 142 var time = initShaderGlobal("time", 0.0'f32)
144 for scene in scenes.mitems: 143 for scene in scenes.mitems:
145 scene.components.add time 144 scene.components.add time
146 renderer.setupDrawableBuffers(scene, vertexInput) 145 engine.addScene(scene, vertexInput)
147 146
148 # MAINLOOP 147 # MAINLOOP
149 echo "Setup successfull, start rendering" 148 echo "Setup successfull, start rendering"
150 for i in 0 ..< 3: 149 for i in 0 ..< 3:
151 for scene in scenes: 150 for scene in scenes:
152 for i in 0 ..< 1000: 151 for i in 0 ..< 1000:
152 engine.updateInputs()
153 setValue[float32](time.value, get[float32](time.value) + 0.0005) 153 setValue[float32](time.value, get[float32](time.value) + 0.0005)
154 discard renderer.render(scene) 154 if not engine.running or engine.keyIsDown(Escape):
155 echo "Rendered ", renderer.framesRendered, " frames" 155 engine.destroy()
156 return
157 discard engine.renderScene(scene)
158 echo "Rendered ", engine.framesRendered, " frames"
159 echo "Processed ", engine.eventsProcessed, " events"
156 160
157 # cleanup 161 # cleanup
158 echo "Start cleanup" 162 echo "Start cleanup"
159 checkVkResult engine.gpuDevice.vk.vkDeviceWaitIdle()
160 renderer.destroy()
161 engine.destroy() 163 engine.destroy()
164
165 when isMainModule:
166 main()