1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QGLFRAMEBUFFEROBJECT_P_H
43#define QGLFRAMEBUFFEROBJECT_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
56QT_BEGIN_NAMESPACE
57
58QT_BEGIN_INCLUDE_NAMESPACE
59
60#include <qglframebufferobject.h>
61#include <private/qglpaintdevice_p.h>
62#include <private/qgl_p.h>
63
64QT_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
72class QGLFramebufferObjectFormatPrivate
73{
74public:
75 QGLFramebufferObjectFormatPrivate()
76 : ref(1),
77 samples(0),
78 attachment(QGLFramebufferObject::NoAttachment),
79 target(GL_TEXTURE_2D),
80 internal_format(DEFAULT_FORMAT),
81 mipmap(false)
82 {
83 }
84 QGLFramebufferObjectFormatPrivate
85 (const QGLFramebufferObjectFormatPrivate *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 QGLFramebufferObjectFormatPrivate *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 QGLFramebufferObject::Attachment attachment;
106 GLenum target;
107 GLenum internal_format;
108 uint mipmap : 1;
109};
110
111class QGLFBOGLPaintDevice : public QGLPaintDevice
112{
113public:
114 virtual QPaintEngine* paintEngine() const {return fbo->paintEngine();}
115 virtual QSize size() const {return fbo->size();}
116 virtual QGLContext* context() const;
117 virtual QGLFormat format() const {return fboFormat;}
118 virtual bool alphaRequested() const { return reqAlpha; }
119
120 void setFBO(QGLFramebufferObject* f,
121 QGLFramebufferObject::Attachment attachment);
122
123private:
124 QGLFramebufferObject* fbo;
125 QGLFormat fboFormat;
126 bool wasBound;
127 bool reqAlpha;
128};
129
130class QGLFramebufferObjectPrivate
131{
132public:
133 QGLFramebufferObjectPrivate() : fbo_guard(0), texture(0), depth_buffer(0), stencil_buffer(0)
134 , color_buffer(0), valid(false), engine(0) {}
135 ~QGLFramebufferObjectPrivate() {}
136
137 void init(QGLFramebufferObject *q, const QSize& sz,
138 QGLFramebufferObject::Attachment attachment,
139 GLenum internal_format, GLenum texture_target,
140 GLint samples = 0, bool mipmap = false);
141 bool checkFramebufferStatus() const;
142 QGLSharedResourceGuard fbo_guard;
143 GLuint texture;
144 GLuint depth_buffer;
145 GLuint stencil_buffer;
146 GLuint color_buffer;
147 GLenum target;
148 QSize size;
149 QGLFramebufferObjectFormat format;
150 uint valid : 1;
151 QGLFramebufferObject::Attachment fbo_attachment;
152 mutable QPaintEngine *engine;
153 QGLFBOGLPaintDevice glDevice;
154
155 inline GLuint fbo() const { return fbo_guard.id(); }
156};
157
158
159QT_END_NAMESPACE
160
161#endif // QGLFRAMEBUFFEROBJECT_P_H
162