00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QGLFRAMEBUFFEROBJECT_H
00043 #define QGLFRAMEBUFFEROBJECT_H
00044
00045 #include <QtOpenGL/qgl.h>
00046 #include <QtGui/qpaintdevice.h>
00047
00048 QT_BEGIN_HEADER
00049
00050 QT_BEGIN_NAMESPACE
00051
00052 QT_MODULE(OpenGL)
00053
00054 class QGLFramebufferObjectPrivate;
00055 class QGLFramebufferObjectFormat;
00056
00057 class Q_OPENGL_EXPORT QGLFramebufferObject : public QPaintDevice
00058 {
00059 Q_DECLARE_PRIVATE(QGLFramebufferObject)
00060 public:
00061 enum Attachment {
00062 NoAttachment,
00063 CombinedDepthStencil,
00064 Depth
00065 };
00066
00067 QGLFramebufferObject(const QSize &size, GLenum target = GL_TEXTURE_2D);
00068 QGLFramebufferObject(int width, int height, GLenum target = GL_TEXTURE_2D);
00069 #if !defined(QT_OPENGL_ES) || defined(Q_QDOC)
00070 QGLFramebufferObject(const QSize &size, Attachment attachment,
00071 GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA8);
00072 QGLFramebufferObject(int width, int height, Attachment attachment,
00073 GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA8);
00074 #else
00075 QGLFramebufferObject(const QSize &size, Attachment attachment,
00076 GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA);
00077 QGLFramebufferObject(int width, int height, Attachment attachment,
00078 GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA);
00079 #endif
00080
00081 QGLFramebufferObject(const QSize &size, const QGLFramebufferObjectFormat &format);
00082 QGLFramebufferObject(int width, int height, const QGLFramebufferObjectFormat &format);
00083
00084 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS
00085 QGLFramebufferObject(const QSize &size, QMacCompatGLenum target = GL_TEXTURE_2D);
00086 QGLFramebufferObject(int width, int height, QMacCompatGLenum target = GL_TEXTURE_2D);
00087
00088 QGLFramebufferObject(const QSize &size, Attachment attachment,
00089 QMacCompatGLenum target = GL_TEXTURE_2D, QMacCompatGLenum internal_format = GL_RGBA8);
00090 QGLFramebufferObject(int width, int height, Attachment attachment,
00091 QMacCompatGLenum target = GL_TEXTURE_2D, QMacCompatGLenum internal_format = GL_RGBA8);
00092 #endif
00093
00094 virtual ~QGLFramebufferObject();
00095
00096 QGLFramebufferObjectFormat format() const;
00097
00098 bool isValid() const;
00099 bool isBound() const;
00100 bool bind();
00101 bool release();
00102
00103 GLuint texture() const;
00104 QSize size() const;
00105 QImage toImage() const;
00106 Attachment attachment() const;
00107
00108 QPaintEngine *paintEngine() const;
00109 GLuint handle() const;
00110
00111 static bool bindDefault();
00112
00113 static bool hasOpenGLFramebufferObjects();
00114
00115 void drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
00116 void drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D);
00117 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS
00118 void drawTexture(const QRectF &target, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget = GL_TEXTURE_2D);
00119 void drawTexture(const QPointF &point, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget = GL_TEXTURE_2D);
00120 #endif
00121
00122 static bool hasOpenGLFramebufferBlit();
00123 static void blitFramebuffer(QGLFramebufferObject *target, const QRect &targetRect,
00124 QGLFramebufferObject *source, const QRect &sourceRect,
00125 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
00126 GLenum filter = GL_NEAREST);
00127
00128 protected:
00129 int metric(PaintDeviceMetric metric) const;
00130 int devType() const { return QInternal::FramebufferObject; }
00131
00132 private:
00133 Q_DISABLE_COPY(QGLFramebufferObject)
00134 QScopedPointer<QGLFramebufferObjectPrivate> d_ptr;
00135 friend class QGLPaintDevice;
00136 friend class QGLFBOGLPaintDevice;
00137 };
00138
00139 class QGLFramebufferObjectFormatPrivate;
00140 class Q_OPENGL_EXPORT QGLFramebufferObjectFormat
00141 {
00142 public:
00143 QGLFramebufferObjectFormat();
00144 QGLFramebufferObjectFormat(const QGLFramebufferObjectFormat &other);
00145 QGLFramebufferObjectFormat &operator=(const QGLFramebufferObjectFormat &other);
00146 ~QGLFramebufferObjectFormat();
00147
00148 void setSamples(int samples);
00149 int samples() const;
00150
00151 void setAttachment(QGLFramebufferObject::Attachment attachment);
00152 QGLFramebufferObject::Attachment attachment() const;
00153
00154 void setTextureTarget(GLenum target);
00155 GLenum textureTarget() const;
00156
00157 void setInternalTextureFormat(GLenum internalTextureFormat);
00158 GLenum internalTextureFormat() const;
00159
00160 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS
00161 void setTextureTarget(QMacCompatGLenum target);
00162 void setInternalTextureFormat(QMacCompatGLenum internalTextureFormat);
00163 #endif
00164
00165 bool operator==(const QGLFramebufferObjectFormat& other) const;
00166 bool operator!=(const QGLFramebufferObjectFormat& other) const;
00167
00168 private:
00169 QGLFramebufferObjectFormatPrivate *d;
00170
00171 void detach();
00172 };
00173
00174 QT_END_NAMESPACE
00175
00176 QT_END_HEADER
00177 #endif // QGLFRAMEBUFFEROBJECT_H