Skip to content

Commit 8adde09

Browse files
Lubrsigmta
authored andcommitted
LibWeb/WebGL: Respect UNPACK_PREMULTIPLY_ALPHA
Fixes splats on https://superspl.at having dark splotches, as they expect textures with unpremultiplied alpha.
1 parent 8f666c6 commit 8adde09

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,6 +2992,8 @@ JS::Value WebGL2RenderingContextImpl::get_parameter(WebIDL::UnsignedLong pname)
29922992
}
29932993
case UNPACK_FLIP_Y_WEBGL:
29942994
return JS::Value(m_unpack_flip_y);
2995+
case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
2996+
return JS::Value(m_unpack_premultiply_alpha);
29952997
case MAX_CLIENT_WAIT_TIMEOUT_WEBGL: {
29962998
// FIXME: Make this an actual limit
29972999
return JS::js_infinity();
@@ -3398,6 +3400,9 @@ void WebGL2RenderingContextImpl::pixel_storei(WebIDL::UnsignedLong pname, WebIDL
33983400
case UNPACK_FLIP_Y_WEBGL:
33993401
m_unpack_flip_y = param != GL_FALSE;
34003402
return;
3403+
case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
3404+
m_unpack_premultiply_alpha = param != GL_FALSE;
3405+
return;
34013406
}
34023407

34033408
glPixelStorei(pname, param);

Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,10 @@ Optional<WebGLRenderingContextBase::ConvertedTexture> WebGLRenderingContextBase:
166166
auto buffer = MUST(ByteBuffer::create_zeroed(buffer_pitch.value() * height));
167167

168168
if (width > 0 && height > 0) {
169-
// FIXME: Respect UNPACK_PREMULTIPLY_ALPHA_WEBGL
170169
// FIXME: Respect unpackColorSpace
171170
auto skia_format = opengl_format_and_type_to_skia_color_type(format, type);
172171
auto color_space = SkColorSpace::MakeSRGB();
173-
auto image_info = SkImageInfo::Make(width, height, skia_format, SkAlphaType::kPremul_SkAlphaType, color_space);
172+
auto image_info = SkImageInfo::Make(width, height, skia_format, m_unpack_premultiply_alpha ? SkAlphaType::kPremul_SkAlphaType : SkAlphaType::kUnpremul_SkAlphaType, color_space);
174173
auto surface = SkSurfaces::WrapPixels(image_info, buffer.data(), buffer_pitch.value());
175174
VERIFY(surface);
176175
auto surface_canvas = surface->getCanvas();

Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Web::WebGL {
1616

1717
static constexpr int COMPRESSED_TEXTURE_FORMATS = 0x86A3;
1818
static constexpr int UNPACK_FLIP_Y_WEBGL = 0x9240;
19+
static constexpr int UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
1920
static constexpr int MAX_CLIENT_WAIT_TIMEOUT_WEBGL = 0x9247;
2021

2122
// NOTE: This is the Variant created by the IDL wrapper generator, and needs to be updated accordingly.
@@ -121,6 +122,12 @@ class WebGLRenderingContextBase {
121122
// the vertical axis, so that conceptually the last row is the first one transferred. The initial value is false.
122123
// Any non-zero value is interpreted as true.
123124
bool m_unpack_flip_y { false };
125+
126+
// UNPACK_PREMULTIPLY_ALPHA_WEBGL of type boolean
127+
// If set, then during any subsequent calls to texImage2D or texSubImage2D, the alpha channel of the source data,
128+
// if present, is multiplied into the color channels during the data transfer. The initial value is false.
129+
// Any non-zero value is interpreted as true.
130+
bool m_unpack_premultiply_alpha { false };
124131
};
125132

126133
}

Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,8 @@ JS::Value WebGLRenderingContextImpl::get_parameter(WebIDL::UnsignedLong pname)
15091509
}
15101510
case UNPACK_FLIP_Y_WEBGL:
15111511
return JS::Value(m_unpack_flip_y);
1512+
case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
1513+
return JS::Value(m_unpack_premultiply_alpha);
15121514
default:
15131515
dbgln("Unknown WebGL parameter name: {:x}", pname);
15141516
set_error(GL_INVALID_ENUM);
@@ -1907,6 +1909,9 @@ void WebGLRenderingContextImpl::pixel_storei(WebIDL::UnsignedLong pname, WebIDL:
19071909
case UNPACK_FLIP_Y_WEBGL:
19081910
m_unpack_flip_y = param != GL_FALSE;
19091911
return;
1912+
case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
1913+
m_unpack_premultiply_alpha = param != GL_FALSE;
1914+
return;
19101915
}
19111916

19121917
glPixelStorei(pname, param);

0 commit comments

Comments
 (0)