Models are temporary

- Add Model.delete
- Allow BlockModel.createEBO to be called more than once for a single
instance
- Clear cache on QuadConverter.delete
This commit is contained in:
PepperCode1 2022-11-06 14:00:24 -08:00
parent 98e4831b6e
commit edd6c736cf
5 changed files with 26 additions and 2 deletions

View file

@ -69,7 +69,6 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
vao = new GlVertexArray();
// XXX Callback seems unnecessary. Remove and extract code to run after alloc call?
model = modelAllocator.alloc(modelData, arenaModel -> {
// XXX VAO is bound and not reset or restored
vao.bind();
@ -77,7 +76,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
arenaModel.setupState(vao);
});
// XXX VAO is already guaranteed to be bound in model callback
// XXX VAO is bound and not reset or restored
vao.bind();
vao.enableArrays(model.getAttributeCount() + instanceFormat.getAttributeCount());

View file

@ -79,6 +79,7 @@ public class QuadConverter {
public void delete() {
GL32.glDeleteBuffers(ebo);
this.cache.clear();
this.quadCapacity = 0;
}

View file

@ -51,4 +51,15 @@ public class ModelPart implements Model {
public VertexList getReader() {
return reader;
}
@Override
public void delete() {
if (reader instanceof AutoCloseable closeable) {
try {
closeable.close();
} catch (Exception e) {
//
}
}
}
}

View file

@ -47,4 +47,15 @@ public class BlockModel implements Model {
public VertexList getReader() {
return reader;
}
@Override
public void delete() {
if (reader instanceof AutoCloseable closeable) {
try {
closeable.close();
} catch (Exception e) {
//
}
}
}
}

View file

@ -62,6 +62,8 @@ public interface Model {
.quads2Tris(vertexCount() / 4);
}
void delete();
/**
* The size in bytes that this model's data takes up.
*/