Skip to content

Commit

Permalink
Make from_egl_context accept context::get_proc_address
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev committed Nov 29, 2024
1 parent b708932 commit 26706ea
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
10 changes: 7 additions & 3 deletions src/platform/egl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ impl Device {

/// Returns the descriptor that this context was created with.
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
GL_FUNCTIONS.with(|gl| unsafe {
ContextDescriptor::from_egl_context(gl, self.egl_display, context.egl_context)
})
unsafe {
ContextDescriptor::from_egl_context(
context::get_proc_address,
self.egl_display,
context.egl_context,
)
}
}

/// Makes the context the current OpenGL context for this thread.
Expand Down
14 changes: 9 additions & 5 deletions src/platform/generic/egl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,22 @@ impl ContextDescriptor {
})
}

pub(crate) unsafe fn from_egl_context(
gl: &Gl,
pub(crate) unsafe fn from_egl_context<F>(
get_proc_address: F,
egl_display: EGLDisplay,
egl_context: EGLContext,
) -> ContextDescriptor {
) -> ContextDescriptor
where
F: FnMut(&str) -> *const c_void,
{
let egl_config_id = get_context_attr(egl_display, egl_context, egl::CONFIG_ID as EGLint);

EGL_FUNCTIONS.with(|egl| {
let _guard = CurrentContextGuard::new();
egl.MakeCurrent(egl_display, egl::NO_SURFACE, egl::NO_SURFACE, egl_context);
let gl_version = GLVersion::current(gl);
let compatibility_profile = context::current_context_uses_compatibility_profile(gl);
let gl = unsafe { Gl::from_loader_function(get_proc_address) };
let gl_version = GLVersion::current(&gl);
let compatibility_profile = context::current_context_uses_compatibility_profile(&gl);

ContextDescriptor {
egl_config_id,
Expand Down
6 changes: 3 additions & 3 deletions src/platform/unix/generic/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ impl Device {
/// Returns the descriptor that this context was created with.
#[inline]
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
GL_FUNCTIONS.with(|gl| unsafe {
unsafe {
ContextDescriptor::from_egl_context(
gl,
context::get_proc_address,
self.native_connection.egl_display,
context.0.egl_context,
)
})
}
}

/// Makes the context the current OpenGL context for this thread.
Expand Down
6 changes: 3 additions & 3 deletions src/platform/unix/wayland/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ impl Device {
/// Returns the descriptor that this context was created with.
#[inline]
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
GL_FUNCTIONS.with(|gl| unsafe {
unsafe {
ContextDescriptor::from_egl_context(
gl,
context::get_proc_address,
self.native_connection.egl_display,
context.0.egl_context,
)
})
}
}

/// Makes the context the current OpenGL context for this thread.
Expand Down
6 changes: 3 additions & 3 deletions src/platform/unix/x11/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ impl Device {
/// Returns the descriptor that this context was created with.
#[inline]
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
GL_FUNCTIONS.with(|gl| unsafe {
unsafe {
ContextDescriptor::from_egl_context(
gl,
context::get_proc_address,
self.native_connection.egl_display,
context.0.egl_context,
)
})
}
}

/// Makes the context the current OpenGL context for this thread.
Expand Down
8 changes: 5 additions & 3 deletions src/platform/windows/angle/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ impl Device {
/// Returns the descriptor that this context was created with.
pub fn context_descriptor(&self, context: &Context) -> ContextDescriptor {
unsafe {
GL_FUNCTIONS.with(|gl| {
ContextDescriptor::from_egl_context(gl, self.egl_display, context.egl_context)
})
ContextDescriptor::from_egl_context(
context::get_proc_address,
self.egl_display,
context.egl_context,
)
}
}

Expand Down

0 comments on commit 26706ea

Please sign in to comment.