Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spine-android] Clean-up, batching renderer, clipping TBD
- Loading branch information
Showing
6 changed files
with
486 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 61 additions & 36 deletions
97
...ndroid/spine-android/src/main/java/com/esotericsoftware/spine/android/AndroidTexture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,70 @@ | ||
|
||
package com.esotericsoftware.spine.android; | ||
|
||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.utils.ObjectMap; | ||
import com.esotericsoftware.spine.BlendMode; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapShader; | ||
import android.graphics.Paint; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.PorterDuffXfermode; | ||
import android.graphics.Shader; | ||
|
||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.graphics.TextureData; | ||
|
||
public class AndroidTexture extends Texture { | ||
private Bitmap bitmap; | ||
private Paint paint; | ||
|
||
protected AndroidTexture(Bitmap bitmap) { | ||
super(); | ||
this.bitmap = bitmap; | ||
this.paint = new Paint(); | ||
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); | ||
paint.setShader(shader); | ||
} | ||
|
||
public Bitmap getBitmap() { | ||
return bitmap; | ||
} | ||
|
||
public Paint getPaint() { | ||
return paint; | ||
} | ||
|
||
@Override | ||
public int getWidth() { | ||
return bitmap.getWidth(); | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
return bitmap.getHeight(); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
bitmap.recycle(); | ||
} | ||
private Bitmap bitmap; | ||
private ObjectMap<BlendMode, Paint> paints = new ObjectMap<>(); | ||
|
||
protected AndroidTexture (Bitmap bitmap) { | ||
super(); | ||
this.bitmap = bitmap; | ||
for (BlendMode blendMode : BlendMode.values()) { | ||
Paint paint = new Paint(); | ||
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); | ||
paint.setShader(shader); | ||
|
||
switch (blendMode) { | ||
case normal: | ||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); | ||
break; | ||
case multiply: | ||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); | ||
break; | ||
case additive: | ||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD)); | ||
break; | ||
case screen: | ||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
paints.put(blendMode, paint); | ||
} | ||
} | ||
|
||
public Bitmap getBitmap () { | ||
return bitmap; | ||
} | ||
|
||
public Paint getPaint (BlendMode blendMode) { | ||
return paints.get(blendMode); | ||
} | ||
|
||
@Override | ||
public int getWidth () { | ||
return bitmap.getWidth(); | ||
} | ||
|
||
@Override | ||
public int getHeight () { | ||
return bitmap.getHeight(); | ||
} | ||
|
||
@Override | ||
public void dispose () { | ||
bitmap.recycle(); | ||
} | ||
} |
Oops, something went wrong.