mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
sokol and fontstash modules
This commit is contained in:
parent
cc606623bb
commit
62481e88f3
84
examples/sokol/drawing.v
Normal file
84
examples/sokol/drawing.v
Normal file
@ -0,0 +1,84 @@
|
||||
import sokol
|
||||
import sokol.sapp
|
||||
import sokol.gfx
|
||||
import sokol.sgl
|
||||
import fontstash
|
||||
|
||||
struct AppState {
|
||||
pass_action sg_pass_action
|
||||
}
|
||||
|
||||
fn main() {
|
||||
state := &AppState{
|
||||
pass_action: gfx.create_clear_pass(0.1, 0.1, 0.1, 1.0)
|
||||
}
|
||||
|
||||
desc := sapp_desc{
|
||||
user_data: state
|
||||
init_userdata_cb: init
|
||||
frame_userdata_cb: frame
|
||||
window_title: 'Sokal Drawing Template'.str
|
||||
}
|
||||
sapp.run(&desc)
|
||||
}
|
||||
|
||||
fn init(user_data voidptr) {
|
||||
desc := sg_desc {
|
||||
mtl_device: C.sapp_metal_get_device()
|
||||
mtl_renderpass_descriptor_cb: sapp_metal_get_renderpass_descriptor
|
||||
mtl_drawable_cb: sapp_metal_get_drawable
|
||||
d3d11_device: sapp_d3d11_get_device()
|
||||
d3d11_device_context: sapp_d3d11_get_device_context()
|
||||
d3d11_render_target_view_cb: sapp_d3d11_get_render_target_view
|
||||
d3d11_depth_stencil_view_cb: sapp_d3d11_get_depth_stencil_view
|
||||
}
|
||||
gfx.setup(&desc)
|
||||
|
||||
sgl_desc := sgl_desc_t{}
|
||||
sgl.setup(&sgl_desc)
|
||||
}
|
||||
|
||||
fn frame(user_data voidptr) {
|
||||
//println('frame')
|
||||
state := &AppState(user_data)
|
||||
|
||||
draw()
|
||||
|
||||
gfx.begin_default_pass(&state.pass_action, sapp.width(), sapp.height())
|
||||
sgl.draw()
|
||||
gfx.end_pass()
|
||||
gfx.commit()
|
||||
}
|
||||
|
||||
fn draw() {
|
||||
// first, reset and setup ortho projection
|
||||
sgl.defaults()
|
||||
sgl.matrix_mode_projection()
|
||||
sgl.ortho(0.0, f32(sapp.width()), f32(sapp.height()), 0.0, -1.0, 1.0)
|
||||
|
||||
sgl.c4b(255, 0, 0, 128)
|
||||
draw_hollow_rect(10, 10, 100, 30)
|
||||
|
||||
sgl.c4b(25, 150, 0, 128)
|
||||
draw_filled_rect(10, 150, 80, 40)
|
||||
//line(0, 0, 500, 500)
|
||||
}
|
||||
|
||||
fn draw_hollow_rect(x, y, w, h f32) {
|
||||
sgl.begin_line_strip()
|
||||
sgl.v2f(x, y)
|
||||
sgl.v2f(x + w, y)
|
||||
sgl.v2f(x + w, y + h)
|
||||
sgl.v2f(x, y + h)
|
||||
sgl.v2f(x, y)
|
||||
sgl.end()
|
||||
}
|
||||
|
||||
fn draw_filled_rect(x, y, w, h f32) {
|
||||
sgl.begin_quads()
|
||||
sgl_v2f(x, y)
|
||||
sgl_v2f(x + w, y)
|
||||
sgl_v2f(x + w, y + h)
|
||||
sgl_v2f(x, y + h)
|
||||
sgl.end()
|
||||
}
|
190
examples/sokol/fonts.v
Normal file
190
examples/sokol/fonts.v
Normal file
@ -0,0 +1,190 @@
|
||||
import sokol
|
||||
import sokol.sapp
|
||||
import sokol.gfx
|
||||
import sokol.sgl
|
||||
import sokol.sfons
|
||||
import fontstash
|
||||
import os
|
||||
import time
|
||||
|
||||
struct AppState {
|
||||
mut:
|
||||
pass_action C.sg_pass_action
|
||||
fons &C.FONScontext
|
||||
font_normal int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut color_action := sg_color_attachment_action {
|
||||
action: C.SG_ACTION_CLEAR
|
||||
}
|
||||
color_action.val[0] = 0.3
|
||||
color_action.val[1] = 0.3
|
||||
color_action.val[2] = 0.32
|
||||
color_action.val[3] = 1.0
|
||||
|
||||
mut pass_action := sg_pass_action{}
|
||||
pass_action.colors[0] = color_action
|
||||
|
||||
state := &AppState{
|
||||
pass_action: pass_action
|
||||
fons: &C.FONScontext(0)
|
||||
}
|
||||
|
||||
desc := sapp_desc{
|
||||
user_data: state
|
||||
init_userdata_cb: init
|
||||
frame_userdata_cb: frame
|
||||
window_title: 'V Metal/GL Text Rendering'.str
|
||||
}
|
||||
sapp.run(&desc)
|
||||
}
|
||||
|
||||
fn init(user_data voidptr) {
|
||||
mut state := &AppState(user_data)
|
||||
|
||||
// dont actually alocate this on the heap in real life
|
||||
gfx.setup(&sg_desc {
|
||||
mtl_device: C.sapp_metal_get_device()
|
||||
mtl_renderpass_descriptor_cb: sapp_metal_get_renderpass_descriptor
|
||||
mtl_drawable_cb: sapp_metal_get_drawable
|
||||
d3d11_device: sapp_d3d11_get_device()
|
||||
d3d11_device_context: sapp_d3d11_get_device_context()
|
||||
d3d11_render_target_view_cb: sapp_d3d11_get_render_target_view
|
||||
d3d11_depth_stencil_view_cb: sapp_d3d11_get_depth_stencil_view
|
||||
})
|
||||
|
||||
s := &C.sgl_desc_t{}
|
||||
C.sgl_setup(s)
|
||||
|
||||
state.fons = C.sfons_create(512, 512, 1)
|
||||
|
||||
// or use DroidSerif-Regular.ttf
|
||||
if bytes := os.read_bytes('assets/ProggyTiny.ttf') {
|
||||
println('loaded font: $bytes.len')
|
||||
state.font_normal = C.fonsAddFontMem(state.fons, "sans", bytes.data, bytes.len, false)
|
||||
}
|
||||
}
|
||||
|
||||
fn frame(user_data voidptr) {
|
||||
t:=time.ticks()
|
||||
mut state := &AppState(user_data)
|
||||
|
||||
state.render_font()
|
||||
|
||||
gfx.begin_default_pass(&state.pass_action, sapp_width(), sapp_height())
|
||||
sgl.draw()
|
||||
gfx.end_pass()
|
||||
gfx.commit()
|
||||
//println(time.ticks()-t)
|
||||
}
|
||||
|
||||
fn (state &AppState) render_font() {
|
||||
mut sx := 0.0
|
||||
mut sy := 0.0
|
||||
mut dx := 0.0
|
||||
mut dy := 0.0
|
||||
lh := 0.0
|
||||
white := C.sfons_rgba(255, 255, 255, 255)
|
||||
black := C.sfons_rgba(0, 0, 0, 255)
|
||||
brown := C.sfons_rgba(192, 128, 0, 128)
|
||||
blue := C.sfons_rgba(0, 192, 255, 255)
|
||||
state.fons.clear_state()
|
||||
|
||||
sgl.defaults()
|
||||
sgl.matrix_mode_projection()
|
||||
sgl.ortho(0.0, f32(C.sapp_width()), f32(C.sapp_height()), 0.0, -1.0, 1.0)
|
||||
|
||||
sx = 0
|
||||
sy = 50
|
||||
dx = sx
|
||||
dy = sy
|
||||
|
||||
state.fons.set_font(state.font_normal)
|
||||
state.fons.set_size(100.0)
|
||||
ascender := 0.0
|
||||
descender := 0.0
|
||||
state.fons.vert_metrics(&ascender, &descender, &lh)
|
||||
dx = sx
|
||||
dy += lh
|
||||
C.fonsSetColor(state.fons, white)
|
||||
dx = C.fonsDrawText(state.fons, dx, dy, c'The quick ', C.NULL)
|
||||
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetSize(state.fons, 48.0)
|
||||
fonsSetColor(state.fons, brown)
|
||||
dx = fonsDrawText(state.fons, dx, dy, c"brown ", C.NULL)
|
||||
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetSize(state.fons, 24.0)
|
||||
fonsSetColor(state.fons, white)
|
||||
dx = fonsDrawText(state.fons, dx, dy, c"fox ", C.NULL)
|
||||
|
||||
dx = sx
|
||||
dy += lh * 1.2
|
||||
fonsSetSize(state.fons, 20.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, blue)
|
||||
fonsDrawText(state.fons, dx, dy, c"Now is the time for all good men to come to the aid of the party.", C.NULL)
|
||||
|
||||
dx = 300
|
||||
dy = 350
|
||||
fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE)
|
||||
fonsSetSize(state.fons, 60.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, white)
|
||||
fonsSetSpacing(state.fons, 5.0)
|
||||
fonsSetBlur(state.fons, 6.0)
|
||||
fonsDrawText(state.fons, dx, dy, c"Blurry...", C.NULL)
|
||||
|
||||
dx = 300
|
||||
dy += 50.0
|
||||
fonsSetSize(state.fons, 28.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, white)
|
||||
fonsSetSpacing(state.fons, 0.0)
|
||||
fonsSetBlur(state.fons, 3.0)
|
||||
fonsDrawText(state.fons, dx,dy + 2, c"DROP SHADOW", C.NULL)
|
||||
fonsSetColor(state.fons, black)
|
||||
fonsSetBlur(state.fons, 0)
|
||||
fonsDrawText(state.fons, dx,dy, c"DROP SHADOW", C.NULL)
|
||||
|
||||
fonsSetSize(state.fons, 18.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, white)
|
||||
dx = 50
|
||||
dy = 350
|
||||
line(dx-10,dy,dx+250,dy)
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_TOP)
|
||||
dx = C.fonsDrawText(state.fons, dx,dy, c"Top",C.NULL)
|
||||
dx += 10
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_MIDDLE)
|
||||
dx = C.fonsDrawText(state.fons, dx,dy, c"Middle",C.NULL)
|
||||
dx += 10
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE)
|
||||
dx = C.fonsDrawText(state.fons, dx,dy, c"Baseline",C.NULL)
|
||||
dx += 10
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BOTTOM)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Bottom",C.NULL)
|
||||
dx = 150
|
||||
dy = 400
|
||||
line(dx,dy-30,dx,dy+80.0)
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Left",C.NULL)
|
||||
dy += 30
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_CENTER | C.FONS_ALIGN_BASELINE)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Center",C.NULL)
|
||||
dy += 30
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_RIGHT | C.FONS_ALIGN_BASELINE)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Right",C.NULL)
|
||||
|
||||
C.sfons_flush(state.fons)
|
||||
}
|
||||
|
||||
fn line(sx f32, sy f32, ex f32, ey f32) {
|
||||
sgl.begin_lines()
|
||||
sgl.c4b(255, 255, 0, 128)
|
||||
sgl.v2f(sx, sy)
|
||||
sgl.v2f(ex, ey)
|
||||
sgl.end()
|
||||
}
|
207
examples/sokol/fonts2.v
Normal file
207
examples/sokol/fonts2.v
Normal file
@ -0,0 +1,207 @@
|
||||
import sokol
|
||||
import sokol.sapp
|
||||
import sokol.gfx
|
||||
import sokol.sgl
|
||||
import sokol.sfons
|
||||
import fontstash
|
||||
import os
|
||||
import time
|
||||
import filepath
|
||||
|
||||
#define FONS_USE_FREETYPE 1
|
||||
|
||||
struct AppState {
|
||||
mut:
|
||||
pass_action C.sg_pass_action
|
||||
fons &C.FONScontext
|
||||
font_normal int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut color_action := sg_color_attachment_action {
|
||||
action: C.SG_ACTION_CLEAR
|
||||
}
|
||||
color_action.val[0] = 0.3
|
||||
color_action.val[1] = 0.3
|
||||
color_action.val[2] = 0.32
|
||||
color_action.val[3] = 1.0
|
||||
|
||||
mut pass_action := sg_pass_action{}
|
||||
pass_action.colors[0] = color_action
|
||||
|
||||
state := &AppState{
|
||||
pass_action: pass_action
|
||||
fons: &C.FONScontext(0)
|
||||
}
|
||||
|
||||
desc := sapp_desc{
|
||||
user_data: state
|
||||
init_userdata_cb: init
|
||||
frame_userdata_cb: frame
|
||||
window_title: 'V Metal/GL Text Rendering'.str
|
||||
}
|
||||
sapp.run(&desc)
|
||||
}
|
||||
|
||||
fn init(user_data voidptr) {
|
||||
mut state := &AppState(user_data)
|
||||
|
||||
// dont actually alocate this on the heap in real life
|
||||
gfx.setup(&sg_desc {
|
||||
mtl_device: C.sapp_metal_get_device()
|
||||
mtl_renderpass_descriptor_cb: sapp_metal_get_renderpass_descriptor
|
||||
mtl_drawable_cb: sapp_metal_get_drawable
|
||||
d3d11_device: sapp_d3d11_get_device()
|
||||
d3d11_device_context: sapp_d3d11_get_device_context()
|
||||
d3d11_render_target_view_cb: sapp_d3d11_get_render_target_view
|
||||
d3d11_depth_stencil_view_cb: sapp_d3d11_get_depth_stencil_view
|
||||
})
|
||||
|
||||
s := &C.sgl_desc_t{}
|
||||
C.sgl_setup(s)
|
||||
|
||||
state.fons = C.sfons_create(512, 512, 1)
|
||||
|
||||
//mut font_path := cfg.font_path
|
||||
//if font_path == '' {
|
||||
mut font_path := 'RobotoMono-Regular.ttf'
|
||||
//}
|
||||
if !os.exists(font_path) {
|
||||
exe_path := os.executable()
|
||||
exe_dir := filepath.basedir(exe_path)
|
||||
font_path = filepath.basedir(exe_dir) + '/tetris/$font_path'
|
||||
println(font_path)
|
||||
}
|
||||
if !os.exists(font_path) {
|
||||
println('failed to load $font_path')
|
||||
return
|
||||
}
|
||||
|
||||
if bytes := os.read_bytes(font_path) {
|
||||
println('loaded font: $bytes.len')
|
||||
state.font_normal = C.fonsAddFontMem(state.fons, "sans", bytes.data, bytes.len, false)
|
||||
}
|
||||
}
|
||||
|
||||
fn frame(user_data voidptr) {
|
||||
t:=time.ticks()
|
||||
mut state := &AppState(user_data)
|
||||
|
||||
state.render_font()
|
||||
|
||||
gfx.begin_default_pass(&state.pass_action, sapp_width(), sapp_height())
|
||||
sgl.draw()
|
||||
gfx.end_pass()
|
||||
gfx.commit()
|
||||
//println(time.ticks()-t)
|
||||
}
|
||||
|
||||
fn (state &AppState) render_font() {
|
||||
mut sx := 0.0
|
||||
mut sy := 0.0
|
||||
mut dx := 0.0
|
||||
mut dy := 0.0
|
||||
lh := 0.0
|
||||
white := C.sfons_rgba(255, 255, 255, 255)
|
||||
black := C.sfons_rgba(0, 0, 0, 255)
|
||||
brown := C.sfons_rgba(192, 128, 0, 128)
|
||||
blue := C.sfons_rgba(0, 192, 255, 255)
|
||||
state.fons.clear_state()
|
||||
|
||||
sgl.defaults()
|
||||
sgl.matrix_mode_projection()
|
||||
sgl.ortho(0.0, f32(C.sapp_width()), f32(C.sapp_height()), 0.0, -1.0, 1.0)
|
||||
|
||||
sx = 0
|
||||
sy = 50
|
||||
dx = sx
|
||||
dy = sy
|
||||
|
||||
state.fons.set_font(state.font_normal)
|
||||
state.fons.set_size(100.0)
|
||||
ascender := 0.0
|
||||
descender := 0.0
|
||||
state.fons.vert_metrics(&ascender, &descender, &lh)
|
||||
dx = sx
|
||||
dy += lh
|
||||
C.fonsSetColor(state.fons, white)
|
||||
dx = C.fonsDrawText(state.fons, dx, dy, c'The 新 quick ', C.NULL)
|
||||
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetSize(state.fons, 48.0)
|
||||
fonsSetColor(state.fons, brown)
|
||||
dx = fonsDrawText(state.fons, dx, dy, c"brown ", C.NULL)
|
||||
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetSize(state.fons, 24.0)
|
||||
fonsSetColor(state.fons, white)
|
||||
dx = fonsDrawText(state.fons, dx, dy, c"fox ", C.NULL)
|
||||
|
||||
dx = sx
|
||||
dy += lh * 1.2
|
||||
fonsSetSize(state.fons, 20.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, blue)
|
||||
fonsDrawText(state.fons, dx, dy, c"Now is the time for all good men to come to the aid of the party.", C.NULL)
|
||||
|
||||
dx = 300
|
||||
dy = 350
|
||||
fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE)
|
||||
fonsSetSize(state.fons, 60.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, white)
|
||||
fonsSetSpacing(state.fons, 5.0)
|
||||
fonsSetBlur(state.fons, 6.0)
|
||||
fonsDrawText(state.fons, dx, dy, c"Blurry...", C.NULL)
|
||||
|
||||
dx = 300
|
||||
dy += 50.0
|
||||
fonsSetSize(state.fons, 28.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, white)
|
||||
fonsSetSpacing(state.fons, 0.0)
|
||||
fonsSetBlur(state.fons, 3.0)
|
||||
fonsDrawText(state.fons, dx,dy + 2, c"DROP SHADOW", C.NULL)
|
||||
fonsSetColor(state.fons, black)
|
||||
fonsSetBlur(state.fons, 0)
|
||||
fonsDrawText(state.fons, dx,dy, c"DROP SHADOW", C.NULL)
|
||||
|
||||
fonsSetSize(state.fons, 18.0)
|
||||
fonsSetFont(state.fons, state.font_normal)
|
||||
fonsSetColor(state.fons, white)
|
||||
dx = 50
|
||||
dy = 350
|
||||
line(dx-10,dy,dx+250,dy)
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_TOP)
|
||||
dx = C.fonsDrawText(state.fons, dx,dy, c"Top",C.NULL)
|
||||
dx += 10
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_MIDDLE)
|
||||
dx = C.fonsDrawText(state.fons, dx,dy, c"Middle",C.NULL)
|
||||
dx += 10
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE)
|
||||
dx = C.fonsDrawText(state.fons, dx,dy, c"Baseline",C.NULL)
|
||||
dx += 10
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BOTTOM)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Bottom",C.NULL)
|
||||
dx = 150
|
||||
dy = 400
|
||||
line(dx,dy-30,dx,dy+80.0)
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_BASELINE)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Left",C.NULL)
|
||||
dy += 30
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_CENTER | C.FONS_ALIGN_BASELINE)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Center",C.NULL)
|
||||
dy += 30
|
||||
C.fonsSetAlign(state.fons, C.FONS_ALIGN_RIGHT | C.FONS_ALIGN_BASELINE)
|
||||
C.fonsDrawText(state.fons, dx,dy, c"Right",C.NULL)
|
||||
|
||||
C.sfons_flush(state.fons)
|
||||
}
|
||||
|
||||
fn line(sx f32, sy f32, ex f32, ey f32) {
|
||||
sgl.begin_lines()
|
||||
sgl.c4b(255, 255, 0, 128)
|
||||
sgl.v2f(sx, sy)
|
||||
sgl.v2f(ex, ey)
|
||||
sgl.end()
|
||||
}
|
1715
thirdparty/fontstash/fontstash.h
vendored
Normal file
1715
thirdparty/fontstash/fontstash.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4882
thirdparty/fontstash/stb_truetype.h
vendored
Normal file
4882
thirdparty/fontstash/stb_truetype.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7566
thirdparty/sokol/sokol_app.h
vendored
Executable file
7566
thirdparty/sokol/sokol_app.h
vendored
Executable file
File diff suppressed because it is too large
Load Diff
11703
thirdparty/sokol/sokol_gfx.h
vendored
Executable file
11703
thirdparty/sokol/sokol_gfx.h
vendored
Executable file
File diff suppressed because it is too large
Load Diff
789
thirdparty/sokol/util/sokol_fontstash.h
vendored
Executable file
789
thirdparty/sokol/util/sokol_fontstash.h
vendored
Executable file
@ -0,0 +1,789 @@
|
||||
#ifndef SOKOL_FONTSTASH_INCLUDED
|
||||
/*
|
||||
sokol_fontstash.h -- renderer for https://github.com/memononen/fontstash
|
||||
on top of sokol_gl.h
|
||||
|
||||
Project URL: https://github.com/floooh/sokol
|
||||
|
||||
Do this:
|
||||
|
||||
#define SOKOL_FONTSTASH_IMPL
|
||||
|
||||
before you include this file in *one* C or C++ file to create the
|
||||
implementation.
|
||||
|
||||
The following defines are used by the implementation to select the
|
||||
platform-specific embedded shader code (these are the same defines as
|
||||
used by sokol_gfx.h and sokol_app.h):
|
||||
|
||||
SOKOL_GLCORE33
|
||||
SOKOL_GLES2
|
||||
SOKOL_GLES3
|
||||
SOKOL_D3D11
|
||||
SOKOL_METAL
|
||||
|
||||
...optionally provide the following macros to override defaults:
|
||||
|
||||
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
|
||||
SOKOL_MALLOC(s) - your own malloc function (default: malloc(s))
|
||||
SOKOL_FREE(p) - your own free function (default: free(p))
|
||||
SOKOL_API_DECL - public function declaration prefix (default: extern)
|
||||
SOKOL_API_IMPL - public function implementation prefix (default: -)
|
||||
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
|
||||
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
|
||||
|
||||
Include the following headers before including sokol_fontstash.h:
|
||||
|
||||
sokol_gfx.h
|
||||
|
||||
Additionally include the following headers for including the sokol_fontstash.h
|
||||
implementation:
|
||||
|
||||
sokol_gl.h
|
||||
|
||||
HOW TO
|
||||
======
|
||||
--- First initialize sokol-gfx and sokol-gl as usual:
|
||||
|
||||
sg_setup(&(sg_desc){...});
|
||||
sgl_setup(&(sgl_desc){...});
|
||||
|
||||
--- Create at least one fontstash context with sfons_create() (this replaces
|
||||
glfonsCreate() from fontstash.h's example GL renderer:
|
||||
|
||||
FONScontext* ctx = sfons_create(atlas_width, atlas_height, FONS_ZERO_TOPLEFT);
|
||||
|
||||
Each FONScontext manages one font atlas texture which can hold rasterized
|
||||
glyphs for multiple fonts.
|
||||
|
||||
--- From here on, use fontstash.h's functions "as usual" to add TTF
|
||||
font data and draw text. Note that (just like with sokol-gl), text
|
||||
rendering can happen anywhere in the frame, not only inside
|
||||
a sokol-gfx rendering pass.
|
||||
|
||||
--- You can use the helper function
|
||||
|
||||
uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||
|
||||
To convert a 0..255 RGBA color into a packed uint32_t color value
|
||||
expected by fontstash.h.
|
||||
|
||||
--- Once per frame before calling sgl_draw(), call:
|
||||
|
||||
sfons_flush(FONScontext* ctx)
|
||||
|
||||
...this will update the dynamic sokol-gfx texture with the latest font
|
||||
atlas content.
|
||||
|
||||
--- To actually render the text (and any other sokol-gl draw commands),
|
||||
call sgl_draw() inside a sokol-gfx frame.
|
||||
|
||||
--- NOTE that you can mix fontstash.h calls with sokol-gl calls to mix
|
||||
text rendering with sokol-gl rendering. You can also use
|
||||
sokol-gl's matrix stack to position fontstash.h text in 3D.
|
||||
|
||||
--- finally on application shutdown, call:
|
||||
|
||||
sfons_shutdown()
|
||||
|
||||
before sgl_shutdown() and sg_shutdown()
|
||||
|
||||
|
||||
WHAT HAPPENS UNDER THE HOOD:
|
||||
============================
|
||||
|
||||
sfons_create():
|
||||
- creates a sokol-gfx shader compatible with sokol-gl
|
||||
- creates an sgl_pipeline object with alpha-blending using
|
||||
this shader
|
||||
- creates a 1-byte-per-pixel font atlas texture via sokol-gfx
|
||||
(pixel format SG_PIXELFORMAT_R8)
|
||||
|
||||
fonsDrawText():
|
||||
- this will call the following sequence of sokol-gl functions:
|
||||
|
||||
sgl_enable_texture();
|
||||
sgl_texture(...);
|
||||
sgl_push_pipeline();
|
||||
sgl_load_pipeline(...);
|
||||
sgl_begin_triangles();
|
||||
for each vertex:
|
||||
sg_v2f_t2f_c1i(...);
|
||||
sgl_end();
|
||||
sgl_pop_pipeline();
|
||||
sgl_disable_texture();
|
||||
|
||||
- note that sokol-gl will merge several sgl_*_begin/sgl_end pairs
|
||||
into a single draw call if no relevant state has changed, typically
|
||||
all calls to fonsDrawText() will be merged into a single draw call
|
||||
as long as all calls use the same FONScontext
|
||||
|
||||
sfons_flush():
|
||||
- this will call sg_update_image() on the font atlas texture
|
||||
if fontstash.h has added any rasterized glyphs since the last
|
||||
frame
|
||||
|
||||
sfons_shutdown():
|
||||
- destroy the font atlas texture, sgl_pipeline and sg_shader objects
|
||||
|
||||
LICENSE
|
||||
=======
|
||||
zlib/libpng license
|
||||
|
||||
Copyright (c) 2018 Andre Weissflog
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the
|
||||
use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software in a
|
||||
product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
#define SOKOL_FONTSTASH_INCLUDED (1)
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(SOKOL_GFX_INCLUDED)
|
||||
#error "Please include sokol_gfx.h before sokol_fontstash.h"
|
||||
#endif
|
||||
|
||||
#ifndef SOKOL_API_DECL
|
||||
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
|
||||
#define SOKOL_API_DECL __declspec(dllexport)
|
||||
#elif defined(_WIN32) && defined(SOKOL_DLL)
|
||||
#define SOKOL_API_DECL __declspec(dllimport)
|
||||
#else
|
||||
#define SOKOL_API_DECL extern
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SOKOL_API_DECL FONScontext* sfons_create(int width, int height, int flags);
|
||||
SOKOL_API_DECL void sfons_destroy(FONScontext* ctx);
|
||||
SOKOL_API_DECL void sfons_flush(FONScontext* ctx);
|
||||
SOKOL_API_DECL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* SOKOL_FONTSTASH_INCLUDED */
|
||||
|
||||
/*-- IMPLEMENTATION ----------------------------------------------------------*/
|
||||
#ifdef SOKOL_FONTSTASH_IMPL
|
||||
#define SOKOL_FONTSTASH_IMPL_INCLUDED (1)
|
||||
#include <string.h> /* memset, memcpy */
|
||||
|
||||
#if !defined(SOKOL_GL_INCLUDED)
|
||||
#error "Please include sokol_gl.h before sokol_fontstash.h"
|
||||
#endif
|
||||
#if !defined(FONS_H)
|
||||
#error "Please include fontstash.h before sokol_fontstash.h"
|
||||
#endif
|
||||
|
||||
#ifndef SOKOL_API_IMPL
|
||||
#define SOKOL_API_IMPL
|
||||
#endif
|
||||
#ifndef SOKOL_DEBUG
|
||||
#ifndef NDEBUG
|
||||
#define SOKOL_DEBUG (1)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SOKOL_ASSERT
|
||||
#include <assert.h>
|
||||
#define SOKOL_ASSERT(c) assert(c)
|
||||
#endif
|
||||
#ifndef SOKOL_MALLOC
|
||||
#include <stdlib.h>
|
||||
#define SOKOL_MALLOC(s) malloc(s)
|
||||
#define SOKOL_FREE(p) free(p)
|
||||
#endif
|
||||
#ifndef SOKOL_LOG
|
||||
#ifdef SOKOL_DEBUG
|
||||
#include <stdio.h>
|
||||
#define SOKOL_LOG(s) { SOKOL_ASSERT(s); puts(s); }
|
||||
#else
|
||||
#define SOKOL_LOG(s)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SOKOL_UNREACHABLE
|
||||
#define SOKOL_UNREACHABLE SOKOL_ASSERT(false)
|
||||
#endif
|
||||
|
||||
#if defined(SOKOL_GLCORE33)
|
||||
static const char* _sfons_vs_src =
|
||||
"#version 330\n"
|
||||
"uniform mat4 mvp;\n"
|
||||
"uniform mat4 tm;\n"
|
||||
"in vec4 position;\n"
|
||||
"in vec2 texcoord0;\n"
|
||||
"in vec4 color0;\n"
|
||||
"out vec4 uv;\n"
|
||||
"out vec4 color;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = mvp * position;\n"
|
||||
" uv = tm * vec4(texcoord0, 0.0, 1.0);\n"
|
||||
" color = color0;\n"
|
||||
"}\n";
|
||||
static const char* _sfons_fs_src =
|
||||
"#version 330\n"
|
||||
"uniform sampler2D tex;\n"
|
||||
"in vec4 uv;\n"
|
||||
"in vec4 color;\n"
|
||||
"out vec4 frag_color;\n"
|
||||
"void main() {\n"
|
||||
" frag_color = vec4(1.0, 1.0, 1.0, texture(tex, uv.xy).r) * color;\n"
|
||||
"}\n";
|
||||
#elif defined(SOKOL_GLES2) || defined(SOKOL_GLES3)
|
||||
static const char* _sfons_vs_src =
|
||||
"uniform mat4 mvp;\n"
|
||||
"uniform mat4 tm;\n"
|
||||
"attribute vec4 position;\n"
|
||||
"attribute vec2 texcoord0;\n"
|
||||
"attribute vec4 color0;\n"
|
||||
"varying vec4 uv;\n"
|
||||
"varying vec4 color;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = mvp * position;\n"
|
||||
" uv = tm * vec4(texcoord0, 0.0, 1.0);\n"
|
||||
" color = color0;\n"
|
||||
"}\n";
|
||||
static const char* _sfons_fs_src =
|
||||
"precision mediump float;\n"
|
||||
"uniform sampler2D tex;\n"
|
||||
"varying vec4 uv;\n"
|
||||
"varying vec4 color;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = vec4(1.0, 1.0, 1.0, texture2D(tex, uv.xy).r) * color;\n"
|
||||
"}\n";
|
||||
#elif defined(SOKOL_METAL)
|
||||
static const char* _sfons_vs_src =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct params_t {\n"
|
||||
" float4x4 mvp;\n"
|
||||
" float4x4 tm;\n"
|
||||
"};\n"
|
||||
"struct vs_in {\n"
|
||||
" float4 pos [[attribute(0)]];\n"
|
||||
" float2 uv [[attribute(1)]];\n"
|
||||
" float4 color [[attribute(2)]];\n"
|
||||
"};\n"
|
||||
"struct vs_out {\n"
|
||||
" float4 pos [[position]];\n"
|
||||
" float4 uv;\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"vertex vs_out _main(vs_in in [[stage_in]], constant params_t& params [[buffer(0)]]) {\n"
|
||||
" vs_out out;\n"
|
||||
" out.pos = params.mvp * in.pos;\n"
|
||||
" out.uv = params.tm * float4(in.uv, 0.0, 1.0);\n"
|
||||
" out.color = in.color;\n"
|
||||
" return out;\n"
|
||||
"}\n";
|
||||
static const char* _sfons_fs_src =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct fs_in {\n"
|
||||
" float4 uv;\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"fragment float4 _main(fs_in in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n"
|
||||
" return float4(1.0, 1.0, 1.0, tex.sample(smp, in.uv.xy).r) * in.color;\n"
|
||||
"}\n";
|
||||
#elif defined(SOKOL_D3D11)
|
||||
/*
|
||||
Shader blobs for D3D11, compiled with:
|
||||
|
||||
fxc.exe /T vs_4_0 /Fh vs.h /Gec /O3 vs.hlsl
|
||||
fxc.exe /T ps_4_0 /Fh fs.h /Gec /O3 fs.hlsl
|
||||
|
||||
Vertex shader source:
|
||||
|
||||
cbuffer params: register(b0) {
|
||||
float4x4 mvp;
|
||||
float4x4 tm;
|
||||
};
|
||||
struct vs_in {
|
||||
float4 pos: POSITION;
|
||||
float2 uv: TEXCOORD0;
|
||||
float4 color: COLOR0;
|
||||
};
|
||||
struct vs_out {
|
||||
float4 uv: TEXCOORD0;
|
||||
float4 color: COLOR0;
|
||||
float4 pos: SV_Position;
|
||||
};
|
||||
vs_out main(vs_in inp) {
|
||||
vs_out outp;
|
||||
outp.pos = mul(mvp, inp.pos);
|
||||
outp.uv = mul(tm, float4(inp.uv, 0.0, 1.0));
|
||||
outp.color = inp.color;
|
||||
return outp;
|
||||
};
|
||||
|
||||
Pixel shader source:
|
||||
|
||||
Texture2D<float4> tex: register(t0);
|
||||
sampler smp: register(s0);
|
||||
float4 main(float4 uv: TEXCOORD0, float4 color: COLOR0): SV_Target0 {
|
||||
return float4(1.0, 1.0, 1.0, tex.Sample(smp, uv.xy).r) * color;
|
||||
}
|
||||
*/
|
||||
static const uint8_t _sfons_vs_bin[] = {
|
||||
68, 88, 66, 67, 89, 173,
|
||||
124, 225, 74, 102, 159, 55,
|
||||
47, 64, 241, 32, 31, 107,
|
||||
240, 204, 1, 0, 0, 0,
|
||||
244, 3, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0,
|
||||
8, 1, 0, 0, 120, 1,
|
||||
0, 0, 236, 1, 0, 0,
|
||||
120, 3, 0, 0, 82, 68,
|
||||
69, 70, 204, 0, 0, 0,
|
||||
1, 0, 0, 0, 68, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
28, 0, 0, 0, 0, 4,
|
||||
254, 255, 0, 17, 0, 0,
|
||||
163, 0, 0, 0, 60, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
112, 97, 114, 97, 109, 115,
|
||||
0, 171, 60, 0, 0, 0,
|
||||
2, 0, 0, 0, 92, 0,
|
||||
0, 0, 128, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 140, 0, 0, 0,
|
||||
0, 0, 0, 0, 64, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
144, 0, 0, 0, 0, 0,
|
||||
0, 0, 160, 0, 0, 0,
|
||||
64, 0, 0, 0, 64, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
144, 0, 0, 0, 0, 0,
|
||||
0, 0, 109, 118, 112, 0,
|
||||
3, 0, 3, 0, 4, 0,
|
||||
4, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 116, 109,
|
||||
0, 77, 105, 99, 114, 111,
|
||||
115, 111, 102, 116, 32, 40,
|
||||
82, 41, 32, 72, 76, 83,
|
||||
76, 32, 83, 104, 97, 100,
|
||||
101, 114, 32, 67, 111, 109,
|
||||
112, 105, 108, 101, 114, 32,
|
||||
49, 48, 46, 49, 0, 171,
|
||||
73, 83, 71, 78, 104, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
8, 0, 0, 0, 80, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
15, 15, 0, 0, 89, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
3, 3, 0, 0, 98, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
15, 15, 0, 0, 80, 79,
|
||||
83, 73, 84, 73, 79, 78,
|
||||
0, 84, 69, 88, 67, 79,
|
||||
79, 82, 68, 0, 67, 79,
|
||||
76, 79, 82, 0, 79, 83,
|
||||
71, 78, 108, 0, 0, 0,
|
||||
3, 0, 0, 0, 8, 0,
|
||||
0, 0, 80, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
0, 0, 0, 0, 15, 0,
|
||||
0, 0, 89, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
1, 0, 0, 0, 15, 0,
|
||||
0, 0, 95, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
2, 0, 0, 0, 15, 0,
|
||||
0, 0, 84, 69, 88, 67,
|
||||
79, 79, 82, 68, 0, 67,
|
||||
79, 76, 79, 82, 0, 83,
|
||||
86, 95, 80, 111, 115, 105,
|
||||
116, 105, 111, 110, 0, 171,
|
||||
83, 72, 68, 82, 132, 1,
|
||||
0, 0, 64, 0, 1, 0,
|
||||
97, 0, 0, 0, 89, 0,
|
||||
0, 4, 70, 142, 32, 0,
|
||||
0, 0, 0, 0, 8, 0,
|
||||
0, 0, 95, 0, 0, 3,
|
||||
242, 16, 16, 0, 0, 0,
|
||||
0, 0, 95, 0, 0, 3,
|
||||
50, 16, 16, 0, 1, 0,
|
||||
0, 0, 95, 0, 0, 3,
|
||||
242, 16, 16, 0, 2, 0,
|
||||
0, 0, 101, 0, 0, 3,
|
||||
242, 32, 16, 0, 0, 0,
|
||||
0, 0, 101, 0, 0, 3,
|
||||
242, 32, 16, 0, 1, 0,
|
||||
0, 0, 103, 0, 0, 4,
|
||||
242, 32, 16, 0, 2, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
104, 0, 0, 2, 1, 0,
|
||||
0, 0, 56, 0, 0, 8,
|
||||
242, 0, 16, 0, 0, 0,
|
||||
0, 0, 86, 21, 16, 0,
|
||||
1, 0, 0, 0, 70, 142,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
5, 0, 0, 0, 50, 0,
|
||||
0, 10, 242, 0, 16, 0,
|
||||
0, 0, 0, 0, 70, 142,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
4, 0, 0, 0, 6, 16,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
70, 14, 16, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 8,
|
||||
242, 32, 16, 0, 0, 0,
|
||||
0, 0, 70, 14, 16, 0,
|
||||
0, 0, 0, 0, 70, 142,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
7, 0, 0, 0, 54, 0,
|
||||
0, 5, 242, 32, 16, 0,
|
||||
1, 0, 0, 0, 70, 30,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
56, 0, 0, 8, 242, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
86, 21, 16, 0, 0, 0,
|
||||
0, 0, 70, 142, 32, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 50, 0, 0, 10,
|
||||
242, 0, 16, 0, 0, 0,
|
||||
0, 0, 70, 142, 32, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 6, 16, 16, 0,
|
||||
0, 0, 0, 0, 70, 14,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
50, 0, 0, 10, 242, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
70, 142, 32, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
166, 26, 16, 0, 0, 0,
|
||||
0, 0, 70, 14, 16, 0,
|
||||
0, 0, 0, 0, 50, 0,
|
||||
0, 10, 242, 32, 16, 0,
|
||||
2, 0, 0, 0, 70, 142,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 246, 31,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
70, 14, 16, 0, 0, 0,
|
||||
0, 0, 62, 0, 0, 1,
|
||||
83, 84, 65, 84, 116, 0,
|
||||
0, 0, 9, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0,
|
||||
0, 0, 6, 0, 0, 0,
|
||||
7, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0
|
||||
};
|
||||
static uint8_t _sfons_fs_bin[] = {
|
||||
68, 88, 66, 67, 180, 53,
|
||||
115, 174, 239, 17, 254, 112,
|
||||
63, 104, 217, 123, 150, 145,
|
||||
179, 27, 1, 0, 0, 0,
|
||||
120, 2, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0,
|
||||
200, 0, 0, 0, 24, 1,
|
||||
0, 0, 76, 1, 0, 0,
|
||||
252, 1, 0, 0, 82, 68,
|
||||
69, 70, 140, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
28, 0, 0, 0, 0, 4,
|
||||
255, 255, 0, 17, 0, 0,
|
||||
100, 0, 0, 0, 92, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
96, 0, 0, 0, 2, 0,
|
||||
0, 0, 5, 0, 0, 0,
|
||||
4, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 13, 0,
|
||||
0, 0, 115, 109, 112, 0,
|
||||
116, 101, 120, 0, 77, 105,
|
||||
99, 114, 111, 115, 111, 102,
|
||||
116, 32, 40, 82, 41, 32,
|
||||
72, 76, 83, 76, 32, 83,
|
||||
104, 97, 100, 101, 114, 32,
|
||||
67, 111, 109, 112, 105, 108,
|
||||
101, 114, 32, 49, 48, 46,
|
||||
49, 0, 73, 83, 71, 78,
|
||||
72, 0, 0, 0, 2, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
56, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 0, 0,
|
||||
0, 0, 15, 3, 0, 0,
|
||||
65, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 1, 0,
|
||||
0, 0, 15, 15, 0, 0,
|
||||
84, 69, 88, 67, 79, 79,
|
||||
82, 68, 0, 67, 79, 76,
|
||||
79, 82, 0, 171, 79, 83,
|
||||
71, 78, 44, 0, 0, 0,
|
||||
1, 0, 0, 0, 8, 0,
|
||||
0, 0, 32, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
0, 0, 0, 0, 15, 0,
|
||||
0, 0, 83, 86, 95, 84,
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171, 83, 72, 68, 82,
|
||||
168, 0, 0, 0, 64, 0,
|
||||
0, 0, 42, 0, 0, 0,
|
||||
90, 0, 0, 3, 0, 96,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
88, 24, 0, 4, 0, 112,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
85, 85, 0, 0, 98, 16,
|
||||
0, 3, 50, 16, 16, 0,
|
||||
0, 0, 0, 0, 98, 16,
|
||||
0, 3, 242, 16, 16, 0,
|
||||
1, 0, 0, 0, 101, 0,
|
||||
0, 3, 242, 32, 16, 0,
|
||||
0, 0, 0, 0, 104, 0,
|
||||
0, 2, 1, 0, 0, 0,
|
||||
69, 0, 0, 9, 242, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
70, 16, 16, 0, 0, 0,
|
||||
0, 0, 150, 115, 16, 0,
|
||||
0, 0, 0, 0, 0, 96,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
54, 0, 0, 5, 18, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 0, 0,
|
||||
128, 63, 56, 0, 0, 7,
|
||||
242, 32, 16, 0, 0, 0,
|
||||
0, 0, 6, 12, 16, 0,
|
||||
0, 0, 0, 0, 70, 30,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
62, 0, 0, 1, 83, 84,
|
||||
65, 84, 116, 0, 0, 0,
|
||||
4, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0
|
||||
};
|
||||
#elif defined(SOKOL_DUMMY_BACKEND)
|
||||
static const char* _sfons_vs_src = "";
|
||||
static const char* _sfons_fs_src = "";
|
||||
#endif
|
||||
|
||||
typedef struct _sfons_t {
|
||||
sg_shader shd;
|
||||
sgl_pipeline pip;
|
||||
sg_image img;
|
||||
int width, height;
|
||||
bool img_dirty;
|
||||
} _sfons_t;
|
||||
|
||||
static int _sfons_render_create(void* user_ptr, int width, int height) {
|
||||
SOKOL_ASSERT(user_ptr && (width > 8) && (height > 8));
|
||||
_sfons_t* sfons = (_sfons_t*) user_ptr;
|
||||
|
||||
/* sokol-gl compatible shader which treats RED channel as alpha */
|
||||
if (sfons->shd.id == SG_INVALID_ID) {
|
||||
sg_shader_desc shd_desc;
|
||||
memset(&shd_desc, 0, sizeof(shd_desc));
|
||||
shd_desc.attrs[0].name = "position";
|
||||
shd_desc.attrs[1].name = "texcoord0";
|
||||
shd_desc.attrs[2].name = "color0";
|
||||
shd_desc.attrs[0].sem_name = "POSITION";
|
||||
shd_desc.attrs[1].sem_name = "TEXCOORD";
|
||||
shd_desc.attrs[2].sem_name = "COLOR";
|
||||
sg_shader_uniform_block_desc* ub = &shd_desc.vs.uniform_blocks[0];
|
||||
ub->size = 128;
|
||||
ub->uniforms[0].name = "mvp";
|
||||
ub->uniforms[0].type = SG_UNIFORMTYPE_MAT4;
|
||||
ub->uniforms[1].name = "tm";
|
||||
ub->uniforms[1].type = SG_UNIFORMTYPE_MAT4;
|
||||
shd_desc.fs.images[0].name = "tex";
|
||||
shd_desc.fs.images[0].type = SG_IMAGETYPE_2D;
|
||||
#if defined(SOKOL_D3D11)
|
||||
shd_desc.vs.byte_code = _sfons_vs_bin;
|
||||
shd_desc.vs.byte_code_size = sizeof(_sfons_vs_bin);
|
||||
shd_desc.fs.byte_code = _sfons_fs_bin;
|
||||
shd_desc.fs.byte_code_size = sizeof(_sfons_fs_bin);
|
||||
#else
|
||||
shd_desc.vs.source = _sfons_vs_src;
|
||||
shd_desc.fs.source = _sfons_fs_src;
|
||||
#endif
|
||||
shd_desc.label = "sfons-shader";
|
||||
sfons->shd = sg_make_shader(&shd_desc);
|
||||
}
|
||||
|
||||
/* sokol-gl pipeline object */
|
||||
if (sfons->pip.id == SG_INVALID_ID) {
|
||||
sg_pipeline_desc pip_desc;
|
||||
memset(&pip_desc, 0, sizeof(pip_desc));
|
||||
pip_desc.shader = sfons->shd;
|
||||
pip_desc.blend.enabled = true;
|
||||
pip_desc.blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA;
|
||||
pip_desc.blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
sfons->pip = sgl_make_pipeline(&pip_desc);
|
||||
}
|
||||
|
||||
/* create or re-create font atlas texture */
|
||||
if (sfons->img.id != SG_INVALID_ID) {
|
||||
sg_destroy_image(sfons->img);
|
||||
sfons->img.id = SG_INVALID_ID;
|
||||
}
|
||||
sfons->width = width;
|
||||
sfons->height = height;
|
||||
|
||||
SOKOL_ASSERT(sfons->img.id == SG_INVALID_ID);
|
||||
sg_image_desc img_desc;
|
||||
memset(&img_desc, 0, sizeof(img_desc));
|
||||
img_desc.width = sfons->width;
|
||||
img_desc.height = sfons->height;
|
||||
img_desc.min_filter = SG_FILTER_LINEAR;
|
||||
img_desc.mag_filter = SG_FILTER_LINEAR;
|
||||
img_desc.usage = SG_USAGE_DYNAMIC;
|
||||
img_desc.pixel_format = SG_PIXELFORMAT_R8;
|
||||
sfons->img = sg_make_image(&img_desc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _sfons_render_resize(void* user_ptr, int width, int height) {
|
||||
return _sfons_render_create(user_ptr, width, height);
|
||||
}
|
||||
|
||||
static void _sfons_render_update(void* user_ptr, int* rect, const unsigned char* data) {
|
||||
SOKOL_ASSERT(user_ptr && rect && data);
|
||||
_sfons_t* sfons = (_sfons_t*) user_ptr;
|
||||
sfons->img_dirty = true;
|
||||
}
|
||||
|
||||
static void _sfons_render_draw(void* user_ptr, const float* verts, const float* tcoords, const unsigned int* colors, int nverts) {
|
||||
SOKOL_ASSERT(user_ptr && verts && tcoords && colors && (nverts > 0));
|
||||
_sfons_t* sfons = (_sfons_t*) user_ptr;
|
||||
sgl_enable_texture();
|
||||
sgl_texture(sfons->img);
|
||||
sgl_push_pipeline();
|
||||
sgl_load_pipeline(sfons->pip);
|
||||
sgl_begin_triangles();
|
||||
for (int i = 0; i < nverts; i++) {
|
||||
sgl_v2f_t2f_c1i(verts[2*i+0], verts[2*i+1], tcoords[2*i+0], tcoords[2*i+1], colors[i]);
|
||||
}
|
||||
sgl_end();
|
||||
sgl_pop_pipeline();
|
||||
sgl_disable_texture();
|
||||
}
|
||||
|
||||
static void _sfons_render_delete(void* user_ptr) {
|
||||
SOKOL_ASSERT(user_ptr);
|
||||
_sfons_t* sfons = (_sfons_t*) user_ptr;
|
||||
if (sfons->img.id != SG_INVALID_ID) {
|
||||
sg_destroy_image(sfons->img);
|
||||
sfons->img.id = SG_INVALID_ID;
|
||||
}
|
||||
if (sfons->pip.id != SG_INVALID_ID) {
|
||||
sgl_destroy_pipeline(sfons->pip);
|
||||
sfons->pip.id = SG_INVALID_ID;
|
||||
}
|
||||
if (sfons->shd.id != SG_INVALID_ID) {
|
||||
sg_destroy_shader(sfons->shd);
|
||||
sfons->shd.id = SG_INVALID_ID;
|
||||
}
|
||||
SOKOL_FREE(sfons);
|
||||
}
|
||||
|
||||
SOKOL_API_IMPL FONScontext* sfons_create(int width, int height, int flags) {
|
||||
SOKOL_ASSERT((width > 0) && (height > 0));
|
||||
FONSparams params;
|
||||
_sfons_t* sfons = (_sfons_t*) SOKOL_MALLOC(sizeof(_sfons_t));
|
||||
memset(sfons, 0, sizeof(_sfons_t));
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.width = width;
|
||||
params.height = height;
|
||||
params.flags = (unsigned char) flags;
|
||||
params.renderCreate = _sfons_render_create;
|
||||
params.renderResize = _sfons_render_resize;
|
||||
params.renderUpdate = _sfons_render_update;
|
||||
params.renderDraw = _sfons_render_draw;
|
||||
params.renderDelete = _sfons_render_delete;
|
||||
params.userPtr = sfons;
|
||||
return fonsCreateInternal(¶ms);
|
||||
}
|
||||
|
||||
SOKOL_API_IMPL void sfons_destroy(FONScontext* ctx) {
|
||||
SOKOL_ASSERT(ctx);
|
||||
fonsDeleteInternal(ctx);
|
||||
}
|
||||
|
||||
SOKOL_API_IMPL void sfons_flush(FONScontext* ctx) {
|
||||
SOKOL_ASSERT(ctx && ctx->params.userPtr);
|
||||
_sfons_t* sfons = (_sfons_t*) ctx->params.userPtr;
|
||||
if (sfons->img_dirty) {
|
||||
sfons->img_dirty = false;
|
||||
sg_image_content content;
|
||||
memset(&content, 0, sizeof(content));
|
||||
content.subimage[0][0].ptr = ctx->texData;
|
||||
content.subimage[0][0].size = sfons->width * sfons->height;
|
||||
sg_update_image(sfons->img, &content);
|
||||
}
|
||||
}
|
||||
|
||||
SOKOL_API_IMPL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
return (r) | (g<<8) | (b<<16) | (a<<24);
|
||||
}
|
||||
|
||||
#endif /* SOKOL_FONTSTASH_IMPL */
|
2372
thirdparty/sokol/util/sokol_gl.h
vendored
Executable file
2372
thirdparty/sokol/util/sokol_gl.h
vendored
Executable file
File diff suppressed because it is too large
Load Diff
152
vlib/fontstash/fontstash.v
Normal file
152
vlib/fontstash/fontstash.v
Normal file
@ -0,0 +1,152 @@
|
||||
module fontstash
|
||||
|
||||
#flag -I @VROOT/thirdparty/fontstash
|
||||
|
||||
|
||||
// Contructor and destructor.
|
||||
[inline]
|
||||
pub fn create_internal(params &C.FONSparams) &C.FONScontext {
|
||||
return C.fonsCreateInternal(params)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn delete_internal(s &C.FONScontext) {
|
||||
C.fonsDeleteInternal(s)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) set_error_callback(callback fn(uptr voidptr, error int, val int), uptr voidptr) {
|
||||
C.fonsSetErrorCallback(s, callback, uptr)
|
||||
}
|
||||
|
||||
// Returns current atlas size.
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) get_atlas_size(width &int, height &int) {
|
||||
C.fonsGetAtlasSize(s, width, height)
|
||||
}
|
||||
|
||||
// Expands the atlas size.
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) expand_atlas(width int, height int) int {
|
||||
return C.fonsExpandAtlas(s, width, height)
|
||||
}
|
||||
|
||||
// Resets the whole stash.
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) reset_atlas(width int, height int) int {
|
||||
return C.fonsResetAtlas(s, width, height)
|
||||
}
|
||||
|
||||
// Add fonts
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) get_font_by_name(name byteptr) int {
|
||||
return C.fonsGetFontByName(s, name)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) add_fallback_font(base int, fallback int) int {
|
||||
return C.fonsAddFallbackFont(s, base, fallback)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) add_font_mem(name byteptr, data byteptr, data_size int, free_data int) int {
|
||||
return C.fonsAddFontMem(s, name, data, data_size, free_data)
|
||||
}
|
||||
|
||||
// State handling
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) push_state() {
|
||||
C.fonsPushState(s)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) pop_state() {
|
||||
C.fonsPopState(s)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) clear_state() {
|
||||
C.fonsClearState(s)
|
||||
}
|
||||
|
||||
// State setting
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) set_size(size f32) {
|
||||
C.fonsSetSize(s, size)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) set_color(color u32) {
|
||||
C.fonsSetColor(s, color)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) set_spacing(spacing f32) {
|
||||
C.fonsSetSpacing(s, spacing)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) set_blur(blur f32) {
|
||||
C.fonsSetBlur(s, blur)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) set_align(align int) {
|
||||
C.fonsSetAlign(s, align)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) set_font(font int) {
|
||||
C.fonsSetFont(s, font)
|
||||
}
|
||||
|
||||
// Draw text
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) draw_text(x f32, y f32, str byteptr, end byteptr) f32 {
|
||||
return C.fonsDrawText(s, x, y, str, end)
|
||||
}
|
||||
|
||||
// Measure text
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) text_bounds(x f32, y f32, str byteptr, end byteptr, bounds &f32) f32 {
|
||||
return C.fonsTextBounds(s, x, y, str, end, bounds)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) line_bounds(y f32, miny &f32, maxy &f32) {
|
||||
C.fonsLineBounds(s, y, miny, maxy)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) vert_metrics(ascender &f32, descender &f32, lineh &f32) {
|
||||
C.fonsVertMetrics(s, ascender, descender, lineh)
|
||||
}
|
||||
|
||||
// Text iterator
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) text_iter_init(iter &C.FONStextIter, x f32, y f32, str byteptr, end byteptr) int {
|
||||
return C.fonsTextIterInit(s, iter, x, y, str, end)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) text_iter_next(iter &C.FONStextIter, quad &C.FONSquad) int {
|
||||
return C.fonsTextIterNext(s, iter, quad)
|
||||
}
|
||||
|
||||
// Pull texture changes
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) get_texture_data(width &int, height &int) byteptr {
|
||||
return C.fonsGetTextureData(s, width, height)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) validate_texture(dirty &int) int {
|
||||
return C.fonsValidateTexture(s, dirty)
|
||||
}
|
||||
|
||||
// Draws the stash texture for debugging
|
||||
[inline]
|
||||
pub fn (s &C.FONScontext) draw_debug(x f32, y f32) {
|
||||
C.fonsDrawDebug(s, x, y)
|
||||
}
|
||||
|
50
vlib/fontstash/fontstash_funcs.v
Normal file
50
vlib/fontstash/fontstash_funcs.v
Normal file
@ -0,0 +1,50 @@
|
||||
module fontstash
|
||||
|
||||
// Contructor and destructor.
|
||||
fn C.fonsCreateInternal(params &C.FONSparams) &C.FONScontext
|
||||
fn C.fonsDeleteInternal(s &C.FONScontext)
|
||||
|
||||
fn C.fonsSetErrorCallback(s &C.FONScontext, callback fn(uptr voidptr, error int, val int), uptr voidptr)
|
||||
// Returns current atlas size.
|
||||
fn C.fonsGetAtlasSize(s &C.FONScontext, width &int, height &int)
|
||||
// Expands the atlas size.
|
||||
fn C.fonsExpandAtlas(s &C.FONScontext, width int, height int) int
|
||||
// Resets the whole stash.
|
||||
fn C.fonsResetAtlas(s &C.FONScontext, width int, height int) int
|
||||
|
||||
// Add fonts
|
||||
fn C.fonsGetFontByName(s &C.FONScontext, name byteptr) int
|
||||
fn C.fonsAddFallbackFont(s &C.FONScontext, base int, fallback int) int
|
||||
fn C.fonsAddFontMem(s &C.FONScontext, name byteptr, data byteptr, dataSize int, freeData int) int
|
||||
|
||||
// State handling
|
||||
fn C.fonsPushState(s &C.FONScontext)
|
||||
fn C.fonsPopState(s &C.FONScontext)
|
||||
fn C.fonsClearState(s &C.FONScontext)
|
||||
|
||||
// State setting
|
||||
fn C.fonsSetSize(s &C.FONScontext, size f32)
|
||||
fn C.fonsSetColor(s &C.FONScontext, color u32)
|
||||
fn C.fonsSetSpacing(s &C.FONScontext, spacing f32)
|
||||
fn C.fonsSetBlur(s &C.FONScontext, blur f32)
|
||||
fn C.fonsSetAlign(s &C.FONScontext, align int)
|
||||
fn C.fonsSetFont(s &C.FONScontext, font int)
|
||||
|
||||
// Draw text
|
||||
fn C.fonsDrawText(s &C.FONScontext, x f32, y f32, str byteptr, end byteptr) f32
|
||||
|
||||
// Measure text
|
||||
fn C.fonsTextBounds(s &C.FONScontext, x f32, y f32, str byteptr, end byteptr, bounds &f32) f32
|
||||
fn C.fonsLineBounds(s &C.FONScontext, y f32, miny &f32, maxy &f32)
|
||||
fn C.fonsVertMetrics(s &C.FONScontext, ascender &f32, descender &f32, lineh &f32)
|
||||
|
||||
// Text iterator
|
||||
fn C.fonsTextIterInit(s &C.FONScontext, iter &C.FONStextIter, x f32, y f32, str byteptr, end byteptr) int
|
||||
fn C.fonsTextIterNext(s &C.FONScontext, iter &C.FONStextIter, quad &C.FONSquad) int
|
||||
|
||||
// Pull texture changes
|
||||
fn C.fonsGetTextureData(s &C.FONScontext, width &int, height &int) byteptr
|
||||
fn C.fonsValidateTexture(s &C.FONScontext, dirty &int) int
|
||||
|
||||
// Draws the stash texture for debugging
|
||||
fn C.fonsDrawDebug(s &C.FONScontext, x f32, y f32)
|
80
vlib/fontstash/fontstash_structs.v
Normal file
80
vlib/fontstash/fontstash_structs.v
Normal file
@ -0,0 +1,80 @@
|
||||
module fontstash
|
||||
|
||||
pub enum FonsFlags {
|
||||
top_left = 1
|
||||
bottom_left = 2
|
||||
}
|
||||
|
||||
pub enum FonsAlign {
|
||||
// Horizontal align
|
||||
left = 1 // Default
|
||||
center = 2
|
||||
right = 4
|
||||
// Vertical align
|
||||
top = 8
|
||||
middle = 16
|
||||
bottom = 32
|
||||
baseline = 64 // Default
|
||||
}
|
||||
|
||||
pub enum FonsErrorCode {
|
||||
// Font atlas is full.
|
||||
atlas_full = 1
|
||||
// Scratch memory used to render glyphs is full, requested size reported in 'val', you may need to bump up FONS_SCRATCH_BUF_SIZE.
|
||||
scratch_full = 2
|
||||
// Calls to fonsPushState has created too large stack, if you need deep state stack bump up FONS_MAX_STATES.
|
||||
states_overflow = 3
|
||||
// Trying to pop too many states fonsPopState().
|
||||
states_underflow = 4
|
||||
}
|
||||
|
||||
pub struct C.FONSparams {
|
||||
width int
|
||||
height int
|
||||
flags char
|
||||
userPtr voidptr
|
||||
// int (*renderCreate)(void* uptr, int width, int height)
|
||||
renderCreate fn(uptr voidptr, width int, height int) int
|
||||
// int (*renderResize)(void* uptr, int width, int height)
|
||||
renderResize fn(uptr voidptr, width int, height int) int
|
||||
// void (*renderUpdate)(void* uptr, int* rect, const unsigned char* data)
|
||||
renderUpdate fn(uptr voidptr, rect &int, data byteptr)
|
||||
// void (*renderDraw)(void* uptr, const float* verts, const float* tcoords, const unsigned int* colors, int nverts)
|
||||
renderDraw fn(uptr voidptr, verts &f32, tcoords &f32, colors &u32, nverts int)
|
||||
// void (*renderDelete)(void* uptr)
|
||||
renderDelete fn(uptr voidptr)
|
||||
}
|
||||
|
||||
pub struct C.FONSquad
|
||||
{
|
||||
x0 f32
|
||||
y0 f32
|
||||
s0 f32
|
||||
t0 f32
|
||||
x1 f32
|
||||
y1 f32
|
||||
s1 f32
|
||||
t1 f32
|
||||
}
|
||||
|
||||
pub struct C.FONStextIter {
|
||||
x f32
|
||||
y f32
|
||||
nextx f32
|
||||
nexty f32
|
||||
scale f32
|
||||
spacing f32
|
||||
codepoint u32
|
||||
isize i16
|
||||
iblur i16
|
||||
font &FONSfont
|
||||
prevGlyphIndex int
|
||||
str byteptr
|
||||
next byteptr
|
||||
end byteptr
|
||||
utf8state u32
|
||||
}
|
||||
|
||||
pub struct C.FONSfont {}
|
||||
|
||||
pub struct C.FONScontext {}
|
304
vlib/sokol/gfx/enums.v
Normal file
304
vlib/sokol/gfx/enums.v
Normal file
@ -0,0 +1,304 @@
|
||||
module gfx
|
||||
|
||||
pub enum Backend {
|
||||
glcore33
|
||||
gles2
|
||||
gles3
|
||||
d3d11
|
||||
metal_ios
|
||||
metal_macos
|
||||
metal_simulator
|
||||
dummy
|
||||
}
|
||||
|
||||
pub enum PixelFormat {
|
||||
_default /* value 0 reserved for default-init */
|
||||
@none
|
||||
|
||||
r8
|
||||
r8sn
|
||||
r8ui
|
||||
r8si
|
||||
|
||||
r16
|
||||
r16sn
|
||||
r16ui
|
||||
r16si
|
||||
r16f
|
||||
rg8
|
||||
rg8sn
|
||||
rg8ui
|
||||
rg8si
|
||||
|
||||
r32ui
|
||||
r32si
|
||||
r32f
|
||||
rg16
|
||||
rg16sn
|
||||
rg16ui
|
||||
rg16si
|
||||
rg16f
|
||||
rgba8
|
||||
rgba8sn
|
||||
rgba8ui
|
||||
rgba8si
|
||||
bgra8
|
||||
rgb10a2
|
||||
rg11b10f
|
||||
|
||||
rg32ui
|
||||
rg32si
|
||||
rg32f
|
||||
rgba16
|
||||
rgba16sn
|
||||
rgba16ui
|
||||
rgba16si
|
||||
rgba16f
|
||||
|
||||
rgba32ui
|
||||
rgba32si
|
||||
rgba32f
|
||||
|
||||
depth
|
||||
depth_stencil
|
||||
|
||||
bc1_rgba
|
||||
bc2_rgba
|
||||
bc3_rgba
|
||||
bc4_r
|
||||
bc4_rsn
|
||||
bc5_rg
|
||||
bc5_rgsn
|
||||
bc6h_rgbf
|
||||
bc6h_rgbuf
|
||||
bc7_rgba
|
||||
pvrtc_rgb_2bpp
|
||||
pvrtc_rgb_4bpp
|
||||
pvrtc_rgba_2bpp
|
||||
pvrtc_rgba_4bpp
|
||||
etc2_rgb8
|
||||
etc2_rgb8a1
|
||||
etc2_rgba8
|
||||
etc2_rg11
|
||||
etc2_rg11sn
|
||||
|
||||
num
|
||||
}
|
||||
|
||||
pub enum ResourceState {
|
||||
initial
|
||||
alloc
|
||||
valid
|
||||
failed
|
||||
invalid
|
||||
}
|
||||
|
||||
pub enum Usage {
|
||||
_default /* value 0 reserved for default-init */
|
||||
immutable
|
||||
dynamic
|
||||
stream
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum BufferType {
|
||||
_default /* value 0 reserved for default-init */
|
||||
vertexbuffer
|
||||
indexbuffer
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum IndexType {
|
||||
_default /* value 0 reserved for default-init */
|
||||
@none
|
||||
uint16
|
||||
uint32
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum ImageType {
|
||||
_default /* value 0 reserved for default-init */
|
||||
_2d
|
||||
cube
|
||||
_3d
|
||||
array
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum CubeFace {
|
||||
pos_x
|
||||
neg_x
|
||||
pos_y
|
||||
neg_y
|
||||
pos_z
|
||||
neg_z
|
||||
num
|
||||
}
|
||||
|
||||
pub enum ShaderStage {
|
||||
vs
|
||||
fs
|
||||
}
|
||||
|
||||
pub enum PrimitiveType {
|
||||
_default /* value 0 reserved for default-init */
|
||||
points
|
||||
lines
|
||||
line_strip
|
||||
triangles
|
||||
triangle_strip
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum Filter {
|
||||
_default /* value 0 reserved for default-init */
|
||||
nearest
|
||||
linear
|
||||
nearest_mipmap_nearest
|
||||
nearest_mipmap_linear
|
||||
linear_mipmap_nearest
|
||||
linear_mipmap_linear
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum Wrap {
|
||||
_default /* value 0 reserved for default-init */
|
||||
repeat
|
||||
clamp_to_edge
|
||||
clamp_to_border
|
||||
mirrored_repeat
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum BorderColor {
|
||||
_default /* value 0 reserved for default-init */
|
||||
transparent_black
|
||||
opaque_black
|
||||
opaque_white
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum VertexFormat {
|
||||
invalid
|
||||
float
|
||||
float2
|
||||
float3
|
||||
float4
|
||||
byte4
|
||||
byte4n
|
||||
ubyte4
|
||||
ubyte4n
|
||||
short2
|
||||
short2n
|
||||
ushort2n
|
||||
short4
|
||||
short4n
|
||||
ushort4n
|
||||
uint10_n2
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum VertexStep {
|
||||
_default /* value 0 reserved for default-init */
|
||||
per_vertex
|
||||
per_instance
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum UniformType {
|
||||
invalid
|
||||
float
|
||||
float2
|
||||
float3
|
||||
float4
|
||||
mat4
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum CullMode {
|
||||
_default /* value 0 reserved for default-init */
|
||||
@none
|
||||
front
|
||||
back
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum FaceWinding {
|
||||
_facewinding_default /* value 0 reserved for default-init */
|
||||
facewinding_ccw
|
||||
facewinding_cw
|
||||
_facewinding_num
|
||||
}
|
||||
|
||||
pub enum CompareFunc {
|
||||
_default /* value 0 reserved for default-init */
|
||||
never
|
||||
less
|
||||
equal
|
||||
less_equal
|
||||
greater
|
||||
not_equal
|
||||
greater_equal
|
||||
always
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum StencilOp {
|
||||
_default /* value 0 reserved for default-init */
|
||||
keep
|
||||
zero
|
||||
replace
|
||||
incr_clamp
|
||||
decr_clamp
|
||||
invert
|
||||
incr_wrap
|
||||
decr_wrap
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum BlendFactor {
|
||||
_default /* value 0 reserved for default-init */
|
||||
zero
|
||||
one
|
||||
src_color
|
||||
one_minus_src_color
|
||||
src_alpha
|
||||
one_minus_src_alpha
|
||||
dst_color
|
||||
one_minus_dst_color
|
||||
dst_alpha
|
||||
one_minus_dst_alpha
|
||||
src_alpha_saturated
|
||||
blend_color
|
||||
one_minus_blend_color
|
||||
blend_alpha
|
||||
one_minus_blend_alpha
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum BlendOp {
|
||||
_default /* value 0 reserved for default-init */
|
||||
add
|
||||
subtract
|
||||
reverse_subtract
|
||||
_num
|
||||
}
|
||||
|
||||
pub enum ColorMask {
|
||||
_default = 0 /* value 0 reserved for default-init */
|
||||
@none = 0x10 /* special value for 'all channels disabled */
|
||||
r = 1
|
||||
g = 2
|
||||
b = 4
|
||||
a = 8
|
||||
rgb = 0x7
|
||||
rgba = 0xF
|
||||
}
|
||||
|
||||
pub enum Action {
|
||||
_default
|
||||
clear
|
||||
load
|
||||
dontcare
|
||||
_num
|
||||
}
|
218
vlib/sokol/gfx/gfx.v
Normal file
218
vlib/sokol/gfx/gfx.v
Normal file
@ -0,0 +1,218 @@
|
||||
module gfx
|
||||
|
||||
// setup and misc functions
|
||||
[inline]
|
||||
pub fn setup(desc &C.sg_desc) {
|
||||
C.sg_setup(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn shutdown() {
|
||||
C.sg_shutdown()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn reset_state_cache() {
|
||||
C.sg_reset_state_cache()
|
||||
}
|
||||
|
||||
// resource creation, destruction and updating
|
||||
[inline]
|
||||
pub fn make_buffer(desc &C.sg_buffer_desc) C.sg_buffer {
|
||||
return C.sg_make_buffer(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn make_image(desc &C.sg_image_desc) C.sg_image {
|
||||
return C.sg_make_image(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn make_shader(desc &C.sg_shader_desc) C.sg_shader {
|
||||
return C.sg_make_shader(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn make_pipeline(desc &C.sg_pipeline_desc) C.sg_pipeline {
|
||||
return C.sg_make_pipeline(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn make_pass(desc &C.sg_pass_desc) C.sg_pass {
|
||||
return C.sg_make_pass(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_buffer(buf C.sg_buffer) {
|
||||
C.sg_destroy_buffer(buf)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_image(img C.sg_image) {
|
||||
C.sg_destroy_image(img)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_shader(shd C.sg_shader) {
|
||||
C.sg_destroy_shader(shd)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_pipeline(pip C.sg_pipeline) {
|
||||
C.sg_destroy_pipeline(pip)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_pass(pass C.sg_pass) {
|
||||
C.sg_destroy_pass(pass)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn update_buffer(buf C.sg_buffer, ptr voidptr, num_bytes int) {
|
||||
C.sg_update_buffer(buf, ptr, num_bytes)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn update_image(img C.sg_image, content &C.sg_image_content) {
|
||||
C.sg_update_image(img, content)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn append_buffer(buf C.sg_buffer, ptr voidptr, num_bytes int) int {
|
||||
return C.sg_append_buffer(buf, ptr, num_bytes)
|
||||
}
|
||||
|
||||
// rendering functions
|
||||
[inline]
|
||||
pub fn begin_default_pass(actions &C.sg_pass_action, width int, height int) {
|
||||
C.sg_begin_default_pass(actions, width, height)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn begin_pass(pass C.sg_pass, actions &C.sg_pass_action) {
|
||||
C.sg_begin_pass(pass, actions)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn apply_viewport(x int, y int, width int, height int, origin_top_left bool) {
|
||||
C.sg_apply_viewport(x, y, width, height, origin_top_left)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn apply_scissor_rect(x int, y int, width int, height int, origin_top_left bool) {
|
||||
C.sg_apply_scissor_rect(x, y, width, height, origin_top_left)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn apply_pipeline(pip C.sg_pipeline) {
|
||||
C.sg_apply_pipeline(pip)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn apply_bindings(bindings &C.sg_bindings) {
|
||||
C.sg_apply_bindings(bindings)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn apply_uniforms(stage int, ub_index int, data voidptr, num_bytes int) {
|
||||
C.sg_apply_uniforms(stage, ub_index, data, num_bytes)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn draw(base_element int, num_elements int, num_instances int) {
|
||||
C.sg_draw(base_element, num_elements, num_instances)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn end_pass() {
|
||||
C.sg_end_pass()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn commit() {
|
||||
C.sg_commit()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_buffer_overflow(buf C.sg_buffer) bool {
|
||||
return C.sg_query_buffer_overflow(buf)
|
||||
}
|
||||
|
||||
// get runtime information about a resource
|
||||
[inline]
|
||||
pub fn query_buffer_info(buf C.sg_buffer) C.sg_buffer_info {
|
||||
return C.sg_query_buffer_info(buf)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_image_info(img C.sg_image) C.sg_image_info {
|
||||
return C.sg_query_image_info(img)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_shader_info(shd C.sg_shader) C.sg_shader_info {
|
||||
return C.sg_query_shader_info(shd)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_pipeline_info(pip C.sg_pipeline) C.sg_pipeline_info {
|
||||
return C.sg_query_pipeline_info(pip)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_pass_info(pass C.sg_pass) C.sg_pass_info {
|
||||
return C.sg_query_pass_info(pass)
|
||||
}
|
||||
|
||||
// getting information
|
||||
[inline]
|
||||
pub fn query_desc() C.sg_desc {
|
||||
return C.sg_query_desc()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_backend() Backend {
|
||||
return C.sg_query_backend()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_features() C.sg_features {
|
||||
return C.sg_query_features()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_limits() C.sg_limits {
|
||||
return C.sg_query_limits()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info {
|
||||
return C.sg_query_pixelformat(fmt)
|
||||
}
|
||||
|
||||
// get resource creation desc struct with their default values replaced
|
||||
[inline]
|
||||
pub fn query_buffer_defaults(desc &C.sg_buffer) C.sg_buffer_desc {
|
||||
return C.sg_query_buffer_defaults(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_image_defaults(desc &C.sg_image) C.sg_image_desc {
|
||||
return C.sg_query_image_defaults(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_shader_defaults(desc &C.sg_shader) C.sg_shader_desc {
|
||||
return C.sg_query_shader_defaults(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_pipeline_defaults(desc &C.sg_pipeline) C.sg_pipeline_desc {
|
||||
return C.sg_query_pipeline_defaults(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn query_pass_defaults(desc &C.sg_pass) C.sg_pass_desc {
|
||||
return C.sg_query_pass_defaults(desc)
|
||||
}
|
||||
|
56
vlib/sokol/gfx/gfx_funcs.v
Normal file
56
vlib/sokol/gfx/gfx_funcs.v
Normal file
@ -0,0 +1,56 @@
|
||||
module gfx
|
||||
|
||||
// setup and misc functions
|
||||
fn C.sg_setup(desc &C.sg_desc)
|
||||
fn C.sg_shutdown()
|
||||
fn C.sg_reset_state_cache()
|
||||
|
||||
// resource creation, destruction and updating
|
||||
fn C.sg_make_buffer(desc &C.sg_buffer_desc) C.sg_buffer
|
||||
fn C.sg_make_image(desc &C.sg_image_desc) C.sg_image
|
||||
fn C.sg_make_shader(desc &C.sg_shader_desc) C.sg_shader
|
||||
fn C.sg_make_pipeline(desc &C.sg_pipeline_desc) C.sg_pipeline
|
||||
fn C.sg_make_pass(desc &C.sg_pass_desc) C.sg_pass
|
||||
fn C.sg_destroy_buffer(buf C.sg_buffer)
|
||||
fn C.sg_destroy_image(img C.sg_image)
|
||||
fn C.sg_destroy_shader(shd C.sg_shader)
|
||||
fn C.sg_destroy_pipeline(pip C.sg_pipeline)
|
||||
fn C.sg_destroy_pass(pass C.sg_pass)
|
||||
fn C.sg_update_buffer(buf C.sg_buffer, ptr voidptr, num_bytes int)
|
||||
fn C.sg_update_image(img C.sg_image, content &C.sg_image_content)
|
||||
fn C.sg_append_buffer(buf C.sg_buffer, ptr voidptr, num_bytes int) int
|
||||
|
||||
// rendering functions
|
||||
fn C.sg_begin_default_pass(actions &C.sg_pass_action, width int, height int)
|
||||
fn C.sg_begin_pass(pass C.sg_pass, actions &C.sg_pass_action)
|
||||
fn C.sg_apply_viewport(x int, y int, width int, height int, origin_top_left bool)
|
||||
fn C.sg_apply_scissor_rect(x int, y int, width int, height int, origin_top_left bool)
|
||||
fn C.sg_apply_pipeline(pip C.sg_pipeline)
|
||||
fn C.sg_apply_bindings(bindings &C.sg_bindings)
|
||||
fn C.sg_apply_uniforms(stage int /*sg_shader_stage*/, ub_index int, data voidptr, num_bytes int)
|
||||
fn C.sg_draw(base_element int, num_elements int, num_instances int)
|
||||
fn C.sg_end_pass()
|
||||
fn C.sg_commit()
|
||||
|
||||
fn C.sg_query_buffer_overflow(buf C.sg_buffer) bool
|
||||
|
||||
// get runtime information about a resource
|
||||
fn C.sg_query_buffer_info(buf C.sg_buffer) C.sg_buffer_info
|
||||
fn C.sg_query_image_info(img C.sg_image) C.sg_image_info
|
||||
fn C.sg_query_shader_info(shd C.sg_shader) C.sg_shader_info
|
||||
fn C.sg_query_pipeline_info(pip C.sg_pipeline) C.sg_pipeline_info
|
||||
fn C.sg_query_pass_info(pass C.sg_pass) C.sg_pass_info
|
||||
|
||||
// getting information
|
||||
fn C.sg_query_desc() C.sg_desc
|
||||
fn C.sg_query_backend() Backend
|
||||
fn C.sg_query_features() C.sg_features
|
||||
fn C.sg_query_limits() C.sg_limits
|
||||
fn C.sg_query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info
|
||||
|
||||
// get resource creation desc struct with their default values replaced
|
||||
fn C.sg_query_buffer_defaults(desc &C.sg_buffer) C.sg_buffer_desc
|
||||
fn C.sg_query_image_defaults(desc &C.sg_image) C.sg_image_desc
|
||||
fn C.sg_query_shader_defaults(desc &C.sg_shader) C.sg_shader_desc
|
||||
fn C.sg_query_pipeline_defaults(desc &C.sg_pipeline) C.sg_pipeline_desc
|
||||
fn C.sg_query_pass_defaults(desc &C.sg_pass) C.sg_pass_desc
|
460
vlib/sokol/gfx/gfx_structs.v
Normal file
460
vlib/sokol/gfx/gfx_structs.v
Normal file
@ -0,0 +1,460 @@
|
||||
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
|
||||
/* GL specific */
|
||||
gl_force_gles2 bool
|
||||
/* Metal-specific */
|
||||
mtl_device voidptr
|
||||
mtl_renderpass_descriptor_cb fn() voidptr
|
||||
mtl_drawable_cb fn() voidptr
|
||||
mtl_global_uniform_buffer_size int
|
||||
mtl_sampler_cache_size int
|
||||
/* D3D11-specific */
|
||||
d3d11_device voidptr
|
||||
d3d11_device_context voidptr
|
||||
d3d11_render_target_view_cb fn() voidptr
|
||||
d3d11_depth_stencil_view_cb fn() voidptr
|
||||
_end_canary u32
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
pub struct C.sg_pipeline_info {
|
||||
|
||||
}
|
||||
|
||||
pub struct C.sg_pipeline {
|
||||
pub:
|
||||
id u32
|
||||
}
|
||||
pub fn (p C.sg_pipeline) free() { sg_destroy_pipeline(p) }
|
||||
|
||||
|
||||
pub struct C.sg_bindings {
|
||||
pub mut:
|
||||
_start_canary u32
|
||||
vertex_buffers [8]sg_buffer
|
||||
vertex_buffer_offsets [8]int
|
||||
index_buffer sg_buffer
|
||||
index_buffer_offset int
|
||||
vs_images [8]sg_image
|
||||
fs_images [8]sg_image
|
||||
_end_canary u32
|
||||
}
|
||||
|
||||
pub fn (b mut sg_bindings) set_vert_image(index int, img C.sg_image) {
|
||||
b.vs_images[index] = img
|
||||
}
|
||||
|
||||
pub fn (b mut sg_bindings) set_frag_image(index int, img C.sg_image) {
|
||||
b.fs_images[index] = img
|
||||
}
|
||||
|
||||
pub fn (b &C.sg_bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) {
|
||||
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 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) {
|
||||
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 sg_append_buffer(b.index_buffer, data, element_size * element_count)
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_shader_desc {
|
||||
pub mut:
|
||||
_start_canary u32
|
||||
attrs [16]sg_shader_attr_desc
|
||||
vs C.sg_shader_stage_desc
|
||||
fs C.sg_shader_stage_desc
|
||||
label byteptr
|
||||
_end_canary u32
|
||||
}
|
||||
|
||||
pub fn (desc mut C.sg_shader_desc) set_vert_src(src string) &C.sg_shader_desc {
|
||||
desc.vs.source = src.str
|
||||
return desc
|
||||
}
|
||||
|
||||
pub fn (desc mut C.sg_shader_desc) set_frag_src(src string) &C.sg_shader_desc {
|
||||
desc.fs.source = src.str
|
||||
return desc
|
||||
}
|
||||
|
||||
pub fn (desc mut 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
|
||||
}
|
||||
|
||||
pub fn (desc mut 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
|
||||
}
|
||||
|
||||
pub fn (desc mut 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 (desc mut 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 (desc mut 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].@type = @type
|
||||
return desc
|
||||
}
|
||||
|
||||
pub fn (desc mut 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].@type = @type
|
||||
return desc
|
||||
}
|
||||
|
||||
pub fn (desc &C.sg_shader_desc) make_shader() C.sg_shader {
|
||||
return 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 */
|
||||
}
|
||||
|
||||
pub struct C.sg_shader_stage_desc {
|
||||
pub mut:
|
||||
source byteptr
|
||||
byte_code &byte
|
||||
byte_code_size int
|
||||
entry byteptr
|
||||
uniform_blocks [4]sg_shader_uniform_block_desc
|
||||
images [12]sg_shader_image_desc
|
||||
}
|
||||
|
||||
pub fn (desc mut 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
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_shader_uniform_block_desc {
|
||||
pub mut:
|
||||
size int
|
||||
uniforms [16]sg_shader_uniform_desc
|
||||
}
|
||||
|
||||
pub struct C.sg_shader_uniform_desc {
|
||||
pub mut:
|
||||
name byteptr
|
||||
@type UniformType
|
||||
array_count int
|
||||
}
|
||||
|
||||
pub struct C.sg_shader_image_desc {
|
||||
pub mut:
|
||||
name byteptr
|
||||
@type ImageType
|
||||
}
|
||||
|
||||
pub struct C.sg_shader_info {}
|
||||
|
||||
pub struct C.sg_context {
|
||||
id u32
|
||||
}
|
||||
|
||||
pub struct C.sg_shader {
|
||||
pub:
|
||||
id u32
|
||||
}
|
||||
pub fn (s C.sg_shader) free() { sg_destroy_shader(s) }
|
||||
|
||||
|
||||
pub struct C.sg_pass_desc {
|
||||
pub mut:
|
||||
_start_canary u32
|
||||
color_attachments [4]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
|
||||
}
|
||||
|
||||
pub struct C.sg_pass_action {
|
||||
pub mut:
|
||||
_start_canary u32
|
||||
colors [4]sg_color_attachment_action
|
||||
depth sg_depth_attachment_action
|
||||
stencil sg_stencil_attachment_action
|
||||
_end_canary u32
|
||||
}
|
||||
|
||||
pub struct C.sg_pass {
|
||||
id u32
|
||||
}
|
||||
pub fn (p C.sg_pass) free() { 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
|
||||
}
|
||||
|
||||
pub struct C.sg_buffer_info {}
|
||||
|
||||
pub struct C.sg_buffer {
|
||||
id u32
|
||||
}
|
||||
pub fn (b C.sg_buffer) free() { sg_destroy_buffer(b) }
|
||||
|
||||
|
||||
pub union 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
|
||||
}
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
pub struct C.sg_image {
|
||||
pub:
|
||||
id u32
|
||||
}
|
||||
pub fn (i C.sg_image) free() { sg_destroy_image(i) }
|
||||
|
||||
|
||||
pub struct C.sg_image_content {
|
||||
pub mut:
|
||||
subimage [6][16]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 */
|
||||
}
|
||||
|
||||
pub struct C.sg_features {
|
||||
pub:
|
||||
instancing bool
|
||||
origin_top_left bool
|
||||
multiple_render_targets bool
|
||||
msaa_render_targets bool
|
||||
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_image_array_layers u32
|
||||
max_vertex_attrs u32 /* <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls) */
|
||||
}
|
||||
|
||||
pub struct C.sg_layout_desc {
|
||||
pub mut:
|
||||
buffers [8]sg_buffer_layout_desc
|
||||
attrs [16]sg_vertex_attr_desc
|
||||
}
|
||||
|
||||
pub struct C.sg_buffer_layout_desc {
|
||||
pub mut:
|
||||
stride int
|
||||
step_func VertexStep
|
||||
step_rate int
|
||||
}
|
||||
|
||||
pub struct C.sg_vertex_attr_desc {
|
||||
pub mut:
|
||||
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
|
||||
}
|
||||
|
||||
pub struct C.sg_stencil_state {
|
||||
fail_op StencilOp
|
||||
depth_fail_op StencilOp
|
||||
pass_op StencilOp
|
||||
compare_func CompareFunc
|
||||
}
|
||||
|
||||
pub struct C.sg_blend_state {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_color_attachment_action {
|
||||
pub mut:
|
||||
action Action
|
||||
val [4]f32
|
||||
}
|
||||
|
||||
pub fn (action mut C.sg_color_attachment_action) set_color_values(r, g, b, a f32) {
|
||||
action.val[0] = r
|
||||
action.val[1] = g
|
||||
action.val[2] = b
|
||||
action.val[3] = a
|
||||
}
|
||||
|
||||
pub struct C.sg_depth_attachment_action {
|
||||
pub mut:
|
||||
action Action
|
||||
val f32
|
||||
}
|
||||
|
||||
pub struct C.sg_stencil_attachment_action {
|
||||
pub mut:
|
||||
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 */
|
||||
}
|
||||
|
||||
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
|
||||
// }
|
||||
}
|
12
vlib/sokol/gfx/gfx_utils.v
Normal file
12
vlib/sokol/gfx/gfx_utils.v
Normal file
@ -0,0 +1,12 @@
|
||||
module gfx
|
||||
|
||||
pub fn create_clear_pass(r, g, b, a f32) C.sg_pass_action {
|
||||
mut color_action := sg_color_attachment_action {
|
||||
action: C.SG_ACTION_CLEAR
|
||||
}
|
||||
color_action.set_color_values(r, g, b, a)
|
||||
|
||||
mut pass_action := sg_pass_action{}
|
||||
pass_action.colors[0] = color_action
|
||||
return pass_action
|
||||
}
|
158
vlib/sokol/sapp/enums.v
Normal file
158
vlib/sokol/sapp/enums.v
Normal file
@ -0,0 +1,158 @@
|
||||
module sapp
|
||||
|
||||
pub enum EventType {
|
||||
invalid
|
||||
key_down
|
||||
key_up
|
||||
char
|
||||
mouse_down
|
||||
mouse_up
|
||||
mouse_scroll
|
||||
mouse_move
|
||||
mouse_enter
|
||||
mouse_leave
|
||||
touches_began
|
||||
touches_moved
|
||||
touches_ended
|
||||
touches_cancelled
|
||||
resized
|
||||
iconified
|
||||
restored
|
||||
suspended
|
||||
resumed
|
||||
update_cursor
|
||||
quit_requested
|
||||
clipboard_pasted
|
||||
num
|
||||
}
|
||||
|
||||
pub enum MouseButton {
|
||||
invalid = -1
|
||||
left = 0
|
||||
right = 1
|
||||
middle = 2
|
||||
}
|
||||
|
||||
pub enum KeyCode {
|
||||
invalid = 0
|
||||
space = 32
|
||||
apostrophe = 39 /* ' */
|
||||
comma = 44 /* , */
|
||||
minus = 45 /* - */
|
||||
period = 46 /* . */
|
||||
slash = 47 /* / */
|
||||
_0 = 48
|
||||
_1 = 49
|
||||
_2 = 50
|
||||
_3 = 51
|
||||
_4 = 52
|
||||
_5 = 53
|
||||
_6 = 54
|
||||
_7 = 55
|
||||
_8 = 56
|
||||
_9 = 57
|
||||
semicolon = 59 /* ; */
|
||||
equal = 61 /* = */
|
||||
a = 65
|
||||
b = 66
|
||||
c = 67
|
||||
d = 68
|
||||
e = 69
|
||||
f = 70
|
||||
g = 71
|
||||
h = 72
|
||||
i = 73
|
||||
j = 74
|
||||
k = 75
|
||||
l = 76
|
||||
m = 77
|
||||
n = 78
|
||||
o = 79
|
||||
p = 80
|
||||
q = 81
|
||||
r = 82
|
||||
s = 83
|
||||
t = 84
|
||||
u = 85
|
||||
v = 86
|
||||
w = 87
|
||||
x = 88
|
||||
y = 89
|
||||
z = 90
|
||||
left_bracket = 91 /* [ */
|
||||
backslash = 92 /* \ */
|
||||
right_bracket = 93 /* ] */
|
||||
grave_accent = 96 /* ` */
|
||||
world_1 = 161 /* non-us #1 */
|
||||
world_2 = 162 /* non-us #2 */
|
||||
escape = 256
|
||||
enter = 257
|
||||
tab = 258
|
||||
backspace = 259
|
||||
insert = 260
|
||||
delete = 261
|
||||
right = 262
|
||||
left = 263
|
||||
down = 264
|
||||
up = 265
|
||||
page_up = 266
|
||||
page_down = 267
|
||||
home = 268
|
||||
end = 269
|
||||
caps_lock = 280
|
||||
scroll_lock = 281
|
||||
num_lock = 282
|
||||
print_screen = 283
|
||||
pause = 284
|
||||
f1 = 290
|
||||
f2 = 291
|
||||
f3 = 292
|
||||
f4 = 293
|
||||
f5 = 294
|
||||
f6 = 295
|
||||
f7 = 296
|
||||
f8 = 297
|
||||
f9 = 298
|
||||
f10 = 299
|
||||
f11 = 300
|
||||
f12 = 301
|
||||
f13 = 302
|
||||
f14 = 303
|
||||
f15 = 304
|
||||
f16 = 305
|
||||
f17 = 306
|
||||
f18 = 307
|
||||
f19 = 308
|
||||
f20 = 309
|
||||
f21 = 310
|
||||
f22 = 311
|
||||
f23 = 312
|
||||
f24 = 313
|
||||
f25 = 314
|
||||
kp_0 = 320
|
||||
kp_1 = 321
|
||||
kp_2 = 322
|
||||
kp_3 = 323
|
||||
kp_4 = 324
|
||||
kp_5 = 325
|
||||
kp_6 = 326
|
||||
kp_7 = 327
|
||||
kp_8 = 328
|
||||
kp_9 = 329
|
||||
kp_decimal = 330
|
||||
kp_divide = 331
|
||||
kp_multiply = 332
|
||||
kp_subtract = 333
|
||||
kp_add = 334
|
||||
kp_enter = 335
|
||||
kp_equal = 336
|
||||
left_shift = 340
|
||||
left_control = 341
|
||||
left_alt = 342
|
||||
left_super = 343
|
||||
right_shift = 344
|
||||
right_control = 345
|
||||
right_alt = 346
|
||||
right_super = 347
|
||||
menu = 348
|
||||
}
|
188
vlib/sokol/sapp/sapp.v
Normal file
188
vlib/sokol/sapp/sapp.v
Normal file
@ -0,0 +1,188 @@
|
||||
module sapp
|
||||
|
||||
/* returns true after sokol-app has been initialized */
|
||||
[inline]
|
||||
pub fn isvalid() bool {
|
||||
return C.sapp_isvalid()
|
||||
}
|
||||
|
||||
/* returns the current framebuffer width in pixels */
|
||||
[inline]
|
||||
pub fn width() int {
|
||||
return C.sapp_width()
|
||||
}
|
||||
|
||||
/* returns the current framebuffer height in pixels */
|
||||
[inline]
|
||||
pub fn height() int {
|
||||
return C.sapp_height()
|
||||
}
|
||||
|
||||
/* returns true when high_dpi was requested and actually running in a high-dpi scenario */
|
||||
[inline]
|
||||
pub fn high_dpi() bool {
|
||||
return C.sapp_high_dpi()
|
||||
}
|
||||
|
||||
/* returns the dpi scaling factor (window pixels to framebuffer pixels) */
|
||||
[inline]
|
||||
pub fn dpi_scale() f32 {
|
||||
return C.sapp_dpi_scale()
|
||||
}
|
||||
|
||||
/* show or hide the mobile device onscreen keyboard */
|
||||
[inline]
|
||||
pub fn show_keyboard(visible bool) {
|
||||
C.sapp_show_keyboard(visible)
|
||||
}
|
||||
|
||||
/* return true if the mobile device onscreen keyboard is currently shown */
|
||||
[inline]
|
||||
pub fn keyboard_shown() bool {
|
||||
return C.sapp_keyboard_shown()
|
||||
}
|
||||
|
||||
/* show or hide the mouse cursor */
|
||||
[inline]
|
||||
pub fn show_mouse(visible bool) {
|
||||
C.sapp_show_mouse(visible)
|
||||
}
|
||||
|
||||
/* show or hide the mouse cursor */
|
||||
[inline]
|
||||
pub fn mouse_shown() bool {
|
||||
return C.sapp_mouse_shown()
|
||||
}
|
||||
|
||||
/* return the userdata pointer optionally provided in sapp_desc */
|
||||
[inline]
|
||||
pub fn userdata() voidptr {
|
||||
return C.sapp_userdata()
|
||||
}
|
||||
|
||||
/* return a copy of the sapp_desc structure */
|
||||
[inline]
|
||||
pub fn query_desc() C.sapp_desc {
|
||||
return C.sapp_query_desc()
|
||||
}
|
||||
|
||||
/* initiate a "soft quit" (sends SAPP_EVENTTYPE_QUIT_REQUESTED) */
|
||||
[inline]
|
||||
pub fn request_quit() {
|
||||
C.sapp_request_quit()
|
||||
}
|
||||
|
||||
/* cancel a pending quit (when SAPP_EVENTTYPE_QUIT_REQUESTED has been received) */
|
||||
[inline]
|
||||
pub fn cancel_quit() {
|
||||
C.sapp_cancel_quit()
|
||||
}
|
||||
|
||||
/* intiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUSTED) */
|
||||
[inline]
|
||||
pub fn quit() {
|
||||
C.sapp_quit()
|
||||
}
|
||||
|
||||
/* call from inside event callback to consume the current event (don't forward to platform) */
|
||||
[inline]
|
||||
pub fn consume_event() {
|
||||
C.sapp_consume_event()
|
||||
}
|
||||
|
||||
/* get the current frame counter (for comparison with sapp_event.frame_count) */
|
||||
[inline]
|
||||
pub fn frame_count() u64 {
|
||||
return C.sapp_frame_count()
|
||||
}
|
||||
|
||||
/* write string into clipboard */
|
||||
[inline]
|
||||
pub fn set_clipboard_string(str byteptr) {
|
||||
C.sapp_set_clipboard_string(str)
|
||||
}
|
||||
|
||||
/* read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED) */
|
||||
[inline]
|
||||
pub fn get_clipboard_string() byteptr {
|
||||
return C.sapp_get_clipboard_string()
|
||||
}
|
||||
|
||||
/* special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub) */
|
||||
[inline]
|
||||
pub fn run(desc &C.sapp_desc) int {
|
||||
return C.sapp_run(desc)
|
||||
}
|
||||
|
||||
/* GL: return true when GLES2 fallback is active (to detect fallback from GLES3) */
|
||||
[inline]
|
||||
pub fn gles2() bool {
|
||||
return C.sapp_gles2()
|
||||
}
|
||||
|
||||
/* HTML5: enable or disable the hardwired "Leave Site?" dialog box */
|
||||
[inline]
|
||||
pub fn html5_ask_leave_site(ask bool) {
|
||||
C.sapp_html5_ask_leave_site(ask)
|
||||
}
|
||||
|
||||
/* Metal: get ARC-bridged pointer to Metal device object */
|
||||
[inline]
|
||||
pub fn metal_get_device() voidptr {
|
||||
return C.sapp_metal_get_device()
|
||||
}
|
||||
|
||||
/* Metal: get ARC-bridged pointer to this frame's renderpass descriptor */
|
||||
[inline]
|
||||
pub fn metal_get_renderpass_descriptor() voidptr {
|
||||
return C.sapp_metal_get_renderpass_descriptor()
|
||||
}
|
||||
|
||||
/* Metal: get ARC-bridged pointer to current drawable */
|
||||
[inline]
|
||||
pub fn metal_get_drawable() voidptr {
|
||||
return C.sapp_metal_get_drawable()
|
||||
}
|
||||
|
||||
/* macOS: get ARC-bridged pointer to macOS NSWindow */
|
||||
[inline]
|
||||
pub fn macos_get_window() voidptr {
|
||||
return C.sapp_macos_get_window()
|
||||
}
|
||||
|
||||
/* iOS: get ARC-bridged pointer to iOS UIWindow */
|
||||
[inline]
|
||||
pub fn ios_get_window() voidptr {
|
||||
return C.sapp_ios_get_window()
|
||||
}
|
||||
|
||||
/* D3D11: get pointer to ID3D11Device object */
|
||||
[inline]
|
||||
pub fn d3d11_get_device() voidptr {
|
||||
return C.sapp_d3d11_get_device()
|
||||
}
|
||||
|
||||
/* D3D11: get pointer to ID3D11DeviceContext object */
|
||||
[inline]
|
||||
pub fn d3d11_get_device_context() voidptr {
|
||||
return C.sapp_d3d11_get_device_context()
|
||||
}
|
||||
|
||||
/* D3D11: get pointer to ID3D11RenderTargetView object */
|
||||
[inline]
|
||||
pub fn d3d11_get_render_target_view() voidptr {
|
||||
return C.sapp_d3d11_get_render_target_view()
|
||||
}
|
||||
|
||||
/* D3D11: get pointer to ID3D11DepthStencilView */
|
||||
[inline]
|
||||
pub fn d3d11_get_depth_stencil_view() voidptr {
|
||||
return C.sapp_d3d11_get_depth_stencil_view()
|
||||
}
|
||||
|
||||
/* Win32: get the HWND window handle */
|
||||
[inline]
|
||||
pub fn win32_get_hwnd() voidptr {
|
||||
return C.sapp_win32_get_hwnd()
|
||||
}
|
||||
|
69
vlib/sokol/sapp/sapp_funcs.v
Normal file
69
vlib/sokol/sapp/sapp_funcs.v
Normal file
@ -0,0 +1,69 @@
|
||||
module sapp
|
||||
|
||||
/* returns true after sokol-app has been initialized */
|
||||
fn C.sapp_isvalid() bool
|
||||
/* returns the current framebuffer width in pixels */
|
||||
fn C.sapp_width() int
|
||||
/* returns the current framebuffer height in pixels */
|
||||
fn C.sapp_height() int
|
||||
/* returns true when high_dpi was requested and actually running in a high-dpi scenario */
|
||||
fn C.sapp_high_dpi() bool
|
||||
/* returns the dpi scaling factor (window pixels to framebuffer pixels) */
|
||||
fn C.sapp_dpi_scale() f32
|
||||
/* show or hide the mobile device onscreen keyboard */
|
||||
fn C.sapp_show_keyboard(visible bool)
|
||||
/* return true if the mobile device onscreen keyboard is currently shown */
|
||||
fn C.sapp_keyboard_shown() bool
|
||||
/* show or hide the mouse cursor */
|
||||
fn C.sapp_show_mouse(visible bool)
|
||||
/* show or hide the mouse cursor */
|
||||
fn C.sapp_mouse_shown() bool
|
||||
/* return the userdata pointer optionally provided in sapp_desc */
|
||||
fn C.sapp_userdata() voidptr
|
||||
/* return a copy of the sapp_desc structure */
|
||||
fn C.sapp_query_desc() C.sapp_desc
|
||||
/* initiate a "soft quit" (sends SAPP_EVENTTYPE_QUIT_REQUESTED) */
|
||||
fn C.sapp_request_quit()
|
||||
/* cancel a pending quit (when SAPP_EVENTTYPE_QUIT_REQUESTED has been received) */
|
||||
fn C.sapp_cancel_quit()
|
||||
/* intiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUSTED) */
|
||||
fn C.sapp_quit()
|
||||
/* call from inside event callback to consume the current event (don't forward to platform) */
|
||||
fn C.sapp_consume_event()
|
||||
/* get the current frame counter (for comparison with sapp_event.frame_count) */
|
||||
fn C.sapp_frame_count() u64
|
||||
/* write string into clipboard */
|
||||
fn C.sapp_set_clipboard_string(str byteptr)
|
||||
/* read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED) */
|
||||
fn C.sapp_get_clipboard_string() byteptr
|
||||
|
||||
/* special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub) */
|
||||
fn C.sapp_run(desc &C.sapp_desc) int
|
||||
|
||||
/* GL: return true when GLES2 fallback is active (to detect fallback from GLES3) */
|
||||
fn C.sapp_gles2() bool
|
||||
|
||||
/* HTML5: enable or disable the hardwired "Leave Site?" dialog box */
|
||||
fn C.sapp_html5_ask_leave_site(ask bool)
|
||||
|
||||
/* Metal: get ARC-bridged pointer to Metal device object */
|
||||
fn C.sapp_metal_get_device() voidptr
|
||||
/* Metal: get ARC-bridged pointer to this frame's renderpass descriptor */
|
||||
fn C.sapp_metal_get_renderpass_descriptor() voidptr
|
||||
/* Metal: get ARC-bridged pointer to current drawable */
|
||||
fn C.sapp_metal_get_drawable() voidptr
|
||||
/* macOS: get ARC-bridged pointer to macOS NSWindow */
|
||||
fn C.sapp_macos_get_window() voidptr
|
||||
/* iOS: get ARC-bridged pointer to iOS UIWindow */
|
||||
fn C.sapp_ios_get_window() voidptr
|
||||
|
||||
/* D3D11: get pointer to ID3D11Device object */
|
||||
fn C.sapp_d3d11_get_device() voidptr
|
||||
/* D3D11: get pointer to ID3D11DeviceContext object */
|
||||
fn C.sapp_d3d11_get_device_context() voidptr
|
||||
/* D3D11: get pointer to ID3D11RenderTargetView object */
|
||||
fn C.sapp_d3d11_get_render_target_view() voidptr
|
||||
/* D3D11: get pointer to ID3D11DepthStencilView */
|
||||
fn C.sapp_d3d11_get_depth_stencil_view() voidptr
|
||||
/* Win32: get the HWND window handle */
|
||||
fn C.sapp_win32_get_hwnd() voidptr
|
69
vlib/sokol/sapp/sapp_structs.v
Normal file
69
vlib/sokol/sapp/sapp_structs.v
Normal file
@ -0,0 +1,69 @@
|
||||
module sapp
|
||||
|
||||
pub struct C.sapp_desc {
|
||||
pub:
|
||||
init_cb fn() /* these are the user-provided callbacks without user data */
|
||||
frame_cb fn()
|
||||
cleanup_cb fn()
|
||||
event_cb fn( voidptr) //&sapp_event)
|
||||
fail_cb fn(byteptr)
|
||||
|
||||
user_data voidptr /* these are the user-provided callbacks with user data */
|
||||
init_userdata_cb fn(voidptr)
|
||||
frame_userdata_cb fn(voidptr)
|
||||
cleanup_userdata_cb fn(voidptr)
|
||||
event_userdata_cb fn(&C.sapp_event, voidptr)
|
||||
fail_userdata_cb fn(voidptr)
|
||||
|
||||
width int /* the preferred width of the window / canvas */
|
||||
height int /* the preferred height of the window / canvas */
|
||||
sample_count int /* MSAA sample count */
|
||||
swap_interval int /* the preferred swap interval (ignored on some platforms) */
|
||||
high_dpi bool /* whether the rendering canvas is full-resolution on HighDPI displays */
|
||||
fullscreen bool /* whether the window should be created in fullscreen mode */
|
||||
alpha bool /* whether the framebuffer should have an alpha channel (ignored on some platforms) */
|
||||
window_title byteptr /* the window title as UTF-8 encoded string */
|
||||
user_cursor bool /* if true, user is expected to manage cursor image in SAPP_EVENTTYPE_UPDATE_CURSOR */
|
||||
enable_clipboard bool /* enable clipboard access, default is false */
|
||||
clipboard_size int /* max size of clipboard content in bytes */
|
||||
|
||||
html5_canvas_name byteptr /* the name (id) of the HTML5 canvas element, default is "canvas" */
|
||||
html5_canvas_resize bool /* if true, the HTML5 canvas size is set to sapp_desc.width/height, otherwise canvas size is tracked */
|
||||
html5_preserve_drawing_buffer bool /* HTML5 only: whether to preserve default framebuffer content between frames */
|
||||
html5_premultiplied_alpha bool /* HTML5 only: whether the rendered pixels use premultiplied alpha convention */
|
||||
html5_ask_leave_site bool /* initial state of the internal html5_ask_leave_site flag (see sapp_html5_ask_leave_site()) */
|
||||
ios_keyboard_resizes_canvas bool /* if true, showing the iOS keyboard shrinks the canvas */
|
||||
gl_force_gles2 bool /* if true, setup GLES2/WebGL even if GLES3/WebGL2 is available */
|
||||
}
|
||||
|
||||
pub struct C.sapp_event {
|
||||
pub:
|
||||
frame_count u64
|
||||
@type EventType
|
||||
key_code KeyCode
|
||||
char_code u32
|
||||
key_repeat bool
|
||||
modifiers u32
|
||||
mouse_button MouseButton
|
||||
mouse_x f32
|
||||
mouse_y f32
|
||||
scroll_x f32
|
||||
scroll_y f32
|
||||
num_touches int
|
||||
touches [8]sapp_touchpoint
|
||||
window_width int
|
||||
window_height int
|
||||
framebuffer_width int
|
||||
framebuffer_height int
|
||||
}
|
||||
pub fn (e &C.sapp_event) str() string {
|
||||
return 'evt: frame_count=$e.frame_count, type=${e.@type}'
|
||||
}
|
||||
|
||||
pub struct C.sapp_touchpoint {
|
||||
pub:
|
||||
identifier u64
|
||||
pos_x f32
|
||||
pos_y f32
|
||||
changed bool
|
||||
}
|
25
vlib/sokol/sfons/sfons.v
Normal file
25
vlib/sokol/sfons/sfons.v
Normal file
@ -0,0 +1,25 @@
|
||||
module sfons
|
||||
import fontstash
|
||||
|
||||
#flag -I fontstash/thirdparty
|
||||
|
||||
[inline]
|
||||
pub fn sfons_create(width int, height int, flags int) &C.FONScontext {
|
||||
return C.sfons_create(width, height, flags)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn sfons_destroy(ctx &C.FONScontext) {
|
||||
C.sfons_destroy(ctx)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn sfons_rgba(r byte, g byte, b byte, a byte) u32 {
|
||||
return C.sfons_rgba(r, g, b, a)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn sfons_flush(ctx &C.FONScontext) {
|
||||
C.sfons_flush(ctx)
|
||||
}
|
||||
|
6
vlib/sokol/sfons/sfons_funcs.v
Normal file
6
vlib/sokol/sfons/sfons_funcs.v
Normal file
@ -0,0 +1,6 @@
|
||||
module sfons
|
||||
|
||||
fn C.sfons_create(width int, height int, flags int) &C.FONScontext
|
||||
fn C.sfons_destroy(ctx &FONScontext)
|
||||
fn C.sfons_rgba(r byte, g byte, b byte, a byte) u32
|
||||
fn C.sfons_flush(ctx &FONScontext)
|
371
vlib/sokol/sgl/sgl.v
Normal file
371
vlib/sokol/sgl/sgl.v
Normal file
@ -0,0 +1,371 @@
|
||||
module sgl
|
||||
|
||||
|
||||
/* 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()
|
||||
}
|
||||
|
89
vlib/sokol/sgl/sgl_funcs.v
Normal file
89
vlib/sokol/sgl/sgl_funcs.v
Normal file
@ -0,0 +1,89 @@
|
||||
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_scissor_rect(x int, y int, w int, h int, 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 []f32) // should be [16]f32
|
||||
fn C.sgl_load_transpose_matrix(m []f32) // should be [16]f32
|
||||
fn C.sgl_mult_matrix(m []f32)
|
||||
fn C.sgl_mult_transpose_matrix(m []f32) // should be [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()
|
24
vlib/sokol/sgl/sgl_structs.v
Normal file
24
vlib/sokol/sgl/sgl_structs.v
Normal file
@ -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 */
|
||||
}
|
39
vlib/sokol/sokol.v
Normal file
39
vlib/sokol/sokol.v
Normal file
@ -0,0 +1,39 @@
|
||||
module sokol
|
||||
|
||||
#flag -I @VROOT/thirdparty/sokol
|
||||
#flag -I @VROOT/thirdparty/sokol/util
|
||||
|
||||
#flag darwin -fobjc-arc
|
||||
#flag linux -lX11 -lGL
|
||||
|
||||
#flag darwin -I/usr/local/Cellar/freetype/2.10.0/include/freetype2/
|
||||
#flag -lfreetype
|
||||
|
||||
|
||||
// METAL
|
||||
// #flag -DSOKOL_METAL
|
||||
// #flag darwin -framework Metal -framework Cocoa -framework MetalKit -framework QuartzCore
|
||||
|
||||
// OPENGL
|
||||
#flag -DSOKOL_GLCORE33
|
||||
#flag darwin -framework OpenGL -framework Cocoa -framework QuartzCore
|
||||
|
||||
|
||||
// for simplicity, all header includes are here because import order matters and we dont have any way
|
||||
// to ensure import order with V yet
|
||||
#define SOKOL_IMPL
|
||||
#define SOKOL_NO_ENTRY
|
||||
#include "sokol_app.h"
|
||||
|
||||
#define SOKOL_IMPL
|
||||
#define SOKOL_NO_DEPRECATED
|
||||
#include "sokol_gfx.h"
|
||||
|
||||
#define SOKOL_GL_IMPL
|
||||
#include "util/sokol_gl.h"
|
||||
|
||||
#define FONS_USE_FREETYPE
|
||||
#define FONTSTASH_IMPLEMENTATION
|
||||
#include "fontstash.h"
|
||||
#define SOKOL_FONTSTASH_IMPL
|
||||
#include "util/sokol_fontstash.h"
|
Loading…
Reference in New Issue
Block a user