@gtkx/gl 0.21.0 → 1.0.0-rc.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.
@@ -1,18 +1,14 @@
1
1
  /**
2
- * GENERATED FILE do not edit.
3
- *
4
- * Emitted by the `@gtkx/codegen` Khronos generator from the vendored
5
- * `registry/gl.xml` (gl 4.6 core profile). Regenerate with
6
- * `pnpm --filter @gtkx/codegen codegen:gl`.
2
+ * GENERATED FILE: do not edit.
7
3
  */
8
4
 
9
- import type { Handle } from "@gtkx/native";
5
+ import { type ExternalObject, type Handle } from "@gtkx/native";
10
6
 
11
7
  /** An opaque `GLsync` fence handle. */
12
- export type GLsync = Handle;
8
+ export type GLsync = ExternalObject<Handle>;
13
9
 
14
10
  /** An opaque native pointer handle (e.g. a `glMapBufferRange` mapping). */
15
- export type GLpointer = Handle;
11
+ export type GLpointer = ExternalObject<Handle>;
16
12
 
17
13
  /** The C `GLenum` scalar. */
18
14
  export type GLenum = number;
@@ -41,24 +37,12 @@ export type GLshort = number;
41
37
  /** The C `GLushort` scalar. */
42
38
  export type GLushort = number;
43
39
 
44
- /** The C `GLfixed` scalar. */
45
- export type GLfixed = number;
46
-
47
- /** The C `GLclampx` scalar. */
48
- export type GLclampx = number;
49
-
50
40
  /** The C `GLfloat` scalar. */
51
41
  export type GLfloat = number;
52
42
 
53
- /** The C `GLclampf` scalar. */
54
- export type GLclampf = number;
55
-
56
43
  /** The C `GLdouble` scalar. */
57
44
  export type GLdouble = number;
58
45
 
59
- /** The C `GLclampd` scalar. */
60
- export type GLclampd = number;
61
-
62
46
  /** The C `GLint64` scalar. */
63
47
  export type GLint64 = number;
64
48
 
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./companion.js";
2
1
  export * from "./generated/commands.js";
3
2
  export * from "./generated/enums.js";
4
3
  export type * from "./generated/types.js";
