Optimize renderer
This commit is contained in:
@@ -12,7 +12,7 @@ import { AIR, CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, Faces, ID_MASK, VOID } from
|
||||
import { AssetManager } from "../assets.ts";
|
||||
import { ChunkWorkerPool } from "../chunk_workers.ts";
|
||||
import { worldgen_mods } from "../mods.ts";
|
||||
import { type FromChunkWorker, TERRAIN_VERTEX_FLOATS } from "../workers/chunk_messages.ts";
|
||||
import type { FaceGroup, FromChunkWorker } from "../workers/chunk_messages.ts";
|
||||
import { create_index_buffer, create_vertex_buffer, destroy_buffer, Texture } from "../renderer/mod.ts";
|
||||
import { crosses_planes } from "../workers/translucent_sort.ts";
|
||||
import { Camera } from "../camera.ts";
|
||||
@@ -37,6 +37,9 @@ export interface Chunk {
|
||||
// bumped on every mesh request so late results from older requests get ignored
|
||||
mesh_version: number;
|
||||
meshes: Partial<Record<RenderLayer, ChunkMesh>>;
|
||||
// the lowest and highest y of its meshes, for frustum culling
|
||||
min_y: number;
|
||||
max_y: number;
|
||||
// only for translucent meshes that have to be sorted again as the camera moves
|
||||
translucent_sort?: TranslucentSort;
|
||||
// blocks its generation put in neighboring chunks (leaves), as x, y, z, numeric id. kept so a neighbor that
|
||||
@@ -49,6 +52,8 @@ export interface ChunkMesh {
|
||||
quad_count: number;
|
||||
// the translucent layer's quads sorted back to front, the others are drawn in order
|
||||
index_buffer?: GPUBuffer;
|
||||
// solid and cutout quads by the way they face, see FACE_GROUPS in chunk_messages.ts
|
||||
groups?: FaceGroup[];
|
||||
}
|
||||
|
||||
interface TranslucentSort {
|
||||
@@ -63,8 +68,6 @@ interface TranslucentSort {
|
||||
applied: number;
|
||||
}
|
||||
|
||||
const FLOATS_PER_QUAD = 4 * TERRAIN_VERTEX_FLOATS;
|
||||
|
||||
export { chunk_key };
|
||||
|
||||
// the block being looked at and which face of it
|
||||
@@ -199,6 +202,8 @@ export class ClientLevel {
|
||||
generated: false,
|
||||
mesh_version: 0,
|
||||
meshes: {},
|
||||
min_y: 0,
|
||||
max_y: 0,
|
||||
};
|
||||
this.chunks.set(chunk_key(x, z), chunk);
|
||||
return chunk;
|
||||
@@ -548,16 +553,15 @@ export class ClientLevel {
|
||||
}
|
||||
|
||||
this.delete_chunk_mesh(chunk);
|
||||
chunk.min_y = message.min_y;
|
||||
chunk.max_y = message.max_y;
|
||||
|
||||
for (const layer of RENDER_LAYERS) {
|
||||
const { vertices, quad_count } = message[layer];
|
||||
const { vertices, quad_count, groups } = message[layer];
|
||||
if (quad_count === 0) {
|
||||
continue;
|
||||
}
|
||||
chunk.meshes[layer] = {
|
||||
vertex_buffer: create_vertex_buffer(vertices.subarray(0, quad_count * FLOATS_PER_QUAD)),
|
||||
quad_count,
|
||||
};
|
||||
chunk.meshes[layer] = { vertex_buffer: create_vertex_buffer(vertices), quad_count, groups };
|
||||
}
|
||||
|
||||
const translucent = message.translucent;
|
||||
|
||||
Reference in New Issue
Block a user