Mercurial > games > semicongine
comparison tests/test_vulkan_wrapper.nim @ 420:91e018270832
fix: all tests (once more)
| author | Sam <sam@basx.dev> |
|---|---|
| date | Mon, 29 Jan 2024 00:19:35 +0700 |
| parents | eaf084ba80e5 |
| children | 6406766a222d |
comparison
equal
deleted
inserted
replaced
| 419:18e5443e4f83 | 420:91e018270832 |
|---|---|
| 10 wrapModeS: VK_SAMPLER_ADDRESS_MODE_REPEAT, | 10 wrapModeS: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
| 11 wrapModeT: VK_SAMPLER_ADDRESS_MODE_REPEAT, | 11 wrapModeT: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
| 12 ) | 12 ) |
| 13 (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) | 13 (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) |
| 14 mat = SINGLE_TEXTURE_MATERIAL.initMaterialData( | 14 mat = SINGLE_TEXTURE_MATERIAL.initMaterialData( |
| 15 name="mat", | 15 name = "mat", |
| 16 attributes={ | 16 attributes = { |
| 17 "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ | 17 "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ |
| 18 R, R, R, R, R, | 18 R, R, R, R, R, |
| 19 R, R, W, R, R, | 19 R, R, W, R, R, |
| 20 R, W, W, W, R, | 20 R, W, W, W, R, |
| 21 R, R, W, R, R, | 21 R, R, W, R, R, |
| 22 R, R, R, R, R, | 22 R, R, R, R, R, |
| 23 ]), sampler: sampler)]) | 23 ]), sampler: sampler)]) |
| 24 }.toTable | 24 }.toTable |
| 25 ) | 25 ) |
| 26 Mat2Type = MaterialType( | 26 Mat2Type = MaterialType( |
| 27 name: "single texture material 2", | 27 name: "single texture material 2", |
| 28 vertexAttributes: { | 28 vertexAttributes: { |
| 29 "position": Vec3F32, | 29 "position": Vec3F32, |
| 30 "uv": Vec2F32, | 30 "uv": Vec2F32, |
| 31 }.toTable, | 31 }.toTable, |
| 32 attributes: {"baseTexture": TextureType}.toTable | 32 attributes: {"baseTexture": TextureType}.toTable |
| 33 ) | 33 ) |
| 34 mat2 = Mat2Type.initMaterialData( | 34 mat2 = Mat2Type.initMaterialData( |
| 35 name="mat2", | 35 name = "mat2", |
| 36 attributes={ | 36 attributes = { |
| 37 "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ | 37 "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ |
| 38 R, W, R, W, R, | 38 R, W, R, W, R, |
| 39 W, R, W, R, W, | 39 W, R, W, R, W, |
| 40 R, W, R, W, R, | 40 R, W, R, W, R, |
| 41 W, R, W, R, W, | 41 W, R, W, R, W, |
| 42 R, W, R, W, R, | 42 R, W, R, W, R, |
| 43 ]), sampler: sampler)]) | 43 ]), sampler: sampler)]) |
| 44 }.toTable | 44 }.toTable |
| 45 ) | 45 ) |
| 46 mat3 = SINGLE_COLOR_MATERIAL.initMaterialData( | 46 mat3 = SINGLE_COLOR_MATERIAL.initMaterialData( |
| 47 name="mat3", | 47 name = "mat3", |
| 48 attributes={ | 48 attributes = { |
| 49 "color": initDataList(@[newVec4f(0, 1, 0, 1)]) | 49 "color": initDataList(@[newVec4f(0, 1, 0, 1)]) |
| 50 }.toTable | 50 }.toTable |
| 51 ) | 51 ) |
| 52 | 52 |
| 53 proc scene_different_mesh_types(): seq[Mesh] = | 53 proc scene_different_mesh_types(): seq[Mesh] = |
| 54 @[ | 54 @[ |
| 55 newMesh( | 55 newMesh( |
| 56 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], | 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)], | 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)], | 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, | 59 material = mat, |
| 60 transform=translate(-0.7, -0.5), | 60 transform = translate(-0.7, -0.5), |
| 61 ), | 61 ), |
| 62 newMesh( | 62 newMesh( |
| 63 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], | 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)], | 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)], | 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, | 66 material = mat, |
| 67 transform=translate(0, -0.5), | 67 transform = translate(0, -0.5), |
| 68 ), | 68 ), |
| 69 newMesh( | 69 newMesh( |
| 70 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], | 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)], | 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)], | 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]], | 73 indices = [[0'u16, 2'u16, 1'u16]], |
| 74 material=mat2, | 74 material = mat2, |
| 75 transform=translate(0.7, -0.5), | 75 transform = translate(0.7, -0.5), |
| 76 ), | 76 ), |
| 77 newMesh( | 77 newMesh( |
| 78 positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], | 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)], | 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)], | 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]], | 81 indices = [[0'u16, 2'u16, 1'u16]], |
| 82 material=mat2, | 82 material = mat2, |
| 83 transform=translate(-0.7, 0.5), | 83 transform = translate(-0.7, 0.5), |
| 84 ), | 84 ), |
| 85 newMesh( | 85 newMesh( |
| 86 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], | 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)], | 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)], | 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]], | 89 indices = [[0'u32, 2'u32, 1'u32]], |
| 90 autoResize=false, | 90 autoResize = false, |
| 91 material=mat2, | 91 material = mat2, |
| 92 transform=translate(0, 0.5), | 92 transform = translate(0, 0.5), |
| 93 ), | 93 ), |
| 94 newMesh( | 94 newMesh( |
| 95 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], | 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)], | 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)], | 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]], | 98 indices = [[0'u32, 2'u32, 1'u32]], |
| 99 autoResize=false, | 99 autoResize = false, |
| 100 material=mat2, | 100 material = mat2, |
| 101 transform=translate(0.7, 0.5), | 101 transform = translate(0.7, 0.5), |
| 102 ), | 102 ), |
| 103 ] | 103 ] |
| 104 | 104 |
| 105 proc scene_simple(): seq[Mesh] = | 105 proc scene_simple(): seq[Mesh] = |
| 106 @[ | 106 @[ |
| 107 newMesh( | 107 newMesh( |
| 108 positions=[newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], | 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)], | 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)], | 110 uvs = [newVec2f(0.0, -0.3), newVec2f(0.3, 0.3), newVec2f(-0.3, 0.3)], |
| 111 material=mat, | 111 material = mat, |
| 112 transform=translate(0.4, 0.4), | 112 transform = translate(0.4, 0.4), |
| 113 ), | 113 ), |
| 114 newMesh( | 114 newMesh( |
| 115 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], | 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)], | 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)], | 117 uvs = [newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], |
| 118 material=mat, | 118 material = mat, |
| 119 transform=translate(0.4, -0.4), | 119 transform = translate(0.4, -0.4), |
| 120 ), | 120 ), |
| 121 newMesh( | 121 newMesh( |
| 122 positions=[newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], | 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)], | 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)], | 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]], | 125 indices = [[0'u32, 1'u32, 2'u32]], |
| 126 autoResize=false, | 126 autoResize = false, |
| 127 material=mat, | 127 material = mat, |
| 128 transform=translate(-0.4, 0.4), | 128 transform = translate(-0.4, 0.4), |
| 129 ), | 129 ), |
| 130 newMesh( | 130 newMesh( |
| 131 positions=[newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], | 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)], | 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)], | 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]], | 134 indices = [[0'u16, 1'u16, 2'u16]], |
| 135 instanceTransforms=[Unit4F32, Unit4F32], | 135 instanceTransforms = [Unit4F32, Unit4F32], |
| 136 material=mat, | 136 material = mat, |
| 137 transform=translate(-0.4, -0.4), | 137 transform = translate(-0.4, -0.4), |
| 138 ) | 138 ) |
| 139 ] | 139 ] |
| 140 | 140 |
| 141 proc scene_primitives(): seq[Mesh] = | 141 proc scene_primitives(): seq[Mesh] = |
| 142 var r = rect(color="ff0000") | 142 var r = rect(color = "ff0000") |
| 143 var t = tri(color="0000ff") | 143 var t = tri(color = "0000ff") |
| 144 var c = circle(color="00ff00") | 144 var c = circle(color = "00ff00") |
| 145 r.material = mat | 145 r.material = mat |
| 146 t.material = mat | 146 t.material = mat |
| 147 c.material = mat | 147 c.material = mat |
| 148 r.transform = translate(newVec3f(0.5, -0.3)) | 148 r.transform = translate(newVec3f(0.5, -0.3)) |
| 149 t.transform = translate(newVec3f(0.3, 0.3)) | 149 t.transform = translate(newVec3f(0.3, 0.3)) |
| 150 c.transform = translate(newVec3f(-0.3, 0.1)) | 150 c.transform = translate(newVec3f(-0.3, 0.1)) |
| 151 result = @[r, c, t] | 151 result = @[r, c, t] |
| 152 | 152 |
| 153 proc scene_flag(): seq[Mesh] = | 153 proc scene_flag(): seq[Mesh] = |
| 154 @[ | 154 @[ |
| 155 newMesh( | 155 newMesh( |
| 156 positions=[newVec3f(-1.0, -1.0), newVec3f(1.0, -1.0), newVec3f(1.0, 1.0), newVec3f(-1.0, 1.0)], | 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)], | 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)], | 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]], | 159 indices = [[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], |
| 160 material=mat, | 160 material = mat, |
| 161 transform=scale(0.5, 0.5) | 161 transform = scale(0.5, 0.5) |
| 162 ) | 162 ) |
| 163 ] | 163 ] |
| 164 | 164 |
| 165 proc scene_multi_material(): seq[Mesh] = | 165 proc scene_multi_material(): seq[Mesh] = |
| 166 var | 166 var |
| 167 r1 = rect(color="ffffff") | 167 r1 = rect(color = "ffffff") |
| 168 r2 = rect(color="000000") | 168 r2 = rect(color = "000000") |
| 169 r1.material = mat | 169 r1.material = mat |
| 170 r2.material = mat3 | 170 r2.material = mat3 |
| 171 r1.transform = translate(newVec3f(-0.5)) | 171 r1.transform = translate(newVec3f(-0.5)) |
| 172 r2.transform = translate(newVec3f(+0.5)) | 172 r2.transform = translate(newVec3f(+0.5)) |
| 173 result = @[r1, r2] | 173 result = @[r1, r2] |
| 176 var engine = initEngine("Test") | 176 var engine = initEngine("Test") |
| 177 | 177 |
| 178 # INIT RENDERER: | 178 # INIT RENDERER: |
| 179 const | 179 const |
| 180 shaderConfiguration1 = createShaderConfiguration( | 180 shaderConfiguration1 = createShaderConfiguration( |
| 181 inputs=[ | 181 inputs = [ |
| 182 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), | 182 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
| 183 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), | 183 attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), |
| 184 attr[Mat4]("transform", perInstance=true), | 184 attr[Mat4]("transform", perInstance = true), |
| 185 ], | 185 ], |
| 186 intermediates=[ | 186 intermediates = [ |
| 187 attr[Vec4f]("outcolor"), | 187 attr[Vec4f]("outcolor"), |
| 188 ], | 188 ], |
| 189 outputs=[attr[Vec4f]("color")], | 189 outputs = [attr[Vec4f]("color")], |
| 190 samplers=[ | 190 samplers = [ |
| 191 attr[Texture]("baseTexture") | 191 attr[Texture]("baseTexture") |
| 192 ], | 192 ], |
| 193 vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", | 193 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", |
| 194 fragmentCode="color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", | 194 fragmentCode = "color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", |
| 195 ) | 195 ) |
| 196 shaderConfiguration2 = createShaderConfiguration( | 196 shaderConfiguration2 = createShaderConfiguration( |
| 197 inputs=[ | 197 inputs = [ |
| 198 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), | 198 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
| 199 attr[Mat4]("transform", perInstance=true), | 199 attr[Mat4]("transform", perInstance = true), |
| 200 ], | 200 ], |
| 201 intermediates=[attr[Vec4f]("outcolor")], | 201 intermediates = [attr[Vec4f]("outcolor")], |
| 202 outputs=[attr[Vec4f]("color")], | 202 outputs = [attr[Vec4f]("color")], |
| 203 uniforms=[attr[Vec4f]("color", arrayCount=1)], | 203 uniforms = [attr[Vec4f]("color", arrayCount = 1)], |
| 204 vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", | 204 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", |
| 205 fragmentCode="color = outcolor;", | 205 fragmentCode = "color = outcolor;", |
| 206 ) | 206 ) |
| 207 engine.initRenderer({ | 207 engine.initRenderer({ |
| 208 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, | 208 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, |
| 209 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, | 209 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, |
| 210 Mat2Type: shaderConfiguration1, | 210 Mat2Type: shaderConfiguration1, |
