Skip to content

Commit

Permalink
This removes native opengl support for qt5 due to the maintenance ove…
Browse files Browse the repository at this point in the history
…rhead and EOL of Qt5.

Qt5 Version now uses a QQuickPaintedItem and the shared software rendering backend thats also used in qt6.
  • Loading branch information
jebos authored and BertholdKrevert committed Aug 28, 2023
1 parent b6d9157 commit 83442ad
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 589 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ https://user-images.githubusercontent.com/1797537/233192955-7360403b-b51b-422a-8
## State of Implementation
| Platform | OpenGL | Direct3D |Vulkan |Metal |SoftwareRendering |
|---------------- |----------- |----------- |-----------|-----------|-----------|
| Qt5.15.2 Windows | partial, no blending |❌|❌|❌|✅(no texture meshes)
| Qt5.15.2 Linux | partial, no blending |❌|❌|❌|✅(no texture meshes)
| Qt5.15.2 macOS | ❌ |❌|❌|❌|✅(no texture meshes)
| Qt5.15.2 Windows | |❌|❌|❌|✅(no texture meshes)
| Qt5.15.2 Linux | |❌|❌|❌|✅(no texture meshes)
| Qt5.15.2 macOS | ❌ |❌|❌|❌|✅(no texture meshes)
| Qt6.5 Windows | ✅ |✅|✅|❌|✅(no texture meshes)
| Qt6.5 Linux | ✅ |❌|✅|❌|✅(no texture meshes)
| Qt6.5 macOS | ❌ |❌|❌|❌|✅(no texture meshes)
Expand Down
2 changes: 0 additions & 2 deletions src/RiveQtQuickItem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ set(PROJECT_SOURCES
riveqtquickitem.cpp
rivestatemachineinput.h
rivestatemachineinput.cpp
riveqsgopenglrendernode.h
riveqsgopenglrendernode.cpp
riveqsgsoftwarerendernode.h
riveqsgsoftwarerendernode.cpp
riveqsgrendernode.h
Expand Down
6 changes: 0 additions & 6 deletions src/RiveQtQuickItem/renderer/riveqtfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
# include "renderer/riveqtrhirenderer.h"
#else
# include "riveqsgopenglrendernode.h"
#endif

RiveQSGRenderNode *RiveQtFactory::renderNode(QQuickWindow *window, std::weak_ptr<rive::ArtboardInstance> artboardInstance,
Expand All @@ -32,10 +30,6 @@ RiveQSGRenderNode *RiveQtFactory::renderNode(QQuickWindow *window, std::weak_ptr
node->setPostprocessingMode(m_renderSettings.postprocessingMode);
return node;
}
#else
case QSGRendererInterface::GraphicsApi::OpenGL:
return new RiveQSGOpenGLRenderNode(window, artboardInstance, geometry);
break;
#endif
case QSGRendererInterface::GraphicsApi::Software:
default:
Expand Down
83 changes: 0 additions & 83 deletions src/RiveQtQuickItem/riveqsgopenglrendernode.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions src/RiveQtQuickItem/riveqsgopenglrendernode.h

This file was deleted.

99 changes: 76 additions & 23 deletions src/RiveQtQuickItem/riveqsgsoftwarerendernode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,68 @@ void RiveQSGSoftwareRenderNode::render(const RenderState *state)
renderSoftware(state);
}

void RiveQSGSoftwareRenderNode::paint(QPainter *painter)
{
if (!painter) {
return;
}

if (m_artboardInstance.expired()) {
return;
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto artboardInstance = m_artboardInstance.lock();

auto x = 0;
auto y = 0;

auto aspectX = painter->device()->width() / (artboardInstance->width());
auto aspectY = painter->device()->height() / (artboardInstance->height());

// Calculate the uniform scale factor to preserve the aspect ratio
auto scaleFactor = qMin(aspectX, aspectY);

// Calculate the new width and height of the item while preserving the aspect ratio
auto newWidth = artboardInstance->width() * scaleFactor;
auto newHeight = artboardInstance->height() * scaleFactor;

// Calculate the offsets needed to center the item within its bounding rectangle
auto offsetX = (painter->device()->width() - newWidth) / 2.0;
auto offsetY = (painter->device()->height() - newHeight) / 2.0;

// TODO this only works for PreserverAspectFit
m_scaleFactorX = scaleFactor;
m_scaleFactorY = scaleFactor;
m_topLeftRivePosition.setX(offsetX);
m_topLeftRivePosition.setY(offsetY);

m_modelViewTransform = QTransform();
// Apply transformations in the correct order
m_modelViewTransform.translate(x, y);
m_modelViewTransform.translate(offsetX, offsetY);
m_modelViewTransform.scale(scaleFactor, scaleFactor);
#endif

painter->save();
{
auto artboardInstance = m_artboardInstance.lock();

painter->setTransform(m_modelViewTransform, false);

m_renderer.setPainter(painter);

painter->save();
{
if (artboardInstance) {
artboardInstance->draw(&m_renderer);
}
}
painter->restore();
}
painter->restore();
}

QTransform matrix4x4ToTransform(const QMatrix4x4 &matrix)
{
return QTransform(matrix(0, 0), matrix(0, 1), matrix(0, 3), matrix(1, 0), matrix(1, 1), matrix(1, 3), matrix(3, 0), matrix(3, 1),
Expand All @@ -33,6 +95,8 @@ QTransform matrix4x4ToTransform(const QMatrix4x4 &matrix)

void RiveQSGSoftwareRenderNode::renderSoftware(const RenderState *state)
{

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (m_artboardInstance.expired()) {
return;
}
Expand All @@ -49,6 +113,7 @@ void RiveQSGSoftwareRenderNode::renderSoftware(const RenderState *state)
auto artboardInstance = m_artboardInstance.lock();

const QRect &boundingRect = state->clipRegion()->boundingRect();

auto x = boundingRect.x();
auto y = boundingRect.y();

Expand All @@ -72,6 +137,14 @@ void RiveQSGSoftwareRenderNode::renderSoftware(const RenderState *state)
m_topLeftRivePosition.setX(offsetX);
m_topLeftRivePosition.setY(offsetY);

// Set the model-view matrix and apply the translation and scale
m_matrix = *state->projectionMatrix();
m_modelViewTransform = matrix4x4ToTransform(m_matrix);
// Apply transformations in the correct order
m_modelViewTransform.translate(x, y);
m_modelViewTransform.translate(offsetX, offsetY);
m_modelViewTransform.scale(scaleFactor, scaleFactor);

QPainter *painter = nullptr;

void *vPainter = renderInterface->getResource(m_window, QSGRendererInterface::Resource::PainterResource);
Expand All @@ -80,27 +153,7 @@ void RiveQSGSoftwareRenderNode::renderSoftware(const RenderState *state)
} else {
return;
}

painter->save();
{
// Set the model-view matrix and apply the translation and scale
QMatrix4x4 matrix = *state->projectionMatrix();
QTransform modelViewTransform = matrix4x4ToTransform(matrix);

// Apply transformations in the correct order
modelViewTransform.translate(x, y);
modelViewTransform.translate(offsetX, offsetY);
modelViewTransform.scale(scaleFactor, scaleFactor);

painter->setTransform(modelViewTransform, false);

m_renderer.setPainter(painter);

painter->save();
{
artboardInstance->draw(&m_renderer);
}
painter->restore();
}
painter->restore();
paint(painter);
#endif
// in qt5 paint will be called by paint method of paintedItem
}
5 changes: 5 additions & 0 deletions src/RiveQtQuickItem/riveqsgsoftwarerendernode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ class RiveQSGSoftwareRenderNode : public RiveQSGRenderNode

void render(const RenderState *state) override;

void paint(QPainter *painter);

private:
void renderSoftware(const RenderState *state);

RiveQtPainterRenderer m_renderer;

QPainter m_fallbackPainter;
QPixmap m_fallbackPixmap;

QMatrix4x4 m_matrix;
QTransform m_modelViewTransform;
};
Loading

0 comments on commit 83442ad

Please sign in to comment.