mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
gfx: swapchain refactor (#9030)
* update effect.hideInEditor * swapchain refactor * webgl multi draw * implicit depth/stencil format * native adapt * explicit resizable texture * DrawInfo in InputAssembler * device cached states * sync defines * gfx: empty backend * update playground * remove profiler camera * update effect types * fix pass.resetUniform
This commit is contained in:
@@ -94,6 +94,7 @@ rules:
|
||||
one-var-declaration-per-line: off # auto-fix has order issues with `one-var`
|
||||
prefer-destructuring: off # auto-fix is not smart enough to merge different instances
|
||||
linebreak-style: off # we don't enforce this on everyone's dev environment for now
|
||||
spaced-comment: off # for license declarations
|
||||
|
||||
##### TYPESCRIPT-SPECIFIC RULE OVERRIDES #####
|
||||
|
||||
|
||||
Vendored
+28
-1
@@ -1,3 +1,30 @@
|
||||
interface WEBGL_multi_draw {
|
||||
multiDrawArraysWEBGL(mode: GLenum,
|
||||
firstsList: GLint[] | Int32Array, firstsOffset: GLuint,
|
||||
countsList: GLsizei[] | Int32Array, countsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
multiDrawElementsWEBGL(mode: GLenum,
|
||||
countsList: GLint[] | Int32Array, countsOffset: GLuint,
|
||||
type: GLenum,
|
||||
offsetsList: GLsizei[] | Int32Array, OffsetsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
multiDrawArraysInstancedWEBGL(mode: GLenum,
|
||||
firstsList: GLint[] | Int32Array, firstsOffset: GLuint,
|
||||
countsList: GLsizei[] | Int32Array, countsOffset: GLuint,
|
||||
instanceCountsList: GLsizei[] | Int32Array, instanceCountsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
multiDrawElementsInstancedWEBGL(mode: GLenum,
|
||||
countsList: GLint[] | Int32Array, countsOffset: GLuint,
|
||||
type: GLenum,
|
||||
offsetsList: GLsizei[] | Int32Array, OffsetsOffset: GLuint,
|
||||
instanceCountsList: GLsizei[] | Int32Array, instanceCountsOffset: GLuint,
|
||||
drawCount: GLsizei
|
||||
): void;
|
||||
}
|
||||
|
||||
interface EXT_color_buffer_half_float {
|
||||
readonly RGBA16F_EXT: GLenum;
|
||||
readonly RGB16F_EXT: GLenum;
|
||||
@@ -28,4 +55,4 @@ interface WEBGL_compressed_texture_pvrtc {
|
||||
readonly COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: GLenum;
|
||||
readonly COMPRESSED_RGB_PVRTC_2BPPV1_IMG: GLenum;
|
||||
readonly COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: GLenum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,8 +681,8 @@ export class SpriteFrame extends Asset {
|
||||
* @en Gets the sampler hash of its texture
|
||||
* @zh 贴图资源的采样器哈希值
|
||||
*/
|
||||
public getSamplerHash () {
|
||||
return this._texture.getSamplerHash();
|
||||
public getSamplerInfo () {
|
||||
return this._texture.getSamplerInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,8 @@ import { Camera, Model } from 'cocos/core/renderer/scene';
|
||||
import { UIStaticBatch } from '../components';
|
||||
import { Material } from '../../core/assets/material';
|
||||
import { RenderRoot2D, Renderable2D, UIComponent } from '../framework';
|
||||
import { Texture, Device, Attribute, Sampler, DescriptorSetInfo, Buffer, BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet } from '../../core/gfx';
|
||||
import { Texture, Device, Attribute, Sampler, DescriptorSetInfo, Buffer,
|
||||
BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet } from '../../core/gfx';
|
||||
import { Pool, RecyclePool } from '../../core/memop';
|
||||
import { CachedArray } from '../../core/memop/cached-array';
|
||||
import { RenderScene } from '../../core/renderer/scene/render-scene';
|
||||
@@ -47,8 +48,6 @@ import { SpriteFrame } from '../assets';
|
||||
import { TextureBase } from '../../core/assets/texture-base';
|
||||
import { sys } from '../../core/platform/sys';
|
||||
import { Mat4 } from '../../core/math';
|
||||
import { value } from '../../core/utils/js-typed';
|
||||
import { NativeDrawBatch2D } from '../../core/renderer/scene';
|
||||
|
||||
const _dsInfo = new DescriptorSetInfo(null!);
|
||||
const m4_1 = new Mat4();
|
||||
@@ -150,7 +149,6 @@ export class Batcher2D {
|
||||
private _currComponent: Renderable2D | null = null;
|
||||
private _currTransform: Node | null = null;
|
||||
private _currTextureHash = 0;
|
||||
private _currSamplerHash = 0;
|
||||
private _currBlendTargetHash = 0;
|
||||
private _currLayer = 0;
|
||||
private _currDepthStencilStateStage: any | null = null;
|
||||
@@ -375,12 +373,10 @@ export class Batcher2D {
|
||||
let texture;
|
||||
let samp;
|
||||
let textureHash = 0;
|
||||
let samplerHash = 0;
|
||||
if (frame) {
|
||||
texture = frame.getGFXTexture();
|
||||
samp = frame.getGFXSampler();
|
||||
textureHash = frame.getHash();
|
||||
samplerHash = frame.getSamplerHash();
|
||||
} else {
|
||||
texture = null;
|
||||
samp = null;
|
||||
@@ -395,7 +391,7 @@ export class Batcher2D {
|
||||
|
||||
if (this._currScene !== renderScene || this._currLayer !== comp.node.layer || this._currMaterial !== mat
|
||||
|| this._currBlendTargetHash !== blendTargetHash || this._currDepthStencilStateStage !== depthStencilStateStage
|
||||
|| this._currTextureHash !== textureHash || this._currSamplerHash !== samplerHash || this._currTransform !== transform) {
|
||||
|| this._currTextureHash !== textureHash || this._currSampler !== samp || this._currTransform !== transform) {
|
||||
this.autoMergeBatches(this._currComponent!);
|
||||
this._currScene = renderScene;
|
||||
this._currComponent = renderComp;
|
||||
@@ -404,7 +400,6 @@ export class Batcher2D {
|
||||
this._currTexture = texture;
|
||||
this._currSampler = samp;
|
||||
this._currTextureHash = textureHash;
|
||||
this._currSamplerHash = samplerHash;
|
||||
this._currBlendTargetHash = blendTargetHash;
|
||||
this._currDepthStencilStateStage = depthStencilStateStage;
|
||||
this._currLayer = comp.node.layer;
|
||||
@@ -477,7 +472,6 @@ export class Batcher2D {
|
||||
this._currTexture = null;
|
||||
this._currSampler = null;
|
||||
this._currTextureHash = 0;
|
||||
this._currSamplerHash = 0;
|
||||
this._currLayer = 0;
|
||||
}
|
||||
|
||||
@@ -533,7 +527,6 @@ export class Batcher2D {
|
||||
curDrawBatch.inputAssembler = ia;
|
||||
curDrawBatch.useLocalData = this._currTransform;
|
||||
curDrawBatch.textureHash = this._currTextureHash;
|
||||
curDrawBatch.samplerHash = this._currSamplerHash;
|
||||
curDrawBatch.fillPasses(mat, depthStencil, dssHash, blendState, bsHash, null);
|
||||
|
||||
this._batches.push(curDrawBatch);
|
||||
@@ -567,10 +560,9 @@ export class Batcher2D {
|
||||
this._currTexture = frame.getGFXTexture();
|
||||
this._currSampler = frame.getGFXSampler();
|
||||
this._currTextureHash = frame.getHash();
|
||||
this._currSamplerHash = frame.getSamplerHash();
|
||||
} else {
|
||||
this._currTexture = this._currSampler = null;
|
||||
this._currTextureHash = this._currSamplerHash = 0;
|
||||
this._currTextureHash = 0;
|
||||
}
|
||||
this._currLayer = renderComp.node.layer;
|
||||
this._currScene = renderComp._getRenderScene();
|
||||
@@ -592,7 +584,6 @@ export class Batcher2D {
|
||||
this._currComponent = null;
|
||||
this._currTransform = null;
|
||||
this._currTextureHash = 0;
|
||||
this._currSamplerHash = 0;
|
||||
this._currLayer = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@ export class DrawBatch2D {
|
||||
public useLocalData: Node | null = null;
|
||||
public isStatic = false;
|
||||
public textureHash = 0;
|
||||
public samplerHash = 0;
|
||||
private _passes: Pass[] = [];
|
||||
private _shaders: Shader[] = [];
|
||||
private _visFlags: number = UI_VIS_FLAG;
|
||||
|
||||
@@ -32,10 +32,9 @@ import { AttributeName, Buffer, BufferUsageBit, Device, Feature, MemoryUsageBit,
|
||||
import { Mesh } from './mesh';
|
||||
import { Texture2D } from '../../core/assets/texture-2d';
|
||||
import { ImageAsset } from '../../core/assets/image-asset';
|
||||
import { samplerLib } from '../../core/renderer/core/sampler-lib';
|
||||
import { UBOMorph, UNIFORM_NORMAL_MORPH_TEXTURE_BINDING,
|
||||
UNIFORM_POSITION_MORPH_TEXTURE_BINDING, UNIFORM_TANGENT_MORPH_TEXTURE_BINDING } from '../../core/pipeline/define';
|
||||
import { warn, warnID } from '../../core/platform/debug';
|
||||
import { warn } from '../../core/platform/debug';
|
||||
import { Morph, MorphRendering, MorphRenderingInstance, SubMeshMorph } from './morph';
|
||||
import { assertIsNonNullable, assertIsTrue } from '../../core/data/utils/asserts';
|
||||
import { log2, nextPow2 } from '../../core/math/bits';
|
||||
@@ -517,7 +516,7 @@ function createVec4TextureFactory (gfxDevice: Device, vec4Capacity: number) {
|
||||
if (!textureAsset.getGFXTexture()) {
|
||||
warn('Unexpected: failed to create morph texture?');
|
||||
}
|
||||
const sampler = samplerLib.getSampler(gfxDevice, textureAsset.getSamplerHash());
|
||||
const sampler = gfxDevice.getSampler(textureAsset.getSamplerInfo());
|
||||
return {
|
||||
/**
|
||||
* Gets the GFX texture.
|
||||
|
||||
@@ -37,13 +37,12 @@ import { BufferUsageBit, MemoryUsageBit, Attribute, DescriptorSet, Buffer, Buffe
|
||||
import { INST_JOINT_ANIM_INFO, UBOSkinningAnimation, UBOSkinningTexture, UNIFORM_JOINT_TEXTURE_BINDING } from '../../core/pipeline/define';
|
||||
import { Node } from '../../core/scene-graph';
|
||||
import { IMacroPatch, Pass } from '../../core/renderer/core/pass';
|
||||
import { samplerLib } from '../../core/renderer/core/sampler-lib';
|
||||
import { DataPoolManager } from '../skeletal-animation/data-pool-manager';
|
||||
import { ModelType } from '../../core/renderer/scene/model';
|
||||
import { IAnimInfo, IJointTextureHandle, jointTextureSamplerHash } from '../skeletal-animation/skeletal-animation-utils';
|
||||
import { IAnimInfo, IJointTextureHandle, jointTextureSamplerInfo } from '../skeletal-animation/skeletal-animation-utils';
|
||||
import { MorphModel } from './morph-model';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
import { NativeAABB, NativeBakedSkinningModel, NativeSkinningModel } from '../../core/renderer/scene/native-scene';
|
||||
import { NativeAABB, NativeBakedSkinningModel } from '../../core/renderer/scene/native-scene';
|
||||
|
||||
interface IJointsInfo {
|
||||
buffer: Buffer | null;
|
||||
@@ -111,7 +110,7 @@ export class BakedSkinningModel extends MorphModel {
|
||||
if (!this._jointsMedium.buffer) {
|
||||
this._jointsMedium.buffer = this._device.createBuffer(new BufferInfo(
|
||||
BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
|
||||
MemoryUsageBit.HOST | MemoryUsageBit.DEVICE,
|
||||
MemoryUsageBit.DEVICE,
|
||||
UBOSkinningTexture.SIZE,
|
||||
UBOSkinningTexture.SIZE,
|
||||
));
|
||||
@@ -224,7 +223,7 @@ export class BakedSkinningModel extends MorphModel {
|
||||
descriptorSet.bindBuffer(UBOSkinningTexture.BINDING, buffer!);
|
||||
descriptorSet.bindBuffer(UBOSkinningAnimation.BINDING, animInfo.buffer);
|
||||
if (texture) {
|
||||
const sampler = samplerLib.getSampler(this._device, jointTextureSamplerHash);
|
||||
const sampler = this._device.getSampler(jointTextureSamplerInfo);
|
||||
descriptorSet.bindTexture(UNIFORM_JOINT_TEXTURE_BINDING, texture.handle.texture);
|
||||
descriptorSet.bindSampler(UNIFORM_JOINT_TEXTURE_BINDING, sampler);
|
||||
}
|
||||
|
||||
@@ -36,11 +36,10 @@ import { Mesh } from '../assets/mesh';
|
||||
import { Skeleton } from '../assets/skeleton';
|
||||
import { AABB } from '../../core/geometry';
|
||||
import { Address, BufferUsageBit, Filter, Format, FormatInfos,
|
||||
MemoryUsageBit, Feature, Device, Buffer, BufferInfo } from '../../core/gfx';
|
||||
MemoryUsageBit, Feature, Device, Buffer, BufferInfo, Sampler, SamplerInfo } from '../../core/gfx';
|
||||
import { Mat4, Quat, Vec3 } from '../../core/math';
|
||||
import { UBOSkinningAnimation } from '../../core/pipeline/define';
|
||||
import { Node } from '../../core/scene-graph';
|
||||
import { genSamplerHash } from '../../core/renderer/core/sampler-lib';
|
||||
import { ITextureBufferHandle, TextureBufferPool } from '../../core/renderer/core/texture-buffer-pool';
|
||||
|
||||
// change here and cc-skinning.chunk to use other skinning algorithms
|
||||
@@ -103,14 +102,14 @@ function roundUpTextureSize (targetLength: number, formatSize: number) {
|
||||
return Math.ceil(Math.max(MINIMUM_JOINT_TEXTURE_SIZE * formatScale, targetLength) / 12) * 12;
|
||||
}
|
||||
|
||||
export const jointTextureSamplerHash = genSamplerHash([
|
||||
export const jointTextureSamplerInfo = new SamplerInfo(
|
||||
Filter.POINT,
|
||||
Filter.POINT,
|
||||
Filter.NONE,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
]);
|
||||
);
|
||||
|
||||
interface IInternalJointAnimInfo {
|
||||
downstream?: Mat4; // downstream default pose, if present
|
||||
|
||||
@@ -35,8 +35,7 @@ import { SpriteFrame } from '../../../2d/assets/sprite-frame';
|
||||
import { TextureBase } from '../../assets/texture-base';
|
||||
import { Type } from '../../gfx';
|
||||
import { Pass } from '../../renderer/core/pass';
|
||||
import { getDefaultFromType, PropertyType } from '../../renderer/core/pass-utils';
|
||||
import { samplerLib } from '../../renderer/core/sampler-lib';
|
||||
import { getDefaultFromType } from '../../renderer/core/pass-utils';
|
||||
import { IValueProxy, IValueProxyFactory } from '../value-proxy';
|
||||
import { warn } from '../../platform/debug';
|
||||
import { legacyCC } from '../../global-exports';
|
||||
@@ -87,8 +86,8 @@ export class UniformProxyFactory implements IValueProxyFactory {
|
||||
if (!handle) {
|
||||
throw new Error(`Material "${target.name}" has no uniform "${this.uniformName}"`);
|
||||
}
|
||||
const propertyType = Pass.getPropertyTypeFromHandle(handle);
|
||||
if (propertyType === PropertyType.BUFFER) {
|
||||
const type = Pass.getTypeFromHandle(handle);
|
||||
if (type < Type.SAMPLER1D) {
|
||||
const realHandle = this.channelIndex === undefined ? handle : pass.getHandle(this.uniformName, this.channelIndex, Type.FLOAT);
|
||||
if (!realHandle) {
|
||||
throw new Error(`Uniform "${this.uniformName} (in material ${target.name}) has no channel ${this.channelIndex!}"`);
|
||||
@@ -105,7 +104,7 @@ export class UniformProxyFactory implements IValueProxyFactory {
|
||||
pass.setUniform(realHandle, value);
|
||||
},
|
||||
};
|
||||
} if (propertyType === PropertyType.TEXTURE) {
|
||||
} else {
|
||||
const binding = Pass.getBindingFromHandle(handle);
|
||||
const prop = pass.properties[this.uniformName];
|
||||
const texName = prop && prop.value ? `${prop.value as string}-texture` : getDefaultFromType(prop.type) as string;
|
||||
@@ -121,12 +120,11 @@ export class UniformProxyFactory implements IValueProxyFactory {
|
||||
if (!texture || !texture.width || !texture.height) { return; }
|
||||
pass.bindTexture(binding, texture);
|
||||
if (value instanceof TextureBase) {
|
||||
pass.bindSampler(binding, samplerLib.getSampler(legacyCC.game._gfxDevice, value.getSamplerHash()));
|
||||
pass.bindSampler(binding, legacyCC.game._gfxDevice.getSampler(value.getSamplerInfo()));
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
throw new Error(`Animations are not available for uniforms with property type ${propertyType}.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,91 +32,113 @@ import { ccclass, serializable, editable, editorOnly } from 'cc.decorator';
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { Root } from '../root';
|
||||
import { BlendState, DepthStencilState, RasterizerState, DescriptorType,
|
||||
DynamicStateFlags, PrimitiveMode, ShaderStageFlags, Type, IUniform, IAttribute } from '../gfx';
|
||||
|
||||
DynamicStateFlags, PrimitiveMode, ShaderStageFlags, Type, SamplerInfo, Uniform, Attribute, MemoryAccess } from '../gfx';
|
||||
import { RenderPassStage } from '../pipeline/define';
|
||||
import { MacroRecord } from '../renderer/core/pass-utils';
|
||||
import { programLib } from '../renderer/core/program-lib';
|
||||
import { Asset } from './asset';
|
||||
import { legacyCC } from '../global-exports';
|
||||
|
||||
export interface IPropertyInfo {
|
||||
type: number; // auto-extracted from shader
|
||||
handleInfo?: [string, number, number]; // auto-generated from 'target'
|
||||
samplerHash?: number; // auto-generated from 'sampler'
|
||||
value?: number[] | string;
|
||||
}
|
||||
// Pass instance itself are compliant to IPassStates too
|
||||
export interface IPassStates {
|
||||
priority?: number;
|
||||
primitive?: PrimitiveMode;
|
||||
stage?: RenderPassStage;
|
||||
rasterizerState?: RasterizerState;
|
||||
depthStencilState?: DepthStencilState;
|
||||
blendState?: BlendState;
|
||||
dynamicStates?: DynamicStateFlags;
|
||||
phase?: string | number;
|
||||
}
|
||||
export interface IPassInfo extends IPassStates {
|
||||
program: string; // auto-generated from 'vert' and 'frag'
|
||||
embeddedMacros?: MacroRecord;
|
||||
propertyIndex?: number;
|
||||
switch?: string;
|
||||
properties?: Record<string, IPropertyInfo>;
|
||||
}
|
||||
export interface ITechniqueInfo {
|
||||
passes: IPassInfo[];
|
||||
name?: string;
|
||||
}
|
||||
export declare namespace EffectAsset {
|
||||
export interface IPropertyInfo {
|
||||
type: number; // auto-extracted from shader
|
||||
handleInfo?: [string, number, number]; // auto-generated from 'target'
|
||||
samplerHash?: number; // auto-generated from 'sampler'
|
||||
value?: number[] | string;
|
||||
}
|
||||
// Pass instance itself are compliant to IPassStates too
|
||||
export interface IPassStates {
|
||||
priority?: number;
|
||||
primitive?: PrimitiveMode;
|
||||
stage?: RenderPassStage;
|
||||
rasterizerState?: RasterizerState;
|
||||
depthStencilState?: DepthStencilState;
|
||||
blendState?: BlendState;
|
||||
dynamicStates?: DynamicStateFlags;
|
||||
phase?: string | number;
|
||||
}
|
||||
export interface IPassInfo extends IPassStates {
|
||||
program: string; // auto-generated from 'vert' and 'frag'
|
||||
embeddedMacros?: MacroRecord;
|
||||
propertyIndex?: number;
|
||||
switch?: string;
|
||||
properties?: Record<string, IPropertyInfo>;
|
||||
}
|
||||
export interface ITechniqueInfo {
|
||||
passes: IPassInfo[];
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface IBlockInfo {
|
||||
binding: number;
|
||||
name: string;
|
||||
members: IUniform[];
|
||||
count: number;
|
||||
stageFlags: ShaderStageFlags;
|
||||
descriptorType?: DescriptorType;
|
||||
}
|
||||
export interface ISamplerTextureInfo {
|
||||
binding: number;
|
||||
name: string;
|
||||
type: Type;
|
||||
count: number;
|
||||
stageFlags: ShaderStageFlags;
|
||||
descriptorType?: DescriptorType;
|
||||
}
|
||||
export interface IAttributeInfo extends IAttribute {
|
||||
defines: string[];
|
||||
}
|
||||
export interface IDefineInfo {
|
||||
name: string;
|
||||
type: string;
|
||||
range?: number[];
|
||||
options?: string[];
|
||||
default?: string;
|
||||
}
|
||||
export interface IBuiltin {
|
||||
name: string;
|
||||
defines: string[];
|
||||
}
|
||||
export interface IBuiltinInfo {
|
||||
blocks: IBuiltin[];
|
||||
samplerTextures: IBuiltin[];
|
||||
}
|
||||
export interface IShaderInfo {
|
||||
name: string;
|
||||
hash: number;
|
||||
glsl4: { vert: string, frag: string };
|
||||
glsl3: { vert: string, frag: string };
|
||||
glsl1: { vert: string, frag: string };
|
||||
builtins: { globals: IBuiltinInfo, locals: IBuiltinInfo, statistics: Record<string, number> };
|
||||
defines: IDefineInfo[];
|
||||
blocks: IBlockInfo[];
|
||||
samplerTextures: ISamplerTextureInfo[];
|
||||
attributes: IAttributeInfo[];
|
||||
}
|
||||
export interface IPreCompileInfo {
|
||||
[name: string]: boolean[] | number[] | string[];
|
||||
export interface IBufferInfo {
|
||||
binding: number;
|
||||
name: string;
|
||||
count: number;
|
||||
stageFlags: ShaderStageFlags;
|
||||
memoryAccess: MemoryAccess;
|
||||
descriptorType?: DescriptorType;
|
||||
}
|
||||
export interface IBlockInfo {
|
||||
binding: number;
|
||||
name: string;
|
||||
members: Uniform[];
|
||||
count: number;
|
||||
stageFlags: ShaderStageFlags;
|
||||
descriptorType?: DescriptorType;
|
||||
}
|
||||
export interface ISamplerTextureInfo {
|
||||
binding: number;
|
||||
name: string;
|
||||
type: Type;
|
||||
count: number;
|
||||
stageFlags: ShaderStageFlags;
|
||||
descriptorType?: DescriptorType;
|
||||
}
|
||||
export interface IImageInfo {
|
||||
binding: number;
|
||||
name: string;
|
||||
type: Type;
|
||||
count: number;
|
||||
stageFlags: ShaderStageFlags;
|
||||
memoryAccess: MemoryAccess;
|
||||
descriptorType?: DescriptorType;
|
||||
}
|
||||
export interface IAttributeInfo extends Attribute {
|
||||
defines: string[];
|
||||
}
|
||||
export interface IDefineInfo {
|
||||
name: string;
|
||||
type: string;
|
||||
range?: number[];
|
||||
options?: string[];
|
||||
default?: string;
|
||||
}
|
||||
export interface IBuiltin {
|
||||
name: string;
|
||||
defines: string[];
|
||||
}
|
||||
export interface IBuiltinInfo {
|
||||
buffers: IBuiltin[];
|
||||
blocks: IBuiltin[];
|
||||
samplerTextures: IBuiltin[];
|
||||
images: IBuiltin[];
|
||||
}
|
||||
export interface IShaderInfo {
|
||||
name: string;
|
||||
hash: number;
|
||||
glsl4: { vert: string, frag: string };
|
||||
glsl3: { vert: string, frag: string };
|
||||
glsl1: { vert: string, frag: string };
|
||||
builtins: { globals: IBuiltinInfo, locals: IBuiltinInfo, statistics: Record<string, number> };
|
||||
defines: IDefineInfo[];
|
||||
buffers: IBufferInfo[];
|
||||
blocks: IBlockInfo[];
|
||||
samplerTextures: ISamplerTextureInfo[];
|
||||
images: IImageInfo[];
|
||||
attributes: IAttributeInfo[];
|
||||
}
|
||||
export interface IPreCompileInfo {
|
||||
[name: string]: boolean[] | number[] | string[];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +202,7 @@ export class EffectAsset extends Asset {
|
||||
*/
|
||||
@serializable
|
||||
@editable
|
||||
public techniques: ITechniqueInfo[] = [];
|
||||
public techniques: EffectAsset.ITechniqueInfo[] = [];
|
||||
|
||||
/**
|
||||
* @en The shaders used by the current effect.
|
||||
@@ -188,7 +210,7 @@ export class EffectAsset extends Asset {
|
||||
*/
|
||||
@serializable
|
||||
@editable
|
||||
public shaders: IShaderInfo[] = [];
|
||||
public shaders: EffectAsset.IShaderInfo[] = [];
|
||||
|
||||
/**
|
||||
* @en The preprocess macro combinations for the shader
|
||||
@@ -196,7 +218,7 @@ export class EffectAsset extends Asset {
|
||||
*/
|
||||
@serializable
|
||||
@editable
|
||||
public combinations: IPreCompileInfo[] = [];
|
||||
public combinations: EffectAsset.IPreCompileInfo[] = [];
|
||||
|
||||
@serializable
|
||||
@editorOnly
|
||||
|
||||
@@ -32,11 +32,11 @@ import { ccclass, serializable, type } from 'cc.decorator';
|
||||
import { Asset } from './asset';
|
||||
import { EffectAsset } from './effect-asset';
|
||||
import { RenderableComponent } from '../components/renderable-component';
|
||||
import { Texture } from '../gfx';
|
||||
import { Texture, Type } from '../gfx';
|
||||
import { TextureBase } from './texture-base';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { IPassInfoFull, Pass, PassOverrides } from '../renderer/core/pass';
|
||||
import { MacroRecord, MaterialProperty, PropertyType } from '../renderer/core/pass-utils';
|
||||
import { MacroRecord, MaterialProperty } from '../renderer/core/pass-utils';
|
||||
import { Color } from '../math/color';
|
||||
import { warnID } from '../platform/debug';
|
||||
|
||||
@@ -418,8 +418,8 @@ export class Material extends Asset {
|
||||
protected _uploadProperty (pass: Pass, name: string, val: MaterialPropertyFull | MaterialPropertyFull[]) {
|
||||
const handle = pass.getHandle(name);
|
||||
if (!handle) { return false; }
|
||||
const propertyType = Pass.getPropertyTypeFromHandle(handle);
|
||||
if (propertyType === PropertyType.BUFFER) {
|
||||
const type = Pass.getTypeFromHandle(handle);
|
||||
if (type < Type.SAMPLER1D) {
|
||||
if (Array.isArray(val)) {
|
||||
pass.setUniformArray(handle, val as MaterialProperty[]);
|
||||
} else if (val !== null) {
|
||||
@@ -427,16 +427,14 @@ export class Material extends Asset {
|
||||
} else {
|
||||
pass.resetUniform(name);
|
||||
}
|
||||
} else if (propertyType === PropertyType.TEXTURE) {
|
||||
if (Array.isArray(val)) {
|
||||
for (let i = 0; i < val.length; i++) {
|
||||
this._bindTexture(pass, handle, val[i], i);
|
||||
}
|
||||
} else if (val) {
|
||||
this._bindTexture(pass, handle, val);
|
||||
} else {
|
||||
pass.resetTexture(name);
|
||||
} else if (Array.isArray(val)) {
|
||||
for (let i = 0; i < val.length; i++) {
|
||||
this._bindTexture(pass, handle, val[i], i);
|
||||
}
|
||||
} else if (val) {
|
||||
this._bindTexture(pass, handle, val);
|
||||
} else {
|
||||
pass.resetTexture(name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -29,17 +29,15 @@
|
||||
*/
|
||||
|
||||
import { ccclass, rangeMin, rangeMax, serializable } from 'cc.decorator';
|
||||
import { Texture, Sampler, ColorAttachment, DepthStencilAttachment, AccessType, RenderPassInfo } from '../gfx';
|
||||
import { Texture, Sampler, ColorAttachment, DepthStencilAttachment, AccessType, RenderPassInfo, SamplerInfo, Format } from '../gfx';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { RenderWindow, IRenderWindowInfo } from '../renderer/core/render-window';
|
||||
|
||||
import { Root } from '../root';
|
||||
import { TextureBase } from './texture-base';
|
||||
import { samplerLib, defaultSamplerHash } from '../renderer/core/sampler-lib';
|
||||
import { IDGenerator } from '../utils/js';
|
||||
import { murmurhash2_32_gc } from '../utils/murmurhash2_gc';
|
||||
|
||||
const idGenerator = new IDGenerator('RenderTex');
|
||||
const defaultSamplerInfo = new SamplerInfo();
|
||||
|
||||
export interface IRenderTextureCreateInfo {
|
||||
name?: string;
|
||||
@@ -49,8 +47,11 @@ export interface IRenderTextureCreateInfo {
|
||||
}
|
||||
|
||||
const _colorAttachment = new ColorAttachment();
|
||||
_colorAttachment.format = Format.RGBA8;
|
||||
_colorAttachment.beginAccesses = [AccessType.FRAGMENT_SHADER_READ_TEXTURE];
|
||||
_colorAttachment.endAccesses = [AccessType.FRAGMENT_SHADER_READ_TEXTURE];
|
||||
const _depthStencilAttachment = new DepthStencilAttachment();
|
||||
_depthStencilAttachment.format = Format.DEPTH_STENCIL;
|
||||
const passInfo = new RenderPassInfo([_colorAttachment], _depthStencilAttachment);
|
||||
|
||||
const _windowInfo: IRenderWindowInfo = {
|
||||
@@ -157,15 +158,15 @@ export class RenderTexture extends TextureBase {
|
||||
*/
|
||||
public getGFXSampler (): Sampler {
|
||||
const root = legacyCC.director.root as Root;
|
||||
return samplerLib.getSampler(root.device, defaultSamplerHash);
|
||||
return root.device.getSampler(defaultSamplerInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Gets the sampler hash for the render texture
|
||||
* @zh 获取渲染贴图的采样器哈希值
|
||||
*/
|
||||
public getSamplerHash () {
|
||||
return defaultSamplerHash;
|
||||
public getSamplerInfo () {
|
||||
return defaultSamplerInfo;
|
||||
}
|
||||
|
||||
public onLoaded () {
|
||||
|
||||
@@ -231,7 +231,7 @@ export class SimpleTexture extends TextureBase {
|
||||
usage: TextureUsageBit.SAMPLED | TextureUsageBit.TRANSFER_DST,
|
||||
format: this._getGFXFormat(),
|
||||
levelCount: this._mipmapLevel,
|
||||
flags: flags | TextureFlagBit.IMMUTABLE,
|
||||
flags,
|
||||
});
|
||||
if (!textureCreateInfo) {
|
||||
return;
|
||||
|
||||
@@ -32,11 +32,10 @@
|
||||
// @ts-check
|
||||
import { EDITOR, TEST } from 'internal:constants';
|
||||
import { ccclass, serializable } from 'cc.decorator';
|
||||
import { genSamplerHash, SamplerInfoIndex, samplerLib } from '../renderer/core/sampler-lib';
|
||||
import IDGenerator from '../utils/id-generator';
|
||||
import { Asset } from './asset';
|
||||
import { Filter, PixelFormat, WrapMode } from './asset-enum';
|
||||
import { Sampler, Texture, Device, Format } from '../gfx';
|
||||
import { Sampler, Texture, Device, Format, SamplerInfo, Address, Filter as GFXFilter } from '../gfx';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { errorID } from '../platform/debug';
|
||||
import { murmurhash2_32_gc } from '../utils/murmurhash2_gc';
|
||||
@@ -92,25 +91,25 @@ export class TextureBase extends Asset {
|
||||
public static Filter = Filter;
|
||||
|
||||
@serializable
|
||||
protected _format: number = PixelFormat.RGBA8888;
|
||||
protected _format = PixelFormat.RGBA8888;
|
||||
|
||||
@serializable
|
||||
protected _minFilter: number = Filter.LINEAR;
|
||||
protected _minFilter = Filter.LINEAR;
|
||||
|
||||
@serializable
|
||||
protected _magFilter: number = Filter.LINEAR;
|
||||
protected _magFilter = Filter.LINEAR;
|
||||
|
||||
@serializable
|
||||
protected _mipFilter: number = Filter.NONE;
|
||||
protected _mipFilter = Filter.NONE;
|
||||
|
||||
@serializable
|
||||
protected _wrapS: number = WrapMode.REPEAT;
|
||||
protected _wrapS = WrapMode.REPEAT;
|
||||
|
||||
@serializable
|
||||
protected _wrapT: number = WrapMode.REPEAT;
|
||||
protected _wrapT = WrapMode.REPEAT;
|
||||
|
||||
@serializable
|
||||
protected _wrapR: number = WrapMode.REPEAT;
|
||||
protected _wrapR = WrapMode.REPEAT;
|
||||
|
||||
@serializable
|
||||
protected _anisotropy = 0;
|
||||
@@ -119,8 +118,7 @@ export class TextureBase extends Asset {
|
||||
protected _height = 1;
|
||||
|
||||
private _id: string;
|
||||
private _samplerInfo: (number | undefined)[] = [];
|
||||
private _samplerHash = 0;
|
||||
private _samplerInfo = new SamplerInfo();
|
||||
private _gfxSampler: Sampler | null = null;
|
||||
private _gfxDevice: Device | null = null;
|
||||
|
||||
@@ -173,18 +171,17 @@ export class TextureBase extends Asset {
|
||||
*/
|
||||
public setWrapMode (wrapS: WrapMode, wrapT: WrapMode, wrapR?: WrapMode) {
|
||||
this._wrapS = wrapS;
|
||||
this._samplerInfo[SamplerInfoIndex.addressU] = wrapS;
|
||||
this._samplerInfo.addressU = wrapS as unknown as Address;
|
||||
this._wrapT = wrapT;
|
||||
this._samplerInfo[SamplerInfoIndex.addressV] = wrapT;
|
||||
this._samplerInfo.addressV = wrapT as unknown as Address;
|
||||
|
||||
if (wrapR !== undefined) {
|
||||
this._wrapR = wrapR;
|
||||
this._samplerInfo[SamplerInfoIndex.addressW] = wrapR;
|
||||
this._samplerInfo.addressW = wrapR as unknown as Address;
|
||||
}
|
||||
|
||||
this._samplerHash = genSamplerHash(this._samplerInfo);
|
||||
// for editor assetDB
|
||||
if (this._gfxDevice) {
|
||||
this._gfxSampler = samplerLib.getSampler(this._gfxDevice, this._samplerHash);
|
||||
this._gfxSampler = this._gfxDevice.getSampler(this._samplerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,12 +193,12 @@ export class TextureBase extends Asset {
|
||||
*/
|
||||
public setFilters (minFilter: Filter, magFilter: Filter) {
|
||||
this._minFilter = minFilter;
|
||||
this._samplerInfo[SamplerInfoIndex.minFilter] = minFilter;
|
||||
this._samplerInfo.minFilter = minFilter as unknown as GFXFilter;
|
||||
this._magFilter = magFilter;
|
||||
this._samplerInfo[SamplerInfoIndex.magFilter] = magFilter;
|
||||
this._samplerHash = genSamplerHash(this._samplerInfo);
|
||||
this._samplerInfo.magFilter = magFilter as unknown as GFXFilter;
|
||||
|
||||
if (this._gfxDevice) {
|
||||
this._gfxSampler = samplerLib.getSampler(this._gfxDevice, this._samplerHash);
|
||||
this._gfxSampler = this._gfxDevice.getSampler(this._samplerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,10 +209,10 @@ export class TextureBase extends Asset {
|
||||
*/
|
||||
public setMipFilter (mipFilter: Filter) {
|
||||
this._mipFilter = mipFilter;
|
||||
this._samplerInfo[SamplerInfoIndex.mipFilter] = mipFilter;
|
||||
this._samplerHash = genSamplerHash(this._samplerInfo);
|
||||
this._samplerInfo.mipFilter = mipFilter as unknown as GFXFilter;
|
||||
|
||||
if (this._gfxDevice) {
|
||||
this._gfxSampler = samplerLib.getSampler(this._gfxDevice, this._samplerHash);
|
||||
this._gfxSampler = this._gfxDevice.getSampler(this._samplerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,10 +223,10 @@ export class TextureBase extends Asset {
|
||||
*/
|
||||
public setAnisotropy (anisotropy: number) {
|
||||
this._anisotropy = anisotropy;
|
||||
this._samplerInfo[SamplerInfoIndex.maxAnisotropy] = anisotropy;
|
||||
this._samplerHash = genSamplerHash(this._samplerInfo);
|
||||
this._samplerInfo.maxAnisotropy = anisotropy;
|
||||
|
||||
if (this._gfxDevice) {
|
||||
this._gfxSampler = samplerLib.getSampler(this._gfxDevice, this._samplerHash);
|
||||
this._gfxSampler = this._gfxDevice.getSampler(this._samplerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,8 +263,8 @@ export class TextureBase extends Asset {
|
||||
* @zh 获取此贴图内部使用的 GFX 采样器信息。
|
||||
* @private
|
||||
*/
|
||||
public getSamplerHash () {
|
||||
return this._samplerHash;
|
||||
public getSamplerInfo (): Readonly<SamplerInfo> {
|
||||
return this._samplerInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +274,7 @@ export class TextureBase extends Asset {
|
||||
public getGFXSampler () {
|
||||
if (!this._gfxSampler) {
|
||||
if (this._gfxDevice) {
|
||||
this._gfxSampler = samplerLib.getSampler(this._gfxDevice, this._samplerHash);
|
||||
this._gfxSampler = this._gfxDevice.getSampler(this._samplerInfo);
|
||||
} else {
|
||||
errorID(9302);
|
||||
}
|
||||
@@ -334,7 +331,7 @@ export class TextureBase extends Asset {
|
||||
this._format = format === undefined ? PixelFormat.RGBA8888 : format;
|
||||
}
|
||||
|
||||
protected _getGFXPixelFormat (format) {
|
||||
protected _getGFXPixelFormat (format: PixelFormat) {
|
||||
if (format === PixelFormat.RGBA_ETC1) {
|
||||
format = PixelFormat.RGB_ETC1;
|
||||
} else if (format === PixelFormat.RGB_A_PVRTC_4BPPV1) {
|
||||
@@ -342,7 +339,7 @@ export class TextureBase extends Asset {
|
||||
} else if (format === PixelFormat.RGB_A_PVRTC_2BPPV1) {
|
||||
format = PixelFormat.RGB_PVRTC_2BPPV1;
|
||||
}
|
||||
return format as Format;
|
||||
return format as unknown as Format;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+210
-165
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -793,8 +793,7 @@ export class Director extends EventTarget {
|
||||
private _init () {
|
||||
// The test environment does not currently support the renderer
|
||||
if (TEST) return Promise.resolve();
|
||||
// @ts-expect-error internal api usage
|
||||
this._root = new Root(game._gfxDevice);
|
||||
this._root = new Root(game._gfxDevice!);
|
||||
const rootInfo = {};
|
||||
return this._root.initialize(rootInfo).catch((error) => {
|
||||
errorID(1217);
|
||||
|
||||
+14
-13
@@ -34,7 +34,7 @@ import { IAssetManagerOptions } from './asset-manager/asset-manager';
|
||||
import { EventTarget } from './event/event-target';
|
||||
import * as debug from './platform/debug';
|
||||
import inputManager from './platform/event-manager/input-manager';
|
||||
import { Device, DeviceInfo } from './gfx';
|
||||
import { Device, DeviceInfo, SampleCount, Swapchain, SwapchainInfo } from './gfx';
|
||||
import { sys } from './platform/sys';
|
||||
import { macro } from './platform/macro';
|
||||
import { ICustomJointTextureLayout } from '../3d/skeletal-animation/skeletal-animation-utils';
|
||||
@@ -366,7 +366,8 @@ export class Game extends EventTarget {
|
||||
|
||||
public _persistRootNodes = {};
|
||||
|
||||
private _gfxDevice: Device | null = null;
|
||||
public _gfxDevice: Device | null = null;
|
||||
public _swapchain: Swapchain | null = null;
|
||||
// states
|
||||
public _configLoaded = false; // whether config loaded
|
||||
public _isCloning = false; // deserializing or instantiating
|
||||
@@ -825,18 +826,10 @@ export class Game extends EventTarget {
|
||||
if (this.renderType === Game.RENDER_TYPE_WEBGL) {
|
||||
const ctors: Constructor<Device>[] = [];
|
||||
|
||||
const opts = new DeviceInfo(
|
||||
this.canvas as HTMLCanvasElement,
|
||||
EDITOR || macro.ENABLE_WEBGL_ANTIALIAS,
|
||||
false,
|
||||
window.devicePixelRatio,
|
||||
sys.windowPixelResolution.width,
|
||||
sys.windowPixelResolution.height,
|
||||
bindingMappingInfo,
|
||||
);
|
||||
const deviceInfo = new DeviceInfo(bindingMappingInfo);
|
||||
|
||||
if (JSB && window.gfx) {
|
||||
this._gfxDevice = gfx.DeviceManager.create(opts);
|
||||
this._gfxDevice = gfx.DeviceManager.create(deviceInfo);
|
||||
} else {
|
||||
let useWebGL2 = (!!window.WebGL2RenderingContext);
|
||||
const userAgent = window.navigator.userAgent.toLowerCase();
|
||||
@@ -851,10 +844,13 @@ export class Game extends EventTarget {
|
||||
if (legacyCC.WebGLDevice) {
|
||||
ctors.push(legacyCC.WebGLDevice);
|
||||
}
|
||||
if (legacyCC.EmptyDevice) {
|
||||
ctors.push(legacyCC.EmptyDevice);
|
||||
}
|
||||
|
||||
for (let i = 0; i < ctors.length; i++) {
|
||||
this._gfxDevice = new ctors[i]();
|
||||
if (this._gfxDevice.initialize(opts)) { break; }
|
||||
if (this._gfxDevice.initialize(deviceInfo)) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -866,6 +862,11 @@ export class Game extends EventTarget {
|
||||
return;
|
||||
}
|
||||
|
||||
const swapchainInfo = new SwapchainInfo(this.canvas!);
|
||||
swapchainInfo.width = sys.windowPixelResolution.width;
|
||||
swapchainInfo.height = sys.windowPixelResolution.height;
|
||||
this._swapchain = this._gfxDevice.createSwapchain(swapchainInfo);
|
||||
|
||||
this.canvas!.oncontextmenu = () => false;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import {
|
||||
BufferFlagBit,
|
||||
BufferFlags,
|
||||
@@ -36,9 +35,8 @@ import {
|
||||
BufferUsageBit,
|
||||
MemoryUsage,
|
||||
MemoryUsageBit,
|
||||
Obj,
|
||||
GFXObject,
|
||||
ObjectType,
|
||||
IndirectBuffer,
|
||||
BufferInfo,
|
||||
BufferViewInfo,
|
||||
BufferSource,
|
||||
@@ -48,7 +46,7 @@ import {
|
||||
* @en GFX buffer.
|
||||
* @zh GFX 缓冲。
|
||||
*/
|
||||
export abstract class Buffer extends Obj {
|
||||
export abstract class Buffer extends GFXObject {
|
||||
/**
|
||||
* @en Usage type of the buffer.
|
||||
* @zh 缓冲使用方式。
|
||||
@@ -93,22 +91,19 @@ export abstract class Buffer extends Obj {
|
||||
return this._flags;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
protected _usage: BufferUsage = BufferUsageBit.NONE;
|
||||
protected _memUsage: MemoryUsage = MemoryUsageBit.NONE;
|
||||
protected _size = 0;
|
||||
protected _stride = 1;
|
||||
protected _count = 0;
|
||||
protected _flags: BufferFlags = BufferFlagBit.NONE;
|
||||
protected _indirectBuffer: IndirectBuffer | null = null;
|
||||
protected _isBufferView = false;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.BUFFER);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: BufferInfo | BufferViewInfo): boolean;
|
||||
public abstract initialize (info: BufferInfo | BufferViewInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
import { Buffer } from './buffer';
|
||||
import { DescriptorSet } from './descriptor-set';
|
||||
import { Device } from './device';
|
||||
import { Framebuffer } from './framebuffer';
|
||||
import { InputAssembler } from './input-assembler';
|
||||
import { PipelineState } from './pipeline-state';
|
||||
@@ -38,22 +37,22 @@ import { Queue } from './queue';
|
||||
import { RenderPass } from './render-pass';
|
||||
import { Texture } from './texture';
|
||||
import {
|
||||
Obj,
|
||||
GFXObject,
|
||||
ObjectType,
|
||||
StencilFace,
|
||||
CommandBufferType,
|
||||
CommandBufferInfo,
|
||||
BufferTextureCopy, Color, Rect, Viewport, DrawInfo,
|
||||
} from './define';
|
||||
import { GlobalBarrier } from './global-barrier';
|
||||
import { TextureBarrier } from './texture-barrier';
|
||||
import { GlobalBarrier } from './states/global-barrier';
|
||||
import { TextureBarrier } from './states/texture-barrier';
|
||||
|
||||
/**
|
||||
* @en GFX command buffer.
|
||||
* @zh GFX 命令缓冲。
|
||||
*/
|
||||
|
||||
export abstract class CommandBuffer extends Obj {
|
||||
export abstract class CommandBuffer extends GFXObject {
|
||||
/**
|
||||
* @en Type of the command buffer.
|
||||
* @zh 命令缓冲类型。
|
||||
@@ -94,24 +93,17 @@ export abstract class CommandBuffer extends Obj {
|
||||
return this._numTris;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _queue: Queue | null = null;
|
||||
|
||||
protected _type: CommandBufferType = CommandBufferType.PRIMARY;
|
||||
|
||||
protected _numDrawCalls = 0;
|
||||
|
||||
protected _numInstances = 0;
|
||||
|
||||
protected _numTris = 0;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.COMMAND_BUFFER);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: CommandBufferInfo): boolean;
|
||||
public abstract initialize (info: CommandBufferInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
|
||||
@@ -238,9 +230,9 @@ export abstract class CommandBuffer extends Obj {
|
||||
/**
|
||||
* @en Draw the specified primitives.
|
||||
* @zh 绘制。
|
||||
* @param info The draw call information.
|
||||
* @param infoOrAssembler The draw call information.
|
||||
*/
|
||||
public abstract draw (info: DrawInfo | InputAssembler): void;
|
||||
public abstract draw (infoOrAssembler: DrawInfo | InputAssembler): void;
|
||||
|
||||
/**
|
||||
* @en Update buffer.
|
||||
@@ -275,5 +267,5 @@ export abstract class CommandBuffer extends Obj {
|
||||
* @param globalBarrier The global memory barrier to apply.
|
||||
* @param textureBarriers The texture memory barriers to apply.
|
||||
*/
|
||||
public abstract pipelineBarrier (globalBarrier: GlobalBarrier, textureBarriers: TextureBarrier[] | null): void;
|
||||
public abstract pipelineBarrier (globalBarrier: GlobalBarrier | null, textureBarriers?: TextureBarrier[], textures?: Texture[]): void;
|
||||
}
|
||||
|
||||
+158
-137
@@ -28,11 +28,13 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { ccenum } from '../../value-types/enum';
|
||||
import { Buffer } from './buffer';
|
||||
import { DescriptorSetLayout } from './descriptor-set-layout';
|
||||
import { Queue } from './queue';
|
||||
import { RenderPass } from './render-pass';
|
||||
import { Sampler } from './sampler';
|
||||
import { Sampler } from './states/sampler';
|
||||
import { Swapchain } from './swapchain';
|
||||
import { Texture } from './texture';
|
||||
|
||||
interface ICopyable { copy(info: ICopyable): ICopyable; }
|
||||
@@ -55,6 +57,7 @@ const deepCopy = <T extends ICopyable>(target: T[], source: T[], Ctor: Construct
|
||||
|
||||
export enum ObjectType {
|
||||
UNKNOWN,
|
||||
SWAPCHAIN,
|
||||
BUFFER,
|
||||
TEXTURE,
|
||||
RENDER_PASS,
|
||||
@@ -71,6 +74,7 @@ export enum ObjectType {
|
||||
GLOBAL_BARRIER,
|
||||
TEXTURE_BARRIER,
|
||||
BUFFER_BARRIER,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
export enum Status {
|
||||
@@ -185,12 +189,8 @@ export enum Format {
|
||||
RGB9E5,
|
||||
|
||||
// Depth-Stencil Format
|
||||
D16,
|
||||
D16S8,
|
||||
D24,
|
||||
D24S8,
|
||||
D32F,
|
||||
D32F_S8,
|
||||
DEPTH,
|
||||
DEPTH_STENCIL,
|
||||
|
||||
// Compressed Format
|
||||
|
||||
@@ -367,8 +367,8 @@ export enum MemoryAccessBit {
|
||||
|
||||
export enum MemoryUsageBit {
|
||||
NONE = 0,
|
||||
DEVICE = 0x1,
|
||||
HOST = 0x2,
|
||||
DEVICE = 0x1, // for rarely-updated resources, use MemoryUsageBit::DEVICE
|
||||
HOST = 0x2, // for frequently-updated resources, use MemoryUsageBit::DEVICE | MemoryUsageBit::HOST
|
||||
}
|
||||
|
||||
export enum TextureType {
|
||||
@@ -393,19 +393,40 @@ export enum TextureUsageBit {
|
||||
|
||||
export enum TextureFlagBit {
|
||||
NONE = 0,
|
||||
GEN_MIPMAP = 0x1,
|
||||
IMMUTABLE = 0x2,
|
||||
GENERAL_LAYOUT = 0x4,
|
||||
GEN_MIPMAP = 0x1, // Generate mipmaps using bilinear filter
|
||||
RESIZABLE = 0x2, // Make the texture resizable, should be avoided whenever possible
|
||||
GENERAL_LAYOUT = 0x4, // For inout framebuffer attachments
|
||||
}
|
||||
|
||||
export enum SampleCount {
|
||||
X1 = 0x1,
|
||||
X2 = 0x2,
|
||||
X4 = 0x4,
|
||||
X8 = 0x8,
|
||||
X16 = 0x10,
|
||||
X32 = 0x20,
|
||||
X64 = 0x40,
|
||||
ONE, // Single sample
|
||||
MULTIPLE_PERFORMANCE, // Multiple samples prioritizing performance over quality
|
||||
MULTIPLE_BALANCE, // Multiple samples leveraging both quality and performance
|
||||
MULTIPLE_QUALITY, // Multiple samples prioritizing quality over performance
|
||||
}
|
||||
|
||||
export enum VsyncMode {
|
||||
// The application does not synchronizes with the vertical sync.
|
||||
// If application renders faster than the display refreshes, frames are wasted and tearing may be observed.
|
||||
// FPS is uncapped. Maximum power consumption. If unsupported, "ON" value will be used instead. Minimum latency.
|
||||
OFF,
|
||||
// The application is always synchronized with the vertical sync. Tearing does not happen.
|
||||
// FPS is capped to the display's refresh rate. For fast applications, battery life is improved. Always supported.
|
||||
ON,
|
||||
// The application synchronizes with the vertical sync, but only if the application rendering speed is greater than refresh rate.
|
||||
// Compared to OFF, there is no tearing. Compared to ON, the FPS will be improved for "slower" applications.
|
||||
// If unsupported, "ON" value will be used instead. Recommended for most applications. Default if supported.
|
||||
RELAXED,
|
||||
// The presentation engine will always use the latest fully rendered image.
|
||||
// Compared to OFF, no tearing will be observed.
|
||||
// Compared to ON, battery power will be worse, especially for faster applications.
|
||||
// If unsupported, "OFF" will be attempted next.
|
||||
MAILBOX,
|
||||
// The application is capped to using half the vertical sync time.
|
||||
// FPS artificially capped to Half the display speed (usually 30fps) to maintain battery.
|
||||
// Best possible battery savings. Worst possible performance.
|
||||
// Recommended for specific applications where battery saving is critical.
|
||||
HALF,
|
||||
}
|
||||
|
||||
export enum Filter {
|
||||
@@ -655,7 +676,7 @@ export class Size {
|
||||
public z: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Size) {
|
||||
public copy (info: Readonly<Size>) {
|
||||
this.x = info.x;
|
||||
this.y = info.y;
|
||||
this.z = info.z;
|
||||
@@ -680,8 +701,6 @@ export class DeviceCaps {
|
||||
public maxUniformBlockSize: number = 0,
|
||||
public maxTextureSize: number = 0,
|
||||
public maxCubeMapTextureSize: number = 0,
|
||||
public depthBits: number = 0,
|
||||
public stencilBits: number = 0,
|
||||
public uboOffsetAlignment: number = 1,
|
||||
public maxComputeSharedMemorySize: number = 0,
|
||||
public maxComputeWorkGroupInvocations: number = 0,
|
||||
@@ -692,7 +711,7 @@ export class DeviceCaps {
|
||||
public clipSpaceSignY: number = 1,
|
||||
) {}
|
||||
|
||||
public copy (info: DeviceCaps) {
|
||||
public copy (info: Readonly<DeviceCaps>) {
|
||||
this.maxVertexAttributes = info.maxVertexAttributes;
|
||||
this.maxVertexUniformVectors = info.maxVertexUniformVectors;
|
||||
this.maxFragmentUniformVectors = info.maxFragmentUniformVectors;
|
||||
@@ -706,8 +725,6 @@ export class DeviceCaps {
|
||||
this.maxUniformBlockSize = info.maxUniformBlockSize;
|
||||
this.maxTextureSize = info.maxTextureSize;
|
||||
this.maxCubeMapTextureSize = info.maxCubeMapTextureSize;
|
||||
this.depthBits = info.depthBits;
|
||||
this.stencilBits = info.stencilBits;
|
||||
this.uboOffsetAlignment = info.uboOffsetAlignment;
|
||||
this.maxComputeSharedMemorySize = info.maxComputeSharedMemorySize;
|
||||
this.maxComputeWorkGroupInvocations = info.maxComputeWorkGroupInvocations;
|
||||
@@ -729,7 +746,7 @@ export class Offset {
|
||||
public z: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Offset) {
|
||||
public copy (info: Readonly<Offset>) {
|
||||
this.x = info.x;
|
||||
this.y = info.y;
|
||||
this.z = info.z;
|
||||
@@ -747,7 +764,7 @@ export class Rect {
|
||||
public height: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Rect) {
|
||||
public copy (info: Readonly<Rect>) {
|
||||
this.x = info.x;
|
||||
this.y = info.y;
|
||||
this.width = info.width;
|
||||
@@ -765,7 +782,7 @@ export class Extent {
|
||||
public depth: number = 1,
|
||||
) {}
|
||||
|
||||
public copy (info: Extent) {
|
||||
public copy (info: Readonly<Extent>) {
|
||||
this.width = info.width;
|
||||
this.height = info.height;
|
||||
this.depth = info.depth;
|
||||
@@ -782,7 +799,7 @@ export class TextureSubresLayers {
|
||||
public layerCount: number = 1,
|
||||
) {}
|
||||
|
||||
public copy (info: TextureSubresLayers) {
|
||||
public copy (info: Readonly<TextureSubresLayers>) {
|
||||
this.mipLevel = info.mipLevel;
|
||||
this.baseArrayLayer = info.baseArrayLayer;
|
||||
this.layerCount = info.layerCount;
|
||||
@@ -800,7 +817,7 @@ export class TextureSubresRange {
|
||||
public layerCount: number = 1,
|
||||
) {}
|
||||
|
||||
public copy (info: TextureSubresRange) {
|
||||
public copy (info: Readonly<TextureSubresRange>) {
|
||||
this.baseMipLevel = info.baseMipLevel;
|
||||
this.levelCount = info.levelCount;
|
||||
this.baseArrayLayer = info.baseArrayLayer;
|
||||
@@ -820,7 +837,7 @@ export class TextureCopy {
|
||||
public extent: Extent = new Extent(),
|
||||
) {}
|
||||
|
||||
public copy (info: TextureCopy) {
|
||||
public copy (info: Readonly<TextureCopy>) {
|
||||
this.srcSubres.copy(info.srcSubres);
|
||||
this.srcOffset.copy(info.srcOffset);
|
||||
this.dstSubres.copy(info.dstSubres);
|
||||
@@ -842,7 +859,7 @@ export class TextureBlit {
|
||||
public dstExtent: Extent = new Extent(),
|
||||
) {}
|
||||
|
||||
public copy (info: TextureBlit) {
|
||||
public copy (info: Readonly<TextureBlit>) {
|
||||
this.srcSubres.copy(info.srcSubres);
|
||||
this.srcOffset.copy(info.srcOffset);
|
||||
this.srcExtent.copy(info.srcExtent);
|
||||
@@ -864,7 +881,7 @@ export class BufferTextureCopy {
|
||||
public texSubres: TextureSubresLayers = new TextureSubresLayers(),
|
||||
) {}
|
||||
|
||||
public copy (info: BufferTextureCopy) {
|
||||
public copy (info: Readonly<BufferTextureCopy>) {
|
||||
this.buffStride = info.buffStride;
|
||||
this.buffTexHeight = info.buffTexHeight;
|
||||
this.texOffset.copy(info.texOffset);
|
||||
@@ -886,7 +903,7 @@ export class Viewport {
|
||||
public maxDepth: number = 1,
|
||||
) {}
|
||||
|
||||
public copy (info: Viewport) {
|
||||
public copy (info: Readonly<Viewport>) {
|
||||
this.left = info.left;
|
||||
this.top = info.top;
|
||||
this.width = info.width;
|
||||
@@ -907,7 +924,7 @@ export class Color {
|
||||
public w: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Color) {
|
||||
public copy (info: Readonly<Color>) {
|
||||
this.x = info.x;
|
||||
this.y = info.y;
|
||||
this.z = info.z;
|
||||
@@ -925,7 +942,7 @@ export class BindingMappingInfo {
|
||||
public flexibleSet: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: BindingMappingInfo) {
|
||||
public copy (info: Readonly<BindingMappingInfo>) {
|
||||
this.bufferOffsets = info.bufferOffsets.slice();
|
||||
this.samplerOffsets = info.samplerOffsets.slice();
|
||||
this.flexibleSet = info.flexibleSet;
|
||||
@@ -933,6 +950,38 @@ export class BindingMappingInfo {
|
||||
}
|
||||
}
|
||||
|
||||
export class SwapchainInfo {
|
||||
declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object
|
||||
|
||||
constructor (
|
||||
public windowHandle: HTMLCanvasElement = null!,
|
||||
public vsyncMode: VsyncMode = VsyncMode.RELAXED,
|
||||
public width: number = 0,
|
||||
public height: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<SwapchainInfo>) {
|
||||
this.windowHandle = info.windowHandle;
|
||||
this.vsyncMode = info.vsyncMode;
|
||||
this.width = info.width;
|
||||
this.height = info.height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export class DeviceInfo {
|
||||
declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object
|
||||
|
||||
constructor (
|
||||
public bindingMappingInfo: BindingMappingInfo = new BindingMappingInfo(),
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<DeviceInfo>) {
|
||||
this.bindingMappingInfo.copy(info.bindingMappingInfo);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export class BufferInfo {
|
||||
declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object
|
||||
|
||||
@@ -944,7 +993,7 @@ export class BufferInfo {
|
||||
public flags: BufferFlags = BufferFlagBit.NONE,
|
||||
) {}
|
||||
|
||||
public copy (info: BufferInfo) {
|
||||
public copy (info: Readonly<BufferInfo>) {
|
||||
this.usage = info.usage;
|
||||
this.memUsage = info.memUsage;
|
||||
this.size = info.size;
|
||||
@@ -963,7 +1012,7 @@ export class BufferViewInfo {
|
||||
public range: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: BufferViewInfo) {
|
||||
public copy (info: Readonly<BufferViewInfo>) {
|
||||
this.buffer = info.buffer;
|
||||
this.offset = info.offset;
|
||||
this.range = info.range;
|
||||
@@ -984,7 +1033,7 @@ export class DrawInfo {
|
||||
public firstInstance: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: DrawInfo) {
|
||||
public copy (info: Readonly<DrawInfo>) {
|
||||
this.vertexCount = info.vertexCount;
|
||||
this.firstVertex = info.firstVertex;
|
||||
this.indexCount = info.indexCount;
|
||||
@@ -1007,7 +1056,7 @@ export class DispatchInfo {
|
||||
public indirectOffset: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: DispatchInfo) {
|
||||
public copy (info: Readonly<DispatchInfo>) {
|
||||
this.groupCountX = info.groupCountX;
|
||||
this.groupCountY = info.groupCountY;
|
||||
this.groupCountZ = info.groupCountZ;
|
||||
@@ -1024,7 +1073,7 @@ export class IndirectBuffer {
|
||||
public drawInfos: DrawInfo[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: IndirectBuffer) {
|
||||
public copy (info: Readonly<IndirectBuffer>) {
|
||||
deepCopy(this.drawInfos, info.drawInfos, DrawInfo);
|
||||
return this;
|
||||
}
|
||||
@@ -1042,11 +1091,12 @@ export class TextureInfo {
|
||||
public flags: TextureFlags = TextureFlagBit.NONE,
|
||||
public layerCount: number = 1,
|
||||
public levelCount: number = 1,
|
||||
public samples: SampleCount = SampleCount.X1,
|
||||
public samples: SampleCount = SampleCount.ONE,
|
||||
public depth: number = 1,
|
||||
public externalRes: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: TextureInfo) {
|
||||
public copy (info: Readonly<TextureInfo>) {
|
||||
this.type = info.type;
|
||||
this.usage = info.usage;
|
||||
this.format = info.format;
|
||||
@@ -1057,6 +1107,7 @@ export class TextureInfo {
|
||||
this.levelCount = info.levelCount;
|
||||
this.samples = info.samples;
|
||||
this.depth = info.depth;
|
||||
this.externalRes = info.externalRes;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1074,7 +1125,7 @@ export class TextureViewInfo {
|
||||
public layerCount: number = 1,
|
||||
) {}
|
||||
|
||||
public copy (info: TextureViewInfo) {
|
||||
public copy (info: Readonly<TextureViewInfo>) {
|
||||
this.texture = info.texture;
|
||||
this.type = info.type;
|
||||
this.format = info.format;
|
||||
@@ -1098,11 +1149,9 @@ export class SamplerInfo {
|
||||
public addressW: Address = Address.WRAP,
|
||||
public maxAnisotropy: number = 0,
|
||||
public cmpFunc: ComparisonFunc = ComparisonFunc.ALWAYS,
|
||||
public borderColor: Color = new Color(),
|
||||
public mipLODBias: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: SamplerInfo) {
|
||||
public copy (info: Readonly<SamplerInfo>) {
|
||||
this.minFilter = info.minFilter;
|
||||
this.magFilter = info.magFilter;
|
||||
this.mipFilter = info.mipFilter;
|
||||
@@ -1111,8 +1160,6 @@ export class SamplerInfo {
|
||||
this.addressW = info.addressW;
|
||||
this.maxAnisotropy = info.maxAnisotropy;
|
||||
this.cmpFunc = info.cmpFunc;
|
||||
this.borderColor.copy(info.borderColor);
|
||||
this.mipLODBias = info.mipLODBias;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1126,7 +1173,7 @@ export class Uniform {
|
||||
public count: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Uniform) {
|
||||
public copy (info: Readonly<Uniform>) {
|
||||
this.name = info.name;
|
||||
this.type = info.type;
|
||||
this.count = info.count;
|
||||
@@ -1145,7 +1192,7 @@ export class UniformBlock {
|
||||
public count: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: UniformBlock) {
|
||||
public copy (info: Readonly<UniformBlock>) {
|
||||
this.set = info.set;
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
@@ -1166,7 +1213,7 @@ export class UniformSamplerTexture {
|
||||
public count: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: UniformSamplerTexture) {
|
||||
public copy (info: Readonly<UniformSamplerTexture>) {
|
||||
this.set = info.set;
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
@@ -1186,7 +1233,7 @@ export class UniformSampler {
|
||||
public count: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: UniformSampler) {
|
||||
public copy (info: Readonly<UniformSampler>) {
|
||||
this.set = info.set;
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
@@ -1206,7 +1253,7 @@ export class UniformTexture {
|
||||
public count: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: UniformTexture) {
|
||||
public copy (info: Readonly<UniformTexture>) {
|
||||
this.set = info.set;
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
@@ -1228,7 +1275,7 @@ export class UniformStorageImage {
|
||||
public memoryAccess: MemoryAccess = MemoryAccessBit.READ_WRITE,
|
||||
) {}
|
||||
|
||||
public copy (info: UniformStorageImage) {
|
||||
public copy (info: Readonly<UniformStorageImage>) {
|
||||
this.set = info.set;
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
@@ -1250,7 +1297,7 @@ export class UniformStorageBuffer {
|
||||
public memoryAccess: MemoryAccess = MemoryAccessBit.READ_WRITE,
|
||||
) {}
|
||||
|
||||
public copy (info: UniformStorageBuffer) {
|
||||
public copy (info: Readonly<UniformStorageBuffer>) {
|
||||
this.set = info.set;
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
@@ -1270,7 +1317,7 @@ export class UniformInputAttachment {
|
||||
public count: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: UniformInputAttachment) {
|
||||
public copy (info: Readonly<UniformInputAttachment>) {
|
||||
this.set = info.set;
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
@@ -1287,7 +1334,7 @@ export class ShaderStage {
|
||||
public source: string = '',
|
||||
) {}
|
||||
|
||||
public copy (info: ShaderStage) {
|
||||
public copy (info: Readonly<ShaderStage>) {
|
||||
this.stage = info.stage;
|
||||
this.source = info.source;
|
||||
return this;
|
||||
@@ -1306,7 +1353,7 @@ export class Attribute {
|
||||
public location: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Attribute) {
|
||||
public copy (info: Readonly<Attribute>) {
|
||||
this.name = info.name;
|
||||
this.format = info.format;
|
||||
this.isNormalized = info.isNormalized;
|
||||
@@ -1333,7 +1380,7 @@ export class ShaderInfo {
|
||||
public subpassInputs: UniformInputAttachment[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: ShaderInfo) {
|
||||
public copy (info: Readonly<ShaderInfo>) {
|
||||
this.name = info.name;
|
||||
deepCopy(this.stages, info.stages, ShaderStage);
|
||||
deepCopy(this.attributes, info.attributes, Attribute);
|
||||
@@ -1358,7 +1405,7 @@ export class InputAssemblerInfo {
|
||||
public indirectBuffer: Buffer | null = null,
|
||||
) {}
|
||||
|
||||
public copy (info: InputAssemblerInfo) {
|
||||
public copy (info: Readonly<InputAssemblerInfo>) {
|
||||
deepCopy(this.attributes, info.attributes, Attribute);
|
||||
this.vertexBuffers = info.vertexBuffers.slice();
|
||||
this.indexBuffer = info.indexBuffer;
|
||||
@@ -1372,15 +1419,15 @@ export class ColorAttachment {
|
||||
|
||||
constructor (
|
||||
public format: Format = Format.UNKNOWN,
|
||||
public sampleCount: SampleCount = SampleCount.X1,
|
||||
public sampleCount: SampleCount = SampleCount.ONE,
|
||||
public loadOp: LoadOp = LoadOp.CLEAR,
|
||||
public storeOp: StoreOp = StoreOp.STORE,
|
||||
public beginAccesses: AccessType[] = [],
|
||||
public endAccesses: AccessType[] = [AccessType.PRESENT],
|
||||
public endAccesses: AccessType[] = [AccessType.COLOR_ATTACHMENT_WRITE],
|
||||
public isGeneralLayout: boolean = false,
|
||||
) {}
|
||||
|
||||
public copy (info: ColorAttachment) {
|
||||
public copy (info: Readonly<ColorAttachment>) {
|
||||
this.format = info.format;
|
||||
this.sampleCount = info.sampleCount;
|
||||
this.loadOp = info.loadOp;
|
||||
@@ -1397,7 +1444,7 @@ export class DepthStencilAttachment {
|
||||
|
||||
constructor (
|
||||
public format: Format = Format.UNKNOWN,
|
||||
public sampleCount: SampleCount = SampleCount.X1,
|
||||
public sampleCount: SampleCount = SampleCount.ONE,
|
||||
public depthLoadOp: LoadOp = LoadOp.CLEAR,
|
||||
public depthStoreOp: StoreOp = StoreOp.STORE,
|
||||
public stencilLoadOp: LoadOp = LoadOp.CLEAR,
|
||||
@@ -1407,7 +1454,7 @@ export class DepthStencilAttachment {
|
||||
public isGeneralLayout: boolean = false,
|
||||
) {}
|
||||
|
||||
public copy (info: DepthStencilAttachment) {
|
||||
public copy (info: Readonly<DepthStencilAttachment>) {
|
||||
this.format = info.format;
|
||||
this.sampleCount = info.sampleCount;
|
||||
this.depthLoadOp = info.depthLoadOp;
|
||||
@@ -1435,7 +1482,7 @@ export class SubpassInfo {
|
||||
public stencilResolveMode: ResolveMode = ResolveMode.NONE,
|
||||
) {}
|
||||
|
||||
public copy (info: SubpassInfo) {
|
||||
public copy (info: Readonly<SubpassInfo>) {
|
||||
this.inputs = info.inputs.slice();
|
||||
this.colors = info.colors.slice();
|
||||
this.resolves = info.resolves.slice();
|
||||
@@ -1458,7 +1505,7 @@ export class SubpassDependency {
|
||||
public dstAccesses: AccessType[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: SubpassDependency) {
|
||||
public copy (info: Readonly<SubpassDependency>) {
|
||||
this.srcSubpass = info.srcSubpass;
|
||||
this.dstSubpass = info.dstSubpass;
|
||||
this.srcAccesses = info.srcAccesses.slice();
|
||||
@@ -1477,7 +1524,7 @@ export class RenderPassInfo {
|
||||
public dependencies: SubpassDependency[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: RenderPassInfo) {
|
||||
public copy (info: Readonly<RenderPassInfo>) {
|
||||
deepCopy(this.colorAttachments, info.colorAttachments, ColorAttachment);
|
||||
this.depthStencilAttachment.copy(info.depthStencilAttachment);
|
||||
deepCopy(this.subpasses, info.subpasses, SubpassInfo);
|
||||
@@ -1494,7 +1541,7 @@ export class GlobalBarrierInfo {
|
||||
public nextAccesses: AccessType[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: GlobalBarrierInfo) {
|
||||
public copy (info: Readonly<GlobalBarrierInfo>) {
|
||||
this.prevAccesses = info.prevAccesses.slice();
|
||||
this.nextAccesses = info.nextAccesses.slice();
|
||||
return this;
|
||||
@@ -1512,7 +1559,7 @@ export class TextureBarrierInfo {
|
||||
public dstQueue: Queue | null = null,
|
||||
) {}
|
||||
|
||||
public copy (info: TextureBarrierInfo) {
|
||||
public copy (info: Readonly<TextureBarrierInfo>) {
|
||||
this.prevAccesses = info.prevAccesses.slice();
|
||||
this.nextAccesses = info.nextAccesses.slice();
|
||||
this.discardContents = info.discardContents;
|
||||
@@ -1527,11 +1574,11 @@ export class FramebufferInfo {
|
||||
|
||||
constructor (
|
||||
public renderPass: RenderPass = null!,
|
||||
public colorTextures: (Texture | null)[] = [],
|
||||
public colorTextures: Texture[] = [],
|
||||
public depthStencilTexture: Texture | null = null,
|
||||
) {}
|
||||
|
||||
public copy (info: FramebufferInfo) {
|
||||
public copy (info: Readonly<FramebufferInfo>) {
|
||||
this.renderPass = info.renderPass;
|
||||
this.colorTextures = info.colorTextures.slice();
|
||||
this.depthStencilTexture = info.depthStencilTexture;
|
||||
@@ -1550,7 +1597,7 @@ export class DescriptorSetLayoutBinding {
|
||||
public immutableSamplers: Sampler[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: DescriptorSetLayoutBinding) {
|
||||
public copy (info: Readonly<DescriptorSetLayoutBinding>) {
|
||||
this.binding = info.binding;
|
||||
this.descriptorType = info.descriptorType;
|
||||
this.count = info.count;
|
||||
@@ -1567,7 +1614,7 @@ export class DescriptorSetLayoutInfo {
|
||||
public bindings: DescriptorSetLayoutBinding[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: DescriptorSetLayoutInfo) {
|
||||
public copy (info: Readonly<DescriptorSetLayoutInfo>) {
|
||||
deepCopy(this.bindings, info.bindings, DescriptorSetLayoutBinding);
|
||||
return this;
|
||||
}
|
||||
@@ -1580,7 +1627,7 @@ export class DescriptorSetInfo {
|
||||
public layout: DescriptorSetLayout = null!,
|
||||
) {}
|
||||
|
||||
public copy (info: DescriptorSetInfo) {
|
||||
public copy (info: Readonly<DescriptorSetInfo>) {
|
||||
this.layout = info.layout;
|
||||
return this;
|
||||
}
|
||||
@@ -1593,7 +1640,7 @@ export class PipelineLayoutInfo {
|
||||
public setLayouts: DescriptorSetLayout[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: PipelineLayoutInfo) {
|
||||
public copy (info: Readonly<PipelineLayoutInfo>) {
|
||||
this.setLayouts = info.setLayouts.slice();
|
||||
return this;
|
||||
}
|
||||
@@ -1606,7 +1653,7 @@ export class InputState {
|
||||
public attributes: Attribute[] = [],
|
||||
) {}
|
||||
|
||||
public copy (info: InputState) {
|
||||
public copy (info: Readonly<InputState>) {
|
||||
deepCopy(this.attributes, info.attributes, Attribute);
|
||||
return this;
|
||||
}
|
||||
@@ -1620,7 +1667,7 @@ export class CommandBufferInfo {
|
||||
public type: CommandBufferType = CommandBufferType.PRIMARY,
|
||||
) {}
|
||||
|
||||
public copy (info: CommandBufferInfo) {
|
||||
public copy (info: Readonly<CommandBufferInfo>) {
|
||||
this.queue = info.queue;
|
||||
this.type = info.type;
|
||||
return this;
|
||||
@@ -1634,7 +1681,7 @@ export class QueueInfo {
|
||||
public type: QueueType = QueueType.GRAPHICS,
|
||||
) {}
|
||||
|
||||
public copy (info: QueueInfo) {
|
||||
public copy (info: Readonly<QueueInfo>) {
|
||||
this.type = info.type;
|
||||
return this;
|
||||
}
|
||||
@@ -1663,7 +1710,7 @@ export class MemoryStatus {
|
||||
public textureSize: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: MemoryStatus) {
|
||||
public copy (info: Readonly<MemoryStatus>) {
|
||||
this.bufferSize = info.bufferSize;
|
||||
this.textureSize = info.textureSize;
|
||||
return this;
|
||||
@@ -1679,7 +1726,7 @@ export class DynamicStencilStates {
|
||||
public reference: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: DynamicStencilStates) {
|
||||
public copy (info: Readonly<DynamicStencilStates>) {
|
||||
this.writeMask = info.writeMask;
|
||||
this.compareMask = info.compareMask;
|
||||
this.reference = info.reference;
|
||||
@@ -1704,7 +1751,7 @@ export class DynamicStates {
|
||||
public stencilStatesBack: DynamicStencilStates = new DynamicStencilStates(),
|
||||
) {}
|
||||
|
||||
public copy (info: DynamicStates) {
|
||||
public copy (info: Readonly<DynamicStates>) {
|
||||
this.viewport.copy(info.viewport);
|
||||
this.scissor.copy(info.scissor);
|
||||
this.blendConstant.copy(info.blendConstant);
|
||||
@@ -1728,65 +1775,43 @@ export class DynamicStates {
|
||||
* ========================= !DO NOT CHANGE THE ABOVE SECTION MANUALLY! =========================
|
||||
*/
|
||||
|
||||
ccenum(Format);
|
||||
|
||||
/**
|
||||
* @en GFX base object.
|
||||
* @zh GFX 基类对象。
|
||||
*/
|
||||
export class Obj {
|
||||
public get gfxType (): ObjectType {
|
||||
return this._gfxType;
|
||||
export class GFXObject {
|
||||
public get objectType (): ObjectType {
|
||||
return this._objectType;
|
||||
}
|
||||
|
||||
protected _gfxType = ObjectType.UNKNOWN;
|
||||
public get objectID (): number {
|
||||
return this._objectID;
|
||||
}
|
||||
|
||||
constructor (gfxType: ObjectType) {
|
||||
this._gfxType = gfxType;
|
||||
public get typedID (): number {
|
||||
return this._typedID;
|
||||
}
|
||||
|
||||
protected _objectType = ObjectType.UNKNOWN;
|
||||
protected _objectID = 0;
|
||||
protected _typedID = 0;
|
||||
|
||||
private static _idTable = Array(ObjectType.COUNT).fill(1 << 16);
|
||||
|
||||
constructor (objectType: ObjectType) {
|
||||
this._objectType = objectType;
|
||||
this._objectID = GFXObject._idTable[ObjectType.UNKNOWN]++;
|
||||
this._typedID = GFXObject._idTable[objectType]++;
|
||||
}
|
||||
}
|
||||
|
||||
export class DeviceInfo {
|
||||
declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object
|
||||
|
||||
constructor (
|
||||
public canvasElm: HTMLElement,
|
||||
public isAntialias: boolean = true,
|
||||
public isPremultipliedAlpha: boolean = true,
|
||||
public devicePixelRatio: number = 1,
|
||||
public width: number = 1,
|
||||
public height: number = 1,
|
||||
/**
|
||||
* For non-vulkan backends, to maintain compatibility and maximize
|
||||
* descriptor cache-locality, descriptor-set-based binding numbers need
|
||||
* to be mapped to backend-specific bindings based on the maximum limit
|
||||
* of available descriptor slots in each set.
|
||||
*
|
||||
* The GFX layer assumes the binding numbers for each descriptor type inside each set
|
||||
* are guaranteed to be consecutive, so the mapping procedure is reduced
|
||||
* to a simple shifting operation. This data structure specifies the
|
||||
* offsets for each descriptor type in each set.
|
||||
*/
|
||||
public bindingMappingInfo = new BindingMappingInfo(),
|
||||
) {}
|
||||
}
|
||||
|
||||
export interface IUniform {
|
||||
name: string;
|
||||
type: Type;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface IShaderStage {
|
||||
stage: ShaderStageFlagBit;
|
||||
source: string;
|
||||
}
|
||||
|
||||
export interface IAttribute {
|
||||
name: string;
|
||||
export interface ISwapchainTextureInfo {
|
||||
swapchain: Swapchain;
|
||||
format: Format;
|
||||
isNormalized: boolean;
|
||||
stream: number;
|
||||
isInstanced: boolean;
|
||||
location: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export enum AttributeName {
|
||||
@@ -1875,12 +1900,8 @@ export const FormatInfos = Object.freeze([
|
||||
new FormatInfo('RGB10A2UI', 2, 4, FormatType.UINT, true, false, false, false),
|
||||
new FormatInfo('RGB9E5', 2, 4, FormatType.FLOAT, true, false, false, false),
|
||||
|
||||
new FormatInfo('D16', 2, 1, FormatType.UINT, false, true, false, false),
|
||||
new FormatInfo('D16S8', 3, 2, FormatType.UINT, false, true, true, false),
|
||||
new FormatInfo('D24', 3, 1, FormatType.UINT, false, true, false, false),
|
||||
new FormatInfo('D24S8', 4, 2, FormatType.UINT, false, true, true, false),
|
||||
new FormatInfo('D32F', 4, 1, FormatType.FLOAT, false, true, false, false),
|
||||
new FormatInfo('D32FS8', 5, 2, FormatType.FLOAT, false, true, true, false),
|
||||
new FormatInfo('DEPTH', 4, 1, FormatType.FLOAT, false, true, false, false),
|
||||
new FormatInfo('DEPTH_STENCIL', 5, 2, FormatType.FLOAT, false, true, true, false),
|
||||
|
||||
new FormatInfo('BC1', 1, 3, FormatType.UNORM, false, false, false, true),
|
||||
new FormatInfo('BC1_ALPHA', 1, 4, FormatType.UNORM, true, false, false, true),
|
||||
|
||||
@@ -28,14 +28,13 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import { Obj, ObjectType, DescriptorSetLayoutBinding, DescriptorSetLayoutInfo } from './define';
|
||||
import { GFXObject, ObjectType, DescriptorSetLayoutBinding, DescriptorSetLayoutInfo } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX descriptor sets layout.
|
||||
* @zh GFX 描述符集布局。
|
||||
*/
|
||||
export abstract class DescriptorSetLayout extends Obj {
|
||||
export abstract class DescriptorSetLayout extends GFXObject {
|
||||
get bindings () {
|
||||
return this._bindings;
|
||||
}
|
||||
@@ -48,20 +47,15 @@ export abstract class DescriptorSetLayout extends Obj {
|
||||
return this._descriptorIndices;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _bindings: DescriptorSetLayoutBinding[] = [];
|
||||
|
||||
protected _bindingIndices: number[] = [];
|
||||
|
||||
protected _descriptorIndices: number[] = [];
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.DESCRIPTOR_SET_LAYOUT);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: DescriptorSetLayoutInfo): boolean;
|
||||
public abstract initialize (info: DescriptorSetLayoutInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
|
||||
@@ -30,22 +30,19 @@
|
||||
|
||||
import { Buffer } from './buffer';
|
||||
import { DescriptorSetLayout } from './descriptor-set-layout';
|
||||
import { Device } from './device';
|
||||
import { Sampler } from './sampler';
|
||||
import { Sampler } from './states/sampler';
|
||||
import { Texture } from './texture';
|
||||
import { Obj, ObjectType, DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE } from './define';
|
||||
import { GFXObject, ObjectType, DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX descriptor sets.
|
||||
* @zh GFX 描述符集组。
|
||||
*/
|
||||
export abstract class DescriptorSet extends Obj {
|
||||
export abstract class DescriptorSet extends GFXObject {
|
||||
get layout () {
|
||||
return this._layout!;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _layout: DescriptorSetLayout | null = null;
|
||||
protected _buffers: Buffer[] = [];
|
||||
protected _textures: Texture[] = [];
|
||||
@@ -53,12 +50,11 @@ export abstract class DescriptorSet extends Obj {
|
||||
|
||||
protected _isDirty = false;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.DESCRIPTOR_SET);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: DescriptorSetInfo): boolean;
|
||||
public abstract initialize (info: DescriptorSetInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
|
||||
|
||||
+46
-121
@@ -28,12 +28,11 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { ccenum } from '../../value-types/enum';
|
||||
import {
|
||||
API, Feature, Filter, Format, MemoryStatus, SurfaceTransform, Rect,
|
||||
API, Feature, MemoryStatus,
|
||||
CommandBufferInfo, BufferInfo, BufferViewInfo, TextureInfo, TextureViewInfo, SamplerInfo, DescriptorSetInfo,
|
||||
ShaderInfo, InputAssemblerInfo, RenderPassInfo, FramebufferInfo, DescriptorSetLayoutInfo, PipelineLayoutInfo,
|
||||
QueueInfo, BufferTextureCopy, DeviceInfo, DeviceCaps, GlobalBarrierInfo, TextureBarrierInfo,
|
||||
QueueInfo, BufferTextureCopy, DeviceInfo, DeviceCaps, GlobalBarrierInfo, TextureBarrierInfo, SwapchainInfo, BindingMappingInfo,
|
||||
} from './define';
|
||||
import { Buffer } from './buffer';
|
||||
import { CommandBuffer } from './command-buffer';
|
||||
@@ -45,35 +44,18 @@ import { InputAssembler } from './input-assembler';
|
||||
import { PipelineState, PipelineStateInfo } from './pipeline-state';
|
||||
import { Queue } from './queue';
|
||||
import { RenderPass } from './render-pass';
|
||||
import { Sampler } from './sampler';
|
||||
import { Sampler } from './states/sampler';
|
||||
import { Shader } from './shader';
|
||||
import { Texture } from './texture';
|
||||
import { GlobalBarrier } from './global-barrier';
|
||||
import { TextureBarrier } from './texture-barrier';
|
||||
|
||||
ccenum(Format);
|
||||
import { GlobalBarrier } from './states/global-barrier';
|
||||
import { TextureBarrier } from './states/texture-barrier';
|
||||
import { Swapchain } from './swapchain';
|
||||
|
||||
/**
|
||||
* @en GFX Device.
|
||||
* @zh GFX 设备。
|
||||
*/
|
||||
export abstract class Device {
|
||||
/**
|
||||
* @en The HTML canvas element.
|
||||
* @zh HTML 画布。
|
||||
*/
|
||||
get canvas (): HTMLCanvasElement {
|
||||
return this._canvas as HTMLCanvasElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The HTML canvas element for 2D rendering.
|
||||
* @zh 用于 2D 绘制的 HTML 画布。
|
||||
*/
|
||||
get canvas2D (): HTMLCanvasElement {
|
||||
return this._canvas2D as HTMLCanvasElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Current rendering API.
|
||||
* @zh 当前 GFX 使用的渲染 API。
|
||||
@@ -98,30 +80,6 @@ export abstract class Device {
|
||||
return this._cmdBuff as CommandBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Device pixel ratio.
|
||||
* @zh DPR 设备像素比。
|
||||
*/
|
||||
get devicePixelRatio (): number {
|
||||
return this._devicePixelRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Device pixel width.
|
||||
* @zh 设备像素宽度。
|
||||
*/
|
||||
get width (): number {
|
||||
return this._width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Device pixel height.
|
||||
* @zh 设备像素高度。
|
||||
*/
|
||||
get height (): number {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Renderer description.
|
||||
* @zh 渲染器描述。
|
||||
@@ -138,22 +96,6 @@ export abstract class Device {
|
||||
return this._vendor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Device color format.
|
||||
* @zh 颜色格式。
|
||||
*/
|
||||
get colorFormat (): Format {
|
||||
return this._colorFmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Device depth stencil format.
|
||||
* @zh 深度模板格式。
|
||||
*/
|
||||
get depthStencilFormat (): Format {
|
||||
return this._depthStencilFmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Number of draw calls currently recorded.
|
||||
* @zh 绘制调用次数。
|
||||
@@ -188,59 +130,45 @@ export abstract class Device {
|
||||
|
||||
/**
|
||||
* @en Current device capabilities.
|
||||
* @zh 当前设备能立数据。
|
||||
* @zh 当前设备能力数据。
|
||||
*/
|
||||
get capabilities (): DeviceCaps {
|
||||
return this._caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The surface transform to be applied in projection matrices.
|
||||
* @zh 需要在投影矩阵中应用的表面变换。
|
||||
* @en Current device binding mappings.
|
||||
* @zh 当前设备的绑定槽位映射关系。
|
||||
*/
|
||||
get surfaceTransform () {
|
||||
return this._transform;
|
||||
get bindingMappingInfo () {
|
||||
return this._bindingMappingInfo;
|
||||
}
|
||||
|
||||
protected _canvas: HTMLCanvasElement | null = null;
|
||||
protected _canvas2D: HTMLCanvasElement | null = null;
|
||||
protected _gfxAPI = API.UNKNOWN;
|
||||
protected _transform = SurfaceTransform.IDENTITY;
|
||||
protected _deviceName = '';
|
||||
protected _renderer = '';
|
||||
protected _vendor = '';
|
||||
protected _version = '';
|
||||
protected _features = new Array<boolean>(Feature.COUNT);
|
||||
protected _queue: Queue | null = null;
|
||||
protected _cmdBuff: CommandBuffer | null = null;
|
||||
protected _devicePixelRatio = 1.0;
|
||||
protected _width = 0;
|
||||
protected _height = 0;
|
||||
protected _colorFmt = Format.UNKNOWN;
|
||||
protected _depthStencilFmt = Format.UNKNOWN;
|
||||
protected _numDrawCalls = 0;
|
||||
protected _numInstances = 0;
|
||||
protected _numTris = 0;
|
||||
protected _memoryStatus = new MemoryStatus();
|
||||
protected _caps = new DeviceCaps();
|
||||
protected _bindingMappingInfo: BindingMappingInfo = new BindingMappingInfo();
|
||||
protected _samplers = new Map<number, Sampler>();
|
||||
protected _globalBarriers = new Map<number, GlobalBarrier>();
|
||||
protected _textureBarriers = new Map<number, TextureBarrier>();
|
||||
|
||||
public abstract initialize (info: DeviceInfo): boolean;
|
||||
public abstract initialize (info: Readonly<DeviceInfo>): boolean;
|
||||
|
||||
public abstract destroy (): void;
|
||||
|
||||
/**
|
||||
* @en Resize the device.
|
||||
* @zh 重置设备大小。
|
||||
* @param width The device width.
|
||||
* @param height The device height.
|
||||
*/
|
||||
public abstract resize (width: number, height: number): void;
|
||||
|
||||
/**
|
||||
* @en Acquire next swapchain image.
|
||||
* @zh 获取下一个交换链缓冲。
|
||||
*/
|
||||
public abstract acquire (): void;
|
||||
public abstract acquire (swapchains: Swapchain[]): void;
|
||||
|
||||
/**
|
||||
* @en Present current swapchain image.
|
||||
@@ -259,105 +187,112 @@ export abstract class Device {
|
||||
* @zh 创建命令缓冲。
|
||||
* @param info GFX command buffer description info.
|
||||
*/
|
||||
public abstract createCommandBuffer (info: CommandBufferInfo): CommandBuffer;
|
||||
public abstract createCommandBuffer (info: Readonly<CommandBufferInfo>): CommandBuffer;
|
||||
|
||||
/**
|
||||
* @en Create swapchain.
|
||||
* @zh 创建交换链。
|
||||
* @param info GFX swapchain description info.
|
||||
*/
|
||||
public abstract createSwapchain (info: Readonly<SwapchainInfo>): Swapchain;
|
||||
|
||||
/**
|
||||
* @en Create buffer.
|
||||
* @zh 创建缓冲。
|
||||
* @param info GFX buffer description info.
|
||||
*/
|
||||
public abstract createBuffer (info: BufferInfo | BufferViewInfo): Buffer;
|
||||
public abstract createBuffer (info: Readonly<BufferInfo> | BufferViewInfo): Buffer;
|
||||
|
||||
/**
|
||||
* @en Create texture.
|
||||
* @zh 创建纹理。
|
||||
* @param info GFX texture description info.
|
||||
*/
|
||||
public abstract createTexture (info: TextureInfo | TextureViewInfo): Texture;
|
||||
|
||||
/**
|
||||
* @en Create sampler.
|
||||
* @zh 创建采样器。
|
||||
* @param info GFX sampler description info.
|
||||
*/
|
||||
public abstract createSampler (info: SamplerInfo): Sampler;
|
||||
public abstract createTexture (info: Readonly<TextureInfo> | TextureViewInfo): Texture;
|
||||
|
||||
/**
|
||||
* @en Create descriptor sets.
|
||||
* @zh 创建描述符集组。
|
||||
* @param info GFX descriptor sets description info.
|
||||
*/
|
||||
public abstract createDescriptorSet (info: DescriptorSetInfo): DescriptorSet;
|
||||
public abstract createDescriptorSet (info: Readonly<DescriptorSetInfo>): DescriptorSet;
|
||||
|
||||
/**
|
||||
* @en Create shader.
|
||||
* @zh 创建着色器。
|
||||
* @param info GFX shader description info.
|
||||
*/
|
||||
public abstract createShader (info: ShaderInfo): Shader;
|
||||
public abstract createShader (info: Readonly<ShaderInfo>): Shader;
|
||||
|
||||
/**
|
||||
* @en Create input assembler.
|
||||
* @zh 创建纹理。
|
||||
* @param info GFX input assembler description info.
|
||||
*/
|
||||
public abstract createInputAssembler (info: InputAssemblerInfo): InputAssembler;
|
||||
public abstract createInputAssembler (info: Readonly<InputAssemblerInfo>): InputAssembler;
|
||||
|
||||
/**
|
||||
* @en Create render pass.
|
||||
* @zh 创建渲染过程。
|
||||
* @param info GFX render pass description info.
|
||||
*/
|
||||
public abstract createRenderPass (info: RenderPassInfo): RenderPass;
|
||||
public abstract createRenderPass (info: Readonly<RenderPassInfo>): RenderPass;
|
||||
|
||||
/**
|
||||
* @en Create frame buffer.
|
||||
* @zh 创建帧缓冲。
|
||||
* @param info GFX frame buffer description info.
|
||||
*/
|
||||
public abstract createFramebuffer (info: FramebufferInfo): Framebuffer;
|
||||
public abstract createFramebuffer (info: Readonly<FramebufferInfo>): Framebuffer;
|
||||
|
||||
/**
|
||||
* @en Create descriptor set layout.
|
||||
* @zh 创建描述符集布局。
|
||||
* @param info GFX descriptor set layout description info.
|
||||
*/
|
||||
public abstract createDescriptorSetLayout (info: DescriptorSetLayoutInfo): DescriptorSetLayout;
|
||||
public abstract createDescriptorSetLayout (info: Readonly<DescriptorSetLayoutInfo>): DescriptorSetLayout;
|
||||
|
||||
/**
|
||||
* @en Create pipeline layout.
|
||||
* @zh 创建管线布局。
|
||||
* @param info GFX pipeline layout description info.
|
||||
*/
|
||||
public abstract createPipelineLayout (info: PipelineLayoutInfo): PipelineLayout;
|
||||
public abstract createPipelineLayout (info: Readonly<PipelineLayoutInfo>): PipelineLayout;
|
||||
|
||||
/**
|
||||
* @en Create pipeline state.
|
||||
* @zh 创建管线状态。
|
||||
* @param info GFX pipeline state description info.
|
||||
*/
|
||||
public abstract createPipelineState (info: PipelineStateInfo): PipelineState;
|
||||
public abstract createPipelineState (info: Readonly<PipelineStateInfo>): PipelineState;
|
||||
|
||||
/**
|
||||
* @en Create queue.
|
||||
* @zh 创建队列。
|
||||
* @param info GFX queue description info.
|
||||
*/
|
||||
public abstract createQueue (info: QueueInfo): Queue;
|
||||
public abstract createQueue (info: Readonly<QueueInfo>): Queue;
|
||||
|
||||
/**
|
||||
* @en Create sampler.
|
||||
* @zh 创建采样器。
|
||||
* @param info GFX sampler description info.
|
||||
*/
|
||||
public abstract getSampler (info: Readonly<SamplerInfo>): Sampler;
|
||||
|
||||
/**
|
||||
* @en Create global barrier.
|
||||
* @zh 创建全局内存屏障。
|
||||
* @param info GFX global barrier description info.
|
||||
*/
|
||||
public abstract createGlobalBarrier (info: GlobalBarrierInfo): GlobalBarrier;
|
||||
public abstract getGlobalBarrier (info: Readonly<GlobalBarrierInfo>): GlobalBarrier;
|
||||
|
||||
/**
|
||||
* @en Create texture barrier.
|
||||
* @zh 创建贴图内存屏障。
|
||||
* @param info GFX texture barrier description info.
|
||||
*/
|
||||
public abstract createTextureBarrier (info: TextureBarrierInfo): TextureBarrier;
|
||||
public abstract getTextureBarrier (info: Readonly<TextureBarrierInfo>): TextureBarrier;
|
||||
|
||||
/**
|
||||
* @en Copy buffers to texture.
|
||||
@@ -366,10 +301,9 @@ export abstract class Device {
|
||||
* @param texture The texture to copy to.
|
||||
* @param regions The region descriptions.
|
||||
*/
|
||||
public abstract copyBuffersToTexture (buffers: ArrayBufferView[], texture: Texture, regions: BufferTextureCopy[]): void;
|
||||
public abstract copyBuffersToTexture (buffers: Readonly<ArrayBufferView[]>, texture: Texture, regions: BufferTextureCopy[]): void;
|
||||
|
||||
/**
|
||||
*
|
||||
* @en Copy texture to buffers
|
||||
* @zh 拷贝纹理到缓冲
|
||||
* @param texture The texture to be copied.
|
||||
@@ -387,15 +321,6 @@ export abstract class Device {
|
||||
*/
|
||||
public abstract copyTexImagesToTexture (texImages: TexImageSource[], texture: Texture, regions: BufferTextureCopy[]): void;
|
||||
|
||||
/**
|
||||
* @en Copy frame buffer to buffer.
|
||||
* @zh 拷贝帧缓冲到缓冲。
|
||||
* @param srcFramebuffer The frame buffer to be copied.
|
||||
* @param dstBuffer The buffer to copy to.
|
||||
* @param regions The region descriptions.
|
||||
*/
|
||||
public abstract copyFramebufferToBuffer (srcFramebuffer: Framebuffer, dstBuffer: ArrayBuffer, regions: BufferTextureCopy[]): void;
|
||||
|
||||
/**
|
||||
* @en Whether the device has specific feature.
|
||||
* @zh 是否具备特性。
|
||||
|
||||
@@ -28,16 +28,15 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import { RenderPass } from './render-pass';
|
||||
import { Texture } from './texture';
|
||||
import { Obj, ObjectType, FramebufferInfo } from './define';
|
||||
import { GFXObject, ObjectType, FramebufferInfo } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX frame buffer.
|
||||
* @zh GFX 帧缓冲。
|
||||
*/
|
||||
export abstract class Framebuffer extends Obj {
|
||||
export abstract class Framebuffer extends GFXObject {
|
||||
/**
|
||||
* @en Get current render pass.
|
||||
* @zh GFX 渲染过程。
|
||||
@@ -62,20 +61,15 @@ export abstract class Framebuffer extends Obj {
|
||||
return this._depthStencilTexture;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _renderPass: RenderPass | null = null;
|
||||
|
||||
protected _colorTextures: (Texture | null)[] = [];
|
||||
|
||||
protected _depthStencilTexture: Texture | null = null;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.FRAMEBUFFER);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: FramebufferInfo): boolean;
|
||||
public abstract initialize (info: FramebufferInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
|
||||
@@ -29,15 +29,22 @@
|
||||
*/
|
||||
|
||||
import { Buffer } from './buffer';
|
||||
import { Device } from './device';
|
||||
import { murmurhash2_32_gc } from '../../utils/murmurhash2_gc';
|
||||
import { Attribute, Obj, ObjectType, InputAssemblerInfo } from './define';
|
||||
import { Attribute, GFXObject, ObjectType, InputAssemblerInfo, DrawInfo } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX input assembler.
|
||||
* @zh GFX 输入汇集器。
|
||||
*/
|
||||
export abstract class InputAssembler extends Obj {
|
||||
export abstract class InputAssembler extends GFXObject {
|
||||
/**
|
||||
* @en Get current attributes.
|
||||
* @zh 顶点属性数组。
|
||||
*/
|
||||
get attributes (): Attribute[] {
|
||||
return this._attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get current vertex buffers.
|
||||
* @zh 顶点缓冲数组。
|
||||
@@ -55,11 +62,11 @@ export abstract class InputAssembler extends Obj {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get current attributes.
|
||||
* @zh 顶点属性数组。
|
||||
* @en Get the indirect buffer, if present.
|
||||
* @zh 间接绘制缓冲。
|
||||
*/
|
||||
get attributes (): Attribute[] {
|
||||
return this._attributes;
|
||||
get indirectBuffer (): Buffer | null {
|
||||
return this._indirectBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,123 +81,73 @@ export abstract class InputAssembler extends Obj {
|
||||
* @en Get current vertex count.
|
||||
* @zh 顶点数量。
|
||||
*/
|
||||
get vertexCount (): number {
|
||||
return this._vertexCount;
|
||||
}
|
||||
|
||||
set vertexCount (count: number) {
|
||||
this._vertexCount = count;
|
||||
this._drawInfo.vertexCount = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get starting vertex.
|
||||
* @zh 起始顶点。
|
||||
*/
|
||||
get firstVertex (): number {
|
||||
return this._firstVertex;
|
||||
}
|
||||
|
||||
set firstVertex (first: number) {
|
||||
this._firstVertex = first;
|
||||
this._drawInfo.firstVertex = first;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get current index count.
|
||||
* @zh 索引数量。
|
||||
*/
|
||||
get indexCount (): number {
|
||||
return this._indexCount;
|
||||
}
|
||||
|
||||
set indexCount (count: number) {
|
||||
this._indexCount = count;
|
||||
this._drawInfo.indexCount = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get starting index.
|
||||
* @zh 起始索引。
|
||||
*/
|
||||
get firstIndex (): number {
|
||||
return this._firstIndex;
|
||||
}
|
||||
|
||||
set firstIndex (first: number) {
|
||||
this._firstIndex = first;
|
||||
this._drawInfo.firstIndex = first;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get current vertex offset.
|
||||
* @zh 顶点偏移量。
|
||||
*/
|
||||
get vertexOffset (): number {
|
||||
return this._vertexOffset;
|
||||
}
|
||||
|
||||
set vertexOffset (offset: number) {
|
||||
this._vertexOffset = offset;
|
||||
this._drawInfo.vertexOffset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get current instance count.
|
||||
* @zh 实例数量。
|
||||
*/
|
||||
get instanceCount (): number {
|
||||
return this._instanceCount;
|
||||
}
|
||||
|
||||
set instanceCount (count: number) {
|
||||
this._instanceCount = count;
|
||||
this._drawInfo.instanceCount = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get starting instance.
|
||||
* @zh 起始实例。
|
||||
*/
|
||||
get firstInstance (): number {
|
||||
return this._firstInstance;
|
||||
}
|
||||
|
||||
set firstInstance (first: number) {
|
||||
this._firstInstance = first;
|
||||
this._drawInfo.firstInstance = first;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get the indirect buffer, if present.
|
||||
* @zh 间接绘制缓冲。
|
||||
*/
|
||||
get indirectBuffer (): Buffer | null {
|
||||
return this._indirectBuffer;
|
||||
get drawInfo (): Readonly<DrawInfo> {
|
||||
return this._drawInfo;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _attributes: Attribute[] = [];
|
||||
|
||||
protected _vertexBuffers: Buffer[] = [];
|
||||
|
||||
protected _indexBuffer: Buffer | null = null;
|
||||
|
||||
protected _vertexCount = 0;
|
||||
|
||||
protected _firstVertex = 0;
|
||||
|
||||
protected _indexCount = 0;
|
||||
|
||||
protected _firstIndex = 0;
|
||||
|
||||
protected _vertexOffset = 0;
|
||||
|
||||
protected _instanceCount = 0;
|
||||
|
||||
protected _firstInstance = 0;
|
||||
|
||||
protected _attributesHash = 0;
|
||||
|
||||
protected _vertexBuffers: Buffer[] = [];
|
||||
protected _indexBuffer: Buffer | null = null;
|
||||
protected _indirectBuffer: Buffer | null = null;
|
||||
|
||||
constructor (device: Device) {
|
||||
protected _drawInfo = new DrawInfo();
|
||||
|
||||
constructor () {
|
||||
super(ObjectType.INPUT_ASSEMBLER);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,6 +172,6 @@ export abstract class InputAssembler extends Obj {
|
||||
return murmurhash2_32_gc(res, 666);
|
||||
}
|
||||
|
||||
public abstract initialize (info: InputAssemblerInfo): boolean;
|
||||
public abstract initialize (info: InputAssemblerInfo): void;
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
|
||||
@@ -29,28 +29,24 @@
|
||||
*/
|
||||
|
||||
import { DescriptorSetLayout } from './descriptor-set-layout';
|
||||
import { Device } from './device';
|
||||
import { Obj, ObjectType, PipelineLayoutInfo } from './define';
|
||||
import { GFXObject, ObjectType, PipelineLayoutInfo } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX pipeline layout.
|
||||
* @zh GFX 管线布局。
|
||||
*/
|
||||
export abstract class PipelineLayout extends Obj {
|
||||
export abstract class PipelineLayout extends GFXObject {
|
||||
get setLayouts () {
|
||||
return this._setLayouts;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _setLayouts: DescriptorSetLayout[] = [];
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.PIPELINE_LAYOUT);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: PipelineLayoutInfo): boolean;
|
||||
public abstract initialize (info: PipelineLayoutInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import { PipelineLayout } from './pipeline-layout';
|
||||
import { RenderPass } from './render-pass';
|
||||
import { Shader } from './shader';
|
||||
@@ -40,7 +39,7 @@ import {
|
||||
CullMode,
|
||||
DynamicStateFlagBit,
|
||||
DynamicStateFlags,
|
||||
Obj,
|
||||
GFXObject,
|
||||
ObjectType,
|
||||
PolygonMode,
|
||||
PrimitiveMode,
|
||||
@@ -265,7 +264,7 @@ export class PipelineStateInfo {
|
||||
* @en GFX pipeline state.
|
||||
* @zh GFX 管线状态。
|
||||
*/
|
||||
export abstract class PipelineState extends Obj {
|
||||
export abstract class PipelineState extends GFXObject {
|
||||
/**
|
||||
* @en Get current shader.
|
||||
* @zh GFX 着色器。
|
||||
@@ -338,32 +337,21 @@ export abstract class PipelineState extends Obj {
|
||||
return this._renderPass as RenderPass;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _shader: Shader | null = null;
|
||||
|
||||
protected _pipelineLayout: PipelineLayout | null = null;
|
||||
|
||||
protected _primitive: PrimitiveMode = PrimitiveMode.TRIANGLE_LIST;
|
||||
|
||||
protected _is: InputState | null = null;
|
||||
|
||||
protected _rs: RasterizerState = new RasterizerState();
|
||||
|
||||
protected _dss: DepthStencilState = new DepthStencilState();
|
||||
|
||||
protected _bs: BlendState = new BlendState();
|
||||
|
||||
protected _dynamicStates: DynamicStateFlags = DynamicStateFlagBit.NONE;
|
||||
|
||||
protected _renderPass: RenderPass | null = null;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.PIPELINE_STATE);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: PipelineStateInfo): boolean;
|
||||
public abstract initialize (info: PipelineStateInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
|
||||
@@ -29,14 +29,13 @@
|
||||
*/
|
||||
|
||||
import { CommandBuffer } from './command-buffer';
|
||||
import { Device } from './device';
|
||||
import { Obj, ObjectType, QueueType, QueueInfo } from './define';
|
||||
import { GFXObject, ObjectType, QueueType, QueueInfo } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX Queue.
|
||||
* @zh GFX 队列。
|
||||
*/
|
||||
export abstract class Queue extends Obj {
|
||||
export abstract class Queue extends GFXObject {
|
||||
/**
|
||||
* @en Get current type.
|
||||
* @zh 队列类型。
|
||||
@@ -45,20 +44,13 @@ export abstract class Queue extends Obj {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _type: QueueType = QueueType.GRAPHICS;
|
||||
|
||||
protected _isAsync = false;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.QUEUE);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public isAsync () { return this._isAsync; }
|
||||
|
||||
public abstract initialize (info: QueueInfo): boolean;
|
||||
public abstract initialize (info: QueueInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
|
||||
|
||||
@@ -28,10 +28,9 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import { murmurhash2_32_gc } from '../../utils/murmurhash2_gc';
|
||||
import {
|
||||
Obj,
|
||||
GFXObject,
|
||||
ObjectType,
|
||||
ColorAttachment,
|
||||
DepthStencilAttachment,
|
||||
@@ -43,15 +42,10 @@ import {
|
||||
* @en GFX render pass.
|
||||
* @zh GFX 渲染过程。
|
||||
*/
|
||||
export abstract class RenderPass extends Obj {
|
||||
protected _device: Device;
|
||||
|
||||
export abstract class RenderPass extends GFXObject {
|
||||
protected _colorInfos: ColorAttachment[] = [];
|
||||
|
||||
protected _depthStencilInfo: DepthStencilAttachment | null = null;
|
||||
|
||||
protected _subpasses: SubpassInfo[] = [];
|
||||
|
||||
protected _hash = 0;
|
||||
|
||||
get colorAttachments () { return this._colorInfos; }
|
||||
@@ -59,9 +53,8 @@ export abstract class RenderPass extends Obj {
|
||||
get subPasses () { return this._subpasses; }
|
||||
get hash () { return this._hash; }
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.RENDER_PASS);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
// Based on render pass compatibility
|
||||
@@ -104,7 +97,7 @@ export abstract class RenderPass extends Obj {
|
||||
return murmurhash2_32_gc(res, 666);
|
||||
}
|
||||
|
||||
public abstract initialize (info: RenderPassInfo): boolean;
|
||||
public abstract initialize (info: RenderPassInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
|
||||
@@ -28,65 +28,40 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import { Obj, ObjectType, ShaderInfo, ShaderStage, UniformBlock, UniformSampler, Attribute } from './define';
|
||||
import { GFXObject, ObjectType, ShaderInfo, ShaderStage, UniformBlock, UniformSampler, Attribute } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX shader.
|
||||
* @zh GFX 着色器。
|
||||
*/
|
||||
export abstract class Shader extends Obj {
|
||||
private static _shaderIdGen = 0;
|
||||
|
||||
/**
|
||||
* @en Get current shader id.
|
||||
* @zh 着色器 id。
|
||||
*/
|
||||
public get id (): number {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get current shader name.
|
||||
* @zh 着色器名称。
|
||||
*/
|
||||
public get name (): string {
|
||||
export abstract class Shader extends GFXObject {
|
||||
get name (): string {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get attributes () {
|
||||
get attributes () {
|
||||
return this._attributes;
|
||||
}
|
||||
|
||||
public get blocks () {
|
||||
get blocks () {
|
||||
return this._blocks;
|
||||
}
|
||||
|
||||
public get samplers () {
|
||||
get samplers () {
|
||||
return this._samplers;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _id: number;
|
||||
|
||||
protected _name = '';
|
||||
|
||||
protected _stages: ShaderStage[] = [];
|
||||
|
||||
protected _attributes: Attribute[] = [];
|
||||
|
||||
protected _blocks: UniformBlock[] = [];
|
||||
|
||||
protected _samplers: UniformSampler[] = [];
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.SHADER);
|
||||
this._device = device;
|
||||
this._id = Shader._shaderIdGen++;
|
||||
}
|
||||
|
||||
public abstract initialize (info: ShaderInfo): boolean;
|
||||
public abstract initialize (info: ShaderInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @packageDocumentation
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { murmurhash2_32_gc } from '../../../utils/murmurhash2_gc';
|
||||
import { GFXObject, ObjectType, GlobalBarrierInfo } from '../define';
|
||||
|
||||
/**
|
||||
* @en GFX global barrier.
|
||||
* @zh GFX 全局内存屏障。
|
||||
*/
|
||||
export class GlobalBarrier extends GFXObject {
|
||||
get info (): Readonly<GlobalBarrierInfo> { return this._info; }
|
||||
|
||||
protected _info: GlobalBarrierInfo = new GlobalBarrierInfo();
|
||||
|
||||
constructor (info: GlobalBarrierInfo) {
|
||||
super(ObjectType.GLOBAL_BARRIER);
|
||||
this._info.copy(info);
|
||||
}
|
||||
|
||||
static computeHash (info: GlobalBarrierInfo) {
|
||||
let res = 'prev:';
|
||||
for (let i = 0; i < info.prevAccesses.length; ++i) {
|
||||
res += ` ${info.prevAccesses[i]}`;
|
||||
}
|
||||
res += 'next:';
|
||||
for (let i = 0; i < info.nextAccesses.length; ++i) {
|
||||
res += ` ${info.nextAccesses[i]}`;
|
||||
}
|
||||
|
||||
return murmurhash2_32_gc(res, 666);
|
||||
}
|
||||
}
|
||||
@@ -28,44 +28,44 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import { Color, Address, ComparisonFunc, Filter, Obj, ObjectType, SamplerInfo } from './define';
|
||||
import { GFXObject, ObjectType, SamplerInfo } from '../define';
|
||||
|
||||
/**
|
||||
* @en GFX sampler.
|
||||
* @zh GFX 采样器。
|
||||
*/
|
||||
export abstract class Sampler extends Obj {
|
||||
get minFilter () { return this._minFilter; }
|
||||
get magFilter () { return this._magFilter; }
|
||||
get mipFilter () { return this._mipFilter; }
|
||||
get addressU () { return this._addressU; }
|
||||
get addressV () { return this._addressV; }
|
||||
get addressW () { return this._addressW; }
|
||||
get maxAnisotropy () { return this._maxAnisotropy; }
|
||||
get cmpFunc () { return this._cmpFunc; }
|
||||
get borderColor () { return this._borderColor; }
|
||||
get mipLODBias () { return this._mipLODBias; }
|
||||
export class Sampler extends GFXObject {
|
||||
get info (): Readonly<SamplerInfo> { return this._info; }
|
||||
|
||||
protected _device: Device;
|
||||
protected _info: SamplerInfo = new SamplerInfo();
|
||||
|
||||
protected _minFilter: Filter = Filter.LINEAR;
|
||||
protected _magFilter: Filter = Filter.LINEAR;
|
||||
protected _mipFilter: Filter = Filter.NONE;
|
||||
protected _addressU: Address = Address.WRAP;
|
||||
protected _addressV: Address = Address.WRAP;
|
||||
protected _addressW: Address = Address.WRAP;
|
||||
protected _maxAnisotropy = 16;
|
||||
protected _cmpFunc: ComparisonFunc = ComparisonFunc.NEVER;
|
||||
protected _borderColor: Color = new Color();
|
||||
protected _mipLODBias = 0.0;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor (info: SamplerInfo) {
|
||||
super(ObjectType.SAMPLER);
|
||||
this._device = device;
|
||||
this._info.copy(info);
|
||||
}
|
||||
|
||||
public abstract initialize (info: SamplerInfo): boolean;
|
||||
static computeHash (info: SamplerInfo) {
|
||||
let hash = info.minFilter;
|
||||
hash |= (info.magFilter << 2);
|
||||
hash |= (info.mipFilter << 4);
|
||||
hash |= (info.addressU << 6);
|
||||
hash |= (info.addressV << 8);
|
||||
hash |= (info.addressW << 10);
|
||||
hash |= (info.maxAnisotropy << 12);
|
||||
hash |= (info.cmpFunc << 16);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public abstract destroy (): void;
|
||||
static unpackFromHash (hash: number) {
|
||||
const info = new SamplerInfo();
|
||||
info.minFilter = (hash & ((1 << 2) - 1)) >> 0;
|
||||
info.magFilter = (hash & ((1 << 2) - 1)) >> 2;
|
||||
info.mipFilter = (hash & ((1 << 2) - 1)) >> 4;
|
||||
info.addressU = (hash & ((1 << 2) - 1)) >> 6;
|
||||
info.addressV = (hash & ((1 << 2) - 1)) >> 8;
|
||||
info.addressW = (hash & ((1 << 2) - 1)) >> 10;
|
||||
info.maxAnisotropy = (hash & ((1 << 4) - 1)) >> 12;
|
||||
info.cmpFunc = (hash & ((1 << 3) - 1)) >> 16;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @packageDocumentation
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { murmurhash2_32_gc } from '../../../utils/murmurhash2_gc';
|
||||
import { GFXObject, ObjectType, TextureBarrierInfo } from '../define';
|
||||
|
||||
/**
|
||||
* @en GFX texture barrier.
|
||||
* @zh GFX 贴图内存屏障。
|
||||
*/
|
||||
export class TextureBarrier extends GFXObject {
|
||||
get info (): Readonly<TextureBarrierInfo> { return this._info; }
|
||||
|
||||
protected _info: TextureBarrierInfo = new TextureBarrierInfo();
|
||||
|
||||
constructor (info: TextureBarrierInfo) {
|
||||
super(ObjectType.TEXTURE_BARRIER);
|
||||
this._info.copy(info);
|
||||
}
|
||||
|
||||
static computeHash (info: TextureBarrierInfo) {
|
||||
let res = 'prev:';
|
||||
for (let i = 0; i < info.prevAccesses.length; ++i) {
|
||||
res += ` ${info.prevAccesses[i]}`;
|
||||
}
|
||||
res += 'next:';
|
||||
for (let i = 0; i < info.nextAccesses.length; ++i) {
|
||||
res += ` ${info.nextAccesses[i]}`;
|
||||
}
|
||||
res += info.discardContents;
|
||||
res += info.srcQueue ? info.srcQueue.type : 0;
|
||||
res += info.dstQueue ? info.dstQueue.type : 0;
|
||||
|
||||
return murmurhash2_32_gc(res, 666);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @packageDocumentation
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { GFXObject, ObjectType, SurfaceTransform, SwapchainInfo } from './define';
|
||||
import { Texture } from './texture';
|
||||
|
||||
/**
|
||||
* @en GFX Swapchain.
|
||||
* @zh GFX 交换链。
|
||||
*/
|
||||
export abstract class Swapchain extends GFXObject {
|
||||
/**
|
||||
* @en The color texture of this swapchain.
|
||||
* @zh 当前交换链的颜色缓冲。
|
||||
*/
|
||||
get colorTexture () {
|
||||
return this._colorTexture;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The depth stencil texture of this swapchain.
|
||||
* @zh 当前交换链的深度模板缓冲。
|
||||
*/
|
||||
get depthStencilTexture () {
|
||||
return this._depthStencilTexture;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The surface transform to be applied in projection matrices.
|
||||
* @zh 需要在投影矩阵中应用的表面变换。
|
||||
*/
|
||||
get surfaceTransform () {
|
||||
return this._transform;
|
||||
}
|
||||
|
||||
get width () {
|
||||
return this._colorTexture.width;
|
||||
}
|
||||
|
||||
get height () {
|
||||
return this._colorTexture.height;
|
||||
}
|
||||
|
||||
protected _transform = SurfaceTransform.IDENTITY;
|
||||
protected _colorTexture: Texture = null!;
|
||||
protected _depthStencilTexture: Texture = null!;
|
||||
|
||||
constructor () {
|
||||
super(ObjectType.SWAPCHAIN);
|
||||
}
|
||||
|
||||
public abstract initialize (info: SwapchainInfo): void;
|
||||
public abstract resize (width: number, height: number): void;
|
||||
public abstract destroy (): void;
|
||||
}
|
||||
@@ -28,10 +28,9 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { Device } from './device';
|
||||
import {
|
||||
Format,
|
||||
Obj,
|
||||
GFXObject,
|
||||
ObjectType,
|
||||
SampleCount,
|
||||
TextureFlagBit,
|
||||
@@ -41,13 +40,14 @@ import {
|
||||
TextureUsageBit,
|
||||
TextureInfo,
|
||||
TextureViewInfo,
|
||||
ISwapchainTextureInfo,
|
||||
} from './define';
|
||||
|
||||
/**
|
||||
* @en GFX texture.
|
||||
* @zh GFX 纹理。
|
||||
*/
|
||||
export abstract class Texture extends Obj {
|
||||
export abstract class Texture extends GFXObject {
|
||||
/**
|
||||
* @en Get texture type.
|
||||
* @zh 纹理类型。
|
||||
@@ -136,8 +136,6 @@ export abstract class Texture extends Obj {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
protected _device: Device;
|
||||
|
||||
protected _type: TextureType = TextureType.TEX2D;
|
||||
protected _usage: TextureUsage = TextureUsageBit.NONE;
|
||||
protected _format: Format = Format.UNKNOWN;
|
||||
@@ -146,17 +144,16 @@ export abstract class Texture extends Obj {
|
||||
protected _depth = 1;
|
||||
protected _layerCount = 1;
|
||||
protected _levelCount = 1;
|
||||
protected _samples: SampleCount = SampleCount.X1;
|
||||
protected _samples: SampleCount = SampleCount.ONE;
|
||||
protected _flags: TextureFlags = TextureFlagBit.NONE;
|
||||
protected _isPowerOf2 = false;
|
||||
protected _size = 0;
|
||||
|
||||
constructor (device: Device) {
|
||||
constructor () {
|
||||
super(ObjectType.TEXTURE);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize (info: TextureInfo | TextureViewInfo): boolean;
|
||||
public abstract initialize (info: TextureInfo | TextureViewInfo): void;
|
||||
|
||||
public abstract destroy (): void;
|
||||
|
||||
@@ -167,4 +164,6 @@ export abstract class Texture extends Obj {
|
||||
* @param height The new height.
|
||||
*/
|
||||
public abstract resize (width: number, height: number): void;
|
||||
|
||||
protected abstract initAsSwapchainTexture (info: ISwapchainTextureInfo): void;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { BufferSource, BufferInfo, BufferViewInfo } from '../base/define';
|
||||
import { Buffer } from '../base/buffer';
|
||||
|
||||
export class EmptyBuffer extends Buffer {
|
||||
public initialize (info: BufferInfo | BufferViewInfo) {
|
||||
if ('buffer' in info) { // buffer view
|
||||
this._isBufferView = true;
|
||||
|
||||
const buffer = info.buffer as EmptyBuffer;
|
||||
|
||||
this._usage = buffer.usage;
|
||||
this._memUsage = buffer.memUsage;
|
||||
this._size = this._stride = info.range;
|
||||
this._count = 1;
|
||||
this._flags = buffer.flags;
|
||||
} else { // native buffer
|
||||
this._usage = info.usage;
|
||||
this._memUsage = info.memUsage;
|
||||
this._size = info.size;
|
||||
this._stride = Math.max(info.stride || this._size, 1);
|
||||
this._count = this._size / this._stride;
|
||||
this._flags = info.flags;
|
||||
}
|
||||
}
|
||||
public destroy () {}
|
||||
public resize (size: number) {}
|
||||
public update (buffer: BufferSource, size?: number) {}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { Buffer } from '../base/buffer';
|
||||
import { CommandBuffer } from '../base/command-buffer';
|
||||
import { Framebuffer } from '../base/framebuffer';
|
||||
import { InputAssembler } from '../base/input-assembler';
|
||||
import { PipelineState } from '../base/pipeline-state';
|
||||
import { Texture } from '../base/texture';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { GlobalBarrier } from '../base/states/global-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { StencilFace, BufferSource, CommandBufferInfo, BufferTextureCopy, Color, Rect, Viewport, DrawInfo } from '../base/define';
|
||||
|
||||
export class EmptyCommandBuffer extends CommandBuffer {
|
||||
public initialize (info: CommandBufferInfo) {
|
||||
this._type = info.type;
|
||||
this._queue = info.queue;
|
||||
}
|
||||
public destroy () {}
|
||||
public begin (renderPass?: RenderPass, subpass = 0, frameBuffer?: Framebuffer) {}
|
||||
public end () {}
|
||||
public beginRenderPass (renderPass: RenderPass, framebuffer: Framebuffer, renderArea: Rect,
|
||||
clearColors: Color[], clearDepth: number, clearStencil: number) {}
|
||||
public endRenderPass () {}
|
||||
public bindPipelineState (pipelineState: PipelineState) {}
|
||||
public bindDescriptorSet (set: number, descriptorSet: DescriptorSet, dynamicOffsets?: number[]) {}
|
||||
public bindInputAssembler (inputAssembler: InputAssembler) {}
|
||||
public setViewport (viewport: Viewport) {}
|
||||
public setScissor (scissor: Rect) {}
|
||||
public setLineWidth (lineWidth: number) {}
|
||||
public setDepthBias (depthBiasConstantFactor: number, depthBiasClamp: number, depthBiasSlopeFactor: number) {}
|
||||
public setBlendConstants (blendConstants: Color) {}
|
||||
public setDepthBound (minDepthBounds: number, maxDepthBounds: number) {}
|
||||
public setStencilWriteMask (face: StencilFace, writeMask: number) {}
|
||||
public setStencilCompareMask (face: StencilFace, reference: number, compareMask: number) {}
|
||||
public draw (infoOrAssembler: DrawInfo | InputAssembler) {}
|
||||
public updateBuffer (buffer: Buffer, data: BufferSource, size?: number) {}
|
||||
public copyBuffersToTexture (buffers: ArrayBufferView[], texture: Texture, regions: BufferTextureCopy[]) {}
|
||||
public execute (cmdBuffs: CommandBuffer[], count: number) {}
|
||||
public pipelineBarrier (globalBarrier: GlobalBarrier, textureBarriers: TextureBarrier[]) {}
|
||||
}
|
||||
+6
-23
@@ -23,29 +23,12 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @packageDocumentation
|
||||
* @module gfx
|
||||
*/
|
||||
import { DescriptorSetLayoutInfo } from '../base/define';
|
||||
import { DescriptorSetLayout } from '../base/descriptor-set-layout';
|
||||
|
||||
import { Device } from './device';
|
||||
import { Obj, ObjectType, TextureBarrierInfo } from './define';
|
||||
|
||||
/**
|
||||
* @en GFX shader.
|
||||
* @zh GFX 着色器。
|
||||
*/
|
||||
export class TextureBarrier extends Obj {
|
||||
protected _device: Device;
|
||||
protected _info: TextureBarrierInfo = new TextureBarrierInfo();
|
||||
|
||||
constructor (device: Device) {
|
||||
super(ObjectType.TEXTURE_BARRIER);
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public initialize (info: TextureBarrierInfo): boolean {
|
||||
this._info.copy(info);
|
||||
return true;
|
||||
export class EmptyDescriptorSetLayout extends DescriptorSetLayout {
|
||||
public initialize (info: DescriptorSetLayoutInfo) {
|
||||
Array.prototype.push.apply(this._bindings, info.bindings);
|
||||
}
|
||||
public destroy () {}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { DescriptorSetInfo } from '../base/define';
|
||||
|
||||
export class EmptyDescriptorSet extends DescriptorSet {
|
||||
public initialize (info: DescriptorSetInfo) {
|
||||
this._layout = info.layout;
|
||||
}
|
||||
public destroy () {}
|
||||
public update () {}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { debug } from '../../platform/debug';
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { DescriptorSetLayout } from '../base/descriptor-set-layout';
|
||||
import { PipelineLayout } from '../base/pipeline-layout';
|
||||
import { Buffer } from '../base/buffer';
|
||||
import { CommandBuffer } from '../base/command-buffer';
|
||||
import { Device } from '../base/device';
|
||||
import { Framebuffer } from '../base/framebuffer';
|
||||
import { InputAssembler } from '../base/input-assembler';
|
||||
import { PipelineState, PipelineStateInfo } from '../base/pipeline-state';
|
||||
import { Queue } from '../base/queue';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { Sampler } from '../base/states/sampler';
|
||||
import { Shader } from '../base/shader';
|
||||
import { Texture } from '../base/texture';
|
||||
import {
|
||||
ShaderInfo,
|
||||
QueueInfo, CommandBufferInfo, DescriptorSetInfo, DescriptorSetLayoutInfo, FramebufferInfo, InputAssemblerInfo, PipelineLayoutInfo,
|
||||
RenderPassInfo, SamplerInfo, TextureInfo, TextureViewInfo, BufferInfo, BufferViewInfo, DeviceInfo, TextureBarrierInfo, GlobalBarrierInfo,
|
||||
QueueType, API, BufferTextureCopy, SwapchainInfo,
|
||||
} from '../base/define';
|
||||
import { GlobalBarrier } from '../base/states/global-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { EmptyDescriptorSet } from './empty-descriptor-set';
|
||||
import { EmptyBuffer } from './empty-buffer';
|
||||
import { EmptyCommandBuffer } from './empty-command-buffer';
|
||||
import { EmptyFramebuffer } from './empty-framebuffer';
|
||||
import { EmptyInputAssembler } from './empty-input-assembler';
|
||||
import { EmptyDescriptorSetLayout } from './empty-descriptor-set-layout';
|
||||
import { EmptyPipelineLayout } from './empty-pipeline-layout';
|
||||
import { EmptyPipelineState } from './empty-pipeline-state';
|
||||
import { EmptyQueue } from './empty-queue';
|
||||
import { EmptyRenderPass } from './empty-render-pass';
|
||||
import { EmptyShader } from './empty-shader';
|
||||
import { EmptySwapchain } from './empty-swapchain';
|
||||
import { EmptyTexture } from './empty-texture';
|
||||
|
||||
export class EmptyDevice extends Device {
|
||||
public initialize (info: DeviceInfo): boolean {
|
||||
this._gfxAPI = API.UNKNOWN;
|
||||
|
||||
this._bindingMappingInfo = info.bindingMappingInfo;
|
||||
if (!this._bindingMappingInfo.bufferOffsets.length) this._bindingMappingInfo.bufferOffsets.push(0);
|
||||
if (!this._bindingMappingInfo.samplerOffsets.length) this._bindingMappingInfo.samplerOffsets.push(0);
|
||||
|
||||
this._queue = this.createQueue(new QueueInfo(QueueType.GRAPHICS));
|
||||
this._cmdBuff = this.createCommandBuffer(new CommandBufferInfo(this._queue));
|
||||
|
||||
debug('Empty device initialized.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
if (this._queue) {
|
||||
this._queue.destroy();
|
||||
this._queue = null;
|
||||
}
|
||||
|
||||
if (this._cmdBuff) {
|
||||
this._cmdBuff.destroy();
|
||||
this._cmdBuff = null;
|
||||
}
|
||||
}
|
||||
|
||||
public flushCommands (cmdBuffs: CommandBuffer[]) {}
|
||||
public acquire (swapchains: Swapchain[]) {}
|
||||
public present () {}
|
||||
|
||||
public createCommandBuffer (info: CommandBufferInfo): CommandBuffer {
|
||||
const cmdBuff = new EmptyCommandBuffer();
|
||||
cmdBuff.initialize(info);
|
||||
return cmdBuff;
|
||||
}
|
||||
|
||||
public createSwapchain (info: SwapchainInfo): Swapchain {
|
||||
const swapchain = new EmptySwapchain();
|
||||
swapchain.initialize(info);
|
||||
return swapchain;
|
||||
}
|
||||
|
||||
public createBuffer (info: BufferInfo | BufferViewInfo): Buffer {
|
||||
const buffer = new EmptyBuffer();
|
||||
buffer.initialize(info);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public createTexture (info: TextureInfo | TextureViewInfo): Texture {
|
||||
const texture = new EmptyTexture();
|
||||
texture.initialize(info);
|
||||
return texture;
|
||||
}
|
||||
|
||||
public createDescriptorSet (info: DescriptorSetInfo): DescriptorSet {
|
||||
const descriptorSet = new EmptyDescriptorSet();
|
||||
descriptorSet.initialize(info);
|
||||
return descriptorSet;
|
||||
}
|
||||
|
||||
public createShader (info: ShaderInfo): Shader {
|
||||
const shader = new EmptyShader();
|
||||
shader.initialize(info);
|
||||
return shader;
|
||||
}
|
||||
|
||||
public createInputAssembler (info: InputAssemblerInfo): InputAssembler {
|
||||
const inputAssembler = new EmptyInputAssembler();
|
||||
inputAssembler.initialize(info);
|
||||
return inputAssembler;
|
||||
}
|
||||
|
||||
public createRenderPass (info: RenderPassInfo): RenderPass {
|
||||
const renderPass = new EmptyRenderPass();
|
||||
renderPass.initialize(info);
|
||||
return renderPass;
|
||||
}
|
||||
|
||||
public createFramebuffer (info: FramebufferInfo): Framebuffer {
|
||||
const framebuffer = new EmptyFramebuffer();
|
||||
framebuffer.initialize(info);
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
public createDescriptorSetLayout (info: DescriptorSetLayoutInfo): DescriptorSetLayout {
|
||||
const descriptorSetLayout = new EmptyDescriptorSetLayout();
|
||||
descriptorSetLayout.initialize(info);
|
||||
return descriptorSetLayout;
|
||||
}
|
||||
|
||||
public createPipelineLayout (info: PipelineLayoutInfo): PipelineLayout {
|
||||
const pipelineLayout = new EmptyPipelineLayout();
|
||||
pipelineLayout.initialize(info);
|
||||
return pipelineLayout;
|
||||
}
|
||||
|
||||
public createPipelineState (info: PipelineStateInfo): PipelineState {
|
||||
const pipelineState = new EmptyPipelineState();
|
||||
pipelineState.initialize(info);
|
||||
return pipelineState;
|
||||
}
|
||||
|
||||
public createQueue (info: QueueInfo): Queue {
|
||||
const queue = new EmptyQueue();
|
||||
queue.initialize(info);
|
||||
return queue;
|
||||
}
|
||||
|
||||
public getSampler (info: SamplerInfo): Sampler {
|
||||
const hash = Sampler.computeHash(info);
|
||||
if (!this._samplers.has(hash)) {
|
||||
this._samplers.set(hash, new Sampler(info));
|
||||
}
|
||||
return this._samplers.get(hash)!;
|
||||
}
|
||||
|
||||
public getGlobalBarrier (info: GlobalBarrierInfo) {
|
||||
const hash = GlobalBarrier.computeHash(info);
|
||||
if (!this._globalBarriers.has(hash)) {
|
||||
this._globalBarriers.set(hash, new GlobalBarrier(info));
|
||||
}
|
||||
return this._globalBarriers.get(hash)!;
|
||||
}
|
||||
|
||||
public getTextureBarrier (info: TextureBarrierInfo) {
|
||||
const hash = TextureBarrier.computeHash(info);
|
||||
if (!this._textureBarriers.has(hash)) {
|
||||
this._textureBarriers.set(hash, new TextureBarrier(info));
|
||||
}
|
||||
return this._textureBarriers.get(hash)!;
|
||||
}
|
||||
|
||||
public copyBuffersToTexture (buffers: ArrayBufferView[], texture: Texture, regions: BufferTextureCopy[]) {}
|
||||
public copyTextureToBuffers (texture: Texture, buffers: ArrayBufferView[], regions: BufferTextureCopy[]) {}
|
||||
public copyTexImagesToTexture (texImages: TexImageSource[], texture: Texture, regions: BufferTextureCopy[]) {}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { FramebufferInfo } from '../base/define';
|
||||
import { Framebuffer } from '../base/framebuffer';
|
||||
|
||||
export class EmptyFramebuffer extends Framebuffer {
|
||||
public initialize (info: FramebufferInfo) {
|
||||
this._renderPass = info.renderPass;
|
||||
this._colorTextures = info.colorTextures || [];
|
||||
this._depthStencilTexture = info.depthStencilTexture || null;
|
||||
}
|
||||
public destroy () {}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { InputAssemblerInfo } from '../base/define';
|
||||
import { InputAssembler } from '../base/input-assembler';
|
||||
|
||||
export class EmptyInputAssembler extends InputAssembler {
|
||||
public initialize (info: InputAssemblerInfo) {
|
||||
this._attributes = info.attributes;
|
||||
this._attributesHash = this.computeAttributesHash();
|
||||
this._vertexBuffers = info.vertexBuffers;
|
||||
|
||||
if (info.indexBuffer) {
|
||||
this._indexBuffer = info.indexBuffer;
|
||||
this._drawInfo.indexCount = this._indexBuffer.size / this._indexBuffer.stride;
|
||||
this._drawInfo.firstIndex = 0;
|
||||
} else {
|
||||
const vertBuff = this._vertexBuffers[0];
|
||||
this._drawInfo.vertexCount = vertBuff.size / vertBuff.stride;
|
||||
this._drawInfo.firstVertex = 0;
|
||||
this._drawInfo.vertexOffset = 0;
|
||||
}
|
||||
}
|
||||
public destroy () {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { PipelineLayout } from '../base/pipeline-layout';
|
||||
import { PipelineLayoutInfo } from '../base/define';
|
||||
|
||||
export class EmptyPipelineLayout extends PipelineLayout {
|
||||
public initialize (info: PipelineLayoutInfo) {
|
||||
Array.prototype.push.apply(this._setLayouts, info.setLayouts);
|
||||
}
|
||||
public destroy () {}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { PipelineState, PipelineStateInfo } from '../base/pipeline-state';
|
||||
|
||||
export class EmptyPipelineState extends PipelineState {
|
||||
public initialize (info: PipelineStateInfo) {
|
||||
this._primitive = info.primitive;
|
||||
this._shader = info.shader;
|
||||
this._pipelineLayout = info.pipelineLayout;
|
||||
const bs = this._bs;
|
||||
if (info.blendState) {
|
||||
const bsInfo = info.blendState;
|
||||
const { targets } = bsInfo;
|
||||
if (targets) {
|
||||
targets.forEach((t, i) => {
|
||||
bs.setTarget(i, t);
|
||||
});
|
||||
}
|
||||
|
||||
if (bsInfo.isA2C !== undefined) { bs.isA2C = bsInfo.isA2C; }
|
||||
if (bsInfo.isIndepend !== undefined) { bs.isIndepend = bsInfo.isIndepend; }
|
||||
if (bsInfo.blendColor !== undefined) { bs.blendColor = bsInfo.blendColor; }
|
||||
}
|
||||
Object.assign(this._rs, info.rasterizerState);
|
||||
Object.assign(this._dss, info.depthStencilState);
|
||||
this._is = info.inputState;
|
||||
this._renderPass = info.renderPass;
|
||||
this._dynamicStates = info.dynamicStates;
|
||||
}
|
||||
public destroy () {}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { QueueInfo } from '../base/define';
|
||||
import { CommandBuffer } from '../base/command-buffer';
|
||||
import { Queue } from '../base/queue';
|
||||
|
||||
export class EmptyQueue extends Queue {
|
||||
public initialize (info: QueueInfo) {
|
||||
this._type = info.type;
|
||||
}
|
||||
public destroy () {}
|
||||
public submit (cmdBuffs: CommandBuffer[]) {}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { RenderPassInfo } from '../base/define';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
|
||||
export class EmptyRenderPass extends RenderPass {
|
||||
public initialize (info: RenderPassInfo) {
|
||||
this._colorInfos = info.colorAttachments;
|
||||
this._depthStencilInfo = info.depthStencilAttachment;
|
||||
this._subpasses = info.subpasses;
|
||||
this._hash = this.computeHash();
|
||||
}
|
||||
public destroy () {}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { debug } from '../../platform';
|
||||
import { ShaderInfo } from '../base/define';
|
||||
import { Shader } from '../base/shader';
|
||||
|
||||
export class EmptyShader extends Shader {
|
||||
public initialize (info: ShaderInfo) {
|
||||
debug(`Shader '${info.name}' compilation succeeded.`);
|
||||
}
|
||||
public destroy () {}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Format, SwapchainInfo } from '../base/define';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { EmptyTexture } from './empty-texture';
|
||||
|
||||
export class EmptySwapchain extends Swapchain {
|
||||
public initialize (info: SwapchainInfo) {
|
||||
this._colorTexture = new EmptyTexture();
|
||||
// @ts-expect-error(2445) private initializer
|
||||
this._colorTexture.initAsSwapchainTexture({
|
||||
swapchain: this,
|
||||
format: Format.RGBA8,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
});
|
||||
|
||||
this._depthStencilTexture = new EmptyTexture();
|
||||
// @ts-expect-error(2445) private initializer
|
||||
this._depthStencilTexture.initAsSwapchainTexture({
|
||||
swapchain: this,
|
||||
format: Format.DEPTH_STENCIL,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
});
|
||||
}
|
||||
public destroy (): void {}
|
||||
public resize (width: number, height: number) {}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { TextureInfo, TextureViewInfo, ISwapchainTextureInfo, FormatSurfaceSize, IsPowerOf2 } from '../base/define';
|
||||
import { Texture } from '../base/texture';
|
||||
|
||||
export class EmptyTexture extends Texture {
|
||||
public initialize (info: TextureInfo | TextureViewInfo, isSwapchainTexture?: boolean) {
|
||||
if ('texture' in info) {
|
||||
this._type = info.type;
|
||||
this._format = info.format;
|
||||
this._layerCount = info.layerCount;
|
||||
this._levelCount = info.levelCount;
|
||||
this._usage = info.texture.usage;
|
||||
this._width = info.texture.width;
|
||||
this._height = info.texture.height;
|
||||
this._depth = info.texture.depth;
|
||||
this._samples = info.texture.samples;
|
||||
this._flags = info.texture.flags;
|
||||
} else {
|
||||
this._type = info.type;
|
||||
this._usage = info.usage;
|
||||
this._format = info.format;
|
||||
this._width = info.width;
|
||||
this._height = info.height;
|
||||
this._depth = info.depth;
|
||||
this._layerCount = info.layerCount;
|
||||
this._levelCount = info.levelCount;
|
||||
this._samples = info.samples;
|
||||
this._flags = info.flags;
|
||||
this._isPowerOf2 = IsPowerOf2(this._width) && IsPowerOf2(this._height);
|
||||
this._size = FormatSurfaceSize(this._format, this.width, this.height,
|
||||
this.depth, this._levelCount) * this._layerCount;
|
||||
}
|
||||
}
|
||||
public destroy () {}
|
||||
public resize (width: number, height: number) {}
|
||||
protected initAsSwapchainTexture (info: ISwapchainTextureInfo) {}
|
||||
}
|
||||
@@ -39,20 +39,22 @@ export * from './base/buffer';
|
||||
export * from './base/command-buffer';
|
||||
export * from './base/define';
|
||||
export * from './base/device';
|
||||
export * from './base/swapchain';
|
||||
export * from './base/framebuffer';
|
||||
export * from './base/input-assembler';
|
||||
export * from './base/descriptor-set-layout';
|
||||
export * from './base/pipeline-layout';
|
||||
export * from './base/queue';
|
||||
export * from './base/render-pass';
|
||||
export * from './base/sampler';
|
||||
export * from './base/shader';
|
||||
export * from './base/texture';
|
||||
export * from './base/global-barrier';
|
||||
export * from './base/texture-barrier';
|
||||
export * from './base/states/sampler';
|
||||
export * from './base/states/global-barrier';
|
||||
export * from './base/states/texture-barrier';
|
||||
|
||||
const polyfillCC: Record<string, unknown> = Object.assign({}, defines);
|
||||
polyfillCC.Device = gfx.Device;
|
||||
polyfillCC.Swapchain = gfx.Swapchain;
|
||||
polyfillCC.Buffer = gfx.Buffer;
|
||||
polyfillCC.Texture = gfx.Texture;
|
||||
polyfillCC.Sampler = gfx.Sampler;
|
||||
|
||||
@@ -36,6 +36,7 @@ export * from './base/buffer';
|
||||
export * from './base/command-buffer';
|
||||
export * from './base/define';
|
||||
export * from './base/device';
|
||||
export * from './base/swapchain';
|
||||
export * from './base/framebuffer';
|
||||
export * from './base/input-assembler';
|
||||
export * from './base/descriptor-set-layout';
|
||||
@@ -43,8 +44,8 @@ export * from './base/pipeline-layout';
|
||||
export * from './base/pipeline-state';
|
||||
export * from './base/queue';
|
||||
export * from './base/render-pass';
|
||||
export * from './base/sampler';
|
||||
export * from './base/states/sampler';
|
||||
export * from './base/shader';
|
||||
export * from './base/texture';
|
||||
export * from './base/global-barrier';
|
||||
export * from './base/texture-barrier';
|
||||
export * from './base/states/global-barrier';
|
||||
export * from './base/states/texture-barrier';
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
import { Buffer } from './base/buffer';
|
||||
import { CommandBuffer } from './base/command-buffer';
|
||||
import { Device } from './base/device';
|
||||
import { Swapchain } from './base/swapchain';
|
||||
import { Framebuffer } from './base/framebuffer';
|
||||
import { InputAssembler } from './base/input-assembler';
|
||||
import { DescriptorSet } from './base/descriptor-set';
|
||||
@@ -39,16 +40,17 @@ import { PipelineLayout } from './base/pipeline-layout';
|
||||
import { PipelineState, PipelineStateInfo, RasterizerState, BlendState, BlendTarget, DepthStencilState } from './base/pipeline-state';
|
||||
import { Queue } from './base/queue';
|
||||
import { RenderPass } from './base/render-pass';
|
||||
import { Sampler } from './base/sampler';
|
||||
import { Sampler } from './base/states/sampler';
|
||||
import { Shader } from './base/shader';
|
||||
import { Texture } from './base/texture';
|
||||
import { GlobalBarrier } from './base/global-barrier';
|
||||
import { TextureBarrier } from './base/texture-barrier';
|
||||
import { GlobalBarrier } from './base/states/global-barrier';
|
||||
import { TextureBarrier } from './base/states/texture-barrier';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import * as defines from './base/define';
|
||||
|
||||
const polyfills: Record<string, unknown> = {
|
||||
Device,
|
||||
Swapchain,
|
||||
Buffer,
|
||||
Texture,
|
||||
Sampler,
|
||||
|
||||
+11
-26
@@ -23,9 +23,9 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Filter, SamplerInfo } from '../base/define';
|
||||
import { Sampler } from '../base/sampler';
|
||||
import { IWebGLGPUSampler } from './webgl-gpu-objects';
|
||||
import { Filter, SamplerInfo } from '../../base/define';
|
||||
import { Sampler } from '../../base/states/sampler';
|
||||
import { IWebGLGPUSampler } from '../webgl-gpu-objects';
|
||||
|
||||
const WebGLWraps: GLenum[] = [
|
||||
0x2901, // WebGLRenderingContext.REPEAT,
|
||||
@@ -41,24 +41,15 @@ export class WebGLSampler extends Sampler {
|
||||
|
||||
private _gpuSampler: IWebGLGPUSampler | null = null;
|
||||
|
||||
public initialize (info: SamplerInfo): boolean {
|
||||
this._minFilter = info.minFilter;
|
||||
this._magFilter = info.magFilter;
|
||||
this._mipFilter = info.mipFilter;
|
||||
this._addressU = info.addressU;
|
||||
this._addressV = info.addressV;
|
||||
this._addressW = info.addressW;
|
||||
this._maxAnisotropy = info.maxAnisotropy;
|
||||
this._cmpFunc = info.cmpFunc;
|
||||
this._borderColor = info.borderColor;
|
||||
this._mipLODBias = info.mipLODBias;
|
||||
constructor (info: SamplerInfo) {
|
||||
super(info);
|
||||
|
||||
let glMinFilter = 0;
|
||||
let glMagFilter = 0;
|
||||
|
||||
const minFilter = this._minFilter;
|
||||
const magFilter = this._magFilter;
|
||||
const mipFilter = this._mipFilter;
|
||||
const minFilter = this._info.minFilter;
|
||||
const magFilter = this._info.magFilter;
|
||||
const mipFilter = this._info.mipFilter;
|
||||
|
||||
if (minFilter === Filter.LINEAR || minFilter === Filter.ANISOTROPIC) {
|
||||
if (mipFilter === Filter.LINEAR || mipFilter === Filter.ANISOTROPIC) {
|
||||
@@ -82,9 +73,9 @@ export class WebGLSampler extends Sampler {
|
||||
glMagFilter = 0x2600; // WebGLRenderingContext.NEAREST;
|
||||
}
|
||||
|
||||
const glWrapS = WebGLWraps[this._addressU];
|
||||
const glWrapT = WebGLWraps[this._addressV];
|
||||
const glWrapR = WebGLWraps[this._addressW];
|
||||
const glWrapS = WebGLWraps[this._info.addressU];
|
||||
const glWrapT = WebGLWraps[this._info.addressV];
|
||||
const glWrapR = WebGLWraps[this._info.addressW];
|
||||
|
||||
this._gpuSampler = {
|
||||
glMinFilter,
|
||||
@@ -93,11 +84,5 @@ export class WebGLSampler extends Sampler {
|
||||
glWrapT,
|
||||
glWrapR,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
this._gpuSampler = null;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { BufferSource, BufferInfo, BufferViewInfo, IndirectBuffer, BufferUsageBit } from '../base/define';
|
||||
import { BufferSource, BufferInfo, BufferViewInfo, BufferUsageBit } from '../base/define';
|
||||
import { Buffer } from '../base/buffer';
|
||||
|
||||
import {
|
||||
@@ -32,8 +32,8 @@ import {
|
||||
WebGLCmdFuncResizeBuffer,
|
||||
WebGLCmdFuncUpdateBuffer,
|
||||
} from './webgl-commands';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
import { IWebGLGPUBuffer, IWebGLGPUBufferView } from './webgl-gpu-objects';
|
||||
import { IWebGLGPUBuffer, IWebGLGPUBufferView, WebGLIndirectDrawInfos } from './webgl-gpu-objects';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
|
||||
export class WebGLBuffer extends Buffer {
|
||||
get gpuBuffer (): IWebGLGPUBuffer {
|
||||
@@ -48,7 +48,7 @@ export class WebGLBuffer extends Buffer {
|
||||
private _gpuBufferView: IWebGLGPUBufferView | null = null;
|
||||
private _uniformBuffer: Uint8Array | null = null;
|
||||
|
||||
public initialize (info: BufferInfo | BufferViewInfo): boolean {
|
||||
public initialize (info: BufferInfo | BufferViewInfo) {
|
||||
if ('buffer' in info) { // buffer view
|
||||
this._isBufferView = true;
|
||||
|
||||
@@ -73,10 +73,6 @@ export class WebGLBuffer extends Buffer {
|
||||
this._count = this._size / this._stride;
|
||||
this._flags = info.flags;
|
||||
|
||||
if (this._usage & BufferUsageBit.INDIRECT) {
|
||||
this._indirectBuffer = new IndirectBuffer();
|
||||
}
|
||||
|
||||
if ((this._usage & BufferUsageBit.UNIFORM) && this._size > 0) {
|
||||
this._uniformBuffer = new Uint8Array(this._size);
|
||||
}
|
||||
@@ -88,31 +84,25 @@ export class WebGLBuffer extends Buffer {
|
||||
stride: this._stride,
|
||||
buffer: null,
|
||||
vf32: null,
|
||||
indirects: [],
|
||||
indirects: new WebGLIndirectDrawInfos(),
|
||||
glTarget: 0,
|
||||
glBuffer: null,
|
||||
};
|
||||
|
||||
if (info.usage & BufferUsageBit.INDIRECT) {
|
||||
this._gpuBuffer.indirects = this._indirectBuffer!.drawInfos;
|
||||
}
|
||||
|
||||
if (this._usage & BufferUsageBit.UNIFORM) {
|
||||
this._gpuBuffer.buffer = this._uniformBuffer;
|
||||
}
|
||||
|
||||
WebGLCmdFuncCreateBuffer(this._device as WebGLDevice, this._gpuBuffer);
|
||||
WebGLCmdFuncCreateBuffer(WebGLDeviceManager.instance, this._gpuBuffer);
|
||||
|
||||
this._device.memoryStatus.bufferSize += this._size;
|
||||
WebGLDeviceManager.instance.memoryStatus.bufferSize += this._size;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuBuffer) {
|
||||
WebGLCmdFuncDestroyBuffer(this._device as WebGLDevice, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= this._size;
|
||||
WebGLCmdFuncDestroyBuffer(WebGLDeviceManager.instance, this._gpuBuffer);
|
||||
WebGLDeviceManager.instance.memoryStatus.bufferSize -= this._size;
|
||||
this._gpuBuffer = null;
|
||||
}
|
||||
|
||||
@@ -144,9 +134,9 @@ export class WebGLBuffer extends Buffer {
|
||||
|
||||
this._gpuBuffer.size = size;
|
||||
if (size > 0) {
|
||||
WebGLCmdFuncResizeBuffer(this._device as WebGLDevice, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= oldSize;
|
||||
this._device.memoryStatus.bufferSize += size;
|
||||
WebGLCmdFuncResizeBuffer(WebGLDeviceManager.instance, this._gpuBuffer);
|
||||
WebGLDeviceManager.instance.memoryStatus.bufferSize -= oldSize;
|
||||
WebGLDeviceManager.instance.memoryStatus.bufferSize += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +157,7 @@ export class WebGLBuffer extends Buffer {
|
||||
}
|
||||
|
||||
WebGLCmdFuncUpdateBuffer(
|
||||
this._device as WebGLDevice,
|
||||
WebGLDeviceManager.instance,
|
||||
this._gpuBuffer!,
|
||||
buffer,
|
||||
0,
|
||||
|
||||
@@ -33,7 +33,6 @@ import { Texture } from '../base/texture';
|
||||
import { WebGLDescriptorSet } from './webgl-descriptor-set';
|
||||
import { WebGLBuffer } from './webgl-buffer';
|
||||
import { WebGLCommandAllocator } from './webgl-command-allocator';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
import { WebGLFramebuffer } from './webgl-framebuffer';
|
||||
import { IWebGLGPUInputAssembler, IWebGLGPUDescriptorSet, IWebGLGPUPipelineState } from './webgl-gpu-objects';
|
||||
import { WebGLInputAssembler } from './webgl-input-assembler';
|
||||
@@ -45,12 +44,14 @@ import { BufferUsageBit, CommandBufferType, StencilFace, BufferSource,
|
||||
CommandBufferInfo, BufferTextureCopy, Color, Rect, Viewport, DrawInfo, DynamicStates } from '../base/define';
|
||||
import { WebGLCmd, WebGLCmdBeginRenderPass, WebGLCmdBindStates, WebGLCmdCopyBufferToTexture,
|
||||
WebGLCmdDraw, WebGLCmdPackage, WebGLCmdUpdateBuffer } from './webgl-commands';
|
||||
import { GlobalBarrier } from '../base/global-barrier';
|
||||
import { TextureBarrier } from '../base/texture-barrier';
|
||||
import { GlobalBarrier } from '../base/states/global-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
|
||||
export class WebGLCommandBuffer extends CommandBuffer {
|
||||
public cmdPackage: WebGLCmdPackage = new WebGLCmdPackage();
|
||||
protected _webGLAllocator: WebGLCommandAllocator | null = null;
|
||||
|
||||
protected _cmdAllocator: WebGLCommandAllocator = new WebGLCommandAllocator();
|
||||
protected _isInRenderPass = false;
|
||||
protected _curGPUPipelineState: IWebGLGPUPipelineState | null = null;
|
||||
protected _curGPUInputAssembler: IWebGLGPUInputAssembler | null = null;
|
||||
@@ -59,29 +60,22 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
protected _curDynamicStates: DynamicStates = new DynamicStates();
|
||||
protected _isStateInvalied = false;
|
||||
|
||||
public initialize (info: CommandBufferInfo): boolean {
|
||||
public initialize (info: CommandBufferInfo) {
|
||||
this._type = info.type;
|
||||
this._queue = info.queue;
|
||||
|
||||
this._webGLAllocator = (this._device as WebGLDevice).cmdAllocator;
|
||||
|
||||
const setCount = (this._device as WebGLDevice).bindingMappingInfo.bufferOffsets.length;
|
||||
const setCount = WebGLDeviceManager.instance.bindingMappingInfo.bufferOffsets.length;
|
||||
for (let i = 0; i < setCount; i++) {
|
||||
this._curGPUDescriptorSets.push(null!);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._webGLAllocator) {
|
||||
this._webGLAllocator.clearCmds(this.cmdPackage);
|
||||
this._webGLAllocator = null;
|
||||
}
|
||||
this._cmdAllocator.clearCmds(this.cmdPackage);
|
||||
}
|
||||
|
||||
public begin (renderPass?: RenderPass, subpass = 0, frameBuffer?: Framebuffer) {
|
||||
this._webGLAllocator!.clearCmds(this.cmdPackage);
|
||||
this._cmdAllocator.clearCmds(this.cmdPackage);
|
||||
this._curGPUPipelineState = null;
|
||||
this._curGPUInputAssembler = null;
|
||||
this._curGPUDescriptorSets.length = 0;
|
||||
@@ -106,7 +100,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
clearDepth: number,
|
||||
clearStencil: number,
|
||||
) {
|
||||
const cmd = this._webGLAllocator!.beginRenderPassCmdPool.alloc(WebGLCmdBeginRenderPass);
|
||||
const cmd = this._cmdAllocator.beginRenderPassCmdPool.alloc(WebGLCmdBeginRenderPass);
|
||||
cmd.gpuRenderPass = (renderPass as WebGLRenderPass).gpuRenderPass;
|
||||
cmd.gpuFramebuffer = (framebuffer as WebGLFramebuffer).gpuFramebuffer;
|
||||
cmd.renderArea = renderArea;
|
||||
@@ -268,22 +262,16 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
public draw (info: DrawInfo | InputAssembler) {
|
||||
public draw (infoOrAssembler: DrawInfo | InputAssembler) {
|
||||
if (this._type === CommandBufferType.PRIMARY && this._isInRenderPass
|
||||
|| this._type === CommandBufferType.SECONDARY) {
|
||||
if (this._isStateInvalied) {
|
||||
this.bindStates();
|
||||
}
|
||||
const info = 'drawInfo' in infoOrAssembler ? infoOrAssembler.drawInfo : infoOrAssembler;
|
||||
|
||||
const cmd = this._webGLAllocator!.drawCmdPool.alloc(WebGLCmdDraw);
|
||||
// cmd.drawInfo = inputAssembler;
|
||||
cmd.drawInfo.vertexCount = info.vertexCount;
|
||||
cmd.drawInfo.firstVertex = info.firstVertex;
|
||||
cmd.drawInfo.indexCount = info.indexCount;
|
||||
cmd.drawInfo.firstIndex = info.firstIndex;
|
||||
cmd.drawInfo.vertexOffset = info.vertexOffset;
|
||||
cmd.drawInfo.instanceCount = info.instanceCount;
|
||||
cmd.drawInfo.firstInstance = info.firstInstance;
|
||||
const cmd = this._cmdAllocator.drawCmdPool.alloc(WebGLCmdDraw);
|
||||
cmd.drawInfo.copy(info);
|
||||
this.cmdPackage.drawCmds.push(cmd);
|
||||
|
||||
this.cmdPackage.cmds.push(WebGLCmd.DRAW);
|
||||
@@ -316,7 +304,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
|| this._type === CommandBufferType.SECONDARY) {
|
||||
const gpuBuffer = (buffer as WebGLBuffer).gpuBuffer;
|
||||
if (gpuBuffer) {
|
||||
const cmd = this._webGLAllocator!.updateBufferCmdPool.alloc(WebGLCmdUpdateBuffer);
|
||||
const cmd = this._cmdAllocator.updateBufferCmdPool.alloc(WebGLCmdUpdateBuffer);
|
||||
|
||||
let buffSize = 0;
|
||||
let buff: BufferSource | null = null;
|
||||
@@ -352,7 +340,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
|| this._type === CommandBufferType.SECONDARY) {
|
||||
const gpuTexture = (texture as WebGLTexture).gpuTexture;
|
||||
if (gpuTexture) {
|
||||
const cmd = this._webGLAllocator!.copyBufferToTextureCmdPool.alloc(WebGLCmdCopyBufferToTexture);
|
||||
const cmd = this._cmdAllocator.copyBufferToTextureCmdPool.alloc(WebGLCmdCopyBufferToTexture);
|
||||
if (cmd) {
|
||||
cmd.gpuTexture = gpuTexture;
|
||||
cmd.regions = regions;
|
||||
@@ -411,15 +399,10 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
public pipelineBarrier (globalBarrier: GlobalBarrier, textureBarriers: TextureBarrier[]) {
|
||||
}
|
||||
|
||||
public get webGLDevice (): WebGLDevice {
|
||||
return this._device as WebGLDevice;
|
||||
}
|
||||
public pipelineBarrier (globalBarrier: GlobalBarrier | null, textureBarriers?: TextureBarrier[], textures?: Texture[]) {}
|
||||
|
||||
protected bindStates () {
|
||||
const bindStatesCmd = this._webGLAllocator!.bindStatesCmdPool.alloc(WebGLCmdBindStates);
|
||||
const bindStatesCmd = this._cmdAllocator.bindStatesCmdPool.alloc(WebGLCmdBindStates);
|
||||
|
||||
if (bindStatesCmd) {
|
||||
bindStatesCmd.gpuPipelineState = this._curGPUPipelineState;
|
||||
|
||||
@@ -95,12 +95,8 @@ export function GFXFormatToWebGLType (format: Format, gl: WebGLRenderingContext)
|
||||
case Format.RGB10A2UI: return gl.UNSIGNED_INT;
|
||||
case Format.RGB9E5: return gl.UNSIGNED_BYTE;
|
||||
|
||||
case Format.D16: return gl.UNSIGNED_SHORT;
|
||||
case Format.D16S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; // not supported, fallback
|
||||
case Format.D24: return gl.UNSIGNED_INT;
|
||||
case Format.D24S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL;
|
||||
case Format.D32F: return gl.UNSIGNED_INT; // not supported, fallback
|
||||
case Format.D32F_S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; // not supported, fallback
|
||||
case Format.DEPTH: return gl.UNSIGNED_INT;
|
||||
case Format.DEPTH_STENCIL: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; // not supported, fallback
|
||||
|
||||
case Format.BC1: return gl.UNSIGNED_BYTE;
|
||||
case Format.BC1_SRGB: return gl.UNSIGNED_BYTE;
|
||||
@@ -178,12 +174,8 @@ export function GFXFormatToWebGLInternalFormat (format: Format, gl: WebGLRenderi
|
||||
case Format.RGBA16F: return WebGLEXT.RGBA16F_EXT;
|
||||
case Format.RGBA32F: return WebGLEXT.RGBA32F_EXT;
|
||||
case Format.SRGB8_A8: return WebGLEXT.SRGB8_ALPHA8_EXT;
|
||||
case Format.D16: return gl.DEPTH_COMPONENT16;
|
||||
case Format.D16S8: return gl.DEPTH_STENCIL;
|
||||
case Format.D24: return gl.DEPTH_COMPONENT16;
|
||||
case Format.D24S8: return gl.DEPTH_STENCIL;
|
||||
case Format.D32F: return gl.DEPTH_COMPONENT16;
|
||||
case Format.D32F_S8: return gl.DEPTH_STENCIL;
|
||||
case Format.DEPTH: return gl.DEPTH_COMPONENT16;
|
||||
case Format.DEPTH_STENCIL: return gl.DEPTH_STENCIL;
|
||||
|
||||
default: {
|
||||
console.error('Unsupported Format, convert to WebGL internal format failed.');
|
||||
@@ -208,12 +200,8 @@ export function GFXFormatToWebGLFormat (format: Format, gl: WebGLRenderingContex
|
||||
case Format.R5G6B5: return gl.RGB;
|
||||
case Format.RGB5A1: return gl.RGBA;
|
||||
case Format.RGBA4: return gl.RGBA;
|
||||
case Format.D16: return gl.DEPTH_COMPONENT;
|
||||
case Format.D16S8: return gl.DEPTH_STENCIL;
|
||||
case Format.D24: return gl.DEPTH_COMPONENT;
|
||||
case Format.D24S8: return gl.DEPTH_STENCIL;
|
||||
case Format.D32F: return gl.DEPTH_COMPONENT;
|
||||
case Format.D32F_S8: return gl.DEPTH_STENCIL;
|
||||
case Format.DEPTH: return gl.DEPTH_COMPONENT;
|
||||
case Format.DEPTH_STENCIL: return gl.DEPTH_STENCIL;
|
||||
|
||||
case Format.BC1: return WebGLEXT.COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_ALPHA: return WebGLEXT.COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
@@ -596,9 +584,9 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
if (glBuffer) {
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
device.extensions.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
}
|
||||
@@ -620,9 +608,9 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
if (glBuffer) {
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
device.extensions.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
}
|
||||
@@ -638,7 +626,6 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
}
|
||||
}
|
||||
} else if (gpuBuffer.usage & BufferUsageBit.UNIFORM) {
|
||||
// console.error("WebGL 1.0 doesn't support uniform buffer.");
|
||||
gpuBuffer.glTarget = gl.NONE;
|
||||
|
||||
if (gpuBuffer.buffer) {
|
||||
@@ -669,9 +656,9 @@ export function WebGLCmdFuncResizeBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
const glUsage: GLenum = gpuBuffer.memUsage & MemoryUsageBit.HOST ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
|
||||
|
||||
if (gpuBuffer.usage & BufferUsageBit.VERTEX) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
device.extensions.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
}
|
||||
@@ -688,9 +675,9 @@ export function WebGLCmdFuncResizeBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
||||
device.stateCache.glArrayBuffer = null;
|
||||
} else if (gpuBuffer.usage & BufferUsageBit.INDEX) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
device.extensions.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
}
|
||||
@@ -707,7 +694,6 @@ export function WebGLCmdFuncResizeBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
||||
device.stateCache.glElementArrayBuffer = null;
|
||||
} else if (gpuBuffer.usage & BufferUsageBit.UNIFORM) {
|
||||
// console.error("WebGL 1.0 doesn't support uniform buffer.");
|
||||
if (gpuBuffer.buffer) {
|
||||
gpuBuffer.vf32 = new Float32Array(gpuBuffer.buffer.buffer);
|
||||
}
|
||||
@@ -729,8 +715,11 @@ export function WebGLCmdFuncUpdateBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
gpuBuffer.vf32!.set(new Float32Array(buffer as ArrayBuffer), offset / Float32Array.BYTES_PER_ELEMENT);
|
||||
}
|
||||
} else if (gpuBuffer.usage & BufferUsageBit.INDIRECT) {
|
||||
gpuBuffer.indirects.length = offset;
|
||||
Array.prototype.push.apply(gpuBuffer.indirects, (buffer as IndirectBuffer).drawInfos);
|
||||
gpuBuffer.indirects.clearDraws();
|
||||
const drawInfos = (buffer as IndirectBuffer).drawInfos;
|
||||
for (let i = 0; i < drawInfos.length; ++i) {
|
||||
gpuBuffer.indirects.setDrawInfo(offset + i, drawInfos[i]);
|
||||
}
|
||||
} else {
|
||||
const buff = buffer as ArrayBuffer;
|
||||
const { gl } = device;
|
||||
@@ -738,9 +727,9 @@ export function WebGLCmdFuncUpdateBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
|
||||
switch (gpuBuffer.glTarget) {
|
||||
case gl.ARRAY_BUFFER: {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
device.extensions.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
}
|
||||
@@ -752,9 +741,9 @@ export function WebGLCmdFuncUpdateBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
break;
|
||||
}
|
||||
case gl.ELEMENT_ARRAY_BUFFER: {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
device.extensions.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
}
|
||||
@@ -791,13 +780,14 @@ export function WebGLCmdFuncCreateTexture (device: WebGLDevice, gpuTexture: IWeb
|
||||
switch (gpuTexture.type) {
|
||||
case TextureType.TEX2D: {
|
||||
gpuTexture.glTarget = gl.TEXTURE_2D;
|
||||
if (gpuTexture.isSwapchainTexture) break;
|
||||
|
||||
const maxSize = Math.max(w, h);
|
||||
if (maxSize > device.capabilities.maxTextureSize) {
|
||||
errorID(9100, maxSize, device.capabilities.maxTextureSize);
|
||||
}
|
||||
|
||||
if (!device.WEBGL_depth_texture && FormatInfos[gpuTexture.format].hasDepth) {
|
||||
if (!device.extensions.WEBGL_depth_texture && FormatInfos[gpuTexture.format].hasDepth) {
|
||||
gpuTexture.glInternalFmt = GFXFormatToWebGLInternalFormat(gpuTexture.format, gl);
|
||||
const glRenderbuffer = gl.createRenderbuffer();
|
||||
if (glRenderbuffer && gpuTexture.size > 0) {
|
||||
@@ -1046,7 +1036,12 @@ export function WebGLCmdFuncResizeTexture (device: WebGLDevice, gpuTexture: IWeb
|
||||
}
|
||||
|
||||
export function WebGLCmdFuncCreateFramebuffer (device: WebGLDevice, gpuFramebuffer: IWebGLGPUFramebuffer) {
|
||||
if (!gpuFramebuffer.gpuColorTextures.length && !gpuFramebuffer.gpuDepthStencilTexture) { return; } // onscreen fbo
|
||||
let isOnscreen = false;
|
||||
for (let i = 0; i < gpuFramebuffer.gpuColorTextures.length; ++i) {
|
||||
if (!gpuFramebuffer.gpuColorTextures[i].glTexture) isOnscreen = true;
|
||||
}
|
||||
if (gpuFramebuffer.gpuDepthStencilTexture && !gpuFramebuffer.gpuDepthStencilTexture.glTexture) isOnscreen = true;
|
||||
if (isOnscreen) return;
|
||||
|
||||
const { gl } = device;
|
||||
const attachments: GLenum[] = [];
|
||||
@@ -1104,8 +1099,8 @@ export function WebGLCmdFuncCreateFramebuffer (device: WebGLDevice, gpuFramebuff
|
||||
}
|
||||
}
|
||||
|
||||
if (device.WEBGL_draw_buffers) {
|
||||
device.WEBGL_draw_buffers.drawBuffersWEBGL(attachments);
|
||||
if (device.extensions.WEBGL_draw_buffers) {
|
||||
device.extensions.WEBGL_draw_buffers.drawBuffersWEBGL(attachments);
|
||||
}
|
||||
|
||||
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
||||
@@ -1210,7 +1205,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
gl.linkProgram(gpuShader.glProgram);
|
||||
|
||||
// detach & delete immediately
|
||||
if (device.destroyShadersImmediately) {
|
||||
if (device.extensions.destroyShadersImmediately) {
|
||||
for (let k = 0; k < gpuShader.gpuStages.length; k++) {
|
||||
const gpuStage = gpuShader.gpuStages[k];
|
||||
if (gpuStage.glShader) {
|
||||
@@ -1333,8 +1328,8 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
|
||||
if (!isSampler) {
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, uniformInfo.name);
|
||||
// Note: getUniformLocation return Object on wechat platform.
|
||||
if (glLoc !== null && (typeof glLoc === 'number' || (glLoc as any).id !== -1)) {
|
||||
// Note: wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
let varName: string;
|
||||
const nameOffset = uniformInfo.name.indexOf('[');
|
||||
if (nameOffset !== -1) {
|
||||
@@ -1394,8 +1389,8 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
// Note: getUniformLocation return Object on wechat platform.
|
||||
if (glLoc !== null && (typeof glLoc === 'number' || (glLoc as any).id !== -1)) {
|
||||
// Note: wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
}
|
||||
@@ -1476,7 +1471,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
export function WebGLCmdFuncDestroyShader (device: WebGLDevice, gpuShader: IWebGLGPUShader) {
|
||||
if (gpuShader.glProgram) {
|
||||
const { gl } = device;
|
||||
if (!device.destroyShadersImmediately) {
|
||||
if (!device.extensions.destroyShadersImmediately) {
|
||||
for (let k = 0; k < gpuShader.gpuStages.length; k++) {
|
||||
const gpuStage = gpuShader.gpuStages[k];
|
||||
if (gpuStage.glShader) {
|
||||
@@ -1529,7 +1524,7 @@ export function WebGLCmdFuncDestroyInputAssembler (device: WebGLDevice, gpuInput
|
||||
const it = gpuInputAssembler.glVAOs.values();
|
||||
let res = it.next();
|
||||
while (!res.done) {
|
||||
device.OES_vertex_array_object!.deleteVertexArrayOES(res.value);
|
||||
device.extensions.OES_vertex_array_object!.deleteVertexArrayOES(res.value);
|
||||
res = it.next();
|
||||
}
|
||||
gpuInputAssembler.glVAOs.clear();
|
||||
@@ -1592,7 +1587,7 @@ export function WebGLCmdFuncBeginRenderPass (
|
||||
// const invalidateAttachments: GLenum[] = [];
|
||||
let clearCount = clearColors.length;
|
||||
|
||||
if (!device.WEBGL_draw_buffers) {
|
||||
if (!device.extensions.WEBGL_draw_buffers) {
|
||||
clearCount = 1;
|
||||
}
|
||||
|
||||
@@ -2182,7 +2177,7 @@ export function WebGLCmdFuncBindStates (
|
||||
if (gpuTexture.glTexture) {
|
||||
gl.bindTexture(gpuTexture.glTarget, gpuTexture.glTexture);
|
||||
} else {
|
||||
gl.bindTexture(gpuTexture.glTarget, device.nullTex2D!.gpuTexture.glTexture);
|
||||
gl.bindTexture(gpuTexture.glTarget, device.nullTex2D.gpuTexture.glTexture);
|
||||
}
|
||||
glTexUnit.glTexture = gpuTexture.glTexture;
|
||||
}
|
||||
@@ -2258,10 +2253,10 @@ export function WebGLCmdFuncBindStates (
|
||||
if (gpuInputAssembler && gpuShader
|
||||
&& (isShaderChanged || gfxStateCache.gpuInputAssembler !== gpuInputAssembler)) {
|
||||
gfxStateCache.gpuInputAssembler = gpuInputAssembler;
|
||||
const ia = device.ANGLE_instanced_arrays;
|
||||
const ia = device.extensions.ANGLE_instanced_arrays;
|
||||
|
||||
if (device.useVAO) {
|
||||
const vao = device.OES_vertex_array_object!;
|
||||
if (device.extensions.useVAO) {
|
||||
const vao = device.extensions.OES_vertex_array_object!;
|
||||
|
||||
// check vao
|
||||
let glVAO = gpuInputAssembler.glVAOs.get(gpuShader.glProgram!);
|
||||
@@ -2482,56 +2477,83 @@ export function WebGLCmdFuncBindStates (
|
||||
} // update dynamic states
|
||||
}
|
||||
|
||||
export function WebGLCmdFuncDraw (device: WebGLDevice, drawInfo: DrawInfo) {
|
||||
export function WebGLCmdFuncDraw (device: WebGLDevice, drawInfo: Readonly<DrawInfo>) {
|
||||
const { gl } = device;
|
||||
const ia = device.ANGLE_instanced_arrays;
|
||||
const { ANGLE_instanced_arrays: ia, WEBGL_multi_draw: md } = device.extensions;
|
||||
const { gpuInputAssembler, glPrimitive } = gfxStateCache;
|
||||
|
||||
if (gpuInputAssembler) {
|
||||
const indexBuffer = gpuInputAssembler.gpuIndexBuffer;
|
||||
if (gpuInputAssembler.gpuIndirectBuffer) {
|
||||
const diLen = gpuInputAssembler.gpuIndirectBuffer.indirects.length;
|
||||
for (let j = 0; j < diLen; j++) {
|
||||
const subDrawInfo = gpuInputAssembler.gpuIndirectBuffer.indirects[j];
|
||||
const gpuBuffer = gpuInputAssembler.gpuIndexBuffer;
|
||||
if (subDrawInfo.instanceCount && ia) {
|
||||
if (gpuBuffer) {
|
||||
if (subDrawInfo.indexCount > 0) {
|
||||
const offset = subDrawInfo.firstIndex * gpuBuffer.stride;
|
||||
ia.drawElementsInstancedANGLE(glPrimitive, subDrawInfo.indexCount,
|
||||
gpuInputAssembler.glIndexType, offset, subDrawInfo.instanceCount);
|
||||
const indirects = gpuInputAssembler.gpuIndirectBuffer.indirects;
|
||||
if (indirects.drawByIndex) {
|
||||
for (let j = 0; j < indirects.drawCount; j++) {
|
||||
indirects.byteOffsets[j] = indirects.offsets[j] * indexBuffer!.stride;
|
||||
}
|
||||
if (md) {
|
||||
if (indirects.instancedDraw) {
|
||||
md.multiDrawElementsInstancedWEBGL(glPrimitive,
|
||||
indirects.counts, 0,
|
||||
gpuInputAssembler.glIndexType,
|
||||
indirects.byteOffsets, 0,
|
||||
indirects.instances, 0,
|
||||
indirects.drawCount);
|
||||
} else {
|
||||
md.multiDrawElementsWEBGL(glPrimitive,
|
||||
indirects.counts, 0,
|
||||
gpuInputAssembler.glIndexType,
|
||||
indirects.byteOffsets, 0,
|
||||
indirects.drawCount);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < indirects.drawCount; j++) {
|
||||
if (indirects.instances[j] > 1 && ia) {
|
||||
ia.drawElementsInstancedANGLE(glPrimitive, indirects.counts[j],
|
||||
gpuInputAssembler.glIndexType, indirects.byteOffsets[j], indirects.instances[j]);
|
||||
} else {
|
||||
gl.drawElements(glPrimitive, indirects.counts[j], gpuInputAssembler.glIndexType, indirects.byteOffsets[j]);
|
||||
}
|
||||
} else if (subDrawInfo.vertexCount > 0) {
|
||||
ia.drawArraysInstancedANGLE(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount, subDrawInfo.instanceCount);
|
||||
}
|
||||
} else if (gpuBuffer) {
|
||||
if (subDrawInfo.indexCount > 0) {
|
||||
const offset = subDrawInfo.firstIndex * gpuBuffer.stride;
|
||||
gl.drawElements(glPrimitive, subDrawInfo.indexCount, gpuInputAssembler.glIndexType, offset);
|
||||
}
|
||||
} else if (md) {
|
||||
if (indirects.instancedDraw) {
|
||||
md.multiDrawArraysInstancedWEBGL(glPrimitive,
|
||||
indirects.offsets, 0,
|
||||
indirects.counts, 0,
|
||||
indirects.instances, 0,
|
||||
indirects.drawCount);
|
||||
} else {
|
||||
md.multiDrawArraysWEBGL(glPrimitive,
|
||||
indirects.offsets, 0,
|
||||
indirects.counts, 0,
|
||||
indirects.drawCount);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < indirects.drawCount; j++) {
|
||||
if (indirects.instances[j] > 1 && ia) {
|
||||
ia.drawArraysInstancedANGLE(glPrimitive, indirects.offsets[j], indirects.counts[j], indirects.instances[j]);
|
||||
} else {
|
||||
gl.drawArrays(glPrimitive, indirects.offsets[j], indirects.counts[j]);
|
||||
}
|
||||
} else if (subDrawInfo.vertexCount > 0) {
|
||||
gl.drawArrays(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const gpuBuffer = gpuInputAssembler.gpuIndexBuffer;
|
||||
if (drawInfo.instanceCount && ia) {
|
||||
if (gpuBuffer) {
|
||||
if (drawInfo.indexCount > 0) {
|
||||
const offset = drawInfo.firstIndex * gpuBuffer.stride;
|
||||
ia.drawElementsInstancedANGLE(glPrimitive, drawInfo.indexCount,
|
||||
gpuInputAssembler.glIndexType, offset, drawInfo.instanceCount);
|
||||
}
|
||||
} else if (drawInfo.vertexCount > 0) {
|
||||
ia.drawArraysInstancedANGLE(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount, drawInfo.instanceCount);
|
||||
}
|
||||
} else if (gpuBuffer) {
|
||||
} else if (drawInfo.instanceCount > 1 && ia) {
|
||||
if (indexBuffer) {
|
||||
if (drawInfo.indexCount > 0) {
|
||||
const offset = drawInfo.firstIndex * gpuBuffer.stride;
|
||||
gl.drawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler.glIndexType, offset);
|
||||
const offset = drawInfo.firstIndex * indexBuffer.stride;
|
||||
ia.drawElementsInstancedANGLE(glPrimitive, drawInfo.indexCount,
|
||||
gpuInputAssembler.glIndexType, offset, drawInfo.instanceCount);
|
||||
}
|
||||
} else if (drawInfo.vertexCount > 0) {
|
||||
gl.drawArrays(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount);
|
||||
ia.drawArraysInstancedANGLE(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount, drawInfo.instanceCount);
|
||||
}
|
||||
} else if (indexBuffer) {
|
||||
if (drawInfo.indexCount > 0) {
|
||||
const offset = drawInfo.firstIndex * indexBuffer.stride;
|
||||
gl.drawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler.glIndexType, offset);
|
||||
}
|
||||
} else if (drawInfo.vertexCount > 0) {
|
||||
gl.drawArrays(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2668,7 +2690,7 @@ export function WebGLCmdFuncCopyBuffersToTexture (
|
||||
gl.texSubImage2D(gl.TEXTURE_2D, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y, w, h,
|
||||
gpuTexture.glFormat, gpuTexture.glType, pixels);
|
||||
} else if (gpuTexture.glInternalFmt === WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL || device.noCompressedTexSubImage2D) {
|
||||
} else if (gpuTexture.glInternalFmt === WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL || device.extensions.noCompressedTexSubImage2D) {
|
||||
gl.compressedTexImage2D(gl.TEXTURE_2D, region.texSubres.mipLevel,
|
||||
gpuTexture.glInternalFmt, w, h, 0, pixels);
|
||||
} else {
|
||||
@@ -2694,7 +2716,7 @@ export function WebGLCmdFuncCopyBuffersToTexture (
|
||||
gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y, w, h,
|
||||
gpuTexture.glFormat, gpuTexture.glType, pixels);
|
||||
} else if (gpuTexture.glInternalFmt === WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL || device.noCompressedTexSubImage2D) {
|
||||
} else if (gpuTexture.glInternalFmt === WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL || device.extensions.noCompressedTexSubImage2D) {
|
||||
gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, region.texSubres.mipLevel,
|
||||
gpuTexture.glInternalFmt, w, h, 0, pixels);
|
||||
} else {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
|
||||
// Extensions
|
||||
export enum WebGLEXT {
|
||||
RGBA16F_EXT = 0x881A,
|
||||
@@ -95,3 +97,47 @@ export enum WebGLEXT {
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD,
|
||||
}
|
||||
|
||||
export interface IWebGLExtensions {
|
||||
EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null;
|
||||
EXT_blend_minmax: EXT_blend_minmax | null;
|
||||
EXT_frag_depth: EXT_frag_depth | null;
|
||||
EXT_shader_texture_lod: EXT_shader_texture_lod | null;
|
||||
EXT_sRGB: EXT_sRGB | null;
|
||||
OES_vertex_array_object: OES_vertex_array_object | null;
|
||||
EXT_color_buffer_half_float: EXT_color_buffer_half_float | null;
|
||||
WEBGL_multi_draw: WEBGL_multi_draw | null;
|
||||
WEBGL_color_buffer_float: WEBGL_color_buffer_float | null;
|
||||
WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null;
|
||||
WEBGL_compressed_texture_etc: WEBGL_compressed_texture_etc | null;
|
||||
WEBGL_compressed_texture_pvrtc: WEBGL_compressed_texture_pvrtc | null;
|
||||
WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc | null;
|
||||
WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null;
|
||||
WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null;
|
||||
WEBGL_debug_shaders: WEBGL_debug_shaders | null;
|
||||
WEBGL_draw_buffers: WEBGL_draw_buffers | null;
|
||||
WEBGL_lose_context: WEBGL_lose_context | null;
|
||||
WEBGL_depth_texture: WEBGL_depth_texture | null;
|
||||
WEBGL_debug_renderer_info: WEBGL_debug_renderer_info | null;
|
||||
OES_texture_half_float: OES_texture_half_float | null;
|
||||
OES_texture_half_float_linear: OES_texture_half_float_linear | null;
|
||||
OES_texture_float: OES_texture_float | null;
|
||||
OES_texture_float_linear: OES_texture_float_linear | null;
|
||||
OES_standard_derivatives: OES_standard_derivatives | null;
|
||||
OES_element_index_uint: OES_element_index_uint | null;
|
||||
ANGLE_instanced_arrays: ANGLE_instanced_arrays | null;
|
||||
destroyShadersImmediately: boolean;
|
||||
noCompressedTexSubImage2D: boolean;
|
||||
useVAO: boolean;
|
||||
}
|
||||
|
||||
// put the global instance here so that we won't have circular dependencies
|
||||
export class WebGLDeviceManager {
|
||||
static get instance () {
|
||||
return WebGLDeviceManager._instance!;
|
||||
}
|
||||
static setInstance (instance: WebGLDevice) {
|
||||
WebGLDeviceManager._instance = instance;
|
||||
}
|
||||
private static _instance: WebGLDevice | null = null;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,6 @@ export class WebGLDescriptorSetLayout extends DescriptorSetLayout {
|
||||
descriptorIndices,
|
||||
descriptorCount,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { WebGLBuffer } from './webgl-buffer';
|
||||
import { IWebGLGPUDescriptorSet, IWebGLGPUDescriptor } from './webgl-gpu-objects';
|
||||
import { WebGLSampler } from './webgl-sampler';
|
||||
import { WebGLSampler } from './states/webgl-sampler';
|
||||
import { WebGLTexture } from './webgl-texture';
|
||||
import { WebGLDescriptorSetLayout } from './webgl-descriptor-set-layout';
|
||||
import { DescriptorSetInfo, DESCRIPTOR_SAMPLER_TYPE, DESCRIPTOR_BUFFER_TYPE } from '../base/define';
|
||||
@@ -38,7 +38,7 @@ export class WebGLDescriptorSet extends DescriptorSet {
|
||||
|
||||
private _gpuDescriptorSet: IWebGLGPUDescriptorSet | null = null;
|
||||
|
||||
public initialize (info: DescriptorSetInfo): boolean {
|
||||
public initialize (info: DescriptorSetInfo) {
|
||||
this._layout = info.layout;
|
||||
const { bindings, descriptorIndices, descriptorCount } = (info.layout as WebGLDescriptorSetLayout).gpuDescriptorSetLayout;
|
||||
|
||||
@@ -60,8 +60,6 @@ export class WebGLDescriptorSet extends DescriptorSet {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { ALIPAY, RUNTIME_BASED, BYTEDANCE, WECHAT, LINKSURE, QTT, COCOSPLAY, HUAWEI } from 'internal:constants';
|
||||
import { macro, warnID, warn } from '../../platform';
|
||||
import { sys } from '../../platform/sys';
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { DescriptorSetLayout } from '../base/descriptor-set-layout';
|
||||
import { PipelineLayout } from '../base/pipeline-layout';
|
||||
@@ -37,12 +34,11 @@ import { InputAssembler } from '../base/input-assembler';
|
||||
import { PipelineState, PipelineStateInfo } from '../base/pipeline-state';
|
||||
import { Queue } from '../base/queue';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { Sampler } from '../base/sampler';
|
||||
import { Sampler } from '../base/states/sampler';
|
||||
import { Shader } from '../base/shader';
|
||||
import { Texture } from '../base/texture';
|
||||
import { WebGLDescriptorSet } from './webgl-descriptor-set';
|
||||
import { WebGLBuffer } from './webgl-buffer';
|
||||
import { WebGLCommandAllocator } from './webgl-command-allocator';
|
||||
import { WebGLCommandBuffer } from './webgl-command-buffer';
|
||||
import { WebGLFramebuffer } from './webgl-framebuffer';
|
||||
import { WebGLInputAssembler } from './webgl-input-assembler';
|
||||
@@ -52,251 +48,71 @@ import { WebGLPipelineState } from './webgl-pipeline-state';
|
||||
import { WebGLPrimaryCommandBuffer } from './webgl-primary-command-buffer';
|
||||
import { WebGLQueue } from './webgl-queue';
|
||||
import { WebGLRenderPass } from './webgl-render-pass';
|
||||
import { WebGLSampler } from './webgl-sampler';
|
||||
import { WebGLSampler } from './states/webgl-sampler';
|
||||
import { WebGLShader } from './webgl-shader';
|
||||
import { WebGLStateCache } from './webgl-state-cache';
|
||||
import { getExtensions, WebGLSwapchain } from './webgl-swapchain';
|
||||
import { WebGLTexture } from './webgl-texture';
|
||||
import {
|
||||
getTypedArrayConstructor, CommandBufferType, Filter, Format, FormatInfos, BindingMappingInfo, ShaderInfo,
|
||||
CommandBufferType, ShaderInfo,
|
||||
QueueInfo, CommandBufferInfo, DescriptorSetInfo, DescriptorSetLayoutInfo, FramebufferInfo, InputAssemblerInfo, PipelineLayoutInfo,
|
||||
RenderPassInfo, SamplerInfo, TextureInfo, TextureViewInfo, BufferInfo, BufferViewInfo, DeviceInfo, TextureBarrierInfo, GlobalBarrierInfo,
|
||||
QueueType, TextureFlagBit, TextureType, TextureUsageBit, API, Feature, BufferTextureCopy, Rect,
|
||||
QueueType, API, Feature, BufferTextureCopy, SwapchainInfo,
|
||||
} from '../base/define';
|
||||
import {
|
||||
GFXFormatToWebGLFormat, GFXFormatToWebGLType, WebGLCmdFuncCopyBuffersToTexture, WebGLCmdFuncCopyTextureToBuffers,
|
||||
WebGLCmdFuncCopyTexImagesToTexture,
|
||||
} from './webgl-commands';
|
||||
import { GlobalBarrier } from '../base/global-barrier';
|
||||
import { TextureBarrier } from '../base/texture-barrier';
|
||||
import { BrowserType, OS } from '../../../../pal/system-info/enum-type';
|
||||
import { WebGLCmdFuncCopyBuffersToTexture, WebGLCmdFuncCopyTextureToBuffers, WebGLCmdFuncCopyTexImagesToTexture } from './webgl-commands';
|
||||
import { GlobalBarrier } from '../base/states/global-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { debug } from '../../platform/debug';
|
||||
|
||||
const eventWebGLContextLost = 'webglcontextlost';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
|
||||
export class WebGLDevice extends Device {
|
||||
get gl () {
|
||||
return this._webGLRC as WebGLRenderingContext;
|
||||
return this._swapchain!.gl;
|
||||
}
|
||||
|
||||
get webGLQueue () {
|
||||
return this._queue as WebGLQueue;
|
||||
get extensions () {
|
||||
return this._swapchain!.extensions;
|
||||
}
|
||||
|
||||
get isAntialias () {
|
||||
return this._isAntialias;
|
||||
get stateCache () {
|
||||
return this._swapchain!.stateCache;
|
||||
}
|
||||
|
||||
get isPremultipliedAlpha () {
|
||||
return this._isPremultipliedAlpha;
|
||||
get nullTex2D () {
|
||||
return this._swapchain!.nullTex2D;
|
||||
}
|
||||
|
||||
get useVAO () {
|
||||
return this._useVAO;
|
||||
get nullTexCube () {
|
||||
return this._swapchain!.nullTexCube;
|
||||
}
|
||||
|
||||
get destroyShadersImmediately () {
|
||||
return this._destroyShadersImmediately;
|
||||
}
|
||||
|
||||
get noCompressedTexSubImage2D () {
|
||||
return this._noCompressedTexSubImage2D;
|
||||
}
|
||||
|
||||
get bindingMappingInfo () {
|
||||
return this._bindingMappingInfo;
|
||||
}
|
||||
|
||||
get EXT_texture_filter_anisotropic () {
|
||||
return this._EXT_texture_filter_anisotropic;
|
||||
}
|
||||
|
||||
get EXT_blend_minmax () {
|
||||
return this._EXT_blend_minmax;
|
||||
}
|
||||
|
||||
get EXT_frag_depth () {
|
||||
return this._EXT_frag_depth;
|
||||
}
|
||||
|
||||
get EXT_shader_texture_lod () {
|
||||
return this._EXT_shader_texture_lod;
|
||||
}
|
||||
|
||||
get EXT_sRGB () {
|
||||
return this._EXT_sRGB;
|
||||
}
|
||||
|
||||
get OES_vertex_array_object () {
|
||||
return this._OES_vertex_array_object;
|
||||
}
|
||||
|
||||
get WEBGL_color_buffer_float () {
|
||||
return this._WEBGL_color_buffer_float;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_etc1 () {
|
||||
return this._WEBGL_compressed_texture_etc1;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_pvrtc () {
|
||||
return this._WEBGL_compressed_texture_pvrtc;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_astc () {
|
||||
return this._WEBGL_compressed_texture_astc;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_s3tc () {
|
||||
return this._WEBGL_compressed_texture_s3tc;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_s3tc_srgb () {
|
||||
return this._WEBGL_compressed_texture_s3tc_srgb;
|
||||
}
|
||||
|
||||
get WEBGL_debug_shaders () {
|
||||
return this._WEBGL_debug_shaders;
|
||||
}
|
||||
|
||||
get WEBGL_draw_buffers () {
|
||||
return this._WEBGL_draw_buffers;
|
||||
}
|
||||
|
||||
get WEBGL_lose_context () {
|
||||
return this._WEBGL_lose_context;
|
||||
}
|
||||
|
||||
get WEBGL_depth_texture () {
|
||||
return this._WEBGL_depth_texture;
|
||||
}
|
||||
|
||||
get WEBGL_debug_renderer_info () {
|
||||
return this._WEBGL_debug_renderer_info;
|
||||
}
|
||||
|
||||
get OES_texture_half_float () {
|
||||
return this._OES_texture_half_float;
|
||||
}
|
||||
|
||||
get OES_texture_half_float_linear () {
|
||||
return this._OES_texture_half_float_linear;
|
||||
}
|
||||
|
||||
get OES_texture_float () {
|
||||
return this._OES_texture_float;
|
||||
}
|
||||
|
||||
get OES_standard_derivatives () {
|
||||
return this._OES_standard_derivatives;
|
||||
}
|
||||
|
||||
get OES_element_index_uint () {
|
||||
return this._OES_element_index_uint;
|
||||
}
|
||||
|
||||
get ANGLE_instanced_arrays () {
|
||||
return this._ANGLE_instanced_arrays;
|
||||
}
|
||||
|
||||
public stateCache: WebGLStateCache = new WebGLStateCache();
|
||||
public cmdAllocator: WebGLCommandAllocator = new WebGLCommandAllocator();
|
||||
public nullTex2D: WebGLTexture | null = null;
|
||||
public nullTexCube: WebGLTexture | null = null;
|
||||
|
||||
private _webGLRC: WebGLRenderingContext | null = null;
|
||||
private _isAntialias = true;
|
||||
private _isPremultipliedAlpha = true;
|
||||
private _useVAO = false;
|
||||
private _destroyShadersImmediately = true;
|
||||
private _noCompressedTexSubImage2D = false;
|
||||
private _bindingMappingInfo: BindingMappingInfo = new BindingMappingInfo();
|
||||
private _webGLContextLostHandler: null | ((event: Event) => void) = null;
|
||||
|
||||
private _extensions: string[] | null = null;
|
||||
private _EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null = null;
|
||||
private _EXT_blend_minmax: EXT_blend_minmax | null = null;
|
||||
private _EXT_frag_depth: EXT_frag_depth | null = null;
|
||||
private _EXT_shader_texture_lod: EXT_shader_texture_lod | null = null;
|
||||
private _EXT_sRGB: EXT_sRGB | null = null;
|
||||
private _OES_vertex_array_object: OES_vertex_array_object | null = null;
|
||||
private _EXT_color_buffer_half_float: EXT_color_buffer_half_float | null = null;
|
||||
private _WEBGL_color_buffer_float: WEBGL_color_buffer_float | null = null;
|
||||
private _WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null = null;
|
||||
private _WEBGL_compressed_texture_etc: WEBGL_compressed_texture_etc | null = null;
|
||||
private _WEBGL_compressed_texture_pvrtc: WEBGL_compressed_texture_pvrtc | null = null;
|
||||
private _WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc | null = null;
|
||||
private _WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null = null;
|
||||
private _WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null = null;
|
||||
private _WEBGL_debug_shaders: WEBGL_debug_shaders | null = null;
|
||||
private _WEBGL_draw_buffers: WEBGL_draw_buffers | null = null;
|
||||
private _WEBGL_lose_context: WEBGL_lose_context | null = null;
|
||||
private _WEBGL_depth_texture: WEBGL_depth_texture | null = null;
|
||||
private _WEBGL_debug_renderer_info: WEBGL_debug_renderer_info | null = null;
|
||||
private _OES_texture_half_float: OES_texture_half_float | null = null;
|
||||
private _OES_texture_half_float_linear: OES_texture_half_float_linear | null = null;
|
||||
private _OES_texture_float: OES_texture_float | null = null;
|
||||
private _OES_texture_float_linear: OES_texture_float_linear | null = null;
|
||||
private _OES_standard_derivatives: OES_standard_derivatives | null = null;
|
||||
private _OES_element_index_uint: OES_element_index_uint | null = null;
|
||||
private _ANGLE_instanced_arrays: ANGLE_instanced_arrays | null = null;
|
||||
private _swapchain: WebGLSwapchain | null = null;
|
||||
|
||||
public initialize (info: DeviceInfo): boolean {
|
||||
this._canvas = info.canvasElm as HTMLCanvasElement;
|
||||
this._isAntialias = info.isAntialias;
|
||||
this._isPremultipliedAlpha = info.isPremultipliedAlpha;
|
||||
WebGLDeviceManager.setInstance(this);
|
||||
this._gfxAPI = API.WEBGL;
|
||||
|
||||
this._bindingMappingInfo = info.bindingMappingInfo;
|
||||
if (!this._bindingMappingInfo.bufferOffsets.length) this._bindingMappingInfo.bufferOffsets.push(0);
|
||||
if (!this._bindingMappingInfo.samplerOffsets.length) this._bindingMappingInfo.samplerOffsets.push(0);
|
||||
|
||||
let gl: WebGLRenderingContext | null = null;
|
||||
|
||||
try {
|
||||
const webGLCtxAttribs: WebGLContextAttributes = {
|
||||
alpha: macro.ENABLE_TRANSPARENT_CANVAS,
|
||||
antialias: this._isAntialias,
|
||||
depth: true,
|
||||
stencil: true,
|
||||
premultipliedAlpha: this._isPremultipliedAlpha,
|
||||
preserveDrawingBuffer: false,
|
||||
powerPreference: 'default',
|
||||
failIfMajorPerformanceCaveat: false,
|
||||
};
|
||||
|
||||
/*
|
||||
if (WECHAT) {
|
||||
webGLCtxAttribs.preserveDrawingBuffer = true;
|
||||
}
|
||||
*/
|
||||
|
||||
this._webGLRC = this._canvas.getContext('webgl', webGLCtxAttribs);
|
||||
gl = document.createElement('canvas').getContext('webgl');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this._webGLRC) {
|
||||
if (!gl) {
|
||||
console.error('This device does not support WebGL.');
|
||||
return false;
|
||||
}
|
||||
|
||||
this._webGLContextLostHandler = this._onWebGLContextLost.bind(this);
|
||||
this._canvas.addEventListener(eventWebGLContextLost, this._onWebGLContextLost);
|
||||
// create queue
|
||||
this._queue = this.createQueue(new QueueInfo(QueueType.GRAPHICS));
|
||||
this._cmdBuff = this.createCommandBuffer(new CommandBufferInfo(this._queue));
|
||||
|
||||
this._canvas2D = document.createElement('canvas');
|
||||
console.info('WebGL device initialized.');
|
||||
|
||||
this._gfxAPI = API.WEBGL;
|
||||
this._deviceName = 'WebGL';
|
||||
const gl = this._webGLRC;
|
||||
|
||||
this._WEBGL_debug_renderer_info = this.getExtension('WEBGL_debug_renderer_info');
|
||||
if (this._WEBGL_debug_renderer_info) {
|
||||
this._renderer = gl.getParameter(this._WEBGL_debug_renderer_info.UNMASKED_RENDERER_WEBGL);
|
||||
this._vendor = gl.getParameter(this._WEBGL_debug_renderer_info.UNMASKED_VENDOR_WEBGL);
|
||||
} else {
|
||||
this._renderer = gl.getParameter(gl.RENDERER);
|
||||
this._vendor = gl.getParameter(gl.VENDOR);
|
||||
}
|
||||
|
||||
this._version = gl.getParameter(gl.VERSION);
|
||||
this._caps.maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
||||
this._caps.maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
||||
this._caps.maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
|
||||
@@ -304,264 +120,113 @@ export class WebGLDevice extends Device {
|
||||
this._caps.maxVertexTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
||||
this._caps.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
||||
this._caps.maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
|
||||
this._caps.depthBits = gl.getParameter(gl.DEPTH_BITS);
|
||||
this._caps.stencilBits = gl.getParameter(gl.STENCIL_BITS);
|
||||
|
||||
this.stateCache.initialize(this._caps.maxTextureUnits, this._caps.maxVertexAttributes);
|
||||
|
||||
if (ALIPAY) {
|
||||
this._caps.depthBits = 24;
|
||||
const extensions = gl.getSupportedExtensions();
|
||||
let extStr = '';
|
||||
if (extensions) {
|
||||
for (const ext of extensions) {
|
||||
extStr += `${ext} `;
|
||||
}
|
||||
}
|
||||
|
||||
this._devicePixelRatio = info.devicePixelRatio || 1.0;
|
||||
this._width = info.width;
|
||||
this._height = info.height;
|
||||
const exts = getExtensions(gl);
|
||||
|
||||
this._colorFmt = Format.RGBA8;
|
||||
|
||||
if (this._caps.depthBits === 24) {
|
||||
if (this._caps.stencilBits === 8) {
|
||||
this._depthStencilFmt = Format.D24S8;
|
||||
} else {
|
||||
this._depthStencilFmt = Format.D24;
|
||||
}
|
||||
} else if (this._caps.stencilBits === 8) {
|
||||
this._depthStencilFmt = Format.D16S8;
|
||||
if (exts.WEBGL_debug_renderer_info) {
|
||||
this._renderer = gl.getParameter(exts.WEBGL_debug_renderer_info.UNMASKED_RENDERER_WEBGL);
|
||||
this._vendor = gl.getParameter(exts.WEBGL_debug_renderer_info.UNMASKED_VENDOR_WEBGL);
|
||||
} else {
|
||||
this._depthStencilFmt = Format.D16;
|
||||
this._renderer = gl.getParameter(gl.RENDERER);
|
||||
this._vendor = gl.getParameter(gl.VENDOR);
|
||||
}
|
||||
|
||||
this._extensions = gl.getSupportedExtensions();
|
||||
let extensions = '';
|
||||
if (this._extensions) {
|
||||
for (const ext of this._extensions) {
|
||||
extensions += `${ext} `;
|
||||
}
|
||||
|
||||
debug(`EXTENSIONS: ${extensions}`);
|
||||
}
|
||||
|
||||
this._EXT_texture_filter_anisotropic = this.getExtension('EXT_texture_filter_anisotropic');
|
||||
this._EXT_blend_minmax = this.getExtension('EXT_blend_minmax');
|
||||
this._EXT_frag_depth = this.getExtension('EXT_frag_depth');
|
||||
this._EXT_shader_texture_lod = this.getExtension('EXT_shader_texture_lod');
|
||||
this._EXT_sRGB = this.getExtension('EXT_sRGB');
|
||||
this._OES_vertex_array_object = this.getExtension('OES_vertex_array_object');
|
||||
this._EXT_color_buffer_half_float = this.getExtension('EXT_color_buffer_half_float');
|
||||
this._WEBGL_color_buffer_float = this.getExtension('WEBGL_color_buffer_float');
|
||||
this._WEBGL_compressed_texture_etc1 = this.getExtension('WEBGL_compressed_texture_etc1');
|
||||
this._WEBGL_compressed_texture_etc = this.getExtension('WEBGL_compressed_texture_etc');
|
||||
this._WEBGL_compressed_texture_pvrtc = this.getExtension('WEBGL_compressed_texture_pvrtc');
|
||||
this._WEBGL_compressed_texture_s3tc = this.getExtension('WEBGL_compressed_texture_s3tc');
|
||||
this._WEBGL_compressed_texture_s3tc_srgb = this.getExtension('WEBGL_compressed_texture_s3tc_srgb');
|
||||
this._WEBGL_debug_shaders = this.getExtension('WEBGL_debug_shaders');
|
||||
this._WEBGL_draw_buffers = this.getExtension('WEBGL_draw_buffers');
|
||||
this._WEBGL_lose_context = this.getExtension('WEBGL_lose_context');
|
||||
this._WEBGL_depth_texture = this.getExtension('WEBGL_depth_texture');
|
||||
this._OES_texture_half_float = this.getExtension('OES_texture_half_float');
|
||||
this._OES_texture_half_float_linear = this.getExtension('OES_texture_half_float_linear');
|
||||
this._OES_texture_float = this.getExtension('OES_texture_float');
|
||||
this._OES_texture_float_linear = this.getExtension('OES_texture_float_linear');
|
||||
this._OES_standard_derivatives = this.getExtension('OES_standard_derivatives');
|
||||
this._OES_element_index_uint = this.getExtension('OES_element_index_uint');
|
||||
this._ANGLE_instanced_arrays = this.getExtension('ANGLE_instanced_arrays');
|
||||
|
||||
// platform-specific hacks
|
||||
// eslint-disable-next-line no-lone-blocks
|
||||
{
|
||||
// iOS 14 browsers crash on getExtension('WEBGL_compressed_texture_astc')
|
||||
if (sys.os !== OS.IOS || sys.osMainVersion !== 14 || !sys.isBrowser) {
|
||||
this._WEBGL_compressed_texture_astc = this.getExtension('WEBGL_compressed_texture_astc');
|
||||
}
|
||||
|
||||
// UC browser instancing implementation doesn't work
|
||||
if (sys.browserType === BrowserType.UC) {
|
||||
this._ANGLE_instanced_arrays = null;
|
||||
}
|
||||
|
||||
// bytedance ios depth texture implementation doesn't work
|
||||
if (BYTEDANCE && sys.os === OS.IOS) {
|
||||
this._WEBGL_depth_texture = null;
|
||||
}
|
||||
|
||||
if (RUNTIME_BASED) {
|
||||
// VAO implementations doesn't work well on some runtime platforms
|
||||
if (LINKSURE || QTT || COCOSPLAY || HUAWEI) {
|
||||
this._OES_vertex_array_object = null;
|
||||
}
|
||||
}
|
||||
|
||||
// some earlier version of iOS and android wechat implement gl.detachShader incorrectly
|
||||
if ((sys.os === OS.IOS && sys.osMainVersion <= 10)
|
||||
|| (WECHAT && sys.os === OS.ANDROID)) {
|
||||
this._destroyShadersImmediately = false;
|
||||
}
|
||||
|
||||
// compressedTexSubImage2D has always been problematic because the parameters differs slightly from GLES
|
||||
if (WECHAT) { // and MANY platforms get it wrong
|
||||
this._noCompressedTexSubImage2D = true;
|
||||
}
|
||||
}
|
||||
const version: string = gl.getParameter(gl.VERSION);
|
||||
|
||||
this._features.fill(false);
|
||||
|
||||
if (this._EXT_sRGB) {
|
||||
if (exts.EXT_sRGB) {
|
||||
this._features[Feature.FORMAT_SRGB] = true;
|
||||
}
|
||||
|
||||
if (this._EXT_blend_minmax) {
|
||||
if (exts.EXT_blend_minmax) {
|
||||
this._features[Feature.BLEND_MINMAX] = true;
|
||||
}
|
||||
|
||||
if (this._WEBGL_color_buffer_float) {
|
||||
if (exts.WEBGL_color_buffer_float) {
|
||||
this._features[Feature.COLOR_FLOAT] = true;
|
||||
}
|
||||
|
||||
if (this._EXT_color_buffer_half_float) {
|
||||
if (exts.EXT_color_buffer_half_float) {
|
||||
this._features[Feature.COLOR_HALF_FLOAT] = true;
|
||||
}
|
||||
|
||||
if (this._OES_texture_float) {
|
||||
if (exts.OES_texture_float) {
|
||||
this._features[Feature.TEXTURE_FLOAT] = true;
|
||||
}
|
||||
|
||||
if (this._OES_texture_half_float) {
|
||||
if (exts.OES_texture_half_float) {
|
||||
this._features[Feature.TEXTURE_HALF_FLOAT] = true;
|
||||
}
|
||||
|
||||
if (this._OES_texture_float_linear) {
|
||||
if (exts.OES_texture_float_linear) {
|
||||
this._features[Feature.TEXTURE_FLOAT_LINEAR] = true;
|
||||
}
|
||||
|
||||
if (this._OES_texture_half_float_linear) {
|
||||
if (exts.OES_texture_half_float_linear) {
|
||||
this._features[Feature.TEXTURE_HALF_FLOAT_LINEAR] = true;
|
||||
}
|
||||
|
||||
this._features[Feature.FORMAT_RGB8] = true;
|
||||
|
||||
if (this._OES_element_index_uint) {
|
||||
if (exts.OES_element_index_uint) {
|
||||
this._features[Feature.ELEMENT_INDEX_UINT] = true;
|
||||
}
|
||||
|
||||
if (this._ANGLE_instanced_arrays) {
|
||||
if (exts.ANGLE_instanced_arrays) {
|
||||
this._features[Feature.INSTANCED_ARRAYS] = true;
|
||||
}
|
||||
|
||||
if (this._WEBGL_draw_buffers) {
|
||||
if (exts.WEBGL_draw_buffers) {
|
||||
this._features[Feature.MULTIPLE_RENDER_TARGETS] = true;
|
||||
}
|
||||
|
||||
let compressedFormat = '';
|
||||
|
||||
if (this._WEBGL_compressed_texture_etc1) {
|
||||
if (exts.WEBGL_compressed_texture_etc1) {
|
||||
this._features[Feature.FORMAT_ETC1] = true;
|
||||
compressedFormat += 'etc1 ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_etc) {
|
||||
if (exts.WEBGL_compressed_texture_etc) {
|
||||
this._features[Feature.FORMAT_ETC2] = true;
|
||||
compressedFormat += 'etc2 ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_s3tc) {
|
||||
if (exts.WEBGL_compressed_texture_s3tc) {
|
||||
this._features[Feature.FORMAT_DXT] = true;
|
||||
compressedFormat += 'dxt ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_pvrtc) {
|
||||
if (exts.WEBGL_compressed_texture_pvrtc) {
|
||||
this._features[Feature.FORMAT_PVRTC] = true;
|
||||
compressedFormat += 'pvrtc ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_astc) {
|
||||
if (exts.WEBGL_compressed_texture_astc) {
|
||||
this._features[Feature.FORMAT_ASTC] = true;
|
||||
compressedFormat += 'astc ';
|
||||
}
|
||||
|
||||
if (this._OES_vertex_array_object) {
|
||||
this._useVAO = true;
|
||||
}
|
||||
|
||||
debug('WebGL device initialized.');
|
||||
debug(`RENDERER: ${this._renderer}`);
|
||||
debug(`VENDOR: ${this._vendor}`);
|
||||
debug(`VERSION: ${this._version}`);
|
||||
debug(`DPR: ${this._devicePixelRatio}`);
|
||||
debug(`SCREEN_SIZE: ${this._width} x ${this._height}`);
|
||||
// debug('COLOR_FORMAT: ' + FormatInfos[this._colorFmt].name);
|
||||
// debug('DEPTH_STENCIL_FORMAT: ' + FormatInfos[this._depthStencilFmt].name);
|
||||
// debug('MAX_VERTEX_ATTRIBS: ' + this._maxVertexAttributes);
|
||||
debug(`MAX_VERTEX_UNIFORM_VECTORS: ${this._caps.maxVertexUniformVectors}`);
|
||||
// debug('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors);
|
||||
// debug('MAX_TEXTURE_IMAGE_UNITS: ' + this._maxTextureUnits);
|
||||
// debug('MAX_VERTEX_TEXTURE_IMAGE_UNITS: ' + this._maxVertexTextureUnits);
|
||||
debug(`DEPTH_BITS: ${this._caps.depthBits}`);
|
||||
debug(`STENCIL_BITS: ${this._caps.stencilBits}`);
|
||||
if (this._EXT_texture_filter_anisotropic) {
|
||||
debug(`MAX_TEXTURE_MAX_ANISOTROPY_EXT: ${this._EXT_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT}`);
|
||||
}
|
||||
debug(`USE_VAO: ${this._useVAO}`);
|
||||
debug(`VERSION: ${version}`);
|
||||
debug(`COMPRESSED_FORMAT: ${compressedFormat}`);
|
||||
|
||||
// init states
|
||||
this.initStates(gl);
|
||||
|
||||
// create queue
|
||||
this._queue = this.createQueue(new QueueInfo(QueueType.GRAPHICS));
|
||||
this._cmdBuff = this.createCommandBuffer(new CommandBufferInfo(this._queue));
|
||||
|
||||
// create default null texture
|
||||
this.nullTex2D = this.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
)) as WebGLTexture;
|
||||
|
||||
this.nullTexCube = this.createTexture(new TextureInfo(
|
||||
TextureType.CUBE,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
6,
|
||||
)) as WebGLTexture;
|
||||
|
||||
const nullTexRegion = new BufferTextureCopy();
|
||||
nullTexRegion.texExtent.width = 2;
|
||||
nullTexRegion.texExtent.height = 2;
|
||||
|
||||
const nullTexBuff = new Uint8Array(this.nullTex2D.size);
|
||||
nullTexBuff.fill(0);
|
||||
this.copyBuffersToTexture([nullTexBuff], this.nullTex2D, [nullTexRegion]);
|
||||
|
||||
nullTexRegion.texSubres.layerCount = 6;
|
||||
this.copyBuffersToTexture(
|
||||
[nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff],
|
||||
this.nullTexCube, [nullTexRegion],
|
||||
);
|
||||
debug(`EXTENSIONS: ${extStr}`);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
if (this._canvas && this._webGLContextLostHandler) {
|
||||
this._canvas.removeEventListener(eventWebGLContextLost, this._webGLContextLostHandler);
|
||||
this._webGLContextLostHandler = null;
|
||||
}
|
||||
|
||||
if (this.nullTex2D) {
|
||||
this.nullTex2D.destroy();
|
||||
this.nullTex2D = null;
|
||||
}
|
||||
|
||||
if (this.nullTexCube) {
|
||||
this.nullTexCube.destroy();
|
||||
this.nullTexCube = null;
|
||||
}
|
||||
|
||||
if (this._queue) {
|
||||
this._queue.destroy();
|
||||
this._queue = null;
|
||||
@@ -571,27 +236,11 @@ export class WebGLDevice extends Device {
|
||||
this._cmdBuff.destroy();
|
||||
this._cmdBuff = null;
|
||||
}
|
||||
|
||||
this._extensions = null;
|
||||
|
||||
this._webGLRC = null;
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
if (this._width !== width || this._height !== height) {
|
||||
debug(`Resizing device: ${width}x${height}`);
|
||||
this._canvas!.width = width;
|
||||
this._canvas!.height = height;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
}
|
||||
}
|
||||
|
||||
public flushCommands (cmdBuffs: CommandBuffer[]) {}
|
||||
|
||||
public acquire () {
|
||||
this.cmdAllocator.releaseCmds();
|
||||
}
|
||||
public acquire (swapchains: Swapchain[]) {}
|
||||
|
||||
public present () {
|
||||
const queue = (this._queue as WebGLQueue);
|
||||
@@ -604,123 +253,106 @@ export class WebGLDevice extends Device {
|
||||
public createCommandBuffer (info: CommandBufferInfo): CommandBuffer {
|
||||
// const Ctor = WebGLCommandBuffer; // opt to instant invocation
|
||||
const Ctor = info.type === CommandBufferType.PRIMARY ? WebGLPrimaryCommandBuffer : WebGLCommandBuffer;
|
||||
const cmdBuff = new Ctor(this);
|
||||
if (cmdBuff.initialize(info)) {
|
||||
return cmdBuff;
|
||||
}
|
||||
return null!;
|
||||
const cmdBuff = new Ctor();
|
||||
cmdBuff.initialize(info);
|
||||
return cmdBuff;
|
||||
}
|
||||
|
||||
public createSwapchain (info: SwapchainInfo): Swapchain {
|
||||
const swapchain = new WebGLSwapchain();
|
||||
this._swapchain = swapchain;
|
||||
swapchain.initialize(info);
|
||||
return swapchain;
|
||||
}
|
||||
|
||||
public createBuffer (info: BufferInfo | BufferViewInfo): Buffer {
|
||||
const buffer = new WebGLBuffer(this);
|
||||
if (buffer.initialize(info)) {
|
||||
return buffer;
|
||||
}
|
||||
return null!;
|
||||
const buffer = new WebGLBuffer();
|
||||
buffer.initialize(info);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public createTexture (info: TextureInfo | TextureViewInfo): Texture {
|
||||
const texture = new WebGLTexture(this);
|
||||
if (texture.initialize(info)) {
|
||||
return texture;
|
||||
}
|
||||
return null!;
|
||||
}
|
||||
|
||||
public createSampler (info: SamplerInfo): Sampler {
|
||||
const sampler = new WebGLSampler(this);
|
||||
if (sampler.initialize(info)) {
|
||||
return sampler;
|
||||
}
|
||||
return null!;
|
||||
const texture = new WebGLTexture();
|
||||
texture.initialize(info);
|
||||
return texture;
|
||||
}
|
||||
|
||||
public createDescriptorSet (info: DescriptorSetInfo): DescriptorSet {
|
||||
const descriptorSet = new WebGLDescriptorSet(this);
|
||||
if (descriptorSet.initialize(info)) {
|
||||
return descriptorSet;
|
||||
}
|
||||
return null!;
|
||||
const descriptorSet = new WebGLDescriptorSet();
|
||||
descriptorSet.initialize(info);
|
||||
return descriptorSet;
|
||||
}
|
||||
|
||||
public createShader (info: ShaderInfo): Shader {
|
||||
const shader = new WebGLShader(this);
|
||||
if (shader.initialize(info)) {
|
||||
return shader;
|
||||
}
|
||||
return null!;
|
||||
const shader = new WebGLShader();
|
||||
shader.initialize(info);
|
||||
return shader;
|
||||
}
|
||||
|
||||
public createInputAssembler (info: InputAssemblerInfo): InputAssembler {
|
||||
const inputAssembler = new WebGLInputAssembler(this);
|
||||
if (inputAssembler.initialize(info)) {
|
||||
return inputAssembler;
|
||||
}
|
||||
return null!;
|
||||
const inputAssembler = new WebGLInputAssembler();
|
||||
inputAssembler.initialize(info);
|
||||
return inputAssembler;
|
||||
}
|
||||
|
||||
public createRenderPass (info: RenderPassInfo): RenderPass {
|
||||
const renderPass = new WebGLRenderPass(this);
|
||||
if (renderPass.initialize(info)) {
|
||||
return renderPass;
|
||||
}
|
||||
return null!;
|
||||
const renderPass = new WebGLRenderPass();
|
||||
renderPass.initialize(info);
|
||||
return renderPass;
|
||||
}
|
||||
|
||||
public createFramebuffer (info: FramebufferInfo): Framebuffer {
|
||||
const framebuffer = new WebGLFramebuffer(this);
|
||||
if (framebuffer.initialize(info)) {
|
||||
return framebuffer;
|
||||
}
|
||||
return null!;
|
||||
const framebuffer = new WebGLFramebuffer();
|
||||
framebuffer.initialize(info);
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
public createDescriptorSetLayout (info: DescriptorSetLayoutInfo): DescriptorSetLayout {
|
||||
const descriptorSetLayout = new WebGLDescriptorSetLayout(this);
|
||||
if (descriptorSetLayout.initialize(info)) {
|
||||
return descriptorSetLayout;
|
||||
}
|
||||
return null!;
|
||||
const descriptorSetLayout = new WebGLDescriptorSetLayout();
|
||||
descriptorSetLayout.initialize(info);
|
||||
return descriptorSetLayout;
|
||||
}
|
||||
|
||||
public createPipelineLayout (info: PipelineLayoutInfo): PipelineLayout {
|
||||
const pipelineLayout = new WebGLPipelineLayout(this);
|
||||
if (pipelineLayout.initialize(info)) {
|
||||
return pipelineLayout;
|
||||
}
|
||||
return null!;
|
||||
const pipelineLayout = new WebGLPipelineLayout();
|
||||
pipelineLayout.initialize(info);
|
||||
return pipelineLayout;
|
||||
}
|
||||
|
||||
public createPipelineState (info: PipelineStateInfo): PipelineState {
|
||||
const pipelineState = new WebGLPipelineState(this);
|
||||
if (pipelineState.initialize(info)) {
|
||||
return pipelineState;
|
||||
}
|
||||
return null!;
|
||||
const pipelineState = new WebGLPipelineState();
|
||||
pipelineState.initialize(info);
|
||||
return pipelineState;
|
||||
}
|
||||
|
||||
public createQueue (info: QueueInfo): Queue {
|
||||
const queue = new WebGLQueue(this);
|
||||
if (queue.initialize(info)) {
|
||||
return queue;
|
||||
}
|
||||
return null!;
|
||||
const queue = new WebGLQueue();
|
||||
queue.initialize(info);
|
||||
return queue;
|
||||
}
|
||||
|
||||
public createGlobalBarrier (info: GlobalBarrierInfo) {
|
||||
const barrier = new GlobalBarrier(this);
|
||||
if (barrier.initialize(info)) {
|
||||
return barrier;
|
||||
public getSampler (info: SamplerInfo): Sampler {
|
||||
const hash = Sampler.computeHash(info);
|
||||
if (!this._samplers.has(hash)) {
|
||||
this._samplers.set(hash, new WebGLSampler(info));
|
||||
}
|
||||
return null!;
|
||||
return this._samplers.get(hash)!;
|
||||
}
|
||||
|
||||
public createTextureBarrier (info: TextureBarrierInfo) {
|
||||
const barrier = new TextureBarrier(this);
|
||||
if (barrier.initialize(info)) {
|
||||
return barrier;
|
||||
public getGlobalBarrier (info: GlobalBarrierInfo) {
|
||||
const hash = GlobalBarrier.computeHash(info);
|
||||
if (!this._globalBarriers.has(hash)) {
|
||||
this._globalBarriers.set(hash, new GlobalBarrier(info));
|
||||
}
|
||||
return null!;
|
||||
return this._globalBarriers.get(hash)!;
|
||||
}
|
||||
|
||||
public getTextureBarrier (info: TextureBarrierInfo) {
|
||||
const hash = TextureBarrier.computeHash(info);
|
||||
if (!this._textureBarriers.has(hash)) {
|
||||
this._textureBarriers.set(hash, new TextureBarrier(info));
|
||||
}
|
||||
return this._textureBarriers.get(hash)!;
|
||||
}
|
||||
|
||||
public copyBuffersToTexture (buffers: ArrayBufferView[], texture: Texture, regions: BufferTextureCopy[]) {
|
||||
@@ -753,100 +385,4 @@ export class WebGLDevice extends Device {
|
||||
regions,
|
||||
);
|
||||
}
|
||||
|
||||
public copyFramebufferToBuffer (
|
||||
srcFramebuffer: Framebuffer,
|
||||
dstBuffer: ArrayBuffer,
|
||||
regions: BufferTextureCopy[],
|
||||
) {
|
||||
const gl = this._webGLRC as WebGLRenderingContext;
|
||||
const gpuFramebuffer = (srcFramebuffer as WebGLFramebuffer).gpuFramebuffer;
|
||||
const format = gpuFramebuffer.gpuColorTextures[0].format;
|
||||
const glFormat = GFXFormatToWebGLFormat(format, gl);
|
||||
const glType = GFXFormatToWebGLType(format, gl);
|
||||
const Ctor = getTypedArrayConstructor(FormatInfos[format]);
|
||||
|
||||
const curFBO = this.stateCache.glFramebuffer;
|
||||
|
||||
if (this.stateCache.glFramebuffer !== gpuFramebuffer.glFramebuffer) {
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuFramebuffer.glFramebuffer);
|
||||
this.stateCache.glFramebuffer = gpuFramebuffer.glFramebuffer;
|
||||
}
|
||||
|
||||
const view = new Ctor(dstBuffer);
|
||||
|
||||
for (const region of regions) {
|
||||
const w = region.texExtent.width;
|
||||
const h = region.texExtent.height;
|
||||
|
||||
gl.readPixels(region.texOffset.x, region.texOffset.y, w, h, glFormat, glType, view);
|
||||
}
|
||||
|
||||
if (this.stateCache.glFramebuffer !== curFBO) {
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, curFBO);
|
||||
this.stateCache.glFramebuffer = curFBO;
|
||||
}
|
||||
}
|
||||
|
||||
public blitFramebuffer (src: Framebuffer, dst: Framebuffer, srcRect: Rect, dstRect: Rect, filter: Filter) {
|
||||
}
|
||||
|
||||
private getExtension (ext: string): any {
|
||||
const prefixes = ['', 'WEBKIT_', 'MOZ_'];
|
||||
for (let i = 0; i < prefixes.length; ++i) {
|
||||
const _ext = this.gl.getExtension(prefixes[i] + ext);
|
||||
if (_ext) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return _ext;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private initStates (gl: WebGLRenderingContext) {
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.pixelStorei(gl.PACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
// rasterizer state
|
||||
gl.enable(gl.SCISSOR_TEST);
|
||||
gl.enable(gl.CULL_FACE);
|
||||
gl.cullFace(gl.BACK);
|
||||
gl.frontFace(gl.CCW);
|
||||
gl.disable(gl.POLYGON_OFFSET_FILL);
|
||||
gl.polygonOffset(0.0, 0.0);
|
||||
|
||||
// depth stencil state
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthMask(true);
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthRange(0.0, 1.0);
|
||||
|
||||
gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.FRONT, 0xffff);
|
||||
gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.BACK, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.BACK, 0xffff);
|
||||
|
||||
gl.disable(gl.STENCIL_TEST);
|
||||
|
||||
// blend state
|
||||
gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
|
||||
gl.disable(gl.BLEND);
|
||||
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
|
||||
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
||||
gl.colorMask(true, true, true, true);
|
||||
gl.blendColor(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
private _onWebGLContextLost (event: Event) {
|
||||
warnID(11000);
|
||||
warn(event);
|
||||
// 2020.9.3: `preventDefault` is not available on some platforms
|
||||
// event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { FramebufferInfo } from '../base/define';
|
||||
import { Framebuffer } from '../base/framebuffer';
|
||||
import { WebGLCmdFuncCreateFramebuffer, WebGLCmdFuncDestroyFramebuffer } from './webgl-commands';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
import { IWebGLGPUFramebuffer, IWebGLGPUTexture } from './webgl-gpu-objects';
|
||||
import { WebGLRenderPass } from './webgl-render-pass';
|
||||
|
||||
@@ -39,7 +39,7 @@ export class WebGLFramebuffer extends Framebuffer {
|
||||
|
||||
private _gpuFramebuffer: IWebGLGPUFramebuffer | null = null;
|
||||
|
||||
public initialize (info: FramebufferInfo): boolean {
|
||||
public initialize (info: FramebufferInfo) {
|
||||
this._renderPass = info.renderPass;
|
||||
this._colorTextures = info.colorTextures || [];
|
||||
this._depthStencilTexture = info.depthStencilTexture || null;
|
||||
@@ -64,14 +64,12 @@ export class WebGLFramebuffer extends Framebuffer {
|
||||
glFramebuffer: null,
|
||||
};
|
||||
|
||||
WebGLCmdFuncCreateFramebuffer(this._device as WebGLDevice, this._gpuFramebuffer);
|
||||
|
||||
return true;
|
||||
WebGLCmdFuncCreateFramebuffer(WebGLDeviceManager.instance, this._gpuFramebuffer);
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuFramebuffer) {
|
||||
WebGLCmdFuncDestroyFramebuffer(this._device as WebGLDevice, this._gpuFramebuffer);
|
||||
WebGLCmdFuncDestroyFramebuffer(WebGLDeviceManager.instance, this._gpuFramebuffer);
|
||||
this._gpuFramebuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,76 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { nextPow2 } from '../../math/bits';
|
||||
import {
|
||||
DescriptorType, BufferUsage, Format, MemoryUsage, SampleCount, DynamicStateFlagBit,
|
||||
ShaderStageFlagBit, TextureFlags, TextureType, TextureUsage, Type,
|
||||
DrawInfo, Attribute, ColorAttachment, DepthStencilAttachment,
|
||||
UniformBlock, UniformSamplerTexture, DescriptorSetLayoutBinding,
|
||||
Attribute, ColorAttachment, DepthStencilAttachment,
|
||||
UniformBlock, UniformSamplerTexture, DescriptorSetLayoutBinding, DrawInfo,
|
||||
} from '../base/define';
|
||||
import { BlendState, DepthStencilState, RasterizerState } from '../base/pipeline-state';
|
||||
|
||||
export class WebGLIndirectDrawInfos {
|
||||
public counts: Int32Array;
|
||||
public offsets: Int32Array;
|
||||
public instances: Int32Array;
|
||||
public drawCount = 0;
|
||||
public drawByIndex = false;
|
||||
public instancedDraw = false;
|
||||
|
||||
// staging buffer
|
||||
public byteOffsets: Int32Array;
|
||||
|
||||
private _capacity = 4;
|
||||
|
||||
constructor () {
|
||||
this.counts = new Int32Array(this._capacity);
|
||||
this.offsets = new Int32Array(this._capacity);
|
||||
this.instances = new Int32Array(this._capacity);
|
||||
this.byteOffsets = new Int32Array(this._capacity);
|
||||
}
|
||||
|
||||
public clearDraws () {
|
||||
this.drawCount = 0;
|
||||
this.drawByIndex = false;
|
||||
this.instancedDraw = false;
|
||||
}
|
||||
|
||||
public setDrawInfo (idx: number, info: DrawInfo) {
|
||||
this._ensureCapacity(idx);
|
||||
this.drawByIndex = info.indexCount > 0;
|
||||
this.instancedDraw = info.instanceCount > 1;
|
||||
this.drawCount = Math.max(idx + 1, this.drawCount);
|
||||
|
||||
if (this.drawByIndex) {
|
||||
this.counts[idx] = info.indexCount;
|
||||
this.offsets[idx] = info.firstIndex;
|
||||
} else {
|
||||
this.counts[idx] = info.vertexCount;
|
||||
this.offsets[idx] = info.firstVertex;
|
||||
}
|
||||
this.instances[idx] = Math.max(1, info.instanceCount);
|
||||
}
|
||||
|
||||
private _ensureCapacity (target: number) {
|
||||
if (this._capacity > target) return;
|
||||
this._capacity = nextPow2(target);
|
||||
|
||||
const counts = new Int32Array(this._capacity);
|
||||
const offsets = new Int32Array(this._capacity);
|
||||
const instances = new Int32Array(this._capacity);
|
||||
this.byteOffsets = new Int32Array(this._capacity);
|
||||
|
||||
counts.set(this.counts);
|
||||
offsets.set(this.offsets);
|
||||
instances.set(this.instances);
|
||||
|
||||
this.counts = counts;
|
||||
this.offsets = offsets;
|
||||
this.instances = instances;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IWebGLGPUUniformInfo {
|
||||
name: string;
|
||||
type: Type;
|
||||
@@ -57,7 +119,7 @@ export interface IWebGLGPUBuffer {
|
||||
|
||||
buffer: ArrayBufferView | null;
|
||||
vf32: Float32Array | null;
|
||||
indirects: DrawInfo[];
|
||||
indirects: WebGLIndirectDrawInfos;
|
||||
}
|
||||
|
||||
export interface IWebGLGPUTexture {
|
||||
@@ -85,6 +147,8 @@ export interface IWebGLGPUTexture {
|
||||
glWrapT: GLenum;
|
||||
glMinFilter: GLenum;
|
||||
glMagFilter: GLenum;
|
||||
|
||||
isSwapchainTexture: boolean;
|
||||
}
|
||||
|
||||
export interface IWebGLGPURenderPass {
|
||||
|
||||
@@ -27,7 +27,7 @@ import { InputAssemblerInfo } from '../base/define';
|
||||
import { InputAssembler } from '../base/input-assembler';
|
||||
import { WebGLBuffer } from './webgl-buffer';
|
||||
import { WebGLCmdFuncCreateInputAssember, WebGLCmdFuncDestroyInputAssembler } from './webgl-commands';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
import { IWebGLGPUInputAssembler, IWebGLGPUBuffer } from './webgl-gpu-objects';
|
||||
|
||||
export class WebGLInputAssembler extends InputAssembler {
|
||||
@@ -37,10 +37,10 @@ export class WebGLInputAssembler extends InputAssembler {
|
||||
|
||||
private _gpuInputAssembler: IWebGLGPUInputAssembler | null = null;
|
||||
|
||||
public initialize (info: InputAssemblerInfo): boolean {
|
||||
public initialize (info: InputAssemblerInfo) {
|
||||
if (info.vertexBuffers.length === 0) {
|
||||
console.error('InputAssemblerInfo.vertexBuffers is null.');
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
this._attributes = info.attributes;
|
||||
@@ -49,16 +49,16 @@ export class WebGLInputAssembler extends InputAssembler {
|
||||
|
||||
if (info.indexBuffer) {
|
||||
this._indexBuffer = info.indexBuffer;
|
||||
this._indexCount = this._indexBuffer.size / this._indexBuffer.stride;
|
||||
this._firstIndex = 0;
|
||||
this._drawInfo.indexCount = this._indexBuffer.size / this._indexBuffer.stride;
|
||||
this._drawInfo.firstIndex = 0;
|
||||
} else {
|
||||
const vertBuff = this._vertexBuffers[0];
|
||||
this._vertexCount = vertBuff.size / vertBuff.stride;
|
||||
this._firstVertex = 0;
|
||||
this._vertexOffset = 0;
|
||||
this._drawInfo.vertexCount = vertBuff.size / vertBuff.stride;
|
||||
this._drawInfo.firstVertex = 0;
|
||||
this._drawInfo.vertexOffset = 0;
|
||||
}
|
||||
this._instanceCount = 0;
|
||||
this._firstInstance = 0;
|
||||
this._drawInfo.instanceCount = 0;
|
||||
this._drawInfo.firstInstance = 0;
|
||||
|
||||
this._indirectBuffer = info.indirectBuffer || null;
|
||||
|
||||
@@ -102,15 +102,13 @@ export class WebGLInputAssembler extends InputAssembler {
|
||||
glVAOs: new Map<WebGLProgram, WebGLVertexArrayObjectOES>(),
|
||||
};
|
||||
|
||||
WebGLCmdFuncCreateInputAssember(this._device as WebGLDevice, this._gpuInputAssembler);
|
||||
|
||||
return true;
|
||||
WebGLCmdFuncCreateInputAssember(WebGLDeviceManager.instance, this._gpuInputAssembler);
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
const webglDev = this._device as WebGLDevice;
|
||||
if (this._gpuInputAssembler && webglDev.useVAO) {
|
||||
WebGLCmdFuncDestroyInputAssembler(webglDev, this._gpuInputAssembler);
|
||||
const device = WebGLDeviceManager.instance;
|
||||
if (this._gpuInputAssembler && device.extensions.useVAO) {
|
||||
WebGLCmdFuncDestroyInputAssembler(device, this._gpuInputAssembler);
|
||||
}
|
||||
this._gpuInputAssembler = null;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,6 @@ export class WebGLPipelineLayout extends PipelineLayout {
|
||||
dynamicOffsetCount,
|
||||
dynamicOffsetOffsets,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -54,7 +54,7 @@ export class WebGLPipelineState extends PipelineState {
|
||||
|
||||
private _gpuPipelineState: IWebGLGPUPipelineState | null = null;
|
||||
|
||||
public initialize (info: PipelineStateInfo): boolean {
|
||||
public initialize (info: PipelineStateInfo) {
|
||||
this._primitive = info.primitive;
|
||||
this._shader = info.shader;
|
||||
this._pipelineLayout = info.pipelineLayout;
|
||||
@@ -95,8 +95,6 @@ export class WebGLPipelineState extends PipelineState {
|
||||
gpuRenderPass: (info.renderPass as WebGLRenderPass).gpuRenderPass,
|
||||
dynamicStates,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -34,11 +34,11 @@ import { WebGLCommandBuffer } from './webgl-command-buffer';
|
||||
import {
|
||||
WebGLCmdFuncBeginRenderPass, WebGLCmdFuncBindStates, WebGLCmdFuncCopyBuffersToTexture,
|
||||
WebGLCmdFuncDraw, WebGLCmdFuncExecuteCmds, WebGLCmdFuncUpdateBuffer } from './webgl-commands';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
import { WebGLFramebuffer } from './webgl-framebuffer';
|
||||
import { WebGLTexture } from './webgl-texture';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { WebGLRenderPass } from './webgl-render-pass';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
|
||||
export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
public beginRenderPass (
|
||||
@@ -50,7 +50,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
clearStencil: number,
|
||||
) {
|
||||
WebGLCmdFuncBeginRenderPass(
|
||||
this._device as WebGLDevice,
|
||||
WebGLDeviceManager.instance,
|
||||
(renderPass as WebGLRenderPass).gpuRenderPass,
|
||||
(framebuffer as WebGLFramebuffer).gpuFramebuffer,
|
||||
renderArea, clearColors, clearDepth, clearStencil,
|
||||
@@ -58,13 +58,15 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
this._isInRenderPass = true;
|
||||
}
|
||||
|
||||
public draw (info: DrawInfo | InputAssembler) {
|
||||
public draw (infoOrAssembler: DrawInfo | InputAssembler) {
|
||||
if (this._isInRenderPass) {
|
||||
if (this._isStateInvalied) {
|
||||
this.bindStates();
|
||||
}
|
||||
|
||||
WebGLCmdFuncDraw(this._device as WebGLDevice, info as DrawInfo);
|
||||
const info = 'drawInfo' in infoOrAssembler ? infoOrAssembler.drawInfo : infoOrAssembler;
|
||||
|
||||
WebGLCmdFuncDraw(WebGLDeviceManager.instance, info as DrawInfo);
|
||||
|
||||
++this._numDrawCalls;
|
||||
this._numInstances += info.instanceCount;
|
||||
@@ -102,7 +104,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
buffSize = (data as ArrayBuffer).byteLength;
|
||||
}
|
||||
|
||||
WebGLCmdFuncUpdateBuffer(this._device as WebGLDevice, gpuBuffer, data as ArrayBuffer, 0, buffSize);
|
||||
WebGLCmdFuncUpdateBuffer(WebGLDeviceManager.instance, gpuBuffer, data as ArrayBuffer, 0, buffSize);
|
||||
}
|
||||
} else {
|
||||
console.error('Command \'updateBuffer\' must be recorded outside a render pass.');
|
||||
@@ -113,7 +115,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
if (!this._isInRenderPass) {
|
||||
const gpuTexture = (texture as WebGLTexture).gpuTexture;
|
||||
if (gpuTexture) {
|
||||
WebGLCmdFuncCopyBuffersToTexture(this._device as WebGLDevice, buffers, gpuTexture, regions);
|
||||
WebGLCmdFuncCopyBuffersToTexture(WebGLDeviceManager.instance, buffers, gpuTexture, regions);
|
||||
}
|
||||
} else {
|
||||
console.error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
|
||||
@@ -124,7 +126,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
for (let i = 0; i < count; ++i) {
|
||||
// actually they are secondary buffers, the cast here is only for type checking
|
||||
const webGLCmdBuff = cmdBuffs[i] as WebGLPrimaryCommandBuffer;
|
||||
WebGLCmdFuncExecuteCmds(this._device as WebGLDevice, webGLCmdBuff.cmdPackage);
|
||||
WebGLCmdFuncExecuteCmds(WebGLDeviceManager.instance, webGLCmdBuff.cmdPackage);
|
||||
this._numDrawCalls += webGLCmdBuff._numDrawCalls;
|
||||
this._numInstances += webGLCmdBuff._numInstances;
|
||||
this._numTris += webGLCmdBuff._numTris;
|
||||
@@ -132,7 +134,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
}
|
||||
|
||||
protected bindStates () {
|
||||
WebGLCmdFuncBindStates(this._device as WebGLDevice, this._curGPUPipelineState, this._curGPUInputAssembler,
|
||||
WebGLCmdFuncBindStates(WebGLDeviceManager.instance, this._curGPUPipelineState, this._curGPUInputAssembler,
|
||||
this._curGPUDescriptorSets, this._curDynamicOffsets, this._curDynamicStates);
|
||||
this._isStateInvalied = false;
|
||||
}
|
||||
|
||||
@@ -32,25 +32,21 @@ export class WebGLQueue extends Queue {
|
||||
public numInstances = 0;
|
||||
public numTris = 0;
|
||||
|
||||
public initialize (info: QueueInfo): boolean {
|
||||
public initialize (info: QueueInfo) {
|
||||
this._type = info.type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
}
|
||||
|
||||
public submit (cmdBuffs: CommandBuffer[]) {
|
||||
if (!this._isAsync) {
|
||||
const len = cmdBuffs.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const cmdBuff = cmdBuffs[i];
|
||||
// WebGLCmdFuncExecuteCmds( this._device as WebGLDevice, (cmdBuff as WebGLCommandBuffer).cmdPackage); // opted out
|
||||
this.numDrawCalls += cmdBuff.numDrawCalls;
|
||||
this.numInstances += cmdBuff.numInstances;
|
||||
this.numTris += cmdBuff.numTris;
|
||||
}
|
||||
const len = cmdBuffs.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const cmdBuff = cmdBuffs[i];
|
||||
// WebGLCmdFuncExecuteCmds( this._device as WebGLDevice, (cmdBuff as WebGLCommandBuffer).cmdPackage); // opted out
|
||||
this.numDrawCalls += cmdBuff.numDrawCalls;
|
||||
this.numInstances += cmdBuff.numInstances;
|
||||
this.numTris += cmdBuff.numTris;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,12 +34,10 @@ export class WebGLRenderPass extends RenderPass {
|
||||
|
||||
private _gpuRenderPass: IWebGLGPURenderPass | null = null;
|
||||
|
||||
public initialize (info: RenderPassInfo): boolean {
|
||||
public initialize (info: RenderPassInfo) {
|
||||
this._colorInfos = info.colorAttachments;
|
||||
this._depthStencilInfo = info.depthStencilAttachment;
|
||||
if (info.subpasses) {
|
||||
this._subpasses = info.subpasses;
|
||||
}
|
||||
this._subpasses = info.subpasses;
|
||||
|
||||
this._gpuRenderPass = {
|
||||
colorAttachments: this._colorInfos,
|
||||
@@ -47,8 +45,6 @@ export class WebGLRenderPass extends RenderPass {
|
||||
};
|
||||
|
||||
this._hash = this.computeHash();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { ShaderInfo } from '../base/define';
|
||||
import { Shader } from '../base/shader';
|
||||
import { WebGLCmdFuncCreateShader, WebGLCmdFuncDestroyShader } from './webgl-commands';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
import { IWebGLGPUShader, IWebGLGPUShaderStage } from './webgl-gpu-objects';
|
||||
|
||||
export class WebGLShader extends Shader {
|
||||
@@ -36,7 +36,7 @@ export class WebGLShader extends Shader {
|
||||
|
||||
private _gpuShader: IWebGLGPUShader | null = null;
|
||||
|
||||
public initialize (info: ShaderInfo): boolean {
|
||||
public initialize (info: ShaderInfo) {
|
||||
this._name = info.name;
|
||||
this._stages = info.stages;
|
||||
this._attributes = info.attributes;
|
||||
@@ -65,14 +65,12 @@ export class WebGLShader extends Shader {
|
||||
};
|
||||
}
|
||||
|
||||
WebGLCmdFuncCreateShader(this._device as WebGLDevice, this._gpuShader);
|
||||
|
||||
return true;
|
||||
WebGLCmdFuncCreateShader(WebGLDeviceManager.instance, this._gpuShader);
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuShader) {
|
||||
WebGLCmdFuncDestroyShader(this._device as WebGLDevice, this._gpuShader);
|
||||
WebGLCmdFuncDestroyShader(WebGLDeviceManager.instance, this._gpuShader);
|
||||
this._gpuShader = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { ALIPAY, RUNTIME_BASED, BYTEDANCE, WECHAT, LINKSURE, QTT, COCOSPLAY, HUAWEI, EDITOR } from 'internal:constants';
|
||||
import { macro, warnID, warn, debug } from '../../platform';
|
||||
import { sys } from '../../platform/sys';
|
||||
import { WebGLCommandAllocator } from './webgl-command-allocator';
|
||||
import { WebGLStateCache } from './webgl-state-cache';
|
||||
import { WebGLTexture } from './webgl-texture';
|
||||
import { Format, TextureInfo, TextureFlagBit, TextureType, TextureUsageBit, BufferTextureCopy, SwapchainInfo } from '../base/define';
|
||||
import { BrowserType, OS } from '../../../../pal/system-info/enum-type';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { IWebGLExtensions, WebGLDeviceManager } from './webgl-define';
|
||||
|
||||
const eventWebGLContextLost = 'webglcontextlost';
|
||||
|
||||
function initStates (gl: WebGLRenderingContext) {
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.pixelStorei(gl.PACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
// rasterizer state
|
||||
gl.enable(gl.SCISSOR_TEST);
|
||||
gl.enable(gl.CULL_FACE);
|
||||
gl.cullFace(gl.BACK);
|
||||
gl.frontFace(gl.CCW);
|
||||
gl.disable(gl.POLYGON_OFFSET_FILL);
|
||||
gl.polygonOffset(0.0, 0.0);
|
||||
|
||||
// depth stencil state
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthMask(true);
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthRange(0.0, 1.0);
|
||||
|
||||
gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.FRONT, 0xffff);
|
||||
gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.BACK, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.BACK, 0xffff);
|
||||
|
||||
gl.disable(gl.STENCIL_TEST);
|
||||
|
||||
// blend state
|
||||
gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
|
||||
gl.disable(gl.BLEND);
|
||||
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
|
||||
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
||||
gl.colorMask(true, true, true, true);
|
||||
gl.blendColor(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
function getExtension (gl: WebGLRenderingContext, ext: string): any {
|
||||
const prefixes = ['', 'WEBKIT_', 'MOZ_'];
|
||||
for (let i = 0; i < prefixes.length; ++i) {
|
||||
const _ext = gl.getExtension(prefixes[i] + ext);
|
||||
if (_ext) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return _ext;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getExtensions (gl: WebGLRenderingContext) {
|
||||
const res: IWebGLExtensions = {
|
||||
EXT_texture_filter_anisotropic: getExtension(gl, 'EXT_texture_filter_anisotropic'),
|
||||
EXT_blend_minmax: getExtension(gl, 'EXT_blend_minmax'),
|
||||
EXT_frag_depth: getExtension(gl, 'EXT_frag_depth'),
|
||||
EXT_shader_texture_lod: getExtension(gl, 'EXT_shader_texture_lod'),
|
||||
EXT_sRGB: getExtension(gl, 'EXT_sRGB'),
|
||||
OES_vertex_array_object: getExtension(gl, 'OES_vertex_array_object'),
|
||||
EXT_color_buffer_half_float: getExtension(gl, 'EXT_color_buffer_half_float'),
|
||||
WEBGL_multi_draw: getExtension(gl, 'WEBGL_multi_draw'),
|
||||
WEBGL_color_buffer_float: getExtension(gl, 'WEBGL_color_buffer_float'),
|
||||
WEBGL_compressed_texture_etc1: getExtension(gl, 'WEBGL_compressed_texture_etc1'),
|
||||
WEBGL_compressed_texture_etc: getExtension(gl, 'WEBGL_compressed_texture_etc'),
|
||||
WEBGL_compressed_texture_pvrtc: getExtension(gl, 'WEBGL_compressed_texture_pvrtc'),
|
||||
WEBGL_compressed_texture_s3tc: getExtension(gl, 'WEBGL_compressed_texture_s3tc'),
|
||||
WEBGL_compressed_texture_s3tc_srgb: getExtension(gl, 'WEBGL_compressed_texture_s3tc_srgb'),
|
||||
WEBGL_debug_shaders: getExtension(gl, 'WEBGL_debug_shaders'),
|
||||
WEBGL_draw_buffers: getExtension(gl, 'WEBGL_draw_buffers'),
|
||||
WEBGL_lose_context: getExtension(gl, 'WEBGL_lose_context'),
|
||||
WEBGL_depth_texture: getExtension(gl, 'WEBGL_depth_texture'),
|
||||
OES_texture_half_float: getExtension(gl, 'OES_texture_half_float'),
|
||||
OES_texture_half_float_linear: getExtension(gl, 'OES_texture_half_float_linear'),
|
||||
OES_texture_float: getExtension(gl, 'OES_texture_float'),
|
||||
OES_texture_float_linear: getExtension(gl, 'OES_texture_float_linear'),
|
||||
OES_standard_derivatives: getExtension(gl, 'OES_standard_derivatives'),
|
||||
OES_element_index_uint: getExtension(gl, 'OES_element_index_uint'),
|
||||
ANGLE_instanced_arrays: getExtension(gl, 'ANGLE_instanced_arrays'),
|
||||
WEBGL_debug_renderer_info: getExtension(gl, 'WEBGL_debug_renderer_info'),
|
||||
WEBGL_compressed_texture_astc: null,
|
||||
destroyShadersImmediately: true,
|
||||
noCompressedTexSubImage2D: false,
|
||||
useVAO: false,
|
||||
};
|
||||
|
||||
// platform-specific extension hacks
|
||||
// eslint-disable-next-line no-lone-blocks
|
||||
{
|
||||
// iOS 14 browsers crash on getExtension('WEBGL_compressed_texture_astc')
|
||||
if (sys.os !== OS.IOS || sys.osMainVersion !== 14 || !sys.isBrowser) {
|
||||
res.WEBGL_compressed_texture_astc = getExtension(gl, 'WEBGL_compressed_texture_astc');
|
||||
}
|
||||
|
||||
// UC browser instancing implementation doesn't work
|
||||
if (sys.browserType === BrowserType.UC) {
|
||||
res.ANGLE_instanced_arrays = null;
|
||||
}
|
||||
|
||||
// bytedance ios depth texture implementation doesn't work
|
||||
if (BYTEDANCE && sys.os === OS.IOS) {
|
||||
res.WEBGL_depth_texture = null;
|
||||
}
|
||||
|
||||
if (RUNTIME_BASED) {
|
||||
// VAO implementations doesn't work well on some runtime platforms
|
||||
if (LINKSURE || QTT || COCOSPLAY || HUAWEI) {
|
||||
res.OES_vertex_array_object = null;
|
||||
}
|
||||
}
|
||||
|
||||
// some earlier version of iOS and android wechat implement gl.detachShader incorrectly
|
||||
if ((sys.os === OS.IOS && sys.osMainVersion <= 10)
|
||||
|| (WECHAT && sys.os === OS.ANDROID)) {
|
||||
res.destroyShadersImmediately = false;
|
||||
}
|
||||
|
||||
// compressedTexSubImage2D has always been problematic because the parameters differs slightly from GLES
|
||||
if (WECHAT) { // and MANY platforms get it wrong
|
||||
res.noCompressedTexSubImage2D = true;
|
||||
}
|
||||
|
||||
if (res.OES_vertex_array_object) {
|
||||
res.useVAO = true;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export class WebGLSwapchain extends Swapchain {
|
||||
get gl () {
|
||||
return this._webGLRC as WebGLRenderingContext;
|
||||
}
|
||||
|
||||
get extensions () {
|
||||
return this._extensions as IWebGLExtensions;
|
||||
}
|
||||
|
||||
public stateCache: WebGLStateCache = new WebGLStateCache();
|
||||
public cmdAllocator: WebGLCommandAllocator = new WebGLCommandAllocator();
|
||||
public nullTex2D: WebGLTexture = null!;
|
||||
public nullTexCube: WebGLTexture = null!;
|
||||
|
||||
private _canvas: HTMLCanvasElement | null = null;
|
||||
private _webGLRC: WebGLRenderingContext | null = null;
|
||||
private _webGLContextLostHandler: ((event: Event) => void) | null = null;
|
||||
private _extensions: IWebGLExtensions | null = null;
|
||||
|
||||
public initialize (info: SwapchainInfo) {
|
||||
this._canvas = info.windowHandle;
|
||||
|
||||
try {
|
||||
const webGLCtxAttribs: WebGLContextAttributes = {
|
||||
alpha: macro.ENABLE_TRANSPARENT_CANVAS,
|
||||
antialias: EDITOR || macro.ENABLE_WEBGL_ANTIALIAS,
|
||||
depth: true,
|
||||
stencil: true,
|
||||
premultipliedAlpha: false,
|
||||
preserveDrawingBuffer: false,
|
||||
powerPreference: 'default',
|
||||
failIfMajorPerformanceCaveat: false,
|
||||
};
|
||||
|
||||
this._webGLRC = this._canvas.getContext('webgl', webGLCtxAttribs);
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._webGLRC) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._webGLContextLostHandler = this._onWebGLContextLost.bind(this);
|
||||
this._canvas.addEventListener(eventWebGLContextLost, this._onWebGLContextLost);
|
||||
|
||||
const gl = this.gl;
|
||||
|
||||
this.stateCache.initialize(
|
||||
WebGLDeviceManager.instance.capabilities.maxTextureUnits,
|
||||
WebGLDeviceManager.instance.capabilities.maxVertexAttributes,
|
||||
);
|
||||
|
||||
this._extensions = getExtensions(gl);
|
||||
|
||||
// init states
|
||||
initStates(gl);
|
||||
|
||||
const colorFmt = Format.RGBA8;
|
||||
let depthStencilFmt = Format.UNKNOWN;
|
||||
|
||||
let depthBits = gl.getParameter(gl.DEPTH_BITS);
|
||||
const stencilBits = gl.getParameter(gl.STENCIL_BITS);
|
||||
|
||||
if (ALIPAY) {
|
||||
depthBits = 24;
|
||||
}
|
||||
|
||||
if (depthBits && stencilBits) depthStencilFmt = Format.DEPTH_STENCIL;
|
||||
else if (depthBits) depthStencilFmt = Format.DEPTH;
|
||||
|
||||
this._colorTexture = new WebGLTexture();
|
||||
// @ts-expect-error(2445) private initializer
|
||||
this._colorTexture.initAsSwapchainTexture({
|
||||
swapchain: this,
|
||||
format: colorFmt,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
});
|
||||
|
||||
this._depthStencilTexture = new WebGLTexture();
|
||||
// @ts-expect-error(2445) private initializer
|
||||
this._depthStencilTexture.initAsSwapchainTexture({
|
||||
swapchain: this,
|
||||
format: depthStencilFmt,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
});
|
||||
|
||||
// create default null texture
|
||||
this.nullTex2D = WebGLDeviceManager.instance.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
)) as WebGLTexture;
|
||||
|
||||
this.nullTexCube = WebGLDeviceManager.instance.createTexture(new TextureInfo(
|
||||
TextureType.CUBE,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
6,
|
||||
)) as WebGLTexture;
|
||||
|
||||
const nullTexRegion = new BufferTextureCopy();
|
||||
nullTexRegion.texExtent.width = 2;
|
||||
nullTexRegion.texExtent.height = 2;
|
||||
|
||||
const nullTexBuff = new Uint8Array(this.nullTex2D.size);
|
||||
nullTexBuff.fill(0);
|
||||
WebGLDeviceManager.instance.copyBuffersToTexture([nullTexBuff], this.nullTex2D, [nullTexRegion]);
|
||||
|
||||
nullTexRegion.texSubres.layerCount = 6;
|
||||
WebGLDeviceManager.instance.copyBuffersToTexture(
|
||||
[nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff],
|
||||
this.nullTexCube, [nullTexRegion],
|
||||
);
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
if (this._canvas && this._webGLContextLostHandler) {
|
||||
this._canvas.removeEventListener(eventWebGLContextLost, this._webGLContextLostHandler);
|
||||
this._webGLContextLostHandler = null;
|
||||
}
|
||||
|
||||
if (this.nullTex2D) {
|
||||
this.nullTex2D.destroy();
|
||||
this.nullTex2D = null!;
|
||||
}
|
||||
|
||||
if (this.nullTexCube) {
|
||||
this.nullTexCube.destroy();
|
||||
this.nullTexCube = null!;
|
||||
}
|
||||
|
||||
this._extensions = null;
|
||||
this._webGLRC = null;
|
||||
this._canvas = null;
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
if (this._canvas!.width !== width || this._canvas!.height !== height) {
|
||||
debug(`Resizing swapchain: ${width}x${height}`);
|
||||
this._canvas!.width = width;
|
||||
this._canvas!.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
private _onWebGLContextLost (event: Event) {
|
||||
warnID(11000);
|
||||
warn(event);
|
||||
// 2020.9.3: `preventDefault` is not available on some platforms
|
||||
// event.preventDefault();
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,10 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { TextureFlagBit, FormatSurfaceSize, TextureInfo, TextureViewInfo, IsPowerOf2 } from '../base/define';
|
||||
import { FormatSurfaceSize, TextureInfo, TextureViewInfo, IsPowerOf2, ISwapchainTextureInfo, TextureUsageBit, FormatInfos } from '../base/define';
|
||||
import { Texture } from '../base/texture';
|
||||
import { WebGLCmdFuncCreateTexture, WebGLCmdFuncDestroyTexture, WebGLCmdFuncResizeTexture } from './webgl-commands';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
import { IWebGLGPUTexture } from './webgl-gpu-objects';
|
||||
|
||||
export class WebGLTexture extends Texture {
|
||||
@@ -36,10 +36,10 @@ export class WebGLTexture extends Texture {
|
||||
|
||||
private _gpuTexture: IWebGLGPUTexture | null = null;
|
||||
|
||||
public initialize (info: TextureInfo | TextureViewInfo): boolean {
|
||||
public initialize (info: TextureInfo | TextureViewInfo, isSwapchainTexture?: boolean) {
|
||||
if ('texture' in info) {
|
||||
console.log('WebGL does not support texture view.');
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
this._type = info.type;
|
||||
@@ -81,19 +81,19 @@ export class WebGLTexture extends Texture {
|
||||
glWrapT: 0,
|
||||
glMinFilter: 0,
|
||||
glMagFilter: 0,
|
||||
|
||||
isSwapchainTexture: isSwapchainTexture || false,
|
||||
};
|
||||
|
||||
WebGLCmdFuncCreateTexture(this._device as WebGLDevice, this._gpuTexture);
|
||||
WebGLCmdFuncCreateTexture(WebGLDeviceManager.instance, this._gpuTexture);
|
||||
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
|
||||
return true;
|
||||
WebGLDeviceManager.instance.memoryStatus.textureSize += this._size;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuTexture) {
|
||||
WebGLCmdFuncDestroyTexture(this._device as WebGLDevice, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= this._size;
|
||||
WebGLCmdFuncDestroyTexture(WebGLDeviceManager.instance, this._gpuTexture);
|
||||
WebGLDeviceManager.instance.memoryStatus.textureSize -= this._size;
|
||||
this._gpuTexture = null;
|
||||
}
|
||||
}
|
||||
@@ -109,9 +109,20 @@ export class WebGLTexture extends Texture {
|
||||
this._gpuTexture.width = width;
|
||||
this._gpuTexture.height = height;
|
||||
this._gpuTexture.size = this._size;
|
||||
WebGLCmdFuncResizeTexture(this._device as WebGLDevice, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= oldSize;
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
WebGLCmdFuncResizeTexture(WebGLDeviceManager.instance, this._gpuTexture);
|
||||
WebGLDeviceManager.instance.memoryStatus.textureSize -= oldSize;
|
||||
WebGLDeviceManager.instance.memoryStatus.textureSize += this._size;
|
||||
}
|
||||
}
|
||||
|
||||
// ======================= Swapchain Specific ======================= //
|
||||
|
||||
protected initAsSwapchainTexture (info: ISwapchainTextureInfo) {
|
||||
const texInfo = new TextureInfo();
|
||||
texInfo.format = info.format;
|
||||
texInfo.usage = FormatInfos[info.format].hasDepth ? TextureUsageBit.DEPTH_STENCIL_ATTACHMENT : TextureUsageBit.COLOR_ATTACHMENT;
|
||||
texInfo.width = info.width;
|
||||
texInfo.height = info.height;
|
||||
this.initialize(texInfo, true);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-27
@@ -23,11 +23,11 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { SamplerInfo } from '../base/define';
|
||||
import { Sampler } from '../base/sampler';
|
||||
import { WebGL2CmdFuncCreateSampler, WebGL2CmdFuncDestroySampler } from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { IWebGL2GPUSampler } from './webgl2-gpu-objects';
|
||||
import { SamplerInfo } from '../../base/define';
|
||||
import { Sampler } from '../../base/states/sampler';
|
||||
import { WebGL2CmdFuncCreateSampler, WebGL2CmdFuncDestroySampler } from '../webgl2-commands';
|
||||
import { WebGL2DeviceManager } from '../webgl2-define';
|
||||
import { IWebGL2GPUSampler } from '../webgl2-gpu-objects';
|
||||
|
||||
export class WebGL2Sampler extends Sampler {
|
||||
public get gpuSampler (): IWebGL2GPUSampler {
|
||||
@@ -36,26 +36,17 @@ export class WebGL2Sampler extends Sampler {
|
||||
|
||||
private _gpuSampler: IWebGL2GPUSampler | null = null;
|
||||
|
||||
public initialize (info: SamplerInfo): boolean {
|
||||
this._minFilter = info.minFilter;
|
||||
this._magFilter = info.magFilter;
|
||||
this._mipFilter = info.mipFilter;
|
||||
this._addressU = info.addressU;
|
||||
this._addressV = info.addressV;
|
||||
this._addressW = info.addressW;
|
||||
this._maxAnisotropy = info.maxAnisotropy;
|
||||
this._cmpFunc = info.cmpFunc;
|
||||
this._borderColor = info.borderColor;
|
||||
this._mipLODBias = info.mipLODBias;
|
||||
constructor (info: SamplerInfo) {
|
||||
super(info);
|
||||
|
||||
this._gpuSampler = {
|
||||
glSampler: null,
|
||||
minFilter: this._minFilter,
|
||||
magFilter: this._magFilter,
|
||||
mipFilter: this._mipFilter,
|
||||
addressU: this._addressU,
|
||||
addressV: this._addressV,
|
||||
addressW: this._addressW,
|
||||
minFilter: this._info.minFilter,
|
||||
magFilter: this._info.magFilter,
|
||||
mipFilter: this._info.mipFilter,
|
||||
addressU: this._info.addressU,
|
||||
addressV: this._info.addressV,
|
||||
addressW: this._info.addressW,
|
||||
|
||||
glMinFilter: 0,
|
||||
glMagFilter: 0,
|
||||
@@ -64,14 +55,12 @@ export class WebGL2Sampler extends Sampler {
|
||||
glWrapR: 0,
|
||||
};
|
||||
|
||||
WebGL2CmdFuncCreateSampler(this._device as WebGL2Device, this._gpuSampler);
|
||||
|
||||
return true;
|
||||
WebGL2CmdFuncCreateSampler(WebGL2DeviceManager.instance, this._gpuSampler);
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
destroy () {
|
||||
if (this._gpuSampler) {
|
||||
WebGL2CmdFuncDestroySampler(this._device as WebGL2Device, this._gpuSampler);
|
||||
WebGL2CmdFuncDestroySampler(WebGL2DeviceManager.instance, this._gpuSampler);
|
||||
this._gpuSampler = null;
|
||||
}
|
||||
}
|
||||
@@ -24,15 +24,15 @@
|
||||
*/
|
||||
|
||||
import { Buffer } from '../base/buffer';
|
||||
import { BufferUsageBit, BufferSource, BufferInfo, BufferViewInfo, IndirectBuffer } from '../base/define';
|
||||
import { BufferUsageBit, BufferSource, BufferInfo, BufferViewInfo } from '../base/define';
|
||||
import {
|
||||
WebGL2CmdFuncCreateBuffer,
|
||||
WebGL2CmdFuncDestroyBuffer,
|
||||
WebGL2CmdFuncResizeBuffer,
|
||||
WebGL2CmdFuncUpdateBuffer,
|
||||
} from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { IWebGL2GPUBuffer } from './webgl2-gpu-objects';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
import { IWebGL2GPUBuffer, WebGL2IndirectDrawInfos } from './webgl2-gpu-objects';
|
||||
|
||||
export class WebGL2Buffer extends Buffer {
|
||||
get gpuBuffer (): IWebGL2GPUBuffer {
|
||||
@@ -41,7 +41,7 @@ export class WebGL2Buffer extends Buffer {
|
||||
|
||||
private _gpuBuffer: IWebGL2GPUBuffer | null = null;
|
||||
|
||||
public initialize (info: BufferInfo | BufferViewInfo): boolean {
|
||||
public initialize (info: BufferInfo | BufferViewInfo) {
|
||||
if ('buffer' in info) { // buffer view
|
||||
this._isBufferView = true;
|
||||
|
||||
@@ -72,39 +72,29 @@ export class WebGL2Buffer extends Buffer {
|
||||
this._count = this._size / this._stride;
|
||||
this._flags = info.flags;
|
||||
|
||||
if (this._usage & BufferUsageBit.INDIRECT) {
|
||||
this._indirectBuffer = new IndirectBuffer();
|
||||
}
|
||||
|
||||
this._gpuBuffer = {
|
||||
usage: this._usage,
|
||||
memUsage: this._memUsage,
|
||||
size: this._size,
|
||||
stride: this._stride,
|
||||
buffer: null,
|
||||
indirects: [],
|
||||
indirects: new WebGL2IndirectDrawInfos(),
|
||||
glTarget: 0,
|
||||
glBuffer: null,
|
||||
glOffset: 0,
|
||||
};
|
||||
|
||||
if (info.usage & BufferUsageBit.INDIRECT) {
|
||||
this._gpuBuffer.indirects = this._indirectBuffer!.drawInfos;
|
||||
}
|
||||
WebGL2CmdFuncCreateBuffer(WebGL2DeviceManager.instance, this._gpuBuffer);
|
||||
|
||||
WebGL2CmdFuncCreateBuffer(this._device as WebGL2Device, this._gpuBuffer);
|
||||
|
||||
this._device.memoryStatus.bufferSize += this._size;
|
||||
WebGL2DeviceManager.instance.memoryStatus.bufferSize += this._size;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuBuffer) {
|
||||
if (!this._isBufferView) {
|
||||
WebGL2CmdFuncDestroyBuffer(this._device as WebGL2Device, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= this._size;
|
||||
WebGL2CmdFuncDestroyBuffer(WebGL2DeviceManager.instance, this._gpuBuffer);
|
||||
WebGL2DeviceManager.instance.memoryStatus.bufferSize -= this._size;
|
||||
}
|
||||
this._gpuBuffer = null;
|
||||
}
|
||||
@@ -125,9 +115,9 @@ export class WebGL2Buffer extends Buffer {
|
||||
if (this._gpuBuffer) {
|
||||
this._gpuBuffer.size = size;
|
||||
if (size > 0) {
|
||||
WebGL2CmdFuncResizeBuffer(this._device as WebGL2Device, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= oldSize;
|
||||
this._device.memoryStatus.bufferSize += size;
|
||||
WebGL2CmdFuncResizeBuffer(WebGL2DeviceManager.instance, this._gpuBuffer);
|
||||
WebGL2DeviceManager.instance.memoryStatus.bufferSize -= oldSize;
|
||||
WebGL2DeviceManager.instance.memoryStatus.bufferSize += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,7 +138,7 @@ export class WebGL2Buffer extends Buffer {
|
||||
}
|
||||
|
||||
WebGL2CmdFuncUpdateBuffer(
|
||||
this._device as WebGL2Device,
|
||||
WebGL2DeviceManager.instance,
|
||||
this._gpuBuffer!,
|
||||
buffer,
|
||||
0,
|
||||
|
||||
@@ -49,7 +49,6 @@ import {
|
||||
WebGL2CmdPackage,
|
||||
WebGL2CmdUpdateBuffer,
|
||||
} from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { WebGL2Framebuffer } from './webgl2-framebuffer';
|
||||
import { IWebGL2GPUInputAssembler, IWebGL2GPUDescriptorSet, IWebGL2GPUPipelineState } from './webgl2-gpu-objects';
|
||||
import { WebGL2InputAssembler } from './webgl2-input-assembler';
|
||||
@@ -57,12 +56,14 @@ import { WebGL2PipelineState } from './webgl2-pipeline-state';
|
||||
import { WebGL2Texture } from './webgl2-texture';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { WebGL2RenderPass } from './webgl2-render-pass';
|
||||
import { GlobalBarrier } from '../base/global-barrier';
|
||||
import { TextureBarrier } from '../base/texture-barrier';
|
||||
import { GlobalBarrier } from '../base/states/global-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
|
||||
export class WebGL2CommandBuffer extends CommandBuffer {
|
||||
public cmdPackage: WebGL2CmdPackage = new WebGL2CmdPackage();
|
||||
protected _webGLAllocator: WebGL2CommandAllocator | null = null;
|
||||
|
||||
protected _cmdAllocator: WebGL2CommandAllocator = new WebGL2CommandAllocator();
|
||||
protected _isInRenderPass = false;
|
||||
protected _curGPUPipelineState: IWebGL2GPUPipelineState | null = null;
|
||||
protected _curGPUDescriptorSets: IWebGL2GPUDescriptorSet[] = [];
|
||||
@@ -71,29 +72,22 @@ export class WebGL2CommandBuffer extends CommandBuffer {
|
||||
protected _curDynamicStates: DynamicStates = new DynamicStates();
|
||||
protected _isStateInvalied = false;
|
||||
|
||||
public initialize (info: CommandBufferInfo): boolean {
|
||||
public initialize (info: CommandBufferInfo) {
|
||||
this._type = info.type;
|
||||
this._queue = info.queue;
|
||||
|
||||
this._webGLAllocator = (this._device as WebGL2Device).cmdAllocator;
|
||||
|
||||
const setCount = (this._device as WebGL2Device).bindingMappingInfo.bufferOffsets.length;
|
||||
const setCount = WebGL2DeviceManager.instance.bindingMappingInfo.bufferOffsets.length;
|
||||
for (let i = 0; i < setCount; i++) {
|
||||
this._curGPUDescriptorSets.push(null!);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._webGLAllocator) {
|
||||
this._webGLAllocator.clearCmds(this.cmdPackage);
|
||||
this._webGLAllocator = null;
|
||||
}
|
||||
this._cmdAllocator.clearCmds(this.cmdPackage);
|
||||
}
|
||||
|
||||
public begin (renderPass?: RenderPass, subpass = 0, frameBuffer?: Framebuffer) {
|
||||
this._webGLAllocator!.clearCmds(this.cmdPackage);
|
||||
this._cmdAllocator.clearCmds(this.cmdPackage);
|
||||
this._curGPUPipelineState = null;
|
||||
this._curGPUInputAssembler = null;
|
||||
this._curGPUDescriptorSets.length = 0;
|
||||
@@ -118,7 +112,7 @@ export class WebGL2CommandBuffer extends CommandBuffer {
|
||||
clearDepth: number,
|
||||
clearStencil: number,
|
||||
) {
|
||||
const cmd = this._webGLAllocator!.beginRenderPassCmdPool.alloc(WebGL2CmdBeginRenderPass);
|
||||
const cmd = this._cmdAllocator.beginRenderPassCmdPool.alloc(WebGL2CmdBeginRenderPass);
|
||||
cmd.gpuRenderPass = (renderPass as WebGL2RenderPass).gpuRenderPass;
|
||||
cmd.gpuFramebuffer = (framebuffer as WebGL2Framebuffer).gpuFramebuffer;
|
||||
cmd.renderArea = renderArea;
|
||||
@@ -279,22 +273,16 @@ export class WebGL2CommandBuffer extends CommandBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
public draw (info: DrawInfo | InputAssembler) {
|
||||
public draw (infoOrAssembler: DrawInfo | InputAssembler) {
|
||||
if (this._type === CommandBufferType.PRIMARY && this._isInRenderPass
|
||||
|| this._type === CommandBufferType.SECONDARY) {
|
||||
if (this._isStateInvalied) {
|
||||
this.bindStates();
|
||||
}
|
||||
const info = 'drawInfo' in infoOrAssembler ? infoOrAssembler.drawInfo : infoOrAssembler;
|
||||
|
||||
const cmd = this._webGLAllocator!.drawCmdPool.alloc(WebGL2CmdDraw);
|
||||
// cmd.drawInfo = inputAssembler;
|
||||
cmd.drawInfo.vertexCount = info.vertexCount;
|
||||
cmd.drawInfo.firstVertex = info.firstVertex;
|
||||
cmd.drawInfo.indexCount = info.indexCount;
|
||||
cmd.drawInfo.firstIndex = info.firstIndex;
|
||||
cmd.drawInfo.vertexOffset = info.vertexOffset;
|
||||
cmd.drawInfo.instanceCount = info.instanceCount;
|
||||
cmd.drawInfo.firstInstance = info.firstInstance;
|
||||
const cmd = this._cmdAllocator.drawCmdPool.alloc(WebGL2CmdDraw);
|
||||
cmd.drawInfo.copy(info);
|
||||
this.cmdPackage.drawCmds.push(cmd);
|
||||
|
||||
this.cmdPackage.cmds.push(WebGL2Cmd.DRAW);
|
||||
@@ -327,7 +315,7 @@ export class WebGL2CommandBuffer extends CommandBuffer {
|
||||
|| this._type === CommandBufferType.SECONDARY) {
|
||||
const gpuBuffer = (buffer as WebGL2Buffer).gpuBuffer;
|
||||
if (gpuBuffer) {
|
||||
const cmd = this._webGLAllocator!.updateBufferCmdPool.alloc(WebGL2CmdUpdateBuffer);
|
||||
const cmd = this._cmdAllocator.updateBufferCmdPool.alloc(WebGL2CmdUpdateBuffer);
|
||||
let buffSize = 0;
|
||||
let buff: BufferSource | null = null;
|
||||
|
||||
@@ -362,7 +350,7 @@ export class WebGL2CommandBuffer extends CommandBuffer {
|
||||
|| this._type === CommandBufferType.SECONDARY) {
|
||||
const gpuTexture = (texture as WebGL2Texture).gpuTexture;
|
||||
if (gpuTexture) {
|
||||
const cmd = this._webGLAllocator!.copyBufferToTextureCmdPool.alloc(WebGL2CmdCopyBufferToTexture);
|
||||
const cmd = this._cmdAllocator.copyBufferToTextureCmdPool.alloc(WebGL2CmdCopyBufferToTexture);
|
||||
cmd.gpuTexture = gpuTexture;
|
||||
cmd.regions = regions;
|
||||
// TODO: Have to copy to staging buffer first to make this work for the execution is deferred.
|
||||
@@ -419,15 +407,10 @@ export class WebGL2CommandBuffer extends CommandBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
public pipelineBarrier (globalBarrier: GlobalBarrier, textureBarriers: TextureBarrier[]) {
|
||||
}
|
||||
|
||||
public get webGLDevice (): WebGL2Device {
|
||||
return this._device as WebGL2Device;
|
||||
}
|
||||
public pipelineBarrier (globalBarrier: GlobalBarrier | null, textureBarriers?: TextureBarrier[], textures?: Texture[]) {}
|
||||
|
||||
protected bindStates () {
|
||||
const bindStatesCmd = this._webGLAllocator!.bindStatesCmdPool.alloc(WebGL2CmdBindStates);
|
||||
const bindStatesCmd = this._cmdAllocator.bindStatesCmdPool.alloc(WebGL2CmdBindStates);
|
||||
bindStatesCmd.gpuPipelineState = this._curGPUPipelineState;
|
||||
Array.prototype.push.apply(bindStatesCmd.gpuDescriptorSets, this._curGPUDescriptorSets);
|
||||
Array.prototype.push.apply(bindStatesCmd.dynamicOffsets, this._curDynamicOffsets);
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
FormatInfos, FormatSize, LoadOp, MemoryUsageBit, SampleCount, ShaderStageFlagBit, TextureFlagBit,
|
||||
Color, Rect, BufferTextureCopy, BufferSource, DrawInfo, IndirectBuffer, UniformBlock, DynamicStates,
|
||||
} from '../base/define';
|
||||
import { WebGLEXT } from '../webgl/webgl-define';
|
||||
import { WebGL2EXT } from './webgl2-define';
|
||||
import { WebGL2CommandAllocator } from './webgl2-command-allocator';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import {
|
||||
@@ -121,12 +121,8 @@ export function GFXFormatToWebGLType (format: Format, gl: WebGL2RenderingContext
|
||||
case Format.RGB10A2UI: return gl.UNSIGNED_INT_2_10_10_10_REV;
|
||||
case Format.RGB9E5: return gl.FLOAT;
|
||||
|
||||
case Format.D16: return gl.UNSIGNED_SHORT;
|
||||
case Format.D16S8: return gl.UNSIGNED_INT_24_8; // no D16S8 support
|
||||
case Format.D24: return gl.UNSIGNED_INT;
|
||||
case Format.D24S8: return gl.UNSIGNED_INT_24_8;
|
||||
case Format.D32F: return gl.FLOAT;
|
||||
case Format.D32F_S8: return gl.FLOAT_32_UNSIGNED_INT_24_8_REV;
|
||||
case Format.DEPTH: return gl.FLOAT;
|
||||
case Format.DEPTH_STENCIL: return gl.FLOAT_32_UNSIGNED_INT_24_8_REV;
|
||||
|
||||
case Format.BC1: return gl.UNSIGNED_BYTE;
|
||||
case Format.BC1_SRGB: return gl.UNSIGNED_BYTE;
|
||||
@@ -250,68 +246,64 @@ export function GFXFormatToWebGLInternalFormat (format: Format, gl: WebGL2Render
|
||||
case Format.RGB10A2: return gl.RGB10_A2;
|
||||
case Format.RGB10A2UI: return gl.RGB10_A2UI;
|
||||
case Format.R11G11B10F: return gl.R11F_G11F_B10F;
|
||||
case Format.D16: return gl.DEPTH_COMPONENT16;
|
||||
case Format.D16S8: return gl.DEPTH24_STENCIL8; // no D16S8 support
|
||||
case Format.D24: return gl.DEPTH_COMPONENT24;
|
||||
case Format.D24S8: return gl.DEPTH24_STENCIL8;
|
||||
case Format.D32F: return gl.DEPTH_COMPONENT32F;
|
||||
case Format.D32F_S8: return gl.DEPTH32F_STENCIL8;
|
||||
case Format.DEPTH: return gl.DEPTH_COMPONENT32F;
|
||||
case Format.DEPTH_STENCIL: return gl.DEPTH32F_STENCIL8;
|
||||
|
||||
case Format.BC1: return WebGLEXT.COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_ALPHA: return WebGLEXT.COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB: return WebGLEXT.COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB_ALPHA: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
|
||||
case Format.BC2: return WebGLEXT.COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case Format.BC2_SRGB: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
|
||||
case Format.BC3: return WebGLEXT.COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case Format.BC3_SRGB: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
||||
case Format.BC1: return WebGL2EXT.COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_ALPHA: return WebGL2EXT.COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB: return WebGL2EXT.COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB_ALPHA: return WebGL2EXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
|
||||
case Format.BC2: return WebGL2EXT.COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case Format.BC2_SRGB: return WebGL2EXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
|
||||
case Format.BC3: return WebGL2EXT.COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case Format.BC3_SRGB: return WebGL2EXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
||||
|
||||
case Format.ETC_RGB8: return WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL;
|
||||
case Format.ETC2_RGB8: return WebGLEXT.COMPRESSED_RGB8_ETC2;
|
||||
case Format.ETC2_SRGB8: return WebGLEXT.COMPRESSED_SRGB8_ETC2;
|
||||
case Format.ETC2_RGB8_A1: return WebGLEXT.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_SRGB8_A1: return WebGLEXT.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_RGBA8: return WebGLEXT.COMPRESSED_RGBA8_ETC2_EAC;
|
||||
case Format.ETC2_SRGB8_A8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
|
||||
case Format.EAC_R11: return WebGLEXT.COMPRESSED_R11_EAC;
|
||||
case Format.EAC_R11SN: return WebGLEXT.COMPRESSED_SIGNED_R11_EAC;
|
||||
case Format.EAC_RG11: return WebGLEXT.COMPRESSED_RG11_EAC;
|
||||
case Format.EAC_RG11SN: return WebGLEXT.COMPRESSED_SIGNED_RG11_EAC;
|
||||
case Format.ETC_RGB8: return WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL;
|
||||
case Format.ETC2_RGB8: return WebGL2EXT.COMPRESSED_RGB8_ETC2;
|
||||
case Format.ETC2_SRGB8: return WebGL2EXT.COMPRESSED_SRGB8_ETC2;
|
||||
case Format.ETC2_RGB8_A1: return WebGL2EXT.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_SRGB8_A1: return WebGL2EXT.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_RGBA8: return WebGL2EXT.COMPRESSED_RGBA8_ETC2_EAC;
|
||||
case Format.ETC2_SRGB8_A8: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
|
||||
case Format.EAC_R11: return WebGL2EXT.COMPRESSED_R11_EAC;
|
||||
case Format.EAC_R11SN: return WebGL2EXT.COMPRESSED_SIGNED_R11_EAC;
|
||||
case Format.EAC_RG11: return WebGL2EXT.COMPRESSED_RG11_EAC;
|
||||
case Format.EAC_RG11SN: return WebGL2EXT.COMPRESSED_SIGNED_RG11_EAC;
|
||||
|
||||
case Format.PVRTC_RGB2: return WebGLEXT.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA2: return WebGLEXT.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGB4: return WebGLEXT.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA4: return WebGLEXT.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
|
||||
case Format.PVRTC_RGB2: return WebGL2EXT.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA2: return WebGL2EXT.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGB4: return WebGL2EXT.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA4: return WebGL2EXT.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
|
||||
|
||||
case Format.ASTC_RGBA_4X4: return WebGLEXT.COMPRESSED_RGBA_ASTC_4x4_KHR;
|
||||
case Format.ASTC_RGBA_5X4: return WebGLEXT.COMPRESSED_RGBA_ASTC_5x4_KHR;
|
||||
case Format.ASTC_RGBA_5X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_5x5_KHR;
|
||||
case Format.ASTC_RGBA_6X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_6x5_KHR;
|
||||
case Format.ASTC_RGBA_6X6: return WebGLEXT.COMPRESSED_RGBA_ASTC_6x6_KHR;
|
||||
case Format.ASTC_RGBA_8X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_8x5_KHR;
|
||||
case Format.ASTC_RGBA_8X6: return WebGLEXT.COMPRESSED_RGBA_ASTC_8x6_KHR;
|
||||
case Format.ASTC_RGBA_8X8: return WebGLEXT.COMPRESSED_RGBA_ASTC_8x8_KHR;
|
||||
case Format.ASTC_RGBA_10X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x5_KHR;
|
||||
case Format.ASTC_RGBA_10X6: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x6_KHR;
|
||||
case Format.ASTC_RGBA_10X8: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x8_KHR;
|
||||
case Format.ASTC_RGBA_10X10: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x10_KHR;
|
||||
case Format.ASTC_RGBA_12X10: return WebGLEXT.COMPRESSED_RGBA_ASTC_12x10_KHR;
|
||||
case Format.ASTC_RGBA_12X12: return WebGLEXT.COMPRESSED_RGBA_ASTC_12x12_KHR;
|
||||
case Format.ASTC_RGBA_4X4: return WebGL2EXT.COMPRESSED_RGBA_ASTC_4x4_KHR;
|
||||
case Format.ASTC_RGBA_5X4: return WebGL2EXT.COMPRESSED_RGBA_ASTC_5x4_KHR;
|
||||
case Format.ASTC_RGBA_5X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_5x5_KHR;
|
||||
case Format.ASTC_RGBA_6X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_6x5_KHR;
|
||||
case Format.ASTC_RGBA_6X6: return WebGL2EXT.COMPRESSED_RGBA_ASTC_6x6_KHR;
|
||||
case Format.ASTC_RGBA_8X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_8x5_KHR;
|
||||
case Format.ASTC_RGBA_8X6: return WebGL2EXT.COMPRESSED_RGBA_ASTC_8x6_KHR;
|
||||
case Format.ASTC_RGBA_8X8: return WebGL2EXT.COMPRESSED_RGBA_ASTC_8x8_KHR;
|
||||
case Format.ASTC_RGBA_10X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x5_KHR;
|
||||
case Format.ASTC_RGBA_10X6: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x6_KHR;
|
||||
case Format.ASTC_RGBA_10X8: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x8_KHR;
|
||||
case Format.ASTC_RGBA_10X10: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x10_KHR;
|
||||
case Format.ASTC_RGBA_12X10: return WebGL2EXT.COMPRESSED_RGBA_ASTC_12x10_KHR;
|
||||
case Format.ASTC_RGBA_12X12: return WebGL2EXT.COMPRESSED_RGBA_ASTC_12x12_KHR;
|
||||
|
||||
case Format.ASTC_SRGBA_4X4: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X4: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X6: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
|
||||
case Format.ASTC_SRGBA_8X6: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
|
||||
case Format.ASTC_SRGBA_10X6: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
|
||||
case Format.ASTC_SRGBA_10X8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X10: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X10: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X12: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
|
||||
case Format.ASTC_SRGBA_4X4: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X4: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X6: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
|
||||
case Format.ASTC_SRGBA_8X6: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X8: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
|
||||
case Format.ASTC_SRGBA_10X6: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
|
||||
case Format.ASTC_SRGBA_10X8: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X10: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X10: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X12: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
|
||||
|
||||
default: {
|
||||
console.error('Unsupported Format, convert to WebGL internal format failed.');
|
||||
@@ -373,68 +365,64 @@ export function GFXFormatToWebGLFormat (format: Format, gl: WebGL2RenderingConte
|
||||
case Format.RGBA4: return gl.RGBA;
|
||||
case Format.SRGB8: return gl.RGB;
|
||||
case Format.SRGB8_A8: return gl.RGBA;
|
||||
case Format.D16: return gl.DEPTH_COMPONENT;
|
||||
case Format.D16S8: return gl.DEPTH_STENCIL;
|
||||
case Format.D24: return gl.DEPTH_COMPONENT;
|
||||
case Format.D24S8: return gl.DEPTH_STENCIL;
|
||||
case Format.D32F: return gl.DEPTH_COMPONENT;
|
||||
case Format.D32F_S8: return gl.DEPTH_STENCIL;
|
||||
case Format.DEPTH: return gl.DEPTH_COMPONENT;
|
||||
case Format.DEPTH_STENCIL: return gl.DEPTH_STENCIL;
|
||||
|
||||
case Format.BC1: return WebGLEXT.COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_ALPHA: return WebGLEXT.COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB: return WebGLEXT.COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB_ALPHA: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
|
||||
case Format.BC2: return WebGLEXT.COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case Format.BC2_SRGB: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
|
||||
case Format.BC3: return WebGLEXT.COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case Format.BC3_SRGB: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
||||
case Format.BC1: return WebGL2EXT.COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_ALPHA: return WebGL2EXT.COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB: return WebGL2EXT.COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
||||
case Format.BC1_SRGB_ALPHA: return WebGL2EXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
|
||||
case Format.BC2: return WebGL2EXT.COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case Format.BC2_SRGB: return WebGL2EXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
|
||||
case Format.BC3: return WebGL2EXT.COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case Format.BC3_SRGB: return WebGL2EXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
||||
|
||||
case Format.ETC_RGB8: return WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL;
|
||||
case Format.ETC2_RGB8: return WebGLEXT.COMPRESSED_RGB8_ETC2;
|
||||
case Format.ETC2_SRGB8: return WebGLEXT.COMPRESSED_SRGB8_ETC2;
|
||||
case Format.ETC2_RGB8_A1: return WebGLEXT.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_SRGB8_A1: return WebGLEXT.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_RGBA8: return WebGLEXT.COMPRESSED_RGBA8_ETC2_EAC;
|
||||
case Format.ETC2_SRGB8_A8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
|
||||
case Format.EAC_R11: return WebGLEXT.COMPRESSED_R11_EAC;
|
||||
case Format.EAC_R11SN: return WebGLEXT.COMPRESSED_SIGNED_R11_EAC;
|
||||
case Format.EAC_RG11: return WebGLEXT.COMPRESSED_RG11_EAC;
|
||||
case Format.EAC_RG11SN: return WebGLEXT.COMPRESSED_SIGNED_RG11_EAC;
|
||||
case Format.ETC_RGB8: return WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL;
|
||||
case Format.ETC2_RGB8: return WebGL2EXT.COMPRESSED_RGB8_ETC2;
|
||||
case Format.ETC2_SRGB8: return WebGL2EXT.COMPRESSED_SRGB8_ETC2;
|
||||
case Format.ETC2_RGB8_A1: return WebGL2EXT.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_SRGB8_A1: return WebGL2EXT.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
case Format.ETC2_RGBA8: return WebGL2EXT.COMPRESSED_RGBA8_ETC2_EAC;
|
||||
case Format.ETC2_SRGB8_A8: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
|
||||
case Format.EAC_R11: return WebGL2EXT.COMPRESSED_R11_EAC;
|
||||
case Format.EAC_R11SN: return WebGL2EXT.COMPRESSED_SIGNED_R11_EAC;
|
||||
case Format.EAC_RG11: return WebGL2EXT.COMPRESSED_RG11_EAC;
|
||||
case Format.EAC_RG11SN: return WebGL2EXT.COMPRESSED_SIGNED_RG11_EAC;
|
||||
|
||||
case Format.PVRTC_RGB2: return WebGLEXT.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA2: return WebGLEXT.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGB4: return WebGLEXT.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA4: return WebGLEXT.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
|
||||
case Format.PVRTC_RGB2: return WebGL2EXT.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA2: return WebGL2EXT.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
|
||||
case Format.PVRTC_RGB4: return WebGL2EXT.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
|
||||
case Format.PVRTC_RGBA4: return WebGL2EXT.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
|
||||
|
||||
case Format.ASTC_RGBA_4X4: return WebGLEXT.COMPRESSED_RGBA_ASTC_4x4_KHR;
|
||||
case Format.ASTC_RGBA_5X4: return WebGLEXT.COMPRESSED_RGBA_ASTC_5x4_KHR;
|
||||
case Format.ASTC_RGBA_5X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_5x5_KHR;
|
||||
case Format.ASTC_RGBA_6X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_6x5_KHR;
|
||||
case Format.ASTC_RGBA_6X6: return WebGLEXT.COMPRESSED_RGBA_ASTC_6x6_KHR;
|
||||
case Format.ASTC_RGBA_8X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_8x5_KHR;
|
||||
case Format.ASTC_RGBA_8X6: return WebGLEXT.COMPRESSED_RGBA_ASTC_8x6_KHR;
|
||||
case Format.ASTC_RGBA_8X8: return WebGLEXT.COMPRESSED_RGBA_ASTC_8x8_KHR;
|
||||
case Format.ASTC_RGBA_10X5: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x5_KHR;
|
||||
case Format.ASTC_RGBA_10X6: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x6_KHR;
|
||||
case Format.ASTC_RGBA_10X8: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x8_KHR;
|
||||
case Format.ASTC_RGBA_10X10: return WebGLEXT.COMPRESSED_RGBA_ASTC_10x10_KHR;
|
||||
case Format.ASTC_RGBA_12X10: return WebGLEXT.COMPRESSED_RGBA_ASTC_12x10_KHR;
|
||||
case Format.ASTC_RGBA_12X12: return WebGLEXT.COMPRESSED_RGBA_ASTC_12x12_KHR;
|
||||
case Format.ASTC_RGBA_4X4: return WebGL2EXT.COMPRESSED_RGBA_ASTC_4x4_KHR;
|
||||
case Format.ASTC_RGBA_5X4: return WebGL2EXT.COMPRESSED_RGBA_ASTC_5x4_KHR;
|
||||
case Format.ASTC_RGBA_5X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_5x5_KHR;
|
||||
case Format.ASTC_RGBA_6X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_6x5_KHR;
|
||||
case Format.ASTC_RGBA_6X6: return WebGL2EXT.COMPRESSED_RGBA_ASTC_6x6_KHR;
|
||||
case Format.ASTC_RGBA_8X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_8x5_KHR;
|
||||
case Format.ASTC_RGBA_8X6: return WebGL2EXT.COMPRESSED_RGBA_ASTC_8x6_KHR;
|
||||
case Format.ASTC_RGBA_8X8: return WebGL2EXT.COMPRESSED_RGBA_ASTC_8x8_KHR;
|
||||
case Format.ASTC_RGBA_10X5: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x5_KHR;
|
||||
case Format.ASTC_RGBA_10X6: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x6_KHR;
|
||||
case Format.ASTC_RGBA_10X8: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x8_KHR;
|
||||
case Format.ASTC_RGBA_10X10: return WebGL2EXT.COMPRESSED_RGBA_ASTC_10x10_KHR;
|
||||
case Format.ASTC_RGBA_12X10: return WebGL2EXT.COMPRESSED_RGBA_ASTC_12x10_KHR;
|
||||
case Format.ASTC_RGBA_12X12: return WebGL2EXT.COMPRESSED_RGBA_ASTC_12x12_KHR;
|
||||
|
||||
case Format.ASTC_SRGBA_4X4: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X4: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X6: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
|
||||
case Format.ASTC_SRGBA_8X6: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X5: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
|
||||
case Format.ASTC_SRGBA_10X6: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
|
||||
case Format.ASTC_SRGBA_10X8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X10: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X10: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X12: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
|
||||
case Format.ASTC_SRGBA_4X4: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X4: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
|
||||
case Format.ASTC_SRGBA_5X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
|
||||
case Format.ASTC_SRGBA_6X6: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
|
||||
case Format.ASTC_SRGBA_8X6: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
|
||||
case Format.ASTC_SRGBA_8X8: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X5: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
|
||||
case Format.ASTC_SRGBA_10X6: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
|
||||
case Format.ASTC_SRGBA_10X8: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
|
||||
case Format.ASTC_SRGBA_10X10: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X10: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
|
||||
case Format.ASTC_SRGBA_12X12: return WebGL2EXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
|
||||
|
||||
default: {
|
||||
console.error('Unsupported Format, convert to WebGL format failed.');
|
||||
@@ -779,7 +767,7 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2Device, gpuBuffer: IWeb
|
||||
if (glBuffer) {
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
@@ -803,7 +791,7 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2Device, gpuBuffer: IWeb
|
||||
if (glBuffer) {
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
@@ -855,7 +843,7 @@ export function WebGL2CmdFuncDestroyBuffer (device: WebGL2Device, gpuBuffer: IWe
|
||||
// can be reproduced in the static batching scene at https://github.com/cocos-creator/test-cases-3d
|
||||
switch (gpuBuffer.glTarget) {
|
||||
case gl.ARRAY_BUFFER:
|
||||
if (device.useVAO && device.stateCache.glVAO) {
|
||||
if (device.extensions.useVAO && device.stateCache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
device.stateCache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
@@ -863,7 +851,7 @@ export function WebGL2CmdFuncDestroyBuffer (device: WebGL2Device, gpuBuffer: IWe
|
||||
device.stateCache.glArrayBuffer = null;
|
||||
break;
|
||||
case gl.ELEMENT_ARRAY_BUFFER:
|
||||
if (device.useVAO && device.stateCache.glVAO) {
|
||||
if (device.extensions.useVAO && device.stateCache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
device.stateCache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
}
|
||||
@@ -888,7 +876,7 @@ export function WebGL2CmdFuncResizeBuffer (device: WebGL2Device, gpuBuffer: IWeb
|
||||
const glUsage: GLenum = gpuBuffer.memUsage & MemoryUsageBit.HOST ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
|
||||
|
||||
if (gpuBuffer.usage & BufferUsageBit.VERTEX) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
@@ -907,7 +895,7 @@ export function WebGL2CmdFuncResizeBuffer (device: WebGL2Device, gpuBuffer: IWeb
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
||||
cache.glArrayBuffer = null;
|
||||
} else if (gpuBuffer.usage & BufferUsageBit.INDEX) {
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = gfxStateCache.gpuInputAssembler = null;
|
||||
@@ -945,8 +933,11 @@ export function WebGL2CmdFuncResizeBuffer (device: WebGL2Device, gpuBuffer: IWeb
|
||||
|
||||
export function WebGL2CmdFuncUpdateBuffer (device: WebGL2Device, gpuBuffer: IWebGL2GPUBuffer, buffer: BufferSource, offset: number, size: number) {
|
||||
if (gpuBuffer.usage & BufferUsageBit.INDIRECT) {
|
||||
gpuBuffer.indirects.length = offset;
|
||||
Array.prototype.push.apply(gpuBuffer.indirects, (buffer as IndirectBuffer).drawInfos);
|
||||
gpuBuffer.indirects.clearDraws();
|
||||
const drawInfos = (buffer as IndirectBuffer).drawInfos;
|
||||
for (let i = 0; i < drawInfos.length; ++i) {
|
||||
gpuBuffer.indirects.setDrawInfo(offset + i, drawInfos[i]);
|
||||
}
|
||||
} else {
|
||||
const buff = buffer as ArrayBuffer;
|
||||
const { gl } = device;
|
||||
@@ -1022,13 +1013,14 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW
|
||||
switch (gpuTexture.type) {
|
||||
case TextureType.TEX2D: {
|
||||
gpuTexture.glTarget = gl.TEXTURE_2D;
|
||||
if (gpuTexture.isSwapchainTexture) break;
|
||||
|
||||
const maxSize = Math.max(w, h);
|
||||
if (maxSize > device.capabilities.maxTextureSize) {
|
||||
errorID(9100, maxSize, device.capabilities.maxTextureSize);
|
||||
}
|
||||
|
||||
if (gpuTexture.samples === SampleCount.X1) {
|
||||
if (gpuTexture.samples === SampleCount.ONE) {
|
||||
const glTexture = gl.createTexture();
|
||||
if (glTexture && gpuTexture.size > 0) {
|
||||
gpuTexture.glTexture = glTexture;
|
||||
@@ -1039,20 +1031,12 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW
|
||||
glTexUnit.glTexture = gpuTexture.glTexture;
|
||||
}
|
||||
|
||||
if (gpuTexture.glInternalFmt === WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
if (gpuTexture.glInternalFmt === WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
// init 2 x 2 texture
|
||||
const imgSize = FormatSize(gpuTexture.format, 2, 2, 1);
|
||||
const view: Uint8Array = new Uint8Array(imgSize);
|
||||
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, gpuTexture.glInternalFmt, 2, 2, 0, view);
|
||||
} else if (gpuTexture.flags & TextureFlagBit.IMMUTABLE) {
|
||||
gl.texStorage2D(gl.TEXTURE_2D, gpuTexture.mipLevel, gpuTexture.glInternalFmt, w, h);
|
||||
} else if (!FormatInfos[gpuTexture.format].isCompressed) {
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
gl.texImage2D(gl.TEXTURE_2D, i, gpuTexture.glInternalFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
} else {
|
||||
} else if (FormatInfos[gpuTexture.format].isCompressed) {
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
const imgSize = FormatSize(gpuTexture.format, w, h, 1);
|
||||
const view: Uint8Array = new Uint8Array(imgSize);
|
||||
@@ -1060,6 +1044,14 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
} else if (!(gpuTexture.flags & TextureFlagBit.RESIZABLE)) {
|
||||
gl.texStorage2D(gl.TEXTURE_2D, gpuTexture.mipLevel, gpuTexture.glInternalFmt, w, h);
|
||||
} else {
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
gl.texImage2D(gl.TEXTURE_2D, i, gpuTexture.glInternalFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gl.deleteTexture(glTexture);
|
||||
@@ -1097,24 +1089,13 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW
|
||||
glTexUnit.glTexture = gpuTexture.glTexture;
|
||||
}
|
||||
|
||||
if (gpuTexture.glInternalFmt === WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
if (gpuTexture.glInternalFmt === WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
for (let f = 0; f < 6; ++f) {
|
||||
const imgSize = FormatSize(gpuTexture.format, 2, 2, 1);
|
||||
const view: Uint8Array = new Uint8Array(imgSize);
|
||||
gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, 0, gpuTexture.glInternalFmt, 2, 2, 0, view);
|
||||
}
|
||||
} else if (gpuTexture.flags & TextureFlagBit.IMMUTABLE) {
|
||||
gl.texStorage2D(gl.TEXTURE_CUBE_MAP, gpuTexture.mipLevel, gpuTexture.glInternalFmt, w, h);
|
||||
} else if (!FormatInfos[gpuTexture.format].isCompressed) {
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
for (let f = 0; f < 6; ++f) {
|
||||
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, i,
|
||||
gpuTexture.glInternalFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
|
||||
}
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
} else {
|
||||
} else if (FormatInfos[gpuTexture.format].isCompressed) {
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
const imgSize = FormatSize(gpuTexture.format, w, h, 1);
|
||||
const view: Uint8Array = new Uint8Array(imgSize);
|
||||
@@ -1124,6 +1105,17 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
} else if (!(gpuTexture.flags & TextureFlagBit.RESIZABLE)) {
|
||||
gl.texStorage2D(gl.TEXTURE_CUBE_MAP, gpuTexture.mipLevel, gpuTexture.glInternalFmt, w, h);
|
||||
} else {
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
for (let f = 0; f < 6; ++f) {
|
||||
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, i,
|
||||
gpuTexture.glInternalFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
|
||||
}
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1163,7 +1155,7 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2Device, gpuTexture: IW
|
||||
errorID(9100, maxSize, device.capabilities.maxTextureSize);
|
||||
}
|
||||
|
||||
if (gpuTexture.samples === SampleCount.X1) {
|
||||
if (gpuTexture.samples === SampleCount.ONE) {
|
||||
const glTexUnit = device.stateCache.glTexUnits[device.stateCache.texUnit];
|
||||
|
||||
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
|
||||
@@ -1177,7 +1169,7 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2Device, gpuTexture: IW
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
} else if (gpuTexture.glInternalFmt !== WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
} else if (gpuTexture.glInternalFmt !== WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
const imgSize = FormatSize(gpuTexture.format, w, h, 1);
|
||||
const view: Uint8Array = new Uint8Array(imgSize);
|
||||
@@ -1224,7 +1216,7 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2Device, gpuTexture: IW
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
}
|
||||
} else if (gpuTexture.glInternalFmt !== WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
} else if (gpuTexture.glInternalFmt !== WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
for (let f = 0; f < 6; ++f) {
|
||||
w = gpuTexture.width;
|
||||
h = gpuTexture.height;
|
||||
@@ -1296,7 +1288,12 @@ export function WebGL2CmdFuncDestroySampler (device: WebGL2Device, gpuSampler: I
|
||||
}
|
||||
|
||||
export function WebGL2CmdFuncCreateFramebuffer (device: WebGL2Device, gpuFramebuffer: IWebGL2GPUFramebuffer) {
|
||||
if (!gpuFramebuffer.gpuColorTextures.length && !gpuFramebuffer.gpuDepthStencilTexture) { return; } // onscreen fbo
|
||||
let isOnscreen = false;
|
||||
for (let i = 0; i < gpuFramebuffer.gpuColorTextures.length; ++i) {
|
||||
if (!gpuFramebuffer.gpuColorTextures[i].glTexture) isOnscreen = true;
|
||||
}
|
||||
if (gpuFramebuffer.gpuDepthStencilTexture && !gpuFramebuffer.gpuDepthStencilTexture.glTexture) isOnscreen = true;
|
||||
if (isOnscreen) return;
|
||||
|
||||
const { gl } = device;
|
||||
const attachments: GLenum[] = [];
|
||||
@@ -1591,8 +1588,8 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
// Note: getUniformLocation return Object on wechat platform.
|
||||
if (glLoc !== null && (typeof glLoc === 'number' || (glLoc as any).id !== -1)) {
|
||||
// wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
}
|
||||
@@ -2205,7 +2202,7 @@ export function WebGL2CmdFuncBindStates (
|
||||
if (gpuTexture.glTexture) {
|
||||
gl.bindTexture(gpuTexture.glTarget, gpuTexture.glTexture);
|
||||
} else {
|
||||
gl.bindTexture(gpuTexture.glTarget, device.nullTex2D!.gpuTexture.glTexture);
|
||||
gl.bindTexture(gpuTexture.glTarget, device.nullTex2D.gpuTexture.glTexture);
|
||||
}
|
||||
glTexUnit.glTexture = gpuTexture.glTexture;
|
||||
}
|
||||
@@ -2227,7 +2224,7 @@ export function WebGL2CmdFuncBindStates (
|
||||
&& (isShaderChanged || gfxStateCache.gpuInputAssembler !== gpuInputAssembler)) {
|
||||
gfxStateCache.gpuInputAssembler = gpuInputAssembler;
|
||||
|
||||
if (device.useVAO) {
|
||||
if (device.extensions.useVAO) {
|
||||
// check vao
|
||||
let glVAO = gpuInputAssembler.glVAOs.get(gpuShader.glProgram!);
|
||||
if (!glVAO) {
|
||||
@@ -2446,45 +2443,76 @@ export function WebGL2CmdFuncBindStates (
|
||||
export function WebGL2CmdFuncDraw (device: WebGL2Device, drawInfo: DrawInfo) {
|
||||
const { gl } = device;
|
||||
const { gpuInputAssembler, glPrimitive } = gfxStateCache;
|
||||
const md = device.extensions.WEBGL_multi_draw;
|
||||
|
||||
if (gpuInputAssembler) {
|
||||
const indexBuffer = gpuInputAssembler.gpuIndexBuffer;
|
||||
if (gpuInputAssembler.gpuIndirectBuffer) {
|
||||
const { indirects } = gpuInputAssembler.gpuIndirectBuffer;
|
||||
for (let k = 0; k < indirects.length; k++) {
|
||||
const subDrawInfo = indirects[k];
|
||||
const gpuBuffer = gpuInputAssembler.gpuIndexBuffer;
|
||||
if (subDrawInfo.instanceCount) {
|
||||
if (gpuBuffer) {
|
||||
if (subDrawInfo.indexCount > 0) {
|
||||
const offset = subDrawInfo.firstIndex * gpuBuffer.stride;
|
||||
gl.drawElementsInstanced(glPrimitive, subDrawInfo.indexCount,
|
||||
gpuInputAssembler.glIndexType, offset, subDrawInfo.instanceCount);
|
||||
if (indirects.drawByIndex) {
|
||||
for (let j = 0; j < indirects.drawCount; j++) {
|
||||
indirects.byteOffsets[j] = indirects.offsets[j] * indexBuffer!.stride;
|
||||
}
|
||||
if (md) {
|
||||
if (indirects.instancedDraw) {
|
||||
md.multiDrawElementsInstancedWEBGL(glPrimitive,
|
||||
indirects.counts, 0,
|
||||
gpuInputAssembler.glIndexType,
|
||||
indirects.byteOffsets, 0,
|
||||
indirects.instances, 0,
|
||||
indirects.drawCount);
|
||||
} else {
|
||||
md.multiDrawElementsWEBGL(glPrimitive,
|
||||
indirects.counts, 0,
|
||||
gpuInputAssembler.glIndexType,
|
||||
indirects.byteOffsets, 0,
|
||||
indirects.drawCount);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < indirects.drawCount; j++) {
|
||||
if (indirects.instances[j] > 1) {
|
||||
gl.drawElementsInstanced(glPrimitive, indirects.counts[j],
|
||||
gpuInputAssembler.glIndexType, indirects.byteOffsets[j], indirects.instances[j]);
|
||||
} else {
|
||||
gl.drawElements(glPrimitive, indirects.counts[j], gpuInputAssembler.glIndexType, indirects.byteOffsets[j]);
|
||||
}
|
||||
} else if (subDrawInfo.vertexCount > 0) {
|
||||
gl.drawArraysInstanced(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount, subDrawInfo.instanceCount);
|
||||
}
|
||||
} else if (gpuBuffer) {
|
||||
if (subDrawInfo.indexCount > 0) {
|
||||
const offset = subDrawInfo.firstIndex * gpuBuffer.stride;
|
||||
gl.drawElements(glPrimitive, subDrawInfo.indexCount, gpuInputAssembler.glIndexType, offset);
|
||||
}
|
||||
} else if (md) {
|
||||
if (indirects.instancedDraw) {
|
||||
md.multiDrawArraysInstancedWEBGL(glPrimitive,
|
||||
indirects.offsets, 0,
|
||||
indirects.counts, 0,
|
||||
indirects.instances, 0,
|
||||
indirects.drawCount);
|
||||
} else {
|
||||
md.multiDrawArraysWEBGL(glPrimitive,
|
||||
indirects.offsets, 0,
|
||||
indirects.counts, 0,
|
||||
indirects.drawCount);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < indirects.drawCount; j++) {
|
||||
if (indirects.instances[j] > 1) {
|
||||
gl.drawArraysInstanced(glPrimitive, indirects.offsets[j], indirects.counts[j], indirects.instances[j]);
|
||||
} else {
|
||||
gl.drawArrays(glPrimitive, indirects.offsets[j], indirects.counts[j]);
|
||||
}
|
||||
} else if (subDrawInfo.vertexCount > 0) {
|
||||
gl.drawArrays(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount);
|
||||
}
|
||||
}
|
||||
} else if (drawInfo.instanceCount) {
|
||||
if (gpuInputAssembler.gpuIndexBuffer) {
|
||||
if (indexBuffer) {
|
||||
if (drawInfo.indexCount > 0) {
|
||||
const offset = drawInfo.firstIndex * gpuInputAssembler.gpuIndexBuffer.stride;
|
||||
const offset = drawInfo.firstIndex * indexBuffer.stride;
|
||||
gl.drawElementsInstanced(glPrimitive, drawInfo.indexCount,
|
||||
gpuInputAssembler.glIndexType, offset, drawInfo.instanceCount);
|
||||
}
|
||||
} else if (drawInfo.vertexCount > 0) {
|
||||
gl.drawArraysInstanced(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount, drawInfo.instanceCount);
|
||||
}
|
||||
} else if (gpuInputAssembler.gpuIndexBuffer) {
|
||||
} else if (indexBuffer) {
|
||||
if (drawInfo.indexCount > 0) {
|
||||
const offset = drawInfo.firstIndex * gpuInputAssembler.gpuIndexBuffer.stride;
|
||||
const offset = drawInfo.firstIndex * indexBuffer.stride;
|
||||
gl.drawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler.glIndexType, offset);
|
||||
}
|
||||
} else if (drawInfo.vertexCount > 0) {
|
||||
@@ -2620,7 +2648,7 @@ export function WebGL2CmdFuncCopyBuffersToTexture (
|
||||
gl.texSubImage2D(gl.TEXTURE_2D, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y, w, h,
|
||||
gpuTexture.glFormat, gpuTexture.glType, pixels);
|
||||
} else if (gpuTexture.glInternalFmt !== WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
} else if (gpuTexture.glInternalFmt !== WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
gl.compressedTexSubImage2D(gl.TEXTURE_2D, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y, w, h,
|
||||
gpuTexture.glFormat, pixels);
|
||||
@@ -2645,7 +2673,7 @@ export function WebGL2CmdFuncCopyBuffersToTexture (
|
||||
gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y, w, h,
|
||||
gpuTexture.glFormat, gpuTexture.glType, pixels);
|
||||
} else if (gpuTexture.glInternalFmt !== WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
} else if (gpuTexture.glInternalFmt !== WebGL2EXT.COMPRESSED_RGB_ETC1_WEBGL) {
|
||||
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y, w, h,
|
||||
gpuTexture.glFormat, pixels);
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
|
||||
// Extensions
|
||||
export enum WebGL2EXT {
|
||||
COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
|
||||
COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
|
||||
COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
|
||||
COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
|
||||
|
||||
COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F,
|
||||
|
||||
COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
|
||||
COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
|
||||
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
|
||||
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,
|
||||
|
||||
COMPRESSED_RGB_ETC1_WEBGL = 0x8D64,
|
||||
|
||||
COMPRESSED_R11_EAC = 0x9270,
|
||||
COMPRESSED_SIGNED_R11_EAC = 0x9271,
|
||||
COMPRESSED_RG11_EAC = 0x9272,
|
||||
COMPRESSED_SIGNED_RG11_EAC = 0x9273,
|
||||
COMPRESSED_RGB8_ETC2 = 0x9274,
|
||||
COMPRESSED_SRGB8_ETC2 = 0x9275,
|
||||
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
|
||||
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,
|
||||
COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
|
||||
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
|
||||
|
||||
COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0,
|
||||
COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1,
|
||||
COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2,
|
||||
COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3,
|
||||
COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4,
|
||||
COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5,
|
||||
COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6,
|
||||
COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7,
|
||||
COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8,
|
||||
COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9,
|
||||
COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA,
|
||||
COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB,
|
||||
COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC,
|
||||
COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD,
|
||||
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC,
|
||||
COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD,
|
||||
}
|
||||
|
||||
export interface IWebGL2Extensions {
|
||||
EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null;
|
||||
EXT_color_buffer_half_float: EXT_color_buffer_half_float | null;
|
||||
EXT_color_buffer_float: EXT_color_buffer_float | null;
|
||||
WEBGL_multi_draw: WEBGL_multi_draw | null;
|
||||
WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null;
|
||||
WEBGL_compressed_texture_etc: WEBGL_compressed_texture_etc | null;
|
||||
WEBGL_compressed_texture_pvrtc: WEBGL_compressed_texture_pvrtc | null;
|
||||
WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc | null;
|
||||
WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null;
|
||||
WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null;
|
||||
WEBGL_debug_shaders: WEBGL_debug_shaders | null;
|
||||
WEBGL_lose_context: WEBGL_lose_context | null;
|
||||
WEBGL_debug_renderer_info: WEBGL_debug_renderer_info | null;
|
||||
OES_texture_half_float_linear: OES_texture_half_float_linear | null;
|
||||
OES_texture_float_linear: OES_texture_float_linear | null;
|
||||
useVAO: boolean;
|
||||
}
|
||||
|
||||
// put the global instance here so that we won't have circular dependencies
|
||||
export class WebGL2DeviceManager {
|
||||
static get instance () {
|
||||
return WebGL2DeviceManager._instance!;
|
||||
}
|
||||
static setInstance (instance: WebGL2Device) {
|
||||
WebGL2DeviceManager._instance = instance;
|
||||
}
|
||||
private static _instance: WebGL2Device | null = null;
|
||||
}
|
||||
@@ -68,8 +68,6 @@ export class WebGL2DescriptorSetLayout extends DescriptorSetLayout {
|
||||
descriptorIndices,
|
||||
descriptorCount,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { WebGL2Buffer } from './webgl2-buffer';
|
||||
import { IWebGL2GPUDescriptorSet, IWebGL2GPUDescriptor } from './webgl2-gpu-objects';
|
||||
import { WebGL2Sampler } from './webgl2-sampler';
|
||||
import { WebGL2Sampler } from './states/webgl2-sampler';
|
||||
import { WebGL2Texture } from './webgl2-texture';
|
||||
import { WebGL2DescriptorSetLayout } from './webgl2-descriptor-set-layout';
|
||||
import { DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE } from '../base/define';
|
||||
@@ -38,7 +38,7 @@ export class WebGL2DescriptorSet extends DescriptorSet {
|
||||
|
||||
private _gpuDescriptorSet: IWebGL2GPUDescriptorSet | null = null;
|
||||
|
||||
public initialize (info: DescriptorSetInfo): boolean {
|
||||
public initialize (info: DescriptorSetInfo) {
|
||||
this._layout = info.layout;
|
||||
const { bindings, descriptorIndices, descriptorCount } = (info.layout as WebGL2DescriptorSetLayout).gpuDescriptorSetLayout;
|
||||
|
||||
@@ -60,8 +60,6 @@ export class WebGL2DescriptorSet extends DescriptorSet {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { macro, warnID, warn } from '../../platform';
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { DescriptorSetLayout } from '../base/descriptor-set-layout';
|
||||
import { PipelineLayout } from '../base/pipeline-layout';
|
||||
@@ -35,12 +34,11 @@ import { InputAssembler } from '../base/input-assembler';
|
||||
import { PipelineState, PipelineStateInfo } from '../base/pipeline-state';
|
||||
import { Queue } from '../base/queue';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { Sampler } from '../base/sampler';
|
||||
import { Sampler } from '../base/states/sampler';
|
||||
import { Shader } from '../base/shader';
|
||||
import { Texture } from '../base/texture';
|
||||
import { WebGL2DescriptorSet } from './webgl2-descriptor-set';
|
||||
import { WebGL2Buffer } from './webgl2-buffer';
|
||||
import { WebGL2CommandAllocator } from './webgl2-command-allocator';
|
||||
import { WebGL2CommandBuffer } from './webgl2-command-buffer';
|
||||
import { WebGL2Framebuffer } from './webgl2-framebuffer';
|
||||
import { WebGL2InputAssembler } from './webgl2-input-assembler';
|
||||
@@ -50,176 +48,71 @@ import { WebGL2PipelineState } from './webgl2-pipeline-state';
|
||||
import { WebGL2PrimaryCommandBuffer } from './webgl2-primary-command-buffer';
|
||||
import { WebGL2Queue } from './webgl2-queue';
|
||||
import { WebGL2RenderPass } from './webgl2-render-pass';
|
||||
import { WebGL2Sampler } from './webgl2-sampler';
|
||||
import { WebGL2Sampler } from './states/webgl2-sampler';
|
||||
import { WebGL2Shader } from './webgl2-shader';
|
||||
import { WebGL2StateCache } from './webgl2-state-cache';
|
||||
import { WebGL2Swapchain, getExtensions } from './webgl2-swapchain';
|
||||
import { WebGL2Texture } from './webgl2-texture';
|
||||
import {
|
||||
getTypedArrayConstructor, CommandBufferType, Filter, Format, FormatInfos, DescriptorSetLayoutInfo, DescriptorSetInfo,
|
||||
PipelineLayoutInfo, BufferViewInfo, CommandBufferInfo, BufferInfo, BindingMappingInfo, FramebufferInfo, InputAssemblerInfo,
|
||||
QueueInfo, RenderPassInfo, SamplerInfo, ShaderInfo, TextureInfo, TextureViewInfo, DeviceInfo, Rect, GlobalBarrierInfo, TextureBarrierInfo,
|
||||
QueueType, TextureFlagBit, TextureType, TextureUsageBit, API, Feature, BufferTextureCopy,
|
||||
CommandBufferType, DescriptorSetLayoutInfo, DescriptorSetInfo,
|
||||
PipelineLayoutInfo, BufferViewInfo, CommandBufferInfo, BufferInfo, FramebufferInfo, InputAssemblerInfo,
|
||||
QueueInfo, RenderPassInfo, SamplerInfo, ShaderInfo, TextureInfo, TextureViewInfo, DeviceInfo, GlobalBarrierInfo, TextureBarrierInfo,
|
||||
QueueType, API, Feature, BufferTextureCopy, SwapchainInfo,
|
||||
} from '../base/define';
|
||||
import {
|
||||
GFXFormatToWebGLFormat, GFXFormatToWebGLType, WebGL2CmdFuncBlitFramebuffer, WebGL2CmdFuncCopyTextureToBuffers,
|
||||
WebGL2CmdFuncCopyBuffersToTexture, WebGL2CmdFuncCopyTexImagesToTexture,
|
||||
} from './webgl2-commands';
|
||||
import { GlobalBarrier } from '../base/global-barrier';
|
||||
import { TextureBarrier } from '../base/texture-barrier';
|
||||
import { WebGL2CmdFuncCopyTextureToBuffers, WebGL2CmdFuncCopyBuffersToTexture, WebGL2CmdFuncCopyTexImagesToTexture } from './webgl2-commands';
|
||||
import { GlobalBarrier } from '../base/states/global-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { debug } from '../../platform/debug';
|
||||
|
||||
const eventWebGLContextLost = 'webglcontextlost';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
|
||||
export class WebGL2Device extends Device {
|
||||
get gl () {
|
||||
return this._webGL2RC as WebGL2RenderingContext;
|
||||
return this._swapchain!.gl;
|
||||
}
|
||||
|
||||
get isAntialias () {
|
||||
return this._isAntialias;
|
||||
get extensions () {
|
||||
return this._swapchain!.extensions;
|
||||
}
|
||||
|
||||
get isPremultipliedAlpha () {
|
||||
return this._isPremultipliedAlpha;
|
||||
get stateCache () {
|
||||
return this._swapchain!.stateCache;
|
||||
}
|
||||
|
||||
get useVAO () {
|
||||
return this._useVAO;
|
||||
get nullTex2D () {
|
||||
return this._swapchain!.nullTex2D;
|
||||
}
|
||||
|
||||
get bindingMappingInfo () {
|
||||
return this._bindingMappingInfo;
|
||||
get nullTexCube () {
|
||||
return this._swapchain!.nullTexCube;
|
||||
}
|
||||
|
||||
get EXT_texture_filter_anisotropic () {
|
||||
return this._EXT_texture_filter_anisotropic;
|
||||
}
|
||||
|
||||
get OES_texture_float_linear () {
|
||||
return this._OES_texture_float_linear;
|
||||
}
|
||||
|
||||
get EXT_color_buffer_float () {
|
||||
return this._EXT_color_buffer_float;
|
||||
}
|
||||
|
||||
get EXT_disjoint_timer_query_webgl2 () {
|
||||
return this._EXT_disjoint_timer_query_webgl2;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_etc1 () {
|
||||
return this._WEBGL_compressed_texture_etc1;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_etc () {
|
||||
return this._WEBGL_compressed_texture_etc;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_pvrtc () {
|
||||
return this._WEBGL_compressed_texture_pvrtc;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_s3tc () {
|
||||
return this._WEBGL_compressed_texture_s3tc;
|
||||
}
|
||||
|
||||
get WEBGL_compressed_texture_s3tc_srgb () {
|
||||
return this._WEBGL_compressed_texture_s3tc_srgb;
|
||||
}
|
||||
|
||||
get WEBGL_texture_storage_multisample () {
|
||||
return this._WEBGL_texture_storage_multisample;
|
||||
}
|
||||
|
||||
get WEBGL_debug_shaders () {
|
||||
return this._WEBGL_debug_shaders;
|
||||
}
|
||||
|
||||
get WEBGL_lose_context () {
|
||||
return this._WEBGL_lose_context;
|
||||
}
|
||||
|
||||
public stateCache: WebGL2StateCache = new WebGL2StateCache();
|
||||
public cmdAllocator: WebGL2CommandAllocator = new WebGL2CommandAllocator();
|
||||
public nullTex2D: WebGL2Texture | null = null;
|
||||
public nullTexCube: WebGL2Texture | null = null;
|
||||
|
||||
private _webGL2RC: WebGL2RenderingContext | null = null;
|
||||
private _isAntialias = true;
|
||||
private _isPremultipliedAlpha = true;
|
||||
private _useVAO = true;
|
||||
private _bindingMappingInfo: BindingMappingInfo = new BindingMappingInfo();
|
||||
private _webGLContextLostHandler: null | ((event: Event) => void) = null;
|
||||
|
||||
private _extensions: string[] | null = null;
|
||||
private _EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null = null;
|
||||
private _OES_texture_float_linear: OES_texture_float_linear | null = null;
|
||||
private _OES_texture_half_float_linear: OES_texture_half_float_linear | null = null;
|
||||
private _EXT_color_buffer_float: EXT_color_buffer_float | null = null;
|
||||
private _EXT_disjoint_timer_query_webgl2: EXT_disjoint_timer_query_webgl2 | null = null;
|
||||
private _WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null = null;
|
||||
private _WEBGL_compressed_texture_etc: WEBGL_compressed_texture_etc | null = null;
|
||||
private _WEBGL_compressed_texture_pvrtc: WEBGL_compressed_texture_pvrtc | null = null;
|
||||
private _WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc | null = null;
|
||||
private _WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null = null;
|
||||
private _WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null = null;
|
||||
private _WEBGL_debug_renderer_info: WEBGL_debug_renderer_info | null = null;
|
||||
private _WEBGL_texture_storage_multisample: WEBGL_texture_storage_multisample | null = null;
|
||||
private _WEBGL_debug_shaders: WEBGL_debug_shaders | null = null;
|
||||
private _WEBGL_lose_context: WEBGL_lose_context | null = null;
|
||||
private _swapchain: WebGL2Swapchain | null = null;
|
||||
|
||||
public initialize (info: DeviceInfo): boolean {
|
||||
this._canvas = info.canvasElm as HTMLCanvasElement;
|
||||
this._isAntialias = info.isAntialias;
|
||||
this._isPremultipliedAlpha = info.isPremultipliedAlpha;
|
||||
WebGL2DeviceManager.setInstance(this);
|
||||
this._gfxAPI = API.WEBGL2;
|
||||
|
||||
this._bindingMappingInfo = info.bindingMappingInfo;
|
||||
if (!this._bindingMappingInfo.bufferOffsets.length) this._bindingMappingInfo.bufferOffsets.push(0);
|
||||
if (!this._bindingMappingInfo.samplerOffsets.length) this._bindingMappingInfo.samplerOffsets.push(0);
|
||||
|
||||
let gl: WebGL2RenderingContext | null = null;
|
||||
|
||||
try {
|
||||
const webGLCtxAttribs: WebGLContextAttributes = {
|
||||
alpha: macro.ENABLE_TRANSPARENT_CANVAS,
|
||||
antialias: this._isAntialias,
|
||||
depth: true,
|
||||
stencil: true,
|
||||
premultipliedAlpha: this._isPremultipliedAlpha,
|
||||
preserveDrawingBuffer: false,
|
||||
powerPreference: 'default',
|
||||
failIfMajorPerformanceCaveat: false,
|
||||
};
|
||||
|
||||
this._webGL2RC = this._canvas.getContext('webgl2', webGLCtxAttribs);
|
||||
gl = document.createElement('canvas').getContext('webgl2');
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
if (!gl) {
|
||||
console.error('This device does not support WebGL.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this._webGL2RC) {
|
||||
console.warn('This device does not support WebGL2.');
|
||||
return false;
|
||||
}
|
||||
// create queue
|
||||
this._queue = this.createQueue(new QueueInfo(QueueType.GRAPHICS));
|
||||
this._cmdBuff = this.createCommandBuffer(new CommandBufferInfo(this._queue));
|
||||
|
||||
this._webGLContextLostHandler = this._onWebGLContextLost.bind(this);
|
||||
this._canvas.addEventListener(eventWebGLContextLost, this._onWebGLContextLost);
|
||||
|
||||
this._canvas2D = document.createElement('canvas');
|
||||
|
||||
console.info('WebGL2 device initialized.');
|
||||
|
||||
this._gfxAPI = API.WEBGL2;
|
||||
this._deviceName = 'WebGL2';
|
||||
const gl = this._webGL2RC;
|
||||
|
||||
this._WEBGL_debug_renderer_info = this.getExtension('WEBGL_debug_renderer_info');
|
||||
if (this._WEBGL_debug_renderer_info) {
|
||||
this._renderer = gl.getParameter(this._WEBGL_debug_renderer_info.UNMASKED_RENDERER_WEBGL);
|
||||
this._vendor = gl.getParameter(this._WEBGL_debug_renderer_info.UNMASKED_VENDOR_WEBGL);
|
||||
} else {
|
||||
this._renderer = gl.getParameter(gl.RENDERER);
|
||||
this._vendor = gl.getParameter(gl.VENDOR);
|
||||
}
|
||||
|
||||
this._version = gl.getParameter(gl.VERSION);
|
||||
this._caps.maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
||||
this._caps.maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
||||
this._caps.maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
|
||||
@@ -230,61 +123,26 @@ export class WebGL2Device extends Device {
|
||||
this._caps.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
||||
this._caps.maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
|
||||
this._caps.uboOffsetAlignment = gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT);
|
||||
this._caps.depthBits = gl.getParameter(gl.DEPTH_BITS);
|
||||
this._caps.stencilBits = gl.getParameter(gl.STENCIL_BITS);
|
||||
// let maxVertexUniformBlocks = gl.getParameter(gl.MAX_VERTEX_UNIFORM_BLOCKS);
|
||||
// let maxFragmentUniformBlocks = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_BLOCKS);
|
||||
|
||||
this.stateCache.initialize(this._caps.maxTextureUnits, this._caps.maxUniformBufferBindings, this._caps.maxVertexAttributes);
|
||||
|
||||
this._devicePixelRatio = info.devicePixelRatio || 1.0;
|
||||
this._width = info.width;
|
||||
this._height = info.height;
|
||||
|
||||
this._colorFmt = Format.RGBA8;
|
||||
|
||||
if (this._caps.depthBits === 32) {
|
||||
if (this._caps.stencilBits === 8) {
|
||||
this._depthStencilFmt = Format.D32F_S8;
|
||||
} else {
|
||||
this._depthStencilFmt = Format.D32F;
|
||||
const extensions = gl.getSupportedExtensions();
|
||||
let extStr = '';
|
||||
if (extensions) {
|
||||
for (const ext of extensions) {
|
||||
extStr += `${ext} `;
|
||||
}
|
||||
} else if (this._caps.depthBits === 24) {
|
||||
if (this._caps.stencilBits === 8) {
|
||||
this._depthStencilFmt = Format.D24S8;
|
||||
} else {
|
||||
this._depthStencilFmt = Format.D24;
|
||||
}
|
||||
} else if (this._caps.stencilBits === 8) {
|
||||
this._depthStencilFmt = Format.D16S8;
|
||||
}
|
||||
|
||||
const exts = getExtensions(gl);
|
||||
|
||||
if (exts.WEBGL_debug_renderer_info) {
|
||||
this._renderer = gl.getParameter(exts.WEBGL_debug_renderer_info.UNMASKED_RENDERER_WEBGL);
|
||||
this._vendor = gl.getParameter(exts.WEBGL_debug_renderer_info.UNMASKED_VENDOR_WEBGL);
|
||||
} else {
|
||||
this._depthStencilFmt = Format.D16;
|
||||
this._renderer = gl.getParameter(gl.RENDERER);
|
||||
this._vendor = gl.getParameter(gl.VENDOR);
|
||||
}
|
||||
|
||||
this._extensions = gl.getSupportedExtensions();
|
||||
let extensions = '';
|
||||
if (this._extensions) {
|
||||
for (const ext of this._extensions) {
|
||||
extensions += `${ext} `;
|
||||
}
|
||||
|
||||
debug(`EXTENSIONS: ${extensions}`);
|
||||
}
|
||||
|
||||
this._EXT_texture_filter_anisotropic = this.getExtension('EXT_texture_filter_anisotropic');
|
||||
this._EXT_color_buffer_float = this.getExtension('EXT_color_buffer_float');
|
||||
this._EXT_disjoint_timer_query_webgl2 = this.getExtension('EXT_disjoint_timer_query_webgl2');
|
||||
this._OES_texture_float_linear = this.getExtension('OES_texture_float_linear');
|
||||
this._OES_texture_half_float_linear = this.getExtension('OES_texture_half_float_linear');
|
||||
this._WEBGL_compressed_texture_etc1 = this.getExtension('WEBGL_compressed_texture_etc1');
|
||||
this._WEBGL_compressed_texture_etc = this.getExtension('WEBGL_compressed_texture_etc');
|
||||
this._WEBGL_compressed_texture_pvrtc = this.getExtension('WEBGL_compressed_texture_pvrtc');
|
||||
this._WEBGL_compressed_texture_astc = this.getExtension('WEBGL_compressed_texture_astc');
|
||||
this._WEBGL_compressed_texture_s3tc = this.getExtension('WEBGL_compressed_texture_s3tc');
|
||||
this._WEBGL_compressed_texture_s3tc_srgb = this.getExtension('WEBGL_compressed_texture_s3tc_srgb');
|
||||
this._WEBGL_texture_storage_multisample = this.getExtension('WEBGL_texture_storage_multisample');
|
||||
this._WEBGL_debug_shaders = this.getExtension('WEBGL_debug_shaders');
|
||||
this._WEBGL_lose_context = this.getExtension('WEBGL_lose_context');
|
||||
const version: string = gl.getParameter(gl.VERSION);
|
||||
|
||||
this._features.fill(false);
|
||||
this._features[Feature.TEXTURE_FLOAT] = true;
|
||||
@@ -297,138 +155,57 @@ export class WebGL2Device extends Device {
|
||||
this._features[Feature.MULTIPLE_RENDER_TARGETS] = true;
|
||||
this._features[Feature.BLEND_MINMAX] = true;
|
||||
|
||||
if (this._EXT_color_buffer_float) {
|
||||
if (exts.EXT_color_buffer_float) {
|
||||
this._features[Feature.COLOR_FLOAT] = true;
|
||||
this._features[Feature.COLOR_HALF_FLOAT] = true;
|
||||
}
|
||||
|
||||
if (this._OES_texture_float_linear) {
|
||||
if (exts.OES_texture_float_linear) {
|
||||
this._features[Feature.TEXTURE_FLOAT_LINEAR] = true;
|
||||
}
|
||||
|
||||
if (this._OES_texture_half_float_linear) {
|
||||
if (exts.OES_texture_half_float_linear) {
|
||||
this._features[Feature.TEXTURE_HALF_FLOAT_LINEAR] = true;
|
||||
}
|
||||
|
||||
let compressedFormat = '';
|
||||
|
||||
if (this._WEBGL_compressed_texture_etc1) {
|
||||
if (exts.WEBGL_compressed_texture_etc1) {
|
||||
this._features[Feature.FORMAT_ETC1] = true;
|
||||
compressedFormat += 'etc1 ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_etc) {
|
||||
if (exts.WEBGL_compressed_texture_etc) {
|
||||
this._features[Feature.FORMAT_ETC2] = true;
|
||||
compressedFormat += 'etc2 ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_s3tc) {
|
||||
if (exts.WEBGL_compressed_texture_s3tc) {
|
||||
this._features[Feature.FORMAT_DXT] = true;
|
||||
compressedFormat += 'dxt ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_pvrtc) {
|
||||
if (exts.WEBGL_compressed_texture_pvrtc) {
|
||||
this._features[Feature.FORMAT_PVRTC] = true;
|
||||
compressedFormat += 'pvrtc ';
|
||||
}
|
||||
|
||||
if (this._WEBGL_compressed_texture_astc) {
|
||||
if (exts.WEBGL_compressed_texture_astc) {
|
||||
this._features[Feature.FORMAT_ASTC] = true;
|
||||
compressedFormat += 'astc ';
|
||||
}
|
||||
|
||||
debug('WebGL2 device initialized.');
|
||||
debug(`RENDERER: ${this._renderer}`);
|
||||
debug(`VENDOR: ${this._vendor}`);
|
||||
debug(`VERSION: ${this._version}`);
|
||||
debug(`DPR: ${this._devicePixelRatio}`);
|
||||
debug(`SCREEN_SIZE: ${this._width} x ${this._height}`);
|
||||
debug(`MAX_VERTEX_ATTRIBS: ${this._caps.maxVertexAttributes}`);
|
||||
debug(`MAX_VERTEX_UNIFORM_VECTORS: ${this._caps.maxVertexUniformVectors}`);
|
||||
debug(`MAX_FRAGMENT_UNIFORM_VECTORS: ${this._caps.maxFragmentUniformVectors}`);
|
||||
debug(`MAX_TEXTURE_IMAGE_UNITS: ${this._caps.maxTextureUnits}`);
|
||||
debug(`MAX_VERTEX_TEXTURE_IMAGE_UNITS: ${this._caps.maxVertexTextureUnits}`);
|
||||
debug(`MAX_UNIFORM_BUFFER_BINDINGS: ${this._caps.maxUniformBufferBindings}`);
|
||||
debug(`MAX_UNIFORM_BLOCK_SIZE: ${this._caps.maxUniformBlockSize}`);
|
||||
debug(`DEPTH_BITS: ${this._caps.depthBits}`);
|
||||
debug(`STENCIL_BITS: ${this._caps.stencilBits}`);
|
||||
debug(`UNIFORM_BUFFER_OFFSET_ALIGNMENT: ${this._caps.uboOffsetAlignment}`);
|
||||
if (this._EXT_texture_filter_anisotropic) {
|
||||
debug(`MAX_TEXTURE_MAX_ANISOTROPY_EXT: ${this._EXT_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT}`);
|
||||
}
|
||||
debug(`USE_VAO: ${this._useVAO}`);
|
||||
debug(`VERSION: ${version}`);
|
||||
debug(`COMPRESSED_FORMAT: ${compressedFormat}`);
|
||||
|
||||
// init states
|
||||
this.initStates(gl);
|
||||
|
||||
// create queue
|
||||
this._queue = this.createQueue(new QueueInfo(QueueType.GRAPHICS));
|
||||
this._cmdBuff = this.createCommandBuffer(new CommandBufferInfo(this._queue));
|
||||
|
||||
// create default null texture
|
||||
this.nullTex2D = this.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
)) as WebGL2Texture;
|
||||
|
||||
this.nullTexCube = new WebGL2Texture(this);
|
||||
this.nullTexCube.initialize(new TextureInfo(
|
||||
TextureType.CUBE,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
6,
|
||||
));
|
||||
|
||||
const nullTexRegion = new BufferTextureCopy();
|
||||
nullTexRegion.texExtent.width = 2;
|
||||
nullTexRegion.texExtent.height = 2;
|
||||
|
||||
const nullTexBuff = new Uint8Array(this.nullTex2D.size);
|
||||
nullTexBuff.fill(0);
|
||||
this.copyBuffersToTexture([nullTexBuff], this.nullTex2D, [nullTexRegion]);
|
||||
|
||||
nullTexRegion.texSubres.layerCount = 6;
|
||||
this.copyBuffersToTexture(
|
||||
[nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff],
|
||||
this.nullTexCube, [nullTexRegion],
|
||||
);
|
||||
debug(`EXTENSIONS: ${extStr}`);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
if (this._canvas && this._webGLContextLostHandler) {
|
||||
this._canvas.removeEventListener(eventWebGLContextLost, this._webGLContextLostHandler);
|
||||
this._webGLContextLostHandler = null;
|
||||
}
|
||||
|
||||
if (this.nullTex2D) {
|
||||
this.nullTex2D.destroy();
|
||||
this.nullTex2D = null;
|
||||
}
|
||||
|
||||
if (this.nullTexCube) {
|
||||
this.nullTexCube.destroy();
|
||||
this.nullTexCube = null;
|
||||
}
|
||||
|
||||
// for (let i = 0; i < this._primaries.length; i++) {
|
||||
// this._primaries[i].destroy();
|
||||
// }
|
||||
// this._nextPrimary = this._primaries.length = 0;
|
||||
|
||||
// for (let i = 0; i < this._secondaries.length; i++) {
|
||||
// this._secondaries[i].destroy();
|
||||
// }
|
||||
// this._nextSecondary = this._secondaries.length = 0;
|
||||
|
||||
if (this._queue) {
|
||||
this._queue.destroy();
|
||||
this._queue = null;
|
||||
@@ -439,26 +216,19 @@ export class WebGL2Device extends Device {
|
||||
this._cmdBuff = null;
|
||||
}
|
||||
|
||||
this._extensions = null;
|
||||
|
||||
this._webGL2RC = null;
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
if (this._width !== width || this._height !== height) {
|
||||
debug(`Resizing device: ${width}x${height}`);
|
||||
this._canvas!.width = width;
|
||||
this._canvas!.height = height;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
const it = this._samplers.values();
|
||||
let res = it.next();
|
||||
while (!res.done) {
|
||||
(res.value as WebGL2Sampler).destroy();
|
||||
res = it.next();
|
||||
}
|
||||
|
||||
this._swapchain = null;
|
||||
}
|
||||
|
||||
public flushCommands (cmdBuffs: CommandBuffer[]) {}
|
||||
|
||||
public acquire () {
|
||||
this.cmdAllocator.releaseCmds();
|
||||
}
|
||||
public acquire (swapchains: Swapchain[]) {}
|
||||
|
||||
public present () {
|
||||
const queue = (this._queue as WebGL2Queue);
|
||||
@@ -471,123 +241,106 @@ export class WebGL2Device extends Device {
|
||||
public createCommandBuffer (info: CommandBufferInfo): CommandBuffer {
|
||||
// const Ctor = WebGLCommandBuffer; // opt to instant invocation
|
||||
const Ctor = info.type === CommandBufferType.PRIMARY ? WebGL2PrimaryCommandBuffer : WebGL2CommandBuffer;
|
||||
const cmdBuff = new Ctor(this);
|
||||
if (cmdBuff.initialize(info)) {
|
||||
return cmdBuff;
|
||||
}
|
||||
return null!;
|
||||
const cmdBuff = new Ctor();
|
||||
cmdBuff.initialize(info);
|
||||
return cmdBuff;
|
||||
}
|
||||
|
||||
public createSwapchain (info: SwapchainInfo): Swapchain {
|
||||
const swapchain = new WebGL2Swapchain();
|
||||
this._swapchain = swapchain;
|
||||
swapchain.initialize(info);
|
||||
return swapchain;
|
||||
}
|
||||
|
||||
public createBuffer (info: BufferInfo | BufferViewInfo): Buffer {
|
||||
const buffer = new WebGL2Buffer(this);
|
||||
if (buffer.initialize(info)) {
|
||||
return buffer;
|
||||
}
|
||||
return null!;
|
||||
const buffer = new WebGL2Buffer();
|
||||
buffer.initialize(info);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public createTexture (info: TextureInfo | TextureViewInfo): Texture {
|
||||
const texture = new WebGL2Texture(this);
|
||||
if (texture.initialize(info)) {
|
||||
return texture;
|
||||
}
|
||||
return null!;
|
||||
}
|
||||
|
||||
public createSampler (info: SamplerInfo): Sampler {
|
||||
const sampler = new WebGL2Sampler(this);
|
||||
if (sampler.initialize(info)) {
|
||||
return sampler;
|
||||
}
|
||||
return null!;
|
||||
const texture = new WebGL2Texture();
|
||||
texture.initialize(info);
|
||||
return texture;
|
||||
}
|
||||
|
||||
public createDescriptorSet (info: DescriptorSetInfo): DescriptorSet {
|
||||
const descriptorSet = new WebGL2DescriptorSet(this);
|
||||
if (descriptorSet.initialize(info)) {
|
||||
return descriptorSet;
|
||||
}
|
||||
return null!;
|
||||
const descriptorSet = new WebGL2DescriptorSet();
|
||||
descriptorSet.initialize(info);
|
||||
return descriptorSet;
|
||||
}
|
||||
|
||||
public createShader (info: ShaderInfo): Shader {
|
||||
const shader = new WebGL2Shader(this);
|
||||
if (shader.initialize(info)) {
|
||||
return shader;
|
||||
}
|
||||
return null!;
|
||||
const shader = new WebGL2Shader();
|
||||
shader.initialize(info);
|
||||
return shader;
|
||||
}
|
||||
|
||||
public createInputAssembler (info: InputAssemblerInfo): InputAssembler {
|
||||
const inputAssembler = new WebGL2InputAssembler(this);
|
||||
if (inputAssembler.initialize(info)) {
|
||||
return inputAssembler;
|
||||
}
|
||||
return null!;
|
||||
const inputAssembler = new WebGL2InputAssembler();
|
||||
inputAssembler.initialize(info);
|
||||
return inputAssembler;
|
||||
}
|
||||
|
||||
public createRenderPass (info: RenderPassInfo): RenderPass {
|
||||
const renderPass = new WebGL2RenderPass(this);
|
||||
if (renderPass.initialize(info)) {
|
||||
return renderPass;
|
||||
}
|
||||
return null!;
|
||||
const renderPass = new WebGL2RenderPass();
|
||||
renderPass.initialize(info);
|
||||
return renderPass;
|
||||
}
|
||||
|
||||
public createFramebuffer (info: FramebufferInfo): Framebuffer {
|
||||
const framebuffer = new WebGL2Framebuffer(this);
|
||||
if (framebuffer.initialize(info)) {
|
||||
return framebuffer;
|
||||
}
|
||||
return null!;
|
||||
const framebuffer = new WebGL2Framebuffer();
|
||||
framebuffer.initialize(info);
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
public createDescriptorSetLayout (info: DescriptorSetLayoutInfo): DescriptorSetLayout {
|
||||
const descriptorSetLayout = new WebGL2DescriptorSetLayout(this);
|
||||
if (descriptorSetLayout.initialize(info)) {
|
||||
return descriptorSetLayout;
|
||||
}
|
||||
return null!;
|
||||
const descriptorSetLayout = new WebGL2DescriptorSetLayout();
|
||||
descriptorSetLayout.initialize(info);
|
||||
return descriptorSetLayout;
|
||||
}
|
||||
|
||||
public createPipelineLayout (info: PipelineLayoutInfo): PipelineLayout {
|
||||
const pipelineLayout = new WebGL2PipelineLayout(this);
|
||||
if (pipelineLayout.initialize(info)) {
|
||||
return pipelineLayout;
|
||||
}
|
||||
return null!;
|
||||
const pipelineLayout = new WebGL2PipelineLayout();
|
||||
pipelineLayout.initialize(info);
|
||||
return pipelineLayout;
|
||||
}
|
||||
|
||||
public createPipelineState (info: PipelineStateInfo): PipelineState {
|
||||
const pipelineState = new WebGL2PipelineState(this);
|
||||
if (pipelineState.initialize(info)) {
|
||||
return pipelineState;
|
||||
}
|
||||
return null!;
|
||||
const pipelineState = new WebGL2PipelineState();
|
||||
pipelineState.initialize(info);
|
||||
return pipelineState;
|
||||
}
|
||||
|
||||
public createQueue (info: QueueInfo): Queue {
|
||||
const queue = new WebGL2Queue(this);
|
||||
if (queue.initialize(info)) {
|
||||
return queue;
|
||||
}
|
||||
return null!;
|
||||
const queue = new WebGL2Queue();
|
||||
queue.initialize(info);
|
||||
return queue;
|
||||
}
|
||||
|
||||
public createGlobalBarrier (info: GlobalBarrierInfo) {
|
||||
const barrier = new GlobalBarrier(this);
|
||||
if (barrier.initialize(info)) {
|
||||
return barrier;
|
||||
public getSampler (info: SamplerInfo): Sampler {
|
||||
const hash = Sampler.computeHash(info);
|
||||
if (!this._samplers.has(hash)) {
|
||||
this._samplers.set(hash, new WebGL2Sampler(info));
|
||||
}
|
||||
return null!;
|
||||
return this._samplers.get(hash)!;
|
||||
}
|
||||
|
||||
public createTextureBarrier (info: TextureBarrierInfo) {
|
||||
const barrier = new TextureBarrier(this);
|
||||
if (barrier.initialize(info)) {
|
||||
return barrier;
|
||||
public getGlobalBarrier (info: GlobalBarrierInfo) {
|
||||
const hash = GlobalBarrier.computeHash(info);
|
||||
if (!this._globalBarriers.has(hash)) {
|
||||
this._globalBarriers.set(hash, new GlobalBarrier(info));
|
||||
}
|
||||
return null!;
|
||||
return this._globalBarriers.get(hash)!;
|
||||
}
|
||||
|
||||
public getTextureBarrier (info: TextureBarrierInfo) {
|
||||
const hash = TextureBarrier.computeHash(info);
|
||||
if (!this._textureBarriers.has(hash)) {
|
||||
this._textureBarriers.set(hash, new TextureBarrier(info));
|
||||
}
|
||||
return this._textureBarriers.get(hash)!;
|
||||
}
|
||||
|
||||
public copyBuffersToTexture (buffers: ArrayBufferView[], texture: Texture, regions: BufferTextureCopy[]) {
|
||||
@@ -620,109 +373,4 @@ export class WebGL2Device extends Device {
|
||||
regions,
|
||||
);
|
||||
}
|
||||
|
||||
public copyFramebufferToBuffer (
|
||||
srcFramebuffer: Framebuffer,
|
||||
dstBuffer: ArrayBuffer,
|
||||
regions: BufferTextureCopy[],
|
||||
) {
|
||||
const gl = this._webGL2RC as WebGL2RenderingContext;
|
||||
const gpuFramebuffer = (srcFramebuffer as WebGL2Framebuffer).gpuFramebuffer;
|
||||
const format = gpuFramebuffer.gpuColorTextures[0].format;
|
||||
const glFormat = GFXFormatToWebGLFormat(format, gl);
|
||||
const glType = GFXFormatToWebGLType(format, gl);
|
||||
const Ctor = getTypedArrayConstructor(FormatInfos[format]);
|
||||
|
||||
const curFBO = this.stateCache.glFramebuffer;
|
||||
|
||||
if (this.stateCache.glFramebuffer !== gpuFramebuffer.glFramebuffer) {
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuFramebuffer.glFramebuffer);
|
||||
this.stateCache.glFramebuffer = gpuFramebuffer.glFramebuffer;
|
||||
}
|
||||
|
||||
const view = new Ctor(dstBuffer);
|
||||
|
||||
for (const region of regions) {
|
||||
const w = region.texExtent.width;
|
||||
const h = region.texExtent.height;
|
||||
|
||||
gl.readPixels(region.texOffset.x, region.texOffset.y, w, h, glFormat, glType, view);
|
||||
}
|
||||
|
||||
if (this.stateCache.glFramebuffer !== curFBO) {
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, curFBO);
|
||||
this.stateCache.glFramebuffer = curFBO;
|
||||
}
|
||||
}
|
||||
|
||||
public blitFramebuffer (src: Framebuffer, dst: Framebuffer, srcRect: Rect, dstRect: Rect, filter: Filter) {
|
||||
const srcFBO = (src as WebGL2Framebuffer).gpuFramebuffer;
|
||||
const dstFBO = (dst as WebGL2Framebuffer).gpuFramebuffer;
|
||||
|
||||
WebGL2CmdFuncBlitFramebuffer(
|
||||
this,
|
||||
srcFBO,
|
||||
dstFBO,
|
||||
srcRect,
|
||||
dstRect,
|
||||
filter,
|
||||
);
|
||||
}
|
||||
|
||||
private getExtension (ext: string): any {
|
||||
const prefixes = ['', 'WEBKIT_', 'MOZ_'];
|
||||
for (let i = 0; i < prefixes.length; ++i) {
|
||||
const _ext = this.gl.getExtension(prefixes[i] + ext);
|
||||
if (_ext) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return _ext;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private initStates (gl: WebGL2RenderingContext) {
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.pixelStorei(gl.PACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
// rasterizer state
|
||||
gl.enable(gl.SCISSOR_TEST);
|
||||
gl.enable(gl.CULL_FACE);
|
||||
gl.cullFace(gl.BACK);
|
||||
gl.frontFace(gl.CCW);
|
||||
gl.polygonOffset(0.0, 0.0);
|
||||
|
||||
// depth stencil state
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthMask(true);
|
||||
gl.depthFunc(gl.LESS);
|
||||
|
||||
gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.FRONT, 0xffff);
|
||||
gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.BACK, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.BACK, 0xffff);
|
||||
|
||||
gl.disable(gl.STENCIL_TEST);
|
||||
|
||||
// blend state
|
||||
gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
|
||||
gl.disable(gl.BLEND);
|
||||
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
|
||||
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
||||
gl.colorMask(true, true, true, true);
|
||||
gl.blendColor(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
private _onWebGLContextLost (event: Event) {
|
||||
warnID(11000);
|
||||
warn(event);
|
||||
// 2020.9.3: `preventDefault` is not available on some platforms
|
||||
// event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { FramebufferInfo } from '../base/define';
|
||||
import { Framebuffer } from '../base/framebuffer';
|
||||
import { WebGL2CmdFuncCreateFramebuffer, WebGL2CmdFuncDestroyFramebuffer } from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
import { IWebGL2GPUFramebuffer, IWebGL2GPUTexture } from './webgl2-gpu-objects';
|
||||
import { WebGL2RenderPass } from './webgl2-render-pass';
|
||||
import { WebGL2Texture } from './webgl2-texture';
|
||||
@@ -38,7 +38,7 @@ export class WebGL2Framebuffer extends Framebuffer {
|
||||
|
||||
private _gpuFramebuffer: IWebGL2GPUFramebuffer | null = null;
|
||||
|
||||
public initialize (info: FramebufferInfo): boolean {
|
||||
public initialize (info: FramebufferInfo) {
|
||||
this._renderPass = info.renderPass;
|
||||
this._colorTextures = info.colorTextures || [];
|
||||
this._depthStencilTexture = info.depthStencilTexture || null;
|
||||
@@ -63,14 +63,12 @@ export class WebGL2Framebuffer extends Framebuffer {
|
||||
glFramebuffer: null,
|
||||
};
|
||||
|
||||
WebGL2CmdFuncCreateFramebuffer(this._device as WebGL2Device, this._gpuFramebuffer);
|
||||
|
||||
return true;
|
||||
WebGL2CmdFuncCreateFramebuffer(WebGL2DeviceManager.instance, this._gpuFramebuffer);
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuFramebuffer) {
|
||||
WebGL2CmdFuncDestroyFramebuffer(this._device as WebGL2Device, this._gpuFramebuffer);
|
||||
WebGL2CmdFuncDestroyFramebuffer(WebGL2DeviceManager.instance, this._gpuFramebuffer);
|
||||
this._gpuFramebuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { nextPow2 } from '../../math/bits';
|
||||
import {
|
||||
Address, DescriptorType, BufferUsage, Filter, Format, MemoryUsage, SampleCount,
|
||||
ShaderStageFlagBit, TextureFlags, TextureType, TextureUsage, Type, DynamicStateFlagBit, DrawInfo, Attribute,
|
||||
@@ -30,6 +31,67 @@ import {
|
||||
} from '../base/define';
|
||||
import { BlendState, DepthStencilState, RasterizerState } from '../base/pipeline-state';
|
||||
|
||||
export class WebGL2IndirectDrawInfos {
|
||||
public counts: Int32Array;
|
||||
public offsets: Int32Array;
|
||||
public instances: Int32Array;
|
||||
public drawCount = 0;
|
||||
public drawByIndex = false;
|
||||
public instancedDraw = false;
|
||||
|
||||
// staging buffer
|
||||
public byteOffsets: Int32Array;
|
||||
|
||||
private _capacity = 4;
|
||||
|
||||
constructor () {
|
||||
this.counts = new Int32Array(this._capacity);
|
||||
this.offsets = new Int32Array(this._capacity);
|
||||
this.instances = new Int32Array(this._capacity);
|
||||
this.byteOffsets = new Int32Array(this._capacity);
|
||||
}
|
||||
|
||||
public clearDraws () {
|
||||
this.drawCount = 0;
|
||||
this.drawByIndex = false;
|
||||
this.instancedDraw = false;
|
||||
}
|
||||
|
||||
public setDrawInfo (idx: number, info: DrawInfo) {
|
||||
this._ensureCapacity(idx);
|
||||
this.drawByIndex = info.indexCount > 0;
|
||||
this.instancedDraw = info.instanceCount > 1;
|
||||
this.drawCount = Math.max(idx + 1, this.drawCount);
|
||||
|
||||
if (this.drawByIndex) {
|
||||
this.counts[idx] = info.indexCount;
|
||||
this.offsets[idx] = info.firstIndex;
|
||||
} else {
|
||||
this.counts[idx] = info.vertexCount;
|
||||
this.offsets[idx] = info.firstVertex;
|
||||
}
|
||||
this.instances[idx] = Math.max(1, info.instanceCount);
|
||||
}
|
||||
|
||||
private _ensureCapacity (target: number) {
|
||||
if (this._capacity > target) return;
|
||||
this._capacity = nextPow2(target);
|
||||
|
||||
const counts = new Int32Array(this._capacity);
|
||||
const offsets = new Int32Array(this._capacity);
|
||||
const instances = new Int32Array(this._capacity);
|
||||
this.byteOffsets = new Int32Array(this._capacity);
|
||||
|
||||
counts.set(this.counts);
|
||||
offsets.set(this.offsets);
|
||||
instances.set(this.instances);
|
||||
|
||||
this.counts = counts;
|
||||
this.offsets = offsets;
|
||||
this.instances = instances;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IWebGL2GPUUniformInfo {
|
||||
name: string;
|
||||
type: Type;
|
||||
@@ -50,7 +112,7 @@ export interface IWebGL2GPUBuffer {
|
||||
glOffset: number;
|
||||
|
||||
buffer: ArrayBufferView | null;
|
||||
indirects: DrawInfo[];
|
||||
indirects: WebGL2IndirectDrawInfos;
|
||||
}
|
||||
|
||||
export interface IWebGL2GPUTexture {
|
||||
@@ -78,6 +140,8 @@ export interface IWebGL2GPUTexture {
|
||||
glWrapT: GLenum;
|
||||
glMinFilter: GLenum;
|
||||
glMagFilter: GLenum;
|
||||
|
||||
isSwapchainTexture: boolean;
|
||||
}
|
||||
|
||||
export interface IWebGL2GPURenderPass {
|
||||
|
||||
@@ -27,7 +27,7 @@ import { InputAssemblerInfo } from '../base/define';
|
||||
import { InputAssembler } from '../base/input-assembler';
|
||||
import { WebGL2Buffer } from './webgl2-buffer';
|
||||
import { WebGL2CmdFuncCreateInputAssember, WebGL2CmdFuncDestroyInputAssembler } from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
import { IWebGL2GPUInputAssembler, IWebGL2GPUBuffer } from './webgl2-gpu-objects';
|
||||
|
||||
export class WebGL2InputAssembler extends InputAssembler {
|
||||
@@ -37,10 +37,10 @@ export class WebGL2InputAssembler extends InputAssembler {
|
||||
|
||||
private _gpuInputAssembler: IWebGL2GPUInputAssembler | null = null;
|
||||
|
||||
public initialize (info: InputAssemblerInfo): boolean {
|
||||
public initialize (info: InputAssemblerInfo) {
|
||||
if (info.vertexBuffers.length === 0) {
|
||||
console.error('InputAssemblerInfo.vertexBuffers is null.');
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
this._attributes = info.attributes;
|
||||
@@ -49,16 +49,16 @@ export class WebGL2InputAssembler extends InputAssembler {
|
||||
|
||||
if (info.indexBuffer) {
|
||||
this._indexBuffer = info.indexBuffer;
|
||||
this._indexCount = this._indexBuffer.size / this._indexBuffer.stride;
|
||||
this._firstIndex = 0;
|
||||
this._drawInfo.indexCount = this._indexBuffer.size / this._indexBuffer.stride;
|
||||
this._drawInfo.firstIndex = 0;
|
||||
} else {
|
||||
const vertBuff = this._vertexBuffers[0];
|
||||
this._vertexCount = vertBuff.size / vertBuff.stride;
|
||||
this._firstVertex = 0;
|
||||
this._vertexOffset = 0;
|
||||
this._drawInfo.vertexCount = vertBuff.size / vertBuff.stride;
|
||||
this._drawInfo.firstVertex = 0;
|
||||
this._drawInfo.vertexOffset = 0;
|
||||
}
|
||||
this._instanceCount = 0;
|
||||
this._firstInstance = 0;
|
||||
this._drawInfo.instanceCount = 0;
|
||||
this._drawInfo.firstInstance = 0;
|
||||
|
||||
this._indirectBuffer = info.indirectBuffer || null;
|
||||
|
||||
@@ -102,15 +102,13 @@ export class WebGL2InputAssembler extends InputAssembler {
|
||||
glVAOs: new Map<WebGLProgram, WebGLVertexArrayObject>(),
|
||||
};
|
||||
|
||||
WebGL2CmdFuncCreateInputAssember(this._device as WebGL2Device, this._gpuInputAssembler);
|
||||
|
||||
return true;
|
||||
WebGL2CmdFuncCreateInputAssember(WebGL2DeviceManager.instance, this._gpuInputAssembler);
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
const webgl2Dev = this._device as WebGL2Device;
|
||||
if (this._gpuInputAssembler && webgl2Dev.useVAO) {
|
||||
WebGL2CmdFuncDestroyInputAssembler(webgl2Dev, this._gpuInputAssembler);
|
||||
const device = WebGL2DeviceManager.instance;
|
||||
if (this._gpuInputAssembler && device.extensions.useVAO) {
|
||||
WebGL2CmdFuncDestroyInputAssembler(device, this._gpuInputAssembler);
|
||||
}
|
||||
this._gpuInputAssembler = null;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,6 @@ export class WebGL2PipelineLayout extends PipelineLayout {
|
||||
dynamicOffsetCount,
|
||||
dynamicOffsetOffsets,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -54,7 +54,7 @@ export class WebGL2PipelineState extends PipelineState {
|
||||
|
||||
private _gpuPipelineState: IWebGL2GPUPipelineState | null = null;
|
||||
|
||||
public initialize (info: PipelineStateInfo): boolean {
|
||||
public initialize (info: PipelineStateInfo) {
|
||||
this._primitive = info.primitive;
|
||||
this._shader = info.shader;
|
||||
this._pipelineLayout = info.pipelineLayout;
|
||||
@@ -95,8 +95,6 @@ export class WebGL2PipelineState extends PipelineState {
|
||||
gpuRenderPass: (info.renderPass as WebGL2RenderPass).gpuRenderPass,
|
||||
dynamicStates,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -34,11 +34,11 @@ import { WebGL2CommandBuffer } from './webgl2-command-buffer';
|
||||
import {
|
||||
WebGL2CmdFuncBeginRenderPass, WebGL2CmdFuncBindStates, WebGL2CmdFuncCopyBuffersToTexture,
|
||||
WebGL2CmdFuncDraw, WebGL2CmdFuncExecuteCmds, WebGL2CmdFuncUpdateBuffer } from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { WebGL2Framebuffer } from './webgl2-framebuffer';
|
||||
import { WebGL2Texture } from './webgl2-texture';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { WebGL2RenderPass } from './webgl2-render-pass';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
|
||||
export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer {
|
||||
public beginRenderPass (
|
||||
@@ -50,7 +50,7 @@ export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer {
|
||||
clearStencil: number,
|
||||
) {
|
||||
WebGL2CmdFuncBeginRenderPass(
|
||||
this._device as WebGL2Device,
|
||||
WebGL2DeviceManager.instance,
|
||||
(renderPass as WebGL2RenderPass).gpuRenderPass,
|
||||
(framebuffer as WebGL2Framebuffer).gpuFramebuffer,
|
||||
renderArea, clearColors, clearDepth, clearStencil,
|
||||
@@ -58,13 +58,15 @@ export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer {
|
||||
this._isInRenderPass = true;
|
||||
}
|
||||
|
||||
public draw (info: DrawInfo | InputAssembler) {
|
||||
public draw (infoOrAssembler: DrawInfo | InputAssembler) {
|
||||
if (this._isInRenderPass) {
|
||||
if (this._isStateInvalied) {
|
||||
this.bindStates();
|
||||
}
|
||||
|
||||
WebGL2CmdFuncDraw(this._device as WebGL2Device, info as DrawInfo);
|
||||
const info = 'drawInfo' in infoOrAssembler ? infoOrAssembler.drawInfo : infoOrAssembler;
|
||||
|
||||
WebGL2CmdFuncDraw(WebGL2DeviceManager.instance, info as DrawInfo);
|
||||
|
||||
++this._numDrawCalls;
|
||||
this._numInstances += info.instanceCount;
|
||||
@@ -102,7 +104,7 @@ export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer {
|
||||
buffSize = (data as ArrayBuffer).byteLength;
|
||||
}
|
||||
|
||||
WebGL2CmdFuncUpdateBuffer(this._device as WebGL2Device, gpuBuffer, data as ArrayBuffer, 0, buffSize);
|
||||
WebGL2CmdFuncUpdateBuffer(WebGL2DeviceManager.instance, gpuBuffer, data as ArrayBuffer, 0, buffSize);
|
||||
}
|
||||
} else {
|
||||
console.error('Command \'updateBuffer\' must be recorded outside a render pass.');
|
||||
@@ -113,7 +115,7 @@ export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer {
|
||||
if (!this._isInRenderPass) {
|
||||
const gpuTexture = (texture as WebGL2Texture).gpuTexture;
|
||||
if (gpuTexture) {
|
||||
WebGL2CmdFuncCopyBuffersToTexture(this._device as WebGL2Device, buffers, gpuTexture, regions);
|
||||
WebGL2CmdFuncCopyBuffersToTexture(WebGL2DeviceManager.instance, buffers, gpuTexture, regions);
|
||||
}
|
||||
} else {
|
||||
console.error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
|
||||
@@ -124,7 +126,7 @@ export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer {
|
||||
for (let i = 0; i < count; ++i) {
|
||||
// actually they are secondary buffers, the cast here is only for type checking
|
||||
const webGL2CmdBuff = cmdBuffs[i] as WebGL2PrimaryCommandBuffer;
|
||||
WebGL2CmdFuncExecuteCmds(this._device as WebGL2Device, webGL2CmdBuff.cmdPackage);
|
||||
WebGL2CmdFuncExecuteCmds(WebGL2DeviceManager.instance, webGL2CmdBuff.cmdPackage);
|
||||
this._numDrawCalls += webGL2CmdBuff._numDrawCalls;
|
||||
this._numInstances += webGL2CmdBuff._numInstances;
|
||||
this._numTris += webGL2CmdBuff._numTris;
|
||||
@@ -132,7 +134,7 @@ export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer {
|
||||
}
|
||||
|
||||
protected bindStates () {
|
||||
WebGL2CmdFuncBindStates(this._device as WebGL2Device, this._curGPUPipelineState, this._curGPUInputAssembler,
|
||||
WebGL2CmdFuncBindStates(WebGL2DeviceManager.instance, this._curGPUPipelineState, this._curGPUInputAssembler,
|
||||
this._curGPUDescriptorSets, this._curDynamicOffsets, this._curDynamicStates);
|
||||
this._isStateInvalied = false;
|
||||
}
|
||||
|
||||
@@ -33,25 +33,20 @@ export class WebGL2Queue extends Queue {
|
||||
public numInstances = 0;
|
||||
public numTris = 0;
|
||||
|
||||
public initialize (info: QueueInfo): boolean {
|
||||
public initialize (info: QueueInfo) {
|
||||
this._type = info.type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
}
|
||||
|
||||
public submit (cmdBuffs: CommandBuffer[]) {
|
||||
// TODO: Async
|
||||
if (!this._isAsync) {
|
||||
for (let i = 0; i < cmdBuffs.length; i++) {
|
||||
const cmdBuff = cmdBuffs[i] as WebGL2CommandBuffer;
|
||||
// WebGL2CmdFuncExecuteCmds(this._device as WebGL2Device, cmdBuff.cmdPackage); // opted out
|
||||
this.numDrawCalls += cmdBuff.numDrawCalls;
|
||||
this.numInstances += cmdBuff.numInstances;
|
||||
this.numTris += cmdBuff.numTris;
|
||||
}
|
||||
for (let i = 0; i < cmdBuffs.length; i++) {
|
||||
const cmdBuff = cmdBuffs[i] as WebGL2CommandBuffer;
|
||||
// WebGL2CmdFuncExecuteCmds(this._device as WebGL2Device, cmdBuff.cmdPackage); // opted out
|
||||
this.numDrawCalls += cmdBuff.numDrawCalls;
|
||||
this.numInstances += cmdBuff.numInstances;
|
||||
this.numTris += cmdBuff.numTris;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,12 +34,10 @@ export class WebGL2RenderPass extends RenderPass {
|
||||
|
||||
private _gpuRenderPass: IWebGL2GPURenderPass | null = null;
|
||||
|
||||
public initialize (info: RenderPassInfo): boolean {
|
||||
public initialize (info: RenderPassInfo) {
|
||||
this._colorInfos = info.colorAttachments;
|
||||
this._depthStencilInfo = info.depthStencilAttachment;
|
||||
if (info.subpasses) {
|
||||
this._subpasses = info.subpasses;
|
||||
}
|
||||
this._subpasses = info.subpasses;
|
||||
|
||||
this._gpuRenderPass = {
|
||||
colorAttachments: this._colorInfos,
|
||||
@@ -47,8 +45,6 @@ export class WebGL2RenderPass extends RenderPass {
|
||||
};
|
||||
|
||||
this._hash = this.computeHash();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { ShaderInfo } from '../base/define';
|
||||
import { Shader } from '../base/shader';
|
||||
import { WebGL2CmdFuncCreateShader, WebGL2CmdFuncDestroyShader } from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
import { IWebGL2GPUShader, IWebGL2GPUShaderStage } from './webgl2-gpu-objects';
|
||||
|
||||
export class WebGL2Shader extends Shader {
|
||||
@@ -36,7 +36,7 @@ export class WebGL2Shader extends Shader {
|
||||
|
||||
private _gpuShader: IWebGL2GPUShader | null = null;
|
||||
|
||||
public initialize (info: ShaderInfo): boolean {
|
||||
public initialize (info: ShaderInfo) {
|
||||
this._name = info.name;
|
||||
this._stages = info.stages;
|
||||
this._attributes = info.attributes;
|
||||
@@ -65,14 +65,12 @@ export class WebGL2Shader extends Shader {
|
||||
};
|
||||
}
|
||||
|
||||
WebGL2CmdFuncCreateShader(this._device as WebGL2Device, this._gpuShader);
|
||||
|
||||
return true;
|
||||
WebGL2CmdFuncCreateShader(WebGL2DeviceManager.instance, this._gpuShader);
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuShader) {
|
||||
WebGL2CmdFuncDestroyShader(this._device as WebGL2Device, this._gpuShader);
|
||||
WebGL2CmdFuncDestroyShader(WebGL2DeviceManager.instance, this._gpuShader);
|
||||
this._gpuShader = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { macro, warnID, warn, debug } from '../../platform';
|
||||
import { WebGL2StateCache } from './webgl2-state-cache';
|
||||
import { WebGL2Texture } from './webgl2-texture';
|
||||
import { Format, TextureInfo, TextureFlagBit, TextureType, TextureUsageBit, BufferTextureCopy, SwapchainInfo } from '../base/define';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { IWebGL2Extensions, WebGL2DeviceManager } from './webgl2-define';
|
||||
|
||||
const eventWebGLContextLost = 'webglcontextlost';
|
||||
|
||||
function initStates (gl: WebGL2RenderingContext) {
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.pixelStorei(gl.PACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
// rasterizer state
|
||||
gl.enable(gl.SCISSOR_TEST);
|
||||
gl.enable(gl.CULL_FACE);
|
||||
gl.cullFace(gl.BACK);
|
||||
gl.frontFace(gl.CCW);
|
||||
gl.polygonOffset(0.0, 0.0);
|
||||
|
||||
// depth stencil state
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthMask(true);
|
||||
gl.depthFunc(gl.LESS);
|
||||
|
||||
gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.FRONT, 0xffff);
|
||||
gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 1, 0xffff);
|
||||
gl.stencilOpSeparate(gl.BACK, gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
gl.stencilMaskSeparate(gl.BACK, 0xffff);
|
||||
|
||||
gl.disable(gl.STENCIL_TEST);
|
||||
|
||||
// blend state
|
||||
gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
|
||||
gl.disable(gl.BLEND);
|
||||
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
|
||||
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
||||
gl.colorMask(true, true, true, true);
|
||||
gl.blendColor(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
function getExtension (gl: WebGL2RenderingContext, ext: string): any {
|
||||
const prefixes = ['', 'WEBKIT_', 'MOZ_'];
|
||||
for (let i = 0; i < prefixes.length; ++i) {
|
||||
const _ext = gl.getExtension(prefixes[i] + ext);
|
||||
if (_ext) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return _ext;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getExtensions (gl: WebGL2RenderingContext) {
|
||||
const res: IWebGL2Extensions = {
|
||||
EXT_texture_filter_anisotropic: getExtension(gl, 'EXT_texture_filter_anisotropic'),
|
||||
EXT_color_buffer_half_float: getExtension(gl, 'EXT_color_buffer_half_float'),
|
||||
EXT_color_buffer_float: getExtension(gl, 'EXT_color_buffer_float'),
|
||||
WEBGL_multi_draw: getExtension(gl, 'WEBGL_multi_draw'),
|
||||
WEBGL_compressed_texture_etc1: getExtension(gl, 'WEBGL_compressed_texture_etc1'),
|
||||
WEBGL_compressed_texture_etc: getExtension(gl, 'WEBGL_compressed_texture_etc'),
|
||||
WEBGL_compressed_texture_pvrtc: getExtension(gl, 'WEBGL_compressed_texture_pvrtc'),
|
||||
WEBGL_compressed_texture_astc: getExtension(gl, 'WEBGL_compressed_texture_astc'),
|
||||
WEBGL_compressed_texture_s3tc: getExtension(gl, 'WEBGL_compressed_texture_s3tc'),
|
||||
WEBGL_compressed_texture_s3tc_srgb: getExtension(gl, 'WEBGL_compressed_texture_s3tc_srgb'),
|
||||
WEBGL_debug_shaders: getExtension(gl, 'WEBGL_debug_shaders'),
|
||||
WEBGL_lose_context: getExtension(gl, 'WEBGL_lose_context'),
|
||||
WEBGL_debug_renderer_info: getExtension(gl, 'WEBGL_debug_renderer_info'),
|
||||
OES_texture_half_float_linear: getExtension(gl, 'OES_texture_half_float_linear'),
|
||||
OES_texture_float_linear: getExtension(gl, 'OES_texture_float_linear'),
|
||||
useVAO: true,
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export class WebGL2Swapchain extends Swapchain {
|
||||
get gl () {
|
||||
return this._webGL2RC as WebGL2RenderingContext;
|
||||
}
|
||||
|
||||
get extensions () {
|
||||
return this._extensions as IWebGL2Extensions;
|
||||
}
|
||||
|
||||
public stateCache: WebGL2StateCache = new WebGL2StateCache();
|
||||
public nullTex2D: WebGL2Texture = null!;
|
||||
public nullTexCube: WebGL2Texture = null!;
|
||||
|
||||
private _canvas: HTMLCanvasElement | null = null;
|
||||
private _webGL2RC: WebGL2RenderingContext | null = null;
|
||||
private _webGL2ContextLostHandler: ((event: Event) => void) | null = null;
|
||||
private _extensions: IWebGL2Extensions | null = null;
|
||||
|
||||
public initialize (info: SwapchainInfo) {
|
||||
this._canvas = info.windowHandle;
|
||||
|
||||
try {
|
||||
const webGLCtxAttribs: WebGLContextAttributes = {
|
||||
alpha: macro.ENABLE_TRANSPARENT_CANVAS,
|
||||
antialias: EDITOR || macro.ENABLE_WEBGL_ANTIALIAS,
|
||||
depth: true,
|
||||
stencil: true,
|
||||
premultipliedAlpha: false,
|
||||
preserveDrawingBuffer: false,
|
||||
powerPreference: 'default',
|
||||
failIfMajorPerformanceCaveat: false,
|
||||
};
|
||||
|
||||
this._webGL2RC = this._canvas.getContext('webgl2', webGLCtxAttribs);
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._webGL2RC) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._webGL2ContextLostHandler = this._onWebGLContextLost.bind(this);
|
||||
this._canvas.addEventListener(eventWebGLContextLost, this._onWebGLContextLost);
|
||||
|
||||
const gl = this.gl;
|
||||
|
||||
this.stateCache.initialize(
|
||||
WebGL2DeviceManager.instance.capabilities.maxTextureUnits,
|
||||
WebGL2DeviceManager.instance.capabilities.maxUniformBufferBindings,
|
||||
WebGL2DeviceManager.instance.capabilities.maxVertexAttributes,
|
||||
);
|
||||
|
||||
this._extensions = getExtensions(gl);
|
||||
|
||||
// init states
|
||||
initStates(gl);
|
||||
|
||||
const colorFmt = Format.RGBA8;
|
||||
let depthStencilFmt = Format.UNKNOWN;
|
||||
|
||||
const depthBits = gl.getParameter(gl.DEPTH_BITS);
|
||||
const stencilBits = gl.getParameter(gl.STENCIL_BITS);
|
||||
|
||||
if (depthBits && stencilBits) depthStencilFmt = Format.DEPTH_STENCIL;
|
||||
else if (depthBits) depthStencilFmt = Format.DEPTH;
|
||||
|
||||
this._colorTexture = new WebGL2Texture();
|
||||
// @ts-expect-error(2445) private initializer
|
||||
this._colorTexture.initAsSwapchainTexture({
|
||||
swapchain: this,
|
||||
format: colorFmt,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
});
|
||||
|
||||
this._depthStencilTexture = new WebGL2Texture();
|
||||
// @ts-expect-error(2445) private initializer
|
||||
this._depthStencilTexture.initAsSwapchainTexture({
|
||||
swapchain: this,
|
||||
format: depthStencilFmt,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
});
|
||||
|
||||
// create default null texture
|
||||
this.nullTex2D = WebGL2DeviceManager.instance.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
)) as WebGL2Texture;
|
||||
|
||||
this.nullTexCube = WebGL2DeviceManager.instance.createTexture(new TextureInfo(
|
||||
TextureType.CUBE,
|
||||
TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
2,
|
||||
2,
|
||||
TextureFlagBit.GEN_MIPMAP,
|
||||
6,
|
||||
)) as WebGL2Texture;
|
||||
|
||||
const nullTexRegion = new BufferTextureCopy();
|
||||
nullTexRegion.texExtent.width = 2;
|
||||
nullTexRegion.texExtent.height = 2;
|
||||
|
||||
const nullTexBuff = new Uint8Array(this.nullTex2D.size);
|
||||
nullTexBuff.fill(0);
|
||||
WebGL2DeviceManager.instance.copyBuffersToTexture([nullTexBuff], this.nullTex2D, [nullTexRegion]);
|
||||
|
||||
nullTexRegion.texSubres.layerCount = 6;
|
||||
WebGL2DeviceManager.instance.copyBuffersToTexture(
|
||||
[nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff],
|
||||
this.nullTexCube, [nullTexRegion],
|
||||
);
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
if (this._canvas && this._webGL2ContextLostHandler) {
|
||||
this._canvas.removeEventListener(eventWebGLContextLost, this._webGL2ContextLostHandler);
|
||||
this._webGL2ContextLostHandler = null;
|
||||
}
|
||||
|
||||
if (this.nullTex2D) {
|
||||
this.nullTex2D.destroy();
|
||||
this.nullTex2D = null!;
|
||||
}
|
||||
|
||||
if (this.nullTexCube) {
|
||||
this.nullTexCube.destroy();
|
||||
this.nullTexCube = null!;
|
||||
}
|
||||
|
||||
this._extensions = null;
|
||||
this._webGL2RC = null;
|
||||
this._canvas = null;
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
if (this._canvas!.width !== width || this._canvas!.height !== height) {
|
||||
debug(`Resizing swapchain: ${width}x${height}`);
|
||||
this._canvas!.width = width;
|
||||
this._canvas!.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
private _onWebGLContextLost (event: Event) {
|
||||
warnID(11000);
|
||||
warn(event);
|
||||
// 2020.9.3: `preventDefault` is not available on some platforms
|
||||
// event.preventDefault();
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,11 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { TextureFlagBit, FormatSurfaceSize, TextureInfo, IsPowerOf2, TextureViewInfo } from '../base/define';
|
||||
import { FormatSurfaceSize, TextureInfo, IsPowerOf2, TextureViewInfo, ISwapchainTextureInfo,
|
||||
FormatInfos, TextureUsageBit, TextureFlagBit } from '../base/define';
|
||||
import { Texture } from '../base/texture';
|
||||
import { WebGL2CmdFuncCreateTexture, WebGL2CmdFuncDestroyTexture, WebGL2CmdFuncResizeTexture } from './webgl2-commands';
|
||||
import { WebGL2Device } from './webgl2-device';
|
||||
import { WebGL2DeviceManager } from './webgl2-define';
|
||||
import { IWebGL2GPUTexture } from './webgl2-gpu-objects';
|
||||
|
||||
export class WebGL2Texture extends Texture {
|
||||
@@ -36,10 +37,10 @@ export class WebGL2Texture extends Texture {
|
||||
|
||||
private _gpuTexture: IWebGL2GPUTexture | null = null;
|
||||
|
||||
public initialize (info: TextureInfo | TextureViewInfo): boolean {
|
||||
public initialize (info: TextureInfo | TextureViewInfo, isSwapchainTexture?: boolean) {
|
||||
if ('texture' in info) {
|
||||
console.log('WebGL2 does not support texture view.');
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
this._type = info.type;
|
||||
@@ -81,24 +82,28 @@ export class WebGL2Texture extends Texture {
|
||||
glWrapT: 0,
|
||||
glMinFilter: 0,
|
||||
glMagFilter: 0,
|
||||
|
||||
isSwapchainTexture: isSwapchainTexture || false,
|
||||
};
|
||||
|
||||
WebGL2CmdFuncCreateTexture(this._device as WebGL2Device, this._gpuTexture);
|
||||
WebGL2CmdFuncCreateTexture(WebGL2DeviceManager.instance, this._gpuTexture);
|
||||
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
|
||||
return true;
|
||||
WebGL2DeviceManager.instance.memoryStatus.textureSize += this._size;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._gpuTexture) {
|
||||
WebGL2CmdFuncDestroyTexture(this._device as WebGL2Device, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= this._size;
|
||||
WebGL2CmdFuncDestroyTexture(WebGL2DeviceManager.instance, this._gpuTexture);
|
||||
WebGL2DeviceManager.instance.memoryStatus.textureSize -= this._size;
|
||||
this._gpuTexture = null;
|
||||
}
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
if (!(this._flags & TextureFlagBit.RESIZABLE)) {
|
||||
console.error('Cannot resize immutable textures');
|
||||
}
|
||||
|
||||
const oldSize = this._size;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
@@ -109,9 +114,20 @@ export class WebGL2Texture extends Texture {
|
||||
this._gpuTexture.width = width;
|
||||
this._gpuTexture.height = height;
|
||||
this._gpuTexture.size = this._size;
|
||||
WebGL2CmdFuncResizeTexture(this._device as WebGL2Device, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= oldSize;
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
WebGL2CmdFuncResizeTexture(WebGL2DeviceManager.instance, this._gpuTexture);
|
||||
WebGL2DeviceManager.instance.memoryStatus.textureSize -= oldSize;
|
||||
WebGL2DeviceManager.instance.memoryStatus.textureSize += this._size;
|
||||
}
|
||||
}
|
||||
|
||||
// ======================= Swapchain Specific ======================= //
|
||||
|
||||
protected initAsSwapchainTexture (info: ISwapchainTextureInfo) {
|
||||
const texInfo = new TextureInfo();
|
||||
texInfo.format = info.format;
|
||||
texInfo.usage = FormatInfos[info.format].hasDepth ? TextureUsageBit.DEPTH_STENCIL_ATTACHMENT : TextureUsageBit.COLOR_ATTACHMENT;
|
||||
texInfo.width = info.width;
|
||||
texInfo.height = info.height;
|
||||
this.initialize(texInfo, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,6 @@ export function countTrailingZeros (v: number) {
|
||||
* @zh 计算大于等于v的最小的二的整数次幂的数字。
|
||||
*/
|
||||
export function nextPow2 (v: number) {
|
||||
v += ((v === 0) as unknown as number);
|
||||
--v;
|
||||
v |= v >>> 1;
|
||||
v |= v >>> 2;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
import { ccclass, displayOrder, type, serializable } from 'cc.decorator';
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib';
|
||||
import { builtinResMgr } from '../../builtin/builtin-res-mgr';
|
||||
import { Texture2D } from '../../assets/texture-2d';
|
||||
import { RenderPipeline, IRenderPipelineInfo } from '../render-pipeline';
|
||||
@@ -39,27 +38,25 @@ import { ShadowFlow } from '../shadow/shadow-flow';
|
||||
import { BufferUsageBit, Format, MemoryUsageBit, ClearFlagBit, ClearFlags, StoreOp, Filter, Address,
|
||||
SurfaceTransform, ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp,
|
||||
RenderPassInfo, BufferInfo, Texture, InputAssembler, InputAssemblerInfo, Attribute, Buffer, AccessType, Framebuffer,
|
||||
TextureInfo, TextureType, TextureUsageBit, FramebufferInfo, Rect } from '../../gfx';
|
||||
import { UBOGlobal, UBOCamera, UBOShadow, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, UNIFORM_GBUFFER_ALBEDOMAP_BINDING,
|
||||
UNIFORM_GBUFFER_POSITIONMAP_BINDING, UNIFORM_GBUFFER_NORMALMAP_BINDING, UNIFORM_GBUFFER_EMISSIVEMAP_BINDING, UNIFORM_LIGHTING_RESULTMAP_BINDING } from '../define';
|
||||
TextureInfo, TextureType, TextureUsageBit, FramebufferInfo, Rect, Swapchain, SamplerInfo, Sampler } from '../../gfx';
|
||||
import { UBOGlobal, UBOCamera, UBOShadow, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING } from '../define';
|
||||
import { SKYBOX_FLAG } from '../../renderer/scene/camera';
|
||||
import { Camera } from '../../renderer/scene';
|
||||
import { errorID } from '../../platform/debug';
|
||||
import { sceneCulling } from '../scene-culling';
|
||||
import { DeferredPipelineSceneData } from './deferred-pipeline-scene-data';
|
||||
import { RenderWindow } from '../../renderer/core/render-window';
|
||||
|
||||
const PIPELINE_TYPE = 1;
|
||||
|
||||
const _samplerInfo = [
|
||||
const _samplerInfo = new SamplerInfo(
|
||||
Filter.POINT,
|
||||
Filter.POINT,
|
||||
Filter.NONE,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
];
|
||||
|
||||
const samplerHash = genSamplerHash(_samplerInfo);
|
||||
);
|
||||
|
||||
class InputAssemblerData {
|
||||
quadIB: Buffer|null = null;
|
||||
@@ -68,11 +65,12 @@ class InputAssemblerData {
|
||||
}
|
||||
|
||||
export class DeferredRenderData {
|
||||
gbufferFrameBuffer: Framebuffer | null = null;
|
||||
gbufferFrameBuffer: Framebuffer = null!;
|
||||
gbufferRenderTargets: Texture[] = [];
|
||||
lightingFrameBuffer: Framebuffer | null = null;
|
||||
lightingFrameBuffer: Framebuffer = null!;
|
||||
lightingRenderTargets: Texture[] = [];
|
||||
depthTex: Texture | null = null;
|
||||
depthTex: Texture = null!;
|
||||
sampler: Sampler = null!;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,17 +125,20 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
return true;
|
||||
}
|
||||
|
||||
public activate (): boolean {
|
||||
if (EDITOR) { console.info('Deferred render pipeline initialized. Note that non-transparent materials with no lighting will not be rendered, such as builtin-unlit.'); }
|
||||
public activate (swapchain: Swapchain): boolean {
|
||||
if (EDITOR) {
|
||||
console.info('Deferred render pipeline initialized. '
|
||||
+ 'Note that non-transparent materials with no lighting will not be rendered, such as builtin-unlit.');
|
||||
}
|
||||
|
||||
this._macros = { CC_PIPELINE_TYPE: PIPELINE_TYPE };
|
||||
this._pipelineSceneData = new DeferredPipelineSceneData();
|
||||
|
||||
if (!super.activate()) {
|
||||
if (!super.activate(swapchain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this._activeRenderer()) {
|
||||
if (!this._activeRenderer(swapchain)) {
|
||||
errorID(2402);
|
||||
return false;
|
||||
}
|
||||
@@ -151,7 +152,7 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
}
|
||||
|
||||
this._commandBuffers[0].begin();
|
||||
this._pipelineUBO.updateGlobalUBO();
|
||||
this._pipelineUBO.updateGlobalUBO(cameras[0].window!); // TODO: window size is also camera-specific
|
||||
for (let i = 0; i < cameras.length; i++) {
|
||||
const camera = cameras[i];
|
||||
if (camera.scene) {
|
||||
@@ -166,15 +167,15 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
this._device.queue.submit(this._commandBuffers);
|
||||
}
|
||||
|
||||
public getRenderPass (clearFlags: ClearFlags): RenderPass {
|
||||
public getRenderPass (clearFlags: ClearFlags, swapchain: Swapchain): RenderPass {
|
||||
let renderPass = this._renderPasses.get(clearFlags);
|
||||
if (renderPass) { return renderPass; }
|
||||
|
||||
const device = this.device;
|
||||
const device = this._device;
|
||||
const colorAttachment = new ColorAttachment();
|
||||
const depthStencilAttachment = new DepthStencilAttachment();
|
||||
colorAttachment.format = device.colorFormat;
|
||||
depthStencilAttachment.format = device.depthStencilFormat;
|
||||
colorAttachment.format = swapchain.colorTexture.format;
|
||||
depthStencilAttachment.format = swapchain.depthStencilTexture.format;
|
||||
depthStencilAttachment.stencilStoreOp = StoreOp.DISCARD;
|
||||
depthStencilAttachment.depthStoreOp = StoreOp.DISCARD;
|
||||
|
||||
@@ -183,15 +184,15 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
colorAttachment.loadOp = LoadOp.DISCARD;
|
||||
} else {
|
||||
colorAttachment.loadOp = LoadOp.LOAD;
|
||||
colorAttachment.beginAccesses = [AccessType.PRESENT];
|
||||
colorAttachment.beginAccesses = [AccessType.COLOR_ATTACHMENT_WRITE];
|
||||
}
|
||||
}
|
||||
|
||||
if ((clearFlags & ClearFlagBit.DEPTH_STENCIL) !== ClearFlagBit.DEPTH_STENCIL) {
|
||||
if (!(clearFlags & ClearFlagBit.DEPTH)) depthStencilAttachment.depthLoadOp = LoadOp.LOAD;
|
||||
if (!(clearFlags & ClearFlagBit.STENCIL)) depthStencilAttachment.stencilLoadOp = LoadOp.LOAD;
|
||||
depthStencilAttachment.beginAccesses = [AccessType.DEPTH_STENCIL_ATTACHMENT_WRITE];
|
||||
}
|
||||
depthStencilAttachment.beginAccesses = [AccessType.DEPTH_STENCIL_ATTACHMENT_WRITE];
|
||||
|
||||
const renderPassInfo = new RenderPassInfo([colorAttachment], depthStencilAttachment);
|
||||
renderPass = device.createRenderPass(renderPassInfo);
|
||||
@@ -200,7 +201,7 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
return renderPass;
|
||||
}
|
||||
|
||||
public getDeferredRenderData (camera): DeferredRenderData {
|
||||
public getDeferredRenderData (): DeferredRenderData {
|
||||
if (!this._deferredRenderData) {
|
||||
this._generateDeferredRenderData();
|
||||
}
|
||||
@@ -208,12 +209,12 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
return this._deferredRenderData!;
|
||||
}
|
||||
|
||||
private _activeRenderer () {
|
||||
private _activeRenderer (swapchain: Swapchain) {
|
||||
const device = this.device;
|
||||
|
||||
this._commandBuffers.push(device.commandBuffer);
|
||||
|
||||
const sampler = samplerLib.getSampler(device, samplerHash);
|
||||
const sampler = device.getSampler(_samplerInfo);
|
||||
this._descriptorSet.bindSampler(UNIFORM_SHADOWMAP_BINDING, sampler);
|
||||
this._descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
this._descriptorSet.bindSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, sampler);
|
||||
@@ -221,7 +222,7 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
this._descriptorSet.update();
|
||||
|
||||
let inputAssemblerDataOffscreen = new InputAssemblerData();
|
||||
inputAssemblerDataOffscreen = this.createQuadInputAssembler(SurfaceTransform.IDENTITY);
|
||||
inputAssemblerDataOffscreen = this.createQuadInputAssembler();
|
||||
if (!inputAssemblerDataOffscreen.quadIB || !inputAssemblerDataOffscreen.quadVB || !inputAssemblerDataOffscreen.quadIA) {
|
||||
return false;
|
||||
}
|
||||
@@ -229,7 +230,7 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
this._quadVBOffscreen = inputAssemblerDataOffscreen.quadVB;
|
||||
this._quadIAOffscreen = inputAssemblerDataOffscreen.quadIA;
|
||||
|
||||
const inputAssemblerDataOnscreen = this.createQuadInputAssembler(device.surfaceTransform);
|
||||
const inputAssemblerDataOnscreen = this.createQuadInputAssembler();
|
||||
if (!inputAssemblerDataOnscreen.quadIB || !inputAssemblerDataOnscreen.quadVB || !inputAssemblerDataOnscreen.quadIA) {
|
||||
return false;
|
||||
}
|
||||
@@ -258,13 +259,15 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
colorAttachment3.storeOp = StoreOp.STORE;
|
||||
|
||||
const depthStencilAttachment = new DepthStencilAttachment();
|
||||
depthStencilAttachment.format = device.depthStencilFormat;
|
||||
depthStencilAttachment.format = Format.DEPTH_STENCIL;
|
||||
depthStencilAttachment.depthLoadOp = LoadOp.CLEAR;
|
||||
depthStencilAttachment.depthStoreOp = StoreOp.STORE;
|
||||
depthStencilAttachment.stencilLoadOp = LoadOp.CLEAR;
|
||||
depthStencilAttachment.stencilStoreOp = StoreOp.STORE;
|
||||
const renderPassInfo = new RenderPassInfo([colorAttachment0, colorAttachment1, colorAttachment2, colorAttachment3],
|
||||
depthStencilAttachment);
|
||||
const renderPassInfo = new RenderPassInfo(
|
||||
[colorAttachment0, colorAttachment1, colorAttachment2, colorAttachment3],
|
||||
depthStencilAttachment,
|
||||
);
|
||||
this._gbufferRenderPass = device.createRenderPass(renderPassInfo);
|
||||
}
|
||||
|
||||
@@ -276,7 +279,7 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
colorAttachment.endAccesses = [AccessType.COLOR_ATTACHMENT_WRITE];
|
||||
|
||||
const depthStencilAttachment = new DepthStencilAttachment();
|
||||
depthStencilAttachment.format = device.depthStencilFormat;
|
||||
depthStencilAttachment.format = Format.DEPTH_STENCIL;
|
||||
depthStencilAttachment.depthLoadOp = LoadOp.LOAD;
|
||||
depthStencilAttachment.depthStoreOp = StoreOp.DISCARD;
|
||||
depthStencilAttachment.stencilLoadOp = LoadOp.LOAD;
|
||||
@@ -288,8 +291,8 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
this._lightingRenderPass = device.createRenderPass(renderPassInfo);
|
||||
}
|
||||
|
||||
this._width = device.width;
|
||||
this._height = device.height;
|
||||
this._width = swapchain.width;
|
||||
this._height = swapchain.height;
|
||||
this._generateDeferredRenderData();
|
||||
|
||||
return true;
|
||||
@@ -300,8 +303,6 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
this._descriptorSet.getBuffer(UBOGlobal.BINDING).destroy();
|
||||
this._descriptorSet.getBuffer(UBOShadow.BINDING).destroy();
|
||||
this._descriptorSet.getBuffer(UBOCamera.BINDING).destroy();
|
||||
this._descriptorSet.getSampler(UNIFORM_SHADOWMAP_BINDING).destroy();
|
||||
this._descriptorSet.getSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING).destroy();
|
||||
this._descriptorSet.getTexture(UNIFORM_SHADOWMAP_BINDING).destroy();
|
||||
this._descriptorSet.getTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING).destroy();
|
||||
}
|
||||
@@ -359,7 +360,7 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
* @zh
|
||||
* 创建四边形输入汇集器。
|
||||
*/
|
||||
protected createQuadInputAssembler (surfaceTransform: SurfaceTransform): InputAssemblerData {
|
||||
protected createQuadInputAssembler (): InputAssemblerData {
|
||||
// create vertex buffer
|
||||
const inputAssemblerData = new InputAssemblerData();
|
||||
|
||||
@@ -416,26 +417,26 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
return inputAssemblerData;
|
||||
}
|
||||
|
||||
public updateQuadVertexData (renderArea: Rect) {
|
||||
public updateQuadVertexData (renderArea: Rect, window: RenderWindow) {
|
||||
if (this._lastUsedRenderArea === renderArea) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._lastUsedRenderArea = renderArea;
|
||||
const offData = this.genQuadVertexData(SurfaceTransform.IDENTITY, renderArea);
|
||||
const offData = this.genQuadVertexData(SurfaceTransform.IDENTITY, renderArea, window);
|
||||
this._quadVBOffscreen!.update(offData);
|
||||
|
||||
const onData = this.genQuadVertexData(this.device.surfaceTransform, renderArea);
|
||||
const onData = this.genQuadVertexData(window.swapchain && window.swapchain.surfaceTransform || SurfaceTransform.IDENTITY, renderArea, window);
|
||||
this._quadVBOnscreen!.update(onData);
|
||||
}
|
||||
|
||||
protected genQuadVertexData (surfaceTransform: SurfaceTransform, renderArea: Rect) : Float32Array {
|
||||
protected genQuadVertexData (surfaceTransform: SurfaceTransform, renderArea: Rect, window: RenderWindow) : Float32Array {
|
||||
const vbData = new Float32Array(4 * 4);
|
||||
|
||||
const minX = renderArea.x / this.device.width;
|
||||
const maxX = (renderArea.x + renderArea.width) / this.device.width;
|
||||
let minY = renderArea.y / this.device.height;
|
||||
let maxY = (renderArea.y + renderArea.height) / this.device.height;
|
||||
const minX = renderArea.x / window.width;
|
||||
const maxX = (renderArea.x + renderArea.width) / window.width;
|
||||
let minY = renderArea.y / window.height;
|
||||
let maxY = (renderArea.y + renderArea.height) / window.height;
|
||||
if (this.device.capabilities.screenSpaceSignY > 0) {
|
||||
const temp = maxY;
|
||||
maxY = minY;
|
||||
@@ -514,41 +515,19 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
|
||||
const data: DeferredRenderData = this._deferredRenderData = new DeferredRenderData();
|
||||
|
||||
data.gbufferRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.RGBA16F,
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
|
||||
data.gbufferRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.RGBA16F,
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
|
||||
data.gbufferRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.RGBA16F,
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
data.gbufferRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.RGBA16F,
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
data.gbufferRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
i % 3 ? Format.RGBA16F : Format.RGBA8, // positions & normals need more precision
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
}
|
||||
data.depthTex = device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.DEPTH_STENCIL_ATTACHMENT,
|
||||
device.depthStencilFormat,
|
||||
Format.DEPTH_STENCIL,
|
||||
this._width,
|
||||
this._height,
|
||||
));
|
||||
@@ -573,17 +552,6 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
data.depthTex,
|
||||
));
|
||||
|
||||
this._descriptorSet.bindTexture(UNIFORM_GBUFFER_ALBEDOMAP_BINDING, data.gbufferFrameBuffer.colorTextures[0]!);
|
||||
this._descriptorSet.bindTexture(UNIFORM_GBUFFER_POSITIONMAP_BINDING, data.gbufferFrameBuffer.colorTextures[1]!);
|
||||
this._descriptorSet.bindTexture(UNIFORM_GBUFFER_NORMALMAP_BINDING, data.gbufferFrameBuffer.colorTextures[2]!);
|
||||
this._descriptorSet.bindTexture(UNIFORM_GBUFFER_EMISSIVEMAP_BINDING, data.gbufferFrameBuffer.colorTextures[3]!);
|
||||
this._descriptorSet.bindTexture(UNIFORM_LIGHTING_RESULTMAP_BINDING, data.lightingFrameBuffer.colorTextures[0]!);
|
||||
|
||||
const sampler = samplerLib.getSampler(device, samplerHash);
|
||||
this._descriptorSet.bindSampler(UNIFORM_GBUFFER_ALBEDOMAP_BINDING, sampler);
|
||||
this._descriptorSet.bindSampler(UNIFORM_GBUFFER_POSITIONMAP_BINDING, sampler);
|
||||
this._descriptorSet.bindSampler(UNIFORM_GBUFFER_NORMALMAP_BINDING, sampler);
|
||||
this._descriptorSet.bindSampler(UNIFORM_GBUFFER_EMISSIVEMAP_BINDING, sampler);
|
||||
this._descriptorSet.bindSampler(UNIFORM_LIGHTING_RESULTMAP_BINDING, sampler);
|
||||
data.sampler = device.getSampler(_samplerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export class GbufferStage extends RenderStage {
|
||||
private _renderArea = new Rect();
|
||||
private _batchedQueue: RenderBatchedQueue;
|
||||
private _instancedQueue: RenderInstancedQueue;
|
||||
private _phaseID = getPhaseID('deferred');
|
||||
private _phaseID = getPhaseID('default');
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
@@ -152,7 +152,7 @@ export class GbufferStage extends RenderStage {
|
||||
this._instancedQueue.uploadBuffers(cmdBuff);
|
||||
this._batchedQueue.uploadBuffers(cmdBuff);
|
||||
this._renderArea = pipeline.generateRenderArea(camera);
|
||||
pipeline.updateQuadVertexData(this._renderArea);
|
||||
pipeline.updateQuadVertexData(this._renderArea, camera.window!);
|
||||
|
||||
if (camera.clearFlag & ClearFlagBit.COLOR) {
|
||||
if (pipeline.pipelineSceneData.isHDR) {
|
||||
@@ -170,8 +170,8 @@ export class GbufferStage extends RenderStage {
|
||||
|
||||
colors[0].w = camera.clearColor.w;
|
||||
|
||||
const deferredData = pipeline.getDeferredRenderData(camera);
|
||||
const framebuffer = deferredData.gbufferFrameBuffer!;
|
||||
const deferredData = pipeline.getDeferredRenderData();
|
||||
const framebuffer = deferredData.gbufferFrameBuffer;
|
||||
const renderPass = framebuffer.renderPass;
|
||||
|
||||
cmdBuff.beginRenderPass(renderPass, framebuffer, this._renderArea,
|
||||
|
||||
@@ -44,7 +44,6 @@ import { intersect, Sphere } from '../../geometry';
|
||||
import { Vec3, Vec4 } from '../../math';
|
||||
import { SRGBToLinear } from '../pipeline-funcs';
|
||||
import { DeferredPipelineSceneData } from './deferred-pipeline-scene-data';
|
||||
import { Pass } from '../../renderer/core/pass';
|
||||
import { renderQueueClearFunc, RenderQueue, convertRenderQueue, renderQueueSortFunc } from '../render-queue';
|
||||
import { RenderQueueDesc } from '../pipeline-serialization';
|
||||
|
||||
@@ -75,7 +74,6 @@ export class LightingStage extends RenderStage {
|
||||
@displayOrder(2)
|
||||
private renderQueues: RenderQueueDesc[] = [];
|
||||
private _phaseID = getPhaseID('default');
|
||||
private _defPhaseID = getPhaseID('deferred');
|
||||
private _renderQueues: RenderQueue[] = [];
|
||||
|
||||
public static initInfo: IRenderStageInfo = {
|
||||
@@ -253,8 +251,8 @@ export class LightingStage extends RenderStage {
|
||||
}
|
||||
|
||||
colors[0].w = 0;
|
||||
const deferredData = pipeline.getDeferredRenderData(camera);
|
||||
const framebuffer = deferredData.lightingFrameBuffer!;
|
||||
const deferredData = pipeline.getDeferredRenderData();
|
||||
const framebuffer = deferredData.lightingFrameBuffer;
|
||||
const renderPass = framebuffer.renderPass;
|
||||
|
||||
cmdBuff.beginRenderPass(renderPass, framebuffer, this._renderArea,
|
||||
@@ -266,6 +264,13 @@ export class LightingStage extends RenderStage {
|
||||
const lightingMat = (sceneData as DeferredPipelineSceneData).deferredLightingMaterial;
|
||||
const pass = lightingMat.passes[0];
|
||||
const shader = pass.getShaderVariant();
|
||||
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
pass.descriptorSet.bindTexture(i, deferredData.gbufferRenderTargets[i]);
|
||||
pass.descriptorSet.bindSampler(i, deferredData.sampler);
|
||||
}
|
||||
pass.descriptorSet.update();
|
||||
|
||||
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, pass.descriptorSet);
|
||||
|
||||
const inputAssembler = pipeline.quadIAOffscreen;
|
||||
@@ -292,8 +297,7 @@ export class LightingStage extends RenderStage {
|
||||
const passes = subModel.passes;
|
||||
for (p = 0; p < passes.length; ++p) {
|
||||
const pass = passes[p];
|
||||
// TODO: need fallback of ulit and gizmo material.
|
||||
if (pass.phase !== this._phaseID && pass.phase !== this._defPhaseID) continue;
|
||||
if (pass.phase !== this._phaseID) continue;
|
||||
for (k = 0; k < this._renderQueues.length; k++) {
|
||||
this._renderQueues[k].insertRenderPass(ro, m, p);
|
||||
}
|
||||
|
||||
@@ -38,9 +38,7 @@ import { Material } from '../../assets/material';
|
||||
import { PipelineStateManager } from '../pipeline-state-manager';
|
||||
import { UIPhase } from '../forward/ui-phase';
|
||||
import { MainFlow } from './main-flow';
|
||||
import { opaqueCompareFn, RenderQueue, transparentCompareFn } from '../render-queue';
|
||||
import { RenderQueueDesc, RenderQueueSortMode } from '../pipeline-serialization';
|
||||
import { getPhaseID } from '../pass-phase';
|
||||
import { RenderQueueDesc } from '../pipeline-serialization';
|
||||
import { DeferredPipelineSceneData } from './deferred-pipeline-scene-data';
|
||||
|
||||
const colors: Color[] = [new Color(0, 0, 0, 1)];
|
||||
@@ -104,7 +102,8 @@ export class PostprocessStage extends RenderStage {
|
||||
this._renderArea.height = vp.height * camera.height * sceneData.shadingScale;
|
||||
|
||||
const framebuffer = camera.window!.framebuffer;
|
||||
const renderPass = framebuffer.colorTextures[0] ? framebuffer.renderPass : pipeline.getRenderPass(camera.clearFlag);
|
||||
const swapchain = camera.window!.swapchain;
|
||||
const renderPass = swapchain ? pipeline.getRenderPass(camera.clearFlag, swapchain) : framebuffer.renderPass;
|
||||
|
||||
if (camera.clearFlag & ClearFlagBit.COLOR) {
|
||||
colors[0].x = camera.clearColor.x;
|
||||
@@ -113,6 +112,7 @@ export class PostprocessStage extends RenderStage {
|
||||
}
|
||||
|
||||
colors[0].w = camera.clearColor.w;
|
||||
const deferredData = pipeline.getDeferredRenderData();
|
||||
|
||||
cmdBuff.beginRenderPass(renderPass, framebuffer, this._renderArea,
|
||||
colors, camera.clearDepth, camera.clearStencil);
|
||||
@@ -123,9 +123,14 @@ export class PostprocessStage extends RenderStage {
|
||||
const builtinPostProcess = (sceneData as DeferredPipelineSceneData).deferredPostMaterial;
|
||||
const pass = builtinPostProcess.passes[0];
|
||||
const shader = pass.getShaderVariant();
|
||||
|
||||
pass.descriptorSet.bindTexture(0, deferredData.lightingRenderTargets[0]);
|
||||
pass.descriptorSet.bindSampler(0, deferredData.sampler);
|
||||
pass.descriptorSet.update();
|
||||
|
||||
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, pass.descriptorSet);
|
||||
|
||||
const inputAssembler = camera.window!.hasOffScreenAttachments ? pipeline.quadIAOffscreen : pipeline.quadIAOnscreen;
|
||||
const inputAssembler = camera.window!.swapchain ? pipeline.quadIAOnscreen : pipeline.quadIAOffscreen;
|
||||
let pso:PipelineState|null = null;
|
||||
if (pass != null && shader != null && inputAssembler != null) {
|
||||
pso = PipelineStateManager.getOrCreatePipelineState(device, pass, shader, renderPass, inputAssembler);
|
||||
|
||||
@@ -121,11 +121,6 @@ export enum PipelineGlobalBindings {
|
||||
SAMPLER_SHADOWMAP,
|
||||
SAMPLER_ENVIRONMENT, // don't put this as the first sampler binding due to Mac GL driver issues: cubemap at texture unit 0 causes rendering issues
|
||||
SAMPLER_SPOT_LIGHTING_MAP,
|
||||
SAMPLER_GBUFFER_ALBEDOMAP,
|
||||
SAMPLER_GBUFFER_POSITIONMAP,
|
||||
SAMPLER_GBUFFER_NORMALMAP,
|
||||
SAMPLER_GBUFFER_EMISSIVEMAP,
|
||||
SAMPLER_LIGHTING_RESULTMAP,
|
||||
|
||||
COUNT,
|
||||
}
|
||||
@@ -285,41 +280,6 @@ const UNIFORM_SHADOWMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIF
|
||||
globalDescriptorSetLayout.layouts[UNIFORM_SHADOWMAP_NAME] = UNIFORM_SHADOWMAP_LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UNIFORM_SHADOWMAP_BINDING] = UNIFORM_SHADOWMAP_DESCRIPTOR;
|
||||
|
||||
const UNIFORM_GBUFFER_ALBEDOMAP_NAME = 'cc_gbuffer_albedoMap';
|
||||
export const UNIFORM_GBUFFER_ALBEDOMAP_BINDING = PipelineGlobalBindings.SAMPLER_GBUFFER_ALBEDOMAP;
|
||||
const UNIFORM_GBUFFER_ALBEDOMAP_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_GBUFFER_ALBEDOMAP_BINDING, DescriptorType.SAMPLER_TEXTURE, 1, ShaderStageFlagBit.FRAGMENT);
|
||||
const UNIFORM_GBUFFER_ALBEDOMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_GBUFFER_ALBEDOMAP_BINDING, UNIFORM_GBUFFER_ALBEDOMAP_NAME, Type.SAMPLER2D, 1);
|
||||
globalDescriptorSetLayout.layouts[UNIFORM_GBUFFER_ALBEDOMAP_NAME] = UNIFORM_GBUFFER_ALBEDOMAP_LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UNIFORM_GBUFFER_ALBEDOMAP_BINDING] = UNIFORM_GBUFFER_ALBEDOMAP_DESCRIPTOR;
|
||||
|
||||
const UNIFORM_GBUFFER_POSITIONMAP_NAME = 'cc_gbuffer_positionMap';
|
||||
export const UNIFORM_GBUFFER_POSITIONMAP_BINDING = PipelineGlobalBindings.SAMPLER_GBUFFER_POSITIONMAP;
|
||||
const UNIFORM_GBUFFER_POSITIONMAP_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_GBUFFER_POSITIONMAP_BINDING, DescriptorType.SAMPLER_TEXTURE, 1, ShaderStageFlagBit.FRAGMENT);
|
||||
const UNIFORM_GBUFFER_POSITIONMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_GBUFFER_POSITIONMAP_BINDING, UNIFORM_GBUFFER_POSITIONMAP_NAME, Type.SAMPLER2D, 1);
|
||||
globalDescriptorSetLayout.layouts[UNIFORM_GBUFFER_POSITIONMAP_NAME] = UNIFORM_GBUFFER_POSITIONMAP_LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UNIFORM_GBUFFER_POSITIONMAP_BINDING] = UNIFORM_GBUFFER_POSITIONMAP_DESCRIPTOR;
|
||||
|
||||
const UNIFORM_GBUFFER_NORMALMAP_NAME = 'cc_gbuffer_normalMap';
|
||||
export const UNIFORM_GBUFFER_NORMALMAP_BINDING = PipelineGlobalBindings.SAMPLER_GBUFFER_NORMALMAP;
|
||||
const UNIFORM_GBUFFER_NORMALMAP_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_GBUFFER_NORMALMAP_BINDING, DescriptorType.SAMPLER_TEXTURE, 1, ShaderStageFlagBit.FRAGMENT);
|
||||
const UNIFORM_GBUFFER_NORMALMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_GBUFFER_NORMALMAP_BINDING, UNIFORM_GBUFFER_NORMALMAP_NAME, Type.SAMPLER2D, 1);
|
||||
globalDescriptorSetLayout.layouts[UNIFORM_GBUFFER_NORMALMAP_NAME] = UNIFORM_GBUFFER_NORMALMAP_LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UNIFORM_GBUFFER_NORMALMAP_BINDING] = UNIFORM_GBUFFER_NORMALMAP_DESCRIPTOR;
|
||||
|
||||
const UNIFORM_LIGHTING_RESULTMAP_NAME = 'cc_lighting_resultMap';
|
||||
export const UNIFORM_LIGHTING_RESULTMAP_BINDING = PipelineGlobalBindings.SAMPLER_LIGHTING_RESULTMAP;
|
||||
const UNIFORM_LIGHTING_RESULTMAP_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_LIGHTING_RESULTMAP_BINDING, DescriptorType.SAMPLER_TEXTURE, 1, ShaderStageFlagBit.FRAGMENT);
|
||||
const UNIFORM_LIGHTING_RESULTMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_LIGHTING_RESULTMAP_BINDING, UNIFORM_LIGHTING_RESULTMAP_NAME, Type.SAMPLER2D, 1);
|
||||
globalDescriptorSetLayout.layouts[UNIFORM_LIGHTING_RESULTMAP_NAME] = UNIFORM_LIGHTING_RESULTMAP_LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UNIFORM_LIGHTING_RESULTMAP_BINDING] = UNIFORM_LIGHTING_RESULTMAP_DESCRIPTOR;
|
||||
|
||||
const UNIFORM_GBUFFER_EMISSIVEMAP_NAME = 'cc_gbuffer_emissiveMap';
|
||||
export const UNIFORM_GBUFFER_EMISSIVEMAP_BINDING = PipelineGlobalBindings.SAMPLER_GBUFFER_EMISSIVEMAP;
|
||||
const UNIFORM_GBUFFER_EMISSIVEMAP_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_GBUFFER_EMISSIVEMAP_BINDING, DescriptorType.SAMPLER_TEXTURE, 1, ShaderStageFlagBit.FRAGMENT);
|
||||
const UNIFORM_GBUFFER_EMISSIVEMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_GBUFFER_EMISSIVEMAP_BINDING, UNIFORM_GBUFFER_EMISSIVEMAP_NAME, Type.SAMPLER2D, 1);
|
||||
globalDescriptorSetLayout.layouts[UNIFORM_GBUFFER_EMISSIVEMAP_NAME] = UNIFORM_GBUFFER_EMISSIVEMAP_LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UNIFORM_GBUFFER_EMISSIVEMAP_BINDING] = UNIFORM_GBUFFER_EMISSIVEMAP_DESCRIPTOR;
|
||||
|
||||
const UNIFORM_ENVIRONMENT_NAME = 'cc_environment';
|
||||
export const UNIFORM_ENVIRONMENT_BINDING = PipelineGlobalBindings.SAMPLER_ENVIRONMENT;
|
||||
const UNIFORM_ENVIRONMENT_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_ENVIRONMENT_BINDING, DescriptorType.SAMPLER_TEXTURE, 1, ShaderStageFlagBit.FRAGMENT);
|
||||
|
||||
@@ -36,26 +36,25 @@ import { RenderTextureConfig } from '../pipeline-serialization';
|
||||
import { ShadowFlow } from '../shadow/shadow-flow';
|
||||
import { UBOGlobal, UBOShadow, UBOCamera, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING } from '../define';
|
||||
import { ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp,
|
||||
RenderPassInfo, ClearFlagBit, ClearFlags, Filter, Address, StoreOp, AccessType } from '../../gfx';
|
||||
RenderPassInfo, ClearFlagBit, ClearFlags, Filter, Address, StoreOp, AccessType, Swapchain, SamplerInfo } from '../../gfx';
|
||||
import { SKYBOX_FLAG } from '../../renderer/scene/camera';
|
||||
import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib';
|
||||
import { builtinResMgr } from '../../builtin';
|
||||
import { Texture2D } from '../../assets/texture-2d';
|
||||
import { Camera } from '../../renderer/scene';
|
||||
import { errorID, warnID } from '../../platform/debug';
|
||||
import { errorID } from '../../platform/debug';
|
||||
import { sceneCulling } from '../scene-culling';
|
||||
import { PipelineSceneData } from '../pipeline-scene-data';
|
||||
|
||||
const PIPELINE_TYPE = 0;
|
||||
|
||||
const _samplerInfo = [
|
||||
const _samplerInfo = new SamplerInfo(
|
||||
Filter.POINT,
|
||||
Filter.POINT,
|
||||
Filter.NONE,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
];
|
||||
);
|
||||
|
||||
/**
|
||||
* @en The forward render pipeline
|
||||
@@ -86,13 +85,13 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
return true;
|
||||
}
|
||||
|
||||
public activate (): boolean {
|
||||
public activate (swapchain: Swapchain): boolean {
|
||||
if (EDITOR) { console.info('Forward render pipeline initialized.'); }
|
||||
|
||||
this._macros = { CC_PIPELINE_TYPE: PIPELINE_TYPE };
|
||||
this._pipelineSceneData = new PipelineSceneData();
|
||||
|
||||
if (!super.activate()) {
|
||||
if (!super.activate(swapchain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -106,7 +105,7 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
public render (cameras: Camera[]) {
|
||||
this._commandBuffers[0].begin();
|
||||
this._pipelineUBO.updateGlobalUBO();
|
||||
this._pipelineUBO.updateGlobalUBO(cameras[0].window!);
|
||||
for (let i = 0; i < cameras.length; i++) {
|
||||
const camera = cameras[i];
|
||||
if (camera.scene) {
|
||||
@@ -122,15 +121,15 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
this._device.queue.submit(this._commandBuffers);
|
||||
}
|
||||
|
||||
public getRenderPass (clearFlags: ClearFlags): RenderPass {
|
||||
public getRenderPass (clearFlags: ClearFlags, swapchain: Swapchain): RenderPass {
|
||||
let renderPass = this._renderPasses.get(clearFlags);
|
||||
if (renderPass) { return renderPass; }
|
||||
|
||||
const device = this.device;
|
||||
const device = this._device;
|
||||
const colorAttachment = new ColorAttachment();
|
||||
const depthStencilAttachment = new DepthStencilAttachment();
|
||||
colorAttachment.format = device.colorFormat;
|
||||
depthStencilAttachment.format = device.depthStencilFormat;
|
||||
colorAttachment.format = swapchain.colorTexture.format;
|
||||
depthStencilAttachment.format = swapchain.depthStencilTexture.format;
|
||||
depthStencilAttachment.stencilStoreOp = StoreOp.DISCARD;
|
||||
depthStencilAttachment.depthStoreOp = StoreOp.DISCARD;
|
||||
|
||||
@@ -139,15 +138,15 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
colorAttachment.loadOp = LoadOp.DISCARD;
|
||||
} else {
|
||||
colorAttachment.loadOp = LoadOp.LOAD;
|
||||
colorAttachment.beginAccesses = [AccessType.PRESENT];
|
||||
colorAttachment.beginAccesses = [AccessType.COLOR_ATTACHMENT_WRITE];
|
||||
}
|
||||
}
|
||||
|
||||
if ((clearFlags & ClearFlagBit.DEPTH_STENCIL) !== ClearFlagBit.DEPTH_STENCIL) {
|
||||
if (!(clearFlags & ClearFlagBit.DEPTH)) depthStencilAttachment.depthLoadOp = LoadOp.LOAD;
|
||||
if (!(clearFlags & ClearFlagBit.STENCIL)) depthStencilAttachment.stencilLoadOp = LoadOp.LOAD;
|
||||
depthStencilAttachment.beginAccesses = [AccessType.DEPTH_STENCIL_ATTACHMENT_WRITE];
|
||||
}
|
||||
depthStencilAttachment.beginAccesses = [AccessType.DEPTH_STENCIL_ATTACHMENT_WRITE];
|
||||
|
||||
const renderPassInfo = new RenderPassInfo([colorAttachment], depthStencilAttachment);
|
||||
renderPass = device.createRenderPass(renderPassInfo);
|
||||
@@ -161,8 +160,7 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
this._commandBuffers.push(device.commandBuffer);
|
||||
|
||||
const shadowMapSamplerHash = genSamplerHash(_samplerInfo);
|
||||
const shadowMapSampler = samplerLib.getSampler(device, shadowMapSamplerHash);
|
||||
const shadowMapSampler = device.getSampler(_samplerInfo);
|
||||
this._descriptorSet.bindSampler(UNIFORM_SHADOWMAP_BINDING, shadowMapSampler);
|
||||
this._descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
this._descriptorSet.bindSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, shadowMapSampler);
|
||||
@@ -177,8 +175,6 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
this._descriptorSet.getBuffer(UBOGlobal.BINDING).destroy();
|
||||
this._descriptorSet.getBuffer(UBOShadow.BINDING).destroy();
|
||||
this._descriptorSet.getBuffer(UBOCamera.BINDING).destroy();
|
||||
this._descriptorSet.getSampler(UNIFORM_SHADOWMAP_BINDING).destroy();
|
||||
this._descriptorSet.getSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING).destroy();
|
||||
this._descriptorSet.getTexture(UNIFORM_SHADOWMAP_BINDING).destroy();
|
||||
this._descriptorSet.getTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING).destroy();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user