use super::GpuBackend;
pub struct OpenGLBackend;
impl GpuBackend for OpenGLBackend {
fn is_available(&self) -> bool {
true
}
fn add(&self, a: &[f32], b: &[f32], out: &mut [f32]) -> Result<(), String> {
for i in 0..a.len() {
out[i] = a[i] + b[i];
}
Ok(())
}
fn sub(&self, a: &[f32], b: &[f32], out: &mut [f32]) -> Result<(), String> {
for i in 0..a.len() {
out[i] = a[i] - b[i];
}
Ok(())
}
fn mul(&self, a: &[f32], b: &[f32], out: &mut [f32]) -> Result<(), String> {
for i in 0..a.len() {
out[i] = a[i] * b[i];
}
Ok(())
}
fn dot(&self, a: &[f32], b: &[f32]) -> Result<f32, String> {
let mut sum = 0.0;
for i in 0..a.len() {
sum += a[i] * b[i];
}
Ok(sum)
}
fn name(&self) -> &'static str { "OpenGL" }
}