@babylonjs/lite-gl 1.24.0 → 1.25.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/CHANGELOG.md +26 -0
- package/README.md +5 -4
- package/blend.d.ts +1 -1
- package/blend.js +1 -1
- package/blend.js.map +1 -1
- package/context.d.ts +47 -4
- package/context.js +100 -11
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +3 -2
- package/depth-stencil.js +10 -11
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +6 -3
- package/dynamic-texture.js +16 -4
- package/dynamic-texture.js.map +1 -1
- package/effect.d.ts +12 -3
- package/effect.js +35 -24
- package/effect.js.map +1 -1
- package/family.d.ts +5 -1
- package/family.js.map +1 -1
- package/framebuffer-validation.d.ts +20 -0
- package/framebuffer-validation.js +37 -0
- package/framebuffer-validation.js.map +1 -0
- package/html-texture.d.ts +2 -2
- package/html-texture.js.map +1 -1
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/mesh.d.ts +68 -14
- package/mesh.js +211 -61
- package/mesh.js.map +1 -1
- package/package.json +3 -3
- package/render-target.d.ts +11 -9
- package/render-target.js +50 -35
- package/render-target.js.map +1 -1
- package/scissor.d.ts +1 -1
- package/scissor.js.map +1 -1
- package/sprites.d.ts +5 -3
- package/sprites.js +24 -23
- package/sprites.js.map +1 -1
- package/state.d.ts +25 -13
- package/state.js +13 -10
- package/state.js.map +1 -1
- package/text/_gpu/text-instances.js +1 -1
- package/text/_gpu/text-instances.js.map +1 -1
- package/texture-3d.d.ts +2 -1
- package/texture-3d.js +7 -2
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +4 -2
- package/texture-source.js +3 -2
- package/texture-source.js.map +1 -1
- package/texture.d.ts +18 -8
- package/texture.js +61 -35
- package/texture.js.map +1 -1
- package/web-family.d.ts +2 -1
- package/web-family.js.map +1 -1
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wCAAwC;AASxC,wEAAwE;AACxE,OAAO,EACH,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACrB,MAAM,cAAc,CAAC;AAGtB,uEAAuE;AACvE,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEvG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvF,uEAAuE;AACvE,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGlF,wEAAwE;AACxE,OAAO,EACH,YAAY,EACZ,SAAS,EACT,aAAa,EACb,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,wEAAwE;AACxE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,UAAU,EAAE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,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAGhK,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1D,wEAAwE;AACxE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGpH,wEAAwE;AACxE,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAIvF,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGnF,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEtG,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtF,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEnH,OAAO,EACH,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Backend-neutral contract ────────────────────────────────────────\n// The generic contract (`GLFamily`, `GLOps`, `GLKit`) is published at\n// `@babylonjs/lite-gl/family`; this entry adds the WebGL2 mapping and keeps the\n// shared descriptors importable alongside the operations that take them.\nexport type { GLEffectOptions, GLViewport, GLClearOptions } from \"./family.js\";\nexport type { WebGLFamily, WebGLHostOps } from \"./web-family.js\";\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getTextureCount,\n getCurrentRenderTarget,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\n\n// ─── Alpha-to-coverage (optional) ───────────────────────────────────\nexport { getAlphaToCoverage, getCurrentSampleCount, setAlphaToCoverage } from \"./alpha-to-coverage.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop, beginFrame, endFrame } from \"./render-loop.js\";\n\n// ─── GPU frame timing (optional) ────────────────────────────────────\nexport { captureGPUFrameTime, getGPUFrameTimeCounter } from \"./gpu-frame-time.js\";\nexport type { GLPerfCounter } from \"./gpu-frame-time.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n getEffectCompilationError,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray2,\n setEffectFloatArray3,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffect } from \"./effect.js\";\nexport { waitForEffect } from \"./effect-ready.js\";\nexport type { GLEffectWaitOptions } from \"./effect-ready.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n unbindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureSamplingPreset,\n updateTextureWrapMode,\n createTextureFromHandle,\n getSamplingModeFilters,\n isTextureReady,\n // GLSamplingMode is a const + same-name type; one value re-export carries both.\n GLSamplingMode,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLTextureUpdateOptions, GLRawTextureOptions, GLFloatTextureOptions, GLTexture, GLSamplingFilters } from \"./texture.js\";\nexport { createTextureFromSource } from \"./texture-source.js\";\nexport type { GLTextureSourceOptions } from \"./texture-source.js\";\nexport {\n createTexture3DFromPixels,\n bindTexture3D,\n unbindTexture3D,\n setEffectTexture3D,\n generateTexture3DMipMaps,\n updateTexture3DSamplingMode,\n updateTexture3DWrapMode,\n disposeTexture3D,\n} from \"./texture-3d.js\";\nexport type { GLPixelsTexture3DOptions, GLTexture3D } from \"./texture-3d.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n restoreDefaultFramebuffer,\n presentRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n readRenderTargetPixelsToBuffer,\n disposeRenderTarget,\n} from \"./render-target.js\";\nexport type {\n GLRenderTarget,\n GLRenderTargetOptions,\n GLFloatRenderTargetOptions,\n GLReadPixelsRegionOptions,\n GLReadPixelsOptions,\n GLReadPixelsToBufferOptions,\n} from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setStencilOpSeparate, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLStencilOpState } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\nexport { createHtmlElementTexture, updateHtmlElementTexture } from \"./html-texture.js\";\n\n// ─── Text (analytic Slug coverage) ───────────────────────────────────\nexport type { GLFont } from \"./text/font.js\";\nexport { loadFont, createFontFromBuffer } from \"./text/font.js\";\nexport { extractGlyphCurves, cubicToQuadratics } from \"./text/glyph-extraction.js\";\nexport type { GLTextLayoutOptions } from \"./text/layout.js\";\nexport type { GLGlyphStorage, GLCurveSetId, GLQuadCurve, GLGlyphBounds, GLGlyphCurves } from \"./text/glyph-storage.js\";\nexport { createGlyphStorage, updateGlyphStorage, disposeGlyphStorage } from \"./text/glyph-storage.js\";\nexport type { GLTextData, GLPlacedGlyph, GLGlyphRun, GLTextDataUpdate } from \"./text/text-data.js\";\nexport { createTextData, updateTextData, disposeTextData } from \"./text/text-data.js\";\nexport type { GLDefaultTextData } from \"./text/default-text-data.js\";\nexport { createDefaultTextData, updateDefaultTextData, disposeDefaultTextData } from \"./text/default-text-data.js\";\nexport type { GLTextLayer, GLTextLayerOptions, GLTextRenderer, GLTextRendererOptions } from \"./text/text-renderer.js\";\nexport {\n createTextLayer,\n setTextLayerPosition,\n createTextRenderer,\n renderText,\n isTextRendererReady,\n addTextRendererLayer,\n removeTextRendererLayer,\n registerTextRenderer,\n unregisterTextRenderer,\n disposeTextRenderer,\n} from \"./text/text-renderer.js\";\nexport { setFontWeightOffset } from \"./text/set-font-weight-offset.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wCAAwC;AASxC,wEAAwE;AACxE,OAAO,EACH,cAAc,EACd,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,wBAAwB,EAAE,MAAM,6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iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGnF,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEtG,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtF,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEnH,OAAO,EACH,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Backend-neutral contract ────────────────────────────────────────\n// The generic contract (`GLFamily`, `GLOps`, `GLKit`) is published at\n// `@babylonjs/lite-gl/family`; this entry adds the WebGL2 mapping and keeps the\n// shared descriptors importable alongside the operations that take them.\nexport type { GLEffectOptions, GLViewport, GLClearOptions } from \"./family.js\";\nexport type { WebGLFamily, WebGLHostOps } from \"./web-family.js\";\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n createHostOwnedGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getTextureCount,\n getCurrentRenderTarget,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\nexport { setFramebufferValidation } from \"./framebuffer-validation.js\";\n\n// ─── Alpha-to-coverage (optional) ───────────────────────────────────\nexport { getAlphaToCoverage, getCurrentSampleCount, setAlphaToCoverage } from \"./alpha-to-coverage.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop, beginFrame, endFrame } from \"./render-loop.js\";\n\n// ─── GPU frame timing (optional) ────────────────────────────────────\nexport { captureGPUFrameTime, getGPUFrameTimeCounter } from \"./gpu-frame-time.js\";\nexport type { GLPerfCounter } from \"./gpu-frame-time.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n getEffectCompilationError,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray2,\n setEffectFloatArray3,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffect } from \"./effect.js\";\nexport { waitForEffect } from \"./effect-ready.js\";\nexport type { GLEffectWaitOptions } from \"./effect-ready.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n unbindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureSamplingPreset,\n updateTextureWrapMode,\n createTextureFromHandle,\n getSamplingModeFilters,\n isTextureReady,\n // GLSamplingMode is a const + same-name type; one value re-export carries both.\n GLSamplingMode,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLTextureUpdateOptions, GLRawTextureOptions, GLFloatTextureOptions, GLTexture, GLSamplingFilters } from \"./texture.js\";\nexport { createTextureFromSource } from \"./texture-source.js\";\nexport type { GLTextureSourceOptions } from \"./texture-source.js\";\nexport {\n createTexture3DFromPixels,\n bindTexture3D,\n unbindTexture3D,\n setEffectTexture3D,\n generateTexture3DMipMaps,\n updateTexture3DSamplingMode,\n updateTexture3DWrapMode,\n disposeTexture3D,\n} from \"./texture-3d.js\";\nexport type { GLPixelsTexture3DOptions, GLTexture3D } from \"./texture-3d.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n restoreDefaultFramebuffer,\n presentRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n readRenderTargetPixelsToBuffer,\n disposeRenderTarget,\n} from \"./render-target.js\";\nexport type {\n GLRenderTarget,\n GLRenderTargetOptions,\n GLFloatRenderTargetOptions,\n GLReadPixelsRegionOptions,\n GLReadPixelsOptions,\n GLReadPixelsToBufferOptions,\n} from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n bindAttributesCached,\n disableAttributeByIndex,\n unbindAllAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setStencilOpSeparate, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLStencilOpState } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\nexport { createHtmlElementTexture, updateHtmlElementTexture } from \"./html-texture.js\";\n\n// ─── Text (analytic Slug coverage) ───────────────────────────────────\nexport type { GLFont } from \"./text/font.js\";\nexport { loadFont, createFontFromBuffer } from \"./text/font.js\";\nexport { extractGlyphCurves, cubicToQuadratics } from \"./text/glyph-extraction.js\";\nexport type { GLTextLayoutOptions } from \"./text/layout.js\";\nexport type { GLGlyphStorage, GLCurveSetId, GLQuadCurve, GLGlyphBounds, GLGlyphCurves } from \"./text/glyph-storage.js\";\nexport { createGlyphStorage, updateGlyphStorage, disposeGlyphStorage } from \"./text/glyph-storage.js\";\nexport type { GLTextData, GLPlacedGlyph, GLGlyphRun, GLTextDataUpdate } from \"./text/text-data.js\";\nexport { createTextData, updateTextData, disposeTextData } from \"./text/text-data.js\";\nexport type { GLDefaultTextData } from \"./text/default-text-data.js\";\nexport { createDefaultTextData, updateDefaultTextData, disposeDefaultTextData } from \"./text/default-text-data.js\";\nexport type { GLTextLayer, GLTextLayerOptions, GLTextRenderer, GLTextRendererOptions } from \"./text/text-renderer.js\";\nexport {\n createTextLayer,\n setTextLayerPosition,\n createTextRenderer,\n renderText,\n isTextRendererReady,\n addTextRendererLayer,\n removeTextRendererLayer,\n registerTextRenderer,\n unregisterTextRenderer,\n disposeTextRenderer,\n} from \"./text/text-renderer.js\";\nexport { setFontWeightOffset } from \"./text/set-font-weight-offset.js\";\n"]}
|
package/mesh.d.ts
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* `createIndexBuffer` / `_releaseBuffer` / `bindIndexBuffer` /
|
|
10
10
|
* `bindInstancesBuffer` / `unbindInstanceAttributes` / `drawElementsType`. The
|
|
11
11
|
* attribute binder reproduces Babylon's instancing semantics EXACTLY, including
|
|
12
|
-
* the `computeStride = false → stride 0` "sliding window" used by
|
|
12
|
+
* the `computeStride = false → stride 0` "sliding window" used by distance-field
|
|
13
13
|
* tape buffers (consecutive instances read overlapping vec4 windows) and the
|
|
14
14
|
* `divisor === undefined → 1` default.
|
|
15
15
|
*
|
|
16
16
|
* The mesh path runs on the DEFAULT (null) VAO — every buffer/attribute op binds
|
|
17
17
|
* `gl.bindVertexArray(null)` first, so it never corrupts the quad / sprite VAOs.
|
|
18
|
-
*
|
|
19
|
-
* `webglcontextrestored`.
|
|
18
|
+
* Unless the engine is host-owned (`createHostOwnedGLEngine`), vertex/index buffers retain their CPU
|
|
19
|
+
* data and re-upload automatically on `webglcontextrestored`.
|
|
20
20
|
*/
|
|
21
21
|
import type { GLEngineContext } from "./context.js";
|
|
22
22
|
import { type GLEffect } from "./effect.js";
|
|
@@ -68,7 +68,7 @@ export interface GLAttributeDescriptor {
|
|
|
68
68
|
* Create a GPU vertex buffer from interleaved float data.
|
|
69
69
|
*
|
|
70
70
|
* @param engine - The engine.
|
|
71
|
-
* @param data - The vertex data. Retained by reference
|
|
71
|
+
* @param data - The vertex data. Retained by reference unless the engine opts out of context restoration — do
|
|
72
72
|
* not mutate it in place; use {@link updateVertexBuffer} to change contents.
|
|
73
73
|
* @param dynamic - Hint that the buffer will be updated frequently
|
|
74
74
|
* (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).
|
|
@@ -78,7 +78,7 @@ export declare function createVertexBuffer(engine: GLEngineContext, data: Float3
|
|
|
78
78
|
/**
|
|
79
79
|
* Upload new contents into (part of) a vertex buffer via `bufferSubData`. A
|
|
80
80
|
* full-buffer update from offset 0 also refreshes the retained CPU data used
|
|
81
|
-
* for context-restore.
|
|
81
|
+
* for context-restore unless the engine opts out. Neither mode copies the input.
|
|
82
82
|
*
|
|
83
83
|
* @param vb - The vertex buffer to update.
|
|
84
84
|
* @param data - The new float data.
|
|
@@ -91,12 +91,13 @@ export declare function updateVertexBuffer(vb: GLVertexBuffer, data: Float32Arra
|
|
|
91
91
|
* VAO element bindings.
|
|
92
92
|
*
|
|
93
93
|
* @param engine - The engine.
|
|
94
|
-
* @param data - The index data. Retained by reference
|
|
94
|
+
* @param data - The index data. Retained by reference unless the engine opts out of context restoration.
|
|
95
95
|
* @returns The new {@link GLIndexBuffer}.
|
|
96
96
|
*/
|
|
97
97
|
export declare function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer;
|
|
98
98
|
/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears
|
|
99
|
-
* the array/element-buffer cache slot if it pointed at this buffer
|
|
99
|
+
* the array/element-buffer cache slot if it pointed at this buffer and releases
|
|
100
|
+
* retained upload/restore references in both recovery modes. Idempotent. */
|
|
100
101
|
export declare function disposeBuffer(buffer: GLVertexBuffer | GLIndexBuffer): void;
|
|
101
102
|
/**
|
|
102
103
|
* Bind an index buffer as the current element-array buffer (on the default
|
|
@@ -108,18 +109,22 @@ export declare function bindIndexBuffer(ib: GLIndexBuffer): void;
|
|
|
108
109
|
/**
|
|
109
110
|
* Configure vertex attributes from `vb`, reproducing Babylon's
|
|
110
111
|
* `bindInstancesBuffer` exactly. For each descriptor: resolves the location
|
|
111
|
-
* (explicit `index` or via the effect), enables the attribute array,
|
|
112
|
-
* `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`).
|
|
113
|
-
* instanced location (divisor ≠ 0) is tracked once so {@link unbindInstanceAttributes}
|
|
112
|
+
* (explicit `index` or via the effect), enables the attribute array (cached),
|
|
113
|
+
* issues `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`).
|
|
114
|
+
* Each instanced location (divisor ≠ 0) is tracked once so {@link unbindInstanceAttributes}
|
|
114
115
|
* can reset its divisor afterwards; per-vertex locations already have divisor 0 and are
|
|
115
116
|
* not tracked, so callers that never instance can rebind every frame without growth.
|
|
116
117
|
*
|
|
117
118
|
* `computeStride` controls the GL stride passed to `vertexAttribPointer`:
|
|
118
119
|
* - `false` (default) → stride `0`: each attribute is independently tightly
|
|
119
120
|
* packed. Combined with overlapping `offset`s this yields the "sliding window"
|
|
120
|
-
*
|
|
121
|
+
* used by distance-field tape buffers.
|
|
121
122
|
* - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.
|
|
122
123
|
*
|
|
124
|
+
* Every call re-issues `vertexAttribPointer`. Callers that rebind an equivalent
|
|
125
|
+
* layout every draw (e.g. a 2D shape renderer) should use {@link bindAttributesCached},
|
|
126
|
+
* which elides unchanged pointers; the two can be mixed freely.
|
|
127
|
+
*
|
|
123
128
|
* Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.
|
|
124
129
|
* No-op on a lost/disposed context or before the effect is ready.
|
|
125
130
|
*
|
|
@@ -129,11 +134,59 @@ export declare function bindIndexBuffer(ib: GLIndexBuffer): void;
|
|
|
129
134
|
* @param computeStride - See above. Default `false`.
|
|
130
135
|
*/
|
|
131
136
|
export declare function bindAttributes(vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride?: boolean): void;
|
|
137
|
+
/**
|
|
138
|
+
* {@link bindAttributes} with a default-VAO attribute cache: `vertexAttribPointer`
|
|
139
|
+
* is issued only when a location's (buffer handle, size, type, normalized,
|
|
140
|
+
* stride, offset) tuple changes, and `vertexAttribDivisor` only when its divisor
|
|
141
|
+
* changes, so rebinding an equivalent layout every draw (e.g. per-shape binds in a
|
|
142
|
+
* 2D shape renderer) issues no attribute calls. Divisors are tracked through
|
|
143
|
+
* `instanceLocations`, so {@link unbindInstanceAttributes} needs no cache code.
|
|
144
|
+
* Semantics, parameters and no-op conditions are
|
|
145
|
+
* otherwise identical to {@link bindAttributes}.
|
|
146
|
+
*
|
|
147
|
+
* The cache (4 numbers per `MAX_VERTEX_ATTRIBS` location) is allocated once on
|
|
148
|
+
* the first effective call; later binds allocate nothing. Disabling an
|
|
149
|
+
* attribute, {@link bindAttributes}, cache wipes/resets and context loss
|
|
150
|
+
* invalidate the affected tuples, and a recreated buffer handle never matches
|
|
151
|
+
* a stale one. Named VAOs keep independent state.
|
|
152
|
+
*
|
|
153
|
+
* @param vb - The buffer supplying the attribute data.
|
|
154
|
+
* @param descriptors - The attribute layout.
|
|
155
|
+
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
156
|
+
* @param computeStride - See {@link bindAttributes}. Default `false`.
|
|
157
|
+
*/
|
|
158
|
+
export declare function bindAttributesCached(vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride?: boolean): void;
|
|
159
|
+
/**
|
|
160
|
+
* Disable an enabled attribute on the default VAO, eliding redundant calls.
|
|
161
|
+
* Leaves its divisor unchanged, like ThinEngine's `disableAttributeByIndex`;
|
|
162
|
+
* use {@link unbindInstanceAttributes} for divisor cleanup. Named VAOs are
|
|
163
|
+
* untouched. No-op on a lost/disposed engine. The enable cache is cleared on
|
|
164
|
+
* context loss or cache reset, so subsequent binds replay their enables. After
|
|
165
|
+
* a plain `wipeGLStateCache`, a location lite-gl has not confirmed
|
|
166
|
+
* disabled is treated as unknown (the host may have enabled it) and is disabled.
|
|
167
|
+
*
|
|
168
|
+
* @param engine - The engine.
|
|
169
|
+
* @param location - The attribute location to disable.
|
|
170
|
+
*/
|
|
171
|
+
export declare function disableAttributeByIndex(engine: GLEngineContext, location: number): void;
|
|
172
|
+
/**
|
|
173
|
+
* Disable all enabled default-VAO attributes in ascending location order.
|
|
174
|
+
* Cached across frames and allocation-free; named VAOs and instance divisors
|
|
175
|
+
* are unchanged (ThinEngine's `unbindAllAttributes` semantics). No-op on a
|
|
176
|
+
* lost/disposed engine. Context loss/cache reset clears the enable cache;
|
|
177
|
+
* subsequent {@link bindAttributes} calls replay their enables. The first call
|
|
178
|
+
* after a plain `wipeGLStateCache` disables every location up to
|
|
179
|
+
* `MAX_VERTEX_ATTRIBS` once, since the host may have enabled any of them.
|
|
180
|
+
*
|
|
181
|
+
* @param engine - The engine.
|
|
182
|
+
*/
|
|
183
|
+
export declare function unbindAllAttributes(engine: GLEngineContext): void;
|
|
132
184
|
/**
|
|
133
185
|
* Reset the vertex divisor of every attribute touched by {@link bindAttributes}
|
|
134
|
-
* back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.
|
|
186
|
+
* or {@link bindAttributesCached} back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.
|
|
135
187
|
* Call after an instanced draw so a following non-instanced draw is not skewed.
|
|
136
|
-
*
|
|
188
|
+
* The divisors are reset on the default VAO (selected if a named VAO is bound),
|
|
189
|
+
* where these binders set them. No-op on a lost/disposed context.
|
|
137
190
|
*
|
|
138
191
|
* @param engine - The engine.
|
|
139
192
|
*/
|
|
@@ -164,7 +217,8 @@ export interface GLMeshVertexBuffer {
|
|
|
164
217
|
/** A recorded Vertex Array Object capturing a static mesh's attribute layout +
|
|
165
218
|
* index binding. Bind + draw it with {@link drawMesh} each frame — the GPU
|
|
166
219
|
* replays the entire attribute setup from one `bindVertexArray`. Re-recorded
|
|
167
|
-
* automatically on `webglcontextrestored
|
|
220
|
+
* automatically on `webglcontextrestored` unless the engine is host-owned
|
|
221
|
+
* (`createHostOwnedGLEngine`). */
|
|
168
222
|
export interface GLMeshVao {
|
|
169
223
|
/** The live `WebGLVertexArrayObject`. Swapped on `webglcontextrestored`. */
|
|
170
224
|
handle: WebGLVertexArrayObject;
|
package/mesh.js
CHANGED
|
@@ -22,7 +22,7 @@ const UNSIGNED_INT = 0x1405;
|
|
|
22
22
|
* Create a GPU vertex buffer from interleaved float data.
|
|
23
23
|
*
|
|
24
24
|
* @param engine - The engine.
|
|
25
|
-
* @param data - The vertex data. Retained by reference
|
|
25
|
+
* @param data - The vertex data. Retained by reference unless the engine opts out of context restoration — do
|
|
26
26
|
* not mutate it in place; use {@link updateVertexBuffer} to change contents.
|
|
27
27
|
* @param dynamic - Hint that the buffer will be updated frequently
|
|
28
28
|
* (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).
|
|
@@ -37,26 +37,26 @@ export function createVertexBuffer(engine, data, dynamic = false) {
|
|
|
37
37
|
const vb = {
|
|
38
38
|
handle,
|
|
39
39
|
byteLength: data.byteLength,
|
|
40
|
-
_data: data,
|
|
41
40
|
_dynamic: dynamic,
|
|
42
41
|
_engine: engine,
|
|
43
42
|
_disposed: false,
|
|
44
|
-
_deleteGpu: () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
vb._deleteGpu = (g) => {
|
|
48
|
-
g.deleteBuffer(vb.handle);
|
|
49
|
-
};
|
|
50
|
-
vb._restore = (target) => {
|
|
51
|
-
const g = target.gl;
|
|
52
|
-
const fresh = g.createBuffer();
|
|
53
|
-
if (fresh === null) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
vb.handle = fresh;
|
|
57
|
-
bindArrayBufferRaw(target, fresh);
|
|
58
|
-
g.bufferData(ARRAY_BUFFER, vb._data, vb._dynamic ? DYNAMIC_DRAW : STATIC_DRAW);
|
|
43
|
+
_deleteGpu: (g) => {
|
|
44
|
+
g.deleteBuffer(vb.handle);
|
|
45
|
+
},
|
|
59
46
|
};
|
|
47
|
+
if (!engine._noRestore) {
|
|
48
|
+
vb._data = data;
|
|
49
|
+
vb._restore = (target) => {
|
|
50
|
+
const g = target.gl;
|
|
51
|
+
const fresh = g.createBuffer();
|
|
52
|
+
if (fresh === null) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
vb.handle = fresh;
|
|
56
|
+
bindArrayBufferRaw(target, fresh);
|
|
57
|
+
g.bufferData(ARRAY_BUFFER, vb._data, vb._dynamic ? DYNAMIC_DRAW : STATIC_DRAW);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
60
|
bindArrayBufferRaw(engine, handle);
|
|
61
61
|
gl.bufferData(ARRAY_BUFFER, data, dynamic ? DYNAMIC_DRAW : STATIC_DRAW);
|
|
62
62
|
engine._buffers.push(vb);
|
|
@@ -65,7 +65,7 @@ export function createVertexBuffer(engine, data, dynamic = false) {
|
|
|
65
65
|
/**
|
|
66
66
|
* Upload new contents into (part of) a vertex buffer via `bufferSubData`. A
|
|
67
67
|
* full-buffer update from offset 0 also refreshes the retained CPU data used
|
|
68
|
-
* for context-restore.
|
|
68
|
+
* for context-restore unless the engine opts out. Neither mode copies the input.
|
|
69
69
|
*
|
|
70
70
|
* @param vb - The vertex buffer to update.
|
|
71
71
|
* @param data - The new float data.
|
|
@@ -79,7 +79,9 @@ export function updateVertexBuffer(vb, data, dstByteOffset = 0) {
|
|
|
79
79
|
bindArrayBufferRaw(engine, vb.handle);
|
|
80
80
|
engine.gl.bufferSubData(ARRAY_BUFFER, dstByteOffset, data);
|
|
81
81
|
if (dstByteOffset === 0 && data.byteLength >= vb.byteLength) {
|
|
82
|
-
|
|
82
|
+
if (!engine._noRestore) {
|
|
83
|
+
vb._data = data;
|
|
84
|
+
}
|
|
83
85
|
vb.byteLength = data.byteLength;
|
|
84
86
|
}
|
|
85
87
|
}
|
|
@@ -89,7 +91,7 @@ export function updateVertexBuffer(vb, data, dstByteOffset = 0) {
|
|
|
89
91
|
* VAO element bindings.
|
|
90
92
|
*
|
|
91
93
|
* @param engine - The engine.
|
|
92
|
-
* @param data - The index data. Retained by reference
|
|
94
|
+
* @param data - The index data. Retained by reference unless the engine opts out of context restoration.
|
|
93
95
|
* @returns The new {@link GLIndexBuffer}.
|
|
94
96
|
*/
|
|
95
97
|
export function createIndexBuffer(engine, data) {
|
|
@@ -103,27 +105,27 @@ export function createIndexBuffer(engine, data) {
|
|
|
103
105
|
handle,
|
|
104
106
|
count: data.length,
|
|
105
107
|
is32Bits: is32,
|
|
106
|
-
_data: data,
|
|
107
108
|
_engine: engine,
|
|
108
109
|
_disposed: false,
|
|
109
|
-
_deleteGpu: () => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
ib._deleteGpu = (g) => {
|
|
113
|
-
g.deleteBuffer(ib.handle);
|
|
114
|
-
};
|
|
115
|
-
ib._restore = (target) => {
|
|
116
|
-
const g = target.gl;
|
|
117
|
-
const fresh = g.createBuffer();
|
|
118
|
-
if (fresh === null) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
ib.handle = fresh;
|
|
122
|
-
bindDefaultVao(target);
|
|
123
|
-
g.bindBuffer(ELEMENT_ARRAY_BUFFER, fresh);
|
|
124
|
-
target._state.boundElementBuffer = fresh;
|
|
125
|
-
g.bufferData(ELEMENT_ARRAY_BUFFER, ib._data, STATIC_DRAW);
|
|
110
|
+
_deleteGpu: (g) => {
|
|
111
|
+
g.deleteBuffer(ib.handle);
|
|
112
|
+
},
|
|
126
113
|
};
|
|
114
|
+
if (!engine._noRestore) {
|
|
115
|
+
ib._data = data;
|
|
116
|
+
ib._restore = (target) => {
|
|
117
|
+
const g = target.gl;
|
|
118
|
+
const fresh = g.createBuffer();
|
|
119
|
+
if (fresh === null) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
ib.handle = fresh;
|
|
123
|
+
bindDefaultVao(target);
|
|
124
|
+
g.bindBuffer(ELEMENT_ARRAY_BUFFER, fresh);
|
|
125
|
+
target._state.boundElementBuffer = fresh;
|
|
126
|
+
g.bufferData(ELEMENT_ARRAY_BUFFER, ib._data, STATIC_DRAW);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
127
129
|
bindDefaultVao(engine);
|
|
128
130
|
gl.bindBuffer(ELEMENT_ARRAY_BUFFER, handle);
|
|
129
131
|
engine._state.boundElementBuffer = handle;
|
|
@@ -132,13 +134,15 @@ export function createIndexBuffer(engine, data) {
|
|
|
132
134
|
return ib;
|
|
133
135
|
}
|
|
134
136
|
/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears
|
|
135
|
-
* the array/element-buffer cache slot if it pointed at this buffer
|
|
137
|
+
* the array/element-buffer cache slot if it pointed at this buffer and releases
|
|
138
|
+
* retained upload/restore references in both recovery modes. Idempotent. */
|
|
136
139
|
export function disposeBuffer(buffer) {
|
|
137
140
|
const engine = buffer._engine;
|
|
138
141
|
if (buffer._disposed) {
|
|
139
142
|
return;
|
|
140
143
|
}
|
|
141
144
|
buffer._disposed = true;
|
|
145
|
+
buffer._data = buffer._restore = undefined;
|
|
142
146
|
const i = engine._buffers.indexOf(buffer);
|
|
143
147
|
if (i !== -1) {
|
|
144
148
|
engine._buffers.splice(i, 1);
|
|
@@ -153,6 +157,11 @@ export function disposeBuffer(buffer) {
|
|
|
153
157
|
if (s.boundElementBuffer === buffer.handle) {
|
|
154
158
|
s.boundElementBuffer = null;
|
|
155
159
|
}
|
|
160
|
+
for (let location = 0; location < s.enabledAttribs.length; location++) {
|
|
161
|
+
if (s.enabledAttribs[location] === buffer.handle) {
|
|
162
|
+
s.enabledAttribs[location] = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
156
165
|
}
|
|
157
166
|
/* ────────────────────────────── binding + draw ──────────────────────────── */
|
|
158
167
|
/**
|
|
@@ -177,18 +186,22 @@ export function bindIndexBuffer(ib) {
|
|
|
177
186
|
/**
|
|
178
187
|
* Configure vertex attributes from `vb`, reproducing Babylon's
|
|
179
188
|
* `bindInstancesBuffer` exactly. For each descriptor: resolves the location
|
|
180
|
-
* (explicit `index` or via the effect), enables the attribute array,
|
|
181
|
-
* `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`).
|
|
182
|
-
* instanced location (divisor ≠ 0) is tracked once so {@link unbindInstanceAttributes}
|
|
189
|
+
* (explicit `index` or via the effect), enables the attribute array (cached),
|
|
190
|
+
* issues `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`).
|
|
191
|
+
* Each instanced location (divisor ≠ 0) is tracked once so {@link unbindInstanceAttributes}
|
|
183
192
|
* can reset its divisor afterwards; per-vertex locations already have divisor 0 and are
|
|
184
193
|
* not tracked, so callers that never instance can rebind every frame without growth.
|
|
185
194
|
*
|
|
186
195
|
* `computeStride` controls the GL stride passed to `vertexAttribPointer`:
|
|
187
196
|
* - `false` (default) → stride `0`: each attribute is independently tightly
|
|
188
197
|
* packed. Combined with overlapping `offset`s this yields the "sliding window"
|
|
189
|
-
*
|
|
198
|
+
* used by distance-field tape buffers.
|
|
190
199
|
* - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.
|
|
191
200
|
*
|
|
201
|
+
* Every call re-issues `vertexAttribPointer`. Callers that rebind an equivalent
|
|
202
|
+
* layout every draw (e.g. a 2D shape renderer) should use {@link bindAttributesCached},
|
|
203
|
+
* which elides unchanged pointers; the two can be mixed freely.
|
|
204
|
+
*
|
|
192
205
|
* Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.
|
|
193
206
|
* No-op on a lost/disposed context or before the effect is ready.
|
|
194
207
|
*
|
|
@@ -220,8 +233,9 @@ export function bindAttributes(vb, descriptors, effect, computeStride = false) {
|
|
|
220
233
|
}
|
|
221
234
|
if (!s.enabledAttribs[loc]) {
|
|
222
235
|
gl.enableVertexAttribArray(loc);
|
|
223
|
-
s.enabledAttribs[loc] = true;
|
|
224
236
|
}
|
|
237
|
+
// Enabled, but with a pointer bindAttributesCached must not trust.
|
|
238
|
+
s.enabledAttribs[loc] = true;
|
|
225
239
|
gl.vertexAttribPointer(loc, d.size, d.type ?? FLOAT, d.normalized ?? false, stride, d.offset ?? 0);
|
|
226
240
|
const divisor = d.divisor ?? 1;
|
|
227
241
|
gl.vertexAttribDivisor(loc, divisor);
|
|
@@ -230,11 +244,134 @@ export function bindAttributes(vb, descriptors, effect, computeStride = false) {
|
|
|
230
244
|
}
|
|
231
245
|
}
|
|
232
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* {@link bindAttributes} with a default-VAO attribute cache: `vertexAttribPointer`
|
|
249
|
+
* is issued only when a location's (buffer handle, size, type, normalized,
|
|
250
|
+
* stride, offset) tuple changes, and `vertexAttribDivisor` only when its divisor
|
|
251
|
+
* changes, so rebinding an equivalent layout every draw (e.g. per-shape binds in a
|
|
252
|
+
* 2D shape renderer) issues no attribute calls. Divisors are tracked through
|
|
253
|
+
* `instanceLocations`, so {@link unbindInstanceAttributes} needs no cache code.
|
|
254
|
+
* Semantics, parameters and no-op conditions are
|
|
255
|
+
* otherwise identical to {@link bindAttributes}.
|
|
256
|
+
*
|
|
257
|
+
* The cache (4 numbers per `MAX_VERTEX_ATTRIBS` location) is allocated once on
|
|
258
|
+
* the first effective call; later binds allocate nothing. Disabling an
|
|
259
|
+
* attribute, {@link bindAttributes}, cache wipes/resets and context loss
|
|
260
|
+
* invalidate the affected tuples, and a recreated buffer handle never matches
|
|
261
|
+
* a stale one. Named VAOs keep independent state.
|
|
262
|
+
*
|
|
263
|
+
* @param vb - The buffer supplying the attribute data.
|
|
264
|
+
* @param descriptors - The attribute layout.
|
|
265
|
+
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
266
|
+
* @param computeStride - See {@link bindAttributes}. Default `false`.
|
|
267
|
+
*/
|
|
268
|
+
export function bindAttributesCached(vb, descriptors, effect, computeStride = false) {
|
|
269
|
+
const engine = vb._engine;
|
|
270
|
+
if (engine._isLost || engine._disposed || vb._disposed || !effect.isReady) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const gl = engine.gl;
|
|
274
|
+
const s = engine._state;
|
|
275
|
+
bindDefaultVao(engine);
|
|
276
|
+
bindArrayBufferRaw(engine, vb.handle);
|
|
277
|
+
const values = (s._attributePointers ??= new Float64Array(gl.getParameter(gl.MAX_VERTEX_ATTRIBS) * 4));
|
|
278
|
+
let stride = 0;
|
|
279
|
+
if (computeStride) {
|
|
280
|
+
for (let i = 0; i < descriptors.length; i++) {
|
|
281
|
+
stride += descriptors[i].size * 4;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
for (let i = 0; i < descriptors.length; i++) {
|
|
285
|
+
const d = descriptors[i];
|
|
286
|
+
const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(effect, d.name) : -1;
|
|
287
|
+
if (loc < 0) {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const enabled = s.enabledAttribs[loc];
|
|
291
|
+
if (!enabled) {
|
|
292
|
+
gl.enableVertexAttribArray(loc);
|
|
293
|
+
}
|
|
294
|
+
const type = d.type ?? FLOAT;
|
|
295
|
+
const normalized = d.normalized ?? false;
|
|
296
|
+
const offset = d.offset ?? 0;
|
|
297
|
+
// A GLenum fits in 32 bits; packing the valid 1..4 size and normalize
|
|
298
|
+
// flag leaves one exact (53-bit) number instead of three cache slots.
|
|
299
|
+
const format = type * 16 + d.size * 2 + +normalized;
|
|
300
|
+
const slot = loc * 4;
|
|
301
|
+
if (enabled !== vb.handle || values[slot] !== format || values[slot + 1] !== stride || values[slot + 2] !== offset) {
|
|
302
|
+
gl.vertexAttribPointer(loc, d.size, type, normalized, stride, offset);
|
|
303
|
+
values[slot] = format;
|
|
304
|
+
values[slot + 1] = stride;
|
|
305
|
+
values[slot + 2] = offset;
|
|
306
|
+
}
|
|
307
|
+
const divisor = d.divisor ?? 1;
|
|
308
|
+
// While this binder owns the location (a buffer handle, not `true`/null),
|
|
309
|
+
// every non-zero divisor it sets is listed in instanceLocations, and only
|
|
310
|
+
// unbindInstanceAttributes (which resets listed divisors to 0) or a cache
|
|
311
|
+
// reset (which also drops ownership) clears that list. An owned, unlisted
|
|
312
|
+
// location therefore has divisor 0; a listed one has the cached divisor.
|
|
313
|
+
const listed = s.instanceLocations.includes(loc);
|
|
314
|
+
if (!enabled || enabled === true || (listed ? values[slot + 3] : 0) !== divisor) {
|
|
315
|
+
gl.vertexAttribDivisor(loc, divisor);
|
|
316
|
+
values[slot + 3] = divisor;
|
|
317
|
+
if (divisor !== 0 && !listed) {
|
|
318
|
+
s.instanceLocations.push(loc);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
s.enabledAttribs[loc] = vb.handle;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Disable an enabled attribute on the default VAO, eliding redundant calls.
|
|
326
|
+
* Leaves its divisor unchanged, like ThinEngine's `disableAttributeByIndex`;
|
|
327
|
+
* use {@link unbindInstanceAttributes} for divisor cleanup. Named VAOs are
|
|
328
|
+
* untouched. No-op on a lost/disposed engine. The enable cache is cleared on
|
|
329
|
+
* context loss or cache reset, so subsequent binds replay their enables. After
|
|
330
|
+
* a plain `wipeGLStateCache`, a location lite-gl has not confirmed
|
|
331
|
+
* disabled is treated as unknown (the host may have enabled it) and is disabled.
|
|
332
|
+
*
|
|
333
|
+
* @param engine - The engine.
|
|
334
|
+
* @param location - The attribute location to disable.
|
|
335
|
+
*/
|
|
336
|
+
export function disableAttributeByIndex(engine, location) {
|
|
337
|
+
const s = engine._state;
|
|
338
|
+
const enabled = s.enabledAttribs[location];
|
|
339
|
+
// `-1` is the "optimized out" sentinel from `getAttribLocation`: always a no-op.
|
|
340
|
+
if (location < 0 || engine._isLost || engine._disposed || (s._unknownAttribs ? enabled === null : !enabled)) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
bindDefaultVao(engine);
|
|
344
|
+
engine.gl.disableVertexAttribArray(location);
|
|
345
|
+
s.enabledAttribs[location] = null;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Disable all enabled default-VAO attributes in ascending location order.
|
|
349
|
+
* Cached across frames and allocation-free; named VAOs and instance divisors
|
|
350
|
+
* are unchanged (ThinEngine's `unbindAllAttributes` semantics). No-op on a
|
|
351
|
+
* lost/disposed engine. Context loss/cache reset clears the enable cache;
|
|
352
|
+
* subsequent {@link bindAttributes} calls replay their enables. The first call
|
|
353
|
+
* after a plain `wipeGLStateCache` disables every location up to
|
|
354
|
+
* `MAX_VERTEX_ATTRIBS` once, since the host may have enabled any of them.
|
|
355
|
+
*
|
|
356
|
+
* @param engine - The engine.
|
|
357
|
+
*/
|
|
358
|
+
export function unbindAllAttributes(engine) {
|
|
359
|
+
if (engine._isLost || engine._disposed) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const s = engine._state;
|
|
363
|
+
const count = s._unknownAttribs ? engine.gl.getParameter(engine.gl.MAX_VERTEX_ATTRIBS) : s.enabledAttribs.length;
|
|
364
|
+
for (let location = 0; location < count; location++) {
|
|
365
|
+
disableAttributeByIndex(engine, location);
|
|
366
|
+
}
|
|
367
|
+
s._unknownAttribs = false;
|
|
368
|
+
}
|
|
233
369
|
/**
|
|
234
370
|
* Reset the vertex divisor of every attribute touched by {@link bindAttributes}
|
|
235
|
-
* back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.
|
|
371
|
+
* or {@link bindAttributesCached} back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.
|
|
236
372
|
* Call after an instanced draw so a following non-instanced draw is not skewed.
|
|
237
|
-
*
|
|
373
|
+
* The divisors are reset on the default VAO (selected if a named VAO is bound),
|
|
374
|
+
* where these binders set them. No-op on a lost/disposed context.
|
|
238
375
|
*
|
|
239
376
|
* @param engine - The engine.
|
|
240
377
|
*/
|
|
@@ -242,8 +379,14 @@ export function unbindInstanceAttributes(engine) {
|
|
|
242
379
|
if (engine._isLost || engine._disposed) {
|
|
243
380
|
return;
|
|
244
381
|
}
|
|
245
|
-
const gl = engine.gl;
|
|
246
382
|
const locs = engine._state.instanceLocations;
|
|
383
|
+
if (locs.length === 0) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
// The listed divisors live on the default VAO; a named VAO bound since then
|
|
387
|
+
// owns its own divisors and must not be reset.
|
|
388
|
+
bindDefaultVao(engine);
|
|
389
|
+
const gl = engine.gl;
|
|
247
390
|
for (let i = 0; i < locs.length; i++) {
|
|
248
391
|
gl.vertexAttribDivisor(locs[i], 0);
|
|
249
392
|
}
|
|
@@ -333,20 +476,25 @@ export function createMeshVao(engine, vertexBuffers, indexBuffer, effect) {
|
|
|
333
476
|
}
|
|
334
477
|
bindings.push({ buffer: vbb.buffer, attrs });
|
|
335
478
|
}
|
|
336
|
-
const vao = { handle, _engine: engine, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
479
|
+
const vao = { handle, _engine: engine, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings };
|
|
480
|
+
if (!engine._noRestore) {
|
|
481
|
+
vao._restore = () => {
|
|
482
|
+
if (engine._isLost || engine._disposed || vao._disposed) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
const fresh = engine.gl.createVertexArray();
|
|
486
|
+
if (fresh === null) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
vao.handle = fresh;
|
|
490
|
+
recordMeshVao(engine, vao);
|
|
491
|
+
};
|
|
492
|
+
onContextRestored(engine, vao._restore);
|
|
493
|
+
}
|
|
348
494
|
recordMeshVao(engine, vao);
|
|
349
|
-
|
|
495
|
+
if (engine._noRestore) {
|
|
496
|
+
bindings.length = 0;
|
|
497
|
+
}
|
|
350
498
|
return vao;
|
|
351
499
|
}
|
|
352
500
|
/**
|
|
@@ -414,7 +562,9 @@ export function disposeMeshVao(vao) {
|
|
|
414
562
|
return;
|
|
415
563
|
}
|
|
416
564
|
vao._disposed = true;
|
|
417
|
-
|
|
565
|
+
if (vao._restore) {
|
|
566
|
+
offContextRestored(engine, vao._restore);
|
|
567
|
+
}
|
|
418
568
|
if (!engine._isLost && !engine._disposed) {
|
|
419
569
|
const s = engine._state;
|
|
420
570
|
engine.gl.deleteVertexArray(vao.handle);
|