Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
emscripten.c File Reference
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "../zstddeclib.c"
#include "testcard-zstd.inl"

Data Structures

struct  vec2
 
struct  posTex2d
 

Macros

#define DXT1_256x256   32768
 
#define GL_VERT_POSXY_ID   0
 
#define GL_VERT_TXUV0_ID   1
 

Functions

size_t ZSTD_decompress (void *dst, size_t dstLen, const void *src, size_t srcLen)
 
int main ()
 

Detailed Description

Emscripten example of using the single-file zstddeclib. Draws a rotating textured quad with data from the in-line Zstd compressed DXT1 texture (DXT1 being hardware compression, further compressed with Zstd).
Compile using:

export CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto --llvm-lto 3 -lGL -DNDEBUG=1"
export EM_FLAGS="-s WASM=1 -s ENVIRONMENT=web --shell-file shell.html --closure 1"
emcc $CC_FLAGS $EM_FLAGS -o out.html emscripten.c
const lzma_allocator const uint8_t size_t uint8_t * out
Definition block.h:528
Author
Carl Woffenden, Numfum GmbH (released under a CC0 license)

Macro Definition Documentation

◆ DXT1_256x256

#define DXT1_256x256   32768

Uncompressed size of srcZstd.

◆ GL_VERT_POSXY_ID

#define GL_VERT_POSXY_ID   0

Vertex position index.

◆ GL_VERT_TXUV0_ID

#define GL_VERT_TXUV0_ID   1

Vertex UV0 index.

Function Documentation

◆ main()

int main ( void )

Creates the GL context, shaders and quad data, decompresses the Zstd data and 'uploads' the resulting texture.

As a (naive) comparison, removing Zstd and building with "-Os -g0 s WASM=1 -lGL emscripten.c" results in a 15kB WebAssembly file; re-adding Zstd increases the Wasm by 26kB.

◆ ZSTD_decompress()

size_t ZSTD_decompress ( void * dst,
size_t dstLen,
const void * src,
size_t srcLen )

For the case where the decompression library hasn't been included we add a dummy function to fake the process and stop the buffers being optimised out.