From e947c7f93fead453b63ccc157bfe2b3bdc5c33b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelie=20Leight=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 4 Dec 2019 14:06:49 +0800 Subject: [PATCH 1/5] Revert cc.memop (#5835) --- cocos/core/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos/core/index.ts b/cocos/core/index.ts index 99bc904eb0..d01ff1759b 100644 --- a/cocos/core/index.ts +++ b/cocos/core/index.ts @@ -32,7 +32,6 @@ import * as math from './math'; import * as memop from './memop'; cc.math = math; cc.geometry = geometry; -cc.memop = memop; export { math, memop, geometry }; From ce99665e6ed7feb9086363d38b7512d7e4f987c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelie=20Leight=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 4 Dec 2019 17:21:13 +0800 Subject: [PATCH 2/5] Convert vertex index to short if platform does not support int (#5837) * Convert vertex index to short if platform does not support int * Circular reference --- EngineErrorMap.md | 4 ++++ cocos/core/assets/mesh.ts | 19 +++++++++++++++++-- cocos/core/gfx/device.ts | 5 +++++ cocos/core/gfx/webgl/webgl-device.ts | 4 ++++ cocos/core/gfx/webgl2/webgl2-device.ts | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/EngineErrorMap.md b/EngineErrorMap.md index 015a4662d4..37c6320368 100644 --- a/EngineErrorMap.md +++ b/EngineErrorMap.md @@ -1972,3 +1972,7 @@ The current buffer beyond the limit in ui static component, please reduce the am ### 9301 The UI has not been initialized + +### 10001 + +The sub-mesh contains %d vertices, which beyonds the capability (%d vertices most) of renderer of your platform. \ No newline at end of file diff --git a/cocos/core/assets/mesh.ts b/cocos/core/assets/mesh.ts index f5ecc7caf4..e18dd2a36d 100644 --- a/cocos/core/assets/mesh.ts +++ b/cocos/core/assets/mesh.ts @@ -40,12 +40,13 @@ import { GFXMemoryUsageBit, GFXPrimitiveMode, } from '../gfx/define'; -import { GFXDevice } from '../gfx/device'; +import { GFXDevice, GFXFeature } from '../gfx/device'; import { IGFXAttribute } from '../gfx/input-assembler'; import { DataPoolManager } from '../renderer/data-pool-manager'; import { murmurhash2_32_gc } from '../utils/murmurhash2_gc'; import { Asset } from './asset'; import { postLoadMesh } from './utils/mesh-utils'; +import { warnID } from '../platform/debug'; function getIndexStrideCtor (stride: number) { switch (stride) { @@ -397,15 +398,29 @@ export class Mesh extends Asset { if (prim.indexView) { const idxView = prim.indexView; + let dstStride = idxView.stride; + if (dstStride === 4 && !gfxDevice.hasFeature(GFXFeature.ELEMENT_INDEX_UINT)) { + const vertexCount = this._struct.vertexBundles[prim.vertexBundelIndices[0]].view.count; + if (vertexCount >= 2 ** 16) { + warnID(10001, vertexCount, 2 ** 16); + continue; // Ignore this primitive + } else { + dstStride = 2; // Reduce to short. + } + } + indexBuffer = gfxDevice.createBuffer({ usage: GFXBufferUsageBit.INDEX | GFXBufferUsageBit.TRANSFER_DST, memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE, size: idxView.length, - stride: idxView.stride, + stride: dstStride, }); indexBuffers.push(indexBuffer); ib = new (getIndexStrideCtor(idxView.stride))(buffer, idxView.offset, idxView.count); + if (idxView.stride !== dstStride) { + ib = getIndexStrideCtor(dstStride).from(ib); + } if (this.loaded) { indexBuffer.update(ib); } diff --git a/cocos/core/gfx/device.ts b/cocos/core/gfx/device.ts index aa06c1c42c..8037724ca5 100644 --- a/cocos/core/gfx/device.ts +++ b/cocos/core/gfx/device.ts @@ -52,6 +52,11 @@ export enum GFXFeature { FORMAT_ASTC, MSAA, COUNT, + + /** + * Allow vertex index to be unsigned 32 bits integer type. + */ + ELEMENT_INDEX_UINT, } /** diff --git a/cocos/core/gfx/webgl/webgl-device.ts b/cocos/core/gfx/webgl/webgl-device.ts index 3e6a0dad30..e703d16cf7 100644 --- a/cocos/core/gfx/webgl/webgl-device.ts +++ b/cocos/core/gfx/webgl/webgl-device.ts @@ -376,6 +376,10 @@ export class WebGLGFXDevice extends GFXDevice { if (sys.platform !== sys.WECHAT_GAME || sys.os !== sys.OS_IOS) { this._useVAO = true; } } + if (this._OES_element_index_uint) { + this._features[GFXFeature.ELEMENT_INDEX_UINT] = true; + } + console.info('RENDERER: ' + this._renderer); console.info('VENDOR: ' + this._vendor); console.info('VERSION: ' + this._version); diff --git a/cocos/core/gfx/webgl2/webgl2-device.ts b/cocos/core/gfx/webgl2/webgl2-device.ts index e3108638a8..c2e96ac388 100644 --- a/cocos/core/gfx/webgl2/webgl2-device.ts +++ b/cocos/core/gfx/webgl2/webgl2-device.ts @@ -249,6 +249,7 @@ export class WebGL2GFXDevice extends GFXDevice { this._features[GFXFeature.FORMAT_D24S8] = true; this._features[GFXFeature.FORMAT_ETC2] = true; this._features[GFXFeature.MSAA] = true; + this._features[GFXFeature.ELEMENT_INDEX_UINT] = true; if (this._EXT_color_buffer_float) { this._features[GFXFeature.COLOR_FLOAT] = true; From 06ea9536992f53acfda95d905441b77db65591f1 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Wed, 4 Dec 2019 17:21:34 +0800 Subject: [PATCH 3/5] cc.audioplayer change (#5839) --- cocos/audio/assets/player.ts | 2 +- cocos/core/splash-image.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/audio/assets/player.ts b/cocos/audio/assets/player.ts index da910930ae..28d343e50f 100644 --- a/cocos/audio/assets/player.ts +++ b/cocos/audio/assets/player.ts @@ -85,4 +85,4 @@ export abstract class AudioPlayer { } } -cc.AudioPlayer = AudioPlayer; +cc.internal.AudioPlayer = AudioPlayer; diff --git a/cocos/core/splash-image.ts b/cocos/core/splash-image.ts index 5fa6fa6749..9c45fe22cd 100644 --- a/cocos/core/splash-image.ts +++ b/cocos/core/splash-image.ts @@ -597,4 +597,4 @@ export class SplashScreen { private constructor () { }; } -cc.SplashScreen = SplashScreen; +cc.internal.SplashScreen = SplashScreen; From bb5934fcac641de348a1ebc613fb12e5e128780b Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Wed, 4 Dec 2019 18:25:54 +0800 Subject: [PATCH 4/5] runtime VAO close (#5840) --- cocos/core/gfx/webgl/webgl-device.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/core/gfx/webgl/webgl-device.ts b/cocos/core/gfx/webgl/webgl-device.ts index e703d16cf7..192c6e6b13 100644 --- a/cocos/core/gfx/webgl/webgl-device.ts +++ b/cocos/core/gfx/webgl/webgl-device.ts @@ -373,7 +373,7 @@ export class WebGLGFXDevice extends GFXDevice { this._features[GFXFeature.MSAA] = false; if (this._OES_vertex_array_object) { - if (sys.platform !== sys.WECHAT_GAME || sys.os !== sys.OS_IOS) { this._useVAO = true; } + if ( !CC_RUNTIME_BASED && (sys.platform !== sys.WECHAT_GAME || sys.os !== sys.OS_IOS)) { this._useVAO = true; } } if (this._OES_element_index_uint) { From 851ea13ef21178f2bb7bd005cc998c401156fa4f Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Wed, 4 Dec 2019 19:12:47 +0800 Subject: [PATCH 5/5] fix spot light culling (#5841) --- cocos/core/pipeline/culling.ts | 4 ++-- cocos/core/pipeline/forward/forward-pipeline.ts | 4 ++-- cocos/core/renderer/scene/sphere-light.ts | 8 +++++--- cocos/core/renderer/scene/spot-light.ts | 10 +++++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cocos/core/pipeline/culling.ts b/cocos/core/pipeline/culling.ts index f3484076d8..84d9c0dd33 100644 --- a/cocos/core/pipeline/culling.ts +++ b/cocos/core/pipeline/culling.ts @@ -3,7 +3,7 @@ */ import { frustum, intersect } from '../geom-utils'; -import { Mat4, Vec3, Quat } from '../math'; +import { Mat4, Quat, Vec3 } from '../math'; import { Camera, Light, Model } from '../renderer'; import { DirectionalLight } from '../renderer/scene/directional-light'; import { SphereLight } from '../renderer/scene/sphere-light'; @@ -24,7 +24,7 @@ export function cullSphereLight (light: SphereLight, model: Model) { export function cullSpotLight (light: SpotLight, model: Model) { return cullLight(light, model) || !!(model.worldBounds && - (!intersect.aabb_aabb(model.worldBounds, light.aabb) || !intersect.aabb_frustum(model.worldBounds, light.frustum))); + (!intersect.aabb_aabb(model.worldBounds, light.aabb) || !intersect.aabb_frustum(model.worldBounds, light.frustum))); } export const cullSceneWithDirectionalLight = (() => { diff --git a/cocos/core/pipeline/forward/forward-pipeline.ts b/cocos/core/pipeline/forward/forward-pipeline.ts index 5f8742abc1..786ef702a0 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -321,7 +321,7 @@ export class ForwardPipeline extends RenderPipeline { * @param model 模型。 */ private cullLightPerModel (model: Model) { - _tempLightIndex.splice(0); + _tempLightIndex.length = 0; for (let i = 0; i < this._validLights.length; i++) { let isCulled = false; switch (this._validLights[i].type) { @@ -345,7 +345,7 @@ export class ForwardPipeline extends RenderPipeline { } } _tempLightIndex.sort(this.sortLight); - this._lightIndices.push(..._tempLightIndex); + Array.prototype.push.apply(this._lightIndices, _tempLightIndex); } private sortLight (a, b) { diff --git a/cocos/core/renderer/scene/sphere-light.ts b/cocos/core/renderer/scene/sphere-light.ts index a77d4ca8c6..1e2a0110e9 100644 --- a/cocos/core/renderer/scene/sphere-light.ts +++ b/cocos/core/renderer/scene/sphere-light.ts @@ -1,11 +1,11 @@ import { aabb } from '../../geom-utils'; import { Vec3 } from '../../math'; -import { INode } from '../../utils/interfaces'; import { Light, LightType, nt2lm } from './light'; -import { RenderScene } from './render-scene'; export class SphereLight extends Light { + protected _needUpdate = false; + get position () { return this._pos; } @@ -20,6 +20,7 @@ export class SphereLight extends Light { set range (range: number) { this._range = range; + this._needUpdate = true; } get range (): number { @@ -52,9 +53,10 @@ export class SphereLight extends Light { } public update () { - if (this._node) { + if (this._node && (this._node.hasChangedFlags || this._needUpdate)) { this._node.getWorldPosition(this._pos); aabb.set(this._aabb, this._pos.x, this._pos.y, this._pos.z, this._range, this._range, this._range); + this._needUpdate = false; } } } diff --git a/cocos/core/renderer/scene/spot-light.ts b/cocos/core/renderer/scene/spot-light.ts index 687e704614..d5272be145 100644 --- a/cocos/core/renderer/scene/spot-light.ts +++ b/cocos/core/renderer/scene/spot-light.ts @@ -22,6 +22,7 @@ export class SpotLight extends Light { protected _aabb: aabb; protected _frustum: frustum; protected _angle: number = 0; + protected _needUpdate = false; get position () { return this._pos; @@ -37,6 +38,7 @@ export class SpotLight extends Light { set range (range: number) { this._range = range; + this._needUpdate = true; } get range (): number { @@ -62,6 +64,7 @@ export class SpotLight extends Light { set spotAngle (val: number) { this._angle = val * 0.5; this._spotAngle = Math.cos(val * 0.5); + this._needUpdate = true; } get aabb () { @@ -81,9 +84,9 @@ export class SpotLight extends Light { } public update () { - if (this._node) { + if (this._node && (this._node.hasChangedFlags || this._needUpdate)) { this._node.getWorldPosition(this._pos); - this._dir = Vec3.transformQuat(_v3, _forward, this._node.getWorldRotation(_qt)); + Vec3.transformQuat(this._dir, _forward, this._node.getWorldRotation(_qt)); Vec3.normalize(this._dir, this._dir); aabb.set(this._aabb, this._pos.x, this._pos.y, this._pos.z, this._range, this._range, this._range); @@ -95,9 +98,10 @@ export class SpotLight extends Light { // view-projection Mat4.multiply(_matViewProj, _matProj, _matView); - Mat4.invert(_matViewProjInv, _matViewProj); + // Mat4.invert(_matViewProjInv, _matViewProj); this._frustum.update(_matViewProj, _matViewProjInv); + this._needUpdate = false; } } }