# HG changeset patch # User Sam # Date 1683569881 -25200 # Node ID a02d503ffa533bb69718f12f27128b0b0d2bc62e # Parent d3500ae5d23586cf425923d5c0327e816df6cd80 add: some adjustment to the last refactoring :P diff -r d3500ae5d235 -r a02d503ffa53 config.nims --- 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"]: diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/core.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/core/utils.nim --- /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))) diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/commandbuffer.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/descriptor.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/device.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/drawable.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/framebuffer.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/instance.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/physicaldevice.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/pipeline.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/renderpass.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/shader.nim --- 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" diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/swapchain.nim --- 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 diff -r d3500ae5d235 -r a02d503ffa53 src/semicongine/vulkan/utils.nim --- 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))) diff -r d3500ae5d235 -r a02d503ffa53 tests/test_resources.nim --- /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()