Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/playcanvas/engine
Browse files Browse the repository at this point in the history
  • Loading branch information
kpal81xd committed Dec 27, 2024
2 parents 5397c68 + 764ca71 commit de9ea7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
21 changes: 14 additions & 7 deletions src/core/math/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,31 @@ class Color {
* is the same format as used in HTML/CSS.
*
* @param {boolean} alpha - If true, the output string will include the alpha value.
* @param {boolean} [asArray] - If true, the output will be an array of numbers. Defaults to false.
* @returns {string} The color in string form.
* @example
* const c = new pc.Color(1, 1, 1);
* // Outputs #ffffffff
* console.log(c.toString());
*/
toString(alpha) {
let s = `#${((1 << 24) + (Math.round(this.r * 255) << 16) + (Math.round(this.g * 255) << 8) + Math.round(this.b * 255)).toString(16).slice(1)}`;
toString(alpha, asArray) {

const { r, g, b, a } = this;

// If any component exceeds 1 (HDR), return the color as an array
if (asArray || r > 1 || g > 1 || b > 1) {
return `${r.toFixed(3)}, ${g.toFixed(3)}, ${b.toFixed(3)}, ${a.toFixed(3)}`;
}

let s = `#${((1 << 24) + (Math.round(r * 255) << 16) + (Math.round(g * 255) << 8) + Math.round(b * 255)).toString(16).slice(1)}`;
if (alpha === true) {
const a = Math.round(this.a * 255).toString(16);
const aa = Math.round(a * 255).toString(16);
if (this.a < 16 / 255) {
s += `0${a}`;
s += `0${aa}`;
} else {
s += a;
s += aa;
}

}

return s;
}

Expand Down
12 changes: 9 additions & 3 deletions src/platform/graphics/render-pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ class RenderPass {
`${colorOps.store ? 'store' : 'discard'} ` +
`${colorOps.resolve ? 'resolve ' : ''}` +
`${colorOps.genMipmaps ? 'mipmaps ' : ''}` +
` [format: ${colorFormat}]`);
` [format: ${colorFormat}]` +
` ${colorOps.clear ? `[clear: ${colorOps.clearValue.toString(true, true)}]` : ''}`
);
}

if (this.depthStencilOps) {
Expand All @@ -513,14 +515,18 @@ class RenderPass {
`${this.depthStencilOps.clearDepth ? 'clear' : 'load'}->` +
`${this.depthStencilOps.storeDepth ? 'store' : 'discard'}` +
`${this.depthStencilOps.resolveDepth ? ' resolve' : ''}` +
`${depthFormat}`);
`${depthFormat}` +
`${this.depthStencilOps.clearDepth ? ` [clear: ${this.depthStencilOps.clearDepthValue}]` : ''}`
);
}

if (hasStencil) {
Debug.trace(TRACEID_RENDER_PASS_DETAIL, ' stencOps: ' +
`${this.depthStencilOps.clearStencil ? 'clear' : 'load'}->` +
`${this.depthStencilOps.storeStencil ? 'store' : 'discard'}` +
`${depthFormat}`);
`${depthFormat}` +
`${this.depthStencilOps.clearStencil ? ` [clear: ${this.depthStencilOps.clearStencilValue}]` : ''}`
);
}
}
}
Expand Down

0 comments on commit de9ea7f

Please sign in to comment.