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_TEXTURE_BUFFER_H 32 #define QSSG_RENDER_TEXTURE_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 QSSGRenderTextureSampler; 52 53 struct QSSGTextureDetails 54 { 55 qint32 width = 0; 56 qint32 height = 0; 57 qint32 depth = 0; 58 qint32 sampleCount = 1; 59 QSSGRenderTextureFormat format = QSSGRenderTextureFormat::Unknown; 60 QSSGTextureDetailsQSSGTextureDetails61 QSSGTextureDetails(qint32 w, qint32 h, qint32 d, qint32 samples, QSSGRenderTextureFormat f) 62 : width(w), height(h), depth(d), sampleCount(samples), format(f) 63 { 64 } 65 QSSGTextureDetails() = default; 66 }; 67 68 class Q_QUICK3DRENDER_EXPORT QSSGRenderTextureBase 69 { 70 Q_DISABLE_COPY(QSSGRenderTextureBase) 71 public: 72 QAtomicInt ref; 73 74 protected: 75 QSSGRef<QSSGRenderContext> m_context; ///< pointer to context 76 QSSGRef<QSSGRenderBackend> m_backend; ///< pointer to backend 77 QSSGRenderBackend::QSSGRenderBackendTextureObject m_handle; ///< opaque backend handle 78 qint32 m_textureUnit; ///< texture unit this texture should use 79 bool m_samplerParamsDirty; ///< true if sampler state is dirty 80 bool m_texStateDirty; ///< true if texture object state is dirty 81 qint32 m_sampleCount; ///< texture height 82 QSSGRenderTextureFormat m_format; ///< texture format 83 QSSGRenderTextureTargetType m_texTarget; ///< texture target 84 QSSGRenderTextureSampler *m_sampler; ///< current texture sampler state 85 qint32 m_baseLevel; ///< minimum lod specified 86 qint32 m_maxLevel; ///< maximum lod specified 87 qint32 m_maxMipLevel; ///< highest mip level 88 bool m_immutable; ///< true if this is a immutable texture ( size and format ) 89 bool m_ownsTexture = true; 90 91 public: 92 /** 93 * @brief constructor 94 * 95 * @param[in] context Pointer to context 96 * @param[in] fnd Pointer to foundation 97 * @param[in] texTarget Texture target 98 * 99 * @return No return. 100 */ 101 QSSGRenderTextureBase(const QSSGRef<QSSGRenderContext> &context, QSSGRenderTextureTargetType texTarget, bool ownsTexture = true); 102 103 virtual ~QSSGRenderTextureBase(); 104 105 virtual void setMinFilter(QSSGRenderTextureMinifyingOp value); 106 virtual void setMagFilter(QSSGRenderTextureMagnifyingOp value); 107 108 virtual void setBaseLevel(qint32 value); 109 virtual void setMaxLevel(qint32 value); 110 111 virtual void setTextureWrapS(QSSGRenderTextureCoordOp value); 112 virtual void setTextureWrapT(QSSGRenderTextureCoordOp value); 113 114 virtual void setTextureCompareMode(QSSGRenderTextureCompareMode value); 115 virtual void setTextureCompareFunc(QSSGRenderTextureCompareOp value); 116 setTextureUnit(qint32 unit)117 virtual void setTextureUnit(qint32 unit) { m_textureUnit = unit; } textureUnit()118 virtual qint32 textureUnit() const { return m_textureUnit; } 119 120 // Get the texture details for mipmap level 0 if it was set. 121 virtual QSSGTextureDetails textureDetails() const = 0; 122 isMultisampleTexture()123 bool isMultisampleTexture() const { return (m_texTarget == QSSGRenderTextureTargetType::Texture2D_MS); } sampleCount()124 qint32 sampleCount() const { return m_sampleCount; } isImmutable()125 bool isImmutable() const { return m_immutable; } target()126 QSSGRenderTextureTargetType target() const { return m_texTarget; } setsamplerParamsDirty()127 void setsamplerParamsDirty() { m_samplerParamsDirty = true; } 128 129 /** 130 * @brief Bind a texture for shader access 131 * 132 * 133 * @return No return. 134 */ 135 virtual void bind() = 0; 136 numMipmaps()137 virtual quint32 numMipmaps() const { return m_maxMipLevel; } 138 139 /** 140 * @brief Query if texture needs coordinate swizzle 141 * 142 * @return texture swizzle mode 143 */ textureSwizzleMode()144 virtual QSSGRenderTextureSwizzleMode textureSwizzleMode() 145 { 146 // if our backend supports hardware texture swizzle then there is no need for a shader 147 // swizzle 148 return (m_backend->getRenderBackendCap(QSSGRenderBackend::QSSGRenderBackendCaps::TexSwizzle)) 149 ? QSSGRenderTextureSwizzleMode::NoSwizzle 150 : m_backend->getTextureSwizzleMode(m_format); 151 } 152 153 /** 154 * @brief get the backend object handle 155 * 156 * @return the backend object handle. 157 */ handle()158 virtual QSSGRenderBackend::QSSGRenderBackendTextureObject handle() { return m_handle; } 159 160 protected: 161 void applyTexParams(); 162 void applyTexSwizzle(); 163 }; 164 165 QT_END_NAMESPACE 166 167 #endif 168