[Interest] createTextureFromId - how/when/where?

Gav Wood qtinterest at gavwood.com
Fri Jun 7 16:46:08 CEST 2013


Hi,

I'm trying to get some custom texture data working within the QSG
framework. I have the basic data for the texture available as a large
array of floats (describing the intensity, for now). I found the
QQuickWindow::createTextureFromId call which seems to be exactly what
I want.

So in my updatePaintNode call, I'm creating a quad to display and
setting the material as an opaque texture of id according to the GL
texture's id. Only problem is that it's coming out black.

If I exchange the createTextureFromId with a createTextureFromImage,
the quad is textured as expected. What am I doing wrong?

// MyPoint2D_AttributeSet is actually just equivalnt to a
TexturedPoint2D attribute set (i.e. x/y & tx/ty).
QSGGeometry* geo = new QSGGeometry(MyPoint2D_AttributeSet, 4);
MyPoint2D* d = static_cast<MyPoint2D*>(geo->vertexData());
d[0] = {0, 0, 0, 0};
d[1] = {h, 0, 1, 0};
d[2] = {h, w, 1, 1};
d[3] = {0, w, 0, 1};
geo->setDrawingMode(GL_QUADS);
QSGGeometryNode* n = new QSGGeometryNode;
n->setGeometry(geo);
n->setFlag(QSGNode::OwnsGeometry);

QSGOpaqueTextureMaterial* m = new QSGOpaqueTextureMaterial;
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
intermed[0] = 1;
intermed[1] = 0.5;
intermed[2] = 0;
intermed[3] = 1;
glTexImage2D(id, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, intermed);
glBindTexture(GL_TEXTURE_2D, 0);
m->setTexture(window()->createTextureFromId(id, QSize(1, 1),
QQuickWindow::TextureOwnsGLTexture));
// memory leak here - texture needs to be deleted at some point.

// NOTE: displays texture fine...
//m->setTexture(window()->createTextureFromImage(QImage("/some/example/image.jpg"));

n->setMaterial(m);
n->setFlag(QSGNode::OwnsMaterial);

Thanks,

Gav.

--
In the course of a normal year, more people die from falling off
horses than from taking ecstasy.



More information about the Interest mailing list