@solidtv/renderer 1.0.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.
Files changed (424) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +137 -0
  4. package/dist/exports/canvas-shaders.d.ts +10 -0
  5. package/dist/exports/canvas-shaders.js +11 -0
  6. package/dist/exports/canvas-shaders.js.map +1 -0
  7. package/dist/exports/canvas.d.ts +26 -0
  8. package/dist/exports/canvas.js +27 -0
  9. package/dist/exports/canvas.js.map +1 -0
  10. package/dist/exports/index.d.ts +50 -0
  11. package/dist/exports/index.js +40 -0
  12. package/dist/exports/index.js.map +1 -0
  13. package/dist/exports/inspector.d.ts +4 -0
  14. package/dist/exports/inspector.js +5 -0
  15. package/dist/exports/inspector.js.map +1 -0
  16. package/dist/exports/utils.d.ts +27 -0
  17. package/dist/exports/utils.js +28 -0
  18. package/dist/exports/utils.js.map +1 -0
  19. package/dist/exports/webgl-shaders.d.ts +11 -0
  20. package/dist/exports/webgl-shaders.js +12 -0
  21. package/dist/exports/webgl-shaders.js.map +1 -0
  22. package/dist/exports/webgl.d.ts +28 -0
  23. package/dist/exports/webgl.js +29 -0
  24. package/dist/exports/webgl.js.map +1 -0
  25. package/dist/src/common/CommonTypes.d.ts +110 -0
  26. package/dist/src/common/CommonTypes.js +2 -0
  27. package/dist/src/common/CommonTypes.js.map +1 -0
  28. package/dist/src/common/EventEmitter.d.ts +12 -0
  29. package/dist/src/common/EventEmitter.js +48 -0
  30. package/dist/src/common/EventEmitter.js.map +1 -0
  31. package/dist/src/common/IAnimationController.d.ts +58 -0
  32. package/dist/src/common/IAnimationController.js +2 -0
  33. package/dist/src/common/IAnimationController.js.map +1 -0
  34. package/dist/src/common/IEventEmitter.d.ts +8 -0
  35. package/dist/src/common/IEventEmitter.js +2 -0
  36. package/dist/src/common/IEventEmitter.js.map +1 -0
  37. package/dist/src/core/Autosizer.d.ts +35 -0
  38. package/dist/src/core/Autosizer.js +178 -0
  39. package/dist/src/core/Autosizer.js.map +1 -0
  40. package/dist/src/core/CoreNode.d.ts +908 -0
  41. package/dist/src/core/CoreNode.js +1837 -0
  42. package/dist/src/core/CoreNode.js.map +1 -0
  43. package/dist/src/core/CoreShaderManager.d.ts +38 -0
  44. package/dist/src/core/CoreShaderManager.js +123 -0
  45. package/dist/src/core/CoreShaderManager.js.map +1 -0
  46. package/dist/src/core/CoreTextNode.d.ts +91 -0
  47. package/dist/src/core/CoreTextNode.js +440 -0
  48. package/dist/src/core/CoreTextNode.js.map +1 -0
  49. package/dist/src/core/CoreTextureManager.d.ts +264 -0
  50. package/dist/src/core/CoreTextureManager.js +318 -0
  51. package/dist/src/core/CoreTextureManager.js.map +1 -0
  52. package/dist/src/core/Stage.d.ts +238 -0
  53. package/dist/src/core/Stage.js +804 -0
  54. package/dist/src/core/Stage.js.map +1 -0
  55. package/dist/src/core/TextureError.d.ts +11 -0
  56. package/dist/src/core/TextureError.js +37 -0
  57. package/dist/src/core/TextureError.js.map +1 -0
  58. package/dist/src/core/TextureMemoryManager.d.ts +150 -0
  59. package/dist/src/core/TextureMemoryManager.js +239 -0
  60. package/dist/src/core/TextureMemoryManager.js.map +1 -0
  61. package/dist/src/core/animations/AnimationManager.d.ts +33 -0
  62. package/dist/src/core/animations/AnimationManager.js +137 -0
  63. package/dist/src/core/animations/AnimationManager.js.map +1 -0
  64. package/dist/src/core/animations/CoreAnimation.d.ts +12 -0
  65. package/dist/src/core/animations/CoreAnimation.js +107 -0
  66. package/dist/src/core/animations/CoreAnimation.js.map +1 -0
  67. package/dist/src/core/lib/ContextSpy.d.ts +12 -0
  68. package/dist/src/core/lib/ContextSpy.js +20 -0
  69. package/dist/src/core/lib/ContextSpy.js.map +1 -0
  70. package/dist/src/core/lib/ImageWorker.d.ts +16 -0
  71. package/dist/src/core/lib/ImageWorker.js +202 -0
  72. package/dist/src/core/lib/ImageWorker.js.map +1 -0
  73. package/dist/src/core/lib/Matrix3d.d.ts +74 -0
  74. package/dist/src/core/lib/Matrix3d.js +218 -0
  75. package/dist/src/core/lib/Matrix3d.js.map +1 -0
  76. package/dist/src/core/lib/RenderCoords.d.ts +12 -0
  77. package/dist/src/core/lib/RenderCoords.js +35 -0
  78. package/dist/src/core/lib/RenderCoords.js.map +1 -0
  79. package/dist/src/core/lib/WebGlContextWrapper.d.ts +782 -0
  80. package/dist/src/core/lib/WebGlContextWrapper.js +1143 -0
  81. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -0
  82. package/dist/src/core/lib/collectionUtils.d.ts +5 -0
  83. package/dist/src/core/lib/collectionUtils.js +82 -0
  84. package/dist/src/core/lib/collectionUtils.js.map +1 -0
  85. package/dist/src/core/lib/colorCache.d.ts +1 -0
  86. package/dist/src/core/lib/colorCache.js +19 -0
  87. package/dist/src/core/lib/colorCache.js.map +1 -0
  88. package/dist/src/core/lib/colorParser.d.ts +21 -0
  89. package/dist/src/core/lib/colorParser.js +54 -0
  90. package/dist/src/core/lib/colorParser.js.map +1 -0
  91. package/dist/src/core/lib/textureCompression.d.ts +28 -0
  92. package/dist/src/core/lib/textureCompression.js +363 -0
  93. package/dist/src/core/lib/textureCompression.js.map +1 -0
  94. package/dist/src/core/lib/textureSvg.d.ts +16 -0
  95. package/dist/src/core/lib/textureSvg.js +45 -0
  96. package/dist/src/core/lib/textureSvg.js.map +1 -0
  97. package/dist/src/core/lib/utils.d.ts +66 -0
  98. package/dist/src/core/lib/utils.js +268 -0
  99. package/dist/src/core/lib/utils.js.map +1 -0
  100. package/dist/src/core/lib/validateImageBitmap.d.ts +7 -0
  101. package/dist/src/core/lib/validateImageBitmap.js +68 -0
  102. package/dist/src/core/lib/validateImageBitmap.js.map +1 -0
  103. package/dist/src/core/platforms/Platform.d.ts +42 -0
  104. package/dist/src/core/platforms/Platform.js +4 -0
  105. package/dist/src/core/platforms/Platform.js.map +1 -0
  106. package/dist/src/core/platforms/web/WebPlatform.d.ts +10 -0
  107. package/dist/src/core/platforms/web/WebPlatform.js +90 -0
  108. package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
  109. package/dist/src/core/renderers/CoreContextTexture.d.ts +13 -0
  110. package/dist/src/core/renderers/CoreContextTexture.js +16 -0
  111. package/dist/src/core/renderers/CoreContextTexture.js.map +1 -0
  112. package/dist/src/core/renderers/CoreRenderOp.d.ts +3 -0
  113. package/dist/src/core/renderers/CoreRenderOp.js +3 -0
  114. package/dist/src/core/renderers/CoreRenderOp.js.map +1 -0
  115. package/dist/src/core/renderers/CoreRenderer.d.ts +81 -0
  116. package/dist/src/core/renderers/CoreRenderer.js +14 -0
  117. package/dist/src/core/renderers/CoreRenderer.js.map +1 -0
  118. package/dist/src/core/renderers/CoreShaderNode.d.ts +69 -0
  119. package/dist/src/core/renderers/CoreShaderNode.js +130 -0
  120. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -0
  121. package/dist/src/core/renderers/CoreShaderProgram.d.ts +4 -0
  122. package/dist/src/core/renderers/CoreShaderProgram.js +2 -0
  123. package/dist/src/core/renderers/CoreShaderProgram.js.map +1 -0
  124. package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +36 -0
  125. package/dist/src/core/renderers/canvas/CanvasRenderer.js +221 -0
  126. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -0
  127. package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +21 -0
  128. package/dist/src/core/renderers/canvas/CanvasShaderNode.js +42 -0
  129. package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -0
  130. package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +17 -0
  131. package/dist/src/core/renderers/canvas/CanvasTexture.js +110 -0
  132. package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -0
  133. package/dist/src/core/renderers/webgl/SdfRenderOp.d.ts +41 -0
  134. package/dist/src/core/renderers/webgl/SdfRenderOp.js +88 -0
  135. package/dist/src/core/renderers/webgl/SdfRenderOp.js.map +1 -0
  136. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +14 -0
  137. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +45 -0
  138. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -0
  139. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +22 -0
  140. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +49 -0
  141. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -0
  142. package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +67 -0
  143. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +259 -0
  144. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -0
  145. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +221 -0
  146. package/dist/src/core/renderers/webgl/WebGlRenderer.js +1015 -0
  147. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -0
  148. package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +213 -0
  149. package/dist/src/core/renderers/webgl/WebGlShaderNode.js +331 -0
  150. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -0
  151. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +37 -0
  152. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +240 -0
  153. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -0
  154. package/dist/src/core/renderers/webgl/internal/BufferCollection.d.ts +28 -0
  155. package/dist/src/core/renderers/webgl/internal/BufferCollection.js +39 -0
  156. package/dist/src/core/renderers/webgl/internal/BufferCollection.js.map +1 -0
  157. package/dist/src/core/renderers/webgl/internal/RendererUtils.d.ts +55 -0
  158. package/dist/src/core/renderers/webgl/internal/RendererUtils.js +88 -0
  159. package/dist/src/core/renderers/webgl/internal/RendererUtils.js.map +1 -0
  160. package/dist/src/core/renderers/webgl/internal/ShaderUtils.d.ts +74 -0
  161. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +83 -0
  162. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js.map +1 -0
  163. package/dist/src/core/renderers/webgl/internal/WebGlUtils.d.ts +10 -0
  164. package/dist/src/core/renderers/webgl/internal/WebGlUtils.js +13 -0
  165. package/dist/src/core/renderers/webgl/internal/WebGlUtils.js.map +1 -0
  166. package/dist/src/core/shaders/canvas/Border.d.ts +15 -0
  167. package/dist/src/core/shaders/canvas/Border.js +83 -0
  168. package/dist/src/core/shaders/canvas/Border.js.map +1 -0
  169. package/dist/src/core/shaders/canvas/HolePunch.d.ts +7 -0
  170. package/dist/src/core/shaders/canvas/HolePunch.js +22 -0
  171. package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -0
  172. package/dist/src/core/shaders/canvas/LinearGradient.d.ts +10 -0
  173. package/dist/src/core/shaders/canvas/LinearGradient.js +32 -0
  174. package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -0
  175. package/dist/src/core/shaders/canvas/RadialGradient.d.ts +11 -0
  176. package/dist/src/core/shaders/canvas/RadialGradient.js +54 -0
  177. package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -0
  178. package/dist/src/core/shaders/canvas/Rounded.d.ts +7 -0
  179. package/dist/src/core/shaders/canvas/Rounded.js +17 -0
  180. package/dist/src/core/shaders/canvas/Rounded.js.map +1 -0
  181. package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +10 -0
  182. package/dist/src/core/shaders/canvas/RoundedWithBorder.js +57 -0
  183. package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -0
  184. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +7 -0
  185. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +61 -0
  186. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -0
  187. package/dist/src/core/shaders/canvas/RoundedWithShadow.d.ts +7 -0
  188. package/dist/src/core/shaders/canvas/RoundedWithShadow.js +26 -0
  189. package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -0
  190. package/dist/src/core/shaders/canvas/Shadow.d.ts +8 -0
  191. package/dist/src/core/shaders/canvas/Shadow.js +15 -0
  192. package/dist/src/core/shaders/canvas/Shadow.js.map +1 -0
  193. package/dist/src/core/shaders/canvas/utils/render.d.ts +5 -0
  194. package/dist/src/core/shaders/canvas/utils/render.js +81 -0
  195. package/dist/src/core/shaders/canvas/utils/render.js.map +1 -0
  196. package/dist/src/core/shaders/templates/BorderTemplate.d.ts +47 -0
  197. package/dist/src/core/shaders/templates/BorderTemplate.js +77 -0
  198. package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -0
  199. package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +46 -0
  200. package/dist/src/core/shaders/templates/HolePunchTemplate.js +19 -0
  201. package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -0
  202. package/dist/src/core/shaders/templates/LinearGradientTemplate.d.ts +23 -0
  203. package/dist/src/core/shaders/templates/LinearGradientTemplate.js +31 -0
  204. package/dist/src/core/shaders/templates/LinearGradientTemplate.js.map +1 -0
  205. package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +33 -0
  206. package/dist/src/core/shaders/templates/RadialGradientTemplate.js +33 -0
  207. package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -0
  208. package/dist/src/core/shaders/templates/RoundedTemplate.d.ts +29 -0
  209. package/dist/src/core/shaders/templates/RoundedTemplate.js +51 -0
  210. package/dist/src/core/shaders/templates/RoundedTemplate.js.map +1 -0
  211. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +7 -0
  212. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js +8 -0
  213. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js.map +1 -0
  214. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +8 -0
  215. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js +9 -0
  216. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js.map +1 -0
  217. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +6 -0
  218. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js +7 -0
  219. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js.map +1 -0
  220. package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +34 -0
  221. package/dist/src/core/shaders/templates/ShadowTemplate.js +50 -0
  222. package/dist/src/core/shaders/templates/ShadowTemplate.js.map +1 -0
  223. package/dist/src/core/shaders/utils.d.ts +5 -0
  224. package/dist/src/core/shaders/utils.js +25 -0
  225. package/dist/src/core/shaders/utils.js.map +1 -0
  226. package/dist/src/core/shaders/webgl/Border.d.ts +3 -0
  227. package/dist/src/core/shaders/webgl/Border.js +153 -0
  228. package/dist/src/core/shaders/webgl/Border.js.map +1 -0
  229. package/dist/src/core/shaders/webgl/Default.d.ts +2 -0
  230. package/dist/src/core/shaders/webgl/Default.js +51 -0
  231. package/dist/src/core/shaders/webgl/Default.js.map +1 -0
  232. package/dist/src/core/shaders/webgl/HolePunch.d.ts +3 -0
  233. package/dist/src/core/shaders/webgl/HolePunch.js +49 -0
  234. package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -0
  235. package/dist/src/core/shaders/webgl/LinearGradient.d.ts +3 -0
  236. package/dist/src/core/shaders/webgl/LinearGradient.js +114 -0
  237. package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -0
  238. package/dist/src/core/shaders/webgl/RadialGradient.d.ts +3 -0
  239. package/dist/src/core/shaders/webgl/RadialGradient.js +81 -0
  240. package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -0
  241. package/dist/src/core/shaders/webgl/Rounded.d.ts +7 -0
  242. package/dist/src/core/shaders/webgl/Rounded.js +88 -0
  243. package/dist/src/core/shaders/webgl/Rounded.js.map +1 -0
  244. package/dist/src/core/shaders/webgl/RoundedWithBorder.d.ts +3 -0
  245. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +202 -0
  246. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -0
  247. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.d.ts +3 -0
  248. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +223 -0
  249. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -0
  250. package/dist/src/core/shaders/webgl/RoundedWithShadow.d.ts +3 -0
  251. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +123 -0
  252. package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -0
  253. package/dist/src/core/shaders/webgl/SdfShader.d.ts +13 -0
  254. package/dist/src/core/shaders/webgl/SdfShader.js +72 -0
  255. package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -0
  256. package/dist/src/core/shaders/webgl/Shadow.d.ts +3 -0
  257. package/dist/src/core/shaders/webgl/Shadow.js +115 -0
  258. package/dist/src/core/shaders/webgl/Shadow.js.map +1 -0
  259. package/dist/src/core/text-rendering/CanvasFontHandler.d.ts +59 -0
  260. package/dist/src/core/text-rendering/CanvasFontHandler.js +206 -0
  261. package/dist/src/core/text-rendering/CanvasFontHandler.js.map +1 -0
  262. package/dist/src/core/text-rendering/CanvasTextRenderer.d.ts +17 -0
  263. package/dist/src/core/text-rendering/CanvasTextRenderer.js +139 -0
  264. package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -0
  265. package/dist/src/core/text-rendering/SdfFontHandler.d.ts +167 -0
  266. package/dist/src/core/text-rendering/SdfFontHandler.js +371 -0
  267. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -0
  268. package/dist/src/core/text-rendering/SdfTextRenderer.d.ts +17 -0
  269. package/dist/src/core/text-rendering/SdfTextRenderer.js +249 -0
  270. package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -0
  271. package/dist/src/core/text-rendering/TextLayoutEngine.d.ts +18 -0
  272. package/dist/src/core/text-rendering/TextLayoutEngine.js +380 -0
  273. package/dist/src/core/text-rendering/TextLayoutEngine.js.map +1 -0
  274. package/dist/src/core/text-rendering/TextRenderer.d.ts +406 -0
  275. package/dist/src/core/text-rendering/TextRenderer.js +2 -0
  276. package/dist/src/core/text-rendering/TextRenderer.js.map +1 -0
  277. package/dist/src/core/text-rendering/Utils.d.ts +30 -0
  278. package/dist/src/core/text-rendering/Utils.js +66 -0
  279. package/dist/src/core/text-rendering/Utils.js.map +1 -0
  280. package/dist/src/core/textures/ColorTexture.d.ts +36 -0
  281. package/dist/src/core/textures/ColorTexture.js +57 -0
  282. package/dist/src/core/textures/ColorTexture.js.map +1 -0
  283. package/dist/src/core/textures/ImageTexture.d.ts +131 -0
  284. package/dist/src/core/textures/ImageTexture.js +211 -0
  285. package/dist/src/core/textures/ImageTexture.js.map +1 -0
  286. package/dist/src/core/textures/NoiseTexture.d.ts +43 -0
  287. package/dist/src/core/textures/NoiseTexture.js +50 -0
  288. package/dist/src/core/textures/NoiseTexture.js.map +1 -0
  289. package/dist/src/core/textures/RenderTexture.d.ts +29 -0
  290. package/dist/src/core/textures/RenderTexture.js +36 -0
  291. package/dist/src/core/textures/RenderTexture.js.map +1 -0
  292. package/dist/src/core/textures/SubTexture.d.ts +61 -0
  293. package/dist/src/core/textures/SubTexture.js +99 -0
  294. package/dist/src/core/textures/SubTexture.js.map +1 -0
  295. package/dist/src/core/textures/Texture.d.ts +275 -0
  296. package/dist/src/core/textures/Texture.js +326 -0
  297. package/dist/src/core/textures/Texture.js.map +1 -0
  298. package/dist/src/core/utils.d.ts +23 -0
  299. package/dist/src/core/utils.js +155 -0
  300. package/dist/src/core/utils.js.map +1 -0
  301. package/dist/src/main-api/INode.d.ts +65 -0
  302. package/dist/src/main-api/INode.js +2 -0
  303. package/dist/src/main-api/INode.js.map +1 -0
  304. package/dist/src/main-api/Inspector.d.ts +154 -0
  305. package/dist/src/main-api/Inspector.js +844 -0
  306. package/dist/src/main-api/Inspector.js.map +1 -0
  307. package/dist/src/main-api/Renderer.d.ts +629 -0
  308. package/dist/src/main-api/Renderer.js +471 -0
  309. package/dist/src/main-api/Renderer.js.map +1 -0
  310. package/dist/src/main-api/utils.d.ts +2 -0
  311. package/dist/src/main-api/utils.js +34 -0
  312. package/dist/src/main-api/utils.js.map +1 -0
  313. package/dist/src/utils.d.ts +123 -0
  314. package/dist/src/utils.js +234 -0
  315. package/dist/src/utils.js.map +1 -0
  316. package/dist/tsconfig.dist.tsbuildinfo +1 -0
  317. package/exports/canvas-shaders.ts +11 -0
  318. package/exports/canvas.ts +27 -0
  319. package/exports/index.ts +69 -0
  320. package/exports/inspector.ts +5 -0
  321. package/exports/utils.ts +32 -0
  322. package/exports/webgl-shaders.ts +12 -0
  323. package/exports/webgl.ts +33 -0
  324. package/package.json +99 -0
  325. package/src/common/CommonTypes.ts +145 -0
  326. package/src/common/EventEmitter.ts +58 -0
  327. package/src/common/IAnimationController.ts +65 -0
  328. package/src/common/IEventEmitter.ts +11 -0
  329. package/src/core/Autosizer.ts +205 -0
  330. package/src/core/CoreNode.test.ts +535 -0
  331. package/src/core/CoreNode.ts +2883 -0
  332. package/src/core/CoreShaderManager.ts +170 -0
  333. package/src/core/CoreTextNode.ts +573 -0
  334. package/src/core/CoreTextureManager.ts +552 -0
  335. package/src/core/Stage.ts +1037 -0
  336. package/src/core/TextureError.ts +46 -0
  337. package/src/core/TextureMemoryManager.ts +378 -0
  338. package/src/core/animations/AnimationManager.ts +178 -0
  339. package/src/core/animations/CoreAnimation.ts +138 -0
  340. package/src/core/lib/ContextSpy.ts +22 -0
  341. package/src/core/lib/ImageWorker.ts +292 -0
  342. package/src/core/lib/Matrix3d.ts +231 -0
  343. package/src/core/lib/RenderCoords.ts +55 -0
  344. package/src/core/lib/WebGlContextWrapper.ts +1448 -0
  345. package/src/core/lib/collectionUtils.ts +99 -0
  346. package/src/core/lib/colorCache.ts +20 -0
  347. package/src/core/lib/colorParser.ts +66 -0
  348. package/src/core/lib/textureCompression.ts +492 -0
  349. package/src/core/lib/textureSvg.ts +59 -0
  350. package/src/core/lib/utils.ts +400 -0
  351. package/src/core/lib/validateImageBitmap.ts +87 -0
  352. package/src/core/platforms/Platform.ts +64 -0
  353. package/src/core/platforms/web/WebPlatform.ts +132 -0
  354. package/src/core/renderers/CoreContextTexture.ts +25 -0
  355. package/src/core/renderers/CoreRenderOp.ts +3 -0
  356. package/src/core/renderers/CoreRenderer.ts +101 -0
  357. package/src/core/renderers/CoreShaderNode.ts +202 -0
  358. package/src/core/renderers/CoreShaderProgram.ts +4 -0
  359. package/src/core/renderers/canvas/CanvasRenderer.ts +274 -0
  360. package/src/core/renderers/canvas/CanvasShaderNode.ts +79 -0
  361. package/src/core/renderers/canvas/CanvasTexture.ts +141 -0
  362. package/src/core/renderers/webgl/SdfRenderOp.ts +103 -0
  363. package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +70 -0
  364. package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +76 -0
  365. package/src/core/renderers/webgl/WebGlCtxTexture.ts +332 -0
  366. package/src/core/renderers/webgl/WebGlRenderer.ts +1323 -0
  367. package/src/core/renderers/webgl/WebGlShaderNode.ts +423 -0
  368. package/src/core/renderers/webgl/WebGlShaderProgram.ts +346 -0
  369. package/src/core/renderers/webgl/internal/BufferCollection.ts +46 -0
  370. package/src/core/renderers/webgl/internal/RendererUtils.ts +136 -0
  371. package/src/core/renderers/webgl/internal/ShaderUtils.ts +262 -0
  372. package/src/core/renderers/webgl/internal/WebGlUtils.ts +16 -0
  373. package/src/core/shaders/canvas/Border.ts +119 -0
  374. package/src/core/shaders/canvas/HolePunch.ts +38 -0
  375. package/src/core/shaders/canvas/LinearGradient.ts +54 -0
  376. package/src/core/shaders/canvas/RadialGradient.ts +82 -0
  377. package/src/core/shaders/canvas/Rounded.ts +38 -0
  378. package/src/core/shaders/canvas/RoundedWithBorder.ts +105 -0
  379. package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +118 -0
  380. package/src/core/shaders/canvas/RoundedWithShadow.ts +56 -0
  381. package/src/core/shaders/canvas/Shadow.ts +35 -0
  382. package/src/core/shaders/canvas/utils/render.ts +143 -0
  383. package/src/core/shaders/templates/BorderTemplate.ts +128 -0
  384. package/src/core/shaders/templates/HolePunchTemplate.ts +65 -0
  385. package/src/core/shaders/templates/LinearGradientTemplate.ts +54 -0
  386. package/src/core/shaders/templates/RadialGradientTemplate.ts +66 -0
  387. package/src/core/shaders/templates/RoundedTemplate.ts +81 -0
  388. package/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.ts +21 -0
  389. package/src/core/shaders/templates/RoundedWithBorderTemplate.ts +23 -0
  390. package/src/core/shaders/templates/RoundedWithShadowTemplate.ts +18 -0
  391. package/src/core/shaders/templates/ShadowTemplate.ts +89 -0
  392. package/src/core/shaders/utils.ts +30 -0
  393. package/src/core/shaders/webgl/Border.ts +158 -0
  394. package/src/core/shaders/webgl/Default.ts +52 -0
  395. package/src/core/shaders/webgl/HolePunch.ts +58 -0
  396. package/src/core/shaders/webgl/LinearGradient.ts +119 -0
  397. package/src/core/shaders/webgl/RadialGradient.ts +91 -0
  398. package/src/core/shaders/webgl/Rounded.ts +97 -0
  399. package/src/core/shaders/webgl/RoundedWithBorder.ts +212 -0
  400. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +235 -0
  401. package/src/core/shaders/webgl/RoundedWithShadow.ts +132 -0
  402. package/src/core/shaders/webgl/SdfShader.ts +73 -0
  403. package/src/core/shaders/webgl/Shadow.ts +119 -0
  404. package/src/core/text-rendering/CanvasFontHandler.ts +285 -0
  405. package/src/core/text-rendering/CanvasTextRenderer.ts +236 -0
  406. package/src/core/text-rendering/SdfFontHandler.ts +566 -0
  407. package/src/core/text-rendering/SdfTextRenderer.ts +352 -0
  408. package/src/core/text-rendering/TextLayoutEngine.ts +672 -0
  409. package/src/core/text-rendering/TextRenderer.ts +449 -0
  410. package/src/core/text-rendering/Utils.ts +80 -0
  411. package/src/core/text-rendering/tests/TextLayoutEngine.test.ts +434 -0
  412. package/src/core/textures/ColorTexture.ts +85 -0
  413. package/src/core/textures/ImageTexture.ts +394 -0
  414. package/src/core/textures/NoiseTexture.ts +87 -0
  415. package/src/core/textures/RenderTexture.ts +68 -0
  416. package/src/core/textures/SubTexture.ts +165 -0
  417. package/src/core/textures/Texture.ts +505 -0
  418. package/src/core/utils.ts +210 -0
  419. package/src/env.d.ts +7 -0
  420. package/src/main-api/INode.ts +92 -0
  421. package/src/main-api/Inspector.ts +1267 -0
  422. package/src/main-api/Renderer.ts +1011 -0
  423. package/src/main-api/utils.ts +45 -0
  424. package/src/utils.ts +302 -0
