Skip to content

Commit

Permalink
[gl] replace Surfman by EGL
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Nov 9, 2020
1 parent 1e824db commit 94b71d5
Show file tree
Hide file tree
Showing 21 changed files with 380 additions and 651 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
- name: Check
run: |
cargo check --manifest-path src/backend/vulkan/Cargo.toml --target ${{ env.TARGET }}
cargo check --manifest-path src/backend/gl/Cargo.toml --target ${{ env.TARGET }}
# see https://github.com/timothee-haudebourg/khronos-egl/issues/6
#cargo check --manifest-path src/backend/gl/Cargo.toml --target ${{ env.TARGET }}
build:
name: ${{ matrix.name }}
Expand Down Expand Up @@ -94,6 +95,11 @@ jobs:
- if: matrix.os == 'windows-2019'
name: Install make
run: choco install make
- if: matrix.os == 'ubuntu-18.04'
name: Install EGL Mesa
run: |
sudo apt-get update -y -qq
sudo apt-get install -y -qq libegl1-mesa-dev
#- if: matrix.channel == 'stable'
# run: rustup component add clippy
# build with no features first
Expand Down
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ else
UNAME_S:=$(shell uname -s)
EXCLUDES+= --exclude gfx-backend-dx12
EXCLUDES+= --exclude gfx-backend-dx11
ifeq ($(UNAME_S),Linux)
EXCLUDES+= --exclude gfx-backend-metal
FEATURES_HAL=vulkan
endif
ifeq ($(TARGET),aarch64-apple-ios)
EXCLUDES+= --exclude gfx-backend-vulkan --exclude gfx-backend-gl
EXCLUDES+= --exclude gfx-backend-vulkan
else ifeq ($(TARGET),x86_64-apple-ios)
EXCLUDES+= --exclude gfx-backend-vulkan --exclude gfx-backend-gl
else
FEATURES_GL=gl
EXCLUDES+= --exclude gfx-backend-vulkan
endif
ifeq ($(UNAME_S),Darwin)
EXCLUDES+= --exclude gfx-backend-gl
FEATURES_HAL=metal
else
EXCLUDES+= --exclude gfx-backend-metal
FEATURES_HAL=vulkan
FEATURES_GL=gl
endif
endif

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gfx-rs is a low-level, cross-platform graphics and compute abstraction library i
* [Vulkan](src/backend/vulkan) (runs on Linux, Windows, and Android)
* [DirectX 12](src/backend/dx12) and [DirectX 11](src/backend/dx11)
* [Metal](src/backend/metal) (runs on macOS and iOS)
* [OpenGL 2.1+/ES2+](src/backend/gl) (runs on Linux, Android, macOS, and WASM/WebGL2)
* [OpenGL ES3](src/backend/gl) (runs on Linux/BSD, Android, and WASM/WebGL2)
* `gfx-warden` which is a data-driven reference test framework, used to verify consistency across all graphics backends.

gfx-rs is hard to use, it's recommended for performance-sensitive libraries and engines. If that's not your domain, take a look at [wgpu-rs](https://github.com/gfx-rs/wgpu-rs) for a safe and simple alternative.
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ path = "../src/backend/vulkan"
version = "0.6"
optional = true

[target.'cfg(unix)'.dependencies.gfx-backend-gl]
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos"), not(target_os = "android")))'.dependencies.gfx-backend-gl]
path = "../src/backend/gl"
version = "0.6"
features = ["x11"]
Expand Down
9 changes: 7 additions & 2 deletions examples/compute/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![cfg_attr(
not(any(
feature = "vulkan",
feature = "gl",
feature = "dx11",
feature = "dx12",
feature = "metal"
feature = "metal",
)),
allow(dead_code, unused_extern_crates, unused_imports)
)]
Expand All @@ -12,6 +13,8 @@
extern crate gfx_backend_dx11 as back;
#[cfg(feature = "dx12")]
extern crate gfx_backend_dx12 as back;
#[cfg(feature = "gl")]
extern crate gfx_backend_gl as back;
#[cfg(feature = "metal")]
extern crate gfx_backend_metal as back;
#[cfg(feature = "vulkan")]
Expand All @@ -23,9 +26,10 @@ use hal::{adapter::MemoryType, buffer, command, memory, pool, prelude::*, pso};

#[cfg(any(
feature = "vulkan",
feature = "gl",
feature = "dx11",
feature = "dx12",
feature = "metal"
feature = "metal",
))]
fn main() {
env_logger::init();
Expand Down Expand Up @@ -288,6 +292,7 @@ unsafe fn create_buffer<B: hal::Backend>(

#[cfg(not(any(
feature = "vulkan",
feature = "gl",
feature = "dx11",
feature = "dx12",
feature = "metal"
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh-shading/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
extern crate gfx_backend_dx11 as back;
#[cfg(feature = "dx12")]
extern crate gfx_backend_dx12 as back;
#[cfg(all(unix, feature = "gl"))]
#[cfg(feature = "gl")]
extern crate gfx_backend_gl as back;
#[cfg(feature = "metal")]
extern crate gfx_backend_metal as back;
Expand Down
2 changes: 1 addition & 1 deletion examples/quad/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern crate gfx_backend_dx12 as back;
feature = "gl",
)))]
extern crate gfx_backend_empty as back;
#[cfg(all(unix, feature = "gl"))]
#[cfg(feature = "gl")]
extern crate gfx_backend_gl as back;
#[cfg(feature = "metal")]
extern crate gfx_backend_metal as back;
Expand Down
12 changes: 4 additions & 8 deletions src/backend/gl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ readme = "README.md"
documentation = "https://docs.rs/gfx-backend-gl"
workspace = "../../.."
edition = "2018"
build = "build.rs"

