Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,202 @@
// from https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletNode
function create_thread(func) {
}
class AudioThread extends AudioWorkletProcessor {
constructor(options) {
super();
const self = this;
this.port.onmessageerror = (e) => {
this.port.postMessage('Error: ' + JSON.stringify(e));
};
const mod = options.processorOptions.mod;
const memory = options.processorOptions.memory;
const importObject = {
env: { memory },
imports: {
imported_func: arg => console.log('thread: ' + arg),
create_thread,
glViewport: function(x, y, width, height) { },
glScissor: function(x, y, width, height) { },
glGetIntegerv: function(pname, data) { },
glGetFloatv: function(pname, data) { },
glGetString: function(name) { },
glDrawElements: function(mode, count, type, offset) { },
glDrawElementsInstanced: function(mode, count, type, indices, instancecount) { },
glVertexAttribDivisor: function(index, divisor) { },
glBindFramebuffer: function(target, framebuffer) { },
glFramebufferTexture2D: function(target, attachment, textarget, texture, level) { },
glGenFramebuffers: function(n, framebuffers) { },
glGenRenderbuffers: function(n, renderbuffers) { },
glBindRenderbuffer: function(target, renderbuffer) { },
glRenderbufferStorage: function(target, internalformat, width, height) { },
glFramebufferRenderbuffer: function(target, attachment, renderbuffertarget, renderbuffer) { },
glReadPixels: function(x, y, width, height, format, type, data) { },
glTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, type, pixels) { },
glEnable: function(cap) { },
glDisable: function(cap) { },
glColorMask: function(red, green, blue, alpha) { },
glClearColor: function(red, green, blue, alpha) { },
glDepthMask: function(flag) { },
glClearDepthf: function(depth) { },
glStencilMask: function(mask) { },
glClearStencil: function(s) { },
glClear: function(mask) { },
glBindBuffer: function(target, buffer) { },
glUseProgram: function(program) { },
glStencilMaskSeparate: function(face, mask) { },
glStencilOpSeparate: function(face, fail, zfail, zpass) { },
glStencilFuncSeparate: function(face, func, ref, mask) { },
glDepthFunc: function(func) { },
glCullFace: function(mode) { },
glBlendFuncSeparate: function(src_rgb, dst_rgb, src_alpha, dst_alpha) { },
glBlendEquationSeparate: function(mode_rgb, mode_alpha) { },
glGenBuffers: function(n, buffers) { },
glBufferData: function(target, size, data, usage) { },
glCreateProgram: function() { },
glAttachShader: function(program, shader) { },
glBindAttribLocation: function(program, index, name) { },
glLinkProgram: function(program) { },
glGetProgramiv: function(program, pname, params) { },
glGetProgramInfoLog: function(program) { },
glCreateShader: function(type) { },
glShaderSource: function(shader, count, source, length) { },
glCompileShader: function(shader) { },
glGetShaderiv: function(shader, pname, params) { },
glGetShaderInfoLog: function(shader) { },
glBufferSubData: function(target, offset, size, data) { },
glEnableVertexAttribArray: function(index) { },
glVertexAttribPointer: function(index, size, type, normalized, stride, offset) { },
glDisableVertexAttribArray: function(index) { },
glGetUniformLocation: function(program, name) { },
glUniform1i: function(location, v0) { },
glUniform2i: function(location, v0, v1) { },
glUniform3i: function(location, v0, v1, v2) { },
glUniform4i: function(location, v0, v1, v2, v3) { },
glUniform1iv: function(location, count, value) { },
glUniform2iv: function(location, count, value) { },
glUniform3iv: function(location, count, value) { },
glUniform4iv: function(location, count, value) { },
glUniform1f: function(location, v0) { },
glUniform2f: function(location, v0, v1) { },
glUniform3f: function(location, v0, v1, v2) { },
glUniform4f: function(location, v0, v1, v2, v3) { },
glUniform1fv: function(location, count, value) { },
glUniform2fv: function(location, count, value) { },
glUniform3fv: function(location, count, value) { },
glUniform4fv: function(location, count, value) { },
glUniformMatrix3fv: function(location, count, transpose, value) { },
glUniformMatrix4fv: function(location, count, transpose, value) { },
glTexParameterf: function(target, pname, param) { },
glActiveTexture: function(texture) { },
glBindTexture: function(target, texture) { },
glTexParameteri: function(target, pname, param) { },
glGetActiveUniform: function(program, index, bufSize, length, size, type, name) { },
glGenTextures: function(n, textures) { },
glTexImage2D: function(target, level, internalformat, width, height, border, format, type, data) { },
glPixelStorei: function(pname, param) { },
glCompressedTexImage2D: function(target, level, internalformat, width, height, border, imageSize, data) { },
glDrawBuffers: function(n, bufs) { },
glGenerateMipmap: function(target) { },
glFlush: function() { },
glDeleteBuffers: function(n, buffers) { },
glDeleteTextures: function(n, textures) { },
glDeleteFramebuffers: function(n, framebuffers) { },
glDeleteProgram: function(program) { },
glDeleteShader: function(shader) { },
js_fprintf: function(format) {
console.log(read_string(format));
},
js_fopen: function(filename) {
return 0;
},
js_ftell: function(stream) {
return 0;
},
js_fseek: function(stream, offset, origin) {
return 0;
},
js_fread: function(ptr, size, count, stream) {
return 0;
},
js_time: function() {
return window.performance.now();
},
js_pow: function(x) {
return Math.pow(x);
},
js_floor: function(x) {
return Math.floor(x);
},
js_sin: function(x) {
return Math.sin(x);
},
js_cos: function(x) {
return Math.cos(x);
},
js_tan: function(x) {
return Math.tan(x);
},
js_log: function(base, exponent) {
return Math.log(base, exponent);
},
js_exp: function(x) {
return Math.exp(x);
},
js_sqrt: function(x) {
return Math.sqrt(x);
},
js_eval: function(str) { }
}
};
WebAssembly.instantiate(mod, importObject).then((instance) => {
this.port.postMessage('Running audio thread');
self.audio_func = instance.exports.audio_func;
self.audio_pointer = instance.exports.malloc(16 * 1024);
this.port.postMessage('Audio pointer: ' + self.audio_pointer);
this.port.postMessage('Memory byteLength: ' + memory.buffer.byteLength);
self.audio_data = new Float32Array(
memory.buffer,
self.audio_pointer,
16 * 256
);
});
}
process(inputs, outputs, parameters) {
const output = outputs[0];
const data = output[0];
//for (let i = 0; i < data.length; ++i) {
// data[i] = Math.random() * 2 - 1;
//}
if (this.audio_func) {
let offset = 0;
for (;;) {
const length = Math.min(data.length - offset, this.audio_data.length);
this.audio_func(this.audio_pointer + offset, length);
for (let i = 0; i < length; ++i) {
data[offset + i] = this.audio_data[i];
}
if (offset + this.audio_data.length >= data.length) {
break;
}
offset += this.audio_data.length;
}
}
return true;
}
}
registerProcessor('audio-thread', AudioThread);

