[SOLVED] Using a vtk renderer in QtQuick
-
Hi z.emb,
I'm working on this exact problem also.
Could you tell me what QSGFboTexture is? and also fbo.get() fbo.reset() ?
-
[quote author="Martell Malone" date="1360770728"]
What about setting the material and the opaque material do you even use them?Is there anything else we should know to get this working?
I seem to be missing something as it keeps crashing.[/quote]No I don't use them. I derived my node from QSGSimpleTextureNode, which handles these things for me, I think. I just need to add my own QSGFboTexture and thats it.
Like I said above, be sure that you don't access any objects in the preprocess() that are also accessed from the GUI thread.
For debugging reasons you can do the rendering also in the updatePaintNode() method (in my example in the updateNode() method which is called from updatePaintNode() ) to be sure it is not a threading problem.Edit:
[quote author="Martell Malone" date="1360770728"]
Could you tell me what QSGFboTexture is? and also fbo.get() fbo.reset() ?
[/quote]QSGFboTexture is my subclass for the FBO texture, just implement the pure virtual functions of QSGTexture:
@
void QSGFboTexture::setFbo(QOpenGLFramebufferObject* fbo)
{
if(d_data->fbo == fbo)
return;d_data->fbo = fbo; d_data->firstTimeBound = true;
}
void QSGFboTexture::bind()
{
if(d_data->fbo == nullptr)
return;auto fboTexture = textureId(); glBindTexture(GL_TEXTURE_2D, fboTexture); if(d_data->firstTimeBound) { updateBindOptions(true); d_data->firstTimeBound = false; }
}
bool QSGFboTexture::hasAlphaChannel() const
{
return true;
}bool QSGFboTexture::hasMipmaps() const
{
if(d_data->fbo == nullptr)
return false;return d_data->fbo->format().mipmap();
}
int QSGFboTexture::textureId() const
{
if(d_data->fbo == nullptr)
return 0;return d_data->fbo->texture();
}
QSize QSGFboTexture::textureSize() const
{
if(d_data->fbo == nullptr)
return QSize();return d_data->fbo->size();
@
I use the "std::unique_ptr":http://www.cplusplus.com/reference/memory/unique_ptr/ template. Therefore the get() and reset().
-
Thansk for that z.emb
I was working basing my code from qt3d before which is why I couldn't get it to work
http://qt.gitorious.net/qt-labs/qt3d/blobs/83fd6411a16f09b81252d4a4398a1968451754c9/src/imports/threed/viewportfbonode_sg.cppSeems you found the solution ;)
-
glPopAttrib and glPushAttrib are invalid functions?
You can do beginNativePainting within QPainter to access these functions but I'm guessing thats not what you did.
Im on qt 5.0.1 ANGLE GLES version
What header did you include?
-
I've made more progress on getting it working on GLES systems.
My window flickers for a frame and then goes gray.Also for that frame the scene is upside down and a texture is missing.
The last two things that I wish to ask
- I noticed
setFbo isn't called anywhere?
and also I have two size methods setRect and setSize
@void ColorNode::setSize(const QSize size)
{
if (size == m_size) return;m_size = size; //m_fbo = NULL; //m_texture = NULL; QSGGeometry::updateTexturedRectGeometry(&m_geometry, QRectF(0, 0, m_size.width(), m_size.height()), QRectF(0, 0, 1, 1)); markDirty(DirtyGeometry);
}
void ColorNode::setRect(const QRectF rect)
{
if (m_rect == rect) returnmarkDirty(DirtyGeometry); m_rect = rect;
}@
I'm guessing yous implementation is different?
Could I get a quick look :)I think I'm really close
- I noticed
-
Actually, I posted almost the whole implementation already, but here you go: "Node":http://pastebin.com/8CgheNzm . The implementation of the texture and the item are already posted.
bq. I noticed setFbo isn’t called anywhere?
You may have noticed that I pass the FBO to the constructor of the texture ;-)
bq. What header did you include?
I compiled Qt 5.0.0 with ANGLE deactivated and the -opengl desktop flag, because I use VTK which also uses the native OpenGL system.
-
I need to set the geometry in my setsize or I get nothing in the window.
@
QSGFboTexture::QSGFboTexture(QGLFramebufferObject* fbo)
:QSGTexture()
{
m_fbo = fbo;// setFbo(fbo);
if (m_fbo != NULL)
firstTimeBound = true;}
@same as setFbo ;-)
The problem is that on ANGLE we are using a GLES emulator not OpenGL.
Those two functions don't exsist.What happens to your window when you dont call the push and pop?
@void ColorNode::preprocess()
{
if(m_fbo == NULL) return; //will happen a few timesQOpenGLContext::currentContext()->functions()->glUseProgram(0); m_fbo->bind();
CCDirector::sharedDirector()->mainLoop();
m_fbo->release();
m_fbo->toImage().save("name.png","png");
}@
-
Its not working without the push and pop (nothing is rendered, only the background). Unfortunatelly I cannot tell you why, I'm no OpenGL expert.
-
I think I understand why.
The only problem is GLES doest support those functions so how do we get around them?Maybe I should make a new thread to this issue?
-
I found a new way of solving this problem.
It Involves setting up a separate opengl context and switching between the two before and after binding and releasing the fbo.
Any idea how to draw correctly for a y inverted fbo.
On qquickpainteditem we can set it to flip but not for the qsgtexture :/ -
Hey, thanks for your reply. Can you provide some code how you do that?
In my case, it also seems to be the cleanest way to do the same thing and I wan't to try that. :-)For the flipping problem I would naivly just scale (glScale) the y-Axis with -1. But as I mentioned, I'm no OpenGL expert.
-
Hey z.emb
I used what was on this thread.
http://qt-project.org/forums/viewthread/25268/
I just changed this line for the flip y.
QSGGeometry::updateTexturedRectGeometry(&m_geometry,
QRectF(0, 0, m_size.width(), m_size.height()),
QRectF(0, 0, 1, 1));to
QSGGeometry::updateTexturedRectGeometry(&m_geometry,
QRectF(0, 0, m_size.width(), m_size.height()),
QRectF(0, 1, 1, -1));//0011 = old y fliped -
Can you give me some code how you switched the GL-context?
-
Hey Guys,
Apologies about not replying.
I didn't realize I got a response.I swapped the context at the very beginning by using the code in this thread
http://qt-project.org/forums/viewthread/25268/
Hope that helps Ricky, just got your pm.
Many Thanks
Martell -
Hi,
I still did not get it.
Could you, please, anyone post a full example about rendering vtk to qtquick?
I was trying to understand the discussion but I did not get through...Best regards,
radek
-
Hey, I join to this request. Even the simplest example would be helpful.
Regards,
rafal -
I have created a repository with code that integrates VTK with Qt QuickControls 2, tested with VTK 8 and Qt 5.9. You can find the code here https://github.com/nicanor-romero/QtVtk with building instructions in the README. Also a brief article about it,
https://blog.bq.com/es/integrating-qtquickcontrols-2-with-vtk/