Mercurial > games > semicongine
annotate old_tests/test_vulkan_wrapper.nim @ 1497:56aa8fe70e9e
add: super suboptimal implementation to support per-frame descriptor sets
| author | sam <sam@basx.dev> | 
|---|---|
| date | Wed, 24 Sep 2025 23:55:36 +0700 | 
| parents | 6360c8d17ce0 | 
| children | 
| rev | line source | 
|---|---|
| 272 
bfcb41211c5b
add: final font-rendering, API changes fixed
 Sam <sam@basx.dev> parents: 
253diff
changeset | 1 import std/tables | 
| 
bfcb41211c5b
add: final font-rendering, API changes fixed
 Sam <sam@basx.dev> parents: 
253diff
changeset | 2 | 
| 117 | 3 import semicongine | 
| 99 
4deffc94484a
add: vertex and (initial) shader types and methods
 Sam <sam@basx.dev> parents: 
98diff
changeset | 4 | 
| 322 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 5 | 
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 6 let | 
| 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 7 sampler = Sampler( | 
| 322 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 8 magnification: VK_FILTER_NEAREST, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 9 minification: VK_FILTER_NEAREST, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 10 wrapModeS: VK_SAMPLER_ADDRESS_MODE_REPEAT, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 11 wrapModeT: VK_SAMPLER_ADDRESS_MODE_REPEAT, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 12 ) | 
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 13 (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) | 
| 1021 | 14 Mat1Type = MaterialType( | 
| 15 name: "single texture material 1", | |
| 16 vertexAttributes: { | |
| 17 "color": Vec4F32, | |
| 18 "position": Vec3F32, | |
| 19 "uv": Vec2F32, | |
| 20 }.toTable, | |
| 21 attributes: {"baseTexture": TextureType}.toTable | |
| 22 ) | |
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 23 mat = Mat1Type.InitMaterialData( | 
| 420 | 24 name = "mat", | 
| 25 attributes = { | |
| 1137 | 26 "baseTexture": InitDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ | 
| 322 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 27 R, R, R, R, R, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 28 R, R, W, R, R, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 29 R, W, W, W, R, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 30 R, R, W, R, R, | 
| 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 31 R, R, R, R, R, | 
| 420 | 32 ]), sampler: sampler)]) | 
| 33 }.toTable | |
| 322 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 34 ) | 
| 376 | 35 Mat2Type = MaterialType( | 
| 36 name: "single texture material 2", | |
| 384 
eaf084ba80e5
fix: cleanup when multiple textures use same vulkan image
 Sam <sam@basx.dev> parents: 
376diff
changeset | 37 vertexAttributes: { | 
| 1021 | 38 "color": Vec4F32, | 
| 376 | 39 "position": Vec3F32, | 
| 40 "uv": Vec2F32, | |
| 41 }.toTable, | |
| 42 attributes: {"baseTexture": TextureType}.toTable | |
| 43 ) | |
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 44 mat2 = Mat2Type.InitMaterialData( | 
| 420 | 45 name = "mat2", | 
| 46 attributes = { | |
| 1137 | 47 "baseTexture": InitDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ | 
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 48 R, W, R, W, R, | 
| 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 49 W, R, W, R, W, | 
| 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 50 R, W, R, W, R, | 
| 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 51 W, R, W, R, W, | 
| 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 52 R, W, R, W, R, | 
| 420 | 53 ]), sampler: sampler)]) | 
| 54 }.toTable | |
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 55 ) | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 56 mat3 = SINGLE_COLOR_MATERIAL.InitMaterialData( | 
| 420 | 57 name = "mat3", | 
| 58 attributes = { | |
| 1137 | 59 "color": InitDataList(@[NewVec4f(0, 1, 0, 1)]) | 
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 60 }.toTable | 
| 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 61 ) | 
| 322 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 62 | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 63 proc scene_different_mesh_types(): seq[Mesh] = | 
| 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 64 @[ | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 65 NewMesh( | 
| 1136 | 66 positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], | 
| 67 uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], | |
| 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)], | |
| 420 | 69 material = mat, | 
| 1136 | 70 transform = Translate(-0.7, -0.5), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 71 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 72 NewMesh( | 
| 1136 | 73 positions = [NewVec3f(0.0, -0.4), NewVec3f(0.4, 0.4), NewVec3f(-0.4, 0.5)], | 
| 74 uvs = [NewVec2f(0.0, -0.4), NewVec2f(0.4, 0.4), NewVec2f(-0.4, 0.5)], | |
| 75 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)], | |
| 420 | 76 material = mat, | 
| 1136 | 77 transform = Translate(0, -0.5), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 78 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 79 NewMesh( | 
| 1136 | 80 positions = [NewVec3f(0.0, 0.5), NewVec3f(0.5, -0.5), NewVec3f(-0.5, -0.5)], | 
| 81 uvs = [NewVec2f(0.0, 0.5), NewVec2f(0.5, -0.5), NewVec2f(-0.5, -0.5)], | |
| 82 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)], | |
| 420 | 83 indices = [[0'u16, 2'u16, 1'u16]], | 
| 84 material = mat2, | |
| 1136 | 85 transform = Translate(0.7, -0.5), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 86 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 87 NewMesh( | 
| 1136 | 88 positions = [NewVec3f(0.0, 0.4), NewVec3f(0.4, -0.4), NewVec3f(-0.4, -0.4)], | 
| 89 uvs = [NewVec2f(0.0, 0.4), NewVec2f(0.4, -0.4), NewVec2f(-0.4, -0.4)], | |
| 90 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)], | |
| 420 | 91 indices = [[0'u16, 2'u16, 1'u16]], | 
| 92 material = mat2, | |
| 1136 | 93 transform = Translate(-0.7, 0.5), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 94 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 95 NewMesh( | 
| 1136 | 96 positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], | 
| 97 uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], | |
| 98 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)], | |
| 420 | 99 indices = [[0'u32, 2'u32, 1'u32]], | 
| 100 autoResize = false, | |
| 101 material = mat2, | |
| 1136 | 102 transform = Translate(0, 0.5), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 103 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 104 NewMesh( | 
| 1136 | 105 positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], | 
| 106 uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], | |
| 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)], | |
| 420 | 108 indices = [[0'u32, 2'u32, 1'u32]], | 
| 109 autoResize = false, | |
| 110 material = mat2, | |
| 1136 | 111 transform = Translate(0.7, 0.5), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 112 ), | 
| 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 113 ] | 
| 124 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 114 | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 115 proc scene_simple(): seq[Mesh] = | 
| 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 116 @[ | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 117 NewMesh( | 
| 1136 | 118 positions = [NewVec3f(0.0, -0.3), NewVec3f(0.3, 0.3), NewVec3f(-0.3, 0.3)], | 
| 119 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)], | |
| 120 uvs = [NewVec2f(0.0, -0.3), NewVec2f(0.3, 0.3), NewVec2f(-0.3, 0.3)], | |
| 420 | 121 material = mat, | 
| 1136 | 122 transform = Translate(0.4, 0.4), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 123 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 124 NewMesh( | 
| 1136 | 125 positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], | 
| 126 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)], | |
| 127 uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], | |
| 420 | 128 material = mat, | 
| 1136 | 129 transform = Translate(0.4, -0.4), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 130 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 131 NewMesh( | 
| 1136 | 132 positions = [NewVec3f(0.0, -0.6), NewVec3f(0.6, 0.6), NewVec3f(-0.6, 0.6)], | 
| 133 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)], | |
| 134 uvs = [NewVec2f(0.0, -0.6), NewVec2f(0.6, 0.6), NewVec2f(-0.6, 0.6)], | |
| 420 | 135 indices = [[0'u32, 1'u32, 2'u32]], | 
| 136 autoResize = false, | |
| 137 material = mat, | |
| 1136 | 138 transform = Translate(-0.4, 0.4), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 139 ), | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 140 NewMesh( | 
| 1136 | 141 positions = [NewVec3f(0.0, -0.8), NewVec3f(0.8, 0.8), NewVec3f(-0.8, 0.8)], | 
| 142 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)], | |
| 143 uvs = [NewVec2f(0.0, -0.8), NewVec2f(0.8, 0.8), NewVec2f(-0.8, 0.8)], | |
| 420 | 144 indices = [[0'u16, 1'u16, 2'u16]], | 
| 145 instanceTransforms = [Unit4F32, Unit4F32], | |
| 146 material = mat, | |
| 1136 | 147 transform = Translate(-0.4, -0.4), | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 148 ) | 
| 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 149 ] | 
| 124 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 150 | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 151 proc scene_primitives(): seq[Mesh] = | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 152 var r = Rect(color = "ff0000") | 
| 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 153 var t = Tri(color = "0000ff") | 
| 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 154 var c = Circle(color = "00ff00") | 
| 368 
51ee41c1d8ed
fix: first example to work correctly with new material system
 Sam <sam@basx.dev> parents: 
