Mercurial > games > semicongine
annotate semicongine/engine.nim @ 950:fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
author | sam <sam@basx.dev> |
---|---|
date | Sun, 31 Mar 2024 22:11:50 +0700 |
parents | 0cf68e7336e8 |
children | c6213a794ab0 |
rev | line source |
---|---|
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
1 import std/algorithm |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
25 const COUNT_N_RENDERTIMES = 99 |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
45 applicationName: string |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
46 debug: bool |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
59 lastNRenderTimes: array[COUNT_N_RENDERTIMES, int64] |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 |
941
e3ef8ebdda46
did: cleanup unnecessasry annotations, comments
sam <sam@basx.dev>
parents:
940
diff
changeset
|
62 # forward declarations |
e3ef8ebdda46
did: cleanup unnecessasry annotations, comments
sam <sam@basx.dev>
parents:
940
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, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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, |
937
d27e28f9d8ab
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
82 eventHandler: proc(engine: var Engine, event: Event) = nil, |
d27e28f9d8ab
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), |
d27e28f9d8ab
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 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
93 result.applicationName = applicationName |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
94 result.debug = debug |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
95 result.showFps = showFps |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 |
937
d27e28f9d8ab
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 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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" |
937
d27e28f9d8ab
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
104 layers.add "VK_LAYER_KHRONOS_validation" |
941
e3ef8ebdda46
did: cleanup unnecessasry annotations, comments
sam <sam@basx.dev>
parents:
940
diff
changeset
|
105 # This stuff might be usefull if we one day to smart GPU memory allocation, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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") |
940
459066429a72
fix: last commit was actually only relevant for ARM, also adjust validation outputs
sam <sam@basx.dev>
parents:
937
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( |
937
d27e28f9d8ab
fix: a few small (vulkan) API optimizations
sam <sam@basx.dev>
parents:
920
diff
changeset
|
111 vulkanVersion = vulkanVersion, |
894 | 112 instanceExtensions = instanceExtensions, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 ) |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
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 |
949
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
126 proc initRenderer*( |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
127 engine: var Engine, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
128 shaders: openArray[(MaterialType, ShaderConfiguration)], |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
129 clearColor = newVec4f(0, 0, 0, 0), |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
130 backFaceCulling = true, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
131 vSync = false, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
132 inFlightFrames = 2, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
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) |
949
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
143 engine.renderer = some(engine.device.initRenderer( |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
144 shaders = allShaders, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
145 clearColor = clearColor, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
146 backFaceCulling = backFaceCulling, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
147 vSync = vSync, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
148 inFlightFrames = inFlightFrames, |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
149 )) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
150 |
949
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
151 proc initRenderer*(engine: var Engine, clearColor = newVec4f(0, 0, 0, 0), vSync = false) = |
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
943
diff
changeset
|
152 engine.initRenderer(@[], clearColor, vSync = vSync) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
153 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
154 proc loadScene*(engine: var Engine, scene: var Scene) = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
155 assert engine.renderer.isSome |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
156 assert not scene.loaded |
904
a253a691e0d6
fix: font-api, allow consistent use of mesh-transform
Sam <sam@basx.dev>
parents:
903
diff
changeset
|
157 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
|
158 engine.renderer.get.setupDrawableBuffers(scene) |
894 | 159 engine.renderer.get.updateMeshData(scene, forceAll = true) |
160 engine.renderer.get.updateUniformData(scene, forceAll = true) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
161 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
162 proc unloadScene*(engine: var Engine, scene: Scene) = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
163 engine.renderer.get.destroy(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
164 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
165 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
|
166 assert engine.state == Running |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
167 assert engine.renderer.isSome |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
168 let t0 = getMonoTime() |
904
a253a691e0d6
fix: font-api, allow consistent use of mesh-transform
Sam <sam@basx.dev>
parents:
903
diff
changeset
|
169 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
|
170 engine.renderer.get.updateMeshData(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
171 engine.renderer.get.updateUniformData(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
172 engine.renderer.get.render(scene) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
173 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
174 if engine.showFps: |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
175 let nanoSecs = getMonoTime().ticks - t0.ticks |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
176 engine.lastNRenderTimes[engine.currentRenderTimeI] = nanoSecs |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
177 inc engine.currentRenderTimeI |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
178 if engine.currentRenderTimeI >= engine.lastNRenderTimes.len: |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
179 engine.currentRenderTimeI = 0 |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
180 engine.lastNRenderTimes.sort |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
181 let |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
182 min = float(engine.lastNRenderTimes[0]) / 1_000_000 |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
183 median = float(engine.lastNRenderTimes[engine.lastNRenderTimes.len div 2]) / 1_000_000 |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
184 max = float(engine.lastNRenderTimes[^1]) / 1_000_000 |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
185 engine.window.setTitle(&"{engine.applicationName} ({min:.2}, {median:.2}, {max:.2})") |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
186 |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
187 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
188 proc updateInputs*(engine: var Engine): EngineState = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
189 assert engine.state in [Starting, Running] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
190 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
191 # reset input states |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
192 engine.input.keyWasPressed = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
193 engine.input.keyWasReleased = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
194 engine.input.mouseWasPressed = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
195 engine.input.mouseWasReleased = {} |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
196 engine.input.mouseWheel = 0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
197 engine.input.mouseMove = newVec2f() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
198 engine.input.windowWasResized = false |
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 if engine.state == Starting: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
201 engine.input.windowWasResized = true |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
202 var mpos = engine.window.getMousePosition() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
203 if mpos.isSome: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
204 engine.input.mousePosition = mpos.get |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
205 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
206 var killed = false |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
207 for event in engine.window.pendingEvents(): |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
208 inc engine.input.eventsProcessed |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
209 if engine.eventHandler != nil: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
210 engine.eventHandler(engine, event) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
211 case event.eventType: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
212 of Quit: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
213 killed = true |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
214 of ResizedWindow: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
215 engine.input.windowWasResized = true |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
216 of KeyPressed: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
217 engine.input.keyWasPressed.incl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
218 engine.input.keyIsDown.incl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
219 of KeyReleased: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
220 engine.input.keyWasReleased.incl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
221 engine.input.keyIsDown.excl event.key |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
222 of MousePressed: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
223 engine.input.mouseWasPressed.incl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
224 engine.input.mouseIsDown.incl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
225 of MouseReleased: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
226 engine.input.mouseWasReleased.incl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
227 engine.input.mouseIsDown.excl event.button |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
228 of MouseMoved: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
229 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
|
230 engine.input.mouseMove = newPos - engine.input.mousePosition |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
231 engine.input.mousePosition = newPos |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
232 of MouseWheel: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
233 engine.input.mouseWheel = event.amount |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
234 if engine.state == Starting: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
235 engine.state = Running |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
236 if killed: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
237 engine.state = Shutdown |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
238 if engine.exitHandler != nil: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
239 engine.exitHandler(engine) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
240 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
|
241 engine.resizeHandler(engine) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
242 return engine.state |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
243 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
244 # wrappers for internal things |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 func mousePositionNormalized*(engine: Engine): Vec2f = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 func gpuDevice*(engine: Engine): Device = engine.device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 func showSystemCursor*(engine: Engine) = engine.window.showSystemCursor() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
264 func hideSystemCursor*(engine: Engine) = engine.window.hideSystemCursor() |
859
a55410a08c63
add: better api for fullscreen management
sam <sam@basx.dev>
parents:
840
diff
changeset
|
265 func fullscreen*(engine: Engine): bool = engine.fullscreen |
a55410a08c63
add: better api for fullscreen management
sam <sam@basx.dev>
parents:
840
diff
changeset
|
266 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
|
267 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
|
268 engine.fullscreen = enable |
e5d7e3f6826e
fix: do not try to change fullscreen if already in correct status
sam <sam@basx.dev>
parents:
859
diff
changeset
|
269 engine.window.fullscreen(engine.fullscreen) |
872
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
862
diff
changeset
|
270 |
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
862
diff
changeset
|
271 func limits*(engine: Engine): VkPhysicalDeviceLimits = |
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
862
diff
changeset
|
272 engine.gpuDevice().physicalDevice.properties.limits |
895 | 273 |
905 | 274 proc processEvents*(engine: Engine, panel: var Panel) = |
275 let hasMouseNow = panel.contains(engine.mousePositionNormalized, engine.getAspectRatio) | |
895 | 276 |
277 # enter/leave events | |
278 if hasMouseNow: | |
279 if panel.hasMouse: | |
280 if panel.onMouseMove != nil: panel.onMouseMove(panel) | |
281 else: | |
282 if panel.onMouseEnter != nil: panel.onMouseEnter(panel) | |
283 else: | |
284 if panel.hasMouse: | |
285 if panel.onMouseLeave != nil: panel.onMouseLeave(panel) | |
286 | |
287 # button events | |
288 if hasMouseNow: | |
289 if engine.input.mouseWasPressed.len > 0: | |
290 if panel.onMouseDown != nil: panel.onMouseDown(panel, engine.input.mouseWasPressed) | |
291 if engine.input.mouseWasReleased.len > 0: | |
292 if panel.onMouseUp != nil: panel.onMouseUp(panel, engine.input.mouseWasReleased) | |
293 | |
294 panel.hasMouse = hasMouseNow |