Mercurial > games > semicongine
annotate tests/test_mesh.nim @ 693:86048c6ed6fd
did: restructure roadmap a bit, update progress
author | Sam <sam@basx.dev> |
---|---|
date | Fri, 19 May 2023 12:45:50 +0700 |
parents | 9182a5d2ea3a |
children | f05497ef8fd2 |
rev | line source |
---|---|
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import std/times |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import semicongine |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 proc main() = |
691 | 6 var scene = loadScene("default_cube.glb") |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 var engine = initEngine("Test meshes") |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 const |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 vertexInput = @[attr[Vec3f]("POSITION", memoryPerformanceHint=PreferFastRead)] |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 fragOutput = @[attr[Vec4f]("color")] |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 uniforms = @[attr[Mat4]("transform")] |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 vertexCode = compileGlslShader( |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 stage=VK_SHADER_STAGE_VERTEX_BIT, |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 inputs=vertexInput, |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 uniforms=uniforms, |
691 | 17 main="""gl_Position = vec4(POSITION, 1.0) * Uniforms.transform;""" |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 ) |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 fragmentCode = compileGlslShader( |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 outputs=fragOutput, |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 uniforms=uniforms, |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 main=""" |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 color = vec4(61/255, 43/255, 31/255, 1); |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 """ |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 ) |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 engine.addScene(scene, vertexInput) |
691 | 29 let rotateAxis = newVec3f(0, 1, 0) |
30 scene.addShaderGlobal("transform", Unit4) | |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 var t = cpuTime() |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
691 | 33 scene.setShaderGlobal( |
34 "transform", | |
35 scale3d(0.2'f32, 0.2'f32, 0.2'f32) * translate3d(0'f32, 0'f32, 1.8'f32) * rotate3d(float32(PI) / 4'f32, newVec3f(1, 0, 0)) * rotate3d(-float32(cpuTime() - t), rotateAxis) | |
36 ) | |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 engine.renderScene(scene) |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 engine.destroy() |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
41 when isMainModule: |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 main() |