Mercurial > games > semicongine
annotate tests/test_gltf.nim @ 1427:676fc13685a9
did: restructure files and imports
author | sam <sam@basx.dev> |
---|---|
date | Sat, 11 Jan 2025 14:04:39 +0700 |
parents | 3b8a736c45a7 |
children |
rev | line source |
---|---|
1299
6d0162bfe48a
did: finish mentioned refactoring, no API changes still
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
1 import std/math |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
2 import std/sequtils |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/monotimes |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
4 import std/times |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
5 import std/options |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
6 |
1267 | 7 import ../semicongine |
1427 | 8 import ../semicongine/rendering |
9 import ../semicongine/loaders | |
10 import ../semicongine/input | |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
11 |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
12 proc test_gltf(time: float32, renderPass: RenderPass) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
13 var renderdata = initRenderData() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
14 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
15 type |
1253 | 16 ObjectData = object |
17 transform: Mat4 | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
18 materialId: int32 |
1332 | 19 |
1253 | 20 Camera = object |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
21 view: Mat4 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
22 normal: Mat4 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
23 projection: Mat4 |
1332 | 24 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
25 Material = object |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
26 color: Vec4f = vec4(1, 1, 1, 1) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
27 # colorTexture: int32 = -1 |
1248 | 28 metallic: float32 = 0 |
29 roughness: float32 = 0 | |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
30 # metallicRoughnessTexture: int32 = -1 |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
31 # normalTexture: int32 = -1 |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
32 # occlusionTexture: int32 = -1 |
1332 | 33 emissive: Vec4f = vec4(0, 0, 0, 0) # emissiveTexture: int32 = -1 |
34 | |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
35 MainDescriptors = object |
1278
772bb32c4368
replcae lodepng with stb_image, some cleanup
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
36 materials: array[50, GPUValue[Material, UniformBuffer]] |
1253 | 37 camera: GPUValue[Camera, UniformBufferMapped] |
1332 | 38 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
39 Shader = object |
1323 | 40 objectData {.PushConstant.}: ObjectData |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
41 position {.VertexAttribute.}: Vec3f |
1254 | 42 color {.VertexAttribute.}: Vec4f |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
43 normal {.VertexAttribute.}: Vec3f |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
44 fragmentPosition {.Pass.}: Vec3f |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
45 fragmentColor {.Pass.}: Vec4f |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
46 fragmentNormal {.Pass.}: Vec3f |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
47 outColor {.ShaderOutput.}: Vec4f |
1323 | 48 descriptors {.DescriptorSet: 0.}: MainDescriptors |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
49 # code |
1332 | 50 vertexCode: string = |
51 """ | |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
52 void main() { |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
53 mat4 modelView = objectData.transform * camera.view; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
54 mat3 normalMat = mat3(transpose(inverse(objectData.transform))); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
55 vec4 posTransformed = vec4(position, 1) * modelView; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
56 fragmentPosition = posTransformed.xyz / posTransformed.w; |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
57 fragmentColor = color * materials[objectData.materialId].color; |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
58 fragmentNormal = normal * normalMat; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
59 gl_Position = vec4(position, 1) * (modelView * camera.projection); |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
60 }""" |
1332 | 61 fragmentCode: string = |
62 """ | |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
63 const vec3 lightPosition = vec3(7, 9, -12); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
64 const float shininess = 40; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
65 const vec3 ambientColor = vec3(0, 0, 0); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
66 const vec3 lightColor = vec3(1, 1, 1); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
67 // const vec3 specColor = vec3(1, 1, 1); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
68 const float lightPower = 20; |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
69 void main() { |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
70 // some setup |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
71 vec3 normal = normalize(fragmentNormal); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
72 vec3 lightDir = lightPosition - fragmentPosition; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
73 float dist = length(lightDir); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
74 lightDir = normalize(lightDir); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
75 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
76 float lambertian = max(dot(lightDir, normal), 0); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
77 float specular = 0; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
78 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
79 // blinn-phong |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
80 if (lambertian > 0) { |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
81 vec3 viewDir = normalize(-fragmentPosition); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
82 vec3 halfDir = normalize(lightDir + viewDir); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
83 float specAngle = max(dot(halfDir, normal), 0.0); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
84 specular = pow(specAngle, shininess); |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
85 } |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
86 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
87 vec3 diffuseColor = fragmentColor.rgb; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
88 vec3 specColor = diffuseColor; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
89 vec3 color = ambientColor + diffuseColor * lambertian * lightColor * lightPower / dist + specColor * specular * lightColor * lightPower / dist; |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
90 |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
91 outColor = vec4(color, fragmentColor.a); |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
92 }""" |
1332 | 93 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
94 Mesh = object |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
95 position: GPUArray[Vec3f, VertexBuffer] |
1254 | 96 color: GPUArray[Vec4f, VertexBuffer] |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
97 normal: GPUArray[Vec3f, VertexBuffer] |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
98 indices: GPUArray[uint32, IndexBuffer] |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
99 material: int32 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
100 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
101 var gltfData = loadMeshes[Mesh, Material]( |
1259 | 102 "town.glb", |
103 # "forest.glb", | |
1248 | 104 MeshAttributeNames( |
105 POSITION: "position", | |
1254 | 106 COLOR: @["color"], |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
107 NORMAL: "normal", |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
108 indices: "indices", |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
109 material: "material", |
1254 | 110 ), |
1248 | 111 MaterialAttributeNames( |
112 baseColorFactor: "color", | |
113 baseColorTexture: "colorTexture", | |
114 metallicFactor: "metallic", | |
115 roughnessFactor: "roughness", | |
116 metallicRoughnessTexture: "metallicRoughnessTexture", | |
117 normalTexture: "normalTexture", | |
118 occlusionTexture: "occlusionTexture", | |
119 emissiveTexture: "emissiveTexture", | |
120 emissiveFactor: "emissive", | |
1332 | 121 ), |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
122 ) |
1323 | 123 var descriptors = asDescriptorSetData( |
1253 | 124 MainDescriptors( |
1332 | 125 camera: asGPUValue( |
126 Camera(view: Unit4, normal: Unit4, projection: Unit4), UniformBufferMapped | |
127 ) | |
1254 | 128 ) |
1253 | 129 ) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
130 for i in 0 ..< gltfData.materials.len: |
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
131 descriptors.data.materials[i] = asGPUValue(gltfData.materials[i], UniformBuffer) |
1251 | 132 for mesh in mitems(gltfData.meshes): |
1249
d83726af7abb
did: first triangles getting loaded from gltf
sam <sam@basx.dev>
parents:
1248
diff
changeset
|
133 for primitive in mitems(mesh): |
1332 | 134 primitive[0].color = asGPUArray( |
135 newSeqWith(primitive[0].position.data.len, vec4(1, 1, 1, 1)), VertexBuffer | |
136 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
137 renderdata.assignBuffers(primitive[0]) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
138 renderdata.assignBuffers(descriptors) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
139 |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
140 var pipeline = createPipeline(Shader(), renderPass = renderPass, cullMode = []) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
141 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors) |
1254 | 142 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
143 renderdata.flushAllMemory() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
144 |
1332 | 145 proc drawNode( |
146 commandbuffer: VkCommandBuffer, pipeline: Pipeline, nodeId: int, transform: Mat4 | |
147 ) = | |
1251 | 148 let nodeTransform = gltfData.nodes[nodeId].transform * transform |
149 if gltfData.nodes[nodeId].mesh >= 0: | |
1321
385dbd68a947
did: a TON of copy elimination, some tests run now waaaay faster
sam <sam@basx.dev>
parents:
1306
diff
changeset
|
150 for primitive in gltfData.meshes[gltfData.nodes[nodeId].mesh].mitems: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
151 renderWithPushConstant( |
1254 | 152 commandbuffer = commandbuffer, |
153 pipeline = pipeline, | |
154 mesh = primitive[0], | |
1332 | 155 pushConstant = |
156 ObjectData(transform: nodeTransform, materialId: primitive[0].material), | |
1254 | 157 ) |
1251 | 158 for childNode in gltfData.nodes[nodeId].children: |
1332 | 159 drawNode( |
160 commandbuffer = commandbuffer, | |
161 pipeline = pipeline, | |
162 nodeId = childNode, | |
163 transform = nodeTransform, | |
164 ) | |
1251 | 165 |
1254 | 166 var camPos: Vec3f |
167 var camYaw: float32 | |
168 var camPitch: float32 | |
169 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
170 discard updateInputs() # clear inputs, otherwise MouseMove will have stuff |
1251 | 171 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
172 var start = getMonoTime() |
1254 | 173 var lastT = getMonoTime() |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
174 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time and updateInputs(): |
1254 | 175 let dt = ((getMonoTime() - lastT).inNanoseconds().int / 1_000_000_000).float32 |
176 lastT = getMonoTime() | |
177 | |
1332 | 178 camYaw += mouseMove().x.float32 / 1000'f32 |
1306 | 179 camPitch += mouseMove().y.float32 / 1000'f32 |
1254 | 180 var |
181 forward = 0'f32 | |
182 sideward = 0'f32 | |
1332 | 183 if keyIsDown(W): |
184 forward += 2 | |
185 if keyIsDown(S): | |
186 forward -= 2 | |
187 if keyIsDown(A): | |
188 sideward -= 2 | |
189 if keyIsDown(D): | |
190 sideward += 2 | |
1254 | 191 |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
192 let camDir = (rotate(camYaw, Y) * rotate(camPitch, X)) * Z |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
193 let camDirSide = camDir.cross(-Y).normalized |
1254 | 194 camPos += camDir * forward * dt |
195 camPos += camDirSide * sideward * dt | |
196 | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
197 let view = rotate(-camPitch, X) * rotate(-camYaw, Y) * translate(-camPos) |
1258
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
198 descriptors.data.camera.data.view = view |
5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
sam <sam@basx.dev>
parents:
1257
diff
changeset
|
199 descriptors.data.camera.data.normal = view |
1332 | 200 descriptors.data.camera.data.projection = |
201 projection(PI / 2, aspect = getAspectRatio(), zNear = 0.01, zFar = 20) | |
1254 | 202 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
203 updateGPUBuffer(descriptors.data.camera) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
204 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
205 withNextFrame(framebuffer, commandbuffer): |
1332 | 206 withRenderPass( |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
207 renderPass, |
1332 | 208 framebuffer, |
209 commandbuffer, | |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
210 frameWidth(), |
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
211 frameHeight(), |
1332 | 212 vec4(0, 0, 0, 0), |
213 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
214 withPipeline(commandbuffer, pipeline): |
1323 | 215 bindDescriptorSet(commandbuffer, descriptors, 0, pipeline) |
216 for nodeId in gltfData.scenes[0]: | |
217 drawNode( | |
218 commandbuffer = commandbuffer, | |
219 pipeline = pipeline, | |
220 nodeId = nodeId, | |
1332 | 221 transform = rotate(PI / 2, Z), |
1323 | 222 ) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
223 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
224 # cleanup |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
225 checkVkResult vkDeviceWaitIdle(engine().vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
226 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
227 destroyRenderData(renderdata) |
1255
2b5ca798f6d6
did: make example town loadable and renderable, yay!
sam <sam@basx.dev>
parents:
1254
diff
changeset
|
228 |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
229 when isMainModule: |
1254 | 230 var time = 1000'f32 |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
231 initEngine("Test glTF") |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
232 |
1332 | 233 var renderpass = createDirectPresentationRenderPass( |
234 depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT | |
235 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
236 setupSwapchain(renderpass = renderpass) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
237 lockMouse(true) |
1305
21c4e598d820
did: work on cursor issues, but now sync unfinished things to notebook
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
238 # showSystemCursor(false) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
239 |
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
240 # tests a simple triangle with minimalistic shader and vertex format |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
241 test_gltf(time, renderpass) |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
242 |
1423
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
243 checkVkResult vkDeviceWaitIdle(engine().vulkan.device) |
3b8a736c45a7
did: put almost all global state into a single struct
sam <sam@basx.dev>
parents:
1414
diff
changeset
|
244 destroyRenderPass(renderpass) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
245 clearSwapchain() |
1247
c15770761865
add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents:
diff
changeset
|
246 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
247 destroyVulkan() |