Skip to content

Commit

Permalink
Rename resources in ModelExperimental
Browse files Browse the repository at this point in the history
  • Loading branch information
Janine Liu committed May 20, 2022
1 parent 2b923a0 commit 407f657
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Source/Scene/ModelExperimental/FeatureIdPipelineStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ function generateImplicitFeatureIdAttribute(
usage: BufferUsage.STATIC_DRAW,
});
vertexBuffer.vertexArrayDestroyable = false;
model._resources.push(vertexBuffer);
model._pipelineResources.push(vertexBuffer);
} else {
value = [implicitFeatureIds.offset];
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/ModelExperimental/InstancingPipelineStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function processFeatureIdAttributes(
usage: BufferUsage.STATIC_DRAW,
});
vertexBuffer.vertexArrayDestroyable = false;
model._resources.push(vertexBuffer);
model._pipelineResources.push(vertexBuffer);

instancingVertexAttributes.push({
index: renderResources.attributeIndex++,
Expand Down Expand Up @@ -381,7 +381,7 @@ function processMatrixAttributes(node, count, renderResources, frameState) {
});
// Destruction of resources allocated by the ModelExperimental is handled by ModelExperimental.destroy().
transformsVertexBuffer.vertexArrayDestroyable = false;
renderResources.model._resources.push(transformsVertexBuffer);
renderResources.model._pipelineResources.push(transformsVertexBuffer);

const vertexSizeInFloats = 12;
const componentByteSize = ComponentDatatype.getSizeInBytes(
Expand Down
12 changes: 6 additions & 6 deletions Source/Scene/ModelExperimental/ModelExperimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default function ModelExperimental(options) {
this._featureTableIdDirty = true;

// Keeps track of resources that need to be destroyed when the draw commands are reset.
this._resources = [];
this._pipelineResources = [];

// Keeps track of resources that need to be destroyed when the Model is destroyed.
this._modelResources = [];
Expand Down Expand Up @@ -1110,7 +1110,7 @@ ModelExperimental.prototype.resetDrawCommands = function () {
if (!this._drawCommandsBuilt) {
return;
}
this.destroyResources();
this.destroyPipelineResources();
this._drawCommandsBuilt = false;
};

Expand Down Expand Up @@ -1464,7 +1464,7 @@ ModelExperimental.prototype.destroy = function () {
}
}

this.destroyResources();
this.destroyPipelineResources();
this.destroyModelResources();

// Only destroy the ClippingPlaneCollection if this is the owner.
Expand Down Expand Up @@ -1494,12 +1494,12 @@ ModelExperimental.prototype.destroy = function () {
* Destroys resources generated in the pipeline stages.
* @private
*/
ModelExperimental.prototype.destroyResources = function () {
const resources = this._resources;
ModelExperimental.prototype.destroyPipelineResources = function () {
const resources = this._pipelineResources;
for (let i = 0; i < resources.length; i++) {
resources[i].destroy();
}
this._resources = [];
this._pipelineResources = [];
};

/**
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/ModelExperimental/PickingPipelineStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PickingPipelineStage.process = function (
const pickObject = buildPickObject(renderResources);

const pickId = context.createPickId(pickObject);
model._resources.push(pickId);
model._pipelineResources.push(pickId);
shaderBuilder.addUniform(
"vec4",
"czm_pickColor",
Expand Down Expand Up @@ -157,7 +157,7 @@ function processInstancedPickIds(renderResources, instances, context) {

const model = renderResources.model;

const modelResources = model._resources;
const modelResources = model._pipelineResources;
for (let i = 0; i < instanceCount; i++) {
const pickObject = buildPickObject(renderResources, i);

Expand Down
13 changes: 8 additions & 5 deletions Source/Scene/ModelExperimental/SceneMode2DPipelineStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SceneTransforms from "../SceneTransforms.js";
const scratchModelMatrix = new Matrix4();

/**
* The scene mode 2D stage processes the vertex attributes of a primitive.
* The scene mode 2D stage generates resources for rendering a primitive in 2D / CV mode.
*
* @namespace SceneMode2DPipelineStage
*
Expand All @@ -25,15 +25,18 @@ const SceneMode2DPipelineStage = {};
SceneMode2DPipelineStage.name = "SceneMode2DPipelineStage"; // Helps with debugging

/**
* This pipeline stage processes the vertex attributes of a primitive, adding the attribute declarations to the shaders,
* the attribute objects to the render resources and setting the flags as needed.
* This pipeline stage processes the position attribute of a primitive and adds the relevant
* define and uniform matrix to the shader. It also generates new resources for the primitive
* in 2D. These resources persist in the runtime primitive so that the typed array used to
* store the positional data can be freed.
*
* This must go before GeometryPipelineStage in the primitive pipeline.
* This stage must go before the GeometryPipelineStage in the primitive pipeline.
*
* Processes a primitive. This stage modifies the following parts of the render resources:
* <ul>
* <li> creates a vertex buffer for the projected positions of the primitive in 2D
* <li> creates a vertex buffer for the positions of the primitive projected to 2D
* <li> creates the bounding sphere for the primitive in 2D
* <li> adds a flag to the shader to use 2D positions
* <li> adds a uniform for the view model matrix in 2D
* </ul>
*
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/ModelExperimental/WireframePipelineStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ WireframePipelineStage.process = function (
renderResources.indices,
frameState
);
renderResources.model._resources.push(wireframeIndexBuffer);
renderResources.model._pipelineResources.push(wireframeIndexBuffer);
renderResources.wireframeIndexBuffer = wireframeIndexBuffer;

// Update render resources so we render LINES with the correct index count
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/ModelExperimental/buildDrawCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function buildDrawCommands(
attributes: primitiveRenderResources.attributes,
});

model._resources.push(vertexArray);
model._pipelineResources.push(vertexArray);

let renderState = primitiveRenderResources.renderStateOptions;

Expand All @@ -61,7 +61,7 @@ export default function buildDrawCommands(
renderState = RenderState.fromCache(renderState);

const shaderProgram = shaderBuilder.buildShaderProgram(frameState.context);
model._resources.push(shaderProgram);
model._pipelineResources.push(shaderProgram);

const pass = primitiveRenderResources.alphaOptions.pass;
const mode = frameState.mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe(
model: {
// pointer to the global resources so they can be cleaned up
// in afterEach()
_resources: resources,
_pipelineResources: resources,
},
attributes: [
{
Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/ModelExperimental/GeometryPipelineStageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import createScene from "../../createScene.js";
import waitForLoaderProcess from "../../waitForLoaderProcess.js";
import ShaderBuilderTester from "../../ShaderBuilderTester.js";

fdescribe(
describe(
"Scene/ModelExperimental/GeometryPipelineStage",
function () {
const positionOnlyPrimitive = {
Expand Down
16 changes: 8 additions & 8 deletions Specs/Scene/ModelExperimental/InstancingPipelineStageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
instancingTranslationMin: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
},
};

Expand Down Expand Up @@ -131,7 +131,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
instancingTranslationMin: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
},
};

Expand Down Expand Up @@ -159,7 +159,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
instancingTranslationMin: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
},
};

Expand Down Expand Up @@ -208,7 +208,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
instancingTranslationMin: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
},
};

Expand Down Expand Up @@ -248,7 +248,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
"attribute vec4 a_instancingTransformRow2;"
);

expect(renderResources.model._resources.length).toEqual(1);
expect(renderResources.model._pipelineResources.length).toEqual(1);
});
});

Expand All @@ -260,7 +260,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
instancingTranslationMin: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
},
};

Expand Down Expand Up @@ -344,7 +344,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
instancingTranslationMin: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
},
};

Expand Down Expand Up @@ -388,7 +388,7 @@ describe("Scene/ModelExperimental/InstancingPipelineStage", function () {
instancingTranslationMin: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
modelMatrix: Matrix4.fromUniformScale(2.0),
sceneGraph: {
axisCorrectionMatrix: ModelExperimentalUtility.getAxisCorrectionMatrix(
Expand Down
10 changes: 5 additions & 5 deletions Specs/Scene/ModelExperimental/ModelExperimentalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1720,13 +1720,13 @@ describe(
{ gltf: boxTexturedGlbUrl },
scene
).then(function (model) {
const resources = model._resources;
const pipelineResources = model._pipelineResources;
const loader = model._loader;
let resource;

let i;
for (i = 0; i < resources.length; i++) {
resource = resources[i];
for (i = 0; i < pipelineResources.length; i++) {
resource = pipelineResources[i];
if (defined(resource.isDestroyed)) {
expect(resource.isDestroyed()).toEqual(false);
}
Expand All @@ -1737,8 +1737,8 @@ describe(
if (!webglStub) {
expect(ShaderProgram.prototype.destroy).toHaveBeenCalled();
}
for (i = 0; i < resources.length - 1; i++) {
resource = resources[i];
for (i = 0; i < pipelineResources.length - 1; i++) {
resource = pipelineResources[i];
if (defined(resource.isDestroyed)) {
expect(resource.isDestroyed()).toEqual(true);
}
Expand Down
14 changes: 7 additions & 7 deletions Specs/Scene/ModelExperimental/PickingPipelineStageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("Scene/ModelExperimental/PickingPipelineStage", function () {
pickId: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
// Setting the content property here makes PickingPipelineStage handle this
// as part of a tileset.
content: {
Expand Down Expand Up @@ -142,7 +142,7 @@ describe("Scene/ModelExperimental/PickingPipelineStage", function () {
expect(uniformMap.czm_pickColor).toBeDefined();
expect(uniformMap.czm_pickColor()).toBeDefined();

expect(renderResources.model._resources.length).toEqual(1);
expect(renderResources.model._pipelineResources.length).toEqual(1);

expect(renderResources.pickId).toEqual("czm_pickColor");
});
Expand All @@ -154,7 +154,7 @@ describe("Scene/ModelExperimental/PickingPipelineStage", function () {
pickId: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
type: ModelExperimentalType.GLTF,
},
runtimePrimitive: {
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("Scene/ModelExperimental/PickingPipelineStage", function () {
expect(uniformMap.czm_pickColor).toBeDefined();
expect(uniformMap.czm_pickColor()).toBeDefined();

expect(renderResources.model._resources.length).toEqual(1);
expect(renderResources.model._pipelineResources.length).toEqual(1);

expect(renderResources.pickId).toEqual("czm_pickColor");
});
Expand All @@ -203,7 +203,7 @@ describe("Scene/ModelExperimental/PickingPipelineStage", function () {
pickId: undefined,
shaderBuilder: new ShaderBuilder(),
model: {
_resources: [],
_pipelineResources: [],
type: ModelExperimentalType.GLTF,
},
runtimePrimitive: {
Expand Down Expand Up @@ -258,7 +258,7 @@ describe("Scene/ModelExperimental/PickingPipelineStage", function () {
);
expect(pickIdAttribute.instanceDivisor).toEqual(1);

expect(renderResources.model._resources.length).toEqual(5);
expect(renderResources.model._pipelineResources.length).toEqual(5);

expect(renderResources.pickId).toEqual("v_pickColor");
});
Expand All @@ -280,7 +280,7 @@ describe("Scene/ModelExperimental/PickingPipelineStage", function () {
model: {
featureIdLabel: "featureId_0",
type: ModelExperimentalType.GLTF,
_resources: [],
_pipelineResources: [],
featureTables: [mockModelFeatureTable],
},
runtimeNode: {
Expand Down
6 changes: 6 additions & 0 deletions Specs/Scene/ModelExperimental/SceneMode2DPipelineStageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ describe("Scene/ModelExperimental/SceneMode2DPipelineStage", function () {
expect(runtimePrimitive.boundingSphere2D).toBeDefined();
expect(runtimePrimitive.positionBuffer2D).toBeDefined();

const model = renderResources.model;
expect(model._modelResources.length).toBe(1);

// Check that the position attribute's typed array has been unloaded.
const positionAttribute = ModelExperimentalUtility.getAttributeBySemantic(
primitive,
Expand Down Expand Up @@ -152,6 +155,9 @@ describe("Scene/ModelExperimental/SceneMode2DPipelineStage", function () {
expect(runtimePrimitive.boundingSphere2D).toBeDefined();
expect(runtimePrimitive.positionBuffer2D).toBeDefined();

const model = renderResources.model;
expect(model._modelResources.length).toBe(1);

// Check that the position attribute's typed array has been unloaded.
const positionAttribute = ModelExperimentalUtility.getAttributeBySemantic(
primitive,
Expand Down
4 changes: 2 additions & 2 deletions Specs/Scene/ModelExperimental/WireframePipelineStageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe(
primitiveType: primitive.primitiveType,
wireframeIndexBuffer: undefined,
model: {
_resources: resources,
_pipelineResources: resources,
},
};
}
Expand Down Expand Up @@ -108,7 +108,7 @@ describe(

it("Creates wireframe indices from typedArray (WebGL 1)", function () {
const options = {
loadAsTypedArray: true,
loadIndicesForWireframe: true,
};
return loadGltf(boxTexturedBinary, scene, options).then(function (
gltfLoader
Expand Down

0 comments on commit 407f657

Please sign in to comment.