From 7e11b11177f7af98a167e1087b593eea422b9aae Mon Sep 17 00:00:00 2001 From: Olli Wang Date: Sun, 2 Jul 2017 01:10:38 +0800 Subject: [PATCH] Discards fragments as early as possible. This commit moves the `discard` instruction in the fragment shader to an earlier position to avoid performing calculations whose results are unused. --- src/nanovg_gl.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 25f9d80..9e9d2ce 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -334,7 +334,7 @@ static void glnvg__blendFuncSeparate(GLNVGcontext* gl, const GLNVGblend* blend) (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); } @@ -626,6 +626,7 @@ static int glnvg__renderCreate(void* uptr) " float scissor = scissorMask(fpos);\n" "#ifdef EDGE_AA\n" " float strokeAlpha = strokeMask();\n" + " if (strokeAlpha < strokeThr) discard;\n" "#else\n" " float strokeAlpha = 1.0;\n" "#endif\n" @@ -665,9 +666,6 @@ static int glnvg__renderCreate(void* uptr) " color *= scissor;\n" " result = color * innerCol;\n" " }\n" - "#ifdef EDGE_AA\n" - " if (strokeAlpha < strokeThr) discard;\n" - "#endif\n" "#ifdef NANOVG_GL3\n" " outColor = result;\n" "#else\n"