@gjsify/webgl 0.4.24 → 0.4.25

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.
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";const e={clearBufferfv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfv==`function`){i.clearBufferfv(e,t,Array.from(n));return}let a=n;if(e===6144){let e=this.getParameter(this.COLOR_CLEAR_VALUE);this.clearColor(a[0]??0,a[1]??0,a[2]??0,a[3]??0),this.clear(this.COLOR_BUFFER_BIT),e&&this.clearColor(e[0],e[1],e[2],e[3])}else if(e===6145){let e=this.getParameter(this.DEPTH_CLEAR_VALUE);this.clearDepth(a[0]??1),this.clear(this.DEPTH_BUFFER_BIT),e!==null&&this.clearDepth(e)}},clearBufferiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferiv==`function`){i.clearBufferiv(e,t,Array.from(n));return}if(e===6146){let e=n,t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearStencil(e[0]??0),this.clear(this.STENCIL_BUFFER_BIT),t!==null&&this.clearStencil(t)}},clearBufferuiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferuiv==`function`){i.clearBufferuiv(e,t,Array.from(n));return}},clearBufferfi(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfi==`function`){i.clearBufferfi(e,t,n,r);return}if(e===34041){let e=this.getParameter(this.DEPTH_CLEAR_VALUE),t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearDepth(n),this.clearStencil(r),this.clear(this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),e!==null&&this.clearDepth(e),t!==null&&this.clearStencil(t)}}};function installClearBufferMethods(t){Object.assign(t,e)}export{installClearBufferMethods};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{vertexCount as e}from"../utils.js";function debugGlEnabled(){return globalThis.__GJSIFY_DEBUG_GL===!0}const t={drawArraysInstanced(t,n,r,i){if(n<0||r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let a=e(this,t,r);if(a<0){this.setError(this.INVALID_ENUM);return}if(this._framebufferOk()&&!(r===0||i===0)&&this._checkVertexAttribState(r+n-1>>>0)){if(debugGlEnabled()){let e=this,t=e.__drawInstCount=(e.__drawInstCount|0)+1;(t<=5||t%100==0)&&console.log(`[WebGL] drawArraysInstanced #${t} count=${a} instances=${i} fbo=${this._activeFramebuffer?._??`_gtkFbo`}`)}this._native2.drawArraysInstanced(t,n,a,i)}},drawElementsInstanced(e,t,n,r,i){if(t<0||r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let a=this._vertexObjectState._elementArrayBufferBinding;if(!a){this.setError(this.INVALID_OPERATION);return}let o=null,s=r;if(n===this.UNSIGNED_SHORT){if(s%2){this.setError(this.INVALID_OPERATION);return}s>>=1,o=new Uint16Array(a._elements.buffer)}else if(n===this.UNSIGNED_INT){if(s%4){this.setError(this.INVALID_OPERATION);return}s>>=2,o=new Uint32Array(a._elements.buffer)}else if(n===this.UNSIGNED_BYTE)o=a._elements;else{this.setError(this.INVALID_ENUM);return}let c=t;switch(e){case this.TRIANGLES:t%3&&(c-=t%3);break;case this.LINES:t%2&&(c-=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(c===0||i===0){this._checkVertexAttribState(0);return}if(c+s>>>0>o.length){this.setError(this.INVALID_OPERATION);return}let l=0;for(let e=s;e<s+c;++e)o[e]>l&&(l=o[e]);this._checkVertexAttribState(l)&&this._native2.drawElementsInstanced(e,c,n,r,i)},vertexAttribDivisor(e,t){this._native2.vertexAttribDivisor(e,t)},vertexAttribIPointer(e,t,n,r,i){this._native2.vertexAttribIPointer(e,t,n,r,i)},drawBuffers(e){let t=!1;for(let n=0;n<e.length;n++)if(e[n]===1029){t=!0;break}if(!t){this._native2.drawBuffers(e);return}this._native2.drawBuffers(e.map(e=>e===1029?this.COLOR_ATTACHMENT0:e))},drawRangeElements(e,t,n,r,i,a){if(r<0||a<0){this.setError(this.INVALID_VALUE);return}if(n<t){this.setError(this.INVALID_VALUE);return}this.drawElements(e,r,i,a)},blitFramebuffer(e,t,n,r,i,a,o,s,c,l){if(debugGlEnabled()){let e=this._gl.getError();e!==0&&console.log(`[WebGL] blitFramebuffer PRE-ERROR 0x${e.toString(16)}`)}if(this._native2.blitFramebuffer(e,t,n,r,i,a,o,s,c,l),debugGlEnabled()){let i=this._gl.getError(),a=this,o=a.__blitCount=(a.__blitCount|0)+1;o<=5&&console.log(`[WebGL] blitFramebuffer #${o} src=(${e},${t},${n},${r}) readFbo=${this._activeReadFramebuffer?._??`_gtkFbo`} err=${i===0?`OK`:`0x`+i.toString(16)}`)}},framebufferTextureLayer(e,t,n,r,i){this._native2.framebufferTextureLayer(e,t,n?n._:0,r,i)},invalidateFramebuffer(e,t){this._native2.invalidateFramebuffer(e,t)},invalidateSubFramebuffer(e,t,n,r,i,a){this._native2.invalidateSubFramebuffer(e,t,n,r,i,a)},readBuffer(e){this._native2.readBuffer(e)},renderbufferStorageMultisample(e,t,n,r,i){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let a=this._activeRenderbuffer;if(!a){this.setError(this.INVALID_OPERATION);return}this._saveError(),this._native2.renderbufferStorageMultisample(e,t,n,r,i);let o=this.getError();this._restoreError(o),o===this.NO_ERROR&&(a._width=r,a._height=i,a._format=n)}};function installInstancedAndFramebufferOpsMethods(e){Object.assign(e,t)}export{installInstancedAndFramebufferOpsMethods};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e}from"../utils.js";const t={texImage3D(t,n,r,i,a,o,s,c,l,u){u===null?this._native2.texImage3DNull(t,n,r,i,a,o,s,c,l):this._native2.texImage3D(t,n,r,i,a,o,s,c,l,e(new Uint8Array(u.buffer,u.byteOffset,u.byteLength)))},texSubImage3D(t,n,r,i,a,o,s,c,l,u,d){d!==null&&this._native2.texSubImage3D(t,n,r,i,a,o,s,c,l,u,e(new Uint8Array(d.buffer,d.byteOffset,d.byteLength)))},compressedTexImage3D(t,n,r,i,a,o,s,c,l){this._native2.compressedTexImage3D(t,n,r,i,a,o,s,e(new Uint8Array(l.buffer,l.byteOffset,l.byteLength)))},compressedTexSubImage3D(t,n,r,i,a,o,s,c,l,u,d){this._native2.compressedTexSubImage3D(t,n,r,i,a,o,s,c,l,e(new Uint8Array(d.buffer,d.byteOffset,d.byteLength)))},copyTexSubImage3D(e,t,n,r,i,a,o,s,c){this._native2.copyTexSubImage3D(e,t,n,r,i,a,o,s,c)},texStorage2D(e,t,n,r,i){this._native2.texStorage2D(e,t,n,r,i);let a=this._getTexImage(e);if(a){for(let e=0;e<t;e++)a._levelWidth[e]=Math.max(1,r>>e),a._levelHeight[e]=Math.max(1,i>>e);a._format=this.RGBA,a._type=this.UNSIGNED_BYTE}},texStorage3D(e,t,n,r,i,a){this._native2.texStorage3D(e,t,n,r,i,a)}};function installTexImage3DMethods(e){Object.assign(e,t)}export{installTexImage3DMethods};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";const e={uniform1ui(e,t){e&&this._native2.uniform1ui(e._,t)},uniform2ui(e,t,n){e&&this._native2.uniform2ui(e._,t,n)},uniform3ui(e,t,n,r){e&&this._native2.uniform3ui(e._,t,n,r)},uniform4ui(e,t,n,r,i){e&&this._native2.uniform4ui(e._,t,n,r,i)},uniform1uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform1uiv(e._,i.length,i)},uniform2uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform2uiv(e._,i.length/2,i)},uniform3uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform3uiv(e._,i.length/3,i)},uniform4uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform4uiv(e._,i.length/4,i)},uniformMatrix2x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x3fv(e._,t,a)},uniformMatrix3x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x2fv(e._,t,a)},uniformMatrix2x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x4fv(e._,t,a)},uniformMatrix4x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x2fv(e._,t,a)},uniformMatrix3x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x4fv(e._,t,a)},uniformMatrix4x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x3fv(e._,t,a)}};function installUniformMethods(t){Object.assign(t,e)}export{installUniformMethods};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t,checkObject as n,convertPixels as r,extractImageData as i,premultiplyAlpha as a,vertexCount as o}from"./utils.js";import{WebGLFramebuffer as s}from"./webgl-framebuffer.js";import{WebGLRenderbuffer as c}from"./webgl-renderbuffer.js";import{WebGLTexture as l}from"./webgl-texture.js";import{WebGLContextBase as u}from"./webgl-context-base.js";import{installObjectLifecycleMethods as d}from"./webgl2-context/object-lifecycle.js";import f from"@girs/gwebgl-0.1";import{warnNotImplemented as p}from"@gjsify/utils";import m from"gi://GdkPixbuf?version=2.0";function debugGlEnabled(){return globalThis.__GJSIFY_DEBUG_GL===!0}var h=class WebGL2RenderingContext extends u{get _gl(){return this._native2}constructor(e,t={}){super(e,t),this._queries={},this._samplers={},this._transformFeedbacks={},this._vertexArrayObjects={},this._syncs={},this._activeReadFramebuffer=null,this._activeDrawFramebuffer=null,this._native2=new f.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:`130`}_validFramebufferAttachment(e){return super._validFramebufferAttachment(e)?!0:e>=36065&&e<=36079}static{this._WGL2_ALL_COLOR_ATTACHMENTS=[36064,36065,36066,36067,36068,36069,36070,36071,36072,36073,36074,36075,36076,36077,36078,36079]}_getColorAttachments(){return WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS}_preCheckFramebufferStatus(e){let t=e._attachments,n=0,r=0,i=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT,...WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS];for(let a of i){let i=t[a];if(i){if(i instanceof l){let t=e._attachmentLevel[a]??0,o=i._levelWidth[t]??0,s=i._levelHeight[t]??0;if(o>0&&s>0){n=o,r=s;break}}else if(i instanceof c&&i._width>0&&i._height>0){n=i._width,r=i._height;break}}}return n>0&&r>0?(e._width=n,e._height=r,this.FRAMEBUFFER_COMPLETE):this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}_updateFramebufferAttachments(e){if(super._updateFramebufferAttachments(e),e)for(let t=1;t<=15;t++){let n=36064+t;if(!(n in e._attachments))continue;let r=e._attachments[n];if(r instanceof l){let t=e._attachmentFace[n]||this.TEXTURE_2D,i=e._attachmentLevel[n]??0;this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,t,r._|0,i|0)}else r instanceof c?this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,n,this.RENDERBUFFER,r._|0):this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,this.TEXTURE_2D,0,0)}}bindBuffer(e,t){if(e===35345||e===35982||e===36662||e===36663){let n=t?t._|0:0;this._gl.bindBuffer(e,n);return}super.bindBuffer(e,t)}bindFramebuffer(e,t){if(e===36008||e===36009){if(!n(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(t&&t._pendingDelete||t&&!this._checkWrapper(t,s))return;let r=t?t._|0:this._gtkFboId;if(this._gl.bindFramebuffer(e,r),e===36008){let e=this._activeReadFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeReadFramebuffer=t}else{let e=this._activeDrawFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeDrawFramebuffer=t,this._activeFramebuffer=t}return}super.bindFramebuffer(this.FRAMEBUFFER,t),this._activeReadFramebuffer=t,this._activeDrawFramebuffer=t}deleteFramebuffer(e){this._activeReadFramebuffer===e&&this.bindFramebuffer(36008,null),this._activeDrawFramebuffer===e&&this.bindFramebuffer(36009,null),super.deleteFramebuffer(e)}bufferData(n,r,i){let a=n===35345||n===35982||n===36662||n===36663,o=i===35041||i===35043||i===35045||i===35042||i===35044||i===35046?this.STATIC_DRAW:i;if(a){if(typeof r==`number`)r>=0&&this._gl.bufferDataSizeOnly(n,r,o);else if(typeof r==`object`&&r){let i=t(r);this._gl.bufferData(n,e(i),o)}return}super.bufferData(n,r,o)}bufferSubData(n,r,i){if(n===35345||n===35982||n===36662||n===36663){if(r<0){this.setError(this.INVALID_VALUE);return}if(!i){this.setError(this.INVALID_VALUE);return}let a=t(i);this._gl.bufferSubData(n,r,e(a));return}super.bufferSubData(n,r,i)}bindTexture(e,t){if(e===32879||e===35866){let n=t,r=n?n._|0:0;this._gl.bindTexture(e,r),n&&(n._binding=e);return}super.bindTexture(e,t)}texParameteri(e,t,n){if(e===32879||e===35866){this._gl.texParameteri(e,t,n);return}if(t===32882||t===34892||t===34893||t===33084||t===33085||t===33083||t===33082){this._gl.texParameteri(e,t,n);return}super.texParameteri(e,t,n)}drawArrays(e,t,n){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=o(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}this._framebufferOk()&&n!==0&&this._checkVertexAttribState(n+t-1>>>0)&&this._native2.drawArrays(e,t,r)}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(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()||t===0)return;let c=0;for(let e=o;e<o+s;++e)e<a.length&&a[e]>c&&(c=a[e]);this._checkVertexAttribState(c)&&this._native2.drawElements(e,s,n,r)}bindBufferBase(e,t,n){this._native2.bindBufferBase(e,t,n?n._:0)}bindBufferRange(e,t,n,r,i){this._native2.bindBufferRange(e,t,n?n._:0,r,i)}copyBufferSubData(e,t,n,r,i){this._native2.copyBufferSubData(e,t,n,r,i)}getBufferSubData(e,t,n,r,i){let a=i===void 0?n.byteLength-(r??0):i,o=this._native2.getBufferSubData(e,t,a),s=new Uint8Array(n.buffer,n.byteOffset+(r??0)*(n instanceof Uint8Array?1:n.BYTES_PER_ELEMENT??1));s.set(o.subarray(0,s.byteLength))}texImage3D(t,n,r,i,a,o,s,c,l,u){u===null?this._native2.texImage3DNull(t,n,r,i,a,o,s,c,l):this._native2.texImage3D(t,n,r,i,a,o,s,c,l,e(new Uint8Array(u.buffer,u.byteOffset,u.byteLength)))}texSubImage3D(t,n,r,i,a,o,s,c,l,u,d){d!==null&&this._native2.texSubImage3D(t,n,r,i,a,o,s,c,l,u,e(new Uint8Array(d.buffer,d.byteOffset,d.byteLength)))}compressedTexImage3D(t,n,r,i,a,o,s,c,l){this._native2.compressedTexImage3D(t,n,r,i,a,o,s,e(new Uint8Array(l.buffer,l.byteOffset,l.byteLength)))}compressedTexSubImage3D(t,n,r,i,a,o,s,c,l,u,d){this._native2.compressedTexSubImage3D(t,n,r,i,a,o,s,c,l,e(new Uint8Array(d.buffer,d.byteOffset,d.byteLength)))}copyTexSubImage3D(e,t,n,r,i,a,o,s,c){this._native2.copyTexSubImage3D(e,t,n,r,i,a,o,s,c)}texStorage2D(e,t,n,r,i){this._native2.texStorage2D(e,t,n,r,i);let a=this._getTexImage(e);if(a){for(let e=0;e<t;e++)a._levelWidth[e]=Math.max(1,r>>e),a._levelHeight[e]=Math.max(1,i>>e);a._format=this.RGBA,a._type=this.UNSIGNED_BYTE}}texStorage3D(e,t,n,r,i,a){this._native2.texStorage3D(e,t,n,r,i,a)}texImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,h=0,g=0,_=0;if(arguments.length===6)if(d=c,g=s,l instanceof m.Pixbuf){let e=l;p=e.get_width(),h=e.get_height(),f=e.get_pixels()}else{let e=i(l);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,h=e.height,f=e.data}else arguments.length>=9&&(p=s,h=c,_=l,g=u);let v=this._getTexImage(t);if(!v){this.setError(this.INVALID_OPERATION);return}let y=r(f);if(this._unpackPremultAlpha&&y&&g===this.RGBA&&(y=a(y)),this._unpackFlipY&&y&&p>0&&h>0){let e=this._computePixelSize(d,g);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(y.length);for(let e=0;e<h;e++){let r=e*t,i=(h-1-e)*t;n.set(y.subarray(r,r+t),i)}y=n}}this._saveError(),this._gl.texImage2D(t,n,o,p,h,_,g,d,e(y));let b=this.getError();if(this._restoreError(b),b!==this.NO_ERROR)return;v._levelWidth[n]=p,v._levelHeight[n]=h,v._format=g,v._type=d;let x=this._activeFramebuffer;if(x){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(x._attachments[t[n]]===v){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}}texSubImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,h=0,g=0;if(arguments.length===7)if(d=l,g=c,u instanceof m.Pixbuf){let e=u;p=e.get_width(),h=e.get_height(),f=e.get_pixels()}else{let e=i(u);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,h=e.height,f=e.data}else p=c,h=l,g=u;if(!this._getTexImage(t)){this.setError(this.INVALID_OPERATION);return}let _=r(f);if(!_){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&_&&g===this.RGBA&&(_=a(_)),this._unpackFlipY&&_&&p>0&&h>0){let e=this._computePixelSize(d,g);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(_.length);for(let e=0;e<h;e++){let r=e*t,i=(h-1-e)*t;n.set(_.subarray(r,r+t),i)}_=n}}this._gl.texSubImage2D(t,n,o,s,p,h,g,d,e(_))}framebufferTextureLayer(e,t,n,r,i){this._native2.framebufferTextureLayer(e,t,n?n._:0,r,i)}drawArraysInstanced(e,t,n,r){if(t<0||n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=o(this,e,n);if(i<0){this.setError(this.INVALID_ENUM);return}if(this._framebufferOk()&&!(n===0||r===0)&&this._checkVertexAttribState(n+t-1>>>0)){if(debugGlEnabled()){let e=this,t=e.__drawInstCount=(e.__drawInstCount|0)+1;(t<=5||t%100==0)&&console.log(`[WebGL] drawArraysInstanced #${t} count=${i} instances=${r} fbo=${this._activeFramebuffer?._??`_gtkFbo`}`)}this._native2.drawArraysInstanced(e,t,i,r)}}drawElementsInstanced(e,t,n,r,i){if(t<0||r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let a=this._vertexObjectState._elementArrayBufferBinding;if(!a){this.setError(this.INVALID_OPERATION);return}let o=null,s=r;if(n===this.UNSIGNED_SHORT){if(s%2){this.setError(this.INVALID_OPERATION);return}s>>=1,o=new Uint16Array(a._elements.buffer)}else if(n===this.UNSIGNED_INT){if(s%4){this.setError(this.INVALID_OPERATION);return}s>>=2,o=new Uint32Array(a._elements.buffer)}else if(n===this.UNSIGNED_BYTE)o=a._elements;else{this.setError(this.INVALID_ENUM);return}let c=t;switch(e){case this.TRIANGLES:t%3&&(c-=t%3);break;case this.LINES:t%2&&(c-=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(c===0||i===0){this._checkVertexAttribState(0);return}if(c+s>>>0>o.length){this.setError(this.INVALID_OPERATION);return}let l=0;for(let e=s;e<s+c;++e)o[e]>l&&(l=o[e]);this._checkVertexAttribState(l)&&this._native2.drawElementsInstanced(e,c,n,r,i)}vertexAttribDivisor(e,t){this._native2.vertexAttribDivisor(e,t)}vertexAttribIPointer(e,t,n,r,i){this._native2.vertexAttribIPointer(e,t,n,r,i)}drawBuffers(e){let t=!1;for(let n=0;n<e.length;n++)if(e[n]===1029){t=!0;break}if(!t){this._native2.drawBuffers(e);return}this._native2.drawBuffers(e.map(e=>e===1029?this.COLOR_ATTACHMENT0:e))}drawRangeElements(e,t,n,r,i,a){if(r<0||a<0){this.setError(this.INVALID_VALUE);return}if(n<t){this.setError(this.INVALID_VALUE);return}this.drawElements(e,r,i,a)}blitFramebuffer(e,t,n,r,i,a,o,s,c,l){if(debugGlEnabled()){let e=this._gl.getError();e!==0&&console.log(`[WebGL] blitFramebuffer PRE-ERROR 0x${e.toString(16)}`)}if(this._native2.blitFramebuffer(e,t,n,r,i,a,o,s,c,l),debugGlEnabled()){let i=this._gl.getError(),a=this,o=a.__blitCount=(a.__blitCount|0)+1;o<=5&&console.log(`[WebGL] blitFramebuffer #${o} src=(${e},${t},${n},${r}) readFbo=${this._activeReadFramebuffer?._??`_gtkFbo`} err=${i===0?`OK`:`0x`+i.toString(16)}`)}}clearBufferfv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfv==`function`){i.clearBufferfv(e,t,Array.from(n));return}let a=n;if(e===6144){let e=this.getParameter(this.COLOR_CLEAR_VALUE);this.clearColor(a[0]??0,a[1]??0,a[2]??0,a[3]??0),this.clear(this.COLOR_BUFFER_BIT),e&&this.clearColor(e[0],e[1],e[2],e[3])}else if(e===6145){let e=this.getParameter(this.DEPTH_CLEAR_VALUE);this.clearDepth(a[0]??1),this.clear(this.DEPTH_BUFFER_BIT),e!==null&&this.clearDepth(e)}}clearBufferiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferiv==`function`){i.clearBufferiv(e,t,Array.from(n));return}if(e===6146){let e=n,t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearStencil(e[0]??0),this.clear(this.STENCIL_BUFFER_BIT),t!==null&&this.clearStencil(t)}}clearBufferuiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferuiv==`function`){i.clearBufferuiv(e,t,Array.from(n));return}}clearBufferfi(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfi==`function`){i.clearBufferfi(e,t,n,r);return}if(e===34041){let e=this.getParameter(this.DEPTH_CLEAR_VALUE),t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearDepth(n),this.clearStencil(r),this.clear(this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),e!==null&&this.clearDepth(e),t!==null&&this.clearStencil(t)}}invalidateFramebuffer(e,t){this._native2.invalidateFramebuffer(e,t)}invalidateSubFramebuffer(e,t,n,r,i,a){this._native2.invalidateSubFramebuffer(e,t,n,r,i,a)}readBuffer(e){this._native2.readBuffer(e)}renderbufferStorageMultisample(e,t,n,r,i){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let a=this._activeRenderbuffer;if(!a){this.setError(this.INVALID_OPERATION);return}this._saveError(),this._native2.renderbufferStorageMultisample(e,t,n,r,i);let o=this.getError();this._restoreError(o),o===this.NO_ERROR&&(a._width=r,a._height=i,a._format=n)}uniform1ui(e,t){e&&this._native2.uniform1ui(e._,t)}uniform2ui(e,t,n){e&&this._native2.uniform2ui(e._,t,n)}uniform3ui(e,t,n,r){e&&this._native2.uniform3ui(e._,t,n,r)}uniform4ui(e,t,n,r,i){e&&this._native2.uniform4ui(e._,t,n,r,i)}uniform1uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform1uiv(e._,i.length,i)}uniform2uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform2uiv(e._,i.length/2,i)}uniform3uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform3uiv(e._,i.length/3,i)}uniform4uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform4uiv(e._,i.length/4,i)}uniformMatrix2x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x3fv(e._,t,a)}uniformMatrix3x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x2fv(e._,t,a)}uniformMatrix2x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x4fv(e._,t,a)}uniformMatrix4x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x2fv(e._,t,a)}uniformMatrix3x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x4fv(e._,t,a)}uniformMatrix4x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x3fv(e._,t,a)}getUniform(e,t){let n=t?._activeInfo?.type,r=5125,i=36294,a=36295,o=n===r||n===i||n===a||n===36296,s=e;if(!o)return super.getUniform(s,t);if(!e||!t)return null;let c=this._native2.getUniformi(s._|0,t._|0);return c?n===r?c[0]>>>0:n===i?new Uint32Array([c[0]>>>0,c[1]>>>0]):n===a?new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0]):new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0,c[3]>>>0]):null}getUniformBlockIndex(e,t){return this._native2.getUniformBlockIndex(e._,t)}uniformBlockBinding(e,t,n){this._native2.uniformBlockBinding(e._,t,n)}getActiveUniformBlockName(e,t){let n=this._native2.getActiveUniformBlockName(e._,t);return n.length>0?n:null}getActiveUniformBlockParameter(e,t,n){return this._native2.getActiveUniformBlockParameter(e._,t,n)}getActiveUniforms(e,t,n){return this._native2.getActiveUniforms(e._,t,n)}getFragDataLocation(e,t){return this._native2.getFragDataLocation(e._,t)}getIndexedParameter(e,t){return this._native2.getIndexedParameteri(e,t)}getInternalformatParameter(e,t,n){return this._native2.getInternalformatParameter(e,t,n)}getParameter(e){if(e===7938)return`WebGL 2.0`;if(e===35724)return`WebGL GLSL ES 3.00`;if(e===7939)return p(`WebGL2RenderingContext.getParameter(GL_EXTENSIONS)`),``;if(e===36006)return this._activeDrawFramebuffer;if(e===36010)return this._activeReadFramebuffer;switch(e){case 36183:case 35071:case 32883:case 36063:case 34852:case 36203:case 33001:case 33e3:case 37157:case 35373:case 35657:case 35077:case 35978:case 35979:case 35968:case 35376:case 35375:case 35659:case 37154:case 35371:case 35658:case 35379:case 35374:case 35377:case 35076:case 3330:case 3332:case 3331:case 35053:case 35055:case 3074:case 32874:case 35869:case 36389:case 35983:case 35368:case 35380:case 32878:case 3314:case 32877:case 3316:case 3315:case 34045:return this._native2.getParameterx(e)?.deepUnpack()|0;case 35977:case 36388:case 36387:return!!this._native2.getParameterx(e)?.deepUnpack()}return super.getParameter(e)}getStringi(e,t){let n=this._native2.getStringi(e,t);return n.length>0?n:null}renderbufferStorage(e,t,n,r){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(n<0||r<0){this.setError(this.INVALID_VALUE);return}for(;this._gl.getError()!==this.NO_ERROR;);if(this._gl.renderbufferStorage(e,t,n,r),this._gl.getError()!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let a=this._activeFramebuffer;if(a){let e=this._getAttachments(),t=!1;for(let n=0;n<e.length;++n)if(a._attachments[e[n]]===i){t=!0;break}t&&this._updateFramebufferAttachments(a)}}getSupportedExtensions(){let e=super.getSupportedExtensions();for(let t of[`EXT_color_buffer_float`,`EXT_color_buffer_half_float`,`OES_texture_half_float`])e.indexOf(t)===-1&&e.push(t);return e}readPixels(t,n,r,i,a,o,s){if(!s)return;if(r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._framebufferOk())return;let c=a===6408||a===32856?4:a===6407?3:a===33319?2:1,l=o===5126?4:o===5131||o===36193?2:o===5125||o===5124?4:o===5123||o===5122?2:1,u=r*i*c*l,d=new Uint8Array(u);this._saveError();let f=this._gl.readPixels(t,n,r,i,a,o,e(d)),p=this.getError();if(this._restoreError(p),p!==this.NO_ERROR)return;let m=f&&f.length>0?f:d;if(s instanceof Uint8Array)s.set(m);else if(s instanceof Float32Array){let e=new Float32Array(m.buffer,0,s.length);s.set(e)}}_framebufferOk(){return!0}};d(h.prototype);export{h as WebGL2RenderingContext};
1
+ import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t,checkObject as n,convertPixels as r,extractImageData as i,premultiplyAlpha as a,vertexCount as o}from"./utils.js";import{WebGLFramebuffer as s}from"./webgl-framebuffer.js";import{WebGLRenderbuffer as c}from"./webgl-renderbuffer.js";import{WebGLTexture as l}from"./webgl-texture.js";import{WebGLContextBase as u}from"./webgl-context-base.js";import{installObjectLifecycleMethods as d}from"./webgl2-context/object-lifecycle.js";import{installTexImage3DMethods as f}from"./webgl2-context/tex-image-3d.js";import{installUniformMethods as p}from"./webgl2-context/uniform.js";import{installClearBufferMethods as m}from"./webgl2-context/clear-buffer.js";import{installInstancedAndFramebufferOpsMethods as h}from"./webgl2-context/instanced-and-framebuffer-ops.js";import g from"@girs/gwebgl-0.1";import{warnNotImplemented as _}from"@gjsify/utils";import v from"gi://GdkPixbuf?version=2.0";var y=class WebGL2RenderingContext extends u{get _gl(){return this._native2}constructor(e,t={}){super(e,t),this._queries={},this._samplers={},this._transformFeedbacks={},this._vertexArrayObjects={},this._syncs={},this._activeReadFramebuffer=null,this._activeDrawFramebuffer=null,this._native2=new g.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:`130`}_validFramebufferAttachment(e){return super._validFramebufferAttachment(e)?!0:e>=36065&&e<=36079}static{this._WGL2_ALL_COLOR_ATTACHMENTS=[36064,36065,36066,36067,36068,36069,36070,36071,36072,36073,36074,36075,36076,36077,36078,36079]}_getColorAttachments(){return WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS}_preCheckFramebufferStatus(e){let t=e._attachments,n=0,r=0,i=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT,...WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS];for(let a of i){let i=t[a];if(i){if(i instanceof l){let t=e._attachmentLevel[a]??0,o=i._levelWidth[t]??0,s=i._levelHeight[t]??0;if(o>0&&s>0){n=o,r=s;break}}else if(i instanceof c&&i._width>0&&i._height>0){n=i._width,r=i._height;break}}}return n>0&&r>0?(e._width=n,e._height=r,this.FRAMEBUFFER_COMPLETE):this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}_updateFramebufferAttachments(e){if(super._updateFramebufferAttachments(e),e)for(let t=1;t<=15;t++){let n=36064+t;if(!(n in e._attachments))continue;let r=e._attachments[n];if(r instanceof l){let t=e._attachmentFace[n]||this.TEXTURE_2D,i=e._attachmentLevel[n]??0;this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,t,r._|0,i|0)}else r instanceof c?this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,n,this.RENDERBUFFER,r._|0):this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,this.TEXTURE_2D,0,0)}}bindBuffer(e,t){if(e===35345||e===35982||e===36662||e===36663){let n=t?t._|0:0;this._gl.bindBuffer(e,n);return}super.bindBuffer(e,t)}bindFramebuffer(e,t){if(e===36008||e===36009){if(!n(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(t&&t._pendingDelete||t&&!this._checkWrapper(t,s))return;let r=t?t._|0:this._gtkFboId;if(this._gl.bindFramebuffer(e,r),e===36008){let e=this._activeReadFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeReadFramebuffer=t}else{let e=this._activeDrawFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeDrawFramebuffer=t,this._activeFramebuffer=t}return}super.bindFramebuffer(this.FRAMEBUFFER,t),this._activeReadFramebuffer=t,this._activeDrawFramebuffer=t}deleteFramebuffer(e){this._activeReadFramebuffer===e&&this.bindFramebuffer(36008,null),this._activeDrawFramebuffer===e&&this.bindFramebuffer(36009,null),super.deleteFramebuffer(e)}bufferData(n,r,i){let a=n===35345||n===35982||n===36662||n===36663,o=i===35041||i===35043||i===35045||i===35042||i===35044||i===35046?this.STATIC_DRAW:i;if(a){if(typeof r==`number`)r>=0&&this._gl.bufferDataSizeOnly(n,r,o);else if(typeof r==`object`&&r){let i=t(r);this._gl.bufferData(n,e(i),o)}return}super.bufferData(n,r,o)}bufferSubData(n,r,i){if(n===35345||n===35982||n===36662||n===36663){if(r<0){this.setError(this.INVALID_VALUE);return}if(!i){this.setError(this.INVALID_VALUE);return}let a=t(i);this._gl.bufferSubData(n,r,e(a));return}super.bufferSubData(n,r,i)}bindTexture(e,t){if(e===32879||e===35866){let n=t,r=n?n._|0:0;this._gl.bindTexture(e,r),n&&(n._binding=e);return}super.bindTexture(e,t)}texParameteri(e,t,n){if(e===32879||e===35866){this._gl.texParameteri(e,t,n);return}if(t===32882||t===34892||t===34893||t===33084||t===33085||t===33083||t===33082){this._gl.texParameteri(e,t,n);return}super.texParameteri(e,t,n)}drawArrays(e,t,n){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=o(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}this._framebufferOk()&&n!==0&&this._checkVertexAttribState(n+t-1>>>0)&&this._native2.drawArrays(e,t,r)}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(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()||t===0)return;let c=0;for(let e=o;e<o+s;++e)e<a.length&&a[e]>c&&(c=a[e]);this._checkVertexAttribState(c)&&this._native2.drawElements(e,s,n,r)}bindBufferBase(e,t,n){this._native2.bindBufferBase(e,t,n?n._:0)}bindBufferRange(e,t,n,r,i){this._native2.bindBufferRange(e,t,n?n._:0,r,i)}copyBufferSubData(e,t,n,r,i){this._native2.copyBufferSubData(e,t,n,r,i)}getBufferSubData(e,t,n,r,i){let a=i===void 0?n.byteLength-(r??0):i,o=this._native2.getBufferSubData(e,t,a),s=new Uint8Array(n.buffer,n.byteOffset+(r??0)*(n instanceof Uint8Array?1:n.BYTES_PER_ELEMENT??1));s.set(o.subarray(0,s.byteLength))}texImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,m=0,h=0,g=0;if(arguments.length===6)if(d=c,h=s,l instanceof v.Pixbuf){let e=l;p=e.get_width(),m=e.get_height(),f=e.get_pixels()}else{let e=i(l);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,m=e.height,f=e.data}else arguments.length>=9&&(p=s,m=c,g=l,h=u);let _=this._getTexImage(t);if(!_){this.setError(this.INVALID_OPERATION);return}let y=r(f);if(this._unpackPremultAlpha&&y&&h===this.RGBA&&(y=a(y)),this._unpackFlipY&&y&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(y.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(y.subarray(r,r+t),i)}y=n}}this._saveError(),this._gl.texImage2D(t,n,o,p,m,g,h,d,e(y));let b=this.getError();if(this._restoreError(b),b!==this.NO_ERROR)return;_._levelWidth[n]=p,_._levelHeight[n]=m,_._format=h,_._type=d;let x=this._activeFramebuffer;if(x){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(x._attachments[t[n]]===_){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}}texSubImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,m=0,h=0;if(arguments.length===7)if(d=l,h=c,u instanceof v.Pixbuf){let e=u;p=e.get_width(),m=e.get_height(),f=e.get_pixels()}else{let e=i(u);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,m=e.height,f=e.data}else p=c,m=l,h=u;if(!this._getTexImage(t)){this.setError(this.INVALID_OPERATION);return}let g=r(f);if(!g){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&g&&h===this.RGBA&&(g=a(g)),this._unpackFlipY&&g&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(g.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(g.subarray(r,r+t),i)}g=n}}this._gl.texSubImage2D(t,n,o,s,p,m,h,d,e(g))}getUniform(e,t){let n=t?._activeInfo?.type,r=5125,i=36294,a=36295,o=n===r||n===i||n===a||n===36296,s=e;if(!o)return super.getUniform(s,t);if(!e||!t)return null;let c=this._native2.getUniformi(s._|0,t._|0);return c?n===r?c[0]>>>0:n===i?new Uint32Array([c[0]>>>0,c[1]>>>0]):n===a?new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0]):new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0,c[3]>>>0]):null}getUniformBlockIndex(e,t){return this._native2.getUniformBlockIndex(e._,t)}uniformBlockBinding(e,t,n){this._native2.uniformBlockBinding(e._,t,n)}getActiveUniformBlockName(e,t){let n=this._native2.getActiveUniformBlockName(e._,t);return n.length>0?n:null}getActiveUniformBlockParameter(e,t,n){return this._native2.getActiveUniformBlockParameter(e._,t,n)}getActiveUniforms(e,t,n){return this._native2.getActiveUniforms(e._,t,n)}getFragDataLocation(e,t){return this._native2.getFragDataLocation(e._,t)}getIndexedParameter(e,t){return this._native2.getIndexedParameteri(e,t)}getInternalformatParameter(e,t,n){return this._native2.getInternalformatParameter(e,t,n)}getParameter(e){if(e===7938)return`WebGL 2.0`;if(e===35724)return`WebGL GLSL ES 3.00`;if(e===7939)return _(`WebGL2RenderingContext.getParameter(GL_EXTENSIONS)`),``;if(e===36006)return this._activeDrawFramebuffer;if(e===36010)return this._activeReadFramebuffer;switch(e){case 36183:case 35071:case 32883:case 36063:case 34852:case 36203:case 33001:case 33e3:case 37157:case 35373:case 35657:case 35077:case 35978:case 35979:case 35968:case 35376:case 35375:case 35659:case 37154:case 35371:case 35658:case 35379:case 35374:case 35377:case 35076:case 3330:case 3332:case 3331:case 35053:case 35055:case 3074:case 32874:case 35869:case 36389:case 35983:case 35368:case 35380:case 32878:case 3314:case 32877:case 3316:case 3315:case 34045:return this._native2.getParameterx(e)?.deepUnpack()|0;case 35977:case 36388:case 36387:return!!this._native2.getParameterx(e)?.deepUnpack()}return super.getParameter(e)}getStringi(e,t){let n=this._native2.getStringi(e,t);return n.length>0?n:null}renderbufferStorage(e,t,n,r){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(n<0||r<0){this.setError(this.INVALID_VALUE);return}for(;this._gl.getError()!==this.NO_ERROR;);if(this._gl.renderbufferStorage(e,t,n,r),this._gl.getError()!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let a=this._activeFramebuffer;if(a){let e=this._getAttachments(),t=!1;for(let n=0;n<e.length;++n)if(a._attachments[e[n]]===i){t=!0;break}t&&this._updateFramebufferAttachments(a)}}getSupportedExtensions(){let e=super.getSupportedExtensions();for(let t of[`EXT_color_buffer_float`,`EXT_color_buffer_half_float`,`OES_texture_half_float`])e.indexOf(t)===-1&&e.push(t);return e}readPixels(t,n,r,i,a,o,s){if(!s)return;if(r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._framebufferOk())return;let c=a===6408||a===32856?4:a===6407?3:a===33319?2:1,l=o===5126?4:o===5131||o===36193?2:o===5125||o===5124?4:o===5123||o===5122?2:1,u=r*i*c*l,d=new Uint8Array(u);this._saveError();let f=this._gl.readPixels(t,n,r,i,a,o,e(d)),p=this.getError();if(this._restoreError(p),p!==this.NO_ERROR)return;let m=f&&f.length>0?f:d;if(s instanceof Uint8Array)s.set(m);else if(s instanceof Float32Array){let e=new Float32Array(m.buffer,0,s.length);s.set(e)}}_framebufferOk(){return!0}};d(y.prototype),f(y.prototype),p(y.prototype),m(y.prototype),h(y.prototype);export{y as WebGL2RenderingContext};
@@ -0,0 +1,12 @@
1
+ export interface ClearBufferMethods {
2
+ clearBufferfv(buffer: GLenum, drawbuffer: GLint, values: Float32List, srcOffset?: GLuint): void;
3
+ clearBufferiv(buffer: GLenum, drawbuffer: GLint, values: Int32List, srcOffset?: GLuint): void;
4
+ clearBufferuiv(buffer: GLenum, drawbuffer: GLint, values: Uint32List, srcOffset?: GLuint): void;
5
+ clearBufferfi(buffer: GLenum, drawbuffer: GLint, depth: GLfloat, stencil: GLint): void;
6
+ }
7
+ declare module '../webgl2-rendering-context.js' {
8
+ interface WebGL2RenderingContext extends ClearBufferMethods {
9
+ }
10
+ }
11
+ /** Install clearBuffer{fv,iv,uiv,fi} methods on WebGL2RenderingContext.prototype. */
12
+ export declare function installClearBufferMethods(proto: object): void;
@@ -0,0 +1,21 @@
1
+ import { WebGLTexture } from '../webgl-texture.js';
2
+ export interface InstancedAndFramebufferOpsMethods {
3
+ drawArraysInstanced(mode: GLenum, first: GLint, count: GLsizei, instanceCount: GLsizei): void;
4
+ drawElementsInstanced(mode: GLenum, count: GLsizei, type: GLenum, offset: GLintptr, instanceCount: GLsizei): void;
5
+ vertexAttribDivisor(index: GLuint, divisor: GLuint): void;
6
+ vertexAttribIPointer(index: GLuint, size: GLint, type: GLenum, stride: GLsizei, offset: GLintptr): void;
7
+ drawBuffers(buffers: GLenum[]): void;
8
+ drawRangeElements(mode: GLenum, start: GLuint, end: GLuint, count: GLsizei, type: GLenum, offset: GLintptr): void;
9
+ blitFramebuffer(srcX0: GLint, srcY0: GLint, srcX1: GLint, srcY1: GLint, dstX0: GLint, dstY0: GLint, dstX1: GLint, dstY1: GLint, mask: GLbitfield, filter: GLenum): void;
10
+ framebufferTextureLayer(target: GLenum, attachment: GLenum, texture: WebGLTexture | null, level: GLint, layer: GLint): void;
11
+ invalidateFramebuffer(target: GLenum, attachments: GLenum[]): void;
12
+ invalidateSubFramebuffer(target: GLenum, attachments: GLenum[], x: GLint, y: GLint, width: GLsizei, height: GLsizei): void;
13
+ readBuffer(src: GLenum): void;
14
+ renderbufferStorageMultisample(target: GLenum, samples: GLsizei, internalFormat: GLenum, width: GLsizei, height: GLsizei): void;
15
+ }
16
+ declare module '../webgl2-rendering-context.js' {
17
+ interface WebGL2RenderingContext extends InstancedAndFramebufferOpsMethods {
18
+ }
19
+ }
20
+ /** Install instanced-draw + framebuffer-op methods on WebGL2RenderingContext.prototype. */
21
+ export declare function installInstancedAndFramebufferOpsMethods(proto: object): void;
@@ -0,0 +1,15 @@
1
+ export interface TexImage3DMethods {
2
+ texImage3D(target: GLenum, level: GLint, internalformat: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, border: GLint, format: GLenum, type: GLenum, pixels: ArrayBufferView | null): void;
3
+ texSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, type: GLenum, pixels: ArrayBufferView | null): void;
4
+ compressedTexImage3D(target: GLenum, level: GLint, internalformat: GLenum, width: GLsizei, height: GLsizei, depth: GLsizei, border: GLint, imageSize: GLsizei, data: ArrayBufferView): void;
5
+ compressedTexSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, imageSize: GLsizei, data: ArrayBufferView): void;
6
+ copyTexSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, x: GLint, y: GLint, width: GLsizei, height: GLsizei): void;
7
+ texStorage2D(target: GLenum, levels: GLsizei, internalformat: GLenum, width: GLsizei, height: GLsizei): void;
8
+ texStorage3D(target: GLenum, levels: GLsizei, internalformat: GLenum, width: GLsizei, height: GLsizei, depth: GLsizei): void;
9
+ }
10
+ declare module '../webgl2-rendering-context.js' {
11
+ interface WebGL2RenderingContext extends TexImage3DMethods {
12
+ }
13
+ }
14
+ /** Install 3D texture upload methods on WebGL2RenderingContext.prototype. */
15
+ export declare function installTexImage3DMethods(proto: object): void;
@@ -0,0 +1,23 @@
1
+ import { WebGLUniformLocation } from '../webgl-uniform-location.js';
2
+ export interface UniformMethods {
3
+ uniform1ui(location: WebGLUniformLocation | null, v0: GLuint): void;
4
+ uniform2ui(location: WebGLUniformLocation | null, v0: GLuint, v1: GLuint): void;
5
+ uniform3ui(location: WebGLUniformLocation | null, v0: GLuint, v1: GLuint, v2: GLuint): void;
6
+ uniform4ui(location: WebGLUniformLocation | null, v0: GLuint, v1: GLuint, v2: GLuint, v3: GLuint): void;
7
+ uniform1uiv(location: WebGLUniformLocation | null, data: Uint32List, srcOffset?: GLuint, srcLength?: GLuint): void;
8
+ uniform2uiv(location: WebGLUniformLocation | null, data: Uint32List, srcOffset?: GLuint, srcLength?: GLuint): void;
9
+ uniform3uiv(location: WebGLUniformLocation | null, data: Uint32List, srcOffset?: GLuint, srcLength?: GLuint): void;
10
+ uniform4uiv(location: WebGLUniformLocation | null, data: Uint32List, srcOffset?: GLuint, srcLength?: GLuint): void;
11
+ uniformMatrix2x3fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, srcOffset?: GLuint, srcLength?: GLuint): void;
12
+ uniformMatrix3x2fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, srcOffset?: GLuint, srcLength?: GLuint): void;
13
+ uniformMatrix2x4fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, srcOffset?: GLuint, srcLength?: GLuint): void;
14
+ uniformMatrix4x2fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, srcOffset?: GLuint, srcLength?: GLuint): void;
15
+ uniformMatrix3x4fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, srcOffset?: GLuint, srcLength?: GLuint): void;
16
+ uniformMatrix4x3fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, srcOffset?: GLuint, srcLength?: GLuint): void;
17
+ }
18
+ declare module '../webgl2-rendering-context.js' {
19
+ interface WebGL2RenderingContext extends UniformMethods {
20
+ }
21
+ }
22
+ /** Install unsigned-integer + non-square matrix uniform methods on WebGL2RenderingContext.prototype. */
23
+ export declare function installUniformMethods(proto: object): void;
@@ -98,47 +98,10 @@ export declare class WebGL2RenderingContext extends WebGLContextBase implements
98
98
  bindBufferRange(target: GLenum, index: GLuint, buffer: WebGLBuffer | null, offset: GLintptr, size: GLsizeiptr): void;
