45 #include <private/qpaintengine_raster_p.h> 49 #include <private/qgl_p.h> 50 #include <private/qdrawhelper_p.h> 51 #include <private/qimage_p.h> 52 #include <private/qfont_p.h> 54 #include <private/qpaintengineex_opengl2_p.h> 103 for (
int i = 0; !chosen && i <
m_fbos.
size(); ++i) {
107 if (fbo->
size() == requestSize && fbo->
format() == requestFormat) {
115 if (fbo->
format() == requestFormat) {
117 if (!candidate ||
areaDiff(requestSize, candidate) >
areaDiff(requestSize, fbo))
169 return data->paintEngine();
174 if (!
data->isValid())
179 m_thisFBO =
data->m_renderFbo->handle();
185 if (
data->needsFill()) {
189 glClearColor(c.
redF() * alpha, c.
greenF() * alpha, c.
blueF() * alpha, alpha);
192 else if (!
data->isUninitialized()) {
201 #if !defined(QT_OPENGL_ES_2) 202 glMatrixMode(GL_MODELVIEW);
205 glMatrixMode(GL_PROJECTION);
207 glOrtho(0,
data->width(),
data->height(), 0, -999999, 999999);
210 glViewport(0, 0,
data->width(),
data->height());
213 context()->drawTexture(
QRect(0, 0,
data->width(),
data->height()),
data->bind(
false));
219 if (!
data->isValid())
222 data->copyBackFromRenderFbo(
false);
228 data->m_renderFbo = 0;
233 data->ensureCreated();
244 return data->m_hasAlpha;
260 , m_hasFillColor(false)
288 return w > 0 &&
h > 0;
302 if (width ==
w && height ==
h)
305 if (width <= 0 || height <= 0) {
337 #ifdef QT_OPENGL_ES_2 338 const GLenum external_format = internal_format;
347 glTexImage2D(target, 0, internal_format,
w,
h, 0, external_format,
GL_UNSIGNED_BYTE, 0);
353 if (external_format ==
GL_RGB) {
357 glTexSubImage2D(target, 0, 0, 0,
w,
h, external_format,
360 const QImage tx = ctx->d_func()->convertToGLFormat(
m_source,
true, external_format);
363 glTexSubImage2D(target, 0, 0, 0,
w,
h, external_format,
375 Qt::ImageConversionFlags flags)
382 Qt::ImageConversionFlags flags)
392 Qt::ImageConversionFlags flags)
396 QFile file(filename);
432 Qt::ImageConversionFlags flags)
435 const char *buf =
reinterpret_cast<const char *
>(
buffer);
479 if (
qApp->desktop()->depth() == 16)
484 || const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels()))
567 bool hasAlpha = color.
alpha() != 255;
665 return _qgl_fbo_pool();
702 if (keepCurrentFboBound) {
746 qWarning() <<
"Failed to create pixmap texture buffer of size " <<
size() <<
", falling back to raster paint engine";
822 qWarning(
"QGLPixmapData::metric(): Invalid metric");
The QColor class provides colors based on RGB, HSV or CMYK values.
static bool hasOpenGLFramebufferObjects()
Returns true if the OpenGL GL_EXT_framebuffer_object extension is present on this system; otherwise r...
virtual bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
QSize size() const
Returns the size of the texture attached to this framebuffer object.
QGLPaintDevice * glDevice() const
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
QGLFramebufferObjectPool * qgl_fbo_pool()
Format
The following image formats are available in Qt.
QScopedPointer< QGLContextPrivate > d_ptr
bool canBindCompressedTexture(const char *buf, int len, const char *format, bool *hasAlpha)
qreal alphaF() const
Returns the alpha color component of this color.
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha)
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
#define GL_TEXTURE_MIN_FILTER
QPixmapData * createCompatiblePixmapData() const
QGLPixmapGLPaintDevice m_glDevice
#define QT_END_NAMESPACE
This macro expands to.
void fill(const QColor &color)
bool isValidContext(const QGLContext *ctx) const
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
qreal greenF() const
Returns the green color component of this color.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Q_GUI_EXPORT int qt_defaultDpiY()
bool open(OpenMode openMode)
Reimplemented Function
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Q_OPENGL_EXPORT QGLWidget * qt_gl_share_widget()
bool isValid() const
Returns true if the framebuffer object is valid.
void fill(uint pixel)
Fills the entire image with the given pixelValue.
The QByteArray class provides an array of bytes.
GLuint bind(bool copyBack=true) const
Q_GUI_EXPORT int qt_defaultDpiX()
QGLContext * context() const
The QGLFramebufferObject class provides a pool of framebuffer objects for offscreen rendering purpose...
QRgb qt_gl_convertToGLFormat(QRgb src_pixel, GLenum texture_format)
QGL2PaintEngineEx * engine
int width() const
Returns the width of the rectangle.
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
long ASN1_INTEGER_get ASN1_INTEGER * a
int metric(QPaintDevice::PaintDeviceMetric metric) const
int qt_next_power_of_two(int v)
The QBuffer class provides a QIODevice interface for a QByteArray.
int height() const
Returns the height of the rectangle.
#define GL_FRAMEBUFFER_EXT
The QString class provides a Unicode character string.
void setHeight(int h)
Sets the height to the given height.
Q_DECL_CONSTEXPR T qAbs(const T &t)
#define glBindFramebuffer
void copyBackFromRenderFbo(bool keepCurrentFboBound) const
QGLContext::BindOptions options
Format format() const
Returns the format of the image.
#define GL_COLOR_ATTACHMENT0_EXT
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
static const QGLContext * currentContext()
Returns the current context, i.e.
void setWidth(int w)
Sets the width to the given width.
QGLFramebufferObject * acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize=false)
static bool areSharing(const QGLContext *context1, const QGLContext *context2)
Returns true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.
#define glBlitFramebufferEXT
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
PixelType pixelType() const
QGLTexture * texture() const
bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
int width() const
Returns the width.
void setColorCount(int)
Resizes the color table to contain colorCount entries.
bool alphaRequested() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
void ensureCreated() const
The QGLContext class encapsulates an OpenGL rendering context.
QGLPixmapData(PixelType type)
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
QList< QGLFramebufferObject * > m_fbos
const T & at(int i) const
Returns the item at index position i in the list.
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
QGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
void resize(int width, int height)
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
void release(QGLFramebufferObject *fbo)
qint64 peek(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, without side effects (i.
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
QPaintEngine * paintEngine
Q_CORE_EXPORT void qWarning(const char *,...)
#define glGenFramebuffers
#define GL_COLOR_BUFFER_BIT
The QImage class provides a hardware-independent image representation that allows direct access to th...
static const char * data(const QByteArray &arr)
int depth() const
Returns the depth of the image.
bool useFramebufferObjects() const
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
QImage mirrored(bool horizontally=false, bool vertically=true) const
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on ...
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
#define GL_DRAW_FRAMEBUFFER_EXT
void fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags)
bool qt_gl_preferGL2Engine()
QPaintEngine * paintEngine() const
The QImageReader class provides a format independent interface for reading images from files or other...
#define GL_READ_FRAMEBUFFER_EXT
QSize size() const
Returns the size of the image, i.
bool hasAlphaChannel() const
const char * constData() const
Returns a pointer to the data stored in the byte array.
uchar * bits()
Returns a pointer to the first pixel data.
int width() const
Returns the width of the image.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
The QFile class provides an interface for reading from and writing to files.
QGLFramebufferObject * fbo
ushort alpha
Returns the alpha color component of this color.
int y() const
Returns the y-coordinate of the rectangle's top edge.
virtual void beginPaint()
void * data_ptr(const QTransform &t)
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
out-of-place conversion (inPlace == false) will always detach()
qreal redF() const
Returns the red color component of this color.
int x() const
Returns the x-coordinate of the rectangle's left edge.
void setPixmapData(QGLPixmapData *)
int size() const
Returns the number of items in the list.
virtual void copy(const QPixmapData *data, const QRect &rect)
int height() const
Returns the height.
qreal blueF() const
Returns the blue color component of this color.
The QRect class defines a rectangle in the plane using integer precision.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
int height() const
Returns the height of the image.
int size() const
Returns the number of bytes in this byte array.
QGLFramebufferObject * m_renderFbo
virtual QImage * buffer()
bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
QPaintEngine * paintEngine() const
Used by QPainter to retrieve a paint engine for the image.
static QSize maybeRoundToNextPowerOfTwo(const QSize &sz)
The QSize class defines the size of a two-dimensional object using integer point precision.
QImage fillImage(const QColor &color) const
bool convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags)
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
QPaintEngine * paintEngine() const
#define GL_TEXTURE_MAG_FILTER
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
#define glFramebufferTexture2D
void setSerialNumber(int serNo)
QPaintEngine * active_engine
static int areaDiff(const QSize &size, const QGLFramebufferObject *fbo)
virtual void close()
Calls QFile::flush() and closes the file.
GLenum qt_gl_preferredTextureFormat()
static bool hasOpenGLFramebufferBlit()
Returns true if the OpenGL GL_EXT_framebuffer_blit extension is present on this system; otherwise ret...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QSize bindCompressedTexture(const QString &fileName, const char *format=0)
QImage read()
Reads an image from the device.
Q_DECL_CONSTEXPR int qRound(qreal d)
static int qt_gl_pixmap_serial
bool scroll(int dx, int dy, const QRect &rect)
void copy(const QPixmapData *data, const QRect &rect)