Skip to content
This repository has been archived by the owner. It is now read-only.

8242920: Gradient Paint doesn't work with metal #82

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -54,6 +54,7 @@ struct GradFrameUniforms {
vector_float3 params;
vector_float4 color1;
vector_float4 color2;
int isCyclic;
};

struct Vertex {
@@ -206,6 +206,14 @@ fragment half4 frag_txt_grad(GradShaderInOut in [[stage_in]],

float3 v = float3(in.position.x, in.position.y, 1);
float a = (dot(v,uniforms.params)-0.25)*2.0;
int fa = floor(a);
if (uniforms.isCyclic) {
if (fa%2) {
a = 1.0 + fa - a;
} else {
a = a - fa;
}
}
float4 c = mix(uniforms.color1, uniforms.color2, a);
return half4(c.r*renderColor.a,
c.g*renderColor.a,
@@ -352,6 +360,14 @@ fragment half4 frag_grad(GradShaderInOut in [[stage_in]],
constant GradFrameUniforms& uniforms [[buffer(0)]]) {
float3 v = float3(in.position.x, in.position.y, 1);
float a = (dot(v,uniforms.params)-0.25)*2.0;
int fa = floor(a);
if (uniforms.isCyclic) {
if (fa%2) {
a = 1.0 + fa - a;
} else {
a = a - fa;
}
}
float4 c = mix(uniforms.color1, uniforms.color2, a);
return half4(c);
}
@@ -420,7 +420,8 @@ - (void)setPipelineState:(id<MTLRenderCommandEncoder>)encoder
struct GradFrameUniforms uf = {
{_p0, _p1, _p3},
RGBA_TO_V4(_pixel1),
RGBA_TO_V4(_pixel2)};
RGBA_TO_V4(_pixel2),
_cyclic};
[encoder setFragmentBytes:&uf length:sizeof(uf) atIndex:0];

} else {
@@ -451,7 +452,9 @@ - (void)setPipelineState:(id<MTLRenderCommandEncoder>)encoder
struct GradFrameUniforms uf = {
{_p0, _p1, _p3},
RGBA_TO_V4(_pixel1),
RGBA_TO_V4(_pixel2)};
RGBA_TO_V4(_pixel2),
_cyclic
};
[encoder setFragmentBytes:&uf length:sizeof(uf) atIndex:0];
} else if (_paintState == sun_java2d_SunGraphics2D_PAINT_TEXTURE) {
vertShader = @"vert_tp";
@@ -525,7 +528,9 @@ - (void)setXorModePipelineState:(id<MTLRenderCommandEncoder>)encoder
struct GradFrameUniforms uf = {
{_p0, _p1, _p3},
RGBA_TO_V4(_pixel1 ^ xorColor),
RGBA_TO_V4(_pixel2 ^ xorColor)};
RGBA_TO_V4(_pixel2 ^ xorColor),
_cyclic
};

[encoder setFragmentBytes: &uf length:sizeof(uf) atIndex:0];
BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();