@gjsify/webgl 0.0.4 → 0.1.0

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 (149) hide show
  1. package/README.md +78 -6
  2. package/lib/esm/canvas-webgl-widget.js +116 -0
  3. package/lib/esm/html-canvas-element.js +31 -50
  4. package/lib/esm/index.js +7 -0
  5. package/lib/esm/index.spec.js +629 -120
  6. package/lib/esm/test-utils.js +87 -0
  7. package/lib/esm/test.js +5 -1
  8. package/lib/esm/utils.js +1 -1
  9. package/lib/esm/webgl-active-info.js +2 -2
  10. package/lib/esm/webgl-buffer.js +2 -3
  11. package/lib/esm/webgl-context-attributes.js +2 -3
  12. package/lib/esm/webgl-framebuffer.js +3 -4
  13. package/lib/esm/webgl-program.js +2 -3
  14. package/lib/esm/webgl-query.js +15 -0
  15. package/lib/esm/webgl-renderbuffer.js +2 -3
  16. package/lib/esm/webgl-rendering-context.js +105 -101
  17. package/lib/esm/webgl-sampler.js +15 -0
  18. package/lib/esm/webgl-shader-precision-format.js +2 -3
  19. package/lib/esm/webgl-shader.js +2 -3
  20. package/lib/esm/webgl-sync.js +15 -0
  21. package/lib/esm/webgl-texture.js +2 -3
  22. package/lib/esm/webgl-transform-feedback.js +15 -0
  23. package/lib/esm/webgl-uniform-location.js +2 -3
  24. package/lib/esm/webgl-vertex-array-object.js +21 -0
  25. package/lib/esm/webgl2-rendering-context.js +591 -0
  26. package/lib/esm/webgl2.spec.js +578 -0
  27. package/lib/types/canvas-webgl-widget.d.ts +509 -0
  28. package/lib/types/extensions/ext-blend-minmax.d.ts +2 -2
  29. package/lib/types/extensions/ext-texture-filter-anisotropic.d.ts +2 -2
  30. package/lib/types/extensions/oes-element-index-unit.d.ts +2 -2
  31. package/lib/types/extensions/oes-standard-derivatives.d.ts +2 -2
  32. package/lib/types/extensions/oes-texture-float-linear.d.ts +2 -2
  33. package/lib/types/extensions/oes-texture-float.d.ts +2 -2
  34. package/lib/types/extensions/stackgl-destroy-context.d.ts +3 -3
  35. package/lib/types/extensions/stackgl-resize-drawing-buffer.d.ts +3 -3
  36. package/lib/types/html-canvas-element.d.ts +19 -31
  37. package/lib/types/index.d.ts +7 -0
  38. package/lib/types/test-utils.d.ts +45 -0
  39. package/lib/types/types/extension.d.ts +2 -2
  40. package/lib/types/utils.d.ts +14 -15
  41. package/lib/types/webgl-active-info.d.ts +1 -2
  42. package/lib/types/webgl-buffer.d.ts +5 -6
  43. package/lib/types/webgl-context-attributes.d.ts +1 -2
  44. package/lib/types/webgl-framebuffer.d.ts +4 -5
  45. package/lib/types/webgl-program.d.ts +4 -5
  46. package/lib/types/webgl-query.d.ts +7 -0
  47. package/lib/types/webgl-renderbuffer.d.ts +4 -5
  48. package/lib/types/webgl-rendering-context.d.ts +15 -13
  49. package/lib/types/webgl-sampler.d.ts +7 -0
  50. package/lib/types/webgl-shader-precision-format.d.ts +1 -2
  51. package/lib/types/webgl-shader.d.ts +4 -5
  52. package/lib/types/webgl-sync.d.ts +7 -0
  53. package/lib/types/webgl-texture-unit.d.ts +3 -3
  54. package/lib/types/webgl-texture.d.ts +6 -7
  55. package/lib/types/webgl-transform-feedback.d.ts +7 -0
  56. package/lib/types/webgl-uniform-location.d.ts +3 -4
  57. package/lib/types/webgl-vertex-array-object.d.ts +9 -0
  58. package/lib/types/webgl-vertex-attribute.d.ts +5 -5
  59. package/lib/types/webgl2-rendering-context.d.ts +124 -0
  60. package/package.json +27 -26
  61. package/prebuilds/linux-aarch64/Gwebgl-0.1.typelib +0 -0
  62. package/prebuilds/linux-aarch64/libgwebgl.so +0 -0
  63. package/prebuilds/linux-x86_64/Gwebgl-0.1.typelib +0 -0
  64. package/prebuilds/linux-x86_64/libgwebgl.so +0 -0
  65. package/lib/cjs/@types/glsl-tokenizer/index.d.js +0 -0
  66. package/lib/cjs/extensions/ext-blend-minmax.js +0 -18
  67. package/lib/cjs/extensions/ext-texture-filter-anisotropic.js +0 -18
  68. package/lib/cjs/extensions/oes-element-index-unit.js +0 -14
  69. package/lib/cjs/extensions/oes-standard-derivatives.js +0 -17
  70. package/lib/cjs/extensions/oes-texture-float-linear.js +0 -14
  71. package/lib/cjs/extensions/oes-texture-float.js +0 -14
  72. package/lib/cjs/extensions/stackgl-destroy-context.js +0 -12
  73. package/lib/cjs/extensions/stackgl-resize-drawing-buffer.js +0 -12
  74. package/lib/cjs/html-canvas-element.js +0 -70
  75. package/lib/cjs/index.js +0 -18
  76. package/lib/cjs/index.spec.js +0 -146
  77. package/lib/cjs/linkable.js +0 -50
  78. package/lib/cjs/test.js +0 -3
  79. package/lib/cjs/types/constructor.js +0 -0
  80. package/lib/cjs/types/extension.js +0 -0
  81. package/lib/cjs/types/index.js +0 -5
  82. package/lib/cjs/types/typed-array.js +0 -0
  83. package/lib/cjs/types/webgl-constants.js +0 -0
  84. package/lib/cjs/types/webgl-context-attribute-options.js +0 -0
  85. package/lib/cjs/utils.js +0 -212
  86. package/lib/cjs/webgl-active-info.js +0 -10
  87. package/lib/cjs/webgl-buffer.js +0 -18
  88. package/lib/cjs/webgl-context-attributes.js +0 -24
  89. package/lib/cjs/webgl-drawing-buffer-wrapper.js +0 -10
  90. package/lib/cjs/webgl-framebuffer.js +0 -109
  91. package/lib/cjs/webgl-program.js +0 -26
  92. package/lib/cjs/webgl-renderbuffer.js +0 -24
  93. package/lib/cjs/webgl-rendering-context.js +0 -3343
  94. package/lib/cjs/webgl-shader-precision-format.js +0 -11
  95. package/lib/cjs/webgl-shader.js +0 -23
  96. package/lib/cjs/webgl-texture-unit.js +0 -12
  97. package/lib/cjs/webgl-texture.js +0 -22
  98. package/lib/cjs/webgl-uniform-location.js +0 -15
  99. package/lib/cjs/webgl-vertex-attribute.js +0 -147
  100. package/meson.build +0 -39
  101. package/src/test/app.vala +0 -60
  102. package/src/ts/@types/glsl-tokenizer/index.d.ts +0 -18
  103. package/src/ts/extensions/angle-instanced-arrays.ts.off +0 -232
  104. package/src/ts/extensions/ext-blend-minmax.ts +0 -18
  105. package/src/ts/extensions/ext-texture-filter-anisotropic.ts +0 -18
  106. package/src/ts/extensions/oes-element-index-unit.ts +0 -14
  107. package/src/ts/extensions/oes-standard-derivatives.ts +0 -17
  108. package/src/ts/extensions/oes-texture-float-linear.ts +0 -14
  109. package/src/ts/extensions/oes-texture-float.ts +0 -14
  110. package/src/ts/extensions/oes-vertex-array-object.ts.off +0 -128
  111. package/src/ts/extensions/stackgl-destroy-context.ts +0 -12
  112. package/src/ts/extensions/stackgl-resize-drawing-buffer.ts +0 -14
  113. package/src/ts/extensions/webgl-draw-buffers.ts.off +0 -107
  114. package/src/ts/html-canvas-element.ts +0 -98
  115. package/src/ts/index.spec.ts +0 -186
  116. package/src/ts/index.ts +0 -21
  117. package/src/ts/linkable.ts +0 -55
  118. package/src/ts/test.ts +0 -6
  119. package/src/ts/types/constructor.ts +0 -3
  120. package/src/ts/types/extension.ts +0 -3
  121. package/src/ts/types/index.ts +0 -26
  122. package/src/ts/types/typed-array.ts +0 -1
  123. package/src/ts/types/webgl-constants.ts +0 -300
  124. package/src/ts/types/webgl-context-attribute-options.ts +0 -12
  125. package/src/ts/utils.ts +0 -266
  126. package/src/ts/webgl-active-info.ts +0 -13
  127. package/src/ts/webgl-buffer.ts +0 -21
  128. package/src/ts/webgl-context-attributes.ts +0 -24
  129. package/src/ts/webgl-drawing-buffer-wrapper.ts +0 -10
  130. package/src/ts/webgl-framebuffer.ts +0 -133
  131. package/src/ts/webgl-program.ts +0 -30
  132. package/src/ts/webgl-renderbuffer.ts +0 -28
  133. package/src/ts/webgl-rendering-context.ts +0 -4050
  134. package/src/ts/webgl-shader-precision-format.ts +0 -12
  135. package/src/ts/webgl-shader.ts +0 -29
  136. package/src/ts/webgl-texture-unit.ts +0 -16
  137. package/src/ts/webgl-texture.ts +0 -27
  138. package/src/ts/webgl-uniform-location.ts +0 -18
  139. package/src/ts/webgl-vertex-attribute.ts +0 -169
  140. package/src/vala/handle-types.vala +0 -23
  141. package/src/vala/webgl-rendering-context-base.vala +0 -1265
  142. package/src/vala/webgl-rendering-context.vala +0 -265
  143. package/src/vapi/epoxy.vapi +0 -14558
  144. package/src/vapi/glesv2.vapi +0 -670
  145. package/test.gjs.js +0 -39937
  146. package/test.gjs.js.meta.json +0 -1
  147. package/tmp/.tsbuildinfo +0 -1
  148. package/tsconfig.json +0 -38
  149. package/tsconfig.types.json +0 -7
