Mercurial > games > semicongine
annotate tests/test_vulkan_wrapper.nim @ 784:fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 19 Aug 2023 22:24:06 +0700 |
parents | 893ec0fbfd44 |
children | cbfe96272205 |
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 materialType: "my_material", |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
17 textures: { |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
18 "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
|
19 R, R, R, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
20 R, R, W, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
21 R, W, W, W, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
22 R, R, W, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
23 R, R, R, R, R, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
24 ]), sampler: sampler) |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
25 }.toTable |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
26 ) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
27 mat2 = Material( |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
28 name: "mat2", |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
29 materialType: "my_material", |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
30 textures: { |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
31 "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
|
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 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
|
36 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
|
37 ]), sampler: sampler) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
38 }.toTable |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
39 ) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
40 mat3 = Material( |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
41 name: "mat3", |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
42 materialType: "my_special_material", |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
43 constants: { |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
44 "colors": toGPUValue(newVec4f(0.5, 0.5, 0)) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
45 }.toTable |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
46 ) |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
47 |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
48 proc scene_different_mesh_types(): Entity = |
763 | 49 result = newEntity("root", [], |
50 newEntity("triangle1", {"mesh": Component(newMesh( | |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
51 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
672 | 52 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
|
53 material=mat, |
763 | 54 ))}), |
55 newEntity("triangle1b", {"mesh": Component(newMesh( | |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
56 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], |
672 | 57 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
|
58 material=mat, |
763 | 59 ))}), |
60 newEntity("triangle2a", {"mesh": Component(newMesh( | |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
61 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], |
672 | 62 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
|
63 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
|
64 material=mat2, |
763 | 65 ))}), |
66 newEntity("triangle2b", {"mesh": Component(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, |
763 | 71 ))}), |
72 newEntity("triangle3a", {"mesh": Component(newMesh( | |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
73 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
672 | 74 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
|
75 indices=[[0'u32, 2'u32, 1'u32]], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
76 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
|
77 material=mat2, |
763 | 78 ))}), |
79 newEntity("triangle3b", {"mesh": Component(newMesh( | |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
80 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
672 | 81 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
|
82 indices=[[0'u32, 2'u32, 1'u32]], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
83 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
|
84 material=mat2, |
763 | 85 ))}), |
574
bbeec60e25ca
did: first final implementation of scene-graph <-> pipeline connection, not working yet
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
86 ) |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
87 for mesh in allComponentsOfType[Mesh](result): |
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
88 mesh.setInstanceData("translate", @[newVec3f()]) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
89 result[0]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(-0.6, -0.6)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
90 result[1]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(-0.6, 0.6)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
91 result[2]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(0.6, -0.6)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
92 result[3]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(0.6, 0.6)]) |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
93 |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
94 proc scene_simple(): Entity = |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
95 var mymesh1 = newMesh( |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
96 positions=[newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], |
672 | 97 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
|
98 material=mat, |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
99 ) |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
100 var mymesh2 = newMesh( |
584
9e7bcc8e0e52
did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents:
583
diff
changeset
|
101 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
672 | 102 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
|
103 material=mat, |
584
9e7bcc8e0e52
did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents:
583
diff
changeset
|
104 ) |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
105 var mymesh3 = newMesh( |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
106 positions=[newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], |
672 | 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)], |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
108 indices=[[0'u32, 1'u32, 2'u32]], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
109 autoResize=false, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
110 material=mat, |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
111 ) |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
112 var mymesh4 = newMesh( |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
113 positions=[newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], |
672 | 114 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)], |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
115 indices=[[0'u16, 1'u16, 2'u16]], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
116 instanceCount=2, |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
117 material=mat, |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
118 ) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
119 mymesh1.setInstanceData("translate", @[newVec3f( 0.4, 0.4)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
120 mymesh2.setInstanceData("translate", @[newVec3f( 0.4, -0.4)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
121 mymesh3.setInstanceData("translate", @[newVec3f(-0.4, -0.4)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
122 mymesh4.setInstanceData("translate", @[newVec3f(-0.4, 0.4), newVec3f(0.0, 0.0)]) |
763 | 123 result = newEntity("root", [], newEntity("triangle", {"mesh1": Component(mymesh4), "mesh2": Component(mymesh3), "mesh3": Component(mymesh2), "mesh4": Component(mymesh1)})) |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
124 |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
125 proc scene_primitives(): Entity = |
586 | 126 var r = rect(color="ff0000") |
127 var t = tri(color="0000ff") | |
128 var c = circle(color="00ff00") | |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
129 r.material = mat |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
130 t.material = mat |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
131 c.material = mat |
687 | 132 |
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
|
133 r.setInstanceData("translate", @[newVec3f(0.5, -0.3)]) |
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
|
134 t.setInstanceData("translate", @[newVec3f(0.3, 0.3)]) |
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
|
135 c.setInstanceData("translate", @[newVec3f(-0.3, 0.1)]) |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
136 result = newEntity("root", {"mesh1": Component(t), "mesh2": Component(r), "mesh3": Component(c)}) |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
137 |
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
|
138 proc scene_flag(): Entity = |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
139 var r = rect(color="ffffff") |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
140 r.material = mat |
763 | 141 result = newEntity("root", {"mesh": Component(r)}) |
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
|
142 |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
143 proc scene_multi_material(): Entity = |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
144 var |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
145 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
|
146 r2 = rect(color="000000") |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
147 r1.material = mat |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
148 r2.material = mat3 |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
149 r1.setInstanceData("translate", @[newVec3f(-0.5)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
150 r2.setInstanceData("translate", @[newVec3f(+0.5)]) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
151 result = newEntity("root", {"mesh1": Component(r1), "mesh2": Component(r2)}) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
152 |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
153 proc main() = |
588 | 154 var engine = initEngine("Test") |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
155 |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
156 # INIT RENDERER: |
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
157 const |
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
|
158 shaderConfiguration = createShaderConfiguration( |
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
|
159 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
|
160 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
|
161 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
162 attr[Vec3f]("translate", perInstance=true), |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
163 attr[uint16]("materialIndex", 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
|
164 ], |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
165 intermediates=[ |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
166 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
|
167 attr[uint16]("materialIndexOut", noInterpolation=true), |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
168 ], |
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
|
169 outputs=[attr[Vec4f]("color")], |
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 uniforms=[attr[float32]("time")], |
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=[ |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
172 attr[Sampler2DType]("my_little_texture", arrayCount=2) |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
173 ], |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
174 vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = color; materialIndexOut = materialIndex;""", |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
175 fragmentCode="color = texture(my_little_texture[materialIndexOut], 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 ) |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
177 engine.initRenderer({ |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
178 "my_material": shaderConfiguration, |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
179 "my_special_material": shaderConfiguration, |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
180 }.toTable) |
585
2df00e84757d
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
584
diff
changeset
|
181 |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
182 # 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
|
183 var scenes = [ |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
184 newScene("simple", scene_simple(), transformAttribute=""), |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
185 newScene("different mesh types", scene_different_mesh_types(), transformAttribute=""), |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
186 newScene("primitives", scene_primitives(), transformAttribute=""), |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
187 newScene("flag", scene_multi_material(), transformAttribute=""), |
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
|
188 ] |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
189 |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
190 for scene in scenes.mitems: |
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
|
191 scene.addShaderGlobal("time", 0.0'f32) |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
192 engine.addScene(scene) |
570 | 193 |
576 | 194 # MAINLOOP |
572
9f1de117aaca
did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents:
570
diff
changeset
|
195 echo "Setup successfull, start rendering" |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
196 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
|
197 for scene in scenes.mitems: |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
198 for i in 0 ..< 1000: |
607 | 199 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
|
200 engine.destroy() |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
201 return |
651
164bf40c664f
add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms
Sam <sam@basx.dev>
parents:
650
diff
changeset
|
202 setShaderGlobal(scene, "time", getShaderGlobal[float32](scene, "time") + 0.0005'f) |
592
cda5874a8454
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
590
diff
changeset
|
203 engine.renderScene(scene) |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
204 echo "Rendered ", engine.framesRendered, " frames" |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
205 echo "Processed ", engine.eventsProcessed, " events" |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
574
diff
changeset
|
206 |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
574
diff
changeset
|
207 # cleanup |
557 | 208 echo "Start cleanup" |
588 | 209 engine.destroy() |
590
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
210 |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
211 when isMainModule: |
1edf3e16144e
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
589
diff
changeset
|
212 main() |