You need to derive from QSGTexture class.
If you need a framebuffer to draw into, do something like this.
// ---------------------------------------------------------------------------
class QMLRenderTarget : public QSGTexture
{
Q_OBJECT
public :
QMLRenderTarget(int width, int height);
virtual ~QMLRenderTarget();
void begin();
void end();
virtual void bind();
virtual bool hasAlphaChannel() const;
virtual bool hasMipmaps() const;
virtual int textureId() const;
virtual QSize textureSize() const;
public:
QOpenGLFramebufferObject *fbo;
};
// ---------------------------------------------------------------------------
QMLRenderTarget::QMLRenderTarget(int width, int height)
{
QOpenGLFramebufferObjectFormat fmt;
fmt.setMipmap(true);
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
fbo = new QOpenGLFramebufferObject(width, height, fmt);
}
// ---------------------------------------------------------------------------
QMLRenderTarget::~QMLRenderTarget()
{
delete fbo;
}
// ---------------------------------------------------------------------------
void QMLRenderTarget::begin()
{
if (!fbo->bind()) {
throw lock_failed();
}
}
// ---------------------------------------------------------------------------
void QMLRenderTarget::end()
{
fbo->release();
}
// ---------------------------------------------------------------------------
void QMLRenderTarget::bind()
{
glBindTexture(GL_TEXTURE_2D, fbo->texture());
}
// ---------------------------------------------------------------------------
bool QMLRenderTarget::hasAlphaChannel() const
{
return true;
}
// ---------------------------------------------------------------------------
bool QMLRenderTarget::hasMipmaps() const
{
return true;
}
// ---------------------------------------------------------------------------
int QMLRenderTarget::textureId() const
{
return fbo->texture();
}
// ---------------------------------------------------------------------------
QSize QMLRenderTarget::textureSize() const
{
return QSize(fbo->width(), fbo->height());
}
↧