Simplify push face code

This commit is contained in:
2026-03-14 20:12:58 -03:00
parent 9557d942d4
commit 86092e0083
2 changed files with 36 additions and 51 deletions
+24 -36
View File
@@ -26,16 +26,13 @@ function push_vertex(
return i; return i;
} }
export function pushFrontFace( export function push_front_face(
vertices: Float32Array, vertices: Float32Array,
i: number, i: number,
texture: Texture, texture: Texture,
x: number, x: number,
y: number, y: number,
z: number, z: number,
w: number,
h: number,
d: number,
sx: number, sx: number,
sy: number, sy: number,
sw: number, sw: number,
@@ -45,9 +42,9 @@ export function pushFrontFace(
b = 1, b = 1,
a = 1, a = 1,
) { ) {
const x2 = x + w; const x2 = x + 1;
const y2 = y + h; const y2 = y + 1;
const z2 = z + d; const z2 = z + 1;
const u0 = sx / texture.width; const u0 = sx / texture.width;
const v0 = sy / texture.height; const v0 = sy / texture.height;
@@ -65,16 +62,13 @@ export function pushFrontFace(
return i; return i;
} }
export function pushBackFace( export function push_back_face(
vertices: Float32Array, vertices: Float32Array,
i: number, i: number,
texture: Texture, texture: Texture,
x: number, x: number,
y: number, y: number,
z: number, z: number,
w: number,
h: number,
d: number,
sx: number, sx: number,
sy: number, sy: number,
sw: number, sw: number,
@@ -84,7 +78,8 @@ export function pushBackFace(
b = 1, b = 1,
a = 1, a = 1,
) { ) {
const x2 = x + w, y2 = y + h; const x2 = x + 1;
const y2 = y + 1;
const u0 = sx / texture.width; const u0 = sx / texture.width;
const v0 = sy / texture.height; const v0 = sy / texture.height;
@@ -102,16 +97,13 @@ export function pushBackFace(
return i; return i;
} }
export function pushLeftFace( export function push_left_face(
vertices: Float32Array, vertices: Float32Array,
i: number, i: number,
texture: Texture, texture: Texture,
x: number, x: number,
y: number, y: number,
z: number, z: number,
w: number,
h: number,
d: number,
sx: number, sx: number,
sy: number, sy: number,
sw: number, sw: number,
@@ -121,8 +113,8 @@ export function pushLeftFace(
b = 1, b = 1,
a = 1, a = 1,
) { ) {
const y2 = y + h; const y2 = y + 1;
const z2 = z + d; const z2 = z + 1;
const u0 = sx / texture.width; const u0 = sx / texture.width;
const v0 = sy / texture.height; const v0 = sy / texture.height;
@@ -140,16 +132,13 @@ export function pushLeftFace(
return i; return i;
} }
export function pushRightFace( export function push_right_face(
vertices: Float32Array, vertices: Float32Array,
i: number, i: number,
texture: Texture, texture: Texture,
x: number, x: number,
y: number, y: number,
z: number, z: number,
w: number,
h: number,
d: number,
sx: number, sx: number,
sy: number, sy: number,
sw: number, sw: number,
@@ -159,34 +148,33 @@ export function pushRightFace(
b = 1, b = 1,
a = 1, a = 1,
) { ) {
const x2 = x + w, y2 = y + h; const x2 = x + 1;
const y2 = y + 1;
const z2 = z + 1;
const u0 = sx / texture.width; const u0 = sx / texture.width;
const v0 = sy / texture.height; const v0 = sy / texture.height;
const u1 = (sx + sw) / texture.width; const u1 = (sx + sw) / texture.width;
const v1 = (sy + sh) / texture.height; const v1 = (sy + sh) / texture.height;
i = push_vertex(vertices, i, x2, y, z + d, u0, v1, r, g, b, a); i = push_vertex(vertices, i, x2, y, z2, u0, v1, r, g, b, a);
i = push_vertex(vertices, i, x2, y, z, u1, v1, r, g, b, a); i = push_vertex(vertices, i, x2, y, z, u1, v1, r, g, b, a);
i = push_vertex(vertices, i, x2, y2, z, u1, v0, r, g, b, a); i = push_vertex(vertices, i, x2, y2, z, u1, v0, r, g, b, a);
i = push_vertex(vertices, i, x2, y, z + d, u0, v1, r, g, b, a); i = push_vertex(vertices, i, x2, y, z2, u0, v1, r, g, b, a);
i = push_vertex(vertices, i, x2, y2, z, u1, v0, r, g, b, a); i = push_vertex(vertices, i, x2, y2, z, u1, v0, r, g, b, a);
i = push_vertex(vertices, i, x2, y2, z + d, u0, v0, r, g, b, a); i = push_vertex(vertices, i, x2, y2, z2, u0, v0, r, g, b, a);
return i; return i;
} }
export function pushTopFace( export function push_top_face(
vertices: Float32Array, vertices: Float32Array,
i: number, i: number,
texture: Texture, texture: Texture,
x: number, x: number,
y: number, y: number,
z: number, z: number,
w: number,
h: number,
d: number,
sx: number, sx: number,
sy: number, sy: number,
sw: number, sw: number,
@@ -196,7 +184,9 @@ export function pushTopFace(
b = 1, b = 1,
a = 1, a = 1,
) { ) {
const x2 = x + w, z2 = z + d, y2 = y + h; const x2 = x + 1;
const z2 = z + 1;
const y2 = y + 1;
const u0 = sx / texture.width; const u0 = sx / texture.width;
const v0 = sy / texture.height; const v0 = sy / texture.height;
@@ -214,16 +204,13 @@ export function pushTopFace(
return i; return i;
} }
export function pushBottomFace( export function push_bottom_face(
vertices: Float32Array, vertices: Float32Array,
i: number, i: number,
texture: Texture, texture: Texture,
x: number, x: number,
y: number, y: number,
z: number, z: number,
w: number,
h: number,
d: number,
sx: number, sx: number,
sy: number, sy: number,
sw: number, sw: number,
@@ -233,7 +220,8 @@ export function pushBottomFace(
b = 1, b = 1,
a = 1, a = 1,
) { ) {
const x2 = x + w, z2 = z + d; const x2 = x + 1;
const z2 = z + 1;
const u0 = sx / texture.width; const u0 = sx / texture.width;
const v0 = sy / texture.height; const v0 = sy / texture.height;
+12 -15
View File
@@ -5,12 +5,12 @@ import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.
import { import {
flush_buffer, flush_buffer,
gl, gl,
pushBackFace, push_back_face,
pushBottomFace, push_bottom_face,
pushFrontFace, push_front_face,
pushLeftFace, push_left_face,
pushRightFace, push_right_face,
pushTopFace, push_top_face,
set_current_texture, set_current_texture,
} from "$/client/renderer/mod.ts"; } from "$/client/renderer/mod.ts";
import { Camera } from "$/client/components/camera.ts"; import { Camera } from "$/client/components/camera.ts";
@@ -40,12 +40,12 @@ function render_chunk_opaque(chunk: Chunk) {
} }
const FACE_PUSHING_FUNCTIONS = { const FACE_PUSHING_FUNCTIONS = {
top: pushTopFace, top: push_top_face,
bottom: pushBottomFace, bottom: push_bottom_face,
front: pushFrontFace, front: push_front_face,
back: pushBackFace, back: push_back_face,
left: pushLeftFace, left: push_left_face,
right: pushRightFace, right: push_right_face,
} as const; } as const;
function make_chunk_mesh(chunk: Chunk, dimension: Dimension, camera: Camera) { function make_chunk_mesh(chunk: Chunk, dimension: Dimension, camera: Camera) {
@@ -139,9 +139,6 @@ function make_chunk_mesh(chunk: Chunk, dimension: Dimension, camera: Camera) {
wx, wx,
y, y,
wz, wz,
1,
1,
1,
region.x * TEXTURE_SIZE, region.x * TEXTURE_SIZE,
region.y * TEXTURE_SIZE, region.y * TEXTURE_SIZE,
TEXTURE_SIZE, TEXTURE_SIZE,