mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
clean up gfx module for independent compilation (#9573)
This commit is contained in:
Vendored
+20
-20
@@ -38,51 +38,51 @@ interface Window {
|
||||
canvas: any;
|
||||
|
||||
XMLHttpRequest: any;
|
||||
mozRequestAnimationFrame (callback: any, element?: any): any;
|
||||
oRequestAnimationFrame (callback: any, element?: any): any;
|
||||
msRequestAnimationFrame (callback: any, element?: any): any;
|
||||
cancelRequestAnimationFrame (callback: any, element?: any): any;
|
||||
msCancelRequestAnimationFrame (callback: any, element?: any): any;
|
||||
mozCancelRequestAnimationFrame (callback: any, element?: any): any;
|
||||
oCancelRequestAnimationFrame (callback: any, element?: any): any;
|
||||
webkitCancelRequestAnimationFrame (callback: any, element?: any): any;
|
||||
msCancelAnimationFrame (callback: any, element?: any): any;
|
||||
mozCancelAnimationFrame (callback: any, element?: any): any;
|
||||
ocancelAnimationFrame (callback: any, element?: any): any;
|
||||
mozRequestAnimationFrame(callback: any, element?: any): any;
|
||||
oRequestAnimationFrame(callback: any, element?: any): any;
|
||||
msRequestAnimationFrame(callback: any, element?: any): any;
|
||||
cancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
msCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
mozCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
oCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
webkitCancelRequestAnimationFrame(callback: any, element?: any): any;
|
||||
msCancelAnimationFrame(callback: any, element?: any): any;
|
||||
mozCancelAnimationFrame(callback: any, element?: any): any;
|
||||
ocancelAnimationFrame(callback: any, element?: any): any;
|
||||
}
|
||||
|
||||
interface Document{
|
||||
interface Document {
|
||||
mozHidden: any;
|
||||
msHidden: any;
|
||||
webkitHidden: any;
|
||||
}
|
||||
|
||||
interface HTMLElement{
|
||||
interface HTMLElement {
|
||||
content: any;
|
||||
name: any;
|
||||
}
|
||||
|
||||
type ActiveXObject = new (s: string) => any;
|
||||
declare const ActiveXObject: ActiveXObject;
|
||||
|
||||
declare type CompareFunction<T> = (a: T, b: T) => number;
|
||||
|
||||
declare type RecursivePartial<T> = {
|
||||
[P in keyof T]?:
|
||||
T[P] extends Array<infer U> ? Array<RecursivePartial<U>> :
|
||||
T[P] extends Array<infer U> ? Array<RecursivePartial<U>> :
|
||||
T[P] extends ReadonlyArray<infer V> ? ReadonlyArray<RecursivePartial<V>> : RecursivePartial<T[P]>;
|
||||
};
|
||||
|
||||
declare type TypedArray = Uint8Array | Uint8ClampedArray | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
|
||||
declare type TypedArray = Uint8Array | Uint8ClampedArray | Int8Array | Uint16Array |
|
||||
Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
|
||||
|
||||
declare type TypedArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Uint32ArrayConstructor | Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
||||
declare type TypedArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor |
|
||||
Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Uint32ArrayConstructor |
|
||||
Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
||||
|
||||
declare interface IWritableArrayLike<T> {
|
||||
readonly length: number;
|
||||
[index: number]: T;
|
||||
}
|
||||
|
||||
declare type Constructor<T = unknown> = new(...args: any[]) => T;
|
||||
declare type Constructor<T = unknown> = new (...args: any[]) => T;
|
||||
|
||||
/**
|
||||
* Alias of `Function` but suppress eslint warning.
|
||||
|
||||
Vendored
+2
-3
@@ -1,5 +1,4 @@
|
||||
interface EXT_color_buffer_float {
|
||||
}
|
||||
interface EXT_color_buffer_float {}
|
||||
|
||||
interface EXT_disjoint_timer_query_webgl2 {
|
||||
readonly QUERY_COUNTER_BITS_EXT: GLenum;
|
||||
@@ -20,4 +19,4 @@ interface WEBGL_texture_storage_multisample {
|
||||
width: GLsizei,
|
||||
height: GLsizei,
|
||||
fixedsamplelocations: GLboolean): void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ const downloadCCONB = (url: string, options: IDownloadParseOptions, onComplete:
|
||||
const ccon = decodeCCONBinary(new Uint8Array(arrayBuffer));
|
||||
onComplete(null, ccon);
|
||||
} catch (err) {
|
||||
onComplete(err);
|
||||
onComplete(err as Error);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -155,7 +155,8 @@ const downloadBundle = (nameOrUrl: string, options: IBundleOptions, onComplete:
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Control all download process, it is a singleton. All member can be accessed with `cc.assetManager.downloader` , it can download several types of files:
|
||||
* Control all download process, it is a singleton.
|
||||
* All member can be accessed with `cc.assetManager.downloader`, it can download several types of files:
|
||||
* 1. Text
|
||||
* 2. Image
|
||||
* 3. Audio
|
||||
@@ -326,7 +327,8 @@ export class Downloader {
|
||||
*
|
||||
* @example
|
||||
* downloader.register('.tga', (url, options, onComplete) => onComplete(null, null));
|
||||
* downloader.register({'.tga': (url, options, onComplete) => onComplete(null, null), '.ext': (url, options, onComplete) => onComplete(null, null)});
|
||||
* downloader.register({'.tga': (url, options, onComplete) => onComplete(null, null),
|
||||
* '.ext': (url, options, onComplete) => onComplete(null, null)});
|
||||
*
|
||||
*/
|
||||
public register (type: string, handler: DownloadHandler): void;
|
||||
@@ -360,8 +362,8 @@ export class Downloader {
|
||||
* @param onComplete.content - The downloaded file
|
||||
*
|
||||
* @example
|
||||
* download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.log(loaded/total)}, onComplete: (err) => console.log(err));
|
||||
*
|
||||
* download('http://example.com/test.tga', '.tga', { onFileProgress: (loaded, total) => console.log(loaded/total) },
|
||||
* onComplete: (err) => console.log(err));
|
||||
*/
|
||||
public download (id: string, url: string, type: string, options: IDownloadParseOptions, onComplete: CompleteCallback): void {
|
||||
// if it is downloaded, don't download again
|
||||
|
||||
@@ -48,13 +48,13 @@ export type CreateHandler = (id: string, data: any, options: IDownloadParseOptio
|
||||
|
||||
function createImageAsset (id: string, data: HTMLImageElement, options: IDownloadParseOptions, onComplete: CompleteCallback<ImageAsset>) {
|
||||
let out: ImageAsset | null = null;
|
||||
let err = null;
|
||||
let err: Error | null = null;
|
||||
try {
|
||||
out = new ImageAsset();
|
||||
out._nativeUrl = id;
|
||||
out._nativeAsset = data;
|
||||
} catch (e) {
|
||||
err = e;
|
||||
err = e as Error;
|
||||
}
|
||||
onComplete(err, out);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ export function transform (input: Request, options?: IOptions | null): string |
|
||||
for (const item of subTask.output) {
|
||||
item.recycle();
|
||||
}
|
||||
error(e.message, e.stack);
|
||||
error((e as Error).message, (e as Error).stack);
|
||||
}
|
||||
subTask.recycle();
|
||||
return urls.length > 1 ? urls : urls[0];
|
||||
|
||||
@@ -224,7 +224,7 @@ function loadDepends (task: Task, asset: Asset, done: CompleteCallbackNoData) {
|
||||
onLoadedInvokedMap.add(asset);
|
||||
}
|
||||
} catch (e) {
|
||||
error(`The asset ${uuid} is invalid for some reason, detail message: ${e.message}, stack: ${e.stack}`);
|
||||
error(`The asset ${uuid} is invalid for some reason, detail message: ${(e as Error).message}, stack: ${(e as Error).stack!}`);
|
||||
if (EDITOR || PREVIEW) {
|
||||
if (asset instanceof Asset) {
|
||||
asset.initDefault();
|
||||
|
||||
@@ -217,7 +217,7 @@ export class Parser {
|
||||
throw new Error('Invalid magic number in PVR header');
|
||||
}
|
||||
} catch (e) {
|
||||
err = e;
|
||||
err = e as Error;
|
||||
}
|
||||
onComplete(err, out);
|
||||
}
|
||||
@@ -245,7 +245,7 @@ export class Parser {
|
||||
format: 0,
|
||||
};
|
||||
} catch (e) {
|
||||
err = e;
|
||||
err = e as Error;
|
||||
}
|
||||
onComplete(err, out);
|
||||
}
|
||||
@@ -273,9 +273,12 @@ export class Parser {
|
||||
|
||||
const format = getASTCFormat(xdim, ydim);
|
||||
|
||||
const xsize = header[ASTC_HEADER_SIZE_X_BEGIN] + (header[ASTC_HEADER_SIZE_X_BEGIN + 1] << 8) + (header[ASTC_HEADER_SIZE_X_BEGIN + 2] << 16);
|
||||
const ysize = header[ASTC_HEADER_SIZE_Y_BEGIN] + (header[ASTC_HEADER_SIZE_Y_BEGIN + 1] << 8) + (header[ASTC_HEADER_SIZE_Y_BEGIN + 2] << 16);
|
||||
const zsize = header[ASTC_HEADER_SIZE_Z_BEGIN] + (header[ASTC_HEADER_SIZE_Z_BEGIN + 1] << 8) + (header[ASTC_HEADER_SIZE_Z_BEGIN + 2] << 16);
|
||||
const xsize = header[ASTC_HEADER_SIZE_X_BEGIN] + (header[ASTC_HEADER_SIZE_X_BEGIN + 1] << 8)
|
||||
+ (header[ASTC_HEADER_SIZE_X_BEGIN + 2] << 16);
|
||||
const ysize = header[ASTC_HEADER_SIZE_Y_BEGIN] + (header[ASTC_HEADER_SIZE_Y_BEGIN + 1] << 8)
|
||||
+ (header[ASTC_HEADER_SIZE_Y_BEGIN + 2] << 16);
|
||||
const zsize = header[ASTC_HEADER_SIZE_Z_BEGIN] + (header[ASTC_HEADER_SIZE_Z_BEGIN + 1] << 8)
|
||||
+ (header[ASTC_HEADER_SIZE_Z_BEGIN + 2] << 16);
|
||||
|
||||
// buffer = buffer.slice(ASTC_HEADER_LENGTH, buffer.byteLength);
|
||||
const astcData = new Uint8Array(buffer, ASTC_HEADER_LENGTH);
|
||||
@@ -288,7 +291,7 @@ export class Parser {
|
||||
format,
|
||||
};
|
||||
} catch (e) {
|
||||
err = e;
|
||||
err = e as Error;
|
||||
}
|
||||
onComplete(err, out);
|
||||
}
|
||||
@@ -310,7 +313,7 @@ export class Parser {
|
||||
try {
|
||||
result = deserialize(file, options);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
err = e as Error;
|
||||
}
|
||||
onComplete(err, result);
|
||||
}
|
||||
@@ -334,7 +337,8 @@ export class Parser {
|
||||
*
|
||||
* @example
|
||||
* parser.register('.tga', (file, options, onComplete) => onComplete(null, null));
|
||||
* parser.register({'.tga': (file, options, onComplete) => onComplete(null, null), '.ext': (file, options, onComplete) => onComplete(null, null)});
|
||||
* parser.register({'.tga': (file, options, onComplete) => onComplete(null, null),
|
||||
* '.ext': (file, options, onComplete) => onComplete(null, null)});
|
||||
*
|
||||
*/
|
||||
public register (type: string, handler: ParseHandler): void;
|
||||
|
||||
@@ -68,11 +68,11 @@ export default function preprocess (task: Task, done: CompleteCallbackNoData) {
|
||||
|
||||
// transform url
|
||||
const subTask = Task.create({ input: task.input, options: subOptions });
|
||||
let err = null;
|
||||
let err: Error | null = null;
|
||||
try {
|
||||
task.output = task.source = transformPipeline.sync(subTask);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
err = e as Error;
|
||||
for (let i = 0, l = subTask.output.length; i < l; i++) {
|
||||
subTask.output[i].recycle();
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export function getDepends (uuid: string, data: Asset | Record<string, any>, exc
|
||||
depends.push({ ...info.nativeDep });
|
||||
}
|
||||
} catch (e) {
|
||||
error(e.message, e.stack);
|
||||
error((e as Error).message, (e as Error).stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ import { Sampler, Texture, Device, Format, SamplerInfo, Address, Filter as GFXFi
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { errorID } from '../platform/debug';
|
||||
import { murmurhash2_32_gc } from '../utils/murmurhash2_gc';
|
||||
import { ccenum } from '../value-types/enum';
|
||||
|
||||
ccenum(Format);
|
||||
|
||||
const idGenerator = new IDGenerator('Tex');
|
||||
/**
|
||||
|
||||
@@ -119,7 +119,7 @@ export function decodeCCONBinary (bytes: Uint8Array) {
|
||||
try {
|
||||
json = JSON.parse(jsonString);
|
||||
} catch (err) {
|
||||
throw new InvalidCCONError(err);
|
||||
throw new InvalidCCONError(err as string);
|
||||
}
|
||||
|
||||
const chunks: Uint8Array[] = [];
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { ccenum } from '../../value-types/enum';
|
||||
import { Buffer } from './buffer';
|
||||
import { DescriptorSetLayout } from './descriptor-set-layout';
|
||||
import { Queue } from './queue';
|
||||
@@ -1789,8 +1788,6 @@ export class DynamicStates {
|
||||
* ========================= !DO NOT CHANGE THE ABOVE SECTION MANUALLY! =========================
|
||||
*/
|
||||
|
||||
ccenum(Format);
|
||||
|
||||
/**
|
||||
* @en GFX base object.
|
||||
* @zh GFX 基类对象。
|
||||
|
||||
@@ -451,7 +451,7 @@ export abstract class WebGLCmdObject {
|
||||
this.cmdType = type;
|
||||
}
|
||||
|
||||
public abstract clear ();
|
||||
public abstract clear (): void;
|
||||
}
|
||||
|
||||
export class WebGLCmdBeginRenderPass extends WebGLCmdObject {
|
||||
|
||||
@@ -24,16 +24,18 @@
|
||||
*/
|
||||
|
||||
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 { warnID, warn, debug } from '../../platform/debug';
|
||||
import { macro } from '../../platform/macro';
|
||||
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, SurfaceTransform } from '../base/define';
|
||||
import { BrowserType, OS } from '../../../../pal/system-info/enum-type';
|
||||
import { BrowserType } from '../../../../pal/system-info/enum-type/browser-type';
|
||||
import { OS } from '../../../../pal/system-info/enum-type/operating-system';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { IWebGLExtensions, WebGLDeviceManager } from './webgl-define';
|
||||
import { legacyCC } from '../../global-exports';
|
||||
|
||||
const eventWebGLContextLost = 'webglcontextlost';
|
||||
|
||||
@@ -128,17 +130,17 @@ export function getExtensions (gl: WebGLRenderingContext) {
|
||||
// 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) {
|
||||
if (legacyCC.sys.os !== OS.IOS || legacyCC.sys.osMainVersion !== 14 || !legacyCC.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) {
|
||||
if (legacyCC.sys.browserType === BrowserType.UC) {
|
||||
res.ANGLE_instanced_arrays = null;
|
||||
}
|
||||
|
||||
// bytedance ios depth texture implementation doesn't work
|
||||
if (BYTEDANCE && sys.os === OS.IOS) {
|
||||
if (BYTEDANCE && legacyCC.sys.os === OS.IOS) {
|
||||
res.WEBGL_depth_texture = null;
|
||||
}
|
||||
|
||||
@@ -150,8 +152,8 @@ export function getExtensions (gl: WebGLRenderingContext) {
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
if ((legacyCC.sys.os === OS.IOS && legacyCC.sys.osMainVersion <= 10)
|
||||
|| (WECHAT && legacyCC.sys.os === OS.ANDROID)) {
|
||||
res.destroyShadersImmediately = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
*/
|
||||
|
||||
import { CachedArray } from '../../memop/cached-array';
|
||||
import { error, errorID } from '../../platform';
|
||||
import { debug } from '../../platform/debug';
|
||||
import { error, errorID, debug } from '../../platform/debug';
|
||||
import {
|
||||
BufferUsageBit, ColorMask, CullMode, DynamicStateFlagBit, Filter, Format, TextureType, Type, FormatInfo,
|
||||
FormatInfos, FormatSize, LoadOp, MemoryUsageBit, SampleCount, ShaderStageFlagBit, TextureFlagBit,
|
||||
@@ -635,7 +634,7 @@ export abstract class WebGL2CmdObject {
|
||||
this.cmdType = type;
|
||||
}
|
||||
|
||||
public abstract clear ();
|
||||
public abstract clear (): void;
|
||||
}
|
||||
|
||||
export class WebGL2CmdBeginRenderPass extends WebGL2CmdObject {
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
*/
|
||||
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { macro, warnID, warn, debug } from '../../platform';
|
||||
import { warnID, warn, debug } from '../../platform/debug';
|
||||
import { macro } from '../../platform/macro';
|
||||
import { WebGL2StateCache } from './webgl2-state-cache';
|
||||
import { WebGL2Texture } from './webgl2-texture';
|
||||
import { Format, TextureInfo, TextureFlagBit, TextureType,
|
||||
|
||||
@@ -53,7 +53,7 @@ export class CachedArray<T> {
|
||||
*/
|
||||
public length = 0;
|
||||
|
||||
private _compareFn;
|
||||
private _compareFn?: (a: T, b: T) => number;
|
||||
|
||||
/**
|
||||
* @param length Initial length
|
||||
@@ -62,12 +62,7 @@ export class CachedArray<T> {
|
||||
constructor (length: number, compareFn?: (a: T, b: T) => number) {
|
||||
this.array = new Array(length);
|
||||
this.length = 0;
|
||||
|
||||
if (compareFn !== undefined) {
|
||||
this._compareFn = compareFn;
|
||||
} else {
|
||||
this._compareFn = (a: number, b: number) => a - b;
|
||||
}
|
||||
this._compareFn = compareFn;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user