| 1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
|---|---|
| 2 | // Copyright (C) 2019 The Qt Company Ltd. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 4 | |
| 5 | #ifndef QSSG_RENDER_CONTEXT_CORE_H |
| 6 | #define QSSG_RENDER_CONTEXT_CORE_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is part of the QtQuick3D API, with limited compatibility guarantees. |
| 13 | // Usage of this API may make your code source and binary incompatible with |
| 14 | // future versions of Qt. |
| 15 | // |
| 16 | |
| 17 | #include <QtQuick3DRuntimeRender/qtquick3druntimerenderexports.h> |
| 18 | |
| 19 | #include <QtCore/QPair> |
| 20 | #include <QtCore/QSize> |
| 21 | #include <memory> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QSSGRhiContext; |
| 26 | class QSSGBufferManager; |
| 27 | class QSSGRenderer; |
| 28 | class QSSGShaderLibraryManager; |
| 29 | class QSSGShaderCache; |
| 30 | class QSSGProgramGenerator; |
| 31 | class QSSGCustomMaterialSystem; |
| 32 | class QSSGRendererInterface; |
| 33 | class QSSGDebugDrawSystem; |
| 34 | class QSSGPerFrameAllocator; |
| 35 | |
| 36 | class QQuickWindow; |
| 37 | class QRhi; |
| 38 | |
| 39 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderContextInterface |
| 40 | { |
| 41 | Q_DISABLE_COPY(QSSGRenderContextInterface) |
| 42 | public: |
| 43 | // The commonly used version (from QQuick3DSceneRenderer). There is one |
| 44 | // rendercontext per QQuickWindow (and so scenegraph render thread). |
| 45 | explicit QSSGRenderContextInterface(QRhi *rhi); |
| 46 | |
| 47 | // This overload must only be used in special cases, e.g. by the genshaders tool. |
| 48 | QSSGRenderContextInterface(std::unique_ptr<QSSGBufferManager> bufferManager, |
| 49 | std::unique_ptr<QSSGRenderer> renderer, |
| 50 | std::shared_ptr<QSSGShaderLibraryManager> shaderLibraryManager, |
| 51 | std::unique_ptr<QSSGShaderCache> shaderCache, |
| 52 | std::unique_ptr<QSSGCustomMaterialSystem> customMaterialSystem, |
| 53 | std::unique_ptr<QSSGProgramGenerator> shaderProgramGenerator, |
| 54 | std::unique_ptr<QSSGRhiContext> ctx, |
| 55 | std::unique_ptr<QSSGDebugDrawSystem> debugDrawSystem = nullptr); |
| 56 | |
| 57 | ~QSSGRenderContextInterface(); |
| 58 | |
| 59 | const std::unique_ptr<QSSGRenderer> &renderer() const; |
| 60 | const std::unique_ptr<QSSGBufferManager> &bufferManager() const; |
| 61 | const std::unique_ptr<QSSGRhiContext> &rhiContext() const; |
| 62 | const std::unique_ptr<QSSGShaderCache> &shaderCache() const; |
| 63 | const std::shared_ptr<QSSGShaderLibraryManager> &shaderLibraryManager() const; |
| 64 | const std::unique_ptr<QSSGCustomMaterialSystem> &customMaterialSystem() const; |
| 65 | const std::unique_ptr<QSSGProgramGenerator> &shaderProgramGenerator() const; |
| 66 | const std::unique_ptr<QSSGDebugDrawSystem> &debugDrawSystem() const; |
| 67 | |
| 68 | private: |
| 69 | friend class QQuick3DSceneRenderer; |
| 70 | friend class QQuick3DWindowAttachment; |
| 71 | friend class QSSGLayerRenderData; |
| 72 | friend class QSSGRenderer; |
| 73 | |
| 74 | QRhi *rhi() const; // Internal convenience function |
| 75 | void init(); |
| 76 | void releaseCachedResources(); |
| 77 | |
| 78 | // The memory used for the per frame allocator is released as the first step in BeginFrame. |
| 79 | // This is useful for short lived objects and datastructures. |
| 80 | // NOTE: Only used internally and not replaceable for now. |
| 81 | const std::unique_ptr<QSSGPerFrameAllocator> &perFrameAllocator() const; |
| 82 | |
| 83 | std::unique_ptr<QSSGRhiContext> m_rhiContext; |
| 84 | std::unique_ptr<QSSGShaderCache> m_shaderCache; |
| 85 | std::unique_ptr<QSSGBufferManager> m_bufferManager; |
| 86 | std::unique_ptr<QSSGRenderer> m_renderer; |
| 87 | std::shared_ptr<QSSGShaderLibraryManager> m_shaderLibraryManager; |
| 88 | std::unique_ptr<QSSGCustomMaterialSystem> m_customMaterialSystem; |
| 89 | std::unique_ptr<QSSGProgramGenerator> m_shaderProgramGenerator; |
| 90 | std::unique_ptr<QSSGDebugDrawSystem> m_debugDrawSystem; |
| 91 | std::unique_ptr<QSSGPerFrameAllocator> m_perFrameAllocator; |
| 92 | }; |
| 93 | QT_END_NAMESPACE |
| 94 | |
| 95 | #endif |
| 96 |
