@gjsify/webgl 0.3.16 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/conformance/attribs.spec.js +3 -315
- package/lib/esm/conformance/buffers.spec.js +1 -220
- package/lib/esm/conformance/context.spec.js +3 -302
- package/lib/esm/conformance/programs.spec.js +3 -477
- package/lib/esm/conformance/rendering-basic.spec.js +3 -141
- package/lib/esm/conformance/rendering.spec.js +7 -514
- package/lib/esm/conformance/setup.js +1 -47
- package/lib/esm/conformance/state.spec.js +1 -365
- package/lib/esm/conformance/textures.spec.js +3 -337
- package/lib/esm/conformance/uniforms.spec.js +1 -484
- package/lib/esm/conformance-test.js +1 -25
- package/lib/esm/extensions/ext-blend-minmax.js +1 -18
- package/lib/esm/extensions/ext-color-buffer-float.js +1 -12
- package/lib/esm/extensions/ext-color-buffer-half-float.js +1 -12
- package/lib/esm/extensions/ext-texture-filter-anisotropic.js +1 -18
- package/lib/esm/extensions/oes-element-index-unit.js +1 -13
- package/lib/esm/extensions/oes-standard-derivatives.js +1 -17
- package/lib/esm/extensions/oes-texture-float-linear.js +1 -13
- package/lib/esm/extensions/oes-texture-float.js +1 -13
- package/lib/esm/extensions/oes-texture-half-float.js +1 -19
- package/lib/esm/extensions/stackgl-destroy-context.js +1 -12
- package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +1 -12
- package/lib/esm/html-canvas-element.js +1 -65
- package/lib/esm/index.js +1 -33
- package/lib/esm/linkable.js +1 -50
- package/lib/esm/test-utils.js +4 -186
- package/lib/esm/test.js +1 -11
- package/lib/esm/types/index.js +1 -5
- package/lib/esm/utils.js +1 -201
- package/lib/esm/webgl-active-info.js +1 -11
- package/lib/esm/webgl-bridge.js +1 -167
- package/lib/esm/webgl-buffer.js +1 -19
- package/lib/esm/webgl-context-attributes.js +1 -24
- package/lib/esm/webgl-context-base.js +8 -3069
- package/lib/esm/webgl-drawing-buffer-wrapper.js +1 -11
- package/lib/esm/webgl-framebuffer.js +1 -110
- package/lib/esm/webgl-program.js +1 -27
- package/lib/esm/webgl-query.js +1 -17
- package/lib/esm/webgl-renderbuffer.js +1 -25
- package/lib/esm/webgl-rendering-context.js +1 -175
- package/lib/esm/webgl-sampler.js +1 -17
- package/lib/esm/webgl-shader-precision-format.js +1 -11
- package/lib/esm/webgl-shader.js +1 -25
- package/lib/esm/webgl-sync.js +1 -17
- package/lib/esm/webgl-texture-unit.js +1 -13
- package/lib/esm/webgl-texture.js +1 -23
- package/lib/esm/webgl-transform-feedback.js +1 -17
- package/lib/esm/webgl-uniform-location.js +1 -15
- package/lib/esm/webgl-vertex-array-object.js +1 -23
- package/lib/esm/webgl-vertex-attribute.js +1 -151
- package/lib/esm/webgl1.spec.js +10 -1044
- package/lib/esm/webgl2-rendering-context.js +1 -1218
- package/lib/esm/webgl2.spec.js +45 -1288
- package/lib/types/webgl-bridge.d.ts +9 -9
- package/package.json +9 -9
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var STACKGLDestroyContext = class {
|
|
3
|
-
constructor(ctx) {
|
|
4
|
-
this.destroy = ctx.destroy.bind(ctx);
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
|
-
function getSTACKGLDestroyContext(ctx) {
|
|
8
|
-
return new STACKGLDestroyContext(ctx);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { STACKGLDestroyContext, getSTACKGLDestroyContext };
|
|
1
|
+
var e=class{constructor(e){this.destroy=e.destroy.bind(e)}};function t(t){return new e(t)}export{e as STACKGLDestroyContext,t as getSTACKGLDestroyContext};
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var STACKGLResizeDrawingBuffer = class {
|
|
3
|
-
constructor(ctx) {
|
|
4
|
-
this.resize = ctx.resize.bind(ctx);
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
|
-
function getSTACKGLResizeDrawingBuffer(ctx) {
|
|
8
|
-
return new STACKGLResizeDrawingBuffer(ctx);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { STACKGLResizeDrawingBuffer, getSTACKGLResizeDrawingBuffer };
|
|
1
|
+
var e=class{constructor(e){this.resize=e.resize.bind(e)}};function t(t){return new e(t)}export{e as STACKGLResizeDrawingBuffer,t as getSTACKGLResizeDrawingBuffer};
|
|
@@ -1,65 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { WebGL2RenderingContext } from "./webgl2-rendering-context.js";
|
|
3
|
-
import { HTMLCanvasElement as HTMLCanvasElement$1 } from "@gjsify/dom-elements";
|
|
4
|
-
|
|
5
|
-
//#region src/ts/html-canvas-element.ts
|
|
6
|
-
var HTMLCanvasElement = class extends HTMLCanvasElement$1 {
|
|
7
|
-
constructor(gtkGlArea) {
|
|
8
|
-
super();
|
|
9
|
-
this.gtkGlArea = gtkGlArea;
|
|
10
|
-
}
|
|
11
|
-
/** Width from the GTK GLArea allocated size (overrides DOM attr-backed getter). */
|
|
12
|
-
get width() {
|
|
13
|
-
return this.gtkGlArea.get_allocated_width();
|
|
14
|
-
}
|
|
15
|
-
set width(_width) {}
|
|
16
|
-
/** Height from the GTK GLArea allocated size (overrides DOM attr-backed getter). */
|
|
17
|
-
get height() {
|
|
18
|
-
return this.gtkGlArea.get_allocated_height();
|
|
19
|
-
}
|
|
20
|
-
set height(_height) {}
|
|
21
|
-
get clientWidth() {
|
|
22
|
-
return this.width;
|
|
23
|
-
}
|
|
24
|
-
get clientHeight() {
|
|
25
|
-
return this.height;
|
|
26
|
-
}
|
|
27
|
-
/** CSS layout width — same as the GTK-allocated pixel width for a full-window canvas. */
|
|
28
|
-
get offsetWidth() {
|
|
29
|
-
return this.width;
|
|
30
|
-
}
|
|
31
|
-
/** CSS layout height — same as the GTK-allocated pixel height for a full-window canvas. */
|
|
32
|
-
get offsetHeight() {
|
|
33
|
-
return this.height;
|
|
34
|
-
}
|
|
35
|
-
/** Returns the underlying Gtk.GLArea. Used by WebGLRenderingContext for GLSL version detection. */
|
|
36
|
-
getGlArea() {
|
|
37
|
-
return this.gtkGlArea;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns a WebGL rendering context backed by the underlying Gtk.GLArea.
|
|
41
|
-
* 'webgl' and 'experimental-webgl' return a WebGLRenderingContext (WebGL 1.0).
|
|
42
|
-
* 'webgl2' returns a WebGL2RenderingContext (WebGL 2.0).
|
|
43
|
-
* Other context types emit a warning and return null.
|
|
44
|
-
*/
|
|
45
|
-
getContext(contextId, options) {
|
|
46
|
-
if (contextId === "webgl" || contextId === "experimental-webgl") {
|
|
47
|
-
if (!this._webgl) {
|
|
48
|
-
this.gtkGlArea.make_current();
|
|
49
|
-
this._webgl = new WebGLRenderingContext(this, options);
|
|
50
|
-
}
|
|
51
|
-
return this._webgl;
|
|
52
|
-
}
|
|
53
|
-
if (contextId === "webgl2") {
|
|
54
|
-
if (!this._webgl2) {
|
|
55
|
-
this.gtkGlArea.make_current();
|
|
56
|
-
this._webgl2 = new WebGL2RenderingContext(this, options);
|
|
57
|
-
}
|
|
58
|
-
return this._webgl2;
|
|
59
|
-
}
|
|
60
|
-
return super.getContext(contextId, options);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
|
-
export { HTMLCanvasElement };
|
|
1
|
+
import{WebGLRenderingContext as e}from"./webgl-rendering-context.js";import{WebGL2RenderingContext as t}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as n}from"@gjsify/dom-elements";var r=class extends n{constructor(e){super(),this.gtkGlArea=e}get width(){return this.gtkGlArea.get_allocated_width()}set width(e){}get height(){return this.gtkGlArea.get_allocated_height()}set height(e){}get clientWidth(){return this.width}get clientHeight(){return this.height}get offsetWidth(){return this.width}get offsetHeight(){return this.height}getGlArea(){return this.gtkGlArea}getContext(n,r){return n===`webgl`||n===`experimental-webgl`?(this._webgl||=(this.gtkGlArea.make_current(),new e(this,r)),this._webgl):n===`webgl2`?(this._webgl2||=(this.gtkGlArea.make_current(),new t(this,r)),this._webgl2):super.getContext(n,r)}};export{r as HTMLCanvasElement};
|
package/lib/esm/index.js
CHANGED
|
@@ -1,33 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WebGLUniformLocation } from "./webgl-uniform-location.js";
|
|
3
|
-
import { WebGLActiveInfo } from "./webgl-active-info.js";
|
|
4
|
-
import { WebGLFramebuffer } from "./webgl-framebuffer.js";
|
|
5
|
-
import { WebGLBuffer } from "./webgl-buffer.js";
|
|
6
|
-
import { WebGLDrawingBufferWrapper } from "./webgl-drawing-buffer-wrapper.js";
|
|
7
|
-
import { WebGLProgram } from "./webgl-program.js";
|
|
8
|
-
import { WebGLRenderbuffer } from "./webgl-renderbuffer.js";
|
|
9
|
-
import { WebGLShader } from "./webgl-shader.js";
|
|
10
|
-
import { WebGLShaderPrecisionFormat } from "./webgl-shader-precision-format.js";
|
|
11
|
-
import { WebGLTextureUnit } from "./webgl-texture-unit.js";
|
|
12
|
-
import { WebGLTexture } from "./webgl-texture.js";
|
|
13
|
-
import { WebGLVertexArrayGlobalAttribute, WebGLVertexArrayGlobalState, WebGLVertexArrayObjectAttribute, WebGLVertexArrayObjectState } from "./webgl-vertex-attribute.js";
|
|
14
|
-
import { WebGLContextBase } from "./webgl-context-base.js";
|
|
15
|
-
import { WebGLRenderingContext } from "./webgl-rendering-context.js";
|
|
16
|
-
import { WebGLQuery } from "./webgl-query.js";
|
|
17
|
-
import { WebGLSampler } from "./webgl-sampler.js";
|
|
18
|
-
import { WebGLSync } from "./webgl-sync.js";
|
|
19
|
-
import { WebGLTransformFeedback } from "./webgl-transform-feedback.js";
|
|
20
|
-
import { WebGLVertexArrayObject } from "./webgl-vertex-array-object.js";
|
|
21
|
-
import { WebGL2RenderingContext } from "./webgl2-rendering-context.js";
|
|
22
|
-
import { HTMLCanvasElement } from "./html-canvas-element.js";
|
|
23
|
-
import { WebGLBridge } from "./webgl-bridge.js";
|
|
24
|
-
import "@girs/gtk-4.0";
|
|
25
|
-
import "@girs/gjs";
|
|
26
|
-
import "@girs/gio-2.0";
|
|
27
|
-
|
|
28
|
-
//#region src/ts/index.ts
|
|
29
|
-
globalThis.WebGLRenderingContext = WebGLRenderingContext;
|
|
30
|
-
globalThis.WebGL2RenderingContext = WebGL2RenderingContext;
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { HTMLCanvasElement, WebGL2RenderingContext, WebGLActiveInfo, WebGLBridge, WebGLBuffer, WebGLContextAttributes, WebGLContextBase, WebGLDrawingBufferWrapper, WebGLFramebuffer, WebGLProgram, WebGLQuery, WebGLRenderbuffer, WebGLRenderingContext, WebGLSampler, WebGLShader, WebGLShaderPrecisionFormat, WebGLSync, WebGLTexture, WebGLTextureUnit, WebGLTransformFeedback, WebGLUniformLocation, WebGLVertexArrayGlobalAttribute, WebGLVertexArrayGlobalState, WebGLVertexArrayObject, WebGLVertexArrayObjectAttribute, WebGLVertexArrayObjectState };
|
|
1
|
+
import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{WebGLUniformLocation as t}from"./webgl-uniform-location.js";import{WebGLActiveInfo as n}from"./webgl-active-info.js";import{WebGLFramebuffer as r}from"./webgl-framebuffer.js";import{WebGLBuffer as i}from"./webgl-buffer.js";import{WebGLDrawingBufferWrapper as a}from"./webgl-drawing-buffer-wrapper.js";import{WebGLProgram as o}from"./webgl-program.js";import{WebGLRenderbuffer as s}from"./webgl-renderbuffer.js";import{WebGLShader as c}from"./webgl-shader.js";import{WebGLShaderPrecisionFormat as l}from"./webgl-shader-precision-format.js";import{WebGLTextureUnit as u}from"./webgl-texture-unit.js";import{WebGLTexture as d}from"./webgl-texture.js";import{WebGLVertexArrayGlobalAttribute as f,WebGLVertexArrayGlobalState as p,WebGLVertexArrayObjectAttribute as m,WebGLVertexArrayObjectState as h}from"./webgl-vertex-attribute.js";import{WebGLContextBase as g}from"./webgl-context-base.js";import{WebGLRenderingContext as _}from"./webgl-rendering-context.js";import{WebGLQuery as v}from"./webgl-query.js";import{WebGLSampler as y}from"./webgl-sampler.js";import{WebGLSync as b}from"./webgl-sync.js";import{WebGLTransformFeedback as x}from"./webgl-transform-feedback.js";import{WebGLVertexArrayObject as S}from"./webgl-vertex-array-object.js";import{WebGL2RenderingContext as C}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as w}from"./html-canvas-element.js";import{WebGLBridge as T}from"./webgl-bridge.js";import"@girs/gtk-4.0";import"@girs/gjs";import"@girs/gio-2.0";globalThis.WebGLRenderingContext=_,globalThis.WebGL2RenderingContext=C;export{w as HTMLCanvasElement,C as WebGL2RenderingContext,n as WebGLActiveInfo,T as WebGLBridge,i as WebGLBuffer,e as WebGLContextAttributes,g as WebGLContextBase,a as WebGLDrawingBufferWrapper,r as WebGLFramebuffer,o as WebGLProgram,v as WebGLQuery,s as WebGLRenderbuffer,_ as WebGLRenderingContext,y as WebGLSampler,c as WebGLShader,l as WebGLShaderPrecisionFormat,b as WebGLSync,d as WebGLTexture,u as WebGLTextureUnit,x as WebGLTransformFeedback,t as WebGLUniformLocation,f as WebGLVertexArrayGlobalAttribute,p as WebGLVertexArrayGlobalState,S as WebGLVertexArrayObject,m as WebGLVertexArrayObjectAttribute,h as WebGLVertexArrayObjectState};
|
package/lib/esm/linkable.js
CHANGED
|
@@ -1,50 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var Linkable = class {
|
|
3
|
-
constructor(_) {
|
|
4
|
-
this._ = 0;
|
|
5
|
-
this._references = [];
|
|
6
|
-
this._refCount = 0;
|
|
7
|
-
this._pendingDelete = false;
|
|
8
|
-
this._binding = 0;
|
|
9
|
-
this._ = _;
|
|
10
|
-
this._references = [];
|
|
11
|
-
this._refCount = 0;
|
|
12
|
-
this._pendingDelete = false;
|
|
13
|
-
this._binding = 0;
|
|
14
|
-
}
|
|
15
|
-
_link(b) {
|
|
16
|
-
this._references.push(b);
|
|
17
|
-
b._refCount += 1;
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
_unlink(b) {
|
|
21
|
-
let idx = this._references.indexOf(b);
|
|
22
|
-
if (idx < 0) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
while (idx >= 0) {
|
|
26
|
-
this._references[idx] = this._references[this._references.length - 1];
|
|
27
|
-
this._references.pop();
|
|
28
|
-
b._refCount -= 1;
|
|
29
|
-
b._checkDelete();
|
|
30
|
-
idx = this._references.indexOf(b);
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
_linked(b) {
|
|
35
|
-
return this._references.indexOf(b) >= 0;
|
|
36
|
-
}
|
|
37
|
-
_checkDelete() {
|
|
38
|
-
if (this._refCount <= 0 && this._pendingDelete && this._ !== 0) {
|
|
39
|
-
while (this._references.length > 0) {
|
|
40
|
-
this._unlink(this._references[0]);
|
|
41
|
-
}
|
|
42
|
-
this._performDelete();
|
|
43
|
-
this._ = 0;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
_performDelete() {}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
export { Linkable };
|
|
1
|
+
var e=class{constructor(e){this._=0,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0,this._=e,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0}_link(e){return this._references.push(e),e._refCount+=1,!0}_unlink(e){let t=this._references.indexOf(e);if(t<0)return!1;for(;t>=0;)this._references[t]=this._references[this._references.length-1],this._references.pop(),--e._refCount,e._checkDelete(),t=this._references.indexOf(e);return!0}_linked(e){return this._references.indexOf(e)>=0}_checkDelete(){if(this._refCount<=0&&this._pendingDelete&&this._!==0){for(;this._references.length>0;)this._unlink(this._references[0]);this._performDelete(),this._=0}}_performDelete(){}};export{e as Linkable};
|
package/lib/esm/test-utils.js
CHANGED
|
@@ -1,203 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
/** Compile a WebGL shader from source. Does not check compile status. */
|
|
3
|
-
function makeShader(gl, type, src) {
|
|
4
|
-
const shader = gl.createShader(type);
|
|
5
|
-
gl.shaderSource(shader, src);
|
|
6
|
-
gl.compileShader(shader);
|
|
7
|
-
return shader;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Link a WebGL program from vertex + fragment source strings.
|
|
11
|
-
* Binds attribute "position" to location 0 before linking so that drawTriangle() works
|
|
12
|
-
* without an explicit getAttribLocation() call.
|
|
13
|
-
* Does not check link status — call getProgramParameter(prog, LINK_STATUS) if needed.
|
|
14
|
-
*/
|
|
15
|
-
function makeProgram(gl, vsSrc, fsSrc) {
|
|
16
|
-
const frag = makeShader(gl, gl.FRAGMENT_SHADER, fsSrc);
|
|
17
|
-
const vert = makeShader(gl, gl.VERTEX_SHADER, vsSrc);
|
|
18
|
-
const program = gl.createProgram();
|
|
19
|
-
gl.attachShader(program, frag);
|
|
20
|
-
gl.attachShader(program, vert);
|
|
21
|
-
gl.bindAttribLocation(program, 0, "position");
|
|
22
|
-
gl.linkProgram(program);
|
|
23
|
-
return program;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Draw a fullscreen triangle using attribute location 0.
|
|
27
|
-
* Covers the entire clip space: vertices at (-2,-2), (-2,4), (4,-2).
|
|
28
|
-
* The active program must expose a vec2 attribute named "position" at location 0
|
|
29
|
-
* (ensured by makeProgram's bindAttribLocation call).
|
|
30
|
-
*/
|
|
31
|
-
function drawTriangle(gl) {
|
|
32
|
-
const buffer = gl.createBuffer();
|
|
33
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
34
|
-
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
|
35
|
-
-2,
|
|
36
|
-
-2,
|
|
37
|
-
-2,
|
|
38
|
-
4,
|
|
39
|
-
4,
|
|
40
|
-
-2
|
|
41
|
-
]), gl.STREAM_DRAW);
|
|
42
|
-
gl.enableVertexAttribArray(0);
|
|
43
|
-
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
|
44
|
-
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
45
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
46
|
-
gl.disableVertexAttribArray(0);
|
|
47
|
-
gl.deleteBuffer(buffer);
|
|
48
|
-
}
|
|
49
|
-
/** Read a single RGBA pixel at (x, y). Defaults to (0, 0). */
|
|
50
|
-
function readPixel(gl, x = 0, y = 0) {
|
|
51
|
-
const pixel = new Uint8Array(4);
|
|
52
|
-
gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
|
|
53
|
-
return pixel;
|
|
54
|
-
}
|
|
55
|
-
/** Return true if |a[i] - b[i]| <= tolerance for every RGBA component. */
|
|
56
|
-
function pixelClose(a, b, tolerance = 3) {
|
|
57
|
-
for (let i = 0; i < 4; i++) {
|
|
58
|
-
if (Math.abs(a[i] - b[i]) > tolerance) return false;
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Create a w×h RGBA8 FBO and bind it as the current framebuffer.
|
|
64
|
-
* Also sets the viewport to (0, 0, w, h).
|
|
65
|
-
* Call destroyTestFBO() when done.
|
|
66
|
-
*/
|
|
67
|
-
function makeTestFBO(gl, width = 4, height = 4) {
|
|
68
|
-
const fb = gl.createFramebuffer();
|
|
69
|
-
const colorTex = gl.createTexture();
|
|
70
|
-
gl.bindTexture(gl.TEXTURE_2D, colorTex);
|
|
71
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
72
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
73
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
74
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
75
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
76
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorTex, 0);
|
|
77
|
-
gl.viewport(0, 0, width, height);
|
|
78
|
-
return {
|
|
79
|
-
fb,
|
|
80
|
-
colorTex,
|
|
81
|
-
width,
|
|
82
|
-
height
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Create a w×h RGBA8 FBO with a DEPTH_COMPONENT16 renderbuffer and bind it.
|
|
87
|
-
* Also sets the viewport to (0, 0, w, h).
|
|
88
|
-
* Call destroyTestFBOWithDepth() when done.
|
|
89
|
-
*/
|
|
90
|
-
function makeTestFBOWithDepth(gl, width = 4, height = 4) {
|
|
91
|
-
const base = makeTestFBO(gl, width, height);
|
|
92
|
-
const depthRb = gl.createRenderbuffer();
|
|
93
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, depthRb);
|
|
94
|
-
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
|
|
95
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
96
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRb);
|
|
97
|
-
return {
|
|
98
|
-
...base,
|
|
99
|
-
depthRb
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/** Unbind the FBO and delete the color texture. */
|
|
103
|
-
function destroyTestFBO(gl, fbo) {
|
|
104
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.fb);
|
|
105
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);
|
|
106
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
107
|
-
gl.deleteTexture(fbo.colorTex);
|
|
108
|
-
gl.deleteFramebuffer(fbo.fb);
|
|
109
|
-
}
|
|
110
|
-
/** Unbind the FBO and delete both the color texture and depth renderbuffer. */
|
|
111
|
-
function destroyTestFBOWithDepth(gl, fbo) {
|
|
112
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.fb);
|
|
113
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);
|
|
114
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null);
|
|
115
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
116
|
-
gl.deleteTexture(fbo.colorTex);
|
|
117
|
-
gl.deleteRenderbuffer(fbo.depthRb);
|
|
118
|
-
gl.deleteFramebuffer(fbo.fb);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Create a w×h RGBA16F FBO (half-float color texture) and bind it.
|
|
122
|
-
* Used for testing Three.js post-processing render target patterns.
|
|
123
|
-
*/
|
|
124
|
-
function makeTestFBOFloat(gl, width = 4, height = 4) {
|
|
125
|
-
const RGBA16F = 34842;
|
|
126
|
-
const HALF_FLOAT = 5131;
|
|
127
|
-
const fb = gl.createFramebuffer();
|
|
128
|
-
const colorTex = gl.createTexture();
|
|
129
|
-
gl.bindTexture(gl.TEXTURE_2D, colorTex);
|
|
130
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, RGBA16F, width, height, 0, gl.RGBA, HALF_FLOAT, null);
|
|
131
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
132
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
133
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
134
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
135
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorTex, 0);
|
|
136
|
-
gl.viewport(0, 0, width, height);
|
|
137
|
-
return {
|
|
138
|
-
fb,
|
|
139
|
-
colorTex,
|
|
140
|
-
width,
|
|
141
|
-
height
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Create a w×h RGBA8 FBO with a DEPTH_COMPONENT24 texture attachment.
|
|
146
|
-
* Three.js uses depth textures (not renderbuffers) for RenderPixelatedPass.
|
|
147
|
-
*/
|
|
148
|
-
function makeTestFBOWithDepthTexture(gl, width = 4, height = 4) {
|
|
149
|
-
const DEPTH_COMPONENT24 = 33190;
|
|
150
|
-
const DEPTH_COMPONENT = 6402;
|
|
151
|
-
const UNSIGNED_INT = 5125;
|
|
152
|
-
const fb = gl.createFramebuffer();
|
|
153
|
-
const colorTex = gl.createTexture();
|
|
154
|
-
gl.bindTexture(gl.TEXTURE_2D, colorTex);
|
|
155
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
156
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
157
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
158
|
-
const depthTex = gl.createTexture();
|
|
159
|
-
gl.bindTexture(gl.TEXTURE_2D, depthTex);
|
|
160
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, DEPTH_COMPONENT24, width, height, 0, DEPTH_COMPONENT, UNSIGNED_INT, null);
|
|
161
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
162
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
163
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
164
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
165
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorTex, 0);
|
|
166
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTex, 0);
|
|
167
|
-
gl.viewport(0, 0, width, height);
|
|
168
|
-
return {
|
|
169
|
-
fb,
|
|
170
|
-
colorTex,
|
|
171
|
-
depthTex,
|
|
172
|
-
width,
|
|
173
|
-
height
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
/** WebGL2 passthrough texture shader (samples texture at UV and outputs it). */
|
|
177
|
-
const TEXTURE_VS_300 = `#version 300 es
|
|
1
|
+
function e(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}function t(t,n,r){let i=e(t,t.FRAGMENT_SHADER,r),a=e(t,t.VERTEX_SHADER,n),o=t.createProgram();return t.attachShader(o,i),t.attachShader(o,a),t.bindAttribLocation(o,0,`position`),t.linkProgram(o),o}function n(e){let t=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,t),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-2,-2,-2,4,4,-2]),e.STREAM_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3),e.bindBuffer(e.ARRAY_BUFFER,null),e.disableVertexAttribArray(0),e.deleteBuffer(t)}function r(e,t=0,n=0){let r=new Uint8Array(4);return e.readPixels(t,n,1,1,e.RGBA,e.UNSIGNED_BYTE,r),r}function i(e,t,n=3){for(let r=0;r<4;r++)if(Math.abs(e[r]-t[r])>n)return!1;return!0}function a(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,width:t,height:n}}function o(e,t=4,n=4){let r=a(e,t,n),i=e.createRenderbuffer();return e.bindRenderbuffer(e.RENDERBUFFER,i),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t,n),e.bindRenderbuffer(e.RENDERBUFFER,null),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,i),{...r,depthRb:i}}function s(e,t){e.bindFramebuffer(e.FRAMEBUFFER,t.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(t.colorTex),e.deleteFramebuffer(t.fb)}function c(e,t){e.bindFramebuffer(e.FRAMEBUFFER,t.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(t.colorTex),e.deleteRenderbuffer(t.depthRb),e.deleteFramebuffer(t.fb)}function l(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,34842,t,n,0,e.RGBA,5131,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,width:t,height:n}}function u(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texImage2D(e.TEXTURE_2D,0,33190,t,n,0,6402,5125,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,a,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,depthTex:a,width:t,height:n}}const d=`#version 300 es
|
|
178
2
|
in vec2 position;
|
|
179
3
|
out vec2 vUv;
|
|
180
4
|
void main() {
|
|
181
5
|
vUv = position * 0.5 + 0.5;
|
|
182
6
|
gl_Position = vec4(position, 0.0, 1.0);
|
|
183
|
-
}
|
|
184
|
-
const TEXTURE_FS_300 = `#version 300 es
|
|
7
|
+
}`,f=`#version 300 es
|
|
185
8
|
precision mediump float;
|
|
186
9
|
uniform sampler2D uTexture;
|
|
187
10
|
in vec2 vUv;
|
|
188
11
|
out vec4 fragColor;
|
|
189
12
|
void main() {
|
|
190
13
|
fragColor = texture(uTexture, vUv);
|
|
191
|
-
}
|
|
192
|
-
/** WebGL2 cubemap sampling shader. */
|
|
193
|
-
const CUBEMAP_FS_300 = `#version 300 es
|
|
14
|
+
}`,p=`#version 300 es
|
|
194
15
|
precision mediump float;
|
|
195
16
|
uniform samplerCube uCubemap;
|
|
196
17
|
uniform vec3 uDirection;
|
|
197
18
|
out vec4 fragColor;
|
|
198
19
|
void main() {
|
|
199
20
|
fragColor = texture(uCubemap, uDirection);
|
|
200
|
-
}`;
|
|
201
|
-
|
|
202
|
-
//#endregion
|
|
203
|
-
export { CUBEMAP_FS_300, TEXTURE_FS_300, TEXTURE_VS_300, destroyTestFBO, destroyTestFBOWithDepth, drawTriangle, makeProgram, makeShader, makeTestFBO, makeTestFBOFloat, makeTestFBOWithDepth, makeTestFBOWithDepthTexture, pixelClose, readPixel };
|
|
21
|
+
}`;export{p as CUBEMAP_FS_300,f as TEXTURE_FS_300,d as TEXTURE_VS_300,s as destroyTestFBO,c as destroyTestFBOWithDepth,n as drawTriangle,t as makeProgram,e as makeShader,a as makeTestFBO,l as makeTestFBOFloat,o as makeTestFBOWithDepth,u as makeTestFBOWithDepthTexture,i as pixelClose,r as readPixel};
|
package/lib/esm/test.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import webgl2_spec_default from "./webgl2.spec.js";
|
|
3
|
-
import { run } from "@gjsify/unit";
|
|
4
|
-
|
|
5
|
-
//#region src/ts/test.ts
|
|
6
|
-
run({ testSuite: async () => {
|
|
7
|
-
await webgl1_spec_default();
|
|
8
|
-
await webgl2_spec_default();
|
|
9
|
-
} });
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
1
|
+
import e from"./webgl1.spec.js";import t from"./webgl2.spec.js";import{run as n}from"@gjsify/unit";n({testSuite:async()=>{await e(),await t()}});
|
package/lib/esm/types/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./extension.js";
|
|
3
|
-
import "./typed-array.js";
|
|
4
|
-
import "./webgl-constants.js";
|
|
5
|
-
import "./webgl-context-attribute-options.js";
|
|
1
|
+
import"./constructor.js";import"./extension.js";import"./typed-array.js";import"./webgl-constants.js";import"./webgl-context-attribute-options.js";
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,201 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import GLib from "@girs/glib-2.0";
|
|
3
|
-
|
|
4
|
-
//#region src/ts/utils.ts
|
|
5
|
-
function bindPublics(props, wrapper, privateInstance, privateMethods) {
|
|
6
|
-
for (let i = 0; i < props.length; i++) {
|
|
7
|
-
const prop = props[i];
|
|
8
|
-
const value = privateInstance[prop];
|
|
9
|
-
if (typeof value === "function") {
|
|
10
|
-
if (privateMethods.indexOf(prop) === -1) {
|
|
11
|
-
wrapper[prop] = value.bind(privateInstance);
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
if (prop[0] === "_" || prop[0] === "0" || prop[0] === "1") {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
wrapper[prop] = value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function checkObject(object) {
|
|
22
|
-
return typeof object === "object" || object === undefined;
|
|
23
|
-
}
|
|
24
|
-
function checkUniform(program, location) {
|
|
25
|
-
return location instanceof WebGLUniformLocation && location._program === program && location._linkCount === program._linkCount;
|
|
26
|
-
}
|
|
27
|
-
function isTypedArray(data) {
|
|
28
|
-
return data instanceof Uint8Array || data instanceof Uint8ClampedArray || data instanceof Int8Array || data instanceof Uint16Array || data instanceof Int16Array || data instanceof Uint32Array || data instanceof Int32Array || data instanceof Float32Array || data instanceof Float64Array;
|
|
29
|
-
}
|
|
30
|
-
function isValidString(str) {
|
|
31
|
-
const c = str.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm, "");
|
|
32
|
-
return !/["$`@\\'\0]/.test(c);
|
|
33
|
-
}
|
|
34
|
-
function vertexCount(gl, primitive, count) {
|
|
35
|
-
switch (primitive) {
|
|
36
|
-
case gl.TRIANGLES: return count - count % 3;
|
|
37
|
-
case gl.LINES: return count - count % 2;
|
|
38
|
-
case gl.LINE_LOOP:
|
|
39
|
-
case gl.POINTS: return count;
|
|
40
|
-
case gl.TRIANGLE_FAN:
|
|
41
|
-
case gl.LINE_STRIP:
|
|
42
|
-
if (count < 2) {
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
return count;
|
|
46
|
-
case gl.TRIANGLE_STRIP:
|
|
47
|
-
if (count < 3) {
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
return count;
|
|
51
|
-
default: return -1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function typeSize(gl, type) {
|
|
55
|
-
switch (type) {
|
|
56
|
-
case gl.UNSIGNED_BYTE:
|
|
57
|
-
case gl.BYTE: return 1;
|
|
58
|
-
case gl.UNSIGNED_SHORT:
|
|
59
|
-
case gl.SHORT: return 2;
|
|
60
|
-
case gl.UNSIGNED_INT:
|
|
61
|
-
case gl.INT:
|
|
62
|
-
case gl.FLOAT: return 4;
|
|
63
|
-
}
|
|
64
|
-
return 0;
|
|
65
|
-
}
|
|
66
|
-
function uniformTypeSize(gl, type) {
|
|
67
|
-
switch (type) {
|
|
68
|
-
case gl.BOOL_VEC4:
|
|
69
|
-
case gl.INT_VEC4:
|
|
70
|
-
case gl.FLOAT_VEC4: return 4;
|
|
71
|
-
case gl.BOOL_VEC3:
|
|
72
|
-
case gl.INT_VEC3:
|
|
73
|
-
case gl.FLOAT_VEC3: return 3;
|
|
74
|
-
case gl.BOOL_VEC2:
|
|
75
|
-
case gl.INT_VEC2:
|
|
76
|
-
case gl.FLOAT_VEC2: return 2;
|
|
77
|
-
case gl.BOOL:
|
|
78
|
-
case gl.INT:
|
|
79
|
-
case gl.FLOAT:
|
|
80
|
-
case gl.SAMPLER_2D:
|
|
81
|
-
case gl.SAMPLER_CUBE: return 1;
|
|
82
|
-
default: return 0;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const listToArray = (values) => {
|
|
86
|
-
const array = [];
|
|
87
|
-
for (const value of values.values()) {
|
|
88
|
-
array.push(value);
|
|
89
|
-
}
|
|
90
|
-
return array;
|
|
91
|
-
};
|
|
92
|
-
function arrayToUint8Array(array) {
|
|
93
|
-
if (isTypedArray(array)) {
|
|
94
|
-
return new Uint8Array(array.buffer).subarray(array.byteOffset, array.byteLength + array.byteOffset);
|
|
95
|
-
}
|
|
96
|
-
if (Array.isArray(array) || array instanceof ArrayBuffer) {
|
|
97
|
-
return new Uint8Array(array);
|
|
98
|
-
}
|
|
99
|
-
if (typeof array.values === "function") {
|
|
100
|
-
return new Uint8Array(listToArray(array));
|
|
101
|
-
}
|
|
102
|
-
throw new Error("Can't unpack typed array!");
|
|
103
|
-
}
|
|
104
|
-
function Uint8ArrayToVariant(array) {
|
|
105
|
-
const variant = new GLib.Variant("ay", array);
|
|
106
|
-
return variant;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Converts an ArrayBufferView to an array of bools. gjs returns
|
|
110
|
-
* Uint8Array, but the elements are actually 4 bytes each.
|
|
111
|
-
* @param array
|
|
112
|
-
* @returns
|
|
113
|
-
*/
|
|
114
|
-
function boolArray(array) {
|
|
115
|
-
return Array.from(new Int32Array(array.buffer)).map((a) => a ? true : false);
|
|
116
|
-
}
|
|
117
|
-
const extractImageData = (pixels) => {
|
|
118
|
-
const width = pixels.width;
|
|
119
|
-
const height = pixels.height;
|
|
120
|
-
if (typeof pixels === "object" && typeof width !== "undefined" && typeof height !== "undefined") {
|
|
121
|
-
if (typeof pixels.data !== "undefined") {
|
|
122
|
-
return pixels;
|
|
123
|
-
}
|
|
124
|
-
let context = null;
|
|
125
|
-
if (typeof pixels.getContext === "function") {
|
|
126
|
-
context = pixels.getContext("2d");
|
|
127
|
-
} else if (typeof pixels.isPixbuf === "function" && pixels.isPixbuf()) {
|
|
128
|
-
return pixels.getImageData();
|
|
129
|
-
} else if (typeof pixels.src !== "undefined" && typeof document === "object" && typeof document.createElement === "function") {
|
|
130
|
-
const canvas = document.createElement("canvas");
|
|
131
|
-
if (typeof canvas === "object" && typeof canvas.getContext === "function") {
|
|
132
|
-
canvas.width = width;
|
|
133
|
-
canvas.height = height;
|
|
134
|
-
context = canvas.getContext("2d");
|
|
135
|
-
if (context !== null) {
|
|
136
|
-
context.drawImage(pixels, 0, 0);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (context !== null) {
|
|
141
|
-
return context.getImageData(0, 0, width, height);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
};
|
|
146
|
-
function formatSize(gl, internalFormat) {
|
|
147
|
-
switch (internalFormat) {
|
|
148
|
-
case gl.ALPHA:
|
|
149
|
-
case gl.LUMINANCE: return 1;
|
|
150
|
-
case gl.LUMINANCE_ALPHA: return 2;
|
|
151
|
-
case gl.RGB: return 3;
|
|
152
|
-
case gl.RGBA: return 4;
|
|
153
|
-
}
|
|
154
|
-
return 0;
|
|
155
|
-
}
|
|
156
|
-
function convertPixels(pixels) {
|
|
157
|
-
if (typeof pixels === "object" && pixels !== null) {
|
|
158
|
-
if (pixels instanceof ArrayBuffer) {
|
|
159
|
-
return new Uint8Array(pixels);
|
|
160
|
-
} else if (pixels instanceof Uint8Array || pixels instanceof Uint16Array || pixels instanceof Uint8ClampedArray || pixels instanceof Float32Array) {
|
|
161
|
-
return arrayToUint8Array(pixels);
|
|
162
|
-
} else if (pixels instanceof Buffer) {
|
|
163
|
-
return new Uint8Array(pixels);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
function checkFormat(gl, format) {
|
|
169
|
-
return format === gl.ALPHA || format === gl.LUMINANCE_ALPHA || format === gl.LUMINANCE || format === gl.RGB || format === gl.RGBA;
|
|
170
|
-
}
|
|
171
|
-
function validCubeTarget(gl, target) {
|
|
172
|
-
return target === gl.TEXTURE_CUBE_MAP_POSITIVE_X || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_X || target === gl.TEXTURE_CUBE_MAP_POSITIVE_Y || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Y || target === gl.TEXTURE_CUBE_MAP_POSITIVE_Z || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Z;
|
|
173
|
-
}
|
|
174
|
-
function flag(options, name, dflt) {
|
|
175
|
-
if (!options || !(typeof options === "object") || !(name in options)) {
|
|
176
|
-
return dflt;
|
|
177
|
-
}
|
|
178
|
-
return !!options[name];
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Premultiply RGB channels by the alpha channel (in-place copy).
|
|
182
|
-
* Required when UNPACK_PREMULTIPLY_ALPHA_WEBGL is set.
|
|
183
|
-
* Excalibur uses blendFunc(ONE, ONE_MINUS_SRC_ALPHA) (premultiplied alpha
|
|
184
|
-
* blending), so textures must have RGB already multiplied by alpha before
|
|
185
|
-
* upload. Without this, transparent-background PNGs (alpha=0 but RGB=255)
|
|
186
|
-
* bleed through as white rectangles.
|
|
187
|
-
*/
|
|
188
|
-
function premultiplyAlpha(data) {
|
|
189
|
-
const out = new Uint8Array(data.length);
|
|
190
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
191
|
-
const a = data[i + 3] / 255;
|
|
192
|
-
out[i] = Math.round(data[i] * a);
|
|
193
|
-
out[i + 1] = Math.round(data[i + 1] * a);
|
|
194
|
-
out[i + 2] = Math.round(data[i + 2] * a);
|
|
195
|
-
out[i + 3] = data[i + 3];
|
|
196
|
-
}
|
|
197
|
-
return out;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
|
-
export { Uint8ArrayToVariant, arrayToUint8Array, bindPublics, boolArray, checkFormat, checkObject, checkUniform, convertPixels, extractImageData, flag, formatSize, isTypedArray, isValidString, listToArray, premultiplyAlpha, typeSize, uniformTypeSize, validCubeTarget, vertexCount };
|
|
1
|
+
import{WebGLUniformLocation as e}from"./webgl-uniform-location.js";import t from"@girs/glib-2.0";function n(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 r(e){return typeof e==`object`||e===void 0}function i(t,n){return n instanceof e&&n._program===t&&n._linkCount===t._linkCount}function a(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 o(e){let t=e.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm,``);return!/["$`@\\'\0]/.test(t)}function s(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 c(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 l(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 u=e=>{let t=[];for(let n of e.values())t.push(n);return t};function d(e){if(a(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(u(e));throw Error(`Can't unpack typed array!`)}function f(e){return new t.Variant(`ay`,e)}function p(e){return Array.from(new Int32Array(e.buffer)).map(e=>!!e)}const m=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 h(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 g(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 d(e);if(e instanceof Buffer)return new Uint8Array(e)}return null}function _(e,t){return t===e.ALPHA||t===e.LUMINANCE_ALPHA||t===e.LUMINANCE||t===e.RGB||t===e.RGBA}function v(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 y(e,t,n){return!e||typeof e!=`object`||!(t in e)?n:!!e[t]}function b(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{f as Uint8ArrayToVariant,d as arrayToUint8Array,n as bindPublics,p as boolArray,_ as checkFormat,r as checkObject,i as checkUniform,g as convertPixels,m as extractImageData,y as flag,h as formatSize,a as isTypedArray,o as isValidString,u as listToArray,b as premultiplyAlpha,c as typeSize,l as uniformTypeSize,v as validCubeTarget,s as vertexCount};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var WebGLActiveInfo = class {
|
|
3
|
-
constructor(_) {
|
|
4
|
-
this.size = _.size;
|
|
5
|
-
this.type = _.type;
|
|
6
|
-
this.name = _.name;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
export { WebGLActiveInfo };
|
|
1
|
+
var e=class{constructor(e){this.size=e.size,this.type=e.type,this.name=e.name}};export{e as WebGLActiveInfo};
|