diff tests/test_vulkan_wrapper.nim @ 189:df92519d4d68

add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
author Sam <sam@basx.dev>
date Fri, 05 May 2023 23:45:50 +0700
parents de9dff24c422
children 8f2eaf0d2808
line wrap: on
line diff
--- a/tests/test_vulkan_wrapper.nim	Thu May 04 23:44:15 2023 +0700
+++ b/tests/test_vulkan_wrapper.nim	Fri May 05 23:45:50 2023 +0700
@@ -117,11 +117,13 @@
     ]
     vertexOutput = @[attr[Vec3f]("outcolor")]
     uniforms = @[attr[float32]("time")]
+    # samplers = @[attr[Sampler2DType]("my_little_texture")]
     fragOutput = @[attr[Vec4f]("color")]
     vertexCode = compileGlslShader(
       stage=VK_SHADER_STAGE_VERTEX_BIT,
       inputs=vertexInput,
       uniforms=uniforms,
+      # samplers=samplers,
       outputs=vertexOutput,
       main="""gl_Position = vec4(position + translate, 1.0); outcolor = color;"""
     )
@@ -129,28 +131,34 @@
       stage=VK_SHADER_STAGE_FRAGMENT_BIT,
       inputs=vertexOutput,
       uniforms=uniforms,
+      # samplers=samplers,
       outputs=fragOutput,
-      main="color = vec4(outcolor, 0.8);"
+      # main="color = texture(my_little_texture, outcolor.xy) * 0.5 + vec4(outcolor, 1) * 0.5;"
+      main="color = vec4(outcolor, 1) * 0.5;"
     )
   var renderPass = engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)
   engine.setRenderer(renderPass)
 
   # INIT SCENES
-  var scenes = [scene_simple(), scene_different_mesh_types(), scene_primitives()]
-  var time = initShaderGlobal("time", 0.0'f32)
+  var scenes = [
+    newScene("simple", scene_simple()),
+    newScene("different mesh types", scene_different_mesh_types()),
+    newScene("primitives", scene_primitives())
+  ]
   for scene in scenes.mitems:
-    scene.components.add time
+    scene.addShaderGlobal("time", 0.0'f32)
     engine.addScene(scene, vertexInput)
 
   # MAINLOOP
   echo "Setup successfull, start rendering"
   for i in 0 ..< 3:
-    for scene in scenes:
+    for scene in scenes.mitems:
       for i in 0 ..< 1000:
         if engine.updateInputs() != Running or engine.keyIsDown(Escape):
           engine.destroy()
           return
-        setValue[float32](time.value, get[float32](time.value) + 0.0005)
+        var time = scene.getShaderGlobal("time")
+        setValue[float32](time, get[float32](time) + 0.0005)
         engine.renderScene(scene)
   echo "Rendered ", engine.framesRendered, " frames"
   echo "Processed ", engine.eventsProcessed, " events"