diff --git a/Cargo.toml b/Cargo.toml index 93d02dff..70a1018c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ categories = ["rendering::graphics-api"] # Optional log-rs like macros implementation # disabled by default log-impl = [] +opengl3 = [] [target.'cfg(target_os = "linux")'.dependencies] libc = "0.2" diff --git a/src/graphics.rs b/src/graphics.rs index b3b77b15..0dbcc1ad 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -304,6 +304,7 @@ impl Error for ShaderError { pub enum TextureFormat { RGB8, RGBA8, + #[cfg(feature = "opengl3")] RGBA16, Depth, Alpha, @@ -315,6 +316,7 @@ impl TextureFormat { match self { TextureFormat::RGB8 => 3 * square, TextureFormat::RGBA8 => 4 * square, + #[cfg(feature = "opengl3")] TextureFormat::RGBA16 => 4 * square, TextureFormat::Depth => 2 * square, TextureFormat::Alpha => 1 * square, diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index 97e7ed78..c09d606a 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -57,6 +57,7 @@ impl From for (GLenum, GLenum, GLenum) { match format { TextureFormat::RGB8 => (GL_RGB, GL_RGB, GL_UNSIGNED_BYTE), TextureFormat::RGBA8 => (GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), + #[cfg(feature = "opengl3")] TextureFormat::RGBA16 => (GL_RGBA16F,GL_RGBA, GL_UNSIGNED_BYTE), TextureFormat::Depth => (GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT), #[cfg(target_arch = "wasm32")] diff --git a/src/native/egl.rs b/src/native/egl.rs index 47314f36..0ce3fe2d 100644 --- a/src/native/egl.rs +++ b/src/native/egl.rs @@ -324,7 +324,11 @@ pub unsafe fn create_egl_context( if !exact_cfg_found { config = available_cfgs[0]; } - let ctx_attributes = vec![EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE]; + let ctx_attributes = if cfg!(target="opengl3") { + vec![EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE] + } else { + vec![EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE] + }; let context = (egl.eglCreateContext.unwrap())( display, config, diff --git a/src/native/ios.rs b/src/native/ios.rs index 8bb4d71c..bdd7a00b 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -250,8 +250,12 @@ unsafe fn create_opengl_view(screen_rect: NSRect, _sample_count: i32, high_dpi: let mut eagl_context_obj: ObjcId = msg_send![eagl_context_obj, initWithAPI: 3]; let mut gles2 = false; if eagl_context_obj.is_null() { - eagl_context_obj = msg_send![eagl_context_obj, initWithAPI: 2]; - gles2 = true; + if cfg!(target = "opengl3") { + panic!("unsupported opengl version") + } else { + eagl_context_obj = msg_send![eagl_context_obj, initWithAPI: 2]; + gles2 = true; + } } msg_send_![ diff --git a/src/native/linux_x11/glx.rs b/src/native/linux_x11/glx.rs index 675ff597..7a6740f7 100644 --- a/src/native/linux_x11/glx.rs +++ b/src/native/linux_x11/glx.rs @@ -311,16 +311,29 @@ impl Glx { } // _sapp_x11_grab_error_handler(libx11); - let attribs: [libc::c_int; 8] = [ - GLX_CONTEXT_MAJOR_VERSION_ARB, - 2, - GLX_CONTEXT_MINOR_VERSION_ARB, - 1, - GLX_CONTEXT_FLAGS_ARB, - GLX_CONTEXT_CORE_PROFILE_BIT_ARB, - 0, - 0, - ]; + let attribs: [libc::c_int; 8] = if(cfg!(feature="opengl3")){ + [ + GLX_CONTEXT_MAJOR_VERSION_ARB, + 3, + GLX_CONTEXT_MINOR_VERSION_ARB, + 1, + GLX_CONTEXT_FLAGS_ARB, + GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + 0, + 0, + ] + } else { + [ + GLX_CONTEXT_MAJOR_VERSION_ARB, + 2, + GLX_CONTEXT_MINOR_VERSION_ARB, + 1, + GLX_CONTEXT_FLAGS_ARB, + GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + 0, + 0, + ] + }; let glx_ctx = self.extensions.glxCreateContextAttribsARB.unwrap()( display, self.fbconfig,