mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-30 06:44:58 +01:00
Better state restore in InstancingEngine
- Attempt to fix optifine issues - Replace <code> with {@code}
This commit is contained in:
parent
8224e47619
commit
e0342c4b78
13 changed files with 55 additions and 21 deletions
|
@ -30,7 +30,7 @@ public interface DynamicInstance extends Instance {
|
||||||
* <br> You might want to opt out of this if you want your animations to remain smooth
|
* <br> You might want to opt out of this if you want your animations to remain smooth
|
||||||
* even when far away from the camera. It is recommended to keep this as is, however.
|
* even when far away from the camera. It is recommended to keep this as is, however.
|
||||||
*
|
*
|
||||||
* @return <code>true</code> if your instance should be slow ticked.
|
* @return {@code true} if your instance should be slow ticked.
|
||||||
*/
|
*/
|
||||||
default boolean decreaseFramerateWithDistance() {
|
default boolean decreaseFramerateWithDistance() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -38,7 +38,7 @@ public interface TickableInstance extends Instance {
|
||||||
* <br> You might want to opt out of this if you want your animations to remain smooth
|
* <br> You might want to opt out of this if you want your animations to remain smooth
|
||||||
* even when far away from the camera. It is recommended to keep this as is, however.
|
* even when far away from the camera. It is recommended to keep this as is, however.
|
||||||
*
|
*
|
||||||
* @return <code>true</code> if your instance should be slow ticked.
|
* @return {@code true} if your instance should be slow ticked.
|
||||||
*/
|
*/
|
||||||
default boolean decreaseTickRateWithDistance() {
|
default boolean decreaseTickRateWithDistance() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -12,10 +12,17 @@ public class GlVertexArray extends GlObject {
|
||||||
setHandle(GlStateManager._glGenVertexArrays());
|
setHandle(GlStateManager._glGenVertexArrays());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void bind(int vao) {
|
||||||
|
GlStateManager._glBindVertexArray(vao);
|
||||||
|
BufferUploaderAccessor.flywheel$setLastVAO(vao);
|
||||||
|
}
|
||||||
|
|
||||||
public void bind() {
|
public void bind() {
|
||||||
int handle = handle();
|
bind(handle());
|
||||||
GlStateManager._glBindVertexArray(handle);
|
}
|
||||||
BufferUploaderAccessor.flywheel$setLastVAO(handle);
|
|
||||||
|
public static int getBoundVertexArray() {
|
||||||
|
return BufferUploaderAccessor.flywheel$getLastVAO();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unbind() {
|
public static void unbind() {
|
||||||
|
|
|
@ -50,4 +50,12 @@ public enum GlBufferType {
|
||||||
case GL15C.GL_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$setLastVBO(0);
|
case GL15C.GL_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$setLastVBO(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBoundBuffer() {
|
||||||
|
return switch (this.glEnum) {
|
||||||
|
case GL15C.GL_ELEMENT_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$getLastEBO();
|
||||||
|
case GL15C.GL_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$getLastVBO();
|
||||||
|
default -> -1;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.lwjgl.opengl.GLCapabilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface should be implemented by enums such that the
|
* This interface should be implemented by enums such that the
|
||||||
* last defined variant <em>always</em> returns <code>true</code>.
|
* last defined variant <em>always</em> returns {@code true}
|
||||||
*/
|
*/
|
||||||
public interface GlVersioned {
|
public interface GlVersioned {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -65,13 +65,13 @@ public abstract class AbstractInstance implements Instance, LightListener {
|
||||||
* When an instance is reset, the instance is deleted and re-created.
|
* When an instance is reset, the instance is deleted and re-created.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Just before {@link #update()} would be called, <code>shouldReset()</code> is checked.
|
* Just before {@link #update()} would be called, {@code shouldReset()} is checked.
|
||||||
* If this function returns <code>true</code>, then this instance will be {@link #remove removed},
|
* If this function returns {@code true}, then this instance will be {@link #remove removed},
|
||||||
* and another instance will be constructed to replace it. This allows for more sane resource
|
* and another instance will be constructed to replace it. This allows for more sane resource
|
||||||
* acquisition compared to trying to update everything within the lifetime of an instance.
|
* acquisition compared to trying to update everything within the lifetime of an instance.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return <code>true</code> if this instance should be discarded and refreshed.
|
* @return {@code true} if this instance should be discarded and refreshed.
|
||||||
*/
|
*/
|
||||||
public boolean shouldReset() {
|
public boolean shouldReset() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -48,12 +48,12 @@ public abstract class BlockEntityInstance<T extends BlockEntity> extends Abstrac
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just before {@link #update()} would be called, <code>shouldReset()</code> is checked.
|
* Just before {@link #update()} would be called, {@code shouldReset()} is checked.
|
||||||
* If this function returns <code>true</code>, then this instance will be {@link #remove removed},
|
* If this function returns {@code true}, then this instance will be {@link #remove removed},
|
||||||
* and another instance will be constructed to replace it. This allows for more sane resource
|
* and another instance will be constructed to replace it. This allows for more sane resource
|
||||||
* acquisition compared to trying to update everything within the lifetime of an instance.
|
* acquisition compared to trying to update everything within the lifetime of an instance.
|
||||||
*
|
*
|
||||||
* @return <code>true</code> if this instance should be discarded and refreshed.
|
* @return {@code true} if this instance should be discarded and refreshed.
|
||||||
*/
|
*/
|
||||||
public boolean shouldReset() {
|
public boolean shouldReset() {
|
||||||
return blockEntity.getBlockState() != blockState;
|
return blockEntity.getBlockState() != blockState;
|
||||||
|
|
|
@ -79,6 +79,10 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render(TaskEngine taskEngine, RenderLayerEvent event) {
|
public void render(TaskEngine taskEngine, RenderLayerEvent event) {
|
||||||
|
int ebo = GlBufferType.ELEMENT_ARRAY_BUFFER.getBoundBuffer();
|
||||||
|
int vbo = GlBufferType.ARRAY_BUFFER.getBoundBuffer();
|
||||||
|
int vao = GlVertexArray.getBoundVertexArray();
|
||||||
|
|
||||||
double camX;
|
double camX;
|
||||||
double camY;
|
double camY;
|
||||||
double camZ;
|
double camZ;
|
||||||
|
@ -99,9 +103,9 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
|
|
||||||
getGroupsToRender(event.getLayer()).forEach(group -> group.render(viewProjection, camX, camY, camZ));
|
getGroupsToRender(event.getLayer()).forEach(group -> group.render(viewProjection, camX, camY, camZ));
|
||||||
|
|
||||||
GlBufferType.ELEMENT_ARRAY_BUFFER.unbind();
|
GlBufferType.ELEMENT_ARRAY_BUFFER.bind(ebo);
|
||||||
GlBufferType.ARRAY_BUFFER.unbind();
|
GlBufferType.ARRAY_BUFFER.bind(vbo);
|
||||||
GlVertexArray.unbind();
|
GlVertexArray.bind(vao);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<InstancedMaterialGroup<P>> getGroupsToRender(@Nullable RenderLayer layer) {
|
private Stream<InstancedMaterialGroup<P>> getGroupsToRender(@Nullable RenderLayer layer) {
|
||||||
|
|
|
@ -217,7 +217,7 @@ public class SourceFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan the source for <code>#use "..."</code> directives.
|
* Scan the source for {@code #use "..."} directives.
|
||||||
* Records the contents of the directive into an {@link Import} object, and marks the directive for elision.
|
* Records the contents of the directive into an {@link Import} object, and marks the directive for elision.
|
||||||
* @param elisions
|
* @param elisions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -14,14 +14,14 @@ public interface FlatLit<D extends InstanceData & FlatLit<D>> {
|
||||||
/**
|
/**
|
||||||
* @param blockLight An integer in the range [0, 15] representing the
|
* @param blockLight An integer in the range [0, 15] representing the
|
||||||
* amount of block light this instance should receive.
|
* amount of block light this instance should receive.
|
||||||
* @return <code>this</code>
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
D setBlockLight(int blockLight);
|
D setBlockLight(int blockLight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param skyLight An integer in the range [0, 15] representing the
|
* @param skyLight An integer in the range [0, 15] representing the
|
||||||
* amount of sky light this instance should receive.
|
* amount of sky light this instance should receive.
|
||||||
* @return <code>this</code>
|
* @return {@code this}
|
||||||
*/
|
*/
|
||||||
D setSkyLight(int skyLight);
|
D setSkyLight(int skyLight);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class WorldModel implements Model {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It is expected that <code>renderWorld.getShade(...)</code> returns a constant.
|
* It is expected that {@code renderWorld.getShade(...)} returns a constant.
|
||||||
*/
|
*/
|
||||||
public WorldModel(BlockAndTintGetter renderWorld, RenderType layer, Collection<StructureTemplate.StructureBlockInfo> blocks, String name) {
|
public WorldModel(BlockAndTintGetter renderWorld, RenderType layer, Collection<StructureTemplate.StructureBlockInfo> blocks, String name) {
|
||||||
reader = Formats.BLOCK.createReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks));
|
reader = Formats.BLOCK.createReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks));
|
||||||
|
|
|
@ -15,11 +15,11 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
* An object describing a shader program that can be loaded by flywheel.
|
* An object describing a shader program that can be loaded by flywheel.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* These are defined through json. All ProgramSpecs in <code>assets/modid/flywheel/programs</code> are parsed and
|
* These are defined through json. All ProgramSpecs in {@code assets/modid/flywheel/programs} are parsed and
|
||||||
* processed. One ProgramSpec typically specifies one "material" that can be used in game to render things.
|
* processed. One ProgramSpec typically specifies one "material" that can be used in game to render things.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* All shader source files in <code>assets/modid/flywheel/shaders</code> are completely loaded and parsed into
|
* All shader source files in {@code assets/modid/flywheel/shaders} are completely loaded and parsed into
|
||||||
* {@link SourceFile SourceFiles}, but not compiled until one of them is
|
* {@link SourceFile SourceFiles}, but not compiled until one of them is
|
||||||
* referenced by a ProgramSpec.
|
* referenced by a ProgramSpec.
|
||||||
* </p>
|
* </p>
|
||||||
|
|
|
@ -21,4 +21,19 @@ public interface BufferUploaderAccessor {
|
||||||
static void flywheel$setLastEBO(int id) {
|
static void flywheel$setLastEBO(int id) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Accessor("lastIndexBufferObject")
|
||||||
|
static int flywheel$getLastEBO() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Accessor("lastVertexBufferObject")
|
||||||
|
static int flywheel$getLastVBO() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Accessor("lastVertexArrayObject")
|
||||||
|
static int flywheel$getLastVAO() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue