aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskytrias <skytrias@protonmail.com>2023-06-23 16:18:40 +0200
committerskytrias <skytrias@protonmail.com>2023-06-23 16:18:40 +0200
commit6b59aee336665d16a3c1dfc295301f0d9c92f4b1 (patch)
tree0132fbc6cab5e4cff180f2b9a0df846047b86cfc
parent26a5614572afd39fc35fc32b47d5f7e5e9771e56 (diff)
cleanup with -vet and add to all_vendor
-rw-r--r--examples/all/all_vendor.odin10
-rw-r--r--vendor/fontstash/fontstash.odin48
-rw-r--r--vendor/nanovg/gl/gl.odin12
-rw-r--r--vendor/nanovg/nanovg.odin52
4 files changed, 63 insertions, 59 deletions
diff --git a/examples/all/all_vendor.odin b/examples/all/all_vendor.odin
index fe1080e20..fa1e8d995 100644
--- a/examples/all/all_vendor.odin
+++ b/examples/all/all_vendor.odin
@@ -47,6 +47,10 @@ import CA "vendor:darwin/QuartzCore"
// NOTE(bill): only one can be checked at a time
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_blake2b
_ :: gost
@@ -92,4 +96,8 @@ _ :: MTL
_ :: MTK
_ :: CA
-_ :: lua_5_4 \ No newline at end of file
+_ :: lua_5_4
+
+_ :: nvg
+_ :: nvg_gl
+_ :: fontstash \ No newline at end of file
diff --git a/vendor/fontstash/fontstash.odin b/vendor/fontstash/fontstash.odin
index b4bf86d46..64c1ce7cd 100644
--- a/vendor/fontstash/fontstash.odin
+++ b/vendor/fontstash/fontstash.odin
@@ -1,12 +1,10 @@
package fontstash
import "core:runtime"
-import "core:fmt"
import "core:log"
import "core:os"
import "core:mem"
import "core:math"
-import "core:unicode"
import "core:strings"
import stbtt "vendor:stb/truetype"
@@ -329,7 +327,7 @@ __AtlasAddWhiteRect :: proc(ctx: ^FontContext, w, h: int) {
// Rasterize
dst := ctx.textureData[gx + gy * ctx.width:]
- for y in 0..<h {
+ for _ in 0..<h {
for x in 0..<w {
dst[x] = 0xff
}
@@ -464,7 +462,7 @@ __getGlyph :: proc(
font: ^Font,
codepoint: rune,
isize: i16,
- blurSize: i16 = 0,
+ blur: i16 = 0,
) -> (res: ^Glyph) #no_bounds_check {
if isize < 2 {
return
@@ -479,7 +477,7 @@ __getGlyph :: proc(
if
glyph.codepoint == codepoint &&
glyph.isize == isize &&
- glyph.blurSize == blurSize
+ glyph.blurSize == blur
{
res = glyph
return
@@ -506,10 +504,10 @@ __getGlyph :: proc(
}
pixel_size := f32(isize) / 10
- blurSize := min(blurSize, 20)
+ blurSize := min(blur, 20)
padding := i16(blurSize + 2) // 2 minimum padding
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
gh := (y1 - y0) + i32(padding) * 2
@@ -596,7 +594,7 @@ BLUR_ZPREC :: 7
__blurCols :: proc(dst: []u8, w, h, dstStride, alpha: int) {
dst := dst
- for y in 0..<h {
+ for _ in 0..<h {
z := 0 // force zero border
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) {
dst := dst
- for x in 0..<w {
+ for _ in 0..<w {
z := 0 // force zero border
for y := dstStride; y < h * dstStride; y += dstStride {
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 {
- width := max(ctx.width, width)
- height := max(ctx.height, height)
+ w := max(ctx.width, width)
+ h := max(ctx.height, height)
- if width == ctx.width && height == ctx.height {
+ if w == ctx.width && h == ctx.height {
return true
}
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 {
- dst := &data[i * width]
+ dst := &data[i * w]
src := &ctx.textureData[i * ctx.width]
mem.copy(dst, src, ctx.width)
- if width > ctx.width {
- mem.set(&data[i * width + ctx.width], 0, width - ctx.width)
+ if w > ctx.width {
+ mem.set(&data[i * w + ctx.width], 0, w - ctx.width)
}
}
- if height > ctx.height {
- mem.set(&data[ctx.height * width], 0, (height - ctx.height) * width)
+ if h > ctx.height {
+ mem.set(&data[ctx.height * w], 0, (h - ctx.height) * w)
}
delete(ctx.textureData)
ctx.textureData = data
// increase atlas size
- __atlasExpand(ctx, width, height)
+ __atlasExpand(ctx, w, h)
// add existing data as dirty
maxy := i16(0)
@@ -700,10 +698,10 @@ ExpandAtlas :: proc(ctx: ^FontContext, width, height: int, allocator := context.
ctx.dirtyRect[2] = f32(ctx.width)
ctx.dirtyRect[3] = f32(maxy)
- ctx.width = width
- ctx.height = height
- ctx.itw = 1.0 / f32(width)
- ctx.ith = 1.0 / f32(height)
+ ctx.width = w
+ ctx.height = h
+ ctx.itw = 1.0 / f32(w)
+ ctx.ith = 1.0 / f32(h)
return true
}
@@ -994,7 +992,7 @@ __getQuad :: proc(
}
// 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)
yoff = f32(glyph.yoff + 1)
x0 = f32(glyph.x0 + 1)
diff --git a/vendor/nanovg/gl/gl.odin b/vendor/nanovg/gl/gl.odin
index 698943e2b..fb1c063f7 100644
--- a/vendor/nanovg/gl/gl.odin
+++ b/vendor/nanovg/gl/gl.odin
@@ -1383,10 +1383,10 @@ BindFramebuffer :: proc(fb: ^framebuffer) {
}
CreateFramebuffer :: proc(ctx: ^nvg.Context, w, h: int, imageFlags: ImageFlags) -> (fb: framebuffer) {
- defaultFBO: i32
- defaultRBO: i32
- gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &defaultFBO)
- gl.GetIntegerv(gl.RENDERBUFFER_BINDING, &defaultRBO)
+ tempFBO: i32
+ tempRBO: i32
+ gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &tempFBO)
+ gl.GetIntegerv(gl.RENDERBUFFER_BINDING, &tempRBO)
imageFlags := imageFlags
incl(&imageFlags, ImageFlags { .FLIP_Y, .PREMULTIPLIED })
@@ -1422,8 +1422,8 @@ CreateFramebuffer :: proc(ctx: ^nvg.Context, w, h: int, imageFlags: ImageFlags)
// goto error
}
- gl.BindFramebuffer(gl.FRAMEBUFFER, u32(defaultFBO))
- gl.BindRenderbuffer(gl.RENDERBUFFER, u32(defaultRBO))
+ gl.BindFramebuffer(gl.FRAMEBUFFER, u32(tempFBO))
+ gl.BindRenderbuffer(gl.RENDERBUFFER, u32(tempRBO))
return
}
diff --git a/vendor/nanovg/nanovg.odin b/vendor/nanovg/nanovg.odin
index 8beb08cce..27054f049 100644
--- a/vendor/nanovg/nanovg.odin
+++ b/vendor/nanovg/nanovg.odin
@@ -4,7 +4,6 @@ package nanovg
// TODO rename enums to old nanovg style!
import "core:mem"
-import "core:runtime"
import "core:math"
import "core:fmt"
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.
LerpRGBA :: proc(c0, c1: Color, u: f32) -> (cint: Color) {
- u := clamp(u, 0.0, 1.0)
- oneminu := 1.0 - u
+ clamped := clamp(u, 0.0, 1.0)
+ oneminu := 1.0 - clamped
for i in 0..<4 {
- cint[i] = c0[i] * oneminu + c1[i] * u
+ cint[i] = c0[i] * oneminu + c1[i] * clamped
}
return
@@ -469,8 +468,8 @@ HSL :: proc(h, s, l: f32) -> Color {
// Returns color value specified by hue, saturation and lightness and alpha.
// HSL values are all in range [0..1], alpha in range [0..255]
-HSLA :: proc(h, s, l: f32, a: u8) -> (col: Color) {
- hue :: proc(h, m1, m2: f32) -> f32 {
+HSLA :: proc(hue, saturation, lightness: f32, a: u8) -> (col: Color) {
+ hue_get :: proc(h, m1, m2: f32) -> f32 {
h := h
if h < 0 {
@@ -492,17 +491,17 @@ HSLA :: proc(h, s, l: f32, a: u8) -> (col: Color) {
return m1
}
- h := math.mod(h, 1.0)
+ h := math.mod(hue, 1.0)
if h < 0.0 {
h += 1.0
}
- s := clamp(s, 0.0, 1.0)
- l := clamp(l, 0.0, 1.0)
+ s := clamp(saturation, 0.0, 1.0)
+ l := clamp(lightness, 0.0, 1.0)
m2 := l <= 0.5 ? (l * (1 + s)) : (l + s - l * s)
m1 := 2 * l - m2
- col.r = clamp(hue(h + 1.0/3.0, m1, m2), 0.0, 1.0)
- col.g = clamp(hue(h, m1, m2), 0.0, 1.0)
- col.b = 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_get(h, 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
return
}
@@ -919,8 +918,8 @@ CreateImageMem :: proc(ctx: ^Context, data: []byte, imageFlags: ImageFlags) -> i
return 0
}
- data := mem.slice_ptr(img, int(w) * int(h) * int(n))
- image := CreateImageRGBA(ctx, int(w), int(h), imageFlags, data)
+ pixel_data := mem.slice_ptr(img, int(w) * int(h) * int(n))
+ image := CreateImageRGBA(ctx, int(w), int(h), imageFlags, pixel_data)
stbi.image_free(img)
return image
}
@@ -1115,11 +1114,11 @@ ImagePattern :: proc(
Scissor :: proc(
ctx: ^Context,
x, y: f32,
- w, h: f32,
+ width, height: f32,
) {
state := __getState(ctx)
- w := max(w, 0)
- h := max(h, 0)
+ w := max(width, 0)
+ h := max(height, 0)
TransformIdentity(&state.scissor.xform)
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
p0.dx = p1.x - p0.x
p0.dy = p1.y - p0.y
@@ -1874,14 +1873,14 @@ __calculateJoins :: proc(
}
// 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:]
p0 := &pts[path.count-1]
p1 := &pts[0]
nleft := 0
path.nbevel = 0
- for j in 0..<path.count {
+ for _ in 0..<path.count {
dlx0, dly0, dlx1, dly1, dmr2, __cross, limit: f32
dlx0 = p0.dy
dly0 = -p0.dx
@@ -2844,14 +2843,14 @@ __isTransformFlipped :: proc(xform: []f32) -> bool {
}
// 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)
scale := __getFontScale(state) * ctx.devicePxRatio
invscale := f32(1.0) / scale
is_flipped := __isTransformFlipped(state.xform[:])
if state.fontId == -1 {
- return x
+ return xpos
}
fs := &ctx.fs
@@ -2871,8 +2870,8 @@ TextIcon :: proc(ctx: ^Context, x, y: f32, codepoint: rune) -> f32 {
fscale := fontstash.__getPixelHeightScale(font, f32(isize) / 10)
// transform x / y
- x := x * scale
- y := y * scale
+ x := xpos * scale
+ y := ypos * scale
switch fstate.ah {
case .LEFT: {}
@@ -3160,7 +3159,7 @@ TextBreakLines :: proc(
fontstash.SetAlignVertical(fs, state.alignVertical)
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^)
prev_iter := iter
q: fontstash.Quad
@@ -3268,7 +3267,7 @@ TextBreakLines :: proc(
}
// 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.
if (break_end == row_start) {
// The current word is longer than the row length, just break it from here.
@@ -3374,7 +3373,6 @@ TextBoxBounds :: proc(
// alignment
halign := state.alignHorizontal
- valign := state.alignVertical
old_align := state.alignHorizontal
defer state.alignHorizontal = old_align
state.alignHorizontal = .LEFT