Skip to content
Permalink
Browse files

Pass the GL context to the VRDisplay when rendering

  • Loading branch information...
asajeffrey committed Feb 21, 2019
1 parent 42ebf46 commit 8ddde7eacc6739db6d9e12086b03228460db67d4

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -11,6 +11,7 @@ use canvas_traits::webgl::{WebGLSender, WebVRCommand, WebVRRenderHandler};
use euclid::Size2D;
use fnv::FnvHashMap;
use gleam::gl;
use gleam::gl::Gl;
use servo_config::prefs::PREFS;
use std::rc::Rc;

@@ -112,8 +113,8 @@ impl WebGLExternalImageApi for WebGLExternalImages {
struct WebVRRenderWrapper(Box<dyn WebVRRenderHandler>);

impl WebVRRenderHandler for WebVRRenderWrapper {
fn handle(&mut self, command: WebVRCommand, texture: Option<(u32, Size2D<i32>)>) {
self.0.handle(command, texture);
fn handle(&mut self, gl: &dyn Gl, command: WebVRCommand, texture: Option<(u32, Size2D<i32>)>) {
self.0.handle(gl, command, texture);
}
}

@@ -210,15 +210,19 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {

/// Handles a WebVRCommand for a specific WebGLContext
fn handle_webvr_command(&mut self, context_id: WebGLContextId, command: WebVRCommand) {
Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id);
let texture = match command {
WebVRCommand::SubmitFrame(..) => self.cached_context_info.get(&context_id),
_ => None,
};
self.webvr_compositor
.as_mut()
.unwrap()
.handle(command, texture.map(|t| (t.texture_id, t.size)));
if let Some(context) =
Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
{
let texture = match command {
WebVRCommand::SubmitFrame(..) => self.cached_context_info.get(&context_id),
_ => None,
};
self.webvr_compositor.as_mut().unwrap().handle(
context.ctx.gl(),
command,
texture.map(|t| (t.texture_id, t.size)),
);
}
}

/// Handles a lock external callback received from webrender::ExternalImageHandler
@@ -4,6 +4,7 @@

use euclid::{Rect, Size2D};
use gleam::gl;
use gleam::gl::Gl;
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSharedMemory};
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use pixels::PixelFormat;
@@ -521,7 +522,7 @@ pub enum WebVRCommand {
// Trait object that handles WebVR commands.
// Receives the texture id and size associated to the WebGLContext.
pub trait WebVRRenderHandler: Send {
fn handle(&mut self, command: WebVRCommand, texture: Option<(u32, Size2D<i32>)>);
fn handle(&mut self, gl: &dyn Gl, command: WebVRCommand, texture: Option<(u32, Size2D<i32>)>);
}

/// WebGL commands required to implement DOMToTexture feature.
@@ -18,6 +18,7 @@ oculusvr = ['rust-webvr/oculusvr']
canvas_traits = {path = "../canvas_traits"}
crossbeam-channel = "0.3"
euclid = "0.19"
gleam = "0.6"
ipc-channel = "0.11"
log = "0.4"
msg = {path = "../msg"}
@@ -5,6 +5,7 @@
use canvas_traits::webgl;
use crossbeam_channel::{unbounded, Receiver, Sender};
use euclid::Size2D;
use gleam::gl::Gl;
use ipc_channel::ipc;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::constellation_msg::PipelineId;
@@ -376,7 +377,12 @@ impl WebVRCompositorHandler {

impl webgl::WebVRRenderHandler for WebVRCompositorHandler {
#[allow(unsafe_code)]
fn handle(&mut self, cmd: webgl::WebVRCommand, texture: Option<(u32, Size2D<i32>)>) {
fn handle(
&mut self,
gl: &dyn Gl,
cmd: webgl::WebVRCommand,
texture: Option<(u32, Size2D<i32>)>,
) {
match cmd {
webgl::WebVRCommand::Create(compositor_id) => {
if let Some(compositor) = self.create_compositor(compositor_id) {
@@ -400,10 +406,7 @@ impl webgl::WebVRRenderHandler for WebVRCompositorHandler {
right_bounds: right_bounds,
texture_size: Some((size.width as u32, size.height as u32)),
};
unsafe {
(*compositor.0).render_layer(&layer);
(*compositor.0).submit_frame();
}
unsafe { (*compositor.0).submit_layer(gl, &layer) };
}
}
},
@@ -13,5 +13,5 @@ path = "lib.rs"
[dependencies]
ipc-channel = "0.11"
msg = {path = "../msg"}
rust-webvr-api = {version = "0.10.2", features = ["ipc"]}
rust-webvr-api = {version = "0.10.3", features = ["ipc"]}
serde = "1.0"

0 comments on commit 8ddde7e

Please sign in to comment.
You can’t perform that action at this time.