summaryrefslogtreecommitdiff
path: root/opengl-bindings
diff options
context:
space:
mode:
Diffstat (limited to 'opengl-bindings')
-rw-r--r--opengl-bindings/src/blending.rs4
-rw-r--r--opengl-bindings/src/buffer.rs16
-rw-r--r--opengl-bindings/src/debug.rs6
-rw-r--r--opengl-bindings/src/lib.rs29
-rw-r--r--opengl-bindings/src/misc.rs24
-rw-r--r--opengl-bindings/src/shader.rs45
-rw-r--r--opengl-bindings/src/texture.rs18
-rw-r--r--opengl-bindings/src/vertex_array.rs22
8 files changed, 82 insertions, 82 deletions
diff --git a/opengl-bindings/src/blending.rs b/opengl-bindings/src/blending.rs
index 5e8c1ef..a855c2a 100644
--- a/opengl-bindings/src/blending.rs
+++ b/opengl-bindings/src/blending.rs
@@ -1,7 +1,7 @@
-use crate::CurrentContextWithFns;
+use crate::MaybeCurrentContextWithFns;
pub fn configure(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
configuration: Configuration,
)
{
diff --git a/opengl-bindings/src/buffer.rs b/opengl-bindings/src/buffer.rs
index edbf2a3..5045855 100644
--- a/opengl-bindings/src/buffer.rs
+++ b/opengl-bindings/src/buffer.rs
@@ -4,7 +4,7 @@ use std::ptr::null;
use safer_ffi::layout::ReprC;
-use crate::CurrentContextWithFns;
+use crate::MaybeCurrentContextWithFns;
#[derive(Debug)]
pub struct Buffer<Item: ReprC>
@@ -16,7 +16,7 @@ pub struct Buffer<Item: ReprC>
impl<Item: ReprC> Buffer<Item>
{
#[must_use]
- pub fn new(current_context: &CurrentContextWithFns<'_>) -> Self
+ pub fn new(current_context: &MaybeCurrentContextWithFns) -> Self
{
let mut buffer = crate::sys::types::GLuint::default();
@@ -33,7 +33,7 @@ impl<Item: ReprC> Buffer<Item>
/// Returns `Err` if the size (in bytes) is too large.
pub fn init(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
size: usize,
usage: Usage,
) -> Result<(), Error>
@@ -62,7 +62,7 @@ impl<Item: ReprC> Buffer<Item>
/// Returns `Err` if the total size (in bytes) is too large.
pub fn store(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
items: &[Item],
usage: Usage,
) -> Result<(), Error>
@@ -93,7 +93,7 @@ impl<Item: ReprC> Buffer<Item>
/// Returns `Err` if the total size (in bytes) is too large.
pub fn store_at_byte_offset(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
byte_offset: usize,
items: &[Item],
// usage: Usage,
@@ -135,7 +135,7 @@ impl<Item: ReprC> Buffer<Item>
/// Returns `Err` if the total size (in bytes) is too large.
pub fn store_mapped<Value>(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
values: &[Value],
usage: Usage,
mut map_func: impl FnMut(&Value) -> Item,
@@ -187,7 +187,7 @@ impl<Item: ReprC> Buffer<Item>
Ok(())
}
- pub fn delete(&self, current_context: &CurrentContextWithFns<'_>)
+ pub fn delete(&self, current_context: &MaybeCurrentContextWithFns)
{
unsafe {
current_context.fns().DeleteBuffers(1, &raw const self.buf);
@@ -196,7 +196,7 @@ impl<Item: ReprC> Buffer<Item>
pub fn bind_to_indexed_target(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
target: BindingTarget,
index: u32,
)
diff --git a/opengl-bindings/src/debug.rs b/opengl-bindings/src/debug.rs
index a9369a4..167173f 100644
--- a/opengl-bindings/src/debug.rs
+++ b/opengl-bindings/src/debug.rs
@@ -5,10 +5,10 @@ use std::panic::catch_unwind;
use util_macros::FromRepr;
-use crate::CurrentContextWithFns;
+use crate::MaybeCurrentContextWithFns;
pub fn set_debug_message_callback(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
cb: MessageCallback,
)
{
@@ -24,7 +24,7 @@ pub fn set_debug_message_callback(
/// # Errors
/// Returns `Err` if `ids` contains too many ids.
pub fn set_debug_message_control(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
source: Option<MessageSource>,
ty: Option<MessageType>,
severity: Option<MessageSeverity>,
diff --git a/opengl-bindings/src/lib.rs b/opengl-bindings/src/lib.rs
index cfdfa35..e4ae27d 100644
--- a/opengl-bindings/src/lib.rs
+++ b/opengl-bindings/src/lib.rs
@@ -16,13 +16,13 @@ pub mod shader;
pub mod texture;
pub mod vertex_array;
-pub struct ContextWithFns
+pub struct MaybeCurrentContextWithFns
{
context: PossiblyCurrentContext,
fns: Box<sys::Gl>,
}
-impl ContextWithFns
+impl MaybeCurrentContextWithFns
{
/// Returns a new `ContextWithFns`.
///
@@ -51,14 +51,15 @@ impl ContextWithFns
Ok(Self { context, fns: Box::new(gl) })
}
- /// Attempts to make this context current.
+ /// Attempts to make this context & the specified surface current in the current
+ /// thread.
///
/// # Errors
/// Returns `Err` if making this context current fails.
pub fn make_current<SurfaceType: SurfaceTypeTrait>(
&self,
surface: &Surface<SurfaceType>,
- ) -> Result<CurrentContextWithFns<'_>, MakeContextCurrentError>
+ ) -> Result<(), MakeContextCurrentError>
{
if !self.context.is_current() || !surface.is_current(&self.context) {
self.context
@@ -66,7 +67,7 @@ impl ContextWithFns
.map_err(MakeContextCurrentError)?;
}
- Ok(CurrentContextWithFns { ctx: self })
+ Ok(())
}
#[must_use]
@@ -75,24 +76,12 @@ impl ContextWithFns
&self.context
}
- #[must_use]
- pub fn context_mut(&mut self) -> &mut PossiblyCurrentContext
- {
- &mut self.context
- }
-}
-
-pub struct CurrentContextWithFns<'ctx>
-{
- ctx: &'ctx ContextWithFns,
-}
-
-impl CurrentContextWithFns<'_>
-{
#[inline]
pub(crate) fn fns(&self) -> &sys::Gl
{
- &self.ctx.fns
+ debug_assert!(self.context.is_current());
+
+ &self.fns
}
}
diff --git a/opengl-bindings/src/misc.rs b/opengl-bindings/src/misc.rs
index 8d871b1..047221b 100644
--- a/opengl-bindings/src/misc.rs
+++ b/opengl-bindings/src/misc.rs
@@ -1,7 +1,7 @@
use bitflags::bitflags;
use crate::data_types::{Dimens, Vec2};
-use crate::CurrentContextWithFns;
+use crate::MaybeCurrentContextWithFns;
/// Sets the viewport.
///
@@ -10,7 +10,7 @@ use crate::CurrentContextWithFns;
/// # Errors
/// Returns `Err` if any value in `position` or `size` does not fit into a `i32`.
pub fn set_viewport(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
position: &Vec2<u32>,
size: &Dimens<u32>,
) -> Result<(), SetViewportError>
@@ -55,7 +55,7 @@ pub fn set_viewport(
}
pub fn get_viewport(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
) -> (Vec2<u32>, Dimens<u32>)
{
let mut values = [0i32; 4];
@@ -81,7 +81,10 @@ pub fn get_viewport(
(pos, size)
}
-pub fn clear_buffers(current_context: &CurrentContextWithFns<'_>, mask: BufferClearMask)
+pub fn clear_buffers(
+ current_context: &MaybeCurrentContextWithFns,
+ mask: BufferClearMask,
+)
{
unsafe {
current_context.fns().Clear(mask.bits());
@@ -89,7 +92,7 @@ pub fn clear_buffers(current_context: &CurrentContextWithFns<'_>, mask: BufferCl
}
pub fn set_polygon_mode(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
face: impl Into<PolygonModeFace>,
mode: impl Into<PolygonMode>,
)
@@ -101,14 +104,14 @@ pub fn set_polygon_mode(
}
}
-pub fn enable(current_context: &CurrentContextWithFns<'_>, capacity: Capability)
+pub fn enable(current_context: &MaybeCurrentContextWithFns, capacity: Capability)
{
unsafe {
current_context.fns().Enable(capacity as u32);
}
}
-pub fn disable(current_context: &CurrentContextWithFns<'_>, capability: Capability)
+pub fn disable(current_context: &MaybeCurrentContextWithFns, capability: Capability)
{
unsafe {
current_context.fns().Disable(capability as u32);
@@ -116,7 +119,7 @@ pub fn disable(current_context: &CurrentContextWithFns<'_>, capability: Capabili
}
pub fn set_enabled(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
capability: Capability,
enabled: bool,
)
@@ -129,7 +132,8 @@ pub fn set_enabled(
}
#[must_use]
-pub fn get_context_flags(current_context: &CurrentContextWithFns<'_>) -> ContextFlags
+pub fn get_context_flags(current_context: &MaybeCurrentContextWithFns)
+ -> ContextFlags
{
let mut context_flags = crate::sys::types::GLint::default();
@@ -144,7 +148,7 @@ pub fn get_context_flags(current_context: &CurrentContextWithFns<'_>) -> Context
/// Defines a rectangle, called the scissor box, in window coordinates.
pub fn define_scissor_box(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
lower_left_corner_pos: Vec2<u16>,
size: Dimens<u16>,
)
diff --git a/opengl-bindings/src/shader.rs b/opengl-bindings/src/shader.rs
index 7eb1ac9..00fec58 100644
--- a/opengl-bindings/src/shader.rs
+++ b/opengl-bindings/src/shader.rs
@@ -4,7 +4,7 @@ use std::ptr::null_mut;
use safer_ffi::layout::ReprC;
use crate::data_types::{Matrix, Vec3};
-use crate::CurrentContextWithFns;
+use crate::MaybeCurrentContextWithFns;
#[derive(Debug)]
pub struct Shader
@@ -15,7 +15,7 @@ pub struct Shader
impl Shader
{
#[must_use]
- pub fn new(current_context: &CurrentContextWithFns<'_>, kind: Kind) -> Self
+ pub fn new(current_context: &MaybeCurrentContextWithFns, kind: Kind) -> Self
{
let shader = unsafe {
current_context
@@ -32,7 +32,7 @@ impl Shader
/// Returns `Err` if `source` is not ASCII.
pub fn set_source(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
source: &str,
) -> Result<(), Error>
{
@@ -64,7 +64,7 @@ impl Shader
/// Returns `Err` if compiling fails.
pub fn compile(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
) -> Result<(), Error>
{
unsafe {
@@ -90,14 +90,14 @@ impl Shader
Ok(())
}
- pub fn delete(self, current_context: &CurrentContextWithFns<'_>)
+ pub fn delete(self, current_context: &MaybeCurrentContextWithFns)
{
unsafe {
current_context.fns().DeleteShader(self.shader);
}
}
- fn get_info_log(&self, current_context: &CurrentContextWithFns<'_>) -> String
+ fn get_info_log(&self, current_context: &MaybeCurrentContextWithFns) -> String
{
const BUF_SIZE: crate::sys::types::GLsizei = 512;
@@ -137,14 +137,18 @@ pub struct Program
impl Program
{
#[must_use]
- pub fn new(current_context: &CurrentContextWithFns<'_>) -> Self
+ pub fn new(current_context: &MaybeCurrentContextWithFns) -> Self
{
let program = unsafe { current_context.fns().CreateProgram() };
Self { program }
}
- pub fn attach(&self, current_context: &CurrentContextWithFns<'_>, shader: &Shader)
+ pub fn attach(
+ &self,
+ current_context: &MaybeCurrentContextWithFns,
+ shader: &Shader,
+ )
{
unsafe {
current_context
@@ -157,7 +161,10 @@ impl Program
///
/// # Errors
/// Returns `Err` if linking fails.
- pub fn link(&self, current_context: &CurrentContextWithFns<'_>) -> Result<(), Error>
+ pub fn link(
+ &self,
+ current_context: &MaybeCurrentContextWithFns,
+ ) -> Result<(), Error>
{
unsafe {
current_context.fns().LinkProgram(self.program);
@@ -182,7 +189,7 @@ impl Program
Ok(())
}
- pub fn activate(&self, current_context: &CurrentContextWithFns<'_>)
+ pub fn activate(&self, current_context: &MaybeCurrentContextWithFns)
{
unsafe {
current_context.fns().UseProgram(self.program);
@@ -191,7 +198,7 @@ impl Program
pub fn set_uniform_at_location(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
location: UniformLocation,
var: &impl UniformVariable,
)
@@ -201,7 +208,7 @@ impl Program
pub fn set_uniform(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
name: &CStr,
var: &impl UniformVariable,
)
@@ -225,14 +232,14 @@ impl Program
self.program
}
- pub fn delete(self, current_context: &CurrentContextWithFns<'_>)
+ pub fn delete(self, current_context: &MaybeCurrentContextWithFns)
{
unsafe {
current_context.fns().DeleteProgram(self.program);
}
}
- fn get_info_log(&self, current_context: &CurrentContextWithFns<'_>) -> String
+ fn get_info_log(&self, current_context: &MaybeCurrentContextWithFns) -> String
{
const BUF_SIZE: crate::sys::types::GLsizei = 512;
@@ -257,7 +264,7 @@ pub trait UniformVariable: ReprC + sealed::Sealed
{
fn set(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
program: &Program,
uniform_location: UniformLocation,
);
@@ -267,7 +274,7 @@ impl UniformVariable for f32
{
fn set(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
program: &Program,
uniform_location: UniformLocation,
)
@@ -288,7 +295,7 @@ impl UniformVariable for i32
{
fn set(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
program: &Program,
uniform_location: UniformLocation,
)
@@ -309,7 +316,7 @@ impl UniformVariable for Vec3<f32>
{
fn set(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
program: &Program,
uniform_location: UniformLocation,
)
@@ -332,7 +339,7 @@ impl UniformVariable for Matrix<f32, 4, 4>
{
fn set(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
program: &Program,
uniform_location: UniformLocation,
)
diff --git a/opengl-bindings/src/texture.rs b/opengl-bindings/src/texture.rs
index 391ae0e..e0035b6 100644
--- a/opengl-bindings/src/texture.rs
+++ b/opengl-bindings/src/texture.rs
@@ -1,5 +1,5 @@
use crate::data_types::Dimens;
-use crate::CurrentContextWithFns;
+use crate::MaybeCurrentContextWithFns;
#[derive(Debug)]
pub struct Texture
@@ -10,7 +10,7 @@ pub struct Texture
impl Texture
{
#[must_use]
- pub fn new(current_context: &CurrentContextWithFns<'_>) -> Self
+ pub fn new(current_context: &MaybeCurrentContextWithFns) -> Self
{
let mut texture = crate::sys::types::GLuint::default();
@@ -27,7 +27,7 @@ impl Texture
pub fn bind_to_texture_unit(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
texture_unit: u32,
)
{
@@ -44,7 +44,7 @@ impl Texture
/// Returns `Err` if any value in `size` does not fit into a `i32`.
pub fn generate(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
size: &Dimens<u32>,
data: &[u8],
pixel_data_format: PixelDataFormat,
@@ -77,7 +77,7 @@ impl Texture
pub fn set_wrap(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
wrapping: Wrapping,
)
{
@@ -98,7 +98,7 @@ impl Texture
pub fn set_magnifying_filter(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
filtering: Filtering,
)
{
@@ -113,7 +113,7 @@ impl Texture
pub fn set_minifying_filter(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
filtering: Filtering,
)
{
@@ -126,7 +126,7 @@ impl Texture
}
}
- pub fn delete(self, current_context: &CurrentContextWithFns<'_>)
+ pub fn delete(self, current_context: &MaybeCurrentContextWithFns)
{
unsafe {
current_context
@@ -147,7 +147,7 @@ impl Texture
fn alloc_image(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
pixel_data_format: PixelDataFormat,
color_space: ColorSpace,
size: &Dimens<crate::sys::types::GLsizei>,
diff --git a/opengl-bindings/src/vertex_array.rs b/opengl-bindings/src/vertex_array.rs
index 30afde4..74ef899 100644
--- a/opengl-bindings/src/vertex_array.rs
+++ b/opengl-bindings/src/vertex_array.rs
@@ -3,7 +3,7 @@ use std::ffi::c_void;
use safer_ffi::layout::ReprC;
use crate::buffer::Buffer;
-use crate::CurrentContextWithFns;
+use crate::MaybeCurrentContextWithFns;
#[derive(Debug)]
pub struct VertexArray
@@ -14,7 +14,7 @@ pub struct VertexArray
impl VertexArray
{
#[must_use]
- pub fn new(current_context: &CurrentContextWithFns<'_>) -> Self
+ pub fn new(current_context: &MaybeCurrentContextWithFns) -> Self
{
let mut array = 0;
@@ -32,7 +32,7 @@ impl VertexArray
/// - `vertex_offset` is too large
/// - `vertex_cnt` is too large
pub fn draw_arrays(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
primitive_kind: PrimitiveKind,
vertex_offset: u32,
vertex_cnt: u32,
@@ -70,7 +70,7 @@ impl VertexArray
/// # Errors
/// Returns `Err` if `cnt` is too large.
pub fn draw_elements(
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
DrawElementsOptions {
primitive_kind,
element_offset,
@@ -115,7 +115,7 @@ impl VertexArray
pub fn bind_element_buffer(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
element_buffer: &Buffer<u32>,
)
{
@@ -128,7 +128,7 @@ impl VertexArray
pub fn bind_vertex_buffer<VertexBufferItem: ReprC>(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
binding_index: u32,
vertex_buffer: &Buffer<VertexBufferItem>,
vertex_buffer_spec: VertexBufferSpec,
@@ -165,7 +165,7 @@ impl VertexArray
pub fn enable_attrib(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
attrib_index: u32,
)
{
@@ -179,7 +179,7 @@ impl VertexArray
pub fn set_attrib_format(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
attrib_index: u32,
attrib_format: AttributeFormat,
)
@@ -203,7 +203,7 @@ impl VertexArray
/// Associate a vertex attribute and a vertex buffer binding.
pub fn set_attrib_vertex_buf_binding(
&self,
- current_context: &CurrentContextWithFns<'_>,
+ current_context: &MaybeCurrentContextWithFns,
attrib_index: u32,
vertex_buf_binding_index: u32,
)
@@ -217,12 +217,12 @@ impl VertexArray
}
}
- pub fn bind(&self, current_context: &CurrentContextWithFns<'_>)
+ pub fn bind(&self, current_context: &MaybeCurrentContextWithFns)
{
unsafe { current_context.fns().BindVertexArray(self.array) }
}
- pub fn delete(&self, current_context: &CurrentContextWithFns<'_>)
+ pub fn delete(&self, current_context: &MaybeCurrentContextWithFns)
{
unsafe {
current_context