Added support for resetting QOpenGLFramebufferObject attachments.
[profile/ivi/qtbase.git] / src / gui / opengl / qopenglframebufferobject_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QOPENGLFRAMEBUFFEROBJECT_P_H
43 #define QOPENGLFRAMEBUFFEROBJECT_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists for the convenience
50 // of the QLibrary class.  This header file may change from
51 // version to version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 QT_BEGIN_NAMESPACE
57
58 QT_BEGIN_INCLUDE_NAMESPACE
59
60 #include <qopenglframebufferobject.h>
61 #include <private/qopenglcontext_p.h>
62 #include <private/qopenglextensions_p.h>
63
64 QT_END_INCLUDE_NAMESPACE
65
66 #ifndef QT_OPENGL_ES
67 #define DEFAULT_FORMAT GL_RGBA8
68 #else
69 #define DEFAULT_FORMAT GL_RGBA
70 #endif
71
72 class QOpenGLFramebufferObjectFormatPrivate
73 {
74 public:
75     QOpenGLFramebufferObjectFormatPrivate()
76         : ref(1),
77           samples(0),
78           attachment(QOpenGLFramebufferObject::NoAttachment),
79           target(GL_TEXTURE_2D),
80           internal_format(DEFAULT_FORMAT),
81           mipmap(false)
82     {
83     }
84     QOpenGLFramebufferObjectFormatPrivate
85             (const QOpenGLFramebufferObjectFormatPrivate *other)
86         : ref(1),
87           samples(other->samples),
88           attachment(other->attachment),
89           target(other->target),
90           internal_format(other->internal_format),
91           mipmap(other->mipmap)
92     {
93     }
94     bool equals(const QOpenGLFramebufferObjectFormatPrivate *other)
95     {
96         return samples == other->samples &&
97                attachment == other->attachment &&
98                target == other->target &&
99                internal_format == other->internal_format &&
100                mipmap == other->mipmap;
101     }
102
103     QAtomicInt ref;
104     int samples;
105     QOpenGLFramebufferObject::Attachment attachment;
106     GLenum target;
107     GLenum internal_format;
108     uint mipmap : 1;
109 };
110
111 class QOpenGLFramebufferObjectPrivate
112 {
113 public:
114     QOpenGLFramebufferObjectPrivate() : fbo_guard(0), texture_guard(0), depth_buffer_guard(0)
115                                   , stencil_buffer_guard(0), color_buffer_guard(0)
116                                   , valid(false) {}
117     ~QOpenGLFramebufferObjectPrivate() {}
118
119     void init(QOpenGLFramebufferObject *q, const QSize& sz,
120               QOpenGLFramebufferObject::Attachment attachment,
121               GLenum internal_format, GLenum texture_target,
122               GLint samples = 0, bool mipmap = false);
123     void initAttachments(QOpenGLContext *ctx, QOpenGLFramebufferObject::Attachment attachment);
124
125     bool checkFramebufferStatus(QOpenGLContext *ctx) const;
126     QOpenGLSharedResourceGuard *fbo_guard;
127     QOpenGLSharedResourceGuard *texture_guard;
128     QOpenGLSharedResourceGuard *depth_buffer_guard;
129     QOpenGLSharedResourceGuard *stencil_buffer_guard;
130     QOpenGLSharedResourceGuard *color_buffer_guard;
131     GLenum target;
132     QSize size;
133     QOpenGLFramebufferObjectFormat format;
134     uint valid : 1;
135     QOpenGLFramebufferObject::Attachment fbo_attachment;
136     QOpenGLExtensions funcs;
137
138     inline GLuint fbo() const { return fbo_guard ? fbo_guard->id() : 0; }
139 };
140
141
142 QT_END_NAMESPACE
143
144 #endif // QOPENGLFRAMEBUFFEROBJECT_P_H