1/****************************************************************************
2**
3** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QT3D_RENDER_GL_IMGUIRENDER_H_
41#define QT3D_RENDER_GL_IMGUIRENDER_H_
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of other Qt classes. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QObject>
55#include <QOpenGLFunctions>
56#include <QPoint>
57#include <memory>
58
59struct ImDrawData;
60
61QT_BEGIN_NAMESPACE
62
63class QMouseEvent;
64class QWheelEvent;
65class QKeyEvent;
66class QOpenGLExtraFunctions;
67class QOpenGLShaderProgram;
68
69namespace Qt3DCore {
70class QServiceLocator;
71}
72
73namespace Qt3DRender {
74namespace Render {
75namespace OpenGL {
76class RenderView;
77class Renderer;
78}
79
80namespace Debug {
81
82#define IMGUI_PERF_LOG_SIZE 30
83
84class ImGuiRenderer : public QObject {
85 Q_OBJECT
86public:
87 ImGuiRenderer(Qt3DRender::Render::OpenGL::Renderer *renderer);
88
89 void processEvent(QEvent *event);
90 void renderDebugOverlay(const QVector<Render::OpenGL::RenderView *> &renderViews, const Render::OpenGL::RenderView *renderView, int jobsInLastFrame);
91
92 void setCapabilities(const QString &capabilities);
93
94private:
95 bool newFrame(const Render::OpenGL::RenderView *renderView);
96 void renderDrawList(ImDrawData *draw_data);
97 void onMouseChange(QMouseEvent *event);
98 void onWheel(QWheelEvent *event);
99 void onKeyPressRelease(QKeyEvent *event);
100 void showGLInfo();
101 void showRenderDetails(const QVector<Render::OpenGL::RenderView *> &renderViews);
102
103 bool createFontsTexture();
104 bool createDeviceObjects();
105
106 double m_time = 0.;
107 bool m_mousePressed[3] = { false, false, false };
108 float m_mouseWheel;
109 float m_mouseWheelH;
110 GLuint m_fontTexture = 0;
111 GLuint m_shaderHandle = 0, m_vertHandle = 0, m_fragHandle = 0;
112 int m_attribLocationTex = 0, m_attribLocationProjMtx = 0;
113 int m_attribLocationPosition = 0, m_attribLocationUV = 0, m_attribLocationColor = 0;
114 unsigned int m_vboHandle = 0, m_vaoHandle = 0, m_elementsHandle = 0;
115
116 Render::OpenGL::Renderer *m_renderer;
117 QOpenGLExtraFunctions *m_funcs = nullptr;
118 QOpenGLShaderProgram *m_shader = nullptr;
119
120 bool m_showGLInfoWindow = false;
121 bool m_showRenderDetailsWindow = false;
122
123 float m_fpsLog[IMGUI_PERF_LOG_SIZE];
124 float m_jobsLog[IMGUI_PERF_LOG_SIZE];
125 std::pair<float, float> m_fpsRange;
126 std::pair<float, float> m_jobsRange;
127
128 QByteArray m_capabilities;
129};
130
131} // namespace Debug
132} // namespace Render
133} // namespace Qt3DRender
134
135QT_END_NAMESPACE
136
137#endif // QT3D_RENDER_GL_IMGUIRENDER_H_
138

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