gabomdq@8833
|
1 |
================================================================================
|
gabomdq@8833
|
2 |
Simple DirectMedia Layer for Native Client
|
gabomdq@8833
|
3 |
================================================================================
|
gabomdq@8833
|
4 |
|
gabomdq@8833
|
5 |
Requirements:
|
gabomdq@8833
|
6 |
|
gabomdq@8833
|
7 |
* Native Client SDK (https://developer.chrome.com/native-client),
|
gabomdq@8833
|
8 |
(tested with Pepper version 33 or higher).
|
gabomdq@8833
|
9 |
|
gabomdq@8833
|
10 |
The SDL backend for Chrome's Native Client has been tested only with the PNaCl
|
gabomdq@8833
|
11 |
toolchain, which generates binaries designed to run on ARM and x86_32/64
|
gabomdq@8833
|
12 |
platforms. This does not mean it won't work with the other toolchains!
|
gabomdq@8833
|
13 |
|
gabomdq@8833
|
14 |
================================================================================
|
gabomdq@8833
|
15 |
Building SDL for NaCl
|
gabomdq@8833
|
16 |
================================================================================
|
gabomdq@8833
|
17 |
|
gabomdq@8833
|
18 |
Set up the right environment variables (see naclbuild.sh), then configure SDL with:
|
gabomdq@8833
|
19 |
|
gabomdq@8833
|
20 |
configure --host=pnacl --prefix some/install/destination
|
gabomdq@8833
|
21 |
|
gabomdq@8833
|
22 |
Then "make".
|
gabomdq@8833
|
23 |
|
gabomdq@8833
|
24 |
As an example of how to create a deployable app a Makefile project is provided
|
gabomdq@8833
|
25 |
in test/nacl/Makefile, which includes some monkey patching of the common.mk file
|
gabomdq@8833
|
26 |
provided by NaCl, without which linking properly to SDL won't work (the search
|
gabomdq@8833
|
27 |
path can't be modified externally, so the linker won't find SDL's binaries unless
|
gabomdq@8833
|
28 |
you dump them into the SDK path, which is inconvenient).
|
gabomdq@8833
|
29 |
Also provided in test/nacl is the required support file, such as index.html,
|
gabomdq@8833
|
30 |
manifest.json, etc.
|
gabomdq@8852
|
31 |
SDL apps for NaCl run on a worker thread using the ppapi_simple infrastructure.
|
gabomdq@8852
|
32 |
This allows for blocking calls on all the relevant systems (OpenGL ES, filesystem),
|
gabomdq@8852
|
33 |
hiding the asynchronous nature of the browser behind the scenes...which is not the
|
philipp@8854
|
34 |
same as making it disappear!
|
gabomdq@8833
|
35 |
|
gabomdq@8833
|
36 |
|
gabomdq@8833
|
37 |
================================================================================
|
gabomdq@8833
|
38 |
Running tests
|
gabomdq@8833
|
39 |
================================================================================
|
gabomdq@8833
|
40 |
|
gabomdq@8833
|
41 |
Due to the nature of NaCl programs, building and running SDL tests is not as
|
gabomdq@8833
|
42 |
straightforward as one would hope. The script naclbuild.sh in build-scripts
|
gabomdq@8833
|
43 |
automates the process and should serve as a guide for users of SDL trying to build
|
gabomdq@8833
|
44 |
their own applications.
|
gabomdq@8833
|
45 |
|
gabomdq@8833
|
46 |
Basic usage:
|
gabomdq@8833
|
47 |
|
gabomdq@8833
|
48 |
./naclbuild.sh path/to/pepper/toolchain (i.e. ~/naclsdk/pepper_35)
|
gabomdq@8833
|
49 |
|
gabomdq@8833
|
50 |
This will build testgles2.c by default.
|
gabomdq@8833
|
51 |
|
gabomdq@8833
|
52 |
If you want to build a different test, for example testrendercopyex.c:
|
gabomdq@8833
|
53 |
|
gabomdq@8833
|
54 |
SOURCES=~/sdl/SDL/test/testrendercopyex.c ./naclbuild.sh ~/naclsdk/pepper_35
|
gabomdq@8833
|
55 |
|
gabomdq@8833
|
56 |
Once the build finishes, you have to serve the contents with a web server (the
|
gabomdq@8833
|
57 |
script will give you instructions on how to do that with Python).
|
gabomdq@8833
|
58 |
|
gabomdq@8833
|
59 |
================================================================================
|
philipp@8854
|
60 |
RWops and nacl_io
|
gabomdq@8851
|
61 |
================================================================================
|
gabomdq@8851
|
62 |
|
gabomdq@8877
|
63 |
SDL_RWops work transparently with nacl_io. Two functions control the mount points:
|
gabomdq@8851
|
64 |
|
gabomdq@8877
|
65 |
int mount(const char* source, const char* target,
|
gabomdq@8852
|
66 |
const char* filesystemtype,
|
gabomdq@8852
|
67 |
unsigned long mountflags, const void *data);
|
gabomdq@8877
|
68 |
int umount(const char *target);
|
gabomdq@8851
|
69 |
|
gabomdq@8852
|
70 |
For convenience, SDL will by default mount an httpfs tree at / before calling
|
philipp@8854
|
71 |
the app's main function. Such setting can be overridden by calling:
|
gabomdq@8852
|
72 |
|
gabomdq@8877
|
73 |
umount("/");
|
gabomdq@8852
|
74 |
|
gabomdq@8852
|
75 |
And then mounting a different filesystem at /
|
gabomdq@8852
|
76 |
|
gabomdq@8852
|
77 |
It's important to consider that the asynchronous nature of file operations on a
|
gabomdq@8852
|
78 |
browser is hidden from the application, effectively providing the developer with
|
gabomdq@8852
|
79 |
a set of blocking file operations just like you get in a regular desktop
|
gabomdq@8852
|
80 |
environment, which eases the job of porting to Native Client, but also introduces
|
gabomdq@8852
|
81 |
a set of challenges of its own, in particular when big file sizes and slow
|
gabomdq@8852
|
82 |
connections are involved.
|
gabomdq@8851
|
83 |
|
gabomdq@8851
|
84 |
For more information on how nacl_io and mount points work, see:
|
gabomdq@8851
|
85 |
|
gabomdq@8851
|
86 |
https://developer.chrome.com/native-client/devguide/coding/nacl_io
|
gabomdq@8877
|
87 |
https://src.chromium.org/chrome/trunk/src/native_client_sdk/src/libraries/nacl_io/nacl_io.h
|
gabomdq@8877
|
88 |
|
gabomdq@8877
|
89 |
To be able to save into the directory "/save/" (like backup of game) :
|
gabomdq@8877
|
90 |
|
gabomdq@8877
|
91 |
mount("", "/save", "html5fs", 0, "type=PERSISTENT");
|
gabomdq@8877
|
92 |
|
gabomdq@8877
|
93 |
And add to manifest.json :
|
gabomdq@8877
|
94 |
|
gabomdq@8877
|
95 |
"permissions": [
|
gabomdq@8877
|
96 |
"unlimitedStorage"
|
gabomdq@8877
|
97 |
]
|
gabomdq@8851
|
98 |
|
gabomdq@8851
|
99 |
================================================================================
|
gabomdq@8833
|
100 |
TODO - Known Issues
|
gabomdq@8833
|
101 |
================================================================================
|
gabomdq@8833
|
102 |
* Testing of all systems with a real application (something other than SDL's tests)
|
gabomdq@8873
|
103 |
* Key events don't seem to work properly
|
gabomdq@8833
|
104 |
|