Skip to content

Commit

Permalink
Add static for Blaze3D faces
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Dec 27, 2022
1 parent b0f72d0 commit 4745214
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public static boolean shouldSkipRenderTrain(TrainClient train) {
}

public static String getRenderStatusMessage() {
return "=== NTE Rendering Status ===\n"
return "\n=== NTE Rendering Status ===\n"
+ "Draw Calls: " + MainClient.profiler.drawCallCount
+ ", Batches: " + MainClient.profiler.batchCount
+ "\n"
+ "Faces: " + MainClient.profiler.singleFaceCount + " non-instanced"
+ ", " + MainClient.profiler.instancedFaceCount + " instanced"
+ ", " + (MainClient.profiler.singleFaceCount + MainClient.profiler.instancedFaceCount) + " total"
+ "\n"
+ "Faces via Blaze3D: " + MainClient.profiler.blazeFaceCount
+ "\n"
+ "Loaded Models: " + MainClient.modelManager.loadedRawModels.size()
+ ", Uploaded VAOs: " + MainClient.modelManager.uploadedVertArraysCount
;
Expand Down
8 changes: 8 additions & 0 deletions common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ public class Profiler {
public int batchCount = 0;
public int singleFaceCount = 0;
public int instancedFaceCount = 0;
public int blazeFaceCount;

private int drawCallCountCF = 0;
private int batchCountCF = 0;
private int singleFaceCountCF = 0;
private int instancedFaceCountCF = 0;
private int blazeFaceCountCF = 0;

public void beginFrame() {
drawCallCount = drawCallCountCF;
batchCount = batchCountCF;
singleFaceCount = singleFaceCountCF;
instancedFaceCount = instancedFaceCountCF;
blazeFaceCount = blazeFaceCountCF;
drawCallCountCF = 0;
batchCountCF = 0;
singleFaceCountCF = 0;
instancedFaceCountCF = 0;
blazeFaceCountCF = 0;
}

public void recordBatches(int batchCount) {
Expand All @@ -35,4 +39,8 @@ public void recordDrawCall(int faceCount, boolean instanced) {
singleFaceCountCF += faceCount;
}
}

public void recordBlazeAction(int faceCount) {
blazeFaceCountCF += faceCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cn.zbx1425.sowcer.batch.ShaderProp;
import cn.zbx1425.sowcer.model.VertArrays;
import cn.zbx1425.sowcer.util.AttrUtil;
import cn.zbx1425.sowcer.util.Profiler;
import cn.zbx1425.sowcer.vertex.VertAttrMapping;
import cn.zbx1425.sowcer.vertex.VertAttrState;
import cn.zbx1425.sowcer.math.Matrix4f;
Expand Down Expand Up @@ -32,7 +33,7 @@ public ModelCluster(RawModel source, VertAttrMapping mapping) {
this.uploadedOpaqueParts = VertArrays.createAll(opaqueParts.upload(mapping), mapping, null);
}

public void renderOpaqueOptimized(BatchManager batchManager, Matrix4f pose, int light) {
public void renderOpaqueOptimized(BatchManager batchManager, Matrix4f pose, int light, Profiler profiler) {
// KHRDebug.glDebugMessageInsert(KHRDebug.GL_DEBUG_SOURCE_APPLICATION, KHRDebug.GL_DEBUG_TYPE_MARKER,
// 0, KHRDebug.GL_DEBUG_SEVERITY_NOTIFICATION, "RenderOptimized " + (source.sourceLocation == null ? "unknown" : source.sourceLocation.toString()));
int shaderLightmapUV = AttrUtil.exchangeLightmapUVBits(light);
Expand All @@ -41,12 +42,12 @@ public void renderOpaqueOptimized(BatchManager batchManager, Matrix4f pose, int
), ShaderProp.DEFAULT);
}

public void renderOpaqueUnoptimized(MultiBufferSource vertexConsumers, Matrix4f pose, int light) {
opaqueParts.writeBlazeBuffer(vertexConsumers, pose, light);
public void renderOpaqueUnoptimized(MultiBufferSource vertexConsumers, Matrix4f pose, int light, Profiler profiler) {
opaqueParts.writeBlazeBuffer(vertexConsumers, pose, light, profiler);
}

public void renderTranslucent(MultiBufferSource vertexConsumers, Matrix4f pose, int light) {
translucentParts.writeBlazeBuffer(vertexConsumers, pose, light);
public void renderTranslucent(MultiBufferSource vertexConsumers, Matrix4f pose, int light, Profiler profiler) {
translucentParts.writeBlazeBuffer(vertexConsumers, pose, light, profiler);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cn.zbx1425.sowcer.object.IndexBuf;
import cn.zbx1425.sowcer.object.VertBuf;
import cn.zbx1425.sowcer.util.OffHeapAllocator;
import cn.zbx1425.sowcer.util.Profiler;
import cn.zbx1425.sowcer.vertex.VertAttrMapping;
import cn.zbx1425.sowcer.vertex.VertAttrSrc;
import cn.zbx1425.sowcer.vertex.VertAttrType;
Expand Down Expand Up @@ -318,7 +319,8 @@ public void setRenderType(String type) {
}
}

public void writeBlazeBuffer(VertexConsumer vertexConsumer, Matrix4f matrix, int color, int light) {
public void writeBlazeBuffer(VertexConsumer vertexConsumer, Matrix4f matrix, int color, int light, Profiler profiler) {
if (profiler != null) profiler.recordBlazeAction(faces.size());
for (Face face : faces) {
assert face.vertices.length == 3;
for (int vertIndex : face.vertices) {
Expand Down
6 changes: 4 additions & 2 deletions common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.zbx1425.sowcer.batch.MaterialProp;
import cn.zbx1425.sowcer.model.Model;
import cn.zbx1425.sowcer.util.AttrUtil;
import cn.zbx1425.sowcer.util.Profiler;
import cn.zbx1425.sowcer.vertex.VertAttrMapping;
import cn.zbx1425.sowcer.math.Matrix4f;
import cn.zbx1425.sowcer.math.Vector3f;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void clearAttrStates() {
}
}

public void writeBlazeBuffer(MultiBufferSource vertexConsumers, Matrix4f matrix, int light) {
public void writeBlazeBuffer(MultiBufferSource vertexConsumers, Matrix4f matrix, int light, Profiler profiler) {
if (meshList.isEmpty()) return;
for (Map.Entry<MaterialProp, RawMesh> entry : meshList.entrySet()) {
RenderType renderType = entry.getKey().getBlazeRenderType();
Expand All @@ -169,7 +170,8 @@ public void writeBlazeBuffer(MultiBufferSource vertexConsumers, Matrix4f matrix,
AttrUtil.zeroRotation(resultMatrix);
}

entry.getValue().writeBlazeBuffer(vertexConsumers.getBuffer(renderType), resultMatrix, resultColor, resultLight);
entry.getValue().writeBlazeBuffer(vertexConsumers.getBuffer(renderType),
resultMatrix, resultColor, resultLight, profiler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public void commit(MultiBufferSource vertexConsumers, boolean isOptimized, Profi
if (drawCalls.size() < 1) return;
for (DrawCallCluster drawCall : drawCalls) {
if (isOptimized) {
drawCall.model.renderOpaqueOptimized(batchManager, drawCall.pose, drawCall.light);
drawCall.model.renderOpaqueOptimized(batchManager, drawCall.pose, drawCall.light, profiler);
} else {
drawCall.model.renderOpaqueUnoptimized(vertexConsumers, drawCall.pose, drawCall.light);
drawCall.model.renderOpaqueUnoptimized(vertexConsumers, drawCall.pose, drawCall.light, profiler);
}
}
if (isOptimized) {
Expand All @@ -44,7 +44,7 @@ public void commit(MultiBufferSource vertexConsumers, boolean isOptimized, Profi
GlStateTracker.restore();
}
for (DrawCallCluster drawCall : drawCalls) {
drawCall.model.renderTranslucent(vertexConsumers, drawCall.pose, drawCall.light);
drawCall.model.renderTranslucent(vertexConsumers, drawCall.pose, drawCall.light, profiler);
}
drawCalls.clear();
}
Expand Down

0 comments on commit 4745214

Please sign in to comment.