mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Extract GlAttributes from BuilderAttribs
This commit is contained in:
parent
f51ace4c78
commit
c244f8c033
|
@ -267,11 +267,11 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
||||||
impl Window {
|
impl Window {
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
|
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
|
||||||
if builder.sharing.is_some() {
|
if builder.opengl.sharing.is_some() {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
match builder.gl_robustness {
|
match builder.opengl.robustness {
|
||||||
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
||||||
return Err(CreationError::RobustnessNotSupported);
|
return Err(CreationError::RobustnessNotSupported);
|
||||||
},
|
},
|
||||||
|
@ -438,7 +438,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_context(view: id, builder: &BuilderAttribs) -> Result<(IdRef, PixelFormat), CreationError> {
|
fn create_context(view: id, builder: &BuilderAttribs) -> Result<(IdRef, PixelFormat), CreationError> {
|
||||||
let profile = match (builder.gl_version, builder.gl_version.to_gl_version(), builder.gl_profile) {
|
let profile = match (builder.opengl.version, builder.opengl.version.to_gl_version(), builder.opengl.profile) {
|
||||||
|
|
||||||
// Note: we are not using ranges because of a rust bug that should be fixed here:
|
// Note: we are not using ranges because of a rust bug that should be fixed here:
|
||||||
// https://github.com/rust-lang/rust/pull/27050
|
// https://github.com/rust-lang/rust/pull/27050
|
||||||
|
@ -540,7 +540,7 @@ impl Window {
|
||||||
};
|
};
|
||||||
|
|
||||||
cxt.setView_(view);
|
cxt.setView_(view);
|
||||||
let value = if builder.vsync { 1 } else { 0 };
|
let value = if builder.opengl.vsync { 1 } else { 0 };
|
||||||
cxt.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
|
cxt.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
|
||||||
|
|
||||||
CGLEnable(cxt.CGLContextObj(), kCGLCECrashOnRemovedFunctions);
|
CGLEnable(cxt.CGLContextObj(), kCGLCECrashOnRemovedFunctions);
|
||||||
|
|
|
@ -162,7 +162,7 @@ impl Context {
|
||||||
native_display: NativeDisplay)
|
native_display: NativeDisplay)
|
||||||
-> Result<ContextPrototype<'a>, CreationError>
|
-> Result<ContextPrototype<'a>, CreationError>
|
||||||
{
|
{
|
||||||
if builder.sharing.is_some() {
|
if builder.opengl.sharing.is_some() {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ impl Context {
|
||||||
|
|
||||||
// binding the right API and choosing the version
|
// binding the right API and choosing the version
|
||||||
let (version, api) = unsafe {
|
let (version, api) = unsafe {
|
||||||
match builder.gl_version {
|
match builder.opengl.version {
|
||||||
GlRequest::Latest => {
|
GlRequest::Latest => {
|
||||||
if egl_version >= (1, 4) {
|
if egl_version >= (1, 4) {
|
||||||
if egl.BindAPI(ffi::egl::OPENGL_API) != 0 {
|
if egl.BindAPI(ffi::egl::OPENGL_API) != 0 {
|
||||||
|
@ -394,18 +394,18 @@ impl<'a> ContextPrototype<'a> {
|
||||||
if let Some(version) = self.version {
|
if let Some(version) = self.version {
|
||||||
try!(create_context(&self.egl, self.display, &self.egl_version,
|
try!(create_context(&self.egl, self.display, &self.egl_version,
|
||||||
&self.extensions, self.api, version, self.config_id,
|
&self.extensions, self.api, version, self.config_id,
|
||||||
self.builder.gl_debug, self.builder.gl_robustness))
|
self.builder.opengl.debug, self.builder.opengl.robustness))
|
||||||
|
|
||||||
} else if self.api == Api::OpenGlEs {
|
} else if self.api == Api::OpenGlEs {
|
||||||
if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
||||||
&self.extensions, self.api, (2, 0), self.config_id,
|
&self.extensions, self.api, (2, 0), self.config_id,
|
||||||
self.builder.gl_debug, self.builder.gl_robustness)
|
self.builder.opengl.debug, self.builder.opengl.robustness)
|
||||||
{
|
{
|
||||||
ctxt
|
ctxt
|
||||||
} else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
} else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
||||||
&self.extensions, self.api, (1, 0),
|
&self.extensions, self.api, (1, 0),
|
||||||
self.config_id, self.builder.gl_debug,
|
self.config_id, self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness)
|
self.builder.opengl.robustness)
|
||||||
{
|
{
|
||||||
ctxt
|
ctxt
|
||||||
} else {
|
} else {
|
||||||
|
@ -415,19 +415,19 @@ impl<'a> ContextPrototype<'a> {
|
||||||
} else {
|
} else {
|
||||||
if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
||||||
&self.extensions, self.api, (3, 2), self.config_id,
|
&self.extensions, self.api, (3, 2), self.config_id,
|
||||||
self.builder.gl_debug, self.builder.gl_robustness)
|
self.builder.opengl.debug, self.builder.opengl.robustness)
|
||||||
{
|
{
|
||||||
ctxt
|
ctxt
|
||||||
} else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
} else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
||||||
&self.extensions, self.api, (3, 1),
|
&self.extensions, self.api, (3, 1),
|
||||||
self.config_id, self.builder.gl_debug,
|
self.config_id, self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness)
|
self.builder.opengl.robustness)
|
||||||
{
|
{
|
||||||
ctxt
|
ctxt
|
||||||
} else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
} else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version,
|
||||||
&self.extensions, self.api, (1, 0),
|
&self.extensions, self.api, (1, 0),
|
||||||
self.config_id, self.builder.gl_debug,
|
self.config_id, self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness)
|
self.builder.opengl.robustness)
|
||||||
{
|
{
|
||||||
ctxt
|
ctxt
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl Window {
|
||||||
|
|
||||||
// setting the attributes
|
// setting the attributes
|
||||||
// FIXME:
|
// FIXME:
|
||||||
/*match builder.gl_version {
|
/*match builder.opengl.version {
|
||||||
Some((major, minor)) => {
|
Some((major, minor)) => {
|
||||||
attributes.majorVersion = major as libc::c_int;
|
attributes.majorVersion = major as libc::c_int;
|
||||||
attributes.minorVersion = minor as libc::c_int;
|
attributes.minorVersion = minor as libc::c_int;
|
||||||
|
|
|
@ -133,7 +133,7 @@ impl<'a> ContextPrototype<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish(self, window: ffi::Window) -> Result<Context, CreationError> {
|
pub fn finish(self, window: ffi::Window) -> Result<Context, CreationError> {
|
||||||
let share = if let Some(win) = self.builder.sharing {
|
let share = if let Some(win) = self.builder.opengl.sharing {
|
||||||
match win {
|
match win {
|
||||||
&PlatformWindow::X(ref win) => match win.x.context {
|
&PlatformWindow::X(ref win) => match win.x.context {
|
||||||
::api::x11::Context::Glx(ref c) => c.context,
|
::api::x11::Context::Glx(ref c) => c.context,
|
||||||
|
@ -160,46 +160,46 @@ impl<'a> ContextPrototype<'a> {
|
||||||
});
|
});
|
||||||
|
|
||||||
// creating GL context
|
// creating GL context
|
||||||
let context = match self.builder.gl_version {
|
let context = match self.builder.opengl.version {
|
||||||
GlRequest::Latest => {
|
GlRequest::Latest => {
|
||||||
if let Ok(ctxt) = create_context(&self.glx, &extra_functions, &extensions, (3, 2),
|
if let Ok(ctxt) = create_context(&self.glx, &extra_functions, &extensions, (3, 2),
|
||||||
self.builder.gl_profile, self.builder.gl_debug,
|
self.builder.opengl.profile, self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness, share,
|
self.builder.opengl.robustness, share,
|
||||||
self.display, self.fb_config, &self.visual_infos)
|
self.display, self.fb_config, &self.visual_infos)
|
||||||
{
|
{
|
||||||
ctxt
|
ctxt
|
||||||
} else if let Ok(ctxt) = create_context(&self.glx, &extra_functions, &extensions,
|
} else if let Ok(ctxt) = create_context(&self.glx, &extra_functions, &extensions,
|
||||||
(3, 1), self.builder.gl_profile,
|
(3, 1), self.builder.opengl.profile,
|
||||||
self.builder.gl_debug,
|
self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness, share, self.display,
|
self.builder.opengl.robustness, share, self.display,
|
||||||
self.fb_config, &self.visual_infos)
|
self.fb_config, &self.visual_infos)
|
||||||
{
|
{
|
||||||
ctxt
|
ctxt
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
try!(create_context(&self.glx, &extra_functions, &extensions, (1, 0),
|
try!(create_context(&self.glx, &extra_functions, &extensions, (1, 0),
|
||||||
self.builder.gl_profile, self.builder.gl_debug,
|
self.builder.opengl.profile, self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness,
|
self.builder.opengl.robustness,
|
||||||
share, self.display, self.fb_config, &self.visual_infos))
|
share, self.display, self.fb_config, &self.visual_infos))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GlRequest::Specific(Api::OpenGl, (major, minor)) => {
|
GlRequest::Specific(Api::OpenGl, (major, minor)) => {
|
||||||
try!(create_context(&self.glx, &extra_functions, &extensions, (major, minor),
|
try!(create_context(&self.glx, &extra_functions, &extensions, (major, minor),
|
||||||
self.builder.gl_profile, self.builder.gl_debug,
|
self.builder.opengl.profile, self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness, share, self.display, self.fb_config,
|
self.builder.opengl.robustness, share, self.display, self.fb_config,
|
||||||
&self.visual_infos))
|
&self.visual_infos))
|
||||||
},
|
},
|
||||||
GlRequest::Specific(_, _) => panic!("Only OpenGL is supported"),
|
GlRequest::Specific(_, _) => panic!("Only OpenGL is supported"),
|
||||||
GlRequest::GlThenGles { opengl_version: (major, minor), .. } => {
|
GlRequest::GlThenGles { opengl_version: (major, minor), .. } => {
|
||||||
try!(create_context(&self.glx, &extra_functions, &extensions, (major, minor),
|
try!(create_context(&self.glx, &extra_functions, &extensions, (major, minor),
|
||||||
self.builder.gl_profile, self.builder.gl_debug,
|
self.builder.opengl.profile, self.builder.opengl.debug,
|
||||||
self.builder.gl_robustness, share, self.display, self.fb_config,
|
self.builder.opengl.robustness, share, self.display, self.fb_config,
|
||||||
&self.visual_infos))
|
&self.visual_infos))
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// vsync
|
// vsync
|
||||||
if self.builder.vsync {
|
if self.builder.opengl.vsync {
|
||||||
unsafe { self.glx.MakeCurrent(self.display as *mut _, window, context) };
|
unsafe { self.glx.MakeCurrent(self.display as *mut _, window, context) };
|
||||||
|
|
||||||
if extra_functions.SwapIntervalEXT.is_loaded() {
|
if extra_functions.SwapIntervalEXT.is_loaded() {
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl OsMesaContext {
|
||||||
|
|
||||||
let dimensions = builder.dimensions.unwrap();
|
let dimensions = builder.dimensions.unwrap();
|
||||||
|
|
||||||
match builder.gl_robustness {
|
match builder.opengl.robustness {
|
||||||
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
||||||
return Err(CreationError::RobustnessNotSupported.into());
|
return Err(CreationError::RobustnessNotSupported.into());
|
||||||
},
|
},
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl Context {
|
||||||
let gl_library = try!(load_opengl32_dll());
|
let gl_library = try!(load_opengl32_dll());
|
||||||
|
|
||||||
// handling vsync
|
// handling vsync
|
||||||
if builder.vsync {
|
if builder.opengl.vsync {
|
||||||
if extensions.split(' ').find(|&i| i == "WGL_EXT_swap_control").is_some() {
|
if extensions.split(' ').find(|&i| i == "WGL_EXT_swap_control").is_some() {
|
||||||
let _guard = try!(CurrentContextGuard::make_current(hdc, context.0));
|
let _guard = try!(CurrentContextGuard::make_current(hdc, context.0));
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context").is_some() {
|
if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context").is_some() {
|
||||||
let mut attributes = Vec::new();
|
let mut attributes = Vec::new();
|
||||||
|
|
||||||
match builder.gl_version {
|
match builder.opengl.version {
|
||||||
GlRequest::Latest => {},
|
GlRequest::Latest => {},
|
||||||
GlRequest::Specific(Api::OpenGl, (major, minor)) => {
|
GlRequest::Specific(Api::OpenGl, (major, minor)) => {
|
||||||
attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int);
|
attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int);
|
||||||
|
@ -252,7 +252,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(profile) = builder.gl_profile {
|
if let Some(profile) = builder.opengl.profile {
|
||||||
if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context_profile").is_some()
|
if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context_profile").is_some()
|
||||||
{
|
{
|
||||||
let flag = match profile {
|
let flag = match profile {
|
||||||
|
@ -273,7 +273,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
|
|
||||||
// robustness
|
// robustness
|
||||||
if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context_robustness").is_some() {
|
if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context_robustness").is_some() {
|
||||||
match builder.gl_robustness {
|
match builder.opengl.robustness {
|
||||||
Robustness::RobustNoResetNotification | Robustness::TryRobustNoResetNotification => {
|
Robustness::RobustNoResetNotification | Robustness::TryRobustNoResetNotification => {
|
||||||
attributes.push(gl::wgl_extra::CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB as libc::c_int);
|
attributes.push(gl::wgl_extra::CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB as libc::c_int);
|
||||||
attributes.push(gl::wgl_extra::NO_RESET_NOTIFICATION_ARB as libc::c_int);
|
attributes.push(gl::wgl_extra::NO_RESET_NOTIFICATION_ARB as libc::c_int);
|
||||||
|
@ -288,7 +288,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
Robustness::NoError => (),
|
Robustness::NoError => (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match builder.gl_robustness {
|
match builder.opengl.robustness {
|
||||||
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
||||||
return Err(CreationError::RobustnessNotSupported);
|
return Err(CreationError::RobustnessNotSupported);
|
||||||
},
|
},
|
||||||
|
@ -296,7 +296,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if builder.gl_debug {
|
if builder.opengl.debug {
|
||||||
flags = flags | gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int;
|
flags = flags | gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
};
|
};
|
||||||
|
|
||||||
// creating the OpenGL context
|
// creating the OpenGL context
|
||||||
let context = match builder.gl_version {
|
let context = match builder.opengl.version {
|
||||||
GlRequest::Specific(Api::OpenGlEs, (_major, _minor)) => {
|
GlRequest::Specific(Api::OpenGlEs, (_major, _minor)) => {
|
||||||
if let Some(egl) = egl {
|
if let Some(egl) = egl {
|
||||||
if let Ok(c) = EglContext::new(egl, &builder,
|
if let Ok(c) = EglContext::new(egl, &builder,
|
||||||
|
|
|
@ -349,7 +349,7 @@ impl Window {
|
||||||
Egl(::api::egl::ContextPrototype<'a>),
|
Egl(::api::egl::ContextPrototype<'a>),
|
||||||
}
|
}
|
||||||
let builder_clone = builder.clone();
|
let builder_clone = builder.clone();
|
||||||
let context = match builder.gl_version {
|
let context = match builder.opengl.version {
|
||||||
GlRequest::Latest | GlRequest::Specific(Api::OpenGl, _) | GlRequest::GlThenGles { .. } => {
|
GlRequest::Latest | GlRequest::Specific(Api::OpenGl, _) | GlRequest::GlThenGles { .. } => {
|
||||||
// GLX should be preferred over EGL, otherwise crashes may occur
|
// GLX should be preferred over EGL, otherwise crashes may occur
|
||||||
// on X11 – issue #314
|
// on X11 – issue #314
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl HeadlessRendererBuilder {
|
||||||
|
|
||||||
/// Sets how the backend should choose the OpenGL API and version.
|
/// Sets how the backend should choose the OpenGL API and version.
|
||||||
pub fn with_gl(mut self, request: GlRequest) -> HeadlessRendererBuilder {
|
pub fn with_gl(mut self, request: GlRequest) -> HeadlessRendererBuilder {
|
||||||
self.attribs.gl_version = request;
|
self.attribs.opengl.version = request;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,13 +40,13 @@ impl HeadlessRendererBuilder {
|
||||||
/// The default value for this flag is `cfg!(ndebug)`, which means that it's enabled
|
/// The default value for this flag is `cfg!(ndebug)`, which means that it's enabled
|
||||||
/// when you run `cargo build` and disabled when you run `cargo build --release`.
|
/// when you run `cargo build` and disabled when you run `cargo build --release`.
|
||||||
pub fn with_gl_debug_flag(mut self, flag: bool) -> HeadlessRendererBuilder {
|
pub fn with_gl_debug_flag(mut self, flag: bool) -> HeadlessRendererBuilder {
|
||||||
self.attribs.gl_debug = flag;
|
self.attribs.opengl.debug = flag;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the robustness of the OpenGL context. See the docs of `Robustness`.
|
/// Sets the robustness of the OpenGL context. See the docs of `Robustness`.
|
||||||
pub fn with_gl_robustness(mut self, robustness: Robustness) -> HeadlessRendererBuilder {
|
pub fn with_gl_robustness(mut self, robustness: Robustness) -> HeadlessRendererBuilder {
|
||||||
self.attribs.gl_robustness = robustness;
|
self.attribs.opengl.robustness = robustness;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
87
src/lib.rs
87
src/lib.rs
|
@ -371,15 +371,9 @@ pub struct BuilderAttribs<'a> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
headless: bool,
|
headless: bool,
|
||||||
strict: bool,
|
strict: bool,
|
||||||
sharing: Option<&'a platform::Window>,
|
|
||||||
dimensions: Option<(u32, u32)>,
|
dimensions: Option<(u32, u32)>,
|
||||||
title: String,
|
title: String,
|
||||||
monitor: Option<platform::MonitorID>,
|
monitor: Option<platform::MonitorID>,
|
||||||
gl_version: GlRequest,
|
|
||||||
gl_profile: Option<GlProfile>,
|
|
||||||
gl_debug: bool,
|
|
||||||
gl_robustness: Robustness,
|
|
||||||
vsync: bool,
|
|
||||||
visible: bool,
|
visible: bool,
|
||||||
multisampling: Option<u16>,
|
multisampling: Option<u16>,
|
||||||
depth_bits: Option<u8>,
|
depth_bits: Option<u8>,
|
||||||
|
@ -390,7 +384,8 @@ pub struct BuilderAttribs<'a> {
|
||||||
srgb: Option<bool>,
|
srgb: Option<bool>,
|
||||||
transparent: bool,
|
transparent: bool,
|
||||||
decorations: bool,
|
decorations: bool,
|
||||||
multitouch: bool
|
multitouch: bool,
|
||||||
|
opengl: GlAttributes<&'a platform::Window>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuilderAttribs<'static> {
|
impl BuilderAttribs<'static> {
|
||||||
|
@ -398,15 +393,9 @@ impl BuilderAttribs<'static> {
|
||||||
BuilderAttribs {
|
BuilderAttribs {
|
||||||
headless: false,
|
headless: false,
|
||||||
strict: false,
|
strict: false,
|
||||||
sharing: None,
|
|
||||||
dimensions: None,
|
dimensions: None,
|
||||||
title: "glutin window".to_string(),
|
title: "glutin window".to_string(),
|
||||||
monitor: None,
|
monitor: None,
|
||||||
gl_version: GlRequest::Latest,
|
|
||||||
gl_profile: None,
|
|
||||||
gl_debug: cfg!(debug_assertions),
|
|
||||||
gl_robustness: Robustness::NotRobust,
|
|
||||||
vsync: false,
|
|
||||||
visible: true,
|
visible: true,
|
||||||
multisampling: None,
|
multisampling: None,
|
||||||
depth_bits: None,
|
depth_bits: None,
|
||||||
|
@ -417,7 +406,8 @@ impl BuilderAttribs<'static> {
|
||||||
srgb: None,
|
srgb: None,
|
||||||
transparent: false,
|
transparent: false,
|
||||||
decorations: true,
|
decorations: true,
|
||||||
multitouch: false
|
multitouch: false,
|
||||||
|
opengl: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,20 +415,14 @@ impl BuilderAttribs<'static> {
|
||||||
impl<'a> BuilderAttribs<'a> {
|
impl<'a> BuilderAttribs<'a> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn extract_non_static(mut self) -> (BuilderAttribs<'static>, Option<&'a platform::Window>) {
|
fn extract_non_static(mut self) -> (BuilderAttribs<'static>, Option<&'a platform::Window>) {
|
||||||
let sharing = self.sharing.take();
|
let sharing = self.opengl.sharing.take();
|
||||||
|
|
||||||
let new_attribs = BuilderAttribs {
|
let new_attribs = BuilderAttribs {
|
||||||
headless: self.headless,
|
headless: self.headless,
|
||||||
strict: self.strict,
|
strict: self.strict,
|
||||||
sharing: None,
|
|
||||||
dimensions: self.dimensions,
|
dimensions: self.dimensions,
|
||||||
title: self.title,
|
title: self.title,
|
||||||
monitor: self.monitor,
|
monitor: self.monitor,
|
||||||
gl_version: self.gl_version,
|
|
||||||
gl_profile: self.gl_profile,
|
|
||||||
gl_debug: self.gl_debug,
|
|
||||||
gl_robustness: self.gl_robustness,
|
|
||||||
vsync: self.vsync,
|
|
||||||
visible: self.visible,
|
visible: self.visible,
|
||||||
multisampling: self.multisampling,
|
multisampling: self.multisampling,
|
||||||
depth_bits: self.depth_bits,
|
depth_bits: self.depth_bits,
|
||||||
|
@ -449,7 +433,15 @@ impl<'a> BuilderAttribs<'a> {
|
||||||
srgb: self.srgb,
|
srgb: self.srgb,
|
||||||
transparent: self.transparent,
|
transparent: self.transparent,
|
||||||
decorations: self.decorations,
|
decorations: self.decorations,
|
||||||
multitouch: self.multitouch
|
multitouch: self.multitouch,
|
||||||
|
opengl: GlAttributes {
|
||||||
|
sharing: None,
|
||||||
|
version: self.opengl.version,
|
||||||
|
profile: self.opengl.profile,
|
||||||
|
debug: self.opengl.debug,
|
||||||
|
robustness: self.opengl.robustness,
|
||||||
|
vsync: self.opengl.vsync,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
(new_attribs, sharing)
|
(new_attribs, sharing)
|
||||||
|
@ -555,6 +547,57 @@ impl<'a> BuilderAttribs<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attributes to use when creating an OpenGL context.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct GlAttributes<S> {
|
||||||
|
/// An existing context to share the new the context with.
|
||||||
|
///
|
||||||
|
/// The default is `None`.
|
||||||
|
pub sharing: Option<S>,
|
||||||
|
|
||||||
|
/// Version to try create. See `GlRequest` for more infos.
|
||||||
|
///
|
||||||
|
/// The default is `Latest`.
|
||||||
|
pub version: GlRequest,
|
||||||
|
|
||||||
|
/// OpenGL profile to use.
|
||||||
|
///
|
||||||
|
/// The default is `None`.
|
||||||
|
pub profile: Option<GlProfile>,
|
||||||
|
|
||||||
|
/// Whether to enable the `debug` flag of the context.
|
||||||
|
///
|
||||||
|
/// Debug contexts are usually slower but give better error reporting.
|
||||||
|
///
|
||||||
|
/// The default is `true` in debug mode and `false` in release mode.
|
||||||
|
pub debug: bool,
|
||||||
|
|
||||||
|
/// How the OpenGL context should detect errors.
|
||||||
|
///
|
||||||
|
/// The default is `NotRobust` because this is what is typically expected when you create an
|
||||||
|
/// OpenGL context. However for safety you should consider `TryRobustLoseContextOnReset`.
|
||||||
|
pub robustness: Robustness,
|
||||||
|
|
||||||
|
/// Whether to use vsync. If vsync is enabled, calling `swap_buffers` will block until the
|
||||||
|
/// screen refreshes. This is typically used to prevent screen tearing.
|
||||||
|
///
|
||||||
|
/// The default is `false`.
|
||||||
|
pub vsync: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Default for GlAttributes<S> {
|
||||||
|
fn default() -> GlAttributes<S> {
|
||||||
|
GlAttributes {
|
||||||
|
sharing: None,
|
||||||
|
version: GlRequest::Latest,
|
||||||
|
profile: None,
|
||||||
|
debug: cfg!(debug_assertions),
|
||||||
|
robustness: Robustness::NotRobust,
|
||||||
|
vsync: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mod native_monitor {
|
mod native_monitor {
|
||||||
/// Native platform identifier for a monitor. Different platforms use fundamentally different types
|
/// Native platform identifier for a monitor. Different platforms use fundamentally different types
|
||||||
/// to represent a monitor ID.
|
/// to represent a monitor ID.
|
||||||
|
|
|
@ -60,19 +60,19 @@ impl<'a> WindowBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// There are some exceptions, like FBOs or VAOs. See the OpenGL documentation.
|
/// There are some exceptions, like FBOs or VAOs. See the OpenGL documentation.
|
||||||
pub fn with_shared_lists(mut self, other: &'a Window) -> WindowBuilder<'a> {
|
pub fn with_shared_lists(mut self, other: &'a Window) -> WindowBuilder<'a> {
|
||||||
self.attribs.sharing = Some(&other.window);
|
self.attribs.opengl.sharing = Some(&other.window);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets how the backend should choose the OpenGL API and version.
|
/// Sets how the backend should choose the OpenGL API and version.
|
||||||
pub fn with_gl(mut self, request: GlRequest) -> WindowBuilder<'a> {
|
pub fn with_gl(mut self, request: GlRequest) -> WindowBuilder<'a> {
|
||||||
self.attribs.gl_version = request;
|
self.attribs.opengl.version = request;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the desired OpenGL context profile.
|
/// Sets the desired OpenGL context profile.
|
||||||
pub fn with_gl_profile(mut self, profile: GlProfile) -> WindowBuilder<'a> {
|
pub fn with_gl_profile(mut self, profile: GlProfile) -> WindowBuilder<'a> {
|
||||||
self.attribs.gl_profile = Some(profile);
|
self.attribs.opengl.profile = Some(profile);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,19 +81,19 @@ impl<'a> WindowBuilder<'a> {
|
||||||
/// The default value for this flag is `cfg!(debug_assertions)`, which means that it's enabled
|
/// The default value for this flag is `cfg!(debug_assertions)`, which means that it's enabled
|
||||||
/// when you run `cargo build` and disabled when you run `cargo build --release`.
|
/// when you run `cargo build` and disabled when you run `cargo build --release`.
|
||||||
pub fn with_gl_debug_flag(mut self, flag: bool) -> WindowBuilder<'a> {
|
pub fn with_gl_debug_flag(mut self, flag: bool) -> WindowBuilder<'a> {
|
||||||
self.attribs.gl_debug = flag;
|
self.attribs.opengl.debug = flag;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the robustness of the OpenGL context. See the docs of `Robustness`.
|
/// Sets the robustness of the OpenGL context. See the docs of `Robustness`.
|
||||||
pub fn with_gl_robustness(mut self, robustness: Robustness) -> WindowBuilder<'a> {
|
pub fn with_gl_robustness(mut self, robustness: Robustness) -> WindowBuilder<'a> {
|
||||||
self.attribs.gl_robustness = robustness;
|
self.attribs.opengl.robustness = robustness;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requests that the window has vsync enabled.
|
/// Requests that the window has vsync enabled.
|
||||||
pub fn with_vsync(mut self) -> WindowBuilder<'a> {
|
pub fn with_vsync(mut self) -> WindowBuilder<'a> {
|
||||||
self.attribs.vsync = true;
|
self.attribs.opengl.vsync = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue