1
0
Fork 0
forked from wry/wry

all: replace ustr literals by cstr literals

This commit is contained in:
Julian Orth 2024-07-09 10:03:39 +02:00
parent 1a0181f2ac
commit e2cb37c4d8
5 changed files with 17 additions and 21 deletions

View file

@ -7,8 +7,7 @@ use {
}, },
RenderError, RenderError,
}, },
std::rc::Rc, std::{ffi::CStr, rc::Rc},
uapi::Ustr,
}; };
pub struct GlProgram { pub struct GlProgram {
@ -51,11 +50,11 @@ impl GlProgram {
Ok(res) Ok(res)
} }
pub unsafe fn get_uniform_location(&self, name: &Ustr) -> GLint { pub unsafe fn get_uniform_location(&self, name: &CStr) -> GLint {
(self.ctx.dpy.gles.glGetUniformLocation)(self.prog, name.as_ptr() as _) (self.ctx.dpy.gles.glGetUniformLocation)(self.prog, name.as_ptr() as _)
} }
pub unsafe fn get_attrib_location(&self, name: &Ustr) -> GLint { pub unsafe fn get_attrib_location(&self, name: &CStr) -> GLint {
(self.ctx.dpy.gles.glGetAttribLocation)(self.prog, name.as_ptr() as _) (self.ctx.dpy.gles.glGetAttribLocation)(self.prog, name.as_ptr() as _)
} }
} }

View file

@ -30,7 +30,6 @@ use {
fmt::{Debug, Formatter}, fmt::{Debug, Formatter},
rc::Rc, rc::Rc,
}, },
uapi::ustr,
}; };
pub(crate) struct TexProg { pub(crate) struct TexProg {
@ -44,13 +43,13 @@ pub(crate) struct TexProg {
impl TexProg { impl TexProg {
unsafe fn from(prog: GlProgram, alpha_multiplier: bool) -> Self { unsafe fn from(prog: GlProgram, alpha_multiplier: bool) -> Self {
let alpha = match alpha_multiplier { let alpha = match alpha_multiplier {
true => prog.get_uniform_location(ustr!("alpha")), true => prog.get_uniform_location(c"alpha"),
false => 0, false => 0,
}; };
Self { Self {
pos: prog.get_attrib_location(ustr!("pos")), pos: prog.get_attrib_location(c"pos"),
texcoord: prog.get_attrib_location(ustr!("texcoord")), texcoord: prog.get_attrib_location(c"texcoord"),
tex: prog.get_uniform_location(ustr!("tex")), tex: prog.get_uniform_location(c"tex"),
alpha, alpha,
prog, prog,
} }
@ -164,8 +163,8 @@ impl GlRenderContext {
tex_internal, tex_internal,
tex_external, tex_external,
fill_prog_pos: fill_prog.get_attrib_location(ustr!("pos")), fill_prog_pos: fill_prog.get_attrib_location(c"pos"),
fill_prog_color: fill_prog.get_uniform_location(ustr!("color")), fill_prog_color: fill_prog.get_uniform_location(c"color"),
fill_prog, fill_prog,
gfx_ops: Default::default(), gfx_ops: Default::default(),

View file

@ -63,7 +63,7 @@ impl VulkanInstance {
.collect(); .collect();
let app_info = ApplicationInfo::default() let app_info = ApplicationInfo::default()
.api_version(API_VERSION) .api_version(API_VERSION)
.application_name(ustr!("jay").as_c_str().unwrap()) .application_name(c"jay")
.application_version(1); .application_version(1);
let mut severity = DebugUtilsMessageSeverityFlagsEXT::empty() let mut severity = DebugUtilsMessageSeverityFlagsEXT::empty()
| DebugUtilsMessageSeverityFlagsEXT::ERROR | DebugUtilsMessageSeverityFlagsEXT::ERROR

View file

@ -18,7 +18,6 @@ use {
PrimitiveTopology, PushConstantRange, SampleCountFlags, ShaderStageFlags, PrimitiveTopology, PushConstantRange, SampleCountFlags, ShaderStageFlags,
}, },
std::{mem, rc::Rc, slice}, std::{mem, rc::Rc, slice},
uapi::ustr,
}; };
pub(super) struct VulkanPipeline { pub(super) struct VulkanPipeline {
@ -87,16 +86,15 @@ impl VulkanDevice {
let destroy_layout = let destroy_layout =
OnDrop(|| unsafe { self.device.destroy_pipeline_layout(pipeline_layout, None) }); OnDrop(|| unsafe { self.device.destroy_pipeline_layout(pipeline_layout, None) });
let pipeline = { let pipeline = {
let main = ustr!("main").as_c_str().unwrap();
let stages = [ let stages = [
PipelineShaderStageCreateInfo::default() PipelineShaderStageCreateInfo::default()
.stage(ShaderStageFlags::VERTEX) .stage(ShaderStageFlags::VERTEX)
.module(info.vert.module) .module(info.vert.module)
.name(main), .name(c"main"),
PipelineShaderStageCreateInfo::default() PipelineShaderStageCreateInfo::default()
.stage(ShaderStageFlags::FRAGMENT) .stage(ShaderStageFlags::FRAGMENT)
.module(info.frag.module) .module(info.frag.module)
.name(main), .name(c"main"),
]; ];
let input_assembly_state = PipelineInputAssemblyStateCreateInfo::default() let input_assembly_state = PipelineInputAssemblyStateCreateInfo::default()
.topology(PrimitiveTopology::TRIANGLE_STRIP); .topology(PrimitiveTopology::TRIANGLE_STRIP);

View file

@ -4,7 +4,7 @@ use {
crate::utils::oserror::OsError, crate::utils::oserror::OsError,
std::{ffi::CStr, marker::PhantomData, ptr, rc::Rc}, std::{ffi::CStr, marker::PhantomData, ptr, rc::Rc},
thiserror::Error, thiserror::Error,
uapi::{c, ustr, Errno, IntoUstr, Ustr}, uapi::{c, Errno, IntoUstr},
}; };
#[repr(transparent)] #[repr(transparent)]
@ -375,7 +375,7 @@ impl UdevDevice {
unsafe { udev_device_get_is_initialized(self.device) != 0 } unsafe { udev_device_get_is_initialized(self.device) != 0 }
} }
fn get_property(&self, prop: &Ustr) -> Option<&CStr> { fn get_property(&self, prop: &CStr) -> Option<&CStr> {
let prop = unsafe { udev_device_get_property_value(self.device, prop.as_ptr()) }; let prop = unsafe { udev_device_get_property_value(self.device, prop.as_ptr()) };
if prop.is_null() { if prop.is_null() {
None None
@ -385,15 +385,15 @@ impl UdevDevice {
} }
pub fn vendor(&self) -> Option<&CStr> { pub fn vendor(&self) -> Option<&CStr> {
self.get_property(ustr!("ID_VENDOR_FROM_DATABASE")) self.get_property(c"ID_VENDOR_FROM_DATABASE")
} }
pub fn model(&self) -> Option<&CStr> { pub fn model(&self) -> Option<&CStr> {
self.get_property(ustr!("ID_MODEL_FROM_DATABASE")) self.get_property(c"ID_MODEL_FROM_DATABASE")
} }
pub fn pci_id(&self) -> Option<&CStr> { pub fn pci_id(&self) -> Option<&CStr> {
self.get_property(ustr!("PCI_ID")) self.get_property(c"PCI_ID")
} }
} }