Skip to content
Closed
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
14 changes: 9 additions & 5 deletions src/backend/gl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gfx-backend-gl"
version = "0.5.0"
version = "0.5.1"
description = "OpenGL backend for gfx-rs"
homepage = "https://github.com/gfx-rs/gfx"
repository = "https://github.com/gfx-rs/gfx"
Expand All @@ -18,7 +18,8 @@ name = "gfx_backend_gl"

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

[dependencies]
arrayvec = "0.5"
Expand All @@ -32,10 +33,12 @@ parking_lot = "0.10"
spirv_cross = { version = "0.18", features = ["glsl"] }
lazy_static = "1"
raw-window-handle = "0.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
glutin = { version = "0.23.0", optional = true }

[target.'cfg(all(unix, not(target_os = "ios")))'.dependencies]
# TODO: Update to released version when it comes out
surfman = { git = "https://github.com/servo/surfman.git", rev = "41ac1ee", features = ["sm-raw-window-handle"], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.6"
wasm-bindgen = "0.2.51"
Expand All @@ -61,7 +64,8 @@ features = [
]

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["libloaderapi", "windef", "wingdi", "winuser"] }
winapi = { version = "0.3", features = ["libloaderapi", "windef", "wingdi", "winuser"], optional = true }

[build-dependencies]
gl_generator = "0.11"
cfg_aliases = "0.1.0"
15 changes: 15 additions & 0 deletions src/backend/gl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ use std::fs::File;
use std::path::PathBuf;

fn main() {
// Setup cfg aliases
cfg_aliases::cfg_aliases! {
// Platforms
wasm: { target_arch = "wasm32" },
android: { target_os = "android" },
macos: { target_os = "macos" },
ios: { target_os = "ios" },
linux: { target_os = "linux" },
// Backends
surfman: { all(unix, feature = "surfman", not(ios)) },
wgl: { all(windows, feature = "wgl") },
glutin: { all(feature = "glutin", not(any(wasm, surfman))) },
dummy: { not(any(wasm, glutin, wgl, surfman)) },
}

let target = env::var("TARGET").unwrap();
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());

Expand Down
46 changes: 29 additions & 17 deletions src/backend/gl/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ impl d::Device<B> for Device {
// Sampler2D won't show up in UniformLocation and the only other uniforms
// should be push constants
uniforms.push(n::UniformDesc {
location: location as _,
location: Starc::new(location),
offset,
utype,
});
Expand Down Expand Up @@ -1669,7 +1669,7 @@ impl d::Device<B> for Device {
}
}

#[cfg(target_arch = "wasm32")]
#[cfg(wasm)]
unsafe fn wait_for_fences<I>(
&self,
fences: I,
Expand Down Expand Up @@ -1862,7 +1862,7 @@ impl d::Device<B> for Device {
) -> Result<(Swapchain, Vec<n::Image>), hal::window::CreationError> {
let gl = &self.share.context;

#[cfg(all(feature = "wgl", not(target_arch = "wasm32")))]
#[cfg(wgl)]
let context = {
use crate::window::wgl::PresentContext;

Expand Down Expand Up @@ -1926,17 +1926,17 @@ impl d::Device<B> for Device {
images.push(image);
}

#[cfg(all(feature = "wgl", not(target_arch = "wasm32")))]
let swapchain = {
self.share.instance_context.make_current();
Swapchain {
fbos,
context,
extent: config.extent,
}
// Web
#[cfg(wasm)]
let _ = surface;
#[cfg(wasm)]
let swapchain = Swapchain {
fbos,
extent: config.extent,
};

#[cfg(all(feature = "glutin", not(target_arch = "wasm32")))]
// Glutin
#[cfg(glutin)]
let swapchain = Swapchain {
fbos,
extent: config.extent,
Expand All @@ -1949,16 +1949,28 @@ impl d::Device<B> for Device {
},
};

#[cfg(target_arch = "wasm32")]
let _ = surface;

#[cfg(target_arch = "wasm32")]
// Surfman
#[cfg(surfman)]
let swapchain = Swapchain {
fbos,
extent: config.extent,
// TODO: Resize the context to the extent
context: surface.context.clone(),
};

// WGL
#[cfg(wgl)]
let swapchain = {
self.share.instance_context.make_current();
Swapchain {
fbos,
context,
extent: config.extent,
}
};

#[cfg(not(any(target_arch = "wasm32", feature = "glutin", feature = "wgl")))]
// Dummy
#[cfg(dummy)]
let swapchain = Swapchain {
extent: {
let _ = surface;
Expand Down
12 changes: 6 additions & 6 deletions src/backend/gl/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,17 @@ 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(target_arch = "wasm32"))]
#[cfg(not(wasm))]
let shading_language =
Version::parse(get_string(gl, glow::SHADING_LANGUAGE_VERSION).unwrap_or_default())
.unwrap();
#[cfg(target_arch = "wasm32")]
#[cfg(wasm)]
let shading_language = Version::new_embedded(3, 0, String::from(""));
// TODO: Use separate path for WebGL extensions in `glow` somehow
// Perhaps automatic fallback for NUM_EXTENSIONS to EXTENSIONS on native
#[cfg(target_arch = "wasm32")]
#[cfg(wasm)]
let extensions = HashSet::new();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(wasm))]
let extensions = if version >= Version::new(3, 0, None, String::from("")) {
let num_exts = get_usize(gl, glow::NUM_EXTENSIONS).unwrap();
(0 .. num_exts)
Expand Down Expand Up @@ -331,7 +331,7 @@ impl Info {
}
}

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

/// Load the information pertaining to the driver and the corresponding device
/// capabilities.
Expand All @@ -351,7 +351,7 @@ pub(crate) fn query_all(
let min_storage_buffer_offset_alignment = if IS_WEBGL {
1024
} else {
get_u64(gl, glow::SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT).unwrap_or(1024)
get_u64(gl, glow::SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT).unwrap_or(256)
};

let mut limits = Limits {
Expand Down
Loading