Skip to content

Commit f419f05

Browse files
committed
support WEBGL_lose_context
1 parent 3c98e4f commit f419f05

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/browser/canvas/WebGLRenderingContext.zig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub const Extension = union(enum) {
6161
WEBGL_debug_shaders: void,
6262
WEBGL_depth_texture: void,
6363
WEBGL_draw_buffers: void,
64-
WEBGL_lose_context: void,
64+
WEBGL_lose_context: Type.WEBGL_lose_context,
6565
WEBGL_multi_draw: void,
6666
WEBGL_polygon_mode: void,
6767

@@ -117,6 +117,12 @@ pub const Extension = union(enum) {
117117
return UNMASKED_RENDERER_WEBGL;
118118
}
119119
};
120+
121+
pub const WEBGL_lose_context = struct {
122+
_: u8 = 0,
123+
pub fn _loseContext(_: *const WEBGL_lose_context) void {}
124+
pub fn _restoreContext(_: *const WEBGL_lose_context) void {}
125+
};
120126
};
121127
};
122128

@@ -128,6 +134,7 @@ pub fn _getExtension(self: *const WebGLRenderingContext, name: []const u8) ?Exte
128134

129135
return switch (tag) {
130136
.WEBGL_debug_renderer_info => @unionInit(Extension, "WEBGL_debug_renderer_info", .{}),
137+
.WEBGL_lose_context => @unionInit(Extension, "WEBGL_lose_context", .{}),
131138
inline else => |comptime_enum| @unionInit(Extension, @tagName(comptime_enum), {}),
132139
};
133140
}

src/browser/canvas/root.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ pub const Interfaces = .{
99
CanvasRenderingContext2D,
1010
WebGLRenderingContext,
1111
Extension.Type.WEBGL_debug_renderer_info,
12+
Extension.Type.WEBGL_lose_context,
1213
};

src/tests/html/canvas.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,15 @@
102102
testing.expectEqual(rendererInfo.UNMASKED_VENDOR_WEBGL, 0x9245);
103103
testing.expectEqual(rendererInfo.UNMASKED_RENDERER_WEBGL, 0x9246);
104104
}
105+
106+
// WEBGL_lose_context
107+
{
108+
const element = document.createElement("canvas");
109+
const ctx = element.getContext("webgl");
110+
const loseContext = ctx.getExtension("WEBGL_lose_context");
111+
testing.expectEqual(true, loseContext instanceof WEBGL_lose_context);
112+
113+
loseContext.loseContext();
114+
loseContext.restoreContext();
115+
}
105116
</script>

0 commit comments

Comments
 (0)