Test8Scene
setColorMask
, setDepthMask
and setStencilMask
// Create the normal tile sampler: this.DEBUG("Creating normal tile sampler...") let ts = new TileSampler("fragmentNormalSampler", normProd); ts.setStoreParent(false); ts.setStoreInvisible(false);/
world .createEntity() .addComponent('transform') .addComponent('terrain', terrain) .addComponent('program', p3) .addComponent('meshbuffers', quad.getBuffers())
world.registerSystem('terrain', (entity: Entity) => { let terrain = ECS.getTerrain(entity); let mesh = ECS.getMesh(entity); terrain.update(entity); terrain.draw(entity); });
width
is the number of points on one side of the plane grid.// Check if the mesh is procedural: if (name.startsWith('%')) { let parts = name.split('-'); let m: Mesh = null; // Check if we are trying to create a plane: if (parts[0] == '%plane') { // Get the width of the plane: let width = Number(parts[1]); let m = MeshUtils.createPlane(width); } this.CHECK(m != null, `Unsupported procedural shape: ${parts[0]}`) // Store that new mesh: this.meshes.set(name, m); return m; }
// load the quad mesh: // let quad = await rman.loadMesh('quad'); let quad = await rman.loadMesh('%plane-2');/
// load the terrain waves shader: let p3 = await rman.loadProgram('terrainWaves');/
Mesh2: Uploading 0 vertices on GPU
public getVerticesCount(): number { return this.verticesPos / this.vertexSize; } public getIndicesCount(): number { return this.indicesPos / this.indexSize; }
Error: Mesh2: Should handle indices here.
Mesh.createBuffers
method with this section: if (ni != 0) { this.THROW("Should handle indices here.") }
if (ni != 0) { if (this.usage == MeshUsage.GPU_STATIC || this.usage == MeshUsage.GPU_DYNAMIC || this.usage == MeshUsage.GPU_STREAM) { this.indexBuffer = new GPUBuffer(); if (this.usage == MeshUsage.GPU_STATIC) { this.uploadIndexDataToGPU(BufferUsage.STATIC_DRAW); } } else if (this.usage == MeshUsage.CPU) { this.indexBuffer = new CPUBuffer(this.indices); } // AttributeType type; // switch (sizeof(index)) { // case 1: // type = A8UI; // break; // case 2: // type = A16UI; // break; // default: // type = A32UI; // break; // } this.buffers.setIndicesBuffer(new AttributeBuffer(0, 1, this.indicesType, false, this.indexBuffer)); }
GPUBuffer.ts:49 WebGL: INVALID_OPERATION: bindBuffer: buffers bound to non ELEMENT_ARRAY_BUFFER targets can not be bound to ELEMENT_ARRAY_BUFFER target
GPUBuffer.setData
method to also support overriding the target to use for the copy: public setData(buf: ArrayBuffer, u: BufferUsage, tgt: number = -1) { this.size = buf.byteLength; if (tgt == -1) tgt = this.ctx.gl2 != null ? this.ctx.gl2.COPY_WRITE_BUFFER : this.ctx.gl.ARRAY_BUFFER; this.ctx.gl.bindBuffer(tgt, this.bufferId); this.ctx.gl.bufferData(tgt, buf, u); this.ctx.gl.bindBuffer(tgt, null); this.ctx.checkGLError(); }
GPUBuffer.setSubData(…)
eventually.
idx = 0; let offset = 0; for (let r = 0; r < (width - 1); r++) { offset = r * width; for (let c = 0; c < (width - 1); c++) { indices[idx++] = offset + c; indices[idx++] = offset + c + 1; indices[idx++] = offset + c + width; indices[idx++] = offset + c + width; indices[idx++] = offset + c + 1; indices[idx++] = offset + c + width + 1; } }
this.DEBUG('Creating TerrainNode...'); let deform = new Deformation(); let size = 50000.0; let zmin = 0.0; let zmax = 5000.0; let splitFactor = 2; let maxLevel = 16; let terrain = new TerrainNode(deform, size, zmin, zmax, splitFactor, maxLevel);