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

More aggressive RectWithSize usage for local rectangles #1087

Merged
merged 4 commits into from Apr 10, 2017
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

Better use of clamp_rect in pixel shaders

  • Loading branch information
kvark committed Apr 7, 2017
commit 4398725a0250e83604f90a481d300d430405c1e8
@@ -46,10 +46,53 @@ struct RectWithEndpoint {
vec2 p1;
};

RectWithEndpoint to_rect_with_endpoint(RectWithSize rect) {
RectWithEndpoint result;
result.p0 = rect.p0;
result.p1 = rect.p0 + rect.size;

return result;
}

RectWithSize to_rect_with_size(RectWithEndpoint rect) {
RectWithSize result;
result.p0 = rect.p0;
result.size = rect.p1 - rect.p0;

return result;
}

vec2 clamp_rect(vec2 point, RectWithSize rect) {
return clamp(point, rect.p0, rect.p0 + rect.size);
}

vec2 clamp_rect(vec2 point, RectWithEndpoint rect) {
return clamp(point, rect.p0, rect.p1);
}

// Clamp 2 points at once.
vec4 clamp_rect(vec4 points, RectWithSize rect) {
return clamp(points, rect.p0.xyxy, rect.p0.xyxy + rect.size.xyxy);
}

vec4 clamp_rect(vec4 points, RectWithEndpoint rect) {
return clamp(points, rect.p0.xyxy, rect.p1.xyxy);
}

RectWithSize intersect_rect(RectWithSize a, RectWithSize b) {
vec4 p = clamp_rect(vec4(a.p0, a.p0 + a.size), b);
return RectWithSize(p.xy, max(vec2(0.0), p.zw - p.xy));
}

RectWithEndpoint intersect_rect(RectWithEndpoint a, RectWithEndpoint b) {
vec4 p = clamp_rect(vec4(a.p0, a.p1), b);
return RectWithEndpoint(p.xy, max(p.xy, p.zw));
}


flat varying RectWithEndpoint vClipMaskUvBounds;
varying vec3 vClipMaskUv;


#ifdef WR_VERTEX_SHADER

#define VECS_PER_LAYER 13
@@ -98,50 +141,6 @@ ivec2 get_fetch_uv_8(int index) {
return get_fetch_uv(index, 8);
}

RectWithEndpoint to_rect_with_endpoint(RectWithSize rect) {
RectWithEndpoint result;
result.p0 = rect.p0;
result.p1 = rect.p0 + rect.size;

return result;
}

RectWithSize to_rect_with_size(RectWithEndpoint rect) {
RectWithSize result;
result.p0 = rect.p0;
result.size = rect.p1 - rect.p0;

return result;
}

vec2 clamp_rect(vec2 point, RectWithSize rect) {
return clamp(point, rect.p0, rect.p0 + rect.size);
}

vec2 clamp_rect(vec2 point, RectWithEndpoint rect) {
return clamp(point, rect.p0, rect.p1);
}

// Clamp 2 points at once.
vec4 clamp_rect(vec4 points, RectWithSize rect) {
return clamp(points, rect.p0.xyxy, rect.p0.xyxy + rect.size.xyxy);
}

vec4 clamp_rect(vec4 points, RectWithEndpoint rect) {
return clamp(points, rect.p0.xyxy, rect.p1.xyxy);
}

RectWithSize intersect_rect(RectWithSize a, RectWithSize b) {
vec4 p = clamp_rect(vec4(a.p0, a.p0 + a.size), b);
return RectWithSize(p.xy, max(vec2(0.0), p.zw - p.xy));
}

RectWithEndpoint intersect_rect(RectWithEndpoint a, RectWithEndpoint b) {
vec4 p = clamp_rect(vec4(a.p0, a.p1), b);
return RectWithEndpoint(p.xy, max(p.xy, p.zw));
}


struct Layer {
mat4 transform;
mat4 inv_transform;
@@ -8,7 +8,7 @@
flat varying vec4 vVerticalColor; // The vertical color, e.g. top/bottom
flat varying vec4 vHorizontalColor; // The horizontal color e.g. left/right
flat varying vec4 vRadii; // The border radius from CSS border-radius
flat varying RectWithSize vBorderRect; // The rect of the border (x, y, w, h) in local space.
flat varying RectWithSize vBorderRect; // The rect of the border in local space.

// for corners, this is the beginning of the corner.
// For the lines, this is the top left of the line.
@@ -131,8 +131,6 @@ void main(void) {
prim.layer,
prim.task);
vLocalPos = vi.local_pos;

// Local space
vLocalRect = segment_rect;
#else
VertexInfo vi = write_vertex(segment_rect,
@@ -11,8 +11,7 @@ void main(void) {

// 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.p0, vLocalRect.p0 + vLocalRect.size) - vLocalRect.p0;
vec2 relative_pos_in_rect = clamp_rect(pos, vLocalRect) - vLocalRect.p0;
#else
float alpha = 1.0;
vec2 relative_pos_in_rect = vLocalPos;
@@ -10,8 +10,7 @@ void main(void) {

// 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.p0, vLocalRect.p0 + vLocalRect.size) - vLocalRect.p0;
vec2 relative_pos_in_rect = clamp_rect(pos, vLocalRect) - vLocalRect.p0;
#else
float alpha = 1.0;;
vec2 relative_pos_in_rect = vLocalPos;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.