OpenGL: Make use of the requested version and profile in QGLWidget
[profile/ivi/qtbase.git] / src / opengl / qglframebufferobject.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 QtOpenGL 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 QGLFRAMEBUFFEROBJECT_H
43 #define QGLFRAMEBUFFEROBJECT_H
44
45 #include <QtOpenGL/qgl.h>
46 #include <QtGui/qpaintdevice.h>
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52
53 class QGLFramebufferObjectPrivate;
54 class QGLFramebufferObjectFormat;
55
56 class Q_OPENGL_EXPORT QGLFramebufferObject : public QPaintDevice
57 {
58     Q_DECLARE_PRIVATE(QGLFramebufferObject)
59 public:
60     enum Attachment {
61         NoAttachment,
62         CombinedDepthStencil,
63         Depth
64     };
65
66     QGLFramebufferObject(const QSize &size, GLenum target = GL_TEXTURE_2D);
67     QGLFramebufferObject(int width, int height, GLenum target = GL_TEXTURE_2D);
68 #if !defined(QT_OPENGL_ES) || defined(Q_QDOC)
69     QGLFramebufferObject(const QSize &size, Attachment attachment,
70                          GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA8);
71     QGLFramebufferObject(int width, int height, Attachment attachment,
72                          GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA8);
73 #else
74     QGLFramebufferObject(const QSize &size, Attachment attachment,
75                          GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA);
76     QGLFramebufferObject(int width, int height, Attachment attachment,
77                          GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA);
78 #endif
79
80     QGLFramebufferObject(const QSize &size, const QGLFramebufferObjectFormat &format);
81     QGLFramebufferObject(int width, int height, const QGLFramebufferObjectFormat &format);
82
83     virtual ~QGLFramebufferObject();
84
85     QGLFramebufferObjectFormat format() const;
86
87     bool isValid() const;
88     bool isBound() const;
89     bool bind();
90     bool release();
91
92     GLuint texture() const;
93     QSize size() const;
94     QImage toImage() const;
95     Attachment attachment() const;
96
97     QPaintEngine *paintEngine() const;
98     GLuint handle() const;
99
100     static bool bindDefault();
101
102     static bool hasOpenGLFramebufferObjects();
103
104     void drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
105     void drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
106
107     static bool hasOpenGLFramebufferBlit();
108     static void blitFramebuffer(QGLFramebufferObject *target, const QRect &targetRect,
109                                 QGLFramebufferObject *source, const QRect &sourceRect,
110                                 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
111                                 GLenum filter = GL_NEAREST);
112
113 protected:
114     int metric(PaintDeviceMetric metric) const;
115     int devType() const { return QInternal::FramebufferObject; }
116
117 private:
118     Q_DISABLE_COPY(QGLFramebufferObject)
119     QScopedPointer<QGLFramebufferObjectPrivate> d_ptr;
120     friend class QGLPaintDevice;
121     friend class QGLFBOGLPaintDevice;
122 };
123
124 class QGLFramebufferObjectFormatPrivate;
125 class Q_OPENGL_EXPORT QGLFramebufferObjectFormat
126 {
127 public:
128     QGLFramebufferObjectFormat();
129     QGLFramebufferObjectFormat(const QGLFramebufferObjectFormat &other);
130     QGLFramebufferObjectFormat &operator=(const QGLFramebufferObjectFormat &other);
131     ~QGLFramebufferObjectFormat();
132
133     void setSamples(int samples);
134     int samples() const;
135
136     void setMipmap(bool enabled);
137     bool mipmap() const;
138
139     void setAttachment(QGLFramebufferObject::Attachment attachment);
140     QGLFramebufferObject::Attachment attachment() const;
141
142     void setTextureTarget(GLenum target);
143     GLenum textureTarget() const;
144
145     void setInternalTextureFormat(GLenum internalTextureFormat);
146     GLenum internalTextureFormat() const;
147
148     bool operator==(const QGLFramebufferObjectFormat& other) const;
149     bool operator!=(const QGLFramebufferObjectFormat& other) const;
150
151 private:
152     QGLFramebufferObjectFormatPrivate *d;
153
154     void detach();
155 };
156
157 QT_END_NAMESPACE
158
159 QT_END_HEADER
160 #endif // QGLFRAMEBUFFEROBJECT_H