Avara3D 0.2.0
C++ API reference
OGLDrawTimer.h
1//
2// OpenGLDrawTimer.h
3// avara3d
4//
5// Created by Morgan Davis on 12/24/25.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_PROFILING_OPENGLDRAWTIMER_H
10#define AVARA3D_PROFILING_OPENGLDRAWTIMER_H
11
12#include <chrono>
13#include <cstdint>
14#include <vector>
15
16#include "a3d/render/backend/opengl/GLTypes.h"
17
18namespace a3d {
19
20 class OGLDrawTimer {
21
22 public:
23 // [Internal Lifecycle Functions]
24
25 explicit OGLDrawTimer(unsigned bufferedFrames);
26
27 OGLDrawTimer(const OGLDrawTimer&) = delete;
28 OGLDrawTimer& operator=(const OGLDrawTimer&) = delete;
29
30 OGLDrawTimer(OGLDrawTimer&& other) = delete;
31 OGLDrawTimer& operator=(OGLDrawTimer&& other) = delete;
32
33 ~OGLDrawTimer();
34
35 // [Internal Member Functions]
36
37 bool initialize();
38 void begin();
39 std::chrono::nanoseconds end();
40
41 private:
42 // [Private Types]
43
44 enum class Mode {
45 Disabled,
46 DesktopTimeElapsed,
47 WebDisjointTimerQuery,
48 WebDisjointTimerQueryExt
49 };
50
51 // [Private Member Functions]
52
53 bool resolveQuery(size_t index);
54 void resolveIssuedQueries(size_t skipIndex);
55
56 // [Private Member Variables]
57
58 Mode _mode;
59 gl::enum_t _queryTarget;
60 unsigned _bufferSize;
61 std::vector<unsigned> _glQueries;
62 size_t _frame;
63 std::chrono::nanoseconds _lastTime;
64 std::vector<uint8_t> _issued;
65 bool _active = false;
66 bool _initialized = false;
67 };
68
69}
70
71#endif // AVARA3D_PROFILING_OPENGLDRAWTIMER_H