changeset 523:311ee4e58032

fix: some formatting, bug when opening on windows.
author Sam <sam@basx.dev>
date Wed, 25 Jan 2023 23:56:59 +0700
parents f2c97bdbb0b3
children 37e42b3b120d
files config.nims src/semicongine/engine.nim src/semicongine/mesh.nim src/semicongine/thing.nim
diffstat 4 files changed, 45 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/config.nims	Tue Jan 24 10:22:38 2023 +0700
+++ b/config.nims	Wed Jan 25 23:56:59 2023 +0700
@@ -116,7 +116,7 @@
     exec(&"scp {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/release/windows/")
 
 task glslangValidator, "Download glslangValidator (required for linux compilation)":
-  let dirname="/tmp/glslang_download"
+  let dirname = "/tmp/glslang_download"
   exec &"mkdir -p {dirname}"
   exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip"
   exec &"cd {dirname} && unzip *.zip"
@@ -124,14 +124,14 @@
   exec &"rm -rf {dirname}"
 
 task glslangValidator_exe, "Download glslangValidator.exe (required for windows compilation)":
-  let dirname="/tmp/glslang_download"
+  let dirname = "/tmp/glslang_download"
   exec &"mkdir -p {dirname}"
   exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip"
   exec &"cd {dirname} && unzip *.zip"
   exec &"mv {dirname}/bin/glslangValidator.exe examples/"
   exec &"rm -rf {dirname}"
 
-task run_all , "Run all binaries":
+task run_all, "Run all binaries":
   for file in listFiles("build/debug/linux"):
     exec file
   for file in listFiles("build/release/linux"):
--- a/src/semicongine/engine.nim	Tue Jan 24 10:22:38 2023 +0700
+++ b/src/semicongine/engine.nim	Wed Jan 25 23:56:59 2023 +0700
@@ -199,6 +199,11 @@
   var imageCount = capabilities.minImageCount + 1
   if capabilities.maxImageCount > 0:
     imageCount = min(capabilities.maxImageCount, imageCount)
+  # TODO: fix when dimension is zero
+  var extent = VkExtent2D(
+    width: if dimension[0] > 0: dimension[0] else: 1,
+    height: if dimension[1] > 0: dimension[1] else: 1,
+  )
   # setup swapchain
   var swapchainCreateInfo = VkSwapchainCreateInfoKHR(
     sType: VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
@@ -206,10 +211,10 @@
     minImageCount: imageCount,
     imageFormat: surfaceFormat.format,
     imageColorSpace: surfaceFormat.colorSpace,
-    imageExtent: VkExtent2D(width: dimension[0], height: dimension[1]),
+    imageExtent: extent,
     imageArrayLayers: 1,
     imageUsage: VkImageUsageFlags(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT),
-    # VK_SHARING_MODE_CONCURRENT no supported (i.e cannot use different queue families for  drawing to swap surface?)
+    # VK_SHARING_MODE_CONCURRENT no supported (i.e cannot use different queue families for drawing to swap surface?)
     imageSharingMode: VK_SHARING_MODE_EXCLUSIVE,
     preTransform: capabilities.currentTransform,
     compositeAlpha: VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
--- a/src/semicongine/mesh.nim	Tue Jan 24 10:22:38 2023 +0700
+++ b/src/semicongine/mesh.nim	Wed Jan 25 23:56:59 2023 +0700
@@ -22,7 +22,8 @@
           when srcname == dstname:
             dstvalue.data.add srcvalue.data
 
-func createUberMesh*[T: object, U: uint16|uint32](meshes: openArray[IndexedMesh[T, U]]): IndexedMesh[T, U] =
+func createUberMesh*[T: object, U: uint16|uint32](meshes: openArray[IndexedMesh[
+    T, U]]): IndexedMesh[T, U] =
   var indexoffset = U(0)
   for mesh in meshes:
     for srcname, srcvalue in mesh.vertexData.fieldPairs:
@@ -36,10 +37,11 @@
       result.indices.add indexdata
     indexoffset += U(mesh.vertexData.VertexCount)
 
-func getVkIndexType[T: object, U: uint16|uint32](m: IndexedMesh[T, U]): VkIndexType =
+func getVkIndexType[T: object, U: uint16|uint32](m: IndexedMesh[T,
+    U]): VkIndexType =
   when U is uint16: VK_INDEX_TYPE_UINT16
   elif U is uint32: VK_INDEX_TYPE_UINT32
-      
+
 proc createVertexBuffers*[M: Mesh|IndexedMesh](
   mesh: M,
   device: VkDevice,
@@ -52,12 +54,15 @@
     when typeof(value) is VertexAttribute:
       assert value.data.len > 0
       var flags = if value.useOnDeviceMemory: {TransferSrc} else: {VertexBuffer}
-      var stagingBuffer = device.InitBuffer(physicalDevice, value.datasize, flags, {HostVisible, HostCoherent})
+      var stagingBuffer = device.InitBuffer(physicalDevice, value.datasize,
+          flags, {HostVisible, HostCoherent})
       copyMem(stagingBuffer.data, addr(value.data[0]), value.datasize)
 
       if value.useOnDeviceMemory:
-        var finalBuffer = device.InitBuffer(physicalDevice, value.datasize, {TransferDst, VertexBuffer}, {DeviceLocal})
-        transferBuffer(commandPool, queue, stagingBuffer, finalBuffer, value.datasize)
+        var finalBuffer = device.InitBuffer(physicalDevice, value.datasize, {
+            TransferDst, VertexBuffer}, {DeviceLocal})
+        transferBuffer(commandPool, queue, stagingBuffer, finalBuffer,
+            value.datasize)
         stagingBuffer.trash()
         result[0].add(finalBuffer)
         value.buffer = finalBuffer
@@ -73,14 +78,17 @@
   queue: VkQueue,
   useDeviceLocalBuffer: bool = true # decides if data is transfered to the fast device-local memory or not
 ): Buffer =
-  let bufferSize = uint64(mesh.indices.len * sizeof(get(genericParams(typeof(mesh.indices)), 0)))
+  let bufferSize = uint64(mesh.indices.len * sizeof(get(genericParams(typeof(
+      mesh.indices)), 0)))
   let flags = if useDeviceLocalBuffer: {TransferSrc} else: {IndexBuffer}
 
-  var stagingBuffer = device.InitBuffer(physicalDevice, bufferSize, flags, {HostVisible, HostCoherent})
+  var stagingBuffer = device.InitBuffer(physicalDevice, bufferSize, flags, {
+      HostVisible, HostCoherent})
   copyMem(stagingBuffer.data, addr(mesh.indices[0]), bufferSize)
 
   if useDeviceLocalBuffer:
-    var finalBuffer = device.InitBuffer(physicalDevice, bufferSize, {TransferDst, IndexBuffer}, {DeviceLocal})
+    var finalBuffer = device.InitBuffer(physicalDevice, bufferSize, {
+        TransferDst, IndexBuffer}, {DeviceLocal})
     transferBuffer(commandPool, queue, stagingBuffer, finalBuffer, bufferSize)
     stagingBuffer.trash()
     return finalBuffer
@@ -95,15 +103,27 @@
   queue: VkQueue,
   useDeviceLocalBufferForIndices: bool = true # decides if data is transfered to the fast device-local memory or not
 ): (seq[Buffer], Buffer, uint32, VkIndexType) =
