summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/Sampler.java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java/android/renderscript/Sampler.java')
-rw-r--r--graphics/java/android/renderscript/Sampler.java151
1 files changed, 141 insertions, 10 deletions
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 40ba7225f95e..57a9889bd325 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -29,14 +29,16 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
/**
- * @hide
- *
+ * Sampler object which defines how data is extracted from textures. Samplers
+ * are attached to Program objects (currently only fragment) when those objects
+ * need to access texture data.
**/
public class Sampler extends BaseObj {
public enum Value {
NEAREST (0),
LINEAR (1),
LINEAR_MIP_LINEAR (2),
+ LINEAR_MIP_NEAREST (5),
WRAP (3),
CLAMP (4);
@@ -47,10 +49,135 @@ public class Sampler extends BaseObj {
}
Sampler(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
+ }
+
+ /**
+ * Retrieve a sampler with min and mag set to nearest and wrap modes set to
+ * clamp.
+ *
+ * @param rs
+ *
+ * @return Sampler
+ */
+ public static Sampler CLAMP_NEAREST(RenderScript rs) {
+ if(rs.mSampler_CLAMP_NEAREST == null) {
+ Builder b = new Builder(rs);
+ b.setMinification(Value.NEAREST);
+ b.setMagnification(Value.NEAREST);
+ b.setWrapS(Value.CLAMP);
+ b.setWrapT(Value.CLAMP);
+ rs.mSampler_CLAMP_NEAREST = b.create();
+ }
+ return rs.mSampler_CLAMP_NEAREST;
}
+ /**
+ * Retrieve a sampler with min and mag set to linear and wrap modes set to
+ * clamp.
+ *
+ * @param rs
+ *
+ * @return Sampler
+ */
+ public static Sampler CLAMP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_CLAMP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMinification(Value.LINEAR);
+ b.setMagnification(Value.LINEAR);
+ b.setWrapS(Value.CLAMP);
+ b.setWrapT(Value.CLAMP);
+ rs.mSampler_CLAMP_LINEAR = b.create();
+ }
+ return rs.mSampler_CLAMP_LINEAR;
+ }
+
+ /**
+ * Retrieve a sampler with ag set to linear, min linear mipmap linear, and
+ * to and wrap modes set to clamp.
+ *
+ * @param rs
+ *
+ * @return Sampler
+ */
+ public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMinification(Value.LINEAR_MIP_LINEAR);
+ b.setMagnification(Value.LINEAR);
+ b.setWrapS(Value.CLAMP);
+ b.setWrapT(Value.CLAMP);
+ rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create();
+ }
+ return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR;
+ }
+
+ /**
+ * Retrieve a sampler with min and mag set to nearest and wrap modes set to
+ * wrap.
+ *
+ * @param rs
+ *
+ * @return Sampler
+ */
+ public static Sampler WRAP_NEAREST(RenderScript rs) {
+ if(rs.mSampler_WRAP_NEAREST == null) {
+ Builder b = new Builder(rs);
+ b.setMinification(Value.NEAREST);
+ b.setMagnification(Value.NEAREST);
+ b.setWrapS(Value.WRAP);
+ b.setWrapT(Value.WRAP);
+ rs.mSampler_WRAP_NEAREST = b.create();
+ }
+ return rs.mSampler_WRAP_NEAREST;
+ }
+
+ /**
+ * Retrieve a sampler with min and mag set to nearest and wrap modes set to
+ * wrap.
+ *
+ * @param rs
+ *
+ * @return Sampler
+ */
+ public static Sampler WRAP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_WRAP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMinification(Value.LINEAR);
+ b.setMagnification(Value.LINEAR);
+ b.setWrapS(Value.WRAP);
+ b.setWrapT(Value.WRAP);
+ rs.mSampler_WRAP_LINEAR = b.create();
+ }
+ return rs.mSampler_WRAP_LINEAR;
+ }
+
+ /**
+ * Retrieve a sampler with ag set to linear, min linear mipmap linear, and
+ * to and wrap modes set to wrap.
+ *
+ * @param rs
+ *
+ * @return Sampler
+ */
+ public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMinification(Value.LINEAR_MIP_LINEAR);
+ b.setMagnification(Value.LINEAR);
+ b.setWrapS(Value.WRAP);
+ b.setWrapT(Value.WRAP);
+ rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create();
+ }
+ return rs.mSampler_WRAP_LINEAR_MIP_LINEAR;
+ }
+
+
+ /**
+ * Builder for creating non-standard samplers. Usefull if mix and match of
+ * wrap modes is necesary or if anisotropic filtering is desired.
+ *
+ */
public static class Builder {
RenderScript mRS;
Value mMin;
@@ -58,6 +185,7 @@ public class Sampler extends BaseObj {
Value mWrapS;
Value mWrapT;
Value mWrapR;
+ float mAniso;
public Builder(RenderScript rs) {
mRS = rs;
@@ -66,19 +194,21 @@ public class Sampler extends BaseObj {
mWrapS = Value.WRAP;
mWrapT = Value.WRAP;
mWrapR = Value.WRAP;
+ mAniso = 1.0f;
}
- public void setMin(Value v) {
+ public void setMinification(Value v) {
if (v == Value.NEAREST ||
v == Value.LINEAR ||
- v == Value.LINEAR_MIP_LINEAR) {
+ v == Value.LINEAR_MIP_LINEAR ||
+ v == Value.LINEAR_MIP_NEAREST) {
mMin = v;
} else {
throw new IllegalArgumentException("Invalid value");
}
}
- public void setMag(Value v) {
+ public void setMagnification(Value v) {
if (v == Value.NEAREST || v == Value.LINEAR) {
mMag = v;
} else {
@@ -102,9 +232,9 @@ public class Sampler extends BaseObj {
}
}
- public void setWrapR(Value v) {
- if (v == Value.WRAP || v == Value.CLAMP) {
- mWrapR = v;
+ public void setAnisotropy(float v) {
+ if(v >= 0.0f) {
+ mAniso = v;
} else {
throw new IllegalArgumentException("Invalid value");
}
@@ -117,6 +247,7 @@ public class Sampler extends BaseObj {
rs.nSamplerSet(2, b.mWrapS.mID);
rs.nSamplerSet(3, b.mWrapT.mID);
rs.nSamplerSet(4, b.mWrapR.mID);
+ rs.nSamplerSet2(5, b.mAniso);
int id = rs.nSamplerCreate();
return new Sampler(id, rs);
}