Mercurial > games > semicongine
comparison tests/test_gltf.nim @ 1249:d83726af7abb
did: first triangles getting loaded from gltf
author | sam <sam@basx.dev> |
---|---|
date | Thu, 25 Jul 2024 22:41:24 +0700 |
parents | 317bb5a73606 |
children | 3f98ad20a9d3 |
comparison
equal
deleted
inserted
replaced
1248:317bb5a73606 | 1249:d83726af7abb |
---|---|
24 emissiveTexture: int32 = -1 | 24 emissiveTexture: int32 = -1 |
25 MainDescriptors = object | 25 MainDescriptors = object |
26 material: GPUValue[Material, UniformBuffer] | 26 material: GPUValue[Material, UniformBuffer] |
27 Shader = object | 27 Shader = object |
28 position {.VertexAttribute.}: Vec3f | 28 position {.VertexAttribute.}: Vec3f |
29 color {.VertexAttribute.}: Vec4f | |
30 uv {.VertexAttribute.}: Vec2f | 29 uv {.VertexAttribute.}: Vec2f |
31 fragmentColor {.Pass.}: Vec4f | 30 fragmentColor {.Pass.}: Vec4f |
32 fragmentUv {.Pass.}: Vec2f | 31 fragmentUv {.Pass.}: Vec2f |
33 outColor {.ShaderOutput.}: Vec4f | 32 outColor {.ShaderOutput.}: Vec4f |
34 descriptors {.DescriptorSets.}: (MainDescriptors, ) | 33 descriptors {.DescriptorSets.}: (MainDescriptors, ) |
35 # code | 34 # code |
36 vertexCode: string = """ | 35 vertexCode: string = """ |
37 void main() { | 36 void main() { |
38 fragmentColor = color; | 37 fragmentColor = vec4(1, 1, 1, 1); |
39 fragmentUv = uv; | 38 fragmentUv = uv; |
40 gl_Position = vec4(position, 1); | 39 gl_Position = vec4(position, 1); |
41 }""" | 40 }""" |
42 fragmentCode: string = """void main() { outColor = fragmentColor;}""" | 41 fragmentCode: string = """void main() { outColor = fragmentColor;}""" |
43 Mesh = object | 42 Mesh = object |
44 position: GPUArray[Vec3f, VertexBuffer] | 43 position: GPUArray[Vec3f, VertexBuffer] |
45 color: GPUArray[Vec4f, VertexBuffer] | |
46 uv: GPUArray[Vec2f, VertexBuffer] | 44 uv: GPUArray[Vec2f, VertexBuffer] |
47 | 45 |
48 let gltfMesh = LoadMeshes[Mesh, Material]( | 46 var gltfMesh = LoadMeshes[Mesh, Material]( |
49 "town.glb", | 47 "town.glb", |
50 MeshAttributeNames( | 48 MeshAttributeNames( |
51 POSITION: "position", | 49 POSITION: "position", |
52 COLOR: @["color"], | 50 TEXCOORD: @["uv"], |
53 TEXCOORD: @["uv"], | 51 ), |
54 ), | |
55 MaterialAttributeNames( | 52 MaterialAttributeNames( |
56 baseColorFactor: "color", | 53 baseColorFactor: "color", |
57 baseColorTexture: "colorTexture", | 54 baseColorTexture: "colorTexture", |
58 metallicFactor: "metallic", | 55 metallicFactor: "metallic", |
59 roughnessFactor: "roughness", | 56 roughnessFactor: "roughness", |
62 occlusionTexture: "occlusionTexture", | 59 occlusionTexture: "occlusionTexture", |
63 emissiveTexture: "emissiveTexture", | 60 emissiveTexture: "emissiveTexture", |
64 emissiveFactor: "emissive", | 61 emissiveFactor: "emissive", |
65 ) | 62 ) |
66 ) | 63 ) |
67 var mesh = gltfMesh.meshes[0][0] | 64 for mesh in mitems(gltfMesh.meshes): |
68 renderdata.AssignBuffers(mesh) | 65 for primitive in mitems(mesh): |
66 renderdata.AssignBuffers(primitive[0]) | |
69 renderdata.FlushAllMemory() | 67 renderdata.FlushAllMemory() |
70 | 68 |
71 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) | 69 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
72 | 70 |
73 var start = getMonoTime() | 71 var start = getMonoTime() |
77 | 75 |
78 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 76 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
79 | 77 |
80 WithPipeline(commandbuffer, pipeline): | 78 WithPipeline(commandbuffer, pipeline): |
81 | 79 |
82 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | 80 for mesh in gltfMesh.meshes: |
81 for primitive in mesh: | |
82 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = primitive[0]) | |
83 | 83 |
84 # cleanup | 84 # cleanup |
85 checkVkResult vkDeviceWaitIdle(vulkan.device) | 85 checkVkResult vkDeviceWaitIdle(vulkan.device) |
86 DestroyPipeline(pipeline) | 86 DestroyPipeline(pipeline) |
87 DestroyRenderData(renderdata) | 87 DestroyRenderData(renderdata) |
88 when isMainModule: | 88 when isMainModule: |
89 var time = 1'f32 | 89 var time = 5'f32 |
90 InitVulkan() | 90 InitVulkan() |
91 | 91 |
92 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT) | 92 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT) |
93 SetupSwapchain(renderpass = renderpass) | 93 SetupSwapchain(renderpass = renderpass) |
94 | 94 |