Skip to content

Commit a723aa6

Browse files
committed
specify fb size in constructor
1 parent 52bd5f4 commit a723aa6

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/main/java/me/cortex/voxy/client/core/model/bakery/SoftwareModelTextureBakery.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class SoftwareModelTextureBakery {
5252
private static final Matrix4f[] VIEWS = new Matrix4f[6];
5353

5454
private final ReuseVertexConsumer vc = new ReuseVertexConsumer();
55-
private final SoftwareRasterizer rasterizer = new SoftwareRasterizer();
55+
private final SoftwareRasterizer rasterizer = new SoftwareRasterizer(ModelFactory.MODEL_TEXTURE_SIZE);
5656

5757
public SoftwareModelTextureBakery() {
5858
}
@@ -246,6 +246,7 @@ public int renderToOutput(BlockState state, long outputBuffer) {
246246
if (!this.vc.isEmpty()) {//only render if there... is shit to render
247247
for (int i = 0; i < VIEWS.length; i++) {
248248
this.rasterizer.setFaceCull(i==1||i==2||i==4);
249+
this.rasterizer.clear();
249250

250251
this.rasterizer.raster(VIEWS[i], this.vc);
251252
UnsafeUtil.memcpy(this.rasterizer.getRawFramebuffer(), outputBuffer+(SINGLE_FACE_OUTPUT_SIZE*i));
@@ -262,6 +263,7 @@ public int renderToOutput(BlockState state, long outputBuffer) {
262263
isAnyDarkend |= this.vc.anyDarkendTex;
263264

264265
this.rasterizer.setFaceCull(i==1||i==2||i==4);
266+
this.rasterizer.clear();
265267

266268
//The projection matrix
267269
this.rasterizer.raster(VIEWS[i], this.vc);

src/main/java/me/cortex/voxy/client/core/model/bakery/SoftwareRasterizer.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import java.util.Random;
1414

1515
public class SoftwareRasterizer {
16-
public static final int TARGET_SIZE = ModelFactory.MODEL_TEXTURE_SIZE;
17-
1816
private final Vector4f scratch = new Vector4f();
1917

2018
private final Vector3f scratch1 = new Vector3f();
@@ -38,7 +36,9 @@ public class SoftwareRasterizer {
3836

3937
private static final long DEPTH_MASK = ((1L<<24)-1)<<(64-24);
4038
private static final long CLEAR_VALUE = DEPTH_MASK;//set the depth to max value and rest of bits to 0
41-
private final long[] framebuffer = new long[TARGET_SIZE*TARGET_SIZE];
39+
40+
private final int targetSize;
41+
private final long[] framebuffer;
4242

4343
private boolean cullBackFace;
4444
private boolean doTheBlending;
@@ -47,7 +47,9 @@ public class SoftwareRasterizer {
4747
private int samplerHeight;
4848
private int[] samplerTexture;
4949

50-
public SoftwareRasterizer() {
50+
public SoftwareRasterizer(int targetSize) {
51+
this.targetSize = targetSize;
52+
this.framebuffer = new long[targetSize*targetSize];
5153
}
5254

5355
public void setFaceCull(boolean isBackFaceCulling) {
@@ -71,12 +73,17 @@ private int sampleTexture(float u, float v) {
7173
return this.samplerTexture[this.samplerWidth*pv+pu];
7274
}
7375

74-
public void raster(Matrix4f mvp, ReuseVertexConsumer vertices) {
76+
public void clear() {
7577
Arrays.fill(this.framebuffer, CLEAR_VALUE);
78+
}
7679

77-
int qc = vertices.quadCount();
78-
for (int i = 0; i < qc; i++) {
79-
this.rasterQuad(mvp, vertices.getAddress()+ReuseVertexConsumer.VERTEX_FORMAT_SIZE*4*i);
80+
public void raster(Matrix4f mvp, ReuseVertexConsumer vertices) {
81+
this.raster(mvp, vertices.getAddress(), vertices.quadCount());
82+
}
83+
public void raster(Matrix4f mvp, long verticesAddr, int quadCount) {
84+
if (quadCount == 0) return;
85+
for (int i = 0; i < quadCount; i++) {
86+
this.rasterQuad(mvp, verticesAddr+ReuseVertexConsumer.VERTEX_FORMAT_SIZE*4L*i);
8087
}
8188
//Arrays.fill(this.framebuffer, -1);
8289
}
@@ -132,9 +139,9 @@ private void rasterTriangle(boolean orZero) {
132139
}*/
133140

134141
int minX = Math.max((int) Math.floor(Math.min(Math.min(v1.x, v2.x), v3.x)), 0);
135-
int maxX = Math.min((int) Math.ceil(Math.max(Math.max(v1.x, v2.x), v3.x)), TARGET_SIZE-1);
142+
int maxX = Math.min((int) Math.ceil(Math.max(Math.max(v1.x, v2.x), v3.x)), this.targetSize-1);
136143
int minY = Math.max((int) Math.floor(Math.min(Math.min(v1.y, v2.y), v3.y)), 0);
137-
int maxY = Math.min((int) Math.ceil(Math.max(Math.max(v1.y, v2.y), v3.y)), TARGET_SIZE-1);
144+
int maxY = Math.min((int) Math.ceil(Math.max(Math.max(v1.y, v2.y), v3.y)), this.targetSize-1);
138145

139146
float invArea = 1.0f/area;
140147
for (int py = minY; py<=maxY; py++) {
@@ -148,7 +155,7 @@ private void rasterTriangle(boolean orZero) {
148155
//Dont need to worry about perspective correction afak as it should already be all correct
149156

150157
//pixel is inside the triangle
151-
this.rasterPixel(px+py*TARGET_SIZE, w1, w2, w3);
158+
this.rasterPixel(px+py*this.targetSize, w1, w2, w3);
152159
}
153160
}
154161
}
@@ -171,6 +178,7 @@ private void rasterPixel(int index, float b1, float b2, float b3) {//Barry coord
171178

172179

173180
final int ALPHA_CUTOFF_THRESHOLD = 0;
181+
//TODO: meta&1 OR if we are blending
174182
if ((meta&1)!=0 && (colour>>>24)<=ALPHA_CUTOFF_THRESHOLD) {//Discard on small alpha
175183
return;
176184
}
@@ -244,7 +252,7 @@ private void loadTransformPos(Matrix4f transform, long addr, int vert, Vector3f
244252
var vec = transform.transformProject(this.scratch);
245253
if (Math.abs(this.scratch.w-1.0f)>0.000001f)
246254
throw new IllegalStateException();
247-
out.set(maintainPrecision(Math.fma(vec.x, 0.5f, 0.5f)*TARGET_SIZE), maintainPrecision(Math.fma(vec.y, 0.5f, 0.5f)*TARGET_SIZE), vec.z);//TODO: dont know if z transform is correct
255+
out.set(maintainPrecision(Math.fma(vec.x, 0.5f, 0.5f)*this.targetSize), maintainPrecision(Math.fma(vec.y, 0.5f, 0.5f)*this.targetSize), vec.z);//TODO: dont know if z transform is correct
248256
}
249257

250258

0 commit comments

Comments
 (0)