diff --git a/io-surface/Cargo.toml b/io-surface/Cargo.toml index 9215da70b..6a80ea999 100644 --- a/io-surface/Cargo.toml +++ b/io-surface/Cargo.toml @@ -10,9 +10,13 @@ license = "MIT / Apache-2.0" [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" +[features] +default = ["gl"] +gl = ["cgl", "leaky-cow"] + [dependencies] libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-foundation-sys = { path = "../core-foundation-sys", version = "0.8" } -cgl = "0.3" -leaky-cow = "0.1.1" +cgl = {version = "0.3", optional = true } +leaky-cow = {version = "0.1.1", optional = true } diff --git a/io-surface/src/lib.rs b/io-surface/src/lib.rs index 4bf687d73..81a0cd485 100644 --- a/io-surface/src/lib.rs +++ b/io-surface/src/lib.rs @@ -13,7 +13,9 @@ extern crate libc; extern crate core_foundation; extern crate core_foundation_sys; +#[cfg(feature = "gl")] extern crate cgl; +#[cfg(feature = "gl")] extern crate leaky_cow; // Rust bindings to the IOSurface framework on macOS. @@ -22,17 +24,25 @@ use core_foundation::base::{CFRelease, CFRetain, CFTypeID, CFTypeRef, CFType, TC use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::string::{CFString, CFStringRef}; use core_foundation_sys::base::mach_port_t; +#[cfg(feature = "gl")] use cgl::{kCGLNoError, CGLGetCurrentContext, CGLTexImageIOSurface2D, CGLErrorString, GLenum}; use libc::{c_int, size_t}; use std::os::raw::c_void; +#[cfg(feature = "gl")] use leaky_cow::LeakyCow; use std::slice; +#[cfg(feature = "gl")] use std::ffi::CStr; +#[cfg(feature = "gl")] const BGRA: GLenum = 0x80E1; +#[cfg(feature = "gl")] const RGBA: GLenum = 0x1908; +#[cfg(feature = "gl")] const RGB: GLenum = 0x1907; +#[cfg(feature = "gl")] const TEXTURE_RECTANGLE_ARB: GLenum = 0x84F5; +#[cfg(feature = "gl")] const UNSIGNED_INT_8_8_8_8_REV: GLenum = 0x8367; #[allow(non_snake_case)] @@ -131,6 +141,7 @@ impl IOSurface { } /// Binds to the current GL texture. + #[cfg(feature = "gl")] pub fn bind_to_gl_texture(&self, width: i32, height: i32, has_alpha: bool) { unsafe { let context = CGLGetCurrentContext();