353diff
changeset | 155 r.material = mat | 
| 
51ee41c1d8ed
fix: first example to work correctly with new material system
 Sam <sam@basx.dev> parents: 
353diff
changeset | 156 t.material = mat | 
| 
51ee41c1d8ed
fix: first example to work correctly with new material system
 Sam <sam@basx.dev> parents: 
353diff
changeset | 157 c.material = mat | 
| 1136 | 158 r.transform = Translate(NewVec3f(0.5, -0.3)) | 
| 159 t.transform = Translate(NewVec3f(0.3, 0.3)) | |
| 160 c.transform = Translate(NewVec3f(-0.3, 0.1)) | |
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 161 result = @[r, c, t] | 
| 124 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 162 | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 163 proc scene_flag(): seq[Mesh] = | 
| 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 164 @[ | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 165 NewMesh( | 
| 1136 | 166 positions = [NewVec3f(-1.0, -1.0), NewVec3f(1.0, -1.0), NewVec3f(1.0, 1.0), NewVec3f(-1.0, 1.0)], | 
| 167 uvs = [NewVec2f(-1.0, -1.0), NewVec2f(1.0, -1.0), NewVec2f(1.0, 1.0), NewVec2f(-1.0, 1.0)], | |
| 168 colors = [NewVec4f(-1, -1, 1, 1), NewVec4f(1, -1, 1, 1), NewVec4f(1, 1, 1, 1), NewVec4f(-1, 1, 1, 1)], | |
| 420 | 169 indices = [[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], | 
| 170 material = mat, | |
| 1136 | 171 transform = Scale(0.5, 0.5) | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 172 ) | 
| 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 173 ] | 
| 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: 
191diff
changeset | 174 | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 175 proc scene_multi_material(): seq[Mesh] = | 
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 176 var | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 177 r1 = Rect(color = "ffffff") | 
| 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 178 r2 = Rect(color = "000000") | 
| 368 
51ee41c1d8ed
fix: first example to work correctly with new material system
 Sam <sam@basx.dev> parents: 
353diff
changeset | 179 r1.material = mat | 
| 
51ee41c1d8ed
fix: first example to work correctly with new material system
 Sam <sam@basx.dev> parents: 
353diff
changeset | 180 r2.material = mat3 | 
| 1136 | 181 r1.transform = Translate(NewVec3f(-0.5)) | 
| 182 r2.transform = Translate(NewVec3f(+0.5)) | |
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 183 result = @[r1, r2] | 
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 184 | 
| 129 
15d37022625c
add: input handling, small refactoring for renderer
 Sam <sam@basx.dev> parents: 
128diff
changeset | 185 proc main() = | 
| 1138 | 186 var engine = InitEngine("Test") | 
| 124 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 187 | 
| 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 188 # INIT RENDERER: | 
| 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 189 const | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 190 shaderConfiguration1 = CreateShaderConfiguration( | 
| 1021 | 191 name = "shader1", | 
| 420 | 192 inputs = [ | 
| 1137 | 193 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | 
| 194 Attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), | |
| 195 Attr[Mat4]("transform", 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: 
316diff
changeset | 196 ], | 
| 420 | 197 intermediates = [ | 
| 1137 | 198 Attr[Vec4f]("outcolor"), | 
| 323 
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
322diff
changeset | 199 ], | 
| 1137 | 200 outputs = [Attr[Vec4f]("color")], | 
| 201 samplers = [Attr[Texture]("baseTexture")], | |
| 420 | 202 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", | 
| 203 fragmentCode = "color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", | |
| 124 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 204 ) | 
| 1139 
114f395b9144
did: finish refactoring and updated all tests accordingly
 sam <sam@basx.dev> parents: 
1138diff
changeset | 205 shaderConfiguration2 = CreateShaderConfiguration( | 
| 1021 | 206 name = "shader2", | 
| 420 | 207 inputs = [ | 
| 1137 | 208 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | 
| 209 Attr[Mat4]("transform", perInstance = true), | |
| 324 
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
323diff
changeset | 210 ], | 
| 1137 | 211 intermediates = [Attr[Vec4f]("outcolor")], | 
| 212 outputs = [Attr[Vec4f]("color")], | |
| 213 uniforms = [Attr[Vec4f]("color", arrayCount = 1)], | |
| 420 | 214 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", | 
| 215 fragmentCode = "color = outcolor;", | |
| 324 
cbfe96272205
add: first complete working version of multiple materials and shaders per scene, yipie :)
 Sam <sam@basx.dev> parents: 
323diff
changeset | 216 ) | 
| 1138 | 217 engine.InitRenderer({ | 
| 1021 | 218 Mat1Type: shaderConfiguration1, | 
| 219 Mat1Type: shaderConfiguration1, | |
| 376 | 220 Mat2Type: shaderConfiguration1, | 
| 368 
51ee41c1d8ed
fix: first example to work correctly with new material system
 Sam <sam@basx.dev> parents: 
353diff
changeset | 221 SINGLE_COLOR_MATERIAL: shaderConfiguration2, | 
| 344 | 222 }) | 
| 124 
cb9e27a30165
fix: completely overhole buffer handling for drawing, fix shit
 Sam <sam@basx.dev> parents: 
