-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGLPProgram+LinkedProgram.m
91 lines (72 loc) · 2.66 KB
/
GLPProgram+LinkedProgram.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#import "GLPProgram+LinkedProgram.h"
#import "GLPShader+CompiledShader.h"
@implementation GLPProgram (LinkedProgram)
+ (instancetype)linkedProgramWithVertexShaderSource:(NSString *)vertexShaderSource fragmentShaderSource:(NSString *)fragmentShaderSource attributes:(NSDictionary *)attributes error:(NSError **)error
{
GLPShader *vertexShader = [GLPShader compiledVertexShaderWithSource:vertexShaderSource error:error];
if(vertexShader == nil)
{
return nil;
}
GLPShader *fragmentShader = [GLPShader compiledFragmentShaderWithSource:fragmentShaderSource error:error];
if(fragmentShader == nil)
{
return nil;
}
return [self linkedProgramWithVertexShader:vertexShader fragmentShader:fragmentShader attributes:attributes error:error];
}
+ (instancetype)linkedProgramWithVertexShaderFile:(NSString *)vertexShaderFile fragmentShaderFile:(NSString *)fragmentShaderFile attributes:(NSDictionary *)attributes error:(NSError **)error
{
GLPShader* vertexShader = [GLPShader compiledVertexShaderWithContentsOfFile:vertexShaderFile error:error];
if(vertexShader == nil)
{
return nil;
}
GLPShader* fragmentShader = [GLPShader compiledFragmentShaderWithContentsOfFile:fragmentShaderFile error:error];
if(fragmentShader == nil)
{
return nil;
}
return [self linkedProgramWithVertexShader:vertexShader fragmentShader:fragmentShader attributes:attributes error:error];
}
+ (instancetype)linkedProgramWithVertexShaderResource:(NSString *)vertexShaderResource fragementShaderResource:(NSString *)fragmentShaderResource bundle:(NSBundle *)bundle attributes:(NSDictionary *)attributes error:(NSError **)error
{
GLPShader *vertexShader = [GLPShader compiledVertexShaderWithResource:vertexShaderResource bundle:bundle error:error];
if(vertexShader == nil)
{
return nil;
}
GLPShader *fragmentShader = [GLPShader compiledFragmentShaderWithResource:fragmentShaderResource bundle:bundle error:error];
if(fragmentShader == nil)
{
return nil;
}
return [self linkedProgramWithVertexShader:vertexShader fragmentShader:fragmentShader attributes:attributes error:error];
}
+ (instancetype)linkedProgramWithVertexShader:(GLPShader *)vertexShader fragmentShader:(GLPShader *)fragmentShader attributes:(NSDictionary *)attributes error:(NSError **)error
{
GLPProgram *program = [self program];
if(vertexShader != nil)
{
[program attachShader:vertexShader];
}
if(fragmentShader != nil)
{
[program attachShader:fragmentShader];
}
[program bindAttributes:attributes];
if(![program link:error])
{
return nil;
}
if(vertexShader != nil)
{
[program detachShader:vertexShader];
}
if(fragmentShader != nil)
{
[program detachShader:fragmentShader];
}
return program;
}
@end