4
+ export * from "./overrides.js";
@@ -0,0 +1,180 @@
1
+ import { t } from "@gtkx/runtime";
2
+ import type {
3
+ DebugSeverity,
4
+ DebugSource,
5
+ DebugType,
6
+ GLenum,
7
+ GLint,
8
+ GLsync,
9
+ GLuint,
10
+ SyncObjectMask,
11
+ SyncStatus,
12
+ } from "./generated/types.js";
13
+ import { clientWaitSync, enable, getProgramiv, getProgramPipelineiv, getShaderiv, LIB } from "./generated/commands.js";
14
+ import {
15
+ ALREADY_SIGNALED,
16
+ CONDITION_SATISFIED,
17
+ DEBUG_OUTPUT,
18
+ DEBUG_OUTPUT_SYNCHRONOUS,
19
+ INFO_LOG_LENGTH,
20
+ TIMEOUT_EXPIRED,
21
+ } from "./generated/enums.js";
22
+
23
+ type LengthQuery = (id: GLuint, pname: GLenum) => GLint;
24
+ type DebugCallbackArgs = [GLenum, GLenum, GLuint, GLenum, number, string];
25
+
26
+ /**
27
+ * A debug message reported by the GL driver.
28
+ */
29
+ type DebugMessage = {
30
+ /** The origin of the message (API, window system, shader compiler, and so on). */
31
+ source: DebugSource;
32
+ /** The category of the message (error, deprecated behavior, performance, and so on). */
33
+ type: DebugType;
34
+ /** The driver-assigned identifier of the message. */
35
+ id: GLuint;
36
+ /** The severity level of the message. */
37
+ severity: DebugSeverity;
38
+ /** The human-readable message text. */
39
+ message: string;
40
+ };
41
+
42
+ /**
43
+ * Callback invoked for each GL debug message reported by the driver.
44
+ * @param message The message reported by the driver.
45
+ */
46
+ type DebugMessageCallback = (message: DebugMessage) => void;
47
+
48
+ const glDebugMessageCallbackBinding = t.bind(
49
+ LIB,
50
+ "glDebugMessageCallback",
51
+ [
52
+ t.callback([t.uint32, t.uint32, t.uint32, t.uint32, t.int32, t.string("borrowed"), t.uint64], t.void, {
53
+ userDataIndex: 6,
54
+ scope: "forever",
55
+ }),
56
+ ],
57
+ t.void,
58
+ );
59
+
60
+ const MAX_WAIT_CHUNK_NS = 1_000_000_000;
61
+
62
+ const readInfoLog = (symbol: string, id: GLuint, query: LengthQuery): string => {
63
+ const length = query(id, INFO_LOG_LENGTH);
64
+
65
+ if (length <= 0) {
66
+ return "";
67
+ }
68
+
69
+ const written = { value: 0 };
70
+ const log = { value: "" };
71
+
72
+ t.bind(LIB, symbol, [t.uint32, t.int32, t.ref(t.int32), t.ref(t.string("borrowed", length))], t.void)(
73
+ id,
74
+ length,
75
+ written,
76
+ log,
77
+ );
78
+
79
+ return log.value;
80
+ };
81
+
82
+ /**
83
+ * Reads the info log for a shader object, containing compilation diagnostics.
84
+ * @param shader The name of the shader object to query.
85
+ * @returns The shader info log, or an empty string when none is available.
86
+ */
87
+ function getShaderInfoLog(shader: GLuint): string {
88
+ return readInfoLog("glGetShaderInfoLog", shader, getShaderiv);
89
+ }
90
+
91
+ /**
92
+ * Reads the info log for a program object, containing linking diagnostics.
93
+ * @param program The name of the program object to query.
94
+ * @returns The program info log, or an empty string when none is available.
95
+ */
96
+ function getProgramInfoLog(program: GLuint): string {
97
+ return readInfoLog("glGetProgramInfoLog", program, getProgramiv);
98
+ }
99
+
100
+ /**
101
+ * Reads the info log for a program pipeline object, containing validation diagnostics.
102
+ * @param pipeline The name of the program pipeline object to query.
103
+ * @returns The pipeline info log, or an empty string when none is available.
104
+ */
105
+ function getProgramPipelineInfoLog(pipeline: GLuint): string {
106
+ return readInfoLog("glGetProgramPipelineInfoLog", pipeline, getProgramPipelineiv);
107
+ }
108
+
109
+ /**
110
+ * Installs a callback that receives GL debug messages, enabling synchronous debug output.
111
+ * Passing null removes any previously installed callback.
112
+ * @param callback The handler to invoke for each debug message, or null to clear it.
113
+ */
114
+ function debugMessageCallback(callback: DebugMessageCallback | null): void {
115
+ if (callback === null) {
116
+ glDebugMessageCallbackBinding(null);
117
+
118
+ return;
119
+ }
120
+
121
+ enable(DEBUG_OUTPUT);
122
+ enable(DEBUG_OUTPUT_SYNCHRONOUS);
123
+
124
+ glDebugMessageCallbackBinding((...args: DebugCallbackArgs) => {
125
+ const [source, type, id, severity, , message] = args;
126
+ callback({ source, type, id, severity, message });
127
+ });
128
+ }
129
+
130
+ const settledSyncStatus = (status: SyncStatus): SyncStatus | null => {
131
+ if (status === ALREADY_SIGNALED || status === CONDITION_SATISFIED) {
132
+ return status;
133
+ }
134
+
135
+ if (status !== TIMEOUT_EXPIRED) {
136
+ return status;
137
+ }
138
+
139
+ return null;
140
+ };
141
+
142
+ /**
143
+ * Blocks until a sync object is signaled or the timeout elapses, looping over glClientWaitSync
144
+ * in bounded chunks so long waits are not truncated by the driver's per-call limit.
145
+ * @param sync The sync object (fence) to wait on.
146
+ * @param flags Flags controlling the wait, such as flushing pending commands on the first call.
147
+ * @param timeoutNs The total time to wait, in nanoseconds.
148
+ * @returns The status of the sync object: signaled, condition satisfied, or timeout expired.
149
+ */
150
+ function clientWaitSyncLoop(sync: GLsync, flags: SyncObjectMask, timeoutNs: number): SyncStatus {
151
+ let remaining = timeoutNs;
152
+ let currentFlags = flags;
153
+
154
+ for (;;) {
155
+ const chunk = Math.min(remaining, MAX_WAIT_CHUNK_NS);
156
+ const settled = settledSyncStatus(clientWaitSync(sync, currentFlags, chunk));
157
+
158
+ if (settled !== null) {
159
+ return settled;
160
+ }
161
+
162
+ remaining -= chunk;
163
+
164
+ if (remaining <= 0) {
165
+ return TIMEOUT_EXPIRED;
166
+ }
167
+
168
+ currentFlags = 0;
169
+ }
170
+ }
171
+
172
+ export {
173
+ getShaderInfoLog,
174
+ getProgramInfoLog,
175
+ getProgramPipelineInfoLog,
176
+ debugMessageCallback,
177
+ clientWaitSyncLoop,
178
+ type DebugMessage,
179
+ type DebugMessageCallback,
180
+ };
@@ -1,8 +0,0 @@
1
- import type { GLbitfield, GLenum, GLsync, GLuint } from "./generated/types.js";
2
- export declare function getShaderInfoLog(shader: GLuint): string;
3
- export declare function getProgramInfoLog(program: GLuint): string;
4
- export declare function getProgramPipelineInfoLog(pipeline: GLuint): string;
5
- export type DebugMessageCallback = (source: GLenum, type: GLenum, id: GLuint, severity: GLenum, message: string) => void;
6
- export declare function debugMessageCallback(callback: DebugMessageCallback | null): void;
7
- export declare function clientWaitSyncLoop(sync: GLsync, flags: GLbitfield, timeoutNs: number): GLenum;
8
- //# sourceMappingURL=companion.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"companion.d.ts","sourceRoot":"","sources":["../src/companion.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAS,MAAM,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAoBtF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,MAAM,MAAM,oBAAoB,GAAG,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,KACd,IAAI,CAAC;AAcV,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,GAAG,IAAI,CAWhF;AAID,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAY7F"}
package/dist/companion.js DELETED
@@ -1,55 +0,0 @@
1
- import { t } from "@gtkx/ffi";
2
- import { clientWaitSync, enable, getProgramiv, getProgramPipelineiv, getShaderiv } from "./generated/commands.js";
3
- import { ALREADY_SIGNALED, CONDITION_SATISFIED, DEBUG_OUTPUT, DEBUG_OUTPUT_SYNCHRONOUS, INFO_LOG_LENGTH, TIMEOUT_EXPIRED, } from "./generated/enums.js";
4
- const LIB = "libGL.so.1";
5
- const readInfoLog = (symbol, id, query) => {
6
- const length = query(id, INFO_LOG_LENGTH);
7
- if (length <= 0)
8
- return "";
9
- const written = { value: 0 };
10
- const log = { value: "" };
11
- t.bind(LIB, symbol, [t.uint32, t.int32, t.ref(t.int32), t.ref(t.string("borrowed", length))], t.void)(id, length, written, log);
12
- return log.value;
13
- };
14
- export function getShaderInfoLog(shader) {
15
- return readInfoLog("glGetShaderInfoLog", shader, getShaderiv);
16
- }
17
- export function getProgramInfoLog(program) {
18
- return readInfoLog("glGetProgramInfoLog", program, getProgramiv);
19
- }
20
- export function getProgramPipelineInfoLog(pipeline) {
21
- return readInfoLog("glGetProgramPipelineInfoLog", pipeline, getProgramPipelineiv);
22
- }
23
- const glDebugMessageCallbackBinding = t.bind(LIB, "glDebugMessageCallback", [
24
- t.callback([t.uint32, t.uint32, t.uint32, t.uint32, t.int32, t.string("borrowed"), t.uint64], t.void, {
25
- userDataIndex: 6,
26
- scope: "forever",
27
- }),
28
- ], t.void);
29
- export function debugMessageCallback(callback) {
30
- if (callback === null) {
31
- glDebugMessageCallbackBinding(null);
32
- return;
33
- }
34
- enable(DEBUG_OUTPUT);
35
- enable(DEBUG_OUTPUT_SYNCHRONOUS);
36
- glDebugMessageCallbackBinding((source, type, id, severity, _length, message) => callback(source, type, id, severity, message));
37
- }
38
- const MAX_WAIT_CHUNK_NS = 1_000_000_000;
39
- export function clientWaitSyncLoop(sync, flags, timeoutNs) {
40
- let remaining = timeoutNs;
41
- let currentFlags = flags;
42
- for (;;) {
43
- const chunk = Math.min(remaining, MAX_WAIT_CHUNK_NS);
44
- const status = clientWaitSync(sync, currentFlags, chunk);
45
- if (status === ALREADY_SIGNALED || status === CONDITION_SATISFIED)
46
- return status;
47
- if (status !== TIMEOUT_EXPIRED)
48
- return status;
49
- remaining -= chunk;
50
- if (remaining <= 0)
51
- return TIMEOUT_EXPIRED;
52
- currentFlags = 0;
53
- }
54
- }
55
- //# sourceMappingURL=companion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"companion.js","sourceRoot":"","sources":["../src/companion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAA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,YAAY,EAAE,KAAK,CAAC,CAAC;QACzD,IAAI,MAAM,KAAK,gBAAgB,IAAI,MAAM,KAAK,mBAAmB;YAAE,OAAO,MAAM,CAAC;QACjF,IAAI,MAAM,KAAK,eAAe;YAAE,OAAO,MAAM,CAAC;QAC9C,SAAS,IAAI,KAAK,CAAC;QACnB,IAAI,SAAS,IAAI,CAAC;YAAE,OAAO,eAAe,CAAC;QAC3C,YAAY,GAAG,CAAC,CAAC;IACrB,CAAC;AACL,CAAC"}
package/src/companion.ts DELETED
@@ -1,90 +0,0 @@
1
- import { t } from "@gtkx/ffi";
2
- import { clientWaitSync, enable, getProgramiv, getProgramPipelineiv, getShaderiv } from "./generated/commands.js";
3
- import {
4
- ALREADY_SIGNALED,
5
- CONDITION_SATISFIED,
6
- DEBUG_OUTPUT,
7
- DEBUG_OUTPUT_SYNCHRONOUS,
8
- INFO_LOG_LENGTH,
9
- TIMEOUT_EXPIRED,
10
- } from "./generated/enums.js";
11
- import type { GLbitfield, GLenum, GLint, GLsync, GLuint } from "./generated/types.js";
12
-
13
- const LIB = "libGL.so.1";
14
-
15
- type LengthQuery = (id: GLuint, pname: GLenum) => GLint;
16
-
17
- const readInfoLog = (symbol: string, id: GLuint, query: LengthQuery): string => {
18
- const length = query(id, INFO_LOG_LENGTH);
19
- if (length <= 0) return "";
20
- const written = { value: 0 };
21
- const log = { value: "" };
22
- t.bind(LIB, symbol, [t.uint32, t.int32, t.ref(t.int32), t.ref(t.string("borrowed", length))], t.void)(
23
- id,
24
- length,
25
- written,
26
- log,
27
- );
28
- return log.value;
29
- };
30
-
31
- export function getShaderInfoLog(shader: GLuint): string {
32
- return readInfoLog("glGetShaderInfoLog", shader, getShaderiv);
33
- }
34
-
35
- export function getProgramInfoLog(program: GLuint): string {
36
- return readInfoLog("glGetProgramInfoLog", program, getProgramiv);
37
- }
38
-
39
- export function getProgramPipelineInfoLog(pipeline: GLuint): string {
40
- return readInfoLog("glGetProgramPipelineInfoLog", pipeline, getProgramPipelineiv);
41
- }
42
-
43
- export type DebugMessageCallback = (
44
- source: GLenum,
45
- type: GLenum,
46
- id: GLuint,
47
- severity: GLenum,
48
- message: string,
49
- ) => void;
50
-
51
- const glDebugMessageCallbackBinding = t.bind(
52
- LIB,
53
- "glDebugMessageCallback",
54
- [
55
- t.callback([t.uint32, t.uint32, t.uint32, t.uint32, t.int32, t.string("borrowed"), t.uint64], t.void, {
56
- userDataIndex: 6,
57
- scope: "forever",
58
- }),
59
- ],
60
- t.void,
61
- );
62
-
63
- export function debugMessageCallback(callback: DebugMessageCallback | null): void {
64
- if (callback === null) {
65
- glDebugMessageCallbackBinding(null);
66
- return;
67
- }
68
- enable(DEBUG_OUTPUT);
69
- enable(DEBUG_OUTPUT_SYNCHRONOUS);
70
- glDebugMessageCallbackBinding(
71
- (source: GLenum, type: GLenum, id: GLuint, severity: GLenum, _length: number, message: string) =>
72
- callback(source, type, id, severity, message),
73
- );
74
- }
75
-
76
- const MAX_WAIT_CHUNK_NS = 1_000_000_000;
77
-
78
- export function clientWaitSyncLoop(sync: GLsync, flags: GLbitfield, timeoutNs: number): GLenum {
79
- let remaining = timeoutNs;
80
- let currentFlags = flags;
81
- for (;;) {
82
- const chunk = Math.min(remaining, MAX_WAIT_CHUNK_NS);
83
- const status = clientWaitSync(sync, currentFlags, chunk);
84
- if (status === ALREADY_SIGNALED || status === CONDITION_SATISFIED) return status;
85
- if (status !== TIMEOUT_EXPIRED) return status;
86
- remaining -= chunk;
87
- if (remaining <= 0) return TIMEOUT_EXPIRED;
88
- currentFlags = 0;
89
- }
90
- }