opencascade qml QQuickItem offscreen FBO

kndpeng

Looking around for some CAD
I modify AndroidQt, but the display area alway display left bottom corner.
JSlyadne says: you'll need to utilize another approach and deal with frame buffer rendering.
Can anyboy give me a example or a clue?
 

JSlyadne

Administrator
Staff member
Please, point out what version of Qt\Qml you use as it makes a big difference since Qt 6.
 

JSlyadne

Administrator
Staff member
The sample you rely on initializes the OCCT viewer by giving it the id of the main window what means the OCCT viewer uses the canvas of the main window for rendering, and changing the size of the host item (OcctViewer item) has an impact on the camera view.

this->initializeViewer(Aspect_Drawable(this->window()->winId()));

Approaching FBO will allow you to make OCCT to render on a specific area of window. To achieve this you should substitu OcctViewer with own implementation which will inherit QQuickFramebufferObject. Look at this (https://code.qt.io/cgit/qt/qtdeclarative.git/tree/examples/quick/scenegraph/fboitem?h=6.5) as an example.
 
Last edited:

JSlyadne

Administrator
Staff member
Below is another sample code where OcctFramebufferObject is an item to render on and OcctViewer is a class wrapping OCCT rendering capabilities (initializes window, context, view(s), etc.)

class OcctFramebufferObject: public QQuickFramebufferObject
{
...

private:
class FboRenderer;
}

class OcctFramebufferObject::FboRenderer : public QQuickFramebufferObject::Renderer
{
public:
FboRenderer();

protected:
void synchronize(QQuickFramebufferObject* fboViewer) override;
QOpenGLFramebufferObject* createFramebufferObject(const QSize& size) override;
void render() override;

private:
OcctViewer m_renderer;
};

OcctFramebufferObject::FboRenderer::FboRenderer()
: Renderer()
{
}

void OcctFramebufferObject::FboRenderer::synchronize(QQuickFramebufferObject* fboViewer)
{
auto* viewer = qobject_cast<OcctFramebufferObject*>(fboViewer);
if (viewer == nullptr)
return;

// The right place for passing data from GUI to Rendering thread
...

}

QOpenGLFramebufferObject* OcctFramebufferObject::FboRenderer::createFramebufferObject(const QSize& size)
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setInternalTextureFormat(GL_RGB8);
format.setSamples(4);
return new QOpenGLFramebufferObject(size, format);
}

void OcctFramebufferObject::FboRenderer::render()
{
const QOpenGLFramebufferObject& fbo = *framebufferObject();
m_renderer.setSize(fbo.width(), fbo.height());
m_renderer.render(fbo.handle()); // Do rendering stuff here
}
 
Top