View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<body>
<canvas id="kanvas" width="800" height="600"></canvas>
<script src="start.js"></script>
</body>

View File

@ -0,0 +1,541 @@
// Includes snippets from https://surma.dev/things/c-to-webassembly/ and https://developer.mozilla.org/en-US/docs/WebAssembly/Using_the_JavaScript_API -->
let memory = null;
let heapu8 = null;
let heapu16 = null;
let heapu32 = null;
let heapi32 = null;
let heapf32 = null;
let mod = null;
let instance = null;
let audio_thread_started = false;
function create_thread(func) {
console.log('Creating thread');
const thread_starter = new Worker('thread_starter.js');
const arr = new Uint8Array(memory.buffer, func, 256);
let str = '';
for (let i = 0; arr[i] != 0; ++i) {
str += String.fromCharCode(arr[i]);
}
thread_starter.postMessage({ mod, memory, func: str });
}
async function start_audio_thread() {
const audioContext = new AudioContext();
await audioContext.audioWorklet.addModule('audio-thread.js');
const audioThreadNode = new AudioWorkletNode(audioContext, 'audio-thread', { processorOptions: { mod, memory }});
audioThreadNode.port.onmessage = (message) => {
console.log(message.data);
};
audioThreadNode.connect(audioContext.destination);
}
function read_string(ptr) {
let str = '';
for (let i = 0; heapu8[ptr + i] != 0; ++i) {
str += String.fromCharCode(heapu8[ptr + i]);
}
return str;
}
function write_string(ptr, str) {
for (let i = 0; i < str.length; ++i) {
heapu8[ptr + i] = str.charCodeAt(i);
}
heapu8[ptr + str.length] = 0;
}
async function init() {
let wasm_bytes = null;
await fetch("./ShaderTest.wasm").then(res => res.arrayBuffer()).then(buffer => wasm_bytes = new Uint8Array(buffer));
// Read memory size from wasm file
let memory_size = 0;
let i = 8;
while (i < wasm_bytes.length) {
function read_leb() {
let result = 0;
let shift = 0;
while (true) {
let byte = wasm_bytes[i++];
result |= (byte & 0x7f) << shift;
if ((byte & 0x80) == 0) return result;
shift += 7;
}
}
let type = read_leb()
let length = read_leb()
if (type == 6) {
read_leb(); // count
i++; // gtype
i++; // mutable
read_leb(); // opcode
memory_size = read_leb() / 65536 + 1;
break;
}
i += length;
}
memory = new WebAssembly.Memory({ initial: memory_size, maximum: memory_size, shared: true });
heapu8 = new Uint8Array(memory.buffer);
heapu16 = new Uint16Array(memory.buffer);
heapu32 = new Uint32Array(memory.buffer);
heapi32 = new Int32Array(memory.buffer);
heapf32 = new Float32Array(memory.buffer);
const kanvas = document.getElementById('kanvas');
const gl = kanvas.getContext('webgl2', { antialias: false, alpha: false });
// gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
gl.getExtension("EXT_color_buffer_float");
gl.getExtension("OES_texture_float_linear");
gl.getExtension("OES_texture_half_float_linear");
gl.getExtension("EXT_texture_filter_anisotropic");
let file_buffer = null;
let file_buffer_pos = 0;
let gl_programs = [null];
let gl_shaders = [null];
let gl_buffers = [null];
let gl_framebuffers = [null];
let gl_renderbuffers = [null];
let gl_textures = [null];
let gl_locations = [null];
const result = await WebAssembly.instantiate(
wasm_bytes, {
env: { memory },
imports: {
create_thread,
glViewport: function(x, y, width, height) {
gl.viewport(x, y, width, height);
},
glScissor: function(x, y, width, height) {
gl.scissor(x, y, width, height);
},
glGetIntegerv: function(pname, data) {
if (pname == 2) { // GL_MAJOR_VERSION
heapu32[data / 4] = 3;
}
else {
heapu32[data / 4] = gl.getParameter(pname);
}
},
glGetFloatv: function(pname, data) {
heapf32[data / 4] = gl.getParameter(pname);
},
glGetString: function(name) {
// return gl.getParameter(name);
},
glDrawElements: function(mode, count, type, offset) {
gl.drawElements(mode, count, type, offset);
},
glDrawElementsInstanced: function(mode, count, type, indices, instancecount) {
gl.drawElementsInstanced(mode, count, type, indices, instancecount);
},
glVertexAttribDivisor: function(index, divisor) {
gl.vertexAttribDivisor(index, divisor);
},
glBindFramebuffer: function(target, framebuffer) {
gl.bindFramebuffer(target, gl_framebuffers[framebuffer]);
},
glFramebufferTexture2D: function(target, attachment, textarget, texture, level) {
gl.framebufferTexture2D(target, attachment, textarget, gl_textures[texture], level);
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
console.log("Incomplete framebuffer");
}
},
glGenFramebuffers: function(n, framebuffers) {
for (let i = 0; i < n; ++i) {
gl_framebuffers.push(gl.createFramebuffer());
heapu32[framebuffers / 4 + i] = gl_framebuffers.length - 1;
}
},
glGenRenderbuffers: function(n, renderbuffers) {
for (let i = 0; i < n; ++i) {
gl_renderbuffers.push(gl.createRenderbuffer());
heapu32[renderbuffers / 4 + i] = gl_renderbuffers.length - 1;
}
},
glBindRenderbuffer: function(target, renderbuffer) {
gl.bindRenderbuffer(target, gl_renderbuffers[renderbuffer]);
},
glRenderbufferStorage: function(target, internalformat, width, height) {
gl.renderbufferStorage(target, internalformat, width, height)
},
glFramebufferRenderbuffer: function(target, attachment, renderbuffertarget, renderbuffer) {
gl.framebufferRenderbuffer(target, attachment, renderbuffertarget, gl_renderbuffers[renderbuffer]);
},
glReadPixels: function(x, y, width, height, format, type, data) {
let pixels = type == gl.FLOAT ? heapf32.subarray(data / 4) : heapu8.subarray(data);
gl.readPixels(x, y, width, height, format, type, pixels);
},
glTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, type, pixels) {
gl.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heapu8.subarray(pixels));
},
glEnable: function(cap) {
gl.enable(cap);
},
glDisable: function(cap) {
gl.disable(cap);
},
glColorMask: function(red, green, blue, alpha) {
gl.colorMask(red, green, blue, alpha);
},
glClearColor: function(red, green, blue, alpha) {
gl.clearColor(red, green, blue, alpha);
},
glDepthMask: function(flag) {
gl.depthMask(flag);
},
glClearDepthf: function(depth) {
gl.clearDepth(depth);
},
glStencilMask: function(mask) {
gl.stencilMask(mask);
},
glClearStencil: function(s) {
gl.clearStencil(s);
},
glClear: function(mask) {
gl.clear(mask);
},
glBindBuffer: function(target, buffer) {
gl.bindBuffer(target, gl_buffers[buffer]);
},
glUseProgram: function(program) {
gl.useProgram(gl_programs[program]);
},
glStencilMaskSeparate: function(face, mask) {
gl.stencilMaskSeparate(face, mask);
},
glStencilOpSeparate: function(face, fail, zfail, zpass) {
gl.stencilOpSeparate(face, fail, zfail, zpass);
},
glStencilFuncSeparate: function(face, func, ref, mask) {
gl.stencilFuncSeparate(face, func, ref, mask);
},
glDepthFunc: function(func) {
gl.depthFunc(func);
},
glCullFace: function(mode) {
gl.cullFace(mode);
},
glBlendFuncSeparate: function(src_rgb, dst_rgb, src_alpha, dst_alpha) {
gl.blendFuncSeparate(src_rgb, dst_rgb, src_alpha, dst_alpha);
},
glBlendEquationSeparate: function(mode_rgb, mode_alpha) {
gl.blendEquationSeparate(mode_rgb, mode_alpha);
},
glGenBuffers: function(n, buffers) {
for (let i = 0; i < n; ++i) {
gl_buffers.push(gl.createBuffer());
heapu32[buffers / 4 + i] = gl_buffers.length - 1;
}
},
glBufferData: function(target, size, data, usage) {
gl.bufferData(target, heapu8.subarray(data, data + Number(size)), usage);
},
glCreateProgram: function() {
gl_programs.push(gl.createProgram());
return gl_programs.length - 1;
},
glAttachShader: function(program, shader) {
gl.attachShader(gl_programs[program], gl_shaders[shader]);
},
glBindAttribLocation: function(program, index, name) {
gl.bindAttribLocation(gl_programs[program], index, read_string(name));
},
glLinkProgram: function(program) {
gl.linkProgram(gl_programs[program]);
},
glGetProgramiv: function(program, pname, params) {
heapu32[params / 4] = gl.getProgramParameter(gl_programs[program], pname);
},
glGetProgramInfoLog: function(program) {
console.log(gl.getProgramInfoLog(gl_programs[program]));
},
glCreateShader: function(type) {
gl_shaders.push(gl.createShader(type));
return gl_shaders.length - 1;
},
glShaderSource: function(shader, count, source, length) {
gl.shaderSource(gl_shaders[shader], read_string(heapu32[source / 4]));
},
glCompileShader: function(shader) {
gl.compileShader(gl_shaders[shader]);
},
glGetShaderiv: function(shader, pname, params) {
heapu32[params / 4] = gl.getShaderParameter(gl_shaders[shader], pname);
},
glGetShaderInfoLog: function(shader) {
console.log(gl.getShaderInfoLog(gl_shaders[shader]));
},
glBufferSubData: function(target, offset, size, data) {
gl.bufferSubData(target, Number(offset), heapu8.subarray(data, data + Number(size)), 0);
},
glEnableVertexAttribArray: function(index) {
gl.enableVertexAttribArray(index);
},
glVertexAttribPointer: function(index, size, type, normalized, stride, offset) {
gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
},
glDisableVertexAttribArray: function(index) {
gl.disableVertexAttribArray(index);
},
glGetUniformLocation: function(program, name) {
gl_locations.push(gl.getUniformLocation(gl_programs[program], read_string(name)));
return gl_locations.length - 1;
},
glUniform1i: function(location, v0) {
gl.uniform1i(gl_locations[location], v0);
},
glUniform2i: function(location, v0, v1) {
gl.uniform2i(gl_locations[location], v0, v1);
},
glUniform3i: function(location, v0, v1, v2) {
gl.uniform3i(gl_locations[location], v0, v1, v2);
},
glUniform4i: function(location, v0, v1, v2, v3) {
gl.uniform4i(gl_locations[location], v0, v1, v2, v3);
},
glUniform1iv: function(location, count, value) {
gl.uniform1iv(gl_locations[location], count, heapi32.subarray(value / 4));
},
glUniform2iv: function(location, count, value) {
gl.uniform2iv(gl_locations[location], count, heapi32.subarray(value / 4));
},
glUniform3iv: function(location, count, value) {
gl.uniform3iv(gl_locations[location], count, heapi32.subarray(value / 4));
},
glUniform4iv: function(location, count, value) {
gl.uniform4iv(gl_locations[location], count, heapi32.subarray(value / 4));
},
glUniform1f: function(location, v0) {
gl.uniform1f(gl_locations[location], v0);
},
glUniform2f: function(location, v0, v1) {
gl.uniform2f(gl_locations[location], v0, v1);
},
glUniform3f: function(location, v0, v1, v2) {
gl.uniform3f(gl_locations[location], v0, v1, v2);
},
glUniform4f: function(location, v0, v1, v2, v3) {
gl.uniform4f(gl_locations[location], v0, v1, v2, v3);
},
glUniform1fv: function(location, count, value) {
var f32 = new Float32Array(memory.buffer, value, count);
gl.uniform1fv(gl_locations[location], f32);
},
glUniform2fv: function(location, count, value) {
var f32 = new Float32Array(memory.buffer, value, count * 2);
gl.uniform2fv(gl_locations[location], f32);
},
glUniform3fv: function(location, count, value) {
var f32 = new Float32Array(memory.buffer, value, count * 3);
gl.uniform3fv(gl_locations[location], f32);
},
glUniform4fv: function(location, count, value) {
var f32 = new Float32Array(memory.buffer, value, count * 4);
gl.uniform4fv(gl_locations[location], f32);
},
glUniformMatrix3fv: function(location, count, transpose, value) {
var f32 = new Float32Array(memory.buffer, value, 3 * 3);
gl.uniformMatrix3fv(gl_locations[location], transpose, f32);
},
glUniformMatrix4fv: function(location, count, transpose, value) {
var f32 = new Float32Array(memory.buffer, value, 4 * 4);
gl.uniformMatrix4fv(gl_locations[location], transpose, f32);
},
glTexParameterf: function(target, pname, param) {
gl.texParameterf(target, pname, param);
},
glActiveTexture: function(texture) {
gl.activeTexture(texture);
},
glBindTexture: function(target, texture) {
gl.bindTexture(target, gl_textures[texture]);
},
glTexParameteri: function(target, pname, param) {
gl.texParameteri(target, pname, param);
},
glGetActiveUniform: function(program, index, bufSize, length, size, type, name) {
let u = gl.getActiveUniform(gl_programs[program], index);
heapu32[size / 4] = u.size;
heapu32[type / 4] = u.type;
write_string(name, u.name);
},
glGenTextures: function(n, textures) {
for (let i = 0; i < n; ++i) {
gl_textures.push(gl.createTexture());
heapu32[textures / 4 + i] = gl_textures.length - 1;
}
},
glTexImage2D: function(target, level, internalformat, width, height, border, format, type, data) {
let pixels = type == gl.FLOAT ? heapf32.subarray(data / 4) :
type == gl.UNSIGNED_INT ? heapu32.subarray(data / 4) :
type == gl.UNSIGNED_SHORT ? heapu16.subarray(data / 2) :
type == gl.HALF_FLOAT ? heapu16.subarray(data / 2) : heapu8.subarray(data);
gl.texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
},
glPixelStorei: function(pname, param) {
gl.pixelStorei(pname, param);
},
glCompressedTexImage2D: function(target, level, internalformat, width, height, border, imageSize, data) {
gl.compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, heapu8.subarray(data));
},
glDrawBuffers: function(n, bufs) {
let ar = [];
for (let i = 0; i < n; ++i) {
ar.push(gl.COLOR_ATTACHMENT0 + i);
}
gl.drawBuffers(ar);
},
glGenerateMipmap: function(target) {
gl.generateMipmap(target);
},
glFlush: function() {
gl.flush();
},
glDeleteBuffers: function(n, buffers) {
for (let i = 0; i < n; ++i) {
gl.deleteBuffer(gl_buffers[heapu32[buffers / 4 + i]]);
}
},
glDeleteTextures: function(n, textures) {
for (let i = 0; i < n; ++i) {
gl.deleteTexture(gl_textures[heapu32[textures / 4 + i]]);
}
},
glDeleteFramebuffers: function(n, framebuffers) {
for (let i = 0; i < n; ++i) {
gl.deleteFramebuffer(gl_framebuffers[heapu32[framebuffers / 4 + i]]);
}
},
glDeleteProgram: function(program) {
gl.deleteProgram(gl_programs[program]);
},
glDeleteShader: function(shader) {
gl.deleteShader(gl_shaders[shader]);
},
js_fprintf: function(format) {
console.log(read_string(format));
},
js_fopen: function(filename) {
const req = new XMLHttpRequest();
req.open("GET", read_string(filename), false);
req.overrideMimeType("text/plain; charset=x-user-defined");
req.send();
let str = req.response;
file_buffer_pos = 0;
file_buffer = new ArrayBuffer(str.length);
let buf_view = new Uint8Array(file_buffer);
for (let i = 0; i < str.length; ++i) {
buf_view[i] = str.charCodeAt(i);
}
return 1;
},
js_ftell: function(stream) {
return file_buffer_pos;
},
js_fseek: function(stream, offset, origin) {
file_buffer_pos = offset;
if (origin == 1) file_buffer_pos += file_buffer.byteLength; // SEEK_END
return 0;
},
js_fread: function(ptr, size, count, stream) {
let buf_view = new Uint8Array(file_buffer);
for (let i = 0; i < count; ++i) {
heapu8[ptr + i] = buf_view[file_buffer_pos++];
}
return count;
},
js_time: function() {
return window.performance.now();
},
js_pow: function(x) {
return Math.pow(x);
},
js_floor: function(x) {
return Math.floor(x);
},
js_sin: function(x) {
return Math.sin(x);
},
js_cos: function(x) {
return Math.cos(x);
},
js_tan: function(x) {
return Math.tan(x);
},
js_log: function(base, exponent) {
return Math.log(base, exponent);
},
js_exp: function(x) {
return Math.exp(x);
},
js_sqrt: function(x) {
return Math.sqrt(x);
},
js_eval: function(str) {
(1, eval)(read_string(str));
}
}
}
);
mod = result.module;
instance = result.instance;
instance.exports._start();
function update() {
instance.exports._update();
window.requestAnimationFrame(update);
}
window.requestAnimationFrame(update);
kanvas.addEventListener('click', (event) => {
if (!audio_thread_started) {
start_audio_thread();
audio_thread_started = true;
}
});
kanvas.addEventListener('contextmenu', (event) => {
event.preventDefault();
});
kanvas.addEventListener('mousedown', (event) => {
instance.exports._mousedown(event.button, event.clientX, event.clientY);
});
kanvas.addEventListener('mouseup', (event) => {
instance.exports._mouseup(event.button, event.clientX, event.clientY);
});
kanvas.addEventListener('mousemove', (event) => {
instance.exports._mousemove(event.clientX, event.clientY);
});
kanvas.addEventListener('wheel', (event) => {
instance.exports._wheel(event.deltaY);
});
kanvas.addEventListener('keydown', (event) => {
if (event.repeat) {
event.preventDefault();
return;
}
instance.exports._keydown(event.keyCode);
});
kanvas.addEventListener('keyup', (event) => {
if (event.repeat) {
event.preventDefault();
return;
}
instance.exports._keyup(event.keyCode);
});
}
init();

