@@ -36,12 +36,30 @@ public Entry[] getEntries() {
36
36
*/
37
37
void applyFormat () {
38
38
for (int index = 0 ; index < this .format .length ; ++index ) {
39
- Entry attribute = this .format [index ];
40
- glVertexAttribPointer (index , attribute .size , attribute .type , attribute .normalised , this .stride , attribute .pointer );
39
+ this .format [index ].vertexAttribPointer (index , this .stride );
41
40
glEnableVertexAttribArray (index );
42
41
}
43
42
}
44
43
44
+ private static Entry createEntry (int type , int size , int pointer , boolean normalised ) {
45
+ switch (type ) {
46
+ case GL_BYTE :
47
+ case GL_UNSIGNED_BYTE :
48
+ case GL_SHORT :
49
+ case GL_UNSIGNED_SHORT :
50
+ case GL_INT :
51
+ case GL_UNSIGNED_INT :
52
+ return new IEntry (type , size , pointer , normalised );
53
+ case GL_HALF_FLOAT :
54
+ case GL_FLOAT :
55
+ case GL_DOUBLE : // in OpenGL 4 this will be an LEntry, and use glVertexAttribLPointer
56
+ return new Entry (type , size , pointer , normalised );
57
+ case 0x140C :
58
+ throw new IllegalArgumentException ("OpenGL 4.1 (which adds GL_FIXED) is not currently supported, however, feel free to open a PR to support the latest GL features." );
59
+ default : throw new IllegalArgumentException ("Unknown GL Type " + type + ". If you believe this is an error with Scalpel, please check if it has been fixed in a newer version, and if not, open an issue!" );
60
+ }
61
+ }
62
+
45
63
private static int nBytes (int type ) throws IllegalArgumentException {
46
64
switch (type ) {
47
65
case GL_BYTE :
@@ -83,7 +101,7 @@ public VertexFormat.Builder add(int type, int size) {
83
101
* @return this vertex format object.
84
102
*/
85
103
public VertexFormat .Builder add (int type , int size , boolean normalised ) {
86
- this .entries .add (new Entry (type , size , this .stride , normalised )); // the current stride is the offset for the pointer.
104
+ this .entries .add (createEntry (type , size , this .stride , normalised )); // the current stride is the offset for the pointer.
87
105
this .stride += nBytes (type ) * size ;
88
106
return this ;
89
107
}
@@ -93,6 +111,17 @@ public VertexFormat build() {
93
111
}
94
112
}
95
113
114
+ private static class IEntry extends Entry {
115
+ IEntry (int type , int size , int pointer , boolean normalised ) {
116
+ super (type , size , pointer , normalised );
117
+ }
118
+
119
+ @ Override
120
+ void vertexAttribPointer (int index , int stride ) {
121
+ glVertexAttribIPointer (index , this .size , this .type , stride , this .pointer );
122
+ }
123
+ }
124
+
96
125
public static class Entry {
97
126
private Entry (int type , int size , int pointer , boolean normalised ) {
98
127
this .type = type ;
@@ -101,10 +130,10 @@ private Entry(int type, int size, int pointer, boolean normalised) {
101
130
this .normalised = normalised ;
102
131
}
103
132
104
- private final int type ;
105
- private final int size ;
106
- private final int pointer ;
107
- private final boolean normalised ;
133
+ final int type ;
134
+ final int size ;
135
+ final int pointer ;
136
+ final boolean normalised ;
108
137
109
138
/**
110
139
* @return the OpenGL type of this entry. For example, {@code GL_FLOAT}.
@@ -133,5 +162,9 @@ public int getPointer() {
133
162
public boolean isNormalised () {
134
163
return this .normalised ;
135
164
}
165
+
166
+ void vertexAttribPointer (int index , int stride ) {
167
+ glVertexAttribPointer (index , this .size , this .type , this .normalised , stride , this .pointer );
168
+ }
136
169
}
137
170
}
0 commit comments