Sampler.java revision 7d435ae5ba100be5710b685653cc351cab159c11
198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams/* 298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Copyright (C) 2012 The Android Open Source Project 398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * you may not use this file except in compliance with the License. 698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * You may obtain a copy of the License at 798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * http://www.apache.org/licenses/LICENSE-2.0 998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 1098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Unless required by applicable law or agreed to in writing, software 1198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * distributed under the License is distributed on an "AS IS" BASIS, 1298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * See the License for the specific language governing permissions and 1498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * limitations under the License. 1598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 1698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 1798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samspackage android.support.v8.renderscript; 1898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 1998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 2098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsimport java.io.IOException; 2198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsimport java.io.InputStream; 2298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 2398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsimport android.content.res.Resources; 2498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsimport android.os.Bundle; 2598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsimport android.util.Log; 2698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 2798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsimport android.graphics.Bitmap; 2898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsimport android.graphics.BitmapFactory; 2998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 3098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams/** 317d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * Sampler object that defines how Allocations can be read as textures within a 327d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * kernel. Samplers are used in conjunction with the {@code rsSample} runtime 337d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * function to return values from normalized coordinates. 347d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * 357d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * Any Allocation used with a Sampler must have been created with {@link 367d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * android.renderscript.Allocation#USAGE_GRAPHICS_TEXTURE}; using a Sampler on 377d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * an {@link android.renderscript.Allocation} that was not created with {@link 387d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * android.renderscript.Allocation#USAGE_GRAPHICS_TEXTURE} is undefined. 3998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams **/ 4098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samspublic class Sampler extends BaseObj { 4198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public enum Value { 4298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams NEAREST (0), 4398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LINEAR (1), 4498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LINEAR_MIP_LINEAR (2), 4598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LINEAR_MIP_NEAREST (5), 4698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams WRAP (3), 47626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray CLAMP (4), 48626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray MIRRORED_REPEAT (6); 4998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 5098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int mID; 5198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value(int id) { 5298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mID = id; 5398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 5498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 5598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 5698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mMin; 5798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mMag; 5898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mWrapS; 5998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mWrapT; 6098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mWrapR; 6198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams float mAniso; 6298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 6398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Sampler(int id, RenderScript rs) { 6498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams super(id, rs); 6598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 6698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 6798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 6898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return minification setting for the sampler 6998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 7098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public Value getMinification() { 7198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return mMin; 7298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 7398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 7498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 7598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return magnification setting for the sampler 7698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 7798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public Value getMagnification() { 7898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return mMag; 7998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 8098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 8198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 8298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return S wrapping mode for the sampler 8398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 8498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public Value getWrapS() { 8598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return mWrapS; 8698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 8798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 8898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 8998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return T wrapping mode for the sampler 9098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 9198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public Value getWrapT() { 9298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return mWrapT; 9398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 9498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 9598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 9698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return anisotropy setting for the sampler 9798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 9898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public float getAnisotropy() { 9998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return mAniso; 10098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 10198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 10298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 10398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Retrieve a sampler with min and mag set to nearest and wrap modes set to 10498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * clamp. 10598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 10698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @param rs Context to which the sampler will belong. 10798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 10898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return Sampler 10998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 11098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public static Sampler CLAMP_NEAREST(RenderScript rs) { 11198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if(rs.mSampler_CLAMP_NEAREST == null) { 11298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Builder b = new Builder(rs); 11398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMinification(Value.NEAREST); 11498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMagnification(Value.NEAREST); 11598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapS(Value.CLAMP); 11698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapT(Value.CLAMP); 11798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rs.mSampler_CLAMP_NEAREST = b.create(); 11898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 11998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rs.mSampler_CLAMP_NEAREST; 12098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 12198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 12298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 12398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Retrieve a sampler with min and mag set to linear and wrap modes set to 12498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * clamp. 12598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 12698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @param rs Context to which the sampler will belong. 12798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 12898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return Sampler 12998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 13098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public static Sampler CLAMP_LINEAR(RenderScript rs) { 13198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if(rs.mSampler_CLAMP_LINEAR == null) { 13298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Builder b = new Builder(rs); 13398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMinification(Value.LINEAR); 13498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMagnification(Value.LINEAR); 13598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapS(Value.CLAMP); 13698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapT(Value.CLAMP); 13798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rs.mSampler_CLAMP_LINEAR = b.create(); 13898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 13998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rs.mSampler_CLAMP_LINEAR; 14098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 14198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 14298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 143f681be1f0ec328acaa311478887352a456d52be8Jason Sams * Retrieve a sampler with mag set to linear, min linear mipmap linear, and 144626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * wrap modes set to clamp. 14598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 14698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @param rs Context to which the sampler will belong. 14798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 14898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return Sampler 14998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 15098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) { 15198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { 15298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Builder b = new Builder(rs); 15398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMinification(Value.LINEAR_MIP_LINEAR); 15498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMagnification(Value.LINEAR); 15598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapS(Value.CLAMP); 15698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapT(Value.CLAMP); 15798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create(); 15898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 15998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR; 16098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 16198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 16298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 16398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Retrieve a sampler with min and mag set to nearest and wrap modes set to 16498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * wrap. 16598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 16698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @param rs Context to which the sampler will belong. 16798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 16898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return Sampler 16998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 17098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public static Sampler WRAP_NEAREST(RenderScript rs) { 17198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if(rs.mSampler_WRAP_NEAREST == null) { 17298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Builder b = new Builder(rs); 17398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMinification(Value.NEAREST); 17498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMagnification(Value.NEAREST); 17598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapS(Value.WRAP); 17698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapT(Value.WRAP); 17798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rs.mSampler_WRAP_NEAREST = b.create(); 17898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 17998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rs.mSampler_WRAP_NEAREST; 18098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 18198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 18298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 183f681be1f0ec328acaa311478887352a456d52be8Jason Sams * Retrieve a sampler with min and mag set to linear and wrap modes set to 18498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * wrap. 18598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 18698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @param rs Context to which the sampler will belong. 18798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 18898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return Sampler 18998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 19098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public static Sampler WRAP_LINEAR(RenderScript rs) { 19198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if(rs.mSampler_WRAP_LINEAR == null) { 19298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Builder b = new Builder(rs); 19398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMinification(Value.LINEAR); 19498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMagnification(Value.LINEAR); 19598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapS(Value.WRAP); 19698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapT(Value.WRAP); 19798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rs.mSampler_WRAP_LINEAR = b.create(); 19898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 19998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rs.mSampler_WRAP_LINEAR; 20098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 20198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 20298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 203f681be1f0ec328acaa311478887352a456d52be8Jason Sams * Retrieve a sampler with mag set to linear, min linear mipmap linear, and 204626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * wrap modes set to wrap. 20598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 20698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @param rs Context to which the sampler will belong. 20798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 20898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * @return Sampler 20998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 21098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) { 21198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { 21298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Builder b = new Builder(rs); 21398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMinification(Value.LINEAR_MIP_LINEAR); 21498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setMagnification(Value.LINEAR); 21598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapS(Value.WRAP); 21698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams b.setWrapT(Value.WRAP); 21798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create(); 21898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 21998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rs.mSampler_WRAP_LINEAR_MIP_LINEAR; 22098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 22198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 222626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray /** 223626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * Retrieve a sampler with min and mag set to nearest and wrap modes set to 224626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * mirrored repeat. 225626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * 226626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * @param rs Context to which the sampler will belong. 227626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * 228626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * @return Sampler 229626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray */ 230626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray public static Sampler MIRRORED_REPEAT_NEAREST(RenderScript rs) { 231626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray if(rs.mSampler_MIRRORED_REPEAT_NEAREST == null) { 232626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray Builder b = new Builder(rs); 233626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setMinification(Value.NEAREST); 234626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setMagnification(Value.NEAREST); 235626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setWrapS(Value.MIRRORED_REPEAT); 236626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setWrapT(Value.MIRRORED_REPEAT); 237626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray rs.mSampler_MIRRORED_REPEAT_NEAREST = b.create(); 238626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray } 239626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray return rs.mSampler_MIRRORED_REPEAT_NEAREST; 240626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray } 241626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray 242626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray /** 243626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * Retrieve a sampler with min and mag set to linear and wrap modes set to 244626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * mirrored repeat. 245626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * 246626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * @param rs Context to which the sampler will belong. 247626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * 248626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray * @return Sampler 249626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray */ 250626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray public static Sampler MIRRORED_REPEAT_LINEAR(RenderScript rs) { 251626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray if(rs.mSampler_MIRRORED_REPEAT_LINEAR == null) { 252626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray Builder b = new Builder(rs); 253626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setMinification(Value.LINEAR); 254626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setMagnification(Value.LINEAR); 255626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setWrapS(Value.MIRRORED_REPEAT); 256626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray b.setWrapT(Value.MIRRORED_REPEAT); 257626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray rs.mSampler_MIRRORED_REPEAT_LINEAR = b.create(); 258626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray } 259626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray return rs.mSampler_MIRRORED_REPEAT_LINEAR; 260626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray } 26198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 26298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /** 2637d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * Builder for creating non-standard samplers. This is only necessary if 2647d435ae5ba100be5710b685653cc351cab159c11Stephen Hines * a Sampler with different min and mag modes is desired. 26598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 26698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public static class Builder { 26798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams RenderScript mRS; 26898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mMin; 26998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mMag; 27098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mWrapS; 27198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mWrapT; 27298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Value mWrapR; 27398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams float mAniso; 27498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 27598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public Builder(RenderScript rs) { 27698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mRS = rs; 27798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mMin = Value.NEAREST; 27898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mMag = Value.NEAREST; 27998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mWrapS = Value.WRAP; 28098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mWrapT = Value.WRAP; 28198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mWrapR = Value.WRAP; 28298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mAniso = 1.0f; 28398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 28498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 28598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public void setMinification(Value v) { 28698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (v == Value.NEAREST || 28798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams v == Value.LINEAR || 28898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams v == Value.LINEAR_MIP_LINEAR || 28998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams v == Value.LINEAR_MIP_NEAREST) { 29098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mMin = v; 29198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } else { 29298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams throw new IllegalArgumentException("Invalid value"); 29398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 29498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 29598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 29698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public void setMagnification(Value v) { 29798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (v == Value.NEAREST || v == Value.LINEAR) { 29898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mMag = v; 29998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } else { 30098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams throw new IllegalArgumentException("Invalid value"); 30198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 30298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 30398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 30498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public void setWrapS(Value v) { 305626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray if (v == Value.WRAP || v == Value.CLAMP || v == Value.MIRRORED_REPEAT) { 30698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mWrapS = v; 30798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } else { 30898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams throw new IllegalArgumentException("Invalid value"); 30998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 31098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 31198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 31298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public void setWrapT(Value v) { 313626e1c2bd520e735a925ed661538ea2accd7f5f0Tim Murray if (v == Value.WRAP || v == Value.CLAMP || v == Value.MIRRORED_REPEAT) { 31498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mWrapT = v; 31598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } else { 31698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams throw new IllegalArgumentException("Invalid value"); 31798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 31898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 31998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 32098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public void setAnisotropy(float v) { 32198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if(v >= 0.0f) { 32298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mAniso = v; 32398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } else { 32498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams throw new IllegalArgumentException("Invalid value"); 32598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 32698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 32798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 32898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams public Sampler create() { 329ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray if (mRS.isNative) { 330ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray RenderScriptThunker rst = (RenderScriptThunker)mRS; 331ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray SamplerThunker.Builder b = new SamplerThunker.Builder(rst); 332ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray b.setMinification(mMin); 333ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray b.setMagnification(mMag); 334ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray b.setWrapS(mWrapS); 335ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray b.setWrapT(mWrapT); 336ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray b.setAnisotropy(mAniso); 337ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray return b.create(); 338ce8b0e674c93035013d1c33aaabc9bb6ceffde0fTim Murray } 33998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mRS.validate(); 34098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int id = mRS.nSamplerCreate(mMag.mID, mMin.mID, 34198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso); 34298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams Sampler sampler = new Sampler(id, mRS); 34398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sampler.mMin = mMin; 34498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sampler.mMag = mMag; 34598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sampler.mWrapS = mWrapS; 34698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sampler.mWrapT = mWrapT; 34798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sampler.mWrapR = mWrapR; 34898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sampler.mAniso = mAniso; 34998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return sampler; 35098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 35198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 35298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 35398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 35498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 355