Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008-2012 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 | #include "RenderScript.h" |
Jason Sams | 66f0a16 | 2014-11-11 13:46:38 -0800 | [diff] [blame] | 18 | #include "rsCppInternal.h" |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 19 | |
Chih-Hung Hsieh | dfcfabf | 2016-11-04 15:55:18 -0700 | [diff] [blame] | 20 | using android::RSC::Sampler; |
| 21 | using android::RSC::sp; |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 22 | |
| 23 | Sampler::Sampler(sp<RS> rs, void* id): |
| 24 | BaseObj(id, rs) |
| 25 | { |
| 26 | RsSamplerValue mMin = RS_SAMPLER_INVALID; |
| 27 | RsSamplerValue mMag = RS_SAMPLER_INVALID; |
Miao Wang | e5428e6 | 2015-03-10 15:29:40 -0700 | [diff] [blame] | 28 | RsSamplerValue mWrapS = RS_SAMPLER_INVALID; |
| 29 | RsSamplerValue mWrapT = RS_SAMPLER_INVALID; |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 30 | float mAniso = 0.f; |
| 31 | } |
| 32 | |
Miao Wang | e5428e6 | 2015-03-10 15:29:40 -0700 | [diff] [blame] | 33 | Sampler::Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag, |
| 34 | RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy): |
| 35 | BaseObj(id, rs) |
| 36 | { |
| 37 | RsSamplerValue mMin = min; |
| 38 | RsSamplerValue mMag = mag; |
| 39 | RsSamplerValue mWrapS = wrapS; |
| 40 | RsSamplerValue mWrapT = wrapT; |
| 41 | float mAniso = anisotropy; |
| 42 | } |
| 43 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 44 | RsSamplerValue Sampler::getMinification() { |
| 45 | return mMin; |
| 46 | } |
| 47 | |
| 48 | RsSamplerValue Sampler::getMagnification() { |
| 49 | return mMag; |
| 50 | } |
| 51 | |
| 52 | RsSamplerValue Sampler::getWrapS() { |
| 53 | return mWrapS; |
| 54 | } |
| 55 | |
| 56 | RsSamplerValue Sampler::getWrapT() { |
| 57 | return mWrapT; |
| 58 | } |
| 59 | |
| 60 | float Sampler::getAnisotropy() { |
| 61 | return mAniso; |
| 62 | } |
| 63 | |
Chih-Hung Hsieh | 45768e1 | 2016-08-10 12:32:11 -0700 | [diff] [blame] | 64 | sp<Sampler> Sampler::create(const sp<RS>& rs, RsSamplerValue min, RsSamplerValue mag, |
Miao Wang | e5428e6 | 2015-03-10 15:29:40 -0700 | [diff] [blame] | 65 | RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy) { |
Miao Wang | cf067b8 | 2015-09-14 18:27:17 -0700 | [diff] [blame] | 66 | // We aren't supporting wrapR in C++ API atm, so always pass wrap for that. |
Miao Wang | e5428e6 | 2015-03-10 15:29:40 -0700 | [diff] [blame] | 67 | void* id = RS::dispatch->SamplerCreate(rs->getContext(), min, mag, wrapS, wrapT, |
| 68 | RS_SAMPLER_WRAP, anisotropy); |
| 69 | return new Sampler(rs, id, min, mag, wrapS, wrapT, anisotropy); |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Chih-Hung Hsieh | 45768e1 | 2016-08-10 12:32:11 -0700 | [diff] [blame] | 72 | #define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(const sp<RS> &rs) { \ |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 73 | if (rs->mSamplers.N == nullptr) { \ |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 74 | rs->mSamplers.N = (create(rs, MIN, MAG, WRAPS, WRAPT, 0.f)); \ |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 75 | } \ |
| 76 | return rs->mSamplers.N; \ |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Miao Wang | 7fbf6e4 | 2015-04-03 10:48:48 -0700 | [diff] [blame] | 79 | CREATE_SAMPLER(CLAMP_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP); |
| 80 | CREATE_SAMPLER(CLAMP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP); |
| 81 | CREATE_SAMPLER(CLAMP_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP); |
| 82 | CREATE_SAMPLER(WRAP_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP); |
| 83 | CREATE_SAMPLER(WRAP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP); |
| 84 | CREATE_SAMPLER(WRAP_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP); |
| 85 | CREATE_SAMPLER(MIRRORED_REPEAT_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT); |
| 86 | CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT); |
| 87 | CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT); |