From 07773e00e98d021ecf02ec31b72d83a87517d6dc Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Sun, 17 Jul 2022 15:25:17 -0700 Subject: [PATCH 01/17] added texture id --- src/nanovg.c | 5 +++++ src/nanovg.h | 5 +++++ src/nanovg_gl.h | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/nanovg.c b/src/nanovg.c index 61826e84..01f5bcad 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -338,6 +338,11 @@ NVGcontext* nvgCreateInternal(NVGparams* params) return 0; } +int nvgGetImageTextureId(NVGcontext* ctx, int handle) +{ + return ctx->params.renderGetImageTextureId(ctx->params.userPtr, handle); +} + NVGparams* nvgInternalParams(NVGcontext* ctx) { return &ctx->params; diff --git a/src/nanovg.h b/src/nanovg.h index cb63e52e..90d23c72 100644 --- a/src/nanovg.h +++ b/src/nanovg.h @@ -624,6 +624,10 @@ void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* l // Words longer than the max width are slit at nearest character (i.e. no hyphenation). int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows); +// Get the GL texture id for specified image handle. Permits shaders to bind to image texture so we can +// directly render to image while preserving z-order and not adding any frame delay. +int nvgGetImageTextureId(NVGcontext* ctx, int handle); + // // Internal Render API // @@ -665,6 +669,7 @@ struct NVGparams { int (*renderDeleteTexture)(void* uptr, int image); int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data); int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h); + int (*renderGetImageTextureId)(void* uptr, int handle); void (*renderViewport)(void* uptr, float width, float height, float devicePixelRatio); void (*renderCancel)(void* uptr); void (*renderFlush)(void* uptr); diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 798b2369..c1ed727c 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -882,6 +882,17 @@ static int glnvg__renderGetTextureSize(void* uptr, int image, int* w, int* h) return 1; } +static int glnvg__renderGetImageTextureId(void* uptr, int handle) +{ + GLNVGcontext* gl = (GLNVGcontext*)uptr; + GLNVGtexture* tex = glnvg__findTexture(gl, handle); + if(tex) { + return tex->tex; + } else { + return -1; + } +} + static void glnvg__xformToMat3x4(float* m3, float* t) { m3[0] = t[0]; @@ -1582,6 +1593,7 @@ NVGcontext* nvgCreateGLES3(int flags) params.renderDeleteTexture = glnvg__renderDeleteTexture; params.renderUpdateTexture = glnvg__renderUpdateTexture; params.renderGetTextureSize = glnvg__renderGetTextureSize; + params.renderGetImageTextureId = glnvg__renderGetImageTextureId; params.renderViewport = glnvg__renderViewport; params.renderCancel = glnvg__renderCancel; params.renderFlush = glnvg__renderFlush; From f0a10679b5ed8e2ef5c10002adcf0e3547010882 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Sun, 17 Jul 2022 15:33:10 -0700 Subject: [PATCH 02/17] cleaned up format --- example/demo.c | 7 ++++++- src/nanovg_gl.h | 12 ++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/example/demo.c b/example/demo.c index 33316229..75439a6c 100644 --- a/example/demo.c +++ b/example/demo.c @@ -816,7 +816,12 @@ int loadDemoData(NVGcontext* vg, DemoData* data) if (data->images[i] == 0) { printf("Could not load %s.\n", file); return -1; - } + } else { + int glTextureId = nvgGetImageTextureId(vg, data->images[i]); + if(glTextureId<0) { + printf("Invalid GL Texture Id for Image\n"); + } + } } data->fontIcons = nvgCreateFont(vg, "icons", "../example/entypo.ttf"); diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index c1ed727c..33849d7b 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -885,12 +885,12 @@ static int glnvg__renderGetTextureSize(void* uptr, int image, int* w, int* h) static int glnvg__renderGetImageTextureId(void* uptr, int handle) { GLNVGcontext* gl = (GLNVGcontext*)uptr; - GLNVGtexture* tex = glnvg__findTexture(gl, handle); - if(tex) { - return tex->tex; - } else { - return -1; - } + GLNVGtexture* tex = glnvg__findTexture(gl, handle); + if(tex) { + return tex->tex; + } else { + return -1; + } } static void glnvg__xformToMat3x4(float* m3, float* t) From c52be9e78311221379b831992612b1aec4f054f8 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Sun, 17 Jul 2022 15:38:49 -0700 Subject: [PATCH 03/17] fixed comment --- example/demo.c | 2 +- src/nanovg.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/demo.c b/example/demo.c index 75439a6c..bba2c89d 100644 --- a/example/demo.c +++ b/example/demo.c @@ -817,7 +817,7 @@ int loadDemoData(NVGcontext* vg, DemoData* data) printf("Could not load %s.\n", file); return -1; } else { - int glTextureId = nvgGetImageTextureId(vg, data->images[i]); + const int glTextureId = nvgGetImageTextureId(vg, data->images[i]); if(glTextureId<0) { printf("Invalid GL Texture Id for Image\n"); } diff --git a/src/nanovg.h b/src/nanovg.h index 90d23c72..309d4d35 100644 --- a/src/nanovg.h +++ b/src/nanovg.h @@ -625,7 +625,7 @@ void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* l int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows); // Get the GL texture id for specified image handle. Permits shaders to bind to image texture so we can -// directly render to image while preserving z-order and not adding any frame delay. +// directly render to image while preserving z-order. int nvgGetImageTextureId(NVGcontext* ctx, int handle); // From e22d493333f2ac1a2d1c6629499ed6ed15bca696 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Sun, 17 Jul 2022 15:40:58 -0700 Subject: [PATCH 04/17] switched to tabs --- example/demo.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example/demo.c b/example/demo.c index bba2c89d..2d6c2cfe 100644 --- a/example/demo.c +++ b/example/demo.c @@ -817,11 +817,11 @@ int loadDemoData(NVGcontext* vg, DemoData* data) printf("Could not load %s.\n", file); return -1; } else { - const int glTextureId = nvgGetImageTextureId(vg, data->images[i]); - if(glTextureId<0) { - printf("Invalid GL Texture Id for Image\n"); - } - } + const int glTextureId = nvgGetImageTextureId(vg, data->images[i]); + if(glTextureId<0) { + printf("Invalid GL Texture Id for Image\n"); + } + } } data->fontIcons = nvgCreateFont(vg, "icons", "../example/entypo.ttf"); From 0b756e0b1e8ef963ce4961e5b10b38badebbd346 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Sun, 17 Jul 2022 15:42:13 -0700 Subject: [PATCH 05/17] added space --- example/demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/demo.c b/example/demo.c index 2d6c2cfe..15b4c31f 100644 --- a/example/demo.c +++ b/example/demo.c @@ -818,7 +818,7 @@ int loadDemoData(NVGcontext* vg, DemoData* data) return -1; } else { const int glTextureId = nvgGetImageTextureId(vg, data->images[i]); - if(glTextureId<0) { + if(glTextureId < 0) { printf("Invalid GL Texture Id for Image\n"); } } From f05de7be52c20f571f280687c0c5cd57c5698dd9 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 00:40:01 -0700 Subject: [PATCH 06/17] added font dilation --- example/demo.c | 15 +++++ src/fontstash.h | 157 +++++++++++++++++++++++++++++++++++++++++++++--- src/nanovg.c | 13 ++++ src/nanovg.h | 3 + 4 files changed, 178 insertions(+), 10 deletions(-) diff --git a/example/demo.c b/example/demo.c index 15b4c31f..63cfaf25 100644 --- a/example/demo.c +++ b/example/demo.c @@ -360,6 +360,20 @@ void drawSlider(NVGcontext* vg, float pos, float x, float y, float w, float h) nvgRestore(vg); } +void drawFancyText(NVGcontext* vg, float x, float y, const char* text){ + nvgFontSize(vg, 50.0f); + nvgFontFace(vg, "sans-bold"); + nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); + nvgFontDilate(vg, 3); // dilate will always be applied before blur + nvgFontBlur(vg, 1); + nvgFillColor(vg, nvgRGB(255, 51, 204)); + nvgText(vg, x, y, text, NULL); + nvgFontDilate(vg,0); + nvgFontBlur(vg,0); + nvgFillColor(vg, nvgRGB(255,255,255)); + nvgText(vg, x, y, text, NULL); +} + void drawEyes(NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t) { NVGpaint gloss, bg; @@ -1073,6 +1087,7 @@ void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, float x,y,popy; drawEyes(vg, width - 250, 50, 150, 100, mx, my, t); + drawFancyText(vg, width - 150, 220, "Font Outline"); drawParagraph(vg, width - 450, 50, 150, 100, mx, my); drawGraph(vg, 0, height/2, width, height/2, t); drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t); diff --git a/src/fontstash.h b/src/fontstash.h index b3feeaab..0ba62143 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -76,7 +76,7 @@ typedef struct FONSquad FONSquad; struct FONStextIter { float x, y, nextx, nexty, scale, spacing; unsigned int codepoint; - short isize, iblur; + short isize, iblur, idilate; struct FONSfont* font; int prevGlyphIndex; const char* str; @@ -116,6 +116,7 @@ void fonsSetSize(FONScontext* s, float size); void fonsSetColor(FONScontext* s, unsigned int color); void fonsSetSpacing(FONScontext* s, float spacing); void fonsSetBlur(FONScontext* s, float blur); +void fonsSetDilate(FONScontext* s, float dilate); void fonsSetAlign(FONScontext* s, int align); void fonsSetFont(FONScontext* s, int font); @@ -225,7 +226,7 @@ struct FONSglyph unsigned int codepoint; int index; int next; - short size, blur; + short size, blur, dilate; short x0,y0,x1,y1; short xadv,xoff,yoff; }; @@ -257,6 +258,7 @@ struct FONSstate float size; unsigned int color; float blur; + float dilate; float spacing; }; typedef struct FONSstate FONSstate; @@ -834,6 +836,10 @@ void fonsSetBlur(FONScontext* stash, float blur) { fons__getState(stash)->blur = blur; } +void fonsSetDilate(FONScontext* stash, float dilate) +{ + fons__getState(stash)->dilate = dilate; +} void fonsSetAlign(FONScontext* stash, int align) { @@ -874,6 +880,7 @@ void fonsClearState(FONScontext* stash) state->color = 0xffffffff; state->font = 0; state->blur = 0; + state->dilate= 0; state->spacing = 0; state->align = FONS_ALIGN_LEFT | FONS_ALIGN_BASELINE; } @@ -1069,12 +1076,127 @@ static void fons__blur(FONScontext* stash, unsigned char* dst, int w, int h, int fons__blurCols(dst, w, h, dstStride, alpha); fons__blurRows(dst, w, h, dstStride, alpha); fons__blurCols(dst, w, h, dstStride, alpha); -// fons__blurrows(dst, w, h, dstStride, alpha); -// fons__blurcols(dst, w, h, dstStride, alpha); +} + +static void fons__maxRows(unsigned char* dst, int w, int h, int dstStride) +{ + int x, y; + for (x = 0; x < w; x++) { + unsigned char prev=dst[0]; + for (y = dstStride; y < h*dstStride; y += dstStride) { + unsigned char current=dst[y]; + if(prev > current){ + dst[y]=prev; + } + prev=current; + } + for (y = (h-2)*dstStride; y >= 0; y -= dstStride) { + unsigned char current=dst[y]; + if(prev > current){ + dst[y]=prev; + } + prev=current; + } + dst++; + } +} + +static void fons__maxCols(unsigned char* dst, int w, int h, int dstStride) +{ + int x, y; + unsigned char prev, current; + for (y = 0; y < h; y++) { + prev=dst[0]; + for (x = 1; x < w; x++) { + current=dst[x]; + if(prev > current){ + dst[x]=prev; + } + prev=current; + } + for (x = w-2; x >= 0; x--) { + current=dst[x]; + if(prev > current){ + dst[x]=prev; + } + prev=current; + } + dst += dstStride; + } +} + +static void fons__maxDiagUp(unsigned char* dst, int w, int h, int dstStride) +{ + int t, y; + const int d=w+h; + const int a =dstStride-1; + unsigned char prev, current; + for(t=0;t current){ + dst[t+y*a]=prev; + } + prev=current; + } + for(y=y_max-2;y>=y_min;y--){ + current=dst[t+y*a]; + if(prev > current){ + dst[t+y*a]=prev; + } + prev=current; + } + } +} + +static void fons__maxDiagDown(unsigned char* dst, int w, int h, int dstStride) +{ + int t, y; + const int d=w+h; + const int a=(h-1)*dstStride; + const int b=dstStride+1; + unsigned char prev, current; + for(t=0;t current){ + dst[t-y*b+a]=prev; + } + prev=current; + } + for(y=y_max-2;y>=y_min;y--){ + current=dst[t-y*b+a]; + if(prev > current){ + dst[t-y*b+a]=prev; + } + prev=current; + } + } +} + +static void fons__dilate(FONScontext* stash, unsigned char* dst, int w, int h, int dstStride, int dilate) +{ + (void)stash; + + for(int iter=0;iter 20) iblur = 20; - pad = iblur+2; + if (idilate > 20) idilate = 20; + const int antiAliasBonus = 2; + pad= antiAliasBonus + iblur + idilate; // Reset allocator. stash->nscratch = 0; @@ -1097,7 +1221,9 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in h = fons__hashint(codepoint) & (FONS_HASH_LUT_SIZE-1); i = font->lut[h]; while (i != -1) { - if (font->glyphs[i].codepoint == codepoint && font->glyphs[i].size == isize && font->glyphs[i].blur == iblur) { + if (font->glyphs[i].codepoint == codepoint && font->glyphs[i].size == isize + && font->glyphs[i].blur == iblur + && font->glyphs[i].dilate == idilate) { glyph = &font->glyphs[i]; if (bitmapOption == FONS_GLYPH_BITMAP_OPTIONAL || (glyph->x0 >= 0 && glyph->y0 >= 0)) { return glyph; @@ -1151,6 +1277,7 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in glyph->codepoint = codepoint; glyph->size = isize; glyph->blur = iblur; + glyph->dilate = idilate; glyph->next = 0; // Insert char to hash lookup. @@ -1195,6 +1322,13 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in } }*/ + // Dilate + if (idilate > 0) { + stash->nscratch = 0; + bdst = &stash->texData[glyph->x0 + glyph->y0 * stash->params.width]; + fons__dilate(stash, bdst, gw, gh, stash->params.width, idilate); + } + // Blur if (iblur > 0) { stash->nscratch = 0; @@ -1331,6 +1465,7 @@ float fonsDrawText(FONScontext* stash, int prevGlyphIndex = -1; short isize = (short)(state->size*10.0f); short iblur = (short)state->blur; + short idilate = (short)state->dilate; float scale; FONSfont* font; float width; @@ -1361,7 +1496,7 @@ float fonsDrawText(FONScontext* stash, for (; str != end; ++str) { if (fons__decutf8(&utf8state, &codepoint, *(const unsigned char*)str)) continue; - glyph = fons__getGlyph(stash, font, codepoint, isize, iblur, FONS_GLYPH_BITMAP_REQUIRED); + glyph = fons__getGlyph(stash, font, codepoint, isize, iblur, idilate, FONS_GLYPH_BITMAP_REQUIRED); if (glyph != NULL) { fons__getQuad(stash, font, prevGlyphIndex, glyph, scale, state->spacing, &x, &y, &q); @@ -1398,6 +1533,7 @@ int fonsTextIterInit(FONScontext* stash, FONStextIter* iter, iter->isize = (short)(state->size*10.0f); iter->iblur = (short)state->blur; + iter->idilate = (short)state->dilate; iter->scale = fons__tt_getPixelHeightScale(&iter->font->font, (float)iter->isize/10.0f); // Align horizontally @@ -1445,7 +1581,7 @@ int fonsTextIterNext(FONScontext* stash, FONStextIter* iter, FONSquad* quad) // Get glyph and quad iter->x = iter->nextx; iter->y = iter->nexty; - glyph = fons__getGlyph(stash, iter->font, iter->codepoint, iter->isize, iter->iblur, iter->bitmapOption); + glyph = fons__getGlyph(stash, iter->font, iter->codepoint, iter->isize, iter->iblur, iter->idilate, iter->bitmapOption); // If the iterator was initialized with FONS_GLYPH_BITMAP_OPTIONAL, then the UV coordinates of the quad will be invalid. if (glyph != NULL) fons__getQuad(stash, iter->font, iter->prevGlyphIndex, glyph, iter->scale, iter->spacing, &iter->nextx, &iter->nexty, quad); @@ -1518,6 +1654,7 @@ float fonsTextBounds(FONScontext* stash, int prevGlyphIndex = -1; short isize = (short)(state->size*10.0f); short iblur = (short)state->blur; + short idilate = (short)state->dilate; float scale; FONSfont* font; float startx, advance; @@ -1543,7 +1680,7 @@ float fonsTextBounds(FONScontext* stash, for (; str != end; ++str) { if (fons__decutf8(&utf8state, &codepoint, *(const unsigned char*)str)) continue; - glyph = fons__getGlyph(stash, font, codepoint, isize, iblur, FONS_GLYPH_BITMAP_OPTIONAL); + glyph = fons__getGlyph(stash, font, codepoint, isize, iblur, idilate, FONS_GLYPH_BITMAP_OPTIONAL); if (glyph != NULL) { fons__getQuad(stash, font, prevGlyphIndex, glyph, scale, state->spacing, &x, &y, &q); if (q.x0 < minx) minx = q.x0; diff --git a/src/nanovg.c b/src/nanovg.c index 01f5bcad..c9304c76 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -84,6 +84,7 @@ struct NVGstate { float letterSpacing; float lineHeight; float fontBlur; + float fontDilate; int textAlign; int fontId; }; @@ -669,6 +670,7 @@ void nvgReset(NVGcontext* ctx) state->letterSpacing = 0.0f; state->lineHeight = 1.0f; state->fontBlur = 0.0f; + state->fontDilate = 0.0f; state->textAlign = NVG_ALIGN_LEFT | NVG_ALIGN_BASELINE; state->fontId = 0; } @@ -2358,6 +2360,12 @@ void nvgFontBlur(NVGcontext* ctx, float blur) state->fontBlur = blur; } +void nvgFontDilate(NVGcontext* ctx, float dilate) +{ + NVGstate* state = nvg__getState(ctx); + state->fontDilate = dilate; +} + void nvgTextLetterSpacing(NVGcontext* ctx, float spacing) { NVGstate* state = nvg__getState(ctx); @@ -2485,6 +2493,7 @@ float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* fonsSetSize(ctx->fs, state->fontSize*scale); fonsSetSpacing(ctx->fs, state->letterSpacing*scale); fonsSetBlur(ctx->fs, state->fontBlur*scale); + fonsSetDilate(ctx->fs, state->fontDilate*scale); fonsSetAlign(ctx->fs, state->textAlign); fonsSetFont(ctx->fs, state->fontId); @@ -2656,6 +2665,7 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa fonsSetSize(ctx->fs, state->fontSize*scale); fonsSetSpacing(ctx->fs, state->letterSpacing*scale); fonsSetBlur(ctx->fs, state->fontBlur*scale); + fonsSetDilate(ctx->fs, state->fontDilate*scale); fonsSetAlign(ctx->fs, state->textAlign); fonsSetFont(ctx->fs, state->fontId); @@ -2840,6 +2850,7 @@ float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const fonsSetSize(ctx->fs, state->fontSize*scale); fonsSetSpacing(ctx->fs, state->letterSpacing*scale); fonsSetBlur(ctx->fs, state->fontBlur*scale); + fonsSetDilate(ctx->fs, state->fontDilate*scale); fonsSetAlign(ctx->fs, state->textAlign); fonsSetFont(ctx->fs, state->fontId); @@ -2884,6 +2895,7 @@ void nvgTextBoxBounds(NVGcontext* ctx, float x, float y, float breakRowWidth, co fonsSetSize(ctx->fs, state->fontSize*scale); fonsSetSpacing(ctx->fs, state->letterSpacing*scale); fonsSetBlur(ctx->fs, state->fontBlur*scale); + fonsSetDilate(ctx->fs, state->fontDilate*scale); fonsSetAlign(ctx->fs, state->textAlign); fonsSetFont(ctx->fs, state->fontId); fonsLineBounds(ctx->fs, 0, &rminy, &rmaxy); @@ -2935,6 +2947,7 @@ void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* l fonsSetSize(ctx->fs, state->fontSize*scale); fonsSetSpacing(ctx->fs, state->letterSpacing*scale); fonsSetBlur(ctx->fs, state->fontBlur*scale); + fonsSetDilate(ctx->fs, state->fontDilate*scale); fonsSetAlign(ctx->fs, state->textAlign); fonsSetFont(ctx->fs, state->fontId); diff --git a/src/nanovg.h b/src/nanovg.h index 309d4d35..f82891fa 100644 --- a/src/nanovg.h +++ b/src/nanovg.h @@ -577,6 +577,9 @@ void nvgFontSize(NVGcontext* ctx, float size); // Sets the blur of current text style. void nvgFontBlur(NVGcontext* ctx, float blur); +// Sets the dilation of current text style. +void nvgFontDilate(NVGcontext* ctx, float dilate); + // Sets the letter spacing of current text style. void nvgTextLetterSpacing(NVGcontext* ctx, float spacing); From 922006a4aab810806bcc3eb0aca444a615fdfa43 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 00:42:58 -0700 Subject: [PATCH 07/17] removed get texture id --- example/demo.c | 5 ----- src/nanovg.c | 5 ----- src/nanovg.h | 5 ----- src/nanovg_gl.h | 12 ------------ 4 files changed, 27 deletions(-) diff --git a/example/demo.c b/example/demo.c index 63cfaf25..2707e396 100644 --- a/example/demo.c +++ b/example/demo.c @@ -830,11 +830,6 @@ int loadDemoData(NVGcontext* vg, DemoData* data) if (data->images[i] == 0) { printf("Could not load %s.\n", file); return -1; - } else { - const int glTextureId = nvgGetImageTextureId(vg, data->images[i]); - if(glTextureId < 0) { - printf("Invalid GL Texture Id for Image\n"); - } } } diff --git a/src/nanovg.c b/src/nanovg.c index c9304c76..fa391276 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -339,11 +339,6 @@ NVGcontext* nvgCreateInternal(NVGparams* params) return 0; } -int nvgGetImageTextureId(NVGcontext* ctx, int handle) -{ - return ctx->params.renderGetImageTextureId(ctx->params.userPtr, handle); -} - NVGparams* nvgInternalParams(NVGcontext* ctx) { return &ctx->params; diff --git a/src/nanovg.h b/src/nanovg.h index f82891fa..26705ba6 100644 --- a/src/nanovg.h +++ b/src/nanovg.h @@ -627,10 +627,6 @@ void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* l // Words longer than the max width are slit at nearest character (i.e. no hyphenation). int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows); -// Get the GL texture id for specified image handle. Permits shaders to bind to image texture so we can -// directly render to image while preserving z-order. -int nvgGetImageTextureId(NVGcontext* ctx, int handle); - // // Internal Render API // @@ -672,7 +668,6 @@ struct NVGparams { int (*renderDeleteTexture)(void* uptr, int image); int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data); int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h); - int (*renderGetImageTextureId)(void* uptr, int handle); void (*renderViewport)(void* uptr, float width, float height, float devicePixelRatio); void (*renderCancel)(void* uptr); void (*renderFlush)(void* uptr); diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 33849d7b..798b2369 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -882,17 +882,6 @@ static int glnvg__renderGetTextureSize(void* uptr, int image, int* w, int* h) return 1; } -static int glnvg__renderGetImageTextureId(void* uptr, int handle) -{ - GLNVGcontext* gl = (GLNVGcontext*)uptr; - GLNVGtexture* tex = glnvg__findTexture(gl, handle); - if(tex) { - return tex->tex; - } else { - return -1; - } -} - static void glnvg__xformToMat3x4(float* m3, float* t) { m3[0] = t[0]; @@ -1593,7 +1582,6 @@ NVGcontext* nvgCreateGLES3(int flags) params.renderDeleteTexture = glnvg__renderDeleteTexture; params.renderUpdateTexture = glnvg__renderUpdateTexture; params.renderGetTextureSize = glnvg__renderGetTextureSize; - params.renderGetImageTextureId = glnvg__renderGetImageTextureId; params.renderViewport = glnvg__renderViewport; params.renderCancel = glnvg__renderCancel; params.renderFlush = glnvg__renderFlush; From fd4de9d932b8a7ed825a17299bc976a798d888c0 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 00:52:33 -0700 Subject: [PATCH 08/17] tweaked num --- example/demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/demo.c b/example/demo.c index 2707e396..81c24b73 100644 --- a/example/demo.c +++ b/example/demo.c @@ -364,7 +364,7 @@ void drawFancyText(NVGcontext* vg, float x, float y, const char* text){ nvgFontSize(vg, 50.0f); nvgFontFace(vg, "sans-bold"); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); - nvgFontDilate(vg, 3); // dilate will always be applied before blur + nvgFontDilate(vg, 2); // Dilate will always be applied before blur nvgFontBlur(vg, 1); nvgFillColor(vg, nvgRGB(255, 51, 204)); nvgText(vg, x, y, text, NULL); From 4681e98e330c2ed390eb1754e96bfc06c226fdbb Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 00:58:56 -0700 Subject: [PATCH 09/17] simplified expression --- src/fontstash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontstash.h b/src/fontstash.h index 0ba62143..c5fdb4bc 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1134,7 +1134,7 @@ static void fons__maxDiagUp(unsigned char* dst, int w, int h, int dstStride) for(t=0;t current){ From 6c10d6e2a0bb72e71ffc64a032788d3628c3c5f2 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 01:01:23 -0700 Subject: [PATCH 10/17] added comment --- src/fontstash.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fontstash.h b/src/fontstash.h index c5fdb4bc..c5129794 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1180,6 +1180,9 @@ static void fons__maxDiagDown(unsigned char* dst, int w, int h, int dstStride) } } +// Gray level morphological dilation approximated by convoling with a max stencil along +// Diagonal convolution overlaps with horizontal and vertical, so we alternate between vertical & horizontal +// and diagonal directions to prevent the dilation from being too large. static void fons__dilate(FONScontext* stash, unsigned char* dst, int w, int h, int dstStride, int dilate) { (void)stash; From 16d1183085ef2a8cd6ebadfff26db2502a80a9c9 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 08:40:33 -0700 Subject: [PATCH 11/17] cleaned up demo --- example/demo.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/example/demo.c b/example/demo.c index 81c24b73..7a9c7c55 100644 --- a/example/demo.c +++ b/example/demo.c @@ -360,18 +360,33 @@ void drawSlider(NVGcontext* vg, float pos, float x, float y, float w, float h) nvgRestore(vg); } -void drawFancyText(NVGcontext* vg, float x, float y, const char* text){ - nvgFontSize(vg, 50.0f); +void drawFancyText(NVGcontext* vg, float x, float y){ + nvgFontSize(vg, 30.0f); nvgFontFace(vg, "sans-bold"); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); - nvgFontDilate(vg, 2); // Dilate will always be applied before blur - nvgFontBlur(vg, 1); - nvgFillColor(vg, nvgRGB(255, 51, 204)); - nvgText(vg, x, y, text, NULL); + + nvgFontBlur(vg, 10); + nvgFillColor(vg, nvgRGB(255, 0, 102)); + nvgText(vg, x, y, "Font Blur", NULL); + nvgFontBlur(vg,0); + nvgFillColor(vg, nvgRGB(255,255,255)); + nvgText(vg, x, y, "Font Blur", NULL); + + nvgFontDilate(vg, 2); + nvgFillColor(vg, nvgRGB(255, 0, 102)); + nvgText(vg, x, y+40, "Font Outline", NULL); + nvgFontDilate(vg,0); + nvgFillColor(vg, nvgRGB(255,255,255)); + nvgText(vg, x, y+40, "Font Outline", NULL); + + nvgFontDilate(vg, 3); // Dilate will always be applied before blur + nvgFontBlur(vg, 2); + nvgFillColor(vg, nvgRGB(255, 0, 102)); + nvgText(vg, x, y+80, "Font Blur Outline", NULL); nvgFontDilate(vg,0); nvgFontBlur(vg,0); nvgFillColor(vg, nvgRGB(255,255,255)); - nvgText(vg, x, y, text, NULL); + nvgText(vg, x, y+80, "Font Blur Outline", NULL); } void drawEyes(NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t) @@ -1082,7 +1097,7 @@ void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, float x,y,popy; drawEyes(vg, width - 250, 50, 150, 100, mx, my, t); - drawFancyText(vg, width - 150, 220, "Font Outline"); + drawFancyText(vg, width - 175, 190); drawParagraph(vg, width - 450, 50, 150, 100, mx, my); drawGraph(vg, 0, height/2, width, height/2, t); drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t); From 078faee576c4a2daff0693a7e851a8e9bd24d080 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 08:45:35 -0700 Subject: [PATCH 12/17] removed cast --- src/fontstash.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fontstash.h b/src/fontstash.h index c5129794..f1753871 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1081,17 +1081,18 @@ static void fons__blur(FONScontext* stash, unsigned char* dst, int w, int h, int static void fons__maxRows(unsigned char* dst, int w, int h, int dstStride) { int x, y; + unsigned char prev, current; for (x = 0; x < w; x++) { - unsigned char prev=dst[0]; + prev=dst[0]; for (y = dstStride; y < h*dstStride; y += dstStride) { - unsigned char current=dst[y]; + current=dst[y]; if(prev > current){ dst[y]=prev; } prev=current; } for (y = (h-2)*dstStride; y >= 0; y -= dstStride) { - unsigned char current=dst[y]; + current=dst[y]; if(prev > current){ dst[y]=prev; } @@ -1128,13 +1129,13 @@ static void fons__maxCols(unsigned char* dst, int w, int h, int dstStride) static void fons__maxDiagUp(unsigned char* dst, int w, int h, int dstStride) { int t, y; - const int d=w+h; const int a =dstStride-1; + const int d=w+h; unsigned char prev, current; for(t=0;t current){ @@ -1155,14 +1156,14 @@ static void fons__maxDiagUp(unsigned char* dst, int w, int h, int dstStride) static void fons__maxDiagDown(unsigned char* dst, int w, int h, int dstStride) { int t, y; - const int d=w+h; const int a=(h-1)*dstStride; const int b=dstStride+1; + const int d=w+h; unsigned char prev, current; for(t=0;t current){ From 8a5f6e9ea799c96744b2f0235bc46373928cba81 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 08:47:37 -0700 Subject: [PATCH 13/17] fixed comment --- src/fontstash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontstash.h b/src/fontstash.h index f1753871..e14f73a7 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1182,7 +1182,7 @@ static void fons__maxDiagDown(unsigned char* dst, int w, int h, int dstStride) } // Gray level morphological dilation approximated by convoling with a max stencil along -// Diagonal convolution overlaps with horizontal and vertical, so we alternate between vertical & horizontal +// Diagonal convolution overlaps with horizontal & vertical, so we alternate between vertical & horizontal // and diagonal directions to prevent the dilation from being too large. static void fons__dilate(FONScontext* stash, unsigned char* dst, int w, int h, int dstStride, int dilate) { From 2e0d75d28a72c637372d46d0507d2abece85e176 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 08:57:39 -0700 Subject: [PATCH 14/17] switched to pointers --- src/fontstash.h | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/fontstash.h b/src/fontstash.h index e14f73a7..d346ec69 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1082,19 +1082,22 @@ static void fons__maxRows(unsigned char* dst, int w, int h, int dstStride) { int x, y; unsigned char prev, current; + unsigned char* ptr; for (x = 0; x < w; x++) { prev=dst[0]; for (y = dstStride; y < h*dstStride; y += dstStride) { - current=dst[y]; + ptr=&dst[y]; + current=*ptr; if(prev > current){ - dst[y]=prev; + *ptr=prev; } prev=current; } for (y = (h-2)*dstStride; y >= 0; y -= dstStride) { - current=dst[y]; + ptr=&dst[y]; + current=*ptr; if(prev > current){ - dst[y]=prev; + *ptr=prev; } prev=current; } @@ -1106,19 +1109,22 @@ static void fons__maxCols(unsigned char* dst, int w, int h, int dstStride) { int x, y; unsigned char prev, current; + unsigned char* ptr; for (y = 0; y < h; y++) { prev=dst[0]; for (x = 1; x < w; x++) { - current=dst[x]; + ptr=&dst[x]; + current=*ptr; if(prev > current){ - dst[x]=prev; + *ptr=prev; } prev=current; } for (x = w-2; x >= 0; x--) { - current=dst[x]; + ptr=&dst[x]; + current=*ptr; if(prev > current){ - dst[x]=prev; + *ptr=prev; } prev=current; } @@ -1132,21 +1138,24 @@ static void fons__maxDiagUp(unsigned char* dst, int w, int h, int dstStride) const int a =dstStride-1; const int d=w+h; unsigned char prev, current; + unsigned char* ptr; for(t=0;t current){ - dst[t+y*a]=prev; + *ptr=prev; } prev=current; } for(y=y_max-2;y>=y_min;y--){ - current=dst[t+y*a]; + ptr=&dst[t+y*a]; + current=*ptr; if(prev > current){ - dst[t+y*a]=prev; + *ptr=prev; } prev=current; } @@ -1160,21 +1169,24 @@ static void fons__maxDiagDown(unsigned char* dst, int w, int h, int dstStride) const int b=dstStride+1; const int d=w+h; unsigned char prev, current; + unsigned char* ptr; for(t=0;t current){ - dst[t-y*b+a]=prev; + *ptr=prev; } prev=current; } for(y=y_max-2;y>=y_min;y--){ - current=dst[t-y*b+a]; + ptr=&dst[t-y*b+a]; + current=*ptr; if(prev > current){ - dst[t-y*b+a]=prev; + *ptr=prev; } prev=current; } From 130d13d54e46b224b2c3f18c9ab3f0fd84dfff79 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 09:00:05 -0700 Subject: [PATCH 15/17] Update src/fontstash.h Co-authored-by: Dominus Iniquitatis --- src/fontstash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontstash.h b/src/fontstash.h index d346ec69..bea8bacc 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1228,7 +1228,7 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in if (iblur > 20) iblur = 20; if (idilate > 20) idilate = 20; const int antiAliasBonus = 2; - pad= antiAliasBonus + iblur + idilate; + pad = antiAliasBonus + iblur + idilate; // Reset allocator. stash->nscratch = 0; From ee4612dc489b3ca104a4d44d237719e8e93df18a Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 09:00:28 -0700 Subject: [PATCH 16/17] Update src/fontstash.h Co-authored-by: Dominus Iniquitatis --- src/fontstash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontstash.h b/src/fontstash.h index bea8bacc..e7b0b3cf 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1193,7 +1193,7 @@ static void fons__maxDiagDown(unsigned char* dst, int w, int h, int dstStride) } } -// Gray level morphological dilation approximated by convoling with a max stencil along +// Gray level morphological dilation approximated by convolving with a max stencil along // Diagonal convolution overlaps with horizontal & vertical, so we alternate between vertical & horizontal // and diagonal directions to prevent the dilation from being too large. static void fons__dilate(FONScontext* stash, unsigned char* dst, int w, int h, int dstStride, int dilate) From bbe00767815ecfc1c051ba7188d3fd9315046536 Mon Sep 17 00:00:00 2001 From: Blake Lucas Date: Mon, 25 Jul 2022 09:18:20 -0700 Subject: [PATCH 17/17] fixed loop start --- src/fontstash.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fontstash.h b/src/fontstash.h index d346ec69..41be756d 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -1151,7 +1151,7 @@ static void fons__maxDiagUp(unsigned char* dst, int w, int h, int dstStride) } prev=current; } - for(y=y_max-2;y>=y_min;y--){ + for(y=y_max-1;y>=y_min;y--){ ptr=&dst[t+y*a]; current=*ptr; if(prev > current){ @@ -1182,7 +1182,7 @@ static void fons__maxDiagDown(unsigned char* dst, int w, int h, int dstStride) } prev=current; } - for(y=y_max-2;y>=y_min;y--){ + for(y=y_max-1;y>=y_min;y--){ ptr=&dst[t-y*b+a]; current=*ptr; if(prev > current){