Mercurial > games > semicongine
comparison test1.nim @ 1199:ba1af13233ee compiletime-tests
add: working main-renderloop
author | sam <sam@basx.dev> |
---|---|
date | Sat, 13 Jul 2024 23:27:12 +0700 |
parents | 96a094cd0c78 |
children | 5c6491f28dcd |
comparison
equal
deleted
inserted
replaced
1198:96a094cd0c78 | 1199:ba1af13233ee |
---|---|
1 import std/os | 1 import std/os |
2 import std/monotimes | |
3 import std/times | |
2 import std/options | 4 import std/options |
3 | 5 |
4 import semicongine | 6 import semicongine |
5 | 7 |
6 type | 8 type |
71 fontAtlas: Texture[TVec4[uint8]](width: 1, height: 1, data: @[TVec4[uint8]([0'u8, 0'u8, 0'u8, 1'u8])]), | 73 fontAtlas: Texture[TVec4[uint8]](width: 1, height: 1, data: @[TVec4[uint8]([0'u8, 0'u8, 0'u8, 1'u8])]), |
72 settings: GPUValue[ShaderSettings, UniformBuffer](data: ShaderSettings(gamma: 1.0)) | 74 settings: GPUValue[ShaderSettings, UniformBuffer](data: ShaderSettings(gamma: 1.0)) |
73 ) | 75 ) |
74 ) | 76 ) |
75 | 77 |
76 let renderpass = CreatePresentationRenderPass() | 78 let mainRenderpass = CreatePresentationRenderPass() |
77 var swapchainResult = InitSwapchain(renderpass = renderpass) | 79 var swapchainResult = InitSwapchain(renderpass = mainRenderpass) |
80 | |
78 assert swapchainResult.isSome() | 81 assert swapchainResult.isSome() |
79 var swapchain = swapchainResult.get() | 82 var swapchain = swapchainResult.get() |
80 | 83 |
81 # shaders | 84 # shaders |
82 var pipeline1 = CreatePipeline[ShaderA](renderPass = renderpass) | 85 var pipeline1 = CreatePipeline[ShaderA](renderPass = mainRenderpass) |
83 | 86 |
84 var renderdata = InitRenderData() | 87 var renderdata = InitRenderData() |
85 | 88 |
86 # buffer assignment | 89 # buffer assignment |
87 echo "Assigning buffers to GPUData fields" | 90 echo "Assigning buffers to GPUData fields" |
107 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(GlobalSet), myGlobals) | 110 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(GlobalSet), myGlobals) |
108 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(MaterialSet), uniforms1) | 111 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(MaterialSet), uniforms1) |
109 | 112 |
110 | 113 |
111 # start command buffer | 114 # start command buffer |
112 while true: | 115 var t = getMonoTime() |
113 RecordRenderingCommands(swapchain, framebuffer, commandbuffer): | 116 while UpdateInputs(): |
114 var | 117 WithNextFrame(swapchain, framebuffer, commandbuffer): |
115 clearColors = [VkClearValue(color: VkClearColorValue(float32: [0, 0, 0, 0]))] | 118 WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(1, 0, 0, 0)): |
116 renderPassInfo = VkRenderPassBeginInfo( | 119 # echo (getMonoTime() - t).inMicroseconds.float / 1000.0 |
117 sType: VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, | 120 t = getMonoTime() |
118 renderPass: renderpass, | |
119 framebuffer: framebuffer, | |
120 renderArea: VkRect2D( | |
121 offset: VkOffset2D(x: 0, y: 0), | |
122 extent: VkExtent2D(width: frameWidth, height: frameHeight), | |
123 ), | |
124 clearValueCount: uint32(clearColors.len), | |
125 pClearValues: clearColors.ToCPointer(), | |
126 ) | |
127 viewport = VkViewport( | |
128 x: 0.0, | |
129 y: 0.0, | |
130 width: frameWidth.float32, | |
131 height: frameHeight.float32, | |
132 minDepth: 0.0, | |
133 maxDepth: 1.0, | |
134 ) | |
135 scissor = VkRect2D( | |
136 offset: VkOffset2D(x: 0, y: 0), | |
137 extent: VkExtent2D(width: frameWidth, height: frameHeight) | |
138 ) | |
139 vkCmdBeginRenderPass(commandbuffer, addr(renderPassInfo), VK_SUBPASS_CONTENTS_INLINE) | |
140 | |
141 # setup viewport | |
142 vkCmdSetViewport(commandbuffer, firstViewport = 0, viewportCount = 1, addr(viewport)) | |
143 vkCmdSetScissor(commandbuffer, firstScissor = 0, scissorCount = 1, addr(scissor)) | |
144 | |
145 # bind pipeline, will be loop | |
146 # block: | |
147 # Bind(pipeline1, commandbuffer, currentFrameInFlight = currentFrameInFlight) | |
148 | |
149 # render object, will be loop | |
150 # block: | |
151 # Render(commandbuffer, pipeline1, myGlobals, uniforms1, myMesh1, instances1) | |
152 | |
153 vkCmdEndRenderPass(commandbuffer) |