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

Support basic borders in a 3d transform context. #344

Merged
merged 1 commit into from Aug 17, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Support basic borders in a 3d transform context.

Also remove unused blit shader.
  • Loading branch information
gw3583 committed Aug 15, 2016
commit effc10feb5a01e0975a3629f40464850c8644b52

This file was deleted.

This file was deleted.

@@ -1,7 +1,12 @@
#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/. */

#ifdef WR_FEATURE_TRANSFORM

#else
// draw a circle at position aDesiredPos with a aRadius
vec4 drawCircle(vec2 aPixel, vec2 aDesiredPos, float aRadius, vec3 aColor) {
float farFromCenter = length(aDesiredPos - aPixel) - aRadius;
@@ -77,14 +82,14 @@ vec4 draw_double_edge(float pos, float len) {

vec4 draw_double_edge_vertical() {
// Get our position within this specific segment
float position = vLocalPos.x - vLocalBorders.x;
return draw_double_edge(position, vLocalBorders.z);
float position = vLocalPos.x - vLocalRect.x;
return draw_double_edge(position, vLocalRect.z);
}

vec4 draw_double_edge_horizontal() {
// Get our position within this specific segment
float position = vLocalPos.y - vLocalBorders.y;
return draw_double_edge(position, vLocalBorders.w);
float position = vLocalPos.y - vLocalRect.y;
return draw_double_edge(position, vLocalRect.w);
}

vec4 draw_double_edge_with_radius() {
@@ -220,49 +225,49 @@ void draw_double_border(void) {
}
}
}
#endif

// TODO: Investigate performance of this shader and see
// if it's worthwhile splitting it / removing branches etc.
void main(void) {
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0;
vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
#else
vec2 local_pos = vLocalPos;
#endif

if (vRadii.x > 0.0 &&
(distance(vRefPoint, vLocalPos) > vRadii.x ||
distance(vRefPoint, vLocalPos) < vRadii.z)) {
(distance(vRefPoint, local_pos) > vRadii.x ||
distance(vRefPoint, local_pos) < vRadii.z)) {
discard;
}

switch (vBorderStyle) {
case BORDER_STYLE_DASHED:
{
draw_dashed_border();
break;
}
case BORDER_STYLE_DOTTED:
{
draw_dotted_border();
break;
}
case BORDER_STYLE_OUTSET:
case BORDER_STYLE_INSET:
{
float color = step(0.0, vF);
oFragColor = mix(vVerticalColor, vHorizontalColor, color);
break;
}
case BORDER_STYLE_NONE:
case BORDER_STYLE_SOLID:
{
float color = step(0.0, vF);
oFragColor = mix(vHorizontalColor, vVerticalColor, color);
break;
}
case BORDER_STYLE_DOUBLE:
{
draw_double_border();
break;
#ifdef WR_FEATURE_TRANSFORM
// TODO(gw): Support other border styles for transformed elements.
float f = (local_pos.x - vSizeInfo.x) * vSizeInfo.w - (local_pos.y - vSizeInfo.y) * vSizeInfo.z;
oFragColor = vec4(1, 1, 1, alpha) * mix(vHorizontalColor, vVerticalColor, step(0.0, f));
#else
switch (vBorderStyle) {
case BORDER_STYLE_DASHED:
draw_dashed_border();
break;
case BORDER_STYLE_DOTTED:
draw_dotted_border();
break;
case BORDER_STYLE_OUTSET:
case BORDER_STYLE_INSET:
oFragColor = mix(vVerticalColor, vHorizontalColor, step(0.0, vF));
break;
case BORDER_STYLE_SOLID:
case BORDER_STYLE_NONE:
oFragColor = mix(vHorizontalColor, vVerticalColor, step(0.0, vF));
break;
case BORDER_STYLE_DOUBLE:
draw_double_border();
break;
default:
discard;
}
default:
{
discard;
}
}
#endif
}
@@ -4,22 +4,27 @@
* 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/. */

// These two are interpolated
varying float vF; // This is a weighting as we get closer to the bottom right corner?

// These are not changing.
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

// These are in device space
varying vec2 vLocalPos; // The clamped position in local space.
varying vec2 vDevicePos; // The clamped position in device space.
flat varying vec4 vBorders; // the rect of the border in (x, y, width, height) form
flat varying vec4 vLocalBorders; // The rect of the border (x, y, w, h) in local space.
flat varying vec4 vLocalRect; // The rect of the border (x, y, w, h) in local space.

// for corners, this is the beginning of the corner.
// For the lines, this is the top left of the line.
flat varying vec2 vRefPoint;
flat varying uint vBorderStyle;
flat varying uint vBorderPart; // Which part of the border we're drawing.

// These are in device space
#ifdef WR_FEATURE_TRANSFORM
varying vec3 vLocalPos; // The clamped position in local space.
flat varying vec4 vSizeInfo;
#else
varying vec2 vLocalPos; // The clamped position in local space.

// These two are interpolated
varying float vF; // This is a weighting as we get closer to the bottom right corner?
varying vec2 vDevicePos; // The clamped position in device space.
flat varying vec4 vBorders; // the rect of the border in (x, y, width, height) form
#endif
@@ -34,7 +34,20 @@ uint get_border_style(Border a_border, uint a_edge) {

void main(void) {
Border border = borders[gl_InstanceID];
#ifdef WR_FEATURE_TRANSFORM
TransformVertexInfo vi = write_transform_vertex(border.info);
vLocalPos = vi.local_pos;
#else
VertexInfo vi = write_vertex(border.info);
vLocalPos = vi.local_clamped_pos.xy;
#endif

// This is what was currently sent.
vVerticalColor = border.verticalColor;
vHorizontalColor = border.horizontalColor;

// Local space
vLocalRect = border.info.local_rect;

// Just our boring radius position.
vRadii = border.radii;
@@ -93,22 +106,16 @@ void main(void) {
// x1 - x0 is the width of the corner / line.
float width = x1 - x0;
float height = y1 - y0;
#ifdef WR_FEATURE_TRANSFORM
vSizeInfo = vec4(x0, y0, width, height);
#else
// This is just a weighting of the pixel colors it seems?
vF = (vi.local_clamped_pos.x - x0) * height - (vi.local_clamped_pos.y - y0) * width;

// This is what was currently sent.
vVerticalColor = border.verticalColor;
vHorizontalColor = border.horizontalColor;

// Local space
vLocalPos = vi.local_clamped_pos.xy;

// Local space
vLocalBorders = border.info.local_rect;

// These are in device space
vDevicePos = vi.global_clamped_pos;

// These are in device space
vBorders = border.info.local_rect * uDevicePixelRatio;
#endif
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.