-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathKinemeGLGenerateMipMapPatch.m
80 lines (66 loc) · 2.32 KB
/
KinemeGLGenerateMipMapPatch.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
//
// KinemeGLGenerateMipMapPatch.m
// GLTools
//
// Created by Christopher Wright on 12/17/08.
// Copyright 2008 Kosada Incorporated. All rights reserved.
//
#import <OpenGL/CGLMacro.h>
#import "KinemeGLGenerateMipMapPatch.h"
@interface NSObject (GLToolsWarningSuppression)
-(id)provider;
-(id)imageBuffer;
-(GLint)name;
@end
@implementation KinemeGLGenerateMipMapPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return 0;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return NO;
}
+ (BOOL)isSafe
{
return YES;
}
- (id)initWithIdentifier:(id)fp8
{
if(self = [super initWithIdentifier: fp8])
[[self userInfo] setObject:@"Kineme GL Generate MipMap" forKey:@"name"];
return self;
}
- (BOOL)setup:(QCOpenGLContext*)context
{
double maxAniso;
CGLContextObj cgl_ctx = [context CGLContextObj];
glGetDoublev(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso);
[inputAniso setMaxDoubleValue: maxAniso];
[inputAniso setMinDoubleValue: 1.0];
return YES;
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
[outputImage setImageValue: nil];
QCImage *img;
if(img = [inputImage imageValue])
{
CGLContextObj cgl_ctx = [context CGLContextObj];
[img setMetadata:[NSNumber numberWithInt:32] forKey:@"textureLevels" shouldForward:YES];
[img setMetadata:[NSNumber numberWithInt:GL_TEXTURE_2D] forKey:@"textureTarget" shouldForward:YES];
//NSLog(@"md: %@", [[inputImage imageValue] allMetadata]);
// Here we rely on a slight hack:
// * interrogating objects to get a texture name is ridiculous (with the 80 zillion qc image classes/providers out there)
// * we can't use the GL to ask which name is bound to which texture unit (AFAICT)
// So, to generate mipmaps, we instead rely on the GL's state machine: when a texture is set on a context, it's bound.
// We take advantage of that binding, and don't manage it ourselves at all. (no glBindTexture(...)).
[inputImage setOnOpenGLContext:context unit:GL_TEXTURE0]; // this performs the bind for us, and GL-ifies the image if necessary.
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, [inputAniso doubleValue]);
glGenerateMipmapEXT(GL_TEXTURE_2D);
[inputImage unsetOnOpenGLContext: context unit:GL_TEXTURE0];
[outputImage setImageValue: [inputImage imageValue]];
}
return YES;
}
@end