| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2008 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | package android.renderscript; | 
 | 18 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 19 | /** | 
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 20 |  * Sampler object that defines how Allocations can be read as textures within a | 
 | 21 |  * kernel. Samplers are used in conjunction with the {@code rsSample} runtime | 
 | 22 |  * function to return values from normalized coordinates. | 
 | 23 |  * | 
 | 24 |  * Any Allocation used with a Sampler must have been created with {@link | 
 | 25 |  * android.renderscript.Allocation#USAGE_GRAPHICS_TEXTURE}; using a Sampler on | 
 | 26 |  * an {@link android.renderscript.Allocation} that was not created with {@link | 
 | 27 |  * android.renderscript.Allocation#USAGE_GRAPHICS_TEXTURE} is undefined. | 
| Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 28 |  * | 
 | 29 |  * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a | 
 | 30 |  * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration | 
 | 31 |  * guide</a> for the proposed alternatives. | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 32 |  **/ | 
| Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 33 | @Deprecated | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 34 | public class Sampler extends BaseObj { | 
 | 35 |     public enum Value { | 
 | 36 |         NEAREST (0), | 
 | 37 |         LINEAR (1), | 
 | 38 |         LINEAR_MIP_LINEAR (2), | 
| Alex Sakhartchouk | 0857196 | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 39 |         LINEAR_MIP_NEAREST (5), | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 40 |         WRAP (3), | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 41 |         CLAMP (4), | 
 | 42 |         MIRRORED_REPEAT (6); | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 43 |  | 
 | 44 |         int mID; | 
 | 45 |         Value(int id) { | 
 | 46 |             mID = id; | 
 | 47 |         } | 
 | 48 |     } | 
 | 49 |  | 
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 50 |     Value mMin; | 
 | 51 |     Value mMag; | 
 | 52 |     Value mWrapS; | 
 | 53 |     Value mWrapT; | 
 | 54 |     Value mWrapR; | 
 | 55 |     float mAniso; | 
 | 56 |  | 
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 57 |     Sampler(long id, RenderScript rs) { | 
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 58 |         super(id, rs); | 
| Yang Ni | eb4dd08 | 2016-03-24 09:40:32 -0700 | [diff] [blame] | 59 |         guard.open("destroy"); | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 60 |     } | 
 | 61 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 62 |     /** | 
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 63 |      * @return minification setting for the sampler | 
 | 64 |      */ | 
 | 65 |     public Value getMinification() { | 
 | 66 |         return mMin; | 
 | 67 |     } | 
 | 68 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 69 |     /** | 
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 70 |      * @return magnification setting for the sampler | 
 | 71 |      */ | 
 | 72 |     public Value getMagnification() { | 
 | 73 |         return mMag; | 
 | 74 |     } | 
 | 75 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 76 |     /** | 
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 77 |      * @return S wrapping mode for the sampler | 
 | 78 |      */ | 
 | 79 |     public Value getWrapS() { | 
 | 80 |         return mWrapS; | 
 | 81 |     } | 
 | 82 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 83 |     /** | 
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 84 |      * @return T wrapping mode for the sampler | 
 | 85 |      */ | 
 | 86 |     public Value getWrapT() { | 
 | 87 |         return mWrapT; | 
 | 88 |     } | 
 | 89 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 90 |     /** | 
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 91 |      * @return anisotropy setting for the sampler | 
 | 92 |      */ | 
 | 93 |     public float getAnisotropy() { | 
 | 94 |         return mAniso; | 
 | 95 |     } | 
 | 96 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 97 |     /** | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 98 |      * Retrieve a sampler with min and mag set to nearest and wrap modes set to | 
 | 99 |      * clamp. | 
 | 100 |      * | 
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 101 |      * @param rs Context to which the sampler will belong. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 102 |      * | 
 | 103 |      * @return Sampler | 
 | 104 |      */ | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 105 |     public static Sampler CLAMP_NEAREST(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 106 |         if (rs.mSampler_CLAMP_NEAREST == null) { | 
 | 107 |             synchronized (rs) { | 
 | 108 |                 if (rs.mSampler_CLAMP_NEAREST == null) { | 
 | 109 |                     Builder b = new Builder(rs); | 
 | 110 |                     b.setMinification(Value.NEAREST); | 
 | 111 |                     b.setMagnification(Value.NEAREST); | 
 | 112 |                     b.setWrapS(Value.CLAMP); | 
 | 113 |                     b.setWrapT(Value.CLAMP); | 
 | 114 |                     rs.mSampler_CLAMP_NEAREST = b.create(); | 
 | 115 |                 } | 
 | 116 |             } | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 117 |         } | 
 | 118 |         return rs.mSampler_CLAMP_NEAREST; | 
 | 119 |     } | 
 | 120 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 121 |     /** | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 122 |      * Retrieve a sampler with min and mag set to linear and wrap modes set to | 
 | 123 |      * clamp. | 
 | 124 |      * | 
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 125 |      * @param rs Context to which the sampler will belong. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 126 |      * | 
 | 127 |      * @return Sampler | 
 | 128 |      */ | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 129 |     public static Sampler CLAMP_LINEAR(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 130 |         if (rs.mSampler_CLAMP_LINEAR == null) { | 
 | 131 |             synchronized (rs) { | 
 | 132 |                 if (rs.mSampler_CLAMP_LINEAR == null) { | 
 | 133 |                     Builder b = new Builder(rs); | 
 | 134 |                     b.setMinification(Value.LINEAR); | 
 | 135 |                     b.setMagnification(Value.LINEAR); | 
 | 136 |                     b.setWrapS(Value.CLAMP); | 
 | 137 |                     b.setWrapT(Value.CLAMP); | 
 | 138 |                     rs.mSampler_CLAMP_LINEAR = b.create(); | 
 | 139 |                 } | 
 | 140 |             } | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 141 |         } | 
 | 142 |         return rs.mSampler_CLAMP_LINEAR; | 
 | 143 |     } | 
 | 144 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 145 |     /** | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 146 |      * Retrieve a sampler with mag set to linear, min linear mipmap linear, and | 
 | 147 |      * wrap modes set to clamp. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 148 |      * | 
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 149 |      * @param rs Context to which the sampler will belong. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 150 |      * | 
 | 151 |      * @return Sampler | 
 | 152 |      */ | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 153 |     public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 154 |         if (rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { | 
 | 155 |             synchronized (rs) { | 
 | 156 |                 if (rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { | 
 | 157 |                     Builder b = new Builder(rs); | 
 | 158 |                     b.setMinification(Value.LINEAR_MIP_LINEAR); | 
 | 159 |                     b.setMagnification(Value.LINEAR); | 
 | 160 |                     b.setWrapS(Value.CLAMP); | 
 | 161 |                     b.setWrapT(Value.CLAMP); | 
 | 162 |                     rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create(); | 
 | 163 |                 } | 
 | 164 |             } | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 165 |         } | 
 | 166 |         return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR; | 
 | 167 |     } | 
 | 168 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 169 |     /** | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 170 |      * Retrieve a sampler with min and mag set to nearest and wrap modes set to | 
 | 171 |      * wrap. | 
 | 172 |      * | 
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 173 |      * @param rs Context to which the sampler will belong. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 174 |      * | 
 | 175 |      * @return Sampler | 
 | 176 |      */ | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 177 |     public static Sampler WRAP_NEAREST(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 178 |         if (rs.mSampler_WRAP_NEAREST == null) { | 
 | 179 |             synchronized (rs) { | 
 | 180 |                 if (rs.mSampler_WRAP_NEAREST == null) { | 
 | 181 |                     Builder b = new Builder(rs); | 
 | 182 |                     b.setMinification(Value.NEAREST); | 
 | 183 |                     b.setMagnification(Value.NEAREST); | 
 | 184 |                     b.setWrapS(Value.WRAP); | 
 | 185 |                     b.setWrapT(Value.WRAP); | 
 | 186 |                     rs.mSampler_WRAP_NEAREST = b.create(); | 
 | 187 |                 } | 
 | 188 |             } | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 189 |         } | 
 | 190 |         return rs.mSampler_WRAP_NEAREST; | 
 | 191 |     } | 
 | 192 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 193 |     /** | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 194 |      * Retrieve a sampler with min and mag set to linear and wrap modes set to | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 195 |      * wrap. | 
 | 196 |      * | 
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 197 |      * @param rs Context to which the sampler will belong. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 198 |      * | 
 | 199 |      * @return Sampler | 
 | 200 |      */ | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 201 |     public static Sampler WRAP_LINEAR(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 202 |         if (rs.mSampler_WRAP_LINEAR == null) { | 
 | 203 |             synchronized (rs) { | 
 | 204 |                 if (rs.mSampler_WRAP_LINEAR == null) { | 
 | 205 |                     Builder b = new Builder(rs); | 
 | 206 |                     b.setMinification(Value.LINEAR); | 
 | 207 |                     b.setMagnification(Value.LINEAR); | 
 | 208 |                     b.setWrapS(Value.WRAP); | 
 | 209 |                     b.setWrapT(Value.WRAP); | 
 | 210 |                     rs.mSampler_WRAP_LINEAR = b.create(); | 
 | 211 |                 } | 
 | 212 |             } | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 213 |         } | 
 | 214 |         return rs.mSampler_WRAP_LINEAR; | 
 | 215 |     } | 
 | 216 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 217 |     /** | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 218 |      * Retrieve a sampler with mag set to linear, min linear mipmap linear, and | 
 | 219 |      * wrap modes set to wrap. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 220 |      * | 
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 221 |      * @param rs Context to which the sampler will belong. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 222 |      * | 
 | 223 |      * @return Sampler | 
 | 224 |      */ | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 225 |     public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 226 |         if (rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { | 
 | 227 |             synchronized (rs) { | 
 | 228 |                 if (rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { | 
 | 229 |                     Builder b = new Builder(rs); | 
 | 230 |                     b.setMinification(Value.LINEAR_MIP_LINEAR); | 
 | 231 |                     b.setMagnification(Value.LINEAR); | 
 | 232 |                     b.setWrapS(Value.WRAP); | 
 | 233 |                     b.setWrapT(Value.WRAP); | 
 | 234 |                     rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create(); | 
 | 235 |                 } | 
 | 236 |             } | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 237 |         } | 
 | 238 |         return rs.mSampler_WRAP_LINEAR_MIP_LINEAR; | 
 | 239 |     } | 
 | 240 |  | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 241 |     /** | 
 | 242 |      * Retrieve a sampler with min and mag set to nearest and wrap modes set to | 
 | 243 |      * mirrored repeat. | 
 | 244 |      * | 
 | 245 |      * @param rs Context to which the sampler will belong. | 
 | 246 |      * | 
 | 247 |      * @return Sampler | 
 | 248 |      */ | 
 | 249 |     public static Sampler MIRRORED_REPEAT_NEAREST(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 250 |         if (rs.mSampler_MIRRORED_REPEAT_NEAREST == null) { | 
 | 251 |             synchronized (rs) { | 
 | 252 |                 if (rs.mSampler_MIRRORED_REPEAT_NEAREST == null) { | 
 | 253 |                     Builder b = new Builder(rs); | 
 | 254 |                     b.setMinification(Value.NEAREST); | 
 | 255 |                     b.setMagnification(Value.NEAREST); | 
 | 256 |                     b.setWrapS(Value.MIRRORED_REPEAT); | 
 | 257 |                     b.setWrapT(Value.MIRRORED_REPEAT); | 
 | 258 |                     rs.mSampler_MIRRORED_REPEAT_NEAREST = b.create(); | 
 | 259 |                 } | 
 | 260 |             } | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 261 |         } | 
 | 262 |         return rs.mSampler_MIRRORED_REPEAT_NEAREST; | 
 | 263 |     } | 
 | 264 |  | 
 | 265 |     /** | 
 | 266 |      * Retrieve a sampler with min and mag set to linear and wrap modes set to | 
 | 267 |      * mirrored repeat. | 
 | 268 |      * | 
 | 269 |      * @param rs Context to which the sampler will belong. | 
 | 270 |      * | 
 | 271 |      * @return Sampler | 
 | 272 |      */ | 
 | 273 |     public static Sampler MIRRORED_REPEAT_LINEAR(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 274 |         if (rs.mSampler_MIRRORED_REPEAT_LINEAR == null) { | 
 | 275 |             synchronized (rs) { | 
 | 276 |                 if (rs.mSampler_MIRRORED_REPEAT_LINEAR == null) { | 
 | 277 |                     Builder b = new Builder(rs); | 
 | 278 |                     b.setMinification(Value.LINEAR); | 
 | 279 |                     b.setMagnification(Value.LINEAR); | 
 | 280 |                     b.setWrapS(Value.MIRRORED_REPEAT); | 
 | 281 |                     b.setWrapT(Value.MIRRORED_REPEAT); | 
 | 282 |                     rs.mSampler_MIRRORED_REPEAT_LINEAR = b.create(); | 
 | 283 |                 } | 
 | 284 |             } | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 285 |         } | 
 | 286 |         return rs.mSampler_MIRRORED_REPEAT_LINEAR; | 
 | 287 |     } | 
 | 288 |  | 
 | 289 |     /** | 
 | 290 |      * Retrieve a sampler with min and mag set to linear and wrap modes set to | 
 | 291 |      * mirrored repeat. | 
 | 292 |      * | 
 | 293 |      * @param rs Context to which the sampler will belong. | 
 | 294 |      * | 
 | 295 |      * @return Sampler | 
 | 296 |      */ | 
 | 297 |     public static Sampler MIRRORED_REPEAT_LINEAR_MIP_LINEAR(RenderScript rs) { | 
| Yang Ni | 6bdfe0f | 2016-04-18 16:56:16 -0700 | [diff] [blame] | 298 |         if (rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR == null) { | 
 | 299 |             synchronized (rs) { | 
 | 300 |                 if (rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR == null) { | 
 | 301 |                     Builder b = new Builder(rs); | 
 | 302 |                     b.setMinification(Value.LINEAR_MIP_LINEAR); | 
 | 303 |                     b.setMagnification(Value.LINEAR); | 
 | 304 |                     b.setWrapS(Value.MIRRORED_REPEAT); | 
 | 305 |                     b.setWrapT(Value.MIRRORED_REPEAT); | 
 | 306 |                     rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR = b.create(); | 
 | 307 |                 } | 
 | 308 |             } | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 309 |         } | 
 | 310 |         return rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR; | 
 | 311 |     } | 
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 312 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 313 |     /** | 
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 314 |      * Builder for creating non-standard samplers.  This is only necessary if | 
 | 315 |      * a Sampler with different min and mag modes is desired. | 
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 316 |      */ | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 317 |     public static class Builder { | 
 | 318 |         RenderScript mRS; | 
 | 319 |         Value mMin; | 
 | 320 |         Value mMag; | 
 | 321 |         Value mWrapS; | 
 | 322 |         Value mWrapT; | 
 | 323 |         Value mWrapR; | 
| Alex Sakhartchouk | f5b3510 | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 324 |         float mAniso; | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 325 |  | 
 | 326 |         public Builder(RenderScript rs) { | 
 | 327 |             mRS = rs; | 
 | 328 |             mMin = Value.NEAREST; | 
 | 329 |             mMag = Value.NEAREST; | 
 | 330 |             mWrapS = Value.WRAP; | 
 | 331 |             mWrapT = Value.WRAP; | 
 | 332 |             mWrapR = Value.WRAP; | 
| Alex Sakhartchouk | f5b3510 | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 333 |             mAniso = 1.0f; | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 334 |         } | 
 | 335 |  | 
| Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 336 |         public void setMinification(Value v) { | 
| Jason Sams | 8bb41dd | 2009-12-16 15:59:59 -0800 | [diff] [blame] | 337 |             if (v == Value.NEAREST || | 
 | 338 |                 v == Value.LINEAR || | 
| Alex Sakhartchouk | 0857196 | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 339 |                 v == Value.LINEAR_MIP_LINEAR || | 
 | 340 |                 v == Value.LINEAR_MIP_NEAREST) { | 
| Jason Sams | 8bb41dd | 2009-12-16 15:59:59 -0800 | [diff] [blame] | 341 |                 mMin = v; | 
 | 342 |             } else { | 
 | 343 |                 throw new IllegalArgumentException("Invalid value"); | 
 | 344 |             } | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 345 |         } | 
 | 346 |  | 
| Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 347 |         public void setMagnification(Value v) { | 
| Jason Sams | 8bb41dd | 2009-12-16 15:59:59 -0800 | [diff] [blame] | 348 |             if (v == Value.NEAREST || v == Value.LINEAR) { | 
 | 349 |                 mMag = v; | 
 | 350 |             } else { | 
 | 351 |                 throw new IllegalArgumentException("Invalid value"); | 
 | 352 |             } | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 353 |         } | 
 | 354 |  | 
 | 355 |         public void setWrapS(Value v) { | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 356 |             if (v == Value.WRAP || v == Value.CLAMP || v == Value.MIRRORED_REPEAT) { | 
| Jason Sams | 8bb41dd | 2009-12-16 15:59:59 -0800 | [diff] [blame] | 357 |                 mWrapS = v; | 
 | 358 |             } else { | 
 | 359 |                 throw new IllegalArgumentException("Invalid value"); | 
 | 360 |             } | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 361 |         } | 
 | 362 |  | 
 | 363 |         public void setWrapT(Value v) { | 
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 364 |             if (v == Value.WRAP || v == Value.CLAMP || v == Value.MIRRORED_REPEAT) { | 
| Jason Sams | 8bb41dd | 2009-12-16 15:59:59 -0800 | [diff] [blame] | 365 |                 mWrapT = v; | 
 | 366 |             } else { | 
 | 367 |                 throw new IllegalArgumentException("Invalid value"); | 
 | 368 |             } | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 369 |         } | 
 | 370 |  | 
| Alex Sakhartchouk | f5b3510 | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 371 |         public void setAnisotropy(float v) { | 
 | 372 |             if(v >= 0.0f) { | 
 | 373 |                 mAniso = v; | 
 | 374 |             } else { | 
 | 375 |                 throw new IllegalArgumentException("Invalid value"); | 
 | 376 |             } | 
 | 377 |         } | 
 | 378 |  | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 379 |         public Sampler create() { | 
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 380 |             mRS.validate(); | 
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 381 |             long id = mRS.nSamplerCreate(mMag.mID, mMin.mID, | 
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 382 |                                         mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso); | 
 | 383 |             Sampler sampler = new Sampler(id, mRS); | 
 | 384 |             sampler.mMin = mMin; | 
 | 385 |             sampler.mMag = mMag; | 
 | 386 |             sampler.mWrapS = mWrapS; | 
 | 387 |             sampler.mWrapT = mWrapT; | 
 | 388 |             sampler.mWrapR = mWrapR; | 
 | 389 |             sampler.mAniso = mAniso; | 
 | 390 |             return sampler; | 
| Jason Sams | 0835d42 | 2009-08-04 17:58:23 -0700 | [diff] [blame] | 391 |         } | 
 | 392 |     } | 
 | 393 |  | 
 | 394 | } | 
 | 395 |  |