mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Clean up create_webgl_context
This commit is contained in:
parent
57053e03bb
commit
99b6091b7a
1 changed files with 37 additions and 39 deletions
|
@ -216,50 +216,48 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new WebGLContext
|
/// Creates a new WebGLContext
|
||||||
fn create_webgl_context(&mut self,
|
fn create_webgl_context(
|
||||||
version: WebGLVersion,
|
&mut self,
|
||||||
size: Size2D<i32>,
|
version: WebGLVersion,
|
||||||
attributes: GLContextAttributes)
|
size: Size2D<i32>,
|
||||||
-> Result<(WebGLContextId, GLLimits, WebGLContextShareMode), String> {
|
attributes: GLContextAttributes,
|
||||||
// First try to create a shared context for the best performance.
|
) -> Result<(WebGLContextId, GLLimits, WebGLContextShareMode), String> {
|
||||||
// Fallback to readback mode if the shared context creation fails.
|
|
||||||
let result = self.gl_factory.new_shared_context(version, size, attributes)
|
|
||||||
.map(|r| (r, WebGLContextShareMode::SharedTexture))
|
|
||||||
.or_else(|err| {
|
|
||||||
warn!("Couldn't create shared GL context ({}), using slow \
|
|
||||||
readback context instead.", err);
|
|
||||||
let ctx = self.gl_factory.new_context(version, size, attributes);
|
|
||||||
ctx.map(|r| (r, WebGLContextShareMode::Readback))
|
|
||||||
});
|
|
||||||
|
|
||||||
// Creating a new GLContext may make the current bound context_id dirty.
|
// Creating a new GLContext may make the current bound context_id dirty.
|
||||||
// Clear it to ensure that make_current() is called in subsequent commands.
|
// Clear it to ensure that make_current() is called in subsequent commands.
|
||||||
self.bound_context_id = None;
|
self.bound_context_id = None;
|
||||||
|
|
||||||
match result {
|
// First try to create a shared context for the best performance.
|
||||||
Ok((ctx, share_mode)) => {
|
// Fallback to readback mode if the shared context creation fails.
|
||||||
let id = WebGLContextId(self.next_webgl_id);
|
let (ctx, share_mode) = self.gl_factory
|
||||||
let (size, texture_id, limits) = ctx.get_info();
|
.new_shared_context(version, size, attributes)
|
||||||
self.next_webgl_id += 1;
|
.map(|r| (r, WebGLContextShareMode::SharedTexture))
|
||||||
self.contexts.insert(id, GLContextData {
|
.or_else(|err| {
|
||||||
ctx,
|
warn!(
|
||||||
state: Default::default(),
|
"Couldn't create shared GL context ({}), using slow readback context instead.",
|
||||||
});
|
err
|
||||||
self.cached_context_info.insert(id, WebGLContextInfo {
|
);
|
||||||
texture_id,
|
let ctx = self.gl_factory.new_context(version, size, attributes)?;
|
||||||
size,
|
Ok((ctx, WebGLContextShareMode::Readback))
|
||||||
alpha: attributes.alpha,
|
})
|
||||||
image_key: None,
|
.map_err(|msg| msg.to_owned())?;
|
||||||
share_mode,
|
|
||||||
gl_sync: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok((id, limits, share_mode))
|
let id = WebGLContextId(self.next_webgl_id);
|
||||||
},
|
let (size, texture_id, limits) = ctx.get_info();
|
||||||
Err(msg) => {
|
self.next_webgl_id += 1;
|
||||||
Err(msg.to_owned())
|
self.contexts.insert(id, GLContextData {
|
||||||
}
|
ctx,
|
||||||
}
|
state: Default::default(),
|
||||||
|
});
|
||||||
|
self.cached_context_info.insert(id, WebGLContextInfo {
|
||||||
|
texture_id,
|
||||||
|
size,
|
||||||
|
alpha: attributes.alpha,
|
||||||
|
image_key: None,
|
||||||
|
share_mode,
|
||||||
|
gl_sync: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok((id, limits, share_mode))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resizes a WebGLContext
|
/// Resizes a WebGLContext
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue