changeset 668:a02d503ffa53

add: some adjustment to the last refactoring :P
author Sam <sam@basx.dev>
date Tue, 09 May 2023 01:18:01 +0700
parents d3500ae5d235
children 0b55be039538
files config.nims src/semicongine/core.nim src/semicongine/core/utils.nim src/semicongine/vulkan/commandbuffer.nim src/semicongine/vulkan/descriptor.nim src/semicongine/vulkan/device.nim src/semicongine/vulkan/drawable.nim src/semicongine/vulkan/framebuffer.nim src/semicongine/vulkan/instance.nim src/semicongine/vulkan/physicaldevice.nim src/semicongine/vulkan/pipeline.nim src/semicongine/vulkan/renderpass.nim src/semicongine/vulkan/shader.nim src/semicongine/vulkan/swapchain.nim src/semicongine/vulkan/utils.nim tests/test_resources.nim
diffstat 16 files changed, 59 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/config.nims	Tue May 09 01:11:51 2023 +0700
+++ b/config.nims	Tue May 09 01:18:01 2023 +0700
@@ -139,7 +139,8 @@
 task generate_vulkan_api, "Generate Vulkan API":
   selfExec &"c -d:ssl --run src/vulkan_api/vulkan_api_generator.nim"
   mkDir "src/semicongine/vulkan/"
-  cpFile "src/vulkan_api/output/api.nim", "src/semicongine/vulkan/api.nim"
+  mkDir "src/semicongine/core/"
+  cpFile "src/vulkan_api/output/api.nim", "src/semicongine/core/api.nim"
   cpDir "src/vulkan_api/output/platform", "src/semicongine/vulkan/platform"
 
 if getCommand() in ["c", "compile", "r", "dump", "check", "idetools"]:
--- a/src/semicongine/core.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/core.nim	Tue May 09 01:18:01 2023 +0700
@@ -8,6 +8,7 @@
 import ./core/gpu_data
 import ./core/matrix
 import ./core/vector
+import ./core/utils
 
 export vulkanapi
 export audiotypes
@@ -16,3 +17,4 @@
 export gpu_data
 export matrix
 export vector
+export utils
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/semicongine/core/utils.nim	Tue May 09 01:18:01 2023 +0700
@@ -0,0 +1,23 @@
+import std/typetraits
+import std/strutils
+import std/strformat
+
+func cleanString*(str: openArray[char]): string =
+  for i in 0 ..< len(str):
+    if str[i] == char(0):
+      result = join(str[0 ..< i])
+      break
+
+func toCPointer*[T](list: var seq[T]): ptr T =
+  if list.len > 0: addr list[0] else: nil
+
+proc staticExecChecked*(command: string, input = ""): string {.compileTime.} =
+  let (output, exitcode) = gorgeEx(
+      command = command,
+      input = input)
+  if exitcode != 0:
+    raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output)
+  return output
+
+func size*[T: seq](list: T): uint64 =
+  uint64(list.len * sizeof(get(genericParams(typeof(list)), 0)))
--- a/src/semicongine/vulkan/commandbuffer.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/commandbuffer.nim	Tue May 09 01:18:01 2023 +0700
@@ -1,7 +1,6 @@
 import ../core
 import ./device
 import ./physicaldevice
-import ./utils
 
 type
   CommandBufferPool* = object
--- a/src/semicongine/vulkan/descriptor.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/descriptor.nim	Tue May 09 01:18:01 2023 +0700
@@ -4,7 +4,6 @@
 import ../core
 import ./device
 import ./buffer
-import ./utils
 import ./image
 
 type
--- a/src/semicongine/vulkan/device.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/device.nim	Tue May 09 01:18:01 2023 +0700
@@ -3,7 +3,6 @@
 import std/tables
 
 import ../core
-import ./utils
 import ./instance
 import ./physicaldevice
 
--- a/src/semicongine/vulkan/drawable.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/drawable.nim	Tue May 09 01:18:01 2023 +0700
@@ -3,7 +3,6 @@
 import std/logging
 
 import ../core
