Skip to content

Commit

Permalink
Revert "Add Multisampling Support. This drops support for older GL ES…
Browse files Browse the repository at this point in the history
… Versions. The plugin now also respects Device Pixel Ratio."

This reverts commit 82996e6.
  • Loading branch information
BertholdKrevert committed Mar 8, 2024
1 parent 925011b commit e978abe
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 215 deletions.
1 change: 0 additions & 1 deletion src/RiveQtQuickItem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ include_directories(${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS})
if (${QT_VERSION_MAJOR} EQUAL 6)
find_package(Qt6 COMPONENTS ShaderTools)
qt6_add_shaders(${PROJECT_NAME} "graph-shaders"
GLSL "300es,330"
BATCHABLE
PRECOMPILE
OPTIMIZED
Expand Down
21 changes: 18 additions & 3 deletions src/RiveQtQuickItem/renderer/riveqtfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,24 @@ RiveQSGRenderNode *RiveQtFactory::renderNode(QQuickWindow *window, std::weak_ptr
}
}

rive::rcp<rive::RenderBuffer> RiveQtFactory::makeRenderBuffer(rive::RenderBufferType renderBufferType,
rive::RenderBufferFlags renderBufferFlags, size_t size)
rive::rcp<rive::RenderBuffer> RiveQtFactory::makeBufferU16(rive::Span<const uint16_t> data)
{
return rive::make_rcp<rive::DataRenderBuffer>(renderBufferType, renderBufferFlags, size);
return nullptr;
}

rive::rcp<rive::RenderBuffer> RiveQtFactory::makeBufferU32(rive::Span<const uint32_t> data)
{
return nullptr;
}

rive::rcp<rive::RenderBuffer> RiveQtFactory::makeBufferF32(rive::Span<const float> data)
{
return nullptr;
}

rive::rcp<rive::RenderBuffer> RiveQtFactory::makeRenderBuffer(rive::RenderBufferType renderBufferType, rive::RenderBufferFlags renderBufferFlags, size_t size)
{
return rive::make_rcp<rive::DataRenderBuffer>(renderBufferType, renderBufferFlags, size);;
}

rive::rcp<rive::RenderShader> RiveQtFactory::makeLinearGradient(float x1, float y1, float x2, float y2, const rive::ColorInt *colors,
Expand Down Expand Up @@ -146,6 +160,7 @@ rive::rcp<rive::Font> RiveQtFactory::decodeFont(rive::Span<const uint8_t> span)
QFont font(fontFamilies.first());
return rive::rcp<RiveQtFont>(new RiveQtFont(font));*/

}

unsigned int RiveQtFactory::levelOfDetail()
Expand Down
6 changes: 5 additions & 1 deletion src/RiveQtQuickItem/renderer/riveqtfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <utils/factory_utils.hpp>

#ifdef WITH_RIVE_TEXT
# include <rive/text/font_hb.hpp>
#include <rive/text/font_hb.hpp>
#endif

#include "datatypes.h"
Expand Down Expand Up @@ -44,6 +44,10 @@ class RiveQtFactory : public rive::Factory

RiveQSGRenderNode *renderNode(QQuickWindow *window, std::weak_ptr<rive::ArtboardInstance> artboardInstance, const QRectF &geometry);

rive::rcp<rive::RenderBuffer> makeBufferU16(rive::Span<const uint16_t> data);
rive::rcp<rive::RenderBuffer> makeBufferU32(rive::Span<const uint32_t> data);
rive::rcp<rive::RenderBuffer> makeBufferF32(rive::Span<const float> data);

rive::rcp<rive::RenderBuffer> makeRenderBuffer(rive::RenderBufferType, rive::RenderBufferFlags, size_t) override;

rive::rcp<rive::RenderShader> makeLinearGradient(float, float, float, float, const rive::ColorInt[], const float[], size_t) override;
Expand Down
38 changes: 18 additions & 20 deletions src/RiveQtQuickItem/renderer/riveqtrhirenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,28 @@ void RiveQtRhiRenderer::drawPath(rive::RenderPath *path, rive::RenderPaint *pain
}

