diff --git a/framework/Source/Mac/PictureOutput.swift b/framework/Source/Mac/PictureOutput.swift index 202b235a..cd31fc8c 100644 --- a/framework/Source/Mac/PictureOutput.swift +++ b/framework/Source/Mac/PictureOutput.swift @@ -46,13 +46,11 @@ public class PictureOutput: ImageConsumer { clearFramebufferWithColor(Color.transparent) // Need the blending here to enable non-1.0 alpha on output image - glBlendEquation(GLenum(GL_FUNC_ADD)) - glBlendFunc(GLenum(GL_ONE), GLenum(GL_ONE)) - glEnable(GLenum(GL_BLEND)) + enableAdditiveBlending() renderQuadWithShader(sharedImageProcessingContext.passthroughShader, uniformSettings:ShaderUniformSettings(), vertices:standardImageVertices, inputTextures:[framebuffer.texturePropertiesForOutputRotation(.noRotation)]) - glDisable(GLenum(GL_BLEND)) + disableBlending() framebuffer.unlock() diff --git a/framework/Source/OpenGLRendering.swift b/framework/Source/OpenGLRendering.swift index fc16cec6..c46db7f0 100755 --- a/framework/Source/OpenGLRendering.swift +++ b/framework/Source/OpenGLRendering.swift @@ -193,6 +193,16 @@ func attachStencilBuffer(width:GLint, height:GLint) throws -> GLuint { return stencilBuffer } +public func enableAdditiveBlending() { + glBlendEquation(GLenum(GL_FUNC_ADD)) + glBlendFunc(GLenum(GL_ONE), GLenum(GL_ONE)) + glEnable(GLenum(GL_BLEND)) +} + +public func disableBlending() { + glDisable(GLenum(GL_BLEND)) +} + extension String { func withNonZeroSuffix(_ suffix:Int) -> String { if suffix == 0 { diff --git a/framework/Source/Operations/Histogram.swift b/framework/Source/Operations/Histogram.swift index 4a926748..95274542 100755 --- a/framework/Source/Operations/Histogram.swift +++ b/framework/Source/Operations/Histogram.swift @@ -62,10 +62,8 @@ public class Histogram: BasicOperation { clearFramebufferWithColor(Color.black) - glBlendEquation(GLenum(GL_FUNC_ADD)) - glBlendFunc(GLenum(GL_ONE), GLenum(GL_ONE)) - glEnable(GLenum(GL_BLEND)) - + enableAdditiveBlending() + shader.use() guard let positionAttribute = shader.attributeIndex("position") else { fatalError("A position attribute was missing from the shader program during rendering.") } glVertexAttribPointer(positionAttribute, 4, GLenum(GL_UNSIGNED_BYTE), 0, (GLint(downsamplingFactor) - 1) * 4, data) @@ -85,7 +83,7 @@ public class Histogram: BasicOperation { glDrawArrays(GLenum(GL_POINTS), 0, inputSize.width * inputSize.height / GLint(downsamplingFactor)) } - glDisable(GLenum(GL_BLEND)) + disableBlending() data.deallocate(capacity:inputByteSize) } } diff --git a/framework/Source/Operations/LineGenerator.swift b/framework/Source/Operations/LineGenerator.swift index befe0d45..0120a184 100644 --- a/framework/Source/Operations/LineGenerator.swift +++ b/framework/Source/Operations/LineGenerator.swift @@ -63,13 +63,12 @@ public class LineGenerator: ImageGenerator { let lineEndpoints = lines.flatMap{$0.toGLEndpoints()} glVertexAttribPointer(positionAttribute, 2, GLenum(GL_FLOAT), 0, 0, lineEndpoints) - glBlendEquation(GLenum(GL_FUNC_ADD)) - glBlendFunc(GLenum(GL_ONE), GLenum(GL_ONE)) - glEnable(GLenum(GL_BLEND)) + + enableAdditiveBlending() glDrawArrays(GLenum(GL_LINES), 0, GLsizei(lines.count) * 2) - glDisable(GLenum(GL_BLEND)) + disableBlending() notifyTargets() }