@thi.ng/wasm-api-webgl 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.
package/zig/lib.zig ADDED
@@ -0,0 +1,143 @@
1
+ const std = @import("std");
2
+ const api = @import("api.zig");
3
+
4
+ pub usingnamespace api;
5
+
6
+ pub extern "webgl" fn canvasGLContext(canvasID: i32, opts: *const api.WebGLContextOpts) i32;
7
+
8
+ pub extern "webgl" fn createShader(ctxID: i32, spec: *const api.ShaderSpec) i32;
9
+
10
+ pub extern "webgl" fn createModel(ctxID: i32, spec: *const api.ModelSpec) i32;
11
+
12
+ pub extern "webgl" fn createTexture(ctxID: i32, spec: *const api.TextureSpec) i32;
13
+
14
+ pub extern "webgl" fn updateAttrib(modelID: i32, name: [*:0]const u8, spec: *const api.AttribUpdateSpec) void;
15
+
16
+ pub extern "webgl" fn uniformVec(modelID: i32, name: [*:0]const u8, value: [*]const f32, size: u32) void;
17
+
18
+ pub extern "webgl" fn uniformIVec(modelID: i32, name: [*:0]const u8, value: [*]const i32, size: u32) void;
19
+
20
+ pub extern "webgl" fn uniformUVec(modelID: i32, name: [*:0]const u8, value: [*]const u32, size: u32) void;
21
+
22
+ pub extern "webgl" fn uniformFloat(modelID: i32, name: [*:0]const u8, value: f32) void;
23
+
24
+ pub extern "webgl" fn uniformInt(modelID: i32, name: [*:0]const u8, value: i32) void;
25
+
26
+ pub extern "webgl" fn uniformUInt(modelID: i32, name: [*:0]const u8, value: u32) void;
27
+
28
+ pub extern "webgl" fn draw(modelID: i32) void;
29
+
30
+ pub extern "webgl" fn clear(ctxID: i32, r: f32, g: f32, b: f32, a: f32) void;
31
+
32
+ // Syntax sugar for `uniformVec()` and vec2 values
33
+ pub fn uniformVec2(modelID: i32, name: [*:0]const u8, value: *const [2]f32) void {
34
+ uniformVec(modelID, name, value, 2);
35
+ }
36
+
37
+ // Syntax sugar for `uniformVec()` and vec3 values
38
+ pub fn uniformVec3(modelID: i32, name: [*:0]const u8, value: *const [3]f32) void {
39
+ uniformVec(modelID, name, value, 3);
40
+ }
41
+
42
+ // Syntax sugar for `uniformVec()` and vec4 values
43
+ pub fn uniformVec4(modelID: i32, name: [*:0]const u8, value: *const [3]f32) void {
44
+ uniformVec(modelID, name, value, 3);
45
+ }
46
+
47
+ // Syntax sugar for `uniformVec()` and mat2 values
48
+ pub fn uniformMat22(modelID: i32, name: [*:0]const u8, value: *const [4]f32) void {
49
+ uniformVec(modelID, name, value, 4);
50
+ }
51
+
52
+ // Syntax sugar for `uniformVec()` and mat3 values
53
+ pub fn uniformMat33(modelID: i32, name: [*:0]const u8, value: *const [9]f32) void {
54
+ uniformVec(modelID, name, value, 9);
55
+ }
56
+
57
+ // Syntax sugar for `uniformVec()` and mat4 values
58
+ pub fn uniformMat44(modelID: i32, name: [*:0]const u8, value: *const [16]f32) void {
59
+ uniformVec(modelID, name, value, 16);
60
+ }
61
+
62
+ /// Syntax sugar for defining a `ModelAttributeSpec` of f32 values
63
+ pub fn modelAttribF32(
64
+ name: [*:0]const u8,
65
+ data: []const f32,
66
+ size: usize,
67
+ stride: usize,
68
+ offset: usize,
69
+ ) api.ModelAttribSpec {
70
+ return .{
71
+ .name = name,
72
+ .data = attribDataF32(data),
73
+ .type = .f32,
74
+ .size = size,
75
+ .stride = stride,
76
+ .offset = offset,
77
+ };
78
+ }
79
+
80
+ /// Syntax sugar for defining a `ModelAttributeSpec` of i32 values
81
+ pub fn modelAttribI32(
82
+ name: [*:0]const u8,
83
+ data: []const i32,
84
+ size: usize,
85
+ stride: usize,
86
+ offset: usize,
87
+ ) api.ModelAttribSpec {
88
+ return .{
89
+ .name = name,
90
+ .data = attribDataI32(data),
91
+ .type = .i32,
92
+ .size = size,
93
+ .stride = stride,
94
+ .offset = offset,
95
+ };
96
+ }
97
+
98
+ /// Syntax sugar for defining a `ModelAttributeSpec` of u32 values
99
+ pub fn modelAttribU32(
100
+ name: [*:0]const u8,
101
+ data: []const u32,
102
+ size: usize,
103
+ stride: usize,
104
+ offset: usize,
105
+ ) api.ModelAttribSpec {
106
+ return .{
107
+ .name = name,
108
+ .data = attribDataU32(data),
109
+ .type = .u32,
110
+ .size = size,
111
+ .stride = stride,
112
+ .offset = offset,
113
+ };
114
+ }
115
+
116
+ pub fn updateAttribF32(modelID: i32, name: [*:0]const u8, data: []const f32, offset: usize) void {
117
+ updateAttrib(modelID, name, &.{ .data = attribDataF32(data), .offset = offset });
118
+ }
119
+
120
+ pub fn updateAttribI32(modelID: i32, name: [*:0]const u8, data: []const i32, offset: usize) void {
121
+ updateAttrib(modelID, name, &.{ .data = attribDataI32(data), .offset = offset });
122
+ }
123
+
124
+ pub fn updateAttribU32(modelID: i32, name: [*:0]const u8, data: []const u32, offset: usize) void {
125
+ updateAttrib(modelID, name, &.{ .data = attribDataU32(data), .offset = offset });
126
+ }
127
+
128
+ pub inline fn attribDataF32(data: []const f32) api.ModelAttribData {
129
+ return .{ .f32 = api.ConstF32Slice.wrap(data) };
130
+ }
131
+
132
+ pub inline fn attribDataI32(data: []const i32) api.ModelAttribData {
133
+ return .{ .i32 = api.ConstI32Slice.wrap(data) };
134
+ }
135
+
136
+ pub inline fn attribDataU32(data: []const u32) api.ModelAttribData {
137
+ return .{ .u32 = api.ConstI32Slice.wrap(data) };
138
+ }
139
+
140
+ /// Syntax sugar for defining u8 based `ImageData` from ABGR u32 source data
141
+ pub inline fn textureDataU32(data: []const u32) api.ImageData {
142
+ return .{ .u8 = api.ConstU8Slice.wrap(std.mem.sliceAsBytes(data)) };
143
+ }