From aefc9a6104341c1c9d8f033f37ce649312d2e269 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Thu, 19 Jun 2014 17:40:53 -0700 Subject: [PATCH 1/2] use -1 as the 'no scissor' value, rather than 0, so that 0 width still scissors --- src/nanovg.c | 4 ++-- src/nanovg_gl.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nanovg.c b/src/nanovg.c index 939d801..b07e560 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -828,8 +828,8 @@ void nvgResetScissor(struct NVGcontext* ctx) { struct NVGstate* state = nvg__getState(ctx); memset(state->scissor.xform, 0, sizeof(state->scissor.xform)); - state->scissor.extent[0] = 0; - state->scissor.extent[1] = 0; + state->scissor.extent[0] = -1.f; + state->scissor.extent[1] = -1.f; } static int nvg__ptEquals(float x1, float y1, float x2, float y2, float tol) diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 6b03595..2c13228 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -750,7 +750,7 @@ static int glnvg__convertPaint(struct GLNVGcontext* gl, struct GLNVGfragUniforms frag->innerCol = glnvg__premulColor(paint->innerColor); frag->outerCol = glnvg__premulColor(paint->outerColor); - if (scissor->extent[0] < 0.5f || scissor->extent[1] < 0.5f) { + if (scissor->extent[0] < -0.5f || scissor->extent[1] < -0.5f) { memset(frag->scissorMat, 0, sizeof(frag->scissorMat)); frag->scissorExt[0] = 1.0f; frag->scissorExt[1] = 1.0f; From bc136b26c878f622feae50fbdf1162ae43b03250 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Fri, 20 Jun 2014 08:54:13 -0700 Subject: [PATCH 2/2] clamp on scissor, fix nvgReset --- src/nanovg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/nanovg.c b/src/nanovg.c index b07e560..76a7e81 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -519,8 +519,8 @@ void nvgReset(struct NVGcontext* ctx) state->alpha = 1.0f; nvgTransformIdentity(state->xform); - state->scissor.extent[0] = 0.0f; - state->scissor.extent[1] = 0.0f; + state->scissor.extent[0] = -1.0f; + state->scissor.extent[1] = -1.0f; state->fontSize = 16.0f; state->letterSpacing = 0.0f; @@ -815,6 +815,9 @@ void nvgScissor(struct NVGcontext* ctx, float x, float y, float w, float h) { struct NVGstate* state = nvg__getState(ctx); + w = nvg__maxf(0.0f, w); + h = nvg__maxf(0.0f, h); + nvgTransformIdentity(state->scissor.xform); state->scissor.xform[4] = x+w*0.5f; state->scissor.xform[5] = y+h*0.5f; @@ -828,8 +831,8 @@ void nvgResetScissor(struct NVGcontext* ctx) { struct NVGstate* state = nvg__getState(ctx); memset(state->scissor.xform, 0, sizeof(state->scissor.xform)); - state->scissor.extent[0] = -1.f; - state->scissor.extent[1] = -1.f; + state->scissor.extent[0] = -1.0f; + state->scissor.extent[1] = -1.0f; } static int nvg__ptEquals(float x1, float y1, float x2, float y2, float tol)