1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2008-2012 NVIDIA Corporation. 4 ** Copyright (C) 2019 The Qt Company Ltd. 5 ** Contact: https://www.qt.io/licensing/ 6 ** 7 ** This file is part of Qt Quick 3D. 8 ** 9 ** $QT_BEGIN_LICENSE:GPL$ 10 ** Commercial License Usage 11 ** Licensees holding valid commercial Qt licenses may use this file in 12 ** accordance with the commercial license agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and The Qt Company. For licensing terms 15 ** and conditions see https://www.qt.io/terms-conditions. For further 16 ** information use the contact form at https://www.qt.io/contact-us. 17 ** 18 ** GNU General Public License Usage 19 ** Alternatively, this file may be used under the terms of the GNU 20 ** General Public License version 3 or (at your option) any later version 21 ** approved by the KDE Free Qt Foundation. The licenses are as published by 22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3 23 ** included in the packaging of this file. Please review the following 24 ** information to ensure the GNU General Public License requirements will 25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 26 ** 27 ** $QT_END_LICENSE$ 28 ** 29 ****************************************************************************/ 30 31 #ifndef QSSG_RENDER_RENDER_FRAME_BUFFER_H 32 #define QSSG_RENDER_RENDER_FRAME_BUFFER_H 33 34 // 35 // W A R N I N G 36 // ------------- 37 // 38 // This file is not part of the Qt API. It exists purely as an 39 // implementation detail. This header file may change from version to 40 // version without notice, or even be removed. 41 // 42 // We mean it. 43 // 44 45 #include <QtQuick3DRender/private/qssgrenderbasetypes_p.h> 46 #include <QtQuick3DRender/private/qssgrenderbackend_p.h> 47 48 QT_BEGIN_NAMESPACE 49 50 class QSSGRenderContext; 51 class QSSGRenderTexture2D; 52 class QSSGRenderRenderBuffer; 53 class QSSGRenderTextureCube; 54 55 class Q_QUICK3DRENDER_EXPORT QSSGRenderTextureOrRenderBuffer 56 { 57 // ### this could be a union 58 QSSGRef<QSSGRenderTexture2D> m_texture2D; 59 QSSGRef<QSSGRenderTextureCube> m_textureCube; 60 QSSGRef<QSSGRenderRenderBuffer> m_renderBuffer; 61 62 public: 63 QSSGRenderTextureOrRenderBuffer(const QSSGRef<QSSGRenderTexture2D> &texture); 64 QSSGRenderTextureOrRenderBuffer(const QSSGRef<QSSGRenderRenderBuffer> &render); 65 QSSGRenderTextureOrRenderBuffer(const QSSGRef<QSSGRenderTextureCube> &textureCube); 66 QSSGRenderTextureOrRenderBuffer(); 67 QSSGRenderTextureOrRenderBuffer(const QSSGRenderTextureOrRenderBuffer &other); 68 ~QSSGRenderTextureOrRenderBuffer(); 69 70 QSSGRenderTextureOrRenderBuffer &operator=(const QSSGRenderTextureOrRenderBuffer &other); 71 hasTexture2D()72 bool hasTexture2D() const { return m_texture2D != nullptr; } hasTextureCube()73 bool hasTextureCube() const { return m_textureCube != nullptr; } hasRenderBuffer()74 bool hasRenderBuffer() const { return m_renderBuffer != nullptr; } 75 76 QSSGRef<QSSGRenderTexture2D> texture2D() const; 77 QSSGRef<QSSGRenderTextureCube> textureCube() const; 78 QSSGRef<QSSGRenderRenderBuffer> renderBuffer() const; 79 }; 80 81 class Q_QUICK3DRENDER_EXPORT QSSGRenderFrameBuffer 82 { 83 Q_DISABLE_COPY(QSSGRenderFrameBuffer) 84 public: 85 QAtomicInt ref; 86 87 private: 88 QSSGRef<QSSGRenderContext> m_context; ///< pointer to context 89 QSSGRef<QSSGRenderBackend> m_backend; ///< pointer to backend 90 91 QSSGRenderTextureOrRenderBuffer m_attachments[static_cast<int>(QSSGRenderFrameBufferAttachment::LastAttachment)]; ///< attachments array 92 QSSGRenderBackend::QSSGRenderBackendRenderTargetObject m_bufferHandle; ///< opaque backend handle 93 94 public: 95 /** 96 * @brief constructor 97 * 98 * @param[in] context Pointer to context 99 * @param[in] fnd Pointer to foundation 100 * 101 * @return No return. 102 */ 103 QSSGRenderFrameBuffer(const QSSGRef<QSSGRenderContext> &context); 104 105 /// destructor 106 ~QSSGRenderFrameBuffer(); 107 108 /** 109 * @brief query attachment 110 * 111 * 112 * @return buffer format 113 */ 114 QSSGRenderTextureOrRenderBuffer attachment(QSSGRenderFrameBufferAttachment attachment); 115 116 /** 117 * @brief Attach a render or texture buffer to a render target 118 * For texture attachments we use always level 0 119 * 120 * @param[in] attachment Attachment point (e.g. COLOR0, DEPTH...) 121 * @param[in] buffer Contains a pointer to the attachment 122 * @param[in] target Attachment texture target 123 * 124 * @return no return 125 */ 126 void attach(QSSGRenderFrameBufferAttachment attachment, 127 const QSSGRenderTextureOrRenderBuffer &buffer, 128 QSSGRenderTextureTargetType target = QSSGRenderTextureTargetType::Texture2D); 129 130 /** 131 * @brief Attach a particular face of the texture cubemap to a render target 132 * 133 * @param[in] attachment Attachment point (e.g. COLOR0, DEPTH...) 134 * @param[in] buffer Pointer to the Texture Array which contains the 135 * layers 136 * @param[in] face The face of the cubemap that will be attached to the 137 * target 138 * @param[in] level Mip level of the texture that will be attached 139 * (default 0) 140 * 141 * @return no return 142 */ 143 // ### currently unused 144 void attachFace(QSSGRenderFrameBufferAttachment attachment, 145 const QSSGRenderTextureOrRenderBuffer &buffer, 146 QSSGRenderTextureCubeFace face); 147 148 /** 149 * @brief Check that this framebuffer is complete and can be rendered to. 150 * 151 * 152 * @return true if complete 153 */ 154 bool isComplete(); 155 156 /** 157 * @brief query if framebuffer has any attachment 158 * 159 * @return true if any attachment 160 */ hasAnyAttachment()161 bool hasAnyAttachment() { return (m_attachmentBits != 0); } 162 163 /** 164 * @brief get the backend object handle 165 * 166 * @return the backend object handle. 167 */ handle()168 QSSGRenderBackend::QSSGRenderBackendRenderTargetObject handle() 169 { 170 return m_bufferHandle; 171 } 172 173 private: 174 /** 175 * @brief releaes an attached object 176 * 177 * @return which target we released 178 */ 179 QSSGRenderTextureTargetType releaseAttachment(QSSGRenderFrameBufferAttachment idx); 180 181 quint32 m_attachmentBits; ///< holds flags for current attached buffers 182 }; 183 184 QT_END_NAMESPACE 185 186 #endif 187