# HG changeset patch # User Sam # Date 1709977557 -25200 # Node ID f4bc149a385ce9a715a73d156168136c7e1894eb # Parent 75a544b946ea4eea5364031585ee63596b710ece add: few string-ify methods, small fix for default-shaders diff -r 75a544b946ea -r f4bc149a385c semicongine/core/gpu_types.nim --- a/semicongine/core/gpu_types.nim Tue Mar 05 14:26:46 2024 +0700 +++ b/semicongine/core/gpu_types.nim Sat Mar 09 16:45:57 2024 +0700 @@ -62,6 +62,15 @@ noInterpolation: bool memoryPerformanceHint*: MemoryPerformanceHint +proc `$`*(attr: ShaderAttribute): string = + result = attr.name + if attr.perInstance: + result &= "*" + result &= &"[{attr.theType}" + if attr.arrayCount > 0: + result &= &", {attr.arrayCount}" + result &= "]" + func vertexInputs*(attributes: seq[ShaderAttribute]): seq[ShaderAttribute] = for attr in attributes: if attr.perInstance == false: diff -r 75a544b946ea -r f4bc149a385c semicongine/engine.nim --- a/semicongine/engine.nim Tue Mar 05 14:26:46 2024 +0700 +++ b/semicongine/engine.nim Sat Mar 09 16:45:57 2024 +0700 @@ -1,6 +1,7 @@ {.experimental: "codeReordering".} import std/options +import std/sequtils import std/logging import std/os @@ -111,9 +112,12 @@ assert not engine.renderer.isSome var allShaders = @shaders - allShaders.add (EMPTY_MATERIAL, EMPTY_SHADER) - allShaders.add (PANEL_MATERIAL_TYPE, PANEL_SHADER) - allShaders.add (TEXT_MATERIAL_TYPE, TEXT_SHADER) + if not shaders.mapIt(it[0]).contains(EMPTY_MATERIAL): + allShaders.add (EMPTY_MATERIAL, EMPTY_SHADER) + if not shaders.mapIt(it[0]).contains(PANEL_MATERIAL_TYPE): + allShaders.add (PANEL_MATERIAL_TYPE, PANEL_SHADER) + if not shaders.mapIt(it[0]).contains(TEXT_MATERIAL_TYPE): + allShaders.add (TEXT_MATERIAL_TYPE, TEXT_SHADER) engine.renderer = some(engine.device.initRenderer(shaders = allShaders, clearColor = clearColor, backFaceCulling = backFaceCulling)) proc initRenderer*(engine: var Engine, clearColor = Vec4f([0.8'f32, 0.8'f32, 0.8'f32, 1'f32])) = diff -r 75a544b946ea -r f4bc149a385c semicongine/material.nim --- a/semicongine/material.nim Tue Mar 05 14:26:46 2024 +0700 +++ b/semicongine/material.nim Sat Mar 09 16:45:57 2024 +0700 @@ -53,13 +53,13 @@ var attributes: seq[string] for key, value in materialType.attributes.pairs: attributes.add &"{key}: {value}" - return &"""MaterialType '{materialType.name}' | Attributes: {attributes.join(", ")}""" + return &"""MaterialType '{materialType.name}' | Attributes: [{attributes.join(", ")}]""" proc `$`*(material: MaterialData): string = var attributes: seq[string] for key, value in material.attributes.pairs: attributes.add &"{key}: {value}" - return &"""Material '{material.name}' | Attributes: {attributes.join(", ")}""" + return &"""Material '{material.name}' | Attributes: [{attributes.join(", ")}]""" proc initMaterialData*( theType: MaterialType, diff -r 75a544b946ea -r f4bc149a385c semicongine/scene.nim --- a/semicongine/scene.nim Tue Mar 05 14:26:46 2024 +0700 +++ b/semicongine/scene.nim Sat Mar 09 16:45:57 2024 +0700 @@ -74,9 +74,6 @@ func hash*(scene: Scene): Hash = hash(scene.name) -func `==`*(a, b: Scene): bool = - a.name == b.name - func usesMaterial*(scene: Scene, materialType: MaterialType): bool = return scene.meshes.anyIt(it.material.theType == materialType) diff -r 75a544b946ea -r f4bc149a385c semicongine/vulkan/shader.nim --- a/semicongine/vulkan/shader.nim Tue Mar 05 14:26:46 2024 +0700 +++ b/semicongine/vulkan/shader.nim Sat Mar 09 16:45:57 2024 +0700 @@ -32,6 +32,8 @@ uniforms*: seq[ShaderAttribute] samplers*: seq[ShaderAttribute] +proc `$`*(shader: ShaderConfiguration): string = + &"Inputs: {shader.inputs}, Uniforms: {shader.uniforms}, Samplers: {shader.samplers}" proc compileGlslToSPIRV(stage: VkShaderStageFlagBits, shaderSource: string, entrypoint: string): seq[uint32] {.compileTime.} = func stage2string(stage: VkShaderStageFlagBits): string {.compileTime.} =