Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[libsimpleservo port] Support OpenGL #21305
Comments
|
I am interested to build projects in Rust ! |
|
Unless you're familiar with cross platform OpenGL, I'm not sure it's an easy project :) But it's totally doable: See the I see 2 possible approaches: full callback implementationImplement I've been toying with this in the past and came up with something like this for MacOS: #[cfg(target_os = "macos")]
pub mod gl {
use servo::gl;
use std::os::raw::c_void;
use std::rc::Rc;
use std::str;
use core_foundation::base::TCFType;
use core_foundation::string::CFString;
use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};
#[cfg(target_os = "macos")]
pub fn init() -> Rc<gl::Gl> {
info!("init_gl");
unsafe {
gl::GlFns::load_with(|addr| {
let symbol_name: CFString = str::FromStr::from_str(addr).unwrap();
let framework_name: CFString = str::FromStr::from_str("com.apple.opengl").unwrap();
let framework = CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef());
let symbol = CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef());
symbol as *const c_void
})
}
}
}Please note that it's not exactly compatible with the new API. Current code requires a We need to do the same thing for Windows and Linux as well. It all comes down to rewritting the callback in The goals of this work is to add OpenGL support to libsimpleservo. Note that we already support OpenGL in ports/servo. ports/servo doesn't use libsimpleservo. But in the future, we want ports/servo to rely on libsimpleservo. So you can look at what ports/servo does to create the GL object: servo/ports/servo/glutin_app/window.rs Line 239 in 62ff032 get_proc_address. The implementation of get_proc_address comes from glutin: https://github.com/tomaka/glutin and you will find that, for mac, the implementation of get_proc_address is exactly what my snipped above does. So you would need to find how GL is initialized in Glutin for Windows and Linux, and just "copy" what it's done there and put it in gl::init.
delegate GL creationAnother approach, that is probably easier, is to have one single I would recommend trying approach 1 first and see how it goes. If it turns out we need extra arguments for approach 1, then it's better to go for approach 2. |
#20912 followup
As of now, libsimpleservo only supports GLES. There is no reason to not also support OpenGL. This could be interesting if we ever want the regular port to rely on libsimpleservo.