diff --git a/Cargo.toml b/Cargo.toml index f3bf8e9..75b5c37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "offscreen_gl_context" license = "MIT / Apache-2.0" edition = "2018" -version = "0.24.0" +version = "0.25.0" 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" @@ -20,11 +20,11 @@ test_egl_in_linux = ["libloading", "lazy_static"] [dependencies] euclid = "0.20" -gleam = "0.7" lazy_static = { version = "1", optional = true } libloading = { version = "0.5", optional = true, default-features = false } log = "0.4" osmesa-sys = { version = "0.1", optional = true } +sparkle = "0.1.3" serde = { version = "1.0", optional = true } [target.x86_64-apple-darwin.dependencies] diff --git a/src/draw_buffer.rs b/src/draw_buffer.rs index 6a72f45..b1648e1 100644 --- a/src/draw_buffer.rs +++ b/src/draw_buffer.rs @@ -1,6 +1,6 @@ use euclid::default::Size2D; -use gleam::gl; -use gleam::gl::types::{GLuint, GLenum, GLint}; +use sparkle::gl; +use sparkle::gl::types::{GLuint, GLenum, GLint}; use std::rc::Rc; use crate::GLContext; @@ -38,7 +38,7 @@ impl ColorAttachment { } } - fn destroy(self, gl: &dyn gl::Gl) { + fn destroy(self, gl: &gl::Gl) { match self { ColorAttachment::Renderbuffer(id) => gl.delete_renderbuffers(&[id]), ColorAttachment::Texture(tex_id) => gl.delete_textures(&[tex_id]), @@ -52,7 +52,7 @@ impl ColorAttachment { /// packed or independent depth or stencil buffers, /// depending on context requirements. pub struct DrawBuffer { - gl_: Rc, + gl_: Rc, size: Size2D, framebuffer: GLuint, color_attachment: Option, @@ -65,7 +65,7 @@ pub struct DrawBuffer { /// Helper function to create a render buffer /// TODO(emilio): We'll need to switch between `glRenderbufferStorage` and /// `glRenderbufferStorageMultisample` when we support antialising -fn create_renderbuffer(gl_: &dyn gl::Gl, +fn create_renderbuffer(gl_: &gl::Gl, format: GLenum, size: &Size2D) -> GLuint { let ret = gl_.gen_renderbuffers(1)[0]; @@ -120,7 +120,7 @@ impl DrawBuffer { draw_buffer.init(context, color_attachment_type)?; - debug_assert_eq!(draw_buffer.gl().check_frame_buffer_status(gl::FRAMEBUFFER), + debug_assert_eq!(draw_buffer.gl().check_framebuffer_status(gl::FRAMEBUFFER), gl::FRAMEBUFFER_COMPLETE); debug_assert_eq!(draw_buffer.gl().get_error(), gl::NO_ERROR); @@ -159,7 +159,7 @@ impl DrawBuffer { } } - fn gl(&self) -> &dyn gl::Gl { + fn gl(&self) -> &gl::Gl { &*self.gl_ } @@ -233,7 +233,7 @@ impl DrawBuffer { fn attach_to_framebuffer(&mut self) -> Result<(), &'static str> { self.gl().bind_framebuffer(gl::FRAMEBUFFER, self.framebuffer); // NOTE: The assertion fails if the framebuffer is not bound - debug_assert_eq!(self.gl().is_framebuffer(self.framebuffer), gl::TRUE); + debug_assert!(self.gl().is_framebuffer(self.framebuffer)); match *self.color_attachment.as_ref().unwrap() { ColorAttachment::Renderbuffer(color_renderbuffer) => { @@ -241,7 +241,7 @@ impl DrawBuffer { gl::COLOR_ATTACHMENT0, gl::RENDERBUFFER, color_renderbuffer); - debug_assert_eq!(self.gl().is_renderbuffer(color_renderbuffer), gl::TRUE); + debug_assert!(self.gl().is_renderbuffer(color_renderbuffer)); }, ColorAttachment::Texture(texture_id) => { self.gl().framebuffer_texture_2d(gl::FRAMEBUFFER, @@ -256,7 +256,7 @@ impl DrawBuffer { gl::DEPTH_STENCIL_ATTACHMENT, gl::RENDERBUFFER, self.packed_depth_stencil_renderbuffer); - debug_assert_eq!(self.gl().is_renderbuffer(self.packed_depth_stencil_renderbuffer), gl::TRUE); + debug_assert!(self.gl().is_renderbuffer(self.packed_depth_stencil_renderbuffer)); } if self.depth_renderbuffer != 0 { @@ -264,7 +264,7 @@ impl DrawBuffer { gl::DEPTH_ATTACHMENT, gl::RENDERBUFFER, self.depth_renderbuffer); - debug_assert_eq!(self.gl().is_renderbuffer(self.depth_renderbuffer), gl::TRUE); + debug_assert!(self.gl().is_renderbuffer(self.depth_renderbuffer)); } if self.stencil_renderbuffer != 0 { @@ -272,7 +272,7 @@ impl DrawBuffer { gl::STENCIL_ATTACHMENT, gl::RENDERBUFFER, self.stencil_renderbuffer); - debug_assert_eq!(self.gl().is_renderbuffer(self.stencil_renderbuffer), gl::TRUE); + debug_assert!(self.gl().is_renderbuffer(self.stencil_renderbuffer)); } Ok(()) diff --git a/src/gl_context.rs b/src/gl_context.rs index 8a9b8f5..243e397 100644 --- a/src/gl_context.rs +++ b/src/gl_context.rs @@ -1,6 +1,6 @@ use euclid::default::Size2D; -use gleam::gl; -use gleam::gl::types::{GLuint}; +use sparkle::gl; +use sparkle::gl::types::{GLuint}; use std::rc::Rc; use crate::NativeGLContextMethods; @@ -13,7 +13,7 @@ use crate::ColorAttachmentType; /// This is a wrapper over a native headless GL context pub struct GLContext { - gl_: Rc, + gl_: Rc, native_context: Native, /// This an abstraction over a custom framebuffer /// with attachments according to WebGLContextAttributes @@ -48,12 +48,16 @@ impl GLContext api_version, dispatcher)?; let gl_ = match api_type { - gl::GlType::Gl => unsafe { gl::GlFns::load_with(|s| Self::get_proc_address(s) as *const _) }, - gl::GlType::Gles => unsafe { gl::GlesFns::load_with(|s| Self::get_proc_address(s) as *const _) }, + gl::GlType::Gl => gl::Gl::gl_fns( + gl::ffi_gl::Gl::load_with(|s| Self::get_proc_address(s) as *const _) + ), + gl::GlType::Gles => gl::Gl::gles_fns( + gl::ffi_gles::Gles2::load_with(|s| Self::get_proc_address(s) as *const _) + ), }; native_context.make_current()?; - let extensions = Self::query_extensions(&gl_, api_version); + let extensions = Self::query_extensions(&*gl_, api_version); let attributes = GLContextAttributes::any(); let formats = GLFormats::detect(&attributes, &extensions[..], api_type, api_version); let limits = GLLimits::detect(&*gl_); @@ -163,11 +167,11 @@ impl GLContext self.native_context.handle() } - pub fn gl(&self) -> &dyn gl::Gl { + pub fn gl(&self) -> &gl::Gl { &*self.gl_ } - pub fn clone_gl(&self) -> Rc { + pub fn clone_gl(&self) -> Rc { self.gl_.clone() } @@ -242,7 +246,7 @@ impl GLContext Ok(()) } - fn query_extensions(gl_: &Rc, api_version: GLVersion) -> Vec { + fn query_extensions(gl_: &gl::Gl, api_version: GLVersion) -> Vec { if api_version.major_version() >=3 { // glGetString(GL_EXTENSIONS) is deprecated on OpenGL >= 3.x. // Some GL backends such as CGL generate INVALID_ENUM error when used. diff --git a/src/gl_context_capabilities.rs b/src/gl_context_capabilities.rs index f92b4e8..17d1745 100644 --- a/src/gl_context_capabilities.rs +++ b/src/gl_context_capabilities.rs @@ -1,5 +1,4 @@ -// use gleam::gl; -use gleam::gl::{GLint}; +use sparkle::gl::{GLint}; #[allow(unused_imports)] use crate::GLFeature; diff --git a/src/gl_formats.rs b/src/gl_formats.rs index af83bea..672828d 100644 --- a/src/gl_formats.rs +++ b/src/gl_formats.rs @@ -1,5 +1,5 @@ -use gleam::gl::types::GLenum; -use gleam::gl; +use sparkle::gl; +use sparkle::gl::GLenum; use crate::GLContextAttributes; use crate::GLVersion; diff --git a/src/gl_limits.rs b/src/gl_limits.rs index 05277aa..45db942 100644 --- a/src/gl_limits.rs +++ b/src/gl_limits.rs @@ -1,4 +1,4 @@ -use gleam::gl; +use sparkle::gl; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -65,7 +65,7 @@ macro_rules! gl_integer { } } -fn gl_fallible_integer(gl_: &dyn gl::Gl, pname: gl::GLenum) -> Result { +fn gl_fallible_integer(gl_: &gl::Gl, pname: gl::GLenum) -> Result { let mut val = [0]; unsafe { gl_.get_integer_v(pname, &mut val); @@ -79,7 +79,7 @@ fn gl_fallible_integer(gl_: &dyn gl::Gl, pname: gl::GLenum) -> Result { } impl GLLimits { - pub fn detect(gl_: &dyn gl::Gl) -> GLLimits { + pub fn detect(gl_: &gl::Gl) -> GLLimits { let max_vertex_attribs = gl_integer!(gl_, MAX_VERTEX_ATTRIBS); let max_tex_size = gl_integer!(gl_, MAX_TEXTURE_SIZE); let max_cube_map_tex_size = gl_integer!(gl_, MAX_CUBE_MAP_TEXTURE_SIZE); diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 52559e9..41a3c1a 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -1,5 +1,5 @@ use crate::gl_context::{GLContextDispatcher, GLVersion}; -use gleam::gl; +use sparkle::gl; pub trait NativeGLContextMethods: Sized { type Handle; diff --git a/src/platform/not_implemented/native_gl_context.rs b/src/platform/not_implemented/native_gl_context.rs index 8fe2b74..21c1b2b 100644 --- a/src/platform/not_implemented/native_gl_context.rs +++ b/src/platform/not_implemented/native_gl_context.rs @@ -1,6 +1,6 @@ -use gleam::gl; use crate::NativeGLContextMethods; use crate::GLVersion; +use sparkle::gl; pub struct NativeGLContext; pub struct NativeGLContextHandle; diff --git a/src/platform/with_cgl/native_gl_context.rs b/src/platform/with_cgl/native_gl_context.rs index f359986..5ed0eab 100644 --- a/src/platform/with_cgl/native_gl_context.rs +++ b/src/platform/with_cgl/native_gl_context.rs @@ -4,7 +4,7 @@ use std::mem; use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName}; use core_foundation::base::TCFType; use core_foundation::string::CFString; -use gleam::gl; +use sparkle::gl; use std::str::FromStr; use std::sync::Mutex; @@ -41,13 +41,14 @@ impl NativeGLContext { None => 0 as CGLContextObj }; - let mut native: CGLContextObj = unsafe { mem::uninitialized() }; + let mut native = mem::MaybeUninit::uninit(); - unsafe { - if CGLCreateContext(*pixel_format, shared, &mut native) != 0 { + let native = unsafe { + if CGLCreateContext(*pixel_format, shared, native.as_mut_ptr()) != 0 { return Err("CGLCreateContext"); } - } + native.assume_init() + }; debug_assert!(native != 0 as CGLContextObj); @@ -134,18 +135,19 @@ impl NativeGLContextMethods for NativeGLContext { 0 ]; - let mut pixel_format : CGLPixelFormatObj = unsafe { mem::uninitialized() }; + let mut pixel_format = mem::MaybeUninit::uninit(); let mut pix_count = 0; - unsafe { - if CGLChoosePixelFormat(attributes.as_mut_ptr(), &mut pixel_format, &mut pix_count) != 0 { + let pixel_format = unsafe { + if CGLChoosePixelFormat(attributes.as_mut_ptr(), pixel_format.as_mut_ptr(), &mut pix_count) != 0 { return Err("CGLChoosePixelFormat"); } if pix_count == 0 { return Err("No pixel formats available"); } - } + pixel_format.assume_init() + }; let result = NativeGLContext::new(with.map(|handle| &handle.0), &pixel_format); diff --git a/src/platform/with_eagl/native_gl_context.rs b/src/platform/with_eagl/native_gl_context.rs index 8bce311..8136204 100644 --- a/src/platform/with_eagl/native_gl_context.rs +++ b/src/platform/with_eagl/native_gl_context.rs @@ -1,9 +1,9 @@ use crate::platform::NativeGLContextMethods; use crate::GLVersion; -use gleam::gl; use objc::runtime::{BOOL, NO}; use objc::runtime::{Class, Object}; use libloading as lib; +use sparkle::gl; use std::ops::Deref; use std::ptr; diff --git a/src/platform/with_egl/native_gl_context.rs b/src/platform/with_egl/native_gl_context.rs index 5087889..c526faa 100644 --- a/src/platform/with_egl/native_gl_context.rs +++ b/src/platform/with_egl/native_gl_context.rs @@ -5,9 +5,9 @@ use std::ffi::CString; use std::ops::Deref; use crate::egl; use crate::egl::types::{EGLint, EGLBoolean, EGLDisplay, EGLSurface, EGLConfig, EGLContext}; -use gleam::gl; use crate::GLVersion; use libloading as lib; +use sparkle::gl; lazy_static! { static ref GL_LIB: Option = { diff --git a/src/platform/with_egl/utils.rs b/src/platform/with_egl/utils.rs index d22cc51..d6420f4 100644 --- a/src/platform/with_egl/utils.rs +++ b/src/platform/with_egl/utils.rs @@ -5,7 +5,7 @@ use super::{NativeGLContext, NativeGLContextHandle}; use crate::GLVersion; use crate::egl; use crate::egl::types::{EGLNativeDisplayType, EGLDisplay, EGLConfig, EGLSurface, EGLint}; -use gleam::gl; +use sparkle::gl; fn create_pbuffer_surface(display: EGLDisplay, config: EGLConfig, size: Size2D) -> Result { let mut attrs = [ diff --git a/src/platform/with_glx/native_gl_context.rs b/src/platform/with_glx/native_gl_context.rs index f380511..0a81983 100644 --- a/src/platform/with_glx/native_gl_context.rs +++ b/src/platform/with_glx/native_gl_context.rs @@ -1,9 +1,9 @@ use std::ffi::CString; use crate::gl_context::GLVersion; -use gleam::gl; use crate::glx; use crate::glx_extra; +use sparkle::gl; use std::os::raw::*; use crate::glx::types::{GLXContext, GLXDrawable, GLXFBConfig, GLXPixmap}; use euclid::Size2D; diff --git a/src/platform/with_glx/utils.rs b/src/platform/with_glx/utils.rs index b1369cc..19c3e85 100644 --- a/src/platform/with_glx/utils.rs +++ b/src/platform/with_glx/utils.rs @@ -1,7 +1,7 @@ -use gleam::gl; use crate::glx; use x11::xlib::*; use glx::types::GLXDrawable; +use sparkle::gl; use std::ffi::CStr; use std::os::raw::*; use euclid::default::Size2D; diff --git a/src/platform/with_osmesa/mod.rs b/src/platform/with_osmesa/mod.rs index 0baaea0..1c4e8f7 100644 --- a/src/platform/with_osmesa/mod.rs +++ b/src/platform/with_osmesa/mod.rs @@ -3,7 +3,7 @@ use std::os::raw::c_int; use std::ptr; use crate::gl_context::GLVersion; -use gleam::gl; +use sparkle::gl; use crate::platform::NativeGLContextMethods; diff --git a/src/platform/with_wgl/native_gl_context.rs b/src/platform/with_wgl/native_gl_context.rs index 550db33..cffd7fe 100644 --- a/src/platform/with_wgl/native_gl_context.rs +++ b/src/platform/with_wgl/native_gl_context.rs @@ -1,7 +1,7 @@ use crate::platform::NativeGLContextMethods; -use gleam::gl; use crate::gl_context::GLContextDispatcher; use crate::GLVersion; +use sparkle::gl; use std::ffi::CString; use std::os::raw::c_void; use std::ptr; diff --git a/src/tests.rs b/src/tests.rs index 00200f5..d6db0de 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,5 +1,5 @@ -use gleam::gl; use euclid::Size2D; +use sparkle::gl; use crate::GLContext; #[cfg(all(target_os = "linux", feature = "test_egl_in_linux"))] @@ -46,7 +46,7 @@ fn test_unbinding(api_version: GLVersion) { let ctx = GLContext::::new(Size2D::new(256, 256), GLContextAttributes::default(), ColorAttachmentType::Renderbuffer, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); @@ -72,7 +72,7 @@ fn test_renderbuffer_color_attachment(api_version: GLVersion) { test_gl_context(&GLContext::::new(Size2D::new(256, 256), GLContextAttributes::default(), ColorAttachmentType::Renderbuffer, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap()); } @@ -92,7 +92,7 @@ fn test_texture_color_attachment(api_version: GLVersion) { let context = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); test_gl_context(&context); @@ -128,7 +128,7 @@ fn test_sharing(api_version: GLVersion) { let primary = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); @@ -138,7 +138,7 @@ fn test_sharing(api_version: GLVersion) { let secondary = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, Some(&primary.handle())).unwrap(); @@ -151,7 +151,7 @@ fn test_sharing(api_version: GLVersion) { assert!(secondary_texture_id != 0); primary.make_current().unwrap(); - assert!(primary.gl().is_texture(secondary_texture_id) != 0); + assert!(primary.gl().is_texture(secondary_texture_id)); // Clearing and re-binding to a framebuffer instead of using getTexImage // since it's not available in GLES2 @@ -189,7 +189,7 @@ fn test_multithread_render(api_version: GLVersion) { let primary = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); test_gl_context(&primary); @@ -200,7 +200,7 @@ fn test_multithread_render(api_version: GLVersion) { let secondary = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); secondary.make_current().unwrap(); @@ -249,7 +249,7 @@ fn test_multithread_sharing(api_version: GLVersion) { let primary = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); primary.make_current().unwrap(); @@ -269,7 +269,7 @@ fn test_multithread_sharing(api_version: GLVersion) { let secondary = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, Some(&primary_handle)).unwrap(); // Make the context current on this thread only @@ -325,7 +325,7 @@ fn test_limits(api_version: GLVersion) { let context = GLContext::::new(size, GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); assert!(context.borrow_limits().max_vertex_attribs != 0); @@ -349,7 +349,7 @@ fn test_no_alpha(api_version: GLVersion) { let context = GLContext::::new(size, attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); assert!(context.borrow_limits().max_vertex_attribs != 0); @@ -373,7 +373,7 @@ fn test_no_depth(api_version: GLVersion) { let context = GLContext::::new(size, attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); assert!(context.borrow_limits().max_vertex_attribs != 0); @@ -398,7 +398,7 @@ fn test_no_depth_no_alpha(api_version: GLVersion) { let context = GLContext::::new(size, attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); assert!(context.borrow_limits().max_vertex_attribs != 0); @@ -424,7 +424,7 @@ fn test_no_premul_alpha(api_version: GLVersion) { let context = GLContext::::new(size, attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); assert!(context.borrow_limits().max_vertex_attribs != 0); @@ -450,7 +450,7 @@ fn test_in_a_row(api_version: GLVersion) { let context = GLContext::::new(size, attributes.clone(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); @@ -459,14 +459,14 @@ fn test_in_a_row(api_version: GLVersion) { GLContext::::new(size, attributes.clone(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, Some(&handle)).unwrap(); GLContext::::new(size, attributes.clone(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, Some(&handle)).unwrap(); } @@ -485,7 +485,7 @@ fn test_zero_size(api_version: GLVersion) { GLContext::::new(Size2D::new(0, 320), GLContextAttributes::default(), ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); } @@ -511,7 +511,7 @@ fn test_both_depth_stencil(api_version: GLVersion) { GLContext::::new(size, attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); } @@ -537,7 +537,7 @@ fn test_stencil_no_depth(api_version: GLVersion) { GLContext::::new(size, attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + gl::GlType::Gl, api_version, None).unwrap(); }