mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
sokol: type alias all gfx
structs (#13014)
This commit is contained in:
@ -33,7 +33,7 @@ const (
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
texture C.sg_image
|
||||
texture gfx.Image
|
||||
init_flag bool
|
||||
frame_count int
|
||||
|
||||
@ -42,11 +42,11 @@ mut:
|
||||
mouse_down bool
|
||||
|
||||
// glsl
|
||||
cube_pip_glsl C.sg_pipeline
|
||||
cube_bind C.sg_bindings
|
||||
cube_pip_glsl gfx.Pipeline
|
||||
cube_bind gfx.Bindings
|
||||
|
||||
pipe map[string]C.sg_pipeline
|
||||
bind map[string]C.sg_bindings
|
||||
pipe map[string]gfx.Pipeline
|
||||
bind map[string]gfx.Bindings
|
||||
|
||||
// time
|
||||
ticks i64
|
||||
@ -64,14 +64,14 @@ mut:
|
||||
******************************************************************************/
|
||||
#flag -I @VMODROOT/.
|
||||
#include "rt_glsl_instancing.h" # Should be generated with `v shader .` (see the instructions at the top of this file)
|
||||
fn C.instancing_shader_desc(gfx.Backend) &C.sg_shader_desc
|
||||
fn C.instancing_shader_desc(gfx.Backend) &gfx.ShaderDesc
|
||||
|
||||
/******************************************************************************
|
||||
* Texture functions
|
||||
******************************************************************************/
|
||||
fn create_texture(w int, h int, buf byteptr) C.sg_image{
|
||||
fn create_texture(w int, h int, buf byteptr) gfx.Image{
|
||||
sz := w * h * 4
|
||||
mut img_desc := C.sg_image_desc{
|
||||
mut img_desc := gfx.ImageDesc{
|
||||
width: w
|
||||
height: h
|
||||
num_mipmaps: 0
|
||||
@ -84,28 +84,28 @@ fn create_texture(w int, h int, buf byteptr) C.sg_image{
|
||||
d3d11_texture: 0
|
||||
}
|
||||
// comment if .dynamic is enabled
|
||||
img_desc.data.subimage[0][0] = C.sg_range{
|
||||
img_desc.data.subimage[0][0] = gfx.Range{
|
||||
ptr: buf
|
||||
size: usize(sz)
|
||||
}
|
||||
|
||||
sg_img := C.sg_make_image(&img_desc)
|
||||
sg_img := gfx.make_image(&img_desc)
|
||||
return sg_img
|
||||
}
|
||||
|
||||
fn destroy_texture(sg_img C.sg_image){
|
||||
C.sg_destroy_image(sg_img)
|
||||
fn destroy_texture(sg_img gfx.Image){
|
||||
gfx.destroy_image(sg_img)
|
||||
}
|
||||
|
||||
// Use only if usage: .dynamic is enabled
|
||||
fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr){
|
||||
fn update_text_texture(sg_img gfx.Image, w int, h int, buf byteptr){
|
||||
sz := w * h * 4
|
||||
mut tmp_sbc := C.sg_image_data{}
|
||||
tmp_sbc.subimage[0][0] = C.sg_range{
|
||||
mut tmp_sbc := gfx.ImageData{}
|
||||
tmp_sbc.subimage[0][0] = gfx.Range{
|
||||
ptr: buf
|
||||
size: usize(sz)
|
||||
}
|
||||
C.sg_update_image(sg_img, &tmp_sbc)
|
||||
gfx.update_image(sg_img, &tmp_sbc)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -172,10 +172,10 @@ fn init_cube_glsl_i(mut app App) {
|
||||
Vertex_t{ 1.0, 1.0, -1.0, c, 0, d},
|
||||
]
|
||||
|
||||
mut vert_buffer_desc := C.sg_buffer_desc{label: c'cube-vertices'}
|
||||
mut vert_buffer_desc := gfx.BufferDesc{label: c'cube-vertices'}
|
||||
unsafe {C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc))}
|
||||
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
|
||||
vert_buffer_desc.data = C.sg_range{
|
||||
vert_buffer_desc.data = gfx.Range{
|
||||
ptr: vertices.data
|
||||
size: usize(vertices.len * int(sizeof(Vertex_t)))
|
||||
}
|
||||
@ -183,7 +183,7 @@ fn init_cube_glsl_i(mut app App) {
|
||||
vbuf := gfx.make_buffer(&vert_buffer_desc)
|
||||
|
||||
/* create an instance buffer for the cube */
|
||||
mut inst_buffer_desc := C.sg_buffer_desc{label: c'instance-data'}
|
||||
mut inst_buffer_desc := gfx.BufferDesc{label: c'instance-data'}
|
||||
unsafe {C.memset(&inst_buffer_desc, 0, sizeof(inst_buffer_desc))}
|
||||
|
||||
inst_buffer_desc.size = usize(num_inst * int(sizeof(m4.Vec4)))
|
||||
@ -202,10 +202,10 @@ fn init_cube_glsl_i(mut app App) {
|
||||
22, 21, 20, 23, 22, 20
|
||||
]
|
||||
|
||||
mut index_buffer_desc := C.sg_buffer_desc{label: c'cube-indices'}
|
||||
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'}
|
||||
unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))}
|
||||
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
|
||||
index_buffer_desc.data = C.sg_range{
|
||||
index_buffer_desc.data = gfx.Range{
|
||||
ptr: indices.data
|
||||
size: usize(indices.len * int(sizeof(u16)))
|
||||
}
|
||||
@ -215,7 +215,7 @@ fn init_cube_glsl_i(mut app App) {
|
||||
/* create shader */
|
||||
shader := gfx.make_shader(C.instancing_shader_desc(C.sg_query_backend()))
|
||||
|
||||
mut pipdesc := C.sg_pipeline_desc{}
|
||||
mut pipdesc := gfx.PipelineDesc{}
|
||||
unsafe {C.memset(&pipdesc, 0, sizeof(pipdesc))}
|
||||
pipdesc.layout.buffers[0].stride = int(sizeof(Vertex_t))
|
||||
|
||||
@ -237,15 +237,15 @@ fn init_cube_glsl_i(mut app App) {
|
||||
pipdesc.shader = shader
|
||||
pipdesc.index_type = .uint16
|
||||
|
||||
pipdesc.depth = C.sg_depth_state{
|
||||
pipdesc.depth = gfx.DepthState{
|
||||
write_enabled: true
|
||||
compare: gfx.CompareFunc(C.SG_COMPAREFUNC_LESS_EQUAL)
|
||||
compare: .less_equal
|
||||
}
|
||||
pipdesc.cull_mode = .back
|
||||
|
||||
pipdesc.label = "glsl_shader pipeline".str
|
||||
|
||||
mut bind := C.sg_bindings{}
|
||||
mut bind := gfx.Bindings{}
|
||||
unsafe {C.memset(&bind, 0, sizeof(bind))}
|
||||
bind.vertex_buffers[0] = vbuf // vertex buffer
|
||||
bind.vertex_buffers[1] = inst_buf // instance buffer
|
||||
@ -310,7 +310,7 @@ fn draw_cube_glsl_i(mut app App){
|
||||
spare_param := f32(index % 10)
|
||||
app.inst_pos[index] = m4.Vec4{e:[f32((x - cx - app.camera_x) * cube_size),y ,f32( (z - cz - app.camera_z) * cube_size),spare_param]!}
|
||||
}
|
||||
range := C.sg_range{
|
||||
range := gfx.Range{
|
||||
ptr: unsafe { &app.inst_pos }
|
||||
size: usize(num_inst * int(sizeof(m4.Vec4)))
|
||||
}
|
||||
@ -320,7 +320,7 @@ fn draw_cube_glsl_i(mut app App){
|
||||
// *** vertex shadeer uniforms ***
|
||||
// passing the view matrix as uniform
|
||||
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
|
||||
vs_uniforms_range := C.sg_range{
|
||||
vs_uniforms_range := gfx.Range{
|
||||
ptr: unsafe { &tr_matrix }
|
||||
size: usize(4 * 16)
|
||||
}
|
||||
@ -338,7 +338,7 @@ fn draw_cube_glsl_i(mut app App){
|
||||
app.frame_count, // frame count
|
||||
0,0 // padding bytes , see "fs_params" struct paddings in rt_glsl.h
|
||||
]!
|
||||
fs_uniforms_range := C.sg_range{
|
||||
fs_uniforms_range := gfx.Range{
|
||||
ptr: unsafe { &tmp_fs_params }
|
||||
size: usize(sizeof(tmp_fs_params))
|
||||
}
|
||||
@ -371,16 +371,16 @@ fn frame(mut app App) {
|
||||
ws := gg.window_size_real_pixels()
|
||||
|
||||
// clear
|
||||
mut color_action := C.sg_color_attachment_action{
|
||||
action: gfx.Action(C.SG_ACTION_CLEAR)
|
||||
value: C.sg_color{
|
||||
mut color_action := gfx.ColorAttachmentAction{
|
||||
action: .clear
|
||||
value: gfx.Color{
|
||||
r: 0.0
|
||||
g: 0.0
|
||||
b: 0.0
|
||||
a: 1.0
|
||||
}
|
||||
}
|
||||
mut pass_action := C.sg_pass_action{}
|
||||
mut pass_action := gfx.PassAction{}
|
||||
pass_action.colors[0] = color_action
|
||||
gfx.begin_default_pass(&pass_action, ws.width, ws.height)
|
||||
|
||||
|
Reference in New Issue
Block a user