4
4
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING
5
5
(
6
6
precision lowp float ;
7
-
8
- varying highp vec2 textureCoordinate;
7
+
8
+ varying highp vec2 textureCoordinate;
9
9
uniform sampler2D inputImageTexture;
10
10
uniform vec4 color;
11
11
uniform int useExistingAlpha;
12
-
12
+
13
13
void main ()
14
14
{
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));
24
16
}
25
- );
17
+ );
26
18
#else
27
19
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING
28
20
(
29
- varying vec2 textureCoordinate;
21
+ varying vec2 textureCoordinate;
30
22
uniform sampler2D inputImageTexture;
31
23
uniform vec4 color;
32
24
uniform int useExistingAlpha;
33
25
34
26
void main ()
35
27
{
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));
45
29
}
46
- );
30
+ );
47
31
#endif
48
32
49
33
@implementation GPUImageSolidColorGenerator
@@ -70,6 +54,27 @@ - (id)init;
70
54
#pragma mark -
71
55
#pragma mark Accessors
72
56
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
+
73
78
- (void )setColor : (GPUVector4)newValue ;
74
79
{
75
80
[self setColorRed: newValue.one green: newValue.two blue: newValue.three alpha: newValue.four];
0 commit comments