|
@@ -27,12 +27,19 @@
|
|
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*****************************************************************************/
|
|
*****************************************************************************/
|
|
|
|
|
|
-import { Disposable } from "@esotericsoftware/spine-core";
|
|
|
|
|
|
+import { BlendMode, Disposable } from "@esotericsoftware/spine-core";
|
|
import { GLTexture } from "./GLTexture";
|
|
import { GLTexture } from "./GLTexture";
|
|
import { Mesh, Position2Attribute, ColorAttribute, TexCoordAttribute, Color2Attribute } from "./Mesh";
|
|
import { Mesh, Position2Attribute, ColorAttribute, TexCoordAttribute, Color2Attribute } from "./Mesh";
|
|
import { Shader } from "./Shader";
|
|
import { Shader } from "./Shader";
|
|
import { ManagedWebGLRenderingContext } from "./WebGL";
|
|
import { ManagedWebGLRenderingContext } from "./WebGL";
|
|
|
|
|
|
|
|
+const GL_ONE = 1;
|
|
|
|
+const GL_ONE_MINUS_SRC_COLOR = 0x0301;
|
|
|
|
+const GL_SRC_ALPHA = 0x0302;
|
|
|
|
+const GL_ONE_MINUS_SRC_ALPHA = 0x0303;
|
|
|
|
+const GL_ONE_MINUS_DST_ALPHA = 0x0305;
|
|
|
|
+const GL_DST_COLOR = 0x0306;
|
|
|
|
+
|
|
export class PolygonBatcher implements Disposable {
|
|
export class PolygonBatcher implements Disposable {
|
|
public static disableCulling = false;
|
|
public static disableCulling = false;
|
|
|
|
|
|
@@ -80,16 +87,28 @@ export class PolygonBatcher implements Disposable {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- setBlendMode (srcColorBlend: number, srcAlphaBlend: number, dstBlend: number) {
|
|
|
|
|
|
+ private static blendModesGL: {srcRgb: number, srcRgbPma: number, dstRgb: number, srcAlpha: number}[] = [
|
|
|
|
+ {srcRgb: GL_SRC_ALPHA, srcRgbPma: GL_ONE, dstRgb: GL_ONE_MINUS_SRC_ALPHA, srcAlpha: GL_ONE },
|
|
|
|
+ {srcRgb: GL_SRC_ALPHA, srcRgbPma: GL_ONE, dstRgb: GL_ONE, srcAlpha: GL_ONE },
|
|
|
|
+ {srcRgb: GL_DST_COLOR, srcRgbPma: GL_DST_COLOR, dstRgb: GL_ONE_MINUS_SRC_ALPHA, srcAlpha: GL_ONE},
|
|
|
|
+ {srcRgb: GL_ONE, srcRgbPma: GL_ONE, dstRgb: GL_ONE_MINUS_SRC_COLOR, srcAlpha: GL_ONE }
|
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+ setBlendMode (blendMode: BlendMode, premultipliedAlpha: boolean) {
|
|
|
|
+ const blendModeGL = PolygonBatcher.blendModesGL[blendMode];
|
|
|
|
+ const srcColorBlend = premultipliedAlpha ? blendModeGL.srcRgbPma : blendModeGL.srcRgb;
|
|
|
|
+ const srcAlphaBlend = blendModeGL.srcAlpha;
|
|
|
|
+ const dstBlend = blendModeGL.dstRgb;
|
|
|
|
+
|
|
if (this.srcColorBlend == srcColorBlend && this.srcAlphaBlend == srcAlphaBlend && this.dstBlend == dstBlend) return;
|
|
if (this.srcColorBlend == srcColorBlend && this.srcAlphaBlend == srcAlphaBlend && this.dstBlend == dstBlend) return;
|
|
this.srcColorBlend = srcColorBlend;
|
|
this.srcColorBlend = srcColorBlend;
|
|
this.srcAlphaBlend = srcAlphaBlend;
|
|
this.srcAlphaBlend = srcAlphaBlend;
|
|
this.dstBlend = dstBlend;
|
|
this.dstBlend = dstBlend;
|
|
if (this.isDrawing) {
|
|
if (this.isDrawing) {
|
|
this.flush();
|
|
this.flush();
|
|
- let gl = this.context.gl;
|
|
|
|
- gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
|
|
|
|
}
|
|
}
|
|
|
|
+ let gl = this.context.gl;
|
|
|
|
+ gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
|
|
}
|
|
}
|
|
|
|
|
|
draw (texture: GLTexture, vertices: ArrayLike<number>, indices: Array<number>) {
|
|
draw (texture: GLTexture, vertices: ArrayLike<number>, indices: Array<number>) {
|