Set up a basic "front-end" for the webassembly module to be tested locally from a data folder (I use python -m http.server). The WebAssembly application is now responsible for all setup/rendering through the WebGL2 context.

This commit is contained in:
2025-09-01 12:13:56 -07:00
parent cca61ea163
commit b548b7bb26
14 changed files with 1416 additions and 14 deletions

35
cwasm_webgl_js_imports.h Normal file
View File

@@ -0,0 +1,35 @@
/*
File: cwasm_webgl_js_imports.h
Author: Taylor Robbins
Date: 09\01\2025
*/
#ifndef _CWASM_WEBGL_JS_IMPORTS_H
#define _CWASM_WEBGL_JS_IMPORTS_H
typedef int GlId; // Really this is just an index into a javascript array that holds the real reference to the WebGL object
typedef int GlEnum;
MAYBE_EXTERN_C GlId jsGlCreateBuffer();
MAYBE_EXTERN_C void jsGlBindBuffer(GlEnum bufferType, GlId bufferId);
MAYBE_EXTERN_C void jsGlBufferData(GlEnum bufferType, u32 dataLength, const void* dataPntr, GlEnum usageHint);
MAYBE_EXTERN_C GlId jsGlCreateVertexArray();
MAYBE_EXTERN_C void jsGlBindVertexArray(GlId vaoId);
MAYBE_EXTERN_C void jsGlEnableVertexAttribArray(GlEnum location);
MAYBE_EXTERN_C void jsGlVertexAttribPointer(GlEnum attribLocation, int componentCount, GlEnum componentType, bool normalized, int stride, int offset);
MAYBE_EXTERN_C GlId jsGlCreateShader(GlEnum shaderType);
MAYBE_EXTERN_C void jsGlShaderSource(GlId shaderId, int sourceLength, const char* sourcePntr);
MAYBE_EXTERN_C void jsGlCompileShader(GlId shaderId);
MAYBE_EXTERN_C bool jsGlGetShaderParameterBool(GlId shaderId, GlEnum parameter);
MAYBE_EXTERN_C int jsGlGetShaderParameterInt(GlId shaderId, GlEnum parameter);
MAYBE_EXTERN_C GlId jsGlCreateProgram();
MAYBE_EXTERN_C void jsGlAttachShader(GlId programId, GlId shaderId);
MAYBE_EXTERN_C void jsGlLinkProgram(GlId programId);
MAYBE_EXTERN_C void jsGlUseProgram(GlId programId);
MAYBE_EXTERN_C bool jsGlGetProgramParameterBool(GlId programId, GlEnum parameter);
MAYBE_EXTERN_C int jsGlGetProgramParameterInt(GlId programId, GlEnum parameter);
MAYBE_EXTERN_C void jsGlClearColor(r32 rValue, r32 gValue, r32 bValue, r32 aValue);
MAYBE_EXTERN_C void jsGlClear(int bufferBits);
MAYBE_EXTERN_C void jsGlDrawArrays(GlEnum geometryType, int startIndex, int count);
#endif // _CWASM_WEBGL_JS_IMPORTS_H