RiveQtPath clipResult;
if (!m_rhiRenderStack.back().m_allClipPainterPathesApplied.empty()) {
QPair<QPainterPath, QMatrix4x4> firstLevel = m_rhiRenderStack.back().m_allClipPainterPathesApplied.first();

clipResult.setQPainterPath(firstLevel.first);
clipResult.applyMatrix(firstLevel.second);

for (int i = 1; i < m_rhiRenderStack.back().m_allClipPainterPathesApplied.count(); ++i) {
RiveQtPath a;
const auto &entry = m_rhiRenderStack.back().m_allClipPainterPathesApplied[i];
a.setQPainterPath(entry.first);
a.applyMatrix(entry.second);
clipResult.intersectWith(a.toQPainterPath());
}
QPair<QPainterPath, QMatrix4x4> firstLevel = m_rhiRenderStack.back().m_allClipPainterPathesApplied.first();

// #if 0 // this allows to draw the clipping area which it useful for debugging :)
// TextureTargetNode *drawClipping = getRiveDrawTargetNode();
// drawClipping->setOpacity(currentOpacity()); // inherit the opacity from the parent
// drawClipping->setColor(QColor(255, 0, 0, 29));
// drawClipping->updateGeometry(clipResult.toVertices(), QMatrix4x4());
// #endif
clipResult.setQPainterPath(firstLevel.first);
clipResult.applyMatrix(firstLevel.second);

node->updateClippingGeometry(clipResult.toVertices());
for (int i = 1; i < m_rhiRenderStack.back().m_allClipPainterPathesApplied.count(); ++i) {
RiveQtPath a;
const auto &entry = m_rhiRenderStack.back().m_allClipPainterPathesApplied[i];
a.setQPainterPath(entry.first);
a.applyMatrix(entry.second);
clipResult.intersectWith(a.toQPainterPath());
}

// #if 0 // this allows to draw the clipping area which it useful for debugging :)
// TextureTargetNode *drawClipping = getRiveDrawTargetNode();
// drawClipping->setOpacity(currentOpacity()); // inherit the opacity from the parent
// drawClipping->setColor(QColor(255, 0, 0, 29));
// drawClipping->updateGeometry(clipResult.toVertices(), QMatrix4x4());
// #endif

node->updateClippingGeometry(clipResult.toVertices());

node->updateGeometry(pathData, transformMatrix());
}

Expand Down
28 changes: 11 additions & 17 deletions src/RiveQtQuickItem/rhi/postprocessingsmaa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ static float vertexData[] = { // Y up, CCW

static quint16 indexData[] = { 0, 1, 2, 0, 2, 3 };

// resolution (2 * 4) + flip (4) + sampleCount(4)
const int UBUFSIZE = 16;
// resolution (2 * 4) + flip (4)
const int UBUFSIZE = 12;

QShader getShader(const QString &name)
{
Expand Down Expand Up @@ -105,11 +105,10 @@ QByteArray PostprocessingSMAA::loadSearchTextureAsR8Array()
}

// void PostprocessingSMAA::initializePostprocessingPipeline(QRhi* rhi, const QSizeF &size, std::weak_ptr<QRhiTexture> frameTexture)
void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, int samples, const QSize &size,
void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, const QSize &size,
QRhiTexture *frameTextureA, QRhiTexture *frameTextureB)
{

m_samples = samples;
// maybe cleanup (check in method)
m_targetSize = size;
QRhiResourceUpdateBatch *resourceUpdates = rhi->nextResourceUpdateBatch();
Expand Down Expand Up @@ -143,7 +142,7 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand

if (!m_edgesPass.edgesTexture) {
// Target for edges
m_edgesPass.edgesTexture = rhi->newTexture(QRhiTexture::RGBA8, size, m_samples, QRhiTexture::RenderTarget);
m_edgesPass.edgesTexture = rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget);
m_releasePool << m_edgesPass.edgesTexture;
m_edgesPass.edgesTexture->create();
}
Expand Down Expand Up @@ -203,13 +202,12 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand
m_edgesPass.edgesPipeline->setVertexInputLayout(quadInputLayout);
m_edgesPass.edgesPipeline->setShaderResourceBindings(m_edgesPass.edgesResourceBindingsA);
m_edgesPass.edgesPipeline->setRenderPassDescriptor(m_edgesPass.edgesRenderPassDescriptor);
m_edgesPass.edgesPipeline->setSampleCount(m_samples);
m_edgesPass.edgesPipeline->create();
}

