Wren a web browser where WebAssembly runs everything, JavaScript included

Module webgl

WebGL 1 and 2 for native/js/odin/web_webgl.js: a context is a host object over a device of its own (native/webgl: a thread in the GPU process); the script sends it command buffers and waits only for what it has to know. A context that is gone (its canvas freed, its device lost, the process dead) does nothing and answers -1 or false: these calls also come from a Wasm module of the page with any numbers, and the command stream is checked on the device's side. In a worker a context is on an OffscreenCanvas.

Exposed to: Window, Worker. Source: api/webgl.widl.

Odin: import "wren:webgl".

Types

callback WebGLNotify

void WebGLNotify(i32 user, i32 kind)

What a context has to say: kind 1 it was lost.

Functions

WebGL_enabled

bool WebGL_enabled(i32 version)

The preference webgl.enabled, and webgl.webgl2 for version 2.

Odin: webgl.enabled.

Host: WebGL_enabled :: proc(c: ^Call, version: i32) -> bool

WebGL_create

u64 WebGL_create(HTMLCanvasElement canvas, u32 flags, WebGLNotify notify, i32 user, out bytes info)

A context on a canvas (an element or an OffscreenCanvas). flags: 1 WebGL 2, 2 alpha, 4 depth, 8 stencil, 16 antialias, 32 premultipliedAlpha, 64 preserveDrawingBuffer, 128 failIfMajorPerformanceCaveat. info: 8 i32, for the script. 0: refused, WebGL_createError says why (nothing when the canvas already has a context of another kind).

Odin: webgl.create.

Host: WebGL_create :: proc(c: ^Call, canvas: Api_HTMLCanvasElement, flags: u32, notify: u32, user: i32, info: []u8) -> u64

WebGL_createOffscreen

u64 WebGL_createOffscreen(OffscreenCanvas canvas, u32 flags, WebGLNotify notify, i32 user, out bytes info)

Odin: webgl.createOffscreen.

Host: WebGL_createOffscreen :: proc(c: ^Call, canvas: Api_OffscreenCanvas, flags: u32, notify: u32, user: i32, info: []u8) -> u64

WebGL_createError

string WebGL_createError()

Odin: webgl.createError.

Host: WebGL_createError :: proc(c: ^Call) -> string

WebGL_submit

void WebGL_submit(u64 gl, bytes commands, bytes data, bool drew)

Commands; data is the bytes of the last one. drew: the canvas changed.

Odin: webgl.submit.

Host: WebGL_submit :: proc(c: ^Call, gl: u64, commands: []u8, data: []u8, drew: bool)

WebGL_query

f64 WebGL_query(u64 gl, bytes request, out bytes reply)

A question: waits for the answer (its bytes in reply). Its length, or the length it needs when it does not fit; -1: the context did not answer in time or is gone.

Odin: webgl.query.

Host: WebGL_query :: proc(c: ^Call, gl: u64, request: []u8, reply: []u8) -> f64

WebGL_queryText

f64 WebGL_queryText(u64 gl, bytes request, bytes text, out bytes reply)

As WebGL_query, with bytes after the request (a name).

Odin: webgl.queryText.

Host: WebGL_queryText :: proc(c: ^Call, gl: u64, request: []u8, text: []u8, reply: []u8) -> f64

WebGL_upload

i32 WebGL_upload(u64 gl, bytes command, u64 source) raises

texImage2D of an element or an ImageBitmap: the command with the source's pixels and size. Raises Security for what the page may not read. 1: nothing to read yet (an image still loading), the page gets INVALID_VALUE.

Odin: webgl.upload.

Raises: returns an Error (see web).

Host: WebGL_upload :: proc(c: ^Call, gl: u64, command: []u8, source: u64) -> (i32, Api_Error)

WebGL_width

u32 WebGL_width(u64 gl)

The drawing buffer's size.

Odin: webgl.width.

Host: WebGL_width :: proc(c: ^Call, gl: u64) -> u32

WebGL_height

u32 WebGL_height(u64 gl)

Odin: webgl.height.

Host: WebGL_height :: proc(c: ^Call, gl: u64) -> u32

WebGL_snapshot

void WebGL_snapshot(u64 gl)

What was drawn so far into the canvas's bitmap, now (toDataURL, drawImage).

Odin: webgl.snapshot.

Host: WebGL_snapshot :: proc(c: ^Call, gl: u64)

WebGL_commit

void WebGL_commit(u64 gl)

The same, and the frame ends: the drawing buffer starts again as after a present (transferToImageBitmap).

Odin: webgl.commit.

Host: WebGL_commit :: proc(c: ^Call, gl: u64)

WebGL_isLost

bool WebGL_isLost(u64 gl)

Odin: webgl.isLost.

Host: WebGL_isLost :: proc(c: ^Call, gl: u64) -> bool

WebGL_lose

void WebGL_lose(u64 gl)

Odin: webgl.lose.

Host: WebGL_lose :: proc(c: ^Call, gl: u64)

WebGL_restore

bool WebGL_restore(u64 gl)

Odin: webgl.restore.

Host: WebGL_restore :: proc(c: ^Call, gl: u64) -> bool

Edit this page on GitHub