Skip to content

Commit

Permalink
allow setting the opengl version to 3
Browse files Browse the repository at this point in the history
for hdr to work at least opengl3 is required.
So, now there is a feature that when enabled forces opengl3 to be used.
Once enabled every fallback to opengl2 are instead replaced by panics.
  • Loading branch information
lenscas committed Aug 26, 2023
1 parent 8e57f30 commit 27cd3b5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl Error for ShaderError {
pub enum TextureFormat {
RGB8,
RGBA8,
#[cfg(feature = "opengl3")]
RGBA16,
Depth,
Alpha,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl From<TextureFormat> 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")]
Expand Down
6 changes: 5 additions & 1 deletion src/native/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/native/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_![
Expand Down
33 changes: 23 additions & 10 deletions src/native/linux_x11/glx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 27cd3b5

Please sign in to comment.