Skip to content

Commit

Permalink
[oogl] fix armv7l support on which c_char is u8 and not i8
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitmel committed Dec 26, 2020
1 parent 707264b commit 60a1026
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions crates/cardboard_oogl/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T> !Send for VertexBuffer<T> {}
impl<T> !Sync for VertexBuffer<T> {}

unsafe impl<T: Copy> Object for VertexBuffer<T> {
const DEBUG_TYPE_IDENTIFIER: u32 = gl::BUFFER;
const DEBUG_TYPE_ID: u32 = gl::BUFFER;

#[inline(always)]
fn ctx(&self) -> &SharedContext { &self.ctx }
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<T: BufferIndex> !Send for ElementBuffer<T> {}
impl<T: BufferIndex> !Sync for ElementBuffer<T> {}

unsafe impl<T: BufferIndex> Object for ElementBuffer<T> {
const DEBUG_TYPE_IDENTIFIER: u32 = gl::BUFFER;
const DEBUG_TYPE_ID: u32 = gl::BUFFER;

#[inline(always)]
fn ctx(&self) -> &SharedContext { &self.ctx }
Expand Down
17 changes: 4 additions & 13 deletions crates/cardboard_oogl/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,19 @@ extern "system" fn internal_debug_message_callback(
);
}

pub(crate) unsafe fn set_object_debug_label(
ctx: &Context,
type_identifier: u32,
addr: u32,
label: &[u8],
) {
pub(crate) unsafe fn set_object_debug_label(ctx: &Context, type_id: u32, addr: u32, label: &[u8]) {
let gl = ctx.raw_gl();
if gl.ObjectLabel.is_loaded() {
let label_len = i32::try_from(label.len()).unwrap();
assert!(label_len <= ctx.capabilities().max_debug_object_label_len);

// TODO: Check that the label doesn't contain any NUL characters

gl.ObjectLabel(type_identifier, addr, label_len, label.as_ptr() as *const c_char);
gl.ObjectLabel(type_id, addr, label_len, label.as_ptr() as *const c_char);
}
}

pub(crate) unsafe fn get_object_debug_label(
ctx: &Context,
type_identifier: u32,
addr: u32,
) -> Vec<u8> {
pub(crate) unsafe fn get_object_debug_label(ctx: &Context, type_id: u32, addr: u32) -> Vec<u8> {
let gl = ctx.raw_gl();
if gl.GetObjectLabel.is_loaded() {
let buf_size =
Expand All @@ -103,7 +94,7 @@ pub(crate) unsafe fn get_object_debug_label(
let mut buf: Vec<u8> = Vec::with_capacity(buf_size as usize);
let mut text_len: i32 = 0;

gl.GetObjectLabel(type_identifier, addr, buf_size, &mut text_len, buf.as_mut_ptr() as *mut i8);
gl.GetObjectLabel(type_id, addr, buf_size, &mut text_len, buf.as_mut_ptr() as *mut c_char);
buf.set_len(text_len as usize);

buf
Expand Down
2 changes: 1 addition & 1 deletion crates/cardboard_oogl/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl !Send for Framebuffer {}
impl !Sync for Framebuffer {}

unsafe impl Object for Framebuffer {
const DEBUG_TYPE_IDENTIFIER: u32 = gl::FRAMEBUFFER;
const DEBUG_TYPE_ID: u32 = gl::FRAMEBUFFER;

#[inline(always)]
fn ctx(&self) -> &SharedContext { &self.ctx }
Expand Down
4 changes: 2 additions & 2 deletions crates/cardboard_oogl/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl !Send for Shader {}
impl !Sync for Shader {}

unsafe impl Object for Shader {
const DEBUG_TYPE_IDENTIFIER: u32 = gl::SHADER;
const DEBUG_TYPE_ID: u32 = gl::SHADER;

#[inline(always)]
fn ctx(&self) -> &SharedContext { &self.ctx }
Expand Down Expand Up @@ -118,7 +118,7 @@ pub const INACTIVE_ATTRIB_LOCATION: u32 = -1_i32 as u32;
const ARRAY_NAME_MARKER: &str = "[0]";

unsafe impl Object for Program {
const DEBUG_TYPE_IDENTIFIER: u32 = gl::PROGRAM;
const DEBUG_TYPE_ID: u32 = gl::PROGRAM;

#[inline(always)]
fn ctx(&self) -> &SharedContext { &self.ctx }
Expand Down
2 changes: 1 addition & 1 deletion crates/cardboard_oogl/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<T: TextureDataType> !Send for Texture2D<T> {}
impl<T: TextureDataType> !Sync for Texture2D<T> {}

unsafe impl<T: TextureDataType> Object for Texture2D<T> {
const DEBUG_TYPE_IDENTIFIER: u32 = gl::TEXTURE;
const DEBUG_TYPE_ID: u32 = gl::TEXTURE;

#[inline(always)]
fn ctx(&self) -> &SharedContext { &self.ctx }
Expand Down
8 changes: 3 additions & 5 deletions crates/cardboard_oogl/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use prelude_plus::*;
pub use crate::{Buffer, BufferBinding, DrawableBufferBinding, Texture, TextureBinding};

pub unsafe trait Object {
const DEBUG_TYPE_IDENTIFIER: u32;
const DEBUG_TYPE_ID: u32;

fn ctx(&self) -> &SharedContext;
fn addr(&self) -> u32;
Expand All @@ -14,13 +14,11 @@ pub unsafe trait Object {
fn raw_gl(&self) -> &RawGL { self.ctx().raw_gl() }

fn set_debug_label(&self, label: &[u8]) {
let type_identifier = Self::DEBUG_TYPE_IDENTIFIER;
unsafe { debug::set_object_debug_label(self.ctx(), type_identifier, self.addr(), label) };
unsafe { debug::set_object_debug_label(self.ctx(), Self::DEBUG_TYPE_ID, self.addr(), label) };
}

fn get_debug_label(&self) -> Vec<u8> {
let type_identifier = Self::DEBUG_TYPE_IDENTIFIER;
unsafe { debug::get_object_debug_label(self.ctx(), type_identifier, self.addr()) }
unsafe { debug::get_object_debug_label(self.ctx(), Self::DEBUG_TYPE_ID, self.addr()) }
}
}

Expand Down

0 comments on commit 60a1026

Please sign in to comment.