@@ -0,0 +1,1143 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
+ import { assertTruthy, isProductionEnvironment } from '../../utils.js';
5
+ import { isWebGl2 } from '../renderers/webgl/internal/WebGlUtils.js';
6
+ /**
7
+ * Optimized WebGL Context Wrapper
8
+ *
9
+ * @remarks
10
+ * This class contains the subset of the WebGLRenderingContext & WebGL2RenderingContext
11
+ * API that is used by the renderer. Select high volume WebGL methods include
12
+ * caching optimizations to avoid making WebGL calls if the state is already set
13
+ * to the desired value.
14
+ *
15
+ * While most methods contained are direct passthroughs to the WebGL context,
16
+ * some methods combine multiple WebGL calls into one for convenience, modify
17
+ * arguments to be more convenient, or are replaced by more specific methods.
18
+ *
19
+ * Not all methods are optimized. Only methods that are called frequently
20
+ * and/or have a high cost are optimized.
21
+ *
22
+ * A subset of GLenum constants are also exposed as properties on this class
23
+ * for convenience.
24
+ */
25
+ export class WebGlContextWrapper {
26
+ gl;
27
+ //#region Cached WebGL State
28
+ activeTextureUnit = 0;
29
+ texture2dUnits;
30
+ texture2dParams = new WeakMap();
31
+ scissorEnabled;
32
+ scissorX;
33
+ scissorY;
34
+ scissorWidth;
35
+ scissorHeight;
36
+ blendEnabled;
37
+ blendSrcRgb;
38
+ blendDstRgb;
39
+ blendSrcAlpha;
40
+ blendDstAlpha;
41
+ boundArrayBuffer;
42
+ boundElementArrayBuffer;
43
+ curProgram;
44
+ curUniformLocations = {};
45
+ //#endregion Cached WebGL State
46
+ //#region Canvas
47
+ canvas;
48
+ //#endregion Canvas
49
+ //#region WebGL Enums
50
+ MAX_RENDERBUFFER_SIZE;
51
+ MAX_TEXTURE_SIZE;
52
+ MAX_VIEWPORT_DIMS;
53
+ MAX_VERTEX_TEXTURE_IMAGE_UNITS;
54
+ MAX_TEXTURE_IMAGE_UNITS;
55
+ MAX_COMBINED_TEXTURE_IMAGE_UNITS;
56
+ MAX_VERTEX_ATTRIBS;
57
+ MAX_VARYING_VECTORS;
58
+ MAX_VERTEX_UNIFORM_VECTORS;
59
+ MAX_FRAGMENT_UNIFORM_VECTORS;
60
+ TEXTURE_MAG_FILTER;
61
+ TEXTURE_MIN_FILTER;
62
+ TEXTURE_WRAP_S;
63
+ TEXTURE_WRAP_T;
64
+ LINEAR;
65
+ LINEAR_MIPMAP_LINEAR;
66
+ CLAMP_TO_EDGE;
67
+ RGB;
68
+ RGBA;
69
+ UNSIGNED_BYTE;
70
+ UNPACK_PREMULTIPLY_ALPHA_WEBGL;
71
+ UNPACK_FLIP_Y_WEBGL;
72
+ FLOAT;
73
+ TRIANGLES;
74
+ UNSIGNED_SHORT;
75
+ ONE;
76
+ ONE_MINUS_SRC_ALPHA;
77
+ VERTEX_SHADER;
78
+ FRAGMENT_SHADER;
79
+ STATIC_DRAW;
80
+ COMPILE_STATUS;
81
+ LINK_STATUS;
82
+ DYNAMIC_DRAW;
83
+ COLOR_ATTACHMENT0;
84
+ INVALID_ENUM;
85
+ INVALID_OPERATION;
86
+ //#endregion WebGL Enums
87
+ constructor(gl) {
88
+ this.gl = gl;
89
+ // The following code extracts the current state of the WebGL context
90
+ // to our local JavaScript cached version of it. This is so we can
91
+ // avoid making WebGL calls if we don't need to.
92
+ // We could assume that the WebGL context is in a default state, but
93
+ // in the future we may want to support restoring a broken WebGL context
94
+ // and this will help with that.
95
+ this.activeTextureUnit =
96
+ gl.getParameter(gl.ACTIVE_TEXTURE) - gl.TEXTURE0;
97
+ const maxTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
98
+ // save current texture units
99
+ this.texture2dUnits = new Array(maxTextureUnits)
100
+ .fill(undefined)
101
+ .map((_, i) => {
102
+ this.activeTexture(i);
103
+ return gl.getParameter(gl.TEXTURE_BINDING_2D);
104
+ });
105
+ // restore active texture unit
106
+ this.activeTexture(this.activeTextureUnit);
107
+ this.scissorEnabled = gl.isEnabled(gl.SCISSOR_TEST);
108
+ const scissorBox = gl.getParameter(gl.SCISSOR_BOX);
109
+ this.scissorX = scissorBox[0];
110
+ this.scissorY = scissorBox[1];
111
+ this.scissorWidth = scissorBox[2];
112
+ this.scissorHeight = scissorBox[3];
113
+ this.blendEnabled = gl.isEnabled(gl.BLEND);
114
+ this.blendSrcRgb = gl.getParameter(gl.BLEND_SRC_RGB);
115
+ this.blendDstRgb = gl.getParameter(gl.BLEND_DST_RGB);
116
+ this.blendSrcAlpha = gl.getParameter(gl.BLEND_SRC_ALPHA);
117
+ this.blendDstAlpha = gl.getParameter(gl.BLEND_DST_ALPHA);
118
+ this.boundArrayBuffer = gl.getParameter(gl.ARRAY_BUFFER_BINDING);
119
+ this.boundElementArrayBuffer = gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING);
120
+ this.curProgram = gl.getParameter(gl.CURRENT_PROGRAM);
121
+ this.canvas = gl.canvas;
122
+ // Extract GLenums
123
+ this.MAX_RENDERBUFFER_SIZE = gl.MAX_RENDERBUFFER_SIZE;
124
+ this.MAX_TEXTURE_SIZE = gl.MAX_TEXTURE_SIZE;
125
+ this.MAX_VIEWPORT_DIMS = gl.MAX_VIEWPORT_DIMS;
126
+ this.MAX_VERTEX_TEXTURE_IMAGE_UNITS = gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS;
127
+ this.MAX_TEXTURE_IMAGE_UNITS = gl.MAX_TEXTURE_IMAGE_UNITS;
128
+ this.MAX_COMBINED_TEXTURE_IMAGE_UNITS = gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS;
129
+ this.MAX_VERTEX_ATTRIBS = gl.MAX_VERTEX_ATTRIBS;
130
+ this.MAX_VARYING_VECTORS = gl.MAX_VARYING_VECTORS;
131
+ this.MAX_VERTEX_UNIFORM_VECTORS = gl.MAX_VERTEX_UNIFORM_VECTORS;
132
+ this.MAX_FRAGMENT_UNIFORM_VECTORS = gl.MAX_FRAGMENT_UNIFORM_VECTORS;
133
+ this.TEXTURE_MAG_FILTER = gl.TEXTURE_MAG_FILTER;
134
+ this.TEXTURE_MIN_FILTER = gl.TEXTURE_MIN_FILTER;
135
+ this.TEXTURE_WRAP_S = gl.TEXTURE_WRAP_S;
136
+ this.TEXTURE_WRAP_T = gl.TEXTURE_WRAP_T;
137
+ this.LINEAR = gl.LINEAR;
138
+ this.LINEAR_MIPMAP_LINEAR = gl.LINEAR_MIPMAP_LINEAR;
139
+ this.CLAMP_TO_EDGE = gl.CLAMP_TO_EDGE;
140
+ this.RGB = gl.RGB;
141
+ this.RGBA = gl.RGBA;
142
+ this.UNSIGNED_BYTE = gl.UNSIGNED_BYTE;
143
+ this.UNPACK_PREMULTIPLY_ALPHA_WEBGL = gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL;
144
+ this.UNPACK_FLIP_Y_WEBGL = gl.UNPACK_FLIP_Y_WEBGL;
145
+ this.FLOAT = gl.FLOAT;
146
+ this.TRIANGLES = gl.TRIANGLES;
147
+ this.UNSIGNED_SHORT = gl.UNSIGNED_SHORT;
148
+ this.ONE = gl.ONE;
149
+ this.ONE_MINUS_SRC_ALPHA = gl.ONE_MINUS_SRC_ALPHA;
150
+ this.MAX_VERTEX_TEXTURE_IMAGE_UNITS = gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS;
151
+ this.TRIANGLES = gl.TRIANGLES;
152
+ this.UNSIGNED_SHORT = gl.UNSIGNED_SHORT;
153
+ this.VERTEX_SHADER = gl.VERTEX_SHADER;
154
+ this.FRAGMENT_SHADER = gl.FRAGMENT_SHADER;
155
+ this.STATIC_DRAW = gl.STATIC_DRAW;
156
+ this.COMPILE_STATUS = gl.COMPILE_STATUS;
157
+ this.LINK_STATUS = gl.LINK_STATUS;
158
+ this.DYNAMIC_DRAW = gl.DYNAMIC_DRAW;
159
+ this.COLOR_ATTACHMENT0 = gl.COLOR_ATTACHMENT0;
160
+ this.INVALID_ENUM = gl.INVALID_ENUM;
161
+ this.INVALID_OPERATION = gl.INVALID_OPERATION;
162
+ }
163
+ /**
164
+ * Returns true if the WebGL context is WebGL2
165
+ *
166
+ * @returns
167
+ */
168
+ isWebGl2() {
169
+ return isWebGl2(this.gl);
170
+ }
171
+ /**
172
+ * ```
173
+ * gl.activeTexture(textureUnit + gl.TEXTURE0);
174
+ * ```
175
+ *
176
+ * @remarks
177
+ * **WebGL Difference**: `textureUnit` is based from 0, not `gl.TEXTURE0`.
178
+ *
179
+ * @param textureUnit
180
+ */
181
+ activeTexture(textureUnit) {
182
+ if (this.activeTextureUnit !== textureUnit) {
183
+ this.gl.activeTexture(textureUnit + this.gl.TEXTURE0);
184
+ this.activeTextureUnit = textureUnit;
185
+ }
186
+ }
187
+ /**
188
+ * ```
189
+ * gl.bindTexture(gl.TEXTURE_2D, texture);
190
+ * ```
191
+ * @remarks
192
+ * **WebGL Difference**: Bind target is always `gl.TEXTURE_2D`
193
+ *
194
+ * @param texture
195
+ */
196
+ bindTexture(texture) {
197
+ if (this.texture2dUnits[this.activeTextureUnit] === texture) {
198
+ return;
199
+ }
200
+ this.texture2dUnits[this.activeTextureUnit] = texture;
201
+ this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
202
+ }
203
+ _getActiveTexture() {
204
+ return this.texture2dUnits[this.activeTextureUnit];
205
+ }
206
+ /**
207
+ * ```
208
+ * gl.texParameteri(gl.TEXTURE_2D, pname, param);
209
+ * ```
210
+ * @remarks
211
+ * **WebGL Difference**: Bind target is always `gl.TEXTURE_2D`
212
+ *
213
+ * @param pname
214
+ * @param param
215
+ * @returns
216
+ */
217
+ texParameteri(pname, param) {
218
+ const activeTexture = this._getActiveTexture();
219
+ if (!activeTexture) {
220
+ throw new Error('No active texture');
221
+ }
222
+ let textureParams = this.texture2dParams.get(activeTexture);
223
+ if (!textureParams) {
224
+ textureParams = {};
225
+ this.texture2dParams.set(activeTexture, textureParams);
226
+ }
227
+ if (textureParams[pname] === param) {
228
+ return;
229
+ }
230
+ textureParams[pname] = param;
231
+ this.gl.texParameteri(this.gl.TEXTURE_2D, pname, param);
232
+ }
233
+ texImage2D(level, internalFormat, widthOrFormat, heightOrType, borderOrSource, format, type, pixels) {
234
+ if (format) {
235
+ this.gl.texImage2D(this.gl.TEXTURE_2D, level, internalFormat, widthOrFormat, heightOrType, borderOrSource, format, type, pixels);
236
+ }
237
+ else {
238
+ this.gl.texImage2D(this.gl.TEXTURE_2D, level, internalFormat, widthOrFormat, heightOrType, borderOrSource);
239
+ }
240
+ }
241
+ /**
242
+ * ```
243
+ * gl.compressedTexImage2D(gl.TEXTURE_2D, level, internalFormat, width, height, border, data);
244
+ * ```
245
+ *
246
+ * @remarks
247
+ * **WebGL Difference**: Bind target is always `gl.TEXTURE_2D`
248
+ */
249
+ compressedTexImage2D(level, internalformat, width, height, border, data) {
250
+ this.gl.compressedTexImage2D(this.gl.TEXTURE_2D, level, internalformat, width, height, border, data);
251
+ }
252
+ /**
253
+ * ```
254
+ * gl.pixelStorei(pname, param);
255
+ * ```
256
+ *
257
+ * @param pname
258
+ * @param param
259
+ */
260
+ pixelStorei(pname, param) {
261
+ this.gl.pixelStorei(pname, param);
262
+ }
263
+ /**
264
+ * ```
265
+ * gl.generateMipmap(gl.TEXTURE_2D);
266
+ * ```
267
+ *
268
+ * @remarks
269
+ * **WebGL Difference**: Bind target is always `gl.TEXTURE_2D`
270
+ */
271
+ generateMipmap() {
272
+ this.gl.generateMipmap(this.gl.TEXTURE_2D);
273
+ }
274
+ /**
275
+ * ```
276
+ * gl.createTexture();
277
+ * ```
278
+ *
279
+ * @returns
280
+ */
281
+ createTexture() {
282
+ return this.gl.createTexture();
283
+ }
284
+ /**
285
+ * ```
286
+ * gl.deleteTexture(texture);
287
+ * ```
288
+ *
289
+ * @param texture
290
+ */
291
+ deleteTexture(texture) {
292
+ if (texture) {
293
+ this.texture2dParams.delete(texture);
294
+ }
295
+ this.gl.deleteTexture(texture);
296
+ }
297
+ /**
298
+ * ```
299
+ * gl.deleteFramebuffer(framebuffer);
300
+ *
301
+ * @param framebuffer
302
+ */
303
+ deleteFramebuffer(framebuffer) {
304
+ this.gl.deleteFramebuffer(framebuffer);
305
+ }
306
+ /**
307
+ * ```
308
+ * gl.viewport(x, y, width, height);
309
+ * ```
310
+ */
311
+ viewport(x, y, width, height) {
312
+ this.gl.viewport(x, y, width, height);
313
+ }
314
+ /**
315
+ * ```
316
+ * gl.clearColor(red, green, blue, alpha);
317
+ * ```
318
+ *
319
+ * @param red
320
+ * @param green
321
+ * @param blue
322
+ * @param alpha
323
+ */
324
+ clearColor(red, green, blue, alpha) {
325
+ this.gl.clearColor(red, green, blue, alpha);
326
+ }
327
+ /**
328
+ * ```
329
+ * gl["enable"|"disable"](gl.SCISSOR_TEST);
330
+ * ```
331
+ * @param enable
332
+ */
333
+ setScissorTest(enable) {
334
+ if (enable === this.scissorEnabled) {
335
+ return;
336
+ }
337
+ if (enable) {
338
+ this.gl.enable(this.gl.SCISSOR_TEST);
339
+ }
340
+ else {
341
+ this.gl.disable(this.gl.SCISSOR_TEST);
342
+ }
343
+ this.scissorEnabled = enable;
344
+ }
345
+ /**
346
+ * ```
347
+ * gl.scissor(x, y, width, height);
348
+ * ```
349
+ *
350
+ * @param x
351
+ * @param y
352
+ * @param width
353
+ * @param height
354
+ */
355
+ scissor(x, y, width, height) {
356
+ if (x !== this.scissorX ||
357
+ y !== this.scissorY ||
358
+ width !== this.scissorWidth ||
359
+ height !== this.scissorHeight) {
360
+ this.gl.scissor(x, y, width, height);
361
+ this.scissorX = x;
362
+ this.scissorY = y;
363
+ this.scissorWidth = width;
364
+ this.scissorHeight = height;
365
+ }
366
+ }
367
+ /**
368
+ * ```
369
+ * gl["enable"|"disable"](gl.BLEND);
370
+ * ```
371
+ *
372
+ * @param blend
373
+ * @returns
374
+ */
375
+ setBlend(blend) {
376
+ if (blend === this.blendEnabled) {
377
+ return;
378
+ }
379
+ if (blend) {
380
+ this.gl.enable(this.gl.BLEND);
381
+ }
382
+ else {
383
+ this.gl.disable(this.gl.BLEND);
384
+ }
385
+ this.blendEnabled = blend;
386
+ }
387
+ /**
388
+ * ```
389
+ * gl.blendFunc(src, dst);
390
+ * ```
391
+ *
392
+ * @param src
393
+ * @param dst
394
+ */
395
+ blendFunc(src, dst) {
396
+ if (src !== this.blendSrcRgb ||
397
+ dst !== this.blendDstRgb ||
398
+ src !== this.blendSrcAlpha ||
399
+ dst !== this.blendDstAlpha) {
400
+ this.gl.blendFunc(src, dst);
401
+ this.blendSrcRgb = src;
402
+ this.blendDstRgb = dst;
403
+ this.blendSrcAlpha = src;
404
+ this.blendDstAlpha = dst;
405
+ }
406
+ }
407
+ /**
408
+ * ```
409
+ * gl.createBuffer();
410
+ * ```
411
+ *
412
+ * @returns
413
+ */
414
+ createBuffer() {
415
+ return this.gl.createBuffer();
416
+ }
417
+ /**
418
+ * ```
419
+ * gl.createFramebuffer();
420
+ * ```
421
+ * @returns
422
+ */
423
+ createFramebuffer() {
424
+ return this.gl.createFramebuffer();
425
+ }
426
+ /**
427
+ * ```
428
+ * gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
429
+ * ```
430
+ *
431
+ * @param framebuffer
432
+ */
433
+ bindFramebuffer(framebuffer) {
434
+ this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, framebuffer);
435
+ }
436
+ /**
437
+ * ```
438
+ * gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
439
+ * ```
440
+ * @remarks
441
+ * **WebGL Difference**: Bind target is always `gl.FRAMEBUFFER` and textarget is always `gl.TEXTURE_2D`
442
+ */
443
+ framebufferTexture2D(attachment, texture, level) {
444
+ const gl = this.gl;
445
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, texture, level);
446
+ }
447
+ /**
448
+ * ```
449
+ * gl.clear(gl.COLOR_BUFFER_BIT);
450
+ * ```
451
+ *
452
+ * @remarks
453
+ * **WebGL Difference**: Clear mask is always `gl.COLOR_BUFFER_BIT`
454
+ */
455
+ clear() {
456
+ this.gl.clear(this.gl.COLOR_BUFFER_BIT);
457
+ }
458
+ /**
459
+ * ```
460
+ * gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
461
+ * gl.bufferData(gl.ARRAY_BUFFER, data, usage);
462
+ * ```
463
+ *
464
+ * @remarks
465
+ * **WebGL Combo**: `gl.bindBuffer` and `gl.bufferData` are combined into one function.
466
+ *
467
+ * @param buffer
468
+ * @param data
469
+ * @param usage
470
+ */
471
+ arrayBufferData(buffer, data, usage) {
472
+ if (this.boundArrayBuffer !== buffer) {
473
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
474
+ this.boundArrayBuffer = buffer;
475
+ }
476
+ this.gl.bufferData(this.gl.ARRAY_BUFFER, data, usage);
477
+ }
478
+ /**
479
+ * ```
480
+ * gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // if needed
481
+ * gl.bufferSubData(gl.ARRAY_BUFFER, dstByteOffset, data);
482
+ * ```
483
+ *
484
+ * @remarks
485
+ * **WebGL Combo**: `gl.bindBuffer` is only called when the buffer changes.
486
+ * Used to surgically update a subset of the GPU buffer without reallocating it.
487
+ *
488
+ * @param buffer
489
+ * @param dstByteOffset - Byte offset into the GPU buffer where `data` will be written
490
+ * @param data
491
+ */
492
+ arrayBufferSubData(buffer, dstByteOffset, data) {
493
+ if (this.boundArrayBuffer !== buffer) {
494
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
495
+ this.boundArrayBuffer = buffer;
496
+ }
497
+ this.gl.bufferSubData(this.gl.ARRAY_BUFFER, dstByteOffset, data);
498
+ }
499
+ /**
500
+ * ```
501
+ * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
502
+ * gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, usage);
503
+ * ```
504
+ * @remarks
505
+ * **WebGL Combo**: `gl.bindBuffer` and `gl.bufferData` are combined into one function.
506
+ *
507
+ * @param buffer
508
+ * @param data
509
+ * @param usage
510
+ */
511
+ elementArrayBufferData(buffer, data, usage) {
512
+ if (this.boundElementArrayBuffer !== buffer) {
513
+ this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, buffer);
514
+ this.boundElementArrayBuffer = buffer;
515
+ }
516
+ this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, data, usage);
517
+ }
518
+ /**
519
+ * ```
520
+ * gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
521
+ * gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
522
+ * ```
523
+ *
524
+ * @remarks
525
+ * **WebGL Combo**: `gl.bindBuffer` and `gl.vertexAttribPointer` are combined into one function.
526
+ *
527
+ * @param buffer
528
+ * @param index
529
+ * @param size
530
+ * @param type
531
+ * @param normalized
532
+ * @param stride
533
+ * @param offset
534
+ */
535
+ vertexAttribPointer(buffer, index, size, type, normalized, stride, offset) {
536
+ if (this.boundArrayBuffer !== buffer) {
537
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
538
+ this.boundArrayBuffer = buffer;
539
+ }
540
+ this.gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
541
+ }
542
+ /**
543
+ * Returns object with Attribute names as key and numbers as location values
544
+ *
545
+ * @param program
546
+ * @returns object with numbers
547
+ */
548
+ getUniformLocations(program) {
549
+ const gl = this.gl;
550
+ const length = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
551
+ const result = {};
552
+ for (let i = 0; i < length; i++) {
553
+ const info = gl.getActiveUniform(program, i);
554
+ //remove bracket + value from uniform name;
555
+ let name = info.name.replace(/\[.*?\]/g, '');
556
+ result[name] = gl.getUniformLocation(program, name);
557
+ }
558
+ return result;
559
+ }
560
+ /**
561
+ * Returns object with Attribute names as key and numbers as location values
562
+ * @param program
563
+ * @returns object with numbers
564
+ */
565
+ getAttributeLocations(program) {
566
+ const gl = this.gl;
567
+ const length = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
568
+ const result = [];
569
+ for (let i = 0; i < length; i++) {
570
+ const { name } = gl.getActiveAttrib(program, i);
571
+ result[gl.getAttribLocation(program, name)] = name;
572
+ }
573
+ return result;
574
+ }
575
+ /**
576
+ * ```
577
+ * gl.useProgram(program);
578
+ * ```
579
+ *
580
+ * @param program
581
+ * @returns
582
+ */
583
+ useProgram(program, uniformLocations) {
584
+ if (this.curProgram === program) {
585
+ return;
586
+ }
587
+ this.gl.useProgram(program);
588
+ this.curProgram = program;
589
+ this.curUniformLocations = uniformLocations;
590
+ }
591
+ /**
592
+ * Sets the value of a single float uniform variable.
593
+ *
594
+ * @param location - The location of the uniform variable.
595
+ * @param v0 - The value to set.
596
+ */
597
+ uniform1f(location, v0) {
598
+ this.gl.uniform1f(this.curUniformLocations[location] || null, v0);
599
+ }
600
+ /**
601
+ * Sets the value of a float array uniform variable.
602
+ *
603
+ * @param location - The location of the uniform variable.
604
+ * @param value - The array of values to set.
605
+ */
606
+ uniform1fv(location, value) {
607
+ this.gl.uniform1fv(this.curUniformLocations[location] || null, value);
608
+ }
609
+ /**
610
+ * Sets the value of a single integer uniform variable.
611
+ *
612
+ * @param location - The location of the uniform variable.
613
+ * @param v0 - The value to set.
614
+ */
615
+ uniform1i(location, v0) {
616
+ this.gl.uniform1i(this.curUniformLocations[location] || null, v0);
617
+ }
618
+ /**
619
+ * Sets the value of an integer array uniform variable.
620
+ *
621
+ * @param location - The location of the uniform variable.
622
+ * @param value - The array of values to set.
623
+ */
624
+ uniform1iv(location, value) {
625
+ this.gl.uniform1iv(this.curUniformLocations[location] || null, value);
626
+ }
627
+ /**
628
+ * Sets the value of a vec2 uniform variable.
629
+ *
630
+ * @param location - The location of the uniform variable.
631
+ * @param v0 - The first component of the vector.
632
+ * @param v1 - The second component of the vector.
633
+ */
634
+ uniform2f(location, v0, v1) {
635
+ this.gl.uniform2f(this.curUniformLocations[location] || null, v0, v1);
636
+ }
637
+ /**
638
+ * Sets the value of a vec3 uniform variable.
639
+ *
640
+ * @param location - The location of the uniform variable.
641
+ * @param v - array of 4 numbers.
642
+ */
643
+ uniform2fa(location, value) {
644
+ this.gl.uniform2f(this.curUniformLocations[location] || null, value[0], value[1]);
645
+ }
646
+ /**
647
+ * Sets the value of a vec2 array uniform variable.
648
+ *
649
+ * @param location - The location of the uniform variable.
650
+ * @param value - The array of vec2 values to set.
651
+ */
652
+ uniform2fv(location, value) {
653
+ this.gl.uniform2fv(this.curUniformLocations[location] || null, value);
654
+ }
655
+ /**
656
+ * Sets the value of a ivec2 uniform variable.
657
+ *
658
+ * @param location - The location of the uniform variable.
659
+ * @param v0 - The first component of the vector.
660
+ * @param v1 - The second component of the vector.
661
+ */
662
+ uniform2i(location, v0, v1) {
663
+ this.gl.uniform2i(this.curUniformLocations[location] || null, v0, v1);
664
+ }
665
+ /**
666
+ * Sets the value of an ivec2 array uniform variable.
667
+ *
668
+ * @param location - The location of the uniform variable.
669
+ * @param value - The array of ivec2 values to set.
670
+ */
671
+ uniform2iv(location, value) {
672
+ this.gl.uniform2iv(this.curUniformLocations[location] || null, value);
673
+ }
674
+ /**
675
+ * Sets the value of a vec3 uniform variable.
676
+ *
677
+ * @param location - The location of the uniform variable.
678
+ * @param v0 - The first component of the vector.
679
+ * @param v1 - The second component of the vector.
680
+ * @param v2 - The third component of the vector.
681
+ */
682
+ uniform3f(location, v0, v1, v2) {
683
+ this.gl.uniform3f(this.curUniformLocations[location] || null, v0, v1, v2);
684
+ }
685
+ /**
686
+ * Sets the value of a vec3 uniform variable.
687
+ *
688
+ * @param location - The location of the uniform variable.
689
+ * @param v - array of 4 numbers.
690
+ */
691
+ uniform3fa(location, value) {
692
+ this.gl.uniform3f(this.curUniformLocations[location] || null, value[0], value[1], value[2]);
693
+ }
694
+ /**
695
+ * Sets the value of a vec3 array uniform variable.
696
+ *
697
+ * @param location - The location of the uniform variable.
698
+ * @param value - The array of vec3 values to set.
699
+ */
700
+ uniform3fv(location, value) {
701
+ this.gl.uniform3fv(this.curUniformLocations[location] || null, value);
702
+ }
703
+ /**
704
+ * Sets the value of a ivec3 uniform variable.
705
+ *
706
+ * @param location - The location of the uniform variable.
707
+ * @param v0 - The first component of the vector.
708
+ * @param v1 - The second component of the vector.
709
+ * @param v2 - The third component of the vector.
710
+ */
711
+ uniform3i(location, v0, v1, v2) {
712
+ this.gl.uniform3i(this.curUniformLocations[location] || null, v0, v1, v2);
713
+ }
714
+ /**
715
+ * Sets the value of an ivec3 array uniform variable.
716
+ *
717
+ * @param location - The location of the uniform variable.
718
+ * @param value - The array of ivec3 values to set.
719
+ */
720
+ uniform3iv(location, value) {
721
+ this.gl.uniform3iv(this.curUniformLocations[location] || null, value);
722
+ }
723
+ /**
724
+ * Sets the value of a vec4 uniform variable.
725
+ *
726
+ * @param location - The location of the uniform variable.
727
+ * @param v0 - The first component of the vector.
728
+ * @param v1 - The second component of the vector.
729
+ * @param v2 - The third component of the vector.
730
+ * @param v3 - The fourth component of the vector.
731
+ */
732
+ uniform4f(location, v0, v1, v2, v3) {
733
+ this.gl.uniform4f(this.curUniformLocations[location] || null, v0, v1, v2, v3);
734
+ }
735
+ /**
736
+ * Sets the value of a vec4 uniform variable.
737
+ *
738
+ * @param location - The location of the uniform variable.
739
+ * @param v - array of 4 numbers.
740
+ */
741
+ uniform4fa(location, value) {
742
+ this.gl.uniform4f(this.curUniformLocations[location] || null, value[0], value[1], value[2], value[3]);
743
+ }
744
+ /**
745
+ * Sets the value of a vec4 array uniform variable.
746
+ *
747
+ * @param location - The location of the uniform variable.
748
+ * @param value - The array of vec4 values to set.
749
+ */
750
+ uniform4fv(location, value) {
751
+ this.gl.uniform4fv(this.curUniformLocations[location] || null, value);
752
+ }
753
+ /**
754
+ * Sets the value of a ivec4 uniform variable.
755
+ *
756
+ * @param location - The location of the uniform variable.
757
+ * @param v0 - The first component of the vector.
758
+ * @param v1 - The second component of the vector.
759
+ * @param v2 - The third component of the vector.
760
+ * @param v3 - The fourth component of the vector.
761
+ */
762
+ uniform4i(location, v0, v1, v2, v3) {
763
+ this.gl.uniform4i(this.curUniformLocations[location] || null, v0, v1, v2, v3);
764
+ }
765
+ /**
766
+ * Sets the value of an ivec4 array uniform variable.
767
+ *
768
+ * @param location - The location of the uniform variable.
769
+ * @param value - The array of ivec4 values to set.
770
+ */
771
+ uniform4iv(location, value) {
772
+ this.gl.uniform4iv(this.curUniformLocations[location] || null, value);
773
+ }
774
+ /**
775
+ * Sets the value of a mat2 uniform variable.
776
+ *
777
+ * @param location - The location of the uniform variable.
778
+ * @param transpose - Whether to transpose the matrix.
779
+ * @param value - The array of mat2 values to set.
780
+ */
781
+ uniformMatrix2fv(location, value) {
782
+ this.gl.uniformMatrix2fv(this.curUniformLocations[location] || null, false, value);
783
+ }
784
+ /**
785
+ * Sets the value of a mat2 uniform variable.
786
+ * @param location - The location of the uniform variable.
787
+ * @param value - The array of mat2 values to set.
788
+ */
789
+ uniformMatrix3fv(location, value) {
790
+ this.gl.uniformMatrix3fv(this.curUniformLocations[location] || null, false, value);
791
+ }
792
+ /**
793
+ * Sets the value of a mat4 uniform variable.
794
+ * @param location - The location of the uniform variable.
795
+ * @param value - The array of mat4 values to set.
796
+ */
797
+ uniformMatrix4fv(location, value) {
798
+ this.gl.uniformMatrix4fv(this.curUniformLocations[location] || null, false, value);
799
+ }
800
+ /**
801
+ * ```
802
+ * gl.getParameter(pname);
803
+ * ```
804
+ *
805
+ * @param pname
806
+ * @returns
807
+ */
808
+ getParameter(pname) {
809
+ return this.gl.getParameter(pname);
810
+ }
811
+ /**
812
+ * ```
813
+ * gl.drawElements(mode, count, type, offset);
814
+ * ```
815
+ *
816
+ * @param mode
817
+ * @param count
818
+ * @param type
819
+ * @param offset
820
+ */
821
+ drawElements(mode, count, type, offset) {
822
+ this.gl.drawElements(mode, count, type, offset);
823
+ }
824
+ /**
825
+ * ```
826
+ * gl.drawArrays(mode, first, count);
827
+ * ```
828
+ *
829
+ * @param mode
830
+ * @param first
831
+ * @param count
832
+ */
833
+ drawArrays(mode, first, count) {
834
+ this.gl.drawArrays(mode, first, count);
835
+ }
836
+ /**
837
+ * ```
838
+ * gl.drawArrays(mode, first, count);
839
+ * ```
840
+ *
841
+ * @param name
842
+ * @returns
843
+ */
844
+ getExtension(name) {
845
+ return this.gl.getExtension(name);
846
+ }
847
+ /**
848
+ * ```
849
+ * gl.getError(type);
850
+ * ```
851
+ *
852
+ * @returns
853
+ */
854
+ getError() {
855
+ return this.gl.getError();
856
+ }
857
+ /**
858
+ * ```
859
+ * gl.createVertexArray();
860
+ * ```
861
+ *
862
+ * @returns
863
+ */
864
+ createVertexArray() {
865
+ if (this.gl instanceof WebGL2RenderingContext) {
866
+ return this.gl.createVertexArray();
867
+ }
868
+ return undefined;
869
+ }
870
+ /**
871
+ * ```
872
+ * gl.bindVertexArray(vertexArray);
873
+ * ```
874
+ *
875
+ * @param vertexArray
876
+ */
877
+ bindVertexArray(vertexArray) {
878
+ if (this.gl instanceof WebGL2RenderingContext) {
879
+ this.gl.bindVertexArray(vertexArray);
880
+ }
881
+ }
882
+ /**
883
+ * ```
884
+ * gl.getAttribLocation(program, name);
885
+ * ```
886
+ *
887
+ * @param program
888
+ * @param name
889
+ * @returns
890
+ */
891
+ getAttribLocation(program, name) {
892
+ return this.gl.getAttribLocation(program, name);
893
+ }
894
+ /**
895
+ * ```
896
+ * gl.getUniformLocation(program, name);
897
+ * ```
898
+ *
899
+ * @param program
900
+ * @param name
901
+ * @returns
902
+ */
903
+ getUniformLocation(program, name) {
904
+ return this.gl.getUniformLocation(program, name);
905
+ }
906
+ /**
907
+ * ```
908
+ * gl.enableVertexAttribArray(index);
909
+ * ```
910
+ *
911
+ * @param index
912
+ */
913
+ enableVertexAttribArray(index) {
914
+ this.gl.enableVertexAttribArray(index);
915
+ }
916
+ /**
917
+ * ```
918
+ * gl.disableVertexAttribArray(index);
919
+ * ```
920
+ *
921
+ * @param index
922
+ */
923
+ disableVertexAttribArray(index) {
924
+ this.gl.disableVertexAttribArray(index);
925
+ }
926
+ /**
927
+ * ```
928
+ * gl.createShader(type);
929
+ * ```
930
+ *
931
+ * @param type
932
+ * @returns
933
+ */
934
+ createShader(type) {
935
+ return this.gl.createShader(type);
936
+ }
937
+ /**
938
+ * ```
939
+ * gl.compileShader(shader);
940
+ * ```
941
+ *
942
+ * @param shader
943
+ * @returns
944
+ */
945
+ compileShader(shader) {
946
+ this.gl.compileShader(shader);
947
+ }
948
+ /**
949
+ * ```
950
+ * gl.attachShader(program, shader);
951
+ * ```
952
+ *
953
+ * @param program
954
+ * @param shader
955
+ */
956
+ attachShader(program, shader) {
957
+ this.gl.attachShader(program, shader);
958
+ }
959
+ /**
960
+ * ```
961
+ * gl.linkProgram(program);
962
+ * ```
963
+ *
964
+ * @param program
965
+ */
966
+ linkProgram(program) {
967
+ this.gl.linkProgram(program);
968
+ }
969
+ /**
970
+ * ```
971
+ * gl.deleteProgram(shader);
972
+ * ```
973
+ *
974
+ * @param shader
975
+ */
976
+ deleteProgram(shader) {
977
+ this.gl.deleteProgram(shader);
978
+ }
979
+ /**
980
+ * ```
981
+ * gl.getShaderParameter(shader, pname);
982
+ * ```
983
+ *
984
+ * @param shader
985
+ * @param pname
986
+ */
987
+ getShaderParameter(shader, pname) {
988
+ return this.gl.getShaderParameter(shader, pname);
989
+ }
990
+ /**
991
+ * ```
992
+ * gl.getShaderInfoLog(shader);
993
+ * ```
994
+ *
995
+ * @param shader
996
+ */
997
+ getShaderInfoLog(shader) {
998
+ return this.gl.getShaderInfoLog(shader);
999
+ }
1000
+ /**
1001
+ * ```
1002
+ * gl.createProgram();
1003
+ * ```
1004
+ *
1005
+ * @returns
1006
+ */
1007
+ createProgram() {
1008
+ return this.gl.createProgram();
1009
+ }
1010
+ /**
1011
+ * ```
1012
+ * gl.getProgramParameter(program, pname);
1013
+ * ```
1014
+ *
1015
+ * @param program
1016
+ * @param pname
1017
+ * @returns
1018
+ */
1019
+ getProgramParameter(program, pname) {
1020
+ return this.gl.getProgramParameter(program, pname);
1021
+ }
1022
+ /**
1023
+ * ```
1024
+ * gl.getProgramInfoLog(program);
1025
+ * ```
1026
+ *
1027
+ * @param program
1028
+ * @returns
1029
+ */
1030
+ getProgramInfoLog(program) {
1031
+ return this.gl.getProgramInfoLog(program);
1032
+ }
1033
+ /**
1034
+ * ```
1035
+ * gl.shaderSource(shader, source);
1036
+ * ```
1037
+ *
1038
+ * @param shader
1039
+ * @param source
1040
+ */
1041
+ shaderSource(shader, source) {
1042
+ this.gl.shaderSource(shader, source);
1043
+ }
1044
+ /**
1045
+ * ```
1046
+ * gl.deleteShader(shader);
1047
+ * ```
1048
+ *
1049
+ * @param shader
1050
+ */
1051
+ deleteShader(shader) {
1052
+ this.gl.deleteShader(shader);
1053
+ }
1054
+ /**
1055
+ * ```
1056
+ * gl.deleteBuffer(buffer);
1057
+ * ```
1058
+ *
1059
+ * @param buffer - The buffer to delete
1060
+ */
1061
+ deleteBuffer(buffer) {
1062
+ const { gl } = this;
1063
+ gl.deleteBuffer(buffer);
1064
+ // Reset bound buffers if they match the deleted buffer
1065
+ if (this.boundArrayBuffer === buffer) {
1066
+ this.boundArrayBuffer = null;
1067
+ }
1068
+ }
1069
+ /**
1070
+ * ```
1071
+ * gl.deleteVertexArray(vertexArray);
1072
+ * ```
1073
+ *
1074
+ * @param vertexArray - The vertex array object to delete
1075
+ */
1076
+ deleteVertexArray(vertexArray) {
1077
+ if (this.isWebGl2()) {
1078
+ this.gl.deleteVertexArray(vertexArray);
1079
+ }
1080
+ }
1081
+ /**
1082
+ * Check for WebGL errors and return error information
1083
+ * @param operation Description of the operation for error reporting
1084
+ * @returns Object with error information or null if no error
1085
+ */
1086
+ checkError(operation) {
1087
+ const error = this.getError();
1088
+ if (error !== 0) {
1089
+ // 0 is GL_NO_ERROR
1090
+ let errorName = 'UNKNOWN_ERROR';
1091
+ switch (error) {
1092
+ case this.INVALID_ENUM:
1093
+ errorName = 'INVALID_ENUM';
1094
+ break;
1095
+ case 0x0501: // GL_INVALID_VALUE
1096
+ errorName = 'INVALID_VALUE';
1097
+ break;
1098
+ case this.INVALID_OPERATION:
1099
+ errorName = 'INVALID_OPERATION';
1100
+ break;
1101
+ case 0x0505: // GL_OUT_OF_MEMORY
1102
+ errorName = 'OUT_OF_MEMORY';
1103
+ break;
1104
+ case 0x9242: // GL_CONTEXT_LOST_WEBGL
1105
+ errorName = 'CONTEXT_LOST_WEBGL';
1106
+ break;
1107
+ }
1108
+ const message = `WebGL ${errorName} (0x${error.toString(16)}) during ${operation}`;
1109
+ return { error, errorName, message };
1110
+ }
1111
+ return null;
1112
+ }
1113
+ }
1114
+ /**
1115
+ * Compare two arrays for equality.
1116
+ *
1117
+ * @remarks
1118
+ * This function will not try to compare nested arrays or Float32Arrays and
1119
+ * instead will always return false when they are encountered.
1120
+ *
1121
+ * @param a
1122
+ * @param b
1123
+ * @returns
1124
+ */
1125
+ export function compareArrays(a, b) {
1126
+ if (a.length !== b.length) {
1127
+ return false;
1128
+ }
1129
+ let result = false;
1130
+ for (let i = 0; i < a.length; i++) {
1131
+ if (Array.isArray(a[i]) || a[i] instanceof Float32Array) {
1132
+ result = false;
1133
+ break;
1134
+ }
1135
+ if (a[i] !== b[i]) {
1136
+ result = false;
1137
+ break;
1138
+ }
1139
+ result = true;
1140
+ }
1141
+ return result;
1142
+ }
1143
+ //# sourceMappingURL=WebGlContextWrapper.js.map