@gjsify/webgl 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +14 -0
  2. package/lib/cjs/@types/glsl-tokenizer/index.d.js +0 -0
  3. package/lib/cjs/extensions/ext-blend-minmax.js +37 -0
  4. package/lib/cjs/extensions/ext-texture-filter-anisotropic.js +37 -0
  5. package/lib/cjs/extensions/oes-element-index-unit.js +33 -0
  6. package/lib/cjs/extensions/oes-standard-derivatives.js +36 -0
  7. package/lib/cjs/extensions/oes-texture-float-linear.js +33 -0
  8. package/lib/cjs/extensions/oes-texture-float.js +33 -0
  9. package/lib/cjs/extensions/stackgl-destroy-context.js +31 -0
  10. package/lib/cjs/extensions/stackgl-resize-drawing-buffer.js +31 -0
  11. package/lib/cjs/html-canvas-element.js +89 -0
  12. package/lib/cjs/index.js +34 -0
  13. package/lib/cjs/index.spec.js +175 -0
  14. package/lib/cjs/linkable.js +69 -0
  15. package/lib/cjs/test.js +25 -0
  16. package/lib/cjs/types/constructor.js +15 -0
  17. package/lib/cjs/types/extension.js +15 -0
  18. package/lib/cjs/types/index.js +21 -0
  19. package/lib/cjs/types/typed-array.js +15 -0
  20. package/lib/cjs/types/webgl-constants.js +15 -0
  21. package/lib/cjs/types/webgl-context-attribute-options.js +15 -0
  22. package/lib/cjs/utils.js +241 -0
  23. package/lib/cjs/webgl-active-info.js +29 -0
  24. package/lib/cjs/webgl-buffer.js +37 -0
  25. package/lib/cjs/webgl-context-attributes.js +43 -0
  26. package/lib/cjs/webgl-drawing-buffer-wrapper.js +29 -0
  27. package/lib/cjs/webgl-framebuffer.js +128 -0
  28. package/lib/cjs/webgl-program.js +45 -0
  29. package/lib/cjs/webgl-renderbuffer.js +43 -0
  30. package/lib/cjs/webgl-rendering-context.js +3355 -0
  31. package/lib/cjs/webgl-shader-precision-format.js +30 -0
  32. package/lib/cjs/webgl-shader.js +42 -0
  33. package/lib/cjs/webgl-texture-unit.js +31 -0
  34. package/lib/cjs/webgl-texture.js +41 -0
  35. package/lib/cjs/webgl-uniform-location.js +34 -0
  36. package/lib/cjs/webgl-vertex-attribute.js +166 -0
  37. package/lib/esm/@types/glsl-tokenizer/index.d.js +0 -0
  38. package/lib/esm/extensions/ext-blend-minmax.js +18 -0
  39. package/lib/esm/extensions/ext-texture-filter-anisotropic.js +18 -0
  40. package/lib/esm/extensions/oes-element-index-unit.js +14 -0
  41. package/lib/esm/extensions/oes-standard-derivatives.js +17 -0
  42. package/lib/esm/extensions/oes-texture-float-linear.js +14 -0
  43. package/lib/esm/extensions/oes-texture-float.js +14 -0
  44. package/lib/esm/extensions/stackgl-destroy-context.js +12 -0
  45. package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +12 -0
  46. package/lib/esm/html-canvas-element.js +70 -0
  47. package/lib/esm/index.js +18 -0
  48. package/lib/esm/index.spec.js +146 -0
  49. package/lib/esm/linkable.js +50 -0
  50. package/lib/esm/test.js +3 -0
  51. package/lib/esm/types/constructor.js +0 -0
  52. package/lib/esm/types/extension.js +0 -0
  53. package/lib/esm/types/index.js +5 -0
  54. package/lib/esm/types/typed-array.js +0 -0
  55. package/lib/esm/types/webgl-constants.js +0 -0
  56. package/lib/esm/types/webgl-context-attribute-options.js +0 -0
  57. package/lib/esm/utils.js +212 -0
  58. package/lib/esm/webgl-active-info.js +10 -0
  59. package/lib/esm/webgl-buffer.js +18 -0
  60. package/lib/esm/webgl-context-attributes.js +24 -0
  61. package/lib/esm/webgl-drawing-buffer-wrapper.js +10 -0
  62. package/lib/esm/webgl-framebuffer.js +109 -0
  63. package/lib/esm/webgl-program.js +26 -0
  64. package/lib/esm/webgl-renderbuffer.js +24 -0
  65. package/lib/esm/webgl-rendering-context.js +3343 -0
  66. package/lib/esm/webgl-shader-precision-format.js +11 -0
  67. package/lib/esm/webgl-shader.js +23 -0
  68. package/lib/esm/webgl-texture-unit.js +12 -0
  69. package/lib/esm/webgl-texture.js +22 -0
  70. package/lib/esm/webgl-uniform-location.js +15 -0
  71. package/lib/esm/webgl-vertex-attribute.js +147 -0
  72. package/lib/types/extensions/ext-blend-minmax.d.ts +7 -0
  73. package/lib/types/extensions/ext-texture-filter-anisotropic.d.ts +7 -0
  74. package/lib/types/extensions/oes-element-index-unit.d.ts +4 -0
  75. package/lib/types/extensions/oes-standard-derivatives.d.ts +6 -0
  76. package/lib/types/extensions/oes-texture-float-linear.d.ts +4 -0
  77. package/lib/types/extensions/oes-texture-float.d.ts +4 -0
  78. package/lib/types/extensions/stackgl-destroy-context.d.ts +6 -0
  79. package/lib/types/extensions/stackgl-resize-drawing-buffer.d.ts +6 -0
  80. package/lib/types/html-canvas-element.d.ts +38 -0
  81. package/lib/types/index.d.ts +18 -0
  82. package/lib/types/linkable.d.ts +13 -0
  83. package/lib/types/types/constructor.d.ts +3 -0
  84. package/lib/types/types/extension.d.ts +2 -0
  85. package/lib/types/types/index.d.ts +5 -0
  86. package/lib/types/types/typed-array.d.ts +1 -0
  87. package/lib/types/types/webgl-constants.d.ts +299 -0
  88. package/lib/types/types/webgl-context-attribute-options.d.ts +12 -0
  89. package/lib/types/utils.d.ts +32 -0
  90. package/lib/types/webgl-active-info.d.ts +7 -0
  91. package/lib/types/webgl-buffer.d.ts +10 -0
  92. package/lib/types/webgl-context-attributes.d.ts +14 -0
  93. package/lib/types/webgl-drawing-buffer-wrapper.d.ts +6 -0
  94. package/lib/types/webgl-framebuffer.d.ts +17 -0
  95. package/lib/types/webgl-program.d.ts +14 -0
  96. package/lib/types/webgl-renderbuffer.d.ts +12 -0
  97. package/lib/types/webgl-rendering-context.d.ts +260 -0
  98. package/lib/types/webgl-shader-precision-format.d.ts +7 -0
  99. package/lib/types/webgl-shader.d.ts +12 -0
  100. package/lib/types/webgl-texture-unit.d.ts +10 -0
  101. package/lib/types/webgl-texture.d.ts +14 -0
  102. package/lib/types/webgl-uniform-location.d.ts +18 -0
  103. package/lib/types/webgl-vertex-attribute.d.ts +38 -0
  104. package/meson.build +39 -0
  105. package/package.json +55 -0
  106. package/src/test/app.vala +60 -0
  107. package/src/ts/@types/glsl-tokenizer/index.d.ts +18 -0
  108. package/src/ts/extensions/angle-instanced-arrays.ts.off +232 -0
  109. package/src/ts/extensions/ext-blend-minmax.ts +18 -0
  110. package/src/ts/extensions/ext-texture-filter-anisotropic.ts +18 -0
  111. package/src/ts/extensions/oes-element-index-unit.ts +14 -0
  112. package/src/ts/extensions/oes-standard-derivatives.ts +17 -0
  113. package/src/ts/extensions/oes-texture-float-linear.ts +14 -0
  114. package/src/ts/extensions/oes-texture-float.ts +14 -0
  115. package/src/ts/extensions/oes-vertex-array-object.ts.off +128 -0
  116. package/src/ts/extensions/stackgl-destroy-context.ts +12 -0
  117. package/src/ts/extensions/stackgl-resize-drawing-buffer.ts +14 -0
  118. package/src/ts/extensions/webgl-draw-buffers.ts.off +107 -0
  119. package/src/ts/html-canvas-element.ts +98 -0
  120. package/src/ts/index.spec.ts +186 -0
  121. package/src/ts/index.ts +21 -0
  122. package/src/ts/linkable.ts +55 -0
  123. package/src/ts/test.ts +6 -0
  124. package/src/ts/types/constructor.ts +3 -0
  125. package/src/ts/types/extension.ts +3 -0
  126. package/src/ts/types/index.ts +26 -0
  127. package/src/ts/types/typed-array.ts +1 -0
  128. package/src/ts/types/webgl-constants.ts +300 -0
  129. package/src/ts/types/webgl-context-attribute-options.ts +12 -0
  130. package/src/ts/utils.ts +266 -0
  131. package/src/ts/webgl-active-info.ts +13 -0
  132. package/src/ts/webgl-buffer.ts +21 -0
  133. package/src/ts/webgl-context-attributes.ts +24 -0
  134. package/src/ts/webgl-drawing-buffer-wrapper.ts +10 -0
  135. package/src/ts/webgl-framebuffer.ts +133 -0
  136. package/src/ts/webgl-program.ts +30 -0
  137. package/src/ts/webgl-renderbuffer.ts +28 -0
  138. package/src/ts/webgl-rendering-context.ts +4050 -0
  139. package/src/ts/webgl-shader-precision-format.ts +12 -0
  140. package/src/ts/webgl-shader.ts +29 -0
  141. package/src/ts/webgl-texture-unit.ts +16 -0
  142. package/src/ts/webgl-texture.ts +27 -0
  143. package/src/ts/webgl-uniform-location.ts +18 -0
  144. package/src/ts/webgl-vertex-attribute.ts +169 -0
  145. package/src/vala/handle-types.vala +23 -0
  146. package/src/vala/webgl-rendering-context-base.vala +1265 -0
  147. package/src/vala/webgl-rendering-context.vala +265 -0
  148. package/src/vapi/epoxy.vapi +14558 -0
  149. package/src/vapi/glesv2.vapi +670 -0
  150. package/test.gjs.js +39972 -0
  151. package/test.gjs.js.meta.json +1 -0
  152. package/tmp/.tsbuildinfo +1 -0
  153. package/tsconfig.json +38 -0
  154. package/tsconfig.types.json +7 -0
