Mercurial > games > semicongine
annotate tests/test_materials.nim @ 199:da68fe12f600
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 |
rev | line source |
---|---|
199
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import semicongine |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 proc main() = |
da68fe12f600
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())) |
da68fe12f600
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]) |
da68fe12f600
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: @[ |
da68fe12f600
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, |
da68fe12f600
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, |
da68fe12f600
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, |
da68fe12f600
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, |
da68fe12f600
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, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 ])) |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 |
da68fe12f600
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") |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 const |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 vertexInput = @[ |
da68fe12f600
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), |
da68fe12f600
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), |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 ] |
da68fe12f600
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")] |
da68fe12f600
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")] |
da68fe12f600
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")] |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 vertexCode = compileGlslShader( |
da68fe12f600
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, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 inputs=vertexInput, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 samplers=samplers, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 outputs=vertexOutput, |
da68fe12f600
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;""" |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 ) |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 fragmentCode = compileGlslShader( |
da68fe12f600
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, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 inputs=vertexOutput, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 samplers=samplers, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 outputs=fragOutput, |
da68fe12f600
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);" |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 ) |
da68fe12f600
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)) |
da68fe12f600
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) |
da68fe12f600
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): |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 engine.renderScene(scene) |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
41 break |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 engine.destroy() |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
44 |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
45 when isMainModule: |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 main() |