diff options
| author | Tim Murray <timmurray@google.com> | 2013-07-23 16:20:42 -0700 |
|---|---|---|
| committer | Tim Murray <timmurray@google.com> | 2013-07-23 16:48:41 -0700 |
| commit | 729b6fe58aff47c4f666b22bbb7a6d6114ddefa9 (patch) | |
| tree | c808036ac490043f23adf4f69456c01974494708 /cpp/Sampler.cpp | |
| parent | 4a92d1268983edaf329f73c8a5b8860cdbb11596 (diff) | |
Add Sampler support to C++ API.
Change-Id: I9a6ada9cf16b5e9f92bcecc12e87d66585df1d33
Diffstat (limited to 'cpp/Sampler.cpp')
| -rw-r--r-- | cpp/Sampler.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/cpp/Sampler.cpp b/cpp/Sampler.cpp new file mode 100644 index 00000000..fa6b2fda --- /dev/null +++ b/cpp/Sampler.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2008-2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "RenderScript.h" +#include <rs.h> + +using namespace android; +using namespace RSC; + +Sampler::Sampler(sp<RS> rs, void* id): + BaseObj(id, rs) +{ + RsSamplerValue mMin = RS_SAMPLER_INVALID; + RsSamplerValue mMag = RS_SAMPLER_INVALID; + RsSamplerValue mWrapS = RS_SAMPLER_INVALID;; + RsSamplerValue mWrapT = RS_SAMPLER_INVALID;; + float mAniso = 0.f; +} + +RsSamplerValue Sampler::getMinification() { + return mMin; +} + +RsSamplerValue Sampler::getMagnification() { + return mMag; +} + +RsSamplerValue Sampler::getWrapS() { + return mWrapS; +} + +RsSamplerValue Sampler::getWrapT() { + return mWrapT; +} + +float Sampler::getAnisotropy() { + return mAniso; +} + +sp<Sampler> Sampler::create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy) { + // we aren't supporting wrapR in C++ API atm, so always pass wrap for that + void* id = RS::dispatch->SamplerCreate(rs.get(), min, mag, wrapS, wrapT, RS_SAMPLER_WRAP, anisotropy); + return new Sampler(rs, id); +} + +#define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(sp<RS> rs) { \ + if (rs->mSamplers.N == NULL) { \ + rs->mSamplers.N = (create(rs, MIN, MAG, WRAPS, WRAPT, 0.f)).get(); \ + } \ + return rs->mSamplers.N; \ + } + +CREATE_SAMPLER(CLAMP_NEAREST, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST); +CREATE_SAMPLER(CLAMP_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR); +CREATE_SAMPLER(CLAMP_LINEAR_MIP_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR); +CREATE_SAMPLER(WRAP_NEAREST, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST); +CREATE_SAMPLER(WRAP_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR); +CREATE_SAMPLER(WRAP_LINEAR_MIP_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR); +CREATE_SAMPLER(MIRRORED_REPEAT_NEAREST, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST); +CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR); +CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR_MIP_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR); |