View File

@ -0,0 +1,24 @@
function create_thread(func) {
}
onmessage = function(e) {
console.log('onmessage');
const mod = e.data.mod;
const memory = e.data.memory;
const func = e.data.func;
const importObject = {
env: { memory },
imports: {
imported_func: arg => console.log('thread: ' + arg),
create_thread
}
};
WebAssembly.instantiate(mod, importObject).then((instance) => {
console.log('Running thread');
instance.exports[func]();
});
};

View File

@ -0,0 +1,246 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef int GLint;
typedef unsigned GLuint;
typedef size_t GLsizei;
typedef float GLfloat;
typedef int GLenum;
typedef bool GLboolean;
typedef uint8_t GLubyte;
typedef float GLclampf;
typedef int GLbitfield;
typedef uint64_t GLsizeiptr;
typedef uint64_t GLintptr;
typedef char GLchar;
// custom
#define GL_MAJOR_VERSION 2
#define GL_EXTENSIONS 0
#define GL_TRUE 1
#define GL_FALSE 0
// not supported
#define GL_INFO_LOG_LENGTH 0xABCD
// regular WebGL defines
#define GL_CLAMP_TO_EDGE 0x812F
#define GL_INT_VEC2 0x8B53
#define GL_INT_VEC3 0x8B54
#define GL_INT_VEC4 0x8B55
#define GL_FLOAT_VEC2 0x8B50
#define GL_FLOAT_VEC3 0x8B51
#define GL_FLOAT_VEC4 0x8B52
#define GL_FLOAT_MAT4 0x8B5C
#define GL_UNSIGNED_SHORT 0x1403
#define GL_UNSIGNED_INT 0x1405
#define GL_TRIANGLES 0x0004
#define GL_SCISSOR_TEST 15
#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE_WRAP_S 0x2802
#define GL_TEXTURE_WRAP_T 0x2803
#define GL_REPEAT 0x2901
#define GL_DEPTH_TEST 0x0B71
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_DEPTH_BUFFER_BIT 0x00000100
#define GL_STENCIL_BUFFER_BIT 0x00000400
#define GL_TEXTURE_2D 0x0DE1
#define GL_TEXTURE_MIN_FILTER 0x2801
#define GL_TEXTURE_MAG_FILTER 0x2800
#define GL_NEAREST 0x2600
#define GL_LINEAR 0x2601
#define GL_NEAREST_MIPMAP_NEAREST 0x2700
#define GL_LINEAR_MIPMAP_NEAREST 0x2701
#define GL_NEAREST_MIPMAP_LINEAR 0x2702
#define GL_LINEAR_MIPMAP_LINEAR 0x2703
#define GL_LEQUAL 0x0203
#define GL_NONE 0
#define GL_TEXTURE_CUBE_MAP 0x8513
#define GL_TEXTURE_MIN_LOD 0x813A
#define GL_TEXTURE_MAX_LOD 0x813B
#define GL_FRAMEBUFFER 0x8D40
#define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_DEPTH_ATTACHMENT 0x8D00
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
#define GL_ANY_SAMPLES_PASSED 0x8C2F
#define GL_QUERY_RESULT_AVAILABLE 0x8867
#define GL_QUERY_RESULT 0x8866
#define GL_FRONT 0x0404
#define GL_BACK 0x0405
#define GL_ALWAYS 0x0207
#define GL_EQUAL 0x0202
#define GL_GREATER 0x0204
#define GL_GEQUAL 0x0206
#define GL_LESS 0x0201
#define GL_NEVER 0x0200
#define GL_NOTEQUAL 0x0205
#define GL_STATIC_DRAW 0x88E4
#define GL_DYNAMIC_DRAW 0x88E8
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#define GL_DECR 0x1E03
#define GL_DECR_WRAP 0x8508
#define GL_INCR 0x1E02
#define GL_INCR_WRAP 0x8507
#define GL_INVERT 0x150A
#define GL_KEEP 0x1E00
#define GL_REPLACE 0x1E01
#define GL_ZERO 0
#define GL_ONE 1
#define GL_SRC_ALPHA 0x0302
#define GL_DST_ALPHA 0x0304
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
#define GL_ONE_MINUS_DST_ALPHA 0x0305
#define GL_SRC_COLOR 0x0300
#define GL_DST_COLOR 0x0306
#define GL_ONE_MINUS_SRC_COLOR 0x0301
#define GL_ONE_MINUS_DST_COLOR 0x0307
#define GL_FUNC_ADD 0x8006
#define GL_FUNC_SUBTRACT 0x800A
#define GL_FUNC_REVERSE_SUBTRACT 0x800B
#define GL_MIN 0x8007
#define GL_MAX 0x8008
#define GL_VERTEX_SHADER 0x8B31
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_COMPILE_STATUS 0x8B81
#define GL_LINK_STATUS 0x8B82
#define GL_STENCIL_TEST 0x0B90
#define GL_CULL_FACE 0x0B44
#define GL_BLEND 0x0BE2
#define GL_FLOAT 0x1406
#define GL_ACTIVE_UNIFORMS 0x8B86
#define GL_DEPTH24_STENCIL8_OES 0x88F0
#define GL_DEPTH_COMPONENT 0x1902
#define GL_DEPTH_COMPONENT16 0x81A5
#define GL_STENCIL_ATTACHMENT 0x8D20
#define GL_RENDERBUFFER 0x8D41
#define GL_RGBA 0x1908
#define GL_LUMINANCE 0x1909
#define GL_R8 0x8229
#define GL_RED 0x1903
#define GL_UNSIGNED_BYTE 0x1401
#define GL_RGB 0x1907
#define GL_UNPACK_ALIGNMENT 0x0CF5
#define GL_ARRAY_BUFFER 0x8892
#define GL_BYTE 0x1400
#define GL_SHORT 0x1402
#define GL_INT 0x1404
#define GL_CONSTANT_COLOR 0x8001
#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
#define GL_MAX_VERTEX_ATTRIBS 0x8869
__attribute__((import_module("imports"), import_name("glUniform1i"))) void glUniform1i(GLint location, GLint v0);
__attribute__((import_module("imports"), import_name("glUniform2i"))) void glUniform2i(GLint location, GLint v0, GLint v1);
__attribute__((import_module("imports"), import_name("glUniform3i"))) void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2);
__attribute__((import_module("imports"), import_name("glUniform4i"))) void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
__attribute__((import_module("imports"), import_name("glUniform1iv"))) void glUniform1iv(GLint location, GLsizei count, const GLint *value);
__attribute__((import_module("imports"), import_name("glUniform2iv"))) void glUniform2iv(GLint location, GLsizei count, const GLint *value);
__attribute__((import_module("imports"), import_name("glUniform3iv"))) void glUniform3iv(GLint location, GLsizei count, const GLint *value);
__attribute__((import_module("imports"), import_name("glUniform4iv"))) void glUniform4iv(GLint location, GLsizei count, const GLint *value);
__attribute__((import_module("imports"), import_name("glUniform1f"))) void glUniform1f(GLint location, GLfloat v0);
__attribute__((import_module("imports"), import_name("glUniform2f"))) void glUniform2f(GLint location, GLfloat v0, GLfloat v1);
__attribute__((import_module("imports"), import_name("glUniform3f"))) void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
__attribute__((import_module("imports"), import_name("glUniform4f"))) void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
__attribute__((import_module("imports"), import_name("glUniform1fv"))) void glUniform1fv(GLint location, GLsizei count, const GLfloat *value);
__attribute__((import_module("imports"), import_name("glUniform2fv"))) void glUniform2fv(GLint location, GLsizei count, const GLfloat *value);
__attribute__((import_module("imports"), import_name("glUniform3fv"))) void glUniform3fv(GLint location, GLsizei count, const GLfloat *value);
__attribute__((import_module("imports"), import_name("glUniform4fv"))) void glUniform4fv(GLint location, GLsizei count, const GLfloat *value);
__attribute__((import_module("imports"), import_name("glUniformMatrix3fv"))) void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose,
const GLfloat *value);
__attribute__((import_module("imports"), import_name("glUniformMatrix4fv"))) void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose,
const GLfloat *value);
__attribute__((import_module("imports"), import_name("glViewport"))) void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
__attribute__((import_module("imports"), import_name("glGetIntegerv"))) void glGetIntegerv(GLenum pname, GLint *data);
__attribute__((import_module("imports"), import_name("glGetString"))) const GLubyte *glGetString(GLenum name);
__attribute__((import_module("imports"), import_name("glDrawElements"))) void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);
__attribute__((import_module("imports"), import_name("glEnable"))) void glEnable(GLenum cap);
__attribute__((import_module("imports"), import_name("glDisable"))) void glDisable(GLenum cap);
__attribute__((import_module("imports"), import_name("glScissor"))) void glScissor(GLint x, GLint y, GLsizei width, GLsizei height);
__attribute__((import_module("imports"), import_name("glColorMask"))) void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
__attribute__((import_module("imports"), import_name("glClearColor"))) void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
__attribute__((import_module("imports"), import_name("glDepthMask"))) void glDepthMask(GLboolean flag);
__attribute__((import_module("imports"), import_name("glClearDepthf"))) void glClearDepthf(GLclampf depth);
__attribute__((import_module("imports"), import_name("glStencilMask"))) void glStencilMask(GLuint mask);
__attribute__((import_module("imports"), import_name("glClearStencil"))) void glClearStencil(GLint s);
__attribute__((import_module("imports"), import_name("glClear"))) void glClear(GLbitfield mask);
__attribute__((import_module("imports"), import_name("glTexParameteri"))) void glTexParameteri(GLenum target, GLenum pname, GLint param);
__attribute__((import_module("imports"), import_name("glActiveTexture"))) void glActiveTexture(GLenum texture);
__attribute__((import_module("imports"), import_name("glGetFloatv"))) void glGetFloatv(GLenum pname, GLfloat *params);
__attribute__((import_module("imports"), import_name("glTexParameterf"))) void glTexParameterf(GLenum target, GLenum pname, GLfloat param);
__attribute__((import_module("imports"), import_name("glBindFramebuffer"))) void glBindFramebuffer(GLenum target, GLuint framebuffer);
__attribute__((import_module("imports"), import_name("glFramebufferTexture2D"))) void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget,
GLuint texture, GLint level);
__attribute__((import_module("imports"), import_name("glGenQueries"))) void glGenQueries(GLsizei n, GLuint *ids);
__attribute__((import_module("imports"), import_name("glDeleteQueries"))) void glDeleteQueries(GLsizei n, const GLuint *ids);
__attribute__((import_module("imports"), import_name("glBeginQuery"))) void glBeginQuery(GLenum target, GLuint id);
__attribute__((import_module("imports"), import_name("glEndQuery"))) void glEndQuery(GLenum target);
__attribute__((import_module("imports"), import_name("glGetQueryObjectuiv"))) void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params);
__attribute__((import_module("imports"), import_name("glDrawArrays"))) void glDrawArrays(GLenum mode, GLint first, GLsizei count);
__attribute__((import_module("imports"), import_name("glFlush"))) void glFlush(void);
__attribute__((import_module("imports"), import_name("glStencilFuncSeparate"))) void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
__attribute__((import_module("imports"), import_name("glGenBuffers"))) void glGenBuffers(GLsizei n, GLuint *buffers);
__attribute__((import_module("imports"), import_name("glDeleteBuffers"))) void glDeleteBuffers(GLsizei n, const GLuint *buffers);
__attribute__((import_module("imports"), import_name("glBindBuffer"))) void glBindBuffer(GLenum target, GLuint buffer);
__attribute__((import_module("imports"), import_name("glBufferData"))) void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage);
__attribute__((import_module("imports"), import_name("glCreateProgram"))) GLuint glCreateProgram(void);
__attribute__((import_module("imports"), import_name("glDeleteProgram"))) void glDeleteProgram(GLuint program);
__attribute__((import_module("imports"), import_name("glCreateShader"))) GLuint glCreateShader(GLenum shaderType);
__attribute__((import_module("imports"), import_name("glShaderSource"))) void glShaderSource(GLuint shader, GLsizei count, const GLchar **string,
const GLint *length);
__attribute__((import_module("imports"), import_name("glCompileShader"))) void glCompileShader(GLuint shader);
__attribute__((import_module("imports"), import_name("glGetShaderiv"))) void glGetShaderiv(GLuint shader, GLenum pname, GLint *params);
__attribute__((import_module("imports"), import_name("glGetShaderInfoLog"))) void glGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length,
GLchar *infoLog);
__attribute__((import_module("imports"), import_name("glAttachShader"))) void glAttachShader(GLuint program, GLuint shader);
__attribute__((import_module("imports"), import_name("glBindAttribLocation"))) void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name);
__attribute__((import_module("imports"), import_name("glLinkProgram"))) void glLinkProgram(GLuint program);
__attribute__((import_module("imports"), import_name("glGetProgramiv"))) void glGetProgramiv(GLuint program, GLenum pname, GLint *params);
__attribute__((import_module("imports"), import_name("glGetProgramInfoLog"))) void glGetProgramInfoLog(GLuint program, GLsizei maxLength, GLsizei *length,
GLchar *infoLog);
__attribute__((import_module("imports"), import_name("glUseProgram"))) void glUseProgram(GLuint program);
__attribute__((import_module("imports"), import_name("glStencilMaskSeparate"))) void glStencilMaskSeparate(GLenum face, GLuint mask);
__attribute__((import_module("imports"), import_name("glStencilOpSeparate"))) void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
__attribute__((import_module("imports"), import_name("glDepthFunc"))) void glDepthFunc(GLenum func);
__attribute__((import_module("imports"), import_name("glCullFace"))) void glCullFace(GLenum mode);
__attribute__((import_module("imports"), import_name("glBlendFuncSeparate"))) void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha,
GLenum dstAlpha);
__attribute__((import_module("imports"), import_name("glBlendEquationSeparate"))) void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
__attribute__((import_module("imports"), import_name("glGetUniformLocation"))) GLint glGetUniformLocation(GLuint program, const GLchar *name);
__attribute__((import_module("imports"), import_name("glGetActiveUniform"))) void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize,
GLsizei *length, GLint *size, GLenum *type, GLchar *name);
__attribute__((import_module("imports"), import_name("glGenTextures"))) void glGenTextures(GLsizei n, GLuint *textures);
__attribute__((import_module("imports"), import_name("glDeleteTextures"))) void glDeleteTextures(GLsizei n, const GLuint *textures);
__attribute__((import_module("imports"), import_name("glBindTexture"))) void glBindTexture(GLenum target, GLuint texture);
__attribute__((import_module("imports"), import_name("glTexImage2D"))) void
glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *data);
__attribute__((import_module("imports"), import_name("glGenRenderbuffers"))) void glGenRenderbuffers(GLsizei n, GLuint *renderbuffers);
__attribute__((import_module("imports"), import_name("glBindRenderbuffer"))) void glBindRenderbuffer(GLenum target, GLuint renderbuffer);
__attribute__((import_module("imports"), import_name("glRenderbufferStorage"))) void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width,
GLsizei height);
__attribute__((import_module("imports"), import_name("glGenFramebuffers"))) void glGenFramebuffers(GLsizei n, GLuint *ids);
__attribute__((import_module("imports"), import_name("glDeleteFramebuffers"))) void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers);
__attribute__((import_module("imports"), import_name("glReadPixels"))) void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
GLenum type, void *data);
__attribute__((import_module("imports"), import_name("glFramebufferRenderbuffer"))) void
glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
__attribute__((import_module("imports"), import_name("glGenerateMipmap"))) void glGenerateMipmap(GLenum target);
__attribute__((import_module("imports"), import_name("glDeleteShader"))) void glDeleteShader(GLuint shader);
__attribute__((import_module("imports"), import_name("glPixelStorei"))) void glPixelStorei(GLenum pname, GLint param);
__attribute__((import_module("imports"), import_name("glCompressedTexImage2D"))) void
glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
__attribute__((import_module("imports"), import_name("glTexSubImage2D"))) void
glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
__attribute__((import_module("imports"), import_name("glBufferSubData"))) void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size,
const void *data);
__attribute__((import_module("imports"), import_name("glEnableVertexAttribArray"))) void glEnableVertexAttribArray(GLuint index);
__attribute__((import_module("imports"), import_name("glDisableVertexAttribArray"))) void glDisableVertexAttribArray(GLuint index);
__attribute__((import_module("imports"), import_name("glVertexAttribPointer"))) void
glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
__attribute__((import_module("imports"), import_name("glBlendColor"))) void glBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
__attribute__((import_module("imports"), import_name("glDrawBuffers"))) void glDrawBuffers(GLsizei n, const GLenum *bufs);
__attribute__((import_module("imports"), import_name("glDrawElementsInstanced"))) void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
const void *indices, GLsizei instancecount);
__attribute__((import_module("imports"), import_name("glVertexAttribDivisor"))) void glVertexAttribDivisor(GLuint index, GLuint divisor);