if (!m_weightsPass.weightsTexture) {
// Target for weights
m_weightsPass.weightsTexture = rhi->newTexture(QRhiTexture::RGBA8, size, m_samples, QRhiTexture::RenderTarget);
m_weightsPass.weightsTexture = rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget);
m_releasePool << m_weightsPass.weightsTexture;
m_weightsPass.weightsTexture->create();
}
Expand All @@ -224,13 +222,13 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand
if (!m_lookup.areaTexture) {
// load Search and Area textures for weight processing (second pass)
// Qt doesnt support RG8 16 bit format, so just vonvert it to RGBA8 for now
m_lookup.areaTexture = rhi->newTexture(QRhiTexture::RGBA8, QSize(AREATEX_WIDTH, AREATEX_HEIGHT), m_samples);
m_lookup.areaTexture = rhi->newTexture(QRhiTexture::RGBA8, QSize(AREATEX_WIDTH, AREATEX_HEIGHT));
m_releasePool << m_lookup.areaTexture;
m_lookup.areaTexture->create();

if (!m_lookup.areaSampler) {
m_lookup.areaSampler = rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge,
QRhiSampler::ClampToEdge);
QRhiSampler::ClampToEdge);
m_releasePool << m_lookup.areaSampler;
m_lookup.areaSampler->create();
}
Expand All @@ -245,13 +243,13 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand
}

if (!m_lookup.searchTexture) {
m_lookup.searchTexture = rhi->newTexture(QRhiTexture::R8, QSize(SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT), m_samples);
m_lookup.searchTexture = rhi->newTexture(QRhiTexture::R8, QSize(SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT));
m_releasePool << m_lookup.searchTexture;
m_lookup.searchTexture->create();

if (!m_lookup.searchSampler) {
m_lookup.searchSampler = rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge,
QRhiSampler::ClampToEdge);
m_lookup.searchSampler =
rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
m_releasePool << m_lookup.searchSampler;
m_lookup.searchSampler->create();
}
Expand Down Expand Up @@ -302,13 +300,12 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand
m_weightsPass.weightsPipeline->setVertexInputLayout(quadInputLayout);
m_weightsPass.weightsPipeline->setShaderResourceBindings(m_weightsPass.weightsResourceBindings);
m_weightsPass.weightsPipeline->setRenderPassDescriptor(m_weightsPass.weightsRenderPassDescriptor);
m_weightsPass.weightsPipeline->setSampleCount(m_samples);
m_weightsPass.weightsPipeline->create();
}

if (!m_blendPass.blendTexture) {
// Target for blending pass
m_blendPass.blendTexture = rhi->newTexture(QRhiTexture::RGBA8, size, m_samples, QRhiTexture::RenderTarget);
m_blendPass.blendTexture = rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget);
m_releasePool << m_blendPass.blendTexture;
m_blendPass.blendTexture->create();
}
Expand Down Expand Up @@ -362,7 +359,6 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand
m_blendPass.blendPipeline->setVertexInputLayout(quadInputLayout);
m_blendPass.blendPipeline->setShaderResourceBindings(m_blendPass.blendResourceBindingsA);
m_blendPass.blendPipeline->setRenderPassDescriptor(m_blendPass.blendRenderPassDescriptor);
m_blendPass.blendPipeline->setSampleCount(m_samples);
m_blendPass.blendPipeline->create();
}
// set resolution
Expand All @@ -376,8 +372,6 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand
flip = 1;
}
resourceUpdates->updateDynamicBuffer(m_common.quadUbuffer, 8, 4, &flip);
int sampleCount = m_samples;
resourceUpdates->updateDynamicBuffer(m_common.quadUbuffer, 12, 4, &sampleCount);

