Skip to content

Commit aeae825

Browse files
mvaligurskyMartin Valigursky
and
Martin Valigursky
authored
Change VertexFormat.defaultInstancingFormat from a property to a function (#4918)
* Change VertexFormat.defaultInstancingFormat from a property to a function * lint Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent ae68126 commit aeae825

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

examples/src/examples/graphics/hardware-instancing.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class HardwareInstancingExample {
105105
}
106106

107107
// create static vertex buffer containing the matrices
108-
const vertexBuffer = new pc.VertexBuffer(app.graphicsDevice, pc.VertexFormat.defaultInstancingFormat, instanceCount, pc.BUFFER_STATIC, matrices);
108+
const vertexBuffer = new pc.VertexBuffer(app.graphicsDevice, pc.VertexFormat.getDefaultInstancingFormat(app.graphicsDevice),
109+
instanceCount, pc.BUFFER_STATIC, matrices);
109110

110111
// initialize instancing using the vertex buffer on meshInstance of the created box
111112
const boxMeshInst = box.render.meshInstances[0];

examples/src/examples/misc/mini-stats.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ class MiniStatsExample {
180180
// add vertex buffer
181181
const vertexCount = 500;
182182
const data = new Float32Array(vertexCount * 16);
183-
vertexBuffer = new pc.VertexBuffer(app.graphicsDevice, pc.VertexFormat.defaultInstancingFormat, vertexCount, pc.BUFFER_STATIC, data);
183+
vertexBuffer = new pc.VertexBuffer(app.graphicsDevice, pc.VertexFormat.getDefaultInstancingFormat(app.graphicsDevice),
184+
vertexCount, pc.BUFFER_STATIC, data);
184185
vertexBuffers.push(vertexBuffer);
185186

186187
// allocate texture

src/deprecated/deprecated.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import { Texture } from '../platform/graphics/texture.js';
5151
import { VertexBuffer } from '../platform/graphics/vertex-buffer.js';
5252
import { VertexFormat } from '../platform/graphics/vertex-format.js';
5353
import { VertexIterator } from '../platform/graphics/vertex-iterator.js';
54+
import { ShaderUtils } from '../platform/graphics/shader-utils.js';
55+
import { GraphicsDeviceAccess } from '../platform/graphics/graphics-device-access.js';
5456

5557
import { PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, LAYERID_IMMEDIATE, LINEBATCH_OVERLAY, LAYERID_WORLD } from '../scene/constants.js';
5658
import { calculateTangents, createBox, createCapsule, createCone, createCylinder, createMesh, createPlane, createSphere, createTorus } from '../scene/procedural.js';
@@ -111,7 +113,6 @@ import {
111113
import { RigidBodyComponent } from '../framework/components/rigid-body/component.js';
112114
import { RigidBodyComponentSystem } from '../framework/components/rigid-body/system.js';
113115
import { basisInitialize } from '../framework/handlers/basis.js';
114-
import { ShaderUtils } from '../platform/graphics/shader-utils.js';
115116

116117
// CORE
117118

@@ -464,6 +465,13 @@ Object.defineProperties(RenderTarget.prototype, {
464465
}
465466
});
466467

468+
Object.defineProperty(VertexFormat, 'defaultInstancingFormat', {
469+
get: function () {
470+
Debug.deprecated('pc.VertexFormat.defaultInstancingFormat is deprecated, use pc.VertexFormat.getDefaultInstancingFormat(graphicsDevice).');
471+
return VertexFormat.getDefaultInstancingFormat(GraphicsDeviceAccess.get());
472+
}
473+
});
474+
467475
VertexFormat.prototype.update = function () {
468476
Debug.deprecated('pc.VertexFormat.update is deprecated, and VertexFormat cannot be changed after it has been created.');
469477
};

src/platform/graphics/vertex-format.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,15 @@ class VertexFormat {
200200
/**
201201
* The {@link VertexFormat} used to store matrices of type {@link Mat4} for hardware instancing.
202202
*
203-
* @type {VertexFormat}
203+
* @param {import('./graphics-device.js').GraphicsDevice} graphicsDevice - The graphics device
204+
* used to create this vertex format.
205+
*
206+
* @returns {VertexFormat} The default instancing vertex format.
204207
*/
205-
static get defaultInstancingFormat() {
208+
static getDefaultInstancingFormat(graphicsDevice) {
206209

207210
if (!VertexFormat._defaultInstancingFormat) {
208-
VertexFormat._defaultInstancingFormat = new VertexFormat(null, [
211+
VertexFormat._defaultInstancingFormat = new VertexFormat(graphicsDevice, [
209212
{ semantic: SEMANTIC_ATTR12, components: 4, type: TYPE_FLOAT32 },
210213
{ semantic: SEMANTIC_ATTR13, components: 4, type: TYPE_FLOAT32 },
211214
{ semantic: SEMANTIC_ATTR14, components: 4, type: TYPE_FLOAT32 },

0 commit comments

Comments
 (0)