Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description to DrawCommand #12119

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/engine/Source/Renderer/ComputeEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function ComputeEngine(context) {

let renderStateScratch;
const drawCommandScratch = new DrawCommand({
description: "ComputeEngine.drawCommandScratch",
primitiveType: PrimitiveType.TRIANGLES,
});
const clearCommandScratch = new ClearCommand({
Expand Down
1 change: 1 addition & 0 deletions packages/engine/Source/Renderer/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ Context.prototype.createViewportQuadCommand = function (
overrides = defaultValue(overrides, defaultValue.EMPTY_OBJECT);

return new DrawCommand({
description: "viewportQuadCommand",
vertexArray: this.getViewportQuadVertexArray(),
primitiveType: PrimitiveType.TRIANGLES,
renderState: overrides.renderState,
Expand Down
26 changes: 24 additions & 2 deletions packages/engine/Source/Renderer/DrawCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Flags = {
function DrawCommand(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

this._description = defaultValue(options.description, "<unknown>");
this._boundingVolume = options.boundingVolume;
this._orientedBoundingBox = options.orientedBoundingBox;
this._modelMatrix = options.modelMatrix;
Expand Down Expand Up @@ -83,6 +84,23 @@ function setFlag(command, flag, value) {
}

Object.defineProperties(DrawCommand.prototype, {
/**
* A short description of this draw command.
* <p>
* This is supposed to be a short description that may not be human-readable,
* but developer-readable, and that helps to identify this command. The exact
* structure of this string is not specified.
* </p>
*
* @memberof DrawCommand.prototype
* @type {string}
*/
description: {
get: function () {
return this._description;
},
},

/**
* The bounding volume of the geometry in world space. This is used for culling and frustum selection.
* <p>
Expand Down Expand Up @@ -566,14 +584,18 @@ Object.defineProperties(DrawCommand.prototype, {
/**
* @private
*/
DrawCommand.shallowClone = function (command, result) {
DrawCommand.shallowClone = function (command, suffix, result) {
if (!defined(command)) {
return undefined;
}
if (!defined(result)) {
result = new DrawCommand();
}

if (!defined(suffix)) {
result._description = `${command._description}.<unknown>`;
} else {
result._description = `${command._description}${suffix}`;
}
result._boundingVolume = command._boundingVolume;
result._orientedBoundingBox = command._orientedBoundingBox;
result._modelMatrix = command._modelMatrix;
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,9 @@ BillboardCollection.prototype.update = function (frameState) {
for (let j = 0; j < totalLength; ++j) {
let command = colorList[j];
if (!defined(command)) {
command = colorList[j] = new DrawCommand();
command = colorList[j] = new DrawCommand({
description: `billboardCollection.colorList[${j}]`,
});
}

const opaqueCommand = opaque || (opaqueAndTranslucent && j % 2 === 0);
Expand Down
10 changes: 5 additions & 5 deletions packages/engine/Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ function getStyleCommandsNeeded(batchTable) {
}

function deriveCommand(command) {
const derivedCommand = DrawCommand.shallowClone(command);
const derivedCommand = DrawCommand.shallowClone(command, ".derived");

// Add a uniform to indicate if the original command was translucent so
// the shader knows not to cull vertices that were originally transparent
Expand All @@ -1028,14 +1028,14 @@ function deriveCommand(command) {
}

function deriveTranslucentCommand(command) {
const derivedCommand = DrawCommand.shallowClone(command);
const derivedCommand = DrawCommand.shallowClone(command, ".translucent");
derivedCommand.pass = Pass.TRANSLUCENT;
derivedCommand.renderState = getTranslucentRenderState(command.renderState);
return derivedCommand;
}

function deriveOpaqueCommand(command) {
const derivedCommand = DrawCommand.shallowClone(command);
const derivedCommand = DrawCommand.shallowClone(command, ".opaque");
derivedCommand.renderState = getOpaqueRenderState(command.renderState);
return derivedCommand;
}
Expand Down Expand Up @@ -1066,7 +1066,7 @@ function getLogDepthPolygonOffsetFragmentShaderProgram(context, shaderProgram) {

function deriveZBackfaceCommand(context, command) {
// Write just backface depth of unresolved tiles so resolved stenciled tiles do not appear in front
const derivedCommand = DrawCommand.shallowClone(command);
const derivedCommand = DrawCommand.shallowClone(command, ".zBackface");
const rs = clone(derivedCommand.renderState, true);
rs.cull.enabled = true;
rs.cull.face = CullFace.FRONT;
Expand Down Expand Up @@ -1111,7 +1111,7 @@ function deriveZBackfaceCommand(context, command) {
function deriveStencilCommand(command, reference) {
// Tiles only draw if their selection depth is >= the tile drawn already. They write their
// selection depth to the stencil buffer to prevent ancestor tiles from drawing on top
const derivedCommand = DrawCommand.shallowClone(command);
const derivedCommand = DrawCommand.shallowClone(command, ".stencil");
const rs = clone(derivedCommand.renderState, true);
// Stencil test is masked to the most significant 3 bits so the reference is shifted. Writes 0 for the terrain bit
rs.stencilTest.enabled = true;
Expand Down
13 changes: 13 additions & 0 deletions packages/engine/Source/Scene/ClassificationPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ function createColorCommands(classificationPrimitive, colorCommands) {
command = colorCommands[i];
if (!defined(command)) {
command = colorCommands[i] = new DrawCommand({
description: `classificationPrimitive.colorCommands[${i}]`,
owner: classificationPrimitive,
primitiveType: primitive._primitiveType,
});
Expand All @@ -687,6 +688,7 @@ function createColorCommands(classificationPrimitive, colorCommands) {

derivedCommand = DrawCommand.shallowClone(
command,
".tileset",
command.derivedCommands.tileset
);
derivedCommand.renderState =
Expand All @@ -698,6 +700,7 @@ function createColorCommands(classificationPrimitive, colorCommands) {
command = colorCommands[i + 1];
if (!defined(command)) {
command = colorCommands[i + 1] = new DrawCommand({
description: `classificationPrimitive.colorCommands[${i + 1}]`,
owner: classificationPrimitive,
primitiveType: primitive._primitiveType,
});
Expand All @@ -718,6 +721,7 @@ function createColorCommands(classificationPrimitive, colorCommands) {

derivedCommand = DrawCommand.shallowClone(
command,
".tileset",
command.derivedCommands.tileset
);
derivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;
Expand All @@ -728,6 +732,7 @@ function createColorCommands(classificationPrimitive, colorCommands) {
// First derive from the terrain command
let derived2DCommand = DrawCommand.shallowClone(
command,
".2d",
command.derivedCommands.appearance2D
);
derived2DCommand.shaderProgram = classificationPrimitive._spColor2D;
Expand All @@ -736,6 +741,7 @@ function createColorCommands(classificationPrimitive, colorCommands) {
// Then derive from the 3D Tiles command
derived2DCommand = DrawCommand.shallowClone(
derivedCommand,
".2d",
derivedCommand.derivedCommands.appearance2D
);
derived2DCommand.shaderProgram = classificationPrimitive._spColor2D;
Expand All @@ -752,6 +758,7 @@ function createColorCommands(classificationPrimitive, colorCommands) {
for (let j = 0; j < length; ++j) {
const commandIgnoreShow = (commandsIgnoreShow[j] = DrawCommand.shallowClone(
colorCommands[commandIndex],
".ignoreShow",
commandsIgnoreShow[j]
));
commandIgnoreShow.shaderProgram = spStencil;
Expand Down Expand Up @@ -799,6 +806,7 @@ function createPickCommands(classificationPrimitive, pickCommands) {
command = pickCommands[j];
if (!defined(command)) {
command = pickCommands[j] = new DrawCommand({
description: `classificationPrimitive.pickCommands[${j}]`,
owner: classificationPrimitive,
primitiveType: primitive._primitiveType,
pickOnly: true,
Expand All @@ -818,6 +826,7 @@ function createPickCommands(classificationPrimitive, pickCommands) {
// Derive for 3D Tiles classification
derivedCommand = DrawCommand.shallowClone(
command,
".tilesetClassification",
command.derivedCommands.tileset
);
derivedCommand.renderState =
Expand All @@ -829,6 +838,7 @@ function createPickCommands(classificationPrimitive, pickCommands) {
command = pickCommands[j + 1];
if (!defined(command)) {
command = pickCommands[j + 1] = new DrawCommand({
description: `classificationPrimitive.pickCommands[${j + 1}]`,
owner: classificationPrimitive,
primitiveType: primitive._primitiveType,
pickOnly: true,
Expand All @@ -847,6 +857,7 @@ function createPickCommands(classificationPrimitive, pickCommands) {

derivedCommand = DrawCommand.shallowClone(
command,
".tileClassification",
command.derivedCommands.tileset
);
derivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;
Expand All @@ -857,6 +868,7 @@ function createPickCommands(classificationPrimitive, pickCommands) {
// First derive from the terrain command
let derived2DCommand = DrawCommand.shallowClone(
command,
".2d",
command.derivedCommands.pick2D
);
derived2DCommand.shaderProgram = classificationPrimitive._spPick2D;
Expand All @@ -865,6 +877,7 @@ function createPickCommands(classificationPrimitive, pickCommands) {
// Then derive from the 3D Tiles command
derived2DCommand = DrawCommand.shallowClone(
derivedCommand,
".2d",
derivedCommand.derivedCommands.pick2D
);
derived2DCommand.shaderProgram = classificationPrimitive._spPick2D;
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/Source/Scene/CloudCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,9 @@ function createDrawCommands(cloudCollection, frameState) {
for (let i = 0; i < vaLength; i++) {
let command = colorList[i];
if (!defined(command)) {
command = colorList[i] = new DrawCommand();
command = colorList[i] = new DrawCommand({
description: `cloudCollection.colorList[${i}]`,
});
}
command.pass = Pass.TRANSLUCENT;
command.owner = cloudCollection;
Expand Down
5 changes: 4 additions & 1 deletion packages/engine/Source/Scene/DebugInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ function createDebugShowFrustumsUniformMap(scene, command) {
return debugUniformMap;
}

const scratchShowFrustumCommand = new DrawCommand();
const scratchShowFrustumCommand = new DrawCommand({
description: `DebugInspector.scratchShowFrustumCommand`,
});
DebugInspector.prototype.executeDebugShowFrustumsCommand = function (
scene,
command,
Expand All @@ -142,6 +144,7 @@ DebugInspector.prototype.executeDebugShowFrustumsCommand = function (

const debugCommand = DrawCommand.shallowClone(
command,
".debug",
scratchShowFrustumCommand
);
debugCommand.shaderProgram = debugShaderProgram;
Expand Down
1 change: 1 addition & 0 deletions packages/engine/Source/Scene/DepthPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ DepthPlane.prototype.update = function (frameState) {
});

this._command = new DrawCommand({
description: `depthPlane._command`,
renderState: this._rs,
boundingVolume: new BoundingSphere(
Cartesian3.ZERO,
Expand Down
15 changes: 12 additions & 3 deletions packages/engine/Source/Scene/DerivedCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ DerivedCommand.createDepthOnlyDerivedCommand = function (

result.depthOnlyCommand = DrawCommand.shallowClone(
command,
".depthOnly",
result.depthOnlyCommand
);

Expand Down Expand Up @@ -251,7 +252,11 @@ DerivedCommand.createLogDepthCommand = function (command, context, result) {
shader = result.command.shaderProgram;
}

result.command = DrawCommand.shallowClone(command, result.command);
result.command = DrawCommand.shallowClone(
command,
".logDepth",
result.command
);

if (!defined(shader) || result.shaderProgramId !== command.shaderProgram.id) {
result.command.shaderProgram = getLogDepthShaderProgram(
Expand Down Expand Up @@ -354,7 +359,11 @@ DerivedCommand.createPickDerivedCommand = function (
renderState = result.pickCommand.renderState;
}

result.pickCommand = DrawCommand.shallowClone(command, result.pickCommand);
result.pickCommand = DrawCommand.shallowClone(
command,
".pick",
result.pickCommand
);

if (!defined(shader) || result.shaderProgramId !== command.shaderProgram.id) {
result.pickCommand.shaderProgram = getPickShaderProgram(
Expand Down Expand Up @@ -414,7 +423,7 @@ DerivedCommand.createHdrCommand = function (command, context, result) {
shader = result.command.shaderProgram;
}

result.command = DrawCommand.shallowClone(command, result.command);
result.command = DrawCommand.shallowClone(command, ".hdr", result.command);

if (!defined(shader) || result.shaderProgramId !== command.shaderProgram.id) {
result.command.shaderProgram = getHdrShaderProgram(
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/Source/Scene/EllipsoidPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ function EllipsoidPrimitive(options) {
this._pickId = undefined;

this._colorCommand = new DrawCommand({
description: `ellipsoidPrimitive._colorCommand`,
owner: defaultValue(options._owner, this),
});
this._pickCommand = new DrawCommand({
description: `ellipsoidPrimitive._pickCommand`,
owner: defaultValue(options._owner, this),
pickOnly: true,
});
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,9 @@ function addDrawCommandsForTile(tileProvider, tile, frameState) {
let uniformMap;

if (tileProvider._drawCommands.length <= tileProvider._usedDrawCommands) {
command = new DrawCommand();
command = new DrawCommand({
description: `tileProvider._drawCommands[${tileProvider._drawCommands.length}]`,
});
command.owner = tile;
command.cull = false;
command.boundingVolume = new BoundingSphere();
Expand Down
6 changes: 5 additions & 1 deletion packages/engine/Source/Scene/GlobeTranslucencyState.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,11 @@ function updateDerivedCommands(
derivedRenderState = undefined;
}

derivedCommand = DrawCommand.shallowClone(command, derivedCommand);
derivedCommand = DrawCommand.shallowClone(
command,
`.derived${i}`,
derivedCommand
);
derivedCommandsObject[derivedCommandName] = derivedCommand;

const derivedUniformMapDirtyFrame = defaultValue(
Expand Down
5 changes: 5 additions & 0 deletions packages/engine/Source/Scene/GroundPolylinePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ function createCommands(
let command = colorCommands[i];
if (!defined(command)) {
command = colorCommands[i] = new DrawCommand({
description: `groundPolylinePrimitive.colorCommands[${i}]`,
owner: groundPolylinePrimitive,
primitiveType: primitive._primitiveType,
});
Expand All @@ -535,6 +536,7 @@ function createCommands(

const derivedTilesetCommand = DrawCommand.shallowClone(
command,
".tileset",
command.derivedCommands.tileset
);
derivedTilesetCommand.renderState =
Expand All @@ -545,13 +547,15 @@ function createCommands(
// derive for 2D
const derived2DCommand = DrawCommand.shallowClone(
command,
".2d",
command.derivedCommands.color2D
);
derived2DCommand.shaderProgram = groundPolylinePrimitive._sp2D;
command.derivedCommands.color2D = derived2DCommand;

const derived2DTilesetCommand = DrawCommand.shallowClone(
derivedTilesetCommand,
".2d",
derivedTilesetCommand.derivedCommands.color2D
);
derived2DTilesetCommand.shaderProgram = groundPolylinePrimitive._sp2D;
Expand All @@ -560,6 +564,7 @@ function createCommands(
// derive for Morph
const derivedMorphCommand = DrawCommand.shallowClone(
command,
".morph",
command.derivedCommands.colorMorph
);
derivedMorphCommand.renderState = groundPolylinePrimitive._renderStateMorph;
Expand Down
Loading