99
99
  copyBufferSubData(readTarget: GLenum, writeTarget: GLenum, readOffset: GLintptr, writeOffset: GLintptr, size: GLsizeiptr): void;
100
100
  getBufferSubData(target: GLenum, srcByteOffset: GLintptr, dstBuffer: ArrayBufferView, dstOffset?: GLuint, length?: GLuint): void;
101
- texImage3D(target: GLenum, level: GLint, internalformat: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, border: GLint, format: GLenum, type: GLenum, pixels: ArrayBufferView | null): void;
102
- texSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, type: GLenum, pixels: ArrayBufferView | null): void;
103
- compressedTexImage3D(target: GLenum, level: GLint, internalformat: GLenum, width: GLsizei, height: GLsizei, depth: GLsizei, border: GLint, _imageSize: GLsizei, data: ArrayBufferView): void;
104
- compressedTexSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, width: GLsizei, height: GLsizei, depth: GLsizei, format: GLenum, _imageSize: GLsizei, data: ArrayBufferView): void;
105
- copyTexSubImage3D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, zoffset: GLint, x: GLint, y: GLint, width: GLsizei, height: GLsizei): void;
106
- texStorage2D(target: GLenum, levels: GLsizei, internalformat: GLenum, width: GLsizei, height: GLsizei): void;
107
- texStorage3D(target: GLenum, levels: GLsizei, internalformat: GLenum, width: GLsizei, height: GLsizei, depth: GLsizei): void;
108
101
  texImage2D(target: GLenum, level: GLint, internalFormat: GLint, width: GLsizei, height: GLsizei, border: GLint, format: GLenum, type: GLenum, pixels: ArrayBufferView | null): void;
