Skip to content

Commit

Permalink
Mesh can be created and used without vertex attributes (#6232)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky authored Apr 9, 2024
1 parent 4ab0ace commit 9ace86a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/scene/mesh-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,13 @@ class MeshInstance {
this.material = material; // The material with which to render this instance

this._shaderDefs = MASK_AFFECT_DYNAMIC << 16; // 2 byte toggles, 2 bytes light mask; Default value is no toggles and mask = pc.MASK_AFFECT_DYNAMIC
this._shaderDefs |= mesh.vertexBuffer.format.hasUv0 ? SHADERDEF_UV0 : 0;
this._shaderDefs |= mesh.vertexBuffer.format.hasUv1 ? SHADERDEF_UV1 : 0;
this._shaderDefs |= mesh.vertexBuffer.format.hasColor ? SHADERDEF_VCOLOR : 0;
this._shaderDefs |= mesh.vertexBuffer.format.hasTangents ? SHADERDEF_TANGENTS : 0;
if (mesh.vertexBuffer) {
const format = mesh.vertexBuffer.format;
this._shaderDefs |= format.hasUv0 ? SHADERDEF_UV0 : 0;
this._shaderDefs |= format.hasUv1 ? SHADERDEF_UV1 : 0;
this._shaderDefs |= format.hasColor ? SHADERDEF_VCOLOR : 0;
this._shaderDefs |= format.hasTangents ? SHADERDEF_TANGENTS : 0;
}

// Render options
this.layer = LAYER_WORLD; // legacy
Expand Down Expand Up @@ -517,7 +520,7 @@ class MeshInstance {
if (!shaderInstance.shader) {

const shader = mat.getShaderVariant(this.mesh.device, scene, shaderDefs, null, shaderPass, sortedLights,
viewUniformFormat, viewBindGroupFormat, this._mesh.vertexBuffer.format);
viewUniformFormat, viewBindGroupFormat, this._mesh.vertexBuffer?.format);

// add it to the material variants cache
mat.variants.set(variantKey, shader);
Expand Down
3 changes: 2 additions & 1 deletion src/scene/mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,8 @@ class Mesh extends RefCountedObject {

// if we don't have index buffer, create new one, otherwise update existing one
if (this.indexBuffer.length <= 0 || !this.indexBuffer[0]) {
const createFormat = this._geometryData.maxVertices > 0xffff ? INDEXFORMAT_UINT32 : INDEXFORMAT_UINT16;
const maxVertices = this._geometryData.maxVertices;
const createFormat = ((maxVertices > 0xffff) || (maxVertices === 0)) ? INDEXFORMAT_UINT32 : INDEXFORMAT_UINT16;
const options = this._storageIndex ? { storage: true } : undefined;
this.indexBuffer[0] = new IndexBuffer(this.device, createFormat, this._geometryData.maxIndices, this._geometryData.indicesUsage, undefined, options);
}
Expand Down

0 comments on commit 9ace86a

Please sign in to comment.