Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the emscripten port of glutin #668

Merged
merged 1 commit into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ shared_library = "0.1.0"
gl_generator = "0.4"
khronos_api = "1.0"

[dev-dependencies]
clock_ticks = "0.1.0"

[target.arm-linux-androideabi.dependencies.android_glue]
version = "0.1"

Expand Down
4 changes: 2 additions & 2 deletions examples/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ pub fn load(window: &glutin::Window) -> Context {

unsafe {
let vs = gl.CreateShader(gl::VERTEX_SHADER);
gl.ShaderSource(vs, 1, [VS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
gl.ShaderSource(vs, 1, [VS_SRC.as_ptr() as *const _].as_ptr(), ptr::null());
gl.CompileShader(vs);

let fs = gl.CreateShader(gl::FRAGMENT_SHADER);
gl.ShaderSource(fs, 1, [FS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
gl.ShaderSource(fs, 1, [FS_SRC.as_ptr() as *const _].as_ptr(), ptr::null());
gl.CompileShader(fs);

let program = gl.CreateProgram();
Expand Down
2 changes: 1 addition & 1 deletion src/api/caca/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(any(target_os = "linux", target_os = "freebsd"))]
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
#![allow(unused_variables, dead_code)]

use libc;
Expand Down
39 changes: 31 additions & 8 deletions src/api/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

use std::ffi::CString;
use libc;
use {Event, BuilderAttribs, CreationError, MouseCursor};
use Api;
use PixelFormat;
use Event;
use CreationError;
use ContextError;
use CursorState;
use GlAttributes;
use GlContext;
use MouseCursor;
use PixelFormat;
use PixelFormatRequirements;
use WindowAttributes;

use std::collections::VecDeque;

Expand Down Expand Up @@ -52,6 +58,7 @@ impl WindowProxy {
}
}

#[derive(Clone)]
pub struct MonitorId;

#[inline]
Expand All @@ -72,14 +79,21 @@ impl MonitorId {
Some("Canvas".to_owned())
}

#[inline]
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
::native_monitor::NativeMonitorId::Unavailable
}

#[inline]
pub fn get_dimensions(&self) -> (u32, u32) {
unimplemented!()
}
}

impl Window {
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
{
// getting the default values of attributes
let mut attributes = unsafe {
use std::mem;
Expand Down Expand Up @@ -198,14 +212,23 @@ impl Window {
}

#[inline]
pub fn set_cursor(&self, _cursor: MouseCursor) {
unimplemented!()
pub fn set_cursor(&self, cursor: MouseCursor) {
}

#[inline]
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
Ok(())
}

#[inline]
pub fn hidpi_factor(&self) -> f32 {
1.0
}

#[inline]
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
Ok(())
}
}

impl GlContext for Window {
Expand All @@ -222,11 +245,11 @@ impl GlContext for Window {
}

fn get_proc_address(&self, addr: &str) -> *const () {
let addr = CString::new(addr.as_bytes()).unwrap();
let addr = addr.as_ptr();
let addr = CString::new(addr).unwrap();

unsafe {
ffi::emscripten_GetProcAddress(addr) as *const _
// FIXME: if `as_ptr()` is used, then wrong data is passed to emscripten
ffi::emscripten_GetProcAddress(addr.into_raw() as *const _) as *const _
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/osmesa/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]

extern crate osmesa_sys;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern crate cocoa;
extern crate core_foundation;
#[cfg(target_os = "macos")]
extern crate core_graphics;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
extern crate x11_dl;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
#[macro_use(wayland_env)]
Expand Down
11 changes: 9 additions & 2 deletions src/platform/emscripten/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#![cfg(target_os = "emscripten")]

use Api;
use ContextError;
use CreationError;
use GlAttributes;
use GlContext;
use PixelFormat;
use PixelFormatRequirements;

pub use api::emscripten::{Window, WindowProxy, MonitorId, get_available_monitors};
pub use api::emscripten::{get_primary_monitor, WaitEventsIterator, PollEventsIterator};
Expand All @@ -11,8 +16,10 @@ pub struct HeadlessContext(Window);
impl HeadlessContext {
/// See the docs in the crate root file.
#[inline]
pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
Window::new(builder).map(|w| HeadlessContext(w))
pub fn new(_: (u32, u32), _: &PixelFormatRequirements, _: &GlAttributes<&HeadlessContext>)
-> Result<HeadlessContext, CreationError>
{
unimplemented!()
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ mod platform;
#[cfg(target_os = "ios")]
#[path="ios/mod.rs"]
mod platform;
#[cfg(target_os = "emscripten")]
#[path="emscripten/mod.rs"]
mod platform;

#[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"),
not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"),
not(target_os = "freebsd")))]
not(target_os = "freebsd"), not(target_os = "emscripten")))]
use this_platform_is_not_supported;