Skip to content

Commit

Permalink
Add WebAssembly test with a little bit macro changes in RayTracer.c.
Browse files Browse the repository at this point in the history
  • Loading branch information
wxfred committed Apr 3, 2022
1 parent b5b8044 commit e671cea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions c/RayTracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#if __EMSCRIPTEN__
#include <emscripten.h>
#endif

const double FarAway = 1000000.0;

Expand Down Expand Up @@ -577,6 +580,18 @@ int main()

printf("Completed in %d ms\n", time_ms);
SaveRGBBitmap(&bitmapData[0], width, height, 32, "c-raytracer.bmp");
#if __EMSCRIPTEN__
EM_ASM(
const stream = FS.open("c-raytracer.bmp", "r");
const blob = new Blob([stream.node.contents], { type: "image/bmp" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "webassembly-raytracer.bmp";
a.click();
URL.revokeObjectURL(a.href);
a.remove();
);
#endif

ReleaseScene(&scene);
free(bitmapData);
Expand Down
2 changes: 2 additions & 0 deletions webassembly/build.o1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
emsdk_env.ps1
emcc ../c/RayTracer.c -O1 -s WASM=1 -s SINGLE_FILE=1 -o RayTracer.html
2 changes: 2 additions & 0 deletions webassembly/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
emsdk_env.ps1
emcc ../c/RayTracer.c -O3 -s WASM=1 -s SINGLE_FILE=1 -o RayTracer.html

0 comments on commit e671cea

Please sign in to comment.