View File

@ -0,0 +1,13 @@
#pragma once
#define KINC_ATOMIC_COMPARE_EXCHANGE(pointer, oldValue, newValue)
#define KINC_ATOMIC_COMPARE_EXCHANGE_POINTER(pointer, oldValue, newValue)
#define KINC_ATOMIC_INCREMENT(pointer)
#define KINC_ATOMIC_DECREMENT(pointer)
#define KINC_ATOMIC_EXCHANGE_32(pointer, value)
#define KINC_ATOMIC_EXCHANGE_FLOAT(pointer, value)

View File

@ -0,0 +1,18 @@
#include <kinc/audio2/audio.h>
#include <stdlib.h>
static kinc_a2_buffer_t a2_buffer;
void kinc_a2_init() {
kinc_a2_internal_init();
}
void kinc_a2_update() {}
void kinc_a2_shutdown() {}
static uint32_t samples_per_second = 44100;
uint32_t kinc_a2_samples_per_second(void) {
return samples_per_second;
}

View File

@ -0,0 +1,47 @@
#include <kinc/display.h>
void kinc_display_init(void) {}
int kinc_primary_display(void) {
return 0;
}
int kinc_count_displays(void) {
return 1;
}
bool kinc_display_available(int display_index) {
return false;
}
const char *kinc_display_name(int display_index) {
return "Browser";
}
kinc_display_mode_t kinc_display_current_mode(int display_index) {
kinc_display_mode_t mode;
mode.x = 0;
mode.y = 0;
mode.width = 800;
mode.height = 600;
mode.pixels_per_inch = 96;
mode.frequency = 60;
mode.bits_per_pixel = 32;
return mode;
}
int kinc_display_count_available_modes(int display_index) {
return 1;
}
kinc_display_mode_t kinc_display_available_mode(int display_index, int mode_index) {
kinc_display_mode_t mode;
mode.x = 0;
mode.y = 0;
mode.width = 800;
mode.height = 600;
mode.pixels_per_inch = 96;
mode.frequency = 60;
mode.bits_per_pixel = 32;
return mode;
}

