@gjsify/webgl 0.4.30 → 0.4.32
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/lib/esm/conformance/context.spec.js +2 -2
- package/lib/esm/context/framebuffer.js +1 -1
- package/lib/esm/context/state.js +1 -1
- package/lib/esm/context/texture-management.js +1 -1
- package/lib/esm/webgl-context-base.js +1 -1
- package/lib/esm/webgl-rendering-context.js +1 -1
- package/lib/types/html-canvas-element.d.ts +1 -1
- package/lib/types/linkable.d.ts +4 -4
- package/lib/types/types/extension.d.ts +8 -1
- package/lib/types/utils.d.ts +2 -2
- package/lib/types/webgl-context-base.d.ts +6 -6
- package/lib/types/webgl2-rendering-context.d.ts +1 -1
- package/package.json +13 -8
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{__name as e}from"../_virtual/_rolldown/runtime.js";import{createGLSetup as t}from"./setup.js";import{beforeEach as n,describe as r,expect as i,it as a,on as o}from"@gjsify/unit";import{WebGLRenderingContext as s}from"@gjsify/webgl";const c=`getContextAttributes.activeTexture.attachShader.bindAttribLocation.bindBuffer.bindFramebuffer.bindRenderbuffer.bindTexture.blendColor.blendEquation.blendEquationSeparate.blendFunc.blendFuncSeparate.bufferData.bufferSubData.checkFramebufferStatus.clear.clearColor.clearDepth.clearStencil.colorMask.compileShader.compressedTexImage2D.compressedTexSubImage2D.copyTexImage2D.copyTexSubImage2D.createBuffer.createFramebuffer.createProgram.createRenderbuffer.createShader.createTexture.cullFace.deleteBuffer.deleteFramebuffer.deleteProgram.deleteRenderbuffer.deleteShader.deleteTexture.depthFunc.depthMask.depthRange.detachShader.disable.disableVertexAttribArray.drawArrays.drawElements.enable.enableVertexAttribArray.finish.flush.framebufferRenderbuffer.framebufferTexture2D.frontFace.generateMipmap.getActiveAttrib.getActiveUniform.getAttachedShaders.getAttribLocation.getParameter.getBufferParameter.getError.getExtension.getFramebufferAttachmentParameter.getProgramParameter.getProgramInfoLog.getRenderbufferParameter.getShaderParameter.getShaderInfoLog.getShaderPrecisionFormat.getShaderSource.getSupportedExtensions.getTexParameter.getUniform.getUniformLocation.getVertexAttrib.getVertexAttribOffset.hint.isBuffer.isContextLost.isEnabled.isFramebuffer.isProgram.isRenderbuffer.isShader.isTexture.lineWidth.linkProgram.pixelStorei.polygonOffset.readPixels.renderbufferStorage.sampleCoverage.scissor.shaderSource.stencilFunc.stencilFuncSeparate.stencilMask.stencilMaskSeparate.stencilOp.stencilOpSeparate.texImage2D.texParameterf.texParameteri.texSubImage2D.uniform1f.uniform1fv.uniform1i.uniform1iv.uniform2f.uniform2fv.uniform2i.uniform2iv.uniform3f.uniform3fv.uniform3i.uniform3iv.uniform4f.uniform4fv.uniform4i.uniform4iv.uniformMatrix2fv.uniformMatrix3fv.uniformMatrix4fv.useProgram.validateProgram.vertexAttrib1f.vertexAttrib1fv.vertexAttrib2f.vertexAttrib2fv.vertexAttrib3f.vertexAttrib3fv.vertexAttrib4f.vertexAttrib4fv.vertexAttribPointer.viewport`.split(`.`),l=[[`DEPTH_BUFFER_BIT`,256],[`STENCIL_BUFFER_BIT`,1024],[`COLOR_BUFFER_BIT`,16384],[`POINTS`,0],[`LINES`,1],[`LINE_LOOP`,2],[`LINE_STRIP`,3],[`TRIANGLES`,4],[`TRIANGLE_STRIP`,5],[`TRIANGLE_FAN`,6],[`ZERO`,0],[`ONE`,1],[`SRC_COLOR`,768],[`SRC_ALPHA`,770],[`FUNC_ADD`,32774],[`ARRAY_BUFFER`,34962],[`ELEMENT_ARRAY_BUFFER`,34963],[`STREAM_DRAW`,35040],[`STATIC_DRAW`,35044],[`DYNAMIC_DRAW`,35048],[`FRAGMENT_SHADER`,35632],[`VERTEX_SHADER`,35633],[`COMPILE_STATUS`,35713],[`LINK_STATUS`,35714],[`VALIDATE_STATUS`,35715],[`FLOAT`,5126],[`FLOAT_VEC2`,35664],[`FLOAT_VEC3`,35665],[`FLOAT_VEC4`,35666],[`FLOAT_MAT2`,35674],[`FLOAT_MAT3`,35675],[`FLOAT_MAT4`,35676],[`INT`,5124],[`TEXTURE_2D`,3553],[`TEXTURE_CUBE_MAP`,34067],[`RGBA`,6408],[`RGB`,6407],[`UNSIGNED_BYTE`,5121],[`UNSIGNED_SHORT`,5123],[`UNSIGNED_INT`,5125],[`FRAMEBUFFER`,36160],[`RENDERBUFFER`,36161],[`DEPTH_COMPONENT16`,33189],[`DEPTH_ATTACHMENT`,36096],[`COLOR_ATTACHMENT0`,36064],[`FRAMEBUFFER_COMPLETE`,36053],[`NO_ERROR`,0],[`INVALID_ENUM`,1280],[`INVALID_VALUE`,1281],[`INVALID_OPERATION`,1282],[`OUT_OF_MEMORY`,1285]];var u=e(async()=>{await o(`Display`,async()=>{let e=t();if(!e){console.warn(`WebGL context not available — skipping conformance/context tests`);return}let{gl:o,glArea:u,win:d}=e;u.make_current(),await r(`conformance/context/methods: all WebGL methods present`,async()=>{n(async()=>{u.make_current()}),await a(`all standard WebGL methods are functions on the context`,async()=>{let e=[];for(let
|
|
2
|
-
`)}`)}),await a(`WebGLRenderingContext class constant values match instance constants`,async()=>{let e=[];for(let[
|
|
1
|
+
import{__name as e}from"../_virtual/_rolldown/runtime.js";import{createGLSetup as t}from"./setup.js";import{beforeEach as n,describe as r,expect as i,it as a,on as o}from"@gjsify/unit";import{WebGLRenderingContext as s}from"@gjsify/webgl";const c=`getContextAttributes.activeTexture.attachShader.bindAttribLocation.bindBuffer.bindFramebuffer.bindRenderbuffer.bindTexture.blendColor.blendEquation.blendEquationSeparate.blendFunc.blendFuncSeparate.bufferData.bufferSubData.checkFramebufferStatus.clear.clearColor.clearDepth.clearStencil.colorMask.compileShader.compressedTexImage2D.compressedTexSubImage2D.copyTexImage2D.copyTexSubImage2D.createBuffer.createFramebuffer.createProgram.createRenderbuffer.createShader.createTexture.cullFace.deleteBuffer.deleteFramebuffer.deleteProgram.deleteRenderbuffer.deleteShader.deleteTexture.depthFunc.depthMask.depthRange.detachShader.disable.disableVertexAttribArray.drawArrays.drawElements.enable.enableVertexAttribArray.finish.flush.framebufferRenderbuffer.framebufferTexture2D.frontFace.generateMipmap.getActiveAttrib.getActiveUniform.getAttachedShaders.getAttribLocation.getParameter.getBufferParameter.getError.getExtension.getFramebufferAttachmentParameter.getProgramParameter.getProgramInfoLog.getRenderbufferParameter.getShaderParameter.getShaderInfoLog.getShaderPrecisionFormat.getShaderSource.getSupportedExtensions.getTexParameter.getUniform.getUniformLocation.getVertexAttrib.getVertexAttribOffset.hint.isBuffer.isContextLost.isEnabled.isFramebuffer.isProgram.isRenderbuffer.isShader.isTexture.lineWidth.linkProgram.pixelStorei.polygonOffset.readPixels.renderbufferStorage.sampleCoverage.scissor.shaderSource.stencilFunc.stencilFuncSeparate.stencilMask.stencilMaskSeparate.stencilOp.stencilOpSeparate.texImage2D.texParameterf.texParameteri.texSubImage2D.uniform1f.uniform1fv.uniform1i.uniform1iv.uniform2f.uniform2fv.uniform2i.uniform2iv.uniform3f.uniform3fv.uniform3i.uniform3iv.uniform4f.uniform4fv.uniform4i.uniform4iv.uniformMatrix2fv.uniformMatrix3fv.uniformMatrix4fv.useProgram.validateProgram.vertexAttrib1f.vertexAttrib1fv.vertexAttrib2f.vertexAttrib2fv.vertexAttrib3f.vertexAttrib3fv.vertexAttrib4f.vertexAttrib4fv.vertexAttribPointer.viewport`.split(`.`),l=[[`DEPTH_BUFFER_BIT`,256],[`STENCIL_BUFFER_BIT`,1024],[`COLOR_BUFFER_BIT`,16384],[`POINTS`,0],[`LINES`,1],[`LINE_LOOP`,2],[`LINE_STRIP`,3],[`TRIANGLES`,4],[`TRIANGLE_STRIP`,5],[`TRIANGLE_FAN`,6],[`ZERO`,0],[`ONE`,1],[`SRC_COLOR`,768],[`SRC_ALPHA`,770],[`FUNC_ADD`,32774],[`ARRAY_BUFFER`,34962],[`ELEMENT_ARRAY_BUFFER`,34963],[`STREAM_DRAW`,35040],[`STATIC_DRAW`,35044],[`DYNAMIC_DRAW`,35048],[`FRAGMENT_SHADER`,35632],[`VERTEX_SHADER`,35633],[`COMPILE_STATUS`,35713],[`LINK_STATUS`,35714],[`VALIDATE_STATUS`,35715],[`FLOAT`,5126],[`FLOAT_VEC2`,35664],[`FLOAT_VEC3`,35665],[`FLOAT_VEC4`,35666],[`FLOAT_MAT2`,35674],[`FLOAT_MAT3`,35675],[`FLOAT_MAT4`,35676],[`INT`,5124],[`TEXTURE_2D`,3553],[`TEXTURE_CUBE_MAP`,34067],[`RGBA`,6408],[`RGB`,6407],[`UNSIGNED_BYTE`,5121],[`UNSIGNED_SHORT`,5123],[`UNSIGNED_INT`,5125],[`FRAMEBUFFER`,36160],[`RENDERBUFFER`,36161],[`DEPTH_COMPONENT16`,33189],[`DEPTH_ATTACHMENT`,36096],[`COLOR_ATTACHMENT0`,36064],[`FRAMEBUFFER_COMPLETE`,36053],[`NO_ERROR`,0],[`INVALID_ENUM`,1280],[`INVALID_VALUE`,1281],[`INVALID_OPERATION`,1282],[`OUT_OF_MEMORY`,1285]];var u=e(async()=>{await o(`Display`,async()=>{let e=t();if(!e){console.warn(`WebGL context not available — skipping conformance/context tests`);return}let{gl:o,glArea:u,win:d}=e;u.make_current(),await r(`conformance/context/methods: all WebGL methods present`,async()=>{n(async()=>{u.make_current()}),await a(`all standard WebGL methods are functions on the context`,async()=>{let e=[],t=o;for(let n of c)typeof t[n]!=`function`&&e.push(n);if(e.length>0)throw Error(`Missing WebGL methods: ${e.join(`, `)}`)})}),await r(`conformance/context/constants-and-properties: constant values`,async()=>{n(async()=>{u.make_current()}),await a(`all sampled WebGL constants have the correct numeric value`,async()=>{let e=[],t=o;for(let[n,r]of l){let i=t[n];i!==r&&e.push(`${n}: expected ${r}, got ${i}`)}if(e.length>0)throw Error(`Wrong constant values:\n${e.join(`
|
|
2
|
+
`)}`)}),await a(`WebGLRenderingContext class constant values match instance constants`,async()=>{let e=[],t=s;for(let[n,r]of l){let i=t[n];i!==void 0&&i!==r&&e.push(`${n}: expected ${r}, got ${i}`)}if(e.length>0)throw Error(`Wrong class constant values:\n${e.join(`
|
|
3
3
|
`)}`)})}),await r(`conformance/context/context-type-test`,async()=>{n(async()=>{u.make_current()}),await a(`WebGLRenderingContext should exist in globalThis`,async()=>{i(globalThis.WebGLRenderingContext!==void 0).toBeTruthy()}),await a(`gl should be an instance of WebGLRenderingContext`,async()=>{i(o instanceof s).toBeTruthy()}),await a(`getContextAttributes returns an object`,async()=>{let e=o.getContextAttributes();i(e).not.toBeNull(),i(typeof e).toBe(`object`)}),await a(`isContextLost returns false initially`,async()=>{i(o.isContextLost()).toBe(!1)}),await a(`canvas property points to the HTMLCanvasElement`,async()=>{i(o.canvas).not.toBeNull(),i(typeof o.canvas.getContext).toBe(`function`)}),await a(`drawingBufferWidth and drawingBufferHeight are positive integers`,async()=>{i(o.drawingBufferWidth).toBeGreaterThan(0),i(o.drawingBufferHeight).toBeGreaterThan(0),i(Number.isInteger(o.drawingBufferWidth)).toBeTruthy(),i(Number.isInteger(o.drawingBufferHeight)).toBeTruthy()}),await a(`getSupportedExtensions returns an array of strings`,async()=>{let e=o.getSupportedExtensions();i(Array.isArray(e)).toBeTruthy();for(let t of e)i(typeof t).toBe(`string`)}),await a(`getParameter(VENDOR) and getParameter(RENDERER) return strings`,async()=>{let e=o.getParameter(o.VENDOR),t=o.getParameter(o.RENDERER),n=o.getParameter(o.VERSION),r=o.getParameter(o.SHADING_LANGUAGE_VERSION);i(typeof e).toBe(`string`),i(typeof t).toBe(`string`),i(typeof n).toBe(`string`),i(typeof r).toBe(`string`)})}),d.destroy()})},`default`);export{u as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,checkObject as t}from"../utils.js";import{WebGLFramebuffer as n}from"../webgl-framebuffer.js";import{WebGLRenderbuffer as r}from"../webgl-renderbuffer.js";import{WebGLTexture as i}from"../webgl-texture.js";import{WebGLDrawingBufferWrapper as a}from"../webgl-drawing-buffer-wrapper.js";const o={bindFramebuffer(e,r){if(!t(r))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!r)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(r._pendingDelete)return;else if(this._checkWrapper(r,n))this._gl.bindFramebuffer(this.FRAMEBUFFER,r._|0);else return;let i=this._activeFramebuffer;i!==r&&(i&&(--i._refCount,i._checkDelete()),r&&(r._refCount+=1)),this._activeFramebuffer=r,r&&this._updateFramebufferAttachments(r)},bindRenderbuffer(e,n){if(!t(n))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!n)this._gl.bindRenderbuffer(e|0,0);else if(n._pendingDelete)return;else if(this._checkWrapper(n,r))this._gl.bindRenderbuffer(e|0,n._|0);else return;let i=this._activeRenderbuffer;i!==n&&(i&&(--i._refCount,i._checkDelete()),n&&(n._refCount+=1)),this._activeRenderbuffer=n},framebufferRenderbuffer(e,n,i,a){if(!t(a))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)||i!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let o=this._activeFramebuffer;if(!o){this.setError(this.INVALID_OPERATION);return}a&&!this._checkWrapper(a,r)||(o._setAttachment(a,n),this._updateFramebufferAttachments(o))},framebufferTexture2D(e,n,r,a,o=0){if(e|=0,n|=0,r|=0,o|=0,!t(a))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)){this.setError(this.INVALID_ENUM);return}if(o!==0){this.setError(this.INVALID_VALUE);return}if(a&&!this._checkWrapper(a,i))return;if(r===this.TEXTURE_2D){if(a&&a._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(r)){if(a&&a._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let s=this._activeFramebuffer;if(!s){this.setError(this.INVALID_OPERATION);return}s._attachmentLevel[n]=o,s._attachmentFace[n]=r,s._setAttachment(a,n),this._updateFramebufferAttachments(s)},createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new n(e,this);return this._framebuffers[e]=t,t},deleteFramebuffer(e){if(!t(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof n&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()},createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new r(e,this);return this._renderbuffers[e]=t,t},deleteRenderbuffer(e){if(!t(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof r&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null),this._detachRenderbufferFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},renderbufferStorage(e=0,t=0,n=0,r=0){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(t!==this.RGBA4&&t!==this.RGB565&&t!==this.RGB5_A1&&t!==this.DEPTH_COMPONENT16&&t!==this.STENCIL_INDEX&&t!==this.STENCIL_INDEX8&&t!==this.DEPTH_STENCIL){this.setError(this.INVALID_ENUM);return}this._saveError(),this._gl.renderbufferStorage(e,t,n,r);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let o=this._activeFramebuffer;if(o){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(o._attachments[t[n]]===i){e=!0;break}e&&this._updateFramebufferAttachments(this._activeFramebuffer)}},getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let a=this._activeFramebuffer;if(!a)return this.setError(this.INVALID_OPERATION),null;let o=a._attachments[t];if(o===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(o instanceof i)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return a._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=a._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(o instanceof r)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),null},getRenderbufferParameter(e=0,t=0){if(e!==this.RENDERBUFFER)return this.setError(this.INVALID_ENUM),null;let n=this._activeRenderbuffer;if(!n)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.RENDERBUFFER_INTERNAL_FORMAT:return n._format;case this.RENDERBUFFER_WIDTH:return n._width;case this.RENDERBUFFER_HEIGHT:return n._height;case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.RENDERBUFFER_RED_SIZE:case this.RENDERBUFFER_GREEN_SIZE:case this.RENDERBUFFER_BLUE_SIZE:case this.RENDERBUFFER_ALPHA_SIZE:case this.RENDERBUFFER_DEPTH_SIZE:case this.RENDERBUFFER_STENCIL_SIZE:return this._gl.getRenderbufferParameter(e,t)}return this.setError(this.INVALID_ENUM),null},checkFramebufferStatus(e){if(e!==this.FRAMEBUFFER)return this.setError(this.INVALID_ENUM),0;let t=this._activeFramebuffer;return t?this._preCheckFramebufferStatus(t):this.FRAMEBUFFER_COMPLETE},_preCheckFramebufferStatus(e){let t=e._attachments,n=[],a=[],o=t[this.DEPTH_ATTACHMENT],s=t[this.DEPTH_STENCIL_ATTACHMENT],c=t[this.STENCIL_ATTACHMENT];if(s&&(c||o)||c&&o)return this.FRAMEBUFFER_UNSUPPORTED;let l=this._getColorAttachments(),u=0;for(let e in t)t[e]&&l.indexOf(Number(e))!==-1&&u++;if(u===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(s instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(s instanceof r){if(s._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(s._width),a.push(s._height)}if(o instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof r){if(o._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),a.push(o._height)}if(c instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(c instanceof r){if(c._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(c._width),a.push(c._height)}let d=!1;for(let o=0;o<l.length;++o){let s=t[l[o]];if(s instanceof i){if(s._format!==this.RGBA||!(s._type===this.UNSIGNED_BYTE||s._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(s._levelWidth[t]),a.push(s._levelHeight[t])}else if(s instanceof r){let e=s._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0,n.push(s._width),a.push(s._height)}}if(!d&&!c&&!o&&!s)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||a.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||a[e-1]!==a[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||a[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=a[0],this.FRAMEBUFFER_COMPLETE)},_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0},_validFramebufferAttachment(e){switch(e){case this.DEPTH_ATTACHMENT:case this.STENCIL_ATTACHMENT:case this.DEPTH_STENCIL_ATTACHMENT:case this.COLOR_ATTACHMENT0:return!0}if(this._extensions.webgl_draw_buffers){let{webgl_draw_buffers:t}=this._extensions;return e<t.COLOR_ATTACHMENT0_WEBGL+t._maxDrawBuffers}return!1},_updateFramebufferAttachments(e){if(!e)return;let t=e._status,n=this._getAttachments();if(e._status=this._preCheckFramebufferStatus(e),e._status!==this.FRAMEBUFFER_COMPLETE){if(t===this.FRAMEBUFFER_COMPLETE)for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}return}for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}for(let t=0;t<n.length;++t){let a=n[t],o=e._attachments[a];o instanceof i?this._gl.framebufferTexture2D(this.FRAMEBUFFER,a,e._attachmentFace[a]||0,o._|0,e._attachmentLevel[a]||0):o instanceof r&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,a,this.RENDERBUFFER,o._|0)}},_tryDetachFramebuffer(e,t){if(e&&e._linked(t)){let n=this._getAttachments();for(let r=0;r<n.length;++r)e._attachments[n[r]]===t&&this.framebufferTexture2D(this.FRAMEBUFFER,n[r]|0,this.TEXTURE_2D,null)}},_detachRenderbufferFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},_getAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS:this.DEFAULT_ATTACHMENTS},_getColorAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_COLOR_ATTACHMENTS:this.DEFAULT_COLOR_ATTACHMENTS},_resizeDrawingBuffer(t,n){let r=this._activeFramebuffer,i=this._getActiveTexture(this.TEXTURE_2D),a=this._activeRenderbuffer,o=this._contextAttributes,s=this._drawingBuffer;s?._framebuffer&&this._gl.bindFramebuffer(this.FRAMEBUFFER,s?._framebuffer);let c=this._getAttachments();for(let e=0;e<c.length;++e)this._gl.framebufferTexture2D(this.FRAMEBUFFER,c[e],this.TEXTURE_2D,0,0);s?._color&&this._gl.bindTexture(this.TEXTURE_2D,s?._color);let l=o.alpha?this.RGBA:this.RGB;this._gl.texImage2D(this.TEXTURE_2D,0,l,t,n,0,l,this.UNSIGNED_BYTE,e(null)),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MIN_FILTER,this.NEAREST),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MAG_FILTER,this.NEAREST),s?._color&&this._gl.framebufferTexture2D(this.FRAMEBUFFER,this.COLOR_ATTACHMENT0,this.TEXTURE_2D,s?._color,0);let u=0,d=0;o.depth&&o.stencil?(u=this.DEPTH_STENCIL,d=this.DEPTH_STENCIL_ATTACHMENT):o.depth?(u=33191,d=this.DEPTH_ATTACHMENT):o.stencil&&(u=this.STENCIL_INDEX8,d=this.STENCIL_ATTACHMENT),u&&(s?._depthStencil&&this._gl.bindRenderbuffer(this.RENDERBUFFER,s?._depthStencil),this._gl.renderbufferStorage(this.RENDERBUFFER,u,t,n),s?._depthStencil&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,d,this.RENDERBUFFER,s?._depthStencil)),this.bindFramebuffer(this.FRAMEBUFFER,r),this.bindTexture(this.TEXTURE_2D,i),this.bindRenderbuffer(this.RENDERBUFFER,a)},_allocateDrawingBuffer(e,t){this._drawingBuffer=new a(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)},resize(e=0,t=0){if(e|=0,t|=0,e>0&&t>0)(e!==this.drawingBufferWidth||t!==this.drawingBufferHeight)&&this._resizeDrawingBuffer(e,t);else throw Error(`Invalid surface dimensions`)}};function installFramebufferMethods(e){Object.assign(e,o)}export{installFramebufferMethods};
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,checkObject as t}from"../utils.js";import{WebGLFramebuffer as n}from"../webgl-framebuffer.js";import{WebGLRenderbuffer as r}from"../webgl-renderbuffer.js";import{WebGLTexture as i}from"../webgl-texture.js";import{WebGLDrawingBufferWrapper as a}from"../webgl-drawing-buffer-wrapper.js";const o={bindFramebuffer(e,r){if(!t(r))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!r)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(r._pendingDelete)return;else if(this._checkWrapper(r,n))this._gl.bindFramebuffer(this.FRAMEBUFFER,r._|0);else return;let i=this._activeFramebuffer;i!==r&&(i&&(--i._refCount,i._checkDelete()),r&&(r._refCount+=1)),this._activeFramebuffer=r,r&&this._updateFramebufferAttachments(r)},bindRenderbuffer(e,n){if(!t(n))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!n)this._gl.bindRenderbuffer(e|0,0);else if(n._pendingDelete)return;else if(this._checkWrapper(n,r))this._gl.bindRenderbuffer(e|0,n._|0);else return;let i=this._activeRenderbuffer;i!==n&&(i&&(--i._refCount,i._checkDelete()),n&&(n._refCount+=1)),this._activeRenderbuffer=n},framebufferRenderbuffer(e,n,i,a){if(!t(a))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)||i!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let o=this._activeFramebuffer;if(!o){this.setError(this.INVALID_OPERATION);return}a&&!this._checkWrapper(a,r)||(o._setAttachment(a,n),this._updateFramebufferAttachments(o))},framebufferTexture2D(e,n,r,a,o=0){if(e|=0,n|=0,r|=0,o|=0,!t(a))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)){this.setError(this.INVALID_ENUM);return}if(o!==0){this.setError(this.INVALID_VALUE);return}if(a&&!this._checkWrapper(a,i))return;if(r===this.TEXTURE_2D){if(a&&a._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(r)){if(a&&a._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let s=this._activeFramebuffer;if(!s){this.setError(this.INVALID_OPERATION);return}s._attachmentLevel[n]=o,s._attachmentFace[n]=r,s._setAttachment(a,n),this._updateFramebufferAttachments(s)},createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new n(e,this);return this._framebuffers[e]=t,t},deleteFramebuffer(e){if(!t(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof n&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()},createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new r(e,this);return this._renderbuffers[e]=t,t},deleteRenderbuffer(e){if(!t(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof r&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null),this._detachRenderbufferFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},renderbufferStorage(e=0,t=0,n=0,r=0){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(t!==this.RGBA4&&t!==this.RGB565&&t!==this.RGB5_A1&&t!==this.DEPTH_COMPONENT16&&t!==this.STENCIL_INDEX&&t!==this.STENCIL_INDEX8&&t!==this.DEPTH_STENCIL){this.setError(this.INVALID_ENUM);return}this._saveError(),this._gl.renderbufferStorage(e,t,n,r);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let o=this._activeFramebuffer;if(o){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(o._attachments[t[n]]===i){e=!0;break}e&&this._updateFramebufferAttachments(this._activeFramebuffer)}},getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let a=this._activeFramebuffer;if(!a)return this.setError(this.INVALID_OPERATION),null;let o=a._attachments[t];if(o===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(o instanceof i)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return a._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=a._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(o instanceof r)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),null},getRenderbufferParameter(e=0,t=0){if(e!==this.RENDERBUFFER)return this.setError(this.INVALID_ENUM),null;let n=this._activeRenderbuffer;if(!n)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.RENDERBUFFER_INTERNAL_FORMAT:return n._format;case this.RENDERBUFFER_WIDTH:return n._width;case this.RENDERBUFFER_HEIGHT:return n._height;case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.RENDERBUFFER_RED_SIZE:case this.RENDERBUFFER_GREEN_SIZE:case this.RENDERBUFFER_BLUE_SIZE:case this.RENDERBUFFER_ALPHA_SIZE:case this.RENDERBUFFER_DEPTH_SIZE:case this.RENDERBUFFER_STENCIL_SIZE:return this._gl.getRenderbufferParameter(e,t)}return this.setError(this.INVALID_ENUM),null},checkFramebufferStatus(e){if(e!==this.FRAMEBUFFER)return this.setError(this.INVALID_ENUM),0;let t=this._activeFramebuffer;return t?this._preCheckFramebufferStatus(t):this.FRAMEBUFFER_COMPLETE},_preCheckFramebufferStatus(e){let t=e._attachments,n=[],a=[],o=t[this.DEPTH_ATTACHMENT],s=t[this.DEPTH_STENCIL_ATTACHMENT],c=t[this.STENCIL_ATTACHMENT];if(s&&(c||o)||c&&o)return this.FRAMEBUFFER_UNSUPPORTED;let l=this._getColorAttachments(),u=0;for(let e in t)t[e]&&l.indexOf(Number(e))!==-1&&u++;if(u===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(s instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(s instanceof r){if(s._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(s._width),a.push(s._height)}if(o instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof r){if(o._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),a.push(o._height)}if(c instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(c instanceof r){if(c._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(c._width),a.push(c._height)}let d=!1;for(let o=0;o<l.length;++o){let s=t[l[o]];if(s instanceof i){if(s._format!==this.RGBA||!(s._type===this.UNSIGNED_BYTE||s._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(s._levelWidth[t]),a.push(s._levelHeight[t])}else if(s instanceof r){let e=s._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0,n.push(s._width),a.push(s._height)}}if(!d&&!c&&!o&&!s)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||a.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||a[e-1]!==a[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||a[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=a[0],this.FRAMEBUFFER_COMPLETE)},_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0},_validFramebufferAttachment(e){switch(e){case this.DEPTH_ATTACHMENT:case this.STENCIL_ATTACHMENT:case this.DEPTH_STENCIL_ATTACHMENT:case this.COLOR_ATTACHMENT0:return!0}if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;return e<t.COLOR_ATTACHMENT0_WEBGL+t._maxDrawBuffers}return!1},_updateFramebufferAttachments(e){if(!e)return;let t=e._status,n=this._getAttachments();if(e._status=this._preCheckFramebufferStatus(e),e._status!==this.FRAMEBUFFER_COMPLETE){if(t===this.FRAMEBUFFER_COMPLETE)for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}return}for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}for(let t=0;t<n.length;++t){let a=n[t],o=e._attachments[a];o instanceof i?this._gl.framebufferTexture2D(this.FRAMEBUFFER,a,e._attachmentFace[a]||0,o._|0,e._attachmentLevel[a]||0):o instanceof r&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,a,this.RENDERBUFFER,o._|0)}},_tryDetachFramebuffer(e,t){if(e&&e._linked(t)){let n=this._getAttachments();for(let r=0;r<n.length;++r)e._attachments[n[r]]===t&&this.framebufferTexture2D(this.FRAMEBUFFER,n[r]|0,this.TEXTURE_2D,null)}},_detachRenderbufferFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},_getAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS:this.DEFAULT_ATTACHMENTS},_getColorAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_COLOR_ATTACHMENTS:this.DEFAULT_COLOR_ATTACHMENTS},_resizeDrawingBuffer(t,n){let r=this._activeFramebuffer,i=this._getActiveTexture(this.TEXTURE_2D),a=this._activeRenderbuffer,o=this._contextAttributes,s=this._drawingBuffer;s?._framebuffer&&this._gl.bindFramebuffer(this.FRAMEBUFFER,s?._framebuffer);let c=this._getAttachments();for(let e=0;e<c.length;++e)this._gl.framebufferTexture2D(this.FRAMEBUFFER,c[e],this.TEXTURE_2D,0,0);s?._color&&this._gl.bindTexture(this.TEXTURE_2D,s?._color);let l=o.alpha?this.RGBA:this.RGB;this._gl.texImage2D(this.TEXTURE_2D,0,l,t,n,0,l,this.UNSIGNED_BYTE,e(null)),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MIN_FILTER,this.NEAREST),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MAG_FILTER,this.NEAREST),s?._color&&this._gl.framebufferTexture2D(this.FRAMEBUFFER,this.COLOR_ATTACHMENT0,this.TEXTURE_2D,s?._color,0);let u=0,d=0;o.depth&&o.stencil?(u=this.DEPTH_STENCIL,d=this.DEPTH_STENCIL_ATTACHMENT):o.depth?(u=33191,d=this.DEPTH_ATTACHMENT):o.stencil&&(u=this.STENCIL_INDEX8,d=this.STENCIL_ATTACHMENT),u&&(s?._depthStencil&&this._gl.bindRenderbuffer(this.RENDERBUFFER,s?._depthStencil),this._gl.renderbufferStorage(this.RENDERBUFFER,u,t,n),s?._depthStencil&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,d,this.RENDERBUFFER,s?._depthStencil)),this.bindFramebuffer(this.FRAMEBUFFER,r),this.bindTexture(this.TEXTURE_2D,i),this.bindRenderbuffer(this.RENDERBUFFER,a)},_allocateDrawingBuffer(e,t){this._drawingBuffer=new a(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)},resize(e=0,t=0){if(e|=0,t|=0,e>0&&t>0)(e!==this.drawingBufferWidth||t!==this.drawingBufferHeight)&&this._resizeDrawingBuffer(e,t);else throw Error(`Invalid surface dimensions`)}};function installFramebufferMethods(e){Object.assign(e,o)}export{installFramebufferMethods};
|
package/lib/esm/context/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_virtual/_rolldown/runtime.js";import{WebGLBuffer as e}from"../webgl-buffer.js";import{WebGLFramebuffer as t}from"../webgl-framebuffer.js";import{WebGLProgram as n}from"../webgl-program.js";import{WebGLRenderbuffer as r}from"../webgl-renderbuffer.js";import{WebGLShader as i}from"../webgl-shader.js";import{WebGLTexture as a}from"../webgl-texture.js";const o={enable(e=0){this._gl.enable(e)},disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}},cullFace(e){this._gl.cullFace(e|0)},depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:this._gl.depthFunc(e);return;default:this.setError(this.INVALID_ENUM)}},depthMask(e){this._gl.depthMask(!!e)},depthRange(e,t){if(e=+e,t=+t,e<=t){this._gl.depthRange(e,t);return}this.setError(this.INVALID_OPERATION)},frontFace(e=0){this._gl.frontFace(e)},lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}this._gl.lineWidth(+e)},polygonOffset(e,t){this._gl.polygonOffset(+e,+t)},sampleCoverage(e,t){this._gl.sampleCoverage(+e,!!t)},hint(e=0,t=0){if(!(e===this.GENERATE_MIPMAP_HINT||
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{WebGLBuffer as e}from"../webgl-buffer.js";import{WebGLFramebuffer as t}from"../webgl-framebuffer.js";import{WebGLProgram as n}from"../webgl-program.js";import{WebGLRenderbuffer as r}from"../webgl-renderbuffer.js";import{WebGLShader as i}from"../webgl-shader.js";import{WebGLTexture as a}from"../webgl-texture.js";const o={enable(e=0){this._gl.enable(e)},disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}},cullFace(e){this._gl.cullFace(e|0)},depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:this._gl.depthFunc(e);return;default:this.setError(this.INVALID_ENUM)}},depthMask(e){this._gl.depthMask(!!e)},depthRange(e,t){if(e=+e,t=+t,e<=t){this._gl.depthRange(e,t);return}this.setError(this.INVALID_OPERATION)},frontFace(e=0){this._gl.frontFace(e)},lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}this._gl.lineWidth(+e)},polygonOffset(e,t){this._gl.polygonOffset(+e,+t)},sampleCoverage(e,t){this._gl.sampleCoverage(+e,!!t)},hint(e=0,t=0){let n=this._extensions.oes_standard_derivatives;if(!(e===this.GENERATE_MIPMAP_HINT||n&&e===n.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}this._gl.hint(e,t)},finish(){this._gl.finish()},flush(){this._gl.flush()},blendColor(e=0,t=0,n=0,r=0){this._gl.blendColor(+e,+t,+n,+r)},blendEquation(e=0){if(this._validBlendMode(e)){this._gl.blendEquation(e);return}this.setError(this.INVALID_ENUM)},blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t)){this._gl.blendEquationSeparate(e,t);return}this.setError(this.INVALID_ENUM)},blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)},blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)},clear(e=0){this._framebufferOk()&&this._gl.clear(e)},clearColor(e,t,n,r){this._gl.clearColor(+e,+t,+n,+r)},clearDepth(e){this._gl.clearDepth(+e)},clearStencil(e=0){this._checkStencil=!1,this._gl.clearStencil(e)},colorMask(e,t,n,r){this._gl.colorMask(!!e,!!t,!!n,!!r)},stencilFunc(e,t,n){this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)},stencilFuncSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)},stencilMask(e){this._checkStencil=!0,this._gl.stencilMask(e>>>0)},stencilMaskSeparate(e,t){this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)},stencilOp(e,t,n){this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)},stencilOpSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)},isEnabled(e=0){return this._gl.isEnabled(e)},isContextLost(){return!1},getError(){return this._gl.getError()},setError(e){this._gl.setError(e)},isBuffer(t){return this._isObject(t,`isBuffer`,e)?this._gl.isBuffer(t?._):!1},isFramebuffer(e){return this._isObject(e,`isFramebuffer`,t)?this._gl.isFramebuffer(e?._):!1},isProgram(e){return this._isObject(e,`isProgram`,n)?this._gl.isProgram(e?._):!1},isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,r)?this._gl.isRenderbuffer(e?._):!1},isShader(e){return this._isObject(e,`isShader`,i)?this._gl.isShader(e?._):!1},isTexture(e){return this._isObject(e,`isTexture`,a)?this._gl.isTexture(e?._):!1},generateMipmap(e=0){this._gl.generateMipmap(e)},_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_validBlendMode(e){let t=this._extensions.ext_blend_minmax;return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||!!(t&&(e===t.MIN_EXT||e===t.MAX_EXT))},_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_saveError(){this._errorStack.push(this.getError())},_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t!==void 0&&this.setError(t)}};function installStateMethods(e){Object.assign(e,o)}export{installStateMethods};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t,checkFormat as n,checkObject as r,convertPixels as i,extractImageData as a,formatSize as o,premultiplyAlpha as s,validCubeTarget as c}from"../utils.js";import{WebGLTexture as l}from"../webgl-texture.js";import*as u from"bit-twiddle";import d from"gi://GdkPixbuf?version=2.0";const f={activeTexture(e=0){let t=e-this.TEXTURE0;if(t>=0&&t<this._textureUnits.length){this._activeTextureUnit=t,this._gl.activeTexture(e);return}this.setError(this.INVALID_ENUM)},bindTexture(e=0,t){if(!r(t))throw TypeError(`bindTexture(GLenum, WebGLTexture)`);if(!this._validTextureTarget(e)){this.setError(this.INVALID_ENUM);return}let n=0;if(!t)t=null;else if(t instanceof l&&t._pendingDelete)return;else if(this._checkWrapper(t,l)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e,t._complete&&(n=t._|0)}else return;this._saveError(),this._gl.bindTexture(e,n);let i=this.getError();if(this._restoreError(i),i!==this.NO_ERROR)return;let a=this._getActiveTextureUnit(),o=this._getActiveTexture(e);o!==t&&(o&&(--o._refCount,o._checkDelete()),t&&(t._refCount+=1)),e===this.TEXTURE_2D?a._bind2D=t:e===this.TEXTURE_CUBE_MAP&&(a._bindCube=t)},createTexture(){let e=this._gl.createTexture();if(e<=0)return null;let t=new l(e,this);return this._textures[e]=t,t},deleteTexture(e){if(!r(e))throw TypeError(`deleteTexture(WebGLTexture)`);if(e instanceof l){if(!this._checkOwns(e)){this.setError(this.INVALID_OPERATION);return}}else return;let t=this._activeTextureUnit;for(let t=0;t<this._textureUnits.length;++t){let n=this._textureUnits[t];n._bind2D===e?(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_2D,null)):n._bindCube===e&&(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_CUBE_MAP,null))}this.activeTexture(this.TEXTURE0+t),this._detachTextureFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},_detachTextureFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,a._attachmentFace[r]||this.TEXTURE_2D,0,a._attachmentLevel[r]||0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},pixelStorei(e=0,t=0){if(typeof t==`boolean`&&(t=t===!1?0:1),e===this.UNPACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._unpackAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.PACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._packAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.UNPACK_COLORSPACE_CONVERSION_WEBGL){if(!(t===this.NONE||t===this.BROWSER_DEFAULT_WEBGL)){this.setError(this.INVALID_VALUE);return}}else if(e===this.UNPACK_FLIP_Y_WEBGL){this._unpackFlipY=!!t;return}else if(e===this.UNPACK_PREMULTIPLY_ALPHA_WEBGL){this._unpackPremultAlpha=!!t;return}this._gl.pixelStorei(e,t)},texImage2D(t=0,r=0,o=0,l=0,u=0,f=0,p=0,m=0,h){let g=0,_=0,v=0,y,b,x=0;if(arguments.length===6)if(m=u,v=l,f instanceof d.Pixbuf)b=f,g=b.get_width(),_=b.get_height(),h=b.get_pixels();else{y=f;let e=a(y);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);g=e.width,_=e.height,h=e.data}else arguments.length===9&&(g=l,_=u,x=f,v=p,h=h);if(typeof h!=`object`&&h!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!n(this,v)||!n(this,o)){this.setError(this.INVALID_ENUM);return}if(m===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let S=this._getTexImage(t);if(!S||v!==o){this.setError(this.INVALID_OPERATION);return}let C=this._computePixelSize(m,v);if(C===0||!this._checkDimensions(t,g,_,r))return;let w=i(h),T=this._computeRowStride(g,C),E=T*_;if(w&&w.length<E){this.setError(this.INVALID_OPERATION);return}if(x!==0||c(this,t)&&g!==_){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&w&&v===this.RGBA&&(w=s(w)),this._unpackFlipY&&w&&g>0&&_>0){let e=new Uint8Array(w.length);for(let t=0;t<_;t++){let n=t*T,r=(_-1-t)*T;e.set(w.subarray(n,n+T),r)}w=e}this._saveError(),this._gl.texImage2D(t,r,o,g,_,x,v,m,e(w));let D=this.getError();if(this._restoreError(D),D!==this.NO_ERROR)return;S._levelWidth[r]=g,S._levelHeight[r]=_,S._format=v,S._type=m;let O=this._activeFramebuffer;if(O){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(O._attachments[t[n]]===S){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}},texSubImage2D(t=0,n=0,r=0,o=0,c=0,l=0,u=0,f=0,p){let m=0,h=0,g=0,_,v;if(arguments.length===7)if(f=l,g=c,u instanceof d.Pixbuf)v=u,m=v.get_width(),h=v.get_height(),p=v.get_pixels();else{_=u;let e=a(_);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);m=e.width,h=e.height,p=e.data}else m=c,h=l,g=u;if(typeof p!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!this._getTexImage(t)){this.setError(this.INVALID_OPERATION);return}if(f===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let y=this._computePixelSize(f,g);if(y===0||!this._checkDimensions(t,m,h,n))return;if(r<0||o<0){this.setError(this.INVALID_VALUE);return}let b=i(p),x=this._computeRowStride(m,y),S=x*h;if(!b||b.length<S){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&b&&g===this.RGBA&&(b=s(b)),this._unpackFlipY&&b&&m>0&&h>0){let e=new Uint8Array(b.length);for(let t=0;t<h;t++){let n=t*x,r=(h-1-t)*x;e.set(b.subarray(n,n+x),r)}b=e}this._gl.texSubImage2D(t,n,r,o,m,h,g,f,e(b))},copyTexImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){let c=this._getTexImage(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||a<0||o<0||s!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(u.isPow2(a)&&u.isPow2(o))){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.copyTexImage2D(e,t,n,r,i,a,o,s);let l=this.getError();this._restoreError(l),l===this.NO_ERROR&&(c._levelWidth[t]=a,c._levelHeight[t]=o,c._format=this.RGBA,c._type=this.UNSIGNED_BYTE)},copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(o<0||s<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,o,s)},compressedTexImage2D(n,r,i,a,o,s,c){this._gl.compressedTexImage2D(n,r,i,a,o,s,e(t(c)))},compressedTexSubImage2D(n,r,i,a,o,s,c,l){this._gl.compressedTexSubImage2D(n,r,i,a,o,s,c,e(t(l)))},texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameterf(e,t,n);return}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameterf(e,t,n);return}this.setError(this.INVALID_ENUM)}},texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameteri(e,t,n);return}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameteri(e,t,n);return}this.setError(this.INVALID_ENUM)}},getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}return this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT?this._getTexParameterDirect(e,t):(this.setError(this.INVALID_ENUM),null)},_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()},_getActiveTextureUnit(){return this._textureUnits[this._activeTextureUnit]},_getActiveTexture(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:e===this.TEXTURE_CUBE_MAP?t._bindCube:null},_getTexImage(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:c(this,e)?t._bindCube:(this.setError(this.INVALID_ENUM),null)},_checkTextureTarget(e){let t=this._getActiveTextureUnit(),n=null;if(e===this.TEXTURE_2D)n=t._bind2D;else if(e===this.TEXTURE_CUBE_MAP)n=t._bindCube;else return this.setError(this.INVALID_ENUM),!1;return n?!0:(this.setError(this.INVALID_OPERATION),!1)},_validTextureTarget(e){return e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP},_validCubeTarget(e){return e===this.TEXTURE_CUBE_MAP_POSITIVE_X||e===this.TEXTURE_CUBE_MAP_NEGATIVE_X||e===this.TEXTURE_CUBE_MAP_POSITIVE_Y||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Y||e===this.TEXTURE_CUBE_MAP_POSITIVE_Z||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Z},_verifyTextureCompleteness(e,t,n){let r=this._getActiveTextureUnit(),i=null;if(e===this.TEXTURE_2D?i=r._bind2D:this._validCubeTarget(e)&&(i=r._bindCube),this._extensions.oes_texture_float&&!this._extensions.oes_texture_float_linear&&i&&i._type===this.FLOAT&&(t===this.TEXTURE_MAG_FILTER||t===this.TEXTURE_MIN_FILTER)&&(n===this.LINEAR||n===this.LINEAR_MIPMAP_NEAREST||n===this.NEAREST_MIPMAP_LINEAR||n===this.LINEAR_MIPMAP_LINEAR)){i._complete=!1,this.bindTexture(e,i);return}i&&i._complete===!1&&(i._complete=!0,this.bindTexture(e,i))},_computePixelSize(e,t){let n=o(this,t);if(n===0)return this.setError(this.INVALID_ENUM),0;switch(e){case this.UNSIGNED_BYTE:return n;case this.UNSIGNED_SHORT_5_6_5:if(t!==this.RGB){this.setError(this.INVALID_OPERATION);break}return 2;case this.UNSIGNED_SHORT_4_4_4_4:case this.UNSIGNED_SHORT_5_5_5_1:if(t!==this.RGBA){this.setError(this.INVALID_OPERATION);break}return 2;case this.FLOAT:return 1}return this.setError(this.INVALID_ENUM),0},_computeRowStride(e,t){let n=e*t;return n%this._unpackAlignment&&(n+=this._unpackAlignment-n%this._unpackAlignment),n},_checkDimensions(e,t,n,r){if(r<0||t<0||n<0)return this.setError(this.INVALID_VALUE),!1;if(e===this.TEXTURE_2D){if(t>this._maxTextureSize||n>this._maxTextureSize||r>this._maxTextureLevel)return this.setError(this.INVALID_VALUE),!1}else if(this._validCubeTarget(e)){if(t>this._maxCubeMapSize||n>this._maxCubeMapSize||r>this._maxCubeMapLevel)return this.setError(this.INVALID_VALUE),!1}else return this.setError(this.INVALID_ENUM),!1;return!0}};function installTextureManagementMethods(e){Object.assign(e,f)}export{installTextureManagementMethods};
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t,checkFormat as n,checkObject as r,convertPixels as i,extractImageData as a,formatSize as o,premultiplyAlpha as s,validCubeTarget as c}from"../utils.js";import{WebGLTexture as l}from"../webgl-texture.js";import*as u from"bit-twiddle";import d from"gi://GdkPixbuf?version=2.0";const f={activeTexture(e=0){let t=e-this.TEXTURE0;if(t>=0&&t<this._textureUnits.length){this._activeTextureUnit=t,this._gl.activeTexture(e);return}this.setError(this.INVALID_ENUM)},bindTexture(e=0,t){if(!r(t))throw TypeError(`bindTexture(GLenum, WebGLTexture)`);if(!this._validTextureTarget(e)){this.setError(this.INVALID_ENUM);return}let n=0;if(!t)t=null;else if(t instanceof l&&t._pendingDelete)return;else if(this._checkWrapper(t,l)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e,t._complete&&(n=t._|0)}else return;this._saveError(),this._gl.bindTexture(e,n);let i=this.getError();if(this._restoreError(i),i!==this.NO_ERROR)return;let a=this._getActiveTextureUnit(),o=this._getActiveTexture(e);o!==t&&(o&&(--o._refCount,o._checkDelete()),t&&(t._refCount+=1)),e===this.TEXTURE_2D?a._bind2D=t:e===this.TEXTURE_CUBE_MAP&&(a._bindCube=t)},createTexture(){let e=this._gl.createTexture();if(e<=0)return null;let t=new l(e,this);return this._textures[e]=t,t},deleteTexture(e){if(!r(e))throw TypeError(`deleteTexture(WebGLTexture)`);if(e instanceof l){if(!this._checkOwns(e)){this.setError(this.INVALID_OPERATION);return}}else return;let t=this._activeTextureUnit;for(let t=0;t<this._textureUnits.length;++t){let n=this._textureUnits[t];n._bind2D===e?(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_2D,null)):n._bindCube===e&&(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_CUBE_MAP,null))}this.activeTexture(this.TEXTURE0+t),this._detachTextureFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},_detachTextureFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,a._attachmentFace[r]||this.TEXTURE_2D,0,a._attachmentLevel[r]||0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},pixelStorei(e=0,t=0){if(typeof t==`boolean`&&(t=t===!1?0:1),e===this.UNPACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._unpackAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.PACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._packAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.UNPACK_COLORSPACE_CONVERSION_WEBGL){if(!(t===this.NONE||t===this.BROWSER_DEFAULT_WEBGL)){this.setError(this.INVALID_VALUE);return}}else if(e===this.UNPACK_FLIP_Y_WEBGL){this._unpackFlipY=!!t;return}else if(e===this.UNPACK_PREMULTIPLY_ALPHA_WEBGL){this._unpackPremultAlpha=!!t;return}this._gl.pixelStorei(e,t)},texImage2D(t=0,r=0,o=0,l=0,u=0,f=0,p=0,m=0,h){let g=0,_=0,v=0,y,b,x=0;if(arguments.length===6)if(m=u,v=l,f instanceof d.Pixbuf)b=f,g=b.get_width(),_=b.get_height(),h=b.get_pixels();else{y=f;let e=a(y);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);g=e.width,_=e.height,h=e.data}else arguments.length===9&&(g=l,_=u,x=f,v=p,h=h);if(typeof h!=`object`&&h!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!n(this,v)||!n(this,o)){this.setError(this.INVALID_ENUM);return}if(m===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let S=this._getTexImage(t);if(!S||v!==o){this.setError(this.INVALID_OPERATION);return}let C=this._computePixelSize(m,v);if(C===0||!this._checkDimensions(t,g,_,r))return;let w=i(h),T=this._computeRowStride(g,C),E=T*_;if(w&&w.length<E){this.setError(this.INVALID_OPERATION);return}if(x!==0||c(this,t)&&g!==_){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&w&&v===this.RGBA&&(w=s(w)),this._unpackFlipY&&w&&g>0&&_>0){let e=new Uint8Array(w.length);for(let t=0;t<_;t++){let n=t*T,r=(_-1-t)*T;e.set(w.subarray(n,n+T),r)}w=e}this._saveError(),this._gl.texImage2D(t,r,o,g,_,x,v,m,e(w));let D=this.getError();if(this._restoreError(D),D!==this.NO_ERROR)return;S._levelWidth[r]=g,S._levelHeight[r]=_,S._format=v,S._type=m;let O=this._activeFramebuffer;if(O){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(O._attachments[t[n]]===S){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}},texSubImage2D(t=0,n=0,r=0,o=0,c=0,l=0,u=0,f=0,p){let m=0,h=0,g=0,_,v;if(arguments.length===7)if(f=l,g=c,u instanceof d.Pixbuf)v=u,m=v.get_width(),h=v.get_height(),p=v.get_pixels();else{_=u;let e=a(_);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);m=e.width,h=e.height,p=e.data}else m=c,h=l,g=u;if(typeof p!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!this._getTexImage(t)){this.setError(this.INVALID_OPERATION);return}if(f===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let y=this._computePixelSize(f,g);if(y===0||!this._checkDimensions(t,m,h,n))return;if(r<0||o<0){this.setError(this.INVALID_VALUE);return}let b=i(p),x=this._computeRowStride(m,y),S=x*h;if(!b||b.length<S){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&b&&g===this.RGBA&&(b=s(b)),this._unpackFlipY&&b&&m>0&&h>0){let e=new Uint8Array(b.length);for(let t=0;t<h;t++){let n=t*x,r=(h-1-t)*x;e.set(b.subarray(n,n+x),r)}b=e}this._gl.texSubImage2D(t,n,r,o,m,h,g,f,e(b))},copyTexImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){let c=this._getTexImage(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||a<0||o<0||s!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(u.isPow2(a)&&u.isPow2(o))){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.copyTexImage2D(e,t,n,r,i,a,o,s);let l=this.getError();this._restoreError(l),l===this.NO_ERROR&&(c._levelWidth[t]=a,c._levelHeight[t]=o,c._format=this.RGBA,c._type=this.UNSIGNED_BYTE)},copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(o<0||s<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,o,s)},compressedTexImage2D(n,r,i,a,o,s,c){this._gl.compressedTexImage2D(n,r,i,a,o,s,e(t(c)))},compressedTexSubImage2D(n,r,i,a,o,s,c,l){this._gl.compressedTexSubImage2D(n,r,i,a,o,s,c,e(t(l)))},texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameterf(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameterf(e,t,n);return}this.setError(this.INVALID_ENUM)}},texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameteri(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameteri(e,t,n);return}this.setError(this.INVALID_ENUM)}},getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}let r=this._extensions.ext_texture_filter_anisotropic;return r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT?this._getTexParameterDirect(e,t):(this.setError(this.INVALID_ENUM),null)},_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()},_getActiveTextureUnit(){return this._textureUnits[this._activeTextureUnit]},_getActiveTexture(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:e===this.TEXTURE_CUBE_MAP?t._bindCube:null},_getTexImage(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:c(this,e)?t._bindCube:(this.setError(this.INVALID_ENUM),null)},_checkTextureTarget(e){let t=this._getActiveTextureUnit(),n=null;if(e===this.TEXTURE_2D)n=t._bind2D;else if(e===this.TEXTURE_CUBE_MAP)n=t._bindCube;else return this.setError(this.INVALID_ENUM),!1;return n?!0:(this.setError(this.INVALID_OPERATION),!1)},_validTextureTarget(e){return e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP},_validCubeTarget(e){return e===this.TEXTURE_CUBE_MAP_POSITIVE_X||e===this.TEXTURE_CUBE_MAP_NEGATIVE_X||e===this.TEXTURE_CUBE_MAP_POSITIVE_Y||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Y||e===this.TEXTURE_CUBE_MAP_POSITIVE_Z||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Z},_verifyTextureCompleteness(e,t,n){let r=this._getActiveTextureUnit(),i=null;if(e===this.TEXTURE_2D?i=r._bind2D:this._validCubeTarget(e)&&(i=r._bindCube),this._extensions.oes_texture_float&&!this._extensions.oes_texture_float_linear&&i&&i._type===this.FLOAT&&(t===this.TEXTURE_MAG_FILTER||t===this.TEXTURE_MIN_FILTER)&&(n===this.LINEAR||n===this.LINEAR_MIPMAP_NEAREST||n===this.NEAREST_MIPMAP_LINEAR||n===this.LINEAR_MIPMAP_LINEAR)){i._complete=!1,this.bindTexture(e,i);return}i&&i._complete===!1&&(i._complete=!0,this.bindTexture(e,i))},_computePixelSize(e,t){let n=o(this,t);if(n===0)return this.setError(this.INVALID_ENUM),0;switch(e){case this.UNSIGNED_BYTE:return n;case this.UNSIGNED_SHORT_5_6_5:if(t!==this.RGB){this.setError(this.INVALID_OPERATION);break}return 2;case this.UNSIGNED_SHORT_4_4_4_4:case this.UNSIGNED_SHORT_5_5_5_1:if(t!==this.RGBA){this.setError(this.INVALID_OPERATION);break}return 2;case this.FLOAT:return 1}return this.setError(this.INVALID_ENUM),0},_computeRowStride(e,t){let n=e*t;return n%this._unpackAlignment&&(n+=this._unpackAlignment-n%this._unpackAlignment),n},_checkDimensions(e,t,n,r){if(r<0||t<0||n<0)return this.setError(this.INVALID_VALUE),!1;if(e===this.TEXTURE_2D){if(t>this._maxTextureSize||n>this._maxTextureSize||r>this._maxTextureLevel)return this.setError(this.INVALID_VALUE),!1}else if(this._validCubeTarget(e)){if(t>this._maxCubeMapSize||n>this._maxCubeMapSize||r>this._maxCubeMapLevel)return this.setError(this.INVALID_VALUE),!1}else return this.setError(this.INVALID_ENUM),!1;return!0}};function installTextureManagementMethods(e){Object.assign(e,f)}export{installTextureManagementMethods};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{flag as t}from"./utils.js";import{getOESElementIndexUint as n}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as r}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloat as i}from"./extensions/oes-texture-float.js";import{getOESTextureFloatLinear as a}from"./extensions/oes-texture-float-linear.js";import{getSTACKGLDestroyContext as o}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as s}from"./extensions/stackgl-resize-drawing-buffer.js";import{getEXTBlendMinMax as c}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as l}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as u}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as d}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESTextureHalfFloat as f}from"./extensions/oes-texture-half-float.js";import{WebGLTextureUnit as p}from"./webgl-texture-unit.js";import{WebGLVertexArrayGlobalState as m,WebGLVertexArrayObjectState as h}from"./webgl-vertex-attribute.js";import{installAllContextMethods as g}from"./context/index.js";import _ from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import*as v from"bit-twiddle";import{warnNotImplemented as y}from"@gjsify/utils";let b=0;const x={oes_element_index_uint:n,oes_texture_float:i,oes_texture_float_linear:a,oes_standard_derivatives:r,stackgl_destroy_context:o,stackgl_resize_drawingbuffer:s,ext_blend_minmax:c,ext_color_buffer_float:l,ext_color_buffer_half_float:u,ext_texture_filter_anisotropic:d,oes_texture_half_float:f};var WebGLContextBase=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(n,r={}){this.unpackColorSpace=`srgb`,this.RGBA8=32856,this.DEFAULT_ATTACHMENTS=[],this.DEFAULT_COLOR_ATTACHMENTS=[],this._=0,this._extensions={},this._programs={},this._shaders={},this._textures={},this._framebuffers={},this._renderbuffers={},this._buffers={},this._activeProgram=null,this._activeFramebuffer=null,this._activeRenderbuffer=null,this._checkStencil=!1,this._stencilState=!0,this._activeTextureUnit=0,this._errorStack=[],this._maxTextureSize=0,this._maxTextureLevel=0,this._maxCubeMapSize=0,this._maxCubeMapLevel=0,this._maxRenderbufferSize=0,this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,this.canvas=n,this._contextAttributes=new e(t(r,`alpha`,!0),t(r,`depth`,!0),t(r,`stencil`,!1),!1,t(r,`premultipliedAlpha`,!0),t(r,`preserveDrawingBuffer`,!1),t(r,`preferLowPowerToHighPerformance`,!1),t(r,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this.drawingBufferWidth||0,n=this.drawingBufferHeight||0;this._=b++;let r=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array.from({length:r});for(let e=0;e<r;++e)this._textureUnits[e]=new p(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new h(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new m(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=v.log2(v.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=v.log2(v.nextPow2(this._maxCubeMapSize)),this._maxRenderbufferSize=this.getParameter(this.MAX_RENDERBUFFER_SIZE),this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this.bindBuffer(this.ARRAY_BUFFER,null),this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this.bindFramebuffer(this.FRAMEBUFFER,null),this.bindRenderbuffer(this.RENDERBUFFER,null),this.viewport(0,0,t,n),this.scissor(0,0,t,n),this.clearDepth(1),this.clearColor(0,0,0,0),this.clearStencil(0),this.clear(this.COLOR_BUFFER_BIT|this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),this.disable(this.DEPTH_TEST),this.disable(this.STENCIL_TEST),this.disable(this.BLEND),this.disable(this.CULL_FACE),this.disable(this.POLYGON_OFFSET_FILL),this.disable(this.SCISSOR_TEST),this._gl.colorMask(!0,!0,!0,!0)}_initGLConstants(){let e=new _.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return e?`100`:`120`}_checkOwns(e){return typeof e==`object`&&!!e&&e._ctx===this}_checkValid(e,t){return e instanceof t&&e._!==0}_checkWrapper(e,t){return this._checkValid(e,t)?this._checkOwns(e)?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}_isObject(e,t,n){if(e!=null&&!(e instanceof n))throw TypeError(t+`(`+n.name+`)`);return!!(this._checkValid(e,n)&&this._checkOwns(e))}_checkStencilState(){return this._checkStencil?(this._checkStencil=!1,this._stencilState=!0,(this.getParameter(this.STENCIL_WRITEMASK)!==this.getParameter(this.STENCIL_BACK_WRITEMASK)||this.getParameter(this.STENCIL_VALUE_MASK)!==this.getParameter(this.STENCIL_BACK_VALUE_MASK)||this.getParameter(this.STENCIL_REF)!==this.getParameter(this.STENCIL_BACK_REF))&&(this.setError(this.INVALID_OPERATION),this._stencilState=!1),this._stencilState):this._stencilState}_validGLSLIdentifier(e){return!(e.indexOf(`webgl_`)===0||e.indexOf(`_webgl_`)===0||e.length>256)}_getParameterDirect(e){return this._gl.getParameterx(e)?.deepUnpack()}getContextAttributes(){return this._contextAttributes}getExtension(e){let t=e.toLowerCase();if(t in this._extensions)return this._extensions[t];let n=x[t]?x[t](this):null;return n&&(this._extensions[t]=n),n}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`],t=this._gl.getSupportedExtensions();return t?(t.indexOf(`GL_OES_element_index_uint`)>=0&&e.push(`OES_element_index_uint`),t.indexOf(`GL_OES_standard_derivatives`)>=0&&e.push(`OES_standard_derivatives`),t.indexOf(`GL_OES_texture_float`)>=0&&e.push(`OES_texture_float`),t.indexOf(`GL_OES_texture_float_linear`)>=0&&e.push(`OES_texture_float_linear`),(t.indexOf(`GL_OES_texture_half_float`)>=0||t.indexOf(`GL_ARB_half_float_pixel`)>=0)&&e.push(`OES_texture_half_float`),(t.indexOf(`GL_EXT_color_buffer_float`)>=0||t.indexOf(`GL_ARB_color_buffer_float`)>=0)&&e.push(`EXT_color_buffer_float`),t.indexOf(`GL_EXT_color_buffer_half_float`)>=0&&e.push(`EXT_color_buffer_half_float`),t.indexOf(`EXT_draw_buffers`)>=0&&e.push(`WEBGL_draw_buffers`),t.indexOf(`EXT_blend_minmax`)>=0&&e.push(`EXT_blend_minmax`),t.indexOf(`EXT_texture_filter_anisotropic`)>=0&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),e):e}getParameter(e=0){switch(e){case this.ARRAY_BUFFER_BINDING:return this._vertexGlobalState._arrayBufferBinding;case this.ELEMENT_ARRAY_BUFFER_BINDING:return this._vertexObjectState._elementArrayBufferBinding;case this.CURRENT_PROGRAM:return this._activeProgram;case this.FRAMEBUFFER_BINDING:return this._activeFramebuffer;case this.RENDERBUFFER_BINDING:return this._activeRenderbuffer;case this.TEXTURE_BINDING_2D:return this._getActiveTextureUnit()._bind2D;case this.TEXTURE_BINDING_CUBE_MAP:return this._getActiveTextureUnit()._bindCube;case this.VERSION:return`WebGL 1.0 0.0.1`;case this.VENDOR:return``;case this.RENDERER:return`ANGLE`;case this.SHADING_LANGUAGE_VERSION:return`WebGL GLSL ES 1.0 `;case this.COMPRESSED_TEXTURE_FORMATS:return new Uint32Array;case this.SCISSOR_BOX:return new Int32Array(this._scissorBox);case this.VIEWPORT:return new Int32Array(this._viewport);case this.MAX_VIEWPORT_DIMS:return new Int32Array([32767,32767]);case this.ALIASED_LINE_WIDTH_RANGE:case this.ALIASED_POINT_SIZE_RANGE:return new Float32Array([1,1]);case this.DEPTH_RANGE:return new Float32Array([0,1]);case this.BLEND_COLOR:case this.COLOR_CLEAR_VALUE:return new Float32Array(this._gl.getParameterfv(e,4));case this.COLOR_WRITEMASK:{let t=this._gl.getParameteriv(e,4);return[!!t[0],!!t[1],!!t[2],!!t[3]]}case this.DEPTH_CLEAR_VALUE:case this.LINE_WIDTH:case this.POLYGON_OFFSET_FACTOR:case this.POLYGON_OFFSET_UNITS:case this.SAMPLE_COVERAGE_VALUE:return this._gl.getParameterf(e);case this.BLEND:case this.CULL_FACE:case this.DEPTH_TEST:case this.DEPTH_WRITEMASK:case this.DITHER:case this.POLYGON_OFFSET_FILL:case this.SAMPLE_COVERAGE_INVERT:case this.SCISSOR_TEST:case this.STENCIL_TEST:case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL:return!!this._gl.getParameteri(e);case this.UNPACK_FLIP_Y_WEBGL:return this._unpackFlipY;case this.ACTIVE_TEXTURE:case this.ALPHA_BITS:case this.BLEND_DST_ALPHA:case this.BLEND_DST_RGB:case this.BLEND_EQUATION_ALPHA:case this.BLEND_EQUATION_RGB:case this.BLEND_SRC_ALPHA:case this.BLEND_SRC_RGB:case this.BLUE_BITS:case this.CULL_FACE_MODE:case this.DEPTH_BITS:case this.DEPTH_FUNC:case this.FRONT_FACE:case this.GENERATE_MIPMAP_HINT:case this.GREEN_BITS:case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS:case this.MAX_RENDERBUFFER_SIZE:case this.MAX_TEXTURE_IMAGE_UNITS:case this.MAX_TEXTURE_SIZE:case this.MAX_VARYING_VECTORS:case this.MAX_VERTEX_ATTRIBS:case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:case this.MAX_VERTEX_UNIFORM_VECTORS:case this.PACK_ALIGNMENT:case this.RED_BITS:case this.SAMPLE_BUFFERS:case this.SAMPLES:case this.STENCIL_BACK_FAIL:case this.STENCIL_BACK_FUNC:case this.STENCIL_BACK_PASS_DEPTH_FAIL:case this.STENCIL_BACK_PASS_DEPTH_PASS:case this.STENCIL_BACK_REF:case this.STENCIL_BACK_VALUE_MASK:case this.STENCIL_BACK_WRITEMASK:case this.STENCIL_BITS:case this.STENCIL_CLEAR_VALUE:case this.STENCIL_FAIL:case this.STENCIL_FUNC:case this.STENCIL_PASS_DEPTH_FAIL:case this.STENCIL_PASS_DEPTH_PASS:case this.STENCIL_REF:case this.STENCIL_VALUE_MASK:case this.STENCIL_WRITEMASK:case this.SUBPIXEL_BITS:case this.UNPACK_ALIGNMENT:case this.UNPACK_COLORSPACE_CONVERSION_WEBGL:return this._gl.getParameteri(e);case this.IMPLEMENTATION_COLOR_READ_FORMAT:case this.IMPLEMENTATION_COLOR_READ_TYPE:return this._getParameterDirect(e);default:if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;switch(e){case t.DRAW_BUFFER0_WEBGL:case t.DRAW_BUFFER1_WEBGL:case t.DRAW_BUFFER2_WEBGL:case t.DRAW_BUFFER3_WEBGL:case t.DRAW_BUFFER4_WEBGL:case t.DRAW_BUFFER5_WEBGL:case t.DRAW_BUFFER6_WEBGL:case t.DRAW_BUFFER7_WEBGL:case t.DRAW_BUFFER8_WEBGL:case t.DRAW_BUFFER9_WEBGL:case t.DRAW_BUFFER10_WEBGL:case t.DRAW_BUFFER11_WEBGL:case t.DRAW_BUFFER12_WEBGL:case t.DRAW_BUFFER13_WEBGL:case t.DRAW_BUFFER14_WEBGL:case t.DRAW_BUFFER15_WEBGL:return t._buffersState.length===1&&t._buffersState[0]===this.BACK?this.BACK:this._getParameterDirect(e);case t.MAX_DRAW_BUFFERS_WEBGL:case t.MAX_COLOR_ATTACHMENTS_WEBGL:return this._getParameterDirect(e)}}return this._extensions.oes_standard_derivatives&&e===this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES||this._extensions.ext_texture_filter_anisotropic&&e===this._extensions.ext_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT?this._getParameterDirect(e):this._extensions.oes_vertex_array_object&&e===this._extensions.oes_vertex_array_object.VERTEX_ARRAY_BINDING_OES?this._extensions.oes_vertex_array_object._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}destroy(){y(`destroy`)}};g(WebGLContextBase.prototype);export{WebGLContextBase};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{flag as t}from"./utils.js";import{getOESElementIndexUint as n}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as r}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloat as i}from"./extensions/oes-texture-float.js";import{getOESTextureFloatLinear as a}from"./extensions/oes-texture-float-linear.js";import{getSTACKGLDestroyContext as o}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as s}from"./extensions/stackgl-resize-drawing-buffer.js";import{getEXTBlendMinMax as c}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as l}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as u}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as d}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESTextureHalfFloat as f}from"./extensions/oes-texture-half-float.js";import{WebGLTextureUnit as p}from"./webgl-texture-unit.js";import{WebGLVertexArrayGlobalState as m,WebGLVertexArrayObjectState as h}from"./webgl-vertex-attribute.js";import{installAllContextMethods as g}from"./context/index.js";import _ from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import*as v from"bit-twiddle";import{warnNotImplemented as y}from"@gjsify/utils";let b=0;const x={oes_element_index_uint:n,oes_texture_float:i,oes_texture_float_linear:a,oes_standard_derivatives:r,stackgl_destroy_context:o,stackgl_resize_drawingbuffer:s,ext_blend_minmax:c,ext_color_buffer_float:l,ext_color_buffer_half_float:u,ext_texture_filter_anisotropic:d,oes_texture_half_float:f};var WebGLContextBase=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(n,r={}){this.unpackColorSpace=`srgb`,this.RGBA8=32856,this.DEFAULT_ATTACHMENTS=[],this.DEFAULT_COLOR_ATTACHMENTS=[],this._=0,this._extensions={},this._programs={},this._shaders={},this._textures={},this._framebuffers={},this._renderbuffers={},this._buffers={},this._activeProgram=null,this._activeFramebuffer=null,this._activeRenderbuffer=null,this._checkStencil=!1,this._stencilState=!0,this._activeTextureUnit=0,this._errorStack=[],this._maxTextureSize=0,this._maxTextureLevel=0,this._maxCubeMapSize=0,this._maxCubeMapLevel=0,this._maxRenderbufferSize=0,this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,this.canvas=n,this._contextAttributes=new e(t(r,`alpha`,!0),t(r,`depth`,!0),t(r,`stencil`,!1),!1,t(r,`premultipliedAlpha`,!0),t(r,`preserveDrawingBuffer`,!1),t(r,`preferLowPowerToHighPerformance`,!1),t(r,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this.drawingBufferWidth||0,n=this.drawingBufferHeight||0;this._=b++;let r=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array.from({length:r});for(let e=0;e<r;++e)this._textureUnits[e]=new p(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new h(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new m(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=v.log2(v.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=v.log2(v.nextPow2(this._maxCubeMapSize)),this._maxRenderbufferSize=this.getParameter(this.MAX_RENDERBUFFER_SIZE),this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this.bindBuffer(this.ARRAY_BUFFER,null),this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this.bindFramebuffer(this.FRAMEBUFFER,null),this.bindRenderbuffer(this.RENDERBUFFER,null),this.viewport(0,0,t,n),this.scissor(0,0,t,n),this.clearDepth(1),this.clearColor(0,0,0,0),this.clearStencil(0),this.clear(this.COLOR_BUFFER_BIT|this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),this.disable(this.DEPTH_TEST),this.disable(this.STENCIL_TEST),this.disable(this.BLEND),this.disable(this.CULL_FACE),this.disable(this.POLYGON_OFFSET_FILL),this.disable(this.SCISSOR_TEST),this._gl.colorMask(!0,!0,!0,!0)}_initGLConstants(){let e=new _.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return e?`100`:`120`}_checkOwns(e){return typeof e==`object`&&!!e&&e._ctx===this}_checkValid(e,t){return e instanceof t&&e._!==0}_checkWrapper(e,t){return this._checkValid(e,t)?this._checkOwns(e)?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}_isObject(e,t,n){if(e!=null&&!(e instanceof n))throw TypeError(t+`(`+n.name+`)`);return!!(this._checkValid(e,n)&&this._checkOwns(e))}_checkStencilState(){return this._checkStencil?(this._checkStencil=!1,this._stencilState=!0,(this.getParameter(this.STENCIL_WRITEMASK)!==this.getParameter(this.STENCIL_BACK_WRITEMASK)||this.getParameter(this.STENCIL_VALUE_MASK)!==this.getParameter(this.STENCIL_BACK_VALUE_MASK)||this.getParameter(this.STENCIL_REF)!==this.getParameter(this.STENCIL_BACK_REF))&&(this.setError(this.INVALID_OPERATION),this._stencilState=!1),this._stencilState):this._stencilState}_validGLSLIdentifier(e){return!(e.indexOf(`webgl_`)===0||e.indexOf(`_webgl_`)===0||e.length>256)}_getParameterDirect(e){return this._gl.getParameterx(e)?.deepUnpack()}getContextAttributes(){return this._contextAttributes}getExtension(e){let t=e.toLowerCase();if(t in this._extensions)return this._extensions[t];let n=x[t]?x[t](this):null;return n&&(this._extensions[t]=n),n}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`],t=this._gl.getSupportedExtensions();return t?(t.indexOf(`GL_OES_element_index_uint`)>=0&&e.push(`OES_element_index_uint`),t.indexOf(`GL_OES_standard_derivatives`)>=0&&e.push(`OES_standard_derivatives`),t.indexOf(`GL_OES_texture_float`)>=0&&e.push(`OES_texture_float`),t.indexOf(`GL_OES_texture_float_linear`)>=0&&e.push(`OES_texture_float_linear`),(t.indexOf(`GL_OES_texture_half_float`)>=0||t.indexOf(`GL_ARB_half_float_pixel`)>=0)&&e.push(`OES_texture_half_float`),(t.indexOf(`GL_EXT_color_buffer_float`)>=0||t.indexOf(`GL_ARB_color_buffer_float`)>=0)&&e.push(`EXT_color_buffer_float`),t.indexOf(`GL_EXT_color_buffer_half_float`)>=0&&e.push(`EXT_color_buffer_half_float`),t.indexOf(`EXT_draw_buffers`)>=0&&e.push(`WEBGL_draw_buffers`),t.indexOf(`EXT_blend_minmax`)>=0&&e.push(`EXT_blend_minmax`),t.indexOf(`EXT_texture_filter_anisotropic`)>=0&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),e):e}getParameter(e=0){switch(e){case this.ARRAY_BUFFER_BINDING:return this._vertexGlobalState._arrayBufferBinding;case this.ELEMENT_ARRAY_BUFFER_BINDING:return this._vertexObjectState._elementArrayBufferBinding;case this.CURRENT_PROGRAM:return this._activeProgram;case this.FRAMEBUFFER_BINDING:return this._activeFramebuffer;case this.RENDERBUFFER_BINDING:return this._activeRenderbuffer;case this.TEXTURE_BINDING_2D:return this._getActiveTextureUnit()._bind2D;case this.TEXTURE_BINDING_CUBE_MAP:return this._getActiveTextureUnit()._bindCube;case this.VERSION:return`WebGL 1.0 0.0.1`;case this.VENDOR:return``;case this.RENDERER:return`ANGLE`;case this.SHADING_LANGUAGE_VERSION:return`WebGL GLSL ES 1.0 `;case this.COMPRESSED_TEXTURE_FORMATS:return new Uint32Array;case this.SCISSOR_BOX:return new Int32Array(this._scissorBox);case this.VIEWPORT:return new Int32Array(this._viewport);case this.MAX_VIEWPORT_DIMS:return new Int32Array([32767,32767]);case this.ALIASED_LINE_WIDTH_RANGE:case this.ALIASED_POINT_SIZE_RANGE:return new Float32Array([1,1]);case this.DEPTH_RANGE:return new Float32Array([0,1]);case this.BLEND_COLOR:case this.COLOR_CLEAR_VALUE:return new Float32Array(this._gl.getParameterfv(e,4));case this.COLOR_WRITEMASK:{let t=this._gl.getParameteriv(e,4);return[!!t[0],!!t[1],!!t[2],!!t[3]]}case this.DEPTH_CLEAR_VALUE:case this.LINE_WIDTH:case this.POLYGON_OFFSET_FACTOR:case this.POLYGON_OFFSET_UNITS:case this.SAMPLE_COVERAGE_VALUE:return this._gl.getParameterf(e);case this.BLEND:case this.CULL_FACE:case this.DEPTH_TEST:case this.DEPTH_WRITEMASK:case this.DITHER:case this.POLYGON_OFFSET_FILL:case this.SAMPLE_COVERAGE_INVERT:case this.SCISSOR_TEST:case this.STENCIL_TEST:case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL:return!!this._gl.getParameteri(e);case this.UNPACK_FLIP_Y_WEBGL:return this._unpackFlipY;case this.ACTIVE_TEXTURE:case this.ALPHA_BITS:case this.BLEND_DST_ALPHA:case this.BLEND_DST_RGB:case this.BLEND_EQUATION_ALPHA:case this.BLEND_EQUATION_RGB:case this.BLEND_SRC_ALPHA:case this.BLEND_SRC_RGB:case this.BLUE_BITS:case this.CULL_FACE_MODE:case this.DEPTH_BITS:case this.DEPTH_FUNC:case this.FRONT_FACE:case this.GENERATE_MIPMAP_HINT:case this.GREEN_BITS:case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS:case this.MAX_RENDERBUFFER_SIZE:case this.MAX_TEXTURE_IMAGE_UNITS:case this.MAX_TEXTURE_SIZE:case this.MAX_VARYING_VECTORS:case this.MAX_VERTEX_ATTRIBS:case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:case this.MAX_VERTEX_UNIFORM_VECTORS:case this.PACK_ALIGNMENT:case this.RED_BITS:case this.SAMPLE_BUFFERS:case this.SAMPLES:case this.STENCIL_BACK_FAIL:case this.STENCIL_BACK_FUNC:case this.STENCIL_BACK_PASS_DEPTH_FAIL:case this.STENCIL_BACK_PASS_DEPTH_PASS:case this.STENCIL_BACK_REF:case this.STENCIL_BACK_VALUE_MASK:case this.STENCIL_BACK_WRITEMASK:case this.STENCIL_BITS:case this.STENCIL_CLEAR_VALUE:case this.STENCIL_FAIL:case this.STENCIL_FUNC:case this.STENCIL_PASS_DEPTH_FAIL:case this.STENCIL_PASS_DEPTH_PASS:case this.STENCIL_REF:case this.STENCIL_VALUE_MASK:case this.STENCIL_WRITEMASK:case this.SUBPIXEL_BITS:case this.UNPACK_ALIGNMENT:case this.UNPACK_COLORSPACE_CONVERSION_WEBGL:return this._gl.getParameteri(e);case this.IMPLEMENTATION_COLOR_READ_FORMAT:case this.IMPLEMENTATION_COLOR_READ_TYPE:return this._getParameterDirect(e);default:if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;switch(e){case t.DRAW_BUFFER0_WEBGL:case t.DRAW_BUFFER1_WEBGL:case t.DRAW_BUFFER2_WEBGL:case t.DRAW_BUFFER3_WEBGL:case t.DRAW_BUFFER4_WEBGL:case t.DRAW_BUFFER5_WEBGL:case t.DRAW_BUFFER6_WEBGL:case t.DRAW_BUFFER7_WEBGL:case t.DRAW_BUFFER8_WEBGL:case t.DRAW_BUFFER9_WEBGL:case t.DRAW_BUFFER10_WEBGL:case t.DRAW_BUFFER11_WEBGL:case t.DRAW_BUFFER12_WEBGL:case t.DRAW_BUFFER13_WEBGL:case t.DRAW_BUFFER14_WEBGL:case t.DRAW_BUFFER15_WEBGL:return t._buffersState.length===1&&t._buffersState[0]===this.BACK?this.BACK:this._getParameterDirect(e);case t.MAX_DRAW_BUFFERS_WEBGL:case t.MAX_COLOR_ATTACHMENTS_WEBGL:return this._getParameterDirect(e)}}let t=this._extensions.oes_standard_derivatives;if(t&&e===t.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)return this._getParameterDirect(e);let n=this._extensions.ext_texture_filter_anisotropic;if(n&&e===n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)return this._getParameterDirect(e);let r=this._extensions.oes_vertex_array_object;return r&&e===r.VERTEX_ARRAY_BINDING_OES?r._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}destroy(){y(`destroy`)}};g(WebGLContextBase.prototype);export{WebGLContextBase};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,vertexCount as t}from"./utils.js";import{WebGLContextBase as n}from"./webgl-context-base.js";import r from"@girs/gwebgl-0.1";var WebGLRenderingContext=class extends n{get _gl(){return this._native}constructor(e,t={}){super(e,t),this._attrib0Buffer=null,this._native=new r.WebGLRenderingContext({}),this._init();let n=this.createBuffer();this._attrib0Buffer=n}_beginAttrib0Hack(){this._native.bindBuffer(this.ARRAY_BUFFER,this._attrib0Buffer?._||0);let t=new Uint8Array(this._vertexGlobalState._attribs[0]._data.buffer);this._native.bufferData(this.ARRAY_BUFFER,e(t),this.STREAM_DRAW),this._native.enableVertexAttribArray(0),this._native.vertexAttribPointer(0,4,this.FLOAT,!1,0,0),this._native._vertexAttribDivisor(0,1)}_endAttrib0Hack(){let e=this._vertexObjectState._attribs[0];e._pointerBuffer?this._native.bindBuffer(this.ARRAY_BUFFER,e._pointerBuffer._):this._native.bindBuffer(this.ARRAY_BUFFER,0),this._native.vertexAttribPointer(0,e._inputSize,e._pointerType,e._pointerNormal,e._inputStride,e._pointerOffset),this._native._vertexAttribDivisor(0,e._divisor),this._native.disableVertexAttribArray(0),this._vertexGlobalState._arrayBufferBinding?this._native.bindBuffer(this.ARRAY_BUFFER,this._vertexGlobalState._arrayBufferBinding._):this._native.bindBuffer(this.ARRAY_BUFFER,0)}drawArrays(e=0,n=0,r=0){if(n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=t(this,e,r);if(i<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||r===0)return;let a=n;if(r>0&&(a=r+n-1>>>0),this._checkVertexAttribState(a)){if(this._vertexObjectState._attribs[0]._isPointer||
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,vertexCount as t}from"./utils.js";import{WebGLContextBase as n}from"./webgl-context-base.js";import r from"@girs/gwebgl-0.1";var WebGLRenderingContext=class extends n{get _gl(){return this._native}constructor(e,t={}){super(e,t),this._attrib0Buffer=null,this._native=new r.WebGLRenderingContext({}),this._init();let n=this.createBuffer();this._attrib0Buffer=n}_beginAttrib0Hack(){this._native.bindBuffer(this.ARRAY_BUFFER,this._attrib0Buffer?._||0);let t=new Uint8Array(this._vertexGlobalState._attribs[0]._data.buffer);this._native.bufferData(this.ARRAY_BUFFER,e(t),this.STREAM_DRAW),this._native.enableVertexAttribArray(0),this._native.vertexAttribPointer(0,4,this.FLOAT,!1,0,0),this._native._vertexAttribDivisor(0,1)}_endAttrib0Hack(){let e=this._vertexObjectState._attribs[0];e._pointerBuffer?this._native.bindBuffer(this.ARRAY_BUFFER,e._pointerBuffer._):this._native.bindBuffer(this.ARRAY_BUFFER,0),this._native.vertexAttribPointer(0,e._inputSize,e._pointerType,e._pointerNormal,e._inputStride,e._pointerOffset),this._native._vertexAttribDivisor(0,e._divisor),this._native.disableVertexAttribArray(0),this._vertexGlobalState._arrayBufferBinding?this._native.bindBuffer(this.ARRAY_BUFFER,this._vertexGlobalState._arrayBufferBinding._):this._native.bindBuffer(this.ARRAY_BUFFER,0)}drawArrays(e=0,n=0,r=0){if(n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=t(this,e,r);if(i<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||r===0)return;let a=n;if(r>0&&(a=r+n-1>>>0),this._checkVertexAttribState(a)){let t=this._extensions.webgl_draw_buffers;if(this._vertexObjectState._attribs[0]._isPointer||t&&t._buffersState&&t._buffersState.length>0)return this._native.drawArrays(e,n,i);this._beginAttrib0Hack(),this._native._drawArraysInstanced(e,n,i,1),this._endAttrib0Hack()}}drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(this._extensions.oes_element_index_uint&&n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk())return;if(t===0){this._checkVertexAttribState(0);return}if(t+o>>>0>a.length){this.setError(this.INVALID_OPERATION);return}let c=-1;for(let e=o;e<o+t;++e)c=Math.max(c,a[e]);if(c<0){this._checkVertexAttribState(0);return}if(this._checkVertexAttribState(c)&&s>0){if(this._vertexObjectState._attribs[0]._isPointer)return this._native.drawElements(e,s,n,r);this._beginAttrib0Hack(),this._native._drawElementsInstanced(e,s,n,r,1),this._endAttrib0Hack()}}};export{n as WebGLContextBase,WebGLRenderingContext};
|
|
@@ -27,5 +27,5 @@ export declare class HTMLCanvasElement extends BaseHTMLCanvasElement {
|
|
|
27
27
|
* 'webgl2' returns a WebGL2RenderingContext (WebGL 2.0).
|
|
28
28
|
* Other context types emit a warning and return null.
|
|
29
29
|
*/
|
|
30
|
-
getContext(contextId: string, options?:
|
|
30
|
+
getContext(contextId: string, options?: unknown): unknown;
|
|
31
31
|
}
|
package/lib/types/linkable.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export declare class Linkable {
|
|
2
2
|
_: number;
|
|
3
|
-
_references:
|
|
3
|
+
_references: Linkable[];
|
|
4
4
|
_refCount: number;
|
|
5
5
|
_pendingDelete: boolean;
|
|
6
6
|
_binding: number;
|
|
7
7
|
constructor(_: number);
|
|
8
|
-
_link(b:
|
|
9
|
-
_unlink(b:
|
|
10
|
-
_linked(b:
|
|
8
|
+
_link(b: Linkable): boolean;
|
|
9
|
+
_unlink(b: Linkable): boolean;
|
|
10
|
+
_linked(b: Linkable): boolean;
|
|
11
11
|
_checkDelete(): void;
|
|
12
12
|
_performDelete(): void;
|
|
13
13
|
}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import type { WebGLContextBase } from '../webgl-context-base.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Each WebGL extension exposes its own heterogeneous surface (GL enum constants
|
|
4
|
+
* plus extension-specific methods). The factory returns a concrete extension
|
|
5
|
+
* class instance whose exact shape varies per extension; consumers narrow with
|
|
6
|
+
* `instanceof` when they need a specific extension's API.
|
|
7
|
+
*/
|
|
8
|
+
export type ExtensionInstance = object;
|
|
9
|
+
export type ExtensionFactory = (context: WebGLContextBase) => ExtensionInstance | null;
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { HTMLImageElement } from '@gjsify/dom-elements';
|
|
|
5
5
|
import type { WebGLContextBase } from './webgl-context-base.js';
|
|
6
6
|
import type { TypedArray } from './types/index.js';
|
|
7
7
|
export declare function bindPublics(props: Array<keyof WebGLContextBase>, wrapper: WebGLContextBase, privateInstance: WebGLContextBase, privateMethods: string[]): void;
|
|
8
|
-
export declare function checkObject(object:
|
|
8
|
+
export declare function checkObject(object: unknown): boolean;
|
|
9
9
|
export declare function checkUniform(program: WebGLProgram, location: WebGLUniformLocation): boolean;
|
|
10
10
|
export declare function isTypedArray(data: TypedArray): data is Uint8Array<ArrayBufferLike> | Uint8ClampedArray<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>;
|
|
11
11
|
export declare function isValidString(str: string): boolean;
|
|
@@ -27,7 +27,7 @@ export declare function formatSize(gl: WebGLContextBase, internalFormat: number)
|
|
|
27
27
|
export declare function convertPixels(pixels: ArrayBuffer | Uint8Array | Uint16Array | Uint8ClampedArray | Float32Array | Buffer | ArrayBufferView | null): Uint8Array<ArrayBufferLike>;
|
|
28
28
|
export declare function checkFormat(gl: WebGLContextBase, format: GLenum): format is 6406 | 6407 | 6408 | 6409 | 6410;
|
|
29
29
|
export declare function validCubeTarget(gl: WebGLContextBase, target: GLenum): target is 34069 | 34070 | 34071 | 34072 | 34073 | 34074;
|
|
30
|
-
export declare function flag<T = Record<string,
|
|
30
|
+
export declare function flag<T = Record<string, unknown>>(options: T, name: keyof T, dflt: boolean): boolean;
|
|
31
31
|
/**
|
|
32
32
|
* Premultiply RGB channels by the alpha channel (in-place copy).
|
|
33
33
|
* Required when UNPACK_PREMULTIPLY_ALPHA_WEBGL is set.
|
|
@@ -13,12 +13,12 @@ import { WebGLTextureUnit } from './webgl-texture-unit.js';
|
|
|
13
13
|
import { WebGLVertexArrayObjectState, WebGLVertexArrayGlobalState } from './webgl-vertex-attribute.js';
|
|
14
14
|
import type { WebGLConstants } from './types/index.js';
|
|
15
15
|
/**
|
|
16
|
-
* Per-extension structural type.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* Per-extension structural type. Each extension is a concrete class instance
|
|
17
|
+
* created by an `ExtensionFactory`, with its own heterogenous GL constants and
|
|
18
|
+
* methods. We track them as plain `object` here and structurally narrow at the
|
|
19
|
+
* access site (e.g. `(ext as { COLOR_ATTACHMENT0_WEBGL: GLenum })`).
|
|
20
20
|
*/
|
|
21
|
-
type WebGLExtensionLike =
|
|
21
|
+
type WebGLExtensionLike = object;
|
|
22
22
|
export interface WebGLContextBase extends WebGLConstants {
|
|
23
23
|
}
|
|
24
24
|
export declare abstract class WebGLContextBase {
|
|
@@ -48,7 +48,7 @@ export declare abstract class WebGLContextBase {
|
|
|
48
48
|
* for that name. Each extension has its own surface area, so we keep this
|
|
49
49
|
* loose-typed but no longer `any`.
|
|
50
50
|
*/
|
|
51
|
-
_extensions: Record<string, WebGLExtensionLike
|
|
51
|
+
_extensions: Record<string, WebGLExtensionLike>;
|
|
52
52
|
_programs: Record<number, WebGLProgram>;
|
|
53
53
|
_shaders: Record<number, WebGLShader>;
|
|
54
54
|
_textures: Record<number, WebGLTexture>;
|
|
@@ -61,7 +61,7 @@ export declare class WebGL2RenderingContext extends WebGLContextBase implements
|
|
|
61
61
|
* The base class handles CA0, DEPTH, STENCIL, DEPTH_STENCIL and calls
|
|
62
62
|
* _preCheckFramebufferStatus (which we override to query native GL).
|
|
63
63
|
*/
|
|
64
|
-
_updateFramebufferAttachments(framebuffer:
|
|
64
|
+
_updateFramebufferAttachments(framebuffer: WebGLFramebuffer | null): void;
|
|
65
65
|
/** WebGL2 adds UNIFORM_BUFFER, TRANSFORM_FEEDBACK_BUFFER, etc. targets. */
|
|
66
66
|
bindBuffer(target: GLenum, buffer: WebGLBuffer | null): void;
|
|
67
67
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webgl",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.32",
|
|
4
4
|
"description": "WebGL module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -16,7 +16,12 @@
|
|
|
16
16
|
"prebuilds"
|
|
17
17
|
],
|
|
18
18
|
"gjsify": {
|
|
19
|
-
"prebuilds": "prebuilds"
|
|
19
|
+
"prebuilds": "prebuilds",
|
|
20
|
+
"runtimes": {
|
|
21
|
+
"gjs": "polyfill",
|
|
22
|
+
"node": "none",
|
|
23
|
+
"browser": "none"
|
|
24
|
+
}
|
|
20
25
|
},
|
|
21
26
|
"scripts": {
|
|
22
27
|
"clear": "rm -rf lib tmp build test.gjs.mjs tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
|
|
@@ -39,8 +44,8 @@
|
|
|
39
44
|
"WebGL"
|
|
40
45
|
],
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@gjsify/cli": "^0.4.
|
|
43
|
-
"@gjsify/unit": "^0.4.
|
|
47
|
+
"@gjsify/cli": "^0.4.32",
|
|
48
|
+
"@gjsify/unit": "^0.4.32",
|
|
44
49
|
"@types/bit-twiddle": "^1.0.3",
|
|
45
50
|
"@types/node": "^25.9.1",
|
|
46
51
|
"typescript": "^6.0.3"
|
|
@@ -49,10 +54,10 @@
|
|
|
49
54
|
"@girs/gjs": "4.0.1",
|
|
50
55
|
"@girs/gtk-4.0": "4.23.0-4.0.1",
|
|
51
56
|
"@girs/gwebgl-0.1": "0.1.0-4.0.0-rc.5",
|
|
52
|
-
"@gjsify/dom-elements": "^0.4.
|
|
53
|
-
"@gjsify/dom-events": "^0.4.
|
|
54
|
-
"@gjsify/event-bridge": "^0.4.
|
|
55
|
-
"@gjsify/utils": "^0.4.
|
|
57
|
+
"@gjsify/dom-elements": "^0.4.32",
|
|
58
|
+
"@gjsify/dom-events": "^0.4.32",
|
|
59
|
+
"@gjsify/event-bridge": "^0.4.32",
|
|
60
|
+
"@gjsify/utils": "^0.4.32",
|
|
56
61
|
"bit-twiddle": "^1.0.2",
|
|
57
62
|
"glsl-tokenizer": "^2.1.5"
|
|
58
63
|
}
|