Mercurial > games > semicongine
changeset 448:ab406a0d1551
add: few string-ify methods, small fix for default-shaders
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 09 Mar 2024 16:45:57 +0700 |
parents | 7ebcf22ec87f |
children | 9e621b1116b9 |
files | semicongine/core/gpu_types.nim semicongine/engine.nim semicongine/material.nim semicongine/scene.nim semicongine/vulkan/shader.nim |
diffstat | 5 files changed, 20 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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])) =
--- 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,
--- 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)
--- 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.} =