summaryrefslogtreecommitdiff
path: root/opengl-bindings/src/shader.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-05-28 19:56:43 +0200
committerHampusM <hampus@hampusmat.com>2026-05-28 19:56:43 +0200
commit038aead236e77f41e6d229510a5e25741a6815c6 (patch)
treefe50c328568f656e3528bef56b550b6b836c7102 /opengl-bindings/src/shader.rs
parentaba4f418af2e514c78fe06a1c98949670eaeacd9 (diff)
refactor(opengl-bindings): remove CurrentContextWithFns
Diffstat (limited to 'opengl-bindings/src/shader.rs')
-rw-r--r--opengl-bindings/src/shader.rs45
1 files changed, 26 insertions, 19 deletions
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,
)