Skip to content

Commit

Permalink
Fix and update unit tests for ModelRuntimePrimitive
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrgags committed Jan 5, 2024
1 parent 990b815 commit c4e1b37
Showing 1 changed file with 116 additions and 49 deletions.
165 changes: 116 additions & 49 deletions packages/engine/Specs/Scene/Model/ModelRuntimePrimitiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {
AlphaPipelineStage,
BatchTexturePipelineStage,
Cesium3DTileStyle,
ClassificationPipelineStage,
CustomShader,
CustomShaderMode,
CustomShaderPipelineStage,
FeatureIdPipelineStage,
FogPipelineStage,
CPUStylingPipelineStage,
DequantizationPipelineStage,
GeometryPipelineStage,
Expand All @@ -30,7 +32,8 @@ import {
WireframePipelineStage,
ClassificationType,
} from "../../../index.js";
import ClassificationPipelineStage from "../../../Source/Scene/Model/ClassificationPipelineStage.js";

import createFrameState from "../../../../../Specs/createFrameState.js";

describe("Scene/Model/ModelRuntimePrimitive", function () {
const mockPrimitive = {
Expand All @@ -43,33 +46,21 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
allowPicking: true,
featureIdLabel: "featureId_0",
};
const mockFrameState = {
context: {
webgl2: false,
},
mode: SceneMode.SCENE3D,
const mockWebgl1Context = {
webgl2: false,
};

const mockFrameStateWebgl2 = {
context: {
webgl2: true,
},
const mockWebgl2Context = {
webgl2: true,
};

const mockFrameState2D = {
context: {
webgl2: false,
},
mode: SceneMode.SCENE2D,
};
const mockFrameState = createFrameState(mockWebgl1Context);
const mockFrameStateWebgl2 = createFrameState(mockWebgl2Context);

const mockFrameState3DOnly = {
context: {
webgl2: false,
},
mode: SceneMode.SCENE3D,
scene3DOnly: true,
};
const mockFrameState2D = createFrameState(mockWebgl1Context);
mockFrameState2D.mode = SceneMode.SCENE2D;

const mockFrameState3DOnly = createFrameState(mockWebgl1Context);
mockFrameState3DOnly.scene3DOnly = true;

const emptyVertexShader =
"void vertexMain(VertexInput vsInput, inout vec3 position) {}";
Expand Down Expand Up @@ -160,7 +151,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -203,7 +193,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
SelectedFeatureIdPipelineStage,
BatchTexturePipelineStage,
CPUStylingPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
PickingPipelineStage,
AlphaPipelineStage,
Expand Down Expand Up @@ -250,7 +239,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
SelectedFeatureIdPipelineStage,
BatchTexturePipelineStage,
CPUStylingPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
PickingPipelineStage,
AlphaPipelineStage,
Expand Down Expand Up @@ -307,7 +295,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
PickingPipelineStage,
AlphaPipelineStage,
Expand Down Expand Up @@ -335,7 +322,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
CustomShaderPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
Expand Down Expand Up @@ -366,7 +352,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
GeometryPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
CustomShaderPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
Expand Down Expand Up @@ -397,7 +382,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
CustomShaderPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
Expand Down Expand Up @@ -438,7 +422,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -473,7 +456,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -507,7 +489,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -538,7 +519,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -570,7 +550,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -600,7 +579,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -633,7 +611,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -675,7 +652,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -708,7 +684,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -740,7 +715,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -772,7 +746,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -803,7 +776,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -835,7 +807,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -866,7 +837,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -897,7 +867,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -929,7 +898,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
PrimitiveOutlinePipelineStage,
AlphaPipelineStage,
Expand Down Expand Up @@ -962,7 +930,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand Down Expand Up @@ -993,7 +960,6 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
Expand All @@ -1002,4 +968,105 @@ describe("Scene/Model/ModelRuntimePrimitive", function () {
primitive.configurePipeline(mockFrameState);
verifyExpectedStages(primitive.pipelineStages, expectedStages);
});

it("configures pipeline stages for vertical exaggeration", function () {
const primitive = new ModelRuntimePrimitive({
primitive: mockPrimitive,
node: mockNode,
model: mockModel,
});
const frameState = createFrameState(mockWebgl2Context);
frameState.verticalExaggeration = 2.0;

const expectedStages = [
GeometryPipelineStage,
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
VerticalExaggerationPipelineStage,
LightingPipelineStage,
PickingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
];

primitive.configurePipeline(frameState);
verifyExpectedStages(primitive.pipelineStages, expectedStages);
});

it("does not add fog stage when fog is not enabled", function () {
const primitive = new ModelRuntimePrimitive({
primitive: mockPrimitive,
node: mockNode,
model: mockModel,
});
const frameState = createFrameState(mockWebgl2Context);
frameState.fog.enabled = false;
frameState.fog.renderable = false;

const expectedStages = [
GeometryPipelineStage,
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
LightingPipelineStage,
PickingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
];

primitive.configurePipeline(frameState);
verifyExpectedStages(primitive.pipelineStages, expectedStages);
});

it("does not add fog stage when fog is not renderable", function () {
const primitive = new ModelRuntimePrimitive({
primitive: mockPrimitive,
node: mockNode,
model: mockModel,
});
const frameState = createFrameState(mockWebgl2Context);
frameState.fog.enabled = true;
frameState.fog.renderable = false;

const expectedStages = [
GeometryPipelineStage,
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
LightingPipelineStage,
PickingPipelineStage,
AlphaPipelineStage,
PrimitiveStatisticsPipelineStage,
];

primitive.configurePipeline(frameState);
verifyExpectedStages(primitive.pipelineStages, expectedStages);
});

it("configures pipeline stages when fog is enabled and renderable", function () {
const primitive = new ModelRuntimePrimitive({
primitive: mockPrimitive,
node: mockNode,
model: mockModel,
});
const frameState = createFrameState(mockWebgl2Context);
frameState.fog.enabled = true;
frameState.fog.renderable = true;

const expectedStages = [
GeometryPipelineStage,
MaterialPipelineStage,
FeatureIdPipelineStage,
MetadataPipelineStage,
LightingPipelineStage,
PickingPipelineStage,
AlphaPipelineStage,
FogPipelineStage,
PrimitiveStatisticsPipelineStage,
];

primitive.configurePipeline(frameState);
verifyExpectedStages(primitive.pipelineStages, expectedStages);
});
});

0 comments on commit c4e1b37

Please sign in to comment.