From 8924ceb2f12a4a0b32a7b7a57b5548fa4f06093a Mon Sep 17 00:00:00 2001 From: ILyoan Date: Thu, 28 Mar 2013 18:58:05 +0900 Subject: [PATCH] support android build and glue --- Makefile.in | 13 ++- android-glue.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++ configure | 1 - glut.rs | 106 ++++++++++++++++++++++ 4 files changed, 351 insertions(+), 3 deletions(-) create mode 100644 android-glue.c diff --git a/Makefile.in b/Makefile.in index e2a5742..d29758d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -7,6 +7,9 @@ AR ?= ar RUSTC ?= rustc RUSTFLAGS ?= +ifeq ($(CFG_OSTYPE),linux-androideabi) +RUSTFLAGS += -L. +endif RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') .PHONY: all @@ -15,13 +18,19 @@ all: librustglut.dummy %.o: %.c $(CC) $< -o $@ -c $(CFLAGS) -librustglut.dummy: glut.rc $(RUST_SRC) +librustglut.dummy: glut.rc $(RUST_SRC) libandroid-glue.a $(RUSTC) $(RUSTFLAGS) $< -o $@ touch $@ -rustglut-test: glut.rc $(RUST_SRC) +rustglut-test: glut.rc $(RUST_SRC) libandroid-glue.a $(RUSTC) $(RUSTFLAGS) $< -o $@ --test +libandroid-glue.a: android-glue.o + $(AR) rcs libandroid-glue.a android-glue.o + +android-glue.o: android-glue.c + $(CC) $(CFLAGS) $< -o $@ -c + check: rustglut-test ./rustglut-test diff --git a/android-glue.c b/android-glue.c new file mode 100644 index 0000000..b806ccb --- /dev/null +++ b/android-glue.c @@ -0,0 +1,234 @@ + +typedef void (*fty_glutMainLoopEvent)(); +typedef void (*fty_glutInit)(int*, char**); +typedef void (*fty_glutInitDisplayMode)(int); +typedef int (*fty_glutCreateWindow)(char*); +typedef void (*fty_glutDestroyWindow)(int); +typedef void (*fty_glutPostRedisplay)(); +typedef void (*fty_glutSwapBuffers)(); +typedef int (*fty_glutGetWindow)(); +typedef void (*fty_glutSetWindow)(int); +typedef void (*fty_glutReshapeWindow)(int ,int); +typedef void (*fty_glutDisplayFunc)(void*); +typedef void (*fty_glutReshapeFunc)(void*); +typedef void (*fty_glutKeyboardFunc)(void*); +typedef void (*fty_glutMouseFunc)(void*); +typedef void (*fty_glutMotionFunc)(void*); +typedef void (*fty_glutPassiveMotionFunc)(void*); +typedef void (*fty_glutTimerFunc)(unsigned int,void*, int); +typedef int (*fty_glutGet)(int); +typedef int (*fty_glutGetModifiers)(); +typedef void (*fty_glutSetWindowTitle)(char*); +typedef void (*fty_glutIdleFunc)(void*); +typedef void (*fty_glutInitWindowSize)(int, int); +typedef void (*fty_glutMouseWheelFunc)(void*); + +fty_glutMainLoopEvent fn_glutMainLoopEvent; +fty_glutInit fn_glutInit; +fty_glutInitDisplayMode fn_glutInitDisplayMode; +fty_glutCreateWindow fn_glutCreateWindow; +fty_glutDestroyWindow fn_glutDestroyWindow; +fty_glutPostRedisplay fn_glutPostRedisplay; +fty_glutSwapBuffers fn_glutSwapBuffers; +fty_glutGetWindow fn_glutGetWindow; +fty_glutSetWindow fn_glutSetWindow; +fty_glutReshapeWindow fn_glutReshapeWindow; +fty_glutDisplayFunc fn_glutDisplayFunc; +fty_glutReshapeFunc fn_glutReshapeFunc; +fty_glutKeyboardFunc fn_glutKeyboardFunc; +fty_glutMouseFunc fn_glutMouseFunc; +fty_glutMotionFunc fn_glutMotionFunc; +fty_glutPassiveMotionFunc fn_glutPassiveMotionFunc; +fty_glutTimerFunc fn_glutTimerFunc; +fty_glutGet fn_glutGet; +fty_glutGetModifiers fn_glutGetModifiers; +fty_glutSetWindowTitle fn_glutSetWindowTitle; +fty_glutIdleFunc fn_glutIdleFunc; +fty_glutInitWindowSize fn_glutInitWindowSize; +fty_glutMouseWheelFunc fn_glutMouseWheelFunc; + +void reg_fn_glutMainLoopEvent(fty_glutMainLoopEvent fn) +{ + fn_glutMainLoopEvent = fn; +} +void reg_fn_glutInit(fty_glutInit fn) +{ + fn_glutInit = fn; +} +void reg_fn_glutInitDisplayMode(fty_glutInitDisplayMode fn) +{ + fn_glutInitDisplayMode = fn; +} +void reg_fn_glutCreateWindow(fty_glutCreateWindow fn) +{ + fn_glutCreateWindow = fn; +} +void reg_fn_glutDestroyWindow(fty_glutDestroyWindow fn) +{ + fn_glutDestroyWindow = fn; +} +void reg_fn_glutPostRedisplay(fty_glutPostRedisplay fn) +{ + fn_glutPostRedisplay = fn; +} +void reg_fn_glutSwapBuffers(fty_glutSwapBuffers fn) +{ + fn_glutSwapBuffers = fn; +} +void reg_fn_glutGetWindow(fty_glutGetWindow fn) +{ + fn_glutGetWindow = fn; +} +void reg_fn_glutSetWindow(fty_glutSetWindow fn) +{ + fn_glutSetWindow = fn; +} +void reg_fn_glutReshapeWindow(fty_glutReshapeWindow fn) +{ + fn_glutReshapeWindow = fn; +} +void reg_fn_glutDisplayFunc(fty_glutDisplayFunc fn) +{ + fn_glutDisplayFunc = fn; +} +void reg_fn_glutReshapeFunc(fty_glutReshapeFunc fn) +{ + fn_glutReshapeFunc = fn; +} +void reg_fn_glutKeyboardFunc(fty_glutKeyboardFunc fn) +{ + fn_glutKeyboardFunc = fn; +} +void reg_fn_glutMouseFunc(fty_glutMouseFunc fn) +{ + fn_glutMouseFunc = fn; +} +void reg_fn_glutMotionFunc(fty_glutMotionFunc fn) +{ + fn_glutMotionFunc = fn; +} +void reg_fn_glutPassiveMotionFunc(fty_glutPassiveMotionFunc fn) +{ + fn_glutPassiveMotionFunc = fn; +} +void reg_fn_glutTimerFunc(fty_glutTimerFunc fn) +{ + fn_glutTimerFunc = fn; +} +void reg_fn_glutGet(fty_glutGet fn) +{ + fn_glutGet = fn; +} +void reg_fn_glutGetModifiers(fty_glutGetModifiers fn) +{ + fn_glutGetModifiers = fn; +} +void reg_fn_glutSetWindowTitle(fty_glutSetWindowTitle fn) +{ + fn_glutSetWindowTitle = fn; +} +void reg_fn_glutIdleFunc(fty_glutIdleFunc fn) +{ + fn_glutIdleFunc = fn; +} +void reg_fn_glutInitWindowSize(fty_glutInitWindowSize fn) +{ + fn_glutInitWindowSize = fn; +} +void reg_fn_glutMouseWheelFunc(fty_glutMouseWheelFunc fn) +{ + fn_glutMouseWheelFunc = fn; +} + +void glutMainLoopEvent() +{ + fn_glutMainLoopEvent(); +} +void glutInit(int* argcp, char** argv) +{ + fn_glutInit(argcp, argv); +} +void glutInitDisplayMode(int mode) +{ + fn_glutInitDisplayMode(mode); +} + int glutCreateWindow(char* title) +{ + return fn_glutCreateWindow(title); +} +void glutDestroyWindow(int win) +{ + fn_glutDestroyWindow(win); +} +void glutPostRedisplay() +{ + fn_glutPostRedisplay(); +} +void glutSwapBuffers() +{ + fn_glutSwapBuffers(); +} +int glutGetWindow() +{ + return fn_glutGetWindow(); +} +void glutSetWindow(int win) +{ + fn_glutSetWindow(win); +} +void glutReshapeWindow(int width, int height) +{ + fn_glutReshapeWindow(width, height); +} +void glutDisplayFunc(void* fn) +{ + fn_glutDisplayFunc(fn); +} +void glutReshapeFunc(void* fn) +{ + fn_glutReshapeFunc(fn); +} +void glutKeyboardFunc(void* fn) +{ + fn_glutKeyboardFunc(fn); +} +void glutMouseFunc(void* fn) +{ + fn_glutMouseFunc(fn); +} +void glutMotionFunc(void* fn) +{ + fn_glutMotionFunc(fn); +} +void glutPassiveMotionFunc(void* fn) +{ + fn_glutPassiveMotionFunc(fn); +} +void glutTimerFunc(unsigned int millis,void* fn, int value) +{ + fn_glutTimerFunc(millis, fn, value); +} +int glutGet(int type) +{ + return fn_glutGet(type); +} +int glutGetModifiers() +{ + return fn_glutGetModifiers(); +} +void glutSetWindowTitle(char* title) +{ + fn_glutSetWindowTitle(title); +} +void glutIdleFunc(void* fn) +{ + fn_glutIdleFunc(fn); +} +void glutInitWindowSize(int width, int height) +{ + fn_glutInitWindowSize(width, height); +} +void glutMouseWheelFunc(void* fn) +{ + fn_glutMouseWheelFunc(fn); +} diff --git a/configure b/configure index ed6c06e..62a0f4c 100755 --- a/configure +++ b/configure @@ -2,4 +2,3 @@ SRCDIR="$(cd $(dirname $0) && pwd)" sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile - diff --git a/glut.rs b/glut.rs index d73caee..4be7394 100644 --- a/glut.rs +++ b/glut.rs @@ -64,6 +64,8 @@ static WINDOW_HEIGHT: GLenum = 103; pub static HAVE_PRECISE_MOUSE_WHEEL: bool = false; #[cfg(target_os="macos")] pub static HAVE_PRECISE_MOUSE_WHEEL: bool = true; +#[cfg(target_os="android")] +pub static HAVE_PRECISE_MOUSE_WHEEL: bool = false; pub enum State { WindowWidth, @@ -292,6 +294,7 @@ pub fn mouse_wheel_callback_tls_key(_callback: @@fn(wheel: c_int, } #[cfg(target_os="linux")] +#[cfg(target_os="android")] pub extern fn mouse_wheel_callback(wheel: c_int, direction: c_int, x: c_int, y: c_int) { unsafe { let callback = local_data_get(mouse_wheel_callback_tls_key).get(); @@ -300,6 +303,7 @@ pub extern fn mouse_wheel_callback(wheel: c_int, direction: c_int, x: c_int, y: } #[cfg(target_os="linux")] +#[cfg(target_os="android")] pub fn mouse_wheel_func(callback: @fn(wheel: c_int, direction: c_int, x: c_int, y: c_int)) { unsafe { local_data_set(mouse_wheel_callback_tls_key, @callback); @@ -322,6 +326,7 @@ pub fn check_loop() { } #[cfg(target_os="linux")] +#[cfg(target_os="android")] pub fn check_loop() { unsafe { glutMainLoopEvent(); @@ -374,6 +379,11 @@ extern { extern { } +#[cfg(target_os="android")] +#[link_args="-landroid-glue"] +extern { +} + #[cfg(target_os="macos")] #[nolink] extern { @@ -382,6 +392,7 @@ extern { } #[cfg(target_os="linux")] +#[cfg(target_os="android")] #[nolink] extern { // freeglut extension. @@ -395,22 +406,27 @@ pub fn glutInit(argcp: *c_int, argv: **c_char); pub fn glutInitDisplayMode(mode: c_uint); +#[cfg(not(target_os="android"))] pub fn glutInitDisplayString(string: *c_char); +#[cfg(not(target_os="android"))] pub fn glutInitWindowPosition(x: c_int, y: c_int); pub fn glutInitWindowSize(width: c_int, height: c_int); +#[cfg(not(target_os="android"))] pub fn glutMainLoop(); pub fn glutCreateWindow(title: *c_char) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutCreateSubWindow(win: c_int, x: c_int, y: c_int, width: c_int, height: c_int) -> c_int; pub fn glutDestroyWindow(win: c_int); pub fn glutPostRedisplay(); +#[cfg(not(target_os="android"))] pub fn glutPostWindowRedisplay(win: c_int); pub fn glutSwapBuffers(); @@ -421,62 +437,90 @@ pub fn glutSetWindow(win: c_int); pub fn glutSetWindowTitle(title: *c_char); +#[cfg(not(target_os="android"))] pub fn glutSetIconTitle(title: *c_char); +#[cfg(not(target_os="android"))] pub fn glutPositionWindow(x: c_int, y: c_int); pub fn glutReshapeWindow(width: c_int, height: c_int); +#[cfg(not(target_os="android"))] pub fn glutPopWindow(); +#[cfg(not(target_os="android"))] pub fn glutPushWindow(); +#[cfg(not(target_os="android"))] pub fn glutIconifyWindow(); +#[cfg(not(target_os="android"))] pub fn glutShowWindow(); +#[cfg(not(target_os="android"))] pub fn glutHideWindow(); +#[cfg(not(target_os="android"))] pub fn glutFullScreen(); +#[cfg(not(target_os="android"))] pub fn glutSetCursor(cursor: c_int); +#[cfg(not(target_os="android"))] pub fn glutWarpPointer(x: c_int, y: c_int); +#[cfg(not(target_os="android"))] pub fn glutEstablishOverlay(); +#[cfg(not(target_os="android"))] pub fn glutRemoveOverlay(); +#[cfg(not(target_os="android"))] pub fn glutUseLayer(layer: GLenum); +#[cfg(not(target_os="android"))] pub fn glutPostOverlayRedisplay(); +#[cfg(not(target_os="android"))] pub fn glutPostWindowOverlayRedisplay(win: c_int); +#[cfg(not(target_os="android"))] pub fn glutShowOverlay(); +#[cfg(not(target_os="android"))] pub fn glutHideOverlay(); +#[cfg(not(target_os="android"))] pub fn glutCreateMenu(arg1: *u8) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutDestroyMenu(menu: c_int); +#[cfg(not(target_os="android"))] pub fn glutGetMenu() -> c_int; +#[cfg(not(target_os="android"))] pub fn glutSetMenu(menu: c_int); +#[cfg(not(target_os="android"))] pub fn glutAddMenuEntry(label: *c_char, value: c_int); +#[cfg(not(target_os="android"))] pub fn glutAddSubMenu(label: *c_char, submenu: c_int); +#[cfg(not(target_os="android"))] pub fn glutChangeToMenuEntry(item: c_int, label: *c_char, value: c_int); +#[cfg(not(target_os="android"))] pub fn glutChangeToSubMenu(item: c_int, label: *c_char, submenu: c_int); +#[cfg(not(target_os="android"))] pub fn glutRemoveMenuItem(item: c_int); +#[cfg(not(target_os="android"))] pub fn glutAttachMenu(button: c_int); +#[cfg(not(target_os="android"))] pub fn glutDetachMenu(button: c_int); pub fn glutDisplayFunc(func: *u8); @@ -488,140 +532,202 @@ pub fn glutKeyboardFunc(func: *u8); pub fn glutMouseFunc(func: *u8); #[cfg(target_os="linux")] +#[cfg(target_os="android")] pub fn glutMouseWheelFunc(func: *u8); pub fn glutMotionFunc(func: *u8); pub fn glutPassiveMotionFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutEntryFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutVisibilityFunc(func: *u8); pub fn glutIdleFunc(func: *u8); pub fn glutTimerFunc(millis: c_uint, func: *u8, value: c_int); +#[cfg(not(target_os="android"))] pub fn glutMenuStateFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutSpecialFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutSpaceballMotionFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutSpaceballRotateFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutSpaceballButtonFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutButtonBoxFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutDialsFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutTabletMotionFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutTabletButtonFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutMenuStatusFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutOverlayDisplayFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutWindowStatusFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutKeyboardUpFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutSpecialUpFunc(func: *u8); +#[cfg(not(target_os="android"))] pub fn glutJoystickFunc(func: *u8, pollInterval: c_int); +#[cfg(not(target_os="android"))] pub fn glutSetColor(arg1: c_int, red: GLfloat, green: GLfloat, blue: GLfloat); +#[cfg(not(target_os="android"))] pub fn glutGetColor(ndx: c_int, component: c_int) -> GLfloat; +#[cfg(not(target_os="android"))] pub fn glutCopyColormap(win: c_int); pub fn glutGet(_type: GLenum) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutDeviceGet(_type: GLenum) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutExtensionSupported(name: *c_char) -> c_int; pub fn glutGetModifiers() -> c_int; +#[cfg(not(target_os="android"))] pub fn glutLayerGet(_type: GLenum) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutGetProcAddress(procName: *c_char) -> *c_void; +#[cfg(not(target_os="android"))] pub fn glutBitmapCharacter(font: *c_void, character: c_int); +#[cfg(not(target_os="android"))] pub fn glutBitmapWidth(font: *c_void, character: c_int) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutStrokeCharacter(font: *c_void, character: c_int); +#[cfg(not(target_os="android"))] pub fn glutStrokeWidth(font: *c_void, character: c_int) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutBitmapLength(font: *c_void, string: *c_uchar) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutStrokeLength(font: *c_void, string: *c_uchar) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutWireSphere(radius: GLdouble, slices: GLint, stacks: GLint); +#[cfg(not(target_os="android"))] pub fn glutSolidSphere(radius: GLdouble, slices: GLint, stacks: GLint); +#[cfg(not(target_os="android"))] pub fn glutWireCone(base: GLdouble, height: GLdouble, slices: GLint, stacks: GLint); +#[cfg(not(target_os="android"))] pub fn glutSolidCone(base: GLdouble, height: GLdouble, slices: GLint, stacks: GLint); +#[cfg(not(target_os="android"))] pub fn glutWireCube(size: GLdouble); +#[cfg(not(target_os="android"))] pub fn glutSolidCube(size: GLdouble); +#[cfg(not(target_os="android"))] pub fn glutWireTorus(innerRadius: GLdouble, outerRadius: GLdouble, sides: GLint, rings: GLint); +#[cfg(not(target_os="android"))] pub fn glutSolidTorus(innerRadius: GLdouble, outerRadius: GLdouble, sides: GLint, rings: GLint); +#[cfg(not(target_os="android"))] pub fn glutWireDodecahedron(); +#[cfg(not(target_os="android"))] pub fn glutSolidDodecahedron(); +#[cfg(not(target_os="android"))] pub fn glutWireTeapot(size: GLdouble); +#[cfg(not(target_os="android"))] pub fn glutSolidTeapot(size: GLdouble); +#[cfg(not(target_os="android"))] pub fn glutWireOctahedron(); +#[cfg(not(target_os="android"))] pub fn glutSolidOctahedron(); +#[cfg(not(target_os="android"))] pub fn glutWireTetrahedron(); +#[cfg(not(target_os="android"))] pub fn glutSolidTetrahedron(); +#[cfg(not(target_os="android"))] pub fn glutWireIcosahedron(); +#[cfg(not(target_os="android"))] pub fn glutSolidIcosahedron(); +#[cfg(not(target_os="android"))] pub fn glutVideoResizeGet(param: GLenum) -> c_int; +#[cfg(not(target_os="android"))] pub fn glutSetupVideoResizing(); +#[cfg(not(target_os="android"))] pub fn glutStopVideoResizing(); +#[cfg(not(target_os="android"))] pub fn glutVideoResize(x: c_int, y: c_int, width: c_int, height: c_int); +#[cfg(not(target_os="android"))] pub fn glutVideoPan(x: c_int, y: c_int, width: c_int, height: c_int); +#[cfg(not(target_os="android"))] pub fn glutReportErrors(); +#[cfg(not(target_os="android"))] pub fn glutIgnoreKeyRepeat(ignore: c_int); +#[cfg(not(target_os="android"))] pub fn glutSetKeyRepeat(repeatMode: c_int); +#[cfg(not(target_os="android"))] pub fn glutForceJoystickFunc(); +#[cfg(not(target_os="android"))] pub fn glutGameModeString(string: *c_char); +#[cfg(not(target_os="android"))] pub fn glutEnterGameMode() -> c_int; +#[cfg(not(target_os="android"))] pub fn glutLeaveGameMode(); +#[cfg(not(target_os="android"))] pub fn glutGameModeGet(mode: GLenum) -> c_int; }