From bfc472f2db29274fa9daf117f442bb4afd4fac87 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 2 Sep 2020 19:54:25 +0800 Subject: [PATCH] Fix some issues --- cocos/core/3d/framework/camera-component.ts | 2 +- cocos/core/3d/framework/mesh-renderer.ts | 4 +- cocos/core/pipeline/define.ts | 2 +- cocos/core/renderer/core/memory-pools.ts | 106 ++++++++++++-------- cocos/core/renderer/scene/camera.ts | 4 +- 5 files changed, 69 insertions(+), 49 deletions(-) diff --git a/cocos/core/3d/framework/camera-component.ts b/cocos/core/3d/framework/camera-component.ts index 2cd70d61c2..ee28f610c9 100644 --- a/cocos/core/3d/framework/camera-component.ts +++ b/cocos/core/3d/framework/camera-component.ts @@ -546,7 +546,7 @@ export class Camera extends Component { protected _createCamera () { this._camera = (legacyCC.director.root as Root).createCamera(); - this._camera.initialize({ + this._camera!.initialize({ name: this.node.name, node: this.node, projection: this._projection, diff --git a/cocos/core/3d/framework/mesh-renderer.ts b/cocos/core/3d/framework/mesh-renderer.ts index 84fdaea7a8..2377dd23d9 100644 --- a/cocos/core/3d/framework/mesh-renderer.ts +++ b/cocos/core/3d/framework/mesh-renderer.ts @@ -351,12 +351,12 @@ export class MeshRenderer extends RenderableComponent { // derived classes should use a morph-able model type(i.e. model type derived from `MorphModel`). // So we should take care of the edge case. const modelType = (preferMorphOverPlain && this._modelType === scene.Model) ? models.MorphModel : this._modelType; - const model = this._model = (legacyCC.director.root as Root).createModel(modelType); + const model = this._model! = (legacyCC.director.root as Root).createModel(modelType); model.visFlags = this.visibility; model.node = model.transform = this.node; this._models.length = 0; this._models.push(this._model); - if (this._morphInstance && model instanceof MorphModel) { + if (this._morphInstance && model instanceof models.MorphModel) { model.setMorphRendering(this._morphInstance); } } diff --git a/cocos/core/pipeline/define.ts b/cocos/core/pipeline/define.ts index 48e266dded..c586ac460f 100644 --- a/cocos/core/pipeline/define.ts +++ b/cocos/core/pipeline/define.ts @@ -9,7 +9,7 @@ import { Layers } from '../scene-graph/layers'; import { legacyCC } from '../global-exports'; import { GFXBindingMappingInfo, GFXDescriptorType, GFXType, GFXShaderStageFlagBit, IGFXDescriptorSetLayoutBinding } from '../gfx'; import { IBlockInfo, ISamplerInfo } from '../assets/effect-asset'; -import { Camera } from '../renderer'; +import { Camera } from '../renderer/scene'; export const PIPELINE_FLOW_FORWARD: string = 'ForwardFlow'; export const PIPELINE_FLOW_SHADOW: string = 'ShadowFlow'; diff --git a/cocos/core/renderer/core/memory-pools.ts b/cocos/core/renderer/core/memory-pools.ts index 1599facc01..222aabeff7 100644 --- a/cocos/core/renderer/core/memory-pools.ts +++ b/cocos/core/renderer/core/memory-pools.ts @@ -31,7 +31,7 @@ import { DEBUG, JSB } from 'internal:constants'; import { NativeBufferPool, NativeObjectPool, NativeArrayPool } from './native-pools'; import { GFXRasterizerState, GFXDepthStencilState, GFXBlendState, IGFXDescriptorSetInfo, GFXDevice, GFXDescriptorSet, GFXShaderInfo, GFXShader, IGFXInputAssemblerInfo, GFXInputAssembler, - IGFXPipelineLayoutInfo, GFXPipelineLayout, GFXFramebuffer, IGFXFramebufferInfo } from '../../gfx'; + IGFXPipelineLayoutInfo, GFXPipelineLayout, GFXFramebuffer, IGFXFramebufferInfo, GFXPrimitiveMode, GFXDynamicStateFlags } from '../../gfx'; import { RenderPassStage } from '../../pipeline/define'; import { BatchingSchemes } from './pass'; import { Vec3, Mat4, IVec4Like } from '../../math'; @@ -168,7 +168,7 @@ class BufferPool

, element: E[keyof E], vec3: Vec3) { + public setVec3 (handle: IHandle

, element: V, vec3: Vec3) { // Web engine has Vec3 property, don't record it in shared memory. if (!JSB) { return; @@ -206,7 +206,7 @@ class BufferPool

, element: E[keyof E], vec4: IVec4Like) { + public setVec4 (handle: IHandle

, element: V, vec4: IVec4Like) { // Web engine has Vec4 property, don't record it in shared memory. if (!JSB) { return; @@ -257,7 +257,7 @@ class BufferPool

, element: E[keyof E], mat4: Mat4) { + public setMat4 (handle: IHandle

, element: V, mat4: Mat4) { // Web engine has mat4 property, don't record it in shared memory. if (!JSB) { return; @@ -393,15 +393,15 @@ export class ArrayPool

{ * @param step The step size to extend the array when exceeding the array size. * It is the same as size if it is not set. */ - public alloc (): Handle

{ + public alloc (): IHandle

{ const handle = this._curArrayHandle++; const array = this._nativeArrayPool.alloc(handle); this._arrayMap.set(handle, array); - return (handle | this._arrayHandleFlag) as unknown as Handle

; + return (handle | this._arrayHandleFlag) as unknown as IHandle

; } - public free (handle: Handle

) { + public free (handle: IHandle

) { let arrayHandle = this._arrayHandleMask & handle as unknown as number; if (this._arrayMap.get(arrayHandle) === undefined) { if (DEBUG) console.warn('invalid array pool handle'); @@ -410,7 +410,7 @@ export class ArrayPool

{ this._arrayMap.delete(arrayHandle); } - public assign (handle: Handle

, index: number, value: Handle) { + public assign (handle: IHandle

, index: number, value: IHandle) { const arrayHandle = this._arrayHandleMask & handle as unknown as number; let array = this._arrayMap.get(arrayHandle); if (array === undefined) { @@ -436,7 +436,7 @@ export class ArrayPool

{ array[0] = index > len ? index : len; } - public erase (handle: Handle

, index: number) { + public erase (handle: IHandle

, index: number) { const array = this._arrayMap.get(this._arrayHandleMask & handle as unknown as number); if (array === undefined || index > array[0]) { if (DEBUG) console.warn('invalid array pool index or invalid array handle'); @@ -448,7 +448,7 @@ export class ArrayPool

{ --array[0]; } - public push (handle: Handle

, value: Handle) { + public push (handle: IHandle

, value: IHandle) { const array = this._arrayMap.get(this._arrayHandleMask & handle as unknown as number); if (array === undefined) { if (DEBUG) console.warn('invalid array pool handle'); @@ -458,7 +458,7 @@ export class ArrayPool

{ this.assign(handle, array[0], value); } - public pop (handle: Handle

) { + public pop (handle: IHandle

) { const array = this._arrayMap.get(this._arrayHandleMask & handle as unknown as number); if (array === undefined) { if (DEBUG) console.warn('invalid array pool handle'); @@ -476,7 +476,7 @@ export class ArrayPool

{ * Clear the contents of array. * @param handle Handle to be clear. */ - public clear (handle: Handle

) { + public clear (handle: IHandle

) { const array = this._arrayMap.get(this._arrayHandleMask & handle as unknown as number); if (array === undefined) { if (DEBUG) console.warn('invalid array pool handle'); @@ -518,26 +518,26 @@ enum PoolType { export const NULL_HANDLE = 0 as unknown as IHandle; -export type RasterizerStateHandle = Handle; -export type DepthStencilStateHandle = Handle; -export type BlendStateHandle = Handle; -export type DescriptorSetHandle = Handle; -export type ShaderHandle = Handle; -export type IAHandle = Handle; -export type PipelineLayoutHandle = Handle; -export type FramebufferHandle = Handle; -export type PassHandle = Handle; -export type SubModelHandle = Handle; -export type ModelHandle = Handle; -export type SceneHandle = Handle; -export type CameraHandle = Handle; -export type NodeHandle = Handle; -export type RootHandle = Handle; -export type AABBHandle = Handle; -export type FrustumHandle = Handle; -export type RenderWindowHandle = Handle; -export type SubModelArrayHandle = Handle; -export type ModelArrayHandle = Handle; +export type RasterizerStateHandle = IHandle; +export type DepthStencilStateHandle = IHandle; +export type BlendStateHandle = IHandle; +export type DescriptorSetHandle = IHandle; +export type ShaderHandle = IHandle; +export type InputAssemblerHandle = IHandle; +export type PipelineLayoutHandle = IHandle; +export type FramebufferHandle = IHandle; +export type PassHandle = IHandle; +export type SubModelHandle = IHandle; +export type ModelHandle = IHandle; +export type SceneHandle = IHandle; +export type CameraHandle = IHandle; +export type NodeHandle = IHandle; +export type RootHandle = IHandle; +export type AABBHandle = IHandle; +export type FrustumHandle = IHandle; +export type RenderWindowHandle = IHandle; +export type SubModelArrayHandle = IHandle; +export type ModelArrayHandle = IHandle; // don't reuse any of these data-only structs, for GFX objects may directly reference them export const RasterizerStatePool = new ObjectPool(PoolType.RASTERIZER_STATE, () => new GFXRasterizerState()); @@ -638,7 +638,6 @@ interface ISubModelViewType extends IBufferTypeManifest { // we'll have to explicitly declare all these types. export const SubModelPool = new BufferPool (PoolType.SUB_MODEL, Uint32Array, SubModelView); -export const SubModelPool = new BufferPool(PoolType.SUB_MODEL, Uint32Array, SubModelView); export enum ModelView { ENABLED, @@ -681,17 +680,38 @@ export enum CameraView { SCENE, // handle FRUSTUM, // handle FORWARD, // Vec3 - POSITION = FORWARD + 3, // Vec3 - VIEW_PORT = POSITION + 3, // Rect - CLEAR_COLOR = VIEW_PORT + 4, // Color - MAT_VIEW = CLEAR_COLOR + 4, // Mat4 - MAT_VIEW_PROJ = MAT_VIEW + 16, // Mat4 - MAT_VIEW_PROJ_INV = MAT_VIEW_PROJ + 16, // Mat4 - MAT_PROJ = MAT_VIEW_PROJ_INV + 16, // Mat4 - MAT_PROJ_INV = MAT_PROJ + 16, // Mat4 - COUNT = MAT_PROJ_INV + 16 + POSITION = 12, // Vec3 + VIEW_PORT = 15, // Rect + CLEAR_COLOR = 19, // Color + MAT_VIEW = 23, // Mat4 + MAT_VIEW_PROJ = 39, // Mat4 + MAT_VIEW_PROJ_INV = 55, // Mat4 + MAT_PROJ = 71, // Mat4 + MAT_PROJ_INV = 87, // Mat4 + COUNT = 103 } -export const CameraPool = new BufferPool(PoolType.CAMERA, Float32Array, CameraView); +interface ICameraViewType extends IBufferTypeManifest { + [CameraView.WIDTH]: number; + [CameraView.HEIGHT]: number; + [CameraView.EXPOSURE]: number; + [CameraView.CLEAR_FLAG]: number; + [CameraView.CLEAR_DEPTH]: number; + [CameraView.CLEAR_STENCIL]: number; + [CameraView.NODE]: NodeHandle; + [CameraView.SCENE]: number; + [CameraView.FRUSTUM]: number; + [CameraView.FORWARD]: number; + [CameraView.POSITION]: number; + [CameraView.VIEW_PORT]: number; + [CameraView.CLEAR_COLOR]: number; + [CameraView.MAT_VIEW]: number; + [CameraView.MAT_VIEW_PROJ]: number; + [CameraView.MAT_VIEW_PROJ_INV]: number; + [CameraView.MAT_PROJ]: number; + [CameraView.MAT_PROJ_INV]: number; + [CameraView.COUNT]: number; +} +export const CameraPool = new BufferPool(PoolType.CAMERA, Float32Array, CameraView); export enum NodeView { LAYER, diff --git a/cocos/core/renderer/scene/camera.ts b/cocos/core/renderer/scene/camera.ts index 10ab4a9aa2..6ff6327629 100644 --- a/cocos/core/renderer/scene/camera.ts +++ b/cocos/core/renderer/scene/camera.ts @@ -414,11 +414,11 @@ export class Camera { } get width () { - return CameraPool.get(this._poolHandle, CameraView.WIDTH); + return CameraPool.get(this._poolHandle, CameraView.WIDTH); } get height () { - return CameraPool.get(this._poolHandle, CameraView.HEIGHT); + return CameraPool.get(this._poolHandle, CameraView.HEIGHT); } get aspect () {