diff --git a/jsconfig.base.json b/jsconfig.base.json index 234ae7b..48f2c0d 100644 --- a/jsconfig.base.json +++ b/jsconfig.base.json @@ -25,7 +25,6 @@ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, "noFallthroughCasesInSwitch": true, "verbatimModuleSyntax": true, "useDefineForClassFields": true diff --git a/wasm/webgl/interface.js b/wasm/webgl/interface.js index b5fd5a7..b01ad65 100644 --- a/wasm/webgl/interface.js +++ b/wasm/webgl/interface.js @@ -12,19 +12,19 @@ export function makeWebGLState() { version: 1, id_counter: 1, last_error: 0, - buffers: [], - programs: [], - framebuffers: [], - renderbuffers: [], - textures: [], - uniforms: [], - shaders: [], - vaos: [], - queries: [], - samplers: [], - transform_feedbacks: [], - syncs: [], - program_infos: [], + buffers: [null], + programs: [null], + framebuffers: [null], + renderbuffers: [null], + textures: [null], + uniforms: [null], + shaders: [null], + vaos: [null], + queries: [null], + samplers: [null], + transform_feedbacks: [null], + syncs: [null], + program_infos: [null], } } diff --git a/wasm/webgl/webgl.js b/wasm/webgl/webgl.js index ff538eb..f8ff504 100644 --- a/wasm/webgl/webgl.js +++ b/wasm/webgl/webgl.js @@ -140,7 +140,10 @@ export function makeOdinWebGL(webgl, wasm) { }, /** @returns {void} */ AttachShader: (/** @type {number} */ program, /** @type {number} */ shader) => { - webgl.ctx.attachShader(webgl.programs[program], webgl.shaders[shader]) + webgl.ctx.attachShader( + /** @type {WebGLProgram} */ (webgl.programs[program]), + /** @type {WebGLShader} */ (webgl.shaders[shader]), + ) }, /** * @param {number} program @@ -151,7 +154,11 @@ export function makeOdinWebGL(webgl, wasm) { */ BindAttribLocation: (program, index, name_ptr, name_len) => { const name = mem.load_string_raw(wasm.memory.buffer, name_ptr, name_len) - webgl.ctx.bindAttribLocation(webgl.programs[program], index, name) + webgl.ctx.bindAttribLocation( + /** @type {WebGLProgram} */ (webgl.programs[program]), + index, + name, + ) }, /** * @param {number} target @@ -184,7 +191,7 @@ export function makeOdinWebGL(webgl, wasm) { // @ts-expect-error webgl.ctx.currentPixelUnpackBufferBinding = buffer } - webgl.ctx.bindBuffer(target, buffer ? webgl.buffers[buffer] : null) + webgl.ctx.bindBuffer(target, webgl.buffers[buffer]) }, /** * @param {number} target @@ -311,7 +318,7 @@ export function makeOdinWebGL(webgl, wasm) { * @returns {void} */ CompileShader: shader => { - webgl.ctx.compileShader(webgl.shaders[shader]) + webgl.ctx.compileShader(/** @type {WebGLShader} */(webgl.shaders[shader])) }, CompressedTexImage2D: ( /** @type {number} */ target, @@ -567,7 +574,10 @@ export function makeOdinWebGL(webgl, wasm) { * @returns {void} */ DetachShader: (program, shader) => { - webgl.ctx.detachShader(webgl.programs[program], webgl.shaders[shader]) + webgl.ctx.detachShader( + /** @type {WebGLProgram} */ (webgl.programs[program]), + /** @type {WebGLShader} */(webgl.shaders[shader]), + ) }, /** * @param {number} cap @@ -676,7 +686,10 @@ export function makeOdinWebGL(webgl, wasm) { */ GetAttribLocation: (program, name_ptr, name_len) => { const name = mem.load_string_raw(wasm.memory.buffer, name_ptr, name_len) - return webgl.ctx.getAttribLocation(webgl.programs[program], name) + return webgl.ctx.getAttribLocation( + /** @type {WebGLProgram} */ (webgl.programs[program]), + name, + ) }, /** * @param {number} pname @@ -691,7 +704,10 @@ export function makeOdinWebGL(webgl, wasm) { * @returns {number} */ GetProgramParameter: (program, pname) => { - return webgl.ctx.getProgramParameter(webgl.programs[program], pname) + return webgl.ctx.getProgramParameter( + /** @type {WebGLProgram} */ (webgl.programs[program]), + pname, + ) }, /** * @param {number} program @@ -703,7 +719,10 @@ export function makeOdinWebGL(webgl, wasm) { GetProgramInfoLog: (program, buf_ptr, buf_len, length_ptr) => { if (buf_len <= 0 || !buf_ptr) return - const log = webgl.ctx.getProgramInfoLog(webgl.programs[program]) ?? "(unknown error)" + const log = + webgl.ctx.getProgramInfoLog( + /** @type {WebGLProgram} */ (webgl.programs[program]), + ) ?? "(unknown error)" const n = mem.store_string_raw(wasm.memory.buffer, buf_ptr, buf_len, log) mem.store_int(new DataView(wasm.memory.buffer), length_ptr, n) }, @@ -717,7 +736,7 @@ export function makeOdinWebGL(webgl, wasm) { GetShaderInfoLog: (shader, buf_ptr, buf_len, length_ptr) => { if (buf_len <= 0 || !buf_ptr) return - const log = webgl.ctx.getShaderInfoLog(webgl.shaders[shader]) ?? "(unknown error)" + const log = webgl.ctx.getShaderInfoLog(/** @type {WebGLShader} */(webgl.shaders[shader])) ?? "(unknown error)" const n = mem.store_string_raw(wasm.memory.buffer, buf_ptr, buf_len, log) mem.store_int(new DataView(wasm.memory.buffer), length_ptr, n) }, @@ -850,7 +869,7 @@ export function makeOdinWebGL(webgl, wasm) { * @returns {void} */ LinkProgram: program => { - webgl.ctx.linkProgram(webgl.programs[program]) + webgl.ctx.linkProgram(/** @type {WebGLProgram} */ (webgl.programs[program])) webgl.program_infos[program] = null populateUniformTable(webgl, program) }, @@ -928,7 +947,7 @@ export function makeOdinWebGL(webgl, wasm) { */ ShaderSource: (shader, strings_ptr, strings_length) => { const source = getSource(wasm.memory.buffer, strings_ptr, strings_length) - webgl.ctx.shaderSource(webgl.shaders[shader], source) + webgl.ctx.shaderSource(/** @type {WebGLShader} */(webgl.shaders[shader]), source) }, /** * @param {number} func @@ -1173,7 +1192,7 @@ export function makeOdinWebGL(webgl, wasm) { * @returns {void} */ ValidateProgram: program => { - webgl.ctx.validateProgram(webgl.programs[program]) + webgl.ctx.validateProgram(/** @type {WebGLProgram} */ (webgl.programs[program])) }, /** * @param {number} index diff --git a/wasm/webgl/webgl2.js b/wasm/webgl/webgl2.js index 5631e9f..cca76fd 100644 --- a/wasm/webgl/webgl2.js +++ b/wasm/webgl/webgl2.js @@ -95,7 +95,9 @@ export function makeOdinWegGL2( ) => { webgl.ctx.invalidateFramebuffer( target, - new Uint32Array(wasm.memory.buffer, attachments_ptr, attachments_len), + /** @type {any} */ ( + new Uint32Array(wasm.memory.buffer, attachments_ptr, attachments_len) + ), ) }, InvalidateSubFramebuffer: ( @@ -109,7 +111,9 @@ export function makeOdinWegGL2( ) => { webgl.ctx.invalidateSubFramebuffer( target, - new Uint32Array(wasm.memory.buffer, attachments_ptr, attachments_len), + /** @type {any} */ ( + new Uint32Array(wasm.memory.buffer, attachments_ptr, attachments_len) + ), x, y, width, @@ -280,7 +284,7 @@ export function makeOdinWegGL2( /** @type {number} */ name_len, ) => { return webgl.ctx.getFragDataLocation( - webgl.programs[program], + /** @type {WebGLProgram} */ (webgl.programs[program]), mem.load_string_raw(wasm.memory.buffer, name_ptr, name_len), ) }, @@ -463,7 +467,9 @@ export function makeOdinWegGL2( /* Multiple Render Targets */ DrawBuffers: (/** @type {number} */ buffers_ptr, /** @type {number} */ buffers_len) => { - webgl.ctx.drawBuffers(mem.load_u32_array(wasm.memory.buffer, buffers_ptr, buffers_len)) + webgl.ctx.drawBuffers( + /** @type {any} */ (new Uint32Array(wasm.memory.buffer, buffers_ptr, buffers_len)), + ) }, ClearBufferfv: ( /** @type {number} */ buffer, @@ -474,7 +480,7 @@ export function makeOdinWegGL2( webgl.ctx.clearBufferfv( buffer, drawbuffer, - mem.load_f32_array(wasm.memory.buffer, values_ptr, values_len), + new Float32Array(wasm.memory.buffer, values_ptr, values_len), ) }, ClearBufferiv: ( @@ -486,7 +492,7 @@ export function makeOdinWegGL2( webgl.ctx.clearBufferiv( buffer, drawbuffer, - mem.load_i32_array(wasm.memory.buffer, values_ptr, values_len), + new Int32Array(wasm.memory.buffer, values_ptr, values_len), ) }, ClearBufferuiv: ( @@ -498,7 +504,7 @@ export function makeOdinWegGL2( webgl.ctx.clearBufferuiv( buffer, drawbuffer, - mem.load_u32_array(wasm.memory.buffer, values_ptr, values_len), + new Uint32Array(wasm.memory.buffer, values_ptr, values_len), ) }, ClearBufferfi: ( @@ -547,7 +553,7 @@ export function makeOdinWegGL2( * @param {number} query */ BeginQuery: (target, query) => { - webgl.ctx.beginQuery(target, webgl.queries[query]) + webgl.ctx.beginQuery(target, /** @type {WebGLQuery} */ (webgl.queries[query])) }, /** @param {number} target */ EndQuery: target => { @@ -619,7 +625,11 @@ export function makeOdinWegGL2( * @returns {void} */ SamplerParameteri: (sampler, pname, param) => { - webgl.ctx.samplerParameteri(webgl.samplers[sampler], pname, param) + webgl.ctx.samplerParameteri( + /** @type {WebGLSampler} */ (webgl.samplers[sampler]), + pname, + param, + ) }, /** * @param {number} sampler @@ -628,7 +638,11 @@ export function makeOdinWegGL2( * @returns {void} */ SamplerParameterf: (sampler, pname, param) => { - webgl.ctx.samplerParameterf(webgl.samplers[sampler], pname, param) + webgl.ctx.samplerParameterf( + /** @type {WebGLSampler} */ (webgl.samplers[sampler]), + pname, + param, + ) }, /* @@ -674,7 +688,11 @@ export function makeOdinWegGL2( * @returns {number} */ ClientWaitSync: (sync, flags, timeout) => { - return webgl.ctx.clientWaitSync(webgl.syncs[sync], flags, timeout) + return webgl.ctx.clientWaitSync( + /** @type {WebGLSync} */ (webgl.syncs[sync]), + flags, + timeout, + ) }, /** * @param {number} sync @@ -683,7 +701,7 @@ export function makeOdinWegGL2( * @returns {void} */ WaitSync: (sync, flags, timeout) => { - webgl.ctx.waitSync(webgl.syncs[sync], flags, timeout) + webgl.ctx.waitSync(/** @type {WebGLSync} */ (webgl.syncs[sync]), flags, timeout) }, /* @@ -738,7 +756,11 @@ export function makeOdinWegGL2( ) => { const data = new DataView(wasm.memory.buffer) const varyings = mem.load_strings(data, varyings_ptr, varyings_len) - webgl.ctx.transformFeedbackVaryings(webgl.programs[program], varyings, buffer_mode) + webgl.ctx.transformFeedbackVaryings( + /** @type {WebGLProgram} */ (webgl.programs[program]), + varyings, + buffer_mode, + ) }, /** @returns {void} */ PauseTransformFeedback: () => { @@ -778,7 +800,7 @@ export function makeOdinWegGL2( /** @type {number} */ name_len, ) => { return webgl.ctx.getUniformBlockIndex( - webgl.programs[program], + /** @type {WebGLProgram} */ (webgl.programs[program]), mem.load_string_raw(wasm.memory.buffer, name_ptr, name_len), ) }, @@ -791,7 +813,7 @@ export function makeOdinWegGL2( /** @type {number} */ length_ptr, ) => { const name = webgl.ctx.getActiveUniformBlockName( - webgl.programs[program], + /** @type {WebGLProgram} */ (webgl.programs[program]), uniform_block_index, ) if (!name) { @@ -808,7 +830,7 @@ export function makeOdinWegGL2( /** @type {number} */ uniformBlockBinding, ) => { webgl.ctx.uniformBlockBinding( - webgl.programs[program], + /** @type {WebGLProgram} */ (webgl.programs[program]), uniformBlockIndex, uniformBlockBinding, )