@@ -0,0 +1,266 @@
1
+ // https://github.com/stackgl/headless-gl/blob/master/src/javascript/utils.js
2
+ // import { gl } from './native-gl.js';
3
+ import { WebGLUniformLocation } from './webgl-uniform-location.js';
4
+ import { WebGLProgram } from './webgl-program.js';
5
+ import GLib from '@girs/glib-2.0';
6
+ import { HTMLImageElement as GjsifyHTMLImageElement } from "@gjsify/html-image-element";
7
+
8
+ import type Gwebgl from '@girs/gwebgl-0.1';
9
+ import type { GjsifyWebGLRenderingContext } from './webgl-rendering-context.js';
10
+ import type { TypedArray} from './types/index.js';
11
+
12
+ export function bindPublics(props: Array<keyof GjsifyWebGLRenderingContext>, wrapper: GjsifyWebGLRenderingContext, privateInstance: GjsifyWebGLRenderingContext, privateMethods: string[]) {
13
+ for (let i = 0; i < props.length; i++) {
14
+ const prop = props[i]
15
+ const value = privateInstance[prop]
16
+ if (typeof value === 'function') {
17
+ if (privateMethods.indexOf(prop) === -1) {
18
+ // @ts-ignore
19
+ wrapper[prop] = value.bind(privateInstance)
20
+ }
21
+ } else {
22
+ if (prop[0] === '_' ||
23
+ prop[0] === '0' ||
24
+ prop[0] === '1') {
25
+ continue
26
+ }
27
+ // @ts-ignore
28
+ wrapper[prop] = value
29
+ }
30
+ }
31
+ }
32
+
33
+ export function checkObject(object: any) {
34
+ return typeof object === 'object' ||
35
+ (object === undefined)
36
+ }
37
+
38
+ export function checkUniform(program: WebGLProgram, location: WebGLUniformLocation) {
39
+ return location instanceof WebGLUniformLocation &&
40
+ location._program === program &&
41
+ location._linkCount === program._linkCount
42
+ }
43
+
44
+ export function isTypedArray(data: TypedArray) {
45
+ return data instanceof Uint8Array ||
46
+ data instanceof Uint8ClampedArray ||
47
+ data instanceof Int8Array ||
48
+ data instanceof Uint16Array ||
49
+ data instanceof Int16Array ||
50
+ data instanceof Uint32Array ||
51
+ data instanceof Int32Array ||
52
+ data instanceof Float32Array ||
53
+ data instanceof Float64Array
54
+ }
55
+
56
+ // Don't allow: ", $, `, @, \, ', \0
57
+ export function isValidString(str: string) {
58
+ // Remove comments first
59
+ const c = str.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm, '')
60
+ return !(/["$`@\\'\0]/.test(c))
61
+ }
62
+
63
+ export function vertexCount(gl: GjsifyWebGLRenderingContext, primitive: GLenum, count: number) {
64
+ switch (primitive) {
65
+ case gl.TRIANGLES:
66
+ return count - (count % 3)
67
+ case gl.LINES:
68
+ return count - (count % 2)
69
+ case gl.LINE_LOOP:
70
+ case gl.POINTS:
71
+ return count
72
+ case gl.TRIANGLE_FAN:
73
+ case gl.LINE_STRIP:
74
+ if (count < 2) {
75
+ return 0
76
+ }
77
+ return count
78
+ case gl.TRIANGLE_STRIP:
79
+ if (count < 3) {
80
+ return 0
81
+ }
82
+ return count
83
+ default:
84
+ return -1
85
+ }
86
+ }
87
+
88
+ export function typeSize(gl: GjsifyWebGLRenderingContext, type: GLenum) {
89
+ switch (type) {
90
+ case gl.UNSIGNED_BYTE:
91
+ case gl.BYTE:
92
+ return 1
93
+ case gl.UNSIGNED_SHORT:
94
+ case gl.SHORT:
95
+ return 2
96
+ case gl.UNSIGNED_INT:
97
+ case gl.INT:
98
+ case gl.FLOAT:
99
+ return 4
100
+ }
101
+ return 0
102
+ }
103
+
104
+ export function uniformTypeSize(gl: GjsifyWebGLRenderingContext, type: GLenum) {
105
+ switch (type) {
106
+ case gl.BOOL_VEC4:
107
+ case gl.INT_VEC4:
108
+ case gl.FLOAT_VEC4:
109
+ return 4
110
+
111
+ case gl.BOOL_VEC3:
112
+ case gl.INT_VEC3:
113
+ case gl.FLOAT_VEC3:
114
+ return 3
115
+
116
+ case gl.BOOL_VEC2:
117
+ case gl.INT_VEC2:
118
+ case gl.FLOAT_VEC2:
119
+ return 2
120
+
121
+ case gl.BOOL:
122
+ case gl.INT:
123
+ case gl.FLOAT:
124
+ case gl.SAMPLER_2D:
125
+ case gl.SAMPLER_CUBE:
126
+ return 1
127
+
128
+ default:
129
+ return 0
130
+ }
131
+ }
132
+
133
+ export const listToArray = (values: Float32List) => {
134
+ const array: number[] = [];
135
+ for (const value of values.values()) {
136
+ array.push(value)
137
+ }
138
+ return array;
139
+ }
140
+
141
+ export function arrayToUint8Array(array: TypedArray | Float32List | Array<number> | ArrayBuffer | DataView) {
142
+
143
+ if(isTypedArray(array as TypedArray | DataView)) {
144
+ return (new Uint8Array((array as TypedArray | DataView).buffer)).subarray(
145
+ (array as TypedArray | DataView).byteOffset,
146
+ (array as TypedArray | DataView).byteLength + (array as TypedArray | DataView).byteOffset)
147
+ }
148
+
149
+ if(Array.isArray(array) || array instanceof ArrayBuffer) {
150
+ return new Uint8Array(array);
151
+ }
152
+
153
+ if(typeof (array as Float32List).values === 'function') {
154
+ return new Uint8Array(listToArray(array as Float32List))
155
+ }
156
+
157
+ throw new Error("Can't unpack typed array!");
158
+ }
159
+
160
+ export function Uint8ArrayToVariant(array: Uint8Array | null) {
161
+ const variant = new GLib.Variant("ay", Array.from(array || []));
162
+ return variant
163
+ }
164
+
165
+ /**
166
+ * Converts an ArrayBufferView to an array of bools. gjs returns
167
+ * Uint8Array, but the elements are actually 4 bytes each.
168
+ * @param array
169
+ * @returns
170
+ */
171
+ export function boolArray(array: ArrayBufferView) {
172
+ return Array.from(new Int32Array(array.buffer)).map(
173
+ a => a ? true : false);
174
+ }
175
+
176
+ export const extractImageData = (pixels: TexImageSource | GjsifyHTMLImageElement): ImageData | null => {
177
+ const width = (pixels as any).width as number | undefined;
178
+ const height = (pixels as any).height as number | undefined;
179
+ if (typeof pixels === 'object' && typeof width !== 'undefined' && typeof height !== 'undefined') {
180
+ if (typeof (pixels as ImageData).data !== 'undefined') {
181
+ return pixels as ImageData
182
+ }
183
+
184
+ let context = null
185
+
186
+ if (typeof (pixels as HTMLCanvasElement).getContext === 'function') {
187
+ context = (pixels as HTMLCanvasElement).getContext('2d')
188
+ } else if (typeof (pixels as GjsifyHTMLImageElement).isPixbuf()) {
189
+ return (pixels as GjsifyHTMLImageElement).getImageData();
190
+ } else if (typeof (pixels as HTMLImageElement).src !== 'undefined' && typeof document === 'object' && typeof document.createElement === 'function') {
191
+ const canvas = document.createElement('canvas')
192
+
193
+ if (typeof canvas === 'object' && typeof canvas.getContext === 'function') {
194
+ canvas.width = width
195
+ canvas.height = height
196
+ context = canvas.getContext('2d')
197
+
198
+ if (context !== null) {
199
+ context.drawImage(pixels as CanvasImageSource, 0, 0)
200
+ }
201
+ }
202
+ }
203
+
204
+ if (context !== null) {
205
+ return context.getImageData(0, 0, width, height)
206
+ }
207
+ }
208
+
209
+ return null
210
+ }
211
+
212
+ export function formatSize(gl: GjsifyWebGLRenderingContext, internalFormat: number) {
213
+ switch (internalFormat) {
214
+ case gl.ALPHA:
215
+ case gl.LUMINANCE:
216
+ return 1
217
+ case gl.LUMINANCE_ALPHA:
218
+ return 2
219
+ case gl.RGB:
220
+ return 3
221
+ case gl.RGBA:
222
+ return 4
223
+ }
224
+ return 0
225
+ }
226
+
227
+ export function convertPixels(pixels: ArrayBuffer | Uint8Array | Uint16Array | Uint8ClampedArray | Float32Array | Buffer | ArrayBufferView | null) {
228
+ if (typeof pixels === 'object' && pixels !== null) {
229
+ if (pixels instanceof ArrayBuffer) {
230
+ return new Uint8Array(pixels)
231
+ } else if (pixels instanceof Uint8Array ||
232
+ pixels instanceof Uint16Array ||
233
+ pixels instanceof Uint8ClampedArray ||
234
+ pixels instanceof Float32Array) {
235
+ return arrayToUint8Array(pixels)
236
+ } else if ((pixels as Buffer) instanceof Buffer) {
237
+ return new Uint8Array(pixels as Buffer)
238
+ }
239
+ }
240
+ return null
241
+ }
242
+
243
+ export function checkFormat(gl: GjsifyWebGLRenderingContext, format: GLenum) {
244
+ return (
245
+ format === gl.ALPHA ||
246
+ format === gl.LUMINANCE_ALPHA ||
247
+ format === gl.LUMINANCE ||
248
+ format === gl.RGB ||
249
+ format === gl.RGBA)
250
+ }
251
+
252
+ export function validCubeTarget(gl: GjsifyWebGLRenderingContext, target: GLenum) {
253
+ return target === gl.TEXTURE_CUBE_MAP_POSITIVE_X ||
254
+ target === gl.TEXTURE_CUBE_MAP_NEGATIVE_X ||
255
+ target === gl.TEXTURE_CUBE_MAP_POSITIVE_Y ||
256
+ target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Y ||
257
+ target === gl.TEXTURE_CUBE_MAP_POSITIVE_Z ||
258
+ target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
259
+ }
260
+
261
+ export function flag<T = Gwebgl.WebGLRenderingContext.ConstructorProperties> (options: T, name: keyof T, dflt: boolean) {
262
+ if (!options || !(typeof options === 'object') || !(name in options)) {
263
+ return dflt
264
+ }
265
+ return !!options[name]
266
+ }
@@ -0,0 +1,13 @@
1
+ class GjsifyWebGLActiveInfo implements WebGLActiveInfo {
2
+ size: GLsizei;
3
+ type: GLenum;
4
+ name: string;
5
+
6
+ constructor (_: WebGLActiveInfo) {
7
+ this.size = _.size
8
+ this.type = _.type
9
+ this.name = _.name
10
+ }
11
+ }
12
+
13
+ export { GjsifyWebGLActiveInfo as WebGLActiveInfo }
@@ -0,0 +1,21 @@
1
+ import { Linkable } from './linkable.js'
2
+
3
+ import type { GjsifyWebGLRenderingContext } from './webgl-rendering-context.js';
4
+
5
+ export class GjsifyWebGLBuffer extends Linkable implements WebGLBuffer {
6
+ _ctx: GjsifyWebGLRenderingContext;
7
+ _size = 0
8
+ _elements = new Uint8Array(0)
9
+ constructor(_: WebGLBuffer & number, ctx: GjsifyWebGLRenderingContext) {
10
+ super(_)
11
+ this._ctx = ctx
12
+ }
13
+
14
+ _performDelete() {
15
+ const ctx = this._ctx
16
+ delete ctx._buffers[this._ | 0]
17
+ ctx._native.deleteBuffer(this._)
18
+ }
19
+ }
20
+
21
+ export { GjsifyWebGLBuffer as WebGLBuffer }
@@ -0,0 +1,24 @@
1
+ export class GjsifyWebGLContextAttributes implements WebGLContextAttributes {
2
+ desynchronized?: boolean;
3
+ powerPreference?: WebGLPowerPreference;
4
+ constructor(
5
+ public alpha?: boolean,
6
+ public depth?: boolean,
7
+ public stencil?: boolean,
8
+ public antialias?: boolean,
9
+ public premultipliedAlpha?: boolean,
10
+ public preserveDrawingBuffer?: boolean,
11
+ public preferLowPowerToHighPerformance?: boolean,
12
+ public failIfMajorPerformanceCaveat?: boolean) {
13
+ this.alpha = alpha
14
+ this.depth = depth
15
+ this.stencil = stencil
16
+ this.antialias = antialias
17
+ this.premultipliedAlpha = premultipliedAlpha
18
+ this.preserveDrawingBuffer = preserveDrawingBuffer
19
+ this.preferLowPowerToHighPerformance = preferLowPowerToHighPerformance
20
+ this.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat
21
+ }
22
+ }
23
+
24
+ export { GjsifyWebGLContextAttributes as WebGLContextAttributes }
@@ -0,0 +1,10 @@
1
+ export class WebGLDrawingBufferWrapper {
2
+ _framebuffer: WebGLFramebuffer & number;
3
+ _color: WebGLTexture & number;
4
+ _depthStencil: WebGLRenderbuffer & number;
5
+ constructor(framebuffer: WebGLFramebuffer & number, color: WebGLTexture & number, depthStencil: WebGLRenderbuffer & number) {
6
+ this._framebuffer = framebuffer
7
+ this._color = color
8
+ this._depthStencil = depthStencil
9
+ }
10
+ }
@@ -0,0 +1,133 @@
1
+ import { Linkable } from './linkable.js'
2
+ // import { gl } from './native-gl.js'
3
+
4
+ import type { GjsifyWebGLRenderingContext } from './webgl-rendering-context.js';
5
+ // import type { WebGLDrawBuffers } from './extensions/webgl-draw-buffers.js';
6
+ type WebGLDrawBuffers = any;
7
+
8
+ export class GjsifyWebGLFramebuffer extends Linkable implements WebGLFramebuffer {
9
+
10
+ _ctx: GjsifyWebGLRenderingContext;
11
+ _binding = 0
12
+
13
+ _width = 0
14
+ _height = 0
15
+ _status: number | null = null
16
+
17
+ _attachments: Record<GLenum, WebGLTexture | WebGLRenderbuffer | null>;
18
+ _attachmentLevel: Record<GLenum, number | null>;
19
+ _attachmentFace: Record<GLenum, number | null>;
20
+
21
+ constructor(_: WebGLFramebuffer & number, ctx: GjsifyWebGLRenderingContext) {
22
+ super(_)
23
+ this._ctx = ctx
24
+
25
+ this._attachments = {}
26
+ this._attachments[ctx.COLOR_ATTACHMENT0] = null
27
+ this._attachments[ctx.DEPTH_ATTACHMENT] = null
28
+ this._attachments[ctx.STENCIL_ATTACHMENT] = null
29
+ this._attachments[ctx.DEPTH_STENCIL_ATTACHMENT] = null
30
+
31
+ this._attachmentLevel = {}
32
+ this._attachmentLevel[ctx.COLOR_ATTACHMENT0] = 0
33
+ this._attachmentLevel[ctx.DEPTH_ATTACHMENT] = 0
34
+ this._attachmentLevel[ctx.STENCIL_ATTACHMENT] = 0
35
+ this._attachmentLevel[ctx.DEPTH_STENCIL_ATTACHMENT] = 0
36
+
37
+ this._attachmentFace = {}
38
+ this._attachmentFace[ctx.COLOR_ATTACHMENT0] = 0
39
+ this._attachmentFace[ctx.DEPTH_ATTACHMENT] = 0
40
+ this._attachmentFace[ctx.STENCIL_ATTACHMENT] = 0
41
+ this._attachmentFace[ctx.DEPTH_STENCIL_ATTACHMENT] = 0
42
+
43
+ if (ctx._extensions.webgl_draw_buffers) {
44
+ const webGLDrawBuffers: WebGLDrawBuffers = ctx._extensions.webgl_draw_buffers;
45
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT1_WEBGL] = null
46
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT2_WEBGL] = null
47
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT3_WEBGL] = null
48
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT4_WEBGL] = null
49
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT5_WEBGL] = null
50
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT6_WEBGL] = null
51
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT7_WEBGL] = null
52
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT8_WEBGL] = null
53
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT9_WEBGL] = null
54
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT10_WEBGL] = null
55
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT11_WEBGL] = null
56
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT12_WEBGL] = null
57
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT13_WEBGL] = null
58
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT14_WEBGL] = null
59
+ this._attachments[webGLDrawBuffers.COLOR_ATTACHMENT15_WEBGL] = null
60
+ this._attachments[ctx.NONE] = null
61
+ this._attachments[ctx.BACK] = null
62
+
63
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT1_WEBGL] = 0
64
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT2_WEBGL] = 0
65
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT3_WEBGL] = 0
66
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT4_WEBGL] = 0
67
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT5_WEBGL] = 0
68
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT6_WEBGL] = 0
69
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT7_WEBGL] = 0
70
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT8_WEBGL] = 0
71
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT9_WEBGL] = 0
72
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT10_WEBGL] = 0
73
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT11_WEBGL] = 0
74
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT12_WEBGL] = 0
75
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT13_WEBGL] = 0
76
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT14_WEBGL] = 0
77
+ this._attachmentLevel[webGLDrawBuffers.COLOR_ATTACHMENT15_WEBGL] = 0
78
+ this._attachmentLevel[ctx.NONE] = null
79
+ this._attachmentLevel[ctx.BACK] = null
80
+
81
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT1_WEBGL] = 0
82
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT2_WEBGL] = 0
83
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT3_WEBGL] = 0
84
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT4_WEBGL] = 0
85
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT5_WEBGL] = 0
86
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT6_WEBGL] = 0
87
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT7_WEBGL] = 0
88
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT8_WEBGL] = 0
89
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT9_WEBGL] = 0
90
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT10_WEBGL] = 0
91
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT11_WEBGL] = 0
92
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT12_WEBGL] = 0
93
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT13_WEBGL] = 0
94
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT14_WEBGL] = 0
95
+ this._attachmentFace[webGLDrawBuffers.COLOR_ATTACHMENT15_WEBGL] = 0
96
+ this._attachmentFace[ctx.NONE] = null
97
+ this._attachmentFace[ctx.BACK] = null
98
+ }
99
+ }
100
+
101
+ _clearAttachment(attachment: GLenum) {
102
+ const object = this._attachments[attachment]
103
+ if (!object) {
104
+ return
105
+ }
106
+ this._attachments[attachment] = null
107
+ this._unlink(object)
108
+ }
109
+
110
+ _setAttachment(object: WebGLTexture | WebGLRenderbuffer | null, attachment: GLenum) {
111
+ const prevObject = this._attachments[attachment]
112
+ if (prevObject === object) {
113
+ return
114
+ }
115
+
116
+ this._clearAttachment(attachment)
117
+ if (!object) {
118
+ return
119
+ }
120
+
121
+ this._attachments[attachment] = object
122
+
123
+ this._link(object)
124
+ }
125
+
126
+ _performDelete() {
127
+ const ctx = this._ctx
128
+ delete ctx._framebuffers[this._ | 0]
129
+ ctx.deleteFramebuffer.call(ctx, this)
130
+ }
131
+ }
132
+
133
+ export { GjsifyWebGLFramebuffer as WebGLFramebuffer }
@@ -0,0 +1,30 @@
1
+ import { Linkable } from './linkable.js'
2
+ import { WebGLActiveInfo } from './webgl-active-info.js';
3
+
4
+ import type { GjsifyWebGLRenderingContext } from './webgl-rendering-context.js';
5
+
6
+ export class GjsifyWebGLProgram extends Linkable implements WebGLProgram {
7
+ _ctx: GjsifyWebGLRenderingContext;
8
+ _linkCount = 0
9
+ _linkStatus = false
10
+ _linkInfoLog: string | null = 'not linked'
11
+ _attributes: number[] = []
12
+ _uniforms: WebGLActiveInfo[] = []
13
+ constructor(_: WebGLProgram & number, ctx: GjsifyWebGLRenderingContext) {
14
+ super(_)
15
+ this._ctx = ctx
16
+ this._linkCount = 0
17
+ this._linkStatus = false
18
+ this._linkInfoLog = 'not linked'
19
+ this._attributes = []
20
+ this._uniforms = []
21
+ }
22
+
23
+ _performDelete() {
24
+ const ctx = this._ctx
25
+ delete ctx._programs[this._ | 0]
26
+ ctx._native.deleteProgram(this._ | 0)
27
+ }
28
+ }
29
+
30
+ export { GjsifyWebGLProgram as WebGLProgram }
@@ -0,0 +1,28 @@
1
+ import { Linkable } from './linkable.js'
2
+ // import { gl } from './native-gl.js'
3
+
4
+ import type { GjsifyWebGLRenderingContext } from './webgl-rendering-context.js';
5
+
6
+ export class GjsifyWebGLRenderbuffer extends Linkable implements WebGLRenderbuffer {
7
+ _ctx: GjsifyWebGLRenderingContext;
8
+ _binding = 0;
9
+ _width = 0;
10
+ _height = 0;
11
+ _format = 0;
12
+ constructor (_: WebGLRenderbuffer & number, ctx: GjsifyWebGLRenderingContext) {
13
+ super(_)
14
+ this._ctx = ctx
15
+ this._binding = 0
16
+ this._width = 0
17
+ this._height = 0
18
+ this._format = 0
19
+ }
20
+
21
+ _performDelete () {
22
+ const ctx = this._ctx
23
+ delete ctx._renderbuffers[this._ | 0]
24
+ ctx._native.deleteRenderbuffer(this._)
25
+ }
26
+ }
27
+
28
+ export { GjsifyWebGLRenderbuffer as WebGLRenderbuffer }