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:
@ -27,7 +27,7 @@ struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
pip_3d C.sgl_pipeline
|
||||
texture C.sg_image
|
||||
texture gfx.Image
|
||||
init_flag bool
|
||||
frame_count int
|
||||
mouse_x int = -1
|
||||
@ -39,9 +39,9 @@ mut:
|
||||
* Texture functions
|
||||
*
|
||||
******************************************************************************/
|
||||
fn create_texture(w int, h int, buf &u8) C.sg_image {
|
||||
fn create_texture(w int, h int, buf &u8) 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
|
||||
@ -54,28 +54,28 @@ fn create_texture(w int, h int, buf &u8) C.sg_image {
|
||||
d3d11_texture: 0
|
||||
}
|
||||
// commen 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 &byte) {
|
||||
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
|
||||
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)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -321,21 +321,21 @@ fn my_init(mut app App) {
|
||||
sgl.setup(&sgl_desc)
|
||||
|
||||
// 3d pipeline
|
||||
mut pipdesc := C.sg_pipeline_desc{}
|
||||
mut pipdesc := gfx.PipelineDesc{}
|
||||
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
|
||||
|
||||
color_state := C.sg_color_state{
|
||||
blend: C.sg_blend_state{
|
||||
color_state := gfx.ColorState{
|
||||
blend: gfx.BlendState{
|
||||
enabled: true
|
||||
src_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_SRC_ALPHA)
|
||||
dst_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA)
|
||||
src_factor_rgb: .src_alpha
|
||||
dst_factor_rgb: .one_minus_src_alpha
|
||||
}
|
||||
}
|
||||
pipdesc.colors[0] = color_state
|
||||
|
||||
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
|
||||
app.pip_3d = sgl.make_pipeline(&pipdesc)
|
||||
|
@ -26,7 +26,7 @@ import gg.m4
|
||||
#flag -I @VMODROOT/.
|
||||
#include "cube_glsl.h" # Should be generated with `v shader .` (see the instructions at the top of this file)
|
||||
|
||||
fn C.cube_shader_desc(gfx.Backend) &C.sg_shader_desc
|
||||
fn C.cube_shader_desc(gfx.Backend) &gfx.ShaderDesc
|
||||
|
||||
const (
|
||||
win_width = 800
|
||||
@ -38,14 +38,14 @@ struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
pip_3d C.sgl_pipeline
|
||||
texture C.sg_image
|
||||
texture gfx.Image
|
||||
init_flag bool
|
||||
frame_count int
|
||||
mouse_x int = -1
|
||||
mouse_y int = -1
|
||||
// glsl
|
||||
cube_pip_glsl C.sg_pipeline
|
||||
cube_bind C.sg_bindings
|
||||
cube_pip_glsl gfx.Pipeline
|
||||
cube_bind gfx.Bindings
|
||||
// time
|
||||
ticks i64
|
||||
}
|
||||
@ -55,9 +55,9 @@ mut:
|
||||
* Texture functions
|
||||
*
|
||||
******************************************************************************/
|
||||
fn create_texture(w int, h int, buf &byte) C.sg_image {
|
||||
fn create_texture(w int, h int, buf &byte) 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
|
||||
@ -70,28 +70,28 @@ fn create_texture(w int, h int, buf &byte) 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 &byte) {
|
||||
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
|
||||
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)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -276,11 +276,11 @@ fn init_cube_glsl(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)))
|
||||
}
|
||||
@ -299,11 +299,11 @@ fn init_cube_glsl(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)))
|
||||
}
|
||||
@ -314,7 +314,7 @@ fn init_cube_glsl(mut app App) {
|
||||
// create shader
|
||||
shader := gfx.make_shader(C.cube_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))
|
||||
@ -327,9 +327,9 @@ fn init_cube_glsl(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
|
||||
|
||||
@ -366,7 +366,7 @@ fn draw_cube_glsl(app App) {
|
||||
//***************
|
||||
// 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: &tr_matrix
|
||||
size: usize(4 * 16)
|
||||
}
|
||||
@ -380,7 +380,7 @@ fn draw_cube_glsl(app App) {
|
||||
time_ticks, /* time as f32 */
|
||||
0 /* padding 4 Bytes == 1 f32 */,
|
||||
]!
|
||||
fs_uniforms_range := C.sg_range{
|
||||
fs_uniforms_range := gfx.Range{
|
||||
ptr: unsafe { &text_res }
|
||||
size: usize(4 * 4)
|
||||
}
|
||||
@ -457,16 +457,16 @@ fn frame(mut app App) {
|
||||
app.gg.end()
|
||||
|
||||
// clear
|
||||
mut color_action := C.sg_color_attachment_action{
|
||||
mut color_action := gfx.ColorAttachmentAction{
|
||||
action: gfx.Action(C.SG_ACTION_DONTCARE) // C.SG_ACTION_CLEAR)
|
||||
value: C.sg_color{
|
||||
value: gfx.Color{
|
||||
r: 1.0
|
||||
g: 1.0
|
||||
b: 1.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)
|
||||
|
||||
@ -492,21 +492,21 @@ fn my_init(mut app App) {
|
||||
sgl.setup(&sgl_desc)
|
||||
|
||||
// 3d pipeline
|
||||
mut pipdesc := C.sg_pipeline_desc{}
|
||||
mut pipdesc := gfx.PipelineDesc{}
|
||||
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
|
||||
|
||||
color_state := C.sg_color_state{
|
||||
blend: C.sg_blend_state{
|
||||
color_state := gfx.ColorState{
|
||||
blend: gfx.BlendState{
|
||||
enabled: true
|
||||
src_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_SRC_ALPHA)
|
||||
dst_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA)
|
||||
src_factor_rgb: .src_alpha
|
||||
dst_factor_rgb: .one_minus_src_alpha
|
||||
}
|
||||
}
|
||||
pipdesc.colors[0] = color_state
|
||||
|
||||
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
|
||||
|
||||
|
@ -27,7 +27,7 @@ import time
|
||||
#flag -I @VMODROOT/.
|
||||
#include "rt_glsl.h" # Should be generated with `v shader .` (see the instructions at the top of this file)
|
||||
|
||||
fn C.rt_shader_desc(gfx.Backend) &C.sg_shader_desc
|
||||
fn C.rt_shader_desc(gfx.Backend) &gfx.ShaderDesc
|
||||
|
||||
const (
|
||||
win_width = 800
|
||||
@ -38,15 +38,15 @@ const (
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
texture C.sg_image
|
||||
texture gfx.Image
|
||||
init_flag bool
|
||||
frame_count int
|
||||
|
||||
mouse_x int = -1
|
||||
mouse_y int = -1
|
||||
// glsl
|
||||
cube_pip_glsl C.sg_pipeline
|
||||
cube_bind C.sg_bindings
|
||||
cube_pip_glsl gfx.Pipeline
|
||||
cube_bind gfx.Bindings
|
||||
// time
|
||||
ticks i64
|
||||
}
|
||||
@ -54,9 +54,9 @@ mut:
|
||||
/******************************************************************************
|
||||
* Texture functions
|
||||
******************************************************************************/
|
||||
fn create_texture(w int, h int, buf &byte) C.sg_image {
|
||||
fn create_texture(w int, h int, buf &byte) 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
|
||||
@ -69,28 +69,28 @@ fn create_texture(w int, h int, buf &byte) 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 &byte) {
|
||||
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
|
||||
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)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -155,11 +155,11 @@ fn init_cube_glsl(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)))
|
||||
}
|
||||
@ -177,11 +177,11 @@ fn init_cube_glsl(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)))
|
||||
}
|
||||
@ -192,7 +192,7 @@ fn init_cube_glsl(mut app App) {
|
||||
// create shader
|
||||
shader := gfx.make_shader(C.rt_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))
|
||||
|
||||
@ -205,9 +205,9 @@ fn init_cube_glsl(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
|
||||
|
||||
@ -264,7 +264,7 @@ fn draw_cube_glsl(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: &tr_matrix
|
||||
size: usize(4 * 16)
|
||||
}
|
||||
@ -282,7 +282,7 @@ fn draw_cube_glsl(app App) {
|
||||
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))
|
||||
}
|
||||
@ -298,9 +298,9 @@ 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
|
||||
@ -308,7 +308,7 @@ fn frame(mut app App) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
@ -26,8 +26,8 @@ import time
|
||||
#flag -I @VMODROOT/.
|
||||
#include "rt_glsl_march.h" # Should be generated with `v shader .` (see the instructions at the top of this file)
|
||||
#include "rt_glsl_puppy.h" # Should be generated with `v shader .` (see the instructions at the top of this file)
|
||||
fn C.rt_march_shader_desc(gfx.Backend) &C.sg_shader_desc
|
||||
fn C.rt_puppy_shader_desc(gfx.Backend) &C.sg_shader_desc
|
||||
fn C.rt_march_shader_desc(gfx.Backend) &gfx.ShaderDesc
|
||||
fn C.rt_puppy_shader_desc(gfx.Backend) &gfx.ShaderDesc
|
||||
|
||||
const (
|
||||
win_width = 800
|
||||
@ -38,17 +38,17 @@ const (
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
texture C.sg_image
|
||||
texture gfx.Image
|
||||
init_flag bool
|
||||
frame_count int
|
||||
mouse_x int = -1
|
||||
mouse_y int = -1
|
||||
mouse_down bool
|
||||
// glsl
|
||||
cube_pip_glsl C.sg_pipeline
|
||||
cube_bind C.sg_bindings
|
||||
pipe map[string]C.sg_pipeline
|
||||
bind map[string]C.sg_bindings
|
||||
cube_pip_glsl gfx.Pipeline
|
||||
cube_bind gfx.Bindings
|
||||
pipe map[string]gfx.Pipeline
|
||||
bind map[string]gfx.Bindings
|
||||
// time
|
||||
ticks i64
|
||||
}
|
||||
@ -56,9 +56,9 @@ mut:
|
||||
/******************************************************************************
|
||||
* 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
|
||||
@ -71,28 +71,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)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -157,10 +157,10 @@ fn init_cube_glsl_m(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)))
|
||||
}
|
||||
@ -179,10 +179,10 @@ fn init_cube_glsl_m(mut app App) {
|
||||
*/
|
||||
]
|
||||
|
||||
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)))
|
||||
}
|
||||
@ -192,7 +192,7 @@ fn init_cube_glsl_m(mut app App) {
|
||||
// create shader
|
||||
shader := gfx.make_shader(C.rt_march_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))
|
||||
|
||||
@ -205,14 +205,14 @@ fn init_cube_glsl_m(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
|
||||
bind.index_buffer = ibuf
|
||||
@ -263,10 +263,10 @@ fn init_cube_glsl_p(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)))
|
||||
}
|
||||
@ -286,10 +286,10 @@ fn init_cube_glsl_p(mut app App) {
|
||||
|
||||
]
|
||||
|
||||
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)))
|
||||
}
|
||||
@ -299,7 +299,7 @@ fn init_cube_glsl_p(mut app App) {
|
||||
// create shader
|
||||
shader := gfx.make_shader(C.rt_puppy_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))
|
||||
|
||||
@ -312,15 +312,15 @@ fn init_cube_glsl_p(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
|
||||
bind.index_buffer = ibuf
|
||||
@ -373,7 +373,7 @@ fn draw_cube_glsl_m(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: &tr_matrix
|
||||
size: usize(4 * 16)
|
||||
}
|
||||
@ -393,7 +393,7 @@ fn draw_cube_glsl_m(app App) {
|
||||
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))
|
||||
}
|
||||
@ -425,7 +425,7 @@ fn draw_cube_glsl_p(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: &tr_matrix
|
||||
size: usize(4 * 16)
|
||||
}
|
||||
@ -445,7 +445,7 @@ fn draw_cube_glsl_p(app App) {
|
||||
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))
|
||||
}
|
||||
@ -477,16 +477,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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -18,9 +18,9 @@ import stbi
|
||||
/******************************************************************************
|
||||
* Texture functions
|
||||
******************************************************************************/
|
||||
pub fn create_texture(w int, h int, buf &byte) C.sg_image {
|
||||
pub fn create_texture(w int, h int, buf &byte) 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
|
||||
@ -33,20 +33,20 @@ pub fn create_texture(w int, h int, buf &byte) 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
|
||||
}
|
||||
|
||||
pub fn destroy_texture(sg_img C.sg_image) {
|
||||
C.sg_destroy_image(sg_img)
|
||||
pub fn destroy_texture(sg_img gfx.Image) {
|
||||
gfx.destroy_image(sg_img)
|
||||
}
|
||||
|
||||
pub fn load_texture(file_name string) C.sg_image {
|
||||
pub fn load_texture(file_name string) gfx.Image {
|
||||
buffer := read_bytes_from_file(file_name)
|
||||
stbi.set_flip_vertically_on_load(true)
|
||||
img := stbi.load_from_memory(buffer.data, buffer.len) or {
|
||||
@ -61,20 +61,20 @@ pub fn load_texture(file_name string) C.sg_image {
|
||||
/******************************************************************************
|
||||
* Pipeline
|
||||
******************************************************************************/
|
||||
pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader, texture C.sg_image) Render_data {
|
||||
pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader, texture gfx.Image) Render_data {
|
||||
mut res := Render_data{}
|
||||
obj_buf := obj_part.get_buffer(in_part)
|
||||
res.n_vert = obj_buf.n_vertex
|
||||
res.material = obj_part.part[in_part[0]].material
|
||||
|
||||
// vertex buffer
|
||||
mut vert_buffer_desc := C.sg_buffer_desc{
|
||||
mut vert_buffer_desc := gfx.BufferDesc{
|
||||
label: 0
|
||||
}
|
||||
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
|
||||
|
||||
vert_buffer_desc.size = usize(obj_buf.vbuf.len * int(sizeof(Vertex_pnct)))
|
||||
vert_buffer_desc.data = C.sg_range{
|
||||
vert_buffer_desc.data = gfx.Range{
|
||||
ptr: obj_buf.vbuf.data
|
||||
size: usize(obj_buf.vbuf.len * int(sizeof(Vertex_pnct)))
|
||||
}
|
||||
@ -84,13 +84,13 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader,
|
||||
vbuf := gfx.make_buffer(&vert_buffer_desc)
|
||||
|
||||
// index buffer
|
||||
mut index_buffer_desc := C.sg_buffer_desc{
|
||||
mut index_buffer_desc := gfx.BufferDesc{
|
||||
label: 0
|
||||
}
|
||||
unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) }
|
||||
|
||||
index_buffer_desc.size = usize(obj_buf.ibuf.len * int(sizeof(u32)))
|
||||
index_buffer_desc.data = C.sg_range{
|
||||
index_buffer_desc.data = gfx.Range{
|
||||
ptr: obj_buf.ibuf.data
|
||||
size: usize(obj_buf.ibuf.len * int(sizeof(u32)))
|
||||
}
|
||||
@ -99,7 +99,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader,
|
||||
index_buffer_desc.label = 'indbuf_part_${in_part:03}'.str
|
||||
ibuf := gfx.make_buffer(&index_buffer_desc)
|
||||
|
||||
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_pnct))
|
||||
|
||||
@ -111,18 +111,18 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader,
|
||||
// pipdesc.layout.attrs[C.ATTR_vs_a_Texcoord0].format = .short2n // u,v as u16
|
||||
pipdesc.index_type = .uint32
|
||||
|
||||
color_state := C.sg_color_state{
|
||||
blend: C.sg_blend_state{
|
||||
color_state := gfx.ColorState{
|
||||
blend: gfx.BlendState{
|
||||
enabled: true
|
||||
src_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_SRC_ALPHA)
|
||||
dst_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA)
|
||||
src_factor_rgb: .src_alpha
|
||||
dst_factor_rgb: .one_minus_src_alpha
|
||||
}
|
||||
}
|
||||
pipdesc.colors[0] = color_state
|
||||
|
||||
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 = .front
|
||||
|
||||
@ -144,7 +144,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader,
|
||||
* Render functions
|
||||
******************************************************************************/
|
||||
// agregate all the part by materials
|
||||
pub fn (mut obj_part ObjPart) init_render_data(texture C.sg_image) {
|
||||
pub fn (mut obj_part ObjPart) init_render_data(texture gfx.Image) {
|
||||
// create shader
|
||||
// One shader for all the model
|
||||
shader := gfx.make_shader(C.gouraud_shader_desc(gfx.query_backend()))
|
||||
@ -234,11 +234,11 @@ pub fn (obj_part ObjPart) bind_and_draw(rend_data_index int, in_data Shader_data
|
||||
gfx.apply_pipeline(part_render_data.pipeline)
|
||||
gfx.apply_bindings(part_render_data.bind)
|
||||
|
||||
vs_uniforms_range := C.sg_range{
|
||||
vs_uniforms_range := gfx.Range{
|
||||
ptr: in_data.vs_data
|
||||
size: usize(in_data.vs_len)
|
||||
}
|
||||
fs_uniforms_range := C.sg_range{
|
||||
fs_uniforms_range := gfx.Range{
|
||||
ptr: unsafe { &tmp_fs_params }
|
||||
size: usize(in_data.fs_len)
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
module obj
|
||||
|
||||
import gg.m4
|
||||
import sokol.gfx
|
||||
|
||||
// part struct mantain the fae indexes list
|
||||
pub struct Part {
|
||||
@ -32,8 +33,8 @@ pub mut:
|
||||
// render data used for the rendering
|
||||
pub struct Render_data {
|
||||
pub mut:
|
||||
pipeline C.sg_pipeline
|
||||
bind C.sg_bindings
|
||||
pipeline gfx.Pipeline
|
||||
bind gfx.Bindings
|
||||
n_vert u32
|
||||
material string
|
||||
}
|
||||
@ -47,10 +48,10 @@ pub mut:
|
||||
vt []m4.Vec4 // textures
|
||||
|
||||
name string
|
||||
part []Part // parts of the ObjPart
|
||||
mat []Material // list of the materials of the ObjPart
|
||||
mat_map map[string]int // maping material name to its material index
|
||||
texture map[string]C.sg_image // GPU loaded texture map
|
||||
part []Part // parts of the ObjPart
|
||||
mat []Material // list of the materials of the ObjPart
|
||||
mat_map map[string]int // maping material name to its material index
|
||||
texture map[string]gfx.Image // GPU loaded texture map
|
||||
material_file string // .mtl file name for the .obj
|
||||
|
||||
rend_data []Render_data // render data used for the rendering
|
||||
|
@ -35,7 +35,7 @@ import obj
|
||||
#flag -I @VMODROOT/.
|
||||
#include "gouraud.h" # Should be generated with `v shader .` (see the instructions at the top of this file)
|
||||
|
||||
fn C.gouraud_shader_desc(gfx.Backend) &C.sg_shader_desc
|
||||
fn C.gouraud_shader_desc(gfx.Backend) &gfx.ShaderDesc
|
||||
|
||||
const (
|
||||
win_width = 600
|
||||
@ -46,7 +46,7 @@ const (
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
texture C.sg_image
|
||||
texture gfx.Image
|
||||
init_flag bool
|
||||
frame_count int
|
||||
|
||||
@ -149,9 +149,9 @@ 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
|
||||
@ -159,7 +159,7 @@ fn frame(mut app App) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import sokol.gfx
|
||||
import sokol.sgl
|
||||
|
||||
struct AppState {
|
||||
pass_action C.sg_pass_action
|
||||
pass_action gfx.PassAction
|
||||
}
|
||||
|
||||
const (
|
||||
@ -27,7 +27,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn init(user_data voidptr) {
|
||||
desc := sapp.create_desc() // C.sg_desc{
|
||||
desc := sapp.create_desc() // gfx.Desc{
|
||||
gfx.setup(&desc)
|
||||
sgl_desc := C.sgl_desc_t{}
|
||||
sgl.setup(&sgl_desc)
|
||||
|
@ -8,23 +8,23 @@ import os
|
||||
|
||||
struct AppState {
|
||||
mut:
|
||||
pass_action C.sg_pass_action
|
||||
pass_action gfx.PassAction
|
||||
fons &fontstash.Context
|
||||
font_normal int
|
||||
}
|
||||
|
||||
[console]
|
||||
fn main() {
|
||||
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.3
|
||||
g: 0.3
|
||||
b: 0.32
|
||||
a: 1.0
|
||||
}
|
||||
}
|
||||
mut pass_action := C.sg_pass_action{}
|
||||
mut pass_action := gfx.PassAction{}
|
||||
pass_action.colors[0] = color_action
|
||||
state := &AppState{
|
||||
pass_action: pass_action
|
||||
|
@ -55,7 +55,7 @@ Let my heart be still a moment and this mystery explore;—
|
||||
|
||||
struct AppState {
|
||||
mut:
|
||||
pass_action C.sg_pass_action
|
||||
pass_action gfx.PassAction
|
||||
fons &fontstash.Context
|
||||
font_normal int
|
||||
inited bool
|
||||
@ -63,16 +63,16 @@ mut:
|
||||
|
||||
[console]
|
||||
fn main() {
|
||||
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: 1.0
|
||||
g: 1.0
|
||||
b: 1.0
|
||||
a: 1.0
|
||||
}
|
||||
}
|
||||
mut pass_action := C.sg_pass_action{}
|
||||
mut pass_action := gfx.PassAction{}
|
||||
pass_action.colors[0] = color_action
|
||||
state := &AppState{
|
||||
pass_action: pass_action
|
||||
|
@ -24,7 +24,7 @@ fn main() {
|
||||
}
|
||||
|
||||
struct App {
|
||||
pass_action C.sg_pass_action
|
||||
pass_action gfx.PassAction
|
||||
mut:
|
||||
width int
|
||||
height int
|
||||
@ -79,14 +79,14 @@ fn init(user_data voidptr) {
|
||||
max_vertices: 50 * 65536
|
||||
}
|
||||
sgl.setup(&sgl_desc)
|
||||
mut pipdesc := C.sg_pipeline_desc{}
|
||||
mut pipdesc := gfx.PipelineDesc{}
|
||||
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
|
||||
|
||||
color_state := C.sg_color_state{
|
||||
blend: C.sg_blend_state{
|
||||
color_state := gfx.ColorState{
|
||||
blend: gfx.BlendState{
|
||||
enabled: true
|
||||
src_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_SRC_ALPHA)
|
||||
dst_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA)
|
||||
src_factor_rgb: .src_alpha
|
||||
dst_factor_rgb: .one_minus_src_alpha
|
||||
}
|
||||
}
|
||||
pipdesc.colors[0] = color_state
|
||||
|
@ -2,6 +2,7 @@ import gg
|
||||
import gx
|
||||
import sokol.sapp
|
||||
import sokol.sgl
|
||||
import sokol.gfx
|
||||
import x.ttf
|
||||
import os
|
||||
|
||||
@ -20,7 +21,7 @@ const (
|
||||
struct App_data {
|
||||
pub mut:
|
||||
gg &gg.Context
|
||||
sg_img C.sg_image
|
||||
sg_img gfx.Image
|
||||
init_flag bool
|
||||
frame_c int
|
||||
tf []ttf.TTF_File
|
||||
|
@ -62,7 +62,7 @@ struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
pip_viewer C.sgl_pipeline
|
||||
texture C.sg_image
|
||||
texture gfx.Image
|
||||
init_flag bool
|
||||
frame_count int
|
||||
mouse_x int = -1
|
||||
@ -102,7 +102,7 @@ mut:
|
||||
font_path string // path to the temp font file
|
||||
// logo
|
||||
logo_path string // path of the temp font logo
|
||||
logo_texture C.sg_image
|
||||
logo_texture gfx.Image
|
||||
logo_w int
|
||||
logo_h int
|
||||
logo_ratio f32 = 1.0
|
||||
@ -115,9 +115,9 @@ mut:
|
||||
* Texture functions
|
||||
*
|
||||
******************************************************************************/
|
||||
fn create_texture(w int, h int, buf &u8) C.sg_image {
|
||||
fn create_texture(w int, h int, buf &u8) 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
|
||||
@ -130,28 +130,28 @@ fn create_texture(w int, h int, buf &u8) 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: .dynamic is enabled
|
||||
fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) {
|
||||
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
|
||||
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)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -225,7 +225,7 @@ pub fn read_bytes_from_file(file_path string) []byte {
|
||||
return buffer
|
||||
}
|
||||
|
||||
fn (mut app App) load_texture_from_buffer(buf voidptr, buf_len int) (C.sg_image, int, int) {
|
||||
fn (mut app App) load_texture_from_buffer(buf voidptr, buf_len int) (gfx.Image, int, int) {
|
||||
// load image
|
||||
stbi.set_flip_vertically_on_load(true)
|
||||
img := stbi.load_from_memory(buf, buf_len) or {
|
||||
@ -240,7 +240,7 @@ fn (mut app App) load_texture_from_buffer(buf voidptr, buf_len int) (C.sg_image,
|
||||
return res, int(img.width), int(img.height)
|
||||
}
|
||||
|
||||
pub fn (mut app App) load_texture_from_file(file_name string) (C.sg_image, int, int) {
|
||||
pub fn (mut app App) load_texture_from_file(file_name string) (gfx.Image, int, int) {
|
||||
app.read_bytes(file_name)
|
||||
return app.load_texture_from_buffer(app.mem_buf, app.mem_buf_size)
|
||||
}
|
||||
@ -315,21 +315,21 @@ fn app_init(mut app App) {
|
||||
app.init_flag = true
|
||||
|
||||
// 3d pipeline
|
||||
mut pipdesc := C.sg_pipeline_desc{}
|
||||
mut pipdesc := gfx.PipelineDesc{}
|
||||
unsafe { C.memset(&pipdesc, 0, sizeof(pipdesc)) }
|
||||
|
||||
color_state := C.sg_color_state{
|
||||
blend: C.sg_blend_state{
|
||||
color_state := gfx.ColorState{
|
||||
blend: gfx.BlendState{
|
||||
enabled: true
|
||||
src_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_SRC_ALPHA)
|
||||
dst_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA)
|
||||
src_factor_rgb: .src_alpha
|
||||
dst_factor_rgb: .one_minus_src_alpha
|
||||
}
|
||||
}
|
||||
pipdesc.colors[0] = color_state
|
||||
|
||||
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
|
||||
app.pip_viewer = sgl.make_pipeline(&pipdesc)
|
||||
|
@ -8,6 +8,7 @@
|
||||
*
|
||||
* TODO:
|
||||
**********************************************************************/
|
||||
import sokol.gfx
|
||||
import szip
|
||||
|
||||
fn (mut il Item_list) scan_zip(path string, in_index int) ? {
|
||||
@ -46,7 +47,7 @@ fn (mut il Item_list) scan_zip(path string, in_index int) ? {
|
||||
zp.close()
|
||||
}
|
||||
|
||||
fn (mut app App) load_texture_from_zip() ?(C.sg_image, int, int) {
|
||||
fn (mut app App) load_texture_from_zip() ?(gfx.Image, int, int) {
|
||||
item := app.item_list.lst[app.item_list.item_index]
|
||||
// println("Load from zip [${item.path}]")
|
||||
|
||||
|
Reference in New Issue
Block a user