-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathKinemeGLLineStructurePatch.m
189 lines (164 loc) · 4.92 KB
/
KinemeGLLineStructurePatch.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#import <OpenGL/gl.h>
#import <OpenGL/OpenGL.h>
#import <OpenGL/CGLMacro.h>
#import "KinemeGLLineStructurePatch.h"
@implementation KinemeGLLineStructurePatch : QCPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return 1;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return NO;
}
+ (BOOL)isSafe
{
return YES;
}
- (id)initWithIdentifier:(id)fp8
{
self=[super initWithIdentifier:fp8];
if(self)
{
[inputSize setDoubleValue:1.0];
[inputSize setMinDoubleValue:0.01];
[inputPattern setIndexValue: 65535];
[inputPattern setMaxIndexValue: 65535];
[inputRepeatCount setIndexValue: 1];
[inputRepeatCount setMaxIndexValue: 256];
[inputColor1 setRed:0.7 green:0.4 blue:0.4 alpha:0.9];
[inputColor2 setRed:0.4 green:0.4 blue:0.7 alpha:0.9];
[inputType setMaxIndexValue:1];
[inputDepth setIndexValue:1]; // set normal read/write depth testing
[inputBlending setIndexValue:3]; // set Alpha blend mode by default
[[self userInfo] setObject:@"Kineme GL Line Structure" forKey:@"name"];
}
return self;
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
GLint smoothLines;
GLint oldFactor;
GLint oldPattern;
GLfloat origLineWidth;
CGFloat red1,green1,blue1,alpha1;
CGFloat red2,green2,blue2,alpha2;
QCStructure *lineStruct = [inputLines structureValue];
if(lineStruct == nil)
return YES; // no points, do nothing
unsigned int count = [lineStruct count];
if(count == 0)
return YES;
[inputColor1 getRed:&red1 green:&green1 blue:&blue1 alpha:&alpha1];
[inputColor2 getRed:&red2 green:&green2 blue:&blue2 alpha:&alpha2];
CGLContextObj cgl_ctx = [context CGLContextObj];
[inputBlending setOnOpenGLContext: context];
[inputDepth setOnOpenGLContext: context];
//[inputImage setOnOpenGLContext:context];
glGetFloatv(GL_LINE_WIDTH, &origLineWidth);
double lineWidth = [inputSize doubleValue];
if(lineWidth != origLineWidth)
glLineWidth([inputSize doubleValue]);
smoothLines = glIsEnabled(GL_LINE_SMOOTH);
if(!smoothLines)
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
int stipple = [inputPattern indexValue];
if(stipple != 0xffff)
{
glGetIntegerv(GL_LINE_STIPPLE_REPEAT,&oldFactor);
glGetIntegerv(GL_LINE_STIPPLE_PATTERN,&oldPattern);
glEnable(GL_LINE_STIPPLE);
glLineStipple([inputRepeatCount indexValue], stipple);
}
Class QCStructureClass = [QCStructure class];
Class NSArrayClass = [NSArray class];
BOOL keyed = (count &&
[[lineStruct memberAtIndex:0] isKindOfClass:QCStructureClass] &&
[[lineStruct memberAtIndex:0] memberForKey:@"X"] != nil);
if([inputType indexValue])
{
unsigned char end = 0;
glBegin(GL_LINES);
for(id point in (GFList*)[lineStruct _list])
{
if(end++&1)
KIGLColor4(red1,green1,blue1,alpha1);
else
KIGLColor4(red2,green2,blue2,alpha2);
if([point isKindOfClass: QCStructureClass])
{
GFList *pointData = [point _list];
if(keyed)
glVertex3d(
[[point memberForKey:@"X"] doubleValue],
[[point memberForKey:@"Y"] doubleValue],
[[point memberForKey:@"Z"] doubleValue]);
else
glVertex3d(
[[pointData objectAtIndex:0] doubleValue],
[[pointData objectAtIndex:1] doubleValue],
[[pointData objectAtIndex:2] doubleValue]);
}
else if([point isKindOfClass:NSArrayClass])
{
glVertex3d(
[[(NSArray *)point objectAtIndex:0] doubleValue],
[[(NSArray *)point objectAtIndex:1] doubleValue],
[[(NSArray *)point objectAtIndex:2] doubleValue]);
}
}
}
else
{
glBegin(GL_LINE_STRIP);
CGFloat dRed, dGreen, dBlue, dAlpha;
dRed = (red2 - red1) / count;
dGreen = (green2 - green1) / count;
dBlue = (blue2 - blue1) / count;
dAlpha = (alpha2 - alpha1) / count;
for(id point in (GFList*)[lineStruct _list])
{
KIGLColor4(red1,green1,blue1,alpha1);
if([point isKindOfClass: QCStructureClass])
{
GFList *pointData = [point _list];
if(keyed)
glVertex3d(
[[point memberForKey:@"X"] doubleValue],
[[point memberForKey:@"Y"] doubleValue],
[[point memberForKey:@"Z"] doubleValue]);
else
glVertex3d(
[[pointData objectAtIndex:0] doubleValue],
[[pointData objectAtIndex:1] doubleValue],
[[pointData objectAtIndex:2] doubleValue]);
}
else if([point isKindOfClass:NSArrayClass])
{
glVertex3d(
[[(NSArray *)point objectAtIndex:0] doubleValue],
[[(NSArray *)point objectAtIndex:1] doubleValue],
[[(NSArray *)point objectAtIndex:2] doubleValue]);
}
red1 += dRed;
green1 += dGreen;
blue1 += dBlue;
alpha1 += dAlpha;
}
}
glEnd();
if(!smoothLines)
glDisable(GL_LINE_SMOOTH);
if(lineWidth != origLineWidth)
glLineWidth(origLineWidth);
if(stipple != 0xffff)
{
glLineStipple(oldFactor, oldPattern);
glDisable(GL_LINE_STIPPLE);
}
[inputDepth unsetOnOpenGLContext: context];
[inputBlending unsetOnOpenGLContext: context];
return YES;
}
@end