Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #20 from Tharit/overdrawPerformance

improved performance when stroking transparent lines
  • Loading branch information...
commit 1e69cb6ba460d2c83ebe47f32791f4d9b5464309 2 parents 4aabff2 + 3dd35c0
@phoboslab authored
View
2  Classes/Ejecta/EJCanvas/EJPath.h
@@ -12,6 +12,8 @@
EJVector2 currentPos, startPos;
int longestSubpath;
+ GLubyte stencilMask;
+
EJVector2 * vertexBuffer;
int vertexBufferLength;
View
23 Classes/Ejecta/EJCanvas/EJPath.mm
@@ -22,7 +22,8 @@ @implementation EJPath
- (id)init {
self = [super init];
if(self) {
- transform = CGAffineTransformIdentity;
+ transform = CGAffineTransformIdentity;
+ stencilMask = 0x1;
}
return self;
}
@@ -430,15 +431,19 @@ - (void)drawLinesToContext:(EJCanvasContext *)context {
color.rgba.a = (float)color.rgba.a * state->globalAlpha;
// enable stencil test when drawing transparent lines
+ // cycle through the highest 7 bits, so that the stencil buffer only has to be cleared after seven stroke operations
+ // the lowest bit is reserved for drawPolygonsToContext
if(color.rgba.a < 0xff) {
+ stencilMask <<= 1;
+
[context createStencilBufferOnce];
glEnable(GL_STENCIL_TEST);
- glStencilMask(0x01);
+ glStencilMask(stencilMask);
- glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
- glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
+ glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+ glStencilFunc(GL_NOTEQUAL, stencilMask, stencilMask);
}
// To draw the line correctly with transformations, we need to construct the line
@@ -494,7 +499,6 @@ - (void)drawLinesToContext:(EJCanvasContext *)context {
if( !transCurrent ) { continue; }
-
currentEdge = nextEdge;
currentExt = nextExt;
nextEdge = EJVector2Normalize(EJVector2Sub(next, current));
@@ -675,8 +679,13 @@ - (void)drawLinesToContext:(EJCanvasContext *)context {
[context flushBuffers];
glDisable(GL_STENCIL_TEST);
- glClearStencil(0);
- glClear(GL_STENCIL_BUFFER_BIT);
+ if(stencilMask == (1<<7)) {
+ stencilMask = (1<<0);
+
+ glStencilMask(0xff);
+ glClearStencil(0x0);
+ glClear(GL_STENCIL_BUFFER_BIT);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.