mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Kick off WebGL 2.0 implementation
This commit is contained in:
parent
fd4843a40e
commit
ddd6c86e99
14 changed files with 1665 additions and 68 deletions
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use canvas_traits::webgl::WebGLCommand;
|
||||
use canvas_traits::webgl::{WebGLCommand, WebGLVersion};
|
||||
use compositing::compositor_thread::{CompositorProxy, self};
|
||||
use euclid::Size2D;
|
||||
use gleam::gl;
|
||||
|
@ -41,9 +41,12 @@ impl GLContextFactory {
|
|||
}
|
||||
|
||||
/// Creates a new shared GLContext with the main GLContext
|
||||
pub fn new_shared_context(&self,
|
||||
size: Size2D<i32>,
|
||||
attributes: GLContextAttributes) -> Result<GLContextWrapper, &'static str> {
|
||||
pub fn new_shared_context(
|
||||
&self,
|
||||
webgl_version: WebGLVersion,
|
||||
size: Size2D<i32>,
|
||||
attributes: GLContextAttributes
|
||||
) -> Result<GLContextWrapper, &'static str> {
|
||||
match *self {
|
||||
GLContextFactory::Native(ref handle, ref dispatcher) => {
|
||||
let dispatcher = dispatcher.as_ref().map(|d| Box::new(d.clone()) as Box<_>);
|
||||
|
@ -51,7 +54,7 @@ impl GLContextFactory {
|
|||
attributes,
|
||||
ColorAttachmentType::Texture,
|
||||
gl::GlType::default(),
|
||||
GLVersion::Major(2),
|
||||
Self::gl_version(webgl_version),
|
||||
Some(handle),
|
||||
dispatcher);
|
||||
ctx.map(GLContextWrapper::Native)
|
||||
|
@ -61,7 +64,7 @@ impl GLContextFactory {
|
|||
attributes,
|
||||
ColorAttachmentType::Texture,
|
||||
gl::GlType::default(),
|
||||
GLVersion::Major(2),
|
||||
Self::gl_version(webgl_version),
|
||||
Some(handle),
|
||||
None);
|
||||
ctx.map(GLContextWrapper::OSMesa)
|
||||
|
@ -70,16 +73,19 @@ impl GLContextFactory {
|
|||
}
|
||||
|
||||
/// Creates a new non-shared GLContext
|
||||
pub fn new_context(&self,
|
||||
size: Size2D<i32>,
|
||||
attributes: GLContextAttributes) -> Result<GLContextWrapper, &'static str> {
|
||||
pub fn new_context(
|
||||
&self,
|
||||
webgl_version: WebGLVersion,
|
||||
size: Size2D<i32>,
|
||||
attributes: GLContextAttributes
|
||||
) -> Result<GLContextWrapper, &'static str> {
|
||||
match *self {
|
||||
GLContextFactory::Native(..) => {
|
||||
let ctx = GLContext::<NativeGLContext>::new_shared_with_dispatcher(size,
|
||||
attributes,
|
||||
ColorAttachmentType::Texture,
|
||||
gl::GlType::default(),
|
||||
GLVersion::Major(2),
|
||||
Self::gl_version(webgl_version),
|
||||
None,
|
||||
None);
|
||||
ctx.map(GLContextWrapper::Native)
|
||||
|
@ -89,13 +95,20 @@ impl GLContextFactory {
|
|||
attributes,
|
||||
ColorAttachmentType::Texture,
|
||||
gl::GlType::default(),
|
||||
GLVersion::Major(2),
|
||||
Self::gl_version(webgl_version),
|
||||
None,
|
||||
None);
|
||||
ctx.map(GLContextWrapper::OSMesa)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn gl_version(webgl_version: WebGLVersion) -> GLVersion {
|
||||
match webgl_version {
|
||||
WebGLVersion::WebGL1 => GLVersion::Major(2),
|
||||
WebGLVersion::WebGL2 => GLVersion::Major(3),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
|||
#[inline]
|
||||
fn handle_msg(&mut self, msg: WebGLMsg, webgl_chan: &WebGLChan) -> bool {
|
||||
match msg {
|
||||
WebGLMsg::CreateContext(size, attributes, result_sender) => {
|
||||
let result = self.create_webgl_context(size, attributes);
|
||||
WebGLMsg::CreateContext(version, size, attributes, result_sender) => {
|
||||
let result = self.create_webgl_context(version, size, attributes);
|
||||
result_sender.send(result.map(|(id, limits, share_mode)|
|
||||
WebGLCreateContextResult {
|
||||
sender: WebGLMsgSender::new(id, webgl_chan.clone()),
|
||||
|
@ -179,15 +179,16 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
|||
|
||||
/// Creates a new WebGLContext
|
||||
fn create_webgl_context(&mut self,
|
||||
version: WebGLVersion,
|
||||
size: Size2D<i32>,
|
||||
attributes: GLContextAttributes)
|
||||
-> Result<(WebGLContextId, GLLimits, WebGLContextShareMode), String> {
|
||||
// First try to create a shared context for the best performance.
|
||||
// Fallback to readback mode if the shared context creation fails.
|
||||
let result = self.gl_factory.new_shared_context(size, attributes)
|
||||
let result = self.gl_factory.new_shared_context(version, size, attributes)
|
||||
.map(|r| (r, WebGLContextShareMode::SharedTexture))
|
||||
.or_else(|_| {
|
||||
let ctx = self.gl_factory.new_context(size, attributes);
|
||||
let ctx = self.gl_factory.new_context(version, size, attributes);
|
||||
ctx.map(|r| (r, WebGLContextShareMode::Readback))
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue