Skip to content

Commit

Permalink
Always provide the GL profile
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Dec 15, 2017
1 parent 007b9c2 commit 1b0ca01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ impl<'a> HeadlessRendererBuilder<'a> {
pub fn new(width: u32, height: u32) -> HeadlessRendererBuilder<'a> {
HeadlessRendererBuilder {
dimensions: (width, height),
pf_reqs: Default::default(),
pf_reqs: PixelFormatRequirements {
hardware_accelerated: None,
.. Default::default()
},
opengl: Default::default(),
platform_specific: Default::default(),
}
Expand Down
19 changes: 8 additions & 11 deletions src/platform/macos/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use cocoa::base::nil;

pub fn get_gl_profile<T>(
opengl: &GlAttributes<&T>
) -> Result<Option<NSOpenGLPFAOpenGLProfiles>, CreationError> {
) -> Result<NSOpenGLPFAOpenGLProfiles, CreationError> {
let version = opengl.version.to_gl_version();
// first, compatibility profile support is strict
if opengl.profile == Some(GlProfile::Compatibility) {
// Note: we are not using ranges because of a rust bug that should be fixed here:
// https://github.com/rust-lang/rust/pull/27050
if version.unwrap_or((2, 1)) < (3, 2) {
Ok(Some(NSOpenGLProfileVersionLegacy))
Ok(NSOpenGLProfileVersionLegacy)
} else {
Err(CreationError::OpenGlVersionNotSupported)
}
Expand All @@ -26,9 +26,9 @@ pub fn get_gl_profile<T>(
if v < (3, 2) {
Err(CreationError::OpenGlVersionNotSupported)
} else if v == (3, 2) {
Ok(Some(NSOpenGLProfileVersion3_2Core))
Ok(NSOpenGLProfileVersion3_2Core)
} else {
Ok(Some(NSOpenGLProfileVersion4_1Core))
Ok(NSOpenGLProfileVersion4_1Core)
}
} else if let GlRequest::Latest = opengl.version {
// now, find the latest supported version automatically
Expand All @@ -46,18 +46,18 @@ pub fn get_gl_profile<T>(
};
if id != nil {
unsafe { msg_send![id, release] }
return Ok(Some(profile));
return Ok(profile);
}
}
// nothing else to do
Ok(None)
Ok(NSOpenGLProfileVersionLegacy)
} else {
Err(CreationError::OpenGlVersionNotSupported)
}
}

pub fn build_nsattributes(
pf_reqs: &PixelFormatRequirements, profile: Option<NSOpenGLPFAOpenGLProfiles>
pf_reqs: &PixelFormatRequirements, profile: NSOpenGLPFAOpenGLProfiles
) -> Result<Vec<u32>, CreationError> {
// NOTE: OS X no longer has the concept of setting individual
// color component's bit size. Instead we can only specify the
Expand All @@ -68,6 +68,7 @@ pub fn build_nsattributes(
let color_depth = pf_reqs.color_bits.unwrap_or(24) + alpha_depth;

let mut attributes = vec![
NSOpenGLPFAOpenGLProfile as u32, profile as u32,
NSOpenGLPFAClosestPolicy as u32,
NSOpenGLPFAColorSize as u32, color_depth as u32,
NSOpenGLPFAAlphaSize as u32, alpha_depth as u32,
Expand All @@ -80,10 +81,6 @@ pub fn build_nsattributes(
attributes.push(NSOpenGLPFAAccelerated as u32);
}

if let Some(profile) = profile {
attributes.push(NSOpenGLPFAOpenGLProfile as u32); attributes.push(profile as u32);
}

if let Some(true) = pf_reqs.double_buffer {
attributes.push(NSOpenGLPFADoubleBuffer as u32);
}
Expand Down

0 comments on commit 1b0ca01

Please sign in to comment.