commandBuffer->resourceUpdate(resourceUpdates);
m_postprocessingRenderTexture = m_blendPass.blendTexture;
Expand Down
6 changes: 2 additions & 4 deletions src/RiveQtQuickItem/rhi/postprocessingsmaa.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class PostprocessingSMAA
bool isInitialized() const { return m_isInitialized; }

// void initializePostprocessingPipeline(QRhi *rhi, const QSizeF &size, std::weak_ptr<QRhiTexture> frameTexture);
void initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, int samples, const QSize &size,
QRhiTexture *frameTextureA, QRhiTexture *frameTextureB);
void initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, const QSize &size, QRhiTexture *frameTextureA,
QRhiTexture *frameTextureB);
void postprocess(QRhi *rhi, QRhiCommandBuffer *commandBuffer, bool useTextureBufferA);
void cleanup();

Expand Down Expand Up @@ -105,6 +105,4 @@ class PostprocessingSMAA
QRhiTexture *m_postprocessingRenderTexture { nullptr };

QSGRendererInterface::GraphicsApi m_api;

int m_samples { 4 };
};
17 changes: 10 additions & 7 deletions src/RiveQtQuickItem/rhi/texturetargetnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,9 @@ void TextureTargetNode::renderBlend(QRhiCommandBuffer *cb)
QMatrix4x4 mvp = (*m_projectionMatrix);
mvp.translate(-m_rect.x(), -m_rect.y());
int flipped = rhi->isYUpInFramebuffer() ? 1 : 0;
int sampleCount = m_node->currentBlendTarget()->sampleCount();
m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 0, 64, mvp.constData());
m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 64, 4, &m_blendMode);
m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 68, 4, &flipped);
m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 72, 4, &sampleCount);

auto *currentDisplayBufferTarget = m_node->currentBlendTarget();
auto *blendPipeline = m_node->currentBlendPipeline();
Expand Down Expand Up @@ -530,10 +528,15 @@ void TextureTargetNode::setGradient(const QGradient *gradient)
}
}

void TextureTargetNode::setTexture(const QImage &image, rive::rcp<rive::RenderBuffer> vertices, rive::rcp<rive::RenderBuffer> uvCoords,
rive::rcp<rive::RenderBuffer> indices, uint32_t vertexCount, uint32_t indexCount, bool recreate,
const QMatrix4x4 &transform)
void TextureTargetNode::setTexture(const QImage &image,
rive::rcp<rive::RenderBuffer> vertices,
rive::rcp<rive::RenderBuffer> uvCoords,
rive::rcp<rive::RenderBuffer> indices,
uint32_t vertexCount, uint32_t indexCount,
bool recreate,
const QMatrix4x4 &transform)
{

if (m_texture.size() != image.size()) {
if (m_sampler) {
m_cleanupList.removeAll(m_sampler);
Expand Down Expand Up @@ -641,8 +644,8 @@ void TextureTargetNode::setTexture(const QImage &image, rive::rcp<rive::RenderBu
assert(indices->sizeInBytes() == indexCount * sizeof(uint16_t));

auto *vertexData = rive::DataRenderBuffer::Cast(vertices.get())->f32s();
auto *uvData = rive::DataRenderBuffer::Cast(uvCoords.get())->f32s();
auto *indexData = rive::DataRenderBuffer::Cast(indices.get())->u16s();
auto *uvData = rive::DataRenderBuffer::Cast(uvCoords.get())->f32s();
auto *indexData = rive::DataRenderBuffer::Cast(indices.get())->u16s();

m_geometryData.resize(vertices->sizeInBytes());
memcpy(m_geometryData.data(), vertexData, vertices->sizeInBytes());
Expand Down
Loading

0 comments on commit e978abe

Please sign in to comment.