Mercurial > games > semicongine
annotate tests/test_vulkan_wrapper.nim @ 828:ad95479c582e
did: improve material system a ton, more to come
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 21 Oct 2023 01:05:34 +0700 |
parents | 6a09fe5dc99b |
children | 51ee41c1d8ed |
rev | line source |
---|---|
733
07c755e65a4a
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
714
diff
changeset
|
1 import std/tables |
07c755e65a4a
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
714
diff
changeset
|
2 |
578 | 3 import semicongine |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
559
diff
changeset
|
4 |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
5 |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
6 let |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
7 sampler = Sampler( |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
8 magnification: VK_FILTER_NEAREST, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
9 minification: VK_FILTER_NEAREST, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
10 wrapModeS: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
11 wrapModeT: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
12 ) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
13 (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
14 mat = Material( |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
15 name: "mat", |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
16 textures: { |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
17 "my_little_texture": Texture(image: Image(width: 5, height: 5, imagedata: @[ |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
18 R, R, R, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
19 R, R, W, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
20 R, W, W, W, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
21 R, R, W, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
22 R, R, R, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
23 ]), sampler: sampler) |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
24 }.toTable |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
25 ) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
26 mat2 = Material( |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
27 name: "mat2", |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
28 textures: { |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
29 "my_little_texture": Texture(image: Image(width: 5, height: 5, imagedata: @[ |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
30 R, W, R, W, R, |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
31 W, R, W, R, W, |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
32 R, W, R, W, R, |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
33 W, R, W, R, W, |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
34 R, W, R, W, R, |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
35 ]), sampler: sampler) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
36 }.toTable |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
37 ) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
38 mat3 = Material( |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
39 name: "mat3", |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
40 constants: { |
791
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
41 "color": toGPUValue(@[newVec4f(0, 1, 0, 1)]) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
42 }.toTable |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
43 ) |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
44 |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
45 proc scene_different_mesh_types(): seq[Mesh] = |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
46 @[ |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
47 newMesh( |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
48 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
672 | 49 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)], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
50 material=mat, |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
51 transform=translate(-0.7, -0.5), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
52 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
53 newMesh( |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
54 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], |
672 | 55 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)], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
56 material=mat, |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
57 transform=translate(0, -0.5), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
58 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
59 newMesh( |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
60 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], |
672 | 61 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)], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
62 indices=[[0'u16, 2'u16, 1'u16]], |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
63 material=mat2, |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
64 transform=translate(0.7, -0.5), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
65 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
66 newMesh( |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
67 positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], |
672 | 68 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)], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
69 indices=[[0'u16, 2'u16, 1'u16]], |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
70 material=mat2, |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
71 transform=translate(-0.7, 0.5), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
72 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
73 newMesh( |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
74 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
672 | 75 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)], |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
76 indices=[[0'u32, 2'u32, 1'u32]], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
77 autoResize=false, |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
78 material=mat2, |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
79 transform=translate(0, 0.5), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
80 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
81 newMesh( |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
82 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
83 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)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
84 indices=[[0'u32, 2'u32, 1'u32]], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
85 autoResize=false, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
86 material=mat2, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
87 transform=translate(0.7, 0.5), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
88 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
89 ] |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
90 |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
91 proc scene_simple(): seq[Mesh] = |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
92 @[ |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
93 newMesh( |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
94 positions=[newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
95 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)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
96 material=mat, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
97 transform=translate(0.4, 0.4), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
98 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
99 newMesh( |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
100 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
101 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)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
102 material=mat, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
103 transform=translate(0.4, -0.4), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
104 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
105 newMesh( |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
106 positions=[newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
107 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)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
108 indices=[[0'u32, 1'u32, 2'u32]], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
109 autoResize=false, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
110 material=mat, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
111 transform=translate(-0.4, 0.4), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
112 ), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
113 newMesh( |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
114 positions=[newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
115 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)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
116 indices=[[0'u16, 1'u16, 2'u16]], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
117 instanceTransforms=[Unit4F32, Unit4F32], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
118 material=mat, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
119 transform=translate(-0.4, -0.4), |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
120 ) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
121 ] |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
122 |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
123 proc scene_primitives(): seq[Mesh] = |
586 | 124 var r = rect(color="ff0000") |
125 var t = tri(color="0000ff") | |
126 var c = circle(color="00ff00") | |
814 | 127 r.materials = @[mat] |
128 t.materials = @[mat] | |
129 c.materials = @[mat] | |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
130 r.transform = translate(newVec3f(0.5, -0.3)) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
131 t.transform = translate(newVec3f(0.3, 0.3)) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
132 c.transform = translate(newVec3f(-0.3, 0.1)) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
133 result = @[r, c, t] |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
134 |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
135 proc scene_flag(): seq[Mesh] = |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
136 @[ |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
137 newMesh( |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
138 positions=[newVec3f(-1.0, -1.0), newVec3f(1.0, -1.0), newVec3f(1.0, 1.0), newVec3f(-1.0, 1.0)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
139 colors=[newVec4f(-1, -1, 1, 1), newVec4f(1, -1, 1, 1), newVec4f(1, 1, 1, 1), newVec4f(-1, 1, 1, 1)], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
140 indices=[[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
141 material=mat, |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
142 transform=scale(0.5, 0.5) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
143 ) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
144 ] |
653
ac7dfbd56cc6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
652
diff
changeset
|
145 |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
146 proc scene_multi_material(): seq[Mesh] = |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
147 var |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
148 r1 = rect(color="ffffff") |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
149 r2 = rect(color="000000") |
814 | 150 r1.materials = @[mat] |
151 r2.materials = @[mat3] | |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
152 r1.transform = translate(newVec3f(-0.5)) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
153 r2.transform = translate(newVec3f(+0.5)) |
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
154 result = @[r1, r2] |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
155 |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
156 proc main() = |
588 | 157 var engine = initEngine("Test") |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
158 |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
159 # INIT RENDERER: |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
160 const |
785
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
161 shaderConfiguration1 = createShaderConfiguration( |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
777
diff
changeset
|
162 inputs=[ |
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
777
diff
changeset
|
163 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
777
diff
changeset
|
164 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
165 attr[Mat4]("transform", perInstance=true), |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
777
diff
changeset
|
166 ], |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
167 intermediates=[ |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
168 attr[Vec4f]("outcolor"), |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
169 ], |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
777
diff
changeset
|
170 outputs=[attr[Vec4f]("color")], |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
171 samplers=[ |
795
4a15d94d9418
fix: remaining tests and an issue with updating uniforms
Sam <sam@basx.dev>
parents:
792
diff
changeset
|
172 attr[Texture]("my_little_texture") |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
173 ], |
791
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
174 vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", |
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
175 fragmentCode="color = texture(my_little_texture, outcolor.xy) * 0.5 + outcolor * 0.5;", |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
176 ) |
785
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
177 shaderConfiguration2 = createShaderConfiguration( |
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
178 inputs=[ |
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
179 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
180 attr[Mat4]("transform", perInstance=true), |
785
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
181 ], |
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
182 intermediates=[attr[Vec4f]("outcolor")], |
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
183 outputs=[attr[Vec4f]("color")], |
791
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
184 uniforms=[attr[Vec4f]("color", arrayCount=1)], |
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
185 vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", |
788
2d8a92171c9e
add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents:
787
diff
changeset
|
186 fragmentCode="color = outcolor;", |
785
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
187 ) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
188 engine.initRenderer({ |
791
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
189 "mat": shaderConfiguration1, |
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
190 "mat2": shaderConfiguration1, |
43432dad4797
did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents:
790
diff
changeset
|
191 "mat3": shaderConfiguration2, |
805 | 192 }) |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
193 |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
194 # INIT SCENES |
650
be6e0f89645a
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:
649
diff
changeset
|
195 var scenes = [ |
789 | 196 Scene(name: "simple", meshes: scene_simple()), |
197 Scene(name: "different mesh types", meshes: scene_different_mesh_types()), | |
198 Scene(name: "primitives", meshes: scene_primitives()), | |
199 Scene(name: "flag", meshes: scene_flag()), | |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
200 Scene(name: "multimaterial", meshes: scene_multi_material()), |
650
be6e0f89645a
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:
649
diff
changeset
|
201 ] |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
202 |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
203 for scene in scenes.mitems: |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
204 engine.addScene(scene) |
570 | 205 |
576 | 206 # MAINLOOP |
572
9f1de117aaca
did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents:
570
diff
changeset
|
207 echo "Setup successfull, start rendering" |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
208 for i in 0 ..< 3: |
650
be6e0f89645a
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:
649
diff
changeset
|
209 for scene in scenes.mitems: |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
786
diff
changeset
|
210 echo "rendering scene ", scene.name |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
211 for i in 0 ..< 1000: |
607 | 212 if engine.updateInputs() != Running or engine.keyIsDown(Escape): |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
213 engine.destroy() |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
214 return |
592
cda5874a8454
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
590
diff
changeset
|
215 engine.renderScene(scene) |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
216 echo "Rendered ", engine.framesRendered, " frames" |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
217 echo "Processed ", engine.eventsProcessed, " events" |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
574
diff
changeset
|
218 |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
574
diff
changeset
|
219 # cleanup |
557 | 220 echo "Start cleanup" |
588 | 221 engine.destroy() |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
222 |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
223 when isMainModule: |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
224 main() |