diff options
-rw-r--r-- | examples/deferred-renderer-cpp/gbuffer.h | 2 | ||||
-rw-r--r-- | examples/materials-cpp/barrel.h | 2 | ||||
-rw-r--r-- | examples/materials-cpp/houseplant.cpp | 2 | ||||
-rw-r--r-- | src/render/frontend/qabstracttextureprovider.cpp | 467 | ||||
-rw-r--r-- | src/render/frontend/qabstracttextureprovider.h | 345 | ||||
-rw-r--r-- | src/render/frontend/qabstracttextureprovider_p.h | 82 | ||||
-rw-r--r-- | src/render/frontend/qtexture.cpp | 545 | ||||
-rw-r--r-- | src/render/frontend/qtexture.h | 323 | ||||
-rw-r--r-- | src/render/frontend/qwrapmode.cpp | 161 | ||||
-rw-r--r-- | src/render/frontend/qwrapmode.h | 97 | ||||
-rw-r--r-- | src/render/frontend/render-frontend.pri | 9 |
11 files changed, 1164 insertions, 871 deletions
diff --git a/examples/deferred-renderer-cpp/gbuffer.h b/examples/deferred-renderer-cpp/gbuffer.h index ee9a86515..7cd51fa31 100644 --- a/examples/deferred-renderer-cpp/gbuffer.h +++ b/examples/deferred-renderer-cpp/gbuffer.h @@ -43,7 +43,7 @@ #define GBUFFER_H #include <Qt3DRenderer/QRenderTarget> -#include <Qt3DRenderer/QTexture> +#include <Qt3DRenderer/qtexture.h> #include <Qt3DRenderer/QRenderAttachment> class GBuffer : public Qt3D::QRenderTarget diff --git a/examples/materials-cpp/barrel.h b/examples/materials-cpp/barrel.h index 0117f7451..11704970a 100644 --- a/examples/materials-cpp/barrel.h +++ b/examples/materials-cpp/barrel.h @@ -43,7 +43,7 @@ #define BARREL_H #include <Qt3DRenderer/QNormalDiffuseSpecularMapMaterial> -#include <Qt3DRenderer/QTexture> +#include <Qt3DRenderer/qtexture.h> #include "renderableentity.h" class Barrel : public RenderableEntity diff --git a/examples/materials-cpp/houseplant.cpp b/examples/materials-cpp/houseplant.cpp index 100c3f0c8..7369dd309 100644 --- a/examples/materials-cpp/houseplant.cpp +++ b/examples/materials-cpp/houseplant.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "houseplant.h" -#include <Qt3DRenderer/QTexture> +#include <Qt3DRenderer/qtexture.h> const char *potNames[] = { "cross", diff --git a/src/render/frontend/qabstracttextureprovider.cpp b/src/render/frontend/qabstracttextureprovider.cpp new file mode 100644 index 000000000..c66a144d6 --- /dev/null +++ b/src/render/frontend/qabstracttextureprovider.cpp @@ -0,0 +1,467 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qabstracttextureprovider.h" +#include "qabstracttextureprovider_p.h" +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +QAbstractTextureProviderPrivate::QAbstractTextureProviderPrivate(QAbstractTextureProvider *qq) + : QNodePrivate(qq) + , m_target(QAbstractTextureProvider::Target2D) + , m_format(QAbstractTextureProvider::RGBA8U) + , m_width(1) + , m_height(1) + , m_depth(1) + , m_autoMipMap(false) + , m_minFilter(QAbstractTextureProvider::Nearest) + , m_magFilter(QAbstractTextureProvider::Nearest) + , m_status(QAbstractTextureProvider::Loading) + , m_maximumAnisotropy(1.0f) + , m_comparisonFunction(QAbstractTextureProvider::CompareLessEqual) + , m_comparisonMode(QAbstractTextureProvider::CompareNone) +{ +} + +void QAbstractTextureProvider::copy(const QNode *ref) +{ + QNode::copy(ref); + const QAbstractTextureProvider *t = static_cast<const QAbstractTextureProvider*>(ref); + d_func()->m_target = t->d_func()->m_target; + d_func()->m_width = t->d_func()->m_width; + d_func()->m_height = t->d_func()->m_height; + d_func()->m_depth = t->d_func()->m_depth; + d_func()->m_format = t->d_func()->m_format; + d_func()->m_wrapMode.setX(t->d_func()->m_wrapMode.x()); + d_func()->m_wrapMode.setY(t->d_func()->m_wrapMode.y()); + d_func()->m_wrapMode.setZ(t->d_func()->m_wrapMode.z()); + d_func()->m_minFilter = t->d_func()->m_minFilter; + d_func()->m_magFilter = t->d_func()->m_magFilter; + d_func()->m_autoMipMap = t->d_func()->m_autoMipMap; + d_func()->m_maximumAnisotropy = t->d_func()->m_maximumAnisotropy; + d_func()->m_comparisonFunction = t->d_func()->m_comparisonFunction; + d_func()->m_comparisonMode = t->d_func()->m_comparisonMode; + // TO DO: Copy TexImageDataPtr +} + +/*! + \class Qt3D::QAbstractTextureProvider + \since 5.5 + \brief Qt3D::QAbstractTextureProvider is a base class to be used to provide textures. + + Qt3D::QAbstractTextureProvider shouldn't be used directly but rather + through one of its subclasses. Each subclass implements a given texture + target (2D, 2DArray, 3D, CubeMap ...) Each subclass provides a set of + functors for each layer, cube map face and mipmap level. In turn the + backend uses those functor to properly fill a corresponding OpenGL texture + with data. + */ + + +QAbstractTextureProvider::QAbstractTextureProvider(QNode *parent) + : QNode(*new QAbstractTextureProviderPrivate(this), parent) +{ +} + +QAbstractTextureProvider::QAbstractTextureProvider(Target target, QNode *parent) + : QNode(*new QAbstractTextureProviderPrivate(this), parent) +{ + d_func()->m_target = target; +} + +QAbstractTextureProvider::QAbstractTextureProvider(QAbstractTextureProvider::Target target, QAbstractTextureProvider::TextureFormat format, + int width, int height, int depth, bool mipMaps, + QAbstractTextureProvider::Filter magnificationFilter, QAbstractTextureProvider::Filter minificationFilter, + float maximumAnisotropy, + QAbstractTextureProvider::ComparisonFunction comparisonFunction, + QAbstractTextureProvider::ComparisonMode comparisonMode, + QNode *parent) + : QNode(*new QAbstractTextureProviderPrivate(this), parent) +{ + d_func()->m_target = target; + d_func()->m_format = format; + d_func()->m_width = width; + d_func()->m_height = height; + d_func()->m_depth = depth; + d_func()->m_autoMipMap = mipMaps; + d_func()->m_magFilter = magnificationFilter; + d_func()->m_minFilter = minificationFilter; + d_func()->m_maximumAnisotropy = maximumAnisotropy; + d_func()->m_comparisonFunction = comparisonFunction; + d_func()->m_comparisonMode = comparisonMode; +} + +QAbstractTextureProvider::QAbstractTextureProvider(QAbstractTextureProviderPrivate &dd, QNode *parent) + : QNode(dd, parent) +{ +} + +QAbstractTextureProvider::~QAbstractTextureProvider() +{ +} + +/*! + Sets the size of the texture provider to width \a, height \a h and depth \a d. + */ +void QAbstractTextureProvider::setSize(int w, int h, int d) +{ + setWidth(w); + setHeight(h); + setDepth(d); +} + +/*! + Sets the width of the texture provider to \a width. + */ +void QAbstractTextureProvider::setWidth(int width) +{ + Q_D(QAbstractTextureProvider); + if (d->m_width != width) { + d->m_width = width; + emit widthChanged(); + } +} + +/*! + Sets the height of the texture provider to \a height. + */ +void QAbstractTextureProvider::setHeight(int height) +{ + Q_D(QAbstractTextureProvider); + if (d->m_height != height) { + d->m_height = height; + emit heightChanged(); + } +} + +/*! + Sets the depth of the texture provider to \a depth. + */ +void QAbstractTextureProvider::setDepth(int depth) +{ + Q_D(QAbstractTextureProvider); + if (d->m_depth != depth) { + d->m_depth = depth; + emit depthChanged(); + } +} + +/*! + \returns the width of the texture provider. + */ +int QAbstractTextureProvider::width() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_width; +} + +/*! + \returns the height of the texture provider. + */ +int QAbstractTextureProvider::height() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_height; +} + +/*! + \returns the depth of the texture provider. + */ +int QAbstractTextureProvider::depth() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_depth; +} + +/*! + Sets the format of the texture provider to \a format. + */ +void QAbstractTextureProvider::setFormat(TextureFormat format) +{ + Q_D(QAbstractTextureProvider); + if (d->m_format != format) { + d->m_format = format; + emit formatChanged(); + } +} + +/*! + \returns the format of the texture provider. + */ +QAbstractTextureProvider::TextureFormat QAbstractTextureProvider::format() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_format; +} + +/*! + Sets the current status of the texture provider to \a status. + */ +void QAbstractTextureProvider::setStatus(Status status) +{ + Q_D(QAbstractTextureProvider); + if (status != d->m_status) { + d->m_status = status; + emit statusChanged(); + } +} + +/*! + \returns the current status of the texture provider. + */ +QAbstractTextureProvider::Status QAbstractTextureProvider::status() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_status; +} + +/*! + \returns the target format of the texture provider. + \note: The target format can only be set once. + */ +QAbstractTextureProvider::Target QAbstractTextureProvider::target() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_target; +} + +bool QAbstractTextureProvider::setFromQImage(QImage img, int layer) +{ + Q_D(QAbstractTextureProvider); + setSize(img.width(), img.height()); + + if ((d->m_target != Target2D) && + (d->m_target != Target2DArray) && + (d->m_target == TargetRectangle)) { + qWarning() << Q_FUNC_INFO << "invalid texture target"; + setStatus(Error); + return false; + } + + TexImageDataPtr dataPtr(new TexImageData(0, layer)); + dataPtr->setImage(img); + addImageData(dataPtr); + setStatus(Loaded); + return true; +} + +void QAbstractTextureProvider::addImageData(TexImageDataPtr imgData) +{ + Q_D(QAbstractTextureProvider); + d->m_data.append(imgData); +} + +QList<TexImageDataPtr> QAbstractTextureProvider::imageData() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_data; +} + +/*! + Sets whether the texture provider should auto generate mipmaps. + */ +void QAbstractTextureProvider::setGenerateMipMaps(bool gen) +{ + Q_D(QAbstractTextureProvider); + if (d->m_autoMipMap != gen) { + d->m_autoMipMap = gen; + emit generateMipMapsChanged(); + } +} + +/*! + \returns whether texture provider auto generates mipmaps. + */ +bool QAbstractTextureProvider::generateMipMaps() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_autoMipMap; +} + +/*! + Sets the minification filter of the texture provider to \a f. + */ +void QAbstractTextureProvider::setMinificationFilter(Filter f) +{ + Q_D(QAbstractTextureProvider); + if (d->m_minFilter != f) { + d->m_minFilter = f; + emit minificationFilterChanged(); + } +} + +/*! + Sets the magnification filter of the texture provider to \a f. + */ +void QAbstractTextureProvider::setMagnificationFilter(Filter f) +{ + Q_D(QAbstractTextureProvider); + if (d->m_magFilter != f) { + d->m_magFilter = f; + emit magnificationFilterChanged(); + } +} + +/*! + \returns the minification filter of the texture provider. + */ +QAbstractTextureProvider::Filter QAbstractTextureProvider::minificationFilter() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_minFilter; +} + +/*! + \returns the magnification filter of the texture provider. + */ +QAbstractTextureProvider::Filter QAbstractTextureProvider::magnificationFilter() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_magFilter; +} + +/*! + Sets the wrap mode of the texture provider to \a wrapMode. + */ +void QAbstractTextureProvider::setWrapMode(const QTextureWrapMode &wrapMode) +{ + Q_D(QAbstractTextureProvider); + if (d->m_wrapMode.x() != wrapMode.x()) { + d->m_wrapMode.setX(wrapMode.x()); + QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this)); + e->setPropertyName(QByteArrayLiteral("wrapModeX")); + e->setValue(static_cast<int>(d->m_wrapMode.x())); + d->notifyObservers(e); + } + if (d->m_wrapMode.y() != wrapMode.y()) { + d->m_wrapMode.setY(wrapMode.y()); + QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this)); + e->setPropertyName(QByteArrayLiteral("wrapModeY")); + e->setValue(static_cast<int>(d->m_wrapMode.y())); + d->notifyObservers(e); + } + if (d->m_wrapMode.z() != wrapMode.z()) { + d->m_wrapMode.setZ(wrapMode.z()); + QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this)); + e->setPropertyName(QByteArrayLiteral("wrapModeZ")); + e->setValue(static_cast<int>(d->m_wrapMode.z())); + d->notifyObservers(e); + } +} + +/*! + \returns the wrap mode of the texture provider. + */ +QTextureWrapMode *QAbstractTextureProvider::wrapMode() +{ + Q_D(QAbstractTextureProvider); + return &d->m_wrapMode; +} + +/*! + Sets the maximum anisotropy of the texture provider to \a anisotropy. + */ +void QAbstractTextureProvider::setMaximumAnisotropy(float anisotropy) +{ + Q_D(QAbstractTextureProvider); + if (!qFuzzyCompare(d->m_maximumAnisotropy, anisotropy)) { + d->m_maximumAnisotropy = anisotropy; + emit maximumAnisotropyChanged(); + } +} + +/*! + \returns the maximum anisotropy of the texture provider. + */ +float QAbstractTextureProvider::maximumAnisotropy() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_maximumAnisotropy; +} + +/*! + Sets the comparison function of the texture provider to \a function. + */ +void QAbstractTextureProvider::setComparisonFunction(QAbstractTextureProvider::ComparisonFunction function) +{ + Q_D(QAbstractTextureProvider); + if (d->m_comparisonFunction != function) { + d->m_comparisonFunction = function; + emit comparisonFunctionChanged(); + } +} + +/*! + \returns the comparison function of the texture provider. + */ +QAbstractTextureProvider::ComparisonFunction QAbstractTextureProvider::comparisonFunction() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_comparisonFunction; +} + +/*! + Sets the comparison mode of the texture provider to \a mode. + */ +void QAbstractTextureProvider::setComparisonMode(QAbstractTextureProvider::ComparisonMode mode) +{ + Q_D(QAbstractTextureProvider); + if (d->m_comparisonMode != mode) { + d->m_comparisonMode = mode; + emit comparisonModeChanged(); + } +} + +/*! + \returns the comparison mode of the texture provider. + */ +QAbstractTextureProvider::ComparisonMode QAbstractTextureProvider::comparisonMode() const +{ + Q_D(const QAbstractTextureProvider); + return d->m_comparisonMode; +} + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/render/frontend/qabstracttextureprovider.h b/src/render/frontend/qabstracttextureprovider.h new file mode 100644 index 000000000..dbe9dee62 --- /dev/null +++ b/src/render/frontend/qabstracttextureprovider.h @@ -0,0 +1,345 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QABSTRACTTEXTUREPROVIDER_H +#define QT3D_QABSTRACTTEXTUREPROVIDER_H + +#include <Qt3DRenderer/texturedata.h> +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <Qt3DCore/qnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QAbstractTextureProviderPrivate; +class QTextureWrapMode; + +class QT3DRENDERERSHARED_EXPORT QAbstractTextureProvider : public QNode +{ + Q_OBJECT + Q_ENUMS(Target) + Q_ENUMS(TextureFormat) + Q_ENUMS(Filter) + Q_ENUMS(Status) + Q_ENUMS(ComparisonFunction) + Q_ENUMS(ComparisonMode) + Q_PROPERTY(Target target READ target CONSTANT) + Q_PROPERTY(TextureFormat format READ format WRITE setFormat NOTIFY formatChanged) + Q_PROPERTY(bool generateMipMaps READ generateMipMaps WRITE setGenerateMipMaps NOTIFY generateMipMapsChanged) + Q_PROPERTY(Qt3D::QTextureWrapMode *wrapMode READ wrapMode CONSTANT) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) + Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) + Q_PROPERTY(int depth READ depth WRITE setDepth NOTIFY depthChanged) + Q_PROPERTY(Filter magnificationFilter READ magnificationFilter WRITE setMagnificationFilter NOTIFY magnificationFilterChanged) + Q_PROPERTY(Filter minificationFilter READ minificationFilter WRITE setMinificationFilter NOTIFY minificationFilterChanged) + Q_PROPERTY(float maximumAnisotropy READ maximumAnisotropy WRITE setMaximumAnisotropy NOTIFY maximumAnisotropyChanged) + Q_PROPERTY(ComparisonFunction comparisonFunction READ comparisonFunction WRITE setComparisonFunction NOTIFY comparisonFunctionChanged) + Q_PROPERTY(ComparisonMode comparisonMode READ comparisonMode WRITE setComparisonMode NOTIFY comparisonModeChanged) + +public: + + enum Status { + Loading = 0, + Loaded, + Error + }; + + enum Target { + Target1D = 0x0DE0, // GL_TEXTURE_1D + Target1DArray = 0x8C18, // GL_TEXTURE_1D_ARRAY + Target2D = 0x0DE1, // GL_TEXTURE_2D + Target2DArray = 0x8C1A, // GL_TEXTURE_2D_ARRAY + Target3D = 0x806F, // GL_TEXTURE_3D + TargetCubeMap = 0x8513, // GL_TEXTURE_CUBE_MAP + TargetCubeMapArray = 0x9009, // GL_TEXTURE_CUBE_MAP_ARRAY + Target2DMultisample = 0x9100, // GL_TEXTURE_2D_MULTISAMPLE + Target2DMultisampleArray = 0x9102, // GL_TEXTURE_2D_MULTISAMPLE_ARRAY + TargetRectangle = 0x84F5, // GL_TEXTURE_RECTANGLE + TargetBuffer = 0x8C2A // GL_TEXTURE_BUFFER + }; + + enum TextureFormat { + NoFormat = 0, // GL_NONE + + // Unsigned normalized formats + R8_UNorm = 0x8229, // GL_R8 + RG8_UNorm = 0x822B, // GL_RG8 + RGB8_UNorm = 0x8051, // GL_RGB8 + RGBA8_UNorm = 0x8058, // GL_RGBA8 + + R16_UNorm = 0x822A, // GL_R16 + RG16_UNorm = 0x822C, // GL_RG16 + RGB16_UNorm = 0x8054, // GL_RGB16 + RGBA16_UNorm = 0x805B, // GL_RGBA16 + + // Signed normalized formats + R8_SNorm = 0x8F94, // GL_R8_SNORM + RG8_SNorm = 0x8F95, // GL_RG8_SNORM + RGB8_SNorm = 0x8F96, // GL_RGB8_SNORM + RGBA8_SNorm = 0x8F97, // GL_RGBA8_SNORM + + R16_SNorm = 0x8F98, // GL_R16_SNORM + RG16_SNorm = 0x8F99, // GL_RG16_SNORM + RGB16_SNorm = 0x8F9A, // GL_RGB16_SNORM + RGBA16_SNorm = 0x8F9B, // GL_RGBA16_SNORM + + // Unsigned integer formats + R8U = 0x8232, // GL_R8UI + RG8U = 0x8238, // GL_RG8UI + RGB8U = 0x8D7D, // GL_RGB8UI + RGBA8U = 0x8D7C, // GL_RGBA8UI + + R16U = 0x8234, // GL_R16UI + RG16U = 0x823A, // GL_RG16UI + RGB16U = 0x8D77, // GL_RGB16UI + RGBA16U = 0x8D76, // GL_RGBA16UI + + R32U = 0x8236, // GL_R32UI + RG32U = 0x823C, // GL_RG32UI + RGB32U = 0x8D71, // GL_RGB32UI + RGBA32U = 0x8D70, // GL_RGBA32UI + + // Signed integer formats + R8I = 0x8231, // GL_R8I + RG8I = 0x8237, // GL_RG8I + RGB8I = 0x8D8F, // GL_RGB8I + RGBA8I = 0x8D8E, // GL_RGBA8I + + R16I = 0x8233, // GL_R16I + RG16I = 0x8239, // GL_RG16I + RGB16I = 0x8D89, // GL_RGB16I + RGBA16I = 0x8D88, // GL_RGBA16I + + R32I = 0x8235, // GL_R32I + RG32I = 0x823B, // GL_RG32I + RGB32I = 0x8D83, // GL_RGB32I + RGBA32I = 0x8D82, // GL_RGBA32I + + // Floating point formats + R16F = 0x822D, // GL_R16F + RG16F = 0x822F, // GL_RG16F + RGB16F = 0x881B, // GL_RGB16F + RGBA16F = 0x881A, // GL_RGBA16F + + R32F = 0x822E, // GL_R32F + RG32F = 0x8230, // GL_RG32F + RGB32F = 0x8815, // GL_RGB32F + RGBA32F = 0x8814, // GL_RGBA32F + + // Packed formats + RGB9E5 = 0x8C3D, // GL_RGB9_E5 + RG11B10F = 0x8C3A, // GL_R11F_G11F_B10F + RG3B2 = 0x2A10, // GL_R3_G3_B2 + R5G6B5 = 0x8D62, // GL_RGB565 + RGB5A1 = 0x8057, // GL_RGB5_A1 + RGBA4 = 0x8056, // GL_RGBA4 + RGB10A2 = 0x906F, // GL_RGB10_A2UI + + // Depth formats + D16 = 0x81A5, // GL_DEPTH_COMPONENT16 + D24 = 0x81A6, // GL_DEPTH_COMPONENT24 + D24S8 = 0x88F0, // GL_DEPTH24_STENCIL8 + D32 = 0x81A7, // GL_DEPTH_COMPONENT32 + D32F = 0x8CAC, // GL_DEPTH_COMPONENT32F + D32FS8X24 = 0x8CAD, // GL_DEPTH32F_STENCIL8 + + // Compressed formats + RGB_DXT1 = 0x83F0, // GL_COMPRESSED_RGB_S3TC_DXT1_EXT + RGBA_DXT1 = 0x83F1, // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT + RGBA_DXT3 = 0x83F2, // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT + RGBA_DXT5 = 0x83F3, // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT + R_ATI1N_UNorm = 0x8DBB, // GL_COMPRESSED_RED_RGTC1 + R_ATI1N_SNorm = 0x8DBC, // GL_COMPRESSED_SIGNED_RED_RGTC1 + RG_ATI2N_UNorm = 0x8DBD, // GL_COMPRESSED_RG_RGTC2 + RG_ATI2N_SNorm = 0x8DBE, // GL_COMPRESSED_SIGNED_RG_RGTC2 + RGB_BP_UNSIGNED_FLOAT = 0x8E8F, // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB + RGB_BP_SIGNED_FLOAT = 0x8E8E, // GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB + RGB_BP_UNorm = 0x8E8C, // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB + + // sRGB formats + SRGB8 = 0x8C41, // GL_SRGB8 + SRGB8_Alpha8 = 0x8C43, // GL_SRGB8_ALPHA8 + SRGB_DXT1 = 0x8C4C, // GL_COMPRESSED_SRGB_S3TC_DXT1_EXT + SRGB_Alpha_DXT1 = 0x8C4D, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT + SRGB_Alpha_DXT3 = 0x8C4E, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT + SRGB_Alpha_DXT5 = 0x8C4F, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT + SRGB_BP_UNorm = 0x8E8D, // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB + + // ES 2 formats + DepthFormat = 0x1902, // GL_DEPTH_COMPONENT + AlphaFormat = 0x1906, // GL_ALPHA + RGBFormat = 0x1907, // GL_RGB + RGBAFormat = 0x1908, // GL_RGBA + LuminanceFormat = 0x1909, // GL_LUMINANCE + LuminanceAlphaFormat = 0x190A + }; + + enum Filter { + Nearest = 0x2600, // GL_NEAREST + Linear = 0x2601, // GL_LINEAR + NearestMipMapNearest = 0x2700, // GL_NEAREST_MIPMAP_NEAREST + NearestMipMapLinear = 0x2702, // GL_NEAREST_MIPMAP_LINEAR + LinearMipMapNearest = 0x2701, // GL_LINEAR_MIPMAP_NEAREST + LinearMipMapLinear = 0x2703 // GL_LINEAR_MIPMAP_LINEAR + }; + + enum CubeMapFace { + CubeMapPositiveX = 0x8515, // GL_TEXTURE_CUBE_MAP_POSITIVE_X + CubeMapNegativeX = 0x8516, // GL_TEXTURE_CUBE_MAP_NEGATIVE_X + CubeMapPositiveY = 0x8517, // GL_TEXTURE_CUBE_MAP_POSITIVE_Y + CubeMapNegativeY = 0x8518, // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y + CubeMapPositiveZ = 0x8519, // GL_TEXTURE_CUBE_MAP_POSITIVE_Z + CubeMapNegativeZ = 0x851A // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + }; + + enum ComparisonFunction { + CompareLessEqual = 0x0203, // GL_LEQUAL + CompareGreaterEqual = 0x0206, // GL_GEQUAL + CompareLess = 0x0201, // GL_LESS + CompareGreater = 0x0204, // GL_GREATER + CompareEqual = 0x0202, // GL_EQUAL + CommpareNotEqual = 0x0205, // GL_NOTEQUAL + CompareAlways = 0x0207, // GL_ALWAYS + CompareNever = 0x0200 // GL_NEVER + }; + + enum ComparisonMode { + CompareRefToTexture = 0x884E, // GL_COMPARE_REF_TO_TEXTURE + CompareNone = 0x0000 // GL_NONE + }; + + // Those will be made protected to only allow creation of a QAbstractTextureProvider through subclasses + explicit QAbstractTextureProvider(Target target, QNode *parent = 0); + explicit QAbstractTextureProvider(Target target, TextureFormat format, int width, int height = 1, int depth = 1, + bool mipMaps = false, Filter magnificationFilter = Nearest, Filter minificationFilter = Nearest, + float maximumAnisotropy = 1.0f, + ComparisonFunction comparisonFunction = CompareLessEqual, + ComparisonMode comparisonMode = CompareNone, + QNode *parent = 0); + ~QAbstractTextureProvider(); + + + Target target() const; + + void setFormat(TextureFormat format); + TextureFormat format() const; + + Status status() const; + + /** + * @brief setFromQImage - set size and image data based upon a QImage + * Can optionally generate mip-map levels automatically too. Target + * must be Texture2D, Texture2DArray or TextureRectangle. + * @param img - valid QImage. If Texture2D is set, should be power-of-2 + * dimensions. + */ + bool setFromQImage(QImage img, int layer = 0); + + void addImageData(TexImageDataPtr imgData); + QList<TexImageDataPtr> imageData() const; + + void setGenerateMipMaps(bool gen); + bool generateMipMaps() const; + + // sampler data - in the future proxy to a Sampler helper + void setMinificationFilter(Filter f); + void setMagnificationFilter(Filter f); + + Filter minificationFilter() const; + Filter magnificationFilter() const; + + void setWrapMode(const QTextureWrapMode &wrapMode); + QTextureWrapMode *wrapMode(); + + void setMaximumAnisotropy(float anisotropy); + float maximumAnisotropy() const; + + void setComparisonFunction(ComparisonFunction function); + ComparisonFunction comparisonFunction() const; + + void setComparisonMode(ComparisonMode mode); + ComparisonMode comparisonMode() const; + + void setSize(int width, int height=1, int depth=1); + + void setWidth(int width); + void setHeight(int height); + void setDepth(int depth); + + int width() const; + int height() const; + int depth() const; + +Q_SIGNALS: + void formatChanged(); + void statusChanged(); + void generateMipMapsChanged(); + void widthChanged(); + void heightChanged(); + void depthChanged(); + void magnificationFilterChanged(); + void minificationFilterChanged(); + void maximumAnisotropyChanged(); + void comparisonFunctionChanged(); + void comparisonModeChanged(); + +protected: + explicit QAbstractTextureProvider(QNode *parent = 0); + QAbstractTextureProvider(QAbstractTextureProviderPrivate &dd, QNode *parent = 0); + void copy(const QNode *ref) Q_DECL_OVERRIDE; + void setStatus(Status status); + +private: + Q_DECLARE_PRIVATE(QAbstractTextureProvider) + QT3D_CLONEABLE(QAbstractTextureProvider) +}; + +} // Qt3D + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3D::QAbstractTextureProvider*) +Q_DECLARE_METATYPE(Qt3D::QAbstractTextureProvider::ComparisonFunction) +Q_DECLARE_METATYPE(Qt3D::QAbstractTextureProvider::ComparisonMode) + +#endif // QT3D_QABSTRACTTEXTUREPROVIDER_H diff --git a/src/render/frontend/qabstracttextureprovider_p.h b/src/render/frontend/qabstracttextureprovider_p.h new file mode 100644 index 000000000..b9b7f51dd --- /dev/null +++ b/src/render/frontend/qabstracttextureprovider_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QABSTRACTTEXTUREPROVIDER_P_H +#define QT3D_QABSTRACTTEXTUREPROVIDER_P_H + +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DRenderer/qabstracttextureprovider.h> +#include <Qt3DRenderer/qwrapmode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QAbstractTextureProviderPrivate : public QNodePrivate +{ +public : + QAbstractTextureProviderPrivate(QAbstractTextureProvider *qq); + + Q_DECLARE_PUBLIC(QAbstractTextureProvider) + + QAbstractTextureProvider::Target m_target; + QAbstractTextureProvider::TextureFormat m_format; + int m_width, m_height, m_depth; + bool m_autoMipMap; + + QList<TexImageDataPtr> m_data; + + QAbstractTextureProvider::Filter m_minFilter, m_magFilter; + // FIXME, store per direction + QTextureWrapMode m_wrapMode; + QAbstractTextureProvider::Status m_status; + float m_maximumAnisotropy; + QAbstractTextureProvider::ComparisonFunction m_comparisonFunction; + QAbstractTextureProvider::ComparisonMode m_comparisonMode; +}; + +} // QT3D + +QT_END_NAMESPACE + +#endif // QT3D_QABSTRACTTEXTUREPROVIDER_P_H + diff --git a/src/render/frontend/qtexture.cpp b/src/render/frontend/qtexture.cpp index 8e7b39a06..65ef9a895 100644 --- a/src/render/frontend/qtexture.cpp +++ b/src/render/frontend/qtexture.cpp @@ -52,551 +52,6 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QAbstractTextureProviderPrivate : public QNodePrivate -{ -public : - QAbstractTextureProviderPrivate(QAbstractTextureProvider *qq) - : QNodePrivate(qq) - , m_target(QAbstractTextureProvider::Target2D) - , m_format(QAbstractTextureProvider::RGBA8U) - , m_width(1) - , m_height(1) - , m_depth(1) - , m_autoMipMap(false) - , m_minFilter(QAbstractTextureProvider::Nearest) - , m_magFilter(QAbstractTextureProvider::Nearest) - , m_status(QAbstractTextureProvider::Loading) - , m_maximumAnisotropy(1.0f) - , m_comparisonFunction(QAbstractTextureProvider::CompareLessEqual) - , m_comparisonMode(QAbstractTextureProvider::CompareNone) - {} - - Q_DECLARE_PUBLIC(QAbstractTextureProvider) - - QAbstractTextureProvider::Target m_target; - QAbstractTextureProvider::TextureFormat m_format; - int m_width, m_height, m_depth; - bool m_autoMipMap; - - QList<TexImageDataPtr> m_data; - - QAbstractTextureProvider::Filter m_minFilter, m_magFilter; - // FIXME, store per direction - QTextureWrapMode m_wrapMode; - QAbstractTextureProvider::Status m_status; - float m_maximumAnisotropy; - QAbstractTextureProvider::ComparisonFunction m_comparisonFunction; - QAbstractTextureProvider::ComparisonMode m_comparisonMode; -}; - -void QAbstractTextureProvider::copy(const QNode *ref) -{ - QNode::copy(ref); - const QAbstractTextureProvider *t = static_cast<const QAbstractTextureProvider*>(ref); - d_func()->m_target = t->d_func()->m_target; - d_func()->m_width = t->d_func()->m_width; - d_func()->m_height = t->d_func()->m_height; - d_func()->m_depth = t->d_func()->m_depth; - d_func()->m_format = t->d_func()->m_format; - d_func()->m_wrapMode.setX(t->d_func()->m_wrapMode.x()); - d_func()->m_wrapMode.setY(t->d_func()->m_wrapMode.y()); - d_func()->m_wrapMode.setZ(t->d_func()->m_wrapMode.z()); - d_func()->m_minFilter = t->d_func()->m_minFilter; - d_func()->m_magFilter = t->d_func()->m_magFilter; - d_func()->m_autoMipMap = t->d_func()->m_autoMipMap; - d_func()->m_maximumAnisotropy = t->d_func()->m_maximumAnisotropy; - d_func()->m_comparisonFunction = t->d_func()->m_comparisonFunction; - d_func()->m_comparisonMode = t->d_func()->m_comparisonMode; - // TO DO: Copy TexImageDataPtr -} - -/*! - \class Qt3D::QAbstractTextureProvider - \since 5.5 - \brief Qt3D::QAbstractTextureProvider is a base class to be used to provide textures. - - Qt3D::QAbstractTextureProvider shouldn't be used directly but rather - through one of its subclasses. Each subclass implements a given texture - target (2D, 2DArray, 3D, CubeMap ...) Each subclass provides a set of - functors for each layer, cube map face and mipmap level. In turn the - backend uses those functor to properly fill a corresponding OpenGL texture - with data. - */ - - -QAbstractTextureProvider::QAbstractTextureProvider(QNode *parent) - : QNode(*new QAbstractTextureProviderPrivate(this), parent) -{ -} - -QAbstractTextureProvider::QAbstractTextureProvider(Target target, QNode *parent) - : QNode(*new QAbstractTextureProviderPrivate(this), parent) -{ - d_func()->m_target = target; -} - -QAbstractTextureProvider::QAbstractTextureProvider(QAbstractTextureProvider::Target target, QAbstractTextureProvider::TextureFormat format, - int width, int height, int depth, bool mipMaps, - QAbstractTextureProvider::Filter magnificationFilter, QAbstractTextureProvider::Filter minificationFilter, - float maximumAnisotropy, - QAbstractTextureProvider::ComparisonFunction comparisonFunction, - QAbstractTextureProvider::ComparisonMode comparisonMode, - QNode *parent) - : QNode(*new QAbstractTextureProviderPrivate(this), parent) -{ - d_func()->m_target = target; - d_func()->m_format = format; - d_func()->m_width = width; - d_func()->m_height = height; - d_func()->m_depth = depth; - d_func()->m_autoMipMap = mipMaps; - d_func()->m_magFilter = magnificationFilter; - d_func()->m_minFilter = minificationFilter; - d_func()->m_maximumAnisotropy = maximumAnisotropy; - d_func()->m_comparisonFunction = comparisonFunction; - d_func()->m_comparisonMode = comparisonMode; -} - -QAbstractTextureProvider::QAbstractTextureProvider(QAbstractTextureProviderPrivate &dd, QNode *parent) - : QNode(dd, parent) -{ -} - -QAbstractTextureProvider::~QAbstractTextureProvider() -{ -} - -/*! - Sets the size of the texture provider to width \a, height \a h and depth \a d. - */ -void QAbstractTextureProvider::setSize(int w, int h, int d) -{ - setWidth(w); - setHeight(h); - setDepth(d); -} - -/*! - Sets the width of the texture provider to \a width. - */ -void QAbstractTextureProvider::setWidth(int width) -{ - Q_D(QAbstractTextureProvider); - if (d->m_width != width) { - d->m_width = width; - emit widthChanged(); - } -} - -/*! - Sets the height of the texture provider to \a height. - */ -void QAbstractTextureProvider::setHeight(int height) -{ - Q_D(QAbstractTextureProvider); - if (d->m_height != height) { - d->m_height = height; - emit heightChanged(); - } -} - -/*! - Sets the depth of the texture provider to \a depth. - */ -void QAbstractTextureProvider::setDepth(int depth) -{ - Q_D(QAbstractTextureProvider); - if (d->m_depth != depth) { - d->m_depth = depth; - emit depthChanged(); - } -} - -/*! - \returns the width of the texture provider. - */ -int QAbstractTextureProvider::width() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_width; -} - -/*! - \returns the height of the texture provider. - */ -int QAbstractTextureProvider::height() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_height; -} - -/*! - \returns the depth of the texture provider. - */ -int QAbstractTextureProvider::depth() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_depth; -} - -/*! - Sets the format of the texture provider to \a format. - */ -void QAbstractTextureProvider::setFormat(TextureFormat format) -{ - Q_D(QAbstractTextureProvider); - if (d->m_format != format) { - d->m_format = format; - emit formatChanged(); - } -} - -/*! - \returns the format of the texture provider. - */ -QAbstractTextureProvider::TextureFormat QAbstractTextureProvider::format() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_format; -} - -/*! - Sets the current status of the texture provider to \a status. - */ -void QAbstractTextureProvider::setStatus(Status status) -{ - Q_D(QAbstractTextureProvider); - if (status != d->m_status) { - d->m_status = status; - emit statusChanged(); - } -} - -/*! - \returns the current status of the texture provider. - */ -QAbstractTextureProvider::Status QAbstractTextureProvider::status() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_status; -} - -/*! - \returns the target format of the texture provider. - \note: The target format can only be set once. - */ -QAbstractTextureProvider::Target QAbstractTextureProvider::target() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_target; -} - -bool QAbstractTextureProvider::setFromQImage(QImage img, int layer) -{ - Q_D(QAbstractTextureProvider); - setSize(img.width(), img.height()); - - if ((d->m_target != Target2D) && - (d->m_target != Target2DArray) && - (d->m_target == TargetRectangle)) { - qWarning() << Q_FUNC_INFO << "invalid texture target"; - setStatus(Error); - return false; - } - - TexImageDataPtr dataPtr(new TexImageData(0, layer)); - dataPtr->setImage(img); - addImageData(dataPtr); - setStatus(Loaded); - return true; -} - -void QAbstractTextureProvider::addImageData(TexImageDataPtr imgData) -{ - Q_D(QAbstractTextureProvider); - d->m_data.append(imgData); -} - -QList<TexImageDataPtr> QAbstractTextureProvider::imageData() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_data; -} - -/*! - Sets whether the texture provider should auto generate mipmaps. - */ -void QAbstractTextureProvider::setGenerateMipMaps(bool gen) -{ - Q_D(QAbstractTextureProvider); - if (d->m_autoMipMap != gen) { - d->m_autoMipMap = gen; - emit generateMipMapsChanged(); - } -} - -/*! - \returns whether texture provider auto generates mipmaps. - */ -bool QAbstractTextureProvider::generateMipMaps() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_autoMipMap; -} - -/*! - Sets the minification filter of the texture provider to \a f. - */ -void QAbstractTextureProvider::setMinificationFilter(Filter f) -{ - Q_D(QAbstractTextureProvider); - if (d->m_minFilter != f) { - d->m_minFilter = f; - emit minificationFilterChanged(); - } -} - -/*! - Sets the magnification filter of the texture provider to \a f. - */ -void QAbstractTextureProvider::setMagnificationFilter(Filter f) -{ - Q_D(QAbstractTextureProvider); - if (d->m_magFilter != f) { - d->m_magFilter = f; - emit magnificationFilterChanged(); - } -} - -/*! - \returns the minification filter of the texture provider. - */ -QAbstractTextureProvider::Filter QAbstractTextureProvider::minificationFilter() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_minFilter; -} - -/*! - \returns the magnification filter of the texture provider. - */ -QAbstractTextureProvider::Filter QAbstractTextureProvider::magnificationFilter() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_magFilter; -} - -/*! - Sets the wrap mode of the texture provider to \a wrapMode. - */ -void QAbstractTextureProvider::setWrapMode(const QTextureWrapMode &wrapMode) -{ - Q_D(QAbstractTextureProvider); - if (d->m_wrapMode.x() != wrapMode.x()) { - d->m_wrapMode.setX(wrapMode.x()); - QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this)); - e->setPropertyName(QByteArrayLiteral("wrapModeX")); - e->setValue(static_cast<int>(d->m_wrapMode.x())); - d->notifyObservers(e); - } - if (d->m_wrapMode.y() != wrapMode.y()) { - d->m_wrapMode.setY(wrapMode.y()); - QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this)); - e->setPropertyName(QByteArrayLiteral("wrapModeY")); - e->setValue(static_cast<int>(d->m_wrapMode.y())); - d->notifyObservers(e); - } - if (d->m_wrapMode.z() != wrapMode.z()) { - d->m_wrapMode.setZ(wrapMode.z()); - QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this)); - e->setPropertyName(QByteArrayLiteral("wrapModeZ")); - e->setValue(static_cast<int>(d->m_wrapMode.z())); - d->notifyObservers(e); - } -} - -/*! - \returns the wrap mode of the texture provider. - */ -QTextureWrapMode *QAbstractTextureProvider::wrapMode() -{ - Q_D(QAbstractTextureProvider); - return &d->m_wrapMode; -} - -/*! - Sets the maximum anisotropy of the texture provider to \a anisotropy. - */ -void QAbstractTextureProvider::setMaximumAnisotropy(float anisotropy) -{ - Q_D(QAbstractTextureProvider); - if (!qFuzzyCompare(d->m_maximumAnisotropy, anisotropy)) { - d->m_maximumAnisotropy = anisotropy; - emit maximumAnisotropyChanged(); - } -} - -/*! - \returns the maximum anisotropy of the texture provider. - */ -float QAbstractTextureProvider::maximumAnisotropy() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_maximumAnisotropy; -} - -/*! - Sets the comparison function of the texture provider to \a function. - */ -void QAbstractTextureProvider::setComparisonFunction(QAbstractTextureProvider::ComparisonFunction function) -{ - Q_D(QAbstractTextureProvider); - if (d->m_comparisonFunction != function) { - d->m_comparisonFunction = function; - emit comparisonFunctionChanged(); - } -} - -/*! - \returns the comparison function of the texture provider. - */ -QAbstractTextureProvider::ComparisonFunction QAbstractTextureProvider::comparisonFunction() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_comparisonFunction; -} - -/*! - Sets the comparison mode of the texture provider to \a mode. - */ -void QAbstractTextureProvider::setComparisonMode(QAbstractTextureProvider::ComparisonMode mode) -{ - Q_D(QAbstractTextureProvider); - if (d->m_comparisonMode != mode) { - d->m_comparisonMode = mode; - emit comparisonModeChanged(); - } -} - -/*! - \returns the comparison mode of the texture provider. - */ -QAbstractTextureProvider::ComparisonMode QAbstractTextureProvider::comparisonMode() const -{ - Q_D(const QAbstractTextureProvider); - return d->m_comparisonMode; -} - -class QTextureWrapModePrivate : public QObjectPrivate -{ -public: - QTextureWrapModePrivate(QTextureWrapMode *qq) - : QObjectPrivate() - , q_ptr(qq) - , m_x(QTextureWrapMode::ClampToEdge) - , m_y(QTextureWrapMode::ClampToEdge) - , m_z(QTextureWrapMode::ClampToEdge) - { - } - - Q_DECLARE_PUBLIC(QTextureWrapMode) - QTextureWrapMode *q_ptr; - QTextureWrapMode::WrapMode m_x; - QTextureWrapMode::WrapMode m_y; - QTextureWrapMode::WrapMode m_z; -}; - -/*! - \class Qt3D::QTextureWrapMode - \since 5.5 - - \brief Qt3D::QTextureWrapMode defines the wrap mode a - Qt3D::QAbstractTextureProvider should apply to a texture. - */ - -QTextureWrapMode::QTextureWrapMode(WrapMode wrapMode, QObject *parent) - : QObject(*new QTextureWrapModePrivate(this), parent) -{ - d_func()->m_x = wrapMode; - d_func()->m_y = wrapMode; - d_func()->m_z = wrapMode; -} - -/*! - Contrusts a new Qt3D::QTextureWrapMode instance with the wrap mode to apply to - each dimension \a x, \a y \a z of the texture and \a parent as parent. - */ -QTextureWrapMode::QTextureWrapMode(WrapMode x,WrapMode y, WrapMode z, QObject *parent) - : QObject(*new QTextureWrapModePrivate(this), parent) -{ - d_func()->m_x = x; - d_func()->m_y = y; - d_func()->m_z = z; -} - -/*! - Sets the wrap mode of the x dimension to \a x. - */ -void QTextureWrapMode::setX(WrapMode x) -{ - Q_D(QTextureWrapMode); - if (d->m_x != x) { - d->m_x = x; - emit xChanged(); - } -} - -/*! - \returns the wrap mode of the x dimension. - */ -QTextureWrapMode::WrapMode QTextureWrapMode::x() const -{ - Q_D(const QTextureWrapMode); - return d->m_x; -} - -/*! - Sets the wrap mode of the y dimension to \a y. - */ -void QTextureWrapMode::setY(WrapMode y) -{ - Q_D(QTextureWrapMode); - if (d->m_y != y) { - d->m_y = y; - emit yChanged(); - } -} - -/*! - \returns the wrap mode of the y dimension. - */ -QTextureWrapMode::WrapMode QTextureWrapMode::y() const -{ - Q_D(const QTextureWrapMode); - return d->m_y; -} - -/*! - Sets the wrap mode of the z dimension to \a z. - */ -void QTextureWrapMode::setZ(WrapMode z) -{ - Q_D(QTextureWrapMode); - if (d->m_z != z) { - d->m_z = z; - emit zChanged(); - } -} - -/*! - \returns the wrap mode of the y dimension. - */ -QTextureWrapMode::WrapMode QTextureWrapMode::z() const -{ - Q_D(const QTextureWrapMode); - return d->m_z; -} - class QAbstractTextureImagePrivate : public QNodePrivate { public: diff --git a/src/render/frontend/qtexture.h b/src/render/frontend/qtexture.h index 3eb3d0fc2..6682b15f3 100644 --- a/src/render/frontend/qtexture.h +++ b/src/render/frontend/qtexture.h @@ -45,6 +45,8 @@ #include <QOpenGLTexture> #include <Qt3DRenderer/texturedata.h> #include <Qt3DRenderer/qt3drenderer_global.h> +#include <Qt3DRenderer/qwrapmode.h> +#include <Qt3DRenderer/qabstracttextureprovider.h> #include <Qt3DCore/qnode.h> #include <QUrl> @@ -52,328 +54,7 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QAbstractTextureProviderPrivate; -class QTextureWrapMode; -class QT3DRENDERERSHARED_EXPORT QAbstractTextureProvider : public QNode -{ - Q_OBJECT - Q_ENUMS(Target) - Q_ENUMS(TextureFormat) - Q_ENUMS(Filter) - Q_ENUMS(Status) - Q_ENUMS(ComparisonFunction) - Q_ENUMS(ComparisonMode) - Q_PROPERTY(Target target READ target CONSTANT) - Q_PROPERTY(TextureFormat format READ format WRITE setFormat NOTIFY formatChanged) - Q_PROPERTY(bool generateMipMaps READ generateMipMaps WRITE setGenerateMipMaps NOTIFY generateMipMapsChanged) - Q_PROPERTY(Qt3D::QTextureWrapMode *wrapMode READ wrapMode CONSTANT) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) - Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) - Q_PROPERTY(int depth READ depth WRITE setDepth NOTIFY depthChanged) - Q_PROPERTY(Filter magnificationFilter READ magnificationFilter WRITE setMagnificationFilter NOTIFY magnificationFilterChanged) - Q_PROPERTY(Filter minificationFilter READ minificationFilter WRITE setMinificationFilter NOTIFY minificationFilterChanged) - Q_PROPERTY(float maximumAnisotropy READ maximumAnisotropy WRITE setMaximumAnisotropy NOTIFY maximumAnisotropyChanged) - Q_PROPERTY(ComparisonFunction comparisonFunction READ comparisonFunction WRITE setComparisonFunction NOTIFY comparisonFunctionChanged) - Q_PROPERTY(ComparisonMode comparisonMode READ comparisonMode WRITE setComparisonMode NOTIFY comparisonModeChanged) - -public: - - enum Status { - Loading = 0, - Loaded, - Error - }; - - enum Target { - Target1D = 0x0DE0, // GL_TEXTURE_1D - Target1DArray = 0x8C18, // GL_TEXTURE_1D_ARRAY - Target2D = 0x0DE1, // GL_TEXTURE_2D - Target2DArray = 0x8C1A, // GL_TEXTURE_2D_ARRAY - Target3D = 0x806F, // GL_TEXTURE_3D - TargetCubeMap = 0x8513, // GL_TEXTURE_CUBE_MAP - TargetCubeMapArray = 0x9009, // GL_TEXTURE_CUBE_MAP_ARRAY - Target2DMultisample = 0x9100, // GL_TEXTURE_2D_MULTISAMPLE - Target2DMultisampleArray = 0x9102, // GL_TEXTURE_2D_MULTISAMPLE_ARRAY - TargetRectangle = 0x84F5, // GL_TEXTURE_RECTANGLE - TargetBuffer = 0x8C2A // GL_TEXTURE_BUFFER - }; - - enum TextureFormat { - NoFormat = 0, // GL_NONE - - // Unsigned normalized formats - R8_UNorm = 0x8229, // GL_R8 - RG8_UNorm = 0x822B, // GL_RG8 - RGB8_UNorm = 0x8051, // GL_RGB8 - RGBA8_UNorm = 0x8058, // GL_RGBA8 - - R16_UNorm = 0x822A, // GL_R16 - RG16_UNorm = 0x822C, // GL_RG16 - RGB16_UNorm = 0x8054, // GL_RGB16 - RGBA16_UNorm = 0x805B, // GL_RGBA16 - - // Signed normalized formats - R8_SNorm = 0x8F94, // GL_R8_SNORM - RG8_SNorm = 0x8F95, // GL_RG8_SNORM - RGB8_SNorm = 0x8F96, // GL_RGB8_SNORM - RGBA8_SNorm = 0x8F97, // GL_RGBA8_SNORM - - R16_SNorm = 0x8F98, // GL_R16_SNORM - RG16_SNorm = 0x8F99, // GL_RG16_SNORM - RGB16_SNorm = 0x8F9A, // GL_RGB16_SNORM - RGBA16_SNorm = 0x8F9B, // GL_RGBA16_SNORM - - // Unsigned integer formats - R8U = 0x8232, // GL_R8UI - RG8U = 0x8238, // GL_RG8UI - RGB8U = 0x8D7D, // GL_RGB8UI - RGBA8U = 0x8D7C, // GL_RGBA8UI - - R16U = 0x8234, // GL_R16UI - RG16U = 0x823A, // GL_RG16UI - RGB16U = 0x8D77, // GL_RGB16UI - RGBA16U = 0x8D76, // GL_RGBA16UI - - R32U = 0x8236, // GL_R32UI - RG32U = 0x823C, // GL_RG32UI - RGB32U = 0x8D71, // GL_RGB32UI - RGBA32U = 0x8D70, // GL_RGBA32UI - - // Signed integer formats - R8I = 0x8231, // GL_R8I - RG8I = 0x8237, // GL_RG8I - RGB8I = 0x8D8F, // GL_RGB8I - RGBA8I = 0x8D8E, // GL_RGBA8I - - R16I = 0x8233, // GL_R16I - RG16I = 0x8239, // GL_RG16I - RGB16I = 0x8D89, // GL_RGB16I - RGBA16I = 0x8D88, // GL_RGBA16I - - R32I = 0x8235, // GL_R32I - RG32I = 0x823B, // GL_RG32I - RGB32I = 0x8D83, // GL_RGB32I - RGBA32I = 0x8D82, // GL_RGBA32I - - // Floating point formats - R16F = 0x822D, // GL_R16F - RG16F = 0x822F, // GL_RG16F - RGB16F = 0x881B, // GL_RGB16F - RGBA16F = 0x881A, // GL_RGBA16F - - R32F = 0x822E, // GL_R32F - RG32F = 0x8230, // GL_RG32F - RGB32F = 0x8815, // GL_RGB32F - RGBA32F = 0x8814, // GL_RGBA32F - - // Packed formats - RGB9E5 = 0x8C3D, // GL_RGB9_E5 - RG11B10F = 0x8C3A, // GL_R11F_G11F_B10F - RG3B2 = 0x2A10, // GL_R3_G3_B2 - R5G6B5 = 0x8D62, // GL_RGB565 - RGB5A1 = 0x8057, // GL_RGB5_A1 - RGBA4 = 0x8056, // GL_RGBA4 - RGB10A2 = 0x906F, // GL_RGB10_A2UI - - // Depth formats - D16 = 0x81A5, // GL_DEPTH_COMPONENT16 - D24 = 0x81A6, // GL_DEPTH_COMPONENT24 - D24S8 = 0x88F0, // GL_DEPTH24_STENCIL8 - D32 = 0x81A7, // GL_DEPTH_COMPONENT32 - D32F = 0x8CAC, // GL_DEPTH_COMPONENT32F - D32FS8X24 = 0x8CAD, // GL_DEPTH32F_STENCIL8 - - // Compressed formats - RGB_DXT1 = 0x83F0, // GL_COMPRESSED_RGB_S3TC_DXT1_EXT - RGBA_DXT1 = 0x83F1, // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT - RGBA_DXT3 = 0x83F2, // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT - RGBA_DXT5 = 0x83F3, // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT - R_ATI1N_UNorm = 0x8DBB, // GL_COMPRESSED_RED_RGTC1 - R_ATI1N_SNorm = 0x8DBC, // GL_COMPRESSED_SIGNED_RED_RGTC1 - RG_ATI2N_UNorm = 0x8DBD, // GL_COMPRESSED_RG_RGTC2 - RG_ATI2N_SNorm = 0x8DBE, // GL_COMPRESSED_SIGNED_RG_RGTC2 - RGB_BP_UNSIGNED_FLOAT = 0x8E8F, // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB - RGB_BP_SIGNED_FLOAT = 0x8E8E, // GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB - RGB_BP_UNorm = 0x8E8C, // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB - - // sRGB formats - SRGB8 = 0x8C41, // GL_SRGB8 - SRGB8_Alpha8 = 0x8C43, // GL_SRGB8_ALPHA8 - SRGB_DXT1 = 0x8C4C, // GL_COMPRESSED_SRGB_S3TC_DXT1_EXT - SRGB_Alpha_DXT1 = 0x8C4D, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT - SRGB_Alpha_DXT3 = 0x8C4E, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT - SRGB_Alpha_DXT5 = 0x8C4F, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT - SRGB_BP_UNorm = 0x8E8D, // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB - - // ES 2 formats - DepthFormat = 0x1902, // GL_DEPTH_COMPONENT - AlphaFormat = 0x1906, // GL_ALPHA - RGBFormat = 0x1907, // GL_RGB - RGBAFormat = 0x1908, // GL_RGBA - LuminanceFormat = 0x1909, // GL_LUMINANCE - LuminanceAlphaFormat = 0x190A - }; - - enum Filter { - Nearest = 0x2600, // GL_NEAREST - Linear = 0x2601, // GL_LINEAR - NearestMipMapNearest = 0x2700, // GL_NEAREST_MIPMAP_NEAREST - NearestMipMapLinear = 0x2702, // GL_NEAREST_MIPMAP_LINEAR - LinearMipMapNearest = 0x2701, // GL_LINEAR_MIPMAP_NEAREST - LinearMipMapLinear = 0x2703 // GL_LINEAR_MIPMAP_LINEAR - }; - - enum CubeMapFace { - CubeMapPositiveX = 0x8515, // GL_TEXTURE_CUBE_MAP_POSITIVE_X - CubeMapNegativeX = 0x8516, // GL_TEXTURE_CUBE_MAP_NEGATIVE_X - CubeMapPositiveY = 0x8517, // GL_TEXTURE_CUBE_MAP_POSITIVE_Y - CubeMapNegativeY = 0x8518, // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - CubeMapPositiveZ = 0x8519, // GL_TEXTURE_CUBE_MAP_POSITIVE_Z - CubeMapNegativeZ = 0x851A // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - }; - - enum ComparisonFunction { - CompareLessEqual = 0x0203, // GL_LEQUAL - CompareGreaterEqual = 0x0206, // GL_GEQUAL - CompareLess = 0x0201, // GL_LESS - CompareGreater = 0x0204, // GL_GREATER - CompareEqual = 0x0202, // GL_EQUAL - CommpareNotEqual = 0x0205, // GL_NOTEQUAL - CompareAlways = 0x0207, // GL_ALWAYS - CompareNever = 0x0200 // GL_NEVER - }; - - enum ComparisonMode { - CompareRefToTexture = 0x884E, // GL_COMPARE_REF_TO_TEXTURE - CompareNone = 0x0000 // GL_NONE - }; - - // Those will be made protected to only allow creation of a QAbstractTextureProvider through subclasses - explicit QAbstractTextureProvider(Target target, QNode *parent = 0); - explicit QAbstractTextureProvider(Target target, TextureFormat format, int width, int height = 1, int depth = 1, - bool mipMaps = false, Filter magnificationFilter = Nearest, Filter minificationFilter = Nearest, - float maximumAnisotropy = 1.0f, - ComparisonFunction comparisonFunction = CompareLessEqual, - ComparisonMode comparisonMode = CompareNone, - QNode *parent = 0); - ~QAbstractTextureProvider(); - - - Target target() const; - - void setFormat(TextureFormat format); - TextureFormat format() const; - - Status status() const; - - /** - * @brief setFromQImage - set size and image data based upon a QImage - * Can optionally generate mip-map levels automatically too. Target - * must be Texture2D, Texture2DArray or TextureRectangle. - * @param img - valid QImage. If Texture2D is set, should be power-of-2 - * dimensions. - */ - bool setFromQImage(QImage img, int layer = 0); - - void addImageData(TexImageDataPtr imgData); - QList<TexImageDataPtr> imageData() const; - - void setGenerateMipMaps(bool gen); - bool generateMipMaps() const; - - // sampler data - in the future proxy to a Sampler helper - void setMinificationFilter(Filter f); - void setMagnificationFilter(Filter f); - - Filter minificationFilter() const; - Filter magnificationFilter() const; - - void setWrapMode(const QTextureWrapMode &wrapMode); - QTextureWrapMode *wrapMode(); - - void setMaximumAnisotropy(float anisotropy); - float maximumAnisotropy() const; - - void setComparisonFunction(ComparisonFunction function); - ComparisonFunction comparisonFunction() const; - - void setComparisonMode(ComparisonMode mode); - ComparisonMode comparisonMode() const; - - void setSize(int width, int height=1, int depth=1); - - void setWidth(int width); - void setHeight(int height); - void setDepth(int depth); - - int width() const; - int height() const; - int depth() const; - -Q_SIGNALS: - void formatChanged(); - void statusChanged(); - void generateMipMapsChanged(); - void widthChanged(); - void heightChanged(); - void depthChanged(); - void magnificationFilterChanged(); - void minificationFilterChanged(); - void maximumAnisotropyChanged(); - void comparisonFunctionChanged(); - void comparisonModeChanged(); - -protected: - explicit QAbstractTextureProvider(QNode *parent = 0); - QAbstractTextureProvider(QAbstractTextureProviderPrivate &dd, QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setStatus(Status status); - -private: - Q_DECLARE_PRIVATE(QAbstractTextureProvider) - QT3D_CLONEABLE(QAbstractTextureProvider) -}; - -class QTextureWrapModePrivate; - -class QT3DRENDERERSHARED_EXPORT QTextureWrapMode: public QObject -{ - Q_OBJECT - Q_ENUMS(WrapMode) - Q_PROPERTY(WrapMode x READ x WRITE setX NOTIFY xChanged) - Q_PROPERTY(WrapMode y READ y WRITE setY NOTIFY yChanged) - Q_PROPERTY(WrapMode z READ z WRITE setZ NOTIFY zChanged) - -public: - enum WrapMode { - Repeat = 0x2901, // GL_REPEAT - MirroredRepeat = 0x8370, // GL_MIRRORED_REPEAT - ClampToEdge = 0x812F, // GL_CLAMP_TO_EDGE - ClampToBorder = 0x812D // GL_CLAMP_TO_BORDER - }; - - explicit QTextureWrapMode(WrapMode wrapMode = ClampToEdge, QObject *parent = 0); - explicit QTextureWrapMode(WrapMode x, WrapMode y, WrapMode z, QObject *parent = 0); - - void setX(WrapMode x); - WrapMode x() const; - - void setY(WrapMode y); - WrapMode y() const; - - void setZ(WrapMode z); - WrapMode z() const; - -Q_SIGNALS: - void xChanged(); - void yChanged(); - void zChanged(); - -private: - Q_DECLARE_PRIVATE(QTextureWrapMode) -}; // TO DO TexImageDataPtr -> QImageDataPtr + d_ptr diff --git a/src/render/frontend/qwrapmode.cpp b/src/render/frontend/qwrapmode.cpp new file mode 100644 index 000000000..8e226b50f --- /dev/null +++ b/src/render/frontend/qwrapmode.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwrapmode.h" +#include <private/qobject_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QTextureWrapModePrivate : public QObjectPrivate +{ +public: + QTextureWrapModePrivate(QTextureWrapMode *qq) + : QObjectPrivate() + , q_ptr(qq) + , m_x(QTextureWrapMode::ClampToEdge) + , m_y(QTextureWrapMode::ClampToEdge) + , m_z(QTextureWrapMode::ClampToEdge) + { + } + + Q_DECLARE_PUBLIC(QTextureWrapMode) + QTextureWrapMode *q_ptr; + QTextureWrapMode::WrapMode m_x; + QTextureWrapMode::WrapMode m_y; + QTextureWrapMode::WrapMode m_z; +}; + +/*! + \class Qt3D::QTextureWrapMode + \since 5.5 + + \brief Qt3D::QTextureWrapMode defines the wrap mode a + Qt3D::QAbstractTextureProvider should apply to a texture. + */ + +QTextureWrapMode::QTextureWrapMode(WrapMode wrapMode, QObject *parent) + : QObject(*new QTextureWrapModePrivate(this), parent) +{ + d_func()->m_x = wrapMode; + d_func()->m_y = wrapMode; + d_func()->m_z = wrapMode; +} + +/*! + Contrusts a new Qt3D::QTextureWrapMode instance with the wrap mode to apply to + each dimension \a x, \a y \a z of the texture and \a parent as parent. + */ +QTextureWrapMode::QTextureWrapMode(WrapMode x,WrapMode y, WrapMode z, QObject *parent) + : QObject(*new QTextureWrapModePrivate(this), parent) +{ + d_func()->m_x = x; + d_func()->m_y = y; + d_func()->m_z = z; +} + +/*! + Sets the wrap mode of the x dimension to \a x. + */ +void QTextureWrapMode::setX(WrapMode x) +{ + Q_D(QTextureWrapMode); + if (d->m_x != x) { + d->m_x = x; + emit xChanged(); + } +} + +/*! + \returns the wrap mode of the x dimension. + */ +QTextureWrapMode::WrapMode QTextureWrapMode::x() const +{ + Q_D(const QTextureWrapMode); + return d->m_x; +} + +/*! + Sets the wrap mode of the y dimension to \a y. + */ +void QTextureWrapMode::setY(WrapMode y) +{ + Q_D(QTextureWrapMode); + if (d->m_y != y) { + d->m_y = y; + emit yChanged(); + } +} + +/*! + \returns the wrap mode of the y dimension. + */ +QTextureWrapMode::WrapMode QTextureWrapMode::y() const +{ + Q_D(const QTextureWrapMode); + return d->m_y; +} + +/*! + Sets the wrap mode of the z dimension to \a z. + */ +void QTextureWrapMode::setZ(WrapMode z) +{ + Q_D(QTextureWrapMode); + if (d->m_z != z) { + d->m_z = z; + emit zChanged(); + } +} + +/*! + \returns the wrap mode of the y dimension. + */ +QTextureWrapMode::WrapMode QTextureWrapMode::z() const +{ + Q_D(const QTextureWrapMode); + return d->m_z; +} + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/render/frontend/qwrapmode.h b/src/render/frontend/qwrapmode.h new file mode 100644 index 000000000..e83d9b08d --- /dev/null +++ b/src/render/frontend/qwrapmode.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QWRAPMODE_H +#define QT3D_QWRAPMODE_H + +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <QObject> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QTextureWrapModePrivate; + +class QT3DRENDERERSHARED_EXPORT QTextureWrapMode: public QObject +{ + Q_OBJECT + Q_ENUMS(WrapMode) + Q_PROPERTY(WrapMode x READ x WRITE setX NOTIFY xChanged) + Q_PROPERTY(WrapMode y READ y WRITE setY NOTIFY yChanged) + Q_PROPERTY(WrapMode z READ z WRITE setZ NOTIFY zChanged) + +public: + enum WrapMode { + Repeat = 0x2901, // GL_REPEAT + MirroredRepeat = 0x8370, // GL_MIRRORED_REPEAT + ClampToEdge = 0x812F, // GL_CLAMP_TO_EDGE + ClampToBorder = 0x812D // GL_CLAMP_TO_BORDER + }; + + explicit QTextureWrapMode(WrapMode wrapMode = ClampToEdge, QObject *parent = 0); + explicit QTextureWrapMode(WrapMode x, WrapMode y, WrapMode z, QObject *parent = 0); + + void setX(WrapMode x); + WrapMode x() const; + + void setY(WrapMode y); + WrapMode y() const; + + void setZ(WrapMode z); + WrapMode z() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + +private: + Q_DECLARE_PRIVATE(QTextureWrapMode) +}; + +} // Qt3D + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3D::QTextureWrapMode*) + +#endif // QT3D_QWRAPMODE_H diff --git a/src/render/frontend/render-frontend.pri b/src/render/frontend/render-frontend.pri index cbc2c2218..f8868e57d 100644 --- a/src/render/frontend/render-frontend.pri +++ b/src/render/frontend/render-frontend.pri @@ -67,7 +67,10 @@ HEADERS += \ $$PWD/qshaderdata.h \ $$PWD/qshaderdata_p.h \ $$PWD/qpolygonoffset.h \ - $$PWD/qcolormask.h + $$PWD/qcolormask.h \ + $$PWD/qabstracttextureprovider.h \ + $$PWD/qabstracttextureprovider_p.h \ + $$PWD/qwrapmode.h SOURCES += \ $$PWD/qmaterial.cpp \ @@ -112,4 +115,6 @@ SOURCES += \ $$PWD/qparametermapping.cpp \ $$PWD/qshaderdata.cpp \ $$PWD/qpolygonoffset.cpp \ - $$PWD/qcolormask.cpp + $$PWD/qcolormask.cpp \ + $$PWD/qabstracttextureprovider.cpp \ + $$PWD/qwrapmode.cpp |