123diff
changeset | 223 | 
| 129 
15d37022625c
add: input handling, small refactoring for renderer
 Sam <sam@basx.dev> parents: 
128diff
changeset | 224 # 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: 
188diff
changeset | 225 var scenes = [ | 
| 328 | 226 Scene(name: "simple", meshes: scene_simple()), | 
| 227 Scene(name: "different mesh types", meshes: scene_different_mesh_types()), | |
| 228 Scene(name: "primitives", meshes: scene_primitives()), | |
| 229 Scene(name: "flag", meshes: scene_flag()), | |
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 230 Scene(name: "multimaterial", meshes: scene_multi_material()), | 
| 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: 
188diff
changeset | 231 ] | 
| 322 
6dab370d1758
add: first, incomplete version of material use
 Sam <sam@basx.dev> parents: 
321diff
changeset | 232 | 
| 128 
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
 Sam <sam@basx.dev> parents: 
127diff
changeset | 233 for scene in scenes.mitems: | 
| 1138 | 234 engine.LoadScene(scene) | 
| 109 | 235 | 
| 115 | 236 # MAINLOOP | 
| 111 
6fd10b7e2d6a
did: allow runtime shader-input definitions
 Sam <sam@basx.dev> parents: 
109diff
changeset | 237 echo "Setup successfull, start rendering" | 
| 128 
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
 Sam <sam@basx.dev> parents: 
