a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 84c9e47123a850e272600411821f1741b2a57aaa
parent 2c0fe3b9e3d3e5d7a7605914d02a5401f223fccc
Author: amin <dev@aminmesbah.com>
Date:   Sun, 21 Jul 2019 02:44:28 +0000

Fix wasm to use glTexImage3D

FossilOrigin-Name: f6e02d1be662b475701964a48352be69d815e0d7a68a86aaaee4b7f43e99e452
Diffstat:
Msrc/platform_wasm_js_symbols.txt | 1+
Msrc/platform_wasm_loader.js | 9+++++++++
Msrc/webgl.h | 18++++++++++++++++++
3 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/platform_wasm_js_symbols.txt b/src/platform_wasm_js_symbols.txt @@ -32,6 +32,7 @@ webglLinkProgram webglScissor webglShaderSource webglTexImage2D +webglTexImage3D webglTexParameteri webglTexStorage3D webglTexSubImage3D diff --git a/src/platform_wasm_loader.js b/src/platform_wasm_loader.js @@ -166,6 +166,15 @@ imports["webglTexImage2D"] = function(target, level, internalformat, width, heig let dataslice = memory.subarray(pixels, pixels + (width * height * bytes_per_pixel)); gl.texImage2D(target, level, internalformat, width, height, border, format, type, dataslice); } +imports["webglTexImage3D"] = function(target, level, internalformat, width, height, depth, border, format, type, pixels) { + const bytes_per_pixel = 4; + let dataslice = null; + // TODO: We're probably in trouble if NULL != 0 in C + if (pixels !== 0) { + dataslice = memory.subarray(pixels, pixels + (width * height * depth * bytes_per_pixel)); + } + gl.texImage3D(target, level, internalformat, width, height, depth, border, format, type, dataslice); +} imports["webglTexParameteri"] = function(target, pname, param) { gl.texParameteri(target, pname, param); } diff --git a/src/webgl.h b/src/webgl.h @@ -40,6 +40,7 @@ void webglLinkProgram(i32 program); void webglScissor(i32 x, i32 y, i32 width, i32 height); void webglShaderSource(i32 shader, const char source[static 1], i32 source_len); void webglTexImage2D(i32 target, i32 level, i32 internalformat, i32 width, i32 height, i32 border, i32 format, i32 type, i32 pixels); +void webglTexImage3D(i32 target, i32 level, i32 internalformat, i32 width, i32 height, i32 depth, i32 border, i32 format, i32 type, i32 pixels); void webglTexParameteri(i32 target, i32 pname, i32 param); void webglTexStorage3D(i32 target, i32 levels, i32 internalformat, i32 width, i32 height, i32 depth); void webglTexSubImage3D (i32 target, i32 level, i32 xoffset, i32 yoffset, i32 zoffset, i32 width, i32 height, i32 depth, i32 format, i32 type, i32 pixels); @@ -100,6 +101,8 @@ typedef char GLchar; typedef long GLsizeiptr; // TODO: add a version with safety checks +// TODO: add a version that explicitely converts NULL to 0 (see todo in JS +// loader) #define WEBGL_CAST_I32(x) (i32)(x) static inline i32 _webgl_strlen(const char *str) @@ -313,6 +316,21 @@ void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei widt WEBGL_CAST_I32(pixels)); } +void glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels) +{ + webglTexImage3D( + WEBGL_CAST_I32(target), + WEBGL_CAST_I32(level), + WEBGL_CAST_I32(internalformat), + WEBGL_CAST_I32(width), + WEBGL_CAST_I32(height), + WEBGL_CAST_I32(depth), + WEBGL_CAST_I32(border), + WEBGL_CAST_I32(format), + WEBGL_CAST_I32(type), + WEBGL_CAST_I32(pixels)); +} + void glTexParameteri(GLenum target, GLenum pname, GLint param) { webglTexParameteri(WEBGL_CAST_I32(target), WEBGL_CAST_I32(pname), WEBGL_CAST_I32(param));