@gjsify/webgl 0.64.58 → 0.64.59
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/context/buffer-binding.js +1 -1
- package/lib/esm/utils.js +1 -1
- package/lib/esm/webgl2-rendering-context.js +1 -1
- package/lib/esm/webgl2.spec.js +1 -1
- package/lib/types/context/buffer-binding.d.ts +2 -2
- package/lib/types/utils.d.ts +7 -0
- package/lib/types/webgl2-rendering-context.d.ts +2 -2
- package/package.json +15 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_virtual/_rolldown/runtime.js";import{WebGLBuffer as e}from"../webgl-buffer.js";import{Uint8ArrayToVariant as t,
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{WebGLBuffer as e}from"../webgl-buffer.js";import{Uint8ArrayToVariant as t,bufferSourceRange as n,checkObject as r,isTypedArray as i}from"../utils.js";const a={bindBuffer(t=0,n){if(!r(n))throw TypeError(`bindBuffer(GLenum, WebGLBuffer)`);if(t!==this.ARRAY_BUFFER&&t!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(!n)n=null,this._gl.bindBuffer(t,0);else if(n._pendingDelete)return;else if(this._checkWrapper(n,e)){if(n._binding&&n._binding!==t){this.setError(this.INVALID_OPERATION);return}n._binding=t|0,this._gl.bindBuffer(t,n._|0)}else return;t===this.ARRAY_BUFFER?this._vertexGlobalState.setArrayBuffer(n):this._vertexObjectState.setElementArrayBuffer(n)},bufferData(e=0,r,a=0,o=0,s=0){let c=0,l=null;if(typeof r==`number`?c=r:typeof r==`object`&&(l=r),a!==this.STREAM_DRAW&&a!==this.STATIC_DRAW&&a!==this.DYNAMIC_DRAW){this.setError(this.INVALID_ENUM);return}if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}let u=this._getActiveBuffer(e);if(!u){this.setError(this.INVALID_OPERATION);return}if(l){let r=null;if((i(l)||l instanceof DataView||l instanceof ArrayBuffer)&&(r=n(l,o,s)),!r){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferData(e,t(r),a);let c=this.getError();if(this._restoreError(c),c!==this.NO_ERROR)return;u._size=r.length,e===this.ELEMENT_ARRAY_BUFFER&&(u._elements=new Uint8Array(r))}else if(typeof r==`number`){if(c<0){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferDataSizeOnly(e,c,a);let t=this.getError();if(this._restoreError(t),t!==this.NO_ERROR)return;u._size=c,e===this.ELEMENT_ARRAY_BUFFER&&(u._elements=new Uint8Array(c))}else this.setError(this.INVALID_VALUE)},bufferSubData(e=0,r=0,a,o=0,s=0){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(typeof a!=`object`||!a)throw TypeError(`bufferSubData: data must be a BufferSource`);let c=this._getActiveBuffer(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(r<0||r>=c._size){this.setError(this.INVALID_VALUE);return}let l=null;if((i(a)||a instanceof DataView||a instanceof ArrayBuffer)&&(l=n(a,o,s)),!l){this.setError(this.INVALID_VALUE);return}if(r+l.length>c._size){this.setError(this.INVALID_VALUE);return}e===this.ELEMENT_ARRAY_BUFFER&&c._elements.set(l,r),this._gl.bufferSubData(e,r,t(l))},createBuffer(){let t=this._gl.createBuffer();if(!t||t<=0)return null;let n=new e(t,this);return this._buffers[t]=n,n},deleteBuffer(t){if(!r(t)||t!==null&&!(t instanceof e))throw TypeError(`deleteBuffer(WebGLBuffer)`);if(!(t instanceof e&&this._checkOwns(t))){this.setError(this.INVALID_OPERATION);return}this._vertexGlobalState._arrayBufferBinding===t&&this.bindBuffer(this.ARRAY_BUFFER,null),this._vertexObjectState._elementArrayBufferBinding===t&&this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this._vertexObjectState===this._defaultVertexObjectState&&this._vertexObjectState.releaseArrayBuffer(t),t._pendingDelete=!0,t._checkDelete()},getBufferParameter(e=0,t=0){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER)return this.setError(this.INVALID_ENUM),null;switch(t){case this.BUFFER_SIZE:case this.BUFFER_USAGE:return this._gl.getBufferParameteriv(e|0,t|0)[0];default:return this.setError(this.INVALID_ENUM),null}},_getActiveBuffer(e){return e===this.ARRAY_BUFFER?this._vertexGlobalState._arrayBufferBinding:e===this.ELEMENT_ARRAY_BUFFER?this._vertexObjectState._elementArrayBufferBinding:null}};function installBufferBindingMethods(e){Object.assign(e,a)}export{installBufferBindingMethods};
|
package/lib/esm/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{WebGLUniformLocation as e}from"./webgl-uniform-location.js";import t from"@girs/glib-2.0";function bindPublics(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=n[a];if(typeof o==`function`)r.indexOf(a)===-1&&(t[a]=o.bind(n));else{if(a[0]===`_`||a[0]===`0`||a[0]===`1`)continue;t[a]=o}}}function checkObject(e){return typeof e==`object`||e===void 0}function checkUniform(t,n){return n instanceof e&&n._program===t&&n._linkCount===t._linkCount}function isTypedArray(e){return e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||e instanceof Uint16Array||e instanceof Int16Array||e instanceof Uint32Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array}function isValidString(e){let t=e.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm,``);return!/["$`@\\'\0]/.test(t)}function vertexCount(e,t,n){switch(t){case e.TRIANGLES:return n-n%3;case e.LINES:return n-n%2;case e.LINE_LOOP:case e.POINTS:return n;case e.TRIANGLE_FAN:case e.LINE_STRIP:return n<2?0:n;case e.TRIANGLE_STRIP:return n<3?0:n;default:return-1}}function typeSize(e,t){switch(t){case e.UNSIGNED_BYTE:case e.BYTE:return 1;case e.UNSIGNED_SHORT:case e.SHORT:return 2;case e.UNSIGNED_INT:case e.INT:case e.FLOAT:return 4}return 0}function uniformTypeSize(e,t){switch(t){case e.BOOL_VEC4:case e.INT_VEC4:case e.FLOAT_VEC4:return 4;case e.BOOL_VEC3:case e.INT_VEC3:case e.FLOAT_VEC3:return 3;case e.BOOL_VEC2:case e.INT_VEC2:case e.FLOAT_VEC2:return 2;case e.BOOL:case e.INT:case e.FLOAT:case e.SAMPLER_2D:case e.SAMPLER_CUBE:return 1;default:return 0}}const listToArray=e=>{let t=[];for(let n of e.values())t.push(n);return t};function arrayToUint8Array(e){if(isTypedArray(e))return new Uint8Array(e.buffer).subarray(e.byteOffset,e.byteLength+e.byteOffset);if(Array.isArray(e)||e instanceof ArrayBuffer)return new Uint8Array(e);if(typeof e.values==`function`)return new Uint8Array(listToArray(e));throw Error(`Can't unpack typed array!`)}function Uint8ArrayToVariant(e){return new t.Variant(`ay`,e)}function boolArray(e){return Array.from(new Int32Array(e.buffer)).map(e=>!!e)}const extractImageData=e=>{let t=e.width,n=e.height;if(typeof e==`object`&&t!==void 0&&n!==void 0){if(e.data!==void 0)return e;let r=null;if(typeof e.getContext==`function`)r=e.getContext(`2d`);else if(typeof e.isPixbuf==`function`&&e.isPixbuf())return e.getImageData();else if(e.src!==void 0&&typeof document==`object`&&typeof document.createElement==`function`){let i=document.createElement(`canvas`);typeof i==`object`&&typeof i.getContext==`function`&&(i.width=t,i.height=n,r=i.getContext(`2d`),r!==null&&r.drawImage(e,0,0))}if(r!==null)return r.getImageData(0,0,t,n)}return null};function formatSize(e,t){switch(t){case e.ALPHA:case e.LUMINANCE:return 1;case e.LUMINANCE_ALPHA:return 2;case e.RGB:return 3;case e.RGBA:return 4}return 0}function convertPixels(e){if(typeof e==`object`&&e){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint8ClampedArray||e instanceof Float32Array)return arrayToUint8Array(e);if(e instanceof Buffer)return new Uint8Array(e)}return null}function checkFormat(e,t){return t===e.ALPHA||t===e.LUMINANCE_ALPHA||t===e.LUMINANCE||t===e.RGB||t===e.RGBA}function validCubeTarget(e,t){return t===e.TEXTURE_CUBE_MAP_POSITIVE_X||t===e.TEXTURE_CUBE_MAP_NEGATIVE_X||t===e.TEXTURE_CUBE_MAP_POSITIVE_Y||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Y||t===e.TEXTURE_CUBE_MAP_POSITIVE_Z||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Z}function flag(e,t,n){return!e||typeof e!=`object`||!(t in e)?n:!!e[t]}function premultiplyAlpha(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=4){let r=e[n+3]/255;t[n]=Math.round(e[n]*r),t[n+1]=Math.round(e[n+1]*r),t[n+2]=Math.round(e[n+2]*r),t[n+3]=e[n+3]}return t}export{Uint8ArrayToVariant,arrayToUint8Array,bindPublics,boolArray,checkFormat,checkObject,checkUniform,convertPixels,extractImageData,flag,formatSize,isTypedArray,isValidString,listToArray,premultiplyAlpha,typeSize,uniformTypeSize,validCubeTarget,vertexCount};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{WebGLUniformLocation as e}from"./webgl-uniform-location.js";import t from"@girs/glib-2.0";function bindPublics(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=n[a];if(typeof o==`function`)r.indexOf(a)===-1&&(t[a]=o.bind(n));else{if(a[0]===`_`||a[0]===`0`||a[0]===`1`)continue;t[a]=o}}}function checkObject(e){return typeof e==`object`||e===void 0}function checkUniform(t,n){return n instanceof e&&n._program===t&&n._linkCount===t._linkCount}function isTypedArray(e){return e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||e instanceof Uint16Array||e instanceof Int16Array||e instanceof Uint32Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array}function isValidString(e){let t=e.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm,``);return!/["$`@\\'\0]/.test(t)}function vertexCount(e,t,n){switch(t){case e.TRIANGLES:return n-n%3;case e.LINES:return n-n%2;case e.LINE_LOOP:case e.POINTS:return n;case e.TRIANGLE_FAN:case e.LINE_STRIP:return n<2?0:n;case e.TRIANGLE_STRIP:return n<3?0:n;default:return-1}}function typeSize(e,t){switch(t){case e.UNSIGNED_BYTE:case e.BYTE:return 1;case e.UNSIGNED_SHORT:case e.SHORT:return 2;case e.UNSIGNED_INT:case e.INT:case e.FLOAT:return 4}return 0}function uniformTypeSize(e,t){switch(t){case e.BOOL_VEC4:case e.INT_VEC4:case e.FLOAT_VEC4:return 4;case e.BOOL_VEC3:case e.INT_VEC3:case e.FLOAT_VEC3:return 3;case e.BOOL_VEC2:case e.INT_VEC2:case e.FLOAT_VEC2:return 2;case e.BOOL:case e.INT:case e.FLOAT:case e.SAMPLER_2D:case e.SAMPLER_CUBE:return 1;default:return 0}}const listToArray=e=>{let t=[];for(let n of e.values())t.push(n);return t};function arrayToUint8Array(e){if(isTypedArray(e))return new Uint8Array(e.buffer).subarray(e.byteOffset,e.byteLength+e.byteOffset);if(Array.isArray(e)||e instanceof ArrayBuffer)return new Uint8Array(e);if(typeof e.values==`function`)return new Uint8Array(listToArray(e));throw Error(`Can't unpack typed array!`)}function bufferSourceRange(e,t=0,n=0){let r=arrayToUint8Array(e),i=ArrayBuffer.isView(e)&&!(e instanceof DataView)?e.BYTES_PER_ELEMENT:1,a=r.length/i;if(t<0||n<0||t>a)return null;let o=n===0?a-t:n;return t+o>a?null:t===0&&o===a?r:r.subarray(t*i,(t+o)*i)}function Uint8ArrayToVariant(e){return new t.Variant(`ay`,e)}function boolArray(e){return Array.from(new Int32Array(e.buffer)).map(e=>!!e)}const extractImageData=e=>{let t=e.width,n=e.height;if(typeof e==`object`&&t!==void 0&&n!==void 0){if(e.data!==void 0)return e;let r=null;if(typeof e.getContext==`function`)r=e.getContext(`2d`);else if(typeof e.isPixbuf==`function`&&e.isPixbuf())return e.getImageData();else if(e.src!==void 0&&typeof document==`object`&&typeof document.createElement==`function`){let i=document.createElement(`canvas`);typeof i==`object`&&typeof i.getContext==`function`&&(i.width=t,i.height=n,r=i.getContext(`2d`),r!==null&&r.drawImage(e,0,0))}if(r!==null)return r.getImageData(0,0,t,n)}return null};function formatSize(e,t){switch(t){case e.ALPHA:case e.LUMINANCE:return 1;case e.LUMINANCE_ALPHA:return 2;case e.RGB:return 3;case e.RGBA:return 4}return 0}function convertPixels(e){if(typeof e==`object`&&e){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint8ClampedArray||e instanceof Float32Array)return arrayToUint8Array(e);if(e instanceof Buffer)return new Uint8Array(e)}return null}function checkFormat(e,t){return t===e.ALPHA||t===e.LUMINANCE_ALPHA||t===e.LUMINANCE||t===e.RGB||t===e.RGBA}function validCubeTarget(e,t){return t===e.TEXTURE_CUBE_MAP_POSITIVE_X||t===e.TEXTURE_CUBE_MAP_NEGATIVE_X||t===e.TEXTURE_CUBE_MAP_POSITIVE_Y||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Y||t===e.TEXTURE_CUBE_MAP_POSITIVE_Z||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Z}function flag(e,t,n){return!e||typeof e!=`object`||!(t in e)?n:!!e[t]}function premultiplyAlpha(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=4){let r=e[n+3]/255;t[n]=Math.round(e[n]*r),t[n+1]=Math.round(e[n+1]*r),t[n+2]=Math.round(e[n+2]*r),t[n+3]=e[n+3]}return t}export{Uint8ArrayToVariant,arrayToUint8Array,bindPublics,boolArray,bufferSourceRange,checkFormat,checkObject,checkUniform,convertPixels,extractImageData,flag,formatSize,isTypedArray,isValidString,listToArray,premultiplyAlpha,typeSize,uniformTypeSize,validCubeTarget,vertexCount};
|
|
@@ -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{isLegacyFormat as u}from"./context/texture-management/legacy-formats.js";import{WebGLContextBase as d}from"./webgl-context-base.js";import{installObjectLifecycleMethods as f}from"./webgl2-context/object-lifecycle.js";import{installTexImage3DMethods as p}from"./webgl2-context/tex-image-3d.js";import{installUniformMethods as m}from"./webgl2-context/uniform.js";import{installClearBufferMethods as h}from"./webgl2-context/clear-buffer.js";import{installInstancedAndFramebufferOpsMethods as g}from"./webgl2-context/instanced-and-framebuffer-ops.js";import _ from"gi://GdkPixbuf?version=2.0";import v from"@girs/gwebgl-0.1";import{warnNotImplemented as y}from"@gjsify/utils";var b=class WebGL2RenderingContext extends d{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 v.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:this._desktopGlslVersion()}_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 e of i){let n=t[e];if(n instanceof l&&u(n._format))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}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&&!u(r._format)){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(t>=36418&&t<=36422){this.setError(this.INVALID_ENUM);return}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 _.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 v=this._getTexImage(t);if(!v){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}}let b=o===h?this._legacyFormatStorage(h,d):null;this._saveError(),this._gl.texImage2D(t,n,b?b.internalFormat:o,p,m,g,b?b.format:h,d,e(y));let x=this.getError();if(this._restoreError(x),x!==this.NO_ERROR)return;this._setTextureSwizzle(t,v,b?b.swizzle:null),v._levelWidth[n]=p,v._levelHeight[n]=m,v._format=h,v._type=d;let S=this._activeFramebuffer;if(S){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(S._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,m=0,h=0;if(arguments.length===7)if(d=l,h=c,u instanceof _.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;let g=this._getTexImage(t);if(!g){this.setError(this.INVALID_OPERATION);return}if(this._legacySubImageMismatch(g,h)){this.setError(this.INVALID_OPERATION);return}let v=r(f);if(!v){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&v&&h===this.RGBA&&(v=a(v)),this._unpackFlipY&&v&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(v.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(v.subarray(r,r+t),i)}v=n}}let y=this._legacyFormatStorage(h,d)?.format??h;this._gl.texSubImage2D(t,n,o,s,p,m,y,d,e(v))}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 y(`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}};f(b.prototype),p(b.prototype),m(b.prototype),h(b.prototype),g(b.prototype);export{b as WebGL2RenderingContext};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,bufferSourceRange 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{isLegacyFormat as u}from"./context/texture-management/legacy-formats.js";import{WebGLContextBase as d}from"./webgl-context-base.js";import{installObjectLifecycleMethods as f}from"./webgl2-context/object-lifecycle.js";import{installTexImage3DMethods as p}from"./webgl2-context/tex-image-3d.js";import{installUniformMethods as m}from"./webgl2-context/uniform.js";import{installClearBufferMethods as h}from"./webgl2-context/clear-buffer.js";import{installInstancedAndFramebufferOpsMethods as g}from"./webgl2-context/instanced-and-framebuffer-ops.js";import _ from"gi://GdkPixbuf?version=2.0";import v from"@girs/gwebgl-0.1";import{warnNotImplemented as y}from"@gjsify/utils";var b=class WebGL2RenderingContext extends d{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 v.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:this._desktopGlslVersion()}_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 e of i){let n=t[e];if(n instanceof l&&u(n._format))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}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&&!u(r._format)){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,a=0,o=0){let s=n===35345||n===35982||n===36662||n===36663,c=i===35041||i===35043||i===35045||i===35042||i===35044||i===35046?this.STATIC_DRAW:i;if(s){if(typeof r==`number`)r>=0&&this._gl.bufferDataSizeOnly(n,r,c);else if(typeof r==`object`&&r){let i=t(r,a,o);if(!i){this.setError(this.INVALID_VALUE);return}this._gl.bufferData(n,e(i),c)}return}super.bufferData(n,r,c,a,o)}bufferSubData(n,r,i,a=0,o=0){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 s=t(i,a,o);if(!s){this.setError(this.INVALID_VALUE);return}this._gl.bufferSubData(n,r,e(s));return}super.bufferSubData(n,r,i,a,o)}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(t>=36418&&t<=36422){this.setError(this.INVALID_ENUM);return}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 _.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 v=this._getTexImage(t);if(!v){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}}let b=o===h?this._legacyFormatStorage(h,d):null;this._saveError(),this._gl.texImage2D(t,n,b?b.internalFormat:o,p,m,g,b?b.format:h,d,e(y));let x=this.getError();if(this._restoreError(x),x!==this.NO_ERROR)return;this._setTextureSwizzle(t,v,b?b.swizzle:null),v._levelWidth[n]=p,v._levelHeight[n]=m,v._format=h,v._type=d;let S=this._activeFramebuffer;if(S){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(S._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,m=0,h=0;if(arguments.length===7)if(d=l,h=c,u instanceof _.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;let g=this._getTexImage(t);if(!g){this.setError(this.INVALID_OPERATION);return}if(this._legacySubImageMismatch(g,h)){this.setError(this.INVALID_OPERATION);return}let v=r(f);if(!v){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&v&&h===this.RGBA&&(v=a(v)),this._unpackFlipY&&v&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(v.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(v.subarray(r,r+t),i)}v=n}}let y=this._legacyFormatStorage(h,d)?.format??h;this._gl.texSubImage2D(t,n,o,s,p,m,y,d,e(v))}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 y(`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}};f(b.prototype),p(b.prototype),m(b.prototype),h(b.prototype),g(b.prototype);export{b as WebGL2RenderingContext};
|
package/lib/esm/webgl2.spec.js
CHANGED
|
@@ -58,4 +58,4 @@ in vec2 a_pos;
|
|
|
58
58
|
void main(){gl_Position=vec4(a_pos,0.,1.);}`,`#version 300 es
|
|
59
59
|
precision mediump float;
|
|
60
60
|
out vec4 c;
|
|
61
|
-
void main(){c=vec4(0.,1.,0.,1.);}`);f(m.getProgramParameter(o,m.LINK_STATUS)).toBeTruthy();let s=m.createVertexArray();m.bindVertexArray(s);let c=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,c),m.bufferData(m.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),m.STATIC_DRAW);let l=m.getAttribLocation(o,`a_pos`);m.enableVertexAttribArray(l),m.vertexAttribPointer(l,2,m.FLOAT,!1,0,0),m.bindVertexArray(null),m.bindFramebuffer(m.FRAMEBUFFER,t),m.viewport(0,0,4,4),m.clearColor(0,0,1,1),m.clear(m.COLOR_BUFFER_BIT),m.useProgram(o),m.bindVertexArray(s),m.drawArrays(m.TRIANGLES,0,3),m.bindVertexArray(null),f(m.getError()).toBe(m.NO_ERROR),m.bindFramebuffer(36008,t),m.bindFramebuffer(36009,r),f(m.getError()).toBe(m.NO_ERROR),m.clearBufferfv(m.COLOR,0,[0,0,1,1]),f(m.getError()).toBe(m.NO_ERROR),m.blitFramebuffer(0,0,4,4,0,0,4,4,m.COLOR_BUFFER_BIT,m.LINEAR),f(m.getError()).toBe(m.NO_ERROR),m.bindFramebuffer(m.FRAMEBUFFER,r);let u=new Uint8Array(4);m.readPixels(0,0,1,1,m.RGBA,m.UNSIGNED_BYTE,u),f(m.getError()).toBe(m.NO_ERROR),m.bindFramebuffer(m.FRAMEBUFFER,t);let d=new Uint8Array(4);m.readPixels(0,0,1,1,m.RGBA,m.UNSIGNED_BYTE,d),f(m.getError()).toBe(m.NO_ERROR),m.bindVertexArray(null),m.deleteVertexArray(s),m.deleteBuffer(c),m.deleteProgram(o),m.bindFramebuffer(m.FRAMEBUFFER,t),m.framebufferTexture2D(m.FRAMEBUFFER,m.COLOR_ATTACHMENT0,m.TEXTURE_2D,null,0),m.bindFramebuffer(m.FRAMEBUFFER,r),m.framebufferTexture2D(m.FRAMEBUFFER,m.COLOR_ATTACHMENT0,m.TEXTURE_2D,null,0),m.bindFramebuffer(m.FRAMEBUFFER,null),m.deleteTexture(n),m.deleteTexture(i),m.deleteFramebuffer(t),m.deleteFramebuffer(r),f(u[0]).toBe(0),f(u[1]).toBe(255),f(u[2]).toBe(0),f(u[3]).toBe(255),f(d[0]).toBe(0),f(d[1]).toBe(255),f(d[2]).toBe(0),f(d[3]).toBe(255)})}),await d(`WebGL2 bufferSubData with UNIFORM_BUFFER`,async()=>{u(async()=>{e.make_current()}),await p(`bufferSubData with UNIFORM_BUFFER target returns NO_ERROR`,async()=>{let e=35345,t=m.createBuffer();m.bindBuffer(e,t),m.bufferData(e,new Float32Array([1,0,0,1]),m.STATIC_DRAW),f(m.getError()).toBe(m.NO_ERROR),m.bufferSubData(e,0,new Float32Array([0,1,0,1])),f(m.getError()).toBe(m.NO_ERROR),m.bindBuffer(e,null),m.deleteBuffer(t)})}),b.destroy()})},`default`);export{y as default};
|
|
61
|
+
void main(){c=vec4(0.,1.,0.,1.);}`);f(m.getProgramParameter(o,m.LINK_STATUS)).toBeTruthy();let s=m.createVertexArray();m.bindVertexArray(s);let c=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,c),m.bufferData(m.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),m.STATIC_DRAW);let l=m.getAttribLocation(o,`a_pos`);m.enableVertexAttribArray(l),m.vertexAttribPointer(l,2,m.FLOAT,!1,0,0),m.bindVertexArray(null),m.bindFramebuffer(m.FRAMEBUFFER,t),m.viewport(0,0,4,4),m.clearColor(0,0,1,1),m.clear(m.COLOR_BUFFER_BIT),m.useProgram(o),m.bindVertexArray(s),m.drawArrays(m.TRIANGLES,0,3),m.bindVertexArray(null),f(m.getError()).toBe(m.NO_ERROR),m.bindFramebuffer(36008,t),m.bindFramebuffer(36009,r),f(m.getError()).toBe(m.NO_ERROR),m.clearBufferfv(m.COLOR,0,[0,0,1,1]),f(m.getError()).toBe(m.NO_ERROR),m.blitFramebuffer(0,0,4,4,0,0,4,4,m.COLOR_BUFFER_BIT,m.LINEAR),f(m.getError()).toBe(m.NO_ERROR),m.bindFramebuffer(m.FRAMEBUFFER,r);let u=new Uint8Array(4);m.readPixels(0,0,1,1,m.RGBA,m.UNSIGNED_BYTE,u),f(m.getError()).toBe(m.NO_ERROR),m.bindFramebuffer(m.FRAMEBUFFER,t);let d=new Uint8Array(4);m.readPixels(0,0,1,1,m.RGBA,m.UNSIGNED_BYTE,d),f(m.getError()).toBe(m.NO_ERROR),m.bindVertexArray(null),m.deleteVertexArray(s),m.deleteBuffer(c),m.deleteProgram(o),m.bindFramebuffer(m.FRAMEBUFFER,t),m.framebufferTexture2D(m.FRAMEBUFFER,m.COLOR_ATTACHMENT0,m.TEXTURE_2D,null,0),m.bindFramebuffer(m.FRAMEBUFFER,r),m.framebufferTexture2D(m.FRAMEBUFFER,m.COLOR_ATTACHMENT0,m.TEXTURE_2D,null,0),m.bindFramebuffer(m.FRAMEBUFFER,null),m.deleteTexture(n),m.deleteTexture(i),m.deleteFramebuffer(t),m.deleteFramebuffer(r),f(u[0]).toBe(0),f(u[1]).toBe(255),f(u[2]).toBe(0),f(u[3]).toBe(255),f(d[0]).toBe(0),f(d[1]).toBe(255),f(d[2]).toBe(0),f(d[3]).toBe(255)})}),await d(`WebGL2 bufferSubData with UNIFORM_BUFFER`,async()=>{u(async()=>{e.make_current()}),await p(`bufferSubData with UNIFORM_BUFFER target returns NO_ERROR`,async()=>{let e=35345,t=m.createBuffer();m.bindBuffer(e,t),m.bufferData(e,new Float32Array([1,0,0,1]),m.STATIC_DRAW),f(m.getError()).toBe(m.NO_ERROR),m.bufferSubData(e,0,new Float32Array([0,1,0,1])),f(m.getError()).toBe(m.NO_ERROR),m.bindBuffer(e,null),m.deleteBuffer(t)})}),await d(`WebGL2 buffer upload srcOffset/length`,async()=>{u(async()=>{e.make_current()});let readBack=(e,t)=>{let n=new Float32Array(t);return m.getBufferSubData(e,0,n),Array.from(n).join(`,`)};await p(`bufferSubData uploads exactly [srcOffset, srcOffset+length) in elements`,async()=>{let e=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,e),m.bufferData(m.ARRAY_BUFFER,new Float32Array([0,0,0,0]),m.STATIC_READ),m.bufferSubData(m.ARRAY_BUFFER,4,new Float32Array([9,1,2,9,9]),1,2),f(m.getError()).toBe(m.NO_ERROR),f(readBack(m.ARRAY_BUFFER,4)).toBe(`0,1,2,0`),m.deleteBuffer(e)}),await p(`bufferSubData with length omitted uploads to the end`,async()=>{let e=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,e),m.bufferData(m.ARRAY_BUFFER,new Float32Array([0,0,0,0]),m.STATIC_READ),m.bufferSubData(m.ARRAY_BUFFER,0,new Float32Array([5,6,7,8]),2),f(m.getError()).toBe(m.NO_ERROR),f(readBack(m.ARRAY_BUFFER,4)).toBe(`7,8,0,0`),m.deleteBuffer(e)}),await p(`bufferSubData larger source than buffer works when length limits it`,async()=>{let e=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,e),m.bufferData(m.ARRAY_BUFFER,new Float32Array(2),m.STATIC_READ),m.bufferSubData(m.ARRAY_BUFFER,0,new Float32Array([3,4,5,6,7,8]),0,2),f(m.getError()).toBe(m.NO_ERROR),f(readBack(m.ARRAY_BUFFER,2)).toBe(`3,4`),m.deleteBuffer(e)}),await p(`bufferSubData out-of-range srcOffset/length is INVALID_VALUE`,async()=>{let e=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,e),m.bufferData(m.ARRAY_BUFFER,new Float32Array(4),m.STATIC_READ),m.bufferSubData(m.ARRAY_BUFFER,0,new Float32Array(2),3),f(m.getError()).toBe(m.INVALID_VALUE),m.bufferSubData(m.ARRAY_BUFFER,0,new Float32Array(2),1,2),f(m.getError()).toBe(m.INVALID_VALUE),m.deleteBuffer(e)}),await p(`bufferData honours srcOffset/length and sets the buffer size`,async()=>{let e=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,e),m.bufferData(m.ARRAY_BUFFER,new Float32Array([1,2,3,4,5]),m.STATIC_READ,1,3),f(m.getError()).toBe(m.NO_ERROR),f(m.getBufferParameter(m.ARRAY_BUFFER,m.BUFFER_SIZE)).toBe(12),f(readBack(m.ARRAY_BUFFER,3)).toBe(`2,3,4`),m.bufferData(m.ARRAY_BUFFER,new Float32Array(2),m.STATIC_READ,3),f(m.getError()).toBe(m.INVALID_VALUE),m.deleteBuffer(e)}),await p(`UNIFORM_BUFFER bufferSubData honours srcOffset/length`,async()=>{let e=35345,t=m.createBuffer();m.bindBuffer(e,t),m.bufferData(e,new Float32Array([0,0,0,0]),m.STATIC_READ),m.bufferSubData(e,0,new Float32Array([7,8,9]),1,2),f(m.getError()).toBe(m.NO_ERROR),f(readBack(e,4)).toBe(`8,9,0,0`),m.bufferSubData(e,0,new Float32Array(2),5),f(m.getError()).toBe(m.INVALID_VALUE),m.bindBuffer(e,null),m.deleteBuffer(t)}),await p(`ELEMENT_ARRAY_BUFFER shadow copy gets the sliced range`,async()=>{let e=m.createBuffer();m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,e),m.bufferData(m.ELEMENT_ARRAY_BUFFER,new Uint16Array([1,2,3,4]),m.STATIC_READ,1,2),f(m.getError()).toBe(m.NO_ERROR),f(e._size).toBe(4),m.bufferSubData(m.ELEMENT_ARRAY_BUFFER,2,new Uint16Array([9,8,7]),1,1);let t=new Uint16Array(e._elements.slice().buffer);f(Array.from(t).join(`,`)).toBe(`2,8`),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,null),m.deleteBuffer(e)})}),b.destroy()})},`default`);export{y as default};
|
|
@@ -2,8 +2,8 @@ import { WebGLBuffer } from '../webgl-buffer.js';
|
|
|
2
2
|
export interface BufferBindingMethods {
|
|
3
3
|
bindBuffer(target: GLenum | undefined, buffer: WebGLBuffer | null): void;
|
|
4
4
|
bufferData(target: GLenum, size: GLsizeiptr, usage: GLenum): void;
|
|
5
|
-
bufferData(target: GLenum, data: BufferSource | null, usage: GLenum): void;
|
|
6
|
-
bufferSubData(target?: GLenum, offset?: GLintptr, data?: BufferSource): void;
|
|
5
|
+
bufferData(target: GLenum, data: BufferSource | null, usage: GLenum, srcOffset?: number, length?: number): void;
|
|
6
|
+
bufferSubData(target?: GLenum, offset?: GLintptr, data?: BufferSource, srcOffset?: number, length?: number): void;
|
|
7
7
|
createBuffer(): WebGLBuffer | null;
|
|
8
8
|
deleteBuffer(buffer: WebGLBuffer | null): void;
|
|
9
9
|
getBufferParameter(target?: GLenum, pname?: GLenum): unknown;
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export declare function typeSize(gl: WebGLContextBase, type: GLenum): 0 | 1 | 2
|
|
|
14
14
|
export declare function uniformTypeSize(gl: WebGLContextBase, type: GLenum): 0 | 1 | 2 | 3 | 4;
|
|
15
15
|
export declare const listToArray: (values: Float32List) => number[];
|
|
16
16
|
export declare function arrayToUint8Array(array: TypedArray | Float32List | Array<number> | ArrayBuffer | DataView): Uint8Array<ArrayBufferLike>;
|
|
17
|
+
/**
|
|
18
|
+
* Byte view of `data[srcOffset, srcOffset + length)` per the WebGL2 buffer
|
|
19
|
+
* upload overloads: both counts are in elements of a typed array (bytes for
|
|
20
|
+
* DataView/ArrayBuffer), `length` 0 means "to the end". Zero-copy.
|
|
21
|
+
* Returns null when the range lies outside `data` (INVALID_VALUE).
|
|
22
|
+
*/
|
|
23
|
+
export declare function bufferSourceRange(data: TypedArray | ArrayBuffer | DataView, srcOffset?: number, length?: number): Uint8Array | null;
|
|
17
24
|
export declare function Uint8ArrayToVariant(array: Uint8Array | null): GLib.Variant<"ay">;
|
|
18
25
|
/**
|
|
19
26
|
* Converts an ArrayBufferView to an array of bools. gjs returns
|
|
@@ -87,9 +87,9 @@ export declare class WebGL2RenderingContext extends WebGLContextBase implements
|
|
|
87
87
|
/** WebGL2 also unbinds from read/draw framebuffer slots when deleting. */
|
|
88
88
|
deleteFramebuffer(framebuffer: WebGLFramebuffer | null): void;
|
|
89
89
|
/** WebGL2 adds READ/COPY buffer usages and additional buffer targets. */
|
|
90
|
-
bufferData(target: GLenum, dataOrSize: GLsizeiptr | BufferSource | null, usage: GLenum): void;
|
|
90
|
+
bufferData(target: GLenum, dataOrSize: GLsizeiptr | BufferSource | null, usage: GLenum, srcOffset?: number, length?: number): void;
|
|
91
91
|
/** WebGL2 adds UNIFORM_BUFFER, TRANSFORM_FEEDBACK_BUFFER, COPY_READ/WRITE targets. */
|
|
92
|
-
bufferSubData(target: GLenum, offset: GLintptr, data: BufferSource): void;
|
|
92
|
+
bufferSubData(target: GLenum, offset: GLintptr, data: BufferSource, srcOffset?: number, length?: number): void;
|
|
93
93
|
/** WebGL2 adds TEXTURE_3D and TEXTURE_2D_ARRAY target support. */
|
|
94
94
|
bindTexture(target: GLenum, texture: WebGLTexture | null): void;
|
|
95
95
|
/** WebGL2 adds TEXTURE_3D/TEXTURE_2D_ARRAY targets and many new pnames. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webgl",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.59",
|
|
4
4
|
"description": "WebGL module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"WebGL"
|
|
65
65
|
],
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@gjsify/cli": "0.64.
|
|
68
|
-
"@gjsify/unit": "0.64.
|
|
67
|
+
"@gjsify/cli": "0.64.59",
|
|
68
|
+
"@gjsify/unit": "0.64.59",
|
|
69
69
|
"@types/bit-twiddle": "^1.0.3",
|
|
70
70
|
"@types/node": "^25.9.2",
|
|
71
71
|
"typescript": "^6.0.3"
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"@girs/gjs": "5.4.0",
|
|
76
76
|
"@girs/gtk-4.0": "5.4.0",
|
|
77
77
|
"@girs/gwebgl-0.1": "0.1.0-4.0.0-rc.5",
|
|
78
|
-
"@gjsify/dom-elements": "0.64.
|
|
79
|
-
"@gjsify/dom-events": "0.64.
|
|
80
|
-
"@gjsify/event-bridge": "0.64.
|
|
81
|
-
"@gjsify/utils": "0.64.
|
|
78
|
+
"@gjsify/dom-elements": "0.64.59",
|
|
79
|
+
"@gjsify/dom-events": "0.64.59",
|
|
80
|
+
"@gjsify/event-bridge": "0.64.59",
|
|
81
|
+
"@gjsify/utils": "0.64.59",
|
|
82
82
|
"bit-twiddle": "^1.0.2",
|
|
83
83
|
"glsl-tokenizer": "^2.1.5"
|
|
84
84
|
},
|
|
@@ -93,13 +93,13 @@
|
|
|
93
93
|
},
|
|
94
94
|
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/framework/webgl#readme",
|
|
95
95
|
"optionalDependencies": {
|
|
96
|
-
"@gjsify/webgl-darwin-arm64": "0.64.
|
|
97
|
-
"@gjsify/webgl-darwin-x64": "0.64.
|
|
98
|
-
"@gjsify/webgl-linux-arm64": "0.64.
|
|
99
|
-
"@gjsify/webgl-linux-ppc64": "0.64.
|
|
100
|
-
"@gjsify/webgl-linux-riscv64": "0.64.
|
|
101
|
-
"@gjsify/webgl-linux-s390x": "0.64.
|
|
102
|
-
"@gjsify/webgl-linux-x64": "0.64.
|
|
103
|
-
"@gjsify/webgl-win32-x64": "0.64.
|
|
96
|
+
"@gjsify/webgl-darwin-arm64": "0.64.59",
|
|
97
|
+
"@gjsify/webgl-darwin-x64": "0.64.59",
|
|
98
|
+
"@gjsify/webgl-linux-arm64": "0.64.59",
|
|
99
|
+
"@gjsify/webgl-linux-ppc64": "0.64.59",
|
|
100
|
+
"@gjsify/webgl-linux-riscv64": "0.64.59",
|
|
101
|
+
"@gjsify/webgl-linux-s390x": "0.64.59",
|
|
102
|
+
"@gjsify/webgl-linux-x64": "0.64.59",
|
|
103
|
+
"@gjsify/webgl-win32-x64": "0.64.59"
|
|
104
104
|
}
|
|
105
105
|
}
|