wip gl work

This commit is contained in:
Mark McCaskey 2019-07-05 16:32:49 -07:00
parent a5ce15b008
commit 097577b68a
7 changed files with 3715 additions and 15 deletions

2108
Cargo.lock generated

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
#![allow(non_snake_case)]
mod generated_gl;
pub mod window;
@ -27,8 +28,96 @@ pub fn graphics_imports() -> ImportObject {
"_emscripten_request_pointerlock" => func!(window::request_pointerlock),
"_emscripten_exit_pointerlock" => func!(window::exit_pointerlock),
"_emscripten_set_element_css_size" => func!(window::set_element_css_size),
// lel
"_emscripten_glBeginQueryEXT" => func!(_emscripten_glBeginQueryEXT),
"_emscripten_glBindVertexArrayOES" => func!(_emscripten_glBindVertexArrayOES),
"_emscripten_glDeleteQueriesEXT" => func!(_emscripten_glDeleteQueriesEXT),
"_emscripten_glDeleteVertexArraysOES" => func!(_emscripten_glDeleteVertexArraysOES),
"_emscripten_glDrawArraysInstancedANGLE" => func!(_emscripten_glDrawArraysInstancedANGLE),
"_emscripten_glDrawBuffersWEBGL" => func!(_emscripten_glDrawBuffersWEBGL),
"_emscripten_glDrawElementsInstancedANGLE" => func!(_emscripten_glDrawElementsInstancedANGLE),
"_emscripten_glEndQueryEXT" => func!(_emscripten_glEndQueryEXT),
"_emscripten_glGenQueriesEXT" => func!(_emscripten_glGenQueriesEXT),
"_emscripten_glGenVertexArraysOES" => func!(_emscripten_glGenVertexArraysOES),
"_emscripten_glGetQueryObjecti64vEXT" => func!(_emscripten_glGetQueryObjecti64vEXT),
"_emscripten_glGetQueryObjectivEXT" => func!(_emscripten_glGetQueryObjectivEXT),
"_emscripten_glGetQueryObjectui64vEXT" => func!(_emscripten_glGetQueryObjectui64vEXT),
"_emscripten_glGetQueryObjectuivEXT" => func!(_emscripten_glGetQueryObjectuivEXT),
"_emscripten_glGetQueryivEXT" => func!(_emscripten_glGetQueryivEXT),
"_emscripten_glIsQueryEXT" => func!(_emscripten_glIsQueryEXT),
"_emscripten_glIsVertexArrayOES" => func!(_emscripten_glIsVertexArrayOES),
"_emscripten_glQueryCounterEXT" => func!(_emscripten_glQueryCounterEXT),
"_emscripten_glVertexAttribDivisorANGLE" => func!(_emscripten_glVertexAttribDivisorANGLE),
},
};
base_imports.extend(gl_imports());
base_imports
}
use wasmer_runtime_core::vm::Ctx;
fn _emscripten_glBeginQueryEXT(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glBeginQueryEXT - stub");
}
fn _emscripten_glBindVertexArrayOES(_ctx: &mut Ctx, _a: i32) {
debug!("emscripten::_glBindVertexArrayOES - stub");
}
fn _emscripten_glDeleteQueriesEXT(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glDeleteQueriesEXT - stub");
}
fn _emscripten_glDeleteVertexArraysOES(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glDeleteVertexArraysOES - stub");
}
fn _emscripten_glDrawArraysInstancedANGLE(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) {
debug!("emscripten::_glDrawArraysInstancedANGLE - stub");
}
fn _emscripten_glDrawBuffersWEBGL(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glDrawBuffersWEBGL - stub");
}
fn _emscripten_glDrawElementsInstancedANGLE(
_ctx: &mut Ctx,
_a: i32,
_b: i32,
_c: i32,
_d: i32,
_e: i32,
) {
debug!("emscripten::_glDrawElementsInstancedANGLE - stub");
}
fn _emscripten_glEndQueryEXT(_ctx: &mut Ctx, _a: i32) {
debug!("emscripten::_glEndQueryEXT - stub");
}
fn _emscripten_glGenQueriesEXT(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glGenQueriesEXT - stub");
}
fn _emscripten_glGenVertexArraysOES(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glGenVertexArraysOES - stub");
}
fn _emscripten_glGetQueryObjecti64vEXT(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) {
debug!("emscripten::_glGetQueryObjecti64vEXT - stub");
}
fn _emscripten_glGetQueryObjectivEXT(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) {
debug!("emscripten::_glGetQueryObjectivEXT - stub");
}
fn _emscripten_glGetQueryObjectui64vEXT(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) {
debug!("emscripten::_glGetQueryObjectui64vEXT - stub");
}
fn _emscripten_glGetQueryObjectuivEXT(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) {
debug!("emscripten::_glGetQueryObjectuivEXT - stub");
}
fn _emscripten_glGetQueryivEXT(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) {
debug!("emscripten::_glGetQueryivEXT - stub");
}
fn _emscripten_glIsQueryEXT(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_glIsQueryEXT - stub");
0
}
fn _emscripten_glIsVertexArrayOES(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_glIsVertexArrayOES - stub");
0
}
fn _emscripten_glQueryCounterEXT(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glQueryCounterEXT - stub");
}
fn _emscripten_glVertexAttribDivisorANGLE(_ctx: &mut Ctx, _a: i32, _b: i32) {
debug!("emscripten::_glVertexAttribDivisorANGLE - stub");
}

View File

