-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVertexFormat.java
55 lines (46 loc) · 1.92 KB
/
VertexFormat.java
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
package com.ripplargames.meshio.vertices;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class VertexFormat {
private final Map<VertexType, AlignedVertexFormatPart> alignedFormatParts;
private final int byteCount;
public VertexFormat(VertexFormatPart... formatParts) {
this(Arrays.asList(formatParts));
}
public VertexFormat(List<VertexFormatPart> formatParts) {
this.alignedFormatParts = createAlignedFormatParts(formatParts);
this.byteCount = calculateByteCount(formatParts);
}
private static Map<VertexType, AlignedVertexFormatPart> createAlignedFormatParts(List<VertexFormatPart> formatEntries) {
Map<VertexType, AlignedVertexFormatPart> alignedFormatParts = new EnumMap<VertexType, AlignedVertexFormatPart>(VertexType.class);
int offset = 0;
for (VertexFormatPart entry : formatEntries) {
VertexType vertexType = entry.getVertexType();
VertexDataType dataType = entry.getDataType();
AlignedVertexFormatPart alignedFormatPart = new AlignedVertexFormatPart(offset, dataType);
alignedFormatParts.put(vertexType, alignedFormatPart);
offset += dataType.byteCount();
}
return Collections.unmodifiableMap(alignedFormatParts);
}
private static int calculateByteCount(List<VertexFormatPart> formatParts) {
int byteCount = 0;
for (VertexFormatPart formatPart : formatParts) {
byteCount += formatPart.getDataType().byteCount();
}
return byteCount;
}
public Iterable<Map.Entry<VertexType, AlignedVertexFormatPart>> alignedParts() {
return alignedFormatParts.entrySet();
}
public Set<VertexType> vertexTypes() {
return alignedFormatParts.keySet();
}
public int byteCount() {
return byteCount;
}
}