View File

@ -0,0 +1,15 @@
#include <kinc/threads/event.h>
void kinc_event_init(kinc_event_t *event, bool auto_reset) {}
void kinc_event_destroy(kinc_event_t *event) {}
void kinc_event_signal(kinc_event_t *event) {}
void kinc_event_wait(kinc_event_t *event) {}
bool kinc_event_try_to_wait(kinc_event_t *event, double seconds) {
return false;
}
void kinc_event_reset(kinc_event_t *event) {}

View File

@ -0,0 +1,13 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int nothing;
} kinc_event_impl_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,11 @@
#include "audio.c.h"
#include "display.c.h"
#include "event.c.h"
#include "mouse.c.h"
#include "mutex.c.h"
#include "semaphore.c.h"
#include "system.c.h"
#include "thread.c.h"
#include "threadlocal.c.h"
#include "video.c.h"
#include "window.c.h"

View File

@ -0,0 +1,17 @@
#include <kinc/input/mouse.h>
void kinc_internal_mouse_lock(int window) {}
void kinc_internal_mouse_unlock(void) {}
bool kinc_mouse_can_lock(void) {
return false;
}
void kinc_mouse_show() {}
void kinc_mouse_hide() {}
void kinc_mouse_set_position(int window, int x, int y) {}
void kinc_mouse_get_position(int window, int *x, int *y) {}

