|
|
|
@@ -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<P extends PoolType, T extends TypedArray, E extends IBufferMani
|
|
|
|
|
// return vec3;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public setVec3 (handle: Handle<P>, element: E[keyof E], vec3: Vec3) {
|
|
|
|
|
public setVec3<V extends E[keyof E]> (handle: IHandle<P>, 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<P extends PoolType, T extends TypedArray, E extends IBufferMani
|
|
|
|
|
// return vec4;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public setVec4 (handle: Handle<P>, element: E[keyof E], vec4: IVec4Like) {
|
|
|
|
|
public setVec4<V extends E[keyof E]> (handle: IHandle<P>, 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<P extends PoolType, T extends TypedArray, E extends IBufferMani
|
|
|
|
|
// return mat4;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public setMat4 (handle: Handle<P>, element: E[keyof E], mat4: Mat4) {
|
|
|
|
|
public setMat4<V extends E[keyof E]> (handle: IHandle<P>, 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<P extends PoolType, D extends PoolType> {
|
|
|
|
|
* @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<P> {
|
|
|
|
|
public alloc (): IHandle<P> {
|
|
|
|
|
const handle = this._curArrayHandle++;
|
|
|
|
|
const array = this._nativeArrayPool.alloc(handle);
|
|
|
|
|
this._arrayMap.set(handle, array);
|
|
|
|
|
|
|
|
|
|
return (handle | this._arrayHandleFlag) as unknown as Handle<P>;
|
|
|
|
|
return (handle | this._arrayHandleFlag) as unknown as IHandle<P>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public free (handle: Handle<P>) {
|
|
|
|
|
public free (handle: IHandle<P>) {
|
|
|
|
|
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<P extends PoolType, D extends PoolType> {
|
|
|
|
|
this._arrayMap.delete(arrayHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public assign (handle: Handle<P>, index: number, value: Handle<D>) {
|
|
|
|
|
public assign (handle: IHandle<P>, index: number, value: IHandle<D>) {
|
|
|
|
|
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<P extends PoolType, D extends PoolType> {
|
|
|
|
|
array[0] = index > len ? index : len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public erase (handle: Handle<P>, index: number) {
|
|
|
|
|
public erase (handle: IHandle<P>, 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<P extends PoolType, D extends PoolType> {
|
|
|
|
|
--array[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public push (handle: Handle<P>, value: Handle<D>) {
|
|
|
|
|
public push (handle: IHandle<P>, value: IHandle<D>) {
|
|
|
|
|
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<P extends PoolType, D extends PoolType> {
|
|
|
|
|
this.assign(handle, array[0], value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public pop (handle: Handle<P>) {
|
|
|
|
|
public pop (handle: IHandle<P>) {
|
|
|
|
|
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<P extends PoolType, D extends PoolType> {
|
|
|
|
|
* Clear the contents of array.
|
|
|
|
|
* @param handle Handle to be clear.
|
|
|
|
|
*/
|
|
|
|
|
public clear (handle: Handle<P>) {
|
|
|
|
|
public clear (handle: IHandle<P>) {
|
|
|
|
|
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<any>;
|
|
|
|
|
|
|
|
|
|
export type RasterizerStateHandle = Handle<PoolType.RASTERIZER_STATE>;
|
|
|
|
|
export type DepthStencilStateHandle = Handle<PoolType.DEPTH_STENCIL_STATE>;
|
|
|
|
|
export type BlendStateHandle = Handle<PoolType.BLEND_STATE>;
|
|
|
|
|
export type DescriptorSetHandle = Handle<PoolType.DESCRIPTOR_SETS>;
|
|
|
|
|
export type ShaderHandle = Handle<PoolType.SHADER>;
|
|
|
|
|
export type IAHandle = Handle<PoolType.INPUT_ASSEMBLER>;
|
|
|
|
|
export type PipelineLayoutHandle = Handle<PoolType.PIPELINE_LAYOUT>;
|
|
|
|
|
export type FramebufferHandle = Handle<PoolType.FRAMEBUFFER>;
|
|
|
|
|
export type PassHandle = Handle<PoolType.PASS>;
|
|
|
|
|
export type SubModelHandle = Handle<PoolType.SUB_MODEL>;
|
|
|
|
|
export type ModelHandle = Handle<PoolType.MODEL>;
|
|
|
|
|
export type SceneHandle = Handle<PoolType.SCENE>;
|
|
|
|
|
export type CameraHandle = Handle<PoolType.CAMERA>;
|
|
|
|
|
export type NodeHandle = Handle<PoolType.NODE>;
|
|
|
|
|
export type RootHandle = Handle<PoolType.ROOT>;
|
|
|
|
|
export type AABBHandle = Handle<PoolType.AABB>;
|
|
|
|
|
export type FrustumHandle = Handle<PoolType.FRUSTUM>;
|
|
|
|
|
export type RenderWindowHandle = Handle<PoolType.RENDER_WINDOW>;
|
|
|
|
|
export type SubModelArrayHandle = Handle<PoolType.SUB_MODEL_ARRAY>;
|
|
|
|
|
export type ModelArrayHandle = Handle<PoolType.MODEL_ARRAY>;
|
|
|
|
|
export type RasterizerStateHandle = IHandle<PoolType.RASTERIZER_STATE>;
|
|
|
|
|
export type DepthStencilStateHandle = IHandle<PoolType.DEPTH_STENCIL_STATE>;
|
|
|
|
|
export type BlendStateHandle = IHandle<PoolType.BLEND_STATE>;
|
|
|
|
|
export type DescriptorSetHandle = IHandle<PoolType.DESCRIPTOR_SETS>;
|
|
|
|
|
export type ShaderHandle = IHandle<PoolType.SHADER>;
|
|
|
|
|
export type InputAssemblerHandle = IHandle<PoolType.INPUT_ASSEMBLER>;
|
|
|
|
|
export type PipelineLayoutHandle = IHandle<PoolType.PIPELINE_LAYOUT>;
|
|
|
|
|
export type FramebufferHandle = IHandle<PoolType.FRAMEBUFFER>;
|
|
|
|
|
export type PassHandle = IHandle<PoolType.PASS>;
|
|
|
|
|
export type SubModelHandle = IHandle<PoolType.SUB_MODEL>;
|
|
|
|
|
export type ModelHandle = IHandle<PoolType.MODEL>;
|
|
|
|
|
export type SceneHandle = IHandle<PoolType.SCENE>;
|
|
|
|
|
export type CameraHandle = IHandle<PoolType.CAMERA>;
|
|
|
|
|
export type NodeHandle = IHandle<PoolType.NODE>;
|
|
|
|
|
export type RootHandle = IHandle<PoolType.ROOT>;
|
|
|
|
|
export type AABBHandle = IHandle<PoolType.AABB>;
|
|
|
|
|
export type FrustumHandle = IHandle<PoolType.FRUSTUM>;
|
|
|
|
|
export type RenderWindowHandle = IHandle<PoolType.RENDER_WINDOW>;
|
|
|
|
|
export type SubModelArrayHandle = IHandle<PoolType.SUB_MODEL_ARRAY>;
|
|
|
|
|
export type ModelArrayHandle = IHandle<PoolType.MODEL_ARRAY>;
|
|
|
|
|
|
|
|
|
|
// 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, typeof SubModelView, ISubModelViewType>
|
|
|
|
|
(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, typeof CameraView, ICameraViewType>(PoolType.CAMERA, Float32Array, CameraView);
|
|
|
|
|
|
|
|
|
|
export enum NodeView {
|
|
|
|
|
LAYER,
|
|
|
|
|