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_TEXTURE_2D_H
32 #define QSSG_RENDER_RENDER_TEXTURE_2D_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 
47 #include <QtQuick3DRender/private/qssgrenderbackend_p.h>
48 #include <QtQuick3DRender/private/qssgrendertexturebase_p.h>
49 
50 QT_BEGIN_NAMESPACE
51 
52 class QSSGRenderContext;
53 class QSGTexture;
54 
55 class Q_QUICK3DRENDER_EXPORT QSSGRenderTexture2D : public QSSGRenderTextureBase
56 {
57     Q_DISABLE_COPY(QSSGRenderTexture2D)
58 private:
59     qint32 m_width; ///< texture width
60     qint32 m_height; ///< texture height
61 
62 public:
63     /**
64      * @brief constructor
65      *
66      * @param[in] context		Pointer to context
67      * @param[in] fnd			Pointer to foundation
68      * @param[in] texTarget		Texture target
69      *
70      * @return No return.
71      */
72     QSSGRenderTexture2D(const QSSGRef<QSSGRenderContext> &context);
73 
74     QSSGRenderTexture2D(const QSSGRef<QSSGRenderContext> &context, QSGTexture *qsgTexture);
75 
76     virtual ~QSSGRenderTexture2D() override;
77 
78     // Get the texture details for mipmap level 0 if it was set.
79     QSSGTextureDetails textureDetails() const override;
80 
81     /**
82      * @brief Create GL texture object and upload data
83      *
84      * @param[in] newBuffer			Texture data for level 0
85      * @param[in] inMipLevel		Texture level count
86      * @param[in] width				Texture width
87      * @param[in] height			Texture height
88      * @param[in] format			Texture data format
89      * @param[in] formaInternal		Texture internal format
90      *
91      * @return No return.
92      */
93     void setTextureData(QSSGByteView newBuffer,
94                                 quint8 inMipLevel,
95                                 qint32 width,
96                                 qint32 height,
97                                 QSSGRenderTextureFormat format,
98                                 QSSGRenderTextureFormat formaInternal = QSSGRenderTextureFormat::Unknown);
99 
100     /**
101      * @brief Create memory storage for a texture object
102      *		  This create a texture storage which is immutable in size and format
103      *		  Use this for textures used within compute shaders
104      *
105      * @param[in] inLevels			Texture level count
106      * @param[in] width				Texture width
107      * @param[in] height			Texture height
108      * @param[in] formaInternal		Texture internal format
109      * @param[in] format			Texture data format of dataBuffer
110      * @param[in] dataBuffer		Texture data for level 0
111      *
112      * @return No return.
113      */
114     void setTextureStorage(qint32 inLevels,
115                                    qint32 width,
116                                    qint32 height,
117                                    QSSGRenderTextureFormat formaInternal,
118                                    QSSGRenderTextureFormat format = QSSGRenderTextureFormat::Unknown,
119                                    QSSGByteView dataBuffer = QSSGByteView());
120 
121     void setTextureDataMultisample(qint32 sampleCount, qint32 width, qint32 height, QSSGRenderTextureFormat format);
122 
123     // Update a sub-rect of the image.  newBuffer is expected to be a continguous subrect of the
124     // image.
125     void setTextureSubData(QSSGByteView newBuffer,
126                                    quint8 inMipLevel,
127                                    qint32 inXOffset,
128                                    qint32 inYOffset,
129                                    qint32 inSubImageWidth,
130                                    qint32 inSubImageHeight,
131                                    QSSGRenderTextureFormat format);
132     // Generate a set of mipmaps from mipLevel( 0 ).  Uses the graphis layer to do this if
133     // possible
134     // glGenerateMipmap
135     void generateMipmaps(QSSGRenderHint genType = QSSGRenderHint::Nicest);
136 
137     /**
138      * @brief Bind a texture for shader access
139      *
140      *
141      * @return No return.
142      */
143     void bind() override;
144 
145     /**
146      * @brief Query if texture needs coordinate swizzle
147      *
148      * @return texture swizzle mode
149      */
textureSwizzleMode()150     QSSGRenderTextureSwizzleMode textureSwizzleMode() override
151     {
152         // if our backend supports hardware texture swizzle then there is no need for a shader
153         // swizzle
154         return (m_backend->getRenderBackendCap(QSSGRenderBackend::QSSGRenderBackendCaps::TexSwizzle))
155                 ? QSSGRenderTextureSwizzleMode::NoSwizzle
156                 : m_backend->getTextureSwizzleMode(m_format);
157     }
158 
159 };
160 
161 QT_END_NAMESPACE
162 
163 #endif
164