1 | // Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QT3D_RENDER_GL_IMGUIRENDER_H_ |
5 | #define QT3D_RENDER_GL_IMGUIRENDER_H_ |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of other Qt classes. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QObject> |
19 | #include <QOpenGLFunctions> |
20 | #include <QPoint> |
21 | #include <memory> |
22 | |
23 | struct ImDrawData; |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class QMouseEvent; |
28 | class QWheelEvent; |
29 | class QKeyEvent; |
30 | class ; |
31 | class QOpenGLShaderProgram; |
32 | |
33 | namespace Qt3DCore { |
34 | class QServiceLocator; |
35 | } |
36 | |
37 | namespace Qt3DRender { |
38 | namespace Render { |
39 | namespace OpenGL { |
40 | class RenderView; |
41 | class Renderer; |
42 | } |
43 | |
44 | namespace Debug { |
45 | |
46 | #define IMGUI_PERF_LOG_SIZE 30 |
47 | |
48 | class Q_AUTOTEST_EXPORT ImGuiRenderer : public QObject { |
49 | public: |
50 | ImGuiRenderer(Qt3DRender::Render::OpenGL::Renderer *renderer); |
51 | ~ImGuiRenderer(); |
52 | |
53 | void processEvent(QEvent *event); |
54 | void renderDebugOverlay(const std::vector<Render::OpenGL::RenderView *> &renderViews, const Render::OpenGL::RenderView *renderView, int jobsInLastFrame); |
55 | |
56 | void setCapabilities(const QString &capabilities); |
57 | |
58 | private: |
59 | bool newFrame(const Render::OpenGL::RenderView *renderView); |
60 | void renderDrawList(ImDrawData *draw_data); |
61 | void onMouseChange(QMouseEvent *event); |
62 | void onWheel(QWheelEvent *event); |
63 | void onKeyPressRelease(QKeyEvent *event); |
64 | void showGLInfo(); |
65 | void showRenderDetails(const std::vector<Render::OpenGL::RenderView *> &renderViews); |
66 | |
67 | bool createFontsTexture(); |
68 | bool createDeviceObjects(); |
69 | |
70 | double m_time = 0.; |
71 | bool m_mousePressed[3] = { false, false, false }; |
72 | float m_mouseWheel; |
73 | float m_mouseWheelH; |
74 | GLuint m_fontTexture = 0; |
75 | GLuint m_shaderHandle = 0; |
76 | int m_attribLocationTex = 0, m_attribLocationProjMtx = 0; |
77 | int m_attribLocationPosition = 0, m_attribLocationUV = 0, m_attribLocationColor = 0; |
78 | unsigned int m_vboHandle = 0, m_vaoHandle = 0, m_elementsHandle = 0; |
79 | |
80 | Render::OpenGL::Renderer *m_renderer; |
81 | QOpenGLExtraFunctions *m_funcs = nullptr; |
82 | QOpenGLShaderProgram *m_shader = nullptr; |
83 | |
84 | bool m_showGLInfoWindow = false; |
85 | bool m_showRenderDetailsWindow = false; |
86 | |
87 | float m_fpsLog[IMGUI_PERF_LOG_SIZE]; |
88 | float m_jobsLog[IMGUI_PERF_LOG_SIZE]; |
89 | std::pair<float, float> m_fpsRange; |
90 | std::pair<float, float> m_jobsRange; |
91 | |
92 | QByteArray m_capabilities; |
93 | }; |
94 | |
95 | } // namespace Debug |
96 | } // namespace Render |
97 | } // namespace Qt3DRender |
98 | |
99 | QT_END_NAMESPACE |
100 | |
101 | #endif // QT3D_RENDER_GL_IMGUIRENDER_H_ |
102 | |