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

sokol: type alias all gfx structs (#13014)

This commit is contained in:
Larpon
2022-01-02 19:36:01 +01:00
committed by GitHub
parent 41e763f79c
commit 4d4398fa8a
25 changed files with 531 additions and 431 deletions

View File

@@ -15,12 +15,13 @@ module ttf
import math
import gg
import sokol.sgl
import sokol.gfx
pub struct TTF_render_Sokol {
pub mut:
bmp &BitMap // Base bitmap render
// rendering fields
sg_img C.sg_image // sokol image
sg_img gfx.Image // sokol image
scale_reduct f32 = 2.0 // scale of the cpu texture for filtering
device_dpi int = 72 // device DPI
}
@@ -118,7 +119,7 @@ pub fn (mut tf_skl TTF_render_Sokol) create_texture() {
w := tf_skl.bmp.width
h := tf_skl.bmp.height
sz := tf_skl.bmp.width * tf_skl.bmp.height * tf_skl.bmp.bp
mut img_desc := C.sg_image_desc{
mut img_desc := gfx.ImageDesc{
width: w
height: h
num_mipmaps: 0
@@ -131,29 +132,29 @@ pub fn (mut tf_skl TTF_render_Sokol) create_texture() {
d3d11_texture: 0
}
// comment for dynamic
img_desc.data.subimage[0][0] = C.sg_range{
img_desc.data.subimage[0][0] = gfx.Range{
ptr: tf_skl.bmp.buf
size: usize(sz)
}
simg := C.sg_make_image(&img_desc)
simg := gfx.make_image(&img_desc)
// free(tf_skl.bmp.buf) // DONT FREE IF Dynamic
tf_skl.sg_img = simg
}
pub fn (tf_skl TTF_render_Sokol) destroy_texture() {
C.sg_destroy_image(tf_skl.sg_img)
gfx.destroy_image(tf_skl.sg_img)
}
// Use only if usage: .dynamic
pub fn (mut tf_skl TTF_render_Sokol) update_text_texture() {
sz := tf_skl.bmp.width * tf_skl.bmp.height * tf_skl.bmp.bp
mut tmp_sbc := C.sg_image_data{}
tmp_sbc.subimage[0][0] = C.sg_range{
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
ptr: tf_skl.bmp.buf
size: usize(sz)
}
C.sg_update_image(tf_skl.sg_img, &tmp_sbc)
gfx.update_image(tf_skl.sg_img, &tmp_sbc)
}
pub fn (tf_skl TTF_render_Sokol) draw_text_bmp(ctx &gg.Context, x f32, y f32) {