Mercurial > games > semicongine
comparison tests/test_vulkan_wrapper.nim @ 1132:7f2c477ae1f4
merge
author | sam <sam@basx.dev> |
---|---|
date | Thu, 23 May 2024 02:26:37 +0700 |
parents | 73b572f82a1f |
children | 74957cbf589b |
comparison
equal
deleted
inserted
replaced
1131:99869a2b8a53 | 1132:7f2c477ae1f4 |
---|---|
9 minification: VK_FILTER_NEAREST, | 9 minification: VK_FILTER_NEAREST, |
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 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 ) | |
23 mat = Mat1Type.initMaterialData( | |
15 name = "mat", | 24 name = "mat", |
16 attributes = { | 25 attributes = { |
17 "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ | 26 "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ |
18 R, R, R, R, R, | 27 R, R, R, R, R, |
19 R, R, W, R, R, | 28 R, R, W, R, R, |
24 }.toTable | 33 }.toTable |
25 ) | 34 ) |
26 Mat2Type = MaterialType( | 35 Mat2Type = MaterialType( |
27 name: "single texture material 2", | 36 name: "single texture material 2", |
28 vertexAttributes: { | 37 vertexAttributes: { |
38 "color": Vec4F32, | |
29 "position": Vec3F32, | 39 "position": Vec3F32, |
30 "uv": Vec2F32, | 40 "uv": Vec2F32, |
31 }.toTable, | 41 }.toTable, |
32 attributes: {"baseTexture": TextureType}.toTable | 42 attributes: {"baseTexture": TextureType}.toTable |
33 ) | 43 ) |
176 var engine = initEngine("Test") | 186 var engine = initEngine("Test") |
177 | 187 |
178 # INIT RENDERER: | 188 # INIT RENDERER: |
179 const | 189 const |
180 shaderConfiguration1 = createShaderConfiguration( | 190 shaderConfiguration1 = createShaderConfiguration( |
191 name = "shader1", | |
181 inputs = [ | 192 inputs = [ |
182 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | 193 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
183 attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), | 194 attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), |
184 attr[Mat4]("transform", perInstance = true), | 195 attr[Mat4]("transform", perInstance = true), |
185 ], | 196 ], |
186 intermediates = [ | 197 intermediates = [ |
187 attr[Vec4f]("outcolor"), | 198 attr[Vec4f]("outcolor"), |
188 ], | 199 ], |
189 outputs = [attr[Vec4f]("color")], | 200 outputs = [attr[Vec4f]("color")], |
190 samplers = [ | 201 samplers = [attr[Texture]("baseTexture")], |
191 attr[Texture]("baseTexture") | |
192 ], | |
193 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", | 202 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", |
194 fragmentCode = "color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", | 203 fragmentCode = "color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", |
195 ) | 204 ) |
196 shaderConfiguration2 = createShaderConfiguration( | 205 shaderConfiguration2 = createShaderConfiguration( |
206 name = "shader2", | |
197 inputs = [ | 207 inputs = [ |
198 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | 208 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
199 attr[Mat4]("transform", perInstance = true), | 209 attr[Mat4]("transform", perInstance = true), |
200 ], | 210 ], |
201 intermediates = [attr[Vec4f]("outcolor")], | 211 intermediates = [attr[Vec4f]("outcolor")], |
203 uniforms = [attr[Vec4f]("color", arrayCount = 1)], | 213 uniforms = [attr[Vec4f]("color", arrayCount = 1)], |
204 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", | 214 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", |
205 fragmentCode = "color = outcolor;", | 215 fragmentCode = "color = outcolor;", |
206 ) | 216 ) |
207 engine.initRenderer({ | 217 engine.initRenderer({ |
208 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, | 218 Mat1Type: shaderConfiguration1, |
209 SINGLE_TEXTURE_MATERIAL: shaderConfiguration1, | 219 Mat1Type: shaderConfiguration1, |
210 Mat2Type: shaderConfiguration1, | 220 Mat2Type: shaderConfiguration1, |
211 SINGLE_COLOR_MATERIAL: shaderConfiguration2, | 221 SINGLE_COLOR_MATERIAL: shaderConfiguration2, |
212 }) | 222 }) |
213 | 223 |
214 # INIT SCENES | 224 # INIT SCENES |
227 echo "Setup successfull, start rendering" | 237 echo "Setup successfull, start rendering" |
228 for i in 0 ..< 3: | 238 for i in 0 ..< 3: |
229 for scene in scenes.mitems: | 239 for scene in scenes.mitems: |
230 echo "rendering scene ", scene.name | 240 echo "rendering scene ", scene.name |
231 for i in 0 ..< 1000: | 241 for i in 0 ..< 1000: |
232 if engine.updateInputs() != Running or engine.keyIsDown(Escape): | 242 if not engine.updateInputs() or keyIsDown(Escape): |
233 engine.destroy() | 243 engine.destroy() |
234 return | 244 return |
235 engine.renderScene(scene) | 245 engine.renderScene(scene) |
236 | 246 |
237 # cleanup | 247 # cleanup |