View File

@ -0,0 +1,23 @@
#include <kinc/threads/mutex.h>
void kinc_mutex_init(kinc_mutex_t *mutex) {}
void kinc_mutex_destroy(kinc_mutex_t *mutex) {}
bool kinc_mutex_try_to_lock(kinc_mutex_t *mutex) {
return false;
}
void kinc_mutex_lock(kinc_mutex_t *mutex) {}
void kinc_mutex_unlock(kinc_mutex_t *mutex) {}
bool kinc_uber_mutex_init(kinc_uber_mutex_t *mutex, const char *name) {
return false;
}
void kinc_uber_mutex_destroy(kinc_uber_mutex_t *mutex) {}
void kinc_uber_mutex_lock(kinc_uber_mutex_t *mutex) {}
void kinc_uber_mutex_unlock(kinc_uber_mutex_t *mutex) {}

View File

@ -0,0 +1,17 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int nothing;
} kinc_mutex_impl_t;
typedef struct {
int nothing;
} kinc_uber_mutex_impl_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,13 @@
#include <kinc/threads/semaphore.h>
void kinc_semaphore_init(kinc_semaphore_t *semaphore, int current, int max) {}
void kinc_semaphore_destroy(kinc_semaphore_t *semaphore) {}
void kinc_semaphore_release(kinc_semaphore_t *semaphore, int count) {}
void kinc_semaphore_acquire(kinc_semaphore_t *semaphore) {}
bool kinc_semaphore_try_to_acquire(kinc_semaphore_t *semaphore, double seconds) {
return false;
}

