I am using QtQuick with a custom OpenGL renderer (custom from the point of view of QtQuick as it is simply OpenSceneGraph). In order to do so I create a custom QQuickItem inheriting from QQuickFramebufferObject and that in turns creates a custom renderer inheriting from QQuickFramebufferObject::Renderer in QQuickFramebufferObject::createRenderer(). This is well documented and there is no problem with these steps.
Now what happens is that in order to be later accessed, the renderer created in QQuickFramebufferObject::createRenderer() is actually cached (it is actually instantiated in QQuickFramebufferObject constructor and simply returned in QQuickFramebufferObject::createRenderer(). This works fine and I can see no straightforward other way to code it as the created renderer is later used to react to events such as geometryChanged or mousePressEvent, e.g.
////////////////////////////////////////////////////////////////////////////////
void OsgItem::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
{
if (m_renderer)
m_renderer->m_window->getEventQueue()->windowResize(newGeometry.x(), newGeometry.y(), newGeometry.width(), newGeometry.height());
QQuickFramebufferObject::geometryChanged(newGeometry, oldGeometry);
}
////////////////////////////////////////////////////////////////////////////////
void OsgItem::mousePressEvent(QMouseEvent *event)
{
m_renderer->m_window->getEventQueue()->mouseButtonPress(event->x(), event->y(), button(*event));
update();
}
, where OsgItem is my custom QQuickFramebufferObject and m_renderer is my custom QQuickFramebufferObject::Renderer.
The problem is that createRenderer() is const (which is not really an invitation to cache things), and this paper clearly states that the renderer should not be cached -(although it is not stated in the official doc).
What's the catch here? Is there something that I have missed? Can you see another clean way I could code things?