bp74 / StageXL

A fast and universal 2D rendering engine for HTML5 and Dart.
http://www.stagexl.org
Other
880 stars 82 forks source link

moved blending logic to `BlendMode` #337

Closed maxme1 closed 3 years ago

maxme1 commented 3 years ago

A solution for #336 The logic necessary for blending is moved to a BlendingMode's method. Now the user could define more complicated blendings, e.g.:

class EquationBlendMode extends BlendMode {
  const EquationBlendMode(int mode, String compositeOperation)
      : super(mode, null, compositeOperation);

  @override
  void blend(gl.RenderingContext renderingContext) {
    var ext = renderingContext.getExtension('EXT_blend_minmax');
    assert(ext != null);
    renderingContext.blendEquation(srcFactor);
  }
}

The null in the constructor looks a bit messy, but I guess this is the only way to add custom behavior and not break any existing code which might rely on the public fields srcFactor and dstFactor.

bp74 commented 3 years ago

Thanks a lot! I will look at it over the weekend and provide a new version.

maxme1 commented 3 years ago

Great, thanks!

bp74 commented 3 years ago

The new version is 1.4.6 - thanks for the pull request. Is your work with StageXL on the internet? would love to take a look at it!

maxme1 commented 3 years ago

Thanks! We use StageXL for an image annotation tool in our lab. Unfortunately it is not publicly available, but I'll let you know if we ever release it.