import { BufferBindFlag, BufferUsage, CameraClearFlags, Canvas, Engine, GLCapabilityType, IPlatformBuffer, IPlatformRenderTarget, IPlatformTexture2D, IPlatformTextureCube, Mesh, RenderTarget, SubMesh, Texture2D, Texture2DArray, TextureCube, TextureCubeFace } from "@galacean/engine-core"; import { IHardwareRenderer, IPlatformPrimitive, IPlatformShaderProgram } from "@galacean/engine-design"; import { Color, Vector4 } from "@galacean/engine-math"; import { GLCapability } from "./GLCapability"; import { GLPrimitive } from "./GLPrimitive"; import { GLRenderStates } from "./GLRenderStates"; import { GLTexture } from "./GLTexture"; import { GLTexture2DArray } from "./GLTexture2DArray"; import { WebGLExtension } from "./type"; /** * WebGL mode. */ export declare enum WebGLMode { /** Auto, use WebGL2.0 if support, or will fallback to WebGL1.0. */ Auto = 0, /** WebGL2.0. */ WebGL2 = 1, /** WebGL1.0, */ WebGL1 = 2 } /** * WebGL graphic device options. */ export interface WebGLGraphicDeviceOptions { /** WebGL mode.*/ webGLMode?: WebGLMode; alpha?: boolean; depth?: boolean; desynchronized?: boolean; failIfMajorPerformanceCaveat?: boolean; powerPreference?: WebGLPowerPreference; premultipliedAlpha?: boolean; preserveDrawingBuffer?: boolean; stencil?: boolean; xrCompatible?: boolean; } /** * WebGL graphic device, including WebGL1.0 and WebGL2.0. */ export declare class WebGLGraphicDevice implements IHardwareRenderer { private _options; private _webGLOptions; private _gl; private _renderStates; private _extensions; private _capability; private _isWebGL2; private _renderer; private _webCanvas; private _activeTextureID; private _activeTextures; private _lastViewport; private _lastScissor; private _lastClearColor; private _scissorEnable; private _onDeviceLost; private _onDeviceRestored; get isWebGL2(): boolean; get renderer(): string; /** * GL Context * @member {WebGLRenderingContext} */ get gl(): (WebGLRenderingContext & WebGLExtension) | WebGL2RenderingContext; get renderStates(): GLRenderStates; get capability(): GLCapability; get canIUseMoreJoints(): boolean; constructor(initializeOptions?: WebGLGraphicDeviceOptions); init(canvas: Canvas, onDeviceLost: () => void, onDeviceRestored: () => void): void; createPlatformPrimitive(primitive: Mesh): IPlatformPrimitive; createPlatformTexture2D(texture2D: Texture2D): IPlatformTexture2D; createPlatformTexture2DArray(texture2D: Texture2DArray): GLTexture2DArray; createPlatformTextureCube(textureCube: TextureCube): IPlatformTextureCube; createPlatformRenderTarget(target: RenderTarget): IPlatformRenderTarget; createPlatformBuffer(type: BufferBindFlag, byteLength: number, bufferUsage?: BufferUsage, data?: ArrayBuffer | ArrayBufferView): IPlatformBuffer; requireExtension(ext: any): any; canIUse(capabilityType: GLCapabilityType): boolean; canIUseCompressedTextureInternalFormat(type: number): boolean; viewport(x: number, y: number, width: number, height: number): void; scissor(x: number, y: number, width: number, height: number): void; colorMask(r: boolean, g: boolean, b: boolean, a: boolean): void; clearRenderTarget(engine: Engine, clearFlags: CameraClearFlags, clearColor?: Color): void; drawPrimitive(primitive: GLPrimitive, subPrimitive: SubMesh, shaderProgram: IPlatformShaderProgram): void; getMainFrameBufferWidth(): number; getMainFrameBufferHeight(): number; activeRenderTarget(renderTarget: RenderTarget, viewport: Vector4, isFlipProjection: boolean, mipLevel?: number, faceIndex?: TextureCubeFace): void; blitInternalRTByBlitFrameBuffer(srcRT: RenderTarget, destRT: RenderTarget, clearFlags: CameraClearFlags, viewport: Vector4): void; copyRenderTargetToSubTexture(srcRT: RenderTarget, grabTexture: Texture2D, viewport: Vector4): void; activeTexture(textureID: number): void; bindTexture(texture: GLTexture): void; setGlobalDepthBias(bias: number, slopeBias: number): void; flush(): void; forceLoseDevice(): void; forceRestoreDevice(): void; /** * @remarks * WebGL context loss and restore can happen at any GPU execution point. refs to: https://www.khronos.org/webgl/wiki/HandlingContextLost */ isContextLost(): boolean; resetState(): void; protected _initGLState(gl: (WebGLRenderingContext & WebGLExtension) | WebGL2RenderingContext): void; destroy(): void; private _onContextCreationError; private _onWebGLContextLost; private _onWebGLContextRestored; }