| 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 | #if QT_CONFIG(wheelevent) |
| 63 | void onWheel(QWheelEvent *event); |
| 64 | #endif |
| 65 | void onKeyPressRelease(QKeyEvent *event); |
| 66 | void showGLInfo(); |
| 67 | void showRenderDetails(const std::vector<Render::OpenGL::RenderView *> &renderViews); |
| 68 | |
| 69 | bool createFontsTexture(); |
| 70 | bool createDeviceObjects(); |
| 71 | |
| 72 | double m_time = 0.; |
| 73 | bool m_mousePressed[3] = { false, false, false }; |
| 74 | float m_mouseWheel; |
| 75 | float m_mouseWheelH; |
| 76 | GLuint m_fontTexture = 0; |
| 77 | GLuint m_shaderHandle = 0; |
| 78 | int m_attribLocationTex = 0, m_attribLocationProjMtx = 0; |
| 79 | int m_attribLocationPosition = 0, m_attribLocationUV = 0, m_attribLocationColor = 0; |
| 80 | unsigned int m_vboHandle = 0, m_vaoHandle = 0, m_elementsHandle = 0; |
| 81 | |
| 82 | Render::OpenGL::Renderer *m_renderer; |
| 83 | QOpenGLExtraFunctions *m_funcs = nullptr; |
| 84 | QOpenGLShaderProgram *m_shader = nullptr; |
| 85 | |
| 86 | bool m_showGLInfoWindow = false; |
| 87 | bool m_showRenderDetailsWindow = false; |
| 88 | |
| 89 | float m_fpsLog[IMGUI_PERF_LOG_SIZE]; |
| 90 | float m_jobsLog[IMGUI_PERF_LOG_SIZE]; |
| 91 | std::pair<float, float> m_fpsRange; |
| 92 | std::pair<float, float> m_jobsRange; |
| 93 | |
| 94 | QByteArray m_capabilities; |
| 95 | }; |
| 96 | |
| 97 | } // namespace Debug |
| 98 | } // namespace Render |
| 99 | } // namespace Qt3DRender |
| 100 | |
| 101 | QT_END_NAMESPACE |
| 102 | |
| 103 | #endif // QT3D_RENDER_GL_IMGUIRENDER_H_ |
| 104 | |