sokol: upgrade to latest version, fix all related issues

This commit is contained in:
Alexander Medvednikov 2023-10-05 20:22:41 +03:00
parent 756075380b
commit 0bf85d049e
36 changed files with 8304 additions and 8096 deletions

View file

@ -101,7 +101,7 @@ jobs:
- name: Shader examples can be build
run: |
wget https://github.com/floooh/sokol-tools-bin/raw/33d2e4cc26088c6c28eaef5467990f8940d15aab/bin/linux/sokol-shdc
wget https://github.com/floooh/sokol-tools-bin/raw/6040b18d39649d56dbae2ae1aed59fb755b26369/bin/linux/sokol-shdc
chmod +x ./sokol-shdc
for f in examples/sokol/02_cubes_glsl/cube_glsl \
examples/sokol/03_march_tracing_glsl/rt_glsl \

View file

@ -13,13 +13,14 @@
// The shader language used is, as described on the overview page linked above, an 'annotated GLSL'
// and 'modern GLSL' (v450) shader language format.
import os
import time
import io.util
import flag
import net.http
const (
shdc_full_hash = '33d2e4cc26088c6c28eaef5467990f8940d15aab'
tool_version = '0.0.1'
shdc_full_hash = '6040b18d39649d56dbae2ae1aed59fb755b26369'
tool_version = '0.0.2'
tool_description = "Compile shaders in sokol's annotated GLSL format to C headers for use with sokol based apps"
tool_name = os.file_name(os.executable())
cache_dir = os.join_path(os.cache_dir(), 'v', tool_name)
@ -29,15 +30,15 @@ const (
const (
supported_hosts = ['linux', 'macos', 'windows']
supported_slangs = [
'glsl330', // desktop GL
'glsl100', // GLES2 / WebGL
'glsl300es', // GLES3 / WebGL2
'hlsl4', // D3D11
'hlsl5', // D3D11
'metal_macos', // Metal on macOS
'metal_ios', // Metal on iOS device
'metal_sim', // Metal on iOS simulator
'wgpu', // WebGPU
'glsl330', // desktop OpenGL backend (SOKOL_GLCORE33)
'glsl100', // OpenGLES2 and WebGL (SOKOL_GLES3)
'glsl300es', // OpenGLES3 and WebGL2 (SOKOL_GLES3)
'hlsl4', // Direct3D11 with HLSL4 (SOKOL_D3D11)
'hlsl5', // Direct3D11 with HLSL5 (SOKOL_D3D11)
'metal_macos', // Metal on macOS (SOKOL_METAL)
'metal_ios', // Metal on iOS devices (SOKOL_METAL)
'metal_sim', // Metal on iOS simulator (SOKOL_METAL)
'wgsl', // WebGPU (SOKOL_WGPU)
]
default_slangs = [
'glsl330',
@ -48,7 +49,7 @@ const (
'metal_macos',
'metal_ios',
'metal_sim',
'wgpu',
'wgsl',
]
shdc_version = shdc_full_hash[0..8]
@ -56,6 +57,7 @@ const (
'windows': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/win32/sokol-shdc.exe'
'macos': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/osx/sokol-shdc'
'linux': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/linux/sokol-shdc'
'osx_a64': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/osx_arm64/sokol-shdc'
}
shdc_version_file = os.join_path(cache_dir, 'sokol-shdc.version')
shdc = shdc_exe()
@ -242,11 +244,20 @@ fn ensure_external_tools(opt Options) ! {
is_shdc_available := os.is_file(shdc)
is_shdc_executable := os.is_executable(shdc)
if is_shdc_available && is_shdc_executable {
if opt.verbose {
version := os.read_file(shdc_version_file) or { 'unknown' }
eprintln('${tool_name} using sokol-shdc version ${version} at "${shdc}"')
if opt.verbose {
eprintln('reading version from ${shdc_version_file} ...')
version := os.read_file(shdc_version_file) or { 'unknown' }
eprintln('${tool_name} using sokol-shdc version ${version} at "${shdc}"')
eprintln('executable: ${is_shdc_executable}')
eprintln(' available: ${is_shdc_available}')
if is_shdc_available {
eprintln(' file path: ${shdc}')
eprintln(' file size: ${os.file_size(shdc)}')
eprintln(' file time: ${time.unix_microsecond(os.file_last_mod_unix(shdc),
0)}')
}
}
if is_shdc_available && is_shdc_executable {
return
}
@ -263,15 +274,24 @@ fn shdc_exe() string {
// download_shdc downloads the `sokol-shdc` tool to an OS specific cache directory.
fn download_shdc(opt Options) ! {
// We want to use the same, runtime, OS type as this tool is invoked on.
download_url := shdc_urls[runtime_os] or { '' }
mut download_url := shdc_urls[runtime_os] or { '' }
$if arm64 && macos {
download_url = shdc_urls['osx_a64']
}
if download_url == '' {
return error('${tool_name} failed to download an external dependency "sokol-shdc" for ${runtime_os}.\nThe supported host platforms for shader compilation is ${supported_hosts}')
}
if opt.verbose {
eprintln('> reading version from ${shdc_version_file} ...')
}
update_to_shdc_version := os.read_file(shdc_version_file) or { shdc_version }
if opt.verbose {
eprintln('> update_to_shdc_version: ${update_to_shdc_version} | shdc_version: ${shdc_version}')
}
file := shdc_exe()
if opt.verbose {
if shdc_version != update_to_shdc_version && os.exists(file) {
eprintln('${tool_name} updating sokol-shdc to version ${update_to_shdc_version} ...')
eprintln('${tool_name} updating sokol-shdc to version ${shdc_version} ...')
} else {
eprintln('${tool_name} installing sokol-shdc version ${update_to_shdc_version} ...')
}
@ -298,5 +318,5 @@ fn download_shdc(opt Options) ! {
os.mv(file, shdc)!
}
// Update internal version file
os.write_file(shdc_version_file, update_to_shdc_version)!
os.write_file(shdc_version_file, shdc_version)!
}

View file

@ -45,11 +45,11 @@ fn create_texture(w int, h int, buf &u8) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}

View file

@ -61,11 +61,11 @@ fn create_texture(w int, h int, buf &byte) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
@ -361,7 +361,7 @@ fn init_cube_glsl(mut app App) {
app.cube_bind.vertex_buffers[0] = vbuf
app.cube_bind.index_buffer = ibuf
app.cube_bind.fs_images[C.SLOT_tex] = app.texture
app.cube_bind.fs.images[C.SLOT_tex] = app.texture
app.cube_pip_glsl = gfx.make_pipeline(&pipdesc)
println('GLSL init DONE!')
}
@ -374,8 +374,8 @@ fn draw_cube_glsl(app App) {
// clear
ws := gg.window_size_real_pixels()
mut color_action := gfx.ColorAttachmentAction{
action: unsafe { gfx.Action(C.SG_ACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
value: gfx.Color{
load_action: unsafe { gfx.Action(C.SG_LOADACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
clear_value: gfx.Color{
r: 1.0
g: 1.0
b: 1.0

View file

@ -60,11 +60,11 @@ fn create_texture(w int, h int, buf &byte) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
@ -223,7 +223,7 @@ fn init_cube_glsl(mut app App) {
app.cube_bind.vertex_buffers[0] = vbuf
app.cube_bind.index_buffer = ibuf
app.cube_bind.fs_images[C.SLOT_tex] = app.texture
app.cube_bind.fs.images[C.SLOT_tex] = app.texture
app.cube_pip_glsl = gfx.make_pipeline(&pipdesc)
println('GLSL init DONE!')
}
@ -312,8 +312,8 @@ fn frame(mut app App) {
// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0

View file

@ -63,11 +63,11 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
@ -227,7 +227,7 @@ fn init_cube_glsl_m(mut app App) {
unsafe { vmemset(&bind, 0, int(sizeof(bind))) }
bind.vertex_buffers[0] = vbuf
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture
bind.fs.images[C.SLOT_tex] = app.texture
app.bind['march'] = bind
app.pipe['march'] = gfx.make_pipeline(&pipdesc)
@ -342,7 +342,7 @@ fn init_cube_glsl_p(mut app App) {
unsafe { vmemset(&bind, 0, int(sizeof(bind))) }
bind.vertex_buffers[0] = vbuf
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture
bind.fs.images[C.SLOT_tex] = app.texture
app.bind['puppy'] = bind
app.pipe['puppy'] = gfx.make_pipeline(&pipdesc)
@ -501,8 +501,8 @@ fn frame(mut app App) {
// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0

View file

@ -71,11 +71,11 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
//usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
@ -257,7 +257,7 @@ fn init_cube_glsl_i(mut app App) {
bind.vertex_buffers[0] = vbuf // vertex buffer
bind.vertex_buffers[1] = inst_buf // instance buffer
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture
bind.fs.images[C.SLOT_tex] = app.texture
app.bind['inst'] = bind
app.pipe['inst'] = gfx.make_pipeline(&pipdesc)
@ -384,8 +384,8 @@ fn frame(mut app App) {
// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0

View file

@ -24,11 +24,11 @@ pub fn create_texture(w int, h int, buf &u8) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
@ -133,7 +133,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
res.bind.vertex_buffers[0] = vbuf
res.bind.index_buffer = ibuf
res.bind.fs_images[C.SLOT_tex] = texture
res.bind.fs.images[C.SLOT_tex] = texture
res.pipeline = gfx.make_pipeline(&pipdesc)
// println('Buffers part [$in_part] init done!')

View file

@ -150,8 +150,8 @@ fn frame(mut app App) {
// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0

View file

@ -15,8 +15,8 @@ mut:
fn main() {
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.3
g: 0.3
b: 0.32

View file

@ -63,8 +63,8 @@ mut:
fn main() {
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 1.0
g: 1.0
b: 1.0

View file

@ -121,11 +121,11 @@ fn create_texture(w int, h int, buf &u8) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -452,7 +452,7 @@ pub fn new_context(cfg Config) &Context {
init_userdata_cb: gg_init_sokol_window
frame_userdata_cb: gg_frame_fn
event_userdata_cb: gg_event_fn
fail_userdata_cb: gg_fail_fn
// fail_userdata_cb: gg_fail_fn
cleanup_userdata_cb: gg_cleanup_fn
window_title: &char(cfg.window_title.str)
html5_canvas_name: &char(cfg.html5_canvas_name.str)
@ -533,20 +533,20 @@ pub struct EndOptions {
const dontcare_pass = gfx.PassAction{
colors: [
gfx.ColorAttachmentAction{
action: .dontcare
value: gfx.Color{1.0, 1.0, 1.0, 1.0}
load_action: .dontcare
clear_value: gfx.Color{1.0, 1.0, 1.0, 1.0}
},
gfx.ColorAttachmentAction{
action: .dontcare
value: gfx.Color{1.0, 1.0, 1.0, 1.0}
load_action: .dontcare
clear_value: gfx.Color{1.0, 1.0, 1.0, 1.0}
},
gfx.ColorAttachmentAction{
action: .dontcare
value: gfx.Color{1.0, 1.0, 1.0, 1.0}
load_action: .dontcare
clear_value: gfx.Color{1.0, 1.0, 1.0, 1.0}
},
gfx.ColorAttachmentAction{
action: .dontcare
value: gfx.Color{1.0, 1.0, 1.0, 1.0}
load_action: .dontcare
clear_value: gfx.Color{1.0, 1.0, 1.0, 1.0}
},
]!
}

View file

@ -89,8 +89,8 @@ pub fn (mut img Image) init_sokol_image() &Image {
width: img.width
height: img.height
num_mipmaps: 0
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge // XTODO SAMPLER
// wrap_v: .clamp_to_edge
label: img.path.str
d3d11_texture: 0
}
@ -142,10 +142,10 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg S
num_slices: 1
num_mipmaps: 1
usage: .stream
wrap_u: sicfg.wrap_u
wrap_v: sicfg.wrap_v
min_filter: sicfg.min_filter
mag_filter: sicfg.mag_filter
// wrap_u: sicfg.wrap_u // SAMPLER
// wrap_v: sicfg.wrap_v
// min_filter: sicfg.min_filter
// mag_filter: sicfg.mag_filter
label: img.path.str
}
// Sokol requires that streamed images have NO .ptr/.size initially:

View file

@ -36,7 +36,7 @@ $if ios {
}
$if emscripten ? {
#flag -DSOKOL_GLES2
#flag -DSOKOL_GLES3
#flag -DSOKOL_NO_ENTRY
#flag -s ERROR_ON_UNDEFINED_SYMBOLS=0
#flag -s ASSERTIONS=1

View file

@ -2,12 +2,12 @@ module gfx
pub enum Backend {
glcore33
gles2
gles3
d3d11
metal_ios
metal_macos
metal_simulator
wgpu
dummy
}
@ -37,6 +37,7 @@ pub enum PixelFormat {
rg16si
rg16f
rgba8
srgb8a8
rgba8sn
rgba8ui
rgba8si

View file

@ -9,16 +9,16 @@ pub const used_import = c.used_import
// setup initialises the SOKOL's gfx library, based on the information passed in `desc`
pub fn setup(desc &Desc) {
if desc.allocator.alloc == unsafe { nil } && desc.allocator.free == unsafe { nil } {
if desc.allocator.alloc_fn == unsafe { nil } && desc.allocator.free_fn == unsafe { nil } {
unsafe {
desc.allocator.alloc = memory.salloc
desc.allocator.free = memory.sfree
desc.allocator.alloc_fn = memory.salloc
desc.allocator.free_fn = memory.sfree
desc.allocator.user_data = voidptr(0x1006fec5)
}
}
if desc.logger.log_cb == unsafe { nil } {
if desc.logger.func == unsafe { nil } {
unsafe {
desc.logger.log_cb = memory.slog
desc.logger.func = memory.slog
}
}
C.sg_setup(desc)

View file

@ -5,14 +5,14 @@ import sokol.memory
[typedef]
pub struct C.sg_allocator {
pub mut:
alloc memory.FnAllocatorAlloc = unsafe { nil }
free memory.FnAllocatorFree = unsafe { nil }
alloc_fn memory.FnAllocatorAlloc = unsafe { nil }
free_fn memory.FnAllocatorFree = unsafe { nil }
user_data voidptr
}
[typedef]
pub struct C.sg_logger {
pub mut:
log_cb memory.FnLogCb = unsafe { nil }
func memory.FnLogCb = unsafe { nil }
user_data voidptr
}

View file

@ -12,7 +12,7 @@ pub mut:
context_pool_size int
uniform_buffer_size int
staging_buffer_size int
sampler_cache_size int
sampler_pool_size int
max_commit_listeners int
disable_validation bool // disable validation layer even in debug mode, useful for tests
//
@ -61,14 +61,14 @@ struct C.sg_d3d11_context_desc {
pub type D3D11ContextDesc = C.sg_d3d11_context_desc
struct C.sg_color_state {
struct C.sg_color_target_state {
pub mut:
pixel_format PixelFormat
write_mask ColorMask
blend BlendState
}
pub type ColorState = C.sg_color_state
pub type ColorState = C.sg_color_target_state
pub struct C.sg_pipeline_desc {
pub mut:
@ -115,19 +115,26 @@ pub mut:
vertex_buffer_offsets [8]int
index_buffer Buffer
index_buffer_offset int
vs_images [8]Image
fs_images [8]Image
_end_canary u32
vs C.sg_stage_bindings
fs C.sg_stage_bindings
// vs_images [8]Image // old
// fs_images [8]Image // old
_end_canary u32
}
pub struct C.sg_stage_bindings {
pub mut:
images [12]Image
}
pub type Bindings = C.sg_bindings
pub fn (mut b Bindings) set_vert_image(index int, img Image) {
b.vs_images[index] = img
b.vs.images[index] = img
}
pub fn (mut b Bindings) set_frag_image(index int, img Image) {
b.fs_images[index] = img
b.fs.images[index] = img
}
pub fn (b &Bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) {
@ -186,13 +193,13 @@ pub fn (mut desc C.sg_shader_desc) set_frag_src(src string) &ShaderDesc {
}
pub fn (mut desc C.sg_shader_desc) set_vert_image(index int, name string) &ShaderDesc {
desc.vs.images[index].name = &char(name.str)
// desc.vs.images[index].name = &char(name.str)
desc.vs.images[index].image_type = ._2d
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &ShaderDesc {
desc.fs.images[index].name = &char(name.str)
// desc.fs.images[index].name = &char(name.str)
desc.fs.images[index].image_type = ._2d
return desc
}
@ -244,7 +251,7 @@ pub mut:
pub type ShaderStageDesc = C.sg_shader_stage_desc
pub fn (mut desc ShaderStageDesc) set_image(index int, name string) ShaderStageDesc {
desc.images[index].name = &char(name.str)
// desc.images[index].name = &char(name.str)
desc.images[index].image_type = ._2d
return *desc
}
@ -269,7 +276,9 @@ pub type ShaderUniformDesc = C.sg_shader_uniform_desc
struct C.sg_shader_image_desc {
pub mut:
name &char
used bool
multisampled bool
// name &char
image_type ImageType
}
@ -397,27 +406,27 @@ pub fn (mut b Buffer) free() {
pub struct C.sg_image_desc {
pub mut:
_start_canary u32
@type ImageType
render_target bool
width int
height int
num_slices int
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
data ImageData
label &char
_start_canary u32
@type ImageType
render_target bool
width int
height int
num_slices int
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
data ImageData
label &char
// GL specific
gl_textures [2]u32
gl_texture_target u32
@ -433,6 +442,18 @@ pub mut:
pub type ImageDesc = C.sg_image_desc
pub struct C.sg_sampler_desc {
min_filter Filter
mag_filter Filter
wrap_u Wrap
wrap_v Wrap
wrap_w Wrap
min_lod f32
max_lod f32
border_color BorderColor
max_anisotropy u32
}
pub struct C.sg_image_info {
pub mut:
slot SlotInfo // resource pool slot info
@ -454,6 +475,8 @@ pub fn (mut i Image) free() {
C.sg_destroy_image(*i)
}
pub struct C.sg_sampler {}
pub const sg_cubeface_num = 6
pub const sg_max_mipmaps = 16
@ -492,31 +515,31 @@ pub:
pub type Limits = C.sg_limits
pub struct C.sg_layout_desc {
pub struct C.sg_vertex_layout_state {
pub mut:
buffers [8]BufferLayoutDesc
attrs [16]VertexAttrDesc
}
pub type LayoutDesc = C.sg_layout_desc
pub type LayoutDesc = C.sg_vertex_layout_state
pub struct C.sg_buffer_layout_desc {
pub struct C.sg_vertex_buffer_layout_state {
pub mut:
stride int
step_func VertexStep
step_rate int
}
pub type BufferLayoutDesc = C.sg_buffer_layout_desc
pub type BufferLayoutDesc = C.sg_vertex_buffer_layout_state
pub struct C.sg_vertex_attr_desc {
pub struct C.sg_vertex_attr_state {
pub mut:
buffer_index int
offset int
format VertexFormat
}
pub type VertexAttrDesc = C.sg_vertex_attr_desc
pub type VertexAttrDesc = C.sg_vertex_attr_state
struct C.sg_stencil_state {
enabled bool
@ -564,8 +587,8 @@ pub type BlendState = C.sg_blend_state
struct C.sg_color_attachment_action {
pub mut:
action Action
value Color
load_action Action
clear_value Color
}
pub type ColorAttachmentAction = C.sg_color_attachment_action

View file

@ -2,8 +2,8 @@ module gfx
pub fn create_clear_pass(r f32, g f32, b f32, a f32) PassAction {
mut color_action := ColorAttachmentAction{
action: unsafe { Action(C.SG_ACTION_CLEAR) }
value: Color{
load_action: Action.clear // unsafe { Action(C.SG_ACTION_CLEAR) }
clear_value: Color{
r: r
g: g
b: b

View file

@ -36,6 +36,8 @@ pub fn slog(const_message &char, user_data voidptr) {
C.fprintf(C.stderr, c'sokol.memory.slog | user_data: %p, message: %s\n', user_data,
const_message)
}
C.fprintf(C.stderr, c'%s\n', const_message)
/*
$if msvc {
C.fprintf(C.stderr, c'%s\n', const_message)
} $else {
@ -43,4 +45,5 @@ pub fn slog(const_message &char, user_data voidptr) {
C.SOKOL_LOG(const_message)
}
}
*/
}

View file

@ -182,28 +182,22 @@ pub fn get_clipboard_string() &char {
// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
pub fn run(desc &Desc) {
if desc.allocator.alloc == unsafe { nil } && desc.allocator.free == unsafe { nil } {
if desc.allocator.alloc_fn == unsafe { nil } && desc.allocator.free_fn == unsafe { nil } {
unsafe {
desc.allocator.alloc = memory.salloc
desc.allocator.free = memory.sfree
desc.allocator.alloc_fn = memory.salloc
desc.allocator.free_fn = memory.sfree
desc.allocator.user_data = voidptr(0x10005a44)
}
}
if desc.logger.log_cb == unsafe { nil } {
if desc.logger.func == unsafe { nil } {
unsafe {
desc.logger.log_cb = memory.slog
desc.logger.func = memory.slog
}
}
g_desc = *desc
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) {

View file

@ -5,14 +5,14 @@ import sokol.memory
[typedef]
pub struct C.sapp_allocator {
pub mut:
alloc memory.FnAllocatorAlloc = unsafe { nil }
free memory.FnAllocatorFree = unsafe { nil }
alloc_fn memory.FnAllocatorAlloc = unsafe { nil }
free_fn memory.FnAllocatorFree = unsafe { nil }
user_data voidptr
}
[typedef]
pub struct C.sapp_logger {
pub mut:
log_cb memory.FnLogCb = unsafe { nil }
func memory.FnLogCb = unsafe { nil }
user_data voidptr
}

View file

@ -98,9 +98,6 @@ fn C.sapp_get_dropped_file_path(int) &u8
// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
fn C.sapp_run(desc &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)

View file

@ -42,14 +42,14 @@ pub:
frame_cb fn () = unsafe { nil }
cleanup_cb fn () = unsafe { nil }
event_cb fn (&Event) = unsafe { nil } // &sapp_event
fail_cb fn (&u8) = unsafe { nil }
// fail_cb fn (&u8) = unsafe { nil }
user_data voidptr // these are the user-provided callbacks with user data
init_userdata_cb fn (voidptr) = unsafe { nil }
frame_userdata_cb fn (voidptr) = unsafe { nil }
cleanup_userdata_cb fn (voidptr) = unsafe { nil }
event_userdata_cb fn (&Event, voidptr) = unsafe { nil }
fail_userdata_cb fn (&char, voidptr) = unsafe { nil }
// fail_userdata_cb fn (&char, voidptr) = unsafe { nil }
width int // the preferred width of the window / canvas
height int // the preferred height of the window / canvas
@ -66,7 +66,6 @@ pub:
max_dropped_file_path_length int // max length in bytes of a dropped UTF-8 file path (default: 2048)
icon IconDesc // the initial window icon to set
// backend-specific options
gl_force_gles2 bool // if true, setup GLES2/WebGL even if GLES3/WebGL2 is available
win32_console_utf8 bool // if true, set the output console codepage to UTF-8
win32_console_create bool // if true, attach stdout/stderr to a new console window
win32_console_attach bool // if true, attach stdout/stderr to parent process

View file

@ -13,8 +13,8 @@ pub fn create(width int, height int, flags int) &fontstash.Context {
assert is_power_of_two(width)
assert is_power_of_two(height)
allocator := C.sfons_allocator_t{
alloc: memory.salloc
free: memory.sfree
alloc_fn: memory.salloc
free_fn: memory.sfree
user_data: voidptr(0x100005f0)
}
desc := C.sfons_desc_t{

View file

@ -6,8 +6,8 @@ import sokol.memory
[typedef]
pub struct C.sfons_allocator_t {
pub:
alloc memory.FnAllocatorAlloc = unsafe { nil }
free memory.FnAllocatorFree = unsafe { nil }
alloc_fn memory.FnAllocatorAlloc = unsafe { nil }
free_fn memory.FnAllocatorFree = unsafe { nil }
user_data voidptr
}

View file

@ -9,16 +9,16 @@ pub const context = Context{0x00010001} // C.SGL_DEFAULT_CONTEXT = { 0x00010001
// setup/shutdown/misc
pub fn setup(desc &Desc) {
if desc.allocator.alloc == unsafe { nil } && desc.allocator.free == unsafe { nil } {
if desc.allocator.alloc_fn == unsafe { nil } && desc.allocator.free_fn == unsafe { nil } {
unsafe {
desc.allocator.alloc = memory.salloc
desc.allocator.free = memory.sfree
desc.allocator.alloc_fn = memory.salloc
desc.allocator.free_fn = memory.sfree
desc.allocator.user_data = voidptr(0x10000561)
}
}
if desc.logger.log_cb == unsafe { nil } {
if desc.logger.func == unsafe { nil } {
unsafe {
desc.logger.log_cb = memory.slog
desc.logger.func = memory.slog
}
}
C.sgl_setup(desc)
@ -123,7 +123,7 @@ pub fn disable_texture() {
[inline]
pub fn texture(img gfx.Image) {
C.sgl_texture(img)
C.sgl_texture(img, C.sg_sampler{}) // TODO need to pass SG_INVALID_ID ?
}
// pipeline stack functions

View file

@ -5,14 +5,14 @@ import sokol.memory
[typedef]
pub struct C.sgl_allocator_t {
pub mut:
alloc memory.FnAllocatorAlloc = unsafe { nil }
free memory.FnAllocatorFree = unsafe { nil }
alloc_fn memory.FnAllocatorAlloc = unsafe { nil }
free_fn memory.FnAllocatorFree = unsafe { nil }
user_data voidptr
}
[typedef]
pub struct C.sgl_logger_t {
pub mut:
log_cb memory.FnLogCb = unsafe { nil }
func memory.FnLogCb = unsafe { nil }
user_data voidptr
}

View file

@ -28,7 +28,7 @@ fn C.sgl_scissor_rect(x int, y int, w int, h int, origin_top_left bool)
fn C.sgl_scissor_rectf(x f32, y f32, w f32, h f32, origin_top_left bool)
fn C.sgl_enable_texture()
fn C.sgl_disable_texture()
fn C.sgl_texture(img C.sg_image)
fn C.sgl_texture(img C.sg_image, sampler C.sg_sampler)
// pipeline stack functions
fn C.sgl_load_default_pipeline()

View file

@ -123,11 +123,11 @@ pub fn (mut tf_skl TTF_render_Sokol) create_texture() {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &char(0)
d3d11_texture: 0
}