mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
more ergonomic uniform
This commit is contained in:
1 parent
f461cbf2b9
commit
514fb08ff1
2 files changed
+7
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
use anyhow::Result as AnyhowResult;
|
||||
use gl::types::*;
|
||||
use std::os::raw::c_char;
|
||||
use std::ffi::CString;
|
||||
|
||||
/// A typesafe handle on uniform IDs with convenience methods.
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
@@ -9,11 +10,13 @@ pub struct Uniform {
|
||||
}
|
||||
|
||||
impl Uniform {
|
||||
pub fn lookup(opengl_program_id: GLuint, identifier: *const c_char) -> AnyhowResult<Self> {
|
||||
let mut loc = -1;
|
||||
pub fn lookup(identifier: &str, opengl_program_id: GLuint) -> AnyhowResult<Self> {
|
||||
let id_cstr : CString = CString::new(identifier)?;
|
||||
let id_cstr_ptr : *const c_char = id_cstr.as_ptr() as *const c_char;
|
||||
|
||||
let mut loc = -1;
|
||||
unsafe {
|
||||
loc = gl::GetUniformLocation(opengl_program_id, identifier);
|
||||
loc = gl::GetUniformLocation(opengl_program_id, id_cstr_ptr);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -201,10 +201,6 @@ impl PointCloudRenderer {
|
||||
let PROJECTION : CString = CString::new("projection").expect("string is correct");
|
||||
let PROJECTION_PTR : *const c_char = PROJECTION.as_ptr() as *const c_char;
|
||||
|
||||
/// Uniform variable name in OpenGL shader program
|
||||
let MODEL_VIEW : CString = CString::new("modelView").expect("string is correct");
|
||||
let MODEL_VIEW_PTR : *const c_char = MODEL_VIEW.as_ptr() as *const c_char;
|
||||
|
||||
/// Uniform variable name in OpenGL shader program
|
||||
let ENABLE_SHADING : CString = CString::new("enableShading").expect("string is correct");
|
||||
let ENABLE_SHADING_PTR : *const c_char = ENABLE_SHADING.as_ptr() as *const c_char;
|
||||
@@ -238,7 +234,7 @@ impl PointCloudRenderer {
|
||||
point_cloud_texture_indices.push(gl::GetUniformLocation(program_id, POINT_CLOUD_1_PTR));
|
||||
}
|
||||
|
||||
let model_transform = Uniform::lookup(program_id, MODEL_VIEW_PTR).unwrap();
|
||||
let model_transform = Uniform::lookup("modelView", program_id).unwrap();
|
||||
|
||||
let color_vertex_attribute_location = unsafe {
|
||||
let location = gl::GetAttribLocation(program_id, COLOR_LOCATION_PTR);
|
||||
|
||||
Reference in new issue
Block a user