mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-12 15:34:22 +00:00
Add support for textures color space formats
[Issues 1479: pictures](https://github.com/thorvg/thorvg/issues/1479) Formats supported: ABGR8888 ARGB8888 ABGR8888S ARGB8888S
This commit is contained in:
parent
cf8cba8f7b
commit
51e98eebdb
4 changed files with 25 additions and 7 deletions
|
@ -27,11 +27,12 @@
|
||||||
// WgPipelineDataImage
|
// WgPipelineDataImage
|
||||||
//************************************************************************
|
//************************************************************************
|
||||||
|
|
||||||
|
void WgPipelineDataImage::updateFormat(const ColorSpace format) {
|
||||||
|
uColorInfo.format = (uint32_t)format;
|
||||||
|
}
|
||||||
|
|
||||||
void WgPipelineDataImage::updateOpacity(const uint8_t opacity) {
|
void WgPipelineDataImage::updateOpacity(const uint8_t opacity) {
|
||||||
uColorInfo.color[0] = 1.0f; // red
|
uColorInfo.opacity = opacity / 255.0f; // alpha
|
||||||
uColorInfo.color[1] = 1.0f; // green
|
|
||||||
uColorInfo.color[2] = 1.0f; // blue
|
|
||||||
uColorInfo.color[3] = opacity / 255.0f; // alpha
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//************************************************************************
|
//************************************************************************
|
||||||
|
|
|
@ -28,12 +28,16 @@
|
||||||
class WgPipelineImage;
|
class WgPipelineImage;
|
||||||
|
|
||||||
struct WgPipelineImageColorInfo {
|
struct WgPipelineImageColorInfo {
|
||||||
float color[4]{};
|
uint32_t format{};
|
||||||
|
float dummy0{};
|
||||||
|
float dummy1{};
|
||||||
|
float opacity{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WgPipelineDataImage: WgPipelineData {
|
struct WgPipelineDataImage: WgPipelineData {
|
||||||
WgPipelineImageColorInfo uColorInfo{}; // @binding(1)
|
WgPipelineImageColorInfo uColorInfo{}; // @binding(1)
|
||||||
|
|
||||||
|
void updateFormat(const ColorSpace format);
|
||||||
void updateOpacity(const uint8_t opacity);
|
void updateOpacity(const uint8_t opacity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,7 @@ RenderData WgRenderer::prepare(Surface* surface, const RenderMesh* mesh, RenderD
|
||||||
if (flags & (RenderUpdateFlag::Color | RenderUpdateFlag::Image | RenderUpdateFlag::Transform)) {
|
if (flags & (RenderUpdateFlag::Color | RenderUpdateFlag::Image | RenderUpdateFlag::Transform)) {
|
||||||
WgPipelineDataImage pipelineDataImage{};
|
WgPipelineDataImage pipelineDataImage{};
|
||||||
pipelineDataImage.updateMatrix(mViewMatrix, transform);
|
pipelineDataImage.updateMatrix(mViewMatrix, transform);
|
||||||
|
pipelineDataImage.updateFormat(surface->cs);
|
||||||
pipelineDataImage.updateOpacity(opacity);
|
pipelineDataImage.updateOpacity(opacity);
|
||||||
renderDataShape->mPipelineBindGroupImage.update(mQueue, pipelineDataImage, surface);
|
renderDataShape->mPipelineBindGroupImage.update(mQueue, pipelineDataImage, surface);
|
||||||
renderDataShape->tesselate(mDevice, mQueue, surface, mesh);
|
renderDataShape->tesselate(mDevice, mQueue, surface, mesh);
|
||||||
|
|
|
@ -281,7 +281,10 @@ struct Matrix {
|
||||||
|
|
||||||
// ColorInfo
|
// ColorInfo
|
||||||
struct ColorInfo {
|
struct ColorInfo {
|
||||||
color: vec4f
|
format: u32,
|
||||||
|
dummy0: f32,
|
||||||
|
dummy1: f32,
|
||||||
|
opacity: f32
|
||||||
};
|
};
|
||||||
|
|
||||||
// vertex output
|
// vertex output
|
||||||
|
@ -312,5 +315,14 @@ fn vs_main(in: VertexInput) -> VertexOutput {
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_main(in: VertexOutput) -> @location(0) vec4f {
|
fn fs_main(in: VertexOutput) -> @location(0) vec4f {
|
||||||
var color: vec4f = textureSample(uTextureViewBase, uSamplerBase, in.texCoords.xy);
|
var color: vec4f = textureSample(uTextureViewBase, uSamplerBase, in.texCoords.xy);
|
||||||
return vec4f(color.rgb, color.a * uColorInfo.color.a);
|
var result: vec4f = color;
|
||||||
|
var format: u32 = uColorInfo.format;
|
||||||
|
if (format == 1u) { /* FMT_ARGB8888 */
|
||||||
|
result = color.bgra;
|
||||||
|
} else if (format == 2u) { /* FMT_ABGR8888S */
|
||||||
|
result = vec4(color.rgb * color.a, color.a);
|
||||||
|
} else if (format == 3u) { /* FMT_ARGB8888S */
|
||||||
|
result = vec4(color.bgr * color.a, color.a);
|
||||||
|
}
|
||||||
|
return vec4f(result.rgb, result.a * uColorInfo.opacity);
|
||||||
})";
|
})";
|
||||||
|
|
Loading…
Add table
Reference in a new issue