Skip to content

Commit

Permalink
Draft for emscripten support
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Aug 23, 2014
1 parent d870fa7 commit 4c71ef1
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/emscripten/ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#![allow(dead_code)]
#![allow(non_snake_case_functions)]
#![allow(non_camel_case_types)]

use libc;

pub type EM_BOOL = libc::c_int;
pub type EM_UTF8 = libc::c_char;
pub type EMSCRIPTEN_WEBGL_CONTEXT_HANDLE = libc::c_int;
pub type EMSCRIPTEN_RESULT = libc::c_int;

pub type em_webgl_context_callback = extern fn(libc::c_int, *const libc::c_void, *mut libc::c_void)
-> EM_BOOL;

#[repr(C)]
pub struct EmscriptenWebGLContextAttributes {
alpha: EM_BOOL,
depth: EM_BOOL,
stencil: EM_BOOL,
antialias: EM_BOOL,
premultipliedAlpha: EM_BOOL,
preserveDrawingBuffer: EM_BOOL,
preferLowPowerToHighPerformance: EM_BOOL,
failIfMajorPerformanceCaveat: EM_BOOL,
majorVersion: libc::c_int,
minorVersion: libc::c_int,
enableExtensionsByDefault: EM_BOOL,
}

// values for EMSCRIPTEN_RESULT
pub static EMSCRIPTEN_RESULT_SUCCESS: libc::c_int = 0;
pub static EMSCRIPTEN_RESULT_DEFERRED: libc::c_int = 1;
pub static EMSCRIPTEN_RESULT_NOT_SUPPORTED: libc::c_int = -1;
pub static EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED: libc::c_int = -2;
pub static EMSCRIPTEN_RESULT_INVALID_TARGET: libc::c_int = -3;
pub static EMSCRIPTEN_RESULT_UNKNOWN_TARGET: libc::c_int = -4;
pub static EMSCRIPTEN_RESULT_INVALID_PARAM: libc::c_int = -5;
pub static EMSCRIPTEN_RESULT_FAILED: libc::c_int = -6;
pub static EMSCRIPTEN_RESULT_NO_DATA: libc::c_int = -7;

extern {
pub fn emscripten_webgl_init_context_attributes(attributes: *mut EmscriptenWebGLContextAttributes);
pub fn emscripten_webgl_create_context(target: *const libc::c_char,
attributes: *const EmscriptenWebGLContextAttributes);

pub fn emscripten_webgl_make_context_current(context: EMSCRIPTEN_WEBGL_CONTEXT_HANDLE)
-> EMSCRIPTEN_RESULT;

pub fn emscripten_webgl_get_current_context() -> EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;

pub fn emscripten_webgl_destroy_context(context: EMSCRIPTEN_WEBGL_CONTEXT_HANDLE)
-> EMSCRIPTEN_RESULT;

pub fn emscripten_webgl_enable_extension(context: EMSCRIPTEN_WEBGL_CONTEXT_HANDLE,
extension: *const libc::c_char) -> EM_BOOL;

pub fn emscripten_set_webglcontextlost_callback(target: *const libc::c_char,
userData: *mut libc::c_void, useCapture: EM_BOOL, callback: em_webgl_context_callback)
-> EMSCRIPTEN_RESULT;
pub fn emscripten_set_webglcontextrestored_callback(target: *const libc::c_char,
userData: *mut libc::c_void, useCapture: EM_BOOL, callback: em_webgl_context_callback)
-> EMSCRIPTEN_RESULT;

pub fn emscripten_is_webgl_context_lost(target: *const libc::c_char) -> EM_BOOL;
}
79 changes: 79 additions & 0 deletions src/emscripten/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use {Event, WindowBuilder};

mod ffi;

pub struct Window;

pub struct MonitorID;

pub fn get_available_monitors() -> Vec<MonitorID> {
vec![MonitorID]
}

pub fn get_primary_monitor() -> MonitorID {
MonitorID
}

impl MonitorID {
pub fn get_name(&self) -> Option<String> {
Some("Canvas".to_string())
}

pub fn get_dimensions(&self) -> (uint, uint) {
unimplemented!()
}
}

impl Window {
pub fn new(_builder: WindowBuilder) -> Result<Window, String> {
unimplemented!()
}

pub fn is_closed(&self) -> bool {
unimplemented!()
}

pub fn set_title(&self, _title: &str) {
unimplemented!()
}

pub fn get_position(&self) -> Option<(int, int)> {
unimplemented!()
}

pub fn set_position(&self, _x: int, _y: int) {
unimplemented!()
}

pub fn get_inner_size(&self) -> Option<(uint, uint)> {
unimplemented!()
}

pub fn get_outer_size(&self) -> Option<(uint, uint)> {
unimplemented!()
}

pub fn set_inner_size(&self, _x: uint, _y: uint) {
unimplemented!()
}

pub fn poll_events(&self) -> Vec<Event> {
unimplemented!()
}

pub fn wait_events(&self) -> Vec<Event> {
unimplemented!()
}

pub unsafe fn make_current(&self) {
unimplemented!()
}

pub fn get_proc_address(&self, _addr: &str) -> *const () {
unimplemented!()
}

pub fn swap_buffers(&self) {
unimplemented!()
}
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ use win32 as winimpl;
use x11 as winimpl;
#[cfg(target_os = "macos")]
use osx as winimpl;
#[cfg(target_os = "emscripten")]
use emscripten as winimpl;

#[cfg(target_os = "windows")]
mod win32;
#[cfg(target_os = "linux")]
mod x11;
#[cfg(target_os = "macos")]
mod osx;
#[cfg(target_os = "emscripten")]
mod emscripten;

#[allow(dead_code)]
//mod egl;
Expand Down

0 comments on commit 4c71ef1

Please sign in to comment.