Skip to content

Commit

Permalink
examples: prefer ptr::cast() over as casts
Browse files Browse the repository at this point in the history
Fixes pedantic clippy lint `ptr_as_ptr`.

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
  • Loading branch information
jschwe committed Aug 29, 2024
1 parent fc792a6 commit 0133d63
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Shader {
gl::ShaderSource(
shader,
1,
&(source.as_ptr() as *const GLchar),
&(source.as_ptr().cast()),
&(source.len() as GLint),
);
ck();
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Buffer {
gl::BufferData(
gl::ARRAY_BUFFER,
data.len() as isize,
data.as_ptr() as *const c_void,
data.as_ptr().cast(),
gl::STATIC_DRAW,
);
ck();
Expand Down
6 changes: 3 additions & 3 deletions examples/offscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl TriVertexArray {
ck();

let vertex_buffer = Buffer::from_data(slice::from_raw_parts(
TRI_VERTICES.as_ptr() as *const u8,
TRI_VERTICES.as_ptr().cast(),
mem::size_of::<Vertex>() * 3,
));

Expand Down Expand Up @@ -251,10 +251,10 @@ impl TriProgram {
let program = Program::new(vertex_shader, fragment_shader);
unsafe {
let position_attribute =
gl::GetAttribLocation(program.object, c"aPosition".as_ptr() as *const GLchar);
gl::GetAttribLocation(program.object, c"aPosition".as_ptr().cast());
ck();
let color_attribute =
gl::GetAttribLocation(program.object, c"aColor".as_ptr() as *const GLchar);
gl::GetAttribLocation(program.object, c"aColor".as_ptr().cast());
ck();
TriProgram {
program,
Expand Down
60 changes: 30 additions & 30 deletions examples/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,26 +811,26 @@ impl BlitProgram {
let program = Program::new(vertex_shader, fragment_shader);
unsafe {
let position_attribute =
gl::GetAttribLocation(program.object, c"aPosition".as_ptr() as *const GLchar);
gl::GetAttribLocation(program.object, c"aPosition".as_ptr().cast());
ck();
let transform_uniform =
gl::GetUniformLocation(program.object, c"uTransform".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uTransform".as_ptr().cast());
ck();
let translation_uniform =
gl::GetUniformLocation(program.object, c"uTranslation".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uTranslation".as_ptr().cast());
ck();
let tex_transform_uniform = gl::GetUniformLocation(
program.object,
c"uTexTransform".as_ptr() as *const GLchar,
c"uTexTransform".as_ptr().cast(),
);
ck();
let tex_translation_uniform = gl::GetUniformLocation(
program.object,
c"uTexTranslation".as_ptr() as *const GLchar,
c"uTexTranslation".as_ptr().cast(),
);
ck();
let source_uniform =
gl::GetUniformLocation(program.object, c"uSource".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uSource".as_ptr().cast());
ck();
BlitProgram {
program,
Expand Down Expand Up @@ -883,48 +883,48 @@ impl GridProgram {
let program = Program::new(vertex_shader, fragment_shader);
unsafe {
let position_attribute =
gl::GetAttribLocation(program.object, c"aPosition".as_ptr() as *const GLchar);
gl::GetAttribLocation(program.object, c"aPosition".as_ptr().cast());
ck();
let transform_uniform =
gl::GetUniformLocation(program.object, c"uTransform".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uTransform".as_ptr().cast());
ck();
let translation_uniform =
gl::GetUniformLocation(program.object, c"uTranslation".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uTranslation".as_ptr().cast());
ck();
let tex_transform_uniform = gl::GetUniformLocation(
program.object,
c"uTexTransform".as_ptr() as *const GLchar,
c"uTexTransform".as_ptr().cast(),
);
ck();
let tex_translation_uniform = gl::GetUniformLocation(
program.object,
c"uTexTranslation".as_ptr() as *const GLchar,
c"uTexTranslation".as_ptr().cast(),
);
ck();
let gridline_color_uniform = gl::GetUniformLocation(
program.object,
c"uGridlineColor".as_ptr() as *const GLchar,
c"uGridlineColor".as_ptr().cast(),
);
ck();
let bg_color_uniform =
gl::GetUniformLocation(program.object, c"uBGColor".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uBGColor".as_ptr().cast());
ck();
let radius_uniform =
gl::GetUniformLocation(program.object, c"uRadius".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uRadius".as_ptr().cast());
ck();
let camera_position_uniform = gl::GetUniformLocation(
program.object,
c"uCameraPosition".as_ptr() as *const GLchar,
c"uCameraPosition".as_ptr().cast(),
);
ck();
let light_position_uniform = gl::GetUniformLocation(
program.object,
c"uLightPosition".as_ptr() as *const GLchar,
c"uLightPosition".as_ptr().cast(),
);
ck();
let sphere_position_uniform = gl::GetUniformLocation(
program.object,
c"uSpherePosition".as_ptr() as *const GLchar,
c"uSpherePosition".as_ptr().cast(),
);
ck();
GridProgram {
Expand Down Expand Up @@ -985,54 +985,54 @@ impl CheckProgram {
let program = Program::new(vertex_shader, fragment_shader);
unsafe {
let position_attribute =
gl::GetAttribLocation(program.object, c"aPosition".as_ptr() as *const GLchar);
gl::GetAttribLocation(program.object, c"aPosition".as_ptr().cast());
ck();
let transform_uniform =
gl::GetUniformLocation(program.object, c"uTransform".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uTransform".as_ptr().cast());
ck();
let translation_uniform =
gl::GetUniformLocation(program.object, c"uTranslation".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uTranslation".as_ptr().cast());
ck();
let tex_transform_uniform = gl::GetUniformLocation(
program.object,
c"uTexTransform".as_ptr() as *const GLchar,
c"uTexTransform".as_ptr().cast(),
);
ck();
let tex_translation_uniform = gl::GetUniformLocation(
program.object,
c"uTexTranslation".as_ptr() as *const GLchar,
c"uTexTranslation".as_ptr().cast(),
);
ck();
let rotation_uniform =
gl::GetUniformLocation(program.object, c"uRotation".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uRotation".as_ptr().cast());
ck();
let color_a_uniform =
gl::GetUniformLocation(program.object, c"uColorA".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uColorA".as_ptr().cast());
ck();
let color_b_uniform =
gl::GetUniformLocation(program.object, c"uColorB".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uColorB".as_ptr().cast());
ck();
let viewport_origin_uniform = gl::GetUniformLocation(
program.object,
c"uViewportOrigin".as_ptr() as *const GLchar,
c"uViewportOrigin".as_ptr().cast(),
);
ck();
let radius_uniform =
gl::GetUniformLocation(program.object, c"uRadius".as_ptr() as *const GLchar);
gl::GetUniformLocation(program.object, c"uRadius".as_ptr().cast());
ck();
let camera_position_uniform = gl::GetUniformLocation(
program.object,
c"uCameraPosition".as_ptr() as *const GLchar,
c"uCameraPosition".as_ptr().cast(),
);
ck();
let light_position_uniform = gl::GetUniformLocation(
program.object,
c"uLightPosition".as_ptr() as *const GLchar,
c"uLightPosition".as_ptr().cast(),
);
ck();
let sphere_position_uniform = gl::GetUniformLocation(
program.object,
c"uSpherePosition".as_ptr() as *const GLchar,
c"uSpherePosition".as_ptr().cast(),
);
ck();
CheckProgram {
Expand Down

0 comments on commit 0133d63

Please sign in to comment.