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

examples: make v -prod build-examples pass without warnings/errors

This commit is contained in:
Delyan Angelov
2020-10-18 09:48:13 +03:00
parent 67ecc04580
commit 8b2e704741
9 changed files with 594 additions and 512 deletions

View File

@@ -13,13 +13,13 @@ import math
// import time
pub type FNCb = fn (x voidptr)
pub type FNEvent = fn (e, x voidptr)
pub type FNEvent = fn (e voidptr, x voidptr)
pub type FNFail = fn (msg string, x voidptr)
pub type FNKeyDown = fn (c sapp.KeyCode, m sapp.Modifier, x voidptr)
pub type FNMove = fn (x, y f32, z voidptr)
pub type FNMove = fn (x f32, y f32, z voidptr)
pub type FNChar = fn (c u32, x voidptr)
@@ -43,13 +43,18 @@ pub:
cleanup_fn FNCb = voidptr(0)
fail_fn FNFail = voidptr(0)
event_fn FNEvent = voidptr(0)
keydown_fn FNKeyDown = voidptr(0) // special case of event_fn
char_fn FNChar = voidptr(0) // special case of event_fn
move_fn FNMove = voidptr(0) // special case of event_fn
click_fn FNMove = voidptr(0) // special case of event_fn
keydown_fn FNKeyDown = voidptr(0)
// special case of event_fn
char_fn FNChar = voidptr(0)
// special case of event_fn
move_fn FNMove = voidptr(0)
// special case of event_fn
click_fn FNMove = voidptr(0)
// special case of event_fn
wait_events bool // set this to true for UIs, to save power
fullscreen bool
scale f32 = 1.0 // vid needs this
scale f32 = 1.0
// vid needs this
// init_text bool
font_path string
}
@@ -61,7 +66,8 @@ mut:
// (so that the user can store image ids, not entire Image objects)
image_cache []Image
pub mut:
scale f32 = 1.0 // will get set to 2.0 for retina, will remain 1.0 for normal
scale f32 = 1.0
// will get set to 2.0 for retina, will remain 1.0 for normal
width int
height int
clear_pass C.sg_pass_action
@@ -237,7 +243,7 @@ pub fn (mut ctx Context) set_bg_color(c gx.Color) {
}
// TODO: Fix alpha
pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
pub fn (ctx &Context) draw_rect(x f32, y f32, w f32, h f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -250,7 +256,7 @@ pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
sgl.end()
}
pub fn (ctx &Context) draw_triangle(x, y, x2, y2, x3, y3 f32, c gx.Color) {
pub fn (ctx &Context) draw_triangle(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -262,7 +268,7 @@ pub fn (ctx &Context) draw_triangle(x, y, x2, y2, x3, y3 f32, c gx.Color) {
sgl.end()
}
pub fn (ctx &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
pub fn (ctx &Context) draw_empty_rect(x f32, y f32, w f32, h f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -284,7 +290,7 @@ pub fn (ctx &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
sgl.end()
}
pub fn (ctx &Context) draw_circle_line(x, y f32, r, segments int, c gx.Color) {
pub fn (ctx &Context) draw_circle_line(x f32, y f32, r int, segments int, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -302,8 +308,7 @@ pub fn (ctx &Context) draw_circle_line(x, y f32, r, segments int, c gx.Color) {
sgl.end()
}
pub fn (ctx &Context) draw_circle(x, y f32, r, segments int, c gx.Color) {
pub fn (ctx &Context) draw_circle(x f32, y f32, r int, segments int, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -322,7 +327,7 @@ pub fn (ctx &Context) draw_circle(x, y f32, r, segments int, c gx.Color) {
sgl.end()
}
pub fn (ctx &Context) draw_arc_line(x, y f32, r int, start_angle, arc_angle f32, segments int, c gx.Color) {
pub fn (ctx &Context) draw_arc_line(x f32, y f32, r int, start_angle f32, arc_angle f32, segments int, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -345,7 +350,7 @@ pub fn (ctx &Context) draw_arc_line(x, y f32, r int, start_angle, arc_angle f32,
sgl.end()
}
pub fn (ctx &Context) draw_arc(x, y f32, r int, start_angle, arc_angle f32, segments int, c gx.Color) {
pub fn (ctx &Context) draw_arc(x f32, y f32, r int, start_angle f32, arc_angle f32, segments int, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -396,7 +401,7 @@ fn abs(a f32) f32 {
return -a
}
pub fn (ctx &Context) draw_line(x, y, x2, y2 f32, c gx.Color) {
pub fn (ctx &Context) draw_line(x f32, y f32, x2 f32, y2 f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
@@ -419,10 +424,10 @@ pub fn (ctx &Context) draw_line(x, y, x2, y2 f32, c gx.Color) {
sgl.end()
}
pub fn (ctx &Context) draw_rounded_rect(x, y, width, height, radius f32, color gx.Color) {
pub fn (ctx &Context) draw_rounded_rect(x f32, y f32, width f32, height f32, radius f32, color gx.Color) {
}
pub fn (ctx &Context) draw_empty_rounded_rect(x, y, width, height, radius f32, border_color gx.Color) {
pub fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, width f32, height f32, radius f32, border_color gx.Color) {
}
fn C.WaitMessage()

View File

@@ -2,17 +2,17 @@
// Use of this source code is governed by an MIT license that can be found in the LICENSE file.
module gg
//import gx
// import gx
// import sokol.sapp
// import sokol.gfx
import os
import sokol
//import sokol.sapp
import sokol.sgl
//import sokol.gfx
import stbi
pub struct Image {
pub mut:
id int
id int
width int
height int
nr_channels int
@@ -21,7 +21,7 @@ pub mut:
ext string
simg_ok bool
simg C.sg_image
path string
path string
}
fn C.sg_isvalid() bool
@@ -30,8 +30,10 @@ fn C.sg_isvalid() bool
pub fn (mut ctx Context) create_image(file string) Image {
if !C.sg_isvalid() {
// Sokol is not initialized yet, add stbi object to a queue/cache
//ctx.image_queue << file
stb_img := stbi.load(file) or { return Image{} }
// ctx.image_queue << file
stb_img := stbi.load(file) or {
return Image{}
}
img := Image{
width: stb_img.width
height: stb_img.height
@@ -57,7 +59,9 @@ fn create_image(file string) Image {
println('gg.create_image(): file not found: $file')
return Image{} // none
}
stb_img := stbi.load(file) or { return Image{} }
stb_img := stbi.load(file) or {
return Image{}
}
mut img := Image{
width: stb_img.width
height: stb_img.height
@@ -72,7 +76,9 @@ fn create_image(file string) Image {
}
pub fn create_image_from_memory(buf byteptr, bufsize int) Image {
stb_img := stbi.load_from_memory(buf, bufsize) or { return Image{} }
stb_img := stbi.load_from_memory(buf, bufsize) or {
return Image{}
}
mut img := Image{
width: stb_img.width
height: stb_img.height
@@ -89,7 +95,7 @@ pub fn create_image_from_byte_array(b []byte) Image {
}
pub fn (mut img Image) init_sokol_image() &Image {
//println('\n init sokol image $img.path ok=$img.simg_ok')
// println('\n init sokol image $img.path ok=$img.simg_ok')
mut img_desc := C.sg_image_desc{
width: img.width
height: img.height
@@ -109,7 +115,7 @@ pub fn (mut img Image) init_sokol_image() &Image {
return img
}
pub fn (ctx &Context) draw_image(x, y, width, height f32, img_ &Image) {
pub fn (ctx &Context) draw_image(x f32, y f32, width f32, height f32, img_ &Image) {
if img_.id >= ctx.image_cache.len {
eprintln('gg: draw_image() bad img id $img_.id (img cache len = $ctx.image_cache.len)')
return
@@ -132,16 +138,16 @@ pub fn (ctx &Context) draw_image(x, y, width, height f32, img_ &Image) {
sgl.texture(img.simg)
sgl.begin_quads()
sgl.c4b(255, 255, 255, 255)
sgl.v2f_t2f(x0, y0, u0, v0)
sgl.v2f_t2f(x1, y0, u1, v0)
sgl.v2f_t2f(x1, y1, u1, v1)
sgl.v2f_t2f(x0, y1, u0, v1)
sgl.v2f_t2f(x0, y0, u0, v0)
sgl.v2f_t2f(x1, y0, u1, v0)
sgl.v2f_t2f(x1, y1, u1, v1)
sgl.v2f_t2f(x0, y1, u0, v1)
sgl.end()
sgl.disable_texture()
}
// TODO remove copy pasta, merge the functions
pub fn (ctx &Context) draw_image_flipped(x, y, width, height f32, img_ &Image) {
pub fn (ctx &Context) draw_image_flipped(x f32, y f32, width f32, height f32, img_ &Image) {
if img_.id >= ctx.image_cache.len {
eprintln('gg: draw_image() bad img id $img_.id (img cache len = $ctx.image_cache.len)')
return
@@ -164,17 +170,15 @@ pub fn (ctx &Context) draw_image_flipped(x, y, width, height f32, img_ &Image) {
sgl.texture(img.simg)
sgl.begin_quads()
sgl.c4b(255, 255, 255, 255)
sgl.v2f_t2f(x0, y0, u1, v0)
sgl.v2f_t2f(x1, y0, u0, v0)
sgl.v2f_t2f(x1, y1, u0, v1)
sgl.v2f_t2f(x0, y1, u1, v1)
sgl.v2f_t2f(x0, y0, u1, v0)
sgl.v2f_t2f(x1, y0, u0, v0)
sgl.v2f_t2f(x1, y1, u0, v1)
sgl.v2f_t2f(x0, y1, u1, v1)
sgl.end()
sgl.disable_texture()
}
pub fn (ctx &Context) draw_image_by_id(x, y, width, height f32, id int) {
pub fn (ctx &Context) draw_image_by_id(x f32, y f32, width f32, height f32, id int) {
img := ctx.image_cache[id]
ctx.draw_image(x,y,width,height,img)
ctx.draw_image(x, y, width, height, img)
}

View File

@@ -16,22 +16,21 @@ enum FontVariant {
struct FT {
pub:
fons &C.FONScontext
fons &C.FONScontext
font_normal int
font_bold int
font_mono int
font_bold int
font_mono int
font_italic int
scale f32 = 1.0
scale f32 = 1.0
}
struct FTConfig {
font_path string
scale f32 = 1.0
scale f32 = 1.0
font_size int
}
fn new_ft(c FTConfig) ?&FT{
fn new_ft(c FTConfig) ?&FT {
if c.font_path == '' {
// Load default font
}
@@ -41,7 +40,6 @@ fn new_ft(c FTConfig) ?&FT{
return none
}
}
mut bytes := []byte{}
$if android {
bytes = os.read_apk_asset(c.font_path) or {
@@ -60,40 +58,38 @@ fn new_ft(c FTConfig) ?&FT{
bytes
}
mono_path := get_font_path_variant(c.font_path, .mono)
bytes_mono:= os.read_bytes(mono_path) or {
bytes_mono := os.read_bytes(mono_path) or {
debug_font_println('failed to load font "$mono_path"')
bytes
}
italic_path := get_font_path_variant(c.font_path, .italic)
bytes_italic:= os.read_bytes(italic_path) or {
bytes_italic := os.read_bytes(italic_path) or {
debug_font_println('failed to load font "$italic_path"')
bytes
}
fons := sfons.create(512, 512, 1)
return &FT{
fons : fons
fons: fons
font_normal: C.fonsAddFontMem(fons, 'sans', bytes.data, bytes.len, false)
font_bold: C.fonsAddFontMem(fons, 'sans', bytes_bold.data, bytes_bold.len, false)
font_mono: C.fonsAddFontMem(fons, 'sans', bytes_mono.data, bytes_mono.len, false)
font_italic: C.fonsAddFontMem(fons, 'sans', bytes_italic.data, bytes_italic.len, false)
font_italic: C.fonsAddFontMem(fons, 'sans', bytes_italic.data, bytes_italic.len,
false)
scale: c.scale
}
}
fn (ctx &Context) set_cfg(cfg gx.TextCfg) {
if !ctx.font_inited {
return
}
if cfg.bold {
ctx.ft.fons.set_font(ctx.ft.font_bold)
}
else if cfg.mono {
} else if cfg.mono {
ctx.ft.fons.set_font(ctx.ft.font_mono)
}
else if cfg.italic {
} else if cfg.italic {
ctx.ft.fons.set_font(ctx.ft.font_italic)
}
else {
} else {
ctx.ft.fons.set_font(ctx.ft.font_normal)
}
scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale }
@@ -111,12 +107,12 @@ fn (ctx &Context) set_cfg(cfg gx.TextCfg) {
ctx.ft.fons.vert_metrics(&ascender, &descender, &lh)
}
pub fn (ctx &Context) draw_text(x, y int, text_ string, cfg gx.TextCfg) {
pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) {
if !ctx.font_inited {
eprintln('gg: draw_text(): font not initialized')
return
}
//text := text_.trim_space() // TODO remove/optimize
// text := text_.trim_space() // TODO remove/optimize
mut text := text_
if text.contains('\t') {
text = text.replace('\t', ' ')
@@ -126,7 +122,7 @@ pub fn (ctx &Context) draw_text(x, y int, text_ string, cfg gx.TextCfg) {
C.fonsDrawText(ctx.ft.fons, x * scale, y * scale, text.str, 0) // TODO: check offsets/alignment
}
pub fn (ctx &Context) draw_text_def(x, y int, text string) {
pub fn (ctx &Context) draw_text_def(x int, y int, text string) {
ctx.draw_text(x, y, text, {})
}
@@ -134,8 +130,7 @@ pub fn (ctx &Context) draw_text_def(x, y int, text string) {
pub fn (mut gg FT) init_font() {
}
*/
pub fn (ft &FT) flush(){
pub fn (ft &FT) flush() {
sfons.flush(ft.fons)
}
@@ -165,14 +160,13 @@ pub fn (ctx &Context) text_height(s string) int {
pub fn (ctx &Context) text_size(s string) (int, int) {
// ctx.set_cfg(cfg) TODO
if !ctx.font_inited {
return 0,0
return 0, 0
}
mut buf := [4]f32{}
C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf)
return int((buf[2] - buf[0]) / ctx.scale), int((buf[3] - buf[1]) / ctx.scale)
}
pub fn system_font_path() string {
env_font := os.getenv('VUI_FONT')
if env_font != '' && os.exists(env_font) {
@@ -182,7 +176,7 @@ pub fn system_font_path() string {
return 'C:\\Windows\\Fonts\\arial.ttf'
}
mut fonts := ['Ubuntu-R.ttf', 'Arial.ttf', 'LiberationSans-Regular.ttf', 'NotoSans-Regular.ttf',
'FreeSans.ttf', 'DejaVuSans.ttf']
'FreeSans.ttf', 'DejaVuSans.ttf']
$if macos {
fonts = ['/System/Library/Fonts/SFNS.ttf', '/System/Library/Fonts/SFNSText.ttf', '/Library/Fonts/Arial.ttf']
for font in fonts {
@@ -191,7 +185,9 @@ pub fn system_font_path() string {
}
}
}
s := os.exec('fc-list') or { panic('failed to fetch system fonts') }
s := os.exec('fc-list') or {
panic('failed to fetch system fonts')
}
system_fonts := s.output.split('\n')
for line in system_fonts {
for font in fonts {
@@ -247,7 +243,7 @@ fn get_font_path_variant(font_path string, variant FontVariant) string {
}
fn debug_font_println(s string) {
$if debug_font? {
$if debug_font ? {
println(s)
}
}

View File

@@ -1,29 +1,106 @@
module gx
pub const (
blue = Color { r: 0, g: 0, b: 255 }
red = Color { r: 255, g: 0, b: 0 }
green = Color { r: 0, g: 255, b: 0 }
yellow = Color { r: 255, g: 255, b: 0 }
orange = Color { r: 255, g: 165, b: 0 }
purple = Color { r: 128, g: 0, b: 128 }
black = Color { r: 0, g: 0, b: 0 }
gray = Color { r: 128, g: 128, b: 128 }
indigo = Color { r: 75, g: 0, b: 130 }
pink = Color { r: 255, g: 192, b: 203 }
violet = Color { r: 238, g: 130, b: 238 }
white = Color { r: 255, g: 255, b: 255 }
dark_blue = Color { r: 0, g: 0, b: 139 }
dark_gray = Color { r: 169, g: 169, b: 169 }
dark_green = Color { r: 0, g: 100, b: 0 }
dark_red = Color { r: 139, g: 0, b: 0 }
light_blue = Color { r: 173, g: 216, b: 230 }
light_gray = Color { r: 211, g: 211, b: 211 }
light_green = Color { r: 144, g: 238, b: 144 }
light_red = Color { r: 255, g: 204, b: 203 }
blue = Color{
r: 0
g: 0
b: 255
}
red = Color{
r: 255
g: 0
b: 0
}
green = Color{
r: 0
g: 255
b: 0
}
yellow = Color{
r: 255
g: 255
b: 0
}
orange = Color{
r: 255
g: 165
b: 0
}
purple = Color{
r: 128
g: 0
b: 128
}
black = Color{
r: 0
g: 0
b: 0
}
gray = Color{
r: 128
g: 128
b: 128
}
indigo = Color{
r: 75
g: 0
b: 130
}
pink = Color{
r: 255
g: 192
b: 203
}
violet = Color{
r: 238
g: 130
b: 238
}
white = Color{
r: 255
g: 255
b: 255
}
dark_blue = Color{
r: 0
g: 0
b: 139
}
dark_gray = Color{
r: 169
g: 169
b: 169
}
dark_green = Color{
r: 0
g: 100
b: 0
}
dark_red = Color{
r: 139
g: 0
b: 0
}
light_blue = Color{
r: 173
g: 216
b: 230
}
light_gray = Color{
r: 211
g: 211
b: 211
}
light_green = Color{
r: 144
g: 238
b: 144
}
light_red = Color{
r: 255
g: 204
b: 203
}
)
// Color represents a 32 bit color value in sRGB format
@@ -37,63 +114,63 @@ pub mut:
// hex takes in a 32 bit integer and splits it into 4 byte values
pub fn hex(color int) Color {
return Color {
r: byte((color >> 24) & 0xFF),
g: byte((color >> 16) & 0xFF),
b: byte((color >> 8) & 0xFF),
a: byte((color ) & 0xFF)
return Color{
r: byte((color >> 24) & 0xFF)
g: byte((color >> 16) & 0xFF)
b: byte((color >> 8) & 0xFF)
a: byte((color) & 0xFF)
}
}
pub fn rgb(r, g, b byte) Color {
pub fn rgb(r byte, g byte, b byte) Color {
return Color{
r: r,
g: g,
r: r
g: g
b: b
}
}
pub fn rgba(r, g, b, a byte) Color {
pub fn rgba(r byte, g byte, b byte, a byte) Color {
return Color{
r: r,
g: g,
b: b,
r: r
g: g
b: b
a: a
}
}
pub fn (c Color) + (c2 Color) Color {
return Color {
r: c.r + c2.r,
g: c.g + c2.g,
b: c.b + c2.b,
pub fn (c Color) +(c2 Color) Color {
return Color{
r: c.r + c2.r
g: c.g + c2.g
b: c.b + c2.b
a: c.b + c2.a
}
}
pub fn (c Color) - (c2 Color) Color {
return Color {
r: c.r - c2.r,
g: c.g - c2.g,
b: c.b - c2.b,
pub fn (c Color) -(c2 Color) Color {
return Color{
r: c.r - c2.r
g: c.g - c2.g
b: c.b - c2.b
a: c.b - c2.a
}
}
pub fn (c Color) * (c2 Color) Color {
return Color {
r: c.r * c2.r,
g: c.g * c2.g,
b: c.b * c2.b,
pub fn (c Color) *(c2 Color) Color {
return Color{
r: c.r * c2.r
g: c.g * c2.g
b: c.b * c2.b
a: c.b * c2.a
}
}
pub fn (c Color) / (c2 Color) Color {
return Color {
r: c.r / c2.r,
g: c.g / c2.g,
b: c.b / c2.b,
pub fn (c Color) /(c2 Color) Color {
return Color{
r: c.r / c2.r
g: c.g / c2.g
b: c.b / c2.b
a: c.b / c2.a
}
}
@@ -107,11 +184,11 @@ pub fn (c Color) str() string {
}
const (
string_colors = {
'black': black
'blue': blue
'red': red
}
string_colors = {
'black': black
'blue': blue
'red': red
}
)
pub fn color_from_string(s string) Color {

View File

@@ -1,16 +1,16 @@
module gfx
pub struct C.sg_desc {
_start_canary u32
buffer_pool_size int
image_pool_size int
shader_pool_size int
pipeline_pool_size int
pass_pool_size int
context_pool_size int
context C.sg_context_desc
/*
// GL specific
_start_canary u32
buffer_pool_size int
image_pool_size int
shader_pool_size int
pipeline_pool_size int
pass_pool_size int
context_pool_size int
context C.sg_context_desc
/*
// GL specific
gl_force_gles2 bool
// Metal-specific
mtl_device voidptr
@@ -23,435 +23,438 @@ pub struct C.sg_desc {
d3d11_device_context voidptr
d3d11_render_target_view_cb fn() voidptr
d3d11_depth_stencil_view_cb fn() voidptr
*/
_end_canary u32
*/
_end_canary u32
}
pub struct C.sg_context_desc {
/*
sg_pixel_format color_format;
sg_pixel_format color_format;
sg_pixel_format depth_format;
int sample_count;
sg_wgpu_context_desc wgpu;
*/
sample_count int
gl C.sg_gl_context_desc
metal C.sg_mtl_context_desc
d3d11 C.sg_d3d11_context_desc
color_format PixelFormat
depth_format PixelFormat
*/
sample_count int
gl C.sg_gl_context_desc
metal C.sg_mtl_context_desc
d3d11 C.sg_d3d11_context_desc
color_format PixelFormat
depth_format PixelFormat
}
pub struct C.sg_gl_context_desc {
gl_force_gles2 bool
gl_force_gles2 bool
}
pub struct C.sg_mtl_context_desc {
device voidptr
renderpass_descriptor_cb fn() voidptr
drawable_cb fn() voidptr
device voidptr
renderpass_descriptor_cb fn () voidptr
drawable_cb fn () voidptr
}
pub struct C.sg_d3d11_context_desc {
device voidptr
device_context voidptr
render_target_view_cb fn() voidptr
depth_stencil_view_cb fn() voidptr
device voidptr
device_context voidptr
render_target_view_cb fn () voidptr
depth_stencil_view_cb fn () voidptr
}
pub struct C.sg_pipeline_desc {
pub mut:
_start_canary u32
layout C.sg_layout_desc
shader C.sg_shader
primitive_type PrimitiveType
index_type IndexType
depth_stencil C.sg_depth_stencil_state
blend C.sg_blend_state
rasterizer C.sg_rasterizer_state
label byteptr
_end_canary u32
_start_canary u32
layout C.sg_layout_desc
shader C.sg_shader
primitive_type PrimitiveType
index_type IndexType
depth_stencil C.sg_depth_stencil_state
blend C.sg_blend_state
rasterizer C.sg_rasterizer_state
label byteptr
_end_canary u32
}
pub struct C.sg_pipeline_info {
}
pub struct C.sg_pipeline {
pub:
id u32
id u32
}
pub fn (p C.sg_pipeline) free() { C.sg_destroy_pipeline(p) }
pub fn (p C.sg_pipeline) free() {
C.sg_destroy_pipeline(p)
}
pub struct C.sg_bindings {
pub mut:
_start_canary u32
vertex_buffers [8]C.sg_buffer
vertex_buffer_offsets [8]int
index_buffer C.sg_buffer
index_buffer_offset int
vs_images [8]C.sg_image
fs_images [8]C.sg_image
_end_canary u32
_start_canary u32
vertex_buffers [8]C.sg_buffer
vertex_buffer_offsets [8]int
index_buffer C.sg_buffer
index_buffer_offset int
vs_images [8]C.sg_image
fs_images [8]C.sg_image
_end_canary u32
}
pub fn (mut b C.sg_bindings) set_vert_image(index int, img C.sg_image) {
b.vs_images[index] = img
b.vs_images[index] = img
}
pub fn (mut b C.sg_bindings) set_frag_image(index int, img C.sg_image) {
b.fs_images[index] = img
b.fs_images[index] = img
}
pub fn (b &C.sg_bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) {
C.sg_update_buffer(b.vertex_buffers[index], data, element_size * element_count)
C.sg_update_buffer(b.vertex_buffers[index], data, element_size * element_count)
}
pub fn (b &C.sg_bindings) append_vert_buffer(index int, data voidptr, element_size int, element_count int) int {
return C.sg_append_buffer(b.vertex_buffers[index], data, element_size * element_count)
return C.sg_append_buffer(b.vertex_buffers[index], data, element_size * element_count)
}
pub fn (b &C.sg_bindings) update_index_buffer(data voidptr, element_size int, element_count int) {
C.sg_update_buffer(b.index_buffer, data, element_size * element_count)
C.sg_update_buffer(b.index_buffer, data, element_size * element_count)
}
pub fn (b &C.sg_bindings) append_index_buffer(data voidptr, element_size int, element_count int) int {
return C.sg_append_buffer(b.index_buffer, data, element_size * element_count)
return C.sg_append_buffer(b.index_buffer, data, element_size * element_count)
}
pub struct C.sg_shader_desc {
pub mut:
_start_canary u32
attrs [16]C.sg_shader_attr_desc
vs C.sg_shader_stage_desc
fs C.sg_shader_stage_desc
label byteptr
_end_canary u32
_start_canary u32
attrs [16]C.sg_shader_attr_desc
vs C.sg_shader_stage_desc
fs C.sg_shader_stage_desc
label byteptr
_end_canary u32
}
pub fn (mut desc C.sg_shader_desc) set_vert_src(src string) &C.sg_shader_desc {
desc.vs.source = src.str
return desc
desc.vs.source = src.str
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_src(src string) &C.sg_shader_desc {
desc.fs.source = src.str
return desc
desc.fs.source = src.str
return desc
}
pub fn (mut desc C.sg_shader_desc) set_vert_image(index int, name string) &C.sg_shader_desc {
desc.vs.images[index].name = name.str
desc.vs.images[index].@type = ._2d
return desc
desc.vs.images[index].name = name.str
desc.vs.images[index].@type = ._2d
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &C.sg_shader_desc {
desc.fs.images[index].name = name.str
desc.fs.images[index].@type = ._2d
return desc
desc.fs.images[index].name = name.str
desc.fs.images[index].@type = ._2d
return desc
}
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index, size int) &C.sg_shader_desc {
desc.vs.uniform_blocks[block_index].size = size
return desc
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size int) &C.sg_shader_desc {
desc.vs.uniform_blocks[block_index].size = size
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index, size int) &C.sg_shader_desc {
desc.fs.uniform_blocks[block_index].size = size
return desc
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size int) &C.sg_shader_desc {
desc.fs.uniform_blocks[block_index].size = size
return desc
}
pub fn (mut desc C.sg_shader_desc) set_vert_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].name = name.str
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].name = name.str
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
return desc
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].name = name.str
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].name = name.str
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
return desc
return desc
}
pub fn (desc &C.sg_shader_desc) make_shader() C.sg_shader {
return C.sg_make_shader(desc)
return C.sg_make_shader(desc)
}
pub struct C.sg_shader_attr_desc {
pub mut:
name byteptr /* GLSL vertex attribute name (only required for GLES2) */
sem_name byteptr /* HLSL semantic name */
sem_index int /* HLSL semantic index */
name byteptr // GLSL vertex attribute name (only required for GLES2)
sem_name byteptr // HLSL semantic name
sem_index int // HLSL semantic index
}
pub struct C.sg_shader_stage_desc {
pub mut:
source byteptr
byte_code &byte
byte_code_size int
entry byteptr
uniform_blocks [4]C.sg_shader_uniform_block_desc
images [12]C.sg_shader_image_desc
source byteptr
byte_code &byte
byte_code_size int
entry byteptr
uniform_blocks [4]C.sg_shader_uniform_block_desc
images [12]C.sg_shader_image_desc
}
pub fn (mut desc C.sg_shader_stage_desc) set_image(index int, name string) C.sg_shader_stage_desc {
desc.images[index].name = name.str
desc.images[index].@type = ._2d
return *desc
desc.images[index].name = name.str
desc.images[index].@type = ._2d
return *desc
}
pub struct C.sg_shader_uniform_block_desc {
pub mut:
size int
uniforms [16]C.sg_shader_uniform_desc
size int
uniforms [16]C.sg_shader_uniform_desc
}
pub struct C.sg_shader_uniform_desc {
pub mut:
name byteptr
@type UniformType
array_count int
name byteptr
@type UniformType
array_count int
}
pub struct C.sg_shader_image_desc {
pub mut:
name byteptr
@type ImageType
name byteptr
@type ImageType
}
pub struct C.sg_shader_info {}
pub struct C.sg_shader_info {
}
pub struct C.sg_context {
id u32
id u32
}
pub struct C.sg_shader {
pub:
id u32
id u32
}
pub fn (s C.sg_shader) free() { C.sg_destroy_shader(s) }
pub fn (s C.sg_shader) free() {
C.sg_destroy_shader(s)
}
pub struct C.sg_pass_desc {
pub mut:
_start_canary u32
color_attachments [4]C.sg_attachment_desc
depth_stencil_attachment C.sg_attachment_desc
label byteptr
_end_canary u32
_start_canary u32
color_attachments [4]C.sg_attachment_desc
depth_stencil_attachment C.sg_attachment_desc
label byteptr
_end_canary u32
}
pub struct C.sg_pass_info {
info C.sg_slot_info
info C.sg_slot_info
}
pub struct C.sg_pass_action {
pub mut:
_start_canary u32
colors [4]C.sg_color_attachment_action
depth C.sg_depth_attachment_action
stencil C.sg_stencil_attachment_action
_end_canary u32
_start_canary u32
colors [4]C.sg_color_attachment_action
depth C.sg_depth_attachment_action
stencil C.sg_stencil_attachment_action
_end_canary u32
}
pub struct C.sg_pass {
id u32
id u32
}
pub fn (p C.sg_pass) free() { C.sg_destroy_pass(p) }
pub fn (p C.sg_pass) free() {
C.sg_destroy_pass(p)
}
pub struct C.sg_buffer_desc {
pub mut:
_start_canary u32
size int
@type BufferType
usage Usage
content byteptr
label byteptr
/* GL specific */
gl_buffers [2]u32
/* Metal specific */
mtl_buffers [2]voidptr
/* D3D11 specific */
d3d11_buffer voidptr
_end_canary u32
_start_canary u32
size int
@type BufferType
usage Usage
content byteptr
label byteptr
// GL specific
gl_buffers [2]u32
// Metal specific
mtl_buffers [2]voidptr
// D3D11 specific
d3d11_buffer voidptr
_end_canary u32
}
pub struct C.sg_buffer_info {}
pub struct C.sg_buffer_info {
}
pub struct C.sg_buffer {
id u32
id u32
}
pub fn (b C.sg_buffer) free() { C.sg_destroy_buffer(b) }
pub fn (b C.sg_buffer) free() {
C.sg_destroy_buffer(b)
}
pub union DepthLayers {
depth int
layers int
pub struct DepthLayers {
depth int
layers int
}
pub struct C.sg_image_desc {
pub mut:
_start_canary u32
@type ImageType
render_target bool
width int
height int
depth DepthLayers
// depth int
// union {
// int depth;
// int layers;
// };
num_mipmaps int
usage Usage
pixel_format PixelFormat
sample_count int
min_filter Filter
mag_filter Filter
wrap_u Wrap
wrap_v Wrap
wrap_w Wrap
border_color BorderColor
max_anisotropy u32
min_lod f32
max_lod f32
content C.sg_image_content
label byteptr
/* GL specific */
gl_textures [2]u32
/* Metal specific */
mtl_textures [2]voidptr
/* D3D11 specific */
d3d11_texture voidptr
_end_canary u32
_start_canary u32
@type ImageType
render_target bool
width int
height int
depth DepthLayers
// depth int
// union {
// int depth;
// int layers;
// };
num_mipmaps int
usage Usage
pixel_format PixelFormat
sample_count int
min_filter Filter
mag_filter Filter
wrap_u Wrap
wrap_v Wrap
wrap_w Wrap
border_color BorderColor
max_anisotropy u32
min_lod f32
max_lod f32
content C.sg_image_content
label byteptr
// GL specific
gl_textures [2]u32
// Metal specific
mtl_textures [2]voidptr
// D3D11 specific
d3d11_texture voidptr
_end_canary u32
}
pub struct C.sg_image_info {
pub mut:
slot C.sg_slot_info /* resource pool slot info */
upd_frame_index u32 /* frame index of last sg_update_image() */
num_slots int /* number of renaming-slots for dynamically updated images */
active_slot int /* currently active write-slot for dynamically updated images */
slot C.sg_slot_info // resource pool slot info
upd_frame_index u32 // frame index of last sg_update_image()
num_slots int // number of renaming-slots for dynamically updated images
active_slot int // currently active write-slot for dynamically updated images
}
pub struct C.sg_image {
pub:
id u32
id u32
}
pub fn (i C.sg_image) free() { C.sg_destroy_image(i) }
pub fn (i C.sg_image) free() {
C.sg_destroy_image(i)
}
pub struct C.sg_image_content {
pub mut:
subimage [6][16]C.sg_subimage_content
subimage [6][16]C.sg_subimage_content
}
pub struct C.sg_subimage_content {
pub mut:
ptr voidptr /* pointer to subimage data */
size int /* size in bytes of pointed-to subimage data */
ptr voidptr // pointer to subimage data
size int // size in bytes of pointed-to subimage data
}
pub struct C.sg_features {
pub:
instancing bool /* hardware instancing supported */
origin_top_left bool /* framebuffer and texture origin is in top left corner */
multiple_render_targets bool /* offscreen render passes can have multiple render targets attached */
msaa_render_targets bool /* offscreen render passes support MSAA antialiasing */
imagetype_3d bool /* creation of SG_IMAGETYPE_3D images is supported */
imagetype_array bool /* creation of SG_IMAGETYPE_ARRAY images is supported */
image_clamp_to_border bool /* border color and clamp-to-border UV-wrap mode is supported */
instancing bool // hardware instancing supported
origin_top_left bool // framebuffer and texture origin is in top left corner
multiple_render_targets bool // offscreen render passes can have multiple render targets attached
msaa_render_targets bool // offscreen render passes support MSAA antialiasing
imagetype_3d bool // creation of SG_IMAGETYPE_3D images is supported
imagetype_array bool // creation of SG_IMAGETYPE_ARRAY images is supported
image_clamp_to_border bool // border color and clamp-to-border UV-wrap mode is supported
}
pub struct C.sg_limits {
pub:
max_image_size_2d u32 /* max width/height of SG_IMAGETYPE_2D images */
max_image_size_cube u32 /* max width/height of SG_IMAGETYPE_CUBE images */
max_image_size_3d u32 /* max width/height/depth of SG_IMAGETYPE_3D images */
max_image_size_array u32 /* max width/height pf SG_IMAGETYPE_ARRAY images */
max_image_array_layers u32 /* max number of layers in SG_IMAGETYPE_ARRAY images */
max_vertex_attrs u32 /* <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls) */
max_image_size_2d u32 // max width/height of SG_IMAGETYPE_2D images
max_image_size_cube u32 // max width/height of SG_IMAGETYPE_CUBE images
max_image_size_3d u32 // max width/height/depth of SG_IMAGETYPE_3D images
max_image_size_array u32 // max width/height pf SG_IMAGETYPE_ARRAY images
max_image_array_layers u32 // max number of layers in SG_IMAGETYPE_ARRAY images
max_vertex_attrs u32 // <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls)
}
pub struct C.sg_layout_desc {
pub mut:
buffers [8]C.sg_buffer_layout_desc
attrs [16]C.sg_vertex_attr_desc
buffers [8]C.sg_buffer_layout_desc
attrs [16]C.sg_vertex_attr_desc
}
pub struct C.sg_buffer_layout_desc {
pub mut:
stride int
step_func VertexStep
step_rate int
stride int
step_func VertexStep
step_rate int
}
pub struct C.sg_vertex_attr_desc {
pub mut:
buffer_index int
offset int
format VertexFormat
buffer_index int
offset int
format VertexFormat
}
pub struct C.sg_depth_stencil_state {
stencil_front sg_stencil_state
stencil_back sg_stencil_state
depth_compare_func CompareFunc
depth_write_enabled bool
stencil_enabled bool
stencil_read_mask byte
stencil_write_mask byte
stencil_ref byte
stencil_front sg_stencil_state
stencil_back sg_stencil_state
depth_compare_func CompareFunc
depth_write_enabled bool
stencil_enabled bool
stencil_read_mask byte
stencil_write_mask byte
stencil_ref byte
}
pub struct C.sg_stencil_state {
fail_op StencilOp
depth_fail_op StencilOp
pass_op StencilOp
compare_func CompareFunc
fail_op StencilOp
depth_fail_op StencilOp
pass_op StencilOp
compare_func CompareFunc
}
pub struct C.sg_blend_state {
pub mut:
enabled bool
src_factor_rgb BlendFactor
dst_factor_rgb BlendFactor
op_rgb BlendOp
src_factor_alpha BlendFactor
dst_factor_alpha BlendFactor
op_alpha BlendOp
color_write_mask byte
color_attachment_count int
color_format PixelFormat
depth_format PixelFormat
blend_color [4]f32
enabled bool
src_factor_rgb BlendFactor
dst_factor_rgb BlendFactor
op_rgb BlendOp
src_factor_alpha BlendFactor
dst_factor_alpha BlendFactor
op_alpha BlendOp
color_write_mask byte
color_attachment_count int
color_format PixelFormat
depth_format PixelFormat
blend_color [4]f32
}
pub struct C.sg_rasterizer_state {
pub mut:
alpha_to_coverage_enabled bool
cull_mode CullMode
face_winding FaceWinding
sample_count int
depth_bias f32
depth_bias_slope_scale f32
depth_bias_clamp f32
alpha_to_coverage_enabled bool
cull_mode CullMode
face_winding FaceWinding
sample_count int
depth_bias f32
depth_bias_slope_scale f32
depth_bias_clamp f32
}
pub struct C.sg_color_attachment_action {
pub mut:
action Action
val [4]f32
action Action
val [4]f32
}
/*
@@ -462,40 +465,38 @@ pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32
action.val[3] = a
}
*/
pub struct C.sg_depth_attachment_action {
pub mut:
action Action
val f32
action Action
val f32
}
pub struct C.sg_stencil_attachment_action {
pub mut:
action Action
val byte
action Action
val byte
}
pub struct C.sg_pixelformat_info {
pub:
sample bool /* pixel format can be sampled in shaders */
filter bool /* pixel format can be sampled with filtering */
render bool /* pixel format can be used as render target */
blend bool /* alpha-blending is supported */
msaa bool /* pixel format can be used as MSAA render target */
depth bool /* pixel format is a depth format */
sample bool // pixel format can be sampled in shaders
filter bool // pixel format can be sampled with filtering
render bool // pixel format can be used as render target
blend bool // alpha-blending is supported
msaa bool // pixel format can be used as MSAA render target
depth bool // pixel format is a depth format
}
pub struct C.sg_attachment_desc {
pub mut:
image C.sg_image
mip_level int
face int
// image sg_image
// mip_level int
// union {
// face int
// layer int
// slice int
// }
image C.sg_image
mip_level int
face int
// image sg_image
// mip_level int
// union {
// face int
// layer int
// slice int
// }
}

View File

@@ -1,15 +1,14 @@
module gfx
pub fn create_clear_pass(r, g, b, a f32) C.sg_pass_action {
mut color_action := C.sg_color_attachment_action {
pub fn create_clear_pass(r f32, g f32, b f32, a f32) C.sg_pass_action {
mut color_action := C.sg_color_attachment_action{
action: C.SG_ACTION_CLEAR
}
//color_action.set_color_values(r, g, b, a)
color_action.val[0] = r
color_action.val[1] = g
color_action.val[2] = b
color_action.val[3] = a
// color_action.set_color_values(r, g, b, a)
color_action.val[0] = r
color_action.val[1] = g
color_action.val[2] = b
color_action.val[3] = a
mut pass_action := C.sg_pass_action{}
pass_action.colors[0] = color_action
return pass_action