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/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/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..192c6e6b13 100644 --- a/cocos/core/gfx/webgl/webgl-device.ts +++ b/cocos/core/gfx/webgl/webgl-device.ts @@ -373,7 +373,11 @@ 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) { + this._features[GFXFeature.ELEMENT_INDEX_UINT] = true; } console.info('RENDERER: ' + this._renderer); 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; 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 }; 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 6c89a69f5c..2f5aa55cf3 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -295,8 +295,8 @@ export class ForwardPipeline extends RenderPipeline { * 对每个模型裁剪光源。 * @param model 模型。 */ - private cullLightPerModel(model: Model) { - _tempLightIndex.splice(0); + private cullLightPerModel (model: Model) { + _tempLightIndex.length = 0; for (let i = 0; i < this._validLights.length; i++) { let isCulled = false; switch (this._validLights[i].type) { @@ -320,7 +320,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; } } } 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;