Mercurial > games > semicongine
changeset 1026:f7802c5069ce
did: some trivial renaming
author | sam <sam@basx.dev> |
---|---|
date | Mon, 20 May 2024 19:34:47 +0700 |
parents | 5a8713d0afd5 |
children | d6c27f0ed3e4 |
files | semicongine/mesh.nim semicongine/renderer.nim semicongine/text.nim |
diffstat | 3 files changed, 21 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/semicongine/mesh.nim Mon May 20 17:53:01 2024 +0700 +++ b/semicongine/mesh.nim Mon May 20 19:34:47 2024 +0700 @@ -382,6 +382,11 @@ proc clearDirtyAttributes*(mesh: var MeshObject) = mesh.dirtyAttributes.reset +proc setShaderMaterialIndices*(mesh: var MeshObject, shadername: string, values: seq[uint16], attributeName = MATERIALINDEX_ATTRIBUTE) = + let indexAttribute = shadername & "_" & attributeName + assert values.len == mesh.instanceCount, &"Mesh {mesh}: While trying to set shader material indices for shader '{shadername}': indices have len {values.len}, but instance count is {mesh.instanceCount}" + mesh[indexAttribute] = values + # MESH-TOOLS proc transform*[T: GPUType](mesh: var MeshObject, attribute: string, transform: Mat4) =
--- a/semicongine/renderer.nim Mon May 20 17:53:01 2024 +0700 +++ b/semicongine/renderer.nim Mon May 20 19:34:47 2024 +0700 @@ -222,28 +222,28 @@ var uploadedTextures: Table[Texture, VulkanTexture] for (materialType, shaderPipeline) in sceneShaders: # gather textures - for texture in shaderPipeline.samplers: - scenedata.shaderData[shaderPipeline.vk].textures[texture.name] = newSeq[VulkanTexture]() - if scene.shaderGlobals.contains(texture.name): - for textureValue in scene.shaderGlobals[texture.name][Texture][]: + for textureAttribute in shaderPipeline.samplers: + scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name] = newSeq[VulkanTexture]() + if scene.shaderGlobals.contains(textureAttribute.name): + for textureValue in scene.shaderGlobals[textureAttribute.name][Texture][]: if not uploadedTextures.contains(textureValue): uploadedTextures[textureValue] = renderer.device.uploadTexture(renderer.queue, textureValue) - scenedata.shaderData[shaderPipeline.vk].textures[texture.name].add uploadedTextures[textureValue] + scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name].add uploadedTextures[textureValue] else: var foundTexture = false for material in scene.getMaterials(materialType): - if material.hasMatchingAttribute(texture): + if material.hasMatchingAttribute(textureAttribute): foundTexture = true - let value = material[texture.name, Texture][] - assert value.len == 1, &"Mesh material attribute '{texture.name}' has texture-array, but only single textures are allowed" + let value = material[textureAttribute.name, Texture][] + assert value.len == 1, &"Mesh material attribute '{textureAttribute.name}' has texture-array, but only single textures are allowed" if not uploadedTextures.contains(value[0]): uploadedTextures[value[0]] = renderer.device.uploadTexture(renderer.queue, value[0]) - scenedata.shaderData[shaderPipeline.vk].textures[texture.name].add uploadedTextures[value[0]] - assert foundTexture, &"No texture found in shaderGlobals or materials for '{texture.name}'" - let nTextures = scenedata.shaderData[shaderPipeline.vk].textures[texture.name].len.uint32 - assert (texture.arrayCount == 0 and nTextures == 1) or texture.arrayCount >= nTextures, &"Shader assigned to render '{materialType}' expected {texture.arrayCount} textures for '{texture.name}' but got {nTextures}" - if texture.arrayCount < nTextures: - warn &"Shader assigned to render '{materialType}' expected {texture.arrayCount} textures for '{texture.name}' but got {nTextures}" + scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name].add uploadedTextures[value[0]] + assert foundTexture, &"No texture found in shaderGlobals or materials for '{textureAttribute.name}'" + let nTextures = scenedata.shaderData[shaderPipeline.vk].textures[textureAttribute.name].len.uint32 + assert (textureAttribute.arrayCount == 0 and nTextures == 1) or textureAttribute.arrayCount >= nTextures, &"Shader assigned to render '{materialType}' expected {textureAttribute.arrayCount} textures for '{textureAttribute.name}' but got {nTextures}" + if textureAttribute.arrayCount < nTextures: + warn &"Shader assigned to render '{materialType}' expected {textureAttribute.arrayCount} textures for '{textureAttribute.name}' but got {nTextures}" # gather uniform sizes var uniformBufferSize = 0'u64
--- a/semicongine/text.nim Mon May 20 17:53:01 2024 +0700 +++ b/semicongine/text.nim Mon May 20 19:34:47 2024 +0700 @@ -13,7 +13,7 @@ SPACE = Rune(' ') # font shader - MAX_TEXT_MATERIALS = 10 + MAX_TEXT_MATERIALS = 100 # need for every different font AND color SHADER_ATTRIB_PREFIX = "semicon_text_" POSITION_ATTRIB = SHADER_ATTRIB_PREFIX & "position" UV_ATTRIB = SHADER_ATTRIB_PREFIX & "uv" @@ -254,8 +254,7 @@ result.mesh = newMesh(positions = positions, indices = indices, uvs = uvs, name = &"text-{instanceCounter}") result.mesh[].renameAttribute("position", POSITION_ATTRIB) result.mesh[].renameAttribute("uv", UV_ATTRIB) - result.mesh.material = initMaterialData( - theType = TEXT_MATERIAL_TYPE, + result.mesh.material = TEXT_MATERIAL_TYPE.initMaterialData( name = font.name & " text", attributes = {"fontAtlas": initDataList(@[font.fontAtlas]), "color": initDataList(@[color])}, )