-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCVPOpenGLTexture.m
86 lines (66 loc) · 1.35 KB
/
CVPOpenGLTexture.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
#import "CVPOpenGLTexture.h"
#import <OpenGL/gl3.h>
@interface CVPOpenGLTexture ()
{
@private
CVOpenGLTextureRef texture;
}
@end
@implementation CVPOpenGLTexture
+ (instancetype)textureWithCVOpenGLTexture:(CVOpenGLTextureRef)texture
{
return [[self alloc] initWithCVOpenGLTexture:texture];
}
- (instancetype)initWithCVOpenGLTexture:(CVOpenGLTextureRef)texture_
{
if(texture_ == NULL)
{
return nil;
}
self = [super init];
if(self != nil)
{
texture = texture_;
CVOpenGLTextureRetain(texture);
glpTextureSetDefaults(self.GLTarget, self.GLTexture);
}
return self;
}
- (void)dealloc
{
CVOpenGLTextureRelease(texture);
}
- (GLenum)GLTarget
{
return CVOpenGLTextureGetTarget(texture);
}
- (GLuint)GLTexture
{
return CVOpenGLTextureGetName(texture);
}
- (void)bind
{
glBindTexture(self.GLTarget, self.GLTexture);
}
- (void)bindToUnit:(GLenum)unit
{
glpActiveTexture(unit);
[self bind];
}
- (void)unbind
{
glBindTexture(self.GLTarget, 0);
}
- (CVOpenGLTextureRef)CVOpenGLTexture NS_RETURNS_INNER_POINTER
{
return texture;
}
- (void)getCleanTextureCoordinates:(GLfloat [8])textureCoordinates
{
CVOpenGLTextureGetCleanTexCoords(texture, textureCoordinates+0, textureCoordinates+2, textureCoordinates+4, textureCoordinates+6);
}
- (NSString*)description
{
return [NSString stringWithFormat:@"<%@: %p | %@>", [self class], self, texture];
}
@end