Skip to content

Commit

Permalink
alt: GL/glutin implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jul 31, 2019
1 parent 25da92e commit 1ece246
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/backend/gl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod state;
mod window;

#[cfg(all(not(target_arch = "wasm32"), feature = "glutin"))]
pub use window::glutin::{config_context, Headless, Surface, Swapchain};
pub use crate::window::glutin::{config_context, Headless, Surface, Swapchain, SurfaceImage};
#[cfg(target_arch = "wasm32")]
pub use window::web::{Surface, Swapchain, Window};

Expand Down
12 changes: 12 additions & 0 deletions src/backend/gl/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,18 @@ impl hal::queue::RawCommandQueue<Backend> for CommandQueue {
Ok(None)
}

#[cfg(any(feature = "glutin", feature = "wgl", target_arch = "wasm32"))]
unsafe fn present_surface(
&mut self,
surface: &mut crate::Surface,
_image: crate::SurfaceImage,
) -> Result<Option<hal::window::Suboptimal>, hal::window::PresentError> {
#[cfg(all(feature = "glutin", not(target_arch = "wasm32")))]
surface.context.swap_buffers().unwrap();

Ok(None)
}

fn wait_idle(&self) -> Result<(), error::HostExecutionError> {
unsafe {
self.share.context.finish();
Expand Down
37 changes: 34 additions & 3 deletions src/backend/gl/src/window/glutin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
//! ```

use crate::hal::window::Extent2D;
use crate::hal::{self, format as f, image, memory, CompositeAlpha};
use crate::hal::{self, format as f, image, CompositeAlpha};
use crate::{native, Backend as B, Device, GlContainer, PhysicalDevice, QueueFamily, Starc};

use glow::Context;

use glutin;

use std::borrow::Borrow;

fn get_window_extent(window: &glutin::Window) -> image::Extent {
let px = window
.get_inner_size()
Expand Down Expand Up @@ -124,6 +124,37 @@ impl Surface {
}
}

#[derive(Debug)]
pub struct SurfaceImage {
view: native::ImageView,
}

impl Borrow<native::ImageView> for SurfaceImage {
fn borrow(&self) -> &native::ImageView {
&self.view
}
}

impl hal::PresentationSurface<B> for Surface {
type SwapchainImage = SurfaceImage;

unsafe fn configure_swapchain(
&mut self, _device: &Device, _config: hal::SwapchainConfig
) -> Result<(), hal::window::CreationError> {
Ok(())
}

unsafe fn acquire_image(
&mut self,
_timeout_ns: u64,
) -> Result<(Self::SwapchainImage, Option<hal::window::Suboptimal>), hal::AcquireError> {
let image = SurfaceImage {
view: native::ImageView::Surface(0),
};
Ok((image, None))
}
}

impl hal::Surface<B> for Surface {
fn compatibility(
&self,
Expand Down
14 changes: 0 additions & 14 deletions src/backend/metal/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ impl hal::Surface<Backend> for Surface {
impl hal::PresentationSurface<Backend> for Surface {
type SwapchainImage = SurfaceImage;

/// Set up the swapchain associated with the surface to have the given format.
unsafe fn configure_swapchain(
&mut self, device: &Device, config: SwapchainConfig
) -> Result<(), CreationError> {
Expand All @@ -455,19 +454,6 @@ impl hal::PresentationSurface<Backend> for Surface {
Ok(())
}

/// Acquire a new swapchain image for rendering.
///
/// May fail according to one of the reasons indicated in `AcquireError` enum.
///
/// # Synchronization
///
/// The acquired image is available to render. No synchronization is required.
///
/// # Examples
///
/// ```no_run
///
/// ```
unsafe fn acquire_image(
&mut self,
_timeout_ns: u64, //TODO: use the timeout
Expand Down
16 changes: 1 addition & 15 deletions src/backend/vulkan/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ impl Borrow<native::ImageView> for SurfaceImage {
impl hal::PresentationSurface<Backend> for Surface {
type SwapchainImage = SurfaceImage;

/// Set up the swapchain associated with the surface to have the given format.
unsafe fn configure_swapchain(
&mut self, device: &Device, config: hal::SwapchainConfig
) -> Result<(), hal::window::CreationError> {
Expand Down Expand Up @@ -522,22 +521,9 @@ impl hal::PresentationSurface<Backend> for Surface {
Ok(())
}

/// Acquire a new swapchain image for rendering.
///
/// May fail according to one of the reasons indicated in `AcquireError` enum.
///
/// # Synchronization
///
/// The acquired image is available to render. No synchronization is required.
///
/// # Examples
///
/// ```no_run
///
/// ```
unsafe fn acquire_image(
&mut self,
mut timeout_ns: u64, //TODO: use the timeout
mut timeout_ns: u64,
) -> Result<(Self::SwapchainImage, Option<hal::window::Suboptimal>), hal::AcquireError> {
use ash::version::DeviceV1_0;
use hal::Swapchain as _;
Expand Down

0 comments on commit 1ece246

Please sign in to comment.