# HG changeset patch # User Sam # Date 1683305876 -25200 # Node ID 164bf40c664f2a2eeed90e183d5da37ceda2edf6 # Parent be6e0f89645a62b8edb42009df0dd45a8d8eeb59 add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms diff -r be6e0f89645a -r 164bf40c664f src/semicongine/entity.nim --- a/src/semicongine/entity.nim Fri May 05 23:45:50 2023 +0700 +++ b/src/semicongine/entity.nim Fri May 05 23:57:56 2023 +0700 @@ -35,8 +35,11 @@ value.setValue(data) scene.shaderGlobals[name] = value -func getShaderGlobal*(scene: Scene, name: string): DataValue = - return scene.shaderGlobals[name] +func getShaderGlobal*[T](scene: Scene, name: string): T = + getValue[T](scene.shaderGlobals[name]) + +func setShaderGlobal*[T](scene: var Scene, name: string, value: T) = + setValue[T](scene.shaderGlobals[name], value) func addTexture*[T](scene: var Scene, name: string, texture: Texture) = scene.textures[name] = texture diff -r be6e0f89645a -r 164bf40c664f src/semicongine/gpu_data.nim --- a/src/semicongine/gpu_data.nim Fri May 05 23:45:50 2023 +0700 +++ b/src/semicongine/gpu_data.nim Fri May 05 23:57:56 2023 +0700 @@ -294,7 +294,7 @@ memoryPerformanceHint: memoryPerformanceHint, ) -func get*[T: GPUType|int|uint|float](value: DataValue): T = +func getValue*[T: GPUType|int|uint|float](value: DataValue): T = when T is float32: value.float32 elif T is float64: value.float64 elif T is int8: value.int8 @@ -345,7 +345,7 @@ elif T is TMat4[float64]: value.mat4f64 else: {.error: "Virtual datatype has no value" .} -func get*[T: GPUType|int|uint|float](value: DataList): seq[T] = +func getValues*[T: GPUType|int|uint|float](value: DataList): seq[T] = when T is float32: value.float32 elif T is float64: value.float64 elif T is int8: value.int8 diff -r be6e0f89645a -r 164bf40c664f src/semicongine/renderer.nim --- a/src/semicongine/renderer.nim Fri May 05 23:45:50 2023 +0700 +++ b/src/semicongine/renderer.nim Fri May 05 23:57:56 2023 +0700 @@ -169,8 +169,8 @@ requireMappable=true, preferVRAM=true, ) - # textures: seq[Table[string, Texture]] var textures: Table[string, Texture] + # todo: get textures from scene data.textures.add textures # need a separate descriptor for each frame in flight pipeline.setupDescriptors(data.uniformBuffers, data.textures, inFlightFrames=renderer.swapchain.inFlightFrames) diff -r be6e0f89645a -r 164bf40c664f src/semicongine/vulkan/descriptor.nim --- a/src/semicongine/vulkan/descriptor.nim Fri May 05 23:45:50 2023 +0700 +++ b/src/semicongine/vulkan/descriptor.nim Fri May 05 23:57:56 2023 +0700 @@ -152,7 +152,6 @@ descriptorCount: descriptor.count, pBufferInfo: addr bufferInfos[^1], ) - #[ elif descriptor.thetype == ImageSampler: assert descriptor.imageview.vk.valid assert descriptor.sampler.vk.valid @@ -170,6 +169,5 @@ descriptorCount: descriptor.count, pImageInfo: addr imageInfos[^1], ) - ]# inc i descriptorSet.layout.device.vk.vkUpdateDescriptorSets(uint32(descriptorSetWrites.len), descriptorSetWrites.toCPointer, 0, nil) diff -r be6e0f89645a -r 164bf40c664f src/semicongine/vulkan/pipeline.nim --- a/src/semicongine/vulkan/pipeline.nim Fri May 05 23:45:50 2023 +0700 +++ b/src/semicongine/vulkan/pipeline.nim Fri May 05 23:57:56 2023 +0700 @@ -50,9 +50,9 @@ descriptor.offset = offset descriptor.size = size offset += size - # elif descriptor.thetype == ImageSampler: - # descriptor.imageview = textures[i][descriptor.name].imageView - # descriptor.sampler = textures[i][descriptor.name].sampler + elif descriptor.thetype == ImageSampler: + descriptor.imageview = textures[i][descriptor.name].imageView + descriptor.sampler = textures[i][descriptor.name].sampler proc createPipeline*(device: Device, renderPass: VkRenderPass, vertexCode: ShaderCode, fragmentCode: ShaderCode, inFlightFrames: int, subpass = 0'u32): Pipeline = assert renderPass.valid diff -r be6e0f89645a -r 164bf40c664f tests/test_vulkan_wrapper.nim --- a/tests/test_vulkan_wrapper.nim Fri May 05 23:45:50 2023 +0700 +++ b/tests/test_vulkan_wrapper.nim Fri May 05 23:57:56 2023 +0700 @@ -157,8 +157,7 @@ if engine.updateInputs() != Running or engine.keyIsDown(Escape): engine.destroy() return - var time = scene.getShaderGlobal("time") - setValue[float32](time, get[float32](time) + 0.0005) + setShaderGlobal(scene, "time", getShaderGlobal[float32](scene, "time") + 0.0005'f) engine.renderScene(scene) echo "Rendered ", engine.framesRendered, " frames" echo "Processed ", engine.eventsProcessed, " events"