forked from cntools/rawdraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNFGWASMDriver.c
84 lines (68 loc) · 1.86 KB
/
CNFGWASMDriver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//Right now, designed for use with https://github.com/cnlohr/rawdrawwasm/
#include <CNFG.h>
#include <stdint.h>
extern void __attribute__((import_module("bynsyncify"))) CNFGSwapBuffersInternal();
void CNFGBlitImageInternal( uint32_t * data, int x, int y, int w, int h );
void print( double idebug );
void prints( const char* sdebug );
//Forward declarations that we get from either WASM or our javascript code.
void CNFGClearFrameInternal( uint32_t bgcolor );
//The WASM driver handles internal resizing automatically.
#ifndef CNFGRASTERIZER
void CNFGInternalResize( short x, short y )
{
}
void CNFGFlushRender()
{
if( !CNFGVertPlace ) return;
CNFGEmitBackendTriangles( CNFGVertDataV, CNFGVertDataC, CNFGVertPlace );
CNFGVertPlace = 0;
}
void CNFGClearFrame()
{
CNFGFlushRender();
CNFGClearFrameInternal( CNFGBGColor );
}
void CNFGSwapBuffers()
{
CNFGFlushRender();
CNFGSwapBuffersInternal( );
}
int CNFGHandleInput()
{
//Do nothing.
//Input is handled on swap frame.
return 1;
}
void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h )
{
CNFGBlitImageInternal( data, x, y, w, h );
}
#else
//Rasterizer - if you want to do this, you will need to enable blitting in the javascript.
//XXX TODO: NEED MEMORY ALLOCATOR
extern unsigned char __heap_base;
unsigned int bump_pointer = (unsigned int)&__heap_base;
void* malloc(unsigned long size) {
unsigned int ptr = bump_pointer;
bump_pointer += size;
return (void *)ptr;
}
void free(void* ptr) { }
#include "CNFGRasterizer.c"
extern void CNFGUpdateScreenWithBitmapInternal( uint32_t * data, int w, int h );
void CNFGUpdateScreenWithBitmap( uint32_t * data, int w, int h )
{
CNFGBlitImageInternal( data, 0, 0, w, h );
CNFGSwapBuffersInternal();
}
void CNFGSetLineWidth( short width )
{
//Rasterizer does not support line width.
}
void CNFGHandleInput()
{
//Do nothing.
//Input is handled on swap frame.
}
#endif