annotate src/semicongine/engine.nim @ 627:34e536f7001f

add: support for showing/hiding cursur, X11 fullscreen (win32 still missing)
author Sam <sam@basx.dev>
date Sun, 30 Apr 2023 01:02:33 +0700
parents bf2f4a9cd962
children 4d4f7a2eb6ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
603
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
1 import std/sequtils
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
2 import ./platform/window
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
3
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
4 import ./vulkan/api
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
5 import ./vulkan/instance
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
6 import ./vulkan/device
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
7 import ./vulkan/physicaldevice
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
8 import ./vulkan/renderpass
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
9
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
10 import ./gpu_data
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
11 import ./entity
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
12 import ./renderer
603
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
13 import ./mesh
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
14 import ./events
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
15 import ./config
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
16 import ./math
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
17
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
18 type
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
19 EngineState* = enum
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
20 Starting
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
21 Running
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
22 Shutdown
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
23 Destroyed
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
24 Input = object
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
25 keyIsDown: set[Key]
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
26 keyWasPressed: set[Key]
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
27 keyWasReleased: set[Key]
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
28 mouseIsDown: set[MouseButton]
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
29 mouseWasPressed: set[MouseButton]
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
30 mouseWasReleased: set[MouseButton]
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
31 mousePosition: Vec2f
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
32 eventsProcessed: uint64
605
510c651cb27d add: window-resize check
Sam <sam@basx.dev>
parents: 603
diff changeset
33 windowWasResized: bool
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
34 Engine* = object
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
35 state*: EngineState
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
36 device: Device
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
37 debugger: Debugger
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
38 instance: Instance
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
39 window: NativeWindow
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
40 renderer: Renderer
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
41 input: Input
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
42 exitHandler: proc(engine: var Engine)
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
43 resizeHandler: proc(engine: var Engine)
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
44 eventHandler: proc(engine: var Engine, event: Event)
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
45
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
46
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
47 proc destroy*(engine: var Engine) =
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
48 checkVkResult engine.device.vk.vkDeviceWaitIdle()
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
49 engine.renderer.destroy()
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
50 engine.device.destroy()
595
7f7e797335ed add: remove a few warning, improve a few things
Sam <sam@basx.dev>
parents: 594
diff changeset
51 if engine.debugger.messenger.valid:
7f7e797335ed add: remove a few warning, improve a few things
Sam <sam@basx.dev>
parents: 594
diff changeset
52 engine.debugger.destroy()
7f7e797335ed add: remove a few warning, improve a few things
Sam <sam@basx.dev>
parents: 594
diff changeset
53 engine.window.destroy()
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
54 engine.instance.destroy()
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
55 engine.state = Destroyed
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
56
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
57
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
58 proc initEngine*(
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
59 applicationName: string,
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
60 debug=DEBUG,
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
61 exitHandler: proc(engine: var Engine) = nil,
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
62 resizeHandler: proc(engine: var Engine) = nil,
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
63 eventHandler: proc(engine: var Engine, event: Event) = nil
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
64 ): Engine =
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
65 result.state = Starting
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
66 result.exitHandler = exitHandler
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
67 result.resizeHandler = resizeHandler
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
68 result.eventHandler = eventHandler
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
69 result.window = createWindow(applicationName)
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
70
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
71 var
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
72 instanceExtensions: seq[string]
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
73 enabledLayers: seq[string]
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
74
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
75 if debug:
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
76 instanceExtensions.add "VK_EXT_debug_utils"
613
40f5d804eca6 fix: wrong layers activated
Sam <sam@basx.dev>
parents: 606
diff changeset
77 enabledLayers.add "VK_LAYER_KHRONOS_validation"
40f5d804eca6 fix: wrong layers activated
Sam <sam@basx.dev>
parents: 606
diff changeset
78 if defined(linux):
40f5d804eca6 fix: wrong layers activated
Sam <sam@basx.dev>
parents: 606
diff changeset
79 enabledLayers.add "VK_LAYER_MESA_overlay"
588
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
80 result.instance = result.window.createInstance(
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
81 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
82 instanceExtensions=instanceExtensions,
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
83 layers=enabledLayers,
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
84 )
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
85 if debug:
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
86 result.debugger = result.instance.createDebugMessenger()
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
87 # create devices
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
88 let selectedPhysicalDevice = result.instance.getPhysicalDevices().filterBestGraphics()
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
89 result.device = result.instance.createDevice(
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
90 selectedPhysicalDevice,
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
91 enabledLayers = @[],
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
92 enabledExtensions = @[],
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
93 selectedPhysicalDevice.filterForGraphicsPresentationQueues()
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
94 )
008592db0442 did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
95
592
cda5874a8454 add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 590
diff changeset
96 proc setRenderer*(engine: var Engine, renderPass: RenderPass) =
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
97 assert engine.state != Destroyed
592
cda5874a8454 add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 590
diff changeset
98 engine.renderer = engine.device.initRenderer(renderPass)
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
99
603
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
100 proc addScene*(engine: var Engine, scene: Entity, vertexInput: seq[ShaderAttribute], transformAttribute="") =
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
101 assert engine.state != Destroyed
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
102 assert transformAttribute == "" or transformAttribute in map(vertexInput, proc(a: ShaderAttribute): string = a.name)
603
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
103 engine.renderer.setupDrawableBuffers(scene, vertexInput, transformAttribute=transformAttribute)
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
104
603
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
105 proc renderScene*(engine: var Engine, scene: Entity) =
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
106 assert engine.state == Running
601
7e54bbbcffba add: some helper functions
Sam <sam@basx.dev>
parents: 595
diff changeset
107 assert engine.renderer.valid
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
108 if engine.state == Running:
603
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
109 engine.renderer.refreshMeshData(scene)
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
110 engine.renderer.render(scene)
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
111
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
112 proc updateInputs*(engine: var Engine): EngineState =
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
113 assert engine.state in [Starting, Running]
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 592
diff changeset
114
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
115 engine.input.keyWasPressed = {}
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
116 engine.input.keyWasReleased = {}
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
117 engine.input.mouseWasPressed = {}
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
118 engine.input.mouseWasReleased = {}
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
119 engine.input.windowWasResized = engine.state == Starting
605
510c651cb27d add: window-resize check
Sam <sam@basx.dev>
parents: 603
diff changeset
120
510c651cb27d add: window-resize check
Sam <sam@basx.dev>
parents: 603
diff changeset
121 var killed = false
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
122 for event in engine.window.pendingEvents():
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
123 inc engine.input.eventsProcessed
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
124 if engine.eventHandler != nil:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
125 engine.eventHandler(engine, event)
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
126 case event.eventType:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
127 of Quit:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
128 killed = true
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
129 of ResizedWindow:
605
510c651cb27d add: window-resize check
Sam <sam@basx.dev>
parents: 603
diff changeset
130 engine.input.windowWasResized = true
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
131 of KeyPressed:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
132 engine.input.keyWasPressed.incl event.key
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
133 engine.input.keyIsDown.incl event.key
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
134 of KeyReleased:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
135 engine.input.keyWasReleased.incl event.key
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
136 engine.input.keyIsDown.excl event.key
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
137 of MousePressed:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
138 engine.input.mouseWasPressed.incl event.button
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
139 engine.input.mouseIsDown.incl event.button
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
140 of MouseReleased:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
141 engine.input.mouseWasReleased.incl event.button
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
142 engine.input.mouseIsDown.excl event.button
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
143 of MouseMoved:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
144 engine.input.mousePosition = newVec2(float32(event.x), float32(event.y))
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
145 if engine.state == Starting:
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
146 engine.state = Running
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
147 if killed:
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
148 engine.state = Shutdown
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
149 if engine.exitHandler != nil:
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
150 engine.exitHandler(engine)
605
510c651cb27d add: window-resize check
Sam <sam@basx.dev>
parents: 603
diff changeset
151 if engine.input.windowWasResized and engine.resizeHandler != nil:
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
152 engine.resizeHandler(engine)
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 605
diff changeset
153 return engine.state
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
154
626
bf2f4a9cd962 add: option to show/hide cursor
Sam <sam@basx.dev>
parents: 613
diff changeset
155 # wrappers for internal things
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
156 func keyIsDown*(engine: Engine, key: Key): auto = key in engine.input.keyIsDown
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
157 func keyWasPressed*(engine: Engine, key: Key): auto = key in engine.input.keyWasPressed
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
158 func keyWasReleased*(engine: Engine, key: Key): auto = key in engine.input.keyWasReleased
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
159 func mouseIsDown*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseIsDown
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
160 func mouseWasPressed*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseWasPressed
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
161 func mouseWasReleased*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseWasReleased
603
f494e291ff4a add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 601
diff changeset
162 func mousePosition*(engine: Engine): auto = engine.input.mousePosition
590
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
163 func eventsProcessed*(engine: Engine): auto = engine.input.eventsProcessed
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
164 func framesRendered*(engine: Engine): auto = engine.renderer.framesRendered
1edf3e16144e add: input handling, small refactoring for renderer
Sam <sam@basx.dev>
parents: 588
diff changeset
165 func gpuDevice*(engine: Engine): Device = engine.device
601
7e54bbbcffba add: some helper functions
Sam <sam@basx.dev>
parents: 595
diff changeset
166 func getWindow*(engine: Engine): auto = engine.window
605
510c651cb27d add: window-resize check
Sam <sam@basx.dev>
parents: 603
diff changeset
167 func windowWasResized*(engine: Engine): auto = engine.input.windowWasResized
626
bf2f4a9cd962 add: option to show/hide cursor
Sam <sam@basx.dev>
parents: 613
diff changeset
168 func showSystemCursor*(engine: Engine) = engine.window.showSystemCursor()
bf2f4a9cd962 add: option to show/hide cursor
Sam <sam@basx.dev>
parents: 613
diff changeset
169 func hideSystemCursor*(engine: Engine) = engine.window.hideSystemCursor()
627
34e536f7001f add: support for showing/hiding cursur, X11 fullscreen (win32 still missing)
Sam <sam@basx.dev>
parents: 626
diff changeset
170 proc fullscreen*(engine: Engine, enable: bool) = engine.window.fullscreen(enable)