changeset 190:8f2eaf0d2808

add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms
author Sam <sam@basx.dev>
date Fri, 05 May 2023 23:57:56 +0700
parents df92519d4d68
children 81dc05b46b85
files src/semicongine/entity.nim src/semicongine/gpu_data.nim src/semicongine/renderer.nim src/semicongine/vulkan/descriptor.nim src/semicongine/vulkan/pipeline.nim tests/test_vulkan_wrapper.nim
diffstat 6 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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
--- 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)
--- 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)
--- 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
--- 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"