diff options
author | 2016-09-03 13:30:42 +0200 | |
---|---|---|
committer | 2016-09-03 13:30:42 +0200 | |
commit | d193abb0ad0827d5ecc0915d65b67faf68a87097 (patch) | |
tree | 9a750cfbd4d229c4607f4d9aaf76dea89944a0bd /3rdparty/bgfx/examples/common/nanovg/nanovg.cpp | |
parent | d8cd5ca1346607349be6777d29358acef1e4517c (diff) |
Update BGFX and BX packages and update MAME code to support new API (nw)
Generated missing shaders (nw)
Diffstat (limited to '3rdparty/bgfx/examples/common/nanovg/nanovg.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/nanovg/nanovg.cpp | 105 |
1 files changed, 98 insertions, 7 deletions
diff --git a/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp b/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp index c7433cdc45d..9904141c103 100644 --- a/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp +++ b/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp @@ -110,6 +110,7 @@ enum NVGpointFlags }; struct NVGstate { + NVGcompositeOperationState compositeOperation; NVGpaint fill; NVGpaint stroke; float strokeWidth; @@ -247,6 +248,76 @@ static void nvg__setDevicePixelRatio(NVGcontext* ctx, float ratio) ctx->devicePxRatio = ratio; } +static NVGcompositeOperationState nvg__compositeOperationState(int op) +{ + // NVG_SOURCE_OVER + int sfactor = NVG_ONE; + int dfactor = NVG_ONE_MINUS_SRC_ALPHA; + + if (op == NVG_SOURCE_IN) + { + sfactor = NVG_DST_ALPHA; + dfactor = NVG_ZERO; + } + else if (op == NVG_SOURCE_OUT) + { + sfactor = NVG_ONE_MINUS_DST_ALPHA; + dfactor = NVG_ZERO; + } + else if (op == NVG_ATOP) + { + sfactor = NVG_DST_ALPHA; + dfactor = NVG_ONE_MINUS_SRC_ALPHA; + } + else if (op == NVG_DESTINATION_OVER) + { + sfactor = NVG_ONE_MINUS_DST_ALPHA; + dfactor = NVG_ONE; + } + else if (op == NVG_DESTINATION_IN) + { + sfactor = NVG_ZERO; + dfactor = NVG_SRC_ALPHA; + } + else if (op == NVG_DESTINATION_OUT) + { + sfactor = NVG_ZERO; + dfactor = NVG_ONE_MINUS_SRC_ALPHA; + } + else if (op == NVG_DESTINATION_ATOP) + { + sfactor = NVG_ONE_MINUS_DST_ALPHA; + dfactor = NVG_SRC_ALPHA; + } + else if (op == NVG_LIGHTER) + { + sfactor = NVG_ONE; + dfactor = NVG_ONE; + } + else if (op == NVG_COPY) + { + sfactor = NVG_ONE; + dfactor = NVG_ZERO; + } + else if (op == NVG_XOR) + { + sfactor = NVG_ONE_MINUS_DST_ALPHA; + dfactor = NVG_ONE_MINUS_SRC_ALPHA; + } + + NVGcompositeOperationState state; + state.srcRGB = sfactor; + state.dstRGB = dfactor; + state.srcAlpha = sfactor; + state.dstAlpha = dfactor; + return state; +} + +static NVGstate* nvg__getState(NVGcontext* ctx) +{ + return &ctx->states[ctx->nstates-1]; +} + NVGcontext* nvgCreateInternal(NVGparams* params) { FONSparams fontParams; @@ -354,7 +425,8 @@ void nvgCancelFrame(NVGcontext* ctx) void nvgEndFrame(NVGcontext* ctx) { - ctx->params.renderFlush(ctx->params.userPtr); + NVGstate* state = nvg__getState(ctx); + ctx->params.renderFlush(ctx->params.userPtr, state->compositeOperation); if (ctx->fontImageIdx != 0) { int fontImage = ctx->fontImages[ctx->fontImageIdx]; int i, j, iw, ih; @@ -477,12 +549,6 @@ NVGcolor nvgHSLA(float h, float s, float l, unsigned char a) return col; } - -static NVGstate* nvg__getState(NVGcontext* ctx) -{ - return &ctx->states[ctx->nstates-1]; -} - void nvgTransformIdentity(float* t) { t[0] = 1.0f; t[1] = 0.0f; @@ -615,6 +681,7 @@ void nvgReset(NVGcontext* ctx) nvg__setPaintColor(&state->fill, nvgRGBA(255,255,255,255)); nvg__setPaintColor(&state->stroke, nvgRGBA(0,0,0,255)); + state->compositeOperation = nvg__compositeOperationState(NVG_SOURCE_OVER); state->strokeWidth = 1.0f; state->miterLimit = 10.0f; state->lineCap = NVG_BUTT; @@ -983,6 +1050,30 @@ void nvgResetScissor(NVGcontext* ctx) state->scissor.extent[1] = -1.0f; } +// Global composite operation. +void nvgGlobalCompositeOperation(NVGcontext* ctx, int op) +{ + NVGstate* state = nvg__getState(ctx); + state->compositeOperation = nvg__compositeOperationState(op); +} + +void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor) +{ + nvgGlobalCompositeBlendFuncSeparate(ctx, sfactor, dfactor, sfactor, dfactor); +} + +void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) +{ + NVGcompositeOperationState op; + op.srcRGB = srcRGB; + op.dstRGB = dstRGB; + op.srcAlpha = srcAlpha; + op.dstAlpha = dstAlpha; + + NVGstate* state = nvg__getState(ctx); + state->compositeOperation = op; +} + static int nvg__ptEquals(float x1, float y1, float x2, float y2, float tol) { float dx = x2 - x1; |