@galacean/engine-rhi-webgl 0.9.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-rhi-webgl",
3
- "version": "0.9.0",
3
+ "version": "1.0.0-beta.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -15,11 +15,11 @@
15
15
  "types/**/*"
16
16
  ],
17
17
  "dependencies": {
18
- "@galacean/engine-core": "0.9.0",
19
- "@galacean/engine-math": "0.9.0"
18
+ "@galacean/engine-core": "1.0.0-beta.0",
19
+ "@galacean/engine-math": "1.0.0-beta.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@galacean/engine-design": "0.9.0"
22
+ "@galacean/engine-design": "1.0.0-beta.0"
23
23
  },
24
24
  "scripts": {
25
25
  "b:types": "tsc"
@@ -0,0 +1,16 @@
1
+ import { BufferBindFlag, BufferUsage, IPlatformBuffer, SetDataOptions } from "@galacean/engine-core";
2
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
3
+ export declare class GLBuffer implements IPlatformBuffer {
4
+ private _gl;
5
+ private _glBindTarget;
6
+ private _glBufferUsage;
7
+ private _glBuffer;
8
+ private _isWebGL2;
9
+ constructor(rhi: WebGLGraphicDevice, type: BufferBindFlag, byteLength: number, bufferUsage?: BufferUsage, data?: ArrayBuffer | ArrayBufferView);
10
+ bind(): void;
11
+ setData(byteLength: number, data: ArrayBuffer | ArrayBufferView, bufferByteOffset?: number, dataOffset?: number, dataLength?: number, options?: SetDataOptions): void;
12
+ getData(data: ArrayBufferView, bufferByteOffset?: number, dataOffset?: number, dataLength?: number): void;
13
+ resize(byteLength: number): void;
14
+ destroy(): void;
15
+ private _getGLBufferUsage;
16
+ }
@@ -1,6 +1,6 @@
1
1
  import { GLCapabilityType } from "@galacean/engine-core";
2
2
  import { GLCompressedTextureInternalFormat } from "./type";
3
- import { WebGLRenderer } from "./WebGLRenderer";
3
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
4
4
  /**
5
5
  * GL capability.
6
6
  */
@@ -8,7 +8,7 @@ export declare class GLCapability {
8
8
  private _maxDrawBuffers;
9
9
  private _maxAnisoLevel;
10
10
  private _maxAntiAliasing;
11
- _rhi: WebGLRenderer;
11
+ _rhi: WebGLGraphicDevice;
12
12
  capabilityList: Map<GLCapabilityType, boolean>;
13
13
  get maxTextureSize(): boolean;
14
14
  get canUseFloatTextureBlendShape(): boolean;
@@ -25,8 +25,8 @@ export declare class GLCapability {
25
25
  * Max MSAA count.
26
26
  */
27
27
  get maxAntiAliasing(): number;
28
- get rhi(): WebGLRenderer;
29
- constructor(rhi: WebGLRenderer);
28
+ get rhi(): WebGLGraphicDevice;
29
+ constructor(rhi: WebGLGraphicDevice);
30
30
  /**
31
31
  * Check device capabilities.
32
32
  */
@@ -1,4 +1,4 @@
1
- import { WebGLRenderer } from "./WebGLRenderer";
1
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
2
2
  import { GLCapabilityType } from "@galacean/engine-core";
3
3
  /**
4
4
  * GLContext extension.
@@ -6,7 +6,7 @@ import { GLCapabilityType } from "@galacean/engine-core";
6
6
  export declare class GLExtensions {
7
7
  private rhi;
8
8
  private _requireResult;
9
- constructor(rhi: WebGLRenderer);
9
+ constructor(rhi: WebGLGraphicDevice);
10
10
  /**
11
11
  * Require an extension.
12
12
  */
@@ -1,5 +1,5 @@
1
1
  import { IPlatformRenderTarget, RenderTarget, TextureCubeFace } from "@galacean/engine-core";
2
- import { WebGLRenderer } from "./WebGLRenderer";
2
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
3
3
  /**
4
4
  * The render target in WebGL platform is used for off-screen rendering.
5
5
  */
@@ -18,7 +18,7 @@ export declare class GLRenderTarget implements IPlatformRenderTarget {
18
18
  /**
19
19
  * Create render target in WebGL platform.
20
20
  */
21
- constructor(rhi: WebGLRenderer, target: RenderTarget);
21
+ constructor(rhi: WebGLGraphicDevice, target: RenderTarget);
22
22
  /**
23
23
  * Set which face and mipLevel of the cube texture to render to.
24
24
  * @param faceIndex - Cube texture face
@@ -1,5 +1,5 @@
1
1
  import { IPlatformTexture, Texture, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureWrapMode } from "@galacean/engine-core";
2
- import { WebGLRenderer } from "./WebGLRenderer";
2
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
3
3
  /**
4
4
  * Texture in WebGL platform.
5
5
  */
@@ -24,7 +24,7 @@ export declare class GLTexture implements IPlatformTexture {
24
24
  /**
25
25
  * Create texture in WebGL platform.
26
26
  */
27
- constructor(rhi: WebGLRenderer, texture: Texture, target: GLenum);
27
+ constructor(rhi: WebGLGraphicDevice, texture: Texture, target: GLenum);
28
28
  /**
29
29
  * Destroy texture.
30
30
  */
@@ -1,13 +1,13 @@
1
1
  import { IPlatformTexture2D, Texture2D } from "@galacean/engine-core";
2
2
  import { GLTexture } from "./GLTexture";
3
- import { WebGLRenderer } from "./WebGLRenderer";
3
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
4
4
  /**
5
5
  * Texture 2d in WebGL platform.
6
6
  */
7
7
  export declare class GLTexture2D extends GLTexture implements IPlatformTexture2D {
8
8
  /** Backward compatible with WebGL1.0. */
9
9
  private _compressedMipFilled;
10
- constructor(rhi: WebGLRenderer, texture2D: Texture2D);
10
+ constructor(rhi: WebGLGraphicDevice, texture2D: Texture2D);
11
11
  /**
12
12
  * {@inheritDoc IPlatformTexture2D.setPixelBuffer}
13
13
  */
@@ -1,11 +1,11 @@
1
1
  import { IPlatformTexture2DArray, Texture2DArray } from "@galacean/engine-core";
2
2
  import { GLTexture } from "./GLTexture";
3
- import { WebGLRenderer } from "./WebGLRenderer";
3
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
4
4
  /**
5
5
  * Texture 2D array in WebGL platform.
6
6
  */
7
7
  export declare class GLTexture2DArray extends GLTexture implements IPlatformTexture2DArray {
8
- constructor(rhi: WebGLRenderer, texture2DArray: Texture2DArray);
8
+ constructor(rhi: WebGLGraphicDevice, texture2DArray: Texture2DArray);
9
9
  /**
10
10
  * {@inheritDoc IPlatformTexture2DArray.setPixelBuffer}
11
11
  */
@@ -1,13 +1,13 @@
1
1
  import { IPlatformTextureCube, TextureCube, TextureCubeFace } from "@galacean/engine-core";
2
2
  import { GLTexture } from "./GLTexture";
3
- import { WebGLRenderer } from "./WebGLRenderer";
3
+ import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
4
4
  /**
5
5
  * Cube texture in WebGL platform.
6
6
  */
7
7
  export declare class GLTextureCube extends GLTexture implements IPlatformTextureCube {
8
8
  /** Backward compatible with WebGL1.0. */
9
9
  private _compressedFaceFilled;
10
- constructor(rhi: WebGLRenderer, textureCube: TextureCube);
10
+ constructor(rhi: WebGLGraphicDevice, textureCube: TextureCube);
11
11
  /**
12
12
  * {@inheritDoc IPlatformTextureCube.setPixelBuffer}
13
13
  */
@@ -1,20 +1,27 @@
1
- import { Engine } from "@galacean/engine-core";
1
+ import { Engine, EngineConfiguration } from "@galacean/engine-core";
2
2
  import { WebCanvas } from "./WebCanvas";
3
- import { WebGLRendererOptions } from "./WebGLRenderer";
4
- type OffscreenCanvas = any;
3
+ import { WebGLGraphicDeviceOptions } from "./";
5
4
  /**
6
5
  * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
7
6
  */
8
7
  export declare class WebGLEngine extends Engine {
9
8
  /**
10
- * Create an engine suitable for the WebGL platform.
11
- * @param canvas - Native web canvas
12
- * @param webGLRendererOptions - WebGL renderer options
9
+ * Create a WebGL engine.
10
+ * @param configuration - WebGL engine configuration
11
+ * @returns A promise that will resolve when the engine is created
13
12
  */
14
- constructor(canvas: string | HTMLCanvasElement | OffscreenCanvas, webGLRendererOptions?: WebGLRendererOptions);
13
+ static create(configuration: WebGLEngineConfiguration): Promise<WebGLEngine>;
15
14
  /**
16
15
  * Web canvas.
17
16
  */
18
17
  get canvas(): WebCanvas;
19
18
  }
20
- export {};
19
+ /**
20
+ * WebGL engine configuration.
21
+ */
22
+ export interface WebGLEngineConfiguration extends EngineConfiguration {
23
+ /** Canvas element or canvas id. */
24
+ canvas: HTMLCanvasElement | string;
25
+ /** Graphic device options. */
26
+ graphicDeviceOptions?: WebGLGraphicDeviceOptions;
27
+ }
@@ -1,4 +1,4 @@
1
- import { CameraClearFlags, Canvas, Engine, GLCapabilityType, IHardwareRenderer, IPlatformRenderTarget, IPlatformTexture2D, IPlatformTextureCube, Mesh, RenderTarget, SubMesh, Texture2D, Texture2DArray, TextureCube } from "@galacean/engine-core";
1
+ import { BufferBindFlag, BufferUsage, CameraClearFlags, Canvas, Engine, GLCapabilityType, IHardwareRenderer, IPlatformBuffer, IPlatformRenderTarget, IPlatformTexture2D, IPlatformTextureCube, Mesh, RenderTarget, SubMesh, Texture2D, Texture2DArray, TextureCube } from "@galacean/engine-core";
2
2
  import { IPlatformPrimitive } from "@galacean/engine-design";
3
3
  import { Color, Vector4 } from "@galacean/engine-math";
4
4
  import { GLCapability } from "./GLCapability";
@@ -18,17 +18,16 @@ export declare enum WebGLMode {
18
18
  WebGL1 = 2
19
19
  }
20
20
  /**
21
- * WebGL renderer options.
21
+ * WebGL graphic device options.
22
22
  */
23
- export interface WebGLRendererOptions extends WebGLContextAttributes {
23
+ export interface WebGLGraphicDeviceOptions extends WebGLContextAttributes {
24
24
  /** WebGL mode.*/
25
25
  webGLMode?: WebGLMode;
26
26
  }
27
27
  /**
28
- * WebGL renderer, including WebGL1.0 and WebGL2.0.
28
+ * WebGL graphic device, including WebGL1.0 and WebGL2.0.
29
29
  */
30
- export declare class WebGLRenderer implements IHardwareRenderer {
31
- _currentBind: any;
30
+ export declare class WebGLGraphicDevice implements IHardwareRenderer {
32
31
  private _options;
33
32
  private _gl;
34
33
  private _renderStates;
@@ -43,6 +42,8 @@ export declare class WebGLRenderer implements IHardwareRenderer {
43
42
  private _lastScissor;
44
43
  private _lastClearColor;
45
44
  private _scissorEnable;
45
+ private _onDeviceLost;
46
+ private _onDeviceRestored;
46
47
  get isWebGL2(): boolean;
47
48
  get renderer(): string;
48
49
  /**
@@ -53,19 +54,20 @@ export declare class WebGLRenderer implements IHardwareRenderer {
53
54
  get renderStates(): GLRenderStates;
54
55
  get capability(): GLCapability;
55
56
  get canIUseMoreJoints(): boolean;
56
- constructor(initializeOptions?: WebGLRendererOptions);
57
- init(canvas: Canvas): void;
57
+ constructor(initializeOptions?: WebGLGraphicDeviceOptions);
58
+ init(canvas: Canvas, onDeviceLost: () => void, onDeviceRestored: () => void): void;
58
59
  createPlatformPrimitive(primitive: Mesh): IPlatformPrimitive;
59
60
  createPlatformTexture2D(texture2D: Texture2D): IPlatformTexture2D;
60
61
  createPlatformTexture2DArray(texture2D: Texture2DArray): GLTexture2DArray;
61
62
  createPlatformTextureCube(textureCube: TextureCube): IPlatformTextureCube;
62
63
  createPlatformRenderTarget(target: RenderTarget): IPlatformRenderTarget;
64
+ createPlatformBuffer(type: BufferBindFlag, byteLength: number, bufferUsage?: BufferUsage, data?: ArrayBuffer | ArrayBufferView): IPlatformBuffer;
63
65
  requireExtension(ext: any): any;
64
66
  canIUse(capabilityType: GLCapabilityType): boolean;
65
67
  canIUseCompressedTextureInternalFormat(type: number): boolean;
66
68
  viewport(x: number, y: number, width: number, height: number): void;
67
69
  scissor(x: number, y: number, width: number, height: number): void;
68
- colorMask(r: any, g: any, b: any, a: any): void;
70
+ colorMask(r: boolean, g: boolean, b: boolean, a: boolean): void;
69
71
  clearRenderTarget(engine: Engine, clearFlags: CameraClearFlags, clearColor: Color): void;
70
72
  drawPrimitive(primitive: Mesh, subPrimitive: SubMesh, shaderProgram: any): void;
71
73
  activeRenderTarget(renderTarget: RenderTarget, viewport: Vector4, mipLevel: number): void;
@@ -73,5 +75,12 @@ export declare class WebGLRenderer implements IHardwareRenderer {
73
75
  bindTexture(texture: GLTexture): void;
74
76
  setGlobalDepthBias(bias: number, slopeBias: number): void;
75
77
  flush(): void;
78
+ forceLoseDevice(): void;
79
+ forceRestoreDevice(): void;
80
+ resetState(): void;
81
+ protected _initGLState(gl: (WebGLRenderingContext & WebGLExtension) | WebGL2RenderingContext): void;
76
82
  destroy(): void;
83
+ private _onContextCreationError;
84
+ private _onWebGLContextLost;
85
+ private _onWebGLContextRestored;
77
86
  }
package/types/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { GLCompressedTextureInternalFormat } from "./type";
2
2
  export { WebCanvas } from "./WebCanvas";
3
3
  export { WebGLEngine } from "./WebGLEngine";
4
- export { WebGLMode, WebGLRenderer } from "./WebGLRenderer";
5
- export type { WebGLRendererOptions } from "./WebGLRenderer";
4
+ export type { WebGLEngineConfiguration } from "./WebGLEngine";
5
+ export { WebGLMode, WebGLGraphicDevice } from "./WebGLGraphicDevice";
6
+ export type { WebGLGraphicDeviceOptions } from "./WebGLGraphicDevice";