109
102
  texImage2D(target: GLenum, level: GLint, internalFormat: GLint, format: GLenum, type: GLenum, source: TexImageSource | GdkPixbuf.Pixbuf): void;
110
103
  texSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, pixels: ArrayBufferView | null): void;
111
104
  texSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, format: GLenum, type: GLenum, source: TexImageSource | GdkPixbuf.Pixbuf): void;
112
- framebufferTextureLayer(target: GLenum, attachment: GLenum, texture: WebGLTexture | null, level: GLint, layer: GLint): void;
113
- drawArraysInstanced(mode: GLenum, first: GLint, count: GLsizei, instanceCount: GLsizei): void;
114
- drawElementsInstanced(mode: GLenum, count: GLsizei, type: GLenum, offset: GLintptr, instanceCount: GLsizei): void;
115
- vertexAttribDivisor(index: GLuint, divisor: GLuint): void;
116
- vertexAttribIPointer(index: GLuint, size: GLint, type: GLenum, stride: GLsizei, offset: GLintptr): void;
117
- drawBuffers(buffers: GLenum[]): void;
118
- drawRangeElements(mode: GLenum, start: GLuint, end: GLuint, count: GLsizei, type: GLenum, offset: GLintptr): void;
119
- blitFramebuffer(srcX0: GLint, srcY0: GLint, srcX1: GLint, srcY1: GLint, dstX0: GLint, dstY0: GLint, dstX1: GLint, dstY1: GLint, mask: GLbitfield, filter: GLenum): void;
120
- clearBufferfv(buffer: GLenum, drawbuffer: GLint, values: Float32List, _srcOffset?: GLuint): void;
121
- clearBufferiv(buffer: GLenum, drawbuffer: GLint, values: Int32List, _srcOffset?: GLuint): void;
122
- clearBufferuiv(buffer: GLenum, drawbuffer: GLint, values: Uint32List, _srcOffset?: GLuint): void;
123
- clearBufferfi(buffer: GLenum, drawbuffer: GLint, depth: GLfloat, stencil: GLint): void;
124
- invalidateFramebuffer(target: GLenum, attachments: GLenum[]): void;
125
- invalidateSubFramebuffer(target: GLenum, attachments: GLenum[], x: GLint, y: GLint, width: GLsizei, height: GLsizei): void;
126
- readBuffer(src: GLenum): void;
127
- renderbufferStorageMultisample(target: GLenum, samples: GLsizei, internalFormat: GLenum, width: GLsizei, height: GLsizei): void;
128
- uniform1ui(location: WebGLUniformLocation | null, v0: GLuint): void;
129
- uniform2ui(location: WebGLUniformLocation | null, v0: GLuint, v1: GLuint): void;
130
- uniform3ui(location: WebGLUniformLocation | null, v0: GLuint, v1: GLuint, v2: GLuint): void;
131
- uniform4ui(location: WebGLUniformLocation | null, v0: GLuint, v1: GLuint, v2: GLuint, v3: GLuint): void;
132
- uniform1uiv(location: WebGLUniformLocation | null, data: Uint32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
133
- uniform2uiv(location: WebGLUniformLocation | null, data: Uint32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
134
- uniform3uiv(location: WebGLUniformLocation | null, data: Uint32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
135
- uniform4uiv(location: WebGLUniformLocation | null, data: Uint32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
136
- uniformMatrix2x3fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
137
- uniformMatrix3x2fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
138
- uniformMatrix2x4fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
139
- uniformMatrix4x2fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
140
- uniformMatrix3x4fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
141
- uniformMatrix4x3fv(location: WebGLUniformLocation | null, transpose: GLboolean, data: Float32List, _srcOffset?: GLuint, _srcLength?: GLuint): void;
142
105
  /** WebGL1 getUniform falls to default:null for UNSIGNED_INT types. Handle them here. */
143
106
  getUniform(program: WebGLProgram, location: WebGLUniformLocation): unknown;
144
107
  getUniformBlockIndex(program: WebGLProgram, uniformBlockName: string): GLuint;
@@ -182,3 +145,11 @@ export declare class WebGL2RenderingContext extends WebGLContextBase implements
182
145
  }
183
146
  import './webgl2-context/object-lifecycle.js';
184
147
  import './webgl2-context/object-lifecycle.js';
148
+ import './webgl2-context/tex-image-3d.js';
149
+ import './webgl2-context/tex-image-3d.js';
150
+ import './webgl2-context/uniform.js';
151
+ import './webgl2-context/uniform.js';
152
+ import './webgl2-context/clear-buffer.js';
153
+ import './webgl2-context/clear-buffer.js';
154
+ import './webgl2-context/instanced-and-framebuffer-ops.js';
155
+ import './webgl2-context/instanced-and-framebuffer-ops.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/webgl",
3
- "version": "0.4.24",
3
+ "version": "0.4.25",
4
4
  "description": "WebGL module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -39,8 +39,8 @@
39
39
  "WebGL"
40
40
  ],
41
41
  "devDependencies": {
42
- "@gjsify/cli": "^0.4.24",
43
- "@gjsify/unit": "^0.4.24",
42
+ "@gjsify/cli": "^0.4.25",
43
+ "@gjsify/unit": "^0.4.25",
44
44
  "@types/bit-twiddle": "^1.0.3",
45
45
  "@types/node": "^25.9.1",
46
46
  "typescript": "^6.0.3"
@@ -49,10 +49,10 @@
49
49
  "@girs/gjs": "4.0.1",
50
50
  "@girs/gtk-4.0": "4.23.0-4.0.1",
51
51
  "@girs/gwebgl-0.1": "0.1.0-4.0.0-rc.5",
52
- "@gjsify/dom-elements": "^0.4.24",
53
- "@gjsify/dom-events": "^0.4.24",
54
- "@gjsify/event-bridge": "^0.4.24",
55
- "@gjsify/utils": "^0.4.24",
52
+ "@gjsify/dom-elements": "^0.4.25",
53
+ "@gjsify/dom-events": "^0.4.25",
54
+ "@gjsify/event-bridge": "^0.4.25",
55
+ "@gjsify/utils": "^0.4.25",
56
56
  "bit-twiddle": "^1.0.2",
57
57
  "glsl-tokenizer": "^2.1.5"
58
58
  }