mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Added setDefaultShader and a bind method for customization when a texture is bound (eg to set shader values).
This commit is contained in:
parent
4e34c0bae1
commit
1dbbec55fc
@ -68,8 +68,8 @@ public class TwoColorPolygonBatch implements PolygonBatch {
|
|||||||
private final Matrix4 combinedMatrix = new Matrix4();
|
private final Matrix4 combinedMatrix = new Matrix4();
|
||||||
private boolean blendingDisabled;
|
private boolean blendingDisabled;
|
||||||
|
|
||||||
private final ShaderProgram defaultShader;
|
private ShaderProgram defaultShader;
|
||||||
private final boolean ownsDefaultShader;
|
private boolean ownsDefaultShader;
|
||||||
private ShaderProgram shader;
|
private ShaderProgram shader;
|
||||||
|
|
||||||
private int vertexIndex, triangleIndex;
|
private int vertexIndex, triangleIndex;
|
||||||
@ -1317,7 +1317,7 @@ public class TwoColorPolygonBatch implements PolygonBatch {
|
|||||||
|
|
||||||
totalRenderCalls++;
|
totalRenderCalls++;
|
||||||
|
|
||||||
lastTexture.bind();
|
bind(lastTexture);
|
||||||
Mesh mesh = this.mesh;
|
Mesh mesh = this.mesh;
|
||||||
mesh.setVertices(vertices, 0, vertexIndex);
|
mesh.setVertices(vertices, 0, vertexIndex);
|
||||||
mesh.setIndices(triangles, 0, triangleIndex);
|
mesh.setIndices(triangles, 0, triangleIndex);
|
||||||
@ -1325,8 +1325,7 @@ public class TwoColorPolygonBatch implements PolygonBatch {
|
|||||||
Gdx.gl.glDisable(GL20.GL_BLEND);
|
Gdx.gl.glDisable(GL20.GL_BLEND);
|
||||||
else {
|
else {
|
||||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||||
if (blendSrcFunc != -1)
|
if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha);
|
||||||
Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha);
|
|
||||||
}
|
}
|
||||||
mesh.render(shader, GL20.GL_TRIANGLES, 0, triangleIndex);
|
mesh.render(shader, GL20.GL_TRIANGLES, 0, triangleIndex);
|
||||||
|
|
||||||
@ -1334,6 +1333,10 @@ public class TwoColorPolygonBatch implements PolygonBatch {
|
|||||||
triangleIndex = 0;
|
triangleIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void bind (Texture texture) {
|
||||||
|
texture.bind();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableBlending () {
|
public void disableBlending () {
|
||||||
flush();
|
flush();
|
||||||
@ -1401,6 +1404,20 @@ public class TwoColorPolygonBatch implements PolygonBatch {
|
|||||||
invTexHeight = 1.0f / texture.getHeight();
|
invTexHeight = 1.0f / texture.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Flushes the batch if the shader was changed. */
|
||||||
|
public void setDefaultShader (ShaderProgram newDefaultShader) {
|
||||||
|
boolean current = shader == defaultShader;
|
||||||
|
boolean flush = current && drawing;
|
||||||
|
if (flush) flush();
|
||||||
|
if (ownsDefaultShader) defaultShader.dispose();
|
||||||
|
defaultShader = newDefaultShader;
|
||||||
|
if (current) shader = newDefaultShader;
|
||||||
|
if (flush) {
|
||||||
|
newDefaultShader.bind();
|
||||||
|
setupMatrices();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Flushes the batch if the shader was changed.
|
/** Flushes the batch if the shader was changed.
|
||||||
* @param newShader If null, the default shader is used. */
|
* @param newShader If null, the default shader is used. */
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user