Mercurial > games > semicongine
changeset 881:11a55a45aba2
fix: all tests (once more)
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 29 Jan 2024 00:19:35 +0700 |
parents | 76380f64edac |
children | 5392cbd9db41 |
files | tests/test_font.nim tests/test_materials.nim tests/test_mesh.nim tests/test_vulkan_wrapper.nim |
diffstat | 4 files changed, 136 insertions(+), 136 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test_font.nim Sun Jan 28 22:18:25 2024 +0700 +++ b/tests/test_font.nim Mon Jan 29 00:19:35 2024 +0700 @@ -22,7 +22,7 @@ Vertical alignment: F4: Top F5: Center - F6: Bottom""", scale = 0.0001, position = newVec2f(0, 0), horizontalAlignment = Left, verticalAlignment = Top) + F6: Bottom""", scale = 0.0002, position = newVec2f(0, 0), horizontalAlignment = Left, verticalAlignment = Top) scene.add main_text scene.add help_text engine.loadScene(scene)
--- a/tests/test_materials.nim Sun Jan 28 22:18:25 2024 +0700 +++ b/tests/test_materials.nim Mon Jan 29 00:19:35 2024 +0700 @@ -6,16 +6,16 @@ let sampler = Sampler(magnification: VK_FILTER_NEAREST, minification: VK_FILTER_NEAREST) (RT, WT, PT) = (toRGBA("A51931").asPixel, toRGBA("F4F5F8").asPixel, toRGBA("2D2A4A").asPixel) - thai = Image(width: 7, height: 5, imagedata: @[ + thai = Image[RGBAPixel](width: 7, height: 5, imagedata: @[ RT, RT, RT, RT, RT, RT, RT, WT, WT, WT, WT, WT, WT, WT, PT, PT, PT, PT, PT, PT, PT, WT, WT, WT, WT, WT, WT, WT, RT, RT, RT, RT, RT, RT, RT, ]) - swiss = loadImage("flag.png") + swiss = loadImage[RGBAPixel]("flag.png") doubleTextureMaterial = MaterialType( - name:"Double texture", + name: "Double texture", vertexAttributes: { "position": Vec3F32, "uv": Vec2F32, @@ -23,11 +23,11 @@ attributes: {"tex1": TextureType, "tex2": TextureType}.toTable ) material = initMaterialData( - theType=doubleTextureMaterial, - name="swiss-thai", - attributes={ - "tex1": initDataList(@[Texture(image: thai, sampler: sampler)]), - "tex2": initDataList(@[Texture(image: swiss, sampler: sampler)]), + theType = doubleTextureMaterial, + name = "swiss-thai", + attributes = { + "tex1": initDataList(@[Texture(colorImage: thai, sampler: sampler, isGrayscale: false)]), + "tex2": initDataList(@[Texture(colorImage: swiss, sampler: sampler, isGrayscale: false)]), } ) @@ -41,23 +41,23 @@ const shaderConfiguration1 = createShaderConfiguration( - inputs=[ - attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), - attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), + inputs = [ + attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), + attr[Vec2f]("uv", memoryPerformanceHint = PreferFastRead), ], - intermediates=[ + intermediates = [ attr[Vec2f]("uvout"), ], - uniforms=[attr[float32]("test2", arrayCount=2)], + uniforms = [attr[float32]("test2", arrayCount = 2)], samplers = @[ - attr[Texture]("tex1", arrayCount=1), - attr[Texture]("tex2", arrayCount=1), + attr[Texture]("tex1", arrayCount = 1), + attr[Texture]("tex2", arrayCount = 1), ], - outputs=[attr[Vec4f]("color")], - vertexCode=""" + outputs = [attr[Vec4f]("color")], + vertexCode = """ gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); uvout = uv;""", - fragmentCode=""" + fragmentCode = """ float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; color = texture(tex1[0], uvout) * (1 - d) + texture(tex2[0], uvout) * d; """,
--- a/tests/test_mesh.nim Sun Jan 28 22:18:25 2024 +0700 +++ b/tests/test_mesh.nim Mon Jan 29 00:19:35 2024 +0700 @@ -8,31 +8,31 @@ var engine = initEngine("Test meshes") const shaderConfiguration = createShaderConfiguration( - inputs=[ - attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), - attr[uint16]("materialIndex", memoryPerformanceHint=PreferFastRead, perInstance=true), - attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), - attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), + inputs = [ + attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), + attr[uint16](MATERIALINDEX_ATTRIBUTE, memoryPerformanceHint = PreferFastRead, perInstance = true), + attr[Vec2f]("texcoord_0", memoryPerformanceHint = PreferFastRead), + attr[Mat4]("transform", memoryPerformanceHint = PreferFastWrite, perInstance = true), ], - intermediates=[ + intermediates = [ attr[Vec4f]("vertexColor"), attr[Vec2f]("colorTexCoord"), - attr[uint16]("materialIndexOut", noInterpolation=true) + attr[uint16]("materialIndexOut", noInterpolation = true) ], - outputs=[attr[Vec4f]("color")], - uniforms=[ + outputs = [attr[Vec4f]("color")], + uniforms = [ attr[Mat4]("projection"), attr[Mat4]("view"), - attr[Vec4f]("color", arrayCount=4), + attr[Vec4f]("color", arrayCount = 4), ], - samplers=[attr[Texture]("baseTexture", arrayCount=4)], - vertexCode=""" + samplers = [attr[Texture]("baseTexture", arrayCount = 4)], + vertexCode = &""" gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); - vertexColor = Uniforms.color[materialIndex]; + vertexColor = Uniforms.color[{MATERIALINDEX_ATTRIBUTE}]; colorTexCoord = texcoord_0; - materialIndexOut = materialIndex; + materialIndexOut = {MATERIALINDEX_ATTRIBUTE}; """, - fragmentCode="color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" + fragmentCode = "color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" ) engine.initRenderer({COLORED_SINGLE_TEXTURE_MATERIAL: shaderConfiguration})
--- a/tests/test_vulkan_wrapper.nim Sun Jan 28 22:18:25 2024 +0700 +++ b/tests/test_vulkan_wrapper.nim Mon Jan 29 00:19:35 2024 +0700 @@ -12,16 +12,16 @@ ) (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) mat = SINGLE_TEXTURE_MATERIAL.initMaterialData( - name="mat", - attributes={ - "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ + name = "mat", + attributes = { + "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ R, R, R, R, R, R, R, W, R, R, R, W, W, W, R, R, R, W, R, R, R, R, R, R, R, - ]), sampler: sampler)]) - }.toTable + ]), sampler: sampler)]) + }.toTable ) Mat2Type = MaterialType( name: "single texture material 2", @@ -32,20 +32,20 @@ attributes: {"baseTexture": TextureType}.toTable ) mat2 = Mat2Type.initMaterialData( - name="mat2", - attributes={ - "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ + name = "mat2", + attributes = { + "baseTexture": initDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ R, W, R, W, R, W, R, W, R, W, R, W, R, W, R, W, R, W, R, W, R, W, R, W, R, - ]), sampler: sampler)]) - }.toTable + ]), sampler: sampler)]) + }.toTable ) mat3 = SINGLE_COLOR_MATERIAL.initMaterialData( - name="mat3", - attributes={ + name = "mat3", + attributes = { "color": initDataList(@[newVec4f(0, 1, 0, 1)]) }.toTable ) @@ -53,119 +53,119 @@ proc scene_different_mesh_types(): seq[Mesh] = @[ newMesh( - positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], - uvs=[newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], - 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)], - material=mat, - transform=translate(-0.7, -0.5), + positions = [newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], + uvs = [newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], + 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)], + material = mat, + transform = translate(-0.7, -0.5), ), newMesh( - positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], - uvs=[newVec2f(0.0, -0.4), newVec2f(0.4, 0.4), newVec2f(-0.4, 0.5)], - 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)], - material=mat, - transform=translate(0, -0.5), + positions = [newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], + uvs = [newVec2f(0.0, -0.4), newVec2f(0.4, 0.4), newVec2f(-0.4, 0.5)], + 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)], + material = mat, + transform = translate(0, -0.5), ), newMesh( - positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], - uvs=[newVec2f(0.0, 0.5), newVec2f(0.5, -0.5), newVec2f(-0.5, -0.5)], - 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)], - indices=[[0'u16, 2'u16, 1'u16]], - material=mat2, - transform=translate(0.7, -0.5), + positions = [newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], + uvs = [newVec2f(0.0, 0.5), newVec2f(0.5, -0.5), newVec2f(-0.5, -0.5)], + 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)], + indices = [[0'u16, 2'u16, 1'u16]], + material = mat2, + transform = translate(0.7, -0.5), ), newMesh( - positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], - uvs=[newVec2f(0.0, 0.4), newVec2f(0.4, -0.4), newVec2f(-0.4, -0.4)], - 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)], - indices=[[0'u16, 2'u16, 1'u16]], - material=mat2, - transform=translate(-0.7, 0.5), + positions = [newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], + uvs = [newVec2f(0.0, 0.4), newVec2f(0.4, -0.4), newVec2f(-0.4, -0.4)], + 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)], + indices = [[0'u16, 2'u16, 1'u16]], + material = mat2, + transform = translate(-0.7, 0.5), ), newMesh( - positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], - uvs=[newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], - 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)], - indices=[[0'u32, 2'u32, 1'u32]], - autoResize=false, - material=mat2, - transform=translate(0, 0.5), + positions = [newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], + uvs = [newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], + 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)], + indices = [[0'u32, 2'u32, 1'u32]], + autoResize = false, + material = mat2, + transform = translate(0, 0.5), ), newMesh( - positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], - uvs=[newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], - 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)], - indices=[[0'u32, 2'u32, 1'u32]], - autoResize=false, - material=mat2, - transform=translate(0.7, 0.5), + positions = [newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], + uvs = [newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], + 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)], + indices = [[0'u32, 2'u32, 1'u32]], + autoResize = false, + material = mat2, + transform = translate(0.7, 0.5), ), ] proc scene_simple(): seq[Mesh] = @[ newMesh( - positions=[newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], - 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)], - uvs=[newVec2f(0.0, -0.3), newVec2f(0.3, 0.3), newVec2f(-0.3, 0.3)], - material=mat, - transform=translate(0.4, 0.4), + positions = [newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], + 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)], + uvs = [newVec2f(0.0, -0.3), newVec2f(0.3, 0.3), newVec2f(-0.3, 0.3)], + material = mat, + transform = translate(0.4, 0.4), ), newMesh( - positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], - 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)], - uvs=[newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], - material=mat, - transform=translate(0.4, -0.4), + positions = [newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], + 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)], + uvs = [newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], + material = mat, + transform = translate(0.4, -0.4), ), newMesh( - positions=[newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], - 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)], - uvs=[newVec2f(0.0, -0.6), newVec2f(0.6, 0.6), newVec2f(-0.6, 0.6)], - indices=[[0'u32, 1'u32, 2'u32]], - autoResize=false, - material=mat, - transform=translate(-0.4, 0.4), + positions = [newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], + 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)], + uvs = [newVec2f(0.0, -0.6), newVec2f(0.6, 0.6), newVec2f(-0.6, 0.6)], + indices = [[0'u32, 1'u32, 2'u32]], + autoResize = false, + material = mat, + transform = translate(-0.4, 0.4), ), newMesh( - positions=[newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], - 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)], - uvs=[newVec2f(0.0, -0.8), newVec2f(0.8, 0.8), newVec2f(-0.8, 0.8)], - indices=[[0'u16, 1'u16, 2'u16]], - instanceTransforms=[Unit4F32, Unit4F32], - material=mat, - transform=translate(-0.4, -0.4), + positions = [newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], + 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)], + uvs = [newVec2f(0.0, -0.8), newVec2f(0.8, 0.8), newVec2f(-0.8, 0.8)], + indices = [[0'u16, 1'u16, 2'u16]], + instanceTransforms = [Unit4F32, Unit4F32], + material = mat, + transform = translate(-0.4, -0.4), ) ] proc scene_primitives(): seq[Mesh] = - var r = rect(color="ff0000") - var t = tri(color="0000ff") - var c = circle(color="00ff00") + var r = rect(color = "ff0000") + var t = tri(color = "0000ff") + var c = circle(color = "00ff00") r.material = mat t.material = mat c.material = mat r.transform = translate(newVec3f(0.5, -0.3)) - t.transform = translate(newVec3f(0.3, 0.3)) - c.transform = translate(newVec3f(-0.3, 0.1)) + t.transform = translate(newVec3f(0.3, 0.3)) + c.transform = translate(newVec3f(-0.3, 0.1)) result = @[r, c, t] proc scene_flag(): seq[Mesh] = @[ newMesh( - positions=[newVec3f(-1.0, -1.0), newVec3f(1.0, -1.0), newVec3f(1.0, 1.0), newVec3f(-1.0, 1.0)], - uvs=[newVec2f(-1.0, -1.0), newVec2f(1.0, -1.0), newVec2f(1.0, 1.0), newVec2f(-1.0, 1.0)], - colors=[newVec4f(-1, -1, 1, 1), newVec4f(1, -1, 1, 1), newVec4f(1, 1, 1, 1), newVec4f(-1, 1, 1, 1)], - indices=[[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], - material=mat, - transform=scale(0.5, 0.5) + positions = [newVec3f(-1.0, -1.0), newVec3f(1.0, -1.0), newVec3f(1.0, 1.0), newVec3f(-1.0, 1.0)], + uvs = [newVec2f(-1.0, -1.0), newVec2f(1.0, -1.0), newVec2f(1.0, 1.0), newVec2f(-1.0, 1.0)], + colors = [newVec4f(-1, -1, 1, 1), newVec4f(1, -1, 1, 1), newVec4f(1, 1, 1, 1), newVec4f(-1, 1, 1, 1)], + indices = [[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], + material = mat, + transform = scale(0.5, 0.5) ) ] proc scene_multi_material(): seq[Mesh] = var - r1 = rect(color="ffffff") - r2 = rect(color="000000") + r1 = rect(color = "ffffff") + r2 = rect(color = "000000") r1.material = mat r2.material = mat3 r1.transform = translate(newVec3f(-0.5)) @@ -178,31 +178,31 @@ # INIT RENDERER: const shaderConfiguration1 = createShaderConfiguration( - inputs=[ - attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), - attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), - attr[Mat4]("transform", perInstance=true), + inputs = [ + attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), + attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), + attr[Mat4]("transform", perInstance = true), ], - intermediates=[ + intermediates = [ attr[Vec4f]("outcolor"), ], - outputs=[attr[Vec4f]("color")], - samplers=[ + outputs = [attr[Vec4f]("color")], + samplers = [ attr[Texture]("baseTexture") ], - vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", - fragmentCode="color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", + vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", + fragmentCode = "color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", ) shaderConfiguration2 = createShaderConfiguration( - inputs=[ - attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), - attr[Mat4]("transform", perInstance=true), + inputs = [ + attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), + attr[Mat4]("transform", perInstance = true), ], - intermediates=[attr[Vec4f]("outcolor")], - outputs=[attr[Vec4f]("color")], - uniforms=[attr[Vec4f]("color", arrayCount=1)], - vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", - fragmentCode="color = outcolor;", + intermediates = [attr[Vec4f]("outcolor")], + outputs = [attr[Vec4f]("color")], + uniforms = [attr[Vec4f]("color", arrayCount = 1)], + vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = Uniforms.color[0];""", + fragmentCode = "color = outcolor;", ) engine.initRenderer({ SINGLE_TEXTURE_MATERIAL: shaderConfiguration1,