diff --git a/Cargo.toml b/Cargo.toml index 4974e9f..98f90dfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "offscreen_gl_context" license = "MIT / Apache-2.0" edition = "2018" -version = "0.22.3" +version = "0.22.4" authors = ["Emilio Cobos Álvarez ", "The Servo Project Developers"] description = "Creation and manipulation of HW accelerated offscreen rendering contexts in multiple platforms. Originally intended for the Servo project's WebGL implementation." repository = "https://github.com/servo/rust-offscreen-rendering-context" diff --git a/src/gl_context.rs b/src/gl_context.rs index 854b865..c14c598 100644 --- a/src/gl_context.rs +++ b/src/gl_context.rs @@ -35,16 +35,16 @@ impl GLContext api_version: GLVersion, shared_with: Option<&Native::Handle>) -> Result { - Self::create_shared_with_dispatcher(api_type, api_version, shared_with, None) + Self::create_shared_with_dispatcher(&api_type, api_version, shared_with, None) } - pub fn create_shared_with_dispatcher(api_type: gl::GlType, + pub fn create_shared_with_dispatcher(api_type: &gl::GlType, api_version: GLVersion, shared_with: Option<&Native::Handle>, dispatcher: Option>) -> Result { let native_context = Native::create_shared_with_dispatcher(shared_with, - &api_type, + api_type, api_version, dispatcher)?; let gl_ = match api_type { @@ -55,7 +55,7 @@ impl GLContext native_context.make_current()?; let extensions = Self::query_extensions(&gl_, api_version); let attributes = GLContextAttributes::any(); - let formats = GLFormats::detect(&attributes, &extensions[..], api_version); + let formats = GLFormats::detect(&attributes, &extensions[..], api_type, api_version); let limits = GLLimits::detect(&*gl_); Ok(GLContext { @@ -107,12 +107,12 @@ impl GLContext // We create a headless context with a dummy size, we're painting to the // draw_buffer's framebuffer anyways. let mut context = - Self::create_shared_with_dispatcher(api_type, + Self::create_shared_with_dispatcher(&api_type, api_version, shared_with, dispatcher)?; - context.formats = GLFormats::detect(&attributes, &context.extensions[..], api_version); + context.formats = GLFormats::detect(&attributes, &context.extensions[..], &api_type, api_version); context.attributes = attributes; context.init_offscreen(size, color_attachment_type)?; diff --git a/src/gl_formats.rs b/src/gl_formats.rs index fcf522a..af83bea 100644 --- a/src/gl_formats.rs +++ b/src/gl_formats.rs @@ -21,62 +21,60 @@ impl GLFormats { // // FIXME: In linux with GLES2 texture attachments create INVALID_ENUM errors. // I suspect that it's because of texture formats, but I need time to debugit. - #[cfg(not(any(target_os="android", target_os="ios")))] - pub fn detect(attrs: &GLContextAttributes, extensions: &[String], api_version: GLVersion) -> GLFormats { + pub fn detect(attrs: &GLContextAttributes, extensions: &[String], api_type: &gl::GlType, api_version: GLVersion) -> GLFormats { let packed_depth_stencil = GLFormats::supports_packed_depth_stencil(&extensions, api_version); - if attrs.alpha { - GLFormats { - color_renderbuffer: gl::RGBA8, - texture_internal: gl::RGBA, - texture: gl::RGBA, - texture_type: gl::UNSIGNED_BYTE, - depth: gl::DEPTH_COMPONENT24, - stencil: gl::STENCIL_INDEX8, - packed_depth_stencil: packed_depth_stencil, - } - } else { - GLFormats { - color_renderbuffer: gl::RGB8, - texture_internal: gl::RGB8, - texture: gl::RGB, - texture_type: gl::UNSIGNED_BYTE, - depth: gl::DEPTH_COMPONENT24, - stencil: gl::STENCIL_INDEX8, - packed_depth_stencil: packed_depth_stencil, + match *api_type { + gl::GlType::Gl => { + let (color_renderbuffer, texture_internal, texture) = if attrs.alpha { + (gl::RGBA8, gl::RGBA, gl::RGBA) + } else { + (gl::RGB8, gl::RGB8, gl::RGB) + }; + + GLFormats { + color_renderbuffer, + texture_internal, + texture, + texture_type: gl::UNSIGNED_BYTE, + depth: gl::DEPTH_COMPONENT24, + stencil: gl::STENCIL_INDEX8, + packed_depth_stencil: packed_depth_stencil, + } } - } - } - #[cfg(any(target_os="android", target_os="ios"))] - pub fn detect(attrs: &GLContextAttributes, extensions: &[String], api_version: GLVersion) -> GLFormats { - // RGB8 or RGBA8 is guaranteed on OpenGLES 3+. - // On OpenGLES 2 detect via extensions if the GPU supports RGB8 and RGBA8 renderbuffer/texture storage formats. - // GL_ARM_rgba8 extension is similar to OES_rgb8_rgba8, but only exposes RGBA8. - let has_rgb8 = api_version.major_version() >= 3 || extensions.iter().any(|s| s == "GL_OES_rgb8_rgba8"); - let has_rgba8 = has_rgb8 || extensions.iter().any(|s| s == "GL_ARM_rgba8"); + gl::GlType::Gles => { + // RGB8 or RGBA8 is guaranteed on OpenGLES 3+. + // On OpenGLES 2 detect via extensions if the GPU supports RGB8 and RGBA8 renderbuffer/texture storage formats. + // GL_ARM_rgba8 extension is similar to OES_rgb8_rgba8, but only exposes RGBA8. + let has_rgb8 = api_version.major_version() >= 3 || extensions.iter().any(|s| s == "GL_OES_rgb8_rgba8"); + let has_rgba8 = has_rgb8 || extensions.iter().any(|s| s == "GL_ARM_rgba8"); - let packed_depth_stencil = GLFormats::supports_packed_depth_stencil(&extensions, api_version); + let (color_renderbuffer, texture_internal, texture, texture_type) = if attrs.alpha { + ( + if has_rgba8 { gl::RGBA8 } else { gl::RGBA4 }, + gl::RGBA, + gl::RGBA, + if has_rgba8 { gl::UNSIGNED_BYTE } else { gl::UNSIGNED_SHORT_4_4_4_4 }, + ) + } else { + ( + if has_rgb8 { gl::RGB8 } else { gl::RGB565 }, + gl::RGB, + gl::RGB, + if has_rgb8 { gl::UNSIGNED_BYTE } else { gl::UNSIGNED_SHORT_4_4_4_4 }, + ) + }; - if attrs.alpha { - GLFormats { - color_renderbuffer: if has_rgba8 { gl::RGBA8 } else { gl::RGBA4 }, - texture_internal: gl::RGBA, - texture: gl::RGBA, - texture_type: if has_rgba8 { gl::UNSIGNED_BYTE } else { gl::UNSIGNED_SHORT_4_4_4_4 }, - depth: gl::DEPTH_COMPONENT16, - stencil: gl::STENCIL_INDEX8, - packed_depth_stencil: packed_depth_stencil, - } - } else { - GLFormats { - color_renderbuffer: if has_rgb8 { gl::RGB8 } else { gl::RGB565 }, - texture_internal: gl::RGB, - texture: gl::RGB, - texture_type: if has_rgb8 { gl::UNSIGNED_BYTE } else { gl::UNSIGNED_SHORT_4_4_4_4 }, - depth: gl::DEPTH_COMPONENT16, - stencil: gl::STENCIL_INDEX8, - packed_depth_stencil: packed_depth_stencil, + GLFormats { + color_renderbuffer, + texture_internal, + texture, + texture_type, + depth: gl::DEPTH_COMPONENT16, + stencil: gl::STENCIL_INDEX8, + packed_depth_stencil: packed_depth_stencil, + } } } } diff --git a/src/platform/with_egl/native_gl_context.rs b/src/platform/with_egl/native_gl_context.rs index 0efce09..5087889 100644 --- a/src/platform/with_egl/native_gl_context.rs +++ b/src/platform/with_egl/native_gl_context.rs @@ -12,7 +12,7 @@ use libloading as lib; lazy_static! { static ref GL_LIB: Option = { let names = if cfg!(target_os="windows") { - &["libEGL.dll"][..] + &["libGLESv2.dll"][..] } else { &["libGLESv2.so", "libGL.so", "libGLESv3.so"][..] };