Skip to content

Commit 53886db

Browse files
committed
Put solid color generator overloads back, improve performance
1 parent 9039aa7 commit 53886db

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

framework/Source/GPUImageSolidColorGenerator.m

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,30 @@
44
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING
55
(
66
precision lowp float;
7-
8-
varying highp vec2 textureCoordinate;
7+
8+
varying highp vec2 textureCoordinate;
99
uniform sampler2D inputImageTexture;
1010
uniform vec4 color;
1111
uniform int useExistingAlpha;
12-
12+
1313
void main()
1414
{
15-
if (useExistingAlpha == 1)
16-
{
17-
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
18-
gl_FragColor = vec4(color.rgb, textureColor.a);
19-
}
20-
else
21-
{
22-
gl_FragColor = color;
23-
}
15+
gl_FragColor = vec4(color.rgb, max(textureColor.a, 1.0 - useExistingAlpha));
2416
}
25-
);
17+
);
2618
#else
2719
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING
2820
(
29-
varying vec2 textureCoordinate;
21+
varying vec2 textureCoordinate;
3022
uniform sampler2D inputImageTexture;
3123
uniform vec4 color;
3224
uniform int useExistingAlpha;
3325

3426
void main()
3527
{
36-
if (useExistingAlpha == 1)
37-
{
38-
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
39-
gl_FragColor = vec4(color.rgb, textureColor.a);
40-
}
41-
else
42-
{
43-
gl_FragColor = color;
44-
}
28+
gl_FragColor = vec4(color.rgb, max(textureColor.a, 1.0 - useExistingAlpha));
4529
}
46-
);
30+
);
4731
#endif
4832

4933
@implementation GPUImageSolidColorGenerator
@@ -70,6 +54,27 @@ - (id)init;
7054
#pragma mark -
7155
#pragma mark Accessors
7256

57+
- (void)forceProcessingAtSize:(CGSize)frameSize;
58+
{
59+
[super forceProcessingAtSize:frameSize];
60+
61+
if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero))
62+
{
63+
[self newFrameReadyAtTime:kCMTimeIndefinite atIndex:0];
64+
}
65+
}
66+
67+
- (void)addTarget:(id<GPUImageInput>)newTarget atTextureLocation:(NSInteger)textureLocation;
68+
{
69+
[super addTarget:newTarget atTextureLocation:textureLocation];
70+
71+
if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero))
72+
{
73+
[newTarget setInputSize:inputTextureSize atIndex:textureLocation];
74+
[newTarget newFrameReadyAtTime:kCMTimeIndefinite atIndex:textureLocation];
75+
}
76+
}
77+
7378
- (void)setColor:(GPUVector4)newValue;
7479
{
7580
[self setColorRed:newValue.one green:newValue.two blue:newValue.three alpha:newValue.four];

0 commit comments

Comments
 (0)