From 339c5e507b804f9d5f0f7f57e745867253b6e568 Mon Sep 17 00:00:00 2001 From: satoren Date: Thu, 15 Sep 2016 02:11:06 +0900 Subject: [PATCH 1/3] Improve nvgGlobalCompositeOperation with state --- example/demo.c | 60 ++++++++++++++++++++++++++++++ example/demo.h | 2 + example/images/composite_a.png | Bin 0 -> 162 bytes example/images/composite_b.png | Bin 0 -> 591 bytes src/nanovg.c | 8 ++-- src/nanovg.h | 8 ++-- src/nanovg_gl.h | 66 ++++++++++++++++++++++++++------- 7 files changed, 122 insertions(+), 22 deletions(-) create mode 100644 example/images/composite_a.png create mode 100644 example/images/composite_b.png diff --git a/example/demo.c b/example/demo.c index cfad99e..f54709d 100644 --- a/example/demo.c +++ b/example/demo.c @@ -818,6 +818,9 @@ int loadDemoData(NVGcontext* vg, DemoData* data) return -1; } } + + data->image_composite_a = nvgCreateImage(vg, "../example/images/composite_a.png", 0); + data->image_composite_b = nvgCreateImage(vg, "../example/images/composite_b.png", 0); data->fontIcons = nvgCreateFont(vg, "icons", "../example/entypo.ttf"); if (data->fontIcons == -1) { @@ -854,6 +857,9 @@ void freeDemoData(NVGcontext* vg, DemoData* data) for (i = 0; i < 12; i++) nvgDeleteImage(vg, data->images[i]); + + nvgDeleteImage(vg, data->image_composite_a); + nvgDeleteImage(vg, data->image_composite_b); } void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, float mx, float my) @@ -1060,6 +1066,58 @@ void drawScissor(NVGcontext* vg, float x, float y, float t) nvgRestore(vg); } + +void drawGlobalCompositeOperation(NVGcontext* vg, float x, float y, DemoData* data) +{ + int i; + NVGpaint imgPaint; + enum NVGcompositeOperation ops[] = { + NVG_SOURCE_OVER, + NVG_SOURCE_IN, + NVG_SOURCE_OUT, + NVG_ATOP, + NVG_DESTINATION_OVER, + NVG_DESTINATION_IN, + NVG_DESTINATION_OUT, + NVG_DESTINATION_ATOP, + NVG_LIGHTER, + NVG_COPY, + NVG_XOR}; + + int count = sizeof(ops)/sizeof(ops[0]); + + + for(i=0;iimage_composite_a, 1.0); + nvgBeginPath(vg); + nvgRect(vg, 0, 0, 30, 30); + nvgFillPaint(vg, imgPaint); + nvgFill(vg); + + nvgGlobalCompositeOperation(vg, ops[i]); + imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_b, 1.0); + nvgBeginPath(vg); + nvgRect(vg, 0, 0, 30, 30); + nvgFillPaint(vg, imgPaint); + nvgFill(vg); + + //fill background transparent color to white. + nvgGlobalCompositeOperation(vg, NVG_DESTINATION_OVER); + nvgBeginPath(vg); + nvgRect(vg, 0, 0, 30, 30); + nvgFillColor(vg, nvgRGBA(255,255,255,255)); + nvgFill(vg); + + nvgRestore(vg); + } +} + void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, float t, int blowup, DemoData* data) { @@ -1080,6 +1138,8 @@ void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, drawCaps(vg, 10, 300, 30); drawScissor(vg, 50, height-80, t); + + drawGlobalCompositeOperation(vg, 100, height-35, data); nvgSave(vg); if (blowup) { diff --git a/example/demo.h b/example/demo.h index aace449..00c2588 100644 --- a/example/demo.h +++ b/example/demo.h @@ -10,6 +10,8 @@ extern "C" { struct DemoData { int fontNormal, fontBold, fontIcons, fontEmoji; int images[12]; + int image_composite_a; + int image_composite_b; }; typedef struct DemoData DemoData; diff --git a/example/images/composite_a.png b/example/images/composite_a.png new file mode 100644 index 0000000000000000000000000000000000000000..6d9f3b530e016af63ed01b84464ebd21afc67281 GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPNC!ZjT)aI>$kw77RPZ!4!kK=F8ZscW95MbWe^0&Os wt%0fY*gF4RYQ~kT_O1-GGcFVdQ&MBb@03etw<^TWy literal 0 HcmV?d00001 diff --git a/example/images/composite_b.png b/example/images/composite_b.png new file mode 100644 index 0000000000000000000000000000000000000000..dca6cad177c6c341042b40ac5f22f7dcccde1c0a GIT binary patch literal 591 zcmV-V091Qb*ad|m(m0o+MM zK~zY`?Upfa+b|S{KgyDlqCh)z=v=r5FiIsu+PSM?AliF~9zaL&UIT{Lt~NTfHsAx; z2k77cMNz+m{aZfn}Kp&qQd&;tFm6;XVSX=v!PtXp6B~rsEW!UWl939cjOuhA}L^nf<}B z75Op66od^}em4&XpIEWp^8b2bnm`9=11;A*1qMJrvYKz|YG5@syTNfH^4vel0lUD5 z9eW=EpCYR{f*>g1m4_=$Rg}{Yy#!_tfa1o?t|#UaQyh^rRkh+c5xFX%Uk!M zvnAD$Rp|h`^v;g-j<>PZ+?(p>XWE#;Khdqhw7RNN9G{DP{U~ZTs=bPHze#jzwCau* z9QeWQ8o_P9Vt;*GHG*4y#fC=@FF2CdIHomnr(W=%9|lvd^PooXpwco;S#iHcaK94V ze)Bin-7=#ZpraG3`ChkEU6%Q*$};a_H8uo6Np*SzG>zYBzMPodZ?4tY5H{|g4Utvv zKzJHk_1?eObJppF2$SNW7Zx{HQ!sRIylrhLXhv3t=PAoXc<$gy(cA_;JHT((hOVy} dB_c}7&|CCIz&9yWcT)fW002ovPDHLkV1kq&0EGYm literal 0 HcmV?d00001 diff --git a/src/nanovg.c b/src/nanovg.c index c388696..54d01ee 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -385,7 +385,7 @@ void nvgCancelFrame(NVGcontext* ctx) void nvgEndFrame(NVGcontext* ctx) { NVGstate* state = nvg__getState(ctx); - ctx->params.renderFlush(ctx->params.userPtr, state->compositeOperation); + ctx->params.renderFlush(ctx->params.userPtr); if (ctx->fontImageIdx != 0) { int fontImage = ctx->fontImages[ctx->fontImageIdx]; int i, j, iw, ih; @@ -2198,7 +2198,7 @@ void nvgFill(NVGcontext* ctx) fillPaint.innerColor.a *= state->alpha; fillPaint.outerColor.a *= state->alpha; - ctx->params.renderFill(ctx->params.userPtr, &fillPaint, &state->scissor, ctx->fringeWidth, + ctx->params.renderFill(ctx->params.userPtr, &fillPaint, state->compositeOperation, &state->scissor, ctx->fringeWidth, ctx->cache->bounds, ctx->cache->paths, ctx->cache->npaths); // Count triangles @@ -2239,7 +2239,7 @@ void nvgStroke(NVGcontext* ctx) else nvg__expandStroke(ctx, strokeWidth*0.5f, state->lineCap, state->lineJoin, state->miterLimit); - ctx->params.renderStroke(ctx->params.userPtr, &strokePaint, &state->scissor, ctx->fringeWidth, + ctx->params.renderStroke(ctx->params.userPtr, &strokePaint, state->compositeOperation, &state->scissor, ctx->fringeWidth, strokeWidth, ctx->cache->paths, ctx->cache->npaths); // Count triangles @@ -2387,7 +2387,7 @@ static void nvg__renderText(NVGcontext* ctx, NVGvertex* verts, int nverts) paint.innerColor.a *= state->alpha; paint.outerColor.a *= state->alpha; - ctx->params.renderTriangles(ctx->params.userPtr, &paint, &state->scissor, verts, nverts); + ctx->params.renderTriangles(ctx->params.userPtr, &paint, state->compositeOperation, &state->scissor, verts, nverts); ctx->drawCallCount++; ctx->textTriCount += nverts/3; diff --git a/src/nanovg.h b/src/nanovg.h index e8a59fa..aa06ea4 100644 --- a/src/nanovg.h +++ b/src/nanovg.h @@ -648,10 +648,10 @@ struct NVGparams { int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h); void (*renderViewport)(void* uptr, int width, int height, float devicePixelRatio); void (*renderCancel)(void* uptr); - void (*renderFlush)(void* uptr, NVGcompositeOperationState compositeOperation); - void (*renderFill)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths); - void (*renderStroke)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths); - void (*renderTriangles)(void* uptr, NVGpaint* paint, NVGscissor* scissor, const NVGvertex* verts, int nverts); + void (*renderFlush)(void* uptr); + void (*renderFill)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths); + void (*renderStroke)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths); + void (*renderTriangles)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, const NVGvertex* verts, int nverts); void (*renderDelete)(void* uptr); }; typedef struct NVGparams NVGparams; diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 4ec95ce..43853e6 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -150,6 +150,15 @@ struct GLNVGtexture { }; typedef struct GLNVGtexture GLNVGtexture; +struct GLNVGblend +{ + GLenum srcRGB; + GLenum dstRGB; + GLenum srcAlpha; + GLenum dstAlpha; +}; +typedef struct GLNVGblend GLNVGblend; + enum GLNVGcallType { GLNVG_NONE = 0, GLNVG_FILL, @@ -166,6 +175,7 @@ struct GLNVGcall { int triangleOffset; int triangleCount; int uniformOffset; + GLNVGblend blendFunc; }; typedef struct GLNVGcall GLNVGcall; @@ -256,6 +266,7 @@ struct GLNVGcontext { GLenum stencilFunc; GLint stencilFuncRef; GLuint stencilFuncMask; + GLNVGblend blendFunc; #endif }; typedef struct GLNVGcontext GLNVGcontext; @@ -316,6 +327,21 @@ static void glnvg__stencilFunc(GLNVGcontext* gl, GLenum func, GLint ref, GLuint glStencilFunc(func, ref, mask); #endif } +static void glnvg__blendFuncSeparate(GLNVGcontext* gl, const GLNVGblend* blend) +{ +#if NANOVG_GL_USE_STATE_FILTER + if ((gl->blendFunc.srcRGB != blend->srcRGB) || + (gl->blendFunc.dstRGB != blend->dstRGB) || + (gl->blendFunc.srcAlpha != blend->srcAlpha) || + (gl->blendFunc.dstAlpha != blend->dstAlpha)) { + + gl->blendFunc = *blend; + glBlendFuncSeparate(blend->srcRGB, blend->dstRGB, blend->srcAlpha,blend->dstAlpha); + } +#else + glBlendFuncSeparate(blend->srcRGB, blend->dstRGB, blend->srcAlpha,blend->dstAlpha); +#endif +} static GLNVGtexture* glnvg__allocTexture(GLNVGcontext* gl) { @@ -1099,19 +1125,24 @@ static GLenum glnvg_convertBlendFuncFactor(int factor) return GL_INVALID_ENUM; } -static void glnvg__blendCompositeOperation(NVGcompositeOperationState op) +static GLNVGblend glnvg__blendCompositeOperation(NVGcompositeOperationState op) { - GLenum srcRGB = glnvg_convertBlendFuncFactor(op.srcRGB); - GLenum dstRGB = glnvg_convertBlendFuncFactor(op.dstRGB); - GLenum srcAlpha = glnvg_convertBlendFuncFactor(op.srcAlpha); - GLenum dstAlpha = glnvg_convertBlendFuncFactor(op.dstAlpha); - if (srcRGB == GL_INVALID_ENUM || dstRGB == GL_INVALID_ENUM || srcAlpha == GL_INVALID_ENUM || dstAlpha == GL_INVALID_ENUM) - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - else - glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); + GLNVGblend blend; + blend.srcRGB = glnvg_convertBlendFuncFactor(op.srcRGB); + blend.dstRGB = glnvg_convertBlendFuncFactor(op.dstRGB); + blend.srcAlpha = glnvg_convertBlendFuncFactor(op.srcAlpha); + blend.dstAlpha = glnvg_convertBlendFuncFactor(op.dstAlpha); + if (blend.srcRGB == GL_INVALID_ENUM || blend.dstRGB == GL_INVALID_ENUM || blend.srcAlpha == GL_INVALID_ENUM || blend.dstAlpha == GL_INVALID_ENUM) + { + blend.srcRGB = GL_ONE; + blend.dstRGB = GL_ONE_MINUS_SRC_ALPHA; + blend.srcAlpha = GL_ONE; + blend.dstAlpha = GL_ONE_MINUS_SRC_ALPHA; + } + return blend; } -static void glnvg__renderFlush(void* uptr, NVGcompositeOperationState compositeOperation) +static void glnvg__renderFlush(void* uptr) { GLNVGcontext* gl = (GLNVGcontext*)uptr; int i; @@ -1121,7 +1152,6 @@ static void glnvg__renderFlush(void* uptr, NVGcompositeOperationState compositeO // Setup require GL state. glUseProgram(gl->shader.prog); - glnvg__blendCompositeOperation(compositeOperation); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); @@ -1140,6 +1170,10 @@ static void glnvg__renderFlush(void* uptr, NVGcompositeOperationState compositeO gl->stencilFunc = GL_ALWAYS; gl->stencilFuncRef = 0; gl->stencilFuncMask = 0xffffffff; + gl->blendFunc.srcRGB = GL_INVALID_ENUM; + gl->blendFunc.srcAlpha = GL_INVALID_ENUM; + gl->blendFunc.dstRGB = GL_INVALID_ENUM; + gl->blendFunc.dstAlpha = GL_INVALID_ENUM; #endif #if NANOVG_GL_USE_UNIFORMBUFFER @@ -1169,6 +1203,7 @@ static void glnvg__renderFlush(void* uptr, NVGcompositeOperationState compositeO for (i = 0; i < gl->ncalls; i++) { GLNVGcall* call = &gl->calls[i]; + glnvg__blendFuncSeparate(gl,&call->blendFunc); if (call->type == GLNVG_FILL) glnvg__fill(gl, call); else if (call->type == GLNVG_CONVEXFILL) @@ -1284,7 +1319,7 @@ static void glnvg__vset(NVGvertex* vtx, float x, float y, float u, float v) vtx->v = v; } -static void glnvg__renderFill(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, +static void glnvg__renderFill(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths) { GLNVGcontext* gl = (GLNVGcontext*)uptr; @@ -1300,6 +1335,7 @@ static void glnvg__renderFill(void* uptr, NVGpaint* paint, NVGscissor* scissor, if (call->pathOffset == -1) goto error; call->pathCount = npaths; call->image = paint->image; + call->blendFunc = glnvg__blendCompositeOperation(compositeOperation); if (npaths == 1 && paths[0].convex) call->type = GLNVG_CONVEXFILL; @@ -1365,7 +1401,7 @@ error: if (gl->ncalls > 0) gl->ncalls--; } -static void glnvg__renderStroke(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, +static void glnvg__renderStroke(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths) { GLNVGcontext* gl = (GLNVGcontext*)uptr; @@ -1379,6 +1415,7 @@ static void glnvg__renderStroke(void* uptr, NVGpaint* paint, NVGscissor* scissor if (call->pathOffset == -1) goto error; call->pathCount = npaths; call->image = paint->image; + call->blendFunc = glnvg__blendCompositeOperation(compositeOperation); // Allocate vertices for all the paths. maxverts = glnvg__maxVertCount(paths, npaths); @@ -1420,7 +1457,7 @@ error: if (gl->ncalls > 0) gl->ncalls--; } -static void glnvg__renderTriangles(void* uptr, NVGpaint* paint, NVGscissor* scissor, +static void glnvg__renderTriangles(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, const NVGvertex* verts, int nverts) { GLNVGcontext* gl = (GLNVGcontext*)uptr; @@ -1431,6 +1468,7 @@ static void glnvg__renderTriangles(void* uptr, NVGpaint* paint, NVGscissor* scis call->type = GLNVG_TRIANGLES; call->image = paint->image; + call->blendFunc = glnvg__blendCompositeOperation(compositeOperation); // Allocate vertices for all the paths. call->triangleOffset = glnvg__allocVerts(gl, nverts); From 9dbd79dbc7bd95c2d24d1397206021dabbb2be7f Mon Sep 17 00:00:00 2001 From: satoren Date: Thu, 15 Sep 2016 04:41:01 +0900 Subject: [PATCH 2/3] Code format --- example/demo.c | 92 ++++++++++++++++++++++++------------------------- src/nanovg_gl.h | 2 +- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/example/demo.c b/example/demo.c index f54709d..b855f52 100644 --- a/example/demo.c +++ b/example/demo.c @@ -1069,53 +1069,51 @@ void drawScissor(NVGcontext* vg, float x, float y, float t) void drawGlobalCompositeOperation(NVGcontext* vg, float x, float y, DemoData* data) { - int i; - NVGpaint imgPaint; - enum NVGcompositeOperation ops[] = { - NVG_SOURCE_OVER, - NVG_SOURCE_IN, - NVG_SOURCE_OUT, - NVG_ATOP, - NVG_DESTINATION_OVER, - NVG_DESTINATION_IN, - NVG_DESTINATION_OUT, - NVG_DESTINATION_ATOP, - NVG_LIGHTER, - NVG_COPY, - NVG_XOR}; - - int count = sizeof(ops)/sizeof(ops[0]); - - - for(i=0;iimage_composite_a, 1.0); - nvgBeginPath(vg); - nvgRect(vg, 0, 0, 30, 30); - nvgFillPaint(vg, imgPaint); - nvgFill(vg); - - nvgGlobalCompositeOperation(vg, ops[i]); - imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_b, 1.0); - nvgBeginPath(vg); - nvgRect(vg, 0, 0, 30, 30); - nvgFillPaint(vg, imgPaint); - nvgFill(vg); - - //fill background transparent color to white. - nvgGlobalCompositeOperation(vg, NVG_DESTINATION_OVER); - nvgBeginPath(vg); - nvgRect(vg, 0, 0, 30, 30); - nvgFillColor(vg, nvgRGBA(255,255,255,255)); - nvgFill(vg); - - nvgRestore(vg); - } + int i; + NVGpaint imgPaint; + enum NVGcompositeOperation ops[] = { + NVG_SOURCE_OVER, + NVG_SOURCE_IN, + NVG_SOURCE_OUT, + NVG_ATOP, + NVG_DESTINATION_OVER, + NVG_DESTINATION_IN, + NVG_DESTINATION_OUT, + NVG_DESTINATION_ATOP, + NVG_LIGHTER, + NVG_COPY, + NVG_XOR + }; + + for (i = 0; i < 11; i++) + { + nvgSave(vg); + + nvgTranslate(vg, x + i * 40, y); + + nvgGlobalCompositeOperation(vg, NVG_COPY); + imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_a, 1.0); + nvgBeginPath(vg); + nvgRect(vg, 0, 0, 30, 30); + nvgFillPaint(vg, imgPaint); + nvgFill(vg); + + nvgGlobalCompositeOperation(vg, ops[i]); + imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_b, 1.0); + nvgBeginPath(vg); + nvgRect(vg, 0, 0, 30, 30); + nvgFillPaint(vg, imgPaint); + nvgFill(vg); + + //fill background transparent color to white. + nvgGlobalCompositeOperation(vg, NVG_DESTINATION_OVER); + nvgBeginPath(vg); + nvgRect(vg, 0, 0, 30, 30); + nvgFillColor(vg, nvgRGBA(255,255,255,255)); + nvgFill(vg); + + nvgRestore(vg); + } } void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 43853e6..68d1f85 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -1138,7 +1138,7 @@ static GLNVGblend glnvg__blendCompositeOperation(NVGcompositeOperationState op) blend.dstRGB = GL_ONE_MINUS_SRC_ALPHA; blend.srcAlpha = GL_ONE; blend.dstAlpha = GL_ONE_MINUS_SRC_ALPHA; - } + } return blend; } From a457efa3c4fdc916eb4618249ffea4aa82808eeb Mon Sep 17 00:00:00 2001 From: satoren Date: Sun, 18 Sep 2016 23:47:56 +0900 Subject: [PATCH 3/3] Remove demo code for nvgGlobalCompositeOperation --- example/demo.c | 58 --------------------------------- example/demo.h | 2 -- example/images/composite_a.png | Bin 162 -> 0 bytes example/images/composite_b.png | Bin 591 -> 0 bytes 4 files changed, 60 deletions(-) delete mode 100644 example/images/composite_a.png delete mode 100644 example/images/composite_b.png diff --git a/example/demo.c b/example/demo.c index b855f52..cfad99e 100644 --- a/example/demo.c +++ b/example/demo.c @@ -818,9 +818,6 @@ int loadDemoData(NVGcontext* vg, DemoData* data) return -1; } } - - data->image_composite_a = nvgCreateImage(vg, "../example/images/composite_a.png", 0); - data->image_composite_b = nvgCreateImage(vg, "../example/images/composite_b.png", 0); data->fontIcons = nvgCreateFont(vg, "icons", "../example/entypo.ttf"); if (data->fontIcons == -1) { @@ -857,9 +854,6 @@ void freeDemoData(NVGcontext* vg, DemoData* data) for (i = 0; i < 12; i++) nvgDeleteImage(vg, data->images[i]); - - nvgDeleteImage(vg, data->image_composite_a); - nvgDeleteImage(vg, data->image_composite_b); } void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, float mx, float my) @@ -1066,56 +1060,6 @@ void drawScissor(NVGcontext* vg, float x, float y, float t) nvgRestore(vg); } - -void drawGlobalCompositeOperation(NVGcontext* vg, float x, float y, DemoData* data) -{ - int i; - NVGpaint imgPaint; - enum NVGcompositeOperation ops[] = { - NVG_SOURCE_OVER, - NVG_SOURCE_IN, - NVG_SOURCE_OUT, - NVG_ATOP, - NVG_DESTINATION_OVER, - NVG_DESTINATION_IN, - NVG_DESTINATION_OUT, - NVG_DESTINATION_ATOP, - NVG_LIGHTER, - NVG_COPY, - NVG_XOR - }; - - for (i = 0; i < 11; i++) - { - nvgSave(vg); - - nvgTranslate(vg, x + i * 40, y); - - nvgGlobalCompositeOperation(vg, NVG_COPY); - imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_a, 1.0); - nvgBeginPath(vg); - nvgRect(vg, 0, 0, 30, 30); - nvgFillPaint(vg, imgPaint); - nvgFill(vg); - - nvgGlobalCompositeOperation(vg, ops[i]); - imgPaint = nvgImagePattern(vg, 0, 0, 30,30, 0.0f/180.0f*NVG_PI, data->image_composite_b, 1.0); - nvgBeginPath(vg); - nvgRect(vg, 0, 0, 30, 30); - nvgFillPaint(vg, imgPaint); - nvgFill(vg); - - //fill background transparent color to white. - nvgGlobalCompositeOperation(vg, NVG_DESTINATION_OVER); - nvgBeginPath(vg); - nvgRect(vg, 0, 0, 30, 30); - nvgFillColor(vg, nvgRGBA(255,255,255,255)); - nvgFill(vg); - - nvgRestore(vg); - } -} - void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, float t, int blowup, DemoData* data) { @@ -1136,8 +1080,6 @@ void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, drawCaps(vg, 10, 300, 30); drawScissor(vg, 50, height-80, t); - - drawGlobalCompositeOperation(vg, 100, height-35, data); nvgSave(vg); if (blowup) { diff --git a/example/demo.h b/example/demo.h index 00c2588..aace449 100644 --- a/example/demo.h +++ b/example/demo.h @@ -10,8 +10,6 @@ extern "C" { struct DemoData { int fontNormal, fontBold, fontIcons, fontEmoji; int images[12]; - int image_composite_a; - int image_composite_b; }; typedef struct DemoData DemoData; diff --git a/example/images/composite_a.png b/example/images/composite_a.png deleted file mode 100644 index 6d9f3b530e016af63ed01b84464ebd21afc67281..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPNC!ZjT)aI>$kw77RPZ!4!kK=F8ZscW95MbWe^0&Os wt%0fY*gF4RYQ~kT_O1-GGcFVdQ&MBb@03etw<^TWy diff --git a/example/images/composite_b.png b/example/images/composite_b.png deleted file mode 100644 index dca6cad177c6c341042b40ac5f22f7dcccde1c0a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 591 zcmV-V091Qb*ad|m(m0o+MM zK~zY`?Upfa+b|S{KgyDlqCh)z=v=r5FiIsu+PSM?AliF~9zaL&UIT{Lt~NTfHsAx; z2k77cMNz+m{aZfn}Kp&qQd&;tFm6;XVSX=v!PtXp6B~rsEW!UWl939cjOuhA}L^nf<}B z75Op66od^}em4&XpIEWp^8b2bnm`9=11;A*1qMJrvYKz|YG5@syTNfH^4vel0lUD5 z9eW=EpCYR{f*>g1m4_=$Rg}{Yy#!_tfa1o?t|#UaQyh^rRkh+c5xFX%Uk!M zvnAD$Rp|h`^v;g-j<>PZ+?(p>XWE#;Khdqhw7RNN9G{DP{U~ZTs=bPHze#jzwCau* z9QeWQ8o_P9Vt;*GHG*4y#fC=@FF2CdIHomnr(W=%9|lvd^PooXpwco;S#iHcaK94V ze)Bin-7=#ZpraG3`ChkEU6%Q*$};a_H8uo6Np*SzG>zYBzMPodZ?4tY5H{|g4Utvv zKzJHk_1?eObJppF2$SNW7Zx{HQ!sRIylrhLXhv3t=PAoXc<$gy(cA_;JHT((hOVy} dB_c}7&|CCIz&9yWcT)fW002ovPDHLkV1kq&0EGYm