-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCVPOpenGLBufferPool.m
99 lines (81 loc) · 2.59 KB
/
CVPOpenGLBufferPool.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 "CVPOpenGLBufferPool.h"
#import <Foundation/Foundation.h>
#import <CoreVideo/CoreVideo.h>
#import <OpenGL/OpenGL.h>
#import "CVPOpenGLBuffer.h"
#import "NSError+CVPError.h"
@interface CVPOpenGLBufferPool ()
{
@private
CVOpenGLBufferPoolRef bufferPool;
}
@end
@implementation CVPOpenGLBufferPool
- (instancetype)initWithMinimumBufferCount:(NSUInteger)minimumBufferCount maximumBufferAge:(NSTimeInterval)maximumBufferAge width:(int32_t)width height:(int32_t)height target:(GLenum)target format:(GLenum)format maximumMipmapLevel:(GLint)maximumMipmapLevel error:(NSError **)error
{
NSDictionary *poolAttributes = @{
(__bridge NSString *)kCVOpenGLBufferPoolMinimumBufferCountKey: @(minimumBufferCount),
(__bridge NSString *)kCVOpenGLBufferPoolMaximumBufferAgeKey: @(maximumBufferAge),
};
NSDictionary *bufferAttributes = @{
(__bridge NSString *)kCVOpenGLBufferWidth: @(width),
(__bridge NSString *)kCVOpenGLBufferHeight: @(height),
(__bridge NSString *)kCVOpenGLBufferTarget: @(target),
(__bridge NSString *)kCVOpenGLBufferInternalFormat: @(format),
(__bridge NSString *)kCVOpenGLBufferMaximumMipmapLevel: @(maximumMipmapLevel),
};
return [self initWithPoolAttributes:poolAttributes bufferAttributes:bufferAttributes error:error];
}
- (instancetype)initWithPoolAttributes:(NSDictionary *)poolAttributes bufferAttributes:(NSDictionary *)bufferAttributes error:(NSError **)error
{
self = [super init];
if(self != nil)
{
CVReturn err = CVOpenGLBufferPoolCreate(NULL, (__bridge CFDictionaryRef)poolAttributes, (__bridge CFDictionaryRef)bufferAttributes, &bufferPool);
if(err != kCVReturnSuccess)
{
if(error != nil)
{
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil];
}
else
{
NSLog(@"%s:%d:ERROR: %d", __FUNCTION__, __LINE__, err);
}
}
}
return self;
}
- (void)dealloc
{
CVOpenGLBufferPoolRelease(bufferPool);
}
- (CVOpenGLBufferRef)createBufferWithError:(NSError **)error
{
CVOpenGLBufferRef buffer = NULL;
CVReturn err = CVOpenGLBufferPoolCreateOpenGLBuffer(NULL, bufferPool, &buffer);
if(err != kCVReturnSuccess)
{
if(error != nil)
{
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil];
}
else
{
NSLog(@"%s:%d:ERROR: %d", __FUNCTION__, __LINE__, err);
}
}
return buffer;
}
- (CVPOpenGLBuffer *)bufferWithError:(NSError **)error
{
CVOpenGLBufferRef buffer = [self createBufferWithError:error];
if (buffer == NULL)
{
return NULL;
}
CVPOpenGLBuffer *bufferObject = [[CVPOpenGLBuffer alloc] initWithCVOpenGLBuffer:buffer];
CVOpenGLBufferRelease(buffer);
return bufferObject;
}
@end