Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "gl" feature for OpenGL related functionality. #484

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions io-surface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
cgl = {version = "0.3", optional = true }
leaky-cow = {version = "0.1.1", optional = true }
cgl = { version = "0.3", optional = true }
leaky-cow = { version = "0.1.1", optional = true }

11 changes: 11 additions & 0 deletions io-surface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)]
Expand Down Expand Up @@ -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();
Expand Down