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
23struct ImDrawData;
24
25QT_BEGIN_NAMESPACE
26
27class QMouseEvent;
28class QWheelEvent;
29class QKeyEvent;
30class QOpenGLExtraFunctions;
31class QOpenGLShaderProgram;
32
33namespace Qt3DCore {
34class QServiceLocator;
35}
36
37namespace Qt3DRender {
38namespace Render {
39namespace OpenGL {
40class RenderView;
41class Renderer;
42}
43
44namespace Debug {
45
46#define IMGUI_PERF_LOG_SIZE 30
47
48class Q_AUTOTEST_EXPORT ImGuiRenderer : public QObject {
49public:
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
58private:
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
99QT_END_NAMESPACE
100
101#endif // QT3D_RENDER_GL_IMGUIRENDER_H_
102

source code of qt3d/src/plugins/renderers/opengl/debug/imguirenderer_p.h