This repository has been archived by the owner on Dec 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoop.ts
91 lines (73 loc) · 2.67 KB
/
Loop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import SSGI from "./runtime/SSGI";
import DirectionalShadows from "./runtime/DirectionalShadows";
import executeScripts from "./runtime/execute-scripts";
import LensPostProcessing from "./runtime/LensPostProcessing";
import FrameComposition from "./runtime/FrameComposition";
import Engine from "./Engine";
import EntityWorkerAPI from "./lib/utils/EntityWorkerAPI";
import OmnidirectionalShadows from "./runtime/OmnidirectionalShadows";
import CameraAPI from "./lib/utils/CameraAPI";
import MetricsController from "./lib/utils/MetricsController";
import VisibilityRenderer from "./runtime/VisibilityRenderer";
import LightsAPI from "./lib/utils/LightsAPI";
import SceneComposition from "./runtime/SceneComposition";
import GPU from "./GPU";
import GPUAPI from "./lib/rendering/GPUAPI";
import StaticFBO from "./lib/StaticFBO";
let previous = 0
export default class Loop {
static #afterDrawing?: Function = () => null
static #frameID: number = undefined
static elapsed = 0
static get isExecuting() {
return Loop.#frameID !== undefined
}
static linkToExecutionPipeline(after?: Function) {
if (typeof after === "function") {
Loop.#afterDrawing = after
} else
Loop.#afterDrawing = () => null
}
static copyToCurrentFrame() {
GPUAPI.copyTexture(StaticFBO.postProcessing1, StaticFBO.postProcessing2, GPU.context.COLOR_BUFFER_BIT)
}
static #callback() {
MetricsController.init()
if (!Engine.isDev)
executeScripts()
DirectionalShadows.execute()
OmnidirectionalShadows.execute()
VisibilityRenderer.execute()
SceneComposition.execute()
Loop.copyToCurrentFrame()
SSGI.execute()
LensPostProcessing.execute()
FrameComposition.execute()
MetricsController.end()
Loop.#afterDrawing()
}
static #loop(current) {
try {
Loop.elapsed = current - previous
previous = current
CameraAPI.updateUBOs()
GPU.context.clear(GPU.context.COLOR_BUFFER_BIT | GPU.context.DEPTH_BUFFER_BIT)
if (EntityWorkerAPI.hasChangeBuffer[0] === 1)
LightsAPI.packageLights(false, true)
Loop.#callback()
EntityWorkerAPI.hasChangeBuffer[0] = 0
CameraAPI.syncThreads()
EntityWorkerAPI.syncThreads()
Loop.#frameID = requestAnimationFrame(Loop.#loop)
} catch (err) {
console.error(err)
}
}
static start() {
Loop.#frameID = requestAnimationFrame(Loop.#loop)
}
static stop() {
cancelAnimationFrame(Loop.#frameID)
Loop.#frameID = undefined
}
}