-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WR - create a new ImageRect shader for external image TextureRectHandle.
MozReview-Commit-ID: 53J6D4CriYC
- Loading branch information
Showing
6 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#line 1 | ||
|
||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
void main(void) { | ||
#ifdef WR_FEATURE_TRANSFORM | ||
float alpha = 0.0; | ||
vec2 pos = init_transform_fs(vLocalPos, vLocalRect, alpha); | ||
|
||
// We clamp the texture coordinate calculation here to the local rectangle boundaries, | ||
// which makes the edge of the texture stretch instead of repeat. | ||
vec2 relative_pos_in_rect = | ||
clamp(pos, vLocalRect.xy, vLocalRect.xy + vLocalRect.zw) - vLocalRect.xy; | ||
#else | ||
float alpha = 1.0; | ||
vec2 relative_pos_in_rect = vLocalPos; | ||
#endif | ||
|
||
alpha = min(alpha, do_clip()); | ||
|
||
// We calculate the particular tile this fragment belongs to, taking into | ||
// account the spacing in between tiles. We only paint if our fragment does | ||
// not fall into that spacing. | ||
vec2 position_in_tile = mod(relative_pos_in_rect, vStretchSize + vTileSpacing); | ||
// We clamp the texture coordinates to the half-pixel offset from the borders | ||
// in order to avoid sampling outside of the texture area. | ||
vec2 st = vTextureOffset + ((position_in_tile / vStretchSize) * vTextureSize); | ||
st = clamp(st, vStRect.xy, vStRect.zw); | ||
|
||
alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize)))); | ||
|
||
oFragColor = vec4(alpha) * texture(sColor0, st); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
flat varying vec2 vTextureOffset; // Offset of this image into the texture atlas. | ||
flat varying vec2 vTextureSize; // Size of the image in the texture atlas. | ||
flat varying vec2 vTileSpacing; // Amount of space between tiled instances of this image. | ||
flat varying vec4 vStRect; // Rectangle of valid texture rect, in st-space. | ||
|
||
#ifdef WR_FEATURE_TRANSFORM | ||
varying vec3 vLocalPos; | ||
flat varying vec4 vLocalRect; | ||
flat varying vec2 vStretchSize; | ||
#else | ||
varying vec2 vLocalPos; | ||
flat varying vec2 vStretchSize; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#line 1 | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
void main(void) { | ||
Primitive prim = load_primitive(); | ||
Image image = fetch_image(prim.prim_index); | ||
ResourceRect res = fetch_resource_rect(prim.user_data.x); | ||
|
||
#ifdef WR_FEATURE_TRANSFORM | ||
TransformVertexInfo vi = write_transform_vertex(prim.local_rect, | ||
prim.local_clip_rect, | ||
prim.z, | ||
prim.layer, | ||
prim.task); | ||
vLocalRect = vi.clipped_local_rect; | ||
vLocalPos = vi.local_pos; | ||
#else | ||
VertexInfo vi = write_vertex(prim.local_rect, | ||
prim.local_clip_rect, | ||
prim.z, | ||
prim.layer, | ||
prim.task); | ||
vLocalPos = vi.local_pos - vi.local_rect.p0; | ||
#endif | ||
|
||
write_clip(vi.screen_pos, prim.clip_area); | ||
|
||
vec2 st0 = res.uv_rect.xy; | ||
vec2 st1 = res.uv_rect.zw; | ||
|
||
vTextureSize = st1 - st0; | ||
vTextureOffset = st0; | ||
vTileSpacing = image.stretch_size_and_tile_spacing.zw; | ||
vStretchSize = image.stretch_size_and_tile_spacing.xy; | ||
|
||
vStRect = vec4(min(st0, st1), max(st0, st1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters