-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathKinemeGLDepthSortEnvironmentPatch.m
91 lines (69 loc) · 1.91 KB
/
KinemeGLDepthSortEnvironmentPatch.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 <OpenGL/CGLMacro.h>
#import "KinemeGLDepthSortEnvironmentPatch.h"
#import <KinemeGLRenderer.h>
static NSInteger KinemeGLDepthSortComparison(id<KinemeGLDepthRenderer> a, id<KinemeGLDepthRenderer> b, void *context)
{
NSComparisonResult rc;
if([a depth] < [b depth])
rc = NSOrderedDescending;
else
rc = NSOrderedAscending;
return rc;
}
@implementation KinemeGLDepthSortEnvironmentPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return kQCPatchExecutionModeConsumer;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return YES;
}
+ (BOOL)isSafe
{
return YES;
}
- (id)initWithIdentifier:(id)fp8
{
if(self=[super initWithIdentifier:fp8])
{
// [inputMode setMaxIndexValue: 1];
[[self userInfo] setObject:@"Kineme GL Depth Sort Environment" forKey:@"name"];
}
return self;
}
-(BOOL)setup:(QCOpenGLContext*)context
{
opaqueElements = [NSMutableArray new];
transparentElements = [NSMutableArray new];
return YES;
}
-(void)cleanup:(QCOpenGLContext*)context
{
[opaqueElements release];
[transparentElements release];
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
[self executeSubpatches:time arguments:arguments];
id<KinemeGLDepthRenderer> e;
[opaqueElements sortUsingFunction:KinemeGLDepthSortComparison context:nil];
[transparentElements sortUsingFunction:KinemeGLDepthSortComparison context:nil];
// Render Opaque elements near-to-far (minimize overdraw)
for(e in opaqueElements)
[e renderOnContext:context];
// Render Transparent elements far-to-near (proper overlapping)
for(e in [transparentElements reverseObjectEnumerator])
[e renderOnContext:context];
[opaqueElements removeAllObjects];
[transparentElements removeAllObjects];
return YES;
}
- (void)addElement:(id<KinemeGLDepthRenderer>)e isOpaque:(BOOL)opaque
{
if(opaque)
[opaqueElements addObject:e];
else
[transparentElements addObject:e];
}
@end