1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtOpenGL module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QGLFRAMEBUFFEROBJECT_P_H 41 #define QGLFRAMEBUFFEROBJECT_P_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include <qglframebufferobject.h> 55 #include <private/qglpaintdevice_p.h> 56 #include <private/qgl_p.h> 57 #include <private/qopenglextensions_p.h> 58 59 QT_BEGIN_NAMESPACE 60 61 class QGLFramebufferObjectFormatPrivate 62 { 63 public: QGLFramebufferObjectFormatPrivate()64 QGLFramebufferObjectFormatPrivate() 65 : ref(1), 66 samples(0), 67 attachment(QGLFramebufferObject::NoAttachment), 68 target(GL_TEXTURE_2D), 69 mipmap(false) 70 { 71 #ifndef QT_OPENGL_ES_2 72 QOpenGLContext *ctx = QOpenGLContext::currentContext(); 73 const bool isES = ctx ? ctx->isOpenGLES() : QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL; 74 internal_format = isES ? GL_RGBA : GL_RGBA8; 75 #else 76 internal_format = GL_RGBA; 77 #endif 78 } QGLFramebufferObjectFormatPrivate(const QGLFramebufferObjectFormatPrivate * other)79 QGLFramebufferObjectFormatPrivate 80 (const QGLFramebufferObjectFormatPrivate *other) 81 : ref(1), 82 samples(other->samples), 83 attachment(other->attachment), 84 target(other->target), 85 internal_format(other->internal_format), 86 mipmap(other->mipmap) 87 { 88 } equals(const QGLFramebufferObjectFormatPrivate * other)89 bool equals(const QGLFramebufferObjectFormatPrivate *other) 90 { 91 return samples == other->samples && 92 attachment == other->attachment && 93 target == other->target && 94 internal_format == other->internal_format && 95 mipmap == other->mipmap; 96 } 97 98 QAtomicInt ref; 99 int samples; 100 QGLFramebufferObject::Attachment attachment; 101 GLenum target; 102 GLenum internal_format; 103 uint mipmap : 1; 104 }; 105 106 class QGLFBOGLPaintDevice : public QGLPaintDevice 107 { 108 public: paintEngine()109 virtual QPaintEngine* paintEngine() const override {return fbo->paintEngine();} size()110 virtual QSize size() const override {return fbo->size();} 111 virtual QGLContext* context() const override; format()112 virtual QGLFormat format() const override {return fboFormat;} alphaRequested()113 virtual bool alphaRequested() const override { return reqAlpha; } 114 115 void setFBO(QGLFramebufferObject* f, 116 QGLFramebufferObject::Attachment attachment); 117 118 private: 119 QGLFramebufferObject* fbo; 120 QGLFormat fboFormat; 121 bool reqAlpha; 122 }; 123 124 class QGLFramebufferObjectPrivate 125 { 126 public: QGLFramebufferObjectPrivate()127 QGLFramebufferObjectPrivate() : fbo_guard(nullptr), texture_guard(nullptr), depth_buffer_guard(nullptr) 128 , stencil_buffer_guard(nullptr), color_buffer_guard(nullptr) 129 , valid(false), engine(nullptr) {} ~QGLFramebufferObjectPrivate()130 ~QGLFramebufferObjectPrivate() {} 131 132 void init(QGLFramebufferObject *q, const QSize& sz, 133 QGLFramebufferObject::Attachment attachment, 134 GLenum internal_format, GLenum texture_target, 135 GLint samples = 0, bool mipmap = false); 136 bool checkFramebufferStatus() const; 137 QGLSharedResourceGuardBase *fbo_guard; 138 QGLSharedResourceGuardBase *texture_guard; 139 QGLSharedResourceGuardBase *depth_buffer_guard; 140 QGLSharedResourceGuardBase *stencil_buffer_guard; 141 QGLSharedResourceGuardBase *color_buffer_guard; 142 GLenum target; 143 QSize size; 144 QGLFramebufferObjectFormat format; 145 uint valid : 1; 146 QGLFramebufferObject::Attachment fbo_attachment; 147 mutable QPaintEngine *engine; 148 QGLFBOGLPaintDevice glDevice; 149 QOpenGLExtensions funcs; 150 fbo()151 inline GLuint fbo() const { return fbo_guard ? fbo_guard->id() : 0; } 152 }; 153 154 155 QT_END_NAMESPACE 156 157 #endif // QGLFRAMEBUFFEROBJECT_P_H 158