-
Notifications
You must be signed in to change notification settings - Fork 4
/
LineBuffers.h
292 lines (201 loc) · 10.4 KB
/
LineBuffers.h
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//
// LineBuffers.h
// FMChart
//
// Created by Keisuke Mori on 2015/08/25.
// Copyright © 2015 Keisuke Mori. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CGGeometry.h>
#import "Line_common.h"
#import "Buffers.h"
@protocol MTLBuffer;
/**
* A wrapper class for struct uniform_line_attr that provides setter methods.
* width is in logical pixel and represents distance from the edge to the other.
* color vector is in RGBA format.
*
* dashLineLength and dashSpaceLength determine shape of dashed line segments and intervals.
* their length (logical pixel) are defined by (width * length).
* dashLineLength with value +FLOAT_MIN will result in dot line, and 1 in stroke of length that equals to width.
* dashSpaceLength with value +FLOAT_MIN will put two segments almost in contact, and 1 in interval of length that equals to width.
*
* dashLineAnchor and dashRepeatAnchor specifies 'the anchor point of the whole line(all segments and space)' and
* 'the anchor point of the repeat unit of semgent and space' which overlap each other.
* dashLineAnchor with vaue -1 place the anchor at the beginning of the whole line, and 0 at the center.
* dashRepeatAnchor with value -1 or +1 place the anchor at the middle of interval, and 0 at the middle of the segment.
*/
@interface FMUniformLineAttributes : FMAttributesBuffer
@property (readonly, nonatomic) uniform_line_attr * _Nonnull attributes;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource
size:(NSUInteger)size
UNAVAILABLE_ATTRIBUTE;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource;
/**
* sets the line width (from the edge to the other) in logical pixel.
*/
- (void)setWidth:(float)width;
- (void)setColorVec:(vector_float4)color;
- (void)setDashLineLength:(float)length;
- (void)setDashSpaceLength:(float)length;
- (void)setDashLineAnchor:(float)anchor;
- (void)setDashRepeatAnchor:(float)anchor;
@end
/**
* See FMAttributesArray, FMArrayBuffer and FMUniformLineAttributes for details.
*/
@interface FMUniformLineAttributesArray : FMAttributesArray<FMUniformLineAttributes*>
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource
capacity:(NSUInteger)capacity
NS_DESIGNATED_INITIALIZER;
@end
/**
* A wrapper class for struct uniform_line_conf that provides setter methods.
*
* alpha must be in range [0, 1], behavior is undefined otherwise.
* if enableDash is set to YES, then properties for dashed line will be active (loads of the fragment shader will be somewhat increased).
* enableOverlay controls anti-aliasing quality and drawing result of polylines with translucent color.
* (if set to YES, line edge will be less juggy, but its joints will be rendered multiple times with a given color due to disabled depth test)
*/
@interface FMUniformLineConf : NSObject
@property (readonly, nonatomic) id<MTLBuffer> _Nonnull buffer;
@property (readonly, nonatomic) uniform_line_conf * _Nonnull conf;
/**
* default NO. (see class description)
*/
@property (nonatomic) BOOL enableDash;
@property (nonatomic) float depthValue;
/**
* default NO. (see class description)
*/
@property (nonatomic) BOOL enableOverlay;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource;
- (void)setAlpha:(float)alpha;
@end
/**
* FMUniformAxisAttributes is a wrapper class for struct uniform_axis_attributes that provides setter methods.
* An instance of this class applies to axis and major/minor ticks.
* Interpretations of width and colors are equivalent to those of FMUniformLineAttribuutes.
*
* lineLength controls ticks length (from center to the edge) in logical pixel.
* lengthModifier (a, b) modifies length of (begin-center) and (center-end) separately.
* ( (-1, 1) -> b--c--e, (-1, 0) -> b--ce, (0, 2) -> bc----e )
*/
@interface FMUniformAxisAttributes : NSObject
@property (readonly, nonatomic) uniform_axis_attributes * _Nonnull attributes;
- (instancetype _Nonnull)initWithAttributes:(uniform_axis_attributes * _Nonnull)attr;
- (void)setWidth:(float)width;
- (void)setColorVec:(vector_float4)color;
- (void)setLineLength:(float)length;
- (void)setLengthModifierStart:(float)start end:(float)end;
- (void)setLengthModifierStart:(float)start;
- (void)setLengthModifierEnd:(float)end;
@end
// 他のUniform系と異なりほとんどがreadableなプロパティで定義されているのは、
// Attributeと違い設定はCPU側で参照される事が多いためである。
// CPU/GPU共有バッファは出来れば書き込み専用にしたいので、プロパティへのミラーリングをしている.
/**
* FMUniformAxisConfiguration is a wrapper class for struct uniform_axis_configuration that provides setter methods.
* An axis has a signle FMUniformAxisConfiguration instance.
*
* axisDataValue controls on which value an axis placed in the 'orthogonal dimension' (where y axis is placed in x dim).
* axisAnchorNDCValue controls specifies an axis position in ndc if in range [-1, 1], axisDataValue will be used otherwise.
* tickAnchorValue specifies from where tick series starts (including negative-indixed ticks) in the dimension alongside.
* majorTickInterval specifies interval between each tick in the dimension alongside.
* minorTicksPerMajor specifies how many minor ticks drawn per a major tick.
* (note that the value 1 will results in overlapped major/minor ticks and none other than that)
*
* dimensionIndex is the index of the dimension an axis belongs to (0 for x axis, 1 for y axis).
*
* maxMajorTicks limit the count how many major ticks can be on screen at once (to reduce gpu workload).
* maxMajorTicks property is not for FMAxis class (FMAxis calcute and set the value, and FMAxisLabel and FMGridLine use it)
*
* majorTickValueModified shows that the properties which affetcts tick values have been modified.
* the flag will be set to NO when checkIfMajorTickValueModified: is called with blocks returning YES.
* (purpose of the property and the method is to check if rendering cache of labels should be invalidated or not).
*/
@interface FMUniformAxisConfiguration : NSObject
@property (readonly, nonatomic) id<MTLBuffer> _Nonnull buffer;
@property (readonly, nonatomic) uniform_axis_configuration * _Nonnull configuration;
@property (assign , nonatomic) float axisAnchorDataValue;
@property (assign , nonatomic) float axisAnchorNDCValue; // [-1, 1], この値の外ではDataValueが使われる
@property (assign , nonatomic) float tickAnchorValue;
@property (assign , nonatomic) float majorTickInterval;
@property (assign , nonatomic) uint8_t minorTicksPerMajor;
@property (assign , nonatomic) uint8_t dimensionIndex;
@property (assign , nonatomic) uint8_t maxMajorTicks;
@property (readonly, nonatomic) BOOL majorTickValueModified;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource;
/**
* check and modify the flag which shows render cache of labels should be invalidated or not.
* if the flag is YES, then ifModified will be executed, and then clear the flag only if its return value is YES.
* returns old value of the flag regardless of results of flag modification.
* passing an nil block will cause EXC_BAD_ACCESS.
*/
- (BOOL)checkIfMajorTickValueModified:(BOOL (^_Nonnull)(FMUniformAxisConfiguration *_Nonnull))ifModified;
/**
* returns the value of an axis position (to resolve conflict of axisAnchorDataValue and axisAnchorNDCValue)
*/
- (float)axisAnchorValueWithProjection:(FMUniformProjectionCartesian2D * _Nonnull)projection;
@end
/**
* FMUniformGridAttributes is a wrapper for struct unifim_gird_attributes that provides setter methods.
*
* Interpretations of width, color, dashing attributes, anchorValue, interval are equivalent to those of FMUniformAxisAttributes.
*/
@interface FMUniformGridAttributes : NSObject
@property (readonly, nonatomic) id<MTLBuffer> _Nonnull buffer;
@property (readonly, nonatomic) uniform_grid_attributes * _Nonnull attributes;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource
NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)init UNAVAILABLE_ATTRIBUTE;
- (void)setWidth:(float)width;
- (void)setColorVec:(vector_float4)color;
- (void)setDashLineLength:(float)length;
- (void)setDashSpaceLength:(float)length;
- (void)setDashLineAnchor:(float)anchor;
- (void)setDashRepeatAnchor:(float)anchor;
@end
/**
* FMUniformGridConfiguration is a wrapper for struct unifim_gird_configuration that provides setter methods.
*
* dimensionIndex is an id of the dimension of an axis (if any) that this grid line intersects.
* (decides dimIndex in FMGridLine initializer and therefore you should not modify it directly)
*/
@interface FMUniformGridConfiguration : NSObject
@property (readonly, nonatomic) id<MTLBuffer> _Nonnull buffer;
@property (readonly, nonatomic) uniform_grid_configuration * _Nonnull conf;
@property (assign , nonatomic) float anchorValue;
@property (assign , nonatomic) float interval;
@property (assign , nonatomic) uint8_t dimensionIndex;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource
NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)init UNAVAILABLE_ATTRIBUTE;
- (void)setDepthValue:(float)depth;
@end
@interface FMUniformLineAreaAttributes : FMAttributesBuffer
@property (readonly, nonatomic) uniform_line_area_attr * _Nonnull attributes;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource
size:(NSUInteger)size
UNAVAILABLE_ATTRIBUTE;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource;
- (void)setGradientStartColor:(vector_float4)colorStart
startPosition:(CGPoint)posStart
endColor:(vector_float4)colorEnd
endPosition:(CGPoint)posEnd
toPositive:(BOOL)positive;
;
- (void)setSolidColor:(vector_float4)color;
@end
@interface FMUniformLineAreaConfiguration : NSObject
@property (readonly, nonatomic) id<MTLBuffer> _Nonnull buffer;
@property (readonly, nonatomic) uniform_line_area_conf * _Nonnull conf;
- (instancetype _Nonnull)initWithResource:(FMDeviceResource * _Nonnull)resource
NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)init UNAVAILABLE_ATTRIBUTE;
- (void)setColorPositionInDateSpace:(BOOL)inDataSpace;
- (void)setAnchorPoint:(CGPoint)anchor inDataSpace:(BOOL)inDataSpace;
- (void)setDirection:(CGPoint)direction;
- (void)setDepthValue:(float)depth;
- (void)setOpacity:(float)opacity;
@end