annotate tests/test_materials.nim @ 660:c6414ade79f0

add: new test file to test to do future test with materials etc.
author Sam <sam@basx.dev>
date Sun, 07 May 2023 17:42:53 +0700
parents
children 1ba005328615
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
660
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
1 import semicongine
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
2
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
3 proc main() =
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
4 var scene = newScene("main", root=newEntity("rect", rect()))
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
5 let (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8])
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
6 scene.addTexture("my_texture", TextureImage(width: 5, height: 5, imagedata: @[
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
7 R, R, R, R, R,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
8 R, R, W, R, R,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
9 R, W, W, W, R,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
10 R, R, W, R, R,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
11 R, R, R, R, R,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
12 ]))
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
13
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
14 var engine = initEngine("Test materials")
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
15 const
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
16 vertexInput = @[
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
17 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
18 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead),
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
19 ]
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
20 vertexOutput = @[attr[Vec2f]("uvout")]
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
21 samplers = @[attr[Sampler2DType]("my_texture")]
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
22 fragOutput = @[attr[Vec4f]("color")]
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
23 vertexCode = compileGlslShader(
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
24 stage=VK_SHADER_STAGE_VERTEX_BIT,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
25 inputs=vertexInput,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
26 samplers=samplers,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
27 outputs=vertexOutput,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
28 main="""gl_Position = vec4(position, 1.0); uvout = uv;"""
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
29 )
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
30 fragmentCode = compileGlslShader(
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
31 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
32 inputs=vertexOutput,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
33 samplers=samplers,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
34 outputs=fragOutput,
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
35 main="color = texture(my_texture, uvout);"
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
36 )
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
37 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode))
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
38 engine.addScene(scene, vertexInput)
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
39 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
40 engine.renderScene(scene)
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
41 break
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
42 engine.destroy()
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
43
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
44
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
45 when isMainModule:
c6414ade79f0 add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff changeset
46 main()