[lib]
name = "gfx_backend_gl"

[features]
default = ["surfman"]
x11 = ["surfman/sm-x11"]
default = []

[dependencies]
arrayvec = "0.5"
Expand All @@ -32,9 +30,10 @@ parking_lot = "0.11"
spirv_cross = { version = "0.22", features = ["glsl"] }
lazy_static = "1"
raw-window-handle = "0.3"
x11 = { version = "2", features = ["xlib"], optional = true }

[target.'cfg(all(unix, not(target_os = "ios")))'.dependencies]
surfman = { version = "0.3", features = ["sm-raw-window-handle"], optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egl = { package = "khronos-egl", version = "2.1.0" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.6"
Expand All @@ -59,6 +58,3 @@ features = [
"WebGlTexture",
"Window",
]

[build-dependencies]
cfg_aliases = "0.1.0"
2 changes: 2 additions & 0 deletions src/backend/gl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[OpenGL](https://www.khronos.org/opengl/) backend for gfx.

Can only be used on non-Apple Unix systems. The WSI is hard-coded to EGL.

## Normalized Coordinates

Render | Depth | Texture
Expand Down
16 changes: 0 additions & 16 deletions src/backend/gl/build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/backend/gl/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ impl d::Device<B> for Device {
}
}

#[cfg(wasm)]
#[cfg(target_arch = "wasm32")]
unsafe fn wait_for_fences<I>(
&self,
fences: I,
Expand Down
21 changes: 10 additions & 11 deletions src/backend/gl/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,23 @@ pub enum Requirement<'a> {
Ext(&'a str),
}

const IS_WEBGL: bool = cfg!(target_arch = "wasm32");

impl Info {
fn get(gl: &GlContainer) -> Info {
let platform_name = PlatformName::get(gl);
let version = Version::parse(get_string(gl, glow::VERSION).unwrap_or_default()).unwrap();
#[cfg(not(wasm))]
let shading_language =
let shading_language = if IS_WEBGL {
Version::new_embedded(3, 0, String::from(""))
} else {
Version::parse(get_string(gl, glow::SHADING_LANGUAGE_VERSION).unwrap_or_default())
.unwrap();
#[cfg(wasm)]
let shading_language = Version::new_embedded(3, 0, String::from(""));
.unwrap()
};
// TODO: Use separate path for WebGL extensions in `glow` somehow
// Perhaps automatic fallback for NUM_EXTENSIONS to EXTENSIONS on native
#[cfg(wasm)]
let extensions = HashSet::new();
#[cfg(not(wasm))]
let extensions = if version >= Version::new(3, 0, None, String::from("")) {
let extensions = if IS_WEBGL {
HashSet::new()
} else if version >= Version::new(3, 0, None, String::from("")) {
let num_exts = get_usize(gl, glow::NUM_EXTENSIONS).unwrap();
(0..num_exts)
.map(|i| unsafe { gl.get_parameter_indexed_string(glow::EXTENSIONS, i as u32) })
Expand Down Expand Up @@ -329,8 +330,6 @@ impl Info {
}
}

const IS_WEBGL: bool = cfg!(wasm);

/// Load the information pertaining to the driver and the corresponding device
/// capabilities.
pub(crate) fn query_all(
Expand Down

0 comments on commit 94b71d5

Please sign in to comment.