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