summaryrefslogtreecommitdiffstats
path: root/src/render/texture
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2017-06-02 08:45:55 +0200
committerPaul Lemire <paul.lemire@kdab.com>2018-03-19 07:49:27 +0000
commit34f6d8a88677cffa44be05da7e1e2da0cfc2f3b4 (patch)
treed95b8632aa5a895b1eaa3cbb14891758923d93c9 /src/render/texture
parente28192812168b676b57dc505b31eed3bfcba0e67 (diff)
Move Renderer specific classes into new folder
This is another step toward isolating the renderer from the render aspect Change-Id: I4031675b961d6645b65bbe05cf62d150993038b0 Task-number: QTBUG-61151 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/texture')
-rw-r--r--src/render/texture/gltexture.cpp468
-rw-r--r--src/render/texture/gltexture_p.h245
-rw-r--r--src/render/texture/gltexturemanager_p.h79
-rw-r--r--src/render/texture/renderbuffer.cpp112
-rw-r--r--src/render/texture/renderbuffer_p.h90
-rw-r--r--src/render/texture/texture.pri9
6 files changed, 2 insertions, 1001 deletions
diff --git a/src/render/texture/gltexture.cpp b/src/render/texture/gltexture.cpp
deleted file mode 100644
index e94122f67..000000000
--- a/src/render/texture/gltexture.cpp
+++ /dev/null
@@ -1,468 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qhash.h>
-#include "gltexture_p.h"
-
-#include <QDebug>
-#include <QOpenGLFunctions>
-#include <QOpenGLTexture>
-#include <QOpenGLPixelTransferOptions>
-#include <Qt3DRender/qtexture.h>
-#include <Qt3DRender/qtexturedata.h>
-#include <Qt3DRender/qtextureimagedata.h>
-#include <Qt3DRender/private/managers_p.h>
-#include <Qt3DRender/private/texturedatamanager_p.h>
-#include <Qt3DRender/private/qabstracttexture_p.h>
-#include <Qt3DRender/private/renderbuffer_p.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
-#include <Qt3DCore/qpropertynodeaddedchange.h>
-#include <Qt3DCore/qpropertynoderemovedchange.h>
-
-QT_BEGIN_NAMESPACE
-
-using namespace Qt3DCore;
-
-namespace Qt3DRender {
-namespace Render {
-
-GLTexture::GLTexture(TextureDataManager *texDataMgr,
- TextureImageDataManager *texImgDataMgr,
- const QTextureGeneratorPtr &texGen,
- bool unique)
- : m_unique(unique)
- , m_gl(nullptr)
- , m_renderBuffer(nullptr)
- , m_textureDataManager(texDataMgr)
- , m_textureImageDataManager(texImgDataMgr)
- , m_dataFunctor(texGen)
-{
- // make sure texture generator is executed
- // this is needed when Texture have the TargetAutomatic
- // to ensure they are loaded before trying to instantiate the QOpenGLTexture
- if (!texGen.isNull())
- m_textureDataManager->requestData(texGen, this);
-}
-
-GLTexture::~GLTexture()
-{
- destroyGLTexture();
-}
-
-void GLTexture::destroyResources()
-{
- if (m_dataFunctor)
- m_textureDataManager->releaseData(m_dataFunctor, this);
-}
-
-void GLTexture::destroyGLTexture()
-{
- delete m_gl;
- m_gl = nullptr;
- delete m_renderBuffer;
- m_renderBuffer = nullptr;
-
- m_dirtyFlags.store(0);
-
- destroyResources();
-}
-
-QOpenGLTexture* GLTexture::getOrCreateGLTexture()
-{
- QMutexLocker locker(&m_textureMutex);
- bool needUpload = false;
-
- // on the first invocation in the render thread, make sure to
- // evaluate the texture data generator output
- // (this might change some property values)
- if (m_dataFunctor && !m_textureData) {
- m_textureData = m_textureDataManager->getData(m_dataFunctor);
-
- // if there is a texture generator, most properties will be defined by it
- if (m_textureData) {
- if (m_properties.target != QAbstractTexture::TargetAutomatic)
- qWarning() << "[Qt3DRender::GLTexture] When a texture provides a generator, it's target is expected to be TargetAutomatic";
-
- m_actualTarget = m_textureData->target();
- m_properties.width = m_textureData->width();
- m_properties.height = m_textureData->height();
- m_properties.depth = m_textureData->depth();
- m_properties.layers = m_textureData->layers();
- m_properties.format = m_textureData->format();
-
- const QVector<QTextureImageDataPtr> imageData = m_textureData->imageData();
-
- if (imageData.size() > 0) {
- // Set the mips level based on the first image if autoMipMapGeneration is disabled
- if (!m_properties.generateMipMaps)
- m_properties.mipLevels = imageData.first()->mipLevels();
- }
-
- setDirtyFlag(Properties, true);
- needUpload = true;
- } else {
- qWarning() << "[Qt3DRender::GLTexture] No QTextureData generated from Texture Generator yet. Texture will be invalid for this frame";
- return nullptr;
- }
- }
-
- // additional texture images may be defined through image data generators
- if (testDirtyFlag(TextureData)) {
- m_imageData.clear();
- needUpload = true;
-
- int maxMipLevel = 0;
- for (const Image &img : qAsConst(m_images)) {
- const QTextureImageDataPtr imgData = m_textureImageDataManager->getData(img.generator);
-
- Q_ASSERT(imgData);
- m_imageData.push_back(imgData);
- maxMipLevel = qMax(maxMipLevel, img.mipLevel);
-
- // If the texture doesn't have a texture generator, we will
- // derive some properties from the first TextureImage (layer=0, miplvl=0, face=0)
- if (!m_textureData && img.layer == 0 && img.mipLevel == 0 && img.face == QAbstractTexture::CubeMapPositiveX) {
- if (imgData->width() != -1 && imgData->height() != -1 && imgData->depth() != -1) {
- m_properties.width = imgData->width();
- m_properties.height = imgData->height();
- m_properties.depth = imgData->depth();
- }
- // Set the format of the texture if the texture format is set to Automatic
- if (m_properties.format == QAbstractTexture::Automatic) {
- m_properties.format = static_cast<QAbstractTexture::TextureFormat>(imgData->format());
- }
- setDirtyFlag(Properties, true);
- }
- }
-
- // make sure the number of mip levels is set when there is no texture data generator
- if (!m_dataFunctor) {
- m_properties.mipLevels = maxMipLevel + 1;
- setDirtyFlag(Properties, true);
- }
- }
-
- // don't try to create the texture if the format was not set
- if (m_properties.format == QAbstractTexture::Automatic)
- return nullptr;
-
- // if the properties changed, we need to re-allocate the texture
- if (testDirtyFlag(Properties)) {
- delete m_gl;
- m_gl = nullptr;
- }
-
- if (!m_gl) {
- m_gl = buildGLTexture();
- if (!m_gl)
- return nullptr;
- m_gl->allocateStorage();
- if (!m_gl->isStorageAllocated()) {
- return nullptr;
- }
- }
-
- // need to (re-)upload texture data?
- if (needUpload) {
- uploadGLTextureData();
- setDirtyFlag(TextureData, false);
- }
-
- // need to set texture parameters?
- if (testDirtyFlag(Properties) || testDirtyFlag(Parameters)) {
- updateGLTextureParameters();
- }
-
- // un-set properties and parameters. The TextureData flag might have been set by another thread
- // in the meantime, so don't clear that.
- setDirtyFlag(Properties, false);
- setDirtyFlag(Parameters, false);
-
- return m_gl;
-}
-
-RenderBuffer *GLTexture::getOrCreateRenderBuffer()
-{
- QMutexLocker locker(&m_textureMutex);
-
- if (m_dataFunctor && !m_textureData) {
- m_textureData = m_textureDataManager->getData(m_dataFunctor);
- if (m_textureData) {
- if (m_properties.target != QAbstractTexture::TargetAutomatic)
- qWarning() << "[Qt3DRender::GLTexture] [renderbuffer] When a texture provides a generator, it's target is expected to be TargetAutomatic";
-
- m_properties.width = m_textureData->width();
- m_properties.height = m_textureData->height();
- m_properties.format = m_textureData->format();
-
- setDirtyFlag(Properties);
- } else {
- qWarning() << "[Qt3DRender::GLTexture] [renderbuffer] No QTextureData generated from Texture Generator yet. Texture will be invalid for this frame";
- return nullptr;
- }
- }
-
- if (testDirtyFlag(Properties)) {
- delete m_renderBuffer;
- m_renderBuffer = nullptr;
- }
-
- if (!m_renderBuffer)
- m_renderBuffer = new RenderBuffer(m_properties.width, m_properties.height, m_properties.format);
-
- setDirtyFlag(Properties, false);
- setDirtyFlag(Parameters, false);
-
- return m_renderBuffer;
-}
-
-void GLTexture::setParameters(const TextureParameters &params)
-{
- QMutexLocker locker(&m_textureMutex);
- if (m_parameters != params) {
- m_parameters = params;
- setDirtyFlag(Parameters);
- }
-}
-
-void GLTexture::setProperties(const TextureProperties &props)
-{
- QMutexLocker locker(&m_textureMutex);
- if (m_properties != props) {
- m_properties = props;
- m_actualTarget = props.target;
- setDirtyFlag(Properties);
- }
-}
-
-void GLTexture::setImages(const QVector<Image> &images)
-{
- // check if something has changed at all
- bool same = (images.size() == m_images.size());
- if (same) {
- for (int i = 0; i < images.size(); i++) {
- if (images[i] != m_images[i]) {
- same = false;
- break;
- }
- }
- }
-
-
- if (!same) {
- m_images = images;
- requestUpload();
- }
-}
-
-void GLTexture::setGenerator(const QTextureGeneratorPtr &generator)
-{
- // Note: we do not compare if the generator is different
- // as in some cases we may want to reset the same generator to force a reload
- // e.g when using remote urls for textures
- if (m_dataFunctor)
- m_textureDataManager->releaseData(m_dataFunctor, this);
-
- m_textureData.reset();
- m_dataFunctor = generator;
-
- if (m_dataFunctor) {
- m_textureDataManager->requestData(m_dataFunctor, this);
- requestUpload();
- }
-}
-
-// Return nullptr if
-// - context cannot be obtained
-// - texture hasn't yet been loaded
-QOpenGLTexture *GLTexture::buildGLTexture()
-{
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
- if (!ctx) {
- qWarning() << Q_FUNC_INFO << "requires an OpenGL context";
- return nullptr;
- }
-
- if (m_actualTarget == QAbstractTexture::TargetAutomatic) {
- // If the target is automatic at this point, it means that the texture
- // hasn't been loaded yet (case of remote urls) and that loading failed
- // and that target format couldn't be deduced
- return nullptr;
- }
-
- QOpenGLTexture* glTex = new QOpenGLTexture(static_cast<QOpenGLTexture::Target>(m_actualTarget));
-
- // m_format may not be ES2 compatible. Now it's time to convert it, if necessary.
- QAbstractTexture::TextureFormat format = m_properties.format;
- if (ctx->isOpenGLES() && ctx->format().majorVersion() < 3) {
- switch (m_properties.format) {
- case QOpenGLTexture::RGBA8_UNorm:
- case QOpenGLTexture::RGBAFormat:
- format = QAbstractTexture::RGBAFormat;
- break;
- case QOpenGLTexture::RGB8_UNorm:
- case QOpenGLTexture::RGBFormat:
- format = QAbstractTexture::RGBFormat;
- break;
- case QOpenGLTexture::DepthFormat:
- format = QAbstractTexture::DepthFormat;
- break;
- default:
- qWarning() << Q_FUNC_INFO << "could not find a matching OpenGL ES 2.0 unsized texture format";
- break;
- }
- }
-
- // Map ETC1 to ETC2 when supported. This allows using features like
- // immutable storage as ETC2 is standard in GLES 3.0, while the ETC1 extension
- // is written against GLES 1.0.
- if (m_properties.format == QAbstractTexture::RGB8_ETC1) {
- if ((ctx->isOpenGLES() && ctx->format().majorVersion() >= 3)
- || ctx->hasExtension(QByteArrayLiteral("GL_OES_compressed_ETC2_RGB8_texture"))
- || ctx->hasExtension(QByteArrayLiteral("GL_ARB_ES3_compatibility")))
- format = m_properties.format = QAbstractTexture::RGB8_ETC2;
- }
-
- glTex->setFormat(m_properties.format == QAbstractTexture::Automatic ?
- QOpenGLTexture::NoFormat :
- static_cast<QOpenGLTexture::TextureFormat>(format));
- glTex->setSize(m_properties.width, m_properties.height, m_properties.depth);
- // Set layers count if texture array
- if (m_actualTarget == QAbstractTexture::Target1DArray ||
- m_actualTarget == QAbstractTexture::Target2DArray ||
- m_actualTarget == QAbstractTexture::Target3D ||
- m_actualTarget == QAbstractTexture::Target2DMultisampleArray ||
- m_actualTarget == QAbstractTexture::TargetCubeMapArray) {
- glTex->setLayers(m_properties.layers);
- }
-
- if (m_actualTarget == QAbstractTexture::Target2DMultisample ||
- m_actualTarget == QAbstractTexture::Target2DMultisampleArray) {
- // Set samples count if multisampled texture
- // (multisampled textures don't have mipmaps)
- glTex->setSamples(m_properties.samples);
- } else if (m_properties.generateMipMaps) {
- glTex->setMipLevels(glTex->maximumMipLevels());
- } else {
- glTex->setAutoMipMapGenerationEnabled(false);
- glTex->setMipBaseLevel(0);
- glTex->setMipMaxLevel(m_properties.mipLevels - 1);
- glTex->setMipLevels(m_properties.mipLevels);
- }
-
- if (!glTex->create()) {
- qWarning() << Q_FUNC_INFO << "creating QOpenGLTexture failed";
- return nullptr;
- }
-
- return glTex;
-}
-
-static void uploadGLData(QOpenGLTexture *glTex,
- int level, int layer, QOpenGLTexture::CubeMapFace face,
- const QByteArray &bytes, const QTextureImageDataPtr &data)
-{
- if (data->isCompressed()) {
- glTex->setCompressedData(level, layer, face, bytes.size(), bytes.constData());
- } else {
- QOpenGLPixelTransferOptions uploadOptions;
- uploadOptions.setAlignment(1);
- glTex->setData(level, layer, face, data->pixelFormat(), data->pixelType(), bytes.constData(), &uploadOptions);
- }
-}
-
-void GLTexture::uploadGLTextureData()
-{
- // Upload all QTexImageData set by the QTextureGenerator
- if (m_textureData) {
- const QVector<QTextureImageDataPtr> imgData = m_textureData->imageData();
-
- for (const QTextureImageDataPtr &data : imgData) {
- const int mipLevels = m_properties.generateMipMaps ? 1 : data->mipLevels();
-
- for (int layer = 0; layer < data->layers(); layer++) {
- for (int face = 0; face < data->faces(); face++) {
- for (int level = 0; level < mipLevels; level++) {
- // ensure we don't accidentally cause a detach / copy of the raw bytes
- const QByteArray bytes(data->data(layer, face, level));
- uploadGLData(m_gl, level, layer,
- static_cast<QOpenGLTexture::CubeMapFace>(QOpenGLTexture::CubeMapPositiveX + face),
- bytes, data);
- }
- }
- }
- }
- }
-
- // Upload all QTexImageData references by the TextureImages
- for (int i = 0; i < m_images.size(); i++) {
- const QTextureImageDataPtr &imgData = m_imageData.at(i);
-
- // ensure we don't accidentally cause a detach / copy of the raw bytes
- const QByteArray bytes(imgData->data());
- uploadGLData(m_gl, m_images[i].mipLevel, m_images[i].layer,
- static_cast<QOpenGLTexture::CubeMapFace>(m_images[i].face),
- bytes, imgData);
- }
-}
-
-void GLTexture::updateGLTextureParameters()
-{
- m_gl->setWrapMode(QOpenGLTexture::DirectionS, static_cast<QOpenGLTexture::WrapMode>(m_parameters.wrapModeX));
- if (m_actualTarget != QAbstractTexture::Target1D &&
- m_actualTarget != QAbstractTexture::Target1DArray &&
- m_actualTarget != QAbstractTexture::TargetBuffer)
- m_gl->setWrapMode(QOpenGLTexture::DirectionT, static_cast<QOpenGLTexture::WrapMode>(m_parameters.wrapModeY));
- if (m_actualTarget == QAbstractTexture::Target3D)
- m_gl->setWrapMode(QOpenGLTexture::DirectionR, static_cast<QOpenGLTexture::WrapMode>(m_parameters.wrapModeZ));
- m_gl->setMinMagFilters(static_cast<QOpenGLTexture::Filter>(m_parameters.minificationFilter),
- static_cast<QOpenGLTexture::Filter>(m_parameters.magnificationFilter));
- if (m_gl->hasFeature(QOpenGLTexture::AnisotropicFiltering))
- m_gl->setMaximumAnisotropy(m_parameters.maximumAnisotropy);
- if (m_gl->hasFeature(QOpenGLTexture::TextureComparisonOperators)) {
- m_gl->setComparisonFunction(static_cast<QOpenGLTexture::ComparisonFunction>(m_parameters.comparisonFunction));
- m_gl->setComparisonMode(static_cast<QOpenGLTexture::ComparisonMode>(m_parameters.comparisonMode));
- }
-}
-
-
-} // namespace Render
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
diff --git a/src/render/texture/gltexture_p.h b/src/render/texture/gltexture_p.h
deleted file mode 100644
index cde0a6973..000000000
--- a/src/render/texture/gltexture_p.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DRENDER_RENDER_GLTEXTURE_H
-#define QT3DRENDER_RENDER_GLTEXTURE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <Qt3DRender/qtexture.h>
-#include <Qt3DRender/qtextureimagedata.h>
-#include <Qt3DRender/qtexturegenerator.h>
-#include <Qt3DRender/private/backendnode_p.h>
-#include <Qt3DRender/private/handle_types_p.h>
-#include <Qt3DRender/private/texture_p.h>
-#include <QOpenGLContext>
-#include <QFlags>
-#include <QMutex>
-#include <QSize>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLTexture;
-
-namespace Qt3DRender {
-namespace Render {
-
-class TextureImageManager;
-class TextureDataManager;
-class TextureImageDataManager;
-class RenderBuffer;
-
-/**
- * @brief
- * Actual implementation of the OpenGL texture object. Makes sure the
- * QOpenGLTexture is up-to-date with the generators, properties and parameters
- * that were set for this GLTexture.
- *
- * Can be shared among multiple QTexture backend nodes through the
- * GLTextureManager, which will make sure that there are no two GLTextures
- * sharing the same texture data.
- *
- * A GLTexture can be unique though. In that case, it will not be shared
- * between QTextures, but private to one QTexture only.
- *
- * A GLTexture can also represent an OpenGL renderbuffer object. This is used
- * only in certain special cases, mainly to provide a packed depth-stencil
- * renderbuffer suitable as an FBO attachment with OpenGL ES 3.1 and earlier.
- * Such a GLTexture will have no texture object under the hood, and therefore
- * the only valid operation is getOrCreateRenderBuffer().
- */
-class Q_AUTOTEST_EXPORT GLTexture
-{
-public:
- GLTexture(TextureDataManager *texDataMgr,
- TextureImageDataManager *texImgDataMgr,
- const QTextureGeneratorPtr &texGen,
- bool unique);
-
- ~GLTexture();
-
- /**
- * Helper class to hold the defining properties of TextureImages
- */
- struct Image {
- QTextureImageDataGeneratorPtr generator;
- int layer;
- int mipLevel;
- QAbstractTexture::CubeMapFace face;
-
- inline bool operator==(const Image &o) const {
- bool sameGenerators = (generator == o.generator)
- || (!generator.isNull() && !o.generator.isNull() && *generator == *o.generator);
- return sameGenerators && layer == o.layer && mipLevel == o.mipLevel && face == o.face;
- }
- inline bool operator!=(const Image &o) const { return !(*this == o); }
- };
-
- inline bool isUnique() const { return m_unique; }
-
- inline TextureProperties properties() const { return m_properties; }
- inline TextureParameters parameters() const { return m_parameters; }
- inline QTextureGeneratorPtr textureGenerator() const { return m_dataFunctor; }
- inline QVector<Image> images() const { return m_images; }
-
- inline QSize size() const { return QSize(m_properties.width, m_properties.height); }
- inline QOpenGLTexture *getGLTexture() const { return m_gl; }
-
- /**
- * @brief
- * Returns the QOpenGLTexture for this GLTexture. If necessary,
- * the GL texture will be created from the TextureImageDatas associated
- * with the texture and image functors. If no functors are provided,
- * the texture will be created without images.
- *
- * If the texture properties or parameters have changed, these changes
- * will be applied to the resulting OpenGL texture.
- */
- QOpenGLTexture* getOrCreateGLTexture();
-
- /**
- * @brief
- * Returns the RenderBuffer for this GLTexture. If this is the first
- * call, the OpenGL renderbuffer object will be created.
- */
- RenderBuffer *getOrCreateRenderBuffer();
-
- /**
- * @brief Make sure to call this before calling the dtor
- */
- void destroyGLTexture();
-
- // Called by TextureDataManager when it has new texture data from
- // a generator that needs to be uploaded.
- void requestUpload()
- {
- setDirtyFlag(TextureData, true);
- }
-
- bool isDirty()
- {
- return m_dirtyFlags.load() != 0;
- }
-
- QMutex *textureLock()
- {
- return &m_textureMutex;
- }
-
-protected:
- template<class APITexture, class APITextureImage>
- friend class APITextureManager;
-
- /*
- * These methods are to be accessed from the GLTextureManager.
- * The renderer and the texture backend nodes can only modify Textures
- * through the GLTextureManager.
- *
- * The methods should only be called for unique textures, or textures
- * that are not shared between multiple nodes.
- */
- void setParameters(const TextureParameters &params);
- void setProperties(const TextureProperties &props);
- void setImages(const QVector<Image> &images);
- void setGenerator(const QTextureGeneratorPtr &generator);
-
-private:
-
- enum DirtyFlag {
- TextureData = 0x01, // one or more image generators have been executed, data needs uploading to GPU
- Properties = 0x02, // texture needs to be (re-)created
- Parameters = 0x04 // texture parameters need to be (re-)set
-
- };
-
- bool testDirtyFlag(DirtyFlag flag)
- {
- return m_dirtyFlags.load() & flag;
- }
-
- void setDirtyFlag(DirtyFlag flag, bool value = true)
- {
- if (value)
- m_dirtyFlags |= flag;
- else
- m_dirtyFlags &= ~static_cast<int>(flag);
- }
-
- QOpenGLTexture *buildGLTexture();
- void uploadGLTextureData();
- void updateGLTextureParameters();
- void destroyResources();
-
- bool m_unique;
- QAtomicInt m_dirtyFlags;
- QMutex m_textureMutex;
- QOpenGLTexture *m_gl;
- RenderBuffer *m_renderBuffer;
-
- TextureDataManager *m_textureDataManager;
- TextureImageDataManager *m_textureImageDataManager;
-
- // target which is actually used for GL texture
- QAbstractTexture::Target m_actualTarget;
- TextureProperties m_properties;
- TextureParameters m_parameters;
-
- QTextureGeneratorPtr m_dataFunctor;
- QVector<Image> m_images;
-
- // cache actual image data generated by the functors
- QTextureDataPtr m_textureData;
- QVector<QTextureImageDataPtr> m_imageData;
-};
-
-} // namespace Render
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
-
-#endif // QT3DRENDER_RENDER_GLTEXTURE_H
diff --git a/src/render/texture/gltexturemanager_p.h b/src/render/texture/gltexturemanager_p.h
deleted file mode 100644
index 1c8b49911..000000000
--- a/src/render/texture/gltexturemanager_p.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DRENDER_RENDER_GLTEXTUREMANAGER_H
-#define QT3DRENDER_RENDER_GLTEXTUREMANAGER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <Qt3DRender/private/apitexturemanager_p.h>
-#include <Qt3DRender/private/gltexture_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DRender {
-namespace Render {
-
-class Q_AUTOTEST_EXPORT GLTextureManager : public APITextureManager<GLTexture, GLTexture::Image>
-{
-public:
- explicit GLTextureManager(TextureImageManager *textureImageManager,
- TextureDataManager *textureDataManager,
- TextureImageDataManager *textureImageDataManager)
- : APITextureManager<GLTexture, GLTexture::Image>(textureImageManager,
- textureDataManager,
- textureImageDataManager)
- {}
-};
-
-} // namespace Render
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
-
-#endif // QT3DRENDER_RENDER_GLTEXTUREMANAGER_H
diff --git a/src/render/texture/renderbuffer.cpp b/src/render/texture/renderbuffer.cpp
deleted file mode 100644
index bc5050f73..000000000
--- a/src/render/texture/renderbuffer.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "renderbuffer_p.h"
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QOpenGLFunctions>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DRender {
-namespace Render {
-
-RenderBuffer::RenderBuffer(int width, int height, QAbstractTexture::TextureFormat format)
- : m_size(width, height),
- m_format(format),
- m_renderBuffer(0),
- m_context(nullptr)
-{
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
- if (!ctx) {
- qWarning("Renderbuffer requires an OpenGL context");
- return;
- }
-
- m_context = ctx;
- QOpenGLFunctions *f = ctx->functions();
- f->glGenRenderbuffers(1, &m_renderBuffer);
- if (!m_renderBuffer)
- return;
-
- f->glBindRenderbuffer(GL_RENDERBUFFER, m_renderBuffer);
- while (f->glGetError() != GL_NO_ERROR) { }
- f->glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
- GLint err = f->glGetError();
- if (err != GL_NO_ERROR)
- qWarning("Failed to set renderbuffer storage: error 0x%x", err);
- f->glBindRenderbuffer(GL_RENDERBUFFER, 0);
-}
-
-RenderBuffer::~RenderBuffer()
-{
- if (m_renderBuffer) {
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
-
- // Ignore the fact that renderbuffers are sharable resources and let's
- // just expect that the context is the same as when the resource was
- // created. QOpenGLTexture suffers from the same limitation anyway, and
- // this is unlikely to become an issue within Qt 3D.
- if (ctx == m_context) {
- ctx->functions()->glDeleteRenderbuffers(1, &m_renderBuffer);
- } else {
- qWarning("Wrong current context; renderbuffer not destroyed");
- }
- }
-}
-
-void RenderBuffer::bind()
-{
- if (!m_renderBuffer)
- return;
-
- m_context->functions()->glBindRenderbuffer(GL_RENDERBUFFER, m_renderBuffer);
-}
-
-void RenderBuffer::release()
-{
- if (!m_context)
- return;
-
- m_context->functions()->glBindRenderbuffer(GL_RENDERBUFFER, 0);
-}
-
-} // namespace Render
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
diff --git a/src/render/texture/renderbuffer_p.h b/src/render/texture/renderbuffer_p.h
deleted file mode 100644
index 7dc62492a..000000000
--- a/src/render/texture/renderbuffer_p.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DRENDER_RENDER_RENDERBUFFER_P_H
-#define QT3DRENDER_RENDER_RENDERBUFFER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <Qt3DRender/qabstracttexture.h>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLContext;
-
-namespace Qt3DRender {
-namespace Render {
-
-class Q_AUTOTEST_EXPORT RenderBuffer
-{
-public:
- RenderBuffer(int width, int height, QAbstractTexture::TextureFormat format);
- ~RenderBuffer();
-
- int width() const { return m_size.width(); }
- int height() const { return m_size.height(); }
- QSize size() const { return m_size; }
- QAbstractTexture::TextureFormat format() const { return m_format; }
- GLuint renderBufferId() const { return m_renderBuffer; }
-
- void bind();
- void release();
-
-private:
- QSize m_size;
- QAbstractTexture::TextureFormat m_format;
- GLuint m_renderBuffer;
- QOpenGLContext *m_context;
-};
-
-} // namespace Render
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
-
-#endif // QT3DRENDER_RENDER_RENDERBUFFER_P_H
diff --git a/src/render/texture/texture.pri b/src/render/texture/texture.pri
index 17855d943..0d520a9ec 100644
--- a/src/render/texture/texture.pri
+++ b/src/render/texture/texture.pri
@@ -21,10 +21,7 @@ HEADERS += \
$$PWD/qtexture_p.h \
$$PWD/qpaintedtextureimage.h \
$$PWD/qpaintedtextureimage_p.h \
- $$PWD/gltexture_p.h \
- $$PWD/gltexturemanager_p.h \
- $$PWD/apitexturemanager_p.h \
- $$PWD/renderbuffer_p.h
+ $$PWD/apitexturemanager_p.h
SOURCES += \
$$PWD/qabstracttextureimage.cpp \
@@ -37,6 +34,4 @@ SOURCES += \
$$PWD/qtextureimagedata.cpp \
$$PWD/qtexturedata.cpp \
$$PWD/qtexturegenerator.cpp \
- $$PWD/qpaintedtextureimage.cpp \
- $$PWD/gltexture.cpp \
- $$PWD/renderbuffer.cpp
+ $$PWD/qpaintedtextureimage.cpp