Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v3.0.0' into device-proof
Browse files Browse the repository at this point in the history
# Conflicts:
#	cocos/3d/assets/morph-rendering.ts
#	cocos/core/builtin/builtin-res-mgr.ts
#	cocos/core/builtin/effects.ts
#	cocos/core/builtin/shader-sources/glsl1.ts
#	cocos/core/builtin/shader-sources/glsl3.ts
#	cocos/core/builtin/shader-sources/glsl4.ts
#	cocos/core/pipeline/index.jsb.ts
#	cocos/core/pipeline/planar-shadow-queue.ts
#	cocos/core/pipeline/render-additive-light-queue.ts
#	cocos/core/pipeline/shadow/shadow-flow.ts
#	cocos/particle/renderer/trail.ts
#	cocos/physics/ammo/polyfill-atob.ts
#	editor/assets/effects/builtin-spine-two-colored.effect.meta
#	jest.config.js
#	platforms/native/engine/jsb-pipeline.js
#	tests/general/sealed-global-variables.json
  • Loading branch information
pandamicro committed Feb 7, 2021
2 parents 78f33fe + e0cb168 commit c5d4c5c
Show file tree
Hide file tree
Showing 121 changed files with 1,940 additions and 22,661 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ rules:
no-underscore-dangle: off
quotes: [warn, single, { allowTemplateLiterals: true }] # force single, but allow template literal
no-else-return: off # else-return is a common pattern which clearly expresses the control flow
no-unused-expressions: off # taken over by '@typescript-eslint/no-unused-expressions'

##### AIRBNB-SPECIFIC RULE OVERRIDES #####

Expand Down Expand Up @@ -95,6 +96,8 @@ rules:

##### TYPESCRIPT-SPECIFIC RULE OVERRIDES #####

'@typescript-eslint/no-unused-expressions': warn

