1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: use vmemset instead of C.memset (#13104)

This commit is contained in:
Larpon 2022-01-09 15:08:11 +01:00 committed by GitHub
parent e2a0046849
commit b44b8c472d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 26 deletions

View File

@ -322,7 +322,7 @@ fn my_init(mut app App) {
// 3d pipeline
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
color_state := gfx.ColorState{
blend: gfx.BlendState{

View File

@ -277,7 +277,7 @@ fn init_cube_glsl(mut app App) {
]
mut vert_buffer_desc := gfx.BufferDesc{label: c'cube-vertices'}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) }
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
@ -300,7 +300,7 @@ fn init_cube_glsl(mut app App) {
]
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'}
unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) }
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
@ -315,7 +315,7 @@ fn init_cube_glsl(mut app App) {
shader := gfx.make_shader(C.cube_shader_desc(C.sg_query_backend()))
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
pipdesc.layout.buffers[0].stride = int(sizeof(Vertex_t))
// the constants [C.ATTR_vs_pos, C.ATTR_vs_color0, C.ATTR_vs_texcoord0] are generated bysokol-shdc
@ -493,7 +493,7 @@ fn my_init(mut app App) {
// 3d pipeline
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
color_state := gfx.ColorState{
blend: gfx.BlendState{

View File

@ -156,7 +156,7 @@ fn init_cube_glsl(mut app App) {
]
mut vert_buffer_desc := gfx.BufferDesc{label: c'cube-vertices'}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) }
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
@ -178,7 +178,7 @@ fn init_cube_glsl(mut app App) {
]
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'}
unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))}
unsafe {vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc)))}
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
@ -193,7 +193,7 @@ fn init_cube_glsl(mut app App) {
shader := gfx.make_shader(C.rt_shader_desc(C.sg_query_backend()))
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
pipdesc.layout.buffers[0].stride = int(sizeof(Vertex_t))
// the constants [C.ATTR_vs_pos, C.ATTR_vs_color0, C.ATTR_vs_texcoord0] are generated by sokol-shdc

View File

@ -158,7 +158,7 @@ fn init_cube_glsl_m(mut app App) {
]
mut vert_buffer_desc := gfx.BufferDesc{label: c'cube-vertices'}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) }
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
ptr: vertices.data
@ -180,7 +180,7 @@ fn init_cube_glsl_m(mut app App) {
]
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'}
unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) }
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
ptr: indices.data
@ -193,7 +193,7 @@ fn init_cube_glsl_m(mut app App) {
shader := gfx.make_shader(C.rt_march_shader_desc(C.sg_query_backend()))
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
pipdesc.layout.buffers[0].stride = int(sizeof(Vertex_t))
// the constants [C.ATTR_vs_m_pos, C.ATTR_vs_m_color0, C.ATTR_vs_m_texcoord0] are generated by sokol-shdc
@ -213,7 +213,7 @@ fn init_cube_glsl_m(mut app App) {
pipdesc.label = 'glsl_shader pipeline'.str
mut bind := gfx.Bindings{}
unsafe { C.memset(&bind, 0, sizeof(bind)) }
unsafe { vmemset(&bind, 0, int(sizeof(bind))) }
bind.vertex_buffers[0] = vbuf
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture
@ -264,7 +264,7 @@ fn init_cube_glsl_p(mut app App) {
]
mut vert_buffer_desc := gfx.BufferDesc{label: c'cube-vertices'}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) }
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
ptr: vertices.data
@ -287,7 +287,7 @@ fn init_cube_glsl_p(mut app App) {
]
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'}
unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) }
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
ptr: indices.data
@ -300,7 +300,7 @@ fn init_cube_glsl_p(mut app App) {
shader := gfx.make_shader(C.rt_puppy_shader_desc(C.sg_query_backend()))
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
pipdesc.layout.buffers[0].stride = int(sizeof(Vertex_t))
// the constants [C.ATTR_vs_p_pos, C.ATTR_vs_p_color0, C.ATTR_vs_p_texcoord0] are generated by sokol-shdc
@ -321,7 +321,7 @@ fn init_cube_glsl_p(mut app App) {
pipdesc.label = 'glsl_shader pipeline'.str
mut bind := gfx.Bindings{}
unsafe { C.memset(&bind, 0, sizeof(bind)) }
unsafe { vmemset(&bind, 0, int(sizeof(bind))) }
bind.vertex_buffers[0] = vbuf
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture

View File

@ -173,7 +173,7 @@ fn init_cube_glsl_i(mut app App) {
]
mut vert_buffer_desc := gfx.BufferDesc{label: c'cube-vertices'}
unsafe {C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc))}
unsafe {vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc)))}
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
ptr: vertices.data
@ -184,7 +184,7 @@ fn init_cube_glsl_i(mut app App) {
/* create an instance buffer for the cube */
mut inst_buffer_desc := gfx.BufferDesc{label: c'instance-data'}
unsafe {C.memset(&inst_buffer_desc, 0, sizeof(inst_buffer_desc))}
unsafe {vmemset(&inst_buffer_desc, 0, int(sizeof(inst_buffer_desc)))}
inst_buffer_desc.size = usize(num_inst * int(sizeof(m4.Vec4)))
inst_buffer_desc.@type = .vertexbuffer
@ -203,7 +203,7 @@ fn init_cube_glsl_i(mut app App) {
]
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'}
unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))}
unsafe {vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc)))}
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
ptr: indices.data
@ -216,7 +216,7 @@ fn init_cube_glsl_i(mut app App) {
shader := gfx.make_shader(C.instancing_shader_desc(C.sg_query_backend()))
mut pipdesc := gfx.PipelineDesc{}
unsafe {C.memset(&pipdesc, 0, sizeof(pipdesc))}
unsafe {vmemset(&pipdesc, 0, int(sizeof(pipdesc)))}
pipdesc.layout.buffers[0].stride = int(sizeof(Vertex_t))
// the constants [C.ATTR_vs_m_pos, C.ATTR_vs_m_color0, C.ATTR_vs_m_texcoord0] are generated by sokol-shdc
@ -246,7 +246,7 @@ fn init_cube_glsl_i(mut app App) {
pipdesc.label = "glsl_shader pipeline".str
mut bind := gfx.Bindings{}
unsafe {C.memset(&bind, 0, sizeof(bind))}
unsafe {vmemset(&bind, 0, int(sizeof(bind)))}
bind.vertex_buffers[0] = vbuf // vertex buffer
bind.vertex_buffers[1] = inst_buf // instance buffer
bind.index_buffer = ibuf

View File

@ -71,7 +71,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
mut vert_buffer_desc := gfx.BufferDesc{
label: 0
}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) }
vert_buffer_desc.size = usize(obj_buf.vbuf.len * int(sizeof(Vertex_pnct)))
vert_buffer_desc.data = gfx.Range{
@ -87,7 +87,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
mut index_buffer_desc := gfx.BufferDesc{
label: 0
}
unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) }
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
index_buffer_desc.size = usize(obj_buf.ibuf.len * int(sizeof(u32)))
index_buffer_desc.data = gfx.Range{
@ -100,7 +100,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
ibuf := gfx.make_buffer(&index_buffer_desc)
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
pipdesc.layout.buffers[0].stride = int(sizeof(Vertex_pnct))
// the constants [C.ATTR_vs_a_Position, C.ATTR_vs_a_Color, C.ATTR_vs_a_Texcoord0] are generated by sokol-shdc

View File

@ -80,7 +80,7 @@ fn init(user_data voidptr) {
}
sgl.setup(&sgl_desc)
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
color_state := gfx.ColorState{
blend: gfx.BlendState{

View File

@ -316,7 +316,7 @@ fn app_init(mut app App) {
// 3d pipeline
mut pipdesc := gfx.PipelineDesc{}
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
color_state := gfx.ColorState{
blend: gfx.BlendState{