@@ -1,11 +0,0 @@
1
- class GjsifyWebGLShaderPrecisionFormat {
2
- constructor(_) {
3
- this.rangeMin = _.rangeMin;
4
- this.rangeMax = _.rangeMax;
5
- this.precision = _.precision;
6
- }
7
- }
8
- export {
9
- GjsifyWebGLShaderPrecisionFormat,
10
- GjsifyWebGLShaderPrecisionFormat as WebGLShaderPrecisionFormat
11
- };
@@ -1,23 +0,0 @@
1
- import { Linkable } from "./linkable.js";
2
- class GjsifyWebGLShader extends Linkable {
3
- constructor(_, ctx, type) {
4
- super(_);
5
- this._source = "";
6
- this._compileStatus = false;
7
- this._compileInfo = "";
8
- this._type = type;
9
- this._ctx = ctx;
10
- this._source = "";
11
- this._compileStatus = false;
12
- this._compileInfo = "";
13
- }
14
- _performDelete() {
15
- const ctx = this._ctx;
16
- delete ctx._shaders[this._ | 0];
17
- ctx._native.deleteShader(this._ | 0);
18
- }
19
- }
20
- export {
21
- GjsifyWebGLShader,
22
- GjsifyWebGLShader as WebGLShader
23
- };
@@ -1,12 +0,0 @@
1
- class WebGLTextureUnit {
2
- constructor(ctx, idx) {
3
- this._mode = 0;
4
- this._bind2D = null;
5
- this._bindCube = null;
6
- this._ctx = ctx;
7
- this._idx = idx;
8
- }
9
- }
10
- export {
11
- WebGLTextureUnit
12
- };
@@ -1,22 +0,0 @@
1
- import { Linkable } from "./linkable.js";
2
- class GjsifyWebGLTexture extends Linkable {
3
- constructor(_, ctx) {
4
- super(_);
5
- this._binding = 0;
6
- this._levelWidth = new Int32Array(32);
7
- this._levelHeight = new Int32Array(32);
8
- this._format = 0;
9
- this._type = 0;
10
- this._complete = true;
11
- this._ctx = ctx;
12
- }
13
- _performDelete() {
14
- const ctx = this._ctx;
15
- delete ctx._textures[this._ | 0];
16
- ctx._native.deleteTexture(this._ | 0);
17
- }
18
- }
19
- export {
20
- GjsifyWebGLTexture,
21
- GjsifyWebGLTexture as WebGLTexture
22
- };
@@ -1,15 +0,0 @@
1
- class GjsifyWebGLUniformLocation {
2
- constructor(_, program, info) {
3
- this._linkCount = 0;
4
- this._array = null;
5
- this._ = _;
6
- this._program = program;
7
- this._linkCount = program._linkCount;
8
- this._activeInfo = info;
9
- this._array = null;
10
- }
11
- }
12
- export {
13
- GjsifyWebGLUniformLocation,
14
- GjsifyWebGLUniformLocation as WebGLUniformLocation
15
- };
@@ -1,147 +0,0 @@
1
- import { WebGLBuffer } from "./webgl-buffer.js";
2
- class WebGLVertexArrayObjectAttribute {
3
- constructor(ctx, idx) {
4
- this._isPointer = false;
5
- this._pointerBuffer = null;
6
- this._pointerOffset = 0;
7
- this._pointerSize = 0;
8
- this._pointerStride = 0;
9
- this._pointerType = 0;
10
- this._pointerNormal = false;
11
- this._divisor = 0;
12
- this._inputSize = 4;
13
- this._inputStride = 0;
14
- this._ctx = ctx;
15
- this._idx = idx;
16
- this._pointerType = ctx.FLOAT;
17
- this._clear();
18
- }
19
- _clear() {
20
- this._isPointer = false;
21
- this._pointerBuffer = null;
22
- this._pointerOffset = 0;
23
- this._pointerSize = 0;
24
- this._pointerStride = 0;
25
- this._pointerType = this._ctx.FLOAT;
26
- this._pointerNormal = false;
27
- this._divisor = 0;
28
- this._inputSize = 4;
29
- this._inputStride = 0;
30
- }
31
- }
32
- class WebGLVertexArrayGlobalAttribute {
33
- constructor(idx) {
34
- this._idx = 0;
35
- this._idx = idx;
36
- this._data = new Float32Array([0, 0, 0, 1]);
37
- }
38
- }
39
- class WebGLVertexArrayObjectState {
40
- constructor(ctx) {
41
- this._elementArrayBufferBinding = null;
42
- const numAttribs = ctx.getParameter(ctx.MAX_VERTEX_ATTRIBS);
43
- this._attribs = new Array(numAttribs);
44
- for (let i = 0; i < numAttribs; ++i) {
45
- this._attribs[i] = new WebGLVertexArrayObjectAttribute(ctx, i);
46
- }
47
- this._elementArrayBufferBinding = null;
48
- }
49
- setElementArrayBuffer(buffer) {
50
- if (buffer !== null && !(buffer instanceof WebGLBuffer)) {
51
- throw new TypeError("setElementArrayBuffer(WebGLBuffer?)");
52
- }
53
- const current = this._elementArrayBufferBinding;
54
- if (current !== buffer) {
55
- if (current) {
56
- current._refCount -= 1;
57
- current._checkDelete();
58
- }
59
- if (buffer) {
60
- buffer._refCount += 1;
61
- }
62
- this._elementArrayBufferBinding = buffer;
63
- }
64
- }
65
- cleanUp() {
66
- const elementArrayBuffer = this._elementArrayBufferBinding;
67
- if (elementArrayBuffer) {
68
- elementArrayBuffer._refCount -= 1;
69
- elementArrayBuffer._checkDelete();
70
- this._elementArrayBufferBinding = null;
71
- }
72
- for (let i = 0; i < this._attribs.length; ++i) {
73
- const attrib = this._attribs[i];
74
- if (attrib._pointerBuffer) {
75
- attrib._pointerBuffer._refCount -= 1;
76
- attrib._pointerBuffer._checkDelete();
77
- }
78
- attrib._clear();
79
- }
80
- }
81
- releaseArrayBuffer(buffer) {
82
- if (!buffer) {
83
- return;
84
- }
85
- for (let i = 0; i < this._attribs.length; ++i) {
86
- const attrib = this._attribs[i];
87
- if (attrib._pointerBuffer === buffer) {
88
- attrib._pointerBuffer._refCount -= 1;
89
- attrib._pointerBuffer._checkDelete();
90
- attrib._clear();
91
- }
92
- }
93
- }
94
- setVertexAttribPointer(buffer, index, pointerSize, pointerOffset, pointerStride, pointerType, pointerNormal, inputStride, inputSize) {
95
- const attrib = this._attribs[index];
96
- if (buffer !== attrib._pointerBuffer) {
97
- if (attrib._pointerBuffer) {
98
- attrib._pointerBuffer._refCount -= 1;
99
- attrib._pointerBuffer._checkDelete();
100
- }
101
- if (buffer) {
102
- buffer._refCount += 1;
103
- }
104
- attrib._pointerBuffer = buffer;
105
- }
106
- attrib._pointerSize = pointerSize;
107
- attrib._pointerOffset = pointerOffset;
108
- attrib._pointerStride = pointerStride;
109
- attrib._pointerType = pointerType;
110
- attrib._pointerNormal = pointerNormal;
111
- attrib._inputStride = inputStride;
112
- attrib._inputSize = inputSize;
113
- }
114
- }
115
- class WebGLVertexArrayGlobalState {
116
- constructor(ctx) {
117
- this._arrayBufferBinding = null;
118
- const numAttribs = ctx.getParameter(ctx.MAX_VERTEX_ATTRIBS);
119
- this._attribs = new Array(numAttribs);
120
- for (let i = 0; i < numAttribs; ++i) {
121
- this._attribs[i] = new WebGLVertexArrayGlobalAttribute(i);
122
- }
123
- this._arrayBufferBinding = null;
124
- }
125
- setArrayBuffer(buffer) {
126
- if (buffer !== null && !(buffer instanceof WebGLBuffer)) {
127
- throw new TypeError("setArrayBuffer(WebGLBuffer?)");
128
- }
129
- const current = this._arrayBufferBinding;
130
- if (current !== buffer) {
131
- if (current) {
132
- current._refCount -= 1;
133
- current._checkDelete();
134
- }
135
- if (buffer) {
136
- buffer._refCount += 1;
137
- }
138
- this._arrayBufferBinding = buffer;
139
- }
140
- }
141
- }
142
- export {
143
- WebGLVertexArrayGlobalAttribute,
144
- WebGLVertexArrayGlobalState,
145
- WebGLVertexArrayObjectAttribute,
146
- WebGLVertexArrayObjectState
147
- };
package/meson.build DELETED
@@ -1,39 +0,0 @@
1
- project('Gwebgl', ['c', 'vala'], version: '0.1')
2
-
3
- root_dir = meson.current_source_dir()
4
-
5
- vapi_dir = root_dir / 'src/vapi'
6
-
7
- add_project_arguments(
8
- [
9
- '--vapidir', vapi_dir,
10
- ],
11
- language: 'vala'
12
- )
13
-
14
- dependencies = [ dependency('glib-2.0'), dependency('gobject-2.0'), dependency('gdk-pixbuf-2.0'), dependency('gtk4'), dependency('epoxy')]
15
-
16
- sources = files('src/vala/handle-types.vala', 'src/vala/webgl-rendering-context-base.vala', 'src/vala/webgl-rendering-context.vala')
17
-
18
- libGwebgl = library('gwebgl', sources,
19
- dependencies: dependencies,
20
- vala_gir: meson.project_name() + '-0.1.gir',
21
- install: true,
22
- install_dir: [true, true, true, true]
23
- )
24
-
25
- g_ir_compiler = find_program('g-ir-compiler')
26
-
27
-
28
- # TODO not working if gwebgl-0.1.gir not exists
29
- custom_target(meson.project_name() + '-0.1.typelib', command: [g_ir_compiler, '--shared-library', 'libgwebgl.so', '--output', '@OUTPUT@', meson.current_build_dir() / meson.project_name() + '-0.1.gir'],
30
- #input: meson.current_build_dir() / meson.project_name() + '-0.1.gir',
31
- output: meson.project_name() +'-0.1.typelib',
32
- depends: libGwebgl,
33
- install: true,
34
- install_dir: get_option('libdir') / 'girepository-1.0')
35
-
36
-
37
- # Test app
38
- test_sources = files('src/vala/handle-types.vala', 'src/vala/webgl-rendering-context-base.vala', 'src/vala/webgl-rendering-context.vala', 'src/test/app.vala')
39
- executable('gwebgl_vala_app', test_sources, dependencies: dependencies)
package/src/test/app.vala DELETED
@@ -1,60 +0,0 @@
1
- using Gtk;
2
- using Gwebgl;
3
-
4
- int main (string[] argv) {
5
- WebGLRenderingContext? gl = null;
6
- // Create a new application
7
- var app = new Gtk.Application ("gjsify.web.webgl.valaapp", GLib.ApplicationFlags.FLAGS_NONE);
8
- app.activate.connect (() => {
9
- var win = new Gtk.ApplicationWindow (app);
10
- win.set_default_size(800, 600);
11
- var glarea = new Gtk.GLArea ();
12
- glarea.set_use_es(true);
13
- glarea.set_required_version(3, 2);
14
-
15
- glarea.realize.connect((widget) => {
16
- print("\nrealize");
17
- glarea.make_current ();
18
-
19
- var error = glarea.get_error ();
20
- if(error != null) {
21
- printerr (error.message);
22
- return;
23
- }
24
- });
25
-
26
- glarea.render.connect((context) => {
27
- print("\nrender");
28
-
29
- var error = glarea.get_error ();
30
- if(error != null) {
31
- printerr (error.message);
32
- return false;
33
- }
34
-
35
- if(gl == null) {
36
- int width = glarea.get_width ();
37
- int height = glarea.get_height ();
38
- gl = new Gwebgl.WebGLRenderingContext (width, height, true, true, false, false, true, false, false, false);
39
- }
40
- // Set clear color to black, fully opaque
41
- gl.clearColor((float) 1.0, (float) 0.0, (float) 0.0, (float) 1.0);
42
-
43
- // GL.glClearColor((GL.GLfloat) 0.0, (GL.GLfloat) 0.0, (GL.GLfloat) 0.0, (GL.GLfloat) 1.0);
44
-
45
- // Clear the color buffer with specified clear color
46
- var COLOR_BUFFER_BIT = gl.get_webgl_constants().get ("COLOR_BUFFER_BIT");
47
- gl.clear(COLOR_BUFFER_BIT);
48
- // GL.glClear(GL.GL_COLOR_BUFFER_BIT);
49
- print("GL.GL_COLOR_BUFFER_BIT %i", GL.GL_COLOR_BUFFER_BIT);
50
- print("COLOR_BUFFER_BIT %i", COLOR_BUFFER_BIT);
51
- return true;
52
- });
53
-
54
- win.set_child (glarea);
55
- win.present ();
56
- });
57
-
58
- app.run (argv);
59
- return 0;
60
- }
@@ -1,18 +0,0 @@
1
- declare module 'glsl-tokenizer/string' {
2
-
3
- export interface Options {
4
- version: '100' | '300 es';
5
- }
6
-
7
- export type TokenType = 'block-comment' | 'line-comment' | 'preprocessor' | 'operator' | 'float' | 'ident' | 'builtin' | 'eof' | 'integer' | 'whitespace' | 'keyword';
8
-
9
- export interface Token {
10
- type: TokenType;
11
- data: string;
12
- position: number;
13
- line: number;
14
- column: number;
15
- }
16
-
17
- export default function tokenString(src: string, opt?: Options): Token[];
18
- }
@@ -1,232 +0,0 @@
1
- import { gl } from '../native-gl';
2
- import { vertexCount } from '../utils';
3
-
4
- import type { GjsifyWebGLRenderingContext } from '../webgl-rendering-context.js';
5
-
6
- export class ANGLEInstancedArrays {
7
-
8
- VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88fe
9
- ctx: GjsifyWebGLRenderingContext;
10
-
11
- _drawArraysInstanced = gl._drawArraysInstanced.bind(ctx)
12
- _drawElementsInstanced = gl._drawElementsInstanced.bind(ctx)
13
- _vertexAttribDivisor = gl._vertexAttribDivisor.bind(ctx)
14
-
15
- constructor (ctx: GjsifyWebGLRenderingContext) {
16
- this.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88fe
17
- this.ctx = ctx
18
-
19
- this._drawArraysInstanced = gl._drawArraysInstanced.bind(ctx)
20
- this._drawElementsInstanced = gl._drawElementsInstanced.bind(ctx)
21
- this._vertexAttribDivisor = gl._vertexAttribDivisor.bind(ctx)
22
- }
23
-
24
- drawArraysInstancedANGLE (mode: GLenum, first: GLint, count: GLuint, primCount: GLuint) {
25
- const { ctx } = this
26
- mode |= 0
27
- first |= 0
28
- count |= 0
29
- primCount |= 0
30
- if (first < 0 || count < 0 || primCount < 0) {
31
- ctx.setError(gl.INVALID_VALUE)
32
- return
33
- }
34
- if (!ctx._checkStencilState()) {
35
- return
36
- }
37
- const reducedCount = vertexCount(mode, count)
38
- if (reducedCount < 0) {
39
- ctx.setError(gl.INVALID_ENUM)
40
- return
41
- }
42
- if (!ctx._framebufferOk()) {
43
- return
44
- }
45
- if (count === 0 || primCount === 0) {
46
- return
47
- }
48
- let maxIndex = first
49
- if (count > 0) {
50
- maxIndex = (count + first - 1) >>> 0
51
- }
52
- if (this.checkInstancedVertexAttribState(maxIndex, primCount)) {
53
- return this._drawArraysInstanced(mode, first, reducedCount, primCount)
54
- }
55
- }
56
-
57
- drawElementsInstancedANGLE (mode: GLenum, count: GLint, type: GLenum, ioffset: GLint, primCount: GLuint) {
58
- const { ctx } = this
59
- mode |= 0
60
- count |= 0
61
- type |= 0
62
- ioffset |= 0
63
- primCount |= 0
64
-
65
- if (count < 0 || ioffset < 0 || primCount < 0) {
66
- ctx.setError(gl.INVALID_VALUE)
67
- return
68
- }
69
-
70
- if (!ctx._checkStencilState()) {
71
- return
72
- }
73
-
74
- const elementBuffer = ctx._vertexObjectState._elementArrayBufferBinding
75
- if (!elementBuffer) {
76
- ctx.setError(gl.INVALID_OPERATION)
77
- return
78
- }
79
-
80
- // Unpack element data
81
- let elementData = null
82
- let offset = ioffset
83
- if (type === gl.UNSIGNED_SHORT) {
84
- if (offset % 2) {
85
- ctx.setError(gl.INVALID_OPERATION)
86
- return
87
- }
88
- offset >>= 1
89
- elementData = new Uint16Array(elementBuffer._elements.buffer)
90
- } else if (ctx._extensions.oes_element_index_uint && type === gl.UNSIGNED_INT) {
91
- if (offset % 4) {
92
- ctx.setError(gl.INVALID_OPERATION)
93
- return
94
- }
95
- offset >>= 2
96
- elementData = new Uint32Array(elementBuffer._elements.buffer)
97
- } else if (type === gl.UNSIGNED_BYTE) {
98
- elementData = elementBuffer._elements
99
- } else {
100
- ctx.setError(gl.INVALID_ENUM)
101
- return
102
- }
103
-
104
- let reducedCount = count
105
- switch (mode) {
106
- case gl.TRIANGLES:
107
- if (count % 3) {
108
- reducedCount -= (count % 3)
109
- }
110
- break
111
- case gl.LINES:
112
- if (count % 2) {
113
- reducedCount -= (count % 2)
114
- }
115
- break
116
- case gl.POINTS:
117
- break
118
- case gl.LINE_LOOP:
119
- case gl.LINE_STRIP:
120
- if (count < 2) {
121
- ctx.setError(gl.INVALID_OPERATION)
122
- return
123
- }
124
- break
125
- case gl.TRIANGLE_FAN:
126
- case gl.TRIANGLE_STRIP:
127
- if (count < 3) {
128
- ctx.setError(gl.INVALID_OPERATION)
129
- return
130
- }
131
- break
132
- default:
133
- ctx.setError(gl.INVALID_ENUM)
134
- return
135
- }
136
-
137
- if (!ctx._framebufferOk()) {
138
- return
139
- }
140
-
141
- if (count === 0 || primCount === 0) {
142
- this.checkInstancedVertexAttribState(0, 0)
143
- return
144
- }
145
-
146
- if ((count + offset) >>> 0 > elementData.length) {
147
- ctx.setError(gl.INVALID_OPERATION)
148
- return
149
- }
150
-
151
- // Compute max index
152
- let maxIndex = -1
153
- for (let i = offset; i < offset + count; ++i) {
154
- maxIndex = Math.max(maxIndex, elementData[i])
155
- }
156
-
157
- if (maxIndex < 0) {
158
- this.checkInstancedVertexAttribState(0, 0)
159
- return
160
- }
161
-
162
- if (this.checkInstancedVertexAttribState(maxIndex, primCount)) {
163
- if (reducedCount > 0) {
164
- this._drawElementsInstanced(mode, reducedCount, type, ioffset, primCount)
165
- }
166
- }
167
- }
168
-
169
- vertexAttribDivisorANGLE (index: GLuint, divisor: GLuint) {
170
- const { ctx } = this
171
- index |= 0
172
- divisor |= 0
173
- if (divisor < 0 ||
174
- index < 0 || index >= ctx._vertexObjectState._attribs.length) {
175
- ctx.setError(gl.INVALID_VALUE)
176
- return
177
- }
178
- const attrib = ctx._vertexObjectState._attribs[index]
179
- attrib._divisor = divisor
180
- this._vertexAttribDivisor(index, divisor)
181
- }
182
-
183
- checkInstancedVertexAttribState (maxIndex: number, primCount: GLuint) {
184
- const { ctx } = this
185
- const program = ctx._activeProgram
186
- if (!program) {
187
- ctx.setError(gl.INVALID_OPERATION)
188
- return false
189
- }
190
-
191
- const attribs = ctx._vertexObjectState._attribs
192
- let hasZero = false
193
- for (let i = 0; i < attribs.length; ++i) {
194
- const attrib = attribs[i]
195
- if (attrib._isPointer) {
196
- const buffer = attrib._pointerBuffer
197
- if (program._attributes.indexOf(i) >= 0) {
198
- if (!buffer) {
199
- ctx.setError(gl.INVALID_OPERATION)
200
- return false
201
- }
202
- let maxByte = 0
203
- if (attrib._divisor === 0) {
204
- hasZero = true
205
- maxByte = attrib._pointerStride * maxIndex +
206
- attrib._pointerSize +
207
- attrib._pointerOffset
208
- } else {
209
- maxByte = attrib._pointerStride * (Math.ceil(primCount / attrib._divisor) - 1) +
210
- attrib._pointerSize +
211
- attrib._pointerOffset
212
- }
213
- if (maxByte > buffer._size) {
214
- ctx.setError(gl.INVALID_OPERATION)
215
- return false
216
- }
217
- }
218
- }
219
- }
220
-
221
- if (!hasZero) {
222
- ctx.setError(gl.INVALID_OPERATION)
223
- return false
224
- }
225
-
226
- return true
227
- }
228
- }
229
-
230
- export function getANGLEInstancedArrays (ctx: GjsifyWebGLRenderingContext) {
231
- return new ANGLEInstancedArrays(ctx)
232
- }
@@ -1,18 +0,0 @@
1
- import type { GjsifyWebGLRenderingContext } from '../webgl-rendering-context.js';
2
-
3
- export class EXTBlendMinMax {
4
- MIN_EXT = 0x8007
5
- MAX_EXT = 0x8008
6
- constructor () {}
7
- }
8
-
9
- export function getEXTBlendMinMax (context: GjsifyWebGLRenderingContext) {
10
- let result = null
11
- const exts = context.getSupportedExtensions()
12
-
13
- if (exts && exts.indexOf('EXT_blend_minmax') >= 0) {
14
- result = new EXTBlendMinMax()
15
- }
16
-
17
- return result
18
- }
@@ -1,18 +0,0 @@
1
- import type { GjsifyWebGLRenderingContext } from '../webgl-rendering-context.js';
2
-
3
- export class EXTTextureFilterAnisotropic {
4
- TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE
5
- MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF
6
- constructor () {}
7
- }
8
-
9
- export function getEXTTextureFilterAnisotropic (context: GjsifyWebGLRenderingContext) {
10
- let result = null
11
- const exts = context.getSupportedExtensions()
12
-
13
- if (exts && exts.indexOf('EXT_texture_filter_anisotropic') >= 0) {
14
- result = new EXTTextureFilterAnisotropic()
15
- }
16
-
17
- return result
18
- }
@@ -1,14 +0,0 @@
1
- import type { GjsifyWebGLRenderingContext } from '../webgl-rendering-context.js';
2
-
3
- export class OESElementIndexUint {}
4
-
5
- export function getOESElementIndexUint (context: GjsifyWebGLRenderingContext) {
6
- let result = null
7
- const exts = context.getSupportedExtensions()
8
-
9
- if (exts && exts.indexOf('OES_element_index_uint') >= 0) {
10
- result = new OESElementIndexUint()
11
- }
12
-
13
- return result
14
- }
@@ -1,17 +0,0 @@
1
- import type { GjsifyWebGLRenderingContext } from '../webgl-rendering-context.js';
2
-
3
- export class OESStandardDerivatives {
4
- FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B
5
- constructor () {}
6
- }
7
-
8
- export function getOESStandardDerivatives (context: GjsifyWebGLRenderingContext) {
9
- let result = null
10
- const exts = context.getSupportedExtensions()
11
-
12
- if (exts && exts.indexOf('OES_standard_derivatives') >= 0) {
13
- result = new OESStandardDerivatives()
14
- }
15
-
16
- return result
17
- }
@@ -1,14 +0,0 @@
1
- import type { GjsifyWebGLRenderingContext } from '../webgl-rendering-context.js';
2
-
3
- export class OESTextureFloatLinear {}
4
-
5
- export function getOESTextureFloatLinear (context: GjsifyWebGLRenderingContext) {
6
- let result = null
7
- const exts = context.getSupportedExtensions()
8
-
9
- if (exts && exts.indexOf('OES_texture_float_linear') >= 0) {
10
- result = new OESTextureFloatLinear()
11
- }
12
-
13
- return result
14
- }
@@ -1,14 +0,0 @@
1
- import type { GjsifyWebGLRenderingContext } from '../webgl-rendering-context.js';
2
-
3
- export class OESTextureFloat {}
4
-
5
- export function getOESTextureFloat (context: GjsifyWebGLRenderingContext) {
6
- let result = null
7
- const exts = context.getSupportedExtensions()
8
-
9
- if (exts && exts.indexOf('OES_texture_float') >= 0) {
10
- result = new OESTextureFloat()
11
- }
12
-
13
- return result
14
- }