@ -1,22 +1,88 @@
use crate::env::get_emscripten_data;
use wasmer_runtime_core::vm::Ctx;
use crate::env::{call_malloc_with_cast, get_emscripten_data};
use wasmer_runtime_core::{memory::ptr::WasmPtr, types::ValueType, vm::Ctx};
pub fn asm_const_v(_ctx: &mut Ctx, _code: i32) {
debug!("emscripten::asm_const_v");
}
pub fn set_main_loop(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) {
pub fn set_main_loop(_ctx: &mut Ctx, _func: i32, _fps: i32, _inf: i32) {
debug!("emscripten::set_main_loop");
use crate::wasmer_runtime_core::structures::TypedIndex;
let f = unsafe {
let module: &wasmer_runtime_core::module::ModuleInner = &*_ctx.module;
let mut p_func = module
.runnable_module
.get_func(
&module.info,
wasmer_runtime_core::types::LocalFuncIndex::new(_func as usize),
)
.unwrap();
let sig = get_emscripten_data(_ctx).take_nothing_give_nothing.inner;
let func: wasmer_runtime_core::Func<(), ()> =
wasmer_runtime_core::Func::from_raw_parts(sig, p_func, _ctx);
func
};
loop {
debug!("Main loop iter");
f.call();
}
}
pub fn webgl_create_context(ctx: &mut Ctx, _a0: i32, _a1: i32) -> i32 {
debug!("emscripten::create_context");
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct EmContextAttributes {
pub alpha: bool,
_pad0: [u8; 3],
pub depth: bool,
_pad1: [u8; 3],
pub stencil: bool,
_pad2: [u8; 3],
pub antialias: bool,
_pad3: [u8; 3],
pub premultiplied_alpha: bool,
_pad4: [u8; 3],
pub preserve_drawing_buffer: bool,
_pad5: [u8; 3],
pub power_preference: bool,
_pad6: [u8; 3],
pub fail_if_major_performance_caveat: bool,
_pad7: [u8; 3],
pub major_version: i32,
pub minor_version: i32,
pub enable_extensions_by_default: i32,
pub explicit_swap_control: i32,
pub proxy_content_to_main_thread: i32,
pub render_via_offscreen_back_buffer: i32,
}
unsafe impl ValueType for EmContextAttributes {}
pub fn webgl_create_context(
ctx: &mut Ctx,
_target: i32,
_attributes: WasmPtr<EmContextAttributes>,
) -> i32 {
debug!(
"emscripten::create_context, target: {}, attributes: {:?}",
_target, _attributes
);
let render = Render::new();
//translate this pointer
let gl_ctx_ptr = unsafe { render.gl_context.raw() };
let data = get_emscripten_data(ctx);
data.render = Some(render);
gl_ctx_ptr as i32
let ptr: WasmPtr<u64> = call_malloc_with_cast(ctx, std::mem::size_of::<u64>() as _);
// is there a worse idea than passing a host pointer into your guest and then trusting it when it gives it back?
unsafe {
ptr.deref_mut(ctx.memory(0))
.unwrap()
.set(gl_ctx_ptr as usize as u64);
}
//gl_ctx_ptr as i32
ptr.offset() as i32
}
pub fn request_fullscreen(ctx: &mut Ctx, _a0: i32, _a1: i32) -> i32 {
@ -169,6 +235,7 @@ impl Render {
.unwrap();
let gl_context = window.gl_create_context().unwrap();
gl::load_with(|s| unsafe { std::mem::transmute(video_subsystem.gl_get_proc_address(s)) });
let canvas = window.into_canvas().build().unwrap();
Self {

View File

@ -160,6 +160,8 @@ pub struct EmscriptenData<'a> {
pub set_threw: Option<Func<'a, (i32, i32)>>,
#[cfg(feature = "opengl")]
pub render: Option<gl::window::Render>,
#[cfg(feature = "opengl")]
pub take_nothing_give_nothing: Func<'a, (), ()>,
pub mapped_dirs: HashMap<String, PathBuf>,
}
@ -233,6 +235,9 @@ impl<'a> EmscriptenData<'a> {
let stack_restore = instance.func("stackRestore").ok();
let set_threw = instance.func("_setThrew").ok();
#[cfg(feature = "opengl")]
let take_nothing_give_nothing = instance.func("take_nothing_give_nothing").unwrap();
EmscriptenData {
malloc,
free,
@ -303,6 +308,8 @@ impl<'a> EmscriptenData<'a> {
set_threw,
#[cfg(feature = "opengl")]
render: None,
#[cfg(feature = "opengl")]
take_nothing_give_nothing,
mapped_dirs,
}
}

View File

@ -157,7 +157,7 @@ where
// }
pub struct Func<'a, Args = (), Rets = (), Inner: Kind = Wasm> {
inner: Inner,
pub inner: Inner,
f: NonNull<vm::Func>,
ctx: *mut Ctx,
_phantom: PhantomData<(&'a (), Args, Rets)>,
@ -168,7 +168,7 @@ where
Args: WasmTypeList,
Rets: WasmTypeList,
{
pub(crate) unsafe fn from_raw_parts(
pub unsafe fn from_raw_parts(
inner: Wasm,
f: NonNull<vm::Func>,
ctx: *mut Ctx,

@ -1 +1 @@
Subproject commit b3cc4f4d76af8ef80570e284c9d7c751d1ce1392
Subproject commit 5d28d230664aed9aae7e9b99f64000e2e813daf9