fbitem.cpp Example File
quickwidgets/quickwidget/fbitem.cpp
#include "fbitem.h"
#include <QtGui/QOpenGLFramebufferObject>
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFunctions>
#include <QtCore/QDebug>
#if QT_CONFIG(opengl)
class FbRenderer : public QQuickFramebufferObject::Renderer
{
public:
FbRenderer() { }
~FbRenderer() override {
qDebug("FbRenderer destroyed");
}
void render() override {
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClearColor(c, 0, 0, 1);
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
c += 0.01f * dir;
if (c >= 1.0f || c <= 0.0f)
dir *= -1;
update();
}
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override {
qDebug() << "Creating FBO" << size;
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
return new QOpenGLFramebufferObject(size, format);
}
private:
float c = 0;
int dir = 1;
};
#endif
QQuickFramebufferObject::Renderer *FbItem::createRenderer() const
{
#if QT_CONFIG(opengl)
return new FbRenderer;
#else
return nullptr;
#endif
}