2014-07-29 14:20:12 +02:00
|
|
|
Native Client
|
2014-06-06 20:45:59 +02:00
|
|
|
================================================================================
|
|
|
|
|
|
|
|
Requirements:
|
2014-08-15 23:39:14 +02:00
|
|
|
|
|
|
|
* Native Client SDK (https://developer.chrome.com/native-client),
|
|
|
|
(tested with Pepper version 33 or higher).
|
2014-06-06 20:45:59 +02:00
|
|
|
|
|
|
|
The SDL backend for Chrome's Native Client has been tested only with the PNaCl
|
|
|
|
toolchain, which generates binaries designed to run on ARM and x86_32/64
|
|
|
|
platforms. This does not mean it won't work with the other toolchains!
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Building SDL for NaCl
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
Set up the right environment variables (see naclbuild.sh), then configure SDL with:
|
|
|
|
|
|
|
|
configure --host=pnacl --prefix some/install/destination
|
|
|
|
|
|
|
|
Then "make".
|
|
|
|
|
|
|
|
As an example of how to create a deployable app a Makefile project is provided
|
|
|
|
in test/nacl/Makefile, which includes some monkey patching of the common.mk file
|
|
|
|
provided by NaCl, without which linking properly to SDL won't work (the search
|
|
|
|
path can't be modified externally, so the linker won't find SDL's binaries unless
|
|
|
|
you dump them into the SDK path, which is inconvenient).
|
|
|
|
Also provided in test/nacl is the required support file, such as index.html,
|
|
|
|
manifest.json, etc.
|
2014-06-08 23:50:40 +02:00
|
|
|
SDL apps for NaCl run on a worker thread using the ppapi_simple infrastructure.
|
|
|
|
This allows for blocking calls on all the relevant systems (OpenGL ES, filesystem),
|
|
|
|
hiding the asynchronous nature of the browser behind the scenes...which is not the
|
2014-06-09 17:28:08 +02:00
|
|
|
same as making it disappear!
|
2014-06-06 20:45:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Running tests
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
Due to the nature of NaCl programs, building and running SDL tests is not as
|
|
|
|
straightforward as one would hope. The script naclbuild.sh in build-scripts
|
|
|
|
automates the process and should serve as a guide for users of SDL trying to build
|
|
|
|
their own applications.
|
|
|
|
|
|
|
|
Basic usage:
|
|
|
|
|
|
|
|
./naclbuild.sh path/to/pepper/toolchain (i.e. ~/naclsdk/pepper_35)
|
|
|
|
|
|
|
|
This will build testgles2.c by default.
|
|
|
|
|
|
|
|
If you want to build a different test, for example testrendercopyex.c:
|
|
|
|
|
|
|
|
SOURCES=~/sdl/SDL/test/testrendercopyex.c ./naclbuild.sh ~/naclsdk/pepper_35
|
|
|
|
|
|
|
|
Once the build finishes, you have to serve the contents with a web server (the
|
|
|
|
script will give you instructions on how to do that with Python).
|
|
|
|
|
2014-06-08 23:18:13 +02:00
|
|
|
================================================================================
|
2014-06-09 17:28:08 +02:00
|
|
|
RWops and nacl_io
|
2014-06-08 23:18:13 +02:00
|
|
|
================================================================================
|
|
|
|
|
2014-06-20 15:59:51 +02:00
|
|
|
SDL_RWops work transparently with nacl_io. Two functions control the mount points:
|
2014-06-08 23:18:13 +02:00
|
|
|
|
2014-06-20 15:59:51 +02:00
|
|
|
int mount(const char* source, const char* target,
|
2014-06-08 23:50:40 +02:00
|
|
|
const char* filesystemtype,
|
|
|
|
unsigned long mountflags, const void *data);
|
2014-06-20 15:59:51 +02:00
|
|
|
int umount(const char *target);
|
2014-06-08 23:18:13 +02:00
|
|
|
|
2014-06-08 23:50:40 +02:00
|
|
|
For convenience, SDL will by default mount an httpfs tree at / before calling
|
2014-06-09 17:28:08 +02:00
|
|
|
the app's main function. Such setting can be overridden by calling:
|
2014-06-08 23:50:40 +02:00
|
|
|
|
2014-06-20 15:59:51 +02:00
|
|
|
umount("/");
|
2014-06-08 23:50:40 +02:00
|
|
|
|
|
|
|
And then mounting a different filesystem at /
|
|
|
|
|
|
|
|
It's important to consider that the asynchronous nature of file operations on a
|
|
|
|
browser is hidden from the application, effectively providing the developer with
|
|
|
|
a set of blocking file operations just like you get in a regular desktop
|
|
|
|
environment, which eases the job of porting to Native Client, but also introduces
|
|
|
|
a set of challenges of its own, in particular when big file sizes and slow
|
|
|
|
connections are involved.
|
2014-06-08 23:18:13 +02:00
|
|
|
|
|
|
|
For more information on how nacl_io and mount points work, see:
|
|
|
|
|
|
|
|
https://developer.chrome.com/native-client/devguide/coding/nacl_io
|
2014-06-20 15:59:51 +02:00
|
|
|
https://src.chromium.org/chrome/trunk/src/native_client_sdk/src/libraries/nacl_io/nacl_io.h
|
|
|
|
|
|
|
|
To be able to save into the directory "/save/" (like backup of game) :
|
|
|
|
|
|
|
|
mount("", "/save", "html5fs", 0, "type=PERSISTENT");
|
|
|
|
|
|
|
|
And add to manifest.json :
|
|
|
|
|
2014-08-15 23:39:14 +02:00
|
|
|
"permissions": [
|
|
|
|
"unlimitedStorage"
|
|
|
|
]
|
2014-06-08 23:18:13 +02:00
|
|
|
|
2014-06-06 20:45:59 +02:00
|
|
|
================================================================================
|
|
|
|
TODO - Known Issues
|
|
|
|
================================================================================
|
|
|
|
* Testing of all systems with a real application (something other than SDL's tests)
|
2014-06-16 14:54:33 +02:00
|
|
|
* Key events don't seem to work properly
|
2014-06-06 20:45:59 +02:00
|
|
|
|