Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitlab/3d'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
  • Loading branch information
jareguo committed Oct 29, 2020
2 parents 60782d9 + d5e35a1 commit 64e435b
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 98 deletions.
16 changes: 8 additions & 8 deletions cocos/core/director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ export class Director extends EventTarget {
console.timeEnd('AttachPersist');
}
const oldScene = this._scene;

// unload scene
if (BUILD && DEBUG) {
console.time('Destroy');
}
if (legacyCC.isValid(oldScene)) {
oldScene!.destroy();
}
if (!EDITOR) {
// auto release assets
if (BUILD && DEBUG) {
Expand All @@ -513,14 +521,6 @@ export class Director extends EventTarget {
}
}

// unload scene
if (BUILD && DEBUG) {
console.time('Destroy');
}
if (legacyCC.isValid(oldScene)) {
oldScene!.destroy();
}

this._scene = null;

// purge destroyed nodes belongs to old scene
Expand Down
8 changes: 4 additions & 4 deletions cocos/core/event/callbacks-invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class CallbacksInvoker {
* @param target - Callback callee
*/
public hasEventListener (key: string, callback?: Function, target?: Object) {
const list = this._callbackTable[key];
const list = this._callbackTable && this._callbackTable[key];
if (!list) {
return false;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ export class CallbacksInvoker {
public removeAll (keyOrTarget: string | Object) {
if (typeof keyOrTarget === 'string') {
// remove by key
const list = this._callbackTable[keyOrTarget];
const list = this._callbackTable && this._callbackTable[keyOrTarget];
if (list) {
if (list.isInvoking) {
list.cancelAll();
Expand Down Expand Up @@ -300,7 +300,7 @@ export class CallbacksInvoker {
* @param target - The callback callee of the event listener
*/
public off (key: string, callback?: Function, target?: Object) {
const list = this._callbackTable[key];
const list = this._callbackTable && this._callbackTable[key];
if (list) {
const infos = list.callbackInfos;
if (callback) {
Expand Down Expand Up @@ -329,7 +329,7 @@ export class CallbacksInvoker {
* @param arg4 - The fifth argument to be passed to the callback
*/
public emit (key: string, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any) {
const list: CallbackList = this._callbackTable[key]!;
const list: CallbackList = this._callbackTable && this._callbackTable[key]!;
if (list) {
const rootInvoker = !list.isInvoking;
list.isInvoking = true;
Expand Down
66 changes: 66 additions & 0 deletions cocos/core/gfx/pipeline-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ export class GFXRasterizerState {
(this.lineWidth === state.lineWidth) &&
(this.isMultisample === state.isMultisample);
}

public reset () {
this.isDiscard = false;
this.polygonMode = GFXPolygonMode.FILL;
this.shadeModel = GFXShadeModel.GOURAND;
this.cullMode = GFXCullMode.BACK;
this.isFrontFaceCCW = true;
this.depthBias = 0;
this.depthBiasClamp = 0.0;
this.depthBiasSlop = 0.0;
this.isDepthClip = true;
this.isMultisample = false;
this.lineWidth = 1.0;
}

public set (rasterizerState: RecursivePartial<GFXRasterizerState>) {
Object.assign(this, rasterizerState);
}
}

/**
Expand Down Expand Up @@ -111,6 +129,32 @@ export class GFXDepthStencilState {
(this.stencilPassOpBack === state.stencilPassOpBack) &&
(this.stencilRefBack === state.stencilRefBack);
}

public reset () {
this.depthTest = true;
this.depthWrite = true;
this.depthFunc = GFXComparisonFunc.LESS;
this.stencilTestFront = false;
this.stencilFuncFront = GFXComparisonFunc.ALWAYS;
this.stencilReadMaskFront = 0xffff;
this.stencilWriteMaskFront = 0xffff;
this.stencilFailOpFront = GFXStencilOp.KEEP;
this.stencilZFailOpFront = GFXStencilOp.KEEP;
this.stencilPassOpFront = GFXStencilOp.KEEP;
this.stencilRefFront = 1;
this.stencilTestBack = false;
this.stencilFuncBack = GFXComparisonFunc.ALWAYS;
this.stencilReadMaskBack = 0xffff;
this.stencilWriteMaskBack = 0xffff;
this.stencilFailOpBack = GFXStencilOp.KEEP;
this.stencilZFailOpBack = GFXStencilOp.KEEP;
this.stencilPassOpBack = GFXStencilOp.KEEP;
this.stencilRefBack = 1;
}

public set (depthStencilState: RecursivePartial<GFXDepthStencilState>) {
Object.assign(this, depthStencilState);
}
}

/**
Expand Down Expand Up @@ -141,6 +185,17 @@ export class GFXBlendTarget {
(this.blendAlphaEq === target.blendAlphaEq) &&
(this.blendColorMask === target.blendColorMask);
}

public reset () {
this.blend = false;
this.blendSrc = GFXBlendFactor.ONE;
this.blendDst = GFXBlendFactor.ZERO;
this.blendEq = GFXBlendOp.ADD;
this.blendSrcAlpha = GFXBlendFactor.ONE;
this.blendDstAlpha = GFXBlendFactor.ZERO;
this.blendAlphaEq = GFXBlendOp.ADD;
this.blendColorMask = GFXColorMask.ALL;
}
}

/**
Expand Down Expand Up @@ -168,6 +223,17 @@ export class GFXBlendState {
public setTarget (index: number, target: GFXBlendTarget) {
this.targets[index] = target;
}

public reset () {
this.isA2C = false;
this.isIndepend = false;
this.blendColor.x = 0;
this.blendColor.y = 0;
this.blendColor.z = 0;
this.blendColor.w = 0;
this.targets.length = 1;
this.targets[0].reset();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/math/mat4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { EPSILON } from './utils';
import { Vec3 } from './vec3';
import { legacyCC } from '../global-exports';

const preTransforms = [
export const preTransforms = [
[ 1, 0, 0, 1], // GFXSurfaceTransform.IDENTITY
[ 0, 1, -1, 0], // GFXSurfaceTransform.ROTATE_90
[-1, 0, 0, -1], // GFXSurfaceTransform.ROTATE_180
Expand Down
11 changes: 7 additions & 4 deletions cocos/core/pipeline/forward/forward-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ export class ForwardStage extends RenderStage {

const camera = view.camera;
const vp = camera.viewport;
this._renderArea!.x = vp.x * camera.width;
this._renderArea!.y = vp.y * camera.height;
this._renderArea!.width = vp.width * camera.width * pipeline.shadingScale;
this._renderArea!.height = vp.height * camera.height * pipeline.shadingScale;
// render area is not oriented
const w = device.surfaceTransform % 2 ? camera.height : camera.width;
const h = device.surfaceTransform % 2 ? camera.width : camera.height;
this._renderArea!.x = vp.x * w;
this._renderArea!.y = vp.y * h;
this._renderArea!.width = vp.width * w * pipeline.shadingScale;
this._renderArea!.height = vp.height * h * pipeline.shadingScale;

if (camera.clearFlag & GFXClearFlag.COLOR) {
if (pipeline.isHDR) {
Expand Down
2 changes: 2 additions & 0 deletions cocos/core/pipeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import * as pipeline from './define';
export { pipeline };

export * from './pass-phase';

export { RenderPipeline } from './render-pipeline';
export { RenderFlow } from './render-flow';
export { RenderStage } from './render-stage';
Expand Down
11 changes: 7 additions & 4 deletions cocos/core/pipeline/ui/ui-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ export class UIStage extends RenderStage {

const camera = view.camera!;
const vp = camera.viewport;
this._renderArea!.x = vp.x * camera.width;
this._renderArea!.y = vp.y * camera.height;
this._renderArea!.width = vp.width * camera.width;
this._renderArea!.height = vp.height * camera.height;
// render area is not oriented
const w = device.surfaceTransform % 2 ? camera.height : camera.width;
const h = device.surfaceTransform % 2 ? camera.width : camera.height;
this._renderArea!.x = vp.x * w;
this._renderArea!.y = vp.y * h;
this._renderArea!.width = vp.width * w;
this._renderArea!.height = vp.height * h;

colors[0] = camera.clearColor as GFXColor;

Expand Down
2 changes: 1 addition & 1 deletion cocos/core/renderer/core/memory-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ const cameraViewDataType: BufferDataTypeManifest<typeof CameraView> = {
[CameraView.FRUSTUM]: BufferDataType.UINT32,
[CameraView.FORWARD]: BufferDataType.FLOAT32,
[CameraView.POSITION]: BufferDataType.FLOAT32,
[CameraView.VIEW_PORT]: BufferDataType.UINT32,
[CameraView.VIEW_PORT]: BufferDataType.FLOAT32,
[CameraView.CLEAR_COLOR]: BufferDataType.FLOAT32,
[CameraView.MAT_VIEW]: BufferDataType.FLOAT32,
[CameraView.MAT_VIEW_PROJ]: BufferDataType.FLOAT32,
Expand Down
9 changes: 3 additions & 6 deletions cocos/core/renderer/core/pass-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,9 @@ export class PassInstance extends Pass {
* @param value The override pipeline state info
*/
public overridePipelineStates (original: IPassInfo, overrides: PassOverrides): void {
BlendStatePool.free(PassPool.get(this._handle, PassView.BLEND_STATE));
RasterizerStatePool.free(PassPool.get(this._handle, PassView.RASTERIZER_STATE));
DepthStencilStatePool.free(PassPool.get(this._handle, PassView.DEPTH_STENCIL_STATE));
PassPool.set(this._handle, PassView.BLEND_STATE, BlendStatePool.alloc());
PassPool.set(this._handle, PassView.RASTERIZER_STATE, RasterizerStatePool.alloc());
PassPool.set(this._handle, PassView.DEPTH_STENCIL_STATE, DepthStencilStatePool.alloc());
BlendStatePool.get(PassPool.get(this._handle, PassView.BLEND_STATE)).reset();
RasterizerStatePool.get(PassPool.get(this._handle, PassView.RASTERIZER_STATE)).reset();
DepthStencilStatePool.get(PassPool.get(this._handle, PassView.DEPTH_STENCIL_STATE)).reset();

Pass.fillPipelineInfo(this._handle, original);
Pass.fillPipelineInfo(this._handle, overrides);
Expand Down
8 changes: 6 additions & 2 deletions cocos/core/renderer/core/pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ export class Pass {
if (bsInfo.isIndepend !== undefined) { bs.isIndepend = bsInfo.isIndepend; }
if (bsInfo.blendColor !== undefined) { Object.assign(bs.blendColor, bsInfo.blendColor); }
}
Object.assign(RasterizerStatePool.get(PassPool.get(hPass, PassView.RASTERIZER_STATE)), info.rasterizerState);
Object.assign(DepthStencilStatePool.get(PassPool.get(hPass, PassView.DEPTH_STENCIL_STATE)), info.depthStencilState);
if (info.rasterizerState) {
RasterizerStatePool.get(PassPool.get(hPass, PassView.RASTERIZER_STATE)).set(info.rasterizerState);
}
if (info.depthStencilState) {
DepthStencilStatePool.get(PassPool.get(hPass, PassView.DEPTH_STENCIL_STATE)).set(info.depthStencilState);
}
}

/**
Expand Down
13 changes: 7 additions & 6 deletions cocos/core/renderer/scene/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export class Camera {
public update (forceUpdate = false) { // for lazy eval situations like the in-editor preview
if (!this._node) return;

let viewProjDirty = false;
// view matrix
if (this._node.hasChangedFlags || forceUpdate) {
Mat4.invert(this._matView, this._node.worldMatrix);
Expand All @@ -252,21 +253,21 @@ export class Camera {
this._node.getWorldPosition(this._position);
CameraPool.setVec3(this._poolHandle, CameraView.POSITION, this._position);
CameraPool.setVec3(this._poolHandle, CameraView.FORWARD, this._forward);
viewProjDirty = true;
}

// projection matrix
const orientation = this._device.surfaceTransform;
const aspect = orientation % 2 ? 1 / this._aspect : this._aspect;
if (this._isProjDirty || this._curTransform !== orientation) {
let projectionSignY = this._device.screenSpaceSignY;
if (this._view && this._view.window.hasOffScreenAttachments) {
projectionSignY *= this._device.UVSpaceSignY; // need flipping if drawing on render targets
}
if (this._proj === CameraProjection.PERSPECTIVE) {
Mat4.perspective(this._matProj, this._fov, aspect, this._nearClip, this._farClip,
Mat4.perspective(this._matProj, this._fov, this._aspect, this._nearClip, this._farClip,
this._fovAxis === CameraFOVAxis.VERTICAL, this._device.clipSpaceMinZ, projectionSignY, orientation);
} else {
const x = this._orthoHeight * aspect;
const x = this._orthoHeight * this._aspect; // aspect is already oriented
const y = this._orthoHeight;
Mat4.ortho(this._matProj, -x, x, -y, y, this._nearClip, this._farClip,
this._device.clipSpaceMinZ, projectionSignY, orientation);
Expand All @@ -275,19 +276,19 @@ export class Camera {
CameraPool.setMat4(this._poolHandle, CameraView.MAT_PROJ, this._matProj);
CameraPool.setMat4(this._poolHandle, CameraView.MAT_PROJ_INV, this._matProjInv);
this._curTransform = orientation;
viewProjDirty = true;
this._isProjDirty = false;
}

// view-projection
if (this._node.hasChangedFlags || this._isProjDirty || forceUpdate) {
if (viewProjDirty) {
Mat4.multiply(this._matViewProj, this._matProj, this._matView);
Mat4.invert(this._matViewProjInv, this._matViewProj);
this._frustum.update(this._matViewProj, this._matViewProjInv);
CameraPool.setMat4(this._poolHandle, CameraView.MAT_VIEW_PROJ, this._matViewProj);
CameraPool.setMat4(this._poolHandle, CameraView.MAT_VIEW_PROJ_INV, this._matViewProjInv);
recordFrustumToSharedMemory(this._frustumHandle, this._frustum);
}

this._isProjDirty = false;
}

set node (val: Node) {
Expand Down
1 change: 1 addition & 0 deletions cocos/core/renderer/ui/stencil-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class StencilManager {
}

// only ui-model use this code
// Notice: Not all state
const stencilState = pass.depthStencilState;
const pattern = this._stencilPattern;
if (pattern.stencilTest !== stencilState.stencilTestFront ||
Expand Down
28 changes: 18 additions & 10 deletions cocos/core/splash-screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as easing from './animation/easing';
import { Material } from './assets/material';
import { preTransforms } from './math/mat4';
import { clamp01 } from './math/utils';
import { COCOSPLAY, XIAOMI, JSB } from 'internal:constants';
import { sys } from './platform/sys';
Expand Down Expand Up @@ -131,8 +132,9 @@ export class SplashScreen {
const clearColor = this.setting.clearColor;
this.clearColors = [ new GFXColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w) ];

this.screenWidth = this.device.width;
this.screenHeight = this.device.height;
const { width, height, surfaceTransform } = this.device;
this.screenWidth = surfaceTransform % 2 ? height : width;
this.screenHeight = surfaceTransform % 2 ? width : height;

this.image = new Image();
this.image.onload = this.init.bind(this);
Expand Down Expand Up @@ -358,11 +360,14 @@ export class SplashScreen {
verts[i + 1] = verts[i + 1] + this.screenHeight * 0.1;
}

// transform to clipspace
// doing the screen adaptation here will not support dynamic screen orientation changes
const ySign = this.device.screenSpaceSignY;
const preTransform = preTransforms[this.device.surfaceTransform];
for (let i = 0; i < verts.length; i += 4) {
verts[i] = verts[i] / this.screenWidth * 2 - 1;
verts[i + 1] = (verts[i + 1] / this.screenHeight * 2 - 1) * ySign;
const x = verts[i] / this.screenWidth * 2 - 1;
const y = (verts[i + 1] / this.screenHeight * 2 - 1) * ySign;
verts[i] = preTransform[0] * x + preTransform[2] * y;
verts[i + 1] = preTransform[1] * x + preTransform[3] * y;
}

this.textVB.update(verts);
Expand Down Expand Up @@ -394,7 +399,7 @@ export class SplashScreen {

private initCMD () {
const device = this.device as GFXDevice;
this.renderArea = new GFXRect(0, 0, device.width, device.height);
this.renderArea = new GFXRect(0, 0, device.nativeWidth, device.nativeHeight);
this.framebuffer = this.root.mainWindow!.framebuffer;

this.cmdBuff = device.commandBuffer;
Expand Down Expand Up @@ -435,11 +440,14 @@ export class SplashScreen {
verts[i + 1] = verts[i + 1] + this.screenHeight / 2;
}

// transform to clipspace
const ySign = device.screenSpaceSignY;
// doing the screen adaptation here will not support dynamic screen orientation changes
const ySign = this.device.screenSpaceSignY;
const preTransform = preTransforms[this.device.surfaceTransform];
for (let i = 0; i < verts.length; i += 4) {
verts[i] = verts[i] / this.screenWidth * 2 - 1;
verts[i + 1] = (verts[i + 1] / this.screenHeight * 2 - 1) * ySign;
const x = verts[i] / this.screenWidth * 2 - 1;
const y = (verts[i + 1] / this.screenHeight * 2 - 1) * ySign;
verts[i] = preTransform[0] * x + preTransform[2] * y;
verts[i + 1] = preTransform[1] * x + preTransform[3] * y;
}

this.vertexBuffers.update(verts);
Expand Down
Loading

0 comments on commit 64e435b

Please sign in to comment.