-import ./utils
 import ./buffer
 
 type
--- a/src/semicongine/vulkan/framebuffer.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/framebuffer.nim	Tue May 09 01:18:01 2023 +0700
@@ -1,6 +1,5 @@
 import ../core
 import ./device
-import ./utils
 import ./image
 
 
--- a/src/semicongine/vulkan/instance.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/instance.nim	Tue May 09 01:18:01 2023 +0700
@@ -4,7 +4,6 @@
 import std/logging
 
 import ../core
-import ./utils
 
 import ../platform/vulkanExtensions
 import ../platform/window
--- a/src/semicongine/vulkan/physicaldevice.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/physicaldevice.nim	Tue May 09 01:18:01 2023 +0700
@@ -3,7 +3,6 @@
 import std/sequtils
 
 import ../core
-import ./utils
 import ./instance
 
 type
--- a/src/semicongine/vulkan/pipeline.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/pipeline.nim	Tue May 09 01:18:01 2023 +0700
@@ -7,7 +7,6 @@
 import ./descriptor
 import ./shader
 import ./buffer
-import ./utils
 import ./image
 
 type
--- a/src/semicongine/vulkan/renderpass.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/renderpass.nim	Tue May 09 01:18:01 2023 +0700
@@ -2,7 +2,6 @@
 import std/logging
 
 import ../core
-import ./utils
 import ./device
 import ./physicaldevice
 import ./pipeline
--- a/src/semicongine/vulkan/shader.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/shader.nim	Tue May 09 01:18:01 2023 +0700
@@ -9,7 +9,6 @@
 
 import ../core
 import ./device
-import ./utils
 
 const DEFAULT_SHADER_VERSION = 450
 const DEFAULT_SHADER_ENTRYPOINT = "main"
--- a/src/semicongine/vulkan/swapchain.nim	Tue May 09 01:11:51 2023 +0700
+++ b/src/semicongine/vulkan/swapchain.nim	Tue May 09 01:18:01 2023 +0700
@@ -3,7 +3,6 @@
 import std/logging
 
 import ../core
-import ./utils
 import ./device
 import ./physicaldevice
 import ./image
--- a/src/semicongine/vulkan/utils.nim	Tue May 09 01:11:51 2023 +0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-import std/typetraits
-import std/strutils
-import std/strformat
-
-func cleanString*(str: openArray[char]): string =
-  for i in 0 ..< len(str):
-    if str[i] == char(0):
-      result = join(str[0 ..< i])
-      break
-
-func toCPointer*[T](list: var seq[T]): ptr T =
-  if list.len > 0: addr list[0] else: nil
-
-proc staticExecChecked*(command: string, input = ""): string {.compileTime.} =
-  let (output, exitcode) = gorgeEx(
-      command = command,
-      input = input)
-  if exitcode != 0:
-    raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output)
-  return output
-
-func size*[T: seq](list: T): uint64 =
-  uint64(list.len * sizeof(get(genericParams(typeof(list)), 0)))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_resources.nim	Tue May 09 01:18:01 2023 +0700
@@ -0,0 +1,32 @@
+import std/times
+
+import semicongine
+
+proc main() =
+  var scene = newScene("main", root=newEntity("rect", rect()))
+  var engine = initEngine("Test materials")
+  const
+    vertexInput = @[
+      attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
+    ]
+    fragOutput = @[attr[Vec4f]("color")]
+    vertexCode = compileGlslShader(
+      stage=VK_SHADER_STAGE_VERTEX_BIT,
+      inputs=vertexInput,
+      main="""gl_Position = vec4(position, 1.0);"""
+    )
+    fragmentCode = compileGlslShader(
+      stage=VK_SHADER_STAGE_FRAGMENT_BIT,
+      outputs=fragOutput,
+      main="""color = vec4(1, 0, 0, 1);"""
+    )
+  engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode))
+  engine.addScene(scene, vertexInput)
+  var t = cpuTime()
+  while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
+    engine.renderScene(scene)
+  engine.destroy()
+
+
+when isMainModule:
+  main()