Mercurial > games > semicongine
annotate tests/test_vulkan_wrapper.nim @ 325:0c3f4f6f1aa2
fix: make stuff halfway working
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 21 Aug 2023 00:17:16 +0700 |
parents | cbfe96272205 |
children | 4ec852355750 |
rev | line source |
---|---|
272
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
253
diff
changeset
|
1 import std/tables |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
253
diff
changeset
|
2 |
117 | 3 import semicongine |
99
4deffc94484a
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
98
diff
changeset
|
4 |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
5 |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
6 let |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
7 sampler = Sampler( |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
8 magnification: VK_FILTER_NEAREST, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
9 minification: VK_FILTER_NEAREST, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
10 wrapModeS: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
11 wrapModeT: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
12 ) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
13 (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
14 mat = Material( |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
15 name: "mat", |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
16 materialType: "my_material", |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
17 textures: { |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
18 "my_little_texture": Texture(image: Image(width: 5, height: 5, imagedata: @[ |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
19 R, R, R, R, R, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
20 R, R, W, R, R, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
21 R, W, W, W, R, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
22 R, R, W, R, R, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
23 R, R, R, R, R, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
24 ]), sampler: sampler) |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
25 }.toTable |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
26 ) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
27 mat2 = Material( |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
28 name: "mat2", |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
29 materialType: "my_material", |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
30 textures: { |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
31 "my_little_texture": Texture(image: Image(width: 5, height: 5, imagedata: @[ |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
32 R, W, R, W, R, |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
33 W, R, W, R, W, |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
34 R, W, R, W, R, |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
35 W, R, W, R, W, |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
36 R, W, R, W, R, |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
37 ]), sampler: sampler) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
38 }.toTable |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
39 ) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
40 mat3 = Material( |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
41 name: "mat3", |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
42 materialType: "my_special_material", |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
43 constants: { |
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
44 "color": toGPUValue(newVec4f(0.5, 0.5, 0)) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
45 }.toTable |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
46 ) |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
47 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
48 proc scene_different_mesh_types(): Entity = |
302 | 49 result = newEntity("root", [], |
50 newEntity("triangle1", {"mesh": Component(newMesh( | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
51 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
211 | 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)], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
53 material=mat, |
302 | 54 ))}), |
55 newEntity("triangle1b", {"mesh": Component(newMesh( | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
56 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], |
211 | 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)], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
58 material=mat, |
302 | 59 ))}), |
60 newEntity("triangle2a", {"mesh": Component(newMesh( | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
61 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], |
211 | 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)], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
63 indices=[[0'u16, 2'u16, 1'u16]], |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
64 material=mat2, |
302 | 65 ))}), |
66 newEntity("triangle2b", {"mesh": Component(newMesh( | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
67 positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], |
211 | 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)], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
69 indices=[[0'u16, 2'u16, 1'u16]], |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
70 material=mat2, |
302 | 71 ))}), |
72 newEntity("triangle3a", {"mesh": Component(newMesh( | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
73 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
211 | 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)], |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
75 indices=[[0'u32, 2'u32, 1'u32]], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
76 autoResize=false, |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
77 material=mat2, |
302 | 78 ))}), |
79 newEntity("triangle3b", {"mesh": Component(newMesh( | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
80 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], |
211 | 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)], |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
82 indices=[[0'u32, 2'u32, 1'u32]], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
83 autoResize=false, |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
84 material=mat2, |
302 | 85 ))}), |
113
7b695fb335ed
did: first final implementation of scene-graph <-> pipeline connection, not working yet
Sam <sam@basx.dev>
parents:
112
diff
changeset
|
86 ) |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
87 for mesh in allComponentsOfType[Mesh](result): |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
88 mesh.setInstanceData("translate", @[newVec3f()]) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
89 result[0]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(-0.6, -0.6)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
90 result[1]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(-0.6, 0.6)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
91 result[2]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(0.6, -0.6)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
92 result[3]["mesh", Mesh()].updateInstanceData("translate", @[newVec3f(0.6, 0.6)]) |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
93 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
94 proc scene_simple(): Entity = |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
95 var mymesh1 = newMesh( |
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
96 positions=[newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], |
211 | 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)], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
98 material=mat, |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
99 ) |
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
100 var mymesh2 = newMesh( |
123
55be3579dc30
did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents:
122
diff
changeset
|
101 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], |
211 | 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)], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
103 material=mat, |
123
55be3579dc30
did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents:
122
diff
changeset
|
104 ) |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
105 var mymesh3 = newMesh( |
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
106 positions=[newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], |
211 | 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)], |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
108 indices=[[0'u32, 1'u32, 2'u32]], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
109 autoResize=false, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
110 material=mat, |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
111 ) |
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
112 var mymesh4 = newMesh( |
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
113 positions=[newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], |
211 | 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)], |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
115 indices=[[0'u16, 1'u16, 2'u16]], |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
116 instanceCount=2, |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
117 material=mat, |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
118 ) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
119 mymesh1.setInstanceData("translate", @[newVec3f( 0.4, 0.4)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
120 mymesh2.setInstanceData("translate", @[newVec3f( 0.4, -0.4)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
121 mymesh3.setInstanceData("translate", @[newVec3f(-0.4, -0.4)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
122 mymesh4.setInstanceData("translate", @[newVec3f(-0.4, 0.4), newVec3f(0.0, 0.0)]) |
302 | 123 result = newEntity("root", [], newEntity("triangle", {"mesh1": Component(mymesh4), "mesh2": Component(mymesh3), "mesh3": Component(mymesh2), "mesh4": Component(mymesh1)})) |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
124 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
125 proc scene_primitives(): Entity = |
125 | 126 var r = rect(color="ff0000") |
127 var t = tri(color="0000ff") | |
128 var c = circle(color="00ff00") | |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
129 r.material = mat |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
130 t.material = mat |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
131 c.material = mat |
226 | 132 |
192
659992f14dd6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
191
diff
changeset
|
133 r.setInstanceData("translate", @[newVec3f(0.5, -0.3)]) |
659992f14dd6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
191
diff
changeset
|
134 t.setInstanceData("translate", @[newVec3f(0.3, 0.3)]) |
659992f14dd6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
191
diff
changeset
|
135 c.setInstanceData("translate", @[newVec3f(-0.3, 0.1)]) |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
136 result = newEntity("root", {"mesh1": Component(t), "mesh2": Component(r), "mesh3": Component(c)}) |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
137 |
192
659992f14dd6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
191
diff
changeset
|
138 proc scene_flag(): Entity = |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
139 var r = rect(color="ffffff") |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
140 r.material = mat |
302 | 141 result = newEntity("root", {"mesh": Component(r)}) |
192
659992f14dd6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
191
diff
changeset
|
142 |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
143 proc scene_multi_material(): Entity = |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
144 var |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
145 r1 = rect(color="ffffff") |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
146 r2 = rect(color="000000") |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
147 r1.material = mat |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
148 r2.material = mat3 |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
149 r1.setInstanceData("translate", @[newVec3f(-0.5)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
150 r2.setInstanceData("translate", @[newVec3f(+0.5)]) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
151 result = newEntity("root", {"mesh1": Component(r1), "mesh2": Component(r2)}) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
152 |
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
153 proc main() = |
127 | 154 var engine = initEngine("Test") |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
155 |
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
156 # INIT RENDERER: |
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
157 const |
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
158 shaderConfiguration1 = createShaderConfiguration( |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
159 inputs=[ |
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
160 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
161 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
162 attr[Vec3f]("translate", perInstance=true), |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
163 attr[uint16]("materialIndex", perInstance=true), |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
164 ], |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
165 intermediates=[ |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
166 attr[Vec4f]("outcolor"), |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
167 attr[uint16]("materialIndexOut", noInterpolation=true), |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
168 ], |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
169 outputs=[attr[Vec4f]("color")], |
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
170 uniforms=[attr[float32]("time")], |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
171 samplers=[ |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
172 attr[Sampler2DType]("my_little_texture", arrayCount=2) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
173 ], |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
174 vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = color; materialIndexOut = materialIndex;""", |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
175 fragmentCode="color = texture(my_little_texture[materialIndexOut], outcolor.xy) * 0.5 + outcolor * 0.5;", |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
176 ) |
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
177 shaderConfiguration2 = createShaderConfiguration( |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
178 inputs=[ |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
179 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
180 attr[Vec3f]("translate", perInstance=true), |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
181 ], |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
182 intermediates=[attr[Vec4f]("outcolor")], |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
183 outputs=[attr[Vec4f]("color")], |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
184 uniforms=[attr[Vec4f]("color")], |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
185 vertexCode="""gl_Position = vec4(position + translate, 1.0); outcolor = Uniforms.color;""", |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
186 fragmentCode="color = outcolor;", |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
187 ) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
188 engine.initRenderer({ |
324
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
189 "my_material": shaderConfiguration1, |
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
323
diff
changeset
|
190 "my_special_material": shaderConfiguration2, |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
191 }.toTable) |
124
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
Sam <sam@basx.dev>
parents:
123
diff
changeset
|
192 |
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
193 # INIT SCENES |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
188
diff
changeset
|
194 var scenes = [ |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
195 newScene("simple", scene_simple(), transformAttribute=""), |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
196 newScene("different mesh types", scene_different_mesh_types(), transformAttribute=""), |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
197 newScene("primitives", scene_primitives(), transformAttribute=""), |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
198 newScene("flag", scene_multi_material(), transformAttribute=""), |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
188
diff
changeset
|
199 ] |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
200 |
325 | 201 scenes[3].addShaderGlobal("color", newVec4f(1, 0, 1)) |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
202 for scene in scenes.mitems: |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
188
diff
changeset
|
203 scene.addShaderGlobal("time", 0.0'f32) |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
204 engine.addScene(scene) |
109 | 205 |
325 | 206 |
115 | 207 # MAINLOOP |
111
6fd10b7e2d6a
did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents:
109
diff
changeset
|
208 echo "Setup successfull, start rendering" |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
209 for i in 0 ..< 3: |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
188
diff
changeset
|
210 for scene in scenes.mitems: |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
211 for i in 0 ..< 1000: |
146 | 212 if engine.updateInputs() != Running or engine.keyIsDown(Escape): |
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
213 engine.destroy() |
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
214 return |
190
8f2eaf0d2808
add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms
Sam <sam@basx.dev>
parents:
189
diff
changeset
|
215 setShaderGlobal(scene, "time", getShaderGlobal[float32](scene, "time") + 0.0005'f) |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
216 engine.renderScene(scene) |
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
217 echo "Rendered ", engine.framesRendered, " frames" |
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
218 echo "Processed ", engine.eventsProcessed, " events" |
114
056e08dfad10
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
113
diff
changeset
|
219 |
056e08dfad10
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
113
diff
changeset
|
220 # cleanup |
96 | 221 echo "Start cleanup" |
127 | 222 engine.destroy() |
129
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
223 |
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
224 when isMainModule: |
15d37022625c
add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
225 main() |