comparison tests/test_rendering.nim @ 1228:4e465583ea32

did: rename texture to image
author sam <sam@basx.dev>
date Thu, 18 Jul 2024 16:33:24 +0700
parents 55896320c8bf
children 5dcb503ef0c0
comparison
equal deleted inserted replaced
1227:4d97cfc4888b 1228:4e465583ea32
126 Material = object 126 Material = object
127 baseColor: Vec3f 127 baseColor: Vec3f
128 128
129 Uniforms = object 129 Uniforms = object
130 material: GPUValue[Material, UniformBuffer] 130 material: GPUValue[Material, UniformBuffer]
131 texture1: Texture[TVec4[uint8]] 131 texture1: Image[TVec4[uint8]]
132 132
133 QuadShader = object 133 QuadShader = object
134 position {.VertexAttribute.}: Vec3f 134 position {.VertexAttribute.}: Vec3f
135 fragmentColor {.Pass.}: Vec3f 135 fragmentColor {.Pass.}: Vec3f
136 uv {.Pass.}: Vec2f 136 uv {.Pass.}: Vec2f
159 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), 159 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer),
160 ) 160 )
161 uniforms1 = asDescriptorSet( 161 uniforms1 = asDescriptorSet(
162 Uniforms( 162 Uniforms(
163 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer), 163 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer),
164 texture1: Texture[TVec4[uint8]](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], interpolation: VK_FILTER_NEAREST), 164 texture1: Image[TVec4[uint8]](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], interpolation: VK_FILTER_NEAREST),
165 ) 165 )
166 ) 166 )
167 uniforms2 = asDescriptorSet( 167 uniforms2 = asDescriptorSet(
168 Uniforms( 168 Uniforms(
169 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer), 169 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer),
170 texture1: Texture[TVec4[uint8]](width: 2, height: 2, data: @[R, G, B, W]), 170 texture1: Image[TVec4[uint8]](width: 2, height: 2, data: @[R, G, B, W]),
171 ) 171 )
172 ) 172 )
173 173
174 AssignBuffers(renderdata, quad) 174 AssignBuffers(renderdata, quad)
175 AssignBuffers(renderdata, uniforms1) 175 AssignBuffers(renderdata, uniforms1)
176 AssignBuffers(renderdata, uniforms2) 176 AssignBuffers(renderdata, uniforms2)
177 UploadTextures(renderdata, uniforms1) 177 UploadImages(renderdata, uniforms1)
178 UploadTextures(renderdata, uniforms2) 178 UploadImages(renderdata, uniforms2)
179 renderdata.FlushAllMemory() 179 renderdata.FlushAllMemory()
180 180
181 var pipeline = CreatePipeline[QuadShader](renderPass = renderPass, samples = samples) 181 var pipeline = CreatePipeline[QuadShader](renderPass = renderPass, samples = samples)
182 182
183 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) 183 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1)
216 ConstSet = object 216 ConstSet = object
217 constants: GPUValue[Constants, UniformBuffer] 217 constants: GPUValue[Constants, UniformBuffer]
218 MainSet = object 218 MainSet = object
219 renderSettings: GPUValue[RenderSettings, UniformBufferMapped] 219 renderSettings: GPUValue[RenderSettings, UniformBufferMapped]
220 material: array[2, GPUValue[Material, UniformBuffer]] 220 material: array[2, GPUValue[Material, UniformBuffer]]
221 texture1: array[2, Texture[TVec1[uint8]]] 221 texture1: array[2, Image[TVec1[uint8]]]
222 OtherSet = object 222 OtherSet = object
223 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped] 223 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped]
224 224
225 QuadShader = object 225 QuadShader = object
226 position {.VertexAttribute.}: Vec3f 226 position {.VertexAttribute.}: Vec3f
260 material: [ 260 material: [
261 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer), 261 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer),
262 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer), 262 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer),
263 ], 263 ],
264 texture1: [ 264 texture1: [
265 Texture[TVec1[uint8]](width: 2, height: 2, data: @[W, G, G, W], interpolation: VK_FILTER_NEAREST), 265 Image[TVec1[uint8]](width: 2, height: 2, data: @[W, G, G, W], interpolation: VK_FILTER_NEAREST),
266 Texture[TVec1[uint8]](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], interpolation: VK_FILTER_NEAREST), 266 Image[TVec1[uint8]](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], interpolation: VK_FILTER_NEAREST),
267 ], 267 ],
268 ), 268 ),
269 ) 269 )
270 var otherset1 = asDescriptorSet( 270 var otherset1 = asDescriptorSet(
271 OtherSet( 271 OtherSet(
281 AssignBuffers(renderdata, quad) 281 AssignBuffers(renderdata, quad)
282 AssignBuffers(renderdata, constset) 282 AssignBuffers(renderdata, constset)
283 AssignBuffers(renderdata, mainset) 283 AssignBuffers(renderdata, mainset)
284 AssignBuffers(renderdata, otherset1) 284 AssignBuffers(renderdata, otherset1)
285 AssignBuffers(renderdata, otherset2) 285 AssignBuffers(renderdata, otherset2)
286 UploadTextures(renderdata, mainset) 286 UploadImages(renderdata, mainset)
287 renderdata.FlushAllMemory() 287 renderdata.FlushAllMemory()
288 288
289 var pipeline = CreatePipeline[QuadShader](renderPass = renderPass, samples = samples) 289 var pipeline = CreatePipeline[QuadShader](renderPass = renderPass, samples = samples)
290 290
291 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset) 291 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset)
322 322
323 var renderdata = InitRenderData() 323 var renderdata = InitRenderData()
324 324
325 type 325 type
326 Uniforms = object 326 Uniforms = object
327 frameTexture: Texture[TVec4[uint8]] 327 frameTexture: Image[TVec4[uint8]]
328 TriangleShader = object 328 TriangleShader = object
329 position {.VertexAttribute.}: Vec3f 329 position {.VertexAttribute.}: Vec3f
330 color {.VertexAttribute.}: Vec3f 330 color {.VertexAttribute.}: Vec3f
331 fragmentColor {.Pass.}: Vec3f 331 fragmentColor {.Pass.}: Vec3f
332 outColor {.ShaderOutput.}: Vec4f 332 outColor {.ShaderOutput.}: Vec4f
371 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), 371 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer),
372 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), 372 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer),
373 ) 373 )
374 var uniforms1 = asDescriptorSet( 374 var uniforms1 = asDescriptorSet(
375 Uniforms( 375 Uniforms(
376 frameTexture: Texture[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true), 376 frameTexture: Image[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true),
377 ) 377 )
378 ) 378 )
379 var uniforms2 = asDescriptorSet( 379 var uniforms2 = asDescriptorSet(
380 Uniforms( 380 Uniforms(
381 frameTexture: Texture[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true), 381 frameTexture: Image[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true),
382 ) 382 )
383 ) 383 )
384 AssignBuffers(renderdata, mesh) 384 AssignBuffers(renderdata, mesh)
385 AssignBuffers(renderdata, quad) 385 AssignBuffers(renderdata, quad)
386 UploadTextures(renderdata, uniforms1) 386 UploadImages(renderdata, uniforms1)
387 UploadTextures(renderdata, uniforms2) 387 UploadImages(renderdata, uniforms2)
388 renderdata.FlushAllMemory() 388 renderdata.FlushAllMemory()
389 389
390 var 390 var
391 drawPipeline = CreatePipeline[TriangleShader](renderPass = offscreenRP, samples = samples) 391 drawPipeline = CreatePipeline[TriangleShader](renderPass = offscreenRP, samples = samples)
392 presentPipeline = CreatePipeline[PresentShader](renderPass = presentRP, samples = samples) 392 presentPipeline = CreatePipeline[PresentShader](renderPass = presentRP, samples = samples)