Added cwasm_vectors.c and cwasm_matrices.c. Vectors API is completely finished, Matrices API is partially finished. Added Clamp(value, min, max) macro to cwasm.h. Fixed types on jsGl functions that take vectors or matrices (and Arena*).

This commit is contained in:
2025-09-02 00:15:03 -07:00
parent b62f0d279b
commit 1a9775d670
7 changed files with 1072 additions and 45 deletions

View File

@@ -187,8 +187,8 @@ WASM_EXPORT(App_Initialize) bool App_Initialize()
sizeof(testPixels), //dataLength
&testPixels //dataPntr
);
jsGlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
jsGlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
jsGlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
jsGlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
jsGlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
jsGlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
jsGlGenerateMipmap(GL_TEXTURE_2D);
@@ -259,14 +259,9 @@ WASM_EXPORT(App_UpdateAndRender) bool App_UpdateAndRender(r64 programTimeR64)
jsGlActiveTexture(GL_TEXTURE0);
jsGlBindTexture(GL_TEXTURE_2D, app.testTexture);
r32 identityMatrix[] = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
};
jsGlUniformMatrix4fv(app.viewMatrixLocation, &identityMatrix[0]);
jsGlUniformMatrix4fv(app.projMatrixLocation, &identityMatrix[0]);
mat4 identityMatrix = Mat4_Identity;
jsGlUniformMatrix4fv(app.viewMatrixLocation, &identityMatrix);
jsGlUniformMatrix4fv(app.projMatrixLocation, &identityMatrix);
#if 0
const u64 numTris = 75;
@@ -295,17 +290,23 @@ WASM_EXPORT(App_UpdateAndRender) bool App_UpdateAndRender(r64 programTimeR64)
#endif
{
r32 offsetX = 0.0f;
r32 offsetY = 0.0f;
r32 scaleX = 1.0f;
r32 scaleY = 1.0f;
r32 worldMatrix[] = {
r32 offsetX = -0.4f;
r32 offsetY = -0.4f;
r32 scaleX = 0.8f;
r32 scaleY = 0.8f;
#if 1
mat4 worldMatrix = Mat4_Identity_Const;
worldMatrix = MulMat4(MakeScaleMat4(scaleX, scaleY, 1.0f), worldMatrix);
worldMatrix = MulMat4(MakeTranslateMat4(offsetX, offsetY, 0.0f), worldMatrix);
#else
mat4 worldMatrix = NewMat4_Const(
scaleX, 0.0f, 0.0f, offsetX,
0.0f, scaleY, 0.0f, offsetY,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
};
jsGlUniformMatrix4fv(app.worldMatrixLocation, &worldMatrix[0]);
0.0f, 0.0f, 0.0f, 1.0f
);
#endif
jsGlUniformMatrix4fv(app.worldMatrixLocation, &worldMatrix);
jsGlDrawArrays(GL_TRIANGLES, 0, 6);
}