diff options
Diffstat (limited to 'v_windows/v/vlib/sokol/sgl')
-rw-r--r-- | v_windows/v/vlib/sokol/sgl/sgl.c.v | 375 | ||||
-rw-r--r-- | v_windows/v/vlib/sokol/sgl/sgl_funcs.c.v | 91 | ||||
-rw-r--r-- | v_windows/v/vlib/sokol/sgl/sgl_structs.c.v | 24 |
3 files changed, 490 insertions, 0 deletions
diff --git a/v_windows/v/vlib/sokol/sgl/sgl.c.v b/v_windows/v/vlib/sokol/sgl/sgl.c.v new file mode 100644 index 0000000..0129cbf --- /dev/null +++ b/v_windows/v/vlib/sokol/sgl/sgl.c.v @@ -0,0 +1,375 @@ +module sgl + +import sokol.gfx + +pub const ( + version = gfx.version + 1 +) + +// setup/shutdown/misc +[inline] +pub fn setup(desc &C.sgl_desc_t) { + C.sgl_setup(desc) +} + +[inline] +pub fn shutdown() { + C.sgl_shutdown() +} + +[inline] +pub fn error() C.sgl_error_t { + return C.sgl_error() +} + +[inline] +pub fn defaults() { + C.sgl_defaults() +} + +[inline] +pub fn rad(deg f32) f32 { + return C.sgl_rad(deg) +} + +[inline] +pub fn deg(rad f32) f32 { + return C.sgl_deg(rad) +} + +// create and destroy pipeline objects +[inline] +pub fn make_pipeline(desc &C.sg_pipeline_desc) C.sgl_pipeline { + return C.sgl_make_pipeline(desc) +} + +[inline] +pub fn destroy_pipeline(pip C.sgl_pipeline) { + C.sgl_destroy_pipeline(pip) +} + +// render state functions +[inline] +pub fn viewport(x int, y int, w int, h int, origin_top_left bool) { + C.sgl_viewport(x, y, w, h, origin_top_left) +} + +[inline] +pub fn scissor_rect(x int, y int, w int, h int, origin_top_left bool) { + C.sgl_scissor_rect(x, y, w, h, origin_top_left) +} + +[inline] +pub fn enable_texture() { + C.sgl_enable_texture() +} + +[inline] +pub fn disable_texture() { + C.sgl_disable_texture() +} + +[inline] +pub fn texture(img C.sg_image) { + C.sgl_texture(img) +} + +// pipeline stack functions +[inline] +pub fn default_pipeline() { + C.sgl_default_pipeline() +} + +[inline] +pub fn load_pipeline(pip C.sgl_pipeline) { + C.sgl_load_pipeline(pip) +} + +[inline] +pub fn push_pipeline() { + C.sgl_push_pipeline() +} + +[inline] +pub fn pop_pipeline() { + C.sgl_pop_pipeline() +} + +// matrix stack functions +[inline] +pub fn matrix_mode_modelview() { + C.sgl_matrix_mode_modelview() +} + +[inline] +pub fn matrix_mode_projection() { + C.sgl_matrix_mode_projection() +} + +[inline] +pub fn matrix_mode_texture() { + C.sgl_matrix_mode_texture() +} + +[inline] +pub fn load_identity() { + C.sgl_load_identity() +} + +[inline] +pub fn load_matrix(m []f32) { + C.sgl_load_matrix(m.data) +} + +[inline] +pub fn load_transpose_matrix(m []f32) { + C.sgl_load_transpose_matrix(m.data) +} + +[inline] +pub fn mult_matrix(m []f32) { + C.sgl_mult_matrix(m.data) +} + +[inline] +pub fn mult_transpose_matrix(m []f32) { + C.sgl_mult_transpose_matrix(m.data) +} + +[inline] +pub fn rotate(angle_rad f32, x f32, y f32, z f32) { + C.sgl_rotate(angle_rad, x, y, z) +} + +[inline] +pub fn scale(x f32, y f32, z f32) { + C.sgl_scale(x, y, z) +} + +[inline] +pub fn translate(x f32, y f32, z f32) { + C.sgl_translate(x, y, z) +} + +[inline] +pub fn frustum(l f32, r f32, b f32, t f32, n f32, f f32) { + C.sgl_frustum(l, r, b, t, n, f) +} + +[inline] +pub fn ortho(l f32, r f32, b f32, t f32, n f32, f f32) { + C.sgl_ortho(l, r, b, t, n, f) +} + +[inline] +pub fn perspective(fov_y f32, aspect f32, z_near f32, z_far f32) { + C.sgl_perspective(fov_y, aspect, z_near, z_far) +} + +[inline] +pub fn lookat(eye_x f32, eye_y f32, eye_z f32, center_x f32, center_y f32, center_z f32, up_x f32, up_y f32, up_z f32) { + C.sgl_lookat(eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z) +} + +[inline] +pub fn push_matrix() { + C.sgl_push_matrix() +} + +[inline] +pub fn pop_matrix() { + C.sgl_pop_matrix() +} + +// these functions only set the internal 'current texcoord / color' (valid inside or outside begin/end) +[inline] +pub fn t2f(u f32, v f32) { + C.sgl_t2f(u, v) +} + +[inline] +pub fn c3f(r f32, g f32, b f32) { + C.sgl_c3f(r, g, b) +} + +[inline] +pub fn c4f(r f32, g f32, b f32, a f32) { + C.sgl_c4f(r, g, b, a) +} + +[inline] +pub fn c3b(r byte, g byte, b byte) { + C.sgl_c3b(r, g, b) +} + +[inline] +pub fn c4b(r byte, g byte, b byte, a byte) { + C.sgl_c4b(r, g, b, a) +} + +[inline] +pub fn c1i(rgba u32) { + C.sgl_c1i(rgba) +} + +// define primitives, each begin/end is one draw command +[inline] +pub fn begin_points() { + C.sgl_begin_points() +} + +[inline] +pub fn begin_lines() { + C.sgl_begin_lines() +} + +[inline] +pub fn begin_line_strip() { + C.sgl_begin_line_strip() +} + +[inline] +pub fn begin_triangles() { + C.sgl_begin_triangles() +} + +[inline] +pub fn begin_triangle_strip() { + C.sgl_begin_triangle_strip() +} + +[inline] +pub fn begin_quads() { + C.sgl_begin_quads() +} + +[inline] +pub fn v2f(x f32, y f32) { + C.sgl_v2f(x, y) +} + +[inline] +pub fn v3f(x f32, y f32, z f32) { + C.sgl_v3f(x, y, z) +} + +[inline] +pub fn v2f_t2f(x f32, y f32, u f32, v f32) { + C.sgl_v2f_t2f(x, y, u, v) +} + +[inline] +pub fn v3f_t2f(x f32, y f32, z f32, u f32, v f32) { + C.sgl_v3f_t2f(x, y, z, u, v) +} + +[inline] +pub fn v2f_c3f(x f32, y f32, r f32, g f32, b f32) { + C.sgl_v2f_c3f(x, y, r, g, b) +} + +[inline] +pub fn v2f_c3b(x f32, y f32, r byte, g byte, b byte) { + C.sgl_v2f_c3b(x, y, r, g, b) +} + +[inline] +pub fn v2f_c4f(x f32, y f32, r f32, g f32, b f32, a f32) { + C.sgl_v2f_c4f(x, y, r, g, b, a) +} + +[inline] +pub fn v2f_c4b(x f32, y f32, r byte, g byte, b byte, a byte) { + C.sgl_v2f_c4b(x, y, r, g, b, a) +} + +[inline] +pub fn v2f_c1i(x f32, y f32, rgba u32) { + C.sgl_v2f_c1i(x, y, rgba) +} + +[inline] +pub fn v3f_c3f(x f32, y f32, z f32, r f32, g f32, b f32) { + C.sgl_v3f_c3f(x, y, z, r, g, b) +} + +[inline] +pub fn v3f_c3b(x f32, y f32, z f32, r byte, g byte, b byte) { + C.sgl_v3f_c3b(x, y, z, r, g, b) +} + +[inline] +pub fn v3f_c4f(x f32, y f32, z f32, r f32, g f32, b f32, a f32) { + C.sgl_v3f_c4f(x, y, z, r, g, b, a) +} + +[inline] +pub fn v3f_c4b(x f32, y f32, z f32, r byte, g byte, b byte, a byte) { + C.sgl_v3f_c4b(x, y, z, r, g, b, a) +} + +[inline] +pub fn v3f_c1i(x f32, y f32, z f32, rgba u32) { + C.sgl_v3f_c1i(x, y, z, rgba) +} + +[inline] +pub fn v2f_t2f_c3f(x f32, y f32, u f32, v f32, r f32, g f32, b f32) { + C.sgl_v2f_t2f_c3f(x, y, u, v, r, g, b) +} + +[inline] +pub fn v2f_t2f_c3b(x f32, y f32, u f32, v f32, r byte, g byte, b byte) { + C.sgl_v2f_t2f_c3b(x, y, u, v, r, g, b) +} + +[inline] +pub fn v2f_t2f_c4f(x f32, y f32, u f32, v f32, r f32, g f32, b f32, a f32) { + C.sgl_v2f_t2f_c4f(x, y, u, v, r, g, b, a) +} + +[inline] +pub fn v2f_t2f_c4b(x f32, y f32, u f32, v f32, r byte, g byte, b byte, a byte) { + C.sgl_v2f_t2f_c4b(x, y, u, v, r, g, b, a) +} + +[inline] +pub fn v2f_t2f_c1i(x f32, y f32, u f32, v f32, rgba u32) { + C.sgl_v2f_t2f_c1i(x, y, u, v, rgba) +} + +[inline] +pub fn v3f_t2f_c3f(x f32, y f32, z f32, u f32, v f32, r f32, g f32, b f32) { + C.sgl_v3f_t2f_c3f(x, y, z, u, v, r, g, b) +} + +[inline] +pub fn v3f_t2f_c3b(x f32, y f32, z f32, u f32, v f32, r byte, g byte, b byte) { + C.sgl_v3f_t2f_c3b(x, y, z, u, v, r, g, b) +} + +[inline] +pub fn v3f_t2f_c4f(x f32, y f32, z f32, u f32, v f32, r f32, g f32, b f32, a f32) { + C.sgl_v3f_t2f_c4f(x, y, z, u, v, r, g, b, a) +} + +[inline] +pub fn v3f_t2f_c4b(x f32, y f32, z f32, u f32, v f32, r byte, g byte, b byte, a byte) { + C.sgl_v3f_t2f_c4b(x, y, z, u, v, r, g, b, a) +} + +[inline] +pub fn v3f_t2f_c1i(x f32, y f32, z f32, u f32, v f32, rgba u32) { + C.sgl_v3f_t2f_c1i(x, y, z, u, v, rgba) +} + +[inline] +pub fn end() { + C.sgl_end() +} + +// render everything +[inline] +pub fn draw() { + C.sgl_draw() +} diff --git a/v_windows/v/vlib/sokol/sgl/sgl_funcs.c.v b/v_windows/v/vlib/sokol/sgl/sgl_funcs.c.v new file mode 100644 index 0000000..16e980d --- /dev/null +++ b/v_windows/v/vlib/sokol/sgl/sgl_funcs.c.v @@ -0,0 +1,91 @@ +module sgl + +// setup/shutdown/misc +fn C.sgl_setup(desc &C.sgl_desc_t) +fn C.sgl_shutdown() +fn C.sgl_error() C.sgl_error_t +fn C.sgl_defaults() +fn C.sgl_rad(deg f32) f32 +fn C.sgl_deg(rad f32) f32 + +// create and destroy pipeline objects +fn C.sgl_make_pipeline(desc &C.sg_pipeline_desc) C.sgl_pipeline +fn C.sgl_destroy_pipeline(pip C.sgl_pipeline) + +// render state functions +fn C.sgl_viewport(x int, y int, w int, h int, origin_top_left bool) +fn C.sgl_viewportf(x f32, y f32, w f32, h f32, origin_top_left bool) +fn C.sgl_scissor_rect(x int, y int, w int, h int, origin_top_left bool) +fn C.sgl_scissor_rectf(x f32, y f32, w f32, h f32, origin_top_left bool) +fn C.sgl_enable_texture() +fn C.sgl_disable_texture() +fn C.sgl_texture(img C.sg_image) + +// pipeline stack functions +fn C.sgl_default_pipeline() +fn C.sgl_load_pipeline(pip C.sgl_pipeline) +fn C.sgl_push_pipeline() +fn C.sgl_pop_pipeline() + +// matrix stack functions +fn C.sgl_matrix_mode_modelview() +fn C.sgl_matrix_mode_projection() +fn C.sgl_matrix_mode_texture() +fn C.sgl_load_identity() +fn C.sgl_load_matrix(m [16]f32) +fn C.sgl_load_transpose_matrix(m [16]f32) +fn C.sgl_mult_matrix(m [16]f32) +fn C.sgl_mult_transpose_matrix(m [16]f32) +fn C.sgl_rotate(angle_rad f32, x f32, y f32, z f32) +fn C.sgl_scale(x f32, y f32, z f32) +fn C.sgl_translate(x f32, y f32, z f32) +fn C.sgl_frustum(l f32, r f32, b f32, t f32, n f32, f f32) +fn C.sgl_ortho(l f32, r f32, b f32, t f32, n f32, f f32) +fn C.sgl_perspective(fov_y f32, aspect f32, z_near f32, z_far f32) +fn C.sgl_lookat(eye_x f32, eye_y f32, eye_z f32, center_x f32, center_y f32, center_z f32, up_x f32, up_y f32, up_z f32) +fn C.sgl_push_matrix() +fn C.sgl_pop_matrix() + +// these functions only set the internal 'current texcoord / color' (valid inside or outside begin/end) +fn C.sgl_t2f(u f32, v f32) +fn C.sgl_c3f(r f32, g f32, b f32) +fn C.sgl_c4f(r f32, g f32, b f32, a f32) +fn C.sgl_c3b(r byte, g byte, b byte) +fn C.sgl_c4b(r byte, g byte, b byte, a byte) +fn C.sgl_c1i(rgba u32) + +// define primitives, each begin/end is one draw command +fn C.sgl_begin_points() +fn C.sgl_begin_lines() +fn C.sgl_begin_line_strip() +fn C.sgl_begin_triangles() +fn C.sgl_begin_triangle_strip() +fn C.sgl_begin_quads() +fn C.sgl_v2f(x f32, y f32) +fn C.sgl_v3f(x f32, y f32, z f32) +fn C.sgl_v2f_t2f(x f32, y f32, u f32, v f32) +fn C.sgl_v3f_t2f(x f32, y f32, z f32, u f32, v f32) +fn C.sgl_v2f_c3f(x f32, y f32, r f32, g f32, b f32) +fn C.sgl_v2f_c3b(x f32, y f32, r byte, g byte, b byte) +fn C.sgl_v2f_c4f(x f32, y f32, r f32, g f32, b f32, a f32) +fn C.sgl_v2f_c4b(x f32, y f32, r byte, g byte, b byte, a byte) +fn C.sgl_v2f_c1i(x f32, y f32, rgba u32) +fn C.sgl_v3f_c3f(x f32, y f32, z f32, r f32, g f32, b f32) +fn C.sgl_v3f_c3b(x f32, y f32, z f32, r byte, g byte, b byte) +fn C.sgl_v3f_c4f(x f32, y f32, z f32, r f32, g f32, b f32, a f32) +fn C.sgl_v3f_c4b(x f32, y f32, z f32, r byte, g byte, b byte, a byte) +fn C.sgl_v3f_c1i(x f32, y f32, z f32, rgba u32) +fn C.sgl_v2f_t2f_c3f(x f32, y f32, u f32, v f32, r f32, g f32, b f32) +fn C.sgl_v2f_t2f_c3b(x f32, y f32, u f32, v f32, r byte, g byte, b byte) +fn C.sgl_v2f_t2f_c4f(x f32, y f32, u f32, v f32, r f32, g f32, b f32, a f32) +fn C.sgl_v2f_t2f_c4b(x f32, y f32, u f32, v f32, r byte, g byte, b byte, a byte) +fn C.sgl_v2f_t2f_c1i(x f32, y f32, u f32, v f32, rgba u32) +fn C.sgl_v3f_t2f_c3f(x f32, y f32, z f32, u f32, v f32, r f32, g f32, b f32) +fn C.sgl_v3f_t2f_c3b(x f32, y f32, z f32, u f32, v f32, r byte, g byte, b byte) +fn C.sgl_v3f_t2f_c4f(x f32, y f32, z f32, u f32, v f32, r f32, g f32, b f32, a f32) +fn C.sgl_v3f_t2f_c4b(x f32, y f32, z f32, u f32, v f32, r byte, g byte, b byte, a byte) +fn C.sgl_v3f_t2f_c1i(x f32, y f32, z f32, u f32, v f32, rgba u32) +fn C.sgl_end() + +// render everything +fn C.sgl_draw() diff --git a/v_windows/v/vlib/sokol/sgl/sgl_structs.c.v b/v_windows/v/vlib/sokol/sgl/sgl_structs.c.v new file mode 100644 index 0000000..25753c4 --- /dev/null +++ b/v_windows/v/vlib/sokol/sgl/sgl_structs.c.v @@ -0,0 +1,24 @@ +module sgl + +// should be in a proper module +pub enum SglError { + no_error + vertices_full + commands_full + stack_overflow + stack_underfloat +} + +pub struct C.sgl_pipeline { + id u32 +} + +pub struct C.sgl_desc_t { + max_vertices int // size for vertex buffer + max_commands int // size of uniform- and command-buffers + pipeline_pool_size int // size of the internal pipeline pool, default is 64 + color_format C.sg_pixel_format + depth_format C.sg_pixel_format + sample_count int + face_winding C.sg_face_winding // default front face winding is CCW +} |