Viewport tweeks
This commit is contained in:
@@ -4,6 +4,7 @@ package me.cortex.voxy.client.core.rendering;
|
||||
// could maybe tosomething else
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import me.cortex.voxy.client.core.gl.GlBuffer;
|
||||
import me.cortex.voxy.client.core.model.ModelManager;
|
||||
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
|
||||
@@ -23,6 +24,7 @@ import org.joml.FrustumIntersection;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
|
||||
@@ -55,6 +57,8 @@ public abstract class AbstractFarWorldRenderer <T extends Viewport> {
|
||||
|
||||
protected FrustumIntersection frustum;
|
||||
|
||||
private final List<T> viewports = new ArrayList<>();
|
||||
|
||||
private final ConcurrentLinkedDeque<Mapper.StateEntry> blockStateUpdates = new ConcurrentLinkedDeque<>();
|
||||
private final ConcurrentLinkedDeque<Mapper.BiomeEntry> biomeUpdates = new ConcurrentLinkedDeque<>();
|
||||
public AbstractFarWorldRenderer(int geometrySize, int maxSections) {
|
||||
@@ -153,5 +157,15 @@ public abstract class AbstractFarWorldRenderer <T extends Viewport> {
|
||||
return this.models;
|
||||
}
|
||||
|
||||
public abstract T createViewport();
|
||||
public final T createViewport() {
|
||||
var viewport = createViewport0();
|
||||
this.viewports.add(viewport);
|
||||
return viewport;
|
||||
}
|
||||
|
||||
final void removeViewport(T viewport) {
|
||||
this.viewports.remove(viewport);
|
||||
}
|
||||
|
||||
protected abstract T createViewport0();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.cortex.voxy.client.core.rendering;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
@@ -21,6 +22,7 @@ public class GeometryManager {
|
||||
private final Long2IntOpenHashMap pos2id = new Long2IntOpenHashMap();
|
||||
private final LongArrayList id2pos = new LongArrayList();
|
||||
private final ObjectArrayList<SectionMeta> sectionMetadata = new ObjectArrayList<>();
|
||||
private final IntArrayList markSectionIds = new IntArrayList();//Section ids to mark as visible (either due to being new, or swapping)
|
||||
|
||||
private final GlBuffer sectionMetaBuffer;
|
||||
private final BufferArena geometryBuffer;
|
||||
@@ -31,7 +33,8 @@ public class GeometryManager {
|
||||
this.pos2id.defaultReturnValue(-1);
|
||||
}
|
||||
|
||||
void uploadResults() {
|
||||
IntArrayList uploadResults() {
|
||||
this.markSectionIds.clear();
|
||||
while (!this.buildResults.isEmpty()) {
|
||||
var result = this.buildResults.pop();
|
||||
boolean isDelete = result.geometryBuffer == null;
|
||||
@@ -66,6 +69,7 @@ public class GeometryManager {
|
||||
}
|
||||
long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long) SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE);
|
||||
swapMeta.writeMetadata(ptr);
|
||||
this.markSectionIds.add(id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -102,6 +106,7 @@ public class GeometryManager {
|
||||
this.sectionMetadata.add(meta);
|
||||
long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long)SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE);
|
||||
meta.writeMetadata(ptr);
|
||||
this.markSectionIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +117,7 @@ public class GeometryManager {
|
||||
|
||||
result.free();
|
||||
}
|
||||
return this.markSectionIds;
|
||||
}
|
||||
|
||||
public void enqueueResult(BuiltSection sectionGeometry) {
|
||||
|
||||
@@ -207,9 +207,8 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer<Gl46Viewport>
|
||||
RenderLayer.getTranslucent().endDrawing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Gl46Viewport createViewport() {
|
||||
return new Gl46Viewport(this.maxSections);
|
||||
protected Gl46Viewport createViewport0() {
|
||||
return new Gl46Viewport(this, this.maxSections);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,55 +1,22 @@
|
||||
package me.cortex.voxy.client.core.rendering;
|
||||
|
||||
import me.cortex.voxy.client.core.gl.GlBuffer;
|
||||
import me.cortex.voxy.client.core.gl.shader.Shader;
|
||||
import me.cortex.voxy.client.core.gl.shader.ShaderType;
|
||||
import me.cortex.voxy.client.core.rendering.util.UploadStream;
|
||||
import me.cortex.voxy.client.mixin.joml.AccessFrustumIntersection;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.GL11C;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opengl.ARBIndirectParameters.GL_PARAMETER_BUFFER_ARB;
|
||||
import static org.lwjgl.opengl.ARBIndirectParameters.glMultiDrawElementsIndirectCountARB;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL14C.glBlendFuncSeparate;
|
||||
import static org.lwjgl.opengl.GL30.glBindVertexArray;
|
||||
import static org.lwjgl.opengl.GL30C.GL_R8UI;
|
||||
import static org.lwjgl.opengl.GL30C.GL_RED_INTEGER;
|
||||
import static org.lwjgl.opengl.GL40C.GL_DRAW_INDIRECT_BUFFER;
|
||||
import static org.lwjgl.opengl.GL42.GL_BLEND;
|
||||
import static org.lwjgl.opengl.GL42.GL_CULL_FACE;
|
||||
import static org.lwjgl.opengl.GL42.GL_DEPTH_TEST;
|
||||
import static org.lwjgl.opengl.GL42.GL_ONE;
|
||||
import static org.lwjgl.opengl.GL42.GL_ONE_MINUS_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL42.GL_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL42.GL_TEXTURE_2D;
|
||||
import static org.lwjgl.opengl.GL42.GL_TEXTURE_BINDING_2D;
|
||||
import static org.lwjgl.opengl.GL42.GL_UNSIGNED_BYTE;
|
||||
import static org.lwjgl.opengl.GL42.GL_UNSIGNED_INT;
|
||||
import static org.lwjgl.opengl.GL42.glBindTexture;
|
||||
import static org.lwjgl.opengl.GL42.glColorMask;
|
||||
import static org.lwjgl.opengl.GL42.glDepthMask;
|
||||
import static org.lwjgl.opengl.GL42.glDisable;
|
||||
import static org.lwjgl.opengl.GL42.glEnable;
|
||||
import static org.lwjgl.opengl.GL42.*;
|
||||
import static org.lwjgl.opengl.GL43.*;
|
||||
import static org.lwjgl.opengl.GL45C.glClearNamedBufferData;
|
||||
|
||||
public class Gl46Viewport extends Viewport {
|
||||
public class Gl46Viewport extends Viewport<Gl46Viewport, Gl46FarWorldRenderer> {
|
||||
GlBuffer visibilityBuffer;
|
||||
public Gl46Viewport(int maxSections) {
|
||||
public Gl46Viewport(Gl46FarWorldRenderer renderer, int maxSections) {
|
||||
super(renderer);
|
||||
this.visibilityBuffer = new GlBuffer(maxSections*4L);
|
||||
glClearNamedBufferData(this.visibilityBuffer.id, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, new int[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
protected void delete0() {
|
||||
this.visibilityBuffer.free();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package me.cortex.voxy.client.core.rendering;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public abstract class Viewport {
|
||||
public abstract class Viewport <A extends Viewport<A,T>, T extends AbstractFarWorldRenderer<A>> {
|
||||
private final T renderer;
|
||||
|
||||
int frameId;
|
||||
Matrix4f projection;
|
||||
Matrix4f modelView;
|
||||
@@ -10,22 +12,31 @@ public abstract class Viewport {
|
||||
double cameraY;
|
||||
double cameraZ;
|
||||
|
||||
public abstract void delete();
|
||||
protected Viewport(T renderer) {
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
public Viewport setProjection(Matrix4f projection) {
|
||||
public final void delete() {
|
||||
this.delete0();
|
||||
this.renderer.removeViewport((A) this);
|
||||
}
|
||||
|
||||
protected abstract void delete0();
|
||||
|
||||
public A setProjection(Matrix4f projection) {
|
||||
this.projection = projection;
|
||||
return this;
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public Viewport setModelView(Matrix4f modelView) {
|
||||
public A setModelView(Matrix4f modelView) {
|
||||
this.modelView = modelView;
|
||||
return this;
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public Viewport setCamera(double x, double y, double z) {
|
||||
public A setCamera(double x, double y, double z) {
|
||||
this.cameraX = x;
|
||||
this.cameraY = y;
|
||||
this.cameraZ = z;
|
||||
return this;
|
||||
return (A) this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user