From 9a82de6fae870da8fd83087329995478956796e0 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Thu, 22 Nov 2018 12:20:31 +0100 Subject: [PATCH] graphics: Move PixelFormat out of gl module --- src/backend/drm/egl/surface.rs | 6 +++++- src/backend/egl/context.rs | 2 +- src/backend/egl/mod.rs | 1 + src/backend/graphics/format.rs | 22 ++++++++++++++++++++++ src/backend/graphics/gl.rs | 25 +------------------------ src/backend/graphics/mod.rs | 3 +++ src/backend/winit.rs | 4 ++-- 7 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 src/backend/graphics/format.rs diff --git a/src/backend/drm/egl/surface.rs b/src/backend/drm/egl/surface.rs index 634310b..682338c 100644 --- a/src/backend/drm/egl/surface.rs +++ b/src/backend/drm/egl/surface.rs @@ -7,7 +7,10 @@ use super::error::*; use backend::drm::{Device, Surface}; use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; use backend::egl::{EGLContext, EGLSurface}; -use backend::graphics::gl::{GLGraphicsBackend, PixelFormat}; +#[cfg(feature = "renderer_gl")] +use backend::graphics::gl::GLGraphicsBackend; +#[cfg(feature = "renderer_gl")] +use backend::graphics::PixelFormat; use backend::graphics::{CursorBackend, SwapBuffersError}; pub struct EglSurface< @@ -91,6 +94,7 @@ where } } +#[cfg(feature = "renderer_gl")] impl::Surface> + 'static, D: Device + NativeDisplay + 'static> GLGraphicsBackend for EglSurface where diff --git a/src/backend/egl/context.rs b/src/backend/egl/context.rs index 070c07a..28f8c70 100644 --- a/src/backend/egl/context.rs +++ b/src/backend/egl/context.rs @@ -1,7 +1,7 @@ //! EGL context related structs use super::{error::*, ffi, native, EGLSurface}; -use backend::graphics::gl::PixelFormat; +use backend::graphics::PixelFormat; use nix::libc::{c_int, c_void}; use slog; use std::{ diff --git a/src/backend/egl/mod.rs b/src/backend/egl/mod.rs index 3516c15..dfafee9 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -337,6 +337,7 @@ impl EGLDisplay { context: &EGLContext, display: *mut wl_display, ) -> EGLDisplay { + #[cfg(feature = "renderer_gl")] let gl = gl_ffi::Gles2::load_with(|s| unsafe { context.get_proc_address(s) as *const _ }); EGLDisplay { diff --git a/src/backend/graphics/format.rs b/src/backend/graphics/format.rs new file mode 100644 index 0000000..7b3176d --- /dev/null +++ b/src/backend/graphics/format.rs @@ -0,0 +1,22 @@ +/// Describes the pixel format of a framebuffer +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct PixelFormat { + /// is the format hardware accelerated + pub hardware_accelerated: bool, + /// number of bits used for colors + pub color_bits: u8, + /// number of bits used for alpha channel + pub alpha_bits: u8, + /// number of bits used for depth channel + pub depth_bits: u8, + /// number of bits used for stencil buffer + pub stencil_bits: u8, + /// is stereoscopy enabled + pub stereoscopy: bool, + /// is double buffering enabled + pub double_buffer: bool, + /// number of samples used for multisampling if enabled + pub multisampling: Option, + /// is srgb enabled + pub srgb: bool, +} \ No newline at end of file diff --git a/src/backend/graphics/gl.rs b/src/backend/graphics/gl.rs index 78c3c9f..a39ce14 100644 --- a/src/backend/graphics/gl.rs +++ b/src/backend/graphics/gl.rs @@ -1,6 +1,6 @@ use nix::libc::c_void; -use super::SwapBuffersError; +use super::{SwapBuffersError, PixelFormat}; #[cfg_attr(feature = "cargo-clippy", allow(clippy))] #[allow(missing_docs)] @@ -10,29 +10,6 @@ pub(crate) mod ffi { pub use self::ffi::Gles2; -/// Describes the pixel format of the main framebuffer -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct PixelFormat { - /// is the format hardware accelerated - pub hardware_accelerated: bool, - /// number of bits used for colors - pub color_bits: u8, - /// number of bits used for alpha channel - pub alpha_bits: u8, - /// number of bits used for depth channel - pub depth_bits: u8, - /// number of bits used for stencil buffer - pub stencil_bits: u8, - /// is stereoscopy enabled - pub stereoscopy: bool, - /// is double buffering enabled - pub double_buffer: bool, - /// number of samples used for multisampling if enabled - pub multisampling: Option, - /// is srgb enabled - pub srgb: bool, -} - /// Trait that describes objects that have an OpenGL context /// and can be used to render upon pub trait GLGraphicsBackend { diff --git a/src/backend/graphics/mod.rs b/src/backend/graphics/mod.rs index abac583..188e1c0 100644 --- a/src/backend/graphics/mod.rs +++ b/src/backend/graphics/mod.rs @@ -8,6 +8,9 @@ pub use self::errors::*; mod cursor; pub use self::cursor::*; +mod format; +pub use self::format::*; + #[cfg(feature = "renderer_gl")] pub mod gl; #[cfg(feature = "renderer_glium")] diff --git a/src/backend/winit.rs b/src/backend/winit.rs index fef1f74..af2dd3f 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -6,8 +6,8 @@ use backend::{ EGLDisplay, EGLGraphicsBackend, EGLSurface, }, graphics::{ - gl::{GLGraphicsBackend, PixelFormat}, - CursorBackend, SwapBuffersError, + gl::GLGraphicsBackend, + CursorBackend, SwapBuffersError, PixelFormat, }, input::{ Axis, AxisSource, Event as BackendEvent, InputBackend, InputHandler, KeyState, KeyboardKeyEvent,