import type { GfxBuffer , GfxTexture , GfxRenderTarget , GfxSampler , GfxProgram , GfxInputLayout , GfxInputState , GfxRenderPipeline , GfxBindings , GfxResource , GfxReadback , GfxQueryPool } from "./GfxPlatformImpl" ; import { GfxFormat } from "./GfxPlatformFormat" ; export enum GfxCompareMode { Never = WebGLRenderingContext . NEVER , Less = WebGLRenderingContext . LESS , Equal = WebGLRenderingContext . EQUAL , LessEqual = WebGLRenderingContext . LEQUAL , Greater = WebGLRenderingContext . GREATER , NotEqual = WebGLRenderingContext . NOTEQUAL , GreaterEqual = WebGLRenderingContext . GEQUAL , Always = WebGLRenderingContext . ALWAYS } export enum GfxFrontFaceMode { CCW = WebGLRenderingContext . CCW , CW = WebGLRenderingContext . CW } export const enum GfxCullMode { None , Front , Back , FrontAndBack } export enum GfxBlendFactor { Zero = WebGLRenderingContext . ZERO , One = WebGLRenderingContext . ONE , Src = WebGLRenderingContext . SRC_COLOR , OneMinusSrc = WebGLRenderingContext . ONE_MINUS_SRC_COLOR , Dst = WebGLRenderingContext . DST_COLOR , OneMinusDst = WebGLRenderingContext . ONE_MINUS_DST_COLOR , SrcAlpha = WebGLRenderingContext . SRC_ALPHA , OneMinusSrcAlpha = WebGLRenderingContext . ONE_MINUS_SRC_ALPHA , DstAlpha = WebGLRenderingContext . DST_ALPHA , OneMinusDstAlpha = WebGLRenderingContext . ONE_MINUS_DST_ALPHA } export enum GfxBlendMode { Add = WebGLRenderingContext . FUNC_ADD , Subtract = WebGLRenderingContext . FUNC_SUBTRACT , ReverseSubtract = WebGLRenderingContext . FUNC_REVERSE_SUBTRACT } export const enum GfxWrapMode { Clamp , Repeat , Mirror } export const enum GfxTexFilterMode { Point , Bilinear } export const enum GfxMipFilterMode { NoMip , Nearest , Linear } export const enum GfxPrimitiveTopology { Triangles } export const enum GfxBufferUsage { Index = 0x01 , Vertex = 0x02 , Uniform = 0x03 } export const enum GfxBufferFrequencyHint { Static = 0x01 , Dynamic = 0x02 } export const enum GfxVertexBufferFrequency { PerVertex = 0x01 , PerInstance = 0x02 } export const enum GfxTextureDimension { n2D , n2DArray , n3D , Cube } export const enum GfxTextureUsage { Sampled = 0x01 , RenderTarget = 0x02 } export const enum GfxChannelWriteMask { None = 0x00 , Red = 0x01 , Green = 0x02 , Blue = 0x04 , Alpha = 0x08 , RGB = 0x07 , AllChannels = 0x0F } export enum GfxStencilOp { Keep = WebGLRenderingContext . KEEP , Zero = WebGLRenderingContext . ZERO , Replace = WebGLRenderingContext . REPLACE , Invert = WebGLRenderingContext . INVERT , IncrementClamp = WebGLRenderingContext . INCR , DecrementClamp = WebGLRenderingContext . DECR , IncrementWrap = WebGLRenderingContext . INCR_WRAP , DecrementWrap = WebGLRenderingContext . DECR_WRAP } export interface GfxVertexBufferDescriptor { buffer : GfxBuffer ; byteOffset : number ; } export interface GfxIndexBufferDescriptor extends GfxVertexBufferDescriptor { } export interface GfxVertexAttributeDescriptor { location : number ; format : GfxFormat ; bufferIndex : number ; bufferByteOffset : number ; } export interface GfxInputLayoutBufferDescriptor { byteStride : number ; frequency : GfxVertexBufferFrequency ; } export interface GfxTextureDescriptor { dimension : GfxTextureDimension ; pixelFormat : GfxFormat ; width : number ; height : number ; depth : number ; numLevels : number ; usage : GfxTextureUsage ; } export function makeTextureDescriptor2D ( pixelFormat , width , height , numLevels ) { const dimension = GfxTextureDimension . n2D , depth = 1 ; const usage = GfxTextureUsage . Sampled ; return { dimension , pixelFormat , width , height , depth , numLevels , usage } ; } export interface GfxSamplerDescriptor { wrapS : GfxWrapMode ; wrapT : GfxWrapMode ; wrapQ ? : GfxWrapMode ; minFilter : GfxTexFilterMode ; magFilter : GfxTexFilterMode ; mipFilter : GfxMipFilterMode ; minLOD ? : number ; maxLOD ? : number ; maxAnisotropy ? : number ; compareMode ? : GfxCompareMode ; } export interface GfxRenderTargetDescriptor { pixelFormat : GfxFormat ; width : number ; height : number ; sampleCount : number ; } export interface GfxBufferBinding { buffer : GfxBuffer ; wordCount : number ; } export interface GfxSamplerBinding { gfxTexture : GfxTexture | null ; gfxSampler : GfxSampler | null ; lateBinding : string | null ; } export const enum GfxSamplerFormatKind { Float , Uint , Sint , Depth } export interface GfxBindingLayoutSamplerDescriptor { dimension : GfxTextureDimension ; formatKind : GfxSamplerFormatKind ; } ; export interface GfxBindingLayoutDescriptor { numUniformBuffers : number ; numSamplers : number ; samplerEntries ? : GfxBindingLayoutSamplerDescriptor [ ] ; } export interface GfxBindingsDescriptor { bindingLayout : GfxBindingLayoutDescriptor ; uniformBufferBindings : GfxBufferBinding [ ] ; samplerBindings : GfxSamplerBinding [ ] ; } export interface GfxProgramDescriptorSimple { preprocessedVert : string ; preprocessedFrag : string | null ; } export interface GfxProgramDescriptor extends GfxProgramDescriptorSimple { ensurePreprocessed ( vendorInfo ) : void ; associate ( device , program ) : void ; } export interface GfxInputLayoutDescriptor { vertexBufferDescriptors : ( GfxInputLayoutBufferDescriptor | null ) [ ] ; vertexAttributeDescriptors : GfxVertexAttributeDescriptor [ ] ; indexBufferFormat : GfxFormat | null ; } export interface GfxChannelBlendState { blendMode : GfxBlendMode ; blendSrcFactor : GfxBlendFactor ; blendDstFactor : GfxBlendFactor ; } export interface GfxAttachmentState { channelWriteMask : GfxChannelWriteMask ; rgbBlendState : GfxChannelBlendState ; alphaBlendState : GfxChannelBlendState ; } export interface GfxMegaStateDescriptor { attachmentsState : GfxAttachmentState [ ] ; blendConstant : GfxColor ; depthCompare : GfxCompareMode ; depthWrite : boolean ; stencilCompare : GfxCompareMode ; stencilWrite : boolean ; stencilPassOp : GfxStencilOp ; cullMode : GfxCullMode ; frontFace : GfxFrontFaceMode ; polygonOffset : boolean ; } export interface GfxRenderPipelineDescriptor { bindingLayouts : GfxBindingLayoutDescriptor [ ] ; inputLayout : GfxInputLayout | null ; program : GfxProgram ; topology : GfxPrimitiveTopology ; megaStateDescriptor : GfxMegaStateDescriptor ; colorAttachmentFormats : ( GfxFormat | null ) [ ] ; depthStencilAttachmentFormat : GfxFormat | null ; sampleCount : number ; } export interface GfxColor { r : number ; g : number ; b : number ; a : number ; } export interface GfxRenderPassDescriptor { colorAttachment : ( GfxRenderTarget | null ) [ ] ; colorClearColor : ( GfxColor | 'load' ) [ ] ; colorResolveTo : ( GfxTexture | null ) [ ] ; colorStore : boolean [ ] ; depthStencilAttachment : GfxRenderTarget | null ; depthStencilResolveTo : GfxTexture | null ; depthStencilStore : boolean ; depthClearValue : number | 'load' ; stencilClearValue : number | 'load' ; occlusionQueryPool : GfxQueryPool | null ; } export interface GfxDeviceLimits { uniformBufferWordAlignment : number ; uniformBufferMaxPageWordSize : number ; readonly supportedSampleCounts : number [ ] ; occlusionQueriesRecommended : boolean ; } export interface GfxDebugGroup { name : string ; drawCallCount : number ; textureBindCount : number ; bufferUploadCount : number ; triangleCount : number ; } export const enum GfxViewportOrigin { LowerLeft , UpperLeft } export const enum GfxClipSpaceNearZ { NegativeOne , Zero } export interface GfxVendorInfo { readonly platformString : string ; readonly glslVersion : string ; readonly explicitBindingLocations : boolean ; readonly separateSamplerTextures : boolean ; readonly viewportOrigin : GfxViewportOrigin ; readonly clipSpaceNearZ : GfxClipSpaceNearZ ; } export type GfxPlatformFramebuffer = WebGLFramebuffer ; export interface GfxNormalizedViewportCoords { x : number ; y : number ; w : number ; h : number ; } export const enum GfxQueryPoolType { OcclusionConservative } export interface GfxSwapChain { configureSwapChain ( width , height , platformFramebuffer ? ) : void ; getDevice ( ) : GfxDevice ; getCanvas ( ) : HTMLCanvasElement | OffscreenCanvas ; getOnscreenTexture ( ) : GfxTexture ; present ( ) : void ; createWebXRLayer ( webXRSession ) : XRWebGLLayer ; } export interface GfxRenderPass { setViewport ( x , y , w , h ) : void ; setScissor ( x , y , w , h ) : void ; setPipeline ( pipeline ) : void ; setBindings ( bindingLayoutIndex , bindings , dynamicByteOffsets ) : void ; setInputState ( inputState ) : void ; setStencilRef ( value ) : void ; draw ( vertexCount , firstVertex ) : void ; drawIndexed ( indexCount , firstIndex ) : void ; drawIndexedInstanced ( indexCount , firstIndex , instanceCount ) : void ; beginOcclusionQuery ( dstOffs ) : void ; endOcclusionQuery ( dstOffs ) : void ; beginDebugGroup ( name ) : void ; endDebugGroup ( ) : void ; } ; export type GfxPass = GfxRenderPass ; /**
 * GfxDevice represents a "virtual GPU"; this is something that, in the abstract, has a bunch of resources
 * and can execute passes. In the concrete, this is a wrapper around a CanvasWebGL2RenderingContext for the
 * WebGL 2 backend, or a GPUDevice for the WebGPU backend.
 *
 * A bit about the design of this API; all resources are "opaque", meaning you cannot look at the
 * implementation details or underlying fields of the resources, and most objects cannot have their
 * creation parameters modified after they are created. So, while buffers and textures can have their
 * contents changed through data upload passes, they cannot be resized after creation. Create a new object
 * and destroy the old one if you wish to "resize" it.
 *
 * To upload data to the GPU, call either {@see uploadBufferData} or {@see uploadTextureData}. Note that
 * this happens on the GPU timeline. Where possible, do try to upload data at the beginning of the frame.
 * There might be additional support for more passes in the future.
 */ export interface GfxDevice { createBuffer ( wordCount , usage , hint ) : GfxBuffer ; createTexture ( descriptor ) : GfxTexture ; createSampler ( descriptor ) : GfxSampler ; createRenderTarget ( descriptor ) : GfxRenderTarget ; createRenderTargetFromTexture ( texture ) : GfxRenderTarget ; createProgram ( program ) : GfxProgram ; createProgramSimple ( program ) : GfxProgram ; createBindings ( bindingsDescriptor ) : GfxBindings ; createInputLayout ( inputLayoutDescriptor ) : GfxInputLayout ; createInputState ( inputLayout , buffers , indexBuffer ) : GfxInputState ; createRenderPipeline ( descriptor ) : GfxRenderPipeline ; createReadback ( byteCount ) : GfxReadback ; createQueryPool ( type , elemCount ) : GfxQueryPool ; destroyBuffer ( o ) : void ; destroyTexture ( o ) : void ; destroySampler ( o ) : void ; destroyRenderTarget ( o ) : void ; destroyProgram ( o ) : void ; destroyBindings ( o ) : void ; destroyInputLayout ( o ) : void ; destroyInputState ( o ) : void ; destroyRenderPipeline ( o ) : void ; destroyReadback ( o ) : void ; destroyQueryPool ( o ) : void ; pipelineQueryReady ( o ) : boolean ; pipelineForceReady ( o ) : void ; createRenderPass ( renderPassDescriptor ) : GfxRenderPass ; submitPass ( o ) : void ; copySubTexture2D ( dst , dstX , dstY , src , srcX , srcY ) : void ; uploadBufferData ( buffer , dstByteOffset , data , srcByteOffset ? , byteCount ? ) : void ; uploadTextureData ( texture , firstMipLevel , levelDatas ) : void ; readPixelFromTexture ( o , dstOffset , a , x , y ) : void ; submitReadback ( o ) : void ; /**
     * Checks if the readback object {@param o} is ready. If so, this will write the full set of readback
     * values to {@param dst}, starting at index {@param dstOffs}, and returns true. If the readback is
     * not ready, false is returned, and the array is untouched.
     */ queryReadbackFinished ( dst , dstOffs , o ) : boolean ; queryPoolResultOcclusion ( o , dstOffs ) : boolean | null ; queryLimits ( ) : GfxDeviceLimits ; queryTextureFormatSupported ( format , width , height ) : boolean ; queryPlatformAvailable ( ) : boolean ; queryVendorInfo ( ) : GfxVendorInfo ; queryRenderPass ( o ) : Readonly < GfxRenderPassDescriptor > ; queryRenderTarget ( o ) : Readonly < GfxRenderTargetDescriptor > ; setResourceName ( o , s ) : void ; setResourceLeakCheck ( o , v ) : void ; checkForLeaks ( ) : void ; programPatched ( o , descriptor ) : void ; pushDebugGroup ( debugGroup ) : void ; popDebugGroup ( ) : void ; } export type { GfxBuffer , GfxTexture , GfxRenderTarget , GfxSampler , GfxProgram , GfxInputLayout , GfxInputState , GfxRenderPipeline , GfxBindings } ; export { GfxFormat } ;