127diff
changeset | 238 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: 
188diff
changeset | 239 for scene in scenes.mitems: | 
| 326 
4ec852355750
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
 Sam <sam@basx.dev> parents: 
325diff
changeset | 240 echo "rendering scene ", scene.name | 
| 128 
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
 Sam <sam@basx.dev> parents: 
127diff
changeset | 241 for i in 0 ..< 1000: | 
| 1135 
74957cbf589b
fix: update tests according to some API renaming
 sam <sam@basx.dev> parents: 
1021diff
changeset | 242 if not engine.UpdateInputs() or KeyIsDown(Escape): | 
| 1138 | 243 engine.Destroy() | 
| 129 
15d37022625c
add: input handling, small refactoring for renderer
 Sam <sam@basx.dev> parents: 
128diff
changeset | 244 return | 
| 1138 | 245 engine.RenderScene(scene) | 
| 114 
056e08dfad10
yay: first triangle rendering with new engine implmentation
 Sam <sam@basx.dev> parents: 
113diff
changeset | 246 | 
| 
056e08dfad10
yay: first triangle rendering with new engine implmentation
 Sam <sam@basx.dev> parents: 
113diff
changeset | 247 # cleanup | 
| 96 | 248 echo "Start cleanup" | 
| 1138 | 249 engine.Destroy() | 
| 129 
15d37022625c
add: input handling, small refactoring for renderer
 Sam <sam@basx.dev> parents: 
128diff
changeset | 250 | 
| 
15d37022625c
add: input handling, small refactoring for renderer
 Sam <sam@basx.dev> parents: 
128diff
changeset | 251 when isMainModule: | 
| 
15d37022625c
add: input handling, small refactoring for renderer
 Sam <sam@basx.dev> parents: 
128diff
changeset | 252 main() | 
