Mercurial > games > semicongine
annotate semicongine/engine.nim @ 1072:d967f9029695
add: some more debug log
author | sam <sam@basx.dev> |
---|---|
date | Tue, 02 Apr 2024 23:06:39 +0700 |
parents | 86b9721dfc09 |
children | 7fb8f62a9ea5 |
rev | line source |
---|---|
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
1 import std/algorithm |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
2 import std/monotimes |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/options |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
4 import std/strformat |
909
f4bc149a385c
add: few string-ify methods, small fix for default-shaders
Sam <sam@basx.dev>
parents:
905
diff
changeset
|
5 import std/sequtils |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 import std/logging |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 import std/os |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 import ./platform/window |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 import ./core |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 import ./vulkan/instance |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 import ./vulkan/device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 import ./vulkan/physicaldevice |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 import ./vulkan/shader |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 import ./scene |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 import ./material |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 import ./renderer |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 import ./events |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 import ./audio |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 import ./text |
894 | 23 import ./panel |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 |
1065
86b9721dfc09
fix: again, I think, I have now a correct syncing of vertex buffers updates and drawing of multiple frames in flight XD
sam <sam@basx.dev>
parents:
1061
diff
changeset
|
25 const COUNT_N_RENDERTIMES = 199 |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
26 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 type |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 EngineState* = enum |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 Starting |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 Running |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 Shutdown |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 Input = object |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 keyIsDown: set[Key] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 keyWasPressed: set[Key] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 keyWasReleased: set[Key] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 mouseIsDown: set[MouseButton] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 mouseWasPressed: set[MouseButton] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 mouseWasReleased: set[MouseButton] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 mousePosition: Vec2f |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 mouseMove: Vec2f |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
41 eventsProcessed: uint64 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 windowWasResized: bool |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 mouseWheel: float32 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
44 Engine* = object |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
45 applicationName: string |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
46 debug: bool |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
47 showFps: bool |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
48 state*: EngineState |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
49 device: Device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
50 debugger: Debugger |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
51 instance: Instance |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
52 window: NativeWindow |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
53 renderer: Option[Renderer] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
54 input: Input |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
55 exitHandler: proc(engine: var Engine) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 resizeHandler: proc(engine: var Engine) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
57 eventHandler: proc(engine: var Engine, event: Event) |
859
a55410a08c63
add: better api for fullscreen management
sam <sam@basx.dev>
parents:
840
diff
changeset
|
58 fullscreen: bool |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
59 lastNRenderTimes: array[COUNT_N_RENDERTIMES, int64] |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
60 currentRenderTimeI: int = 0 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
61 |
1050
47a6fc0df3a9
did: cleanup unnecessasry annotations, comments
sam <sam@basx.dev>
parents:
1049
diff
changeset
|
62 # forward declarations |
47a6fc0df3a9
did: cleanup unnecessasry annotations, comments
sam <sam@basx.dev>
parents:
1049
diff
changeset
|
63 func getAspectRatio*(engine: Engine): float32 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
65 proc destroy*(engine: var Engine) = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 checkVkResult engine.device.vk.vkDeviceWaitIdle() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
67 if engine.renderer.isSome: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
68 engine.renderer.get.destroy() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
69 engine.device.destroy() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
70 if engine.debugger.messenger.valid: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
71 engine.debugger.destroy() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
72 engine.window.destroy() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 engine.instance.destroy() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
75 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 proc initEngine*( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 applicationName: string, |
894 | 78 debug = DEBUG, |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
79 showFps = DEBUG, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
80 exitHandler: proc(engine: var Engine) = nil, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
81 resizeHandler: proc(engine: var Engine) = nil, |
1045
e02d8e65d68e
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
82 eventHandler: proc(engine: var Engine, event: Event) = nil, |
e02d8e65d68e
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
83 vulkanVersion = VK_MAKE_API_VERSION(0, 1, 3, 0), |
e02d8e65d68e
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
84 vulkanLayers: openArray[string] = [], |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
85 ): Engine = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
86 echo "Set log level to ", ENGINE_LOGLEVEL |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
87 setLogFilter(ENGINE_LOGLEVEL) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
88 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
89 result.state = Starting |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
90 result.exitHandler = exitHandler |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
91 result.resizeHandler = resizeHandler |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
92 result.eventHandler = eventHandler |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
93 result.applicationName = applicationName |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
94 result.debug = debug |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
95 result.showFps = showFps |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
96 result.window = createWindow(result.applicationName) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
97 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
98 var |
1045
e02d8e65d68e
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
99 layers = @vulkanLayers |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
100 instanceExtensions: seq[string] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
101 |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
102 if result.debug: |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
103 instanceExtensions.add "VK_EXT_debug_utils" |
1045
e02d8e65d68e
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
104 layers.add "VK_LAYER_KHRONOS_validation" |
1050
47a6fc0df3a9
did: cleanup unnecessasry annotations, comments
sam <sam@basx.dev>
parents:
1049
diff
changeset
|
105 # This stuff might be usefull if we one day to smart GPU memory allocation, |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
106 # but right now it just clobbers up the console log: |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
107 # putEnv("VK_LAYER_ENABLES", "VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT") |
1049
93623146dd61
fix: last commit was actually only relevant for ARM, also adjust validation outputs
sam <sam@basx.dev>
parents:
1045
diff
changeset
|
108 putEnv("VK_LAYER_ENABLES", "VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_AMD,VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_NVIDIA,VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXTVK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT,VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT") |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
109 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
110 result.instance = result.window.createInstance( |
1045
e02d8e65d68e
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
111 vulkanVersion = vulkanVersion, |
894 | 112 instanceExtensions = instanceExtensions, |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
113 layers = layers.deduplicate(), |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
114 ) |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
115 if result.debug: |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
116 result.debugger = result.instance.createDebugMessenger() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
117 # create devices |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
118 let selectedPhysicalDevice = result.instance.getPhysicalDevices().filterBestGraphics() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
119 result.device = result.instance.createDevice( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
120 selectedPhysicalDevice, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
121 enabledExtensions = @[], |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
122 selectedPhysicalDevice.filterForGraphicsPresentationQueues() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
123 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
124 startMixerThread() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
125 |
1058
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
126 proc initRenderer*( |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
127 engine: var Engine, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
128 shaders: openArray[(MaterialType, ShaderConfiguration)], |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
129 clearColor = newVec4f(0, 0, 0, 0), |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
130 backFaceCulling = true, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
131 vSync = false, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
132 inFlightFrames = 2, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
133 ) = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
134 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
135 assert not engine.renderer.isSome |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
136 var allShaders = @shaders |
909
f4bc149a385c
add: few string-ify methods, small fix for default-shaders
Sam <sam@basx.dev>
parents:
905
diff
changeset
|
137 if not shaders.mapIt(it[0]).contains(EMPTY_MATERIAL): |
f4bc149a385c
add: few string-ify methods, small fix for default-shaders
Sam <sam@basx.dev>
parents:
905
diff
changeset
|
138 allShaders.add (EMPTY_MATERIAL, EMPTY_SHADER) |
f4bc149a385c
add: few string-ify methods, small fix for default-shaders
Sam <sam@basx.dev>
parents:
905
diff
changeset
|
139 if not shaders.mapIt(it[0]).contains(PANEL_MATERIAL_TYPE): |
f4bc149a385c
add: few string-ify methods, small fix for default-shaders
Sam <sam@basx.dev>
parents:
905
diff
changeset
|
140 allShaders.add (PANEL_MATERIAL_TYPE, PANEL_SHADER) |
f4bc149a385c
add: few string-ify methods, small fix for default-shaders
Sam <sam@basx.dev>
parents:
905
diff
changeset
|
141 if not shaders.mapIt(it[0]).contains(TEXT_MATERIAL_TYPE): |
f4bc149a385c
add: few string-ify methods, small fix for default-shaders
Sam <sam@basx.dev>
parents:
905
diff
changeset
|
142 allShaders.add (TEXT_MATERIAL_TYPE, TEXT_SHADER) |
1058
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
143 engine.renderer = some(engine.device.initRenderer( |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
144 shaders = allShaders, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
145 clearColor = clearColor, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
146 backFaceCulling = backFaceCulling, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
147 vSync = vSync, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
148 inFlightFrames = inFlightFrames, |
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
149 )) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
150 |
1058
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
151 proc initRenderer*(engine: var Engine, clearColor = newVec4f(0, 0, 0, 0), vSync = false) = |
1065
86b9721dfc09
fix: again, I think, I have now a correct syncing of vertex buffers updates and drawing of multiple frames in flight XD
sam <sam@basx.dev>
parents:
1061
diff
changeset
|
152 checkVkResult engine.device.vk.vkDeviceWaitIdle() |
1058
7a0d5fc00f4f
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
1052
diff
changeset
|
153 engine.initRenderer(@[], clearColor, vSync = vSync) |
1065
86b9721dfc09
fix: again, I think, I have now a correct syncing of vertex buffers updates and drawing of multiple frames in flight XD
sam <sam@basx.dev>
parents:
1061
diff
changeset
|
154 checkVkResult engine.device.vk.vkDeviceWaitIdle() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
155 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
156 proc loadScene*(engine: var Engine, scene: var Scene) = |
1072 | 157 debug &"start loading scene '{scene.name}'" |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
158 assert engine.renderer.isSome |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
159 assert not scene.loaded |
1065
86b9721dfc09
fix: again, I think, I have now a correct syncing of vertex buffers updates and drawing of multiple frames in flight XD
sam <sam@basx.dev>
parents:
1061
diff
changeset
|
160 checkVkResult engine.device.vk.vkDeviceWaitIdle() |
904
a253a691e0d6
fix: font-api, allow consistent use of mesh-transform
Sam <sam@basx.dev>
parents:
903
diff
changeset
|
161 scene.addShaderGlobal(ASPECT_RATIO_ATTRIBUTE, engine.getAspectRatio) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
162 engine.renderer.get.setupDrawableBuffers(scene) |
894 | 163 engine.renderer.get.updateMeshData(scene, forceAll = true) |
164 engine.renderer.get.updateUniformData(scene, forceAll = true) | |
1065
86b9721dfc09
fix: again, I think, I have now a correct syncing of vertex buffers updates and drawing of multiple frames in flight XD
sam <sam@basx.dev>
parents:
1061
diff
changeset
|
165 checkVkResult engine.device.vk.vkDeviceWaitIdle() |
1072 | 166 debug &"done loading scene '{scene.name}'" |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
167 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
168 proc unloadScene*(engine: var Engine, scene: Scene) = |
1072 | 169 debug &"unload scene '{scene.name}'" |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
170 engine.renderer.get.destroy(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
171 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
172 proc renderScene*(engine: var Engine, scene: var Scene) = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
173 assert engine.state == Running |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
174 assert engine.renderer.isSome |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
175 let t0 = getMonoTime() |
1061
71a23166ccd6
fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents:
1059
diff
changeset
|
176 |
71a23166ccd6
fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents:
1059
diff
changeset
|
177 engine.renderer.get.startNewFrame() |
904
a253a691e0d6
fix: font-api, allow consistent use of mesh-transform
Sam <sam@basx.dev>
parents:
903
diff
changeset
|
178 scene.setShaderGlobal(ASPECT_RATIO_ATTRIBUTE, engine.getAspectRatio) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
179 engine.renderer.get.updateMeshData(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
180 engine.renderer.get.updateUniformData(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
181 engine.renderer.get.render(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
182 |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
183 if engine.showFps: |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
184 let nanoSecs = getMonoTime().ticks - t0.ticks |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
185 engine.lastNRenderTimes[engine.currentRenderTimeI] = nanoSecs |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
186 inc engine.currentRenderTimeI |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
187 if engine.currentRenderTimeI >= engine.lastNRenderTimes.len: |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
188 engine.currentRenderTimeI = 0 |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
189 engine.lastNRenderTimes.sort |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
190 let |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
191 min = float(engine.lastNRenderTimes[0]) / 1_000_000 |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
192 median = float(engine.lastNRenderTimes[engine.lastNRenderTimes.len div 2]) / 1_000_000 |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
193 max = float(engine.lastNRenderTimes[^1]) / 1_000_000 |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
194 engine.window.setTitle(&"{engine.applicationName} ({min:.2}, {median:.2}, {max:.2})") |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
195 |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
1058
diff
changeset
|
196 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
197 proc updateInputs*(engine: var Engine): EngineState = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
198 assert engine.state in [Starting, Running] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
199 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
200 # reset input states |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
201 engine.input.keyWasPressed = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
202 engine.input.keyWasReleased = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
203 engine.input.mouseWasPressed = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
204 engine.input.mouseWasReleased = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
205 engine.input.mouseWheel = 0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
206 engine.input.mouseMove = newVec2f() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
207 engine.input.windowWasResized = false |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
208 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
209 if engine.state == Starting: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
210 engine.input.windowWasResized = true |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
211 var mpos = engine.window.getMousePosition() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
212 if mpos.isSome: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
213 engine.input.mousePosition = mpos.get |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
214 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
215 var killed = false |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
216 for event in engine.window.pendingEvents(): |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
217 inc engine.input.eventsProcessed |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
218 if engine.eventHandler != nil: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
219 engine.eventHandler(engine, event) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
220 case event.eventType: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
221 of Quit: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
222 killed = true |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
223 of ResizedWindow: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
224 engine.input.windowWasResized = true |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
225 of KeyPressed: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
226 engine.input.keyWasPressed.incl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
227 engine.input.keyIsDown.incl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
228 of KeyReleased: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
229 engine.input.keyWasReleased.incl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
230 engine.input.keyIsDown.excl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
231 of MousePressed: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
232 engine.input.mouseWasPressed.incl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
233 engine.input.mouseIsDown.incl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
234 of MouseReleased: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
235 engine.input.mouseWasReleased.incl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
236 engine.input.mouseIsDown.excl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
237 of MouseMoved: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
238 let newPos = newVec2(float32(event.x), float32(event.y)) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
239 engine.input.mouseMove = newPos - engine.input.mousePosition |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
240 engine.input.mousePosition = newPos |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
241 of MouseWheel: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
242 engine.input.mouseWheel = event.amount |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
243 if engine.state == Starting: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
244 engine.state = Running |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
245 if killed: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
246 engine.state = Shutdown |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
247 if engine.exitHandler != nil: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
248 engine.exitHandler(engine) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
249 if engine.input.windowWasResized and engine.resizeHandler != nil: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
250 engine.resizeHandler(engine) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
251 return engine.state |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
252 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
253 # wrappers for internal things |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
254 func keyIsDown*(engine: Engine, key: Key): auto = key in engine.input.keyIsDown |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
255 func keyWasPressed*(engine: Engine, key: Key): auto = key in engine.input.keyWasPressed |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
256 func keyWasPressed*(engine: Engine): auto = engine.input.keyWasPressed.len > 0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
257 func keyWasReleased*(engine: Engine, key: Key): auto = key in engine.input.keyWasReleased |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
258 func mouseIsDown*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseIsDown |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
259 func mouseWasPressed*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseWasPressed |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
260 func mouseWasReleased*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseWasReleased |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
261 func mousePosition*(engine: Engine): auto = engine.input.mousePosition |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
262 func mousePositionNormalized*(engine: Engine): Vec2f = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
263 result.x = (engine.input.mousePosition.x / float32(engine.window.size[0])) * 2.0 - 1.0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
264 result.y = (engine.input.mousePosition.y / float32(engine.window.size[1])) * 2.0 - 1.0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
265 func mouseMove*(engine: Engine): auto = engine.input.mouseMove |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
266 func mouseWheel*(engine: Engine): auto = engine.input.mouseWheel |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
267 func eventsProcessed*(engine: Engine): auto = engine.input.eventsProcessed |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
268 func gpuDevice*(engine: Engine): Device = engine.device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
269 func getWindow*(engine: Engine): auto = engine.window |
904
a253a691e0d6
fix: font-api, allow consistent use of mesh-transform
Sam <sam@basx.dev>
parents:
903
diff
changeset
|
270 func getAspectRatio*(engine: Engine): float32 = engine.getWindow().size[0] / engine.getWindow().size[1] |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
271 func windowWasResized*(engine: Engine): auto = engine.input.windowWasResized |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
272 func showSystemCursor*(engine: Engine) = engine.window.showSystemCursor() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
273 func hideSystemCursor*(engine: Engine) = engine.window.hideSystemCursor() |
859
a55410a08c63
add: better api for fullscreen management
sam <sam@basx.dev>
parents:
840
diff
changeset
|
274 func fullscreen*(engine: Engine): bool = engine.fullscreen |
a55410a08c63
add: better api for fullscreen management
sam <sam@basx.dev>
parents:
840
diff
changeset
|
275 proc `fullscreen=`*(engine: var Engine, enable: bool) = |
862
e5d7e3f6826e
fix: do not try to change fullscreen if already in correct status
sam <sam@basx.dev>
parents:
859
diff
changeset
|
276 if enable != engine.fullscreen: |
e5d7e3f6826e
fix: do not try to change fullscreen if already in correct status
sam <sam@basx.dev>
parents:
859
diff
changeset
|
277 engine.fullscreen = enable |
e5d7e3f6826e
fix: do not try to change fullscreen if already in correct status
sam <sam@basx.dev>
parents:
859
diff
changeset
|
278 engine.window.fullscreen(engine.fullscreen) |
872
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
862
diff
changeset
|
279 |
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
862
diff
changeset
|
280 func limits*(engine: Engine): VkPhysicalDeviceLimits = |
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
862
diff
changeset
|
281 engine.gpuDevice().physicalDevice.properties.limits |
895 | 282 |
905 | 283 proc processEvents*(engine: Engine, panel: var Panel) = |
284 let hasMouseNow = panel.contains(engine.mousePositionNormalized, engine.getAspectRatio) | |
895 | 285 |
286 # enter/leave events | |
287 if hasMouseNow: | |
288 if panel.hasMouse: | |
289 if panel.onMouseMove != nil: panel.onMouseMove(panel) | |
290 else: | |
291 if panel.onMouseEnter != nil: panel.onMouseEnter(panel) | |
292 else: | |
293 if panel.hasMouse: | |
294 if panel.onMouseLeave != nil: panel.onMouseLeave(panel) | |
295 | |
296 # button events | |
297 if hasMouseNow: | |
298 if engine.input.mouseWasPressed.len > 0: | |
299 if panel.onMouseDown != nil: panel.onMouseDown(panel, engine.input.mouseWasPressed) | |
300 if engine.input.mouseWasReleased.len > 0: | |
301 if panel.onMouseUp != nil: panel.onMouseUp(panel, engine.input.mouseWasReleased) | |
302 | |
303 panel.hasMouse = hasMouseNow |