wiki:GraphicsApi

Version 8 (modified by davea, 17 years ago) (diff)

--

Application graphics (version 6+)

T(VersionSix)?

Starting with BOINC version 6.0, application graphics are generated by a separate 'graphics app' program. The only constraints on a graphics app are:

  • If invoked with --fullscreen, it opens a full-screen borderless window, and must exit on mouse or keyboard input.
  • Otherwise it opens a standard window, and may handle mouse/keyboard input.

The graphics app is launched by the BOINC Manager and by the screensaver. It may be killed at any time. Multiple instances of the graphics app may run at the same time (e.g. if the user opens a graphics window via the Manager, and then the screensaver runs and launches another instance).

The BOINC graphics API (described below) provides cross-platform support for developing graphics apps; however, you need not use it.

The logical name of the program must be 'graphics_app'. When you set up your application version directory, give it a filename like

graphics_app=uc2_graphics_5.10_windows_intelx86.exe

The BOINC Graphics API

BOINC supplies a library (libboinc_graphics2.a) that makes it easy to develop graphics apps. To use this library, the graphics app must call

boinc_graphics_loop(int argc, char** argv);

after its initialization. This function executes an event loop, and does not return.

The application must supply the following functions:

void app_graphics_render(int xs, ys, double time_of_day);
void app_graphics_resize(int x, int y);
void boinc_app_mouse_move();
void boinc_app_mouse_button();
void boinc_app_key_press();
void boinc_app_key_release();

These functions are described here.

Communicating with the main application

The graphics app may want to get information from the main app. This can be done efficiently using shared memory. The BOINC library supplies the following functions to facilitate this:

void* boinc_graphics_make_shmem(char* appname, int size);
void* boinc_graphics_get_shmem(char* appname);

boinc_graphics_make_shmem() (called from the main app) creates a shared memory segment of the given size. 'appname' should be the name of this application (used to ensure uniqueness of the shared-memory segment name). boinc_graphics_get_shmem() (called from the graphics app) attaches to an existing segment.

The contents of the shared memory segment are up to you. You may want to include the following items:

struct UC_SHMEM {
    double update_time;
    double fraction_done;
    double cpu_time;
    BOINC_STATUS status;
};

This structure should be updated by the main app once per second, using boinc_set_timer_handler(). The items are:

update_time
The current time (dtime()). The graphics app should exit if the current time exceeds this by 5 seconds or so.
fraction_done
The last fraction done reported by the main app.
cpu_time
The current CPU time.
status
The BOINC status. If the 'suspended' flag is set, the graphics app should stop changing its display, and simply display an "application suspended" message.

Keep in mind that multiple instances of the graphics app may run simultaneously; avoid having the graphics app write to the shared memory. If you use shared memory to store a data structure, use a semaphore to synchronize access so that the graphics app doesn't see an inconsistent state.