Skip to content

Commit 3633099

Browse files
committed
this should fix int stuff
1 parent ba08a12 commit 3633099

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

src/main/java/valoeghese/scalpel/scene/VertexFormat.java

+40-7
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,30 @@ public Entry[] getEntries() {
3636
*/
3737
void applyFormat() {
3838
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);
4140
glEnableVertexAttribArray(index);
4241
}
4342
}
4443

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+
4563
private static int nBytes(int type) throws IllegalArgumentException {
4664
switch (type) {
4765
case GL_BYTE:
@@ -83,7 +101,7 @@ public VertexFormat.Builder add(int type, int size) {
83101
* @return this vertex format object.
84102
*/
85103
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.
87105
this.stride += nBytes(type) * size;
88106
return this;
89107
}
@@ -93,6 +111,17 @@ public VertexFormat build() {
93111
}
94112
}
95113

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+
96125
public static class Entry {
97126
private Entry(int type, int size, int pointer, boolean normalised) {
98127
this.type = type;
@@ -101,10 +130,10 @@ private Entry(int type, int size, int pointer, boolean normalised) {
101130
this.normalised = normalised;
102131
}
103132

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;
108137

109138
/**
110139
* @return the OpenGL type of this entry. For example, {@code GL_FLOAT}.
@@ -133,5 +162,9 @@ public int getPointer() {
133162
public boolean isNormalised() {
134163
return this.normalised;
135164
}
165+
166+
void vertexAttribPointer(int index, int stride) {
167+
glVertexAttribPointer(index, this.size, this.type, this.normalised, stride, this.pointer);
168+
}
136169
}
137170
}

0 commit comments

Comments
 (0)