-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathKinemeGLPolygonModePatch.m
119 lines (102 loc) · 2.86 KB
/
KinemeGLPolygonModePatch.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
#import <OpenGL/gl.h>
#import <OpenGL/OpenGL.h>
#import <OpenGL/CGLMacro.h>
#import "KinemeGLPolygonModePatch.h"
@implementation KinemeGLPolygonModePatch : QCPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return 1; // renders stuff
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return YES;
}
+ (BOOL)isSafe
{
return YES;
}
- (id)initWithIdentifier:(id)fp8
{
self=[super initWithIdentifier:fp8];
if(self)
{
[inputFrontPolygonMode setMaxIndexValue: 2];
[inputBackPolygonMode setMaxIndexValue: 2];
[inputSize setMinDoubleValue: 0.4];
[inputWidth setMinDoubleValue: 0.4];
[inputSize setDoubleValue: 1.0];
[inputWidth setDoubleValue: 1.0];
[inputStipplePattern setMaxIndexValue: 65535];
[inputStipplePattern setIndexValue: 65535];
[inputRepeatCount setMaxIndexValue: 256];
[inputRepeatCount setIndexValue: 1];
[[self userInfo] setObject:@"Kineme GL Polygon Mode" forKey:@"name"];
}
return self;
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
GLint origPolygonMode[2];
GLfloat origLineWidth;
GLfloat origPointSize;
GLint oldFactor;
GLint oldPattern;
GLboolean smoothPoints, smoothLines;
CGLContextObj cgl_ctx = [context CGLContextObj];
// store the original values
glGetIntegerv(GL_LINE_STIPPLE_REPEAT,&oldFactor);
glGetIntegerv(GL_LINE_STIPPLE_PATTERN,&oldPattern);
glGetIntegerv(GL_POLYGON_MODE,origPolygonMode);
glGetFloatv(GL_LINE_WIDTH,&origLineWidth);
glGetFloatv(GL_POINT_SIZE, &origPointSize);
smoothPoints = glIsEnabled(GL_POINT_SMOOTH);
smoothLines = glIsEnabled(GL_LINE_SMOOTH);
if([inputAntialiasPoints booleanValue] && !smoothPoints)
glEnable(GL_POINT_SMOOTH);
if([inputAntialiasLines booleanValue] && !smoothLines)
glEnable(GL_LINE_SMOOTH);
glEnable(GL_LINE_STIPPLE);
glLineStipple([inputRepeatCount indexValue],[inputStipplePattern indexValue]);
switch([inputFrontPolygonMode indexValue])
{
default:
case 0: // filled
glPolygonMode(GL_FRONT, GL_FILL);
break;
case 1: // wireframe
glPolygonMode(GL_FRONT, GL_LINE);
break;
case 2: // points
glPolygonMode(GL_FRONT, GL_POINT);
break;
}
switch([inputBackPolygonMode indexValue])
{
default:
case 0: // filled
glPolygonMode(GL_BACK, GL_FILL);
break;
case 1: // wireframe
glPolygonMode(GL_BACK, GL_LINE);
break;
case 2: // points
glPolygonMode(GL_BACK, GL_POINT);
break;
}
glLineWidth([inputWidth doubleValue]);
glPointSize([inputSize doubleValue]);
[self executeSubpatches:time arguments:arguments];
// restore the previous mode
glDisable(GL_LINE_STIPPLE);
glLineStipple(oldFactor, oldPattern);
if(!smoothPoints)
glDisable(GL_POINT_SMOOTH);
if(!smoothLines)
glDisable(GL_LINE_SMOOTH);
glPolygonMode(GL_FRONT,origPolygonMode[0]);
glPolygonMode(GL_BACK,origPolygonMode[1]);
glLineWidth(origLineWidth);
glPointSize(origPointSize);
return YES;
}
@end