Kick off WebGL 2.0 implementation

This commit is contained in:
Imanol Fernandez 2017-10-26 18:04:13 +02:00
parent fd4843a40e
commit ddd6c86e99
14 changed files with 1665 additions and 68 deletions

View file

@ -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),
}
}
}