Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back texelFetch from clip surface #3086

Merged
merged 2 commits into from Sep 25, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Snap the clip mask and fix bounds checking

  • Loading branch information
kvark committed Sep 24, 2018
commit e6f6b52561fb24f9b7638716e31ce24e1c2cf982
@@ -91,6 +91,7 @@ void main(void) {
#ifdef WR_FEATURE_ALPHA_PASS
write_clip(
vi.world_pos,
vi.snap_offset,
clip_area
);
#endif
@@ -222,9 +222,9 @@ VertexInfo write_transform_vertex(RectWithSize local_segment_rect,
return vi;
}

void write_clip(vec4 world_pos, ClipArea area) {
void write_clip(vec4 world_pos, vec2 snap_offset, ClipArea area) {
vec2 uv = world_pos.xy * uDevicePixelRatio +
world_pos.w * (area.common_data.task_rect.p0 - area.screen_origin);
world_pos.w * (snap_offset + area.common_data.task_rect.p0 - area.screen_origin);
vClipMaskUvBounds = vec4(
area.common_data.task_rect.p0,
area.common_data.task_rect.p0 + area.common_data.task_rect.size
@@ -243,15 +243,17 @@ float do_clip() {
// anything outside of the mask is considered transparent
//Note: we assume gl_FragCoord.w == interpolated(1 / vClipMaskUv.w)
vec2 mask_uv = vClipMaskUv.xy * gl_FragCoord.w;
bvec4 inside = lessThanEqual(
vec4(vClipMaskUvBounds.xy, mask_uv),
vec4(mask_uv, vClipMaskUvBounds.zw));
bvec2 left = lessThanEqual(vClipMaskUvBounds.xy, mask_uv); // inclusive
bvec2 right = greaterThan(vClipMaskUvBounds.zw, mask_uv); // non-inclusive
// bail out if the pixel is outside the valid bounds
if (!all(inside)) {
if (!all(bvec4(left, right))) {
return 0.0;
}
// finally, the slow path - fetch the mask value from an image
ivec3 tc = ivec3(mask_uv, vClipMaskUv.z);
// Note the Z getting rounded to the nearest integer because the variable
// is still interpolated and becomes a subject of precision-caused
// fluctuations, see https://bugzilla.mozilla.org/show_bug.cgi?id=1491911
ivec3 tc = ivec3(mask_uv, vClipMaskUv.z + 0.5);
return texelFetch(sCacheA8, tc, 0).r;
}

@@ -80,6 +80,7 @@ void main(void) {

write_clip(
world_pos,
vec2(0.0),
clip_area
);

@@ -229,7 +229,7 @@ void main(void) {
vec2 f = (vi.local_pos - glyph_rect.p0) / glyph_rect.size;
#endif

write_clip(vi.world_pos, clip_area);
write_clip(vi.world_pos, vi.snap_offset, clip_area);

switch (color_mode) {
case COLOR_MODE_ALPHA:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.