Better state restore in InstancingEngine

- Attempt to fix optifine issues
 - Replace <code> with {@code}
This commit is contained in:
Jozufozu 2022-01-05 11:44:52 -08:00
parent 8224e47619
commit e0342c4b78
13 changed files with 55 additions and 21 deletions

View file

@ -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
* 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() {
return true;

View file

@ -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
* 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() {
return true;

View file

@ -12,10 +12,17 @@ public class GlVertexArray extends GlObject {
setHandle(GlStateManager._glGenVertexArrays());
}
public static void bind(int vao) {
GlStateManager._glBindVertexArray(vao);
BufferUploaderAccessor.flywheel$setLastVAO(vao);
}
public void bind() {
int handle = handle();
GlStateManager._glBindVertexArray(handle);
BufferUploaderAccessor.flywheel$setLastVAO(handle);
bind(handle());
}
public static int getBoundVertexArray() {
return BufferUploaderAccessor.flywheel$getLastVAO();
}
public static void unbind() {

View file

@ -50,4 +50,12 @@ public enum GlBufferType {
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;
};
}
}

View file

@ -4,7 +4,7 @@ import org.lwjgl.opengl.GLCapabilities;
/**
* 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 {
/**

View file

@ -65,13 +65,13 @@ public abstract class AbstractInstance implements Instance, LightListener {
* When an instance is reset, the instance is deleted and re-created.
*
* <p>
* Just before {@link #update()} would be called, <code>shouldReset()</code> is checked.
* If this function returns <code>true</code>, then this instance will be {@link #remove removed},
* Just before {@link #update()} would be called, {@code shouldReset()} is checked.
* 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
* acquisition compared to trying to update everything within the lifetime of an instance.
* </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() {
return false;

View file

@ -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.
* If this function returns <code>true</code>, then this instance will be {@link #remove removed},
* Just before {@link #update()} would be called, {@code shouldReset()} is checked.
* 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
* 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() {
return blockEntity.getBlockState() != blockState;

View file

@ -79,6 +79,10 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
*/
@Override
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 camY;
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));
GlBufferType.ELEMENT_ARRAY_BUFFER.unbind();
GlBufferType.ARRAY_BUFFER.unbind();
GlVertexArray.unbind();
GlBufferType.ELEMENT_ARRAY_BUFFER.bind(ebo);
GlBufferType.ARRAY_BUFFER.bind(vbo);
GlVertexArray.bind(vao);
}
private Stream<InstancedMaterialGroup<P>> getGroupsToRender(@Nullable RenderLayer layer) {

View file

@ -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.
* @param elisions
*/

View file

@ -14,14 +14,14 @@ public interface FlatLit<D extends InstanceData & FlatLit<D>> {
/**
* @param blockLight An integer in the range [0, 15] representing the
* amount of block light this instance should receive.
* @return <code>this</code>
* @return {@code this}
*/
D setBlockLight(int blockLight);
/**
* @param skyLight An integer in the range [0, 15] representing the
* amount of sky light this instance should receive.
* @return <code>this</code>
* @return {@code this}
*/
D setSkyLight(int skyLight);

View file

@ -16,7 +16,7 @@ public class WorldModel implements Model {
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) {
reader = Formats.BLOCK.createReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks));

View file

@ -15,11 +15,11 @@ import net.minecraft.resources.ResourceLocation;
* An object describing a shader program that can be loaded by flywheel.
*
* <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.
* </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
* referenced by a ProgramSpec.
* </p>

View file

@ -21,4 +21,19 @@ public interface BufferUploaderAccessor {
static void flywheel$setLastEBO(int id) {
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();
}
}