Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/plugins/score-plugin-gfx/Gfx/Graph/ImageNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class ImagesNode::PreloadedRenderer : public GenericNodeRenderer
if(m_textures.size() <= i)
{
QRhiTexture* tex = tex
= rhi.newTexture(QRhiTexture::BGRA8, tex_size, 1, QRhiTexture::Flag{});
= rhi.newTexture(imageTextureFormat(rhi), tex_size, 1, QRhiTexture::Flag{});
tex->setName("ImagesNode::tex");
tex->create();
m_textures.push_back(tex);
Expand Down Expand Up @@ -702,7 +702,7 @@ class ImagesNode::OnTheFlyRenderer : public GenericNodeRenderer
maxSize.setHeight(std::max(maxSize.height(), sz.height()));
}

auto tex = rhi.newTexture(QRhiTexture::BGRA8, maxSize, 1, QRhiTexture::Flag{});
auto tex = rhi.newTexture(imageTextureFormat(rhi), maxSize, 1, QRhiTexture::Flag{});

tex->setName("OnTheFlyRenderer::tex");
tex->create();
Expand Down Expand Up @@ -945,7 +945,7 @@ class FullScreenImageNode::Renderer : public GenericNodeRenderer
// Create GPU textures for the image
const QSize sz = n.m_image.size();
auto tex = rhi.newTexture(
QRhiTexture::BGRA8, QSize{sz.width(), sz.height()}, 1, QRhiTexture::Flag{});
imageTextureFormat(rhi), QSize{sz.width(), sz.height()}, 1, QRhiTexture::Flag{});

tex->setName("FullScreenImageNode::tex");
tex->create();
Expand Down
25 changes: 24 additions & 1 deletion src/plugins/score-plugin-gfx/Gfx/Graph/RenderList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,33 @@ BufferView RenderList::bufferForOutput(const Edge& edge) const noexcept
return {};
}

QRhiTexture::Format imageTextureFormat(const QRhi& rhi) noexcept
{
return rhi.isTextureFormatSupported(QRhiTexture::BGRA8) ? QRhiTexture::BGRA8
: QRhiTexture::RGBA8;
}

QImage adaptImageFormat(QImage img, QRhiTexture::Format fmt)
{
const bool premultiplied = img.format() == QImage::Format_ARGB32_Premultiplied
|| img.format() == QImage::Format_RGBA8888_Premultiplied;

QImage::Format wanted{};
if(fmt == QRhiTexture::BGRA8)
wanted = premultiplied ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32;
else
wanted = premultiplied ? QImage::Format_RGBA8888_Premultiplied
: QImage::Format_RGBA8888;

if(img.format() != wanted)
img.convertTo(wanted);
return img;
}

QImage RenderList::adaptImage(const QImage& frame)
{
auto res = resizeTexture(frame, m_minTexSize, m_maxTexSize);
return res;
return adaptImageFormat(std::move(res), imageTextureFormat(*state.rhi));
//if(m_flip)
// res = std::move(res).mirrored();
//return res;
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/score-plugin-gfx/Gfx/Graph/RenderList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,23 @@ class SCORE_PLUGIN_GFX_EXPORT RenderList
bool m_ready{};
bool m_built{};
};

/**
* @brief Texture format to use for images uploaded from the CPU
*
* BGRA8 where the backend has it, RGBA8 otherwise. QRhiGles2 asks for
* GL_BGRA whenever a texture is BGRA8, and WebGL has no such format at all,
* so uploading one there is an INVALID_ENUM and the image never appears.
*/
SCORE_PLUGIN_GFX_EXPORT
QRhiTexture::Format imageTextureFormat(const QRhi& rhi) noexcept;

/**
* @brief Put an image in the byte order imageTextureFormat() asks for
*
* QRhi uploads a QImage's bits as-is, so the two have to agree.
* Premultiplication is preserved: only the channel order changes.
*/
SCORE_PLUGIN_GFX_EXPORT
QImage adaptImageFormat(QImage img, QRhiTexture::Format fmt);
}
6 changes: 4 additions & 2 deletions src/plugins/score-plugin-gfx/Gfx/Graph/TextNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class TextNode::Renderer : public GenericNodeRenderer
QRhi& rhi = *renderer.state.rhi;

{
auto tex = rhi.newTexture(QRhiTexture::BGRA8, sz, 1, QRhiTexture::Flag{});
auto tex = rhi.newTexture(imageTextureFormat(rhi), sz, 1, QRhiTexture::Flag{});

tex->setName("TextNode::tex");
tex->create();
Expand Down Expand Up @@ -167,7 +167,9 @@ class TextNode::Renderer : public GenericNodeRenderer

if(!m_uploaded)
{
res.uploadTexture(m_textures[0].second, m_img);
res.uploadTexture(
m_textures[0].second,
adaptImageFormat(m_img, imageTextureFormat(*renderer.state.rhi)));

m_uploaded = true;
}
Expand Down
Loading