mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-02 19:14:42 +00:00
Merge pull request #2268 from Skytrias/skytrias-vendor-additions
fontstash / nanovg vendor additions
This commit is contained in:
@@ -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
|
||||
_ :: lua_5_4
|
||||
|
||||
_ :: nvg
|
||||
_ :: nvg_gl
|
||||
_ :: fontstash
|
||||
14
vendor/README.md
vendored
14
vendor/README.md
vendored
@@ -6,9 +6,9 @@ Its use is similar to that of `core:` packages, which would be available in any
|
||||
|
||||
Presently, the `vendor:` collection comprises the following packages:
|
||||
|
||||
## microui
|
||||
## microui (Port)
|
||||
|
||||
A tiny, portable, immediate-mode UI library written in Odin. (Ported from [rxi/microui](https://github.com/rxi/microui).)
|
||||
A tiny, portable, immediate-mode UI library written in Odin. [rxi/microui](https://github.com/rxi/microui)
|
||||
|
||||
This package is available under the MIT license. See `LICENSE` for more details.
|
||||
|
||||
@@ -158,4 +158,12 @@ Includes full bindings.
|
||||
|
||||
Used in: [bgfx](https://github.com/bkaradzic/bgfx), [Filament](https://github.com/google/filament), [gltfpack](https://github.com/zeux/meshoptimizer/tree/master/gltf), [raylib](https://github.com/raysan5/raylib), [Unigine](https://developer.unigine.com/en/docs/2.14.1/third_party?rlang=cpp#cgltf), and more!
|
||||
|
||||
See also LICENCE in `cgltf` directory itself.
|
||||
Se also LICENCE in `cgltf` directory itself.
|
||||
|
||||
## nanovg (Port)
|
||||
|
||||
[NanoVG](https://github.com/memononen/nanovg) is a small antialiased vector graphics rendering library for OpenGL. It has lean API modeled after HTML5 canvas API. It is aimed to be a practical and fun toolset for building scalable user interfaces and visualizations.
|
||||
|
||||
## fontstash (Port)
|
||||
|
||||
[Font stash](https://github.com/memononen/fontstash) is a light-weight online font texture atlas builder. It uses stb_truetype to render fonts on demand to a texture atlas.
|
||||
|
||||
1229
vendor/fontstash/fontstash.odin
vendored
Normal file
1229
vendor/fontstash/fontstash.odin
vendored
Normal file
File diff suppressed because it is too large
Load Diff
123
vendor/nanovg/gl/frag.glsl
vendored
Normal file
123
vendor/nanovg/gl/frag.glsl
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifdef GL_ES
|
||||
#if defined(GL_FRAGMENT_PRECISION_HIGH) || defined(NANOVG_GL3)
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NANOVG_GL3
|
||||
#ifdef USE_UNIFORMBUFFER
|
||||
layout(std140) uniform frag {
|
||||
mat3 scissorMat;
|
||||
mat3 paintMat;
|
||||
vec4 innerCol;
|
||||
vec4 outerCol;
|
||||
vec2 scissorExt;
|
||||
vec2 scissorScale;
|
||||
vec2 extent;
|
||||
float radius;
|
||||
float feather;
|
||||
float strokeMult;
|
||||
float strokeThr;
|
||||
int texType;
|
||||
int type;
|
||||
};
|
||||
#else // NANOVG_GL3 && !USE_UNIFORMBUFFER
|
||||
uniform vec4 frag[UNIFORMARRAY_SIZE];
|
||||
#endif
|
||||
uniform sampler2D tex;
|
||||
in vec2 ftcoord;
|
||||
in vec2 fpos;
|
||||
out vec4 outColor;
|
||||
#else // !NANOVG_GL3
|
||||
uniform vec4 frag[UNIFORMARRAY_SIZE];
|
||||
uniform sampler2D tex;
|
||||
varying vec2 ftcoord;
|
||||
varying vec2 fpos;
|
||||
#endif
|
||||
#ifndef USE_UNIFORMBUFFER
|
||||
#define scissorMat mat3(frag[0].xyz, frag[1].xyz, frag[2].xyz)
|
||||
#define paintMat mat3(frag[3].xyz, frag[4].xyz, frag[5].xyz)
|
||||
#define innerCol frag[6]
|
||||
#define outerCol frag[7]
|
||||
#define scissorExt frag[8].xy
|
||||
#define scissorScale frag[8].zw
|
||||
#define extent frag[9].xy
|
||||
#define radius frag[9].z
|
||||
#define feather frag[9].w
|
||||
#define strokeMult frag[10].x
|
||||
#define strokeThr frag[10].y
|
||||
#define texType int(frag[10].z)
|
||||
#define type int(frag[10].w)
|
||||
#endif
|
||||
|
||||
float sdroundrect(vec2 pt, vec2 ext, float rad) {
|
||||
vec2 ext2 = ext - vec2(rad,rad);
|
||||
vec2 d = abs(pt) - ext2;
|
||||
return min(max(d.x,d.y),0.0) + length(max(d,0.0)) - rad;
|
||||
}
|
||||
|
||||
// Scissoring
|
||||
float scissorMask(vec2 p) {
|
||||
vec2 sc = (abs((scissorMat * vec3(p,1.0)).xy) - scissorExt);
|
||||
sc = vec2(0.5,0.5) - sc * scissorScale;
|
||||
return clamp(sc.x,0.0,1.0) * clamp(sc.y,0.0,1.0);
|
||||
}
|
||||
#ifdef EDGE_AA
|
||||
// Stroke - from [0..1] to clipped pyramid, where the slope is 1px.
|
||||
float strokeMask() {
|
||||
return min(1.0, (1.0-abs(ftcoord.x*2.0-1.0))*strokeMult) * min(1.0, ftcoord.y);
|
||||
}
|
||||
#endif
|
||||
|
||||
void main(void) {
|
||||
vec4 result;
|
||||
float scissor = scissorMask(fpos);
|
||||
#ifdef EDGE_AA
|
||||
float strokeAlpha = strokeMask();
|
||||
if (strokeAlpha < strokeThr) discard;
|
||||
#else
|
||||
float strokeAlpha = 1.0;
|
||||
#endif
|
||||
if (type == 0) { // Gradient
|
||||
// Calculate gradient color using box gradient
|
||||
vec2 pt = (paintMat * vec3(fpos,1.0)).xy;
|
||||
float d = clamp((sdroundrect(pt, extent, radius) + feather*0.5) / feather, 0.0, 1.0);
|
||||
vec4 color = mix(innerCol,outerCol,d);
|
||||
// Combine alpha
|
||||
color *= strokeAlpha * scissor;
|
||||
result = color;
|
||||
} else if (type == 1) { // Image
|
||||
// Calculate color fron texture
|
||||
vec2 pt = (paintMat * vec3(fpos,1.0)).xy / extent;
|
||||
#ifdef NANOVG_GL3
|
||||
vec4 color = texture(tex, pt);
|
||||
#else
|
||||
vec4 color = texture2D(tex, pt);
|
||||
#endif
|
||||
if (texType == 1) color = vec4(color.xyz*color.w,color.w);
|
||||
if (texType == 2) color = vec4(color.x);
|
||||
// Apply color tint and alpha.
|
||||
color *= innerCol;
|
||||
// Combine alpha
|
||||
color *= strokeAlpha * scissor;
|
||||
result = color;
|
||||
} else if (type == 2) { // Stencil fill
|
||||
result = vec4(1,1,1,1);
|
||||
} else if (type == 3) { // Textured tris
|
||||
#ifdef NANOVG_GL3
|
||||
vec4 color = texture(tex, ftcoord);
|
||||
#else
|
||||
vec4 color = texture2D(tex, ftcoord);
|
||||
#endif
|
||||
if (texType == 1) color = vec4(color.xyz*color.w,color.w);
|
||||
if (texType == 2) color = vec4(color.x);
|
||||
color *= scissor;
|
||||
result = color * innerCol;
|
||||
}
|
||||
#ifdef NANOVG_GL3
|
||||
outColor = result;
|
||||
#else
|
||||
gl_FragColor = result;
|
||||
#endif
|
||||
}
|
||||
1453
vendor/nanovg/gl/gl.odin
vendored
Normal file
1453
vendor/nanovg/gl/gl.odin
vendored
Normal file
File diff suppressed because it is too large
Load Diff
19
vendor/nanovg/gl/vert.glsl
vendored
Normal file
19
vendor/nanovg/gl/vert.glsl
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifdef NANOVG_GL3
|
||||
uniform vec2 viewSize;
|
||||
in vec2 vertex;
|
||||
in vec2 tcoord;
|
||||
out vec2 ftcoord;
|
||||
out vec2 fpos;
|
||||
#else
|
||||
uniform vec2 viewSize;
|
||||
attribute vec2 vertex;
|
||||
attribute vec2 tcoord;
|
||||
varying vec2 ftcoord;
|
||||
varying vec2 fpos;
|
||||
#endif
|
||||
|
||||
void main(void) {
|
||||
ftcoord = tcoord;
|
||||
fpos = vertex;
|
||||
gl_Position = vec4(2.0*vertex.x/viewSize.x - 1.0, 1.0 - 2.0*vertex.y/viewSize.y, 0, 1);
|
||||
}
|
||||
3481
vendor/nanovg/nanovg.odin
vendored
Normal file
3481
vendor/nanovg/nanovg.odin
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user