View File

@ -0,0 +1,13 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int nothing;
} kinc_semaphore_impl_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,108 @@
#include <kinc/audio2/audio.h>
#include <kinc/graphics4/graphics.h>
#include <kinc/input/keyboard.h>
#include <kinc/input/mouse.h>
#include <kinc/log.h>
#include <kinc/system.h>
#include <kinc/window.h>
#include <stdio.h>
#include <stdlib.h>
__attribute__((import_module("imports"), import_name("js_time"))) int js_time();
extern int kinc_internal_window_width;
extern int kinc_internal_window_height;
#ifdef KINC_KONG
void kong_init(void);
#endif
int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) {
kinc_window_options_t defaultWin;
if (win == NULL) {
kinc_window_options_set_defaults(&defaultWin);
win = &defaultWin;
}
kinc_framebuffer_options_t defaultFrame;
if (frame == NULL) {
kinc_framebuffer_options_set_defaults(&defaultFrame);
frame = &defaultFrame;
}
win->width = width;
win->height = height;
kinc_internal_window_width = width;
kinc_internal_window_height = height;
kinc_g4_internal_init();
kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true);
#ifdef KINC_KONG
kong_init();
#endif
return 0;
}
bool kinc_internal_handle_messages() {
return true;
}
void kinc_set_keep_screen_on(bool on) {}
double kinc_frequency(void) {
return 1000.0;
}
kinc_ticks_t kinc_timestamp(void) {
return (kinc_ticks_t)(js_time());
}
double kinc_time(void) {
return js_time() / 1000.0;
}
int kinc_cpu_cores(void) {
return 4;
}
int kinc_hardware_threads(void) {
return 4;
}
void kinc_internal_shutdown(void) {}
extern int kickstart(int argc, char **argv);
__attribute__((export_name("_start"))) void _start(void) {
kickstart(0, NULL);
}
__attribute__((export_name("_update"))) void _update(void) {
kinc_internal_update_callback();
kinc_a2_update();
}
__attribute__((export_name("_mousedown"))) void _mousedown(int button, int x, int y) {
kinc_internal_mouse_trigger_press(0, button, x, y);
}
__attribute__((export_name("_mouseup"))) void _mouseup(int button, int x, int y) {
kinc_internal_mouse_trigger_release(0, button, x, y);
}
__attribute__((export_name("_mousemove"))) void _mousemove(int x, int y) {
kinc_internal_mouse_trigger_move(0, x, y);
}
__attribute__((export_name("_wheel"))) void _wheel(int delta) {
kinc_internal_mouse_trigger_scroll(0, delta);
}
__attribute__((export_name("_keydown"))) void _keydown(int key) {
kinc_internal_keyboard_trigger_key_down(key);
}
__attribute__((export_name("_keyup"))) void _keyup(int key) {
kinc_internal_keyboard_trigger_key_up(key);
}

