Mercurial > games > semicongine
changeset 371:f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 22 Nov 2023 23:24:47 +0700 |
parents | fad6490fb728 |
children | eb2ac324a162 |
files | tests/test_collision.nim tests/test_font.nim tests/test_mesh.nim tests/test_vulkan_wrapper.nim |
diffstat | 4 files changed, 24 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test_collision.nim Wed Nov 22 23:24:07 2023 +0700 +++ b/tests/test_collision.nim Wed Nov 22 23:24:47 2023 +0700 @@ -6,6 +6,9 @@ scene.add rect(color="f00f") scene.add rect() scene.add circle(color="0f0f") + scene.meshes[0].material = VERTEX_COLORED_MATERIAL.initMaterialData() + scene.meshes[1].material = VERTEX_COLORED_MATERIAL.initMaterialData() + scene.meshes[2].material = VERTEX_COLORED_MATERIAL.initMaterialData() scene.meshes[1].transform = scale(0.8, 0.8) scene.meshes[2].transform = scale(0.1, 0.1) scene.addShaderGlobal("perspective", Unit4F32) @@ -26,8 +29,8 @@ var engine = initEngine("Test collisions") - engine.initRenderer({"default material": shaderConfiguration}) - engine.addScene(scene) + engine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}) + engine.loadScene(scene) while engine.updateInputs() == Running and not engine.keyIsDown(Escape): if engine.windowWasResized():
--- a/tests/test_font.nim Wed Nov 22 23:24:07 2023 +0700 +++ b/tests/test_font.nim Wed Nov 22 23:24:47 2023 +0700 @@ -3,15 +3,17 @@ import semicongine proc main() = + # setup engine + var engine = initEngine("Test fonts") + engine.initRenderer([]) + + # build scene + var scene = Scene(name: "main") var font = loadFont("DejaVuSans.ttf", color=newVec4f(1, 0.5, 0.5, 1), resolution=20) - var textbox = initTextbox(32, font, "") - var scene = Scene(name: "main") scene.add textbox textbox.mesh.transform = scale(0.01, 0.01) - var engine = initEngine("Test fonts") - engine.initRenderer([]) - engine.addScene(scene) + engine.loadScene(scene) while engine.updateInputs() == Running and not engine.keyIsDown(Escape): if engine.windowWasResized():
--- a/tests/test_mesh.nim Wed Nov 22 23:24:07 2023 +0700 +++ b/tests/test_mesh.nim Wed Nov 22 23:24:47 2023 +0700 @@ -4,17 +4,8 @@ import semicongine proc main() = - # var myScene = Scene(name: "hi", meshes: @[rect()]) - # myScene.meshes[0].transform = translate3d(0.2'f32, 0'f32, 0'f32) - # myScene.root[0].transform = translate3d(0'f32, 0.2'f32, 0'f32) var scenes = [ - # loadScene("default_cube.glb", "1"), - # loadScene("default_cube1.glb", "3"), - # loadScene("default_cube2.glb", "4"), - # loadScene("flat.glb", "5"), - Scene(name: "Donut", meshes: loadMeshes("tutorialk-donat.glb")[0].toSeq), - # myScene, - # loadScene("personv3.glb", "2"), + Scene(name: "Donut", meshes: loadMeshes("tutorialk-donat.glb", COLORED_SINGLE_TEXTURE_MATERIAL)[0].toSeq), ] var engine = initEngine("Test meshes") @@ -22,7 +13,7 @@ shaderConfiguration = createShaderConfiguration( inputs=[ attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), - attr[uint16]("materialIndex", memoryPerformanceHint=PreferFastRead), + attr[uint16]("materialIndex", memoryPerformanceHint=PreferFastRead, perInstance=true), attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), ], @@ -35,37 +26,23 @@ uniforms=[ attr[Mat4]("projection"), attr[Mat4]("view"), - attr[Vec4f]("baseColorFactor", arrayCount=4), + attr[Vec4f]("color", arrayCount=4), ], - samplers=[attr[Texture]("baseColorTexture", arrayCount=4)], + samplers=[attr[Texture]("baseTexture", arrayCount=4)], vertexCode=""" gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); - vertexColor = Uniforms.baseColorFactor[materialIndex]; + vertexColor = Uniforms.color[materialIndex]; colorTexCoord = texcoord_0; materialIndexOut = materialIndex; """, - fragmentCode="color = texture(baseColorTexture[materialIndexOut], colorTexCoord) * vertexColor;" + fragmentCode="color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" ) - engine.initRenderer({ - "Material": shaderConfiguration, - "Material.001": shaderConfiguration, - "Material.002": shaderConfiguration, - "Material.004": shaderConfiguration, - }) + engine.initRenderer({COLORED_SINGLE_TEXTURE_MATERIAL: shaderConfiguration}) for scene in scenes.mitems: scene.addShaderGlobal("projection", Unit4F32) scene.addShaderGlobal("view", Unit4F32) - var materials: Table[uint16, Material] - for mesh in scene.meshes: - for material in mesh.materials: - if not materials.contains(material.index): - materials[material.index] = material - let baseColors = sortedByIt(values(materials).toSeq, it.index).mapIt(getValue[Vec4f](it.constants["baseColorFactor"], 0)) - let baseTextures = sortedByIt(values(materials).toSeq, it.index).mapIt(it.textures["baseColorTexture"]) - scene.addShaderGlobalArray("baseColorFactor", baseColors) - scene.addShaderGlobalArray("baseColorTexture", baseTextures) - engine.addScene(scene) + engine.loadScene(scene) var size = 1'f32
--- a/tests/test_vulkan_wrapper.nim Wed Nov 22 23:24:07 2023 +0700 +++ b/tests/test_vulkan_wrapper.nim Wed Nov 22 23:24:47 2023 +0700 @@ -14,7 +14,7 @@ mat = SINGLE_TEXTURE_MATERIAL.initMaterialData( name="mat", attributes={ - "texture1": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ + "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ R, R, R, R, R, R, R, W, R, R, R, W, W, W, R, @@ -26,7 +26,7 @@ mat2 = SINGLE_TEXTURE_MATERIAL.initMaterialData( name="mat2", attributes={ - "texture1": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ + "baseTexture": initDataList(@[Texture(image: Image(width: 5, height: 5, imagedata: @[ R, W, R, W, R, W, R, W, R, W, R, W, R, W, R, @@ -180,10 +180,10 @@ ], outputs=[attr[Vec4f]("color")], samplers=[ - attr[Texture]("texture1") + attr[Texture]("baseTexture") ], vertexCode="""gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", - fragmentCode="color = texture(texture1, outcolor.xy) * 0.5 + outcolor * 0.5;", + fragmentCode="color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", ) shaderConfiguration2 = createShaderConfiguration( inputs=[