Mercurial > games > semicongine
annotate tests/test_vulkan_wrapper.nim @ 390:1727bec9ca2f
did: finish importing system
| author | Sam <sam@basx.dev> |
|---|---|
| date | Wed, 06 Dec 2023 00:05:55 +0700 |
| parents | eaf084ba80e5 |
| children | 91e018270832 |
| rev | line source |
|---|---|
|
272
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
253
diff
changeset
|
1 import std/tables |
|
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
253
diff
changeset
|
2 |
| 117 | 3 import semicongine |
|
99
4deffc94484a
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
98
diff
changeset
|
4 |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
5 |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
6 let |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
7 sampler = Sampler( |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
8 magnification: VK_FILTER_NEAREST, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
9 minification: VK_FILTER_NEAREST, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
10 wrapModeS: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
11 wrapModeT: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
12 ) |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
13 (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
14 mat = SINGLE_TEXTURE_MATERIAL.initMaterialData( |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
15 name="mat", |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
16 attributes={ |
|
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
368
diff
changeset
|
17 "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
18 R, R, R, R, R, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
19 R, R, W, R, R, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
20 R, W, W, W, R, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
21 R, R, W, R, R, |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
22 R, R, R, R, R, |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
23 ]), sampler: sampler)]) |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
24 }.toTable |
|
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
25 ) |
| 376 | 26 Mat2Type = MaterialType( |
| 27 name: "single texture material 2", | |
|
384
eaf084ba80e5
fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents:
376
diff
changeset
|
28 vertexAttributes: { |
| 376 | 29 "position": Vec3F32, |
| 30 "uv": Vec2F32, | |
| 31 }.toTable, | |
| 32 attributes: {"baseTexture": TextureType}.toTable | |
| 33 ) | |
| 34 mat2 = Mat2Type.initMaterialData( | |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
35 name="mat2", |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
36 attributes={ |
|
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
368
diff
changeset
|
37 "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
38 R, W, R, W, R, |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
39 W, R, W, R, W, |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
40 R, W, R, W, R, |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
41 W, R, W, R, W, |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
42 R, W, R, W, R, |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
43 ]), sampler: sampler)]) |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
44 }.toTable |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
45 ) |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
46 mat3 = SINGLE_COLOR_MATERIAL.initMaterialData( |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
47 name="mat3", |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
48 attributes={ |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
49 "color": initDataList(@[newVec4f(0, 1, 0, 1)]) |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
50 }.toTable |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
51 ) |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
52 |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
53 proc scene_different_mesh_types(): seq[Mesh] = |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
54 @[ |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
55 newMesh( |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
56 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
57 uvs=[newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], |
| 211 | 58 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
59 material=mat, |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
60 transform=translate(-0.7, -0.5), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
61 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
62 newMesh( |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
63 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
64 uvs=[newVec2f(0.0, -0.4), newVec2f(0.4, 0.4), newVec2f(-0.4, 0.5)], |
| 211 | 65 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
66 material=mat, |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
67 transform=translate(0, -0.5), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
68 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
69 newMesh( |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
70 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
71 uvs=[newVec2f(0.0, 0.5), newVec2f(0.5, -0.5), newVec2f(-0.5, -0.5)], |
| 211 | 72 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
73 indices=[[0'u16, 2'u16, 1'u16]], |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
74 material=mat2, |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
75 transform=translate(0.7, -0.5), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
76 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
77 newMesh( |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
78 positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
79 uvs=[newVec2f(0.0, 0.4), newVec2f(0.4, -0.4), newVec2f(-0.4, -0.4)], |
| 211 | 80 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
81 indices=[[0'u16, 2'u16, 1'u16]], |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
82 material=mat2, |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
83 transform=translate(-0.7, 0.5), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
84 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
85 newMesh( |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
86 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
87 uvs=[newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], |
| 211 | 88 colors=[newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
89 indices=[[0'u32, 2'u32, 1'u32]], |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
90 autoResize=false, |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
91 material=mat2, |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
92 transform=translate(0, 0.5), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
93 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
94 newMesh( |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
95 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
96 uvs=[newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
97 colors=[newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
98 indices=[[0'u32, 2'u32, 1'u32]], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
99 autoResize=false, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
100 material=mat2, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
101 transform=translate(0.7, 0.5), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
102 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
103 ] |
|
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
104 |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
105 proc scene_simple(): seq[Mesh] = |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
106 @[ |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
107 newMesh( |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
108 positions=[newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
109 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
110 uvs=[newVec2f(0.0, -0.3), newVec2f(0.3, 0.3), newVec2f(-0.3, 0.3)], |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
111 material=mat, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
112 transform=translate(0.4, 0.4), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
113 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
114 newMesh( |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
115 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
116 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
117 uvs=[newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
118 material=mat, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
119 transform=translate(0.4, -0.4), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
120 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
121 newMesh( |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
122 positions=[newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
123 colors=[newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
124 uvs=[newVec2f(0.0, -0.6), newVec2f(0.6, 0.6), newVec2f(-0.6, 0.6)], |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
125 indices=[[0'u32, 1'u32, 2'u32]], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
126 autoResize=false, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
127 material=mat, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
128 transform=translate(-0.4, 0.4), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
129 ), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
130 newMesh( |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
131 positions=[newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
132 colors=[newVec4f(0.0, 0.0, 1.0, 1), newVec4f(0.0, 0.0, 1.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
133 uvs=[newVec2f(0.0, -0.8), newVec2f(0.8, 0.8), newVec2f(-0.8, 0.8)], |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
134 indices=[[0'u16, 1'u16, 2'u16]], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
135 instanceTransforms=[Unit4F32, Unit4F32], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
136 material=mat, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
137 transform=translate(-0.4, -0.4), |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
138 ) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
139 ] |
|
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
140 |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
141 proc scene_primitives(): seq[Mesh] = |
| 125 | 142 var r = rect(color="ff0000") |
| 143 var t = tri(color="0000ff") | |
| 144 var c = circle(color="00ff00") | |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
145 r.material = mat |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
146 t.material = mat |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
147 c.material = mat |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
148 r.transform = translate(newVec3f(0.5, -0.3)) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
149 t.transform = translate(newVec3f(0.3, 0.3)) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
150 c.transform = translate(newVec3f(-0.3, 0.1)) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
151 result = @[r, c, t] |
|
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
152 |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
153 proc scene_flag(): seq[Mesh] = |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
154 @[ |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
155 newMesh( |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
156 positions=[newVec3f(-1.0, -1.0), newVec3f(1.0, -1.0), newVec3f(1.0, 1.0), newVec3f(-1.0, 1.0)], |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
157 uvs=[newVec2f(-1.0, -1.0), newVec2f(1.0, -1.0), newVec2f(1.0, 1.0), newVec2f(-1.0, 1.0)], |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
158 colors=[newVec4f(-1, -1, 1, 1), newVec4f(1, -1, 1, 1), newVec4f(1, 1, 1, 1), newVec4f(-1, 1, 1, 1)], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
159 indices=[[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
160 material=mat, |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
161 transform=scale(0.5, 0.5) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
162 ) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
163 ] |
|
192
659992f14dd6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
191
diff
changeset
|
164 |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
165 proc scene_multi_material(): seq[Mesh] = |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
166 var |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
167 r1 = rect(color="ffffff") |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
168 r2 = rect(color="000000") |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
169 r1.material = mat |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
170 r2.material = mat3 |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
171 r1.transform = translate(newVec3f(-0.5)) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
172 r2.transform = translate(newVec3f(+0.5)) |
|
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
173 result = @[r1, r2] |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
174 |
|
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
175 proc main() = |
| 127 | 176 var engine = initEngine("Test") |
|
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
177 |
|
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
178 # INIT RENDERER: |
|
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
179 const |
|
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
180 shaderConfiguration1 = createShaderConfiguration( |
|
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
181 inputs=[ |
|
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
182 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
|
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
183 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
184 attr[Mat4]("transform", perInstance=true), |
|
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
185 ], |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
186 intermediates=[ |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
187 attr[Vec4f]("outcolor"), |
|
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
188 ], |
|
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
189 outputs=[attr[Vec4f]("color")], |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
190 samplers=[ |
|
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
368
diff
changeset
|
191 attr[Texture]("baseTexture") |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
192 ], |
|
330
04531bec3583
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
329
diff
changeset
|
193 vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", |
|
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
368
diff
changeset
|
194 fragmentCode="color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", |
|
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
195 ) |
|
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
196 shaderConfiguration2 = createShaderConfiguration( |
|
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
197 inputs=[ |
|
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
198 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
199 attr[Mat4]("transform", perInstance=true), |
|
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
200 ], |
|
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
201 intermediates=[attr[Vec4f]("outcolor")], |
|
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
202 outputs=[attr[Vec4f]("color")], |
|
330
04531bec3583
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
329
diff
changeset
|
203 uniforms=[attr[Vec4f]("color", arrayCount=1)], |
|
04531bec3583
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
329
diff
changeset
|
204 vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", |
|
327
a63bd8f29252
add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents:
326
diff
changeset
|
205 fragmentCode="color = outcolor;", |
|
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
206 ) |
|
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
207 engine.initRenderer({ |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
208 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, |
|
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
209 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, |
| 376 | 210 Mat2Type: shaderConfiguration1, |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
211 SINGLE_COLOR_MATERIAL: shaderConfiguration2, |
| 344 | 212 }) |
|
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
213 |
|
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
214 # INIT SCENES |
|
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
188
diff
changeset
|
215 var scenes = [ |
| 328 | 216 Scene(name: "simple", meshes: scene_simple()), |
| 217 Scene(name: "different mesh types", meshes: scene_different_mesh_types()), | |
| 218 Scene(name: "primitives", meshes: scene_primitives()), | |
| 219 Scene(name: "flag", meshes: scene_flag()), | |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
220 Scene(name: "multimaterial", meshes: scene_multi_material()), |
|
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
188
diff
changeset
|
221 ] |
|
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
222 |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
223 for scene in scenes.mitems: |
|
368
51ee41c1d8ed
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
224 engine.loadScene(scene) |
| 109 | 225 |
| 115 | 226 # MAINLOOP |
|
111
6fd10b7e2d6a
did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents:
109
diff
changeset
|
227 echo "Setup successfull, start rendering" |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
228 for i in 0 ..< 3: |
|
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
188
diff
changeset
|
229 for scene in scenes.mitems: |
|
326
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
325
diff
changeset
|
230 echo "rendering scene ", scene.name |
|
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
231 for i in 0 ..< 1000: |
| 146 | 232 if engine.updateInputs() != Running or engine.keyIsDown(Escape): |
|
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
233 engine.destroy() |
|
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
234 return |
|
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
235 engine.renderScene(scene) |
|
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
236 echo "Rendered ", engine.framesRendered, " frames" |
|
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
237 echo "Processed ", engine.eventsProcessed, " events" |
|
114
056e08dfad10
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
113
diff
changeset
|
238 |
|
056e08dfad10
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
113
diff
changeset
|
239 # cleanup |
| 96 | 240 echo "Start cleanup" |
| 127 | 241 engine.destroy() |
|
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
242 |
|
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
243 when isMainModule: |
|
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
244 main() |
