-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGLPFramebuffer.m
99 lines (77 loc) · 1.96 KB
/
GLPFramebuffer.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
92
93
94
95
96
97
98
99
#import "GLPFramebuffer.h"
@implementation GLPFramebuffer
+ (instancetype)framebuffer
{
return [[self alloc] init];
}
- (instancetype)init
{
self = [super init];
if(self != nil) {
target = GL_FRAMEBUFFER;
glGenFramebuffers(1, &framebuffer);
if(framebuffer == 0)
{
return nil;
}
}
return self;
}
- (void)dealloc
{
glDeleteFramebuffers(1, &framebuffer);
}
- (void)attach:(GLenum)attachment texture:(id<GLPTexture>)texture
{
[self attach:attachment texture:texture level:0];
}
- (void)attach:(GLenum)attachment texture:(id<GLPTexture>)texture level:(GLint)level
{
// [self bindFramebuffer];
glFramebufferTexture2D(target, attachment, texture.GLTarget, texture.GLTexture, level);
}
- (void)attach:(GLenum)attachment renderbuffer:(GLPRenderbuffer *)renderbuffer
{
// [self bindFramebuffer];
glFramebufferRenderbuffer(target, attachment, renderbuffer.GLTarget, renderbuffer.GLRenderbuffer);
}
- (void)detach:(GLenum)attachment
{
// [self bindFramebuffer];
glFramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, 0);
}
- (BOOL)valid
{
return self.status == GL_FRAMEBUFFER_COMPLETE;
}
- (GLenum)status
{
// [self bindFramebuffer];
return glCheckFramebufferStatus(target);
}
#if 0
- (NSData*)readPixelsInRect:(CGRect)rect format:(EEGLPixelformat)pixelformat {
int x = rect.origin.x;
int y = rect.origin.y;
int width = rect.size.width;
int height = rect.size.height;
NSUInteger length = eeglPixelformatGetBytesPerPixel(pixelformat) * width * height;
GLuint format = eeglPixelformatGetFormat(pixelformat);
GLuint type = eeglPixelformatGetType(pixelformat);
NSMutableData* data = [NSMutableData dataWithLength:length];
glReadPixels(x, y, width, height, format, type, data.mutableBytes);
return data;
}
#endif
#pragma mark - EEGLFramebuffer
- (void)bindFramebuffer
{
glBindFramebuffer(target, framebuffer);
}
- (void)unbindFramebuffer
{
glBindFramebuffer(target, 0);
}
@synthesize GLTarget = target;
@synthesize GLFramebuffer = framebuffer;
@end