View File

@ -0,0 +1,15 @@
#include <kinc/threads/thread.h>
void kinc_thread_init(kinc_thread_t *t, void (*thread)(void *param), void *param) {}
void kinc_thread_wait_and_destroy(kinc_thread_t *thread) {}
bool kinc_thread_try_to_destroy(kinc_thread_t *thread) {
return false;
}
void kinc_threads_init() {}
void kinc_threads_quit() {}
void kinc_thread_sleep(int milliseconds) {}

View File

@ -0,0 +1,13 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int nothing;
} kinc_thread_impl_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,13 @@
#include <kinc/threads/threadlocal.h>
#include <string.h>
void kinc_thread_local_init(kinc_thread_local_t *local) {}
void kinc_thread_local_destroy(kinc_thread_local_t *local) {}
void *kinc_thread_local_get(kinc_thread_local_t *local) {
return NULL;
}
void kinc_thread_local_set(kinc_thread_local_t *local, void *data) {}

View File

@ -0,0 +1,13 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int nothing;
} kinc_thread_local_impl_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,57 @@
#include <kinc/video.h>
void kinc_video_init(kinc_video_t *video, const char *filename) {}
void kinc_video_destroy(kinc_video_t *video) {}
void kinc_video_play(kinc_video_t *video, bool loop) {}
void kinc_video_pause(kinc_video_t *video) {}
void kinc_video_stop(kinc_video_t *video) {}
int kinc_video_width(kinc_video_t *video) {
return 256;
}
int kinc_video_height(kinc_video_t *video) {
return 256;
}
kinc_g4_texture_t *kinc_video_current_image(kinc_video_t *video) {
return NULL;
}
double kinc_video_duration(kinc_video_t *video) {
return 0.0;
}
double kinc_video_position(kinc_video_t *video) {
return 0.0;
}
bool kinc_video_finished(kinc_video_t *video) {
return false;
}
bool kinc_video_paused(kinc_video_t *video) {
return false;
}
void kinc_video_update(kinc_video_t *video, double time) {}
void kinc_internal_video_sound_stream_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency) {}
void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t *stream) {}
void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {}
static float samples[2] = {0};
float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) {
return samples;
}
bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) {
return true;
}

View File

@ -0,0 +1,27 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int nothing;
} kinc_video_impl_t;
typedef struct kinc_internal_video_sound_stream {
int nothing;
} kinc_internal_video_sound_stream_t;
void kinc_internal_video_sound_stream_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency);
void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t *stream);
void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count);
float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream);
bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,81 @@
#include <kinc/display.h>
#include <kinc/graphics4/graphics.h>
#include <kinc/window.h>
#include <string.h>
int kinc_internal_window_width = 0;
int kinc_internal_window_height = 0;
kinc_window_mode_t kinc_internal_window_mode = KINC_WINDOW_MODE_WINDOW;
int kinc_count_windows(void) {
return 1;
}
int kinc_window_x(int window_index) {
return 0;
}
int kinc_window_y(int window_index) {
return 0;
}
int kinc_window_width(int window_index) {
return kinc_internal_window_width;
}
int kinc_window_height(int window_index) {
return kinc_internal_window_height;
}
void kinc_window_resize(int window_index, int width, int height) {}
void kinc_window_move(int window_index, int x, int y) {}
void kinc_window_change_framebuffer(int window_index, kinc_framebuffer_options_t *frame) {
//**kinc_g4_changeFramebuffer(0, frame);
}
void kinc_window_change_features(int window_index, int features) {}
// In HTML5 fullscreen is activable only from user input.
void kinc_window_change_mode(int window_index, kinc_window_mode_t mode) {
if (mode == KINC_WINDOW_MODE_FULLSCREEN || mode == KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
if (kinc_internal_window_mode == KINC_WINDOW_MODE_FULLSCREEN || kinc_internal_window_mode == KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
kinc_internal_window_mode = mode;
return;
}
// TODO: call js Fullscreen API
kinc_internal_window_mode = mode;
}
else {
if (mode == kinc_internal_window_mode) {
return;
}
// TODO: call js Fullscreen API
kinc_internal_window_mode = mode;
}
}
void kinc_window_destroy(int window_index) {}
void kinc_window_show(int window_index) {}
void kinc_window_hide(int window_index) {}
// TODO: change browser title.
void kinc_window_set_title(int window_index, const char *title) {}
int kinc_window_create(kinc_window_options_t *win, kinc_framebuffer_options_t *frame) {
return 0;
}
void kinc_window_set_resize_callback(int window_index, void (*callback)(int x, int y, void *data), void *data) {}
void kinc_window_set_ppi_changed_callback(int window_index, void (*callback)(int ppi, void *data), void *data) {}
void kinc_window_set_close_callback(int window, bool (*callback)(void *), void *data) {}
kinc_window_mode_t kinc_window_get_mode(int window_index) {
return kinc_internal_window_mode;
}

View File

@ -0,0 +1,8 @@
#pragma once
namespace Kore {
struct WindowData {
int width, height, mode;
WindowData();
};
}