Mercurial > games > semicongine
annotate tests/test_vulkan_wrapper.nim @ 918:71559c2468ea
add: shader compiler tool
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 20 Mar 2024 18:47:42 +0700 |
parents | 11a55a45aba2 |
children | 6406766a222d |
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]) |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
14 mat = SINGLE_TEXTURE_MATERIAL.initMaterialData( |
881 | 15 name = "mat", |
16 attributes = { | |
17 "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ | |
783
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, |
881 | 23 ]), sampler: sampler)]) |
24 }.toTable | |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
25 ) |
837 | 26 Mat2Type = MaterialType( |
27 name: "single texture material 2", | |
845
19b5051d6eb7
fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents:
837
diff
changeset
|
28 vertexAttributes: { |
837 | 29 "position": Vec3F32, |
30 "uv": Vec2F32, | |
31 }.toTable, | |
32 attributes: {"baseTexture": TextureType}.toTable | |
33 ) | |
34 mat2 = Mat2Type.initMaterialData( | |
881 | 35 name = "mat2", |
36 attributes = { | |
37 "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ | |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 R, W, R, W, R, |
881 | 43 ]), sampler: sampler)]) |
44 }.toTable | |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
45 ) |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
46 mat3 = SINGLE_COLOR_MATERIAL.initMaterialData( |
881 | 47 name = "mat3", |
48 attributes = { | |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
49 "color": initDataList(@[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
|
50 }.toTable |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
51 ) |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
52 |
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
|
53 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
|
54 @[ |
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
|
55 newMesh( |
881 | 56 positions = [newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
57 uvs = [newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], | |
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)], | |
59 material = mat, | |
60 transform = translate(-0.7, -0.5), | |
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
|
61 ), |
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
|
62 newMesh( |
881 | 63 positions = [newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], |
64 uvs = [newVec2f(0.0, -0.4), newVec2f(0.4, 0.4), newVec2f(-0.4, 0.5)], | |
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)], | |
66 material = mat, | |
67 transform = translate(0, -0.5), | |
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
|
68 ), |
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
|
69 newMesh( |
881 | 70 positions = [newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], |
71 uvs = [newVec2f(0.0, 0.5), newVec2f(0.5, -0.5), newVec2f(-0.5, -0.5)], | |
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)], | |
73 indices = [[0'u16, 2'u16, 1'u16]], | |
74 material = mat2, | |
75 transform = translate(0.7, -0.5), | |
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
|
76 ), |
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
|
77 newMesh( |
881 | 78 positions = [newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], |
79 uvs = [newVec2f(0.0, 0.4), newVec2f(0.4, -0.4), newVec2f(-0.4, -0.4)], | |
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)], | |
81 indices = [[0'u16, 2'u16, 1'u16]], | |
82 material = mat2, | |
83 transform = translate(-0.7, 0.5), | |
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
|
84 ), |
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 newMesh( |
881 | 86 positions = [newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
87 uvs = [newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], | |
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)], | |
89 indices = [[0'u32, 2'u32, 1'u32]], | |
90 autoResize = false, | |
91 material = mat2, | |
92 transform = translate(0, 0.5), | |
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
|
93 ), |
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 newMesh( |
881 | 95 positions = [newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
96 uvs = [newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], | |
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)], | |
98 indices = [[0'u32, 2'u32, 1'u32]], | |
99 autoResize = false, | |
100 material = mat2, | |
101 transform = translate(0.7, 0.5), | |
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
|
102 ), |
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 ] |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
104 |
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
|
105 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
|
106 @[ |
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 newMesh( |
881 | 108 positions = [newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], |
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)], | |
110 uvs = [newVec2f(0.0, -0.3), newVec2f(0.3, 0.3), newVec2f(-0.3, 0.3)], | |
111 material = mat, | |
112 transform = translate(0.4, 0.4), | |
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
|
113 ), |
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 newMesh( |
881 | 115 positions = [newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
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)], | |
117 uvs = [newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], | |
118 material = mat, | |
119 transform = translate(0.4, -0.4), | |
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
|
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 newMesh( |
881 | 122 positions = [newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], |
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)], | |
124 uvs = [newVec2f(0.0, -0.6), newVec2f(0.6, 0.6), newVec2f(-0.6, 0.6)], | |
125 indices = [[0'u32, 1'u32, 2'u32]], | |
126 autoResize = false, | |
127 material = mat, | |
128 transform = translate(-0.4, 0.4), | |
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
|
129 ), |
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 newMesh( |
881 | 131 positions = [newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], |
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)], | |
133 uvs = [newVec2f(0.0, -0.8), newVec2f(0.8, 0.8), newVec2f(-0.8, 0.8)], | |
134 indices = [[0'u16, 1'u16, 2'u16]], | |
135 instanceTransforms = [Unit4F32, Unit4F32], | |
136 material = mat, | |
137 transform = translate(-0.4, -0.4), | |
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
|
138 ) |
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 ] |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
140 |
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
|
141 proc scene_primitives(): seq[Mesh] = |
881 | 142 var r = rect(color = "ff0000") |
143 var t = tri(color = "0000ff") | |
144 var c = circle(color = "00ff00") | |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
145 r.material = mat |
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
146 t.material = mat |
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
147 c.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
|
148 r.transform = translate(newVec3f(0.5, -0.3)) |
881 | 149 t.transform = translate(newVec3f(0.3, 0.3)) |
150 c.transform = translate(newVec3f(-0.3, 0.1)) | |
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
|
151 result = @[r, c, t] |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
152 |
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
|
153 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
|
154 @[ |
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
|
155 newMesh( |
881 | 156 positions = [newVec3f(-1.0, -1.0), newVec3f(1.0, -1.0), newVec3f(1.0, 1.0), newVec3f(-1.0, 1.0)], |
157 uvs = [newVec2f(-1.0, -1.0), newVec2f(1.0, -1.0), newVec2f(1.0, 1.0), newVec2f(-1.0, 1.0)], | |
158 colors = [newVec4f(-1, -1, 1, 1), newVec4f(1, -1, 1, 1), newVec4f(1, 1, 1, 1), newVec4f(-1, 1, 1, 1)], | |
159 indices = [[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], | |
160 material = mat, | |
161 transform = scale(0.5, 0.5) | |
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
|
162 ) |
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
|
163 ] |
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
|
164 |
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 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
|
166 var |
881 | 167 r1 = rect(color = "ffffff") |
168 r2 = rect(color = "000000") | |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
169 r1.material = mat |
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
170 r2.material = 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
|
171 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
|
172 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
|
173 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
|
174 |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
175 proc main() = |
588 | 176 var engine = initEngine("Test") |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
177 |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
178 # INIT RENDERER: |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
179 const |
785
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
180 shaderConfiguration1 = createShaderConfiguration( |
881 | 181 inputs = [ |
182 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | |
183 attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), | |
184 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
|
185 ], |
881 | 186 intermediates = [ |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
187 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
|
188 ], |
881 | 189 outputs = [attr[Vec4f]("color")], |
190 samplers = [ | |
832
388c4b35a6e3
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
829
diff
changeset
|
191 attr[Texture]("baseTexture") |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
192 ], |
881 | 193 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", |
194 fragmentCode = "color = texture(baseTexture, 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
|
195 ) |
785
1880ab140165
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
196 shaderConfiguration2 = createShaderConfiguration( |
881 | 197 inputs = [ |
198 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | |
199 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
|
200 ], |
881 | 201 intermediates = [attr[Vec4f]("outcolor")], |
202 outputs = [attr[Vec4f]("color")], | |
203 uniforms = [attr[Vec4f]("color", arrayCount = 1)], | |
204 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", | |
205 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
|
206 ) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
207 engine.initRenderer({ |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
208 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, |
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
209 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, |
837 | 210 Mat2Type: shaderConfiguration1, |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
211 SINGLE_COLOR_MATERIAL: shaderConfiguration2, |
805 | 212 }) |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
213 |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
214 # 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
|
215 var scenes = [ |
789 | 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()), | |
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
|
220 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
|
221 ] |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
222 |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
223 for scene in scenes.mitems: |
829
0a0402d1d729
fix: first example to work correctly with new material system
Sam <sam@basx.dev>
parents:
814
diff
changeset
|
224 engine.loadScene(scene) |
570 | 225 |
576 | 226 # MAINLOOP |
572
9f1de117aaca
did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents:
570
diff
changeset
|
227 echo "Setup successfull, start rendering" |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
228 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
|
229 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
|
230 echo "rendering scene ", scene.name |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
231 for i in 0 ..< 1000: |
607 | 232 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
|
233 engine.destroy() |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
234 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
|
235 engine.renderScene(scene) |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
236 echo "Rendered ", engine.framesRendered, " frames" |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
237 echo "Processed ", engine.eventsProcessed, " events" |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
574
diff
changeset
|
238 |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
574
diff
changeset
|
239 # cleanup |
557 | 240 echo "Start cleanup" |
588 | 241 engine.destroy() |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
242 |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
243 when isMainModule: |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
244 main() |