cleanup with -vet and add to all_vendor

This commit is contained in:
skytrias
2023-06-23 16:18:40 +02:00
parent 26a5614572
commit 6b59aee336
4 changed files with 63 additions and 59 deletions
+8
View File
@@ -47,6 +47,10 @@ import CA "vendor:darwin/QuartzCore"
// NOTE(bill): only one can be checked at a time // NOTE(bill): only one can be checked at a time
import lua_5_4 "vendor:lua/5.4" import lua_5_4 "vendor:lua/5.4"
import nvg "vendor:nanovg"
import nvg_gl "vendor:nanovg/gl"
import fontstash "vendor:fontstash"
_ :: botan_bindings _ :: botan_bindings
_ :: botan_blake2b _ :: botan_blake2b
_ :: gost _ :: gost
@@ -93,3 +97,7 @@ _ :: MTK
_ :: CA _ :: CA
_ :: lua_5_4 _ :: lua_5_4
_ :: nvg
_ :: nvg_gl
_ :: fontstash
+23 -25
View File
@@ -1,12 +1,10 @@
package fontstash package fontstash
import "core:runtime" import "core:runtime"
import "core:fmt"
import "core:log" import "core:log"
import "core:os" import "core:os"
import "core:mem" import "core:mem"
import "core:math" import "core:math"
import "core:unicode"
import "core:strings" import "core:strings"
import stbtt "vendor:stb/truetype" import stbtt "vendor:stb/truetype"
@@ -329,7 +327,7 @@ __AtlasAddWhiteRect :: proc(ctx: ^FontContext, w, h: int) {
// Rasterize // Rasterize
dst := ctx.textureData[gx + gy * ctx.width:] dst := ctx.textureData[gx + gy * ctx.width:]
for y in 0..<h { for _ in 0..<h {
for x in 0..<w { for x in 0..<w {
dst[x] = 0xff dst[x] = 0xff
} }
@@ -464,7 +462,7 @@ __getGlyph :: proc(
font: ^Font, font: ^Font,
codepoint: rune, codepoint: rune,
isize: i16, isize: i16,
blurSize: i16 = 0, blur: i16 = 0,
) -> (res: ^Glyph) #no_bounds_check { ) -> (res: ^Glyph) #no_bounds_check {
if isize < 2 { if isize < 2 {
return return
@@ -479,7 +477,7 @@ __getGlyph :: proc(
if if
glyph.codepoint == codepoint && glyph.codepoint == codepoint &&
glyph.isize == isize && glyph.isize == isize &&
glyph.blurSize == blurSize glyph.blurSize == blur
{ {
res = glyph res = glyph
return return
@@ -506,10 +504,10 @@ __getGlyph :: proc(
} }
pixel_size := f32(isize) / 10 pixel_size := f32(isize) / 10
blurSize := min(blurSize, 20) blurSize := min(blur, 20)
padding := i16(blurSize + 2) // 2 minimum padding padding := i16(blurSize + 2) // 2 minimum padding
scale := __getPixelHeightScale(render_font, pixel_size) scale := __getPixelHeightScale(render_font, pixel_size)
advance, lsb, x0, y0, x1, y1 := __buildGlyphBitmap(render_font, glyph_index, pixel_size, scale) advance, _, x0, y0, x1, y1 := __buildGlyphBitmap(render_font, glyph_index, pixel_size, scale)
gw := (x1 - x0) + i32(padding) * 2 gw := (x1 - x0) + i32(padding) * 2
gh := (y1 - y0) + i32(padding) * 2 gh := (y1 - y0) + i32(padding) * 2
@@ -596,7 +594,7 @@ BLUR_ZPREC :: 7
__blurCols :: proc(dst: []u8, w, h, dstStride, alpha: int) { __blurCols :: proc(dst: []u8, w, h, dstStride, alpha: int) {
dst := dst dst := dst
for y in 0..<h { for _ in 0..<h {
z := 0 // force zero border z := 0 // force zero border
for x in 1..<w { for x in 1..<w {
@@ -620,7 +618,7 @@ __blurCols :: proc(dst: []u8, w, h, dstStride, alpha: int) {
__blurRows :: proc(dst: []u8, w, h, dstStride, alpha: int) { __blurRows :: proc(dst: []u8, w, h, dstStride, alpha: int) {
dst := dst dst := dst
for x in 0..<w { for _ in 0..<w {
z := 0 // force zero border z := 0 // force zero border
for y := dstStride; y < h * dstStride; y += dstStride { for y := dstStride; y < h * dstStride; y += dstStride {
z += (alpha * ((int(dst[y]) << BLUR_ZPREC) - z)) >> BLUR_APREC z += (alpha * ((int(dst[y]) << BLUR_ZPREC) - z)) >> BLUR_APREC
@@ -657,38 +655,38 @@ __blur :: proc(dst: []u8, w, h, dstStride: int, blurSize: i16) {
///////////////////////////////// /////////////////////////////////
ExpandAtlas :: proc(ctx: ^FontContext, width, height: int, allocator := context.allocator) -> bool { ExpandAtlas :: proc(ctx: ^FontContext, width, height: int, allocator := context.allocator) -> bool {
width := max(ctx.width, width) w := max(ctx.width, width)
height := max(ctx.height, height) h := max(ctx.height, height)
if width == ctx.width && height == ctx.height { if w == ctx.width && h == ctx.height {
return true return true
} }
if ctx.callbackResize != nil { if ctx.callbackResize != nil {
ctx.callbackResize(ctx.userData, width, height) ctx.callbackResize(ctx.userData, w, h)
} }
data := make([]byte, width * height, allocator) data := make([]byte, w * h, allocator)
for i in 0..<ctx.height { for i in 0..<ctx.height {
dst := &data[i * width] dst := &data[i * w]
src := &ctx.textureData[i * ctx.width] src := &ctx.textureData[i * ctx.width]
mem.copy(dst, src, ctx.width) mem.copy(dst, src, ctx.width)
if width > ctx.width { if w > ctx.width {
mem.set(&data[i * width + ctx.width], 0, width - ctx.width) mem.set(&data[i * w + ctx.width], 0, w - ctx.width)
} }
} }
if height > ctx.height { if h > ctx.height {
mem.set(&data[ctx.height * width], 0, (height - ctx.height) * width) mem.set(&data[ctx.height * w], 0, (h - ctx.height) * w)
} }
delete(ctx.textureData) delete(ctx.textureData)
ctx.textureData = data ctx.textureData = data
// increase atlas size // increase atlas size
__atlasExpand(ctx, width, height) __atlasExpand(ctx, w, h)
// add existing data as dirty // add existing data as dirty
maxy := i16(0) maxy := i16(0)
@@ -700,10 +698,10 @@ ExpandAtlas :: proc(ctx: ^FontContext, width, height: int, allocator := context.
ctx.dirtyRect[2] = f32(ctx.width) ctx.dirtyRect[2] = f32(ctx.width)
ctx.dirtyRect[3] = f32(maxy) ctx.dirtyRect[3] = f32(maxy)
ctx.width = width ctx.width = w
ctx.height = height ctx.height = h
ctx.itw = 1.0 / f32(width) ctx.itw = 1.0 / f32(w)
ctx.ith = 1.0 / f32(height) ctx.ith = 1.0 / f32(h)
return true return true
} }
@@ -994,7 +992,7 @@ __getQuad :: proc(
} }
// fill props right // fill props right
rx, ry, x0, y0, x1, y1, xoff, yoff, glyph_width, glyph_height: f32 rx, ry, x0, y0, x1, y1, xoff, yoff: f32
xoff = f32(glyph.xoff + 1) xoff = f32(glyph.xoff + 1)
yoff = f32(glyph.yoff + 1) yoff = f32(glyph.yoff + 1)
x0 = f32(glyph.x0 + 1) x0 = f32(glyph.x0 + 1)
+6 -6
View File
@@ -1383,10 +1383,10 @@ BindFramebuffer :: proc(fb: ^framebuffer) {
} }
CreateFramebuffer :: proc(ctx: ^nvg.Context, w, h: int, imageFlags: ImageFlags) -> (fb: framebuffer) { CreateFramebuffer :: proc(ctx: ^nvg.Context, w, h: int, imageFlags: ImageFlags) -> (fb: framebuffer) {
defaultFBO: i32 tempFBO: i32
defaultRBO: i32 tempRBO: i32
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &defaultFBO) gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &tempFBO)
gl.GetIntegerv(gl.RENDERBUFFER_BINDING, &defaultRBO) gl.GetIntegerv(gl.RENDERBUFFER_BINDING, &tempRBO)
imageFlags := imageFlags imageFlags := imageFlags
incl(&imageFlags, ImageFlags { .FLIP_Y, .PREMULTIPLIED }) incl(&imageFlags, ImageFlags { .FLIP_Y, .PREMULTIPLIED })
@@ -1422,8 +1422,8 @@ CreateFramebuffer :: proc(ctx: ^nvg.Context, w, h: int, imageFlags: ImageFlags)
// goto error // goto error
} }
gl.BindFramebuffer(gl.FRAMEBUFFER, u32(defaultFBO)) gl.BindFramebuffer(gl.FRAMEBUFFER, u32(tempFBO))
gl.BindRenderbuffer(gl.RENDERBUFFER, u32(defaultRBO)) gl.BindRenderbuffer(gl.RENDERBUFFER, u32(tempRBO))
return return
} }
+25 -27
View File
@@ -4,7 +4,6 @@ package nanovg
// TODO rename enums to old nanovg style! // TODO rename enums to old nanovg style!
import "core:mem" import "core:mem"
import "core:runtime"
import "core:math" import "core:math"
import "core:fmt" import "core:fmt"
import "../fontstash" import "../fontstash"
@@ -452,10 +451,10 @@ RGBA :: proc(r, g, b, a: u8) -> (res: Color) {
// Linearly interpolates from color c0 to c1, and returns resulting color value. // Linearly interpolates from color c0 to c1, and returns resulting color value.
LerpRGBA :: proc(c0, c1: Color, u: f32) -> (cint: Color) { LerpRGBA :: proc(c0, c1: Color, u: f32) -> (cint: Color) {
u := clamp(u, 0.0, 1.0) clamped := clamp(u, 0.0, 1.0)
oneminu := 1.0 - u oneminu := 1.0 - clamped
for i in 0..<4 { for i in 0..<4 {
cint[i] = c0[i] * oneminu + c1[i] * u cint[i] = c0[i] * oneminu + c1[i] * clamped
} }
return return
@@ -469,8 +468,8 @@ HSL :: proc(h, s, l: f32) -> Color {
// Returns color value specified by hue, saturation and lightness and alpha. // Returns color value specified by hue, saturation and lightness and alpha.
// HSL values are all in range [0..1], alpha in range [0..255] // HSL values are all in range [0..1], alpha in range [0..255]
HSLA :: proc(h, s, l: f32, a: u8) -> (col: Color) { HSLA :: proc(hue, saturation, lightness: f32, a: u8) -> (col: Color) {
hue :: proc(h, m1, m2: f32) -> f32 { hue_get :: proc(h, m1, m2: f32) -> f32 {
h := h h := h
if h < 0 { if h < 0 {
@@ -492,17 +491,17 @@ HSLA :: proc(h, s, l: f32, a: u8) -> (col: Color) {
return m1 return m1
} }
h := math.mod(h, 1.0) h := math.mod(hue, 1.0)
if h < 0.0 { if h < 0.0 {
h += 1.0 h += 1.0
} }
s := clamp(s, 0.0, 1.0) s := clamp(saturation, 0.0, 1.0)
l := clamp(l, 0.0, 1.0) l := clamp(lightness, 0.0, 1.0)
m2 := l <= 0.5 ? (l * (1 + s)) : (l + s - l * s) m2 := l <= 0.5 ? (l * (1 + s)) : (l + s - l * s)
m1 := 2 * l - m2 m1 := 2 * l - m2
col.r = clamp(hue(h + 1.0/3.0, m1, m2), 0.0, 1.0) col.r = clamp(hue_get(h + 1.0/3.0, m1, m2), 0.0, 1.0)
col.g = clamp(hue(h, m1, m2), 0.0, 1.0) col.g = clamp(hue_get(h, m1, m2), 0.0, 1.0)
col.b = clamp(hue(h - 1.0/3.0, m1, m2), 0.0, 1.0) col.b = clamp(hue_get(h - 1.0/3.0, m1, m2), 0.0, 1.0)
col.a = f32(a) / 255.0 col.a = f32(a) / 255.0
return return
} }
@@ -919,8 +918,8 @@ CreateImageMem :: proc(ctx: ^Context, data: []byte, imageFlags: ImageFlags) -> i
return 0 return 0
} }
data := mem.slice_ptr(img, int(w) * int(h) * int(n)) pixel_data := mem.slice_ptr(img, int(w) * int(h) * int(n))
image := CreateImageRGBA(ctx, int(w), int(h), imageFlags, data) image := CreateImageRGBA(ctx, int(w), int(h), imageFlags, pixel_data)
stbi.image_free(img) stbi.image_free(img)
return image return image
} }
@@ -1115,11 +1114,11 @@ ImagePattern :: proc(
Scissor :: proc( Scissor :: proc(
ctx: ^Context, ctx: ^Context,
x, y: f32, x, y: f32,
w, h: f32, width, height: f32,
) { ) {
state := __getState(ctx) state := __getState(ctx)
w := max(w, 0) w := max(width, 0)
h := max(h, 0) h := max(height, 0)
TransformIdentity(&state.scissor.xform) TransformIdentity(&state.scissor.xform)
state.scissor.xform[4] = x + w * 0.5 state.scissor.xform[4] = x + w * 0.5
@@ -1568,7 +1567,7 @@ __flattenPaths :: proc(ctx: ^Context) {
} }
} }
for k in 0..<path.count { for _ in 0..<path.count {
// Calculate segment direction and length // Calculate segment direction and length
p0.dx = p1.x - p0.x p0.dx = p1.x - p0.x
p0.dy = p1.y - p0.y p0.dy = p1.y - p0.y
@@ -1874,14 +1873,14 @@ __calculateJoins :: proc(
} }
// Calculate which joins needs extra vertices to append, and gather vertex count. // Calculate which joins needs extra vertices to append, and gather vertex count.
for path, i in &cache.paths { for path in &cache.paths {
pts := cache.points[path.first:] pts := cache.points[path.first:]
p0 := &pts[path.count-1] p0 := &pts[path.count-1]
p1 := &pts[0] p1 := &pts[0]
nleft := 0 nleft := 0
path.nbevel = 0 path.nbevel = 0
for j in 0..<path.count { for _ in 0..<path.count {
dlx0, dly0, dlx1, dly1, dmr2, __cross, limit: f32 dlx0, dly0, dlx1, dly1, dmr2, __cross, limit: f32
dlx0 = p0.dy dlx0 = p0.dy
dly0 = -p0.dx dly0 = -p0.dx
@@ -2844,14 +2843,14 @@ __isTransformFlipped :: proc(xform: []f32) -> bool {
} }
// draw a single codepoint, useful for icons // draw a single codepoint, useful for icons
TextIcon :: proc(ctx: ^Context, x, y: f32, codepoint: rune) -> f32 { TextIcon :: proc(ctx: ^Context, xpos, ypos: f32, codepoint: rune) -> f32 {
state := __getState(ctx) state := __getState(ctx)
scale := __getFontScale(state) * ctx.devicePxRatio scale := __getFontScale(state) * ctx.devicePxRatio
invscale := f32(1.0) / scale invscale := f32(1.0) / scale
is_flipped := __isTransformFlipped(state.xform[:]) is_flipped := __isTransformFlipped(state.xform[:])
if state.fontId == -1 { if state.fontId == -1 {
return x return xpos
} }
fs := &ctx.fs fs := &ctx.fs
@@ -2871,8 +2870,8 @@ TextIcon :: proc(ctx: ^Context, x, y: f32, codepoint: rune) -> f32 {
fscale := fontstash.__getPixelHeightScale(font, f32(isize) / 10) fscale := fontstash.__getPixelHeightScale(font, f32(isize) / 10)
// transform x / y // transform x / y
x := x * scale x := xpos * scale
y := y * scale y := ypos * scale
switch fstate.ah { switch fstate.ah {
case .LEFT: {} case .LEFT: {}
@@ -3160,7 +3159,7 @@ TextBreakLines :: proc(
fontstash.SetAlignVertical(fs, state.alignVertical) fontstash.SetAlignVertical(fs, state.alignVertical)
fontstash.SetFont(fs, state.fontId) fontstash.SetFont(fs, state.fontId)
break_row_width := break_row_width * scale break_x := break_row_width * scale
iter := fontstash.TextIterInit(fs, 0, 0, text^) iter := fontstash.TextIterInit(fs, 0, 0, text^)
prev_iter := iter prev_iter := iter
q: fontstash.Quad q: fontstash.Quad
@@ -3268,7 +3267,7 @@ TextBreakLines :: proc(
} }
// Break to new line when a character is beyond break width. // Break to new line when a character is beyond break width.
if (type == .Char || type == .CJK) && next_width > break_row_width { if (type == .Char || type == .CJK) && next_width > break_x {
// The run length is too long, need to break to new line. // The run length is too long, need to break to new line.
if (break_end == row_start) { if (break_end == row_start) {
// The current word is longer than the row length, just break it from here. // The current word is longer than the row length, just break it from here.
@@ -3374,7 +3373,6 @@ TextBoxBounds :: proc(
// alignment // alignment
halign := state.alignHorizontal halign := state.alignHorizontal
valign := state.alignVertical
old_align := state.alignHorizontal old_align := state.alignHorizontal
defer state.alignHorizontal = old_align defer state.alignHorizontal = old_align
state.alignHorizontal = .LEFT state.alignHorizontal = .LEFT