| 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 QT3DRENDER_RENDER_OPENGL_TEXTURESUBMISSIONCONTEXT_H |
| 5 | #define QT3DRENDER_RENDER_OPENGL_TEXTURESUBMISSIONCONTEXT_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 | |
| 19 | #include <qglobal.h> |
| 20 | #include <vector> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QOpenGLContext; |
| 25 | |
| 26 | namespace Qt3DRender { |
| 27 | namespace Render { |
| 28 | namespace OpenGL { |
| 29 | |
| 30 | class GraphicsContext; |
| 31 | class GLTexture; |
| 32 | |
| 33 | class Q_AUTOTEST_EXPORT TextureSubmissionContext |
| 34 | { |
| 35 | public: |
| 36 | enum TextureScope |
| 37 | { |
| 38 | TextureScopeMaterial = 0, |
| 39 | TextureScopeTechnique |
| 40 | // per-pass for deferred rendering? |
| 41 | }; |
| 42 | |
| 43 | TextureSubmissionContext(); |
| 44 | ~TextureSubmissionContext(); |
| 45 | |
| 46 | void initialize(GraphicsContext *context); |
| 47 | void endDrawing(); |
| 48 | int activateTexture(TextureScope scope, QOpenGLContext *gl, GLTexture* tex); |
| 49 | void deactivateTexture(GLTexture *tex); |
| 50 | void deactivateTexturesWithScope(TextureScope ts); |
| 51 | |
| 52 | private: |
| 53 | void decayTextureScores(); |
| 54 | int assignUnitForTexture(GLTexture* tex); |
| 55 | |
| 56 | // active textures, indexed by texture unit |
| 57 | struct ActiveTexture { |
| 58 | GLTexture *texture = nullptr; |
| 59 | int score = 0; |
| 60 | TextureScope scope = TextureScopeMaterial; |
| 61 | bool pinned = false; |
| 62 | }; |
| 63 | std::vector<ActiveTexture> m_activeTextures; |
| 64 | }; |
| 65 | |
| 66 | } // namespace OpenGL |
| 67 | } // namespace Render |
| 68 | } // namespace Qt3DRender |
| 69 | |
| 70 | QT_END_NAMESPACE |
| 71 | |
| 72 | #endif // QT3DRENDER_RENDER_OPENGL_TEXTURESUBMISSIONCONTEXT_H |
| 73 | |