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

Gentz' misc stuff, containing the following: #1101

Merged
merged 1 commit into from
Feb 26, 2019
Merged
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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Unreleased

- We no longer load `libegl.so` and `libgl.so` multiple times.
- Fixes `Context::is_current` incorrectly returning `false`.
- **Breaking:** Renamed `GlContext{,Ext}` to `ContextTrait{,Ext}`.
- Implemented context sharing support for Windows and Linux.
- Added `SeparatedContext`.
- **Breaking:** Renamed `GlWindow` to `CombinedContext`.
- **Breaking:** Removed `shareable_with_windowed_contexts`. Now you must build
OsMesa contexts via a separate extension.
- Added `ContextBuilder::build` method.
- On X11 and Wayland, you can now use shared contexts, however, one limitation
of the Wayland backend is that all shared contexts must use the same events
pool as each other.
- Added context sharing support to windows.
- Improved docs.
- Refactored code to be more consistent/cleaner. Ran rustfmt on everything.
- Added NetBSD support.
- **Breaking:** Removed `new_shared` function from `Context` and `GlWindow`, in favor of `new`.
- Added `build` method to `ContextBuilder`.
Expand Down
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ icon_loading = ["winit/icon_loading"]
serde = ["winit/serde"]

[dependencies]
lazy_static = "1"
lazy_static = "1.1"
libc = "0.2"
shared_library = "0.1.0"
winit = "0.18.0"
shared_library = "0.1"
winit = "0.18"

[build-dependencies]
gl_generator = "0.10"
Expand All @@ -48,7 +48,11 @@ features = [
"libloaderapi",
]

[target.'cfg(target_os = "windows")'.dependencies]
libloading = "0.5"

[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="netbsd", target_os="openbsd"))'.dependencies]
osmesa-sys = "0.1.0"
wayland-client = { version = "0.21", features = ["egl", "dlopen"] }
x11-dl = "2.18.3"
libloading = "0.5"
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,36 @@ extern crate gl;
extern crate glutin;

use glutin::dpi::*;
use glutin::GlContext;
use glutin::ContextTrait;