-  result[0] = createVertexBuffers(mesh, device, physicalDevice, commandPool, queue)[0]
-  result[1] = createIndexBuffer(mesh, device, physicalDevice, commandPool, queue, useDeviceLocalBufferForIndices)
+  result[0] = createVertexBuffers(mesh, device, physicalDevice, commandPool,
+      queue)[0]
+  result[1] = createIndexBuffer(mesh, device, physicalDevice, commandPool,
+      queue, useDeviceLocalBufferForIndices)
   result[2] = uint32(mesh.indices.len * mesh.indices[0].len)
 
   result[3] = getVkIndexType(mesh)
 
-func squareData*[T:SomeFloat](): auto = PositionAttribute[TVec2[T]](
-  data: @[TVec2[T]([T(0), T(0)]), TVec2[T]([T(0), T(1)]), TVec2[T]([T(1), T(1)]), TVec2[T]([T(1), T(0)])]
+func squareData*[T: SomeFloat](): auto = PositionAttribute[TVec2[T]](
+  data: @[TVec2[T]([T(0), T(0)]), TVec2[T]([T(0), T(1)]), TVec2[T]([T(1), T(
+      1)]), TVec2[T]([T(1), T(0)])]
 )
-func squareIndices*[T:uint16|uint32](): auto = seq[array[3, T]](
+func squareIndices*[T: uint16|uint32](): auto = seq[array[3, T]](
   @[[T(0), T(1), T(3)], [T(2), T(1), T(3)]]
 )
+
+method update*(mesh: Mesh, dt: float32) =
+  echo "The update"
+  echo mesh.thing.getModelTransform()
+  echo mesh.vertexData
+method update*(mesh: IndexedMesh, dt: float32) =
+  echo "The update"
+  echo mesh.thing.getModelTransform()
+  echo mesh.vertexData
--- a/src/semicongine/thing.nim	Tue Jan 24 10:22:38 2023 +0700
+++ b/src/semicongine/thing.nim	Wed Jan 25 23:56:59 2023 +0700
@@ -130,16 +130,5 @@
       queue.add child
     yield next
 
-method update*(thing: Thing, dt: float32) {.base.} =
-  echo "The update"
-  let transform = thing.getModelTransform()
-  for part in thing.parts:
-    echo "  The part ", part
-    for name, value in part[].fieldPairs:
-      echo "    attribute ", name
-      when typeof(value) is ModelTransformAttribute:
-        value.data = @[transform.transposed()]
-        echo "updated stuff"
-
+method update*(thing: Thing, dt: float32) {.base.} = discard
 method update*(part: Part, dt: float32) {.base.} = discard
-