How can I implement QQuickItem::updatePaintNode() to show an video image using QSGTexture?
-
@
QSGTexture texture;
QSGNode * updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData )
{
QSGNode node;
if(!oldNode)
{
node = new QSGSimpleTextureNode();
}node->setTexture(&texture); return node;
}
@How can I construct a QSGTexture object to show an image?
(there's an image buffer pointer which points to pixels data of an image: imgBuffer)
should I need to call EGL library function? -
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());
}@