fn main() {
let mut events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new()
let mut el = glutin::EventsLoop::new();
let wb = glutin::WindowBuilder::new()
.with_title("Hello, world!")
.with_dimensions(LogicalSize::new(1024.0, 768.0));
let context = glutin::ContextBuilder::new()
.with_vsync(true);
let gl_window = glutin::GlWindow::new(window, context, &events_loop).unwrap();
let combined_context = glutin::ContextBuilder::new()
.with_vsync(true)
.build_combined(wb, &el)
.unwrap();

unsafe {
gl_window.make_current().unwrap();
combined_context.make_current().unwrap();
}

unsafe {
gl::load_with(|symbol| gl_window.get_proc_address(symbol) as *const _);
gl::load_with(|symbol| combined_context.get_proc_address(symbol) as *const _);
gl::ClearColor(0.0, 1.0, 0.0, 1.0);
}

let mut running = true;
while running {
events_loop.poll_events(|event| {
el.poll_events(|event| {
match event {
glutin::Event::WindowEvent{ event, .. } => match event {
glutin::WindowEvent::CloseRequested => running = false,
glutin::WindowEvent::Resized(logical_size) => {
let dpi_factor = gl_window.get_hidpi_factor();
gl_window.resize(logical_size.to_physical(dpi_factor));
let dpi_factor = combined_context.get_hidpi_factor();
combined_context.resize(logical_size.to_physical(dpi_factor));
},
_ => ()
},
Expand All @@ -79,7 +80,7 @@ fn main() {
gl::Clear(gl::COLOR_BUFFER_BIT);
}

gl_window.swap_buffers().unwrap();
combined_context.swap_buffers().unwrap();
}
}
```
Expand Down
255 changes: 157 additions & 98 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate gl_generator;

use gl_generator::{Registry, Api, Profile, Fallbacks};
use gl_generator::{Api, Fallbacks, Profile, Registry};
use std::env;
use std::fs::File;
use std::path::PathBuf;
Expand All @@ -17,131 +17,190 @@ fn main() {
.write_bindings(gl_generator::StaticGenerator, &mut file)
.unwrap();

let mut file = File::create(&dest.join("wgl_extra_bindings.rs")).unwrap();
Registry::new(Api::Wgl, (1, 0), Profile::Core, Fallbacks::All, [
"WGL_ARB_create_context",
"WGL_ARB_create_context_profile",
"WGL_ARB_create_context_robustness",
"WGL_ARB_context_flush_control",
"WGL_ARB_extensions_string",
"WGL_ARB_framebuffer_sRGB",
"WGL_ARB_multisample",
"WGL_ARB_pixel_format",
"WGL_ARB_pixel_format_float",
"WGL_EXT_create_context_es2_profile",
"WGL_EXT_extensions_string",
"WGL_EXT_framebuffer_sRGB",
"WGL_EXT_swap_control",
])
.write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
let mut file =
File::create(&dest.join("wgl_extra_bindings.rs")).unwrap();
Registry::new(
Api::Wgl,
(1, 0),
Profile::Core,
Fallbacks::All,
[
"WGL_ARB_create_context",
"WGL_ARB_create_context_profile",
"WGL_ARB_create_context_robustness",
"WGL_ARB_context_flush_control",
"WGL_ARB_extensions_string",
"WGL_ARB_framebuffer_sRGB",
"WGL_ARB_multisample",
"WGL_ARB_pixel_format",
"WGL_ARB_pixel_format_float",
"WGL_EXT_create_context_es2_profile",
"WGL_EXT_extensions_string",
"WGL_EXT_framebuffer_sRGB",
"WGL_EXT_swap_control",
],
)
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();

let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
])
.write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
Registry::new(
Api::Egl,
(1, 5),
Profile::Core,
Fallbacks::All,
[
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
],
)
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();
}

if target.contains("linux") || target.contains("dragonfly") || target.contains("freebsd") || target.contains("netbsd") || target.contains("openbsd") {
if target.contains("linux")
|| target.contains("dragonfly")
|| target.contains("freebsd")
|| target.contains("netbsd")
|| target.contains("openbsd")
{
let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap();
Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();

let mut file = File::create(&dest.join("glx_extra_bindings.rs")).unwrap();
Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, [
"GLX_ARB_create_context",
"GLX_ARB_create_context_profile",
"GLX_ARB_create_context_robustness",
"GLX_ARB_context_flush_control",
"GLX_ARB_fbconfig_float",
"GLX_ARB_framebuffer_sRGB",
"GLX_EXT_framebuffer_sRGB",
"GLX_ARB_multisample",
"GLX_EXT_swap_control",
"GLX_SGI_swap_control"
])
.write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
let mut file =
File::create(&dest.join("glx_extra_bindings.rs")).unwrap();
Registry::new(
Api::Glx,
(1, 4),
Profile::Core,
Fallbacks::All,
[
"GLX_ARB_create_context",
"GLX_ARB_create_context_profile",
"GLX_ARB_create_context_robustness",
"GLX_ARB_context_flush_control",
"GLX_ARB_fbconfig_float",
"GLX_ARB_framebuffer_sRGB",
"GLX_EXT_framebuffer_sRGB",
"GLX_ARB_multisample",
"GLX_EXT_swap_control",
"GLX_SGI_swap_control",
],
)
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();

let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
])
.write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
Registry::new(
Api::Egl,
(1, 5),
Profile::Core,
Fallbacks::All,
[
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
],
)
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();
}

if target.contains("android") {
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
])
.write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap();
Registry::new(
Api::Egl,
(1, 5),
Profile::Core,
Fallbacks::All,
[
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
],
)
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();
}

if target.contains("ios") {
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
])
.write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap();
Registry::new(
Api::Egl,
(1, 5),
Profile::Core,
Fallbacks::All,
[
"EGL_KHR_create_context",
"EGL_EXT_create_context_robustness",
"EGL_KHR_create_context_no_error",
"EGL_KHR_platform_x11",
"EGL_KHR_platform_android",
"EGL_KHR_platform_wayland",
"EGL_KHR_platform_gbm",
"EGL_EXT_platform_base",
"EGL_EXT_platform_x11",
"EGL_MESA_platform_gbm",
"EGL_EXT_platform_wayland",
"EGL_EXT_platform_device",
],
)
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();

let mut file = File::create(&dest.join("gles2_bindings.rs")).unwrap();
Registry::new(Api::Gles2, (2, 0), Profile::Core, Fallbacks::None, [])
.write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap();
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();
}

if target.contains("darwin") {
let mut file = File::create(&dest.join("gl_bindings.rs")).unwrap();
Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, ["GL_EXT_framebuffer_object"])
.write_bindings(gl_generator::GlobalGenerator, &mut file).unwrap();
Registry::new(
Api::Gl,
(3, 2),
Profile::Core,
Fallbacks::All,
["GL_EXT_framebuffer_object"],
)
.write_bindings(gl_generator::GlobalGenerator, &mut file)
.unwrap();
}

// TODO: only build the bindings below if we run tests/examples

let mut file = File::create(&dest.join("test_gl_bindings.rs")).unwrap();
Registry::new(Api::Gles2, (3, 0), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();
}
Loading