# TODO: this is just too much work
'@typescript-eslint/explicit-module-boundary-types': off

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-build-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: publish-build-engine
on:
push:
branches:
- 3d
- v*
jobs:
publish-build-engine:
name: publish-build-engine
Expand Down
500 changes: 500 additions & 0 deletions @types/jsb.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cocos/2d/components/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const stride = getAttributeStride(attributes);
@ccclass('cc.Graphics')
@help('i18n:cc.Graphics')
@executionOrder(110)
@menu('UI/Render/Graphics')
@menu('2D/Graphics')
export class Graphics extends Renderable2D {
/**
* @en
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/components/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ ccenum(CacheMode);
@ccclass('cc.Label')
@help('i18n:cc.Label')
@executionOrder(110)
@menu('UI/Render/Label')
@menu('2D/Label')
export class Label extends Renderable2D {
/**
* @en
Expand Down Expand Up @@ -703,7 +703,7 @@ export class Label extends Renderable2D {
this._assemblerData = null;
if (this._ttfSpriteFrame) {
const tex = this._ttfSpriteFrame.texture;
if (tex) {
if (tex && this._ttfSpriteFrame.original === null) {
const tex2d = tex as Texture2D;
if (tex2d.image) {
tex2d.image.destroy();
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/components/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const SEGMENTS_MAX = 10000;
@ccclass('cc.Mask')
@help('i18n:cc.Mask')
@executionOrder(110)
@menu('UI/Render/Mask')
@menu('2D/Mask')
export class Mask extends Renderable2D {
/**
* @en
Expand Down
17 changes: 15 additions & 2 deletions cocos/2d/components/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { ccclass, executeInEditMode, executionOrder, help, menu, tooltip, multiline, type, serializable } from 'cc.decorator';
import { DEV, EDITOR } from 'internal:constants';
import { Font, SpriteAtlas, TTFFont, SpriteFrame } from '../assets';
import { assert, EventTouch, warnID } from '../../core/platform';
import { assert, EventTouch, SystemEventType, warnID } from '../../core/platform';
import { BASELINE_RATIO, fragmentText, isUnicodeCJK, isUnicodeSpace } from '../utils/text-utils';
import { HtmlTextParser, IHtmlTextParserResultObj, IHtmlTextParserStack } from '../utils/html-text-parser';
import Pool from '../../core/utils/pool';
Expand Down Expand Up @@ -146,7 +146,7 @@ interface ISegment {
@ccclass('cc.RichText')
@help('i18n:cc.RichText')
@executionOrder(110)
@menu('UI/Render/RichText')
@menu('2D/RichText')
@executeInEditMode
export class RichText extends UIComponent {
/**
Expand Down Expand Up @@ -455,6 +455,10 @@ export class RichText extends UIComponent {
this._updateRichTextStatus = this._updateRichText;
}

public onLoad () {
this.node.on(SystemEventType.LAYER_CHANGED, this._applyLayer, this);
}

public onEnable () {
if (this.handleTouchEvent) {
this._addEventListeners();
Expand Down Expand Up @@ -503,6 +507,7 @@ export class RichText extends UIComponent {
}

this.node.off(Node.EventType.ANCHOR_CHANGED, this._updateRichTextPosition, this);
this.node.off(SystemEventType.LAYER_CHANGED, this._applyLayer, this);
}

protected _addEventListeners () {
Expand Down Expand Up @@ -657,6 +662,7 @@ export class RichText extends UIComponent {
labelSegment.styleIndex = styleIndex;
labelSegment.lineCount = this._lineCount;
labelSegment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 0);
labelSegment.node.layer = this.node.layer;
this._applyTextAttribute(labelSegment);
this.node.addChild(labelSegment.node);
this._segments.push(labelSegment);
Expand Down Expand Up @@ -789,6 +795,7 @@ export class RichText extends UIComponent {
break;
}

segment.node.layer = this.node.layer;
this.node.addChild(segment.node);
this._segments.push(segment);

Expand Down Expand Up @@ -1101,4 +1108,10 @@ export class RichText extends UIComponent {
assembler.updateRenderData(label);
}
}

protected _applyLayer () {
for (const seg of this._segments) {
seg.node.layer = this.node.layer;
}
}
}
2 changes: 1 addition & 1 deletion cocos/2d/components/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ enum EventType {
@ccclass('cc.Sprite')
@help('i18n:cc.Sprite')
@executionOrder(110)
@menu('UI/Render/Sprite')
@menu('2D/Sprite')
export class Sprite extends Renderable2D {
/**
* @en
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/components/ui-static-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { BlendFactor } from '../../core/gfx';
*/
@ccclass('cc.UIStaticBatch')
@help('i18n:cc.UIStaticBatch')
@menu('UI/Render/UIStaticBatch')
@menu('2D/UIStaticBatch')
@executionOrder(110)
export class UIStaticBatch extends Renderable2D {
@override
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ export class Canvas extends RenderRoot2D {
}
}

if (EDITOR) {
this._onResizeCamera();
this._onResizeCamera();

if (EDITOR) {
// Constantly align canvas node in edit mode
legacyCC.director.on(legacyCC.Director.EVENT_AFTER_UPDATE, this._fitDesignResolution!, this);

Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/framework/render-root-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { UITransform } from './ui-transform';

@ccclass('cc.RenderRoot2D')
@executionOrder(100)
@menu('UI/RenderRoot2D')
@menu('2D/RenderRoot2D')
@requireComponent(UITransform)
@disallowMultiple
@executeInEditMode
Expand Down
3 changes: 2 additions & 1 deletion cocos/2d/framework/renderable-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { RenderableComponent } from '../../core/components/renderable-component'
import { Stage } from '../renderer/stencil-manager';
import { warnID } from '../../core/platform/debug';
import { legacyCC } from '../../core/global-exports';
import { murmurhash2_32_gc } from '../../core/utils/murmurhash2_gc';

// hack
ccenum(BlendFactor);
Expand Down Expand Up @@ -320,7 +321,7 @@ export class Renderable2D extends RenderableComponent {
}

public updateBlendHash () {
const dst = this._blendState.targets[0].blendDst << 16;
const dst = this._blendState.targets[0].blendDst << 4;
this._blendHash = dst | this._blendState.targets[0].blendSrc;
}

Expand Down
27 changes: 21 additions & 6 deletions cocos/2d/framework/ui-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,37 @@ export class UITransform extends Component {

/**
* @en
* Sets the untransformed size of the node.<br/>
* Sets the untransformed size of the ui transform.<br/>
* The contentSize remains the same no matter if the node is scaled or rotated.<br/>
* All nodes have a size. Layer and Scene have the same size of the screen.
*
* @zh
* 设置节点原始大小,不受该节点是否被缩放或者旋转的影响。
* 设置节点 UI Transform 的原始大小,不受该节点是否被缩放或者旋转的影响。
*
* @param size - 节点内容变换的尺寸或者宽度。
* @param height - 节点内容未变换的高度。
* @param size - The size of the UI transformation.
* @example
* ```ts
* import { Size } from 'cc';
* node.setContentSize(new Size(100, 100));
* ```
*/
public setContentSize(size: Size) : void;

/**
* @en
* Sets the untransformed size of the ui transform.<br/>
* The contentSize remains the same no matter if the node is scaled or rotated.<br/>
* @zh
* 设置节点 UI Transform 的原始大小,不受该节点是否被缩放或者旋转的影响。
*
* @param width - The width of the UI transformation.
* @param height - The height of the UI transformation.
* @example
* ```ts
* import { Size } from 'cc';
* node.setContentSize(100, 100);
* ```
*/
public setContentSize(width: number, height: number) : void;

public setContentSize (size: Size | number, height?: number) {
const locContentSize = this._contentSize;
let clone: Size;
Expand Down
19 changes: 15 additions & 4 deletions cocos/2d/renderer/batcher-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class Batcher2D {
}

public getFirstRenderCamera (node: Node): Camera | null {
if (node.scene.renderScene) {
if (node.scene && node.scene.renderScene) {
const cameras = node.scene.renderScene.cameras;
for (let i = 0; i < cameras.length; i++) {
const camera = cameras[i];
Expand Down Expand Up @@ -320,6 +320,7 @@ export class Batcher2D {
this._currComponent = null;
this._currTransform = null;
this._currScene = null;
this._currMeshBuffer = null;
this._meshBufferUseCount.clear();
this._batches.clear();
StencilManager.sharedManager!.reset();
Expand Down Expand Up @@ -406,12 +407,14 @@ export class Batcher2D {
}

let depthStencil;
let dssHash = 0;
if (mat) {
// Notice: A little hack, if not this two stage, not need update here, while control by stencilManger
if (comp.stencilStage === Stage.ENABLED || comp.stencilStage === Stage.DISABLED) {
comp.stencilStage = StencilManager.sharedManager!.stage;
}
depthStencil = StencilManager.sharedManager!.getStencilStage(comp.stencilStage, mat);
dssHash = StencilManager.sharedManager!.getStencilHash(comp.stencilStage);
}

const stamp = legacyCC.director.getTotalFrames();
Expand All @@ -431,7 +434,7 @@ export class Batcher2D {
curDrawBatch.sampler = null;
curDrawBatch.useLocalData = null;
if (!depthStencil) { depthStencil = null; }
curDrawBatch.fillPasses(mat, depthStencil, null, subModel.patches);
curDrawBatch.fillPasses(mat, depthStencil, dssHash, null, 0, subModel.patches);
curDrawBatch.hDescriptorSet = SubModelPool.get(subModel.handle, SubModelView.DESCRIPTOR_SET);
curDrawBatch.hInputAssembler = SubModelPool.get(subModel.handle, SubModelView.INPUT_ASSEMBLER);
curDrawBatch.model!.visFlags = curDrawBatch.visFlags;
Expand Down Expand Up @@ -480,9 +483,17 @@ export class Batcher2D {
}
let blendState;
let depthStencil;
let dssHash = 0;
let bsHash = 0;
if (renderComp) {
blendState = renderComp.blendHash === -1 ? null : renderComp.getBlendState();
depthStencil = StencilManager.sharedManager!.getStencilStage(renderComp.stencilStage);
bsHash = renderComp.blendHash;
if (renderComp.customMaterial !== null) {
depthStencil = StencilManager.sharedManager!.getStencilStage(renderComp.stencilStage, mat);
} else {
depthStencil = StencilManager.sharedManager!.getStencilStage(renderComp.stencilStage);
}
dssHash = StencilManager.sharedManager!.getStencilHash(renderComp.stencilStage);
}

const curDrawBatch = this._currStaticRoot ? this._currStaticRoot._requireDrawBatch() : this._drawBatchPool.alloc();
Expand All @@ -495,7 +506,7 @@ export class Batcher2D {
curDrawBatch.useLocalData = this._currTransform;
curDrawBatch.textureHash = this._currTextureHash;
curDrawBatch.samplerHash = this._currSamplerHash;
curDrawBatch.fillPasses(mat, depthStencil, blendState, null);
curDrawBatch.fillPasses(mat, depthStencil, dssHash, blendState, bsHash, null);

this._batches.push(curDrawBatch);

Expand Down
12 changes: 8 additions & 4 deletions cocos/2d/renderer/draw-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ export class DrawBatch2D {
}

// object version
public fillPasses (mat: Material | null, dss, bs, patches) {
public fillPasses (mat: Material | null, dss, dssHash, bs, bsHash, patches) {
if (mat) {
const passes = mat.passes;
if (!passes) { return; }

BatchPool2D.set(this._handle, BatchView2D.PASS_COUNT, passes.length);
let passOffset = BatchView2D.PASS_0;
let shaderOffset = BatchView2D.SHADER_0;
let hashFactor = 0;
for (let i = 0; i < passes.length; i++, passOffset++, shaderOffset++) {
if (!this._passes[i]) {
this._passes[i] = new Pass(legacyCC.director.root);
Expand All @@ -132,12 +133,15 @@ export class DrawBatch2D {
}
const mtlPass = passes[i];
const passInUse = this._passes[i];
if (!dss) { dss = mtlPass.depthStencilState; }
if (!bs) { bs = mtlPass.blendState; }
if (!dss) { dss = mtlPass.depthStencilState; dssHash = 0; }
if (!bs) { bs = mtlPass.blendState; bsHash = 0; }
if (bsHash === -1) { bsHash = 0; }

hashFactor = (dssHash << 16) | bsHash;

mtlPass.update();
// @ts-expect-error hack for UI use pass object
passInUse._initPassFromTarget(mtlPass, dss, bs);
passInUse._initPassFromTarget(mtlPass, dss, bs, hashFactor);
BatchPool2D.set(this._handle, passOffset, passInUse.handle);
BatchPool2D.set(this._handle, shaderOffset, passInUse.getShaderVariant(patches));
}
Expand Down
6 changes: 5 additions & 1 deletion cocos/2d/renderer/stencil-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class StencilManager {

public getStencilStage (stage: Stage, mat?: Material) {
let key = 0;
let depthTest = true;
let depthTest = false;
let depthWrite = false;
let depthFunc = ComparisonFunc.LESS;
let cacheMap = this.stencilStateMap;
Expand Down Expand Up @@ -181,6 +181,10 @@ export class StencilManager {
return depthStencilState;
}

public getStencilHash (stage: Stage) {
return (stage << 8) | this._maskStack.length;
}

// Notice: Only children node in Mask need use this.stage
private setStateFromStage (stage) {
const pattern = this._stencilPattern;
Expand Down
3 changes: 1 addition & 2 deletions cocos/2d/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* @hidden
*/
import './font-loader';
import { DynamicAtlasManager } from './dynamic-atlas/atlas-manager';
import { Atlas } from './dynamic-atlas/atlas';

export * from './html-text-parser';
export * from './text-utils';
export { dynamicAtlasManager } from './dynamic-atlas/atlas-manager';
9 changes: 2 additions & 7 deletions cocos/3d/assets/morph-rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ export class StdMorphRendering implements MorphRendering {
continue;
}

if (subMeshMorph.targets.length > UBOMorph.MAX_MORPH_TARGET_COUNT) {
warnID(10002, UBOMorph.MAX_MORPH_TARGET_COUNT, subMeshMorph.targets.length);
continue;
}

if (preferCpuComputing) {
if (preferCpuComputing || subMeshMorph.targets.length > UBOMorph.MAX_MORPH_TARGET_COUNT) {
this._subMeshRenderings[iSubMesh] = new CpuComputing(
this._mesh,
iSubMesh,
Expand Down Expand Up @@ -110,7 +105,7 @@ export class StdMorphRendering implements MorphRendering {
const subMeshMorph = this._mesh.struct.morph.subMeshMorphs[subMeshIndex];
const subMeshRenderingInstance = subMeshInstances[subMeshIndex];
if (subMeshRenderingInstance === null) {
return null;
return undefined;
}
assertIsNonNullable(subMeshMorph);
const patches: IMacroPatch[] = [
Expand Down
2 changes: 1 addition & 1 deletion cocos/3d/framework/mesh-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ModelLightmapSettings {
@ccclass('cc.MeshRenderer')
@help('i18n:cc.MeshRenderer')
@executionOrder(100)
@menu('Components/MeshRenderer')
@menu('Mesh/MeshRenderer')
@executeInEditMode
export class MeshRenderer extends RenderableComponent {
public static ShadowCastingMode = ModelShadowCastingMode;
Expand Down
Loading

0 